@aiworker/web 1.22.0 → 1.22.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (354) hide show
  1. package/README.md +4 -4
  2. package/bin/cli.js +7 -4
  3. package/bin/cli.test.js +165 -73
  4. package/bin/lib/cli-api-target.js +2 -2
  5. package/bin/lib/cli-args.js +119 -119
  6. package/bin/lib/cli-lifecycle.js +9 -9
  7. package/bin/lib/cli-network.js +3 -3
  8. package/bin/lib/cli-paths.js +3 -3
  9. package/bin/lib/cli-ports.js +2 -2
  10. package/bin/lib/cli-process.js +4 -4
  11. package/bin/lib/cli-startup.js +64 -15
  12. package/bin/lib/cli-tunnel-profiles.js +1 -1
  13. package/bin/lib/cli-tunnel-utils.js +2 -2
  14. package/bin/lib/commands-connect-url.js +19 -19
  15. package/bin/lib/commands-lifecycle.js +27 -27
  16. package/bin/lib/commands-logs.js +5 -5
  17. package/bin/lib/commands-models.js +1 -1
  18. package/bin/lib/commands-projects.js +1 -1
  19. package/bin/lib/commands-schedule.js +1 -1
  20. package/bin/lib/commands-serve.js +29 -29
  21. package/bin/lib/commands-session.js +1 -1
  22. package/bin/lib/commands-startup.js +45 -10
  23. package/bin/lib/commands-status.js +1 -1
  24. package/bin/lib/commands-tunnel.js +40 -40
  25. package/bin/lib/commands-update.js +1 -1
  26. package/bin/lib/commands-update.test.js +6 -6
  27. package/dist/assets/{CodeMirrorCommentWidgets-B3u7UIcE.js → CodeMirrorCommentWidgets-CSICpWQD.js} +1 -1
  28. package/dist/assets/{DiffView-DluiRSla.js → DiffView-hDBKesA_.js} +3 -3
  29. package/dist/assets/DirtyBranchSwitchDialog-C22HdWj4.js +1 -0
  30. package/dist/assets/FilesView-CdWzeOp9.js +17 -0
  31. package/dist/assets/GitView-VQQkYuUw.js +6 -0
  32. package/dist/assets/{JsonTreeView-B0BdZEHG.js → JsonTreeView-6lrhwD3q.js} +1 -1
  33. package/dist/assets/LinearIssuesView-Ba6Q9569.js +1 -0
  34. package/dist/assets/{MarkdownImageGallery-ClOvuZxC.js → MarkdownImageGallery-Czv_mhvS.js} +1 -1
  35. package/dist/assets/MarkdownRendererImpl-BrMcswiy.js +12 -0
  36. package/dist/assets/{OnboardingScreen-D2DG7K6b.js → OnboardingScreen-ChxQoAkx.js} +1 -1
  37. package/dist/assets/{PatchDiff-DvfqDql7.js → PatchDiff-BzcZPlOq.js} +1 -1
  38. package/dist/assets/{PierreDiffViewer-B7m3f0d7.js → PierreDiffViewer-BchBtZlp.js} +2 -2
  39. package/dist/assets/PlanView-DyDt_nZ_.js +5 -0
  40. package/dist/assets/SettingsView-BKf5xBsP.js +28 -0
  41. package/dist/assets/{SettingsWindow-i45U1Cy1.js → SettingsWindow-DDQYaKWQ.js} +1 -1
  42. package/dist/assets/{ToolOutputDialog-BTwyh5OF.js → ToolOutputDialog-iYF8Y2bz.js} +6 -6
  43. package/dist/assets/ToolPartDiffPreview-CdjbOVMM.js +8 -0
  44. package/dist/assets/{VirtualizedFileDiff-DD8lDVej.js → VirtualizedFileDiff-fFFm2QgH.js} +1 -1
  45. package/dist/assets/{WalkthroughView-egQgxel3.js → WalkthroughView-DOeCsMju.js} +2 -2
  46. package/dist/assets/{computeVirtualFileMetrics-BMIRgMHv.js → computeVirtualFileMetrics-CzgLum_K.js} +2 -2
  47. package/dist/assets/{contextPanelEmbeddedChat-C3fjDbdg.js → contextPanelEmbeddedChat-C0ZLAepL.js} +1 -1
  48. package/dist/assets/{de-C1P6X5Rs.js → de-B5JaA3SA.js} +6 -5
  49. package/dist/assets/{es-CDgaF1_t.js → es-EPIH88ii.js} +6 -5
  50. package/dist/assets/{fr-Bgxqvvz_.js → fr-CAMfxUdZ.js} +6 -5
  51. package/dist/assets/{index-CODwDsU_.js → index-Bl3LSbjn.js} +1 -1
  52. package/dist/assets/index-DF5kMP-i.js +39 -0
  53. package/dist/assets/index-Dl3xbAB_.css +1 -0
  54. package/dist/assets/{isDiffPlainText-BqayB8d3.js → isDiffPlainText-Dx-dB_8l.js} +1 -1
  55. package/dist/assets/{isFilePlainText-QfoiKJNY.js → isFilePlainText-CWFPwmnU.js} +1 -1
  56. package/dist/assets/{ja-BDRrEcNP.js → ja-CifOE1VN.js} +7 -6
  57. package/dist/assets/{ko-Ba8sQV79.js → ko-BBDyAyYQ.js} +7 -6
  58. package/dist/assets/{main-C5DVOxc6.js → main-DnBAoktx.js} +2 -2
  59. package/dist/assets/main-MhSaOZoB.js +930 -0
  60. package/dist/assets/{markdownCore-CZwzz5gw.js → markdownCore-BrBwOOMn.js} +2 -2
  61. package/dist/assets/{miniChat-DUJ4irZc.js → miniChat-BKyvLseN.js} +2 -2
  62. package/dist/assets/{mobile-CcaxB0n4.js → mobile-DKjeFgMN.js} +2 -2
  63. package/dist/assets/{patchFileDiff-yNfWXN4E.js → patchFileDiff-o8ms1me8.js} +1 -1
  64. package/dist/assets/pl-DgEHYfFM.js +16 -0
  65. package/dist/assets/{pt-BR-DIs6ElwV.js → pt-BR-DuWHojUw.js} +6 -5
  66. package/dist/assets/{renderElectronMiniChatApp-BcKLHXKe.js → renderElectronMiniChatApp-CDgBwwCS.js} +2 -2
  67. package/dist/assets/renderMobileApp-DJIKIK1r.js +25 -0
  68. package/dist/assets/runtimeEndpointReset-CYJ9O_xX.js +17 -0
  69. package/dist/assets/{scheduledTasksApi-DLW0mkQK.js → scheduledTasksApi-D8yamh1b.js} +1 -1
  70. package/dist/assets/{shikiHighlight-DYOWuY65.js → shikiHighlight-TEQCmzW8.js} +1 -1
  71. package/dist/assets/tr-D5m2yIWL.js +7 -0
  72. package/dist/assets/{uk-ZrCNjM7Y.js → uk-D_q60oog.js} +6 -5
  73. package/dist/assets/{useAppFontEffects-CjrntdL0.js → useAppFontEffects-D7sNpuL2.js} +161 -190
  74. package/dist/assets/useInlineCommentController-Brz_cLcQ.js +2 -0
  75. package/dist/assets/{useRootScrollLock-BHYPkrLv.js → useRootScrollLock-lXEnWlaU.js} +1 -1
  76. package/dist/assets/{vendor-codemirror-language-data-DFZik9R2.js → vendor-codemirror-language-data-Dp3KMRQG.js} +2 -2
  77. package/dist/assets/vendor-zod-CK21ihK-.js +39 -0
  78. package/dist/assets/{web-components-Bhg83tjf.js → web-components-_mNEMjFY.js} +1 -1
  79. package/dist/assets/{zh-CN-iv_AV4EC.js → zh-CN-D8QvsVeg.js} +6 -5
  80. package/dist/assets/{zh-TW-CzEUk38j.js → zh-TW-B9t7rQQO.js} +6 -5
  81. package/dist/index.html +22 -22
  82. package/dist/mini-chat.html +7 -7
  83. package/dist/mobile.html +5 -5
  84. package/package.json +3 -3
  85. package/server/index.js +118 -85
  86. package/server/lib/agent-memory/actions.js +2 -2
  87. package/server/lib/agent-memory/feature-flag.js +1 -1
  88. package/server/lib/agent-memory/feature-flag.test.js +8 -8
  89. package/server/lib/agent-memory/routes.js +2 -2
  90. package/server/lib/agent-tool/runtime.js +37 -54
  91. package/server/lib/agent-tool/runtime.test.js +59 -59
  92. package/server/lib/browser-control/broker.js +3 -3
  93. package/server/lib/browser-control/broker.test.js +1 -1
  94. package/server/lib/changelog/update-notes.js +82 -0
  95. package/server/lib/changelog/update-notes.test.js +59 -0
  96. package/server/lib/client-auth/remote-clients.test.js +5 -5
  97. package/server/lib/context-obligatory/runtime.js +7 -7
  98. package/server/lib/context-obligatory/runtime.test.js +5 -5
  99. package/server/lib/dev-servers/parse.js +2 -2
  100. package/server/lib/dev-servers/parse.test.js +2 -2
  101. package/server/lib/dev-servers/routes.js +1 -1
  102. package/server/lib/dev-tunnel/DOCUMENTATION.md +13 -4
  103. package/server/lib/dev-tunnel/client.js +1 -1
  104. package/server/lib/dev-tunnel/runtime.js +5 -5
  105. package/server/lib/dev-tunnel/tunnel.test.js +21 -1
  106. package/server/lib/dictation/local/model-catalog.js +1 -1
  107. package/server/lib/dictation/local/worker-process.js +2 -2
  108. package/server/lib/event-stream/directory-ws-bridge.js +1 -1
  109. package/server/lib/event-stream/global-ws-bridge.js +1 -1
  110. package/server/lib/event-stream/protocol.test.js +4 -4
  111. package/server/lib/event-stream/runtime.test.js +6 -6
  112. package/server/lib/fs/DOCUMENTATION.md +2 -0
  113. package/server/lib/fs/routes.js +37 -26
  114. package/server/lib/fs/routes.test.js +98 -21
  115. package/server/lib/git/DOCUMENTATION.md +3 -1
  116. package/server/lib/git/identity-storage.js +1 -1
  117. package/server/lib/git/issue-2746-longpaths.test.js +4 -4
  118. package/server/lib/git/routes.js +17 -1
  119. package/server/lib/git/service.js +116 -26
  120. package/server/lib/git/service.test.js +174 -3
  121. package/server/lib/github/auth.js +8 -8
  122. package/server/lib/github/pr-status.js +1 -1
  123. package/server/lib/github/routes.js +2 -2
  124. package/server/lib/inherited-env.js +1 -1
  125. package/server/lib/inherited-env.test.js +2 -2
  126. package/server/lib/linear/auth.js +8 -8
  127. package/server/lib/linear/auth.test.js +24 -24
  128. package/server/lib/linear/issues.test.js +6 -6
  129. package/server/lib/linear/mapping.test.js +4 -4
  130. package/server/lib/linear/oauth.js +2 -2
  131. package/server/lib/linear/oauth.test.js +14 -14
  132. package/server/lib/linear/routes.js +5 -5
  133. package/server/lib/linear/routes.test.js +16 -16
  134. package/server/lib/linear/status-runtime.test.js +9 -9
  135. package/server/lib/linear/status.js +1 -1
  136. package/server/lib/linear/status.test.js +15 -15
  137. package/server/lib/linear/teams.test.js +4 -4
  138. package/server/lib/magic-prompts/routes.js +2 -2
  139. package/server/lib/mcp-reconnect/DOCUMENTATION.md +55 -0
  140. package/server/lib/mcp-reconnect/runtime.js +122 -0
  141. package/server/lib/mcp-reconnect/runtime.test.js +140 -0
  142. package/server/lib/message-queue/DOCUMENTATION.md +158 -0
  143. package/server/lib/message-queue/runtime.js +870 -0
  144. package/server/lib/message-queue/runtime.test.js +482 -0
  145. package/server/lib/notifications/apns-runtime.js +17 -17
  146. package/server/lib/notifications/apns-runtime.test.js +11 -11
  147. package/server/lib/notifications/emitter-runtime.js +1 -1
  148. package/server/lib/notifications/emitter-runtime.test.js +1 -1
  149. package/server/lib/notifications/push-runtime.js +7 -7
  150. package/server/lib/notifications/routes.js +1 -1
  151. package/server/lib/notifications/runtime.js +1 -1
  152. package/server/lib/openchamber-control/action-resolution.test.js +10 -10
  153. package/server/lib/openchamber-control/actions.js +24 -24
  154. package/server/lib/openchamber-control/error.js +4 -4
  155. package/server/lib/openchamber-control/routes.js +2 -2
  156. package/server/lib/openchamber-control/routes.test.js +5 -5
  157. package/server/lib/openchamber-control/screenshots.js +1 -1
  158. package/server/lib/openchamber-control/screenshots.test.js +1 -1
  159. package/server/lib/openchamber-control/service.js +50 -50
  160. package/server/lib/openchamber-control/service.test.js +5 -5
  161. package/server/lib/openchamber-sessions/routes.js +124 -22
  162. package/server/lib/openchamber-sessions/routes.test.js +99 -11
  163. package/server/lib/opencode/DOCUMENTATION.md +13 -5
  164. package/server/lib/opencode/auth.js +1 -1
  165. package/server/lib/opencode/bootstrap-runtime.js +6 -6
  166. package/server/lib/opencode/cli-options.js +8 -8
  167. package/server/lib/opencode/config-paths.test.js +116 -0
  168. package/server/lib/opencode/core-routes.js +8 -7
  169. package/server/lib/opencode/core-routes.test.js +11 -11
  170. package/server/lib/opencode/env-config.js +5 -5
  171. package/server/lib/opencode/env-config.test.js +7 -7
  172. package/server/lib/opencode/env-runtime.js +10 -10
  173. package/server/lib/opencode/env-runtime.test.js +18 -18
  174. package/server/lib/opencode/feature-routes-runtime.js +17 -12
  175. package/server/lib/opencode/hmr-state-runtime.js +2 -2
  176. package/server/lib/opencode/hmr-state-runtime.test.js +1 -1
  177. package/server/lib/opencode/input-history-scope.js +14 -0
  178. package/server/lib/opencode/lifecycle.js +8 -8
  179. package/server/lib/opencode/lifecycle.test.js +4 -4
  180. package/server/lib/opencode/managed-plugin-config.js +35 -0
  181. package/server/lib/opencode/managed-process-registry.js +3 -3
  182. package/server/lib/opencode/mcp-oauth-callback.test.js +2 -2
  183. package/server/lib/opencode/openchamber-routes.js +15 -15
  184. package/server/lib/opencode/openchamber-routes.test.js +11 -11
  185. package/server/lib/opencode/plugins.js +2 -2
  186. package/server/lib/opencode/plugins.test.js +1 -1
  187. package/server/lib/opencode/project-icon-routes.js +2 -2
  188. package/server/lib/opencode/project-icon-routes.test.js +1 -1
  189. package/server/lib/opencode/providers.js +44 -2
  190. package/server/lib/opencode/providers.test.js +131 -4
  191. package/server/lib/opencode/proxy.js +2 -2
  192. package/server/lib/opencode/pwa-manifest-routes.js +1 -1
  193. package/server/lib/opencode/restart-session-recovery.test.js +1 -1
  194. package/server/lib/opencode/routes-upgrade.test.js +4 -4
  195. package/server/lib/opencode/routes.js +14 -14
  196. package/server/lib/opencode/server-startup-runtime.js +6 -6
  197. package/server/lib/opencode/session-runtime.js +3 -3
  198. package/server/lib/opencode/session-runtime.test.js +6 -6
  199. package/server/lib/opencode/settings-helpers.js +31 -3
  200. package/server/lib/opencode/settings-helpers.test.js +189 -12
  201. package/server/lib/opencode/settings-runtime.js +2 -2
  202. package/server/lib/opencode/settings-runtime.test.js +29 -0
  203. package/server/lib/opencode/shared.js +5 -2
  204. package/server/lib/opencode/shared.test.js +7 -7
  205. package/server/lib/opencode/shutdown-runtime.js +2 -0
  206. package/server/lib/opencode/skill-routes.js +2 -1
  207. package/server/lib/opencode/snippets.js +1 -2
  208. package/server/lib/opencode/startup-performance.js +1 -1
  209. package/server/lib/opencode/startup-performance.test.js +6 -6
  210. package/server/lib/opencode/static-routes-runtime.js +8 -8
  211. package/server/lib/opencode/static-routes-runtime.test.js +7 -7
  212. package/server/lib/opencode/upgrade-capability.js +2 -2
  213. package/server/lib/opencode/upgrade-capability.test.js +3 -3
  214. package/server/lib/package-manager.js +17 -42
  215. package/server/lib/package-manager.test.js +19 -19
  216. package/server/lib/permission-auto-accept/runtime.js +1 -1
  217. package/server/lib/project-context/routes.js +1 -1
  218. package/server/lib/projects/project-config.js +2 -2
  219. package/server/lib/quota/DOCUMENTATION.md +9 -1
  220. package/server/lib/quota/credentials/providers.js +4 -0
  221. package/server/lib/quota/credentials/store.js +4 -4
  222. package/server/lib/quota/credentials/store.test.js +8 -8
  223. package/server/lib/quota/index.js +1 -0
  224. package/server/lib/quota/providers/exe-dev.js +75 -0
  225. package/server/lib/quota/providers/exe-dev.test.js +47 -0
  226. package/server/lib/quota/providers/hyper.js +118 -0
  227. package/server/lib/quota/providers/hyper.test.js +126 -0
  228. package/server/lib/quota/providers/index.js +15 -0
  229. package/server/lib/quota/providers/ollama-cloud.js +1 -1
  230. package/server/lib/quota/providers/opencode-go.js +2 -1
  231. package/server/lib/quota/providers/opencode-go.test.js +9 -5
  232. package/server/lib/quota/providers/xai.js +1 -1
  233. package/server/lib/quota/routes.js +2 -0
  234. package/server/lib/quota/utils/auth.js +1 -1
  235. package/server/lib/relay/DOCUMENTATION.md +1 -1
  236. package/server/lib/relay/host-client.js +1 -1
  237. package/server/lib/relay/host-client.test.js +9 -1
  238. package/server/lib/relay/host-lock.js +1 -1
  239. package/server/lib/relay/service.js +5 -5
  240. package/server/lib/relay/tunnel-host.js +3 -1
  241. package/server/lib/relay/tunnel-host.test.js +9 -1
  242. package/server/lib/scheduled-tasks/issue-2710-double-execution.test.js +2 -2
  243. package/server/lib/scheduled-tasks/routes.js +5 -5
  244. package/server/lib/scheduled-tasks/service.js +25 -25
  245. package/server/lib/scheduled-tasks/service.test.js +1 -1
  246. package/server/lib/security/bind-host.js +4 -4
  247. package/server/lib/security/bind-host.test.js +1 -1
  248. package/server/lib/security/request-security.js +11 -5
  249. package/server/lib/security/request-security.test.js +14 -14
  250. package/server/lib/session-assist/runtime.js +10 -9
  251. package/server/lib/session-folders/routes.js +2 -2
  252. package/server/lib/session-folders/routes.test.js +8 -8
  253. package/server/lib/session-goal/DOCUMENTATION.md +20 -7
  254. package/server/lib/session-goal/create.js +4 -2
  255. package/server/lib/session-goal/create.test.js +1 -1
  256. package/server/lib/session-goal/objectives.js +4 -4
  257. package/server/lib/session-goal/routes.js +1 -1
  258. package/server/lib/session-goal/runtime.js +88 -22
  259. package/server/lib/session-goal/runtime.test.js +428 -2
  260. package/server/lib/session-knowledge/runtime.js +11 -11
  261. package/server/lib/session-knowledge/runtime.test.js +5 -5
  262. package/server/lib/skills-catalog/DOCUMENTATION.md +1 -1
  263. package/server/lib/skills-catalog/cache.test.js +2 -2
  264. package/server/lib/skills-catalog/disk-cache.js +5 -5
  265. package/server/lib/skills-catalog/github-meta.test.js +2 -2
  266. package/server/lib/skills-catalog/install.js +3 -2
  267. package/server/lib/small-model/DOCUMENTATION.md +4 -0
  268. package/server/lib/small-model/call.js +9 -3
  269. package/server/lib/small-model/call.test.js +29 -6
  270. package/server/lib/small-model/index.js +8 -7
  271. package/server/lib/small-model/index.test.js +1 -1
  272. package/server/lib/small-model/resolve.js +1 -1
  273. package/server/lib/small-model/resolve.test.js +1 -1
  274. package/server/lib/small-model/routes.js +2 -1
  275. package/server/lib/system-prompt/runtime.js +3 -22
  276. package/server/lib/system-prompt/runtime.test.js +3 -3
  277. package/server/lib/terminal/DOCUMENTATION.md +11 -7
  278. package/server/lib/terminal/runtime.js +180 -26
  279. package/server/lib/terminal/runtime.test.js +554 -27
  280. package/server/lib/terminal/shells.js +20 -3
  281. package/server/lib/terminal/shells.test.js +33 -2
  282. package/server/lib/tts/base-url.js +3 -3
  283. package/server/lib/tts/routes.test.js +20 -20
  284. package/server/lib/ui-auth/ui-auth.js +12 -9
  285. package/server/lib/ui-auth/ui-auth.test.js +19 -3
  286. package/server/lib/ui-auth/ui-passkeys.js +7 -7
  287. package/server/lib/walkthrough/index.js +1 -0
  288. package/server/lib/walkthrough/jobs.test.js +1 -1
  289. package/server/lib/walkthrough/language.test.js +1 -1
  290. package/server/lib/walkthrough/model-settings.js +3 -3
  291. package/server/lib/walkthrough/model-settings.test.js +1 -1
  292. package/server/lib/walkthrough/pull-request.test.js +5 -5
  293. package/server/lib/walkthrough/reproduce-2607.test.js +2 -2
  294. package/server/lib/walkthrough/routes.test.js +26 -5
  295. package/server/lib/walkthrough/store.js +3 -3
  296. package/server/lib/walkthrough/store.test.js +1 -1
  297. package/server/opencode-proxy.test.js +2 -2
  298. package/server/proxy-headers.js +1 -1
  299. package/server/sse-routes.test.js +4 -4
  300. package/README.md.bak +0 -250
  301. package/bin/lib/DOCUMENTATION.md.bak +0 -163
  302. package/dist/assets/CommitSection-SGBCAW0w.js +0 -1
  303. package/dist/assets/FilesView-Bdq8ppva.js +0 -17
  304. package/dist/assets/GitView-Znn7VJcP.js +0 -6
  305. package/dist/assets/LinearIssuesView-jP-hXyac.js +0 -1
  306. package/dist/assets/MarkdownRendererImpl-Dt9mjTRN.js +0 -12
  307. package/dist/assets/PlanView-B0F3BtPZ.js +0 -5
  308. package/dist/assets/SettingsView-BBW-S-gh.js +0 -28
  309. package/dist/assets/ToolPartDiffPreview-CUNe28U1.js +0 -8
  310. package/dist/assets/index-C57jT0Sa.css +0 -1
  311. package/dist/assets/index-DW_E3rnL.js +0 -7
  312. package/dist/assets/main-Bv5Pkngh.js +0 -928
  313. package/dist/assets/pl-Dioz29BI.js +0 -15
  314. package/dist/assets/renderMobileApp-D9yQJy0L.js +0 -25
  315. package/dist/assets/runtimeEndpointReset-CjhvxLH0.js +0 -16
  316. package/dist/assets/tr-DFnMlPxY.js +0 -6
  317. package/dist/assets/useInlineCommentController-CDEuSlPH.js +0 -2
  318. package/dist/assets/vendor-zod-BLfBSgBh.js +0 -39
  319. package/server/index.d.ts.bak +0 -39
  320. package/server/lib/agent-tool/DOCUMENTATION.md.bak +0 -119
  321. package/server/lib/browser-control/DOCUMENTATION.md.bak +0 -50
  322. package/server/lib/context-obligatory/DOCUMENTATION.md.bak +0 -19
  323. package/server/lib/dev-tunnel/DOCUMENTATION.md.bak +0 -57
  324. package/server/lib/dictation/DOCUMENTATION.md.bak +0 -100
  325. package/server/lib/event-stream/DOCUMENTATION.md.bak +0 -62
  326. package/server/lib/fs/DOCUMENTATION.md.bak +0 -47
  327. package/server/lib/git/DOCUMENTATION.md.bak +0 -193
  328. package/server/lib/github/DOCUMENTATION.md.bak +0 -183
  329. package/server/lib/linear/DOCUMENTATION.md.bak +0 -97
  330. package/server/lib/linear/OAUTH-BROKER-HANDOFF.md.bak +0 -91
  331. package/server/lib/markdown-image-grants/DOCUMENTATION.md.bak +0 -40
  332. package/server/lib/notifications/APNS.md.bak +0 -135
  333. package/server/lib/notifications/DOCUMENTATION.md.bak +0 -138
  334. package/server/lib/openchamber-control/DOCUMENTATION.md.bak +0 -64
  335. package/server/lib/opencode/DOCUMENTATION.md.bak +0 -431
  336. package/server/lib/opencode/managed-process-registry.d.ts.bak +0 -13
  337. package/server/lib/opencode/provider-env-aliases.d.ts.bak +0 -3
  338. package/server/lib/permission-auto-accept/DOCUMENTATION.md.bak +0 -34
  339. package/server/lib/project-context/DOCUMENTATION.md.bak +0 -160
  340. package/server/lib/quota/DOCUMENTATION.md.bak +0 -123
  341. package/server/lib/relay/DOCUMENTATION.md.bak +0 -100
  342. package/server/lib/scheduled-tasks/DOCUMENTATION.md.bak +0 -182
  343. package/server/lib/session-assist/DOCUMENTATION.md.bak +0 -66
  344. package/server/lib/session-goal/DOCUMENTATION.md.bak +0 -213
  345. package/server/lib/session-knowledge/DOCUMENTATION.md.bak +0 -89
  346. package/server/lib/skills-catalog/DOCUMENTATION.md.bak +0 -151
  347. package/server/lib/small-model/DOCUMENTATION.md.bak +0 -212
  348. package/server/lib/system-prompt/DOCUMENTATION.md.bak +0 -36
  349. package/server/lib/terminal/DOCUMENTATION.md.bak +0 -50
  350. package/server/lib/text/DOCUMENTATION.md.bak +0 -35
  351. package/server/lib/tts/DOCUMENTATION.md.bak +0 -147
  352. package/server/lib/tunnels/DOCUMENTATION.md.bak +0 -21
  353. package/server/lib/ui-auth/DOCUMENTATION.md.bak +0 -44
  354. package/server/lib/walkthrough/DOCUMENTATION.md.bak +0 -411
@@ -1,28 +0,0 @@
1
- import{R as o,j as s,f as mt,r as qe}from"./vendor-react-BUCujlKS.js";import{f as at,B,I as O,o as yn,b5 as ma,t as M,O as ac,fG as ic,er as _e,fH as Et,b as Vs,h as we,fI as rc,b1 as sn,b3 as nn,fJ as oc,b4 as an,ei as Bn,fK as ol,fL as lc,fM as la,fN as on,c2 as Bs,bG as Ft,bH as Kt,bI as Ut,bJ as _t,bK as $t,bL as es,S as Je,fO as za,b0 as rn,e6 as Zi,fP as cc,fQ as zn,et as Jt,fR as qs,l as Ze,eG as Ot,bU as Pt,bV as It,eD as Lt,bW as Rt,bX as At,bY as ot,fS as qt,bZ as Is,dt as Oa,eF as Mn,eI as da,eH as en,fT as fs,dy as Ss,fU as Ps,fV as dc,cm as gt,fW as ll,fX as uc,fY as $n,fZ as cl,f_ as pc,f$ as ua,g0 as $s,g1 as ca,g2 as dl,g3 as pr,du as ul,g4 as vn,a5 as pa,a4 as Os,g5 as pl,g6 as Ar,aa as mc,e4 as ml,g as La,g7 as gc,g8 as Js,e3 as fc,g9 as hc,ga as xc,gb as mr,a6 as gr,a7 as fr,a8 as gl,gc as fn,a0 as gi,bd as hr,L as xr,gd as Tr,am as vc,b_ as yc,cC as bc,Q as wc,N as jc,R as kc,V as fl,ge as Nc,gf as Sc,bR as Cc,b$ as Xi,gg as hl,a9 as li,gh as xl,P as Un,gi as Ws,eq as zs,eb as vl,$ as Pc,n as ss,d_ as fi,x as yl,w as Ic,i as Ac,j as Tc,d$ as Ec,p as Dc,gj as Mc,gk as Rc,gl as Er,dz as bl,gm as Oc,gn as Mi,go as Dr,gp as Lc,gq as Fc,gr as Kc,gs as zc,dF as hi,gt as hs,gu as Ls,gv as mn,gw as gn,at as Dn,au as ia,gx as En,gy as Cn,gz as Ua,gA as Mr,gB as ja,gC as ka,bD as Hn,gD as Uc,gE as _c,gF as $c,gG as Vc,gH as Ri,gI as Rr,gJ as Bc,gK as Hc,gL as Gc,gM as Wc,gN as Or,y as qc,m as Lr,cQ as Jc,gO as Qc,gP as Oi,gQ as Fr,e1 as Yc,gR as vi,gS as Zc,gT as Xc,gU as ed,gV as td,gW as sd,gX as Li,cn as nd,bE as wl,gY as jl,gZ as ad,ao as Pn,aq as id}from"./useAppFontEffects-CjrntdL0.js";import{r as pt,u as de,F as us,cG as rd,cH as Kr,w as hn,aq as xn,X as od,a0 as yt,o as tn,z as os,K as zr,c7 as Ur,ca as _r,L as Na,p as ld,cI as cd,j as dd,c6 as oa,cJ as ud,a9 as pd,c9 as md,cK as gd,cL as fd,s as hd,e as _a,c8 as xd,A as $a,cM as kl,T as vd,cN as yd,cx as bd,S as wd,aH as $r,ax as jd,$ as Vn,cO as kd,v as Nl,cP as Vr,cF as Br,cQ as Hr,av as Gr,cR as Nd,cS as Sd,cT as Wr,b as Cd,at as Sl,cU as Cl,cV as Pd,cW as Id,cX as Ad,cY as Td,cZ as Ed,c_ as Dd,ak as Md,i as Pl}from"./index-DW_E3rnL.js";import{u as Rd,U as qr,y as Gn,A as Wn,B as qn,E as Jn,d as vr,v as bn,x as wn,w as jn,X as _n,H as Od,j as Cs,R as Ld,Y as Ma,Z as Il,F as Fd,G as Kd}from"./runtimeEndpointReset-CjhvxLH0.js";import{u as Ds,c as Al,d as zd,p as Ud}from"./vendor-zustand-BAGL70zf.js";import{s as _d,p as $d}from"./vendor-yaml-3778uTud.js";import{c as Jr,s as Vd,C as Qr,P as Bd}from"./shikiHighlight-DYOWuY65.js";import{getResolvedShikiTheme as Hd}from"./appThemeRegistry-BK0dHKa6.js";import{E as Yr}from"./vendor-codemirror-view-CiLROUVV.js";import{Q as Tl}from"./vendor-qrcode-DTJ12-WC.js";const Zr=()=>{const{t}=at(),[e,a]=o.useState(null);o.useEffect(()=>{let i=!1;const r=typeof AbortController<"u"?new AbortController:void 0;return(async()=>{try{const u=await pt("/api/system/info",{signal:r?.signal,headers:{Accept:"application/json"}});if(!u.ok)return;const p=await u.json().catch(()=>null);if(!p||i)return;const h=typeof p.port=="number"&&Number.isFinite(p.port)&&p.port>0?p.port:null,d=typeof p.tunnelUrl=="string"&&p.tunnelUrl.trim().length>0?p.tunnelUrl.trim():null;a({port:h,tunnelUrl:d})}catch{}})(),()=>{i=!0,r?.abort()}},[]);const n=[];return e?.port!==null&&e?.port!==void 0&&n.push({key:"application",label:t("settings.aiworker.about.field.applicationUrl"),url:`http://localhost:${e.port}/`}),e?.tunnelUrl&&n.push({key:"tunnel",label:t("settings.aiworker.about.field.tunnelUrl"),url:e.tunnelUrl}),n.length===0?null:s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:n.map(i=>s.jsxs(B,{type:"button",variant:"outline",size:"sm",title:i.label,className:"max-w-full gap-1.5 px-2.5",onClick:()=>{yn(i.url)},children:[s.jsx(O,{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))})},Xr="https://github.com/openchamber/openchamber",Gd="https://discord.gg/ZYRSdnwwKA",eo="https://x.com/openchamber_dev",Wd=800,El=({initialUpdateDialogOpen:t=!1})=>{const{t:e}=at(),[a,n]=o.useState(t),[i,r]=o.useState(!1),[l,u]=o.useState(null),[p,h]=o.useState(null),d=Rd(Ds(C=>({info:C.info,checking:C.checking,available:C.available,error:C.error,downloading:C.downloading,downloaded:C.downloaded,progress:C.progress,runtimeType:C.runtimeType,checkForUpdates:C.checkForUpdates,downloadUpdate:C.downloadUpdate,restartToUpdate:C.restartToUpdate}))),{isMobile:w}=ma(),c=l||d.info?.currentVersion||"unknown";o.useEffect(()=>{let C=!1;return(async()=>{try{const S=await pt("/api/system/info",{method:"GET",headers:{Accept:"application/json"}});if(!S.ok)return;const g=await S.json().catch(()=>null),T=typeof g?.aiworkerVersion=="string"&&g.aiworkerVersion.trim().length>0?g.aiworkerVersion.trim():null;C||u(T)}catch{C||u(null)}})(),()=>{C=!0}},[]),o.useEffect(()=>{let C=!1;return(async()=>{try{const S=await pt("/api/opencode/upgrade-status",{method:"GET",headers:{Accept:"application/json"}});if(!S.ok)return;const g=await S.json().catch(()=>null),T=typeof g?.currentVersion=="string"&&g.currentVersion.trim().length>0?g.currentVersion.trim():null;C||h(T)}catch{C||h(null)}})(),()=>{C=!0}},[]);const N=o.useRef(!1);o.useEffect(()=>{if(d.checking)r(!0),N.current=!0;else if(i){const C=setTimeout(()=>{r(!1),N.current&&!d.available&&!d.error&&(M.success(e("settings.aiworker.about.toast.latestVersion")),N.current=!1)},Wd);return()=>clearTimeout(C)}},[e,d.checking,i,d.available,d.error]);const v=d.checking||i;return w?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(ac,{width:72,height:72}),s.jsx("h2",{className:`mt-4 ${ic}`,children:"AiWorker"}),s.jsxs("div",{className:"mt-2 space-y-1 typography-ui text-muted-foreground",children:[s.jsx("p",{children:e("aboutDialog.openChamberVersionLabel",{version:c})}),s.jsx("p",{children:e("aboutDialog.openCodeVersionLabel",{version:p||e("settings.aiworker.about.state.unknown")})})]}),s.jsx(Zr,{})]}),s.jsxs("div",{className:"flex justify-center",children:[!d.available&&!d.error&&s.jsxs(B,{type:"button",variant:"outline",size:"sm",onClick:()=>d.checkForUpdates(),disabled:v,className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[v?s.jsx(O,{name:"loader",className:"size-4 animate-spin"}):s.jsx(O,{name:"refresh",className:"size-4"}),e(v?"settings.aiworker.about.state.checking":"settings.aiworker.about.actions.checkForUpdates")]}),!v&&d.available&&s.jsxs(B,{type:"button",variant:"default",size:"sm",onClick:()=>n(!0),className:"h-10 w-auto justify-center gap-2 rounded-xl px-4",children:[s.jsx(O,{name:"download",className:"size-4"}),e("settings.aiworker.about.actions.updateToVersion",{version:d.info?.version||""})]})]}),d.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:d.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:Xr,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(O,{name:"github-fill",className:"size-5"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:Gd,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(O,{name:"discord-fill",className:"size-5"}),s.jsx("span",{children:"Discord"})]})]}),s.jsxs("a",{href:eo,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(O,{name:"twitter-xfill",className:"size-5"}),s.jsx("span",{children:"@aiworker_dev"})]})]}),s.jsx("p",{className:"text-center typography-ui text-muted-foreground/60",children:e("aboutDialog.footerNote")}),s.jsx(qr,{open:a,onOpenChange:n,info:d.info,downloading:d.downloading,downloaded:d.downloaded,progress:d.progress,error:d.error,onDownload:d.downloadUpdate,onRestart:d.restartToUpdate,runtimeType:d.runtimeType})]}):s.jsxs(_e,{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:Et,children:e("settings.aiworker.about.field.version")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:c})]}),s.jsxs("div",{className:"flex min-w-0 flex-col",children:[s.jsx("span",{className:Et,children:e("settings.aiworker.about.field.openCodeVersion")}),s.jsx("span",{className:"typography-meta text-muted-foreground font-mono",children:p||e("settings.aiworker.about.state.unknown")})]}),s.jsxs("div",{className:"flex items-center gap-3",children:[d.checking&&s.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[s.jsx(O,{name:"loader",className:"h-4 w-4 animate-spin"}),s.jsx("span",{className:"typography-meta",children:e("settings.aiworker.about.state.checking")})]}),!d.checking&&d.available&&s.jsxs(B,{size:"sm",variant:"default",onClick:()=>n(!0),children:[s.jsx(O,{name:"download",className:"h-4 w-4 mr-1"}),e("settings.aiworker.about.actions.updateToVersion",{version:d.info?.version||""})]}),!d.checking&&!d.available&&!d.error&&s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.aiworker.about.state.upToDate")}),s.jsx(B,{size:"sm",variant:"outline",onClick:()=>d.checkForUpdates(),disabled:d.checking,children:e("settings.aiworker.about.actions.checkForUpdates")})]})]}),d.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:d.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:Et,children:e("settings.aiworker.about.field.instanceUrls")}),s.jsx(Zr,{})]}),s.jsxs("div",{className:"flex items-center gap-4 px-4 py-4",children:[s.jsxs("a",{href:Xr,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(O,{name:"github-fill",className:"h-4 w-4"}),s.jsx("span",{children:"GitHub"})]}),s.jsxs("a",{href:eo,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(O,{name:"twitter-xfill",className:"h-4 w-4"}),s.jsx("span",{children:"@aiworker_dev"})]})]})]}),s.jsx(qr,{open:a,onOpenChange:n,info:d.info,downloading:d.downloading,downloaded:d.downloaded,progress:d.progress,error:d.error,onDownload:d.downloadUpdate,onRestart:d.restartToUpdate,runtimeType:d.runtimeType})]})},qd=(t,e,a)=>t&&e.some(i=>i.path===t)?t:(e.find(i=>i.id===a)??e[0])?.path??null,Us=()=>{const t=mt.c(4),e=de(Jd),a=Vs(Qd),n=Vs(Yd);let i;return t[0]!==n||t[1]!==a||t[2]!==e?(i=qd(e,a,n),t[0]=n,t[1]=a,t[2]=e,t[3]=i):i=t[3],i};function Jd(t){return t.settingsProjectPath}function Qd(t){return t.projects}function Yd(t){return t.activeProjectId}const Dl=t=>t.trim(),Va=t=>{const e=mt.c(40),{className:a}=t,{t:n}=at(),i=Vs(Zd),r=Us(),l=de(Xd),u=us();let p;e[0]!==i?(p=[...i].sort(eu),e[0]=i,e[1]=p):p=e[1];const h=p;let d;e:{if(h.length===0){d=null;break e}let q;e[2]!==r||e[3]!==h?(q=h.find(k=>k.path===r)??h[0],e[2]=r,e[3]=h,e[4]=q):q=e[4],d=q}const w=d;if(u||h.length===0)return null;let c;e[5]!==w||e[6]!==n?(c=w?.label&&w.label.trim().length>0?w.label:w?.path.split("/").filter(Boolean).pop()||w?.path||n("settings.shared.projectSelector.fallbackProject"),e[5]=w,e[6]=n,e[7]=c):c=e[7];const N=c;let v;e[8]!==N?(v=Dl(N),e[8]=N,e[9]=v):v=e[9];const C=v;let y;e[10]!==a?(y=we(a),e[10]=a,e[11]=y):y=e[11];let S;e[12]!==n?(S=n("settings.shared.projectSelector.switchProjectAria"),e[12]=n,e[13]=S):S=e[13];let g;e[14]!==n?(g=n("settings.shared.projectSelector.switchProjectTitle"),e[14]=n,e[15]=g):g=e[15];let T,R;e[16]===Symbol.for("react.memo_cache_sentinel")?(T=we("text-foreground border border-border/80 appearance-none flex h-8 w-full min-w-0 rounded-lg bg-transparent px-3 py-1 outline-none","hover:border-input focus-visible:ring-1 focus-visible:ring-primary/50 focus-visible:border-primary/70","flex items-center gap-1.5 text-left"),R=s.jsx(O,{name:"folder",className:"h-4 w-4 opacity-70"}),e[16]=T,e[17]=R):(T=e[16],R=e[17]);let A;e[18]!==C?(A=s.jsx("span",{className:"min-w-0 flex-1 truncate typography-ui-label font-medium",children:C}),e[18]=C,e[19]=A):A=e[19];let j;e[20]===Symbol.for("react.memo_cache_sentinel")?(j=s.jsx(O,{name:"arrow-down-s",className:"size-4 opacity-50"}),e[20]=j):j=e[20];let f;e[21]!==A||e[22]!==S||e[23]!==g?(f=s.jsx(sn,{asChild:!0,children:s.jsxs("button",{type:"button","aria-label":S,title:g,className:T,children:[R,A,j]})}),e[21]=A,e[22]=S,e[23]=g,e[24]=f):f=e[24];const b=w?.id??"";let F;e[25]!==l||e[26]!==h?(F=q=>{if(!q)return;const k=h.find($=>$.id===q);k&&l(k.path)},e[25]=l,e[26]=h,e[27]=F):F=e[27];let D;e[28]!==h?(D=h.map(tu),e[28]=h,e[29]=D):D=e[29];let P;e[30]!==b||e[31]!==F||e[32]!==D?(P=s.jsx(nn,{align:"start",className:"w-auto",children:s.jsx(oc,{value:b,onValueChange:F,children:D})}),e[30]=b,e[31]=F,e[32]=D,e[33]=P):P=e[33];let I;e[34]!==f||e[35]!==P?(I=s.jsxs(an,{children:[f,P]}),e[34]=f,e[35]=P,e[36]=I):I=e[36];let U;return e[37]!==I||e[38]!==y?(U=s.jsx("div",{className:y,children:I}),e[37]=I,e[38]=y,e[39]=U):U=e[39],U};function Zd(t){return t.projects}function Xd(t){return t.setSettingsProjectPath}function eu(t,e){return(t.label||t.path).localeCompare(e.label||e.path)}function tu(t){const e=t.label?.trim()?t.label.trim():t.path.split("/").filter(Boolean).pop()||t.path,a=Dl(e);return s.jsx(rc,{value:t.id,children:s.jsx("span",{className:"min-w-0 truncate typography-ui",children:a})},t.id)}function su(t,e){return`opencode:sidebar-group:${t}:${e}`}const er=t=>{const e=mt.c(33),{label:a,count:n,storageKey:i,defaultExpanded:r,children:l}=t,u=r===void 0?!0:r;let p;e[0]!==a||e[1]!==i?(p=su(i,a),e[0]=a,e[1]=i,e[2]=p):p=e[2];const h=p,d=o.useId();let w;e[3]!==u||e[4]!==h?(w=()=>{try{const P=localStorage.getItem(h);if(P!==null)return P==="true"}catch{}return u},e[3]=u,e[4]=h,e[5]=w):w=e[5];const[c,N]=qe.useState(w);let v,C;e[6]!==c||e[7]!==h?(v=()=>{try{localStorage.setItem(h,String(c))}catch{}},C=[h,c],e[6]=c,e[7]=h,e[8]=v,e[9]=C):(v=e[8],C=e[9]),qe.useEffect(v,C);let y;e[10]===Symbol.for("react.memo_cache_sentinel")?(y=()=>N(nu),e[10]=y):y=e[10];let S;e[11]===Symbol.for("react.memo_cache_sentinel")?(S=we("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-primary/50"),e[11]=S):S=e[11];const g=!c&&"-rotate-90";let T;e[12]!==g?(T=we("h-3.5 w-3.5 flex-shrink-0 transition-transform duration-200",g),e[12]=g,e[13]=T):T=e[13];let R;e[14]!==T?(R=s.jsx(O,{name:"arrow-down-s",className:T}),e[14]=T,e[15]=R):R=e[15];let A;e[16]!==a?(A=s.jsx("span",{className:"flex-1 truncate",children:a}),e[16]=a,e[17]=A):A=e[17];let j;e[18]!==n?(j=s.jsx("span",{className:"ml-1 tabular-nums opacity-60",children:n}),e[18]=n,e[19]=j):j=e[19];let f;e[20]!==d||e[21]!==c||e[22]!==R||e[23]!==A||e[24]!==j?(f=s.jsxs("button",{type:"button",onClick:y,"aria-expanded":c,"aria-controls":d,className:S,children:[R,A,j]}),e[20]=d,e[21]=c,e[22]=R,e[23]=A,e[24]=j,e[25]=f):f=e[25];const b=!c;let F;e[26]!==l||e[27]!==d||e[28]!==b?(F=s.jsx("div",{id:d,hidden:b,className:"mt-0.5 space-y-0.5 ml-2 pl-3 border-l-2 border-[var(--interactive-border)]",children:l}),e[26]=l,e[27]=d,e[28]=b,e[29]=F):F=e[29];let D;return e[30]!==f||e[31]!==F?(D=s.jsxs("div",{children:[f,F]}),e[30]=f,e[31]=F,e[32]=D):D=e[32],D};function nu(t){return!t}const au=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!a||typeof a!="object")continue;const n=a;typeof n.permission!="string"||typeof n.pattern!="string"||typeof n.action!="string"||n.action!=="allow"&&n.action!=="ask"&&n.action!=="deny"||e.push({permission:n.permission,pattern:n.pattern,action:n.action})}return e},iu=t=>{const e=new Map;for(const a of t)!a.permission||a.permission==="invalid"||a.pattern&&e.set(`${a.permission}::${a.pattern}`,a);return Array.from(e.values())},to=t=>{const e=iu(au(t));if(e.length===0)return;const a={};for(const i of e)i.permission&&((a[i.permission]||={})[i.pattern]=i.action);const n={};for(const[i,r]of Object.entries(a)){const l=Object.keys(r);if(l.length===1&&l[0]==="*"){n[i]=r["*"];continue}n[i]=r}return Object.keys(n).length>0?n:void 0},ru=({onItemSelect:t})=>{const{t:e}=at(),[a,n]=o.useState(null),[i,r]=o.useState(""),[l,u]=o.useState(null),[p,h]=o.useState(null),[d,w]=o.useState(!1),[c,N]=o.useState(null),{selectedAgentName:v,setSelectedAgent:C,setAgentDraft:y,createAgent:S,deleteAgent:g,loadAgents:T}=Bn(Ds(L=>({selectedAgentName:L.selectedAgentName,setSelectedAgent:L.setSelectedAgent,setAgentDraft:L.setAgentDraft,createAgent:L.createAgent,deleteAgent:L.deleteAgent,loadAgents:L.loadAgents}))),R=Us(),A=Bn(L=>ol(L,R));o.useEffect(()=>{T(R)},[T,R]);const j="bg-background",f=()=>{const L="new-agent";let se=L,z=1;for(;A.some(V=>V.name===se);)se=`${L}-${z}`,z++;y({name:se,scope:"user"}),C(se),t?.()},b=async L=>{if(la(L)){M.error(e("settings.agents.sidebar.toast.builtInCannotDelete"));return}u(L),h("delete")},F=async L=>{la(L)&&(u(L),h("reset"))},D=()=>{u(null),h(null)},P=async()=>{if(!(!l||!p)){w(!0);try{const L=await g(l.name,l.scope,R);L.ok?(L.requiresManualRestart?M.warning(e("settings.agents.page.toast.savedManualRestart")):L.restartDeferred?M.success(e("settings.view.pendingRestart.saved")):p==="delete"?M.success(e("settings.agents.sidebar.toast.agentDeleted",{name:l.name})):M.success(e("settings.agents.sidebar.toast.agentReset",{name:l.name})),D()):p==="delete"?M.error(e("settings.agents.sidebar.toast.deleteFailed")):M.error(e("settings.agents.sidebar.toast.resetFailed"))}catch(L){const se=L instanceof Error?L.message:"",z=/built-in|not deletable|not found/i.test(se);p==="delete"?M.error(e(z?"settings.agents.sidebar.toast.definitionNotFound":"settings.agents.sidebar.toast.deleteFailed")):M.error(e("settings.agents.sidebar.toast.resetFailed"))}w(!1)}},I=L=>{const se=L.name;let z=1,V=`${se}-copy`;for(;A.some(Y=>Y.name===V);)z++,V=`${se}-copy-${z}`;const _=L,K=L.model?.providerID&&L.model?.modelID?`${L.model.providerID}/${L.model.modelID}`:null,Z=L;y({name:V,scope:_.scope||"user",description:L.description,model:K,variant:L.variant,temperature:L.temperature,top_p:L.topP,prompt:L.prompt,mode:L.mode,permission:to(L.permission),disable:Z.disable}),C(V),t?.()},U=L=>{r(L.name),n(L)},q=async()=>{if(!a)return;const L=i.trim().replace(/\s+/g,"-");if(!L){M.error(e("settings.agents.sidebar.toast.agentNameRequired"));return}if(L===a.name){n(null);return}if(A.some(_=>_.name===L)){M.error(e("settings.agents.sidebar.toast.agentExists"));return}const se=a.model?.providerID&&a.model?.modelID?`${a.model.providerID}/${a.model.modelID}`:null,z=a,V=await S({name:L,description:a.description,model:se,variant:a.variant,temperature:a.temperature,top_p:a.topP,prompt:a.prompt,mode:a.mode,permission:to(a.permission),disable:z.disable,scope:z.scope},R);if(V.ok){const _=await g(a.name,z.scope,R);_.ok?(V.requiresManualRestart||_.requiresManualRestart?M.warning(e("settings.agents.page.toast.savedManualRestart")):M.success(e("settings.agents.sidebar.toast.agentRenamed",{name:L})),C(L)):M.error(e("settings.agents.sidebar.toast.removeOldAfterRenameFailed"))}else M.error(e("settings.agents.sidebar.toast.renameFailed"));n(null)},k=L=>{switch(L){case"primary":return s.jsx(O,{name:"ai-agent",className:"h-3 w-3 text-primary"});case"all":return s.jsx(O,{name:"ai-agent-fill",className:"h-3 w-3 text-primary"});case"subagent":return s.jsx(O,{name:"robot",className:"h-3 w-3 text-primary"});default:return null}},$=A.filter(L=>!lc(L)),G=$.filter(la),E=$.filter(L=>!la(L)),{groupedCustomAgents:J,ungroupedCustomAgents:X}=qe.useMemo(()=>{const L={},se=[];for(const V of E){const _=V;_.group?(L[_.group]||(L[_.group]=[]),L[_.group].push(V)):se.push(V)}return{groupedCustomAgents:Object.keys(L).sort((V,_)=>V.localeCompare(_)).map(V=>({name:V,agents:L[V]})),ungroupedCustomAgents:se}},[E]);return s.jsxs("div",{className:we("flex h-full flex-col",j),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${on} mb-3`,children:e("settings.agents.sidebar.title")}),s.jsx(Va,{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:$.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:f,children:s.jsx(O,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Bs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:$.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(O,{name:"robot-2",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.agents.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.agents.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[G.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.agents.sidebar.section.builtIn")}),G.map(L=>s.jsx(Fi,{agent:L,isSelected:v===L.name,onSelect:()=>{C(L.name),t?.()},onReset:()=>F(L),onDuplicate:()=>I(L),getAgentModeIcon:k,isMenuOpen:c===L.name,onMenuOpenChange:se=>N(se?L.name:null)},L.name))]}),E.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")}),J.map(({name:L,agents:se})=>s.jsx(er,{label:L,count:se.length,storageKey:"agents",children:se.map(z=>s.jsx(Fi,{agent:z,isSelected:v===z.name,onSelect:()=>{C(z.name),t?.()},onRename:()=>U(z),onDelete:()=>b(z),onDuplicate:()=>I(z),getAgentModeIcon:k,isMenuOpen:c===z.name,onMenuOpenChange:V=>N(V?z.name:null)},z.name))},L)),X.map(L=>s.jsx(Fi,{agent:L,isSelected:v===L.name,onSelect:()=>{C(L.name),t?.()},onRename:()=>U(L),onDelete:()=>b(L),onDuplicate:()=>I(L),getAgentModeIcon:k,isMenuOpen:c===L.name,onMenuOpenChange:se=>N(se?L.name:null)},L.name))]})]})}),s.jsx(Ft,{open:l!==null&&p!==null,onOpenChange:L=>{!L&&!d&&D()},children:s.jsxs(Kt,{className:"max-w-md",children:[s.jsxs(Ut,{children:[s.jsx(_t,{children:e(p==="delete"?"settings.agents.sidebar.dialog.deleteTitle":"settings.agents.sidebar.dialog.resetTitle")}),s.jsx($t,{children:p==="delete"?e("settings.agents.sidebar.dialog.deleteDescription",{name:l?.name??""}):e("settings.agents.sidebar.dialog.resetDescription",{name:l?.name??""})})]}),s.jsxs(es,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:D,disabled:d,children:e("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",onClick:P,disabled:d,children:e(p==="delete"?"settings.common.actions.delete":"settings.common.actions.reset")})]})]})}),s.jsx(Ft,{open:a!==null,onOpenChange:L=>!L&&n(null),children:s.jsxs(Kt,{children:[s.jsxs(Ut,{children:[s.jsx(_t,{children:e("settings.agents.sidebar.renameDialog.title")}),s.jsx($t,{children:e("settings.agents.sidebar.renameDialog.description",{name:a?.name??""})})]}),s.jsx(Je,{value:i,onChange:L=>r(L.target.value),placeholder:e("settings.agents.sidebar.renameDialog.placeholder"),className:"text-foreground placeholder:text-muted-foreground",onKeyDown:L=>{L.key==="Enter"&&q()}}),s.jsxs(es,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>n(null),children:e("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",onClick:q,children:e("settings.common.actions.rename")})]})]})})]})},Fi=t=>{const e=mt.c(52),{agent:a,isSelected:n,onSelect:i,onDelete:r,onReset:l,onRename:u,onDuplicate:p,getAgentModeIcon:h,isMenuOpen:d,onMenuOpenChange:w}=t,{t:c}=at(),N=a;let v;e[0]===Symbol.for("react.memo_cache_sentinel")?(v=za(),e[0]=v):v=e[0];const C=v,[y,S]=o.useState(!1);let g;e[1]!==r||e[2]!==p||e[3]!==u||e[4]!==l||e[5]!==c?(g=se=>s.jsxs(s.Fragment,{children:[u&&s.jsxs(se,{onClick:z=>{z.stopPropagation(),u()},children:[s.jsx(O,{name:"edit",className:"h-4 w-4 mr-px"}),c("settings.common.actions.rename")]}),s.jsxs(se,{onClick:z=>{z.stopPropagation(),p()},children:[s.jsx(O,{name:"file-copy",className:"h-4 w-4 mr-px"}),c("settings.common.actions.duplicate")]}),l&&s.jsxs(se,{onClick:z=>{z.stopPropagation(),l()},children:[s.jsx(O,{name:"restart",className:"h-4 w-4 mr-px"}),c("settings.common.actions.reset")]}),r&&s.jsxs(se,{onClick:z=>{z.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(O,{name:"delete-bin",className:"h-4 w-4 mr-px"}),c("settings.common.actions.delete")]})]}),e[1]=r,e[2]=p,e[3]=u,e[4]=l,e[5]=c,e[6]=g):g=e[6];const T=g,R=n?"bg-interactive-selection":"hover:bg-interactive-hover";let A;e[7]!==R?(A=we("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",R),e[7]=R,e[8]=A):A=e[8];let j;e[9]===Symbol.for("react.memo_cache_sentinel")?(j=C?void 0:se=>{se.preventDefault(),S(!0)},e[9]=j):j=e[9];let f;e[10]!==A?(f=s.jsx("div",{className:A,onContextMenu:j}),e[10]=A,e[11]=f):f=e[11];let b;e[12]!==a.name?(b=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a.name}),e[12]=a.name,e[13]=b):b=e[13];let F;e[14]!==a.mode||e[15]!==h?(F=h(a.mode),e[14]=a.mode,e[15]=h,e[16]=F):F=e[16];let D;e[17]!==a||e[18]!==N.scope||e[19]!==c?(D=(N.scope||la(a))&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:la(a)?c("settings.agents.sidebar.badge.system"):N.scope}),e[17]=a,e[18]=N.scope,e[19]=c,e[20]=D):D=e[20];let P;e[21]!==b||e[22]!==F||e[23]!==D?(P=s.jsxs("div",{className:"flex items-center gap-1.5",children:[b,F,D]}),e[21]=b,e[22]=F,e[23]=D,e[24]=P):P=e[24];let I;e[25]!==a.description?(I=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[25]=a.description,e[26]=I):I=e[26];let U;e[27]!==i||e[28]!==P||e[29]!==I?(U=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-primary/50",tabIndex:0,children:[P,I]}),e[27]=i,e[28]=P,e[29]=I,e[30]=U):U=e[30];let q;e[31]!==w?(q=se=>{se&&S(!1),w(se)},e[31]=w,e[32]=q):q=e[32];let k;e[33]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(sn,{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(O,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[33]=k):k=e[33];let $;e[34]!==T?($=s.jsx(nn,{align:"end",className:"w-fit min-w-20",children:T(rn)}),e[34]=T,e[35]=$):$=e[35];let G;e[36]!==d||e[37]!==q||e[38]!==$?(G=s.jsxs(an,{open:d,onOpenChange:q,children:[k,$]}),e[36]=d,e[37]=q,e[38]=$,e[39]=G):G=e[39];let E;e[40]!==U||e[41]!==G?(E=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[U,G]}),e[40]=U,e[41]=G,e[42]=E):E=e[42];let J;e[43]!==E||e[44]!==f?(J=s.jsx(qn,{render:f,children:E}),e[43]=E,e[44]=f,e[45]=J):J=e[45];let X;e[46]!==T?(X=s.jsx(Gn,{className:"w-fit min-w-20",children:T(Wn)}),e[46]=T,e[47]=X):X=e[47];let L;return e[48]!==y||e[49]!==J||e[50]!==X?(L=s.jsxs(Jn,{open:y,onOpenChange:S,children:[J,X]}),e[48]=y,e[49]=J,e[50]=X,e[51]=L):L=e[51],L},ns=t=>{const e=mt.c(21),{children:a,className:n,outerClassName:i,title:r,titleLeading:l,titleAccessory:u,description:p,headerEnd:h,showSaveStatus:d}=t,w=d===void 0?!1:d,c=r!=null||p!=null||h!=null||w,N=typeof r=="string"||typeof r=="number",v=l!=null||u!=null;let C;e[0]!==i?(C=we("h-full",i),e[0]=i,e[1]=C):C=e[1];let y;e[2]!==n?(y=we("mx-auto max-w-[840px] space-y-0 px-6 py-6 @3xl:px-12 @3xl:py-8","[&>section:first-of-type]:border-t-0 [&>section:first-of-type]:pt-0",n),e[2]=n,e[3]=y):y=e[3];let S;e[4]!==p||e[5]!==c||e[6]!==v||e[7]!==h||e[8]!==N||e[9]!==w||e[10]!==r||e[11]!==u||e[12]!==l?(S=c&&s.jsxs("div",{className:"mb-2 flex flex-wrap items-start justify-between gap-x-4 gap-y-3 pb-6",children:[s.jsxs("div",{className:"min-w-0 flex-1 basis-64 space-y-1",children:[r!=null?N?v?s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[l,s.jsx("h1",{"data-settings-page-heading":!0,tabIndex:-1,className:we(Zi,"min-w-0 truncate"),children:r}),s.jsx("span",{className:"shrink-0",children:u})]}):s.jsx("h1",{"data-settings-page-heading":!0,tabIndex:-1,className:Zi,children:r}):r:null,p!=null?typeof p=="string"||typeof p=="number"?s.jsx("p",{className:cc,children:p}):p:null]}),s.jsxs("div",{className:"flex shrink-0 flex-wrap items-center justify-end gap-3",children:[h,w&&s.jsx(lu,{})]})]}),e[4]=p,e[5]=c,e[6]=v,e[7]=h,e[8]=N,e[9]=w,e[10]=r,e[11]=u,e[12]=l,e[13]=S):S=e[13];let g;e[14]!==a||e[15]!==y||e[16]!==S?(g=s.jsxs("div",{className:y,children:[S,a]}),e[14]=a,e[15]=y,e[16]=S,e[17]=g):g=e[17];let T;return e[18]!==C||e[19]!==g?(T=s.jsx(Bs,{outerClassName:C,className:"w-full @container",children:g}),e[18]=C,e[19]=g,e[20]=T):T=e[20],T},ou=500,lu=()=>{const t=mt.c(13),{t:e}=at(),a=o.useSyncExternalStore(rd,Kr,Kr),[n,i]=o.useState(!1);let r,l;if(t[0]!==a?(r=()=>{if(a!=="saving"){i(!1);return}const d=setTimeout(()=>i(!0),ou);return()=>clearTimeout(d)},l=[a],t[0]=a,t[1]=r,t[2]=l):(r=t[1],l=t[2]),o.useEffect(r,l),a==="error"){let d;t[3]===Symbol.for("react.memo_cache_sentinel")?(d=s.jsx(O,{name:"error-warning",className:"size-3.5"}),t[3]=d):d=t[3];let w;t[4]!==e?(w=e("settings.common.status.saveFailed"),t[4]=e,t[5]=w):w=t[5];let c;return t[6]!==w?(c=s.jsxs("div",{"aria-live":"assertive",className:"flex shrink-0 items-center gap-1.5 typography-meta text-[var(--status-error)]",children:[d,s.jsx("span",{children:w})]}),t[6]=w,t[7]=c):c=t[7],c}if(a!=="saving"||!n)return null;let u;t[8]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(O,{name:"loader-4",className:"size-3.5 animate-spin"}),t[8]=u):u=t[8];let p;t[9]!==e?(p=e("settings.common.actions.saving"),t[9]=e,t[10]=p):p=t[10];let h;return t[11]!==p?(h=s.jsxs("div",{"aria-live":"polite",className:"flex shrink-0 items-center gap-1.5 typography-meta text-muted-foreground",children:[u,s.jsx("span",{children:p})]}),t[11]=p,t[12]=h):h=t[12],h},cu=["allow","ask","deny"],Ra=t=>t==="allow"||t==="ask"||t==="deny",tr=()=>({global:null,keys:{}}),du=t=>{const e=tr();if(t==null)return e;if(typeof t=="string")return Ra(t)&&(e.global=t),e;if(typeof t!="object"||Array.isArray(t))return e;for(const[a,n]of Object.entries(t)){if(a==="*"){Ra(n)&&(e.global=n);continue}const i={action:null,patterns:[]};if(Ra(n))i.action=n;else if(n&&typeof n=="object"&&!Array.isArray(n))for(const[r,l]of Object.entries(n))Ra(l)&&(r==="*"?i.action=l:i.patterns.push({pattern:r,action:l}));else continue;e.keys[a]=i}return e},sr=t=>{const e={};t.global!==null&&(e["*"]=t.global);for(const[a,n]of Object.entries(t.keys)){const i=n.patterns.filter(r=>r.pattern.trim().length>0);if(n.action!==null&&i.length===0)e[a]=n.action;else if(i.length>0){const r={};n.action!==null&&(r["*"]=n.action);for(const l of i)r[l.pattern]=l.action;e[a]=r}}return Object.keys(e).length>0?e:null},uu=(t,e)=>JSON.stringify(sr(t))===JSON.stringify(sr(e)),In=t=>JSON.parse(JSON.stringify(t)),pu=["edit","external_directory","doom_loop","plan_enter","plan_exit"],mu=new Set(["read","edit","glob","grep","list","bash","task","external_directory","lsp","skill"]),so=new Set(["write","patch","apply_patch","multiedit","invalid"]),gu=t=>t.split(/[_-]/).filter(Boolean).map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join(" "),fu=({agent:t})=>{const{t:e}=at(),a=Bn(_=>_.updateAgent),[n,i]=o.useState(tr),[r,l]=o.useState(tr),[u,p]=o.useState(!0),[h,d]=o.useState(!1),[w,c]=o.useState(!1),[N,v]=o.useState({}),[C,y]=o.useState([]),[S,g]=o.useState(""),[T,R]=o.useState(0),A=t.name,j=Us();o.useEffect(()=>{let _=!1;return p(!0),d(!1),(async()=>{try{const K=j,Z=K?`?directory=${encodeURIComponent(K)}`:"",Y=await pt(`/api/config/agents/${encodeURIComponent(A)}/config${Z}`,{headers:{"Cache-Control":"no-cache",...K?{"x-opencode-directory":K}:{}}});if(!Y.ok)throw new Error(String(Y.status));const te=await Y.json().catch(()=>null);if(_)return;const ge=du(te?.config?.permission);i(In(ge)),l(ge)}catch{_||d(!0)}finally{_||p(!1)}})(),()=>{_=!0}},[A,T,j]),o.useEffect(()=>{let _=!1;return(async()=>{try{const K=await hn.listToolIds({directory:j});!_&&Array.isArray(K)&&y(K.filter(Z=>typeof Z=="string"&&!so.has(Z)))}catch{}})(),()=>{_=!0}},[A,j]);const f=o.useMemo(()=>{const _=t.permission;if(!Array.isArray(_))return[];const K=[];for(const Z of _){if(!Z||typeof Z!="object")continue;const{permission:Y,pattern:te,action:ge}=Z;typeof Y=="string"&&typeof te=="string"&&Ra(ge)&&K.push({permission:Y,pattern:te,action:ge})}return K},[t]),b=o.useCallback(_=>{const K=f.find(Y=>Y.permission===_&&Y.pattern==="*");if(K)return K.action;const Z=f.find(Y=>Y.permission==="*"&&Y.pattern==="*");return Z?Z.action:null},[f]),F=o.useCallback(_=>{const K=r.keys[_]?.patterns??[],Z=new Set(K.map(Y=>Y.pattern));return f.filter(Y=>Y.permission===_&&Y.pattern!=="*"&&!Z.has(Y.pattern))},[f,r.keys]),D=o.useMemo(()=>{const _=new Set;for(const K of C)_.add(K);for(const K of pu)_.add(K);for(const K of Object.keys(r.keys))_.add(K);for(const K of so)_.delete(K);return Array.from(_).sort((K,Z)=>K.localeCompare(Z))},[C,r.keys]),P=o.useMemo(()=>!uu(r,n),[r,n]),I=_=>{l(K=>({...K,global:_}))},U=(_,K)=>{l(Z=>{const Y=In(Z),te=Y.keys[_]??{action:null,patterns:[]};return te.action=K,te.action===null&&te.patterns.length===0?delete Y.keys[_]:Y.keys[_]=te,Y})},q=(_,K,Z,Y)=>{l(te=>{const ge=In(te),le=ge.keys[_]??{action:null,patterns:[]};return le.patterns[K]={pattern:Z,action:Y},ge.keys[_]=le,ge})},k=_=>{l(K=>{const Z=In(K),Y=Z.keys[_]??{action:null,patterns:[]};return Y.patterns.push({pattern:"",action:"allow"}),Z.keys[_]=Y,Z}),v(K=>({...K,[_]:!0}))},$=(_,K)=>{l(Z=>{const Y=In(Z),te=Y.keys[_];return te?(te.patterns.splice(K,1),te.action===null&&te.patterns.length===0&&delete Y.keys[_],Y):Z})},G=()=>{const _=S.trim();!_||_==="*"||(l(K=>{if(K.keys[_])return K;const Z=In(K);return Z.keys[_]={action:"ask",patterns:[]},Z}),v(K=>({...K,[_]:!0})),g(""))},E=async()=>{c(!0);try{const _=sr(r),K=await a(A,{permission:_});K.ok?(i(In(r)),M.success(K.requiresManualRestart?e("settings.agents.page.permissionsEditor.toast.savedRestartRequired"):e("settings.agents.page.permissionsEditor.toast.saved"))):M.error(e("settings.agents.page.permissionsEditor.toast.saveFailed"))}finally{c(!1)}},J=()=>{l(In(n))},X=_=>e(_==="allow"?"settings.agents.page.permissionsEditor.action.allow":_==="ask"?"settings.agents.page.permissionsEditor.action.ask":"settings.agents.page.permissionsEditor.action.deny"),L=e("settings.agents.page.permissionsEditor.action.inherit"),se=e("settings.agents.page.permissionsEditor.action.default"),z=_=>[..._?[{value:"inherit",label:_}]:[],...cu.map(K=>({value:K,label:X(K)}))],V=(_,K,Z,Y=L)=>s.jsx(qs,{value:_??"inherit",options:z(Y),onChange:te=>K(te==="inherit"?null:te),"aria-label":Z});return u?s.jsx(_e,{title:e("settings.agents.page.section.toolPermissions"),children:s.jsx("p",{className:zn,children:e("common.loading")})}):h?s.jsx(_e,{title:e("settings.agents.page.section.toolPermissions"),children:s.jsxs("div",{className:"flex items-center gap-3",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:e("settings.agents.page.permissionsEditor.state.loadFailed")}),s.jsx(B,{variant:"outline",size:"xs",onClick:()=>R(_=>_+1),children:e("settings.agents.page.permissionsEditor.actions.retry")})]})}):s.jsxs(_e,{title:e("settings.agents.page.section.toolPermissions"),settingsItem:"agents.permissions",info:e("settings.agents.page.permissionsEditor.sectionInfo"),headerAction:P?s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal",onClick:J,disabled:w,children:e("settings.agents.page.permissionsEditor.actions.discard")}),s.jsx(B,{size:"xs",className:"!font-normal",onClick:()=>{E()},disabled:w,children:e(w?"settings.common.actions.saving":"settings.agents.page.permissionsEditor.actions.save")})]}):void 0,contentClassName:"space-y-4",children:[s.jsxs("div",{className:"flex flex-col gap-2 pb-2 @xl:flex-row @xl:items-center @xl:justify-between",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Et,children:e("settings.agents.page.permissionsEditor.defaultLabel")}),s.jsx(Jt,{children:e("settings.agents.page.permissionsEditor.defaultInfo")}),r.global===null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.agents.page.permissionsEditor.effectiveHint",{action:X(b("*")??"allow")})})]}),V(r.global,I,e("settings.agents.page.permissionsEditor.defaultAria"),se)]}),s.jsx("div",{children:D.map(_=>{const K=r.keys[_]??{action:null,patterns:[]},Z=F(_),Y=mu.has(_)||K.patterns.length>0,te=Y||Z.length>0,ge=N[_]===!0,le=b(_);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:te?()=>v(he=>({...he,[_]:!ge})):void 0,className:we("flex min-w-0 items-center gap-1.5 text-left",!te&&"cursor-default"),"aria-expanded":te?ge:void 0,children:[s.jsx(O,{name:ge&&te?"arrow-down-s":"arrow-right-s",className:we("h-3.5 w-3.5 shrink-0 text-muted-foreground",!te&&"opacity-0")}),s.jsx("span",{className:Et,children:gu(_)}),s.jsx("span",{className:"typography-micro font-mono text-muted-foreground/70",children:_}),K.action===null&&le!==null&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.agents.page.permissionsEditor.effectiveHint",{action:X(le)})}),K.patterns.length>0&&s.jsx("span",{className:"typography-micro rounded bg-muted px-1 text-muted-foreground",children:e("settings.agents.page.permissionsEditor.ruleCount",{count:String(K.patterns.length)})})]}),V(K.action,he=>U(_,he),e("settings.agents.page.permissionsEditor.keyAria",{key:_}))]}),ge&&te&&s.jsxs("div",{className:"mt-2 space-y-2 pl-5",children:[K.patterns.map((he,ne)=>s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(Je,{value:he.pattern,onChange:ae=>q(_,ne,ae.target.value,he.action),placeholder:e("settings.agents.page.permissionsEditor.patternPlaceholder"),className:"h-8 w-full max-w-[24rem] min-w-0 flex-1 font-mono text-xs"}),s.jsx(qs,{value:he.action,options:z(),onChange:ae=>q(_,ne,he.pattern,ae),"aria-label":e("settings.agents.page.permissionsEditor.patternActionAria",{key:_})}),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:()=>$(_,ne),"aria-label":e("settings.agents.page.permissionsEditor.actions.removeRuleAria"),children:s.jsx(O,{name:"close",className:"h-3.5 w-3.5"})})]},ne)),Y&&s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>k(_),children:[s.jsx(O,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e("settings.agents.page.permissionsEditor.actions.addRule")]}),Z.length>0&&s.jsxs("div",{className:"space-y-1 pt-1",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:"typography-micro font-medium text-muted-foreground",children:e("settings.agents.page.permissionsEditor.sessionRulesTitle")}),s.jsx(Jt,{children:e("settings.agents.page.permissionsEditor.sessionRulesInfo")})]}),Z.map(he=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("span",{className:"typography-micro min-w-0 flex-1 truncate font-mono text-muted-foreground/70",children:he.pattern}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:X(he.action)})]},`${he.pattern}-${he.action}`))]})]})]},_)})}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2 border-t border-border/40 pt-3",children:[s.jsx(Je,{value:S,onChange:_=>g(_.target.value),onKeyDown:_=>{_.key==="Enter"&&(_.preventDefault(),G())},placeholder:e("settings.agents.page.permissionsEditor.customKeyPlaceholder"),className:"h-8 w-full max-w-[16rem] font-mono text-xs"}),s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:G,disabled:!S.trim(),children:[s.jsx(O,{name:"add",className:"mr-1 h-3.5 w-3.5"}),e("settings.agents.page.permissionsEditor.actions.addKey")]})]})]})},hu=(t,e)=>{const a=da(e);if(!a)return[];const i=t.find(r=>r.id===a.providerId)?.models?.find(r=>r.id===a.modelId);return i?.variants?Object.keys(i.variants):[]},xu=()=>{const{t}=at(),e=Ze(V=>V.providers),{selectedAgentName:a,getAgentByName:n,createAgent:i,updateAgent:r,agentDraft:l,setAgentDraft:u}=Bn(Ds(V=>({selectedAgentName:V.selectedAgentName,getAgentByName:V.getAgentByName,createAgent:V.createAgent,updateAgent:V.updateAgent,agentDraft:V.agentDraft,setAgentDraft:V.setAgentDraft}))),p=Us(),h=Bn(V=>ol(V,p)),d=a?n(a,p):null,w=!!(l&&l.name===a&&!d),[c,N]=o.useState(""),[v,C]=o.useState("user"),[y,S]=o.useState(""),[g,T]=o.useState("subagent"),[R,A]=o.useState(""),[j,f]=o.useState(""),[b,F]=o.useState(void 0),[D,P]=o.useState(void 0),[I,U]=o.useState(""),[q,k]=o.useState(!1),$=o.useRef(null),G=o.useMemo(()=>hu(e,R),[R,e]),E=G.length>0,J=j||"__default",X=E,L=o.useMemo(()=>j&&!G.includes(j)?[j,...G]:G,[j,G]);o.useEffect(()=>{if(w&&l){const V=l.name||"",_=l.scope||"user",K=l.description||"",Z=l.mode||"subagent",Y=l.model||"",te=l.variant||"",ge=l.temperature??void 0,le=l.top_p??void 0,he=l.prompt||"";N(V),C(_),S(K),T(Z),A(Y),f(te),F(ge),P(le),U(he),$.current={draftName:V,draftScope:_,description:K,mode:Z,model:Y,variant:te,temperature:ge,topP:le,prompt:he};return}if(d&&a===d.name){const V=d.description||"",_=d.mode||"subagent",K=d.model?.providerID&&d.model?.modelID?`${d.model.providerID}/${d.model.modelID}`:"",Z=d.variant||"",Y=d.temperature??void 0,te=d.topP??void 0,ge=d.prompt||"";S(V),T(_),A(K),f(Z),F(Y),P(te),U(ge),$.current={draftName:"",draftScope:"user",description:V,mode:_,model:K,variant:Z,temperature:Y,topP:te,prompt:ge}}},[l,w,d,a]);const se=o.useMemo(()=>{const V=$.current;return V?!!(w&&(c!==V.draftName||v!==V.draftScope)||y!==V.description||g!==V.mode||R!==V.model||j!==V.variant||b!==V.temperature||D!==V.topP||I!==V.prompt):!1},[y,c,v,w,g,R,I,b,D,j]),z=async()=>{const V=w?c.trim().replace(/\s+/g,"-"):a?.trim();if(!V){M.error(t("settings.agents.sidebar.toast.agentNameRequired"));return}if(w&&h.some(_=>_.name===V)){M.error(t("settings.agents.sidebar.toast.agentExists"));return}k(!0);try{const _=R.trim(),K=j.trim(),Z=I.trim(),Y={name:V,...y.trim()?{description:y.trim()}:{},mode:g,model:_===""?null:_,variant:K===""?null:K||void 0,temperature:b??null,top_p:D??null,prompt:Z||(w?void 0:null),...w&&v?{scope:v}:{}};let te;w?(te=await i(Y,p),te.ok&&u(null)):te=await r(V,Y,p),te.ok?te.requiresManualRestart?M.warning(t("settings.agents.page.toast.savedManualRestart")):te.restartDeferred?M.success(t("settings.view.pendingRestart.saved")):M.success(t(w?"settings.agents.page.toast.created":"settings.agents.page.toast.updated")):M.error(t(w?"settings.agents.page.toast.createFailed":"settings.agents.page.toast.updateFailed"))}catch(_){console.error("Error saving agent:",_);const K=_ instanceof Error&&_.message?_.message:t("settings.agents.page.toast.saveUnexpectedError");M.error(K)}finally{k(!1)}};return a?s.jsxs(ns,{title:w?t("settings.agents.page.title.new"):a,description:t(w?"settings.agents.page.subtitle.new":"settings.agents.page.subtitle.edit"),showSaveStatus:!1,children:[s.jsxs(_e,{title:t("settings.agents.page.section.identityRole"),divider:!1,contentClassName:"space-y-0",children:[w&&s.jsxs(Ot,{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(Je,{value:c,onChange:V=>N(V.target.value),placeholder:t("settings.agents.page.field.agentNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(Pt,{value:v,onValueChange:V=>C(V),children:[s.jsx(It,{size:Lt,className:"w-fit min-w-[100px]",children:s.jsx(Rt,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(At,{align:"end",children:[s.jsx(ot,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(O,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(ot,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(O,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.project")})]})})]})]})]}),s.jsx(qt,{label:t("settings.common.field.description"),controlClassName:"w-full max-w-none",children:s.jsx(Is,{value:y,onChange:V=>S(V.target.value),placeholder:t("settings.agents.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})}),s.jsx(qt,{settingsItem:"agents.mode",label:t("settings.agents.page.field.mode"),info:t("settings.agents.page.field.modeTooltip"),children:s.jsx(qs,{"aria-label":t("settings.agents.page.field.mode"),value:g,onChange:T,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(_e,{title:t("settings.agents.page.section.modelParameters"),contentClassName:"space-y-3",children:[s.jsx(Ot,{settingsItem:"agents.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(Oa,{providerId:da(R)?.providerId??"",modelId:da(R)?.modelId??"",onChange:(V,_)=>{A(V&&_?`${V}/${_}`:""),f("")},className:Mn})}),s.jsx(Ot,{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:X?s.jsxs(Pt,{value:J,onValueChange:V=>f(V==="__default"?"":V),children:[s.jsx(It,{size:Lt,className:en,children:s.jsx(Rt,{placeholder:t("settings.agents.page.field.variantPlaceholder"),children:V=>V==="__default"?t("chat.modelControls.default"):V})}),s.jsxs(At,{children:[s.jsx(ot,{value:"__default",children:t("chat.modelControls.default")}),L.map(V=>s.jsx(ot,{value:V,children:V},V))]})]}):s.jsxs(s.Fragment,{children:[s.jsx(Je,{value:j,onChange:V=>f(V.target.value),placeholder:t("settings.agents.page.field.variantPlaceholder"),disabled:!R&&!j,className:"h-8 w-40 rounded-md px-3"}),j&&s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>f(""),className:fs,"aria-label":t("settings.common.actions.clear"),title:t("settings.common.actions.clear"),children:s.jsx(O,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsxs(Ot,{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(Ss,{value:b,fallbackValue:.7,onValueChange:F,onClear:()=>F(void 0),min:0,max:2,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:Ps}),b!==void 0&&s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>F(void 0),className:fs,"aria-label":t("settings.agents.page.field.clearTemperatureAria"),title:t("settings.common.actions.clear"),children:s.jsx(O,{name:"close",className:"h-3.5 w-3.5"})})]}),s.jsxs(Ot,{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(Ss,{value:D,fallbackValue:.9,onValueChange:P,onClear:()=>P(void 0),min:0,max:1,step:.1,inputMode:"decimal",placeholder:"—",emptyLabel:"—",className:Ps}),D!==void 0&&s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>P(void 0),className:fs,"aria-label":t("settings.agents.page.field.clearTopPAria"),title:t("settings.common.actions.clear"),children:s.jsx(O,{name:"close",className:"h-3.5 w-3.5"})})]})]}),s.jsx(_e,{title:t("settings.agents.page.section.systemPrompt"),settingsItem:"agents.system-prompt",children:s.jsx(Is,{value:I,onChange:V=>U(V.target.value),placeholder:t("settings.agents.page.field.systemPromptPlaceholder"),rows:8,className:"w-full font-mono typography-meta min-h-[120px] max-h-[60vh] bg-transparent resize-y"})}),!w&&d&&s.jsx(fu,{agent:d}),s.jsx("div",{className:"pb-8",children:s.jsx(B,{onClick:z,disabled:q||!se,size:"xs",className:"!font-normal",children:t(q?"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(O,{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")})]})})},vu="~/.config/opencode/AGENTS.md",Ml=async(t,e)=>{const a=await t.json().catch(()=>null);return typeof a?.error=="string"&&a.error.trim()?a.error:e},yu=t=>t.length>0&&!t.endsWith(`
2
- `)?`${t}
3
- `:t,Qa={prompt:"",optimizeSystemPrompt:!1,responseStyleEnabled:!1,responseStylePreset:"concise",responseStyleCustomInstructions:""},bu=(t,e)=>t==="custom"?e:pc(t),wu=t=>t==="custom"?"custom":ll(t)?t:"concise",no={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"},Ki=async(t,e)=>{xn("saving");try{const a=await pt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify(t)});if(!a.ok)throw new Error(await Ml(a,e));xn("saved")}catch(a){throw xn("error"),a}},ju=()=>{const{t}=at(),e=dc(),[a,n]=o.useState(""),[i,r]=o.useState(!1),[l,u]=o.useState(Qa.responseStyleEnabled),[p,h]=o.useState(Qa.responseStylePreset),[d,w]=o.useState(Qa.responseStyleCustomInstructions),[c,N]=o.useState(!0),[v,C]=o.useState(!1),[y,S]=o.useState(!1),[g,T]=o.useState(""),[R,A]=o.useState(!1),j=o.useRef(null);o.useEffect(()=>{const I=new AbortController;return(async()=>{try{const[q,k]=await Promise.all([pt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},signal:I.signal}),pt("/api/behavior/agents-md",{method:"GET",headers:{Accept:"application/json"},signal:I.signal})]);let $=Qa;if(q.ok){const G=await q.json();$={...$,optimizeSystemPrompt:G.optimizeSystemPrompt===!0,responseStyleEnabled:G.responseStyleEnabled===!0,responseStylePreset:wu(G.responseStylePreset),responseStyleCustomInstructions:typeof G.responseStyleCustomInstructions=="string"?G.responseStyleCustomInstructions:""},typeof G.globalBehaviorPrompt=="string"&&($={...$,prompt:G.globalBehaviorPrompt})}if(!$.prompt.trim()&&k.ok){const G=await k.json();typeof G.content=="string"&&($={...$,prompt:G.content})}n($.prompt),r($.optimizeSystemPrompt),A($.optimizeSystemPrompt),u($.responseStyleEnabled),h($.responseStylePreset),w($.responseStyleCustomInstructions),T($.prompt),j.current={enabled:$.responseStyleEnabled,preset:$.responseStylePreset,custom:$.responseStyleCustomInstructions}}catch(q){q.name!=="AbortError"&&console.warn("Failed to load behavior settings:",q)}finally{N(!1)}})(),()=>I.abort()},[]),o.useEffect(()=>{if(c)return;const I=j.current;if(I&&I.enabled===l&&I.preset===p&&I.custom===d)return;const U={enabled:l,preset:p,custom:d},q=setTimeout(async()=>{try{await Ki({responseStyleEnabled:U.enabled,responseStylePreset:U.preset,responseStyleCustomInstructions:U.custom},t("settings.behavior.page.toast.saveFailed")),j.current=U}catch(k){const $=k instanceof Error?k.message:t("settings.behavior.page.toast.saveFailed");M.error($)}},400);return()=>clearTimeout(q)},[l,p,d,c,t]);const f=bu(p,d),b=a!==g,F=i!==R,D=async()=>{C(!0);try{const I=yu(a),U=await pt("/api/behavior/agents-md",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({content:I})});if(!U.ok)throw new Error(await Ml(U,t("settings.behavior.page.toast.saveFailed")));const q=await U.json().catch(()=>null),k=cl(q,"behavior",{id:"agents-md"});await Ki({globalBehaviorPrompt:I},t("settings.behavior.page.toast.saveFailed")),n(I),T(I),M.success(t(k?"settings.view.pendingRestart.saved":"settings.behavior.page.toast.saved"))}catch(I){console.error("Failed to save behavior:",I);const U=I instanceof Error?I.message:t("settings.behavior.page.toast.saveFailed");M.error(U)}finally{C(!1)}},P=async()=>{S(!0);try{await Ki({optimizeSystemPrompt:i},t("settings.behavior.page.toast.saveFailed")),A(i),$n("behavior",{id:"optimize-system-prompt"}),M.success(t("settings.view.pendingRestart.saved"))}catch(I){const U=I instanceof Error?I.message:t("settings.behavior.page.toast.saveFailed");M.error(U)}finally{S(!1)}};return s.jsxs(ns,{title:t("settings.behavior.page.title"),description:t("settings.page.behavior.description"),showSaveStatus:!0,children:[!e&&s.jsxs(_e,{title:t("settings.behavior.page.section.systemPromptOptimization"),divider:!1,settingsItem:"behavior.system-prompt-optimization",contentClassName:"space-y-3",children:[s.jsx(gt,{checked:i,onChange:r,disabled:c||y,label:t("settings.behavior.page.systemPromptOptimization.enable"),ariaLabel:t("settings.behavior.page.systemPromptOptimization.enableAria"),info:t("settings.behavior.page.systemPromptOptimization.info")}),s.jsx(B,{type:"button",size:"xs",onClick:()=>{P()},disabled:c||y||!F,className:"!font-normal",children:t(y?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]}),s.jsxs(_e,{title:t("settings.behavior.page.section.systemPrompt"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{className:"font-medium text-foreground",children:t("settings.behavior.page.warning.title")}),s.jsx("p",{children:t("settings.behavior.page.warning.description",{path:vu})})]}),settingsItem:"behavior.system-prompt",contentClassName:"space-y-3",children:[s.jsx(Is,{value:a,onChange:I=>n(I.target.value),placeholder:t("settings.behavior.page.field.systemPromptPlaceholder"),rows:12,disabled:c,outerClassName:"min-h-[160px] max-h-[70vh]",className:"w-full font-mono typography-meta bg-transparent"}),s.jsx(B,{onClick:D,disabled:v||!b||c,size:"xs",className:"!font-normal",children:t(v?"settings.common.actions.saving":"settings.common.actions.saveChanges")})]}),s.jsxs(_e,{title:t("settings.behavior.page.section.responseStyle"),info:t("settings.behavior.page.responseStyle.tooltip"),settingsItem:"behavior.response-style",contentClassName:"space-y-3",children:[s.jsx(gt,{checked:l,onChange:u,disabled:c,label:t("settings.behavior.page.responseStyle.enable"),ariaLabel:t("settings.behavior.page.responseStyle.enableAria")}),s.jsx(Ot,{label:t("settings.behavior.page.responseStyle.preset"),alignEnd:!1,children:s.jsxs(Pt,{value:p,onValueChange:I=>h(I),disabled:c||!l,children:[s.jsx(It,{size:Lt,className:en,children:s.jsx(Rt,{children:I=>I==="custom"?t("settings.behavior.page.responseStyle.option.custom"):ll(I)?t(no[I]):null})}),s.jsxs(At,{children:[uc.map(I=>s.jsx(ot,{value:I,children:t(no[I])},I)),s.jsx(ot,{value:"custom",children:t("settings.behavior.page.responseStyle.option.custom")})]})]})}),s.jsx(Is,{value:f,onChange:I=>w(I.target.value),placeholder:t("settings.behavior.page.responseStyle.customPlaceholder"),rows:5,disabled:c||!l||p!=="custom",outerClassName:"min-h-[120px]",className:"w-full font-mono typography-meta bg-transparent"})]})]})},ku=t=>{const e=mt.c(176),{onItemSelect:a}=t,{t:n}=at(),[i,r]=o.useState(null),[l,u]=o.useState(""),[p,h]=o.useState(null),[d,w]=o.useState(null),[c,N]=o.useState(!1),[v,C]=o.useState(null),{selectedCommandName:y,setSelectedCommand:S,setCommandDraft:g,createCommand:T,deleteCommand:R,loadCommands:A}=ua(Ds(Nu)),j=Us();let f;e[0]!==j?(f=ze=>dl(ze,j),e[0]=j,e[1]=f):f=e[1];const b=ua(f);let F;e[2]!==j?(F=ze=>pr(ze,j),e[2]=j,e[3]=F):F=e[3];const D=$s(F),P=$s(Su);let I,U;e[4]!==A||e[5]!==P||e[6]!==j?(I=()=>{A(j),P(j)},U=[A,P,j],e[4]=A,e[5]=P,e[6]=j,e[7]=I,e[8]=U):(I=e[7],U=e[8]),o.useEffect(I,U);let q;e[9]!==D?(q=new Set(D.map(Cu)),e[9]=D,e[10]=q):q=e[10];const k=q;let $;if(e[11]!==b||e[12]!==k){let ze;e[14]!==k?(ze=jt=>!k.has(jt.name),e[14]=k,e[15]=ze):ze=e[15],$=b.filter(ze),e[11]=b,e[12]=k,e[13]=$}else $=e[13];const G=$;let E,J;e[16]!==y||e[17]!==S||e[18]!==k?(E=()=>{y&&k.has(y)&&S(null)},J=[y,S,k],e[16]=y,e[17]=S,e[18]=k,e[19]=E,e[20]=J):(E=e[19],J=e[20]),o.useEffect(E,J);let X;e[21]!==b||e[22]!==a||e[23]!==g||e[24]!==S?(X=()=>{let ze="new-command",jt=1;for(;b.some(Te=>Te.name===ze);)ze=`new-command-${jt}`,jt++;g({name:ze,scope:"user"}),S(ze),a?.()},e[21]=b,e[22]=a,e[23]=g,e[24]=S,e[25]=X):X=e[25];const L=X;let se;e[26]!==n?(se=async ze=>{if(ca(ze)){M.error(n("settings.commands.sidebar.toast.builtInCannotDelete"));return}h(ze),w("delete")},e[26]=n,e[27]=se):se=e[27];const z=se;let V;e[28]===Symbol.for("react.memo_cache_sentinel")?(V=async ze=>{ca(ze)&&(h(ze),w("reset"))},e[28]=V):V=e[28];const _=V;let K;e[29]===Symbol.for("react.memo_cache_sentinel")?(K=()=>{h(null),w(null)},e[29]=K):K=e[29];const Z=K;let Y;e[30]!==p||e[31]!==d||e[32]!==R||e[33]!==j||e[34]!==n?(Y=async()=>{if(!p||!d)return;N(!0),await R(p.name,j)?(d==="delete"?M.success(n("settings.commands.sidebar.toast.commandDeleted",{name:p.name})):M.success(n("settings.commands.sidebar.toast.commandReset",{name:p.name})),Z()):d==="delete"?M.error(n("settings.commands.sidebar.toast.deleteFailed")):M.error(n("settings.commands.sidebar.toast.resetFailed")),N(!1)},e[30]=p,e[31]=d,e[32]=R,e[33]=j,e[34]=n,e[35]=Y):Y=e[35];const te=Y;let ge;e[36]!==b||e[37]!==g||e[38]!==S?(ge=ze=>{const jt=ze.name;let Te=1,wt=`${jt}-copy`;for(;b.some(Q=>Q.name===wt);)Te++,wt=`${jt}-copy-${Te}`;g({name:wt,scope:ze.scope||"user",description:ze.description,template:ze.template,agent:ze.agent,model:ze.model}),S(wt)},e[36]=b,e[37]=g,e[38]=S,e[39]=ge):ge=e[39];const le=ge;let he;e[40]===Symbol.for("react.memo_cache_sentinel")?(he=ze=>{u(ze.name),r(ze)},e[40]=he):he=e[40];const ne=he;let ae;e[41]!==b||e[42]!==T||e[43]!==R||e[44]!==i||e[45]!==l||e[46]!==S||e[47]!==j||e[48]!==n?(ae=async()=>{if(!i)return;const ze=l.trim().replace(/\s+/g,"-");if(!ze){M.error(n("settings.commands.sidebar.toast.commandNameRequired"));return}if(ze===i.name){r(null);return}if(b.some(Te=>Te.name===ze)){M.error(n("settings.commands.sidebar.toast.commandExists"));return}await T({name:ze,description:i.description,template:i.template,agent:i.agent,model:i.model},j)?await R(i.name,j)?(M.success(`Command renamed to "${ze}"`),S(ze)):M.error(n("settings.commands.sidebar.toast.removeOldAfterRenameFailed")):M.error(n("settings.commands.sidebar.toast.renameFailed")),r(null)},e[41]=b,e[42]=T,e[43]=R,e[44]=i,e[45]=l,e[46]=S,e[47]=j,e[48]=n,e[49]=ae):ae=e[49];const me=ae;let Pe,Ne,Se,be,Ke,Le;if(e[50]!==G||e[51]!==L||e[52]!==z||e[53]!==le||e[54]!==a||e[55]!==v||e[56]!==y||e[57]!==S||e[58]!==n){const ze=G.filter(ca),jt=G.filter(Pu);e[65]===Symbol.for("react.memo_cache_sentinel")?(Ke=we("flex h-full flex-col","bg-background"),e[65]=Ke):Ke=e[65];let Te;e[66]!==n?(Te=n("settings.commands.sidebar.title"),e[66]=n,e[67]=Te):Te=e[67];let wt;e[68]!==Te?(wt=s.jsx("h2",{className:`${on} mb-3`,children:Te}),e[68]=Te,e[69]=wt):wt=e[69];let Q;e[70]===Symbol.for("react.memo_cache_sentinel")?(Q=s.jsx(Va,{className:"mb-3"}),e[70]=Q):Q=e[70];let fe;e[71]!==G.length||e[72]!==n?(fe=n("settings.commands.sidebar.total",{count:G.length}),e[71]=G.length,e[72]=n,e[73]=fe):fe=e[73];let Ue;e[74]!==fe?(Ue=s.jsx("span",{className:"typography-meta text-muted-foreground",children:fe}),e[74]=fe,e[75]=Ue):Ue=e[75];let Me;e[76]===Symbol.for("react.memo_cache_sentinel")?(Me=s.jsx(O,{name:"add",className:"h-3.5 w-3.5"}),e[76]=Me):Me=e[76];let ct;e[77]!==L?(ct=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:L,children:Me}),e[77]=L,e[78]=ct):ct=e[78];let lt;e[79]!==Ue||e[80]!==ct?(lt=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Ue,ct]}),e[79]=Ue,e[80]=ct,e[81]=lt):lt=e[81],e[82]!==wt||e[83]!==lt?(Le=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[wt,Q,lt]}),e[82]=wt,e[83]=lt,e[84]=Le):Le=e[84],Pe=Bs,Ne="flex-1 min-h-0",Se="space-y-1 px-3 py-2",be=G.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(O,{name:"terminal-box",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.commands.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.commands.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[ze.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.commands.sidebar.section.builtIn")}),[...ze].sort(Iu).map(Qe=>s.jsx(ao,{command:Qe,isSelected:y===Qe.name,onSelect:()=>{S(Qe.name),a?.()},onReset:()=>_(Qe),onDuplicate:()=>le(Qe),isMenuOpen:v===Qe.name,onMenuOpenChange:Nt=>C(Nt?Qe.name:null)},Qe.name))]}),jt.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.commands.sidebar.section.custom")}),[...jt].sort(Au).map(Qe=>s.jsx(ao,{command:Qe,isSelected:y===Qe.name,onSelect:()=>{S(Qe.name),a?.()},onRename:()=>ne(Qe),onDelete:()=>z(Qe),onDuplicate:()=>le(Qe),isMenuOpen:v===Qe.name,onMenuOpenChange:Nt=>C(Nt?Qe.name:null)},Qe.name))]})]}),e[50]=G,e[51]=L,e[52]=z,e[53]=le,e[54]=a,e[55]=v,e[56]=y,e[57]=S,e[58]=n,e[59]=Pe,e[60]=Ne,e[61]=Se,e[62]=be,e[63]=Ke,e[64]=Le}else Pe=e[59],Ne=e[60],Se=e[61],be=e[62],Ke=e[63],Le=e[64];let oe;e[85]!==Pe||e[86]!==Ne||e[87]!==Se||e[88]!==be?(oe=s.jsx(Pe,{outerClassName:Ne,className:Se,children:be}),e[85]=Pe,e[86]=Ne,e[87]=Se,e[88]=be,e[89]=oe):oe=e[89];const xe=p!==null&&d!==null;let Ee;e[90]!==c?(Ee=ze=>{!ze&&!c&&Z()},e[90]=c,e[91]=Ee):Ee=e[91];let Ve;e[92]!==d||e[93]!==n?(Ve=n(d==="delete"?"settings.commands.sidebar.dialog.deleteTitle":"settings.commands.sidebar.dialog.resetTitle"),e[92]=d,e[93]=n,e[94]=Ve):Ve=e[94];let $e;e[95]!==Ve?($e=s.jsx(_t,{children:Ve}),e[95]=Ve,e[96]=$e):$e=e[96];let We;e[97]!==p?.name||e[98]!==d||e[99]!==n?(We=d==="delete"?n("settings.commands.sidebar.dialog.deleteDescription",{name:p?.name??""}):n("settings.commands.sidebar.dialog.resetDescription",{name:p?.name??""}),e[97]=p?.name,e[98]=d,e[99]=n,e[100]=We):We=e[100];let Fe;e[101]!==We?(Fe=s.jsx($t,{children:We}),e[101]=We,e[102]=Fe):Fe=e[102];let ie;e[103]!==$e||e[104]!==Fe?(ie=s.jsxs(Ut,{children:[$e,Fe]}),e[103]=$e,e[104]=Fe,e[105]=ie):ie=e[105];let re;e[106]!==n?(re=n("settings.common.actions.cancel"),e[106]=n,e[107]=re):re=e[107];let je;e[108]!==c||e[109]!==re?(je=s.jsx(B,{size:"sm",variant:"ghost",onClick:Z,disabled:c,children:re}),e[108]=c,e[109]=re,e[110]=je):je=e[110];let ve;e[111]!==d||e[112]!==n?(ve=n(d==="delete"?"settings.common.actions.delete":"settings.common.actions.reset"),e[111]=d,e[112]=n,e[113]=ve):ve=e[113];let Re;e[114]!==te||e[115]!==c||e[116]!==ve?(Re=s.jsx(B,{size:"sm",onClick:te,disabled:c,children:ve}),e[114]=te,e[115]=c,e[116]=ve,e[117]=Re):Re=e[117];let Ae;e[118]!==je||e[119]!==Re?(Ae=s.jsxs(es,{children:[je,Re]}),e[118]=je,e[119]=Re,e[120]=Ae):Ae=e[120];let ye;e[121]!==ie||e[122]!==Ae?(ye=s.jsxs(Kt,{className:"max-w-md",children:[ie,Ae]}),e[121]=ie,e[122]=Ae,e[123]=ye):ye=e[123];let He;e[124]!==xe||e[125]!==Ee||e[126]!==ye?(He=s.jsx(Ft,{open:xe,onOpenChange:Ee,children:ye}),e[124]=xe,e[125]=Ee,e[126]=ye,e[127]=He):He=e[127];const ue=i!==null;let Ce;e[128]===Symbol.for("react.memo_cache_sentinel")?(Ce=ze=>!ze&&r(null),e[128]=Ce):Ce=e[128];let De;e[129]!==n?(De=n("settings.commands.sidebar.renameDialog.title"),e[129]=n,e[130]=De):De=e[130];let Ye;e[131]!==De?(Ye=s.jsx(_t,{children:De}),e[131]=De,e[132]=Ye):Ye=e[132];const W=i?.name??"";let ke;e[133]!==n||e[134]!==W?(ke=n("settings.commands.sidebar.renameDialog.description",{name:W}),e[133]=n,e[134]=W,e[135]=ke):ke=e[135];let Ie;e[136]!==ke?(Ie=s.jsx($t,{children:ke}),e[136]=ke,e[137]=Ie):Ie=e[137];let Ge;e[138]!==Ye||e[139]!==Ie?(Ge=s.jsxs(Ut,{children:[Ye,Ie]}),e[138]=Ye,e[139]=Ie,e[140]=Ge):Ge=e[140];let it;e[141]===Symbol.for("react.memo_cache_sentinel")?(it=ze=>u(ze.target.value),e[141]=it):it=e[141];let nt;e[142]!==n?(nt=n("settings.commands.sidebar.renameDialog.placeholder"),e[142]=n,e[143]=nt):nt=e[143];let dt;e[144]!==me?(dt=ze=>{ze.key==="Enter"&&me()},e[144]=me,e[145]=dt):dt=e[145];let xt;e[146]!==l||e[147]!==nt||e[148]!==dt?(xt=s.jsx(Je,{value:l,onChange:it,placeholder:nt,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:dt}),e[146]=l,e[147]=nt,e[148]=dt,e[149]=xt):xt=e[149];let H;e[150]===Symbol.for("react.memo_cache_sentinel")?(H=()=>r(null),e[150]=H):H=e[150];let Be;e[151]!==n?(Be=n("settings.common.actions.cancel"),e[151]=n,e[152]=Be):Be=e[152];let tt;e[153]!==Be?(tt=s.jsx(B,{size:"sm",variant:"ghost",onClick:H,children:Be}),e[153]=Be,e[154]=tt):tt=e[154];let rt;e[155]!==n?(rt=n("settings.common.actions.rename"),e[155]=n,e[156]=rt):rt=e[156];let ut;e[157]!==me||e[158]!==rt?(ut=s.jsx(B,{size:"sm",onClick:me,children:rt}),e[157]=me,e[158]=rt,e[159]=ut):ut=e[159];let Ct;e[160]!==tt||e[161]!==ut?(Ct=s.jsxs(es,{children:[tt,ut]}),e[160]=tt,e[161]=ut,e[162]=Ct):Ct=e[162];let et;e[163]!==Ge||e[164]!==xt||e[165]!==Ct?(et=s.jsxs(Kt,{children:[Ge,xt,Ct]}),e[163]=Ge,e[164]=xt,e[165]=Ct,e[166]=et):et=e[166];let Xe;e[167]!==ue||e[168]!==et?(Xe=s.jsx(Ft,{open:ue,onOpenChange:Ce,children:et}),e[167]=ue,e[168]=et,e[169]=Xe):Xe=e[169];let ft;return e[170]!==Ke||e[171]!==Le||e[172]!==oe||e[173]!==He||e[174]!==Xe?(ft=s.jsxs("div",{className:Ke,children:[Le,oe,He,Xe]}),e[170]=Ke,e[171]=Le,e[172]=oe,e[173]=He,e[174]=Xe,e[175]=ft):ft=e[175],ft},ao=t=>{const e=mt.c(47),{command:a,isSelected:n,onSelect:i,onDelete:r,onReset:l,onRename:u,onDuplicate:p,isMenuOpen:h,onMenuOpenChange:d}=t,{t:w}=at();let c;e[0]===Symbol.for("react.memo_cache_sentinel")?(c=za(),e[0]=c):c=e[0];const N=c,[v,C]=o.useState(!1);let y;e[1]!==r||e[2]!==p||e[3]!==u||e[4]!==l||e[5]!==w?(y=J=>s.jsxs(s.Fragment,{children:[u&&s.jsxs(J,{onClick:X=>{X.stopPropagation(),u()},children:[s.jsx(O,{name:"edit",className:"h-4 w-4 mr-px"}),w("settings.common.actions.rename")]}),s.jsxs(J,{onClick:X=>{X.stopPropagation(),p()},children:[s.jsx(O,{name:"file-copy",className:"h-4 w-4 mr-px"}),w("settings.common.actions.duplicate")]}),l&&s.jsxs(J,{onClick:X=>{X.stopPropagation(),l()},children:[s.jsx(O,{name:"restart",className:"h-4 w-4 mr-px"}),w("settings.common.actions.reset")]}),r&&s.jsxs(J,{onClick:X=>{X.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(O,{name:"delete-bin",className:"h-4 w-4 mr-px"}),w("settings.common.actions.delete")]})]}),e[1]=r,e[2]=p,e[3]=u,e[4]=l,e[5]=w,e[6]=y):y=e[6];const S=y,g=n?"bg-interactive-selection":"hover:bg-interactive-hover";let T;e[7]!==g?(T=we("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",g),e[7]=g,e[8]=T):T=e[8];let R;e[9]===Symbol.for("react.memo_cache_sentinel")?(R=N?void 0:J=>{J.preventDefault(),C(!0)},e[9]=R):R=e[9];let A;e[10]!==T?(A=s.jsx("div",{className:T,onContextMenu:R}),e[10]=T,e[11]=A):A=e[11];let j;e[12]!==a.name?(j=s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["/",a.name]}),e[12]=a.name,e[13]=j):j=e[13];let f;e[14]!==a||e[15]!==w?(f=(a.scope||ca(a))&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:ca(a)?w("settings.agents.sidebar.badge.system"):a.scope}),e[14]=a,e[15]=w,e[16]=f):f=e[16];let b;e[17]!==j||e[18]!==f?(b=s.jsxs("div",{className:"flex items-center gap-2",children:[j,f]}),e[17]=j,e[18]=f,e[19]=b):b=e[19];let F;e[20]!==a.description?(F=a.description&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:a.description}),e[20]=a.description,e[21]=F):F=e[21];let D;e[22]!==i||e[23]!==F||e[24]!==b?(D=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-primary/50",tabIndex:0,children:[b,F]}),e[22]=i,e[23]=F,e[24]=b,e[25]=D):D=e[25];let P;e[26]!==d?(P=J=>{J&&C(!1),d(J)},e[26]=d,e[27]=P):P=e[27];let I;e[28]===Symbol.for("react.memo_cache_sentinel")?(I=s.jsx(sn,{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(O,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[28]=I):I=e[28];let U;e[29]!==S?(U=s.jsx(nn,{align:"end",className:"w-fit min-w-20",children:S(rn)}),e[29]=S,e[30]=U):U=e[30];let q;e[31]!==h||e[32]!==P||e[33]!==U?(q=s.jsxs(an,{open:h,onOpenChange:P,children:[I,U]}),e[31]=h,e[32]=P,e[33]=U,e[34]=q):q=e[34];let k;e[35]!==D||e[36]!==q?(k=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[D,q]}),e[35]=D,e[36]=q,e[37]=k):k=e[37];let $;e[38]!==k||e[39]!==A?($=s.jsx(qn,{render:A,children:k}),e[38]=k,e[39]=A,e[40]=$):$=e[40];let G;e[41]!==S?(G=s.jsx(Gn,{className:"w-fit min-w-20",children:S(Wn)}),e[41]=S,e[42]=G):G=e[42];let E;return e[43]!==v||e[44]!==$||e[45]!==G?(E=s.jsxs(Jn,{open:v,onOpenChange:C,children:[$,G]}),e[43]=v,e[44]=$,e[45]=G,e[46]=E):E=e[46],E};function Nu(t){return{selectedCommandName:t.selectedCommandName,setSelectedCommand:t.setSelectedCommand,setCommandDraft:t.setCommandDraft,createCommand:t.createCommand,deleteCommand:t.deleteCommand,loadCommands:t.loadCommands}}function Su(t){return t.loadSkills}function Cu(t){return t.name}function Pu(t){return!ca(t)}function Iu(t,e){return t.name.localeCompare(e.name)}function Au(t,e){return t.name.localeCompare(e.name)}const Tu=()=>{const{t}=at(),{selectedCommandName:e,getCommandByName:a,createCommand:n,updateCommand:i,commandDraft:r,setCommandDraft:l}=ua(Ds(I=>({selectedCommandName:I.selectedCommandName,getCommandByName:I.getCommandByName,createCommand:I.createCommand,updateCommand:I.updateCommand,commandDraft:I.commandDraft,setCommandDraft:I.setCommandDraft}))),u=Us(),p=ua(I=>dl(I,u)),h=e?a(e,u):null,d=!!(r&&r.name===e&&!h),[w,c]=o.useState(""),[N,v]=o.useState("user"),[C,y]=o.useState(""),[S,g]=o.useState(""),[T,R]=o.useState(""),[A,j]=o.useState(""),[f,b]=o.useState(!1),F=o.useRef(null);o.useEffect(()=>{if(d&&r){const I=r.name||"",U=r.scope||"user",q=r.description||"",k=r.agent||"",$=r.model||"",G=r.template||"";c(I),v(U),y(q),g(k),R($),j(G),F.current={draftName:I,draftScope:U,description:q,agent:k,model:$,template:G}}else if(h){const I=h.description||"",U=h.agent||"",q=h.model||"",k=h.template||"";y(I),g(U),R(q),j(k),F.current={draftName:"",draftScope:"user",description:I,agent:U,model:q,template:k}}},[h,d,e,p,r]);const D=o.useMemo(()=>{const I=F.current;return I?!!(d&&(w!==I.draftName||N!==I.draftScope)||C!==I.description||S!==I.agent||T!==I.model||A!==I.template):!1},[S,C,w,N,d,T,A]),P=async()=>{const I=d?w.trim().replace(/\s+/g,"-"):e?.trim();if(!I){M.error(t("settings.commands.sidebar.toast.commandNameRequired"));return}if(!A.trim()){M.error(t("settings.commands.page.toast.templateRequired"));return}if(d&&p.some(U=>U.name===I)){M.error(t("settings.commands.sidebar.toast.commandExists"));return}b(!0);try{const U=S.trim(),q=T.trim(),k=A.trim(),$={name:I,description:C.trim()||void 0,agent:U===""?null:U,model:q===""?null:q,template:k,scope:d?N:void 0};let G;if(d?(G=await n($,u),G&&l(null)):G=await i(I,$,u),G){const E=vn.getState().changes.some(J=>J.scope==="commands"&&J.id.startsWith(`commands:${I}:`));M.success(t(E?"settings.view.pendingRestart.saved":d?"settings.commands.page.toast.created":"settings.commands.page.toast.updated"))}else M.error(t(d?"settings.commands.page.toast.createFailed":"settings.commands.page.toast.updateFailed"))}catch(U){console.error("Error saving command:",U),M.error(t("settings.commands.page.toast.saveUnexpectedError"))}finally{b(!1)}};return e?s.jsxs(ns,{title:d?t("settings.commands.page.title.new"):`/${e}`,description:t(d?"settings.commands.page.subtitle.new":"settings.commands.page.subtitle.edit"),showSaveStatus:!1,children:[s.jsxs(_e,{title:t("settings.commands.page.section.identity"),divider:!1,contentClassName:"space-y-0",children:[d&&s.jsxs(Ot,{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(Je,{value:w,onChange:I=>c(I.target.value),placeholder:t("settings.commands.page.field.commandNamePlaceholder"),className:"h-7 w-40 px-2"})]}),s.jsxs(Pt,{value:N,onValueChange:I=>v(I),children:[s.jsx(It,{size:Lt,className:"w-fit min-w-[100px]",children:s.jsx(Rt,{placeholder:t("settings.agents.page.field.scopePlaceholder")})}),s.jsxs(At,{align:"end",children:[s.jsx(ot,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(O,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.common.scope.global")})]})}),s.jsx(ot,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(O,{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(Is,{value:C,onChange:I=>y(I.target.value),placeholder:t("settings.commands.page.field.descriptionPlaceholder"),rows:2,className:"w-full resize-none min-h-[60px] bg-transparent"})})]})]}),s.jsxs(_e,{title:t("settings.commands.page.section.executionContext"),contentClassName:"space-y-0",children:[s.jsx(Ot,{settingsItem:"commands.agent",label:t("settings.commands.page.field.overrideAgent"),children:s.jsx(ul,{agentName:S,onChange:I=>g(I),className:Mn})}),s.jsx(Ot,{settingsItem:"commands.model",label:t("settings.agents.page.field.overrideModel"),children:s.jsx(Oa,{providerId:da(T)?.providerId??"",modelId:da(T)?.modelId??"",onChange:(I,U)=>{R(I&&U?`${I}/${U}`:"")},className:Mn})})]}),s.jsxs(_e,{title:t("settings.commands.page.section.template"),settingsItem:"commands.template",children:[s.jsx(Is,{value:A,onChange:I=>j(I.target.value),placeholder:t("settings.commands.page.field.templatePlaceholder"),rows:12,className:"w-full font-mono typography-meta min-h-[160px] max-h-[60vh] bg-transparent resize-y"}),s.jsxs("p",{className:"mt-2 typography-meta text-muted-foreground",children:[s.jsx("code",{className:"text-foreground",children:"$ARGUMENTS"})," ",t("settings.commands.page.templateHint.userInput")," ·"," ",s.jsx("code",{className:"text-foreground",children:"!`cmd`"})," ",t("settings.commands.page.templateHint.shellOutput")," ·"," ",s.jsx("code",{className:"text-foreground",children:"@file"})," ",t("settings.commands.page.templateHint.fileContents")]}),s.jsx("div",{className:"pt-3",children:s.jsx(B,{onClick:P,disabled:f||!D,size:"xs",className:"!font-normal",children:t(f?"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(O,{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")})]})})},io=t=>{switch(t){case"connected":return"success";case"failed":return"error";case"needs_auth":case"needs_client_registration":return"warning";default:return"idle"}},ro=t=>{const e=mt.c(5),{tone:a,enabled:n}=t;if(!n){let l;return e[0]===Symbol.for("react.memo_cache_sentinel")?(l=s.jsx("span",{className:"inline-block h-2 w-2 rounded-full bg-muted-foreground/30 flex-shrink-0"}),e[0]=l):l=e[0],l}let i;e[1]!==a?(i=we("inline-block h-2 w-2 rounded-full flex-shrink-0",{success:"bg-[var(--status-success)]",error:"bg-[var(--status-error)]",warning:"bg-[var(--status-warning)]",idle:"bg-muted-foreground/40"}[a]),e[1]=a,e[2]=i):i=e[2];let r;return e[3]!==i?(r=s.jsx("span",{className:i}),e[3]=i,e[4]=r):r=e[4],r},Eu=t=>{const e=mt.c(124),{onItemSelect:a}=t,{t:n}=at(),{selectedMcpName:i,setSelectedMcp:r,setMcpDraft:l,loadMcpConfigs:u,deleteMcp:p}=pa(Ds(Du)),h=Us();let d;e[0]!==h?(d=W=>pl(W,h),e[0]=h,e[1]=d):d=e[1];const w=pa(d);let c;e[2]!==h?(c=W=>W.getStatusForDirectory(h),e[2]=h,e[3]=c):c=e[3];const N=Os(c),v=Os(Mu),C=Os(Ru),[y,S]=o.useState(null),[g,T]=o.useState(!1),[R,A]=o.useState(null),[j,f]=o.useState(null),[b,F]=o.useState(!1);let D;e[4]!==w?(D=w.filter(Ou),e[4]=w,e[5]=D):D=e[5];const P=D;let I;e[6]!==w?(I=w.filter(Lu),e[6]=w,e[7]=I):I=e[7];const U=I;let q,k;e[8]!==u||e[9]!==h?(q=()=>{u({directory:h})},k=[u,h],e[8]=u,e[9]=h,e[10]=q,e[11]=k):(q=e[10],k=e[11]),o.useEffect(q,k);let $;e[12]!==C||e[13]!==b||e[14]!==v||e[15]!==h?($=()=>{if(b)return;F(!0);const W=new Promise(Fu);Promise.all([v({directory:h,silent:!0}),W]).then(()=>{const ke=C(h);ke&&M.error(ke)}).finally(()=>{F(!1)})},e[12]=C,e[13]=b,e[14]=v,e[15]=h,e[16]=$):$=e[16];const G=$;let E;e[17]!==w||e[18]!==a||e[19]!==l||e[20]!==r?(E=()=>{let W="new-mcp-server",ke=1;for(;w.some(Ge=>Ge.name===W);)W=`new-mcp-server-${ke}`,ke++;l({name:W,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),r(W),a?.()},e[17]=w,e[18]=a,e[19]=l,e[20]=r,e[21]=E):E=e[21];const J=E;let X;e[22]!==p||e[23]!==y||e[24]!==h||e[25]!==n?(X=async()=>{if(!y)return;T(!0);const W=await p(y.name,h);W.ok?W.reloadFailed?M.warning(W.message||`MCP server "${y.name}" deleted, but OpenCode reload failed`,{description:W.warning||n("settings.mcp.sidebar.toast.refreshListIfStale")}):M.success(W.message||n("settings.mcp.sidebar.toast.serverDeleted",{name:y.name})):M.error(n("settings.mcp.sidebar.toast.deleteFailed")),S(null),T(!1)},e[22]=p,e[23]=y,e[24]=h,e[25]=n,e[26]=X):X=e[26];const L=X;let se;e[27]!==n?(se=(W,ke)=>s.jsxs(ke,{onClick:Ie=>{Ie.stopPropagation(),S(W)},className:"text-destructive focus:text-destructive",children:[s.jsx(O,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]}),e[27]=n,e[28]=se):se=e[28];const z=se;let V;e[29]===Symbol.for("react.memo_cache_sentinel")?(V=we("flex h-full flex-col","bg-background"),e[29]=V):V=e[29];let _;e[30]!==n?(_=n("settings.mcp.sidebar.title"),e[30]=n,e[31]=_):_=e[31];let K;e[32]!==_?(K=s.jsx("h2",{className:on,children:_}),e[32]=_,e[33]=K):K=e[33];let Z;e[34]!==n?(Z=n("settings.mcp.sidebar.actions.refreshStatusAria"),e[34]=n,e[35]=Z):Z=e[35];let Y;e[36]!==n?(Y=n("settings.mcp.sidebar.actions.refreshStatusTitle"),e[36]=n,e[37]=Y):Y=e[37];const te=b&&"animate-spin";let ge;e[38]!==te?(ge=we("h-4 w-4",te),e[38]=te,e[39]=ge):ge=e[39];let le;e[40]!==ge?(le=s.jsx(O,{name:"refresh",className:ge}),e[40]=ge,e[41]=le):le=e[41];let he;e[42]!==G||e[43]!==b||e[44]!==Z||e[45]!==Y||e[46]!==le?(he=s.jsx("button",{type:"button",className:"inline-flex h-7 w-7 items-center justify-center rounded-md text-muted-foreground transition-colors hover:text-foreground hover:bg-interactive-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary",disabled:b,onClick:G,"aria-label":Z,title:Y,children:le}),e[42]=G,e[43]=b,e[44]=Z,e[45]=Y,e[46]=le,e[47]=he):he=e[47];let ne;e[48]!==K||e[49]!==he?(ne=s.jsxs("div",{className:"mb-3 flex items-center justify-between gap-3",children:[K,he]}),e[48]=K,e[49]=he,e[50]=ne):ne=e[50];let ae;e[51]===Symbol.for("react.memo_cache_sentinel")?(ae=s.jsx(Va,{className:"mb-3"}),e[51]=ae):ae=e[51];let me;e[52]!==w.length||e[53]!==n?(me=n("settings.mcp.sidebar.total",{count:w.length}),e[52]=w.length,e[53]=n,e[54]=me):me=e[54];let Pe;e[55]!==me?(Pe=s.jsx("span",{className:"typography-meta text-muted-foreground",children:me}),e[55]=me,e[56]=Pe):Pe=e[56];let Ne;e[57]!==n?(Ne=n("settings.mcp.sidebar.actions.addServerTitle"),e[57]=n,e[58]=Ne):Ne=e[58];let Se;e[59]===Symbol.for("react.memo_cache_sentinel")?(Se=s.jsx(O,{name:"add",className:"h-3.5 w-3.5"}),e[59]=Se):Se=e[59];let be;e[60]!==J||e[61]!==Ne?(be=s.jsx(B,{size:"sm","data-settings-item":"mcp.create",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:J,title:Ne,children:Se}),e[60]=J,e[61]=Ne,e[62]=be):be=e[62];let Ke;e[63]!==Pe||e[64]!==be?(Ke=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Pe,be]}),e[63]=Pe,e[64]=be,e[65]=Ke):Ke=e[65];let Le;e[66]!==ne||e[67]!==Ke?(Le=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ne,ae,Ke]}),e[66]=ne,e[67]=Ke,e[68]=Le):Le=e[68];let oe;e[69]!==w.length||e[70]!==N||e[71]!==a||e[72]!==R||e[73]!==P||e[74]!==z||e[75]!==j||e[76]!==i||e[77]!==l||e[78]!==r||e[79]!==n||e[80]!==U?(oe=s.jsx(Bs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:w.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(O,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.mcp.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.mcp.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[P.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.mcp.sidebar.group.projectServers")}),P.map(W=>{const ke=N[W.name],Ie=io(ke?.status),Ge=i===W.name,it=za();return s.jsxs(Jn,{open:j===W.name,onOpenChange:nt=>f(nt?W.name:null),children:[s.jsxs(qn,{render:s.jsx("div",{className:we("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",Ge?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:it?void 0:nt=>{nt.preventDefault(),f(W.name)}}),children:[s.jsxs("button",{onClick:()=>{r(W.name),l(null),a?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ro,{tone:Ie,enabled:W.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:W.name}),s.jsx("span",{title:W.type==="local"?n("settings.mcp.sidebar.serverType.localTitle"):n("settings.mcp.sidebar.serverType.remoteTitle"),children:W.type==="local"?s.jsx(O,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(O,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:W.type==="local"?W.command?.join(" ")??"":W.url??""})]}),s.jsxs(an,{open:R===W.name,onOpenChange:nt=>{nt&&f(null),A(nt?W.name:null)},children:[s.jsx(sn,{asChild:!0,children:s.jsx(B,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(O,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(nn,{align:"end",className:"w-fit min-w-20",children:z(W,rn)})]})]}),s.jsx(Gn,{className:"w-fit min-w-20",children:z(W,Wn)})]},W.name)})]}),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:n("settings.mcp.sidebar.group.userServers")}),U.map(W=>{const ke=N[W.name],Ie=io(ke?.status),Ge=i===W.name,it=za();return s.jsxs(Jn,{open:j===W.name,onOpenChange:nt=>f(nt?W.name:null),children:[s.jsxs(qn,{render:s.jsx("div",{className:we("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",Ge?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:it?void 0:nt=>{nt.preventDefault(),f(W.name)}}),children:[s.jsxs("button",{onClick:()=>{r(W.name),l(null),a?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(ro,{tone:Ie,enabled:W.enabled}),s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:W.name}),s.jsx("span",{title:W.type==="local"?n("settings.mcp.sidebar.serverType.localTitle"):n("settings.mcp.sidebar.serverType.remoteTitle"),children:W.type==="local"?s.jsx(O,{name:"server",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"}):s.jsx(O,{name:"global",className:"h-3 w-3 text-muted-foreground/60 flex-shrink-0"})})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight pl-4",children:W.type==="local"?W.command?.join(" ")??"":W.url??""})]}),s.jsxs(an,{open:R===W.name,onOpenChange:nt=>{nt&&f(null),A(nt?W.name:null)},children:[s.jsx(sn,{asChild:!0,children:s.jsx(B,{size:"xs",variant:"ghost",className:"flex-shrink-0 -mr-1 opacity-100 transition-opacity md:opacity-0 md:group-hover:opacity-100",children:s.jsx(O,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(nn,{align:"end",className:"w-fit min-w-20",children:z(W,rn)})]})]}),s.jsx(Gn,{className:"w-fit min-w-20",children:z(W,Wn)})]},W.name)})]})]})}),e[69]=w.length,e[70]=N,e[71]=a,e[72]=R,e[73]=P,e[74]=z,e[75]=j,e[76]=i,e[77]=l,e[78]=r,e[79]=n,e[80]=U,e[81]=oe):oe=e[81];const xe=y!==null;let Ee;e[82]!==g?(Ee=W=>{!W&&!g&&S(null)},e[82]=g,e[83]=Ee):Ee=e[83];let Ve;e[84]!==n?(Ve=n("settings.mcp.sidebar.deleteDialog.title"),e[84]=n,e[85]=Ve):Ve=e[85];let $e;e[86]!==Ve?($e=s.jsx(_t,{children:Ve}),e[86]=Ve,e[87]=$e):$e=e[87];const We=y?.name||"";let Fe;e[88]!==n||e[89]!==We?(Fe=n("settings.mcp.sidebar.deleteDialog.descriptionPrefix",{name:We}),e[88]=n,e[89]=We,e[90]=Fe):Fe=e[90];let ie;e[91]===Symbol.for("react.memo_cache_sentinel")?(ie=s.jsx("code",{className:"text-foreground",children:"opencode.json"}),e[91]=ie):ie=e[91];let re;e[92]!==Fe?(re=s.jsxs($t,{children:[Fe," ",ie,"."]}),e[92]=Fe,e[93]=re):re=e[93];let je;e[94]!==$e||e[95]!==re?(je=s.jsxs(Ut,{children:[$e,re]}),e[94]=$e,e[95]=re,e[96]=je):je=e[96];let ve;e[97]===Symbol.for("react.memo_cache_sentinel")?(ve=()=>S(null),e[97]=ve):ve=e[97];let Re;e[98]!==n?(Re=n("settings.common.actions.cancel"),e[98]=n,e[99]=Re):Re=e[99];let Ae;e[100]!==g||e[101]!==Re?(Ae=s.jsx(B,{size:"sm",variant:"ghost",onClick:ve,disabled:g,children:Re}),e[100]=g,e[101]=Re,e[102]=Ae):Ae=e[102];let ye;e[103]!==g||e[104]!==n?(ye=n(g?"settings.mcp.sidebar.actions.deleting":"settings.common.actions.delete"),e[103]=g,e[104]=n,e[105]=ye):ye=e[105];let He;e[106]!==L||e[107]!==g||e[108]!==ye?(He=s.jsx(B,{size:"sm",onClick:L,disabled:g,children:ye}),e[106]=L,e[107]=g,e[108]=ye,e[109]=He):He=e[109];let ue;e[110]!==Ae||e[111]!==He?(ue=s.jsxs(es,{children:[Ae,He]}),e[110]=Ae,e[111]=He,e[112]=ue):ue=e[112];let Ce;e[113]!==je||e[114]!==ue?(Ce=s.jsxs(Kt,{className:"max-w-md",children:[je,ue]}),e[113]=je,e[114]=ue,e[115]=Ce):Ce=e[115];let De;e[116]!==xe||e[117]!==Ee||e[118]!==Ce?(De=s.jsx(Ft,{open:xe,onOpenChange:Ee,children:Ce}),e[116]=xe,e[117]=Ee,e[118]=Ce,e[119]=De):De=e[119];let Ye;return e[120]!==Le||e[121]!==oe||e[122]!==De?(Ye=s.jsxs("div",{className:V,children:[Le,oe,De]}),e[120]=Le,e[121]=oe,e[122]=De,e[123]=Ye):Ye=e[123],Ye};function Du(t){return{selectedMcpName:t.selectedMcpName,setSelectedMcp:t.setSelectedMcp,setMcpDraft:t.setMcpDraft,loadMcpConfigs:t.loadMcpConfigs,deleteMcp:t.deleteMcp}}function Mu(t){return t.refresh}function Ru(t){return t.getErrorForDirectory}function Ou(t){return t.scope==="project"}function Lu(t){return t.scope!=="project"}function Fu(t){return setTimeout(t,500)}function Xs(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Sa(t){return Array.isArray(t)&&t.every(e=>typeof e=="string")}function Zs(t,e){return e!==void 0?{ok:!1,error:t,parsed:e}:{ok:!1,error:t}}function Ya(t,e,a){const n=Ku(a),i=typeof a.url=="string"?a.url.trim():"",r=oo(a,"env","environment"),l=oo(a,"headers"),u=zu(a),p=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.clientId??"").trim():"",h=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.clientSecret??"").trim():"",d=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.scope??"").trim():"",w=typeof a.oauth=="object"&&a.oauth!==null?String(a.oauth.redirectUri??"").trim():"",c=Uu(a),N=_u(a);return{ok:!0,name:t,type:e,command:n,url:i,environment:r,headers:l,oauthEnabled:u,oauthClientId:p,oauthClientSecret:h,oauthScope:d,oauthRedirectUri:w,timeout:c,enabled:N}}function Ku(t){const e=t.command,a=t.args;if(Sa(e)&&Sa(a))return[...e,...a];if(Sa(e))return e;if(typeof e=="string"&&e.trim()){const n=e.trim().split(/\s+/);return Sa(a)?[...n,...a]:n}return Sa(a)?a:[]}function oo(t,...e){for(const a of e){const n=t[a];if(!Xs(n))continue;const i=Object.entries(n).filter(([r,l])=>r&&typeof l=="string");if(i.length>0)return i.map(([r,l])=>({key:r,value:String(l)}))}return[]}function zu(t){if(t.oauth===!1||t.oauth===null||t.oauth===void 0||!Xs(t.oauth))return!1;const e=t.oauth;return!!(typeof e.clientId=="string"&&e.clientId.trim()||typeof e.clientSecret=="string"&&e.clientSecret.trim()||typeof e.scope=="string"&&e.scope.trim()||typeof e.redirectUri=="string"&&e.redirectUri.trim())}function Uu(t){const e=t.timeout;if(typeof e=="number"&&Number.isFinite(e)&&e>0)return String(Math.floor(e));if(typeof e=="string"&&e.trim()){const a=Number(e);if(Number.isFinite(a)&&a>0)return String(Math.floor(a))}return""}function _u(t){return"disabled"in t&&t.disabled===!0?!1:"enabled"in t?!!t.enabled:!0}function $u(t){const e=t.mcpServers;if(Xs(e)){const n=Object.keys(e);if(n.length===1){const i=n[0],r=e[i];if(Xs(r))return{name:i,entry:r}}if(n.length>1)return null}const a=Object.keys(t).filter(n=>{const i=t[n];return n!=="mcpServers"&&Xs(i)});if(a.length===1){const n=a[0],i=t[n];if(Rl(i))return{name:n,entry:i}}return null}function Rl(t){return t.type==="local"||t.type==="remote"||Array.isArray(t.command)||typeof t.url=="string"||Array.isArray(t.args)}function Vu(t,e){let a;try{const u=t.trim();if(!u)return Zs("No JSON content provided");a=JSON.parse(u)}catch(u){return Zs(u instanceof Error?`Invalid JSON: ${u.message}`:"Invalid JSON")}if(!Xs(a))return Zs("Expected a JSON object, not an array or primitive");const n=a,i=n.mcpServers;if(Xs(i)){const u=Object.keys(i);if(u.length===0)return Zs("mcpServers object is empty",a);if(u.length>1)return Zs("Paste one server at a time. Found "+u.length+" servers in mcpServers",a);const p=u[0],h=i[p];return Xs(h)?Ya(p,Za(h),h):Zs("Server entry is not a valid object",a)}const r=n.mcp;if(Xs(r)){const u=Object.keys(r);if(u.length===0)return Zs("mcp object is empty",a);if(u.length>1)return Zs("Paste one server at a time. Found "+u.length+" servers in mcp",a);const p=u[0],h=r[p];return Xs(h)?Ya(p,Za(h),h):Zs("Server entry in mcp is not a valid object",a)}const l=$u(n);if(l)return Ya(l.name,Za(l.entry),l.entry);if(Rl(n)){const u=Za(n),p=typeof n.name=="string"&&n.name.trim()?n.name.trim():e?.fallbackName;return Ya(p,u,n)}return Zs("No recognizable MCP server configuration found in JSON",a)}function Za(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 Bu(t,e,a){const n=a?.isNewServer??!1,i=t.name,r=n&&i?i:e.name??"";return{...e,name:r,type:t.type,command:t.type==="local"?t.command:[],url:t.type==="remote"?t.url:"",environment:t.environment,headers:t.type==="remote"?t.headers:[],oauthEnabled:t.type==="remote"?t.oauthEnabled:!1,oauthClientId:t.type==="remote"?t.oauthClientId:"",oauthClientSecret:t.type==="remote"?t.oauthClientSecret:"",oauthScope:t.type==="remote"?t.oauthScope:"",oauthRedirectUri:t.type==="remote"?t.oauthRedirectUri:"",timeout:t.type==="remote"?t.timeout:"",enabled:t.enabled}}function Ol(t){const e=[];let a="",n=!1,i=!1;for(let r=0;r<t.length;r++){const l=t[r];if(l==="'"&&!i){n=!n;continue}if(l==='"'&&!n){i=!i;continue}if((l===" "||l===" ")&&!n&&!i){a&&(e.push(a),a="");continue}a+=l}return a&&e.push(a),e}function Hu(t){const e=t.trim();if(!e)return{code:null,context:null,stateKey:null};try{const a=new URL(e),n=a.searchParams.get("code");if(typeof n=="string"&&n.trim())return{code:n.trim(),context:fc(a.searchParams),stateKey:ml(a.searchParams)}}catch{}return{code:e,context:null,stateKey:null}}const Gu=t=>{const e=mt.c(27),{value:a,onChange:n,preview:i,onDetectUrl:r}=t;let l;e[0]!==a?(l=()=>a.join(`
4
- `),e[0]=a,e[1]=l):l=e[1];const[u,p]=o.useState(l),h=o.useRef(a);let d,w;e[2]!==a?(d=()=>{JSON.stringify(h.current)!==JSON.stringify(a)&&(h.current=a,p(a.join(`
5
- `)))},w=[a],e[2]=a,e[3]=d,e[4]=w):(d=e[3],w=e[4]),o.useEffect(d,w);let c;e[5]!==n||e[6]!==r?(c=j=>{const f=j.split(`
6
- `).filter(ep);if(r&&f.length===1&&/^https?:\/\/\S+$/i.test(f[0].trim())){r(f[0].trim());return}n(f)},e[5]=n,e[6]=r,e[7]=c):c=e[7];const N=c;let v;e[8]!==n?(v=j=>{const b=j.clipboardData.getData("text").trim();if(!b||b.includes(`
7
- `)||!/\s/.test(b))return;const F=j.currentTarget;if(F.selectionStart!==0||F.selectionEnd!==F.value.length)return;j.preventDefault();const D=Ol(b);p(D.join(`
8
- `)),n(D)},e[8]=n,e[9]=v):v=e[9];const C=v;let y;e[10]!==N?(y=j=>{p(j.target.value),N(j.target.value)},e[10]=N,e[11]=y):y=e[11];let S;e[12]!==N||e[13]!==u?(S=()=>{const j=u.split(`
9
- `).map(tp).join(`
10
- `);p(j),N(j)},e[12]=N,e[13]=u,e[14]=S):S=e[14];const g=Math.max(4,a.length+1);let T;e[15]!==C||e[16]!==y||e[17]!==S||e[18]!==g||e[19]!==u?(T=s.jsx(Is,{onPaste:C,value:u,onChange:y,onBlur:S,placeholder:`npx
11
- -y
12
- @modelcontextprotocol/server-postgres
13
- postgresql://user:pass@host/db`,rows:g,className:"font-mono typography-meta min-h-[80px]",spellCheck:!1}),e[15]=C,e[16]=y,e[17]=S,e[18]=g,e[19]=u,e[20]=T):T=e[20];let R;e[21]!==i||e[22]!==a?(R=a.length>0&&s.jsxs("details",{className:"group",children:[s.jsx("summary",{className:"typography-micro text-muted-foreground/60 cursor-pointer select-none hover:text-muted-foreground",children:i(a.length)}),s.jsx("div",{className:"mt-1 rounded-md bg-[var(--surface-elevated)] px-3 py-2 overflow-x-auto",children:s.jsx("code",{className:"typography-micro text-foreground/80 whitespace-pre",children:a.map(sp)})})]}),e[21]=i,e[22]=a,e[23]=R):R=e[23];let A;return e[24]!==R||e[25]!==T?(A=s.jsxs("div",{className:"space-y-2","data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",children:[T,R]}),e[24]=R,e[25]=T,e[26]=A):A=e[26],A},Wu=t=>t.toUpperCase().replace(/[^A-Z0-9_]/g,"_"),lo=({value:t,onChange:e,keyTransform:a=Wu,keyPlaceholder:n="API_KEY",keyInputClassName:i="w-36 shrink-0 font-mono typography-meta uppercase",pasteLabel:r="Paste .env",pasteTitle:l="Paste KEY=VALUE lines from clipboard",noPairsFoundError:u,importSuccess:p,clipboardReadFailed:h,keyLabel:d,valueLabel:w,valuePlaceholder:c,hideValueTitle:N,showValueTitle:v,addVariable:C,plainTextWarning:y,removeVariableAria:S})=>{const[g,T]=o.useState(new Set),R=()=>e([...t,{key:"",value:""}]),A=D=>{e(t.filter((P,I)=>I!==D)),T(P=>{const I=new Set(P);return I.delete(D),I})},j=(D,P,I)=>{const U=[...t];U[D]={...U[D],[P]:I},e(U)},f=D=>{T(P=>{const I=new Set(P);return I.has(D)?I.delete(D):I.add(D),I})},b=async()=>{try{const D=await navigator.clipboard.readText(),P=[];for(const U of D.split(`
14
- `)){const q=U.trim();if(!q||q.startsWith("#"))continue;const k=q.indexOf("=");if(k===-1)continue;const $=q.slice(0,k).trim();let G=q.slice(k+1).trim();(G.startsWith('"')&&G.endsWith('"')||G.startsWith("'")&&G.endsWith("'"))&&(G=G.slice(1,-1)),$&&P.push({key:$,value:G})}if(P.length===0){M.error(u);return}const I=[...t];for(const U of P){const q=I.findIndex(k=>k.key===U.key);q!==-1?I[q]=U:I.push(U)}e(I),M.success(p(P.length))}catch{M.error(h)}},F=t.some(D=>D.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:d}),s.jsx("span",{className:"typography-micro text-muted-foreground",children:w})]}),s.jsxs(B,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:b,type:"button",title:l,children:[s.jsx(O,{name:"clipboard",className:"h-3 w-3"}),r]})]}),s.jsx("div",{className:"space-y-1.5",children:t.map((D,P)=>s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Je,{value:D.key,onChange:I=>j(P,"key",a(I.target.value)),placeholder:n,className:i,"data-bwignore":"true","data-1p-ignore":"true","data-lpignore":"true",spellCheck:!1}),s.jsxs("div",{className:"relative flex-1 flex items-center",children:[s.jsx(Je,{type:g.has(P)?"text":"password",value:D.value,onChange:I=>j(P,"value",I.target.value),placeholder:c,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:()=>f(P),className:"absolute right-2 text-muted-foreground/60 hover:text-muted-foreground",title:g.has(P)?N:v,children:g.has(P)?s.jsx(O,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(O,{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:()=>A(P),"aria-label":S,children:s.jsx(O,{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:R,type:"button",children:[s.jsx(O,{name:"add",className:"h-3.5 w-3.5"}),C]}),F&&s.jsx("p",{className:"typography-micro text-muted-foreground/60",children:y})]})},zi=t=>{const e=mt.c(14),{status:a,enabled:n,getStatusLabel:i,variant:r}=t,l=r===void 0?"compact":r;if(!n||!a)return null;let u,p;if(e[0]!==i||e[1]!==a||e[2]!==l){p=Symbol.for("react.early_return_sentinel");e:{const c={connected:{text:"text-[var(--status-success)]",bg:"bg-[var(--status-success)]/10"},failed:{text:"text-[var(--status-error)]",bg:"bg-[var(--status-error)]/10"},needs_auth:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"},needs_client_registration:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"},awaiting_restart:{text:"text-[var(--status-warning)]",bg:"bg-[var(--status-warning)]/10"}}[a]??{text:"text-muted-foreground",bg:""};if(l==="pill"){const N=we("typography-micro font-medium rounded-full px-2 py-0.5",c.text,c.bg);let v;e[5]!==i||e[6]!==a?(v=i(a),e[5]=i,e[6]=a,e[7]=v):v=e[7],p=s.jsxs("span",{className:N,children:["● ",v]});break e}u=we("typography-micro font-medium",c.text)}e[0]=i,e[1]=a,e[2]=l,e[3]=u,e[4]=p}else u=e[3],p=e[4];if(p!==Symbol.for("react.early_return_sentinel"))return p;let h;e[8]!==i||e[9]!==a?(h=i(a),e[8]=i,e[9]=a,e[10]=h):h=e[10];let d;return e[11]!==u||e[12]!==h?(d=s.jsxs("span",{className:u,children:["● ",h]}),e[11]=u,e[12]=h,e[13]=d):d=e[13],d},qu=(t,e,a)=>{switch(t){case"connected":return e("settings.mcp.page.status.description.connected");case"failed":return a?.trim()||e("settings.mcp.page.status.description.failedDefault");case"needs_auth":return e("settings.mcp.page.status.description.needsAuth");case"needs_client_registration":return a?.trim()||e("settings.mcp.page.status.description.needsClientRegistrationDefault");case"disabled":return e("settings.mcp.page.status.description.disabled");default:return e("settings.mcp.page.status.description.default")}},Ju=t=>{switch(t){case"failed":return"border-[var(--status-error-border)] bg-[var(--status-error-background)]";case"needs_auth":case"needs_client_registration":return"border-[var(--status-warning-border)] bg-[var(--status-warning-background)]";default:return"border-[var(--interactive-border)] bg-[var(--surface-elevated)]"}},Qu=(t,e,a,n)=>!!(t==="failed"||t==="needs_auth"||t==="needs_client_registration"||e||a||n),Yu=async t=>{const e=await pt(`/api/mcp/auth/pending?state=${encodeURIComponent(t)}`);if(!e.ok)return null;const a=await e.json().catch(()=>null);return a?.name?.trim()?{name:a.name.trim(),directory:typeof a.directory=="string"&&a.directory.trim()?a.directory.trim():null}:null},Ca=async t=>{typeof t!="string"||!t.trim()||await pt(`/api/mcp/auth/pending?state=${encodeURIComponent(t.trim())}`,{method:"DELETE"}).catch(()=>{})},Xa=(t,e,a)=>{const n=t instanceof Error?t.message:e;return/oauth state required/i.test(n)?a("settings.mcp.page.toast.authSessionExpired"):n},Zu=(t,e)=>{const a=typeof e=="string"&&e.trim()?e.trim():"__global__";return`${t??"__none__"}::${a}`},Xu=()=>{const{t}=at(),e=o.useCallback((ce,ht)=>t(ce,ht),[t]),{selectedMcpName:a,mcpDraft:n,setMcpDraft:i,setSelectedMcp:r,getMcpByName:l,createMcp:u,updateMcp:p,deleteMcp:h}=pa(Ds(ce=>({selectedMcpName:ce.selectedMcpName,mcpDraft:ce.mcpDraft,setMcpDraft:ce.setMcpDraft,setSelectedMcp:ce.setSelectedMcp,getMcpByName:ce.getMcpByName,createMcp:ce.createMcp,updateMcp:ce.updateMcp,deleteMcp:ce.deleteMcp}))),d=Us(),w=o.useMemo(()=>us(),[]),c=Os(ce=>ce.getStatusForDirectory(d)),N=Os(ce=>ce.getDiagnosticForDirectory(d)),v=Os(ce=>ce.refresh),C=Os(ce=>ce.connect),y=Os(ce=>ce.disconnect),S=Os(ce=>ce.completeAuth),g=Os(ce=>ce.clearAuth),T=Os(ce=>ce.testConnection),R=vn(ce=>ce.changes),A=pa(ce=>pl(ce,d)),j=a?l(a,d):null,f=!!(n&&n.name===a&&!j),[b,F]=o.useState(""),[D,P]=o.useState("user"),[I,U]=o.useState("local"),[q,k]=o.useState([]),[$,G]=o.useState(""),[E,J]=o.useState([]),[X,L]=o.useState([]),[se,z]=o.useState(!0),[V,_]=o.useState(""),[K,Z]=o.useState(""),[Y,te]=o.useState(""),[ge,le]=o.useState(""),[he,ne]=o.useState(""),[ae,me]=o.useState(!0),[Pe,Ne]=o.useState(!1),[Se,be]=o.useState(!1),[Ke,Le]=o.useState(!1),[oe,xe]=o.useState(!1),[Ee,Ve]=o.useState(!1),[$e,We]=o.useState(!1),[Fe,ie]=o.useState(!1),[re,je]=o.useState(!1),[ve,Re]=o.useState(null),[Ae,ye]=o.useState(null),[He,ue]=o.useState(""),[Ce,De]=o.useState(!1),Ye=o.useRef(0),W=o.useRef(!1),[ke,Ie]=o.useState(!1),[Ge,it]=o.useState(!1),[nt,dt]=o.useState(""),[xt,H]=o.useState(null),Be=o.useMemo(()=>Zu(a,d),[d,a]),tt=o.useRef(Be),rt=o.useRef(null),ut=o.useCallback(()=>{Re(null),ye(null),ue(""),De(!1),Ye.current=0,je(!1),Ve(!1),We(!1),W.current=!1},[]),Ct=o.useCallback(()=>{dt(""),H(null),it(!0)},[]),et=o.useCallback(async()=>{try{const ce=await navigator.clipboard.readText();dt(ce),H(null)}catch{M.error(t("settings.mcp.page.toast.clipboardReadFailed"))}},[t]),Xe=o.useCallback(()=>{const ce=Vu(nt,{fallbackName:b});if(!ce.ok){H(ce.error);return}const bt=Bu(ce,{name:b,scope:D,type:I,command:q,url:$,environment:E,headers:X,oauthEnabled:se,oauthClientId:V,oauthClientSecret:K,oauthScope:Y,oauthRedirectUri:ge,timeout:he,enabled:ae},{isNewServer:f});F(bt.name),U(bt.type),k(bt.command??[]),G(bt.url??""),J(bt.environment??[]),L(bt.headers??[]),z(bt.oauthEnabled??!1),_(bt.oauthClientId??""),Z(bt.oauthClientSecret??""),te(bt.oauthScope??""),le(bt.oauthRedirectUri??""),ne(bt.timeout??""),me(bt.enabled??!0),it(!1),dt(""),H(null),M.success(t("settings.mcp.page.toast.configImported"))},[nt,b,D,I,q,$,E,X,se,V,K,Y,ge,he,ae,f,t]);o.useEffect(()=>{if(f&&n){F(n.name),P(n.scope||"user"),U(n.type),k(n.command),G(n.url),J(n.environment),L(n.headers),z(n.oauthEnabled),_(n.oauthClientId),Z(n.oauthClientSecret),te(n.oauthScope),le(n.oauthRedirectUri),ne(n.timeout),me(n.enabled),Ie(!1),rt.current={mcpType:n.type,command:n.command,url:n.url,envEntries:n.environment,headerEntries:n.headers,oauthEnabled:n.oauthEnabled,oauthClientId:n.oauthClientId,oauthClientSecret:n.oauthClientSecret,oauthScope:n.oauthScope,oauthRedirectUri:n.oauthRedirectUri,timeout:n.timeout,enabled:n.enabled};return}if(j){P(j.scope==="project"?"project":"user");const ce=Ar(j.environment),ht=j.type==="remote"?j:null,bt=Ar(ht?.headers),Qt=ht?.oauth,Yt=Qt&&typeof Qt=="object"?Qt:null,Ht=Qt!==!1,as=j.type,ws=as==="local"?j.command??[]:[],cs=as==="remote"?j.url??"":"",St=typeof ht?.timeout=="number"&&Number.isFinite(ht.timeout)?String(ht.timeout):"";U(as),k(ws),G(cs),J(ce),L(bt),z(Ht),_(Ht?Yt?.clientId??"":""),Z(Ht?Yt?.clientSecret??"":""),te(Ht?Yt?.scope??"":""),le(Ht?Yt?.redirectUri??"":""),ne(St),me(j.enabled),Ie(!1),rt.current={mcpType:as,command:ws,url:cs,envEntries:ce,headerEntries:bt,oauthEnabled:Ht,oauthClientId:Ht?Yt?.clientId??"":"",oauthClientSecret:Ht?Yt?.clientSecret??"":"",oauthScope:Ht?Yt?.scope??"":"",oauthRedirectUri:Ht?Yt?.redirectUri??"":"",timeout:St,enabled:j.enabled}}},[j,f,n]);const ft=o.useMemo(()=>{const ce=rt.current;return ce?I!==ce.mcpType||ae!==ce.enabled||JSON.stringify(q)!==JSON.stringify(ce.command)||$!==ce.url||JSON.stringify(E)!==JSON.stringify(ce.envEntries)||JSON.stringify(X)!==JSON.stringify(ce.headerEntries)||se!==ce.oauthEnabled||V!==ce.oauthClientId||K!==ce.oauthClientSecret||Y!==ce.oauthScope||ge!==ce.oauthRedirectUri||he!==ce.timeout:!1},[I,q,$,E,X,se,V,K,Y,ge,he,ae]),ze=o.useMemo(()=>[{id:"local",label:t("settings.mcp.page.connection.kindCommand"),icon:s.jsx(O,{name:"terminal",className:"h-3.5 w-3.5"})},{id:"remote",label:t("settings.mcp.page.connection.kindLink"),icon:s.jsx(O,{name:"global",className:"h-3.5 w-3.5"})}],[t]),jt=o.useCallback(ce=>{U("remote"),G(ce),k([])},[]),Te=o.useCallback(ce=>{G(ce);const ht=ce.trim();ht&&!/^[a-z][a-z0-9+.-]*:\/\//i.test(ht)&&/\s/.test(ht)&&(U("local"),k(Ol(ht)),G(""))},[]),wt=async()=>{const ce=f?b.trim():a??"";if(!ce){M.error(t("settings.mcp.page.toast.nameRequired"));return}if(f&&A.some(bt=>bt.name===ce)){M.error(t("settings.mcp.page.toast.serverNameExists"));return}if(I==="local"&&q.filter(Boolean).length===0){M.error(t("settings.mcp.page.toast.localCommandRequired"));return}if(I==="remote"&&!$.trim()){M.error(t("settings.mcp.page.toast.remoteUrlRequired"));return}const ht={name:ce,scope:D,type:I,command:q,url:$,environment:E,headers:X,oauthEnabled:se,oauthClientId:V,oauthClientSecret:K,oauthScope:Y,oauthRedirectUri:ge,timeout:he,enabled:ae};Ne(!0);try{const bt=f?await u(ht,d):await p(ce,ht,d);bt.ok?(await Ca(Ae),ut(),f&&(i(null),r(ce)),await v({directory:d,silent:!0}),bt.reloadFailed?M.warning(bt.message||t(f?"settings.mcp.page.toast.serverCreatedReloadFailed":"settings.mcp.page.toast.savedReloadFailed"),{description:bt.warning||t("settings.mcp.page.toast.retryRefreshHint")}):bt.restartDeferred?M.success(t("settings.view.pendingRestart.saved")):M.success(bt.message||t(f?"settings.mcp.page.toast.serverCreatedReloading":"settings.mcp.page.toast.savedReloading"))):M.error(t("settings.mcp.page.toast.saveFailed"))}catch(bt){M.error(bt instanceof Error?bt.message:t("settings.mcp.page.toast.unexpectedError"))}finally{Ne(!1)}},Q=async()=>{if(!a)return;Le(!0);const ce=await h(a,d);ce.ok?(await Ca(Ae),ut(),ce.reloadFailed?M.warning(ce.message||t("settings.mcp.page.toast.serverDeletedReloadFailed",{name:a}),{description:ce.warning||t("settings.mcp.page.toast.refreshListIfStale")}):M.success(ce.message||t("settings.mcp.page.toast.serverDeleted",{name:a})),be(!1)):M.error(t("settings.mcp.page.toast.deleteFailed")),Le(!1)},fe=async()=>{if(a){xe(!0);try{if(c[a]?.status==="connected")await y(a,d),M.success(t("settings.mcp.page.toast.disconnected"));else{await C(a,d),await v({directory:d,silent:!0});const ht=Os.getState().getStatusForDirectory(d)[a];ht?.status==="connected"?M.success(t("settings.mcp.page.toast.connected")):ht?.status==="needs_auth"?M.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):ht?.status==="needs_client_registration"?M.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):ht?.status==="failed"?M.error(ht.error||t("settings.mcp.page.toast.connectionFailed")):M.message(t("settings.mcp.page.toast.connectionAttemptFinished"));return}await v({directory:d,silent:!0})}catch(ce){M.error(ce instanceof Error?ce.message:t("settings.mcp.page.toast.connectionFailed"))}finally{xe(!1)}}},Ue=o.useCallback(()=>f?(M.error(t("settings.mcp.page.toast.createServerBeforeLiveActions")),!1):ft?(M.error(t("settings.mcp.page.toast.saveBeforeLiveActions")),!1):!0,[ft,f,t]),Me=o.useCallback(async(ce=!1)=>{try{await v({directory:d,silent:ce})}catch(ht){ce||M.error(ht instanceof Error?ht.message:t("settings.mcp.page.toast.refreshStatusFailed"))}},[d,v,t]);o.useEffect(()=>{Me(!0)},[Me]),o.useEffect(()=>{tt.current=Be,xe(!1),ie(!1),ut()},[ut,Be]);const ct=o.useCallback(async()=>{if(!a||I!=="remote"||!Ue())return;Ve(!0);const ce=Be;let ht=null;try{const bt=Os.getState().getStatusForDirectory(d)[a]?.status;W.current=bt==="needs_auth"||bt==="needs_client_registration";const{authorizationUrl:Qt,opened:Yt,nativeFlow:Ht,completion:as}=await mc({name:a,directory:d});if(Ht){if(tt.current!==ce)return;Re(null),ye(null),De(!0),Ye.current=0,M.message(t("settings.mcp.page.toast.completeAuthorizationInBrowser")),as?.then(()=>{tt.current===ce&&(De(!1),Ye.current=0,W.current=!1,M.success(t("settings.mcp.page.toast.authorizationCompleted")))}).catch(cs=>{tt.current===ce&&(De(!1),Ye.current=0,W.current=!1,M.error(Xa(cs,t("settings.mcp.page.toast.authorizationFailed"),e)))});return}const ws=ml(new URL(Qt).searchParams);if(ht=ws,tt.current!==ce||(Re(Qt),ye(ws??null),De(!0),Ye.current=0,tt.current!==ce))return;Yt?M.message(t(w?"settings.mcp.page.toast.completeAuthorizationInBrowserWithPaste":"settings.mcp.page.toast.completeAuthorizationInBrowser")):M.error(t("settings.mcp.page.toast.openAuthorizationUrlFailed"))}catch(bt){await Ca(ht),tt.current===ce&&M.error(Xa(bt,t("settings.mcp.page.toast.authorizationStartFailed"),e))}finally{tt.current===ce&&Ve(!1)}},[d,w,I,Ue,Be,a,t,e]),lt=o.useCallback(async()=>{if(!a||!Ue())return;We(!0);const ce=Be;try{if(await g(a,d),tt.current!==ce)return;Re(null),ye(null),ue(""),De(!1),Ye.current=0,await Ca(Ae),M.success(t("settings.mcp.page.toast.savedAuthorizationRemoved"))}catch(ht){tt.current===ce&&M.error(Xa(ht,t("settings.mcp.page.toast.clearAuthorizationFailed"),e))}finally{tt.current===ce&&We(!1)}},[Ae,g,d,Ue,Be,a,t,e]),Qe=o.useCallback(async()=>{if(!ve)return;if((await La(ve)).ok){M.success(t("settings.mcp.page.toast.authorizationUrlCopied"));return}M.error(t("settings.mcp.page.toast.authorizationUrlCopyFailed"))},[ve,t]),Nt=o.useCallback(async()=>{const ce=Hu(He);if(!ce.code){M.error(t("settings.mcp.page.toast.pasteCallbackOrCodeFirst"));return}const ht=ce.stateKey?await Yu(ce.stateKey):null,bt=ce.context??ht,Qt=bt?.name??a,Yt=bt?.directory??d;if(!Qt){M.error(t("settings.mcp.page.toast.missingServerDetails"));return}if(!bt&&!Ue())return;je(!0);const Ht=Be;try{if(await S(Qt,ce.code,Yt),await Ca(ce.stateKey??Ae),tt.current!==Ht)return;ue(""),Re(null),ye(null),De(!1),Ye.current=0,M.success(Qt===a?t("settings.mcp.page.toast.authorizationCompleted"):t("settings.mcp.page.toast.authorizationCompletedFor",{name:Qt}))}catch(as){tt.current===Ht&&M.error(Xa(as,t("settings.mcp.page.toast.authorizationCompleteFailed"),e))}finally{tt.current===Ht&&je(!1)}},[He,Ae,S,d,Ue,Be,a,t,e]),xs=o.useCallback(async()=>{if(!(!a||!Ue())){if(!ae){M.error(t("settings.mcp.page.toast.enableServerBeforeTest"));return}ie(!0);try{const ce=await T(a,d),ht=ce.status?.status;ce.warning?M.warning(ce.warning):ht==="connected"?M.success(t("settings.mcp.page.toast.connectionTestSucceeded")):ht==="needs_auth"?M.message(t("settings.mcp.page.toast.connectionNeedsAuthorization")):ht==="needs_client_registration"?M.message(t("settings.mcp.page.toast.connectionNeedsClientRegistration")):ht==="failed"?M.error(ce.status?.error||ce.error||t("settings.mcp.page.toast.connectionTestFailed")):ce.error?M.error(ce.error):M.message(t("settings.mcp.page.toast.connectionTestFinished"))}catch(ce){M.error(ce instanceof Error?ce.message:t("settings.mcp.page.toast.connectionTestFailed"))}finally{ie(!1)}}},[d,ae,Ue,a,t,T]);if(o.useEffect(()=>{if(!Ce||!a)return;const ce=window.setInterval(()=>{(async()=>{Ye.current+=1,await v({directory:d,silent:!0});const ht=Os.getState().getStatusForDirectory(d)[a];if(ht){if(W.current&&ht.status!=="needs_auth"&&ht.status!=="needs_client_registration"){De(!1),Ye.current=0,W.current=!1,Re(null),ue(""),ht.status==="connected"&&M.success(t("settings.mcp.page.toast.authorizationCompleted"));return}if(!W.current&&ht.status==="failed"){De(!1),Ye.current=0,W.current=!1,M.error(ht.error||t("settings.mcp.page.toast.authorizationFailed"));return}Ye.current>=30&&(De(!1),Ye.current=0,W.current=!1,M.message(t("settings.mcp.page.toast.authorizationStillInProgress")))}})()},2e3);return()=>{window.clearInterval(ce)}},[d,Ce,v,a,t]),!a)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(O,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.mcp.page.empty.selectServer")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.mcp.page.empty.addNewOne")})]})});const ts=c[a],Ms=a?N[a]:void 0,Bt=ts??Ms,ls=!f&&!Bt&&R.some(ce=>ce.scope==="mcp"&&ce.id.startsWith(`mcp:${a}:`)),Wt=ts?.status==="connected",vs=ts?.status==="needs_auth"||ts?.status==="needs_client_registration",ps=w||!a?null:gc(a),ys=async()=>{if(ps)try{await navigator.clipboard.writeText(ps),M.success(t("settings.mcp.page.toast.copiedCallbackUrl"))}catch{M.error(t("settings.mcp.page.toast.clipboardWriteFailed"))}},ms=qu(Bt?.status,e,Bt&&"error"in Bt?Bt.error:void 0),bs=ce=>{switch(ce){case"connected":return t("settings.mcp.page.status.label.connected");case"failed":return t("settings.mcp.page.status.label.failed");case"needs_auth":return t("settings.mcp.page.status.label.needsAuth");case"needs_client_registration":return t("settings.mcp.page.status.label.needsRegistration");case"awaiting_restart":return t("settings.mcp.page.status.label.awaitingRestart");default:return ce}};return s.jsxs(s.Fragment,{children:[s.jsxs(ns,{title:f?t("settings.mcp.page.header.newServer"):a,titleAccessory:f?void 0:s.jsx(zi,{status:ls?"awaiting_restart":Bt?.status,enabled:ae,getStatusLabel:bs,variant:"pill"}),description:f?t("settings.mcp.page.header.configureNewServer"):t("settings.mcp.page.header.transport",{type:t(I==="local"?"settings.mcp.page.transport.local":"settings.mcp.page.transport.remote")}),headerEnd:!f&&!ls?s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(B,{variant:Wt?"outline":"default",size:"xs",className:"!font-normal",onClick:fe,disabled:oe||!ae,children:t(oe?"settings.mcp.page.actions.working":Wt?"settings.mcp.page.actions.disconnect":"settings.mcp.page.actions.connect")}),I==="remote"&&s.jsxs(s.Fragment,{children:[s.jsx(B,{variant:vs?"default":"outline",size:"xs",className:"!font-normal",onClick:()=>{ct()},disabled:Ee||!ae,children:t(Ee?"settings.mcp.page.actions.starting":Wt?"settings.mcp.page.actions.reauthorize":"settings.mcp.page.actions.authorize")}),s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{lt()},disabled:$e||!ae,children:t($e?"settings.mcp.page.actions.clearing":"settings.mcp.page.actions.clearAuth")})]}),Wt&&s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal gap-1 text-muted-foreground",onClick:()=>{xs()},disabled:Fe||!ae,children:t(Fe?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.test")})]}):void 0,showSaveStatus:!1,children:[ls&&s.jsx(_e,{divider:!1,children:s.jsx("div",{className:"rounded-lg border p-3 border-[var(--status-warning-border)] bg-[var(--status-warning-background)]",children:s.jsxs("div",{className:"min-w-0 space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[s.jsx("span",{className:Et,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(zi,{status:"awaiting_restart",enabled:ae,getStatusLabel:bs})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.mcp.page.status.description.awaitingRestart")})]})})}),!f&&!ls&&Qu(Bt?.status,ve,vs,Ce)&&s.jsx(_e,{divider:!1,children:s.jsxs("div",{className:we("rounded-lg border p-3",Ju(Bt?.status)),children:[s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"min-w-0 space-y-1",children:[s.jsxs("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-1",children:[s.jsx("span",{className:Et,children:t("settings.mcp.page.status.runtimeStatus")}),s.jsx(zi,{status:Bt?.status,enabled:ae,getStatusLabel:bs})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:ms}),s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:D==="project"?t("settings.mcp.page.status.projectScopedTo",{directory:d??t("settings.mcp.page.status.activeProject")}):t("settings.mcp.page.status.userScoped")})]}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:!Wt&&s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{xs()},disabled:Fe||!ae,children:t(Fe?"settings.mcp.page.actions.testing":"settings.mcp.page.actions.testConnection")})}),Bt?.status==="needs_client_registration"&&s.jsxs("div",{className:"space-y-3 rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-3",children:[s.jsxs("div",{children:[s.jsx(Js,{as:"div",children:t("settings.mcp.page.registration.title")}),s.jsx("p",{className:"mt-1 typography-micro text-muted-foreground",children:t("settings.mcp.page.registration.description")})]}),ps&&s.jsxs("div",{children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.registration.callbackLabel")}),s.jsxs("div",{className:"mt-1 flex items-start gap-2",children:[s.jsx("span",{className:"min-w-0 flex-1 break-all font-mono typography-micro text-foreground/80",children:ps}),s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{ys()},children:[s.jsx(O,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]}),s.jsxs("div",{className:"grid gap-3 @xl:grid-cols-2",children:[s.jsx(qt,{label:t("settings.mcp.page.registration.clientId"),children:s.jsx(Je,{value:V,onChange:ce=>{_(ce.target.value),z(!0)},className:"font-mono typography-meta","data-bwignore":"true","data-1p-ignore":"true"})}),s.jsx(qt,{label:t("settings.mcp.page.registration.clientSecret"),children:s.jsx(Je,{type:"password",value:K,onChange:ce=>{Z(ce.target.value),z(!0)},className:"font-mono typography-meta","data-bwignore":"true","data-1p-ignore":"true"})})]}),s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.registration.afterSaving")})]}),ve&&s.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-2",children:s.jsxs("div",{className:"space-y-2",children:[s.jsx("div",{className:"typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.authorizationUrl")}),s.jsx("div",{className:"break-all typography-micro text-foreground font-mono",children:ve}),s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{yn(ve)},children:[s.jsx(O,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.openInBrowser")]}),s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Qe()},children:[s.jsx(O,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.actions.copyLink")]})]})]})}),w&&I==="remote"&&(vs||Ce||ve)&&s.jsx("div",{className:"rounded-md border border-[var(--interactive-border)] bg-[var(--surface-background)] px-3 py-3",children:s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{children:[s.jsx(Js,{as:"div",children:t("settings.mcp.page.auth.manualFallbackTitle")}),s.jsx("p",{className:"mt-1 typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.manualFallbackDescription")})]}),s.jsx(Is,{value:He,onChange:ce=>ue(ce.target.value),placeholder:t("settings.mcp.page.auth.callbackInputPlaceholder"),rows:3,className:"font-mono typography-meta","data-bwignore":"true","data-1p-ignore":"true",spellCheck:!1}),s.jsx("div",{className:"flex flex-wrap items-center gap-2",children:s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Nt()},disabled:re,children:t(re?"settings.mcp.page.actions.completing":"settings.mcp.page.actions.completeAuthorization")})})]})})]}),Ce&&s.jsx("p",{className:"mt-4 typography-micro text-muted-foreground",children:t("settings.mcp.page.auth.waitingForOpenCode")})]})}),s.jsxs(_e,{title:t("settings.mcp.page.server.title"),divider:!1,settingsItem:"mcp.server",contentClassName:"space-y-0",titleAccessory:f?s.jsxs(B,{variant:"ghost",size:"xs",className:"!font-normal gap-1.5 text-muted-foreground",onClick:Ct,type:"button",title:t("settings.mcp.page.server.importJsonTitle"),children:[s.jsx(O,{name:"file-code",className:"h-3.5 w-3.5"}),t("settings.mcp.page.server.importJson")]}):null,children:[f&&s.jsxs(Ot,{label:t("settings.mcp.page.server.name"),controlClassName:"flex-wrap @xl:w-auto @xl:flex-1",children:[s.jsx(Je,{value:b,onChange:ce=>F(ce.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(Pt,{value:D,onValueChange:ce=>P(ce),children:[s.jsxs(It,{size:Lt,className:"!h-7 min-w-0 max-w-full gap-1.5 px-2",children:[s.jsx(O,{name:D==="user"?"user-3":"folder",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"truncate",children:t(D==="user"?"settings.mcp.page.scope.everywhere":"settings.mcp.page.scope.thisProject")})]}),s.jsxs(At,{align:"end",children:[s.jsx(ot,{value:"user",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(O,{name:"user-3",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.everywhere")})]})}),s.jsx(ot,{value:"project",children:s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(O,{name:"folder",className:"h-3.5 w-3.5"}),s.jsx("span",{children:t("settings.mcp.page.scope.thisProject")})]})})]})]})]}),s.jsx(gt,{checked:ae,onChange:me,label:t("settings.mcp.page.server.enable"),ariaLabel:t("settings.mcp.page.server.enableAria")})]}),s.jsxs(_e,{title:t("settings.mcp.page.connection.title"),description:t("settings.mcp.page.connection.description"),settingsItem:"mcp.command",contentClassName:"space-y-2",children:[s.jsx(vr,{items:ze,activeId:I,onSelect:ce=>U(ce),layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),I==="local"?s.jsx(Gu,{value:q,onChange:k,preview:ce=>t("settings.mcp.page.connection.previewArgs",{count:ce}),onDetectUrl:jt}):s.jsx(Je,{value:$,onChange:ce=>Te(ce.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(I==="local"?"settings.mcp.page.connection.hintCommand":"settings.mcp.page.connection.hintLink")})]}),I==="remote"&&s.jsx(_e,{title:t("settings.mcp.page.advanced.title"),settingsItem:"mcp.advanced",children:s.jsxs(bn,{open:ke,onOpenChange:Ie,children:[s.jsxs(wn,{className:"flex w-full items-center justify-between py-0.5 group",children:[s.jsxs("div",{className:"flex items-center gap-1.5 text-left",children:[s.jsx("span",{className:"typography-ui-label font-normal text-foreground",children:t("settings.mcp.page.advanced.configure")}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",X.length," ",t("settings.mcp.page.advanced.headers"),he?` · ${he}ms`:"",")"]})]}),ke?s.jsx(O,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(O,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(jn,{className:"pt-2",children:s.jsxs("div",{className:"space-y-4",children:[s.jsx("div",{className:"space-y-2",children:s.jsxs("div",{className:"flex flex-col gap-2 @xl:flex-row @xl:items-center @xl:gap-8",children:[s.jsxs("div",{className:"flex min-w-0 flex-row items-center gap-1 @xl:w-56 shrink-0",children:[s.jsx("span",{className:Et,children:t("settings.mcp.page.advanced.timeoutMs")}),s.jsx(Jt,{children:t("settings.mcp.page.advanced.timeoutHint")})]}),s.jsx("div",{className:"flex items-center gap-2",children:s.jsx(Je,{type:"number",min:"1",step:"1",value:he,onChange:ce=>ne(ce.target.value),placeholder:"5000",className:"h-7 w-32 font-mono px-2","data-bwignore":"true","data-1p-ignore":"true"})})]})}),s.jsxs("div",{children:[s.jsxs(Js,{as:"div",className:"mb-2",children:[t("settings.mcp.page.advanced.requestHeaders"),X.length>0&&s.jsxs("span",{className:"ml-1.5 typography-micro text-muted-foreground font-normal",children:["(",X.length,")"]})]}),s.jsx(lo,{value:X,onChange:L,keyTransform:ce=>ce.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:ce=>t("settings.mcp.page.toast.importedVariablesCount",{count:ce}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})]})]})})]})}),s.jsx(_e,{title:t("settings.mcp.page.env.title"),description:t("settings.mcp.page.env.description"),titleAccessory:E.length>0?s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",E.length,")"]}):null,settingsItem:"mcp.environment",children:E.length===0?s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal gap-1.5",onClick:()=>J([{key:"",value:""}]),children:[s.jsx(O,{name:"add",className:"h-3.5 w-3.5"}),t("settings.mcp.page.env.addEnvironmentVariable")]}):s.jsx(lo,{value:E,onChange:J,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:ce=>t("settings.mcp.page.toast.importedVariablesCount",{count:ce}),clipboardReadFailed:t("settings.mcp.page.toast.clipboardReadFailed"),keyLabel:t("settings.mcp.page.env.key"),valueLabel:t("settings.mcp.page.env.value"),valuePlaceholder:t("settings.mcp.page.env.valuePlaceholder"),hideValueTitle:t("settings.mcp.page.env.hide"),showValueTitle:t("settings.mcp.page.env.show"),addVariable:t("settings.mcp.page.env.addVariable"),plainTextWarning:t("settings.mcp.page.env.plainTextWarning"),removeVariableAria:t("settings.mcp.page.env.removeVariableAria")})}),s.jsxs("div",{className:"flex items-center gap-2 pb-8",children:[s.jsx(B,{onClick:wt,disabled:Pe||!ft&&!f,size:"xs",className:"!font-normal",children:t(Pe?"settings.common.actions.saving":f?"settings.common.actions.create":"settings.common.actions.saveChanges")}),!f&&s.jsx(B,{variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>be(!0),children:t("settings.common.actions.delete")})]})," "]}),s.jsx(Ft,{open:Ge,onOpenChange:ce=>{ce||(it(!1),dt(""),H(null))},children:s.jsxs(Kt,{className:"max-w-md",children:[s.jsxs(Ut,{children:[s.jsx(_t,{children:t("settings.mcp.page.importDialog.title")}),s.jsx($t,{children:t("settings.mcp.page.importDialog.description")})]}),s.jsxs("div",{className:"space-y-3",children:[s.jsx(Is,{value:nt,onChange:ce=>{dt(ce.target.value),H(null)},placeholder:`{
15
- "mcpServers": {
16
- "postgres": {
17
- "command": "npx",
18
- "args": ["-y", "@modelcontextprotocol/server-postgres"]
19
- }
20
- }
21
- }`,rows:8,className:"font-mono typography-meta",spellCheck:!1,"data-bwignore":"true","data-1p-ignore":"true"}),xt&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:xt}),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:et,type:"button",children:[s.jsx(O,{name:"clipboard",className:"h-3.5 w-3.5"}),t("settings.mcp.page.importDialog.pasteFromClipboard")]})})]}),s.jsxs(es,{children:[s.jsx(B,{variant:"outline",onClick:()=>{it(!1),dt(""),H(null)},className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(B,{onClick:Xe,disabled:!nt.trim(),size:"sm",children:t("settings.common.actions.import")})]})]})}),s.jsx(Ft,{open:Se,onOpenChange:ce=>{!ce&&!Ke&&be(!1)},children:s.jsxs(Kt,{className:"max-w-md",children:[s.jsxs(Ut,{children:[s.jsx(_t,{children:t("settings.mcp.page.deleteDialog.title",{name:a??""})}),s.jsxs($t,{children:[t("settings.mcp.page.deleteDialog.descriptionPrefix")," ",s.jsx("code",{className:"text-foreground",children:"opencode.json"}),"."," ",t("settings.mcp.page.deleteDialog.descriptionSuffix")]})]}),s.jsxs(es,{children:[s.jsx(B,{variant:"outline",onClick:()=>be(!1),disabled:Ke,className:"text-foreground",children:t("settings.common.actions.cancel")}),s.jsx(B,{variant:"destructive",size:"sm",onClick:Q,disabled:Ke,children:t(Ke?"settings.mcp.page.actions.deleting":"settings.common.actions.delete")})]})]})})]})};function ep(t){return t.trim().length>0}function tp(t){return t.trimEnd()}function sp(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 ci=()=>{try{const e=Vs.getState().getActiveProject?.();if(e?.path?.trim())return e.path.trim();const a=hn.getDirectory();if(a?.trim())return a.trim()}catch(t){console.warn("[PluginsStore] Error resolving config directory:",t)}return null},np=800,ap=5e3,ip="__default__",nr=new Map,Ui=new Map,rp=1500,Ll=t=>t?.trim()||ip,op=t=>{nr.delete(Ll(t))},rs=Al()(zd(Ud((t,e)=>({entries:[],files:[],selectedId:null,isLoading:!1,registryInfo:{},isLoadingRegistry:!1,draft:null,setSelected:a=>t({selectedId:a}),setDraft:a=>t({draft:a}),loadPlugins:async a=>{const n=ci(),i=Ll(n),r=Date.now(),l=nr.get(i)??0,u=e().entries.length>0||e().files.length>0;if(!a?.force&&u&&r-l<ap)return!0;const p=Ui.get(i);if(!a?.force&&p)return p;const h=(async()=>{t({isLoading:!0});try{const d=await pt(An("/api/config/plugins",n),{headers:Pa(n)});if(!d.ok)throw new Error("Failed to load plugins");const w=await di(d);return t({entries:w.entries??[],files:w.files??[],isLoading:!1}),nr.set(i,Date.now()),a?.force||e().loadRegistryInfo(),!0}catch(d){return console.error("[PluginsStore] Failed to load plugins:",d),t({isLoading:!1}),!1}})();Ui.set(i,h);try{return await h}finally{Ui.delete(i)}},loadRegistryInfo:async a=>{const n=cp(a?.specs??e().entries.map(i=>i.spec));if(n.length===0)return t({isLoadingRegistry:!1}),!0;t({isLoadingRegistry:!0});try{const i=ci(),r={...e().registryInfo};for(const l of dp(n)){const u=await pt(lp(l,a?.force===!0,i),{headers:Pa(i)});if(!u.ok)throw new Error("Failed to load plugin registry info");const p=await di(u);for(const h of p.results??[])r[h.spec]=h}return t({registryInfo:r,isLoadingRegistry:!1}),!0}catch(i){return console.error("[PluginsStore] Failed to load plugin registry info:",i),t({isLoadingRegistry:!1}),!1}},updateToLatest:async a=>{const n=e().entries.find(r=>r.id===a);if(!n)return{ok:!1};const i=e().registryInfo[n.spec];return!i||i.kind!=="npm-ok"||!i.hasUpdate||!i.latestVersion?{ok:!1}:await e().updateEntry(a,{spec:`${i.name}@${i.latestVersion}`})},createEntry:async a=>{const n=await ra("Creating plugin entry…",async i=>await pt(An("/api/config/plugins/entry",i),{method:"POST",headers:ei(i),body:JSON.stringify(co(a))}),e,{restartId:a.spec});return n.ok&&e().loadRegistryInfo({specs:[a.spec],force:!0}),n},updateEntry:async(a,n)=>{const i=e().entries.find(u=>u.id===a)?.spec,r=n.spec??i,l=await ra("Updating plugin entry…",async u=>await pt(An(`/api/config/plugins/entry/${encodeURIComponent(a)}`,u),{method:"PATCH",headers:ei(u),body:JSON.stringify(co(n))}),e,{restartId:a});return l.ok&&r&&e().loadRegistryInfo({specs:[r],force:!0}),l},deleteEntry:async a=>{const n=e().entries.find(r=>r.id===a),i=await ra("Deleting plugin entry…",async r=>await pt(An(`/api/config/plugins/entry/${encodeURIComponent(a)}`,r),{method:"DELETE",headers:Pa(r)}),e,{restartId:a});if(i.ok&&e().selectedId===a&&t({selectedId:null}),i.ok&&n){const r={...e().registryInfo};delete r[n.spec],t({registryInfo:r})}return i},readFile:async a=>{try{const n=ci(),i=await pt(An(`/api/config/plugins/file/${encodeURIComponent(a)}`,n),{headers:Pa(n)});if(!i.ok)throw new Error("Failed to read plugin file");return await di(i)}catch(n){return console.error("[PluginsStore] Failed to read plugin file:",n),null}},createFile:async a=>ra("Creating plugin file…",async n=>await pt(An("/api/config/plugins/file",n),{method:"POST",headers:ei(n),body:JSON.stringify(a)}),e,{restartId:a.fileName}),updateFile:async(a,n)=>ra("Updating plugin file…",async i=>await pt(An(`/api/config/plugins/file/${encodeURIComponent(a)}`,i),{method:"PUT",headers:ei(i),body:JSON.stringify(n)}),e,{restartId:a}),deleteFile:async a=>{const n=await ra("Deleting plugin file…",async i=>await pt(An(`/api/config/plugins/file/${encodeURIComponent(a)}`,i),{method:"DELETE",headers:Pa(i)}),e,{restartId:a});return n.ok&&e().selectedId===a&&t({selectedId:null}),n},getById:a=>e().entries.find(n=>n.id===a)??e().files.find(n=>n.id===a)}),{name:"plugins-store",storage:od(),partialize:t=>({selectedId:t.selectedId})}),{name:"plugins-store"}));function An(t,e){const a=e?`?directory=${encodeURIComponent(e)}`:"";return`${t}${a}`}function lp(t,e,a){const n=new URLSearchParams;e&&n.set("refresh","true"),a&&n.set("directory",a);const i=n.toString();return`/api/config/plugins/registry?${`specs=${t.map(encodeURIComponent).join(",")}`}${i?`&${i}`:""}`}function cp(t){return Array.from(new Set(t.map(e=>e.trim()).filter(Boolean)))}function dp(t){const e=[];let a=[],n=0;for(const i of t){const r=encodeURIComponent(i),l=a.length===0?r.length:n+1+r.length;a.length>0&&l>rp?(e.push(a),a=[i],n=r.length):(a.push(i),n=l)}return a.length>0&&e.push(a),e}function Pa(t){return t?{"x-opencode-directory":t}:void 0}function ei(t){return{"Content-Type":"application/json",...t?{"x-opencode-directory":t}:{}}}function co(t){const e={};return t.spec!==void 0&&(e.spec=t.spec),t.options!==void 0&&(e.options=t.options),t.scope!==void 0&&(e.scope=t.scope),e}async function ra(t,e,a,n){try{const i=ci(),r=await e(i),l=await di(r).catch(()=>null);if(!r.ok)throw new Error(l?.error||"Failed to update plugin configuration");return op(i),l?.requiresManualRestart?(await a().loadPlugins({force:!0}),{ok:!0,requiresManualRestart:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning}):cl(l,"plugins",{id:n?.restartId})?(await a().loadPlugins({force:!0}),{ok:!0,restartDeferred:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning}):(l?.requiresReload&&(hc(t),await xc({message:l.message,delayMs:l.reloadDelayMs??np,scopes:["all"]})),await a().loadPlugins({force:!0}),{ok:!0,reloadFailed:l?.reloadFailed===!0,message:l?.message,warning:l?.warning})}catch(i){return console.error("[PluginsStore] Failed to update plugin configuration:",i),{ok:!1}}}async function di(t){return await t.json()}const up=/^[a-z0-9][a-z0-9-_.]*\.(js|ts|mjs|cjs)$/;function pp(t){const e=t.trim();if(e==="")return{ok:!0,value:void 0};try{const a=JSON.parse(e);return a===null||typeof a!="object"||Array.isArray(a)?{ok:!1}:{ok:!0,value:a}}catch{return{ok:!1}}}const mp=({open:t,onOpenChange:e,defaultScope:a="user"})=>{const{t:n}=at(),i=rs(k=>k.createEntry),r=rs(k=>k.createFile),[l,u]=o.useState("npm"),[p,h]=o.useState(""),[d,w]=o.useState(""),[c,N]=o.useState(""),[v,C]=o.useState(""),[y,S]=o.useState(a),[g,T]=o.useState(!1),R=o.useCallback(()=>{h(""),w(""),N(""),C(""),S(a)},[a]);o.useEffect(()=>{t&&(u("npm"),R())},[t,R]);const A=k=>{k!==l&&(u(k),R())},j=o.useMemo(()=>pp(d),[d]),f=!j.ok,b=l==="file"&&c.trim()!==""&&!up.test(c.trim()),F=(l==="npm"||l==="path")&&p.trim()==="",D=l==="file"&&v.trim()==="",P=l==="file"&&c.trim()==="",I=g||f||l==="npm"&&F||l==="path"&&F||l==="file"&&(P||b||D),U=async()=>{if(!I){T(!0);try{let k;l==="file"?k=await r({fileName:c.trim(),content:v,scope:y}):k=await i({spec:p.trim(),options:j.ok?j.value:void 0,scope:y}),k.ok?(k.restartDeferred?M.success(n("settings.view.pendingRestart.saved")):M.success(k.message||n("settings.plugins.toast.created")),k.reloadFailed&&M.warning(n("settings.plugins.toast.reloadFailed")),e(!1)):M.error(k.message||n("settings.plugins.sidebar.toast.deleteFailed"))}finally{T(!1)}}},q=o.useMemo(()=>[{id:"npm",label:n("settings.plugins.dialog.add.tab.npm")},{id:"path",label:n("settings.plugins.dialog.add.tab.path")},{id:"file",label:n("settings.plugins.dialog.add.tab.file")}],[n]);return s.jsx(Ft,{open:t,onOpenChange:k=>{!k&&g||e(k)},children:s.jsxs(Kt,{className:"max-w-xl",children:[s.jsxs(Ut,{children:[s.jsx(_t,{children:n("settings.plugins.dialog.add.title")}),s.jsx($t,{children:n("settings.plugins.sidebar.empty.description")})]}),s.jsx(vr,{items:q,activeId:l,onSelect:k=>A(k),layoutMode:"fit",variant:"active-pill",activePillLowercase:!1,className:"h-10"}),s.jsxs("div",{className:"flex flex-col gap-4",children:[(l==="npm"||l==="path")&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{"data-settings-item":"plugins.spec",className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-spec",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.spec")}),s.jsx(Je,{id:"plugin-spec",value:p,onChange:k=>h(k.target.value),placeholder:n("settings.plugins.page.field.spec.placeholder"),"aria-invalid":F?!1:void 0,disabled:g}),F&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:n("settings.plugins.validation.specRequired")})]}),s.jsxs("div",{"data-settings-item":"plugins.options",className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-options",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.options")}),s.jsx(Is,{id:"plugin-options",value:d,onChange:k=>w(k.target.value),rows:5,className:"font-mono",hasError:f,disabled:g}),f&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:n("settings.plugins.page.field.options.invalidJson")})]})]}),l==="file"&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{"data-settings-item":"plugins.content",className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-filename",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.fileName")}),s.jsx(Je,{id:"plugin-filename",value:c,onChange:k=>N(k.target.value),placeholder:"my-plugin.ts","aria-invalid":b||void 0,disabled:g}),b&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:n("settings.plugins.validation.fileName")})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("label",{htmlFor:"plugin-content",className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.content")}),s.jsx(Is,{id:"plugin-content",value:v,onChange:k=>C(k.target.value),rows:16,className:"font-mono",disabled:g})]})]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:n("settings.plugins.page.field.scope")}),s.jsx("div",{className:"flex items-center gap-4",children:["user","project"].map(k=>{const $=y===k,G=n(k==="user"?"settings.plugins.scope.user":"settings.plugins.scope.project");return s.jsxs("button",{type:"button",onClick:()=>S(k),disabled:g,className:"flex items-center gap-2 py-1 text-left disabled:opacity-50",children:[s.jsx(mr,{checked:$,onChange:()=>S(k),ariaLabel:G}),s.jsx("span",{className:we("typography-ui-label font-normal",$?"text-foreground":"text-foreground/60"),children:G})]},k)})})]})]}),s.jsxs(es,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>e(!1),disabled:g,children:n("settings.plugins.dialog.add.action.cancel")}),s.jsxs(B,{size:"sm",onClick:()=>{U()},disabled:I,children:[g?s.jsx(O,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin"}):null,n("settings.plugins.dialog.add.action.submit")]})]})]})})},gp=t=>{const e=mt.c(33),{spec:a}=t;let n;e[0]!==a?(n=u=>u.registryInfo[a],e[0]=a,e[1]=n):n=e[1];const i=rs(n),{t:r}=at();if(!i)return null;const l=fp;switch(i.kind){case"npm-ok":{if(!i.hasUpdate||!i.latestVersion)return null;let u;e[2]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(O,{name:"arrow-up-s",className:"h-3 w-3"}),e[2]=u):u=e[2];let p;e[3]!==i.latestVersion?(p=s.jsxs("span",{className:"inline-flex items-center gap-0.5 text-[var(--status-success)]",children:[u,i.latestVersion]}),e[3]=i.latestVersion,e[4]=p):p=e[4];let h;return e[5]!==i.currentVersion||e[6]!==i.latestVersion||e[7]!==r||e[8]!==p?(h=l(p,r("settings.plugins.registry.badge.update.tooltip",{current:i.currentVersion??"",latest:i.latestVersion})),e[5]=i.currentVersion,e[6]=i.latestVersion,e[7]=r,e[8]=p,e[9]=h):h=e[9],h}case"npm-missing-version":{let u;e[10]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(O,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[10]=u):u=e[10];let p;return e[11]!==i.currentVersion||e[12]!==i.name||e[13]!==r?(p=l(u,r("settings.plugins.registry.badge.missingVersion.tooltip",{version:i.currentVersion,name:i.name})),e[11]=i.currentVersion,e[12]=i.name,e[13]=r,e[14]=p):p=e[14],p}case"npm-missing-package":{let u;e[15]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(O,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[15]=u):u=e[15];let p;return e[16]!==i.name||e[17]!==r?(p=l(u,r("settings.plugins.registry.badge.missingPackage.tooltip",{name:i.name})),e[16]=i.name,e[17]=r,e[18]=p):p=e[18],p}case"npm-malformed":{let u;e[19]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(O,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[19]=u):u=e[19];let p;return e[20]!==r?(p=l(u,r("settings.plugins.registry.badge.malformed.tooltip")),e[20]=r,e[21]=p):p=e[21],p}case"npm-network":{let u;e[22]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(O,{name:"cloud-off",className:"h-3 w-3 text-muted-foreground"}),e[22]=u):u=e[22];let p;return e[23]!==r?(p=l(u,r("settings.plugins.registry.badge.network.tooltip")),e[23]=r,e[24]=p):p=e[24],p}case"path-missing":{let u;e[25]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(O,{name:"error-warning",className:"h-3 w-3 text-[var(--status-error)]"}),e[25]=u):u=e[25];let p;return e[26]!==i.absolutePath||e[27]!==r?(p=l(u,r("settings.plugins.registry.badge.pathMissing.tooltip",{path:i.absolutePath})),e[26]=i.absolutePath,e[27]=r,e[28]=p):p=e[28],p}case"path-unreadable":{let u;e[29]===Symbol.for("react.memo_cache_sentinel")?(u=s.jsx(O,{name:"error-warning",className:"h-3 w-3 text-[var(--status-warning)]"}),e[29]=u):u=e[29];let p;return e[30]!==i.absolutePath||e[31]!==r?(p=l(u,r("settings.plugins.registry.badge.pathUnreadable.tooltip",{path:i.absolutePath})),e[30]=i.absolutePath,e[31]=r,e[32]=p):p=e[32],p}case"path-ok":return null;default:return null}};function fp(t,e){return s.jsxs(gr,{children:[s.jsx(fr,{asChild:!0,children:s.jsx("span",{className:"inline-flex shrink-0 items-center gap-0.5 text-xs",children:t})}),s.jsx(gl,{children:e})]})}const Fl=t=>{const e=mt.c(26),{header:a,footer:n,children:i,className:r,variant:l}=t,u=l===void 0?"sidebar":l,p=us(),h=o.useRef(null),[d,w]=o.useState(!1),[c,N]=o.useState(!1),v=u==="background"||p?"bg-background":"bg-sidebar",C=v==="bg-background"?"var(--surface-background)":"var(--surface-muted)";let y;e[0]===Symbol.for("react.memo_cache_sentinel")?(y=()=>{const I=h.current;if(!I){w(!1),N(!1);return}if(!(I.scrollHeight>I.clientHeight+1)){w(!1),N(!1);return}w(I.scrollTop>1),N(I.scrollTop+I.clientHeight<I.scrollHeight-1)},e[0]=y):y=e[0];const S=y;let g;e[1]===Symbol.for("react.memo_cache_sentinel")?(g=()=>{S()},e[1]=g):g=e[1];let T;e[2]!==i?(T=[i,S],e[2]=i,e[3]=T):T=e[3],o.useEffect(g,T);let R,A;e[4]===Symbol.for("react.memo_cache_sentinel")?(R=()=>{const I=h.current;if(!I)return;const U=()=>S();return I.addEventListener("scroll",U,{passive:!0}),()=>I.removeEventListener("scroll",U)},A=[S],e[4]=R,e[5]=A):(R=e[4],A=e[5]),o.useEffect(R,A);let j;e[6]!==v||e[7]!==r?(j=we("flex h-full flex-col",v,r),e[6]=v,e[7]=r,e[8]=j):j=e[8];let f;e[9]!==i?(f=s.jsx(Bs,{ref:h,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]=f):f=e[10];let b;e[11]!==C||e[12]!==d?(b=d&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 top-0 h-4",style:{background:`linear-gradient(to bottom, ${C} 0%, transparent 100%)`}}),e[11]=C,e[12]=d,e[13]=b):b=e[13];let F;e[14]!==C||e[15]!==c?(F=c&&s.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 h-6",style:{background:`linear-gradient(to top, ${C} 0%, transparent 100%)`}}),e[14]=C,e[15]=c,e[16]=F):F=e[16];let D;e[17]!==F||e[18]!==f||e[19]!==b?(D=s.jsxs("div",{className:"relative flex flex-1 min-h-0 flex-col",children:[f,b,F]}),e[17]=F,e[18]=f,e[19]=b,e[20]=D):D=e[20];let P;return e[21]!==n||e[22]!==a||e[23]!==D||e[24]!==j?(P=s.jsxs("div",{className:j,children:[a,D,n]}),e[21]=n,e[22]=a,e[23]=D,e[24]=j,e[25]=P):P=e[25],P},ar=t=>{const e=mt.c(23),{title:a,metadata:n,selected:i,onSelect:r,icon:l,actions:u,className:p}=t,h=i===void 0?!1:i,d=u&&u.length>0,w=h?"bg-interactive-selection":"hover:bg-interactive-hover";let c;e[0]!==p||e[1]!==w?(c=we("group relative flex items-center rounded-md px-1.5 py-0.5 transition-all duration-200",w,p),e[0]=p,e[1]=w,e[2]=c):c=e[2];let N;e[3]!==a?(N=s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a}),e[3]=a,e[4]=N):N=e[4];let v;e[5]!==l||e[6]!==N?(v=s.jsxs("div",{className:"flex items-center gap-1.5",children:[l,N]}),e[5]=l,e[6]=N,e[7]=v):v=e[7];let C;e[8]!==n?(C=n&&s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:n}),e[8]=n,e[9]=C):C=e[9];let y;e[10]!==r||e[11]!==v||e[12]!==C?(y=s.jsxs("button",{onClick:r,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[v,C]}),e[10]=r,e[11]=v,e[12]=C,e[13]=y):y=e[13];let S;e[14]!==u||e[15]!==d?(S=d&&s.jsxs(an,{children:[s.jsx(sn,{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(O,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(nn,{align:"end",className:"w-fit min-w-20",children:u.map(hp)})]}),e[14]=u,e[15]=d,e[16]=S):S=e[16];let g;e[17]!==y||e[18]!==S?(g=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[y,S]}),e[17]=y,e[18]=S,e[19]=g):g=e[19];let T;return e[20]!==c||e[21]!==g?(T=s.jsx("div",{className:c,children:g}),e[20]=c,e[21]=g,e[22]=T):T=e[22],T};function hp(t){const e=t.icon;return s.jsxs(rn,{onClick:a=>{a.stopPropagation(),t.onClick()},className:we(t.destructive&&"text-destructive focus:text-destructive"),children:[e&&s.jsx(O,{name:e,className:"h-4 w-4 mr-px"}),t.label]},t.label)}const xp=t=>t.parsedKind==="npm"?"code-box":"folder",vp=t=>{const e=mt.c(144),{onItemSelect:a,onAddClick:n}=t,{t:i}=at(),{entries:r,files:l,selectedId:u,setSelected:p,deleteEntry:h,deleteFile:d,loadPlugins:w}=rs(Ds(yp)),c=rs(bp),N=rs(wp),v=rs(jp),C=rs(kp),[y,S]=o.useState(null),[g,T]=o.useState(!1),[R,A]=o.useState(!1);let j,f;e[0]!==w?(j=()=>{w()},f=[w],e[0]=w,e[1]=j,e[2]=f):(j=e[1],f=e[2]),o.useEffect(j,f);let b,F;e[3]===Symbol.for("react.memo_cache_sentinel")?(b=()=>{const et=()=>A(!0);return window.addEventListener("aiworker:settings-open-plugin-add",et),()=>window.removeEventListener("aiworker:settings-open-plugin-add",et)},F=[],e[3]=b,e[4]=F):(b=e[3],F=e[4]),o.useEffect(b,F);let D;if(e[5]!==r||e[6]!==c){D={userEntries:0,projectEntries:0};for(const et of r){const Xe=c[et.spec];Xe?.kind==="npm-ok"&&Xe.hasUpdate&&(et.scope==="user"?D.userEntries=D.userEntries+1:et.scope==="project"&&(D.projectEntries=D.projectEntries+1))}e[5]=r,e[6]=c,e[7]=D}else D=e[7];const P=D;let I;e[8]!==r?(I=r.filter(Np),e[8]=r,e[9]=I):I=e[9];const U=I;let q;e[10]!==r?(q=r.filter(Sp),e[10]=r,e[11]=q):q=e[11];const k=q;let $;e[12]!==l?($=l.filter(Cp),e[12]=l,e[13]=$):$=e[13];const G=$;let E;e[14]!==l?(E=l.filter(Pp),e[14]=l,e[15]=E):E=e[15];const J=E,X=r.length+l.length,L=X===0;let se;e[16]!==n?(se=()=>{n?n():A(!0)},e[16]=n,e[17]=se):se=e[17];const z=se;let V;e[18]!==a||e[19]!==p?(V=et=>{p(et),a?.()},e[18]=a,e[19]=p,e[20]=V):V=e[20];const _=V;let K;e[21]!==r||e[22]!==c||e[23]!==i||e[24]!==C?(K=async et=>{const Xe=r.find(Te=>Te.id===et);if(!Xe)return;const ft=c[Xe.spec];if(!ft||ft.kind!=="npm-ok"||!ft.hasUpdate||!ft.latestVersion)return;const ze=ft.latestVersion;(await C(et)).ok?M.success(i("settings.plugins.toast.updatedToLatest",{version:ze})):M.error(i("settings.plugins.toast.refreshFailed"))},e[21]=r,e[22]=c,e[23]=i,e[24]=C,e[25]=K):K=e[25];const Z=K;let Y;e[26]!==v||e[27]!==i?(Y=async()=>{M.info(i("settings.plugins.toast.refreshing"));try{await v({force:!0})}catch{M.error(i("settings.plugins.toast.refreshFailed"))}},e[26]=v,e[27]=i,e[28]=Y):Y=e[28];const te=Y;let ge;e[29]!==h||e[30]!==d||e[31]!==y||e[32]!==i?(ge=async()=>{if(!y)return;T(!0);const et=y.kind==="entry"?await h(y.id):await d(y.id);et.ok?M.success(et.message||i("settings.plugins.sidebar.toast.deleted",{name:y.label})):M.error(i("settings.plugins.sidebar.toast.deleteFailed")),S(null),T(!1)},e[29]=h,e[30]=d,e[31]=y,e[32]=i,e[33]=ge):ge=e[33];const le=ge;let he;e[34]!==_||e[35]!==Z||e[36]!==c||e[37]!==u||e[38]!==i?(he=et=>{const Xe=c[et.spec],ft=Xe?.kind==="npm-ok"&&Xe.hasUpdate&&!!Xe.latestVersion,ze=[];return ft&&ze.push({label:i("settings.plugins.sidebar.actions.updateToLatest"),icon:"arrow-up-s",onClick:()=>{Z(et.id)}}),ze.push({label:i("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>S({kind:"entry",id:et.id,label:et.spec})}),s.jsx(ar,{title:s.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[s.jsx("span",{className:"min-w-0 flex-1 truncate",children:et.spec}),s.jsx(gp,{spec:et.spec})]}),metadata:et.parsedKind==="npm"?i("settings.plugins.sidebar.kind.npm"):i("settings.plugins.sidebar.kind.path"),selected:u===et.id,onSelect:()=>_(et.id),icon:s.jsx(O,{name:xp(et),className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:ze},et.id)},e[34]=_,e[35]=Z,e[36]=c,e[37]=u,e[38]=i,e[39]=he):he=e[39];const ne=he;let ae;e[40]!==_||e[41]!==u||e[42]!==i?(ae=et=>s.jsx(ar,{title:et.fileName,metadata:i("settings.plugins.sidebar.kind.file"),selected:u===et.id,onSelect:()=>_(et.id),icon:s.jsx(O,{name:"file-text",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/70"}),actions:[{label:i("settings.common.actions.delete"),icon:"delete-bin",destructive:!0,onClick:()=>S({kind:"file",id:et.id,label:et.fileName})}]},et.id),e[40]=_,e[41]=u,e[42]=i,e[43]=ae):ae=e[43];const me=ae;let Pe;e[44]!==i?(Pe=(et,Xe,ft)=>{const ze=ft===void 0?0:ft;return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:[et,ze>0&&s.jsx("span",{className:"ml-2 normal-case font-normal text-[var(--status-success)]",children:i(ze===1?"settings.plugins.sidebar.group.updatesAvailable_one":"settings.plugins.sidebar.group.updatesAvailable_other",{count:ze})})]}),Xe]})},e[44]=i,e[45]=Pe):Pe=e[45];const Ne=Pe;let Se;e[46]!==i?(Se=i("settings.plugins.sidebar.title"),e[46]=i,e[47]=Se):Se=e[47];let be;e[48]!==Se?(be=s.jsx("div",{className:"mb-3 flex items-center justify-between gap-3",children:s.jsx("h2",{className:on,children:Se})}),e[48]=Se,e[49]=be):be=e[49];let Ke;e[50]!==i||e[51]!==X?(Ke=i("settings.plugins.sidebar.total",{count:X}),e[50]=i,e[51]=X,e[52]=Ke):Ke=e[52];let Le;e[53]!==Ke?(Le=s.jsx("span",{className:"typography-meta text-muted-foreground",children:Ke}),e[53]=Ke,e[54]=Le):Le=e[54];let oe;e[55]!==te?(oe=()=>{te()},e[55]=te,e[56]=oe):oe=e[56];let xe;e[57]!==i?(xe=i("settings.plugins.sidebar.actions.refresh"),e[57]=i,e[58]=xe):xe=e[58];let Ee;e[59]!==i?(Ee=i("settings.plugins.sidebar.actions.refresh"),e[59]=i,e[60]=Ee):Ee=e[60];const Ve=N?"size-4 animate-spin":"size-4";let $e;e[61]!==Ve?($e=s.jsx(O,{name:"refresh",className:Ve}),e[61]=Ve,e[62]=$e):$e=e[62];let We;e[63]!==N||e[64]!==oe||e[65]!==xe||e[66]!==Ee||e[67]!==$e?(We=s.jsx(B,{type:"button","data-settings-item":"plugins.create",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:oe,disabled:N,"aria-label":xe,title:Ee,children:$e}),e[63]=N,e[64]=oe,e[65]=xe,e[66]=Ee,e[67]=$e,e[68]=We):We=e[68];let Fe;e[69]!==i?(Fe=i("settings.plugins.sidebar.actions.addTitle"),e[69]=i,e[70]=Fe):Fe=e[70];let ie;e[71]!==i?(ie=i("settings.plugins.sidebar.actions.addTitle"),e[71]=i,e[72]=ie):ie=e[72];let re;e[73]===Symbol.for("react.memo_cache_sentinel")?(re=s.jsx(O,{name:"add",className:"size-4"}),e[73]=re):re=e[73];let je;e[74]!==z||e[75]!==Fe||e[76]!==ie?(je=s.jsx(B,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:z,"aria-label":Fe,title:ie,children:re}),e[74]=z,e[75]=Fe,e[76]=ie,e[77]=je):je=e[77];let ve;e[78]!==We||e[79]!==je?(ve=s.jsxs("div",{className:"flex items-center gap-1",children:[We,je]}),e[78]=We,e[79]=je,e[80]=ve):ve=e[80];let Re;e[81]!==Le||e[82]!==ve?(Re=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Le,ve]}),e[81]=Le,e[82]=ve,e[83]=Re):Re=e[83];let Ae;e[84]!==be||e[85]!==Re?(Ae=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[be,Re]}),e[84]=be,e[85]=Re,e[86]=Ae):Ae=e[86];let ye;e[87]!==L||e[88]!==k||e[89]!==J||e[90]!==ne||e[91]!==me||e[92]!==Ne||e[93]!==i||e[94]!==P||e[95]!==U||e[96]!==G?(ye=L?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(O,{name:"plug",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:i("settings.plugins.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:i("settings.plugins.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[U.length>0&&Ne(i("settings.plugins.sidebar.group.userEntries"),U.map(ne),P.userEntries),G.length>0&&Ne(i("settings.plugins.sidebar.group.userFiles"),G.map(me)),k.length>0&&Ne(i("settings.plugins.sidebar.group.projectEntries"),k.map(ne),P.projectEntries),J.length>0&&Ne(i("settings.plugins.sidebar.group.projectFiles"),J.map(me))]}),e[87]=L,e[88]=k,e[89]=J,e[90]=ne,e[91]=me,e[92]=Ne,e[93]=i,e[94]=P,e[95]=U,e[96]=G,e[97]=ye):ye=e[97];let He;e[98]!==Ae||e[99]!==ye?(He=s.jsx(Fl,{variant:"background",header:Ae,children:ye}),e[98]=Ae,e[99]=ye,e[100]=He):He=e[100];let ue;e[101]!==R?(ue=s.jsx(mp,{open:R,onOpenChange:A}),e[101]=R,e[102]=ue):ue=e[102];const Ce=y!==null;let De;e[103]!==g?(De=et=>{!et&&!g&&S(null)},e[103]=g,e[104]=De):De=e[104];let Ye;e[105]!==i?(Ye=i("settings.plugins.sidebar.deleteDialog.title"),e[105]=i,e[106]=Ye):Ye=e[106];let W;e[107]!==Ye?(W=s.jsx(_t,{children:Ye}),e[107]=Ye,e[108]=W):W=e[108];const ke=y?.label??"";let Ie;e[109]!==i||e[110]!==ke?(Ie=i("settings.plugins.sidebar.deleteDialog.description",{name:ke}),e[109]=i,e[110]=ke,e[111]=Ie):Ie=e[111];let Ge;e[112]!==Ie?(Ge=s.jsx($t,{children:Ie}),e[112]=Ie,e[113]=Ge):Ge=e[113];let it;e[114]!==W||e[115]!==Ge?(it=s.jsxs(Ut,{children:[W,Ge]}),e[114]=W,e[115]=Ge,e[116]=it):it=e[116];let nt;e[117]===Symbol.for("react.memo_cache_sentinel")?(nt=()=>S(null),e[117]=nt):nt=e[117];let dt;e[118]!==i?(dt=i("settings.common.actions.cancel"),e[118]=i,e[119]=dt):dt=e[119];let xt;e[120]!==g||e[121]!==dt?(xt=s.jsx(B,{size:"sm",variant:"ghost",onClick:nt,disabled:g,children:dt}),e[120]=g,e[121]=dt,e[122]=xt):xt=e[122];let H;e[123]!==g||e[124]!==i?(H=i(g?"settings.plugins.sidebar.actions.deleting":"settings.common.actions.delete"),e[123]=g,e[124]=i,e[125]=H):H=e[125];let Be;e[126]!==le||e[127]!==g||e[128]!==H?(Be=s.jsx(B,{size:"sm",variant:"destructive",onClick:le,disabled:g,children:H}),e[126]=le,e[127]=g,e[128]=H,e[129]=Be):Be=e[129];let tt;e[130]!==xt||e[131]!==Be?(tt=s.jsxs(es,{children:[xt,Be]}),e[130]=xt,e[131]=Be,e[132]=tt):tt=e[132];let rt;e[133]!==it||e[134]!==tt?(rt=s.jsxs(Kt,{className:"max-w-md",children:[it,tt]}),e[133]=it,e[134]=tt,e[135]=rt):rt=e[135];let ut;e[136]!==Ce||e[137]!==De||e[138]!==rt?(ut=s.jsx(Ft,{open:Ce,onOpenChange:De,children:rt}),e[136]=Ce,e[137]=De,e[138]=rt,e[139]=ut):ut=e[139];let Ct;return e[140]!==He||e[141]!==ue||e[142]!==ut?(Ct=s.jsxs(s.Fragment,{children:[He,ue,ut]}),e[140]=He,e[141]=ue,e[142]=ut,e[143]=Ct):Ct=e[143],Ct};function yp(t){return{entries:t.entries,files:t.files,selectedId:t.selectedId,setSelected:t.setSelected,deleteEntry:t.deleteEntry,deleteFile:t.deleteFile,loadPlugins:t.loadPlugins}}function bp(t){return t.registryInfo}function wp(t){return t.isLoadingRegistry}function jp(t){return t.loadRegistryInfo}function kp(t){return t.updateToLatest}function Np(t){return t.scope==="user"}function Sp(t){return t.scope==="project"}function Cp(t){return t.scope==="user"}function Pp(t){return t.scope==="project"}const Ip=({entryId:t,spec:e})=>{const{t:a}=at(),n=rs(w=>w.registryInfo[e]),i=rs(w=>w.updateToLatest),[r,l]=o.useState(!1);if(!n)return null;if(n.kind==="npm-ok"){if(!n.hasUpdate||!n.latestVersion)return null;const w=n.latestVersion,c=n.currentVersion??"",N=async()=>{l(!0);try{(await i(t)).ok?M.success(a("settings.plugins.toast.updatedToLatest",{version:w})):M.error(a("settings.plugins.toast.refreshFailed"))}finally{l(!1)}};return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(O,{name:"arrow-up",className:"h-5 w-5 text-[var(--status-success)] shrink-0 mt-0.5"}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label text-[var(--status-success)]",children:a("settings.plugins.registry.banner.updateAvailable.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:a("settings.plugins.registry.banner.updateAvailable.description",{current:c,latest:w})})]}),s.jsx(B,{variant:"default",size:"sm",onClick:()=>{N()},disabled:r,children:a("settings.plugins.registry.banner.updateAvailable.action",{latest:w})})]})}if(n.kind==="path-ok")return null;if(n.kind==="npm-network")return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(O,{name:"cloud-off",className:"h-5 w-5 text-muted-foreground shrink-0 mt-0.5"}),s.jsx("div",{className:"flex-1 min-w-0",children:s.jsx("p",{className:"typography-micro text-muted-foreground",children:a("settings.plugins.registry.badge.network.tooltip")})})]});const u=n.kind==="path-unreadable",p=u?"var(--status-warning)":"var(--status-error)",h=u?"alert":"error-warning",d=(()=>{switch(n.kind){case"npm-missing-version":return a("settings.plugins.registry.banner.invalid.missingVersion");case"npm-missing-package":return a("settings.plugins.registry.banner.invalid.missingPackage");case"npm-malformed":return a("settings.plugins.registry.banner.invalid.malformed");case"path-missing":return a("settings.plugins.registry.banner.invalid.pathMissing");case"path-unreadable":return a("settings.plugins.registry.banner.invalid.pathUnreadable")}})();return s.jsxs("div",{className:"rounded-md border border-border bg-card p-3 flex items-start gap-3",children:[s.jsx(O,{name:h,className:"h-5 w-5 shrink-0 mt-0.5",style:{color:p}}),s.jsxs("div",{className:"flex-1 min-w-0",children:[s.jsx("p",{className:"typography-label",style:{color:p},children:a("settings.plugins.registry.banner.invalid.title")}),s.jsx("p",{className:"typography-micro text-muted-foreground mt-0.5",children:d})]})]})};function Ap(t){const e=t.trim();if(e.length===0)return{ok:!0,value:void 0};try{const a=JSON.parse(e);return a===null||typeof a!="object"||Array.isArray(a)?{ok:!1}:{ok:!0,value:a}}catch{return{ok:!1}}}function Kl(t){return!t||Object.keys(t).length===0?"":JSON.stringify(t,null,2)}function uo(t){return{mode:"entry",scope:t.scope,spec:t.spec,optionsJson:Kl(t.options),fileName:"",content:""}}function po(t,e){return{mode:"file",scope:t.scope,spec:"",optionsJson:"",fileName:t.fileName,content:e}}const mo=t=>{const e=mt.c(4),{scope:a,label:n}=t;let i;e[0]===Symbol.for("react.memo_cache_sentinel")?(i=we("typography-micro font-medium rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-muted-foreground","border border-[var(--interactive-border)]"),e[0]=i):i=e[0];let r;return e[1]!==n||e[2]!==a?(r=s.jsx("span",{className:i,"data-scope":a,children:n}),e[1]=n,e[2]=a,e[3]=r):r=e[3],r},Tp=()=>{const{t}=at(),e=rs(y=>y.selectedId),a=rs(y=>y.entries),n=rs(y=>y.files),i=rs(y=>y.draft),r=rs(y=>y.setDraft),l=rs(y=>y.updateEntry),u=rs(y=>y.updateFile),p=rs(y=>y.readFile),h=o.useMemo(()=>e?a.find(y=>y.id===e)??null:null,[a,e]),d=o.useMemo(()=>e?n.find(y=>y.id===e)??null:null,[n,e]),[w,c]=o.useState(!1),[N,v]=o.useState(!1),C=o.useRef(new Map);if(o.useEffect(()=>{let y=!1;return h?(r(uo(h)),()=>{y=!0}):d?(v(!0),(async()=>{const S=await p(d.id);if(y)return;v(!1);const g=S?.content??"";C.current.set(d.id,g),r(po(d,g))})(),()=>{y=!0}):(r(null),()=>{y=!0})},[h,d,p,r]),!e)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(O,{name:"plug",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.plugins.page.empty.select")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.plugins.page.empty.add")})]})});if(h&&i&&i.mode==="entry"){const y=Ap(i.optionsJson),S=y.ok,g=i.spec!==h.spec||i.optionsJson!==Kl(h.options),T=()=>{r(uo(h))},R=async()=>{if(!S)return;const A=i.spec.trim();if(!A){M.error(t("settings.plugins.validation.specRequired"));return}c(!0);try{const j=await l(h.id,{spec:A,options:y.value});j.ok?j.reloadFailed?M.warning(j.message||t("settings.plugins.toast.reloadFailed"),{description:j.warning}):j.restartDeferred?M.success(t("settings.view.pendingRestart.saved")):M.success(j.message||t("settings.plugins.toast.updated")):M.error(j.message||t("settings.plugins.toast.reloadFailed"))}finally{c(!1)}};return s.jsxs(ns,{title:t("settings.plugins.page.header.entry"),titleAccessory:s.jsx(mo,{scope:h.scope,label:h.scope==="project"?t("settings.plugins.sidebar.group.projectEntries"):t("settings.plugins.sidebar.group.userEntries")}),showSaveStatus:!1,children:[s.jsx(_e,{divider:!1,children:s.jsx(Ip,{entryId:h.id,spec:h.spec})}),s.jsx(_e,{title:t("settings.plugins.page.field.spec"),settingsItem:"plugins.spec",children:s.jsx(Je,{value:i.spec,onChange:A=>r({...i,spec:A.target.value}),placeholder:t("settings.plugins.page.field.spec.placeholder"),className:"font-mono typography-meta",spellCheck:!1})}),s.jsxs(_e,{title:t("settings.plugins.page.field.options"),settingsItem:"plugins.options",children:[s.jsx(Is,{value:i.optionsJson,onChange:A=>r({...i,optionsJson:A.target.value}),rows:10,className:we("font-mono typography-meta min-h-[200px]",!S&&"border-[var(--status-error-border)]"),spellCheck:!1,placeholder:"{ }"}),!S&&s.jsx("p",{className:"typography-micro text-[var(--status-error)]",children:t("settings.plugins.page.field.options.invalidJson")}),s.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[s.jsx(B,{variant:"default",size:"sm",onClick:()=>{R()},disabled:!g||!S||w,children:t("settings.plugins.page.action.save")}),s.jsx(B,{variant:"outline",size:"sm",onClick:T,disabled:!g||w,children:t("settings.plugins.page.action.discard")})]})]})]})}if(d&&i&&i.mode==="file"){const y=C.current.get(d.id)??"",S=i.content!==y||i.fileName!==d.fileName,g=()=>{(async()=>{v(!0);const A=(await p(d.id))?.content??"";v(!1),C.current.set(d.id,A),r(po(d,A))})()},T=async()=>{c(!0);try{const R=await u(d.id,{content:i.content});R.ok?(C.current.set(d.id,i.content),R.reloadFailed?M.warning(R.message||t("settings.plugins.toast.reloadFailed"),{description:R.warning}):R.restartDeferred?M.success(t("settings.view.pendingRestart.saved")):M.success(R.message||t("settings.plugins.toast.updated"))):M.error(R.message||t("settings.plugins.toast.reloadFailed"))}finally{c(!1)}};return s.jsx(ns,{title:t("settings.plugins.page.header.file"),titleAccessory:s.jsxs(s.Fragment,{children:[s.jsx(mo,{scope:d.scope,label:d.scope==="project"?t("settings.plugins.sidebar.group.projectFiles"):t("settings.plugins.sidebar.group.userFiles")}),s.jsx("span",{className:we("typography-micro font-mono rounded-full px-2 py-0.5","bg-[var(--surface-elevated)] text-foreground","border border-[var(--interactive-border)]"),children:d.fileName})]}),showSaveStatus:!1,children:s.jsxs(_e,{title:t("settings.plugins.page.field.content"),divider:!1,settingsItem:"plugins.content",children:[s.jsx(Is,{value:i.content,onChange:R=>r({...i,content:R.target.value}),rows:16,className:"font-mono typography-meta min-h-[320px]",spellCheck:!1,disabled:N}),s.jsxs("div",{className:"flex items-center gap-2 pt-3",children:[s.jsx(B,{variant:"default",size:"sm",onClick:()=>{T()},disabled:!S||w||N,children:t("settings.plugins.page.action.save")}),s.jsx(B,{variant:"outline",size:"sm",onClick:g,disabled:w||N,children:t("settings.plugins.page.action.discard")})]})]})})}return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsx("div",{className:"text-center text-muted-foreground",children:s.jsx(O,{name:"loader-4",className:"mx-auto mb-3 h-6 w-6 animate-spin opacity-50"})})})},Ep="<built-in>",Fa=t=>t?.path===Ep,ir=t=>!!t&&!Fa(t)&&t.renamable===!0,Dp=t=>{const e=mt.c(157),{onItemSelect:a}=t,{t:n}=at(),[i,r]=o.useState(null),[l,u]=o.useState(""),[p,h]=o.useState(null),[d,w]=o.useState(!1),[c,N]=o.useState(null),{selectedSkillName:v,setSelectedSkill:C,setSkillDraft:y,deleteSkill:S,renameSkill:g,getSkillDetail:T}=$s(Ds(Mp)),R=Us();let A;e[0]!==R?(A=Te=>pr(Te,R),e[0]=R,e[1]=A):A=e[1];const j=$s(A),f=$s(Rp);let b,F;e[2]!==f||e[3]!==R?(b=()=>{f(R)},F=[f,R],e[2]=f,e[3]=R,e[4]=b,e[5]=F):(b=e[4],F=e[5]),o.useEffect(b,F);let D;e[6]!==a||e[7]!==C||e[8]!==y||e[9]!==j?(D=()=>{let Te="new-skill",wt=1;for(;j.some(Q=>Q.name===Te);)Te=`new-skill-${wt}`,wt++;y({name:Te,scope:"user",source:"opencode",description:""}),C(Te),a?.()},e[6]=a,e[7]=C,e[8]=y,e[9]=j,e[10]=D):D=e[10];const P=D;let I;e[11]===Symbol.for("react.memo_cache_sentinel")?(I=async Te=>{Fa(Te)||h(Te)},e[11]=I):I=e[11];const U=I;let q;e[12]!==p||e[13]!==S||e[14]!==R||e[15]!==n?(q=async()=>{if(!p)return;if(Fa(p)){h(null);return}w(!0),await S(p.name,R)?(M.success(n("settings.skills.sidebar.toast.skillDeleted",{name:p.name})),h(null)):M.error(n("settings.skills.sidebar.toast.deleteSkillFailed")),w(!1)},e[12]=p,e[13]=S,e[14]=R,e[15]=n,e[16]=q):q=e[16];const k=q;let $;e[17]!==T||e[18]!==C||e[19]!==y||e[20]!==R||e[21]!==j||e[22]!==n?($=async Te=>{if(Fa(Te))return;const wt=Te.name;let Q=1,fe=`${wt}-copy`;for(;j.some(Me=>Me.name===fe);)Q++,fe=`${wt}-copy-${Q}`;const Ue=await T(Te.name,R);if(!Ue){M.error(n("settings.skills.sidebar.toast.duplicateLoadFailed"));return}y({name:fe,scope:Te.scope||"user",source:Te.source||"opencode",description:(Ue.sources.md.fields.includes("description"),""),instructions:""}),C(fe)},e[17]=T,e[18]=C,e[19]=y,e[20]=R,e[21]=j,e[22]=n,e[23]=$):$=e[23];const G=$;let E;e[24]===Symbol.for("react.memo_cache_sentinel")?(E=Te=>{ir(Te)&&(u(Te.name),r(Te))},e[24]=E):E=e[24];const J=E;let X;e[25]!==i||e[26]!==l||e[27]!==g||e[28]!==C||e[29]!==R||e[30]!==j||e[31]!==n?(X=async()=>{if(!i)return;if(!ir(i)){r(null);return}const Te=l.trim().replace(/\s+/g,"-").toLowerCase();if(!Te){M.error(n("settings.skills.page.toast.skillNameRequired"));return}if(Te===i.name){r(null);return}if(j.some(Q=>Q.name===Te)){M.error(n("settings.skills.page.toast.skillExists"));return}await g(i.name,Te,R)?(M.success(n("settings.skills.sidebar.toast.skillRenamed",{name:Te})),C(Te)):M.error(n("settings.skills.sidebar.toast.renameFailed")),r(null)},e[25]=i,e[26]=l,e[27]=g,e[28]=C,e[29]=R,e[30]=j,e[31]=n,e[32]=X):X=e[32];const L=X;let se;e[33]!==j?(se=j.filter(Op),e[33]=j,e[34]=se):se=e[34];const z=se;let V;e[35]!==j?(V=j.filter(Lp),e[35]=j,e[36]=V):V=e[36];const _=V;let K;e[37]===Symbol.for("react.memo_cache_sentinel")?(K=function(wt){const Q={},fe=[];for(const Me of wt)Me.group?(Q[Me.group]||(Q[Me.group]=[]),Q[Me.group].push(Me)):fe.push(Me);const Ue=Object.keys(Q).sort(Fp).map(Me=>({name:Me,skills:[...Q[Me]].sort(Kp)}));return fe.sort(zp),{sortedGroups:Ue,ungrouped:fe}},e[37]=K):K=e[37];const Z=K;let Y;e[38]!==z?(Y=Z(z),e[38]=z,e[39]=Y):Y=e[39];const te=Y;let ge;e[40]!==_?(ge=Z(_),e[40]=_,e[41]=ge):ge=e[41];const le=ge;let he;e[42]===Symbol.for("react.memo_cache_sentinel")?(he=we("flex h-full flex-col","bg-background"),e[42]=he):he=e[42];let ne;e[43]!==n?(ne=n("settings.skills.sidebar.title"),e[43]=n,e[44]=ne):ne=e[44];let ae;e[45]!==ne?(ae=s.jsx("h2",{className:`${on} mb-3`,children:ne}),e[45]=ne,e[46]=ae):ae=e[46];let me;e[47]===Symbol.for("react.memo_cache_sentinel")?(me=s.jsx(Va,{className:"mb-3"}),e[47]=me):me=e[47];let Pe;e[48]!==j.length||e[49]!==n?(Pe=n("settings.skills.sidebar.total",{count:j.length}),e[48]=j.length,e[49]=n,e[50]=Pe):Pe=e[50];let Ne;e[51]!==Pe?(Ne=s.jsx("span",{className:"typography-meta text-muted-foreground",children:Pe}),e[51]=Pe,e[52]=Ne):Ne=e[52];let Se;e[53]===Symbol.for("react.memo_cache_sentinel")?(Se=s.jsx(O,{name:"add",className:"h-3.5 w-3.5"}),e[53]=Se):Se=e[53];let be;e[54]!==P?(be=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:P,children:Se}),e[54]=P,e[55]=be):be=e[55];let Ke;e[56]!==Ne||e[57]!==be?(Ke=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[Ne,be]}),e[56]=Ne,e[57]=be,e[58]=Ke):Ke=e[58];let Le;e[59]!==ae||e[60]!==Ke?(Le=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[ae,me,Ke]}),e[59]=ae,e[60]=Ke,e[61]=Le):Le=e[61];let oe;e[62]!==te||e[63]!==le||e[64]!==G||e[65]!==a||e[66]!==c||e[67]!==z||e[68]!==v||e[69]!==C||e[70]!==j.length||e[71]!==n||e[72]!==_?(oe=s.jsx(Bs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:j.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(O,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:n("settings.skills.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.skills.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[z.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.skills.sidebar.section.project")}),te.sortedGroups.map(Te=>{const{name:wt,skills:Q}=Te;return s.jsx(er,{label:wt,count:Q.length,storageKey:"project-skills",children:Q.map(fe=>s.jsx(ti,{skill:fe,isSelected:v===fe.name,onSelect:()=>{C(fe.name),a?.()},onRename:()=>J(fe),onDelete:()=>U(fe),onDuplicate:()=>G(fe),isMenuOpen:c===fe.name,onMenuOpenChange:Ue=>N(Ue?fe.name:null)},fe.name))},wt)}),te.ungrouped.map(Te=>s.jsx(ti,{skill:Te,isSelected:v===Te.name,onSelect:()=>{C(Te.name),a?.()},onRename:()=>J(Te),onDelete:()=>U(Te),onDuplicate:()=>G(Te),isMenuOpen:c===Te.name,onMenuOpenChange:wt=>N(wt?Te.name:null)},Te.name))]}),_.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-3 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:n("settings.skills.sidebar.section.user")}),le.sortedGroups.map(Te=>{const{name:wt,skills:Q}=Te;return s.jsx(er,{label:wt,count:Q.length,storageKey:"user-skills",children:Q.map(fe=>s.jsx(ti,{skill:fe,isSelected:v===fe.name,onSelect:()=>{C(fe.name),a?.()},onRename:()=>J(fe),onDelete:()=>U(fe),onDuplicate:()=>G(fe),isMenuOpen:c===fe.name,onMenuOpenChange:Ue=>N(Ue?fe.name:null)},fe.name))},wt)}),le.ungrouped.map(Te=>s.jsx(ti,{skill:Te,isSelected:v===Te.name,onSelect:()=>{C(Te.name),a?.()},onRename:()=>J(Te),onDelete:()=>U(Te),onDuplicate:()=>G(Te),isMenuOpen:c===Te.name,onMenuOpenChange:wt=>N(wt?Te.name:null)},Te.name))]})]})}),e[62]=te,e[63]=le,e[64]=G,e[65]=a,e[66]=c,e[67]=z,e[68]=v,e[69]=C,e[70]=j.length,e[71]=n,e[72]=_,e[73]=oe):oe=e[73];const xe=p!==null;let Ee;e[74]!==d?(Ee=Te=>{!Te&&!d&&h(null)},e[74]=d,e[75]=Ee):Ee=e[75];let Ve;e[76]!==n?(Ve=n("settings.skills.sidebar.deleteDialog.title"),e[76]=n,e[77]=Ve):Ve=e[77];let $e;e[78]!==Ve?($e=s.jsx(_t,{children:Ve}),e[78]=Ve,e[79]=$e):$e=e[79];const We=p?.name??"";let Fe;e[80]!==n||e[81]!==We?(Fe=n("settings.skills.sidebar.deleteDialog.description",{name:We}),e[80]=n,e[81]=We,e[82]=Fe):Fe=e[82];let ie;e[83]!==Fe?(ie=s.jsx($t,{children:Fe}),e[83]=Fe,e[84]=ie):ie=e[84];let re;e[85]!==$e||e[86]!==ie?(re=s.jsxs(Ut,{children:[$e,ie]}),e[85]=$e,e[86]=ie,e[87]=re):re=e[87];let je;e[88]===Symbol.for("react.memo_cache_sentinel")?(je=()=>h(null),e[88]=je):je=e[88];let ve;e[89]!==n?(ve=n("settings.common.actions.cancel"),e[89]=n,e[90]=ve):ve=e[90];let Re;e[91]!==d||e[92]!==ve?(Re=s.jsx(B,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:je,disabled:d,children:ve}),e[91]=d,e[92]=ve,e[93]=Re):Re=e[93];let Ae;e[94]!==n?(Ae=n("settings.common.actions.delete"),e[94]=n,e[95]=Ae):Ae=e[95];let ye;e[96]!==k||e[97]!==d||e[98]!==Ae?(ye=s.jsx(B,{size:"sm",onClick:k,disabled:d,children:Ae}),e[96]=k,e[97]=d,e[98]=Ae,e[99]=ye):ye=e[99];let He;e[100]!==Re||e[101]!==ye?(He=s.jsxs(es,{children:[Re,ye]}),e[100]=Re,e[101]=ye,e[102]=He):He=e[102];let ue;e[103]!==re||e[104]!==He?(ue=s.jsxs(Kt,{className:"max-w-md",children:[re,He]}),e[103]=re,e[104]=He,e[105]=ue):ue=e[105];let Ce;e[106]!==xe||e[107]!==Ee||e[108]!==ue?(Ce=s.jsx(Ft,{open:xe,onOpenChange:Ee,children:ue}),e[106]=xe,e[107]=Ee,e[108]=ue,e[109]=Ce):Ce=e[109];const De=i!==null;let Ye;e[110]===Symbol.for("react.memo_cache_sentinel")?(Ye=Te=>!Te&&r(null),e[110]=Ye):Ye=e[110];let W;e[111]!==n?(W=n("settings.skills.sidebar.renameDialog.title"),e[111]=n,e[112]=W):W=e[112];let ke;e[113]!==W?(ke=s.jsx(_t,{children:W}),e[113]=W,e[114]=ke):ke=e[114];const Ie=i?.name??"";let Ge;e[115]!==n||e[116]!==Ie?(Ge=n("settings.skills.sidebar.renameDialog.description",{name:Ie}),e[115]=n,e[116]=Ie,e[117]=Ge):Ge=e[117];let it;e[118]!==Ge?(it=s.jsx($t,{children:Ge}),e[118]=Ge,e[119]=it):it=e[119];let nt;e[120]!==ke||e[121]!==it?(nt=s.jsxs(Ut,{children:[ke,it]}),e[120]=ke,e[121]=it,e[122]=nt):nt=e[122];let dt;e[123]===Symbol.for("react.memo_cache_sentinel")?(dt=Te=>u(Te.target.value),e[123]=dt):dt=e[123];let xt;e[124]!==n?(xt=n("settings.skills.sidebar.renameDialog.placeholder"),e[124]=n,e[125]=xt):xt=e[125];let H;e[126]!==L?(H=Te=>{Te.key==="Enter"&&L()},e[126]=L,e[127]=H):H=e[127];let Be;e[128]!==l||e[129]!==xt||e[130]!==H?(Be=s.jsx(Je,{value:l,onChange:dt,placeholder:xt,className:"text-foreground placeholder:text-muted-foreground",onKeyDown:H}),e[128]=l,e[129]=xt,e[130]=H,e[131]=Be):Be=e[131];let tt;e[132]===Symbol.for("react.memo_cache_sentinel")?(tt=()=>r(null),e[132]=tt):tt=e[132];let rt;e[133]!==n?(rt=n("settings.common.actions.cancel"),e[133]=n,e[134]=rt):rt=e[134];let ut;e[135]!==rt?(ut=s.jsx(B,{size:"sm",className:"text-foreground hover:bg-interactive-hover hover:text-foreground",variant:"ghost",onClick:tt,children:rt}),e[135]=rt,e[136]=ut):ut=e[136];let Ct;e[137]!==n?(Ct=n("settings.common.actions.rename"),e[137]=n,e[138]=Ct):Ct=e[138];let et;e[139]!==L||e[140]!==Ct?(et=s.jsx(B,{size:"sm",onClick:L,children:Ct}),e[139]=L,e[140]=Ct,e[141]=et):et=e[141];let Xe;e[142]!==ut||e[143]!==et?(Xe=s.jsxs(es,{children:[ut,et]}),e[142]=ut,e[143]=et,e[144]=Xe):Xe=e[144];let ft;e[145]!==nt||e[146]!==Be||e[147]!==Xe?(ft=s.jsxs(Kt,{children:[nt,Be,Xe]}),e[145]=nt,e[146]=Be,e[147]=Xe,e[148]=ft):ft=e[148];let ze;e[149]!==De||e[150]!==ft?(ze=s.jsx(Ft,{open:De,onOpenChange:Ye,children:ft}),e[149]=De,e[150]=ft,e[151]=ze):ze=e[151];let jt;return e[152]!==Le||e[153]!==oe||e[154]!==Ce||e[155]!==ze?(jt=s.jsxs("div",{className:he,children:[Le,oe,Ce,ze]}),e[152]=Le,e[153]=oe,e[154]=Ce,e[155]=ze,e[156]=jt):jt=e[156],jt},ti=t=>{const e=mt.c(41),{skill:a,isSelected:n,onSelect:i,onDelete:r,onRename:l,onDuplicate:u,isMenuOpen:p,onMenuOpenChange:h}=t,{t:d}=at();let w;e[0]===Symbol.for("react.memo_cache_sentinel")?(w=za(),e[0]=w):w=e[0];const c=w;let N;e[1]!==a?(N=Fa(a),e[1]=a,e[2]=N):N=e[2];const v=N;let C;e[3]!==a?(C=ir(a),e[3]=a,e[4]=C):C=e[4];const y=C,[S,g]=o.useState(!1);let T;e[5]!==y||e[6]!==r||e[7]!==u||e[8]!==l||e[9]!==d?(T=G=>s.jsxs(s.Fragment,{children:[y?s.jsxs(G,{onClick:E=>{E.stopPropagation(),l()},children:[s.jsx(O,{name:"edit",className:"h-4 w-4 mr-px"}),d("settings.common.actions.rename")]}):null,s.jsxs(G,{onClick:E=>{E.stopPropagation(),u()},children:[s.jsx(O,{name:"file-copy",className:"h-4 w-4 mr-px"}),d("settings.common.actions.duplicate")]}),s.jsxs(G,{onClick:E=>{E.stopPropagation(),r()},className:"text-destructive focus:text-destructive",children:[s.jsx(O,{name:"delete-bin",className:"h-4 w-4 mr-px"}),d("settings.common.actions.delete")]})]}),e[5]=y,e[6]=r,e[7]=u,e[8]=l,e[9]=d,e[10]=T):T=e[10];const R=T,A=!v&&S,j=n?"bg-interactive-selection":"hover:bg-interactive-hover";let f;e[11]!==j?(f=we("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",j),e[11]=j,e[12]=f):f=e[12];let b;e[13]!==v?(b=!c&&!v?G=>{G.preventDefault(),g(!0)}:void 0,e[13]=v,e[14]=b):b=e[14];let F;e[15]!==f||e[16]!==b?(F=s.jsx("div",{className:f,onContextMenu:b}),e[15]=f,e[16]=b,e[17]=F):F=e[17];let D;e[18]!==a.name?(D=s.jsx("div",{className:"flex items-center gap-1.5",children:s.jsx("span",{className:"typography-ui-label font-normal truncate text-foreground",children:a.name})}),e[18]=a.name,e[19]=D):D=e[19];let P;e[20]!==i||e[21]!==D?(P=s.jsx("button",{onClick:i,className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:D}),e[20]=i,e[21]=D,e[22]=P):P=e[22];let I;e[23]!==v||e[24]!==p||e[25]!==h||e[26]!==R?(I=v?null:s.jsxs(an,{open:p,onOpenChange:G=>{G&&g(!1),h(G)},children:[s.jsx(sn,{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(O,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(nn,{align:"end",className:"w-fit min-w-20",children:R(rn)})]}),e[23]=v,e[24]=p,e[25]=h,e[26]=R,e[27]=I):I=e[27];let U;e[28]!==P||e[29]!==I?(U=s.jsxs("div",{className:"flex min-w-0 flex-1 items-center",children:[P,I]}),e[28]=P,e[29]=I,e[30]=U):U=e[30];let q;e[31]!==U||e[32]!==F?(q=s.jsx(qn,{render:F,children:U}),e[31]=U,e[32]=F,e[33]=q):q=e[33];let k;e[34]!==v||e[35]!==R?(k=v?null:s.jsx(Gn,{className:"w-fit min-w-20",children:R(Wn)}),e[34]=v,e[35]=R,e[36]=k):k=e[36];let $;return e[37]!==q||e[38]!==k||e[39]!==A?($=s.jsxs(Jn,{open:A,onOpenChange:g,children:[q,k]}),e[37]=q,e[38]=k,e[39]=A,e[40]=$):$=e[40],$};function Mp(t){return{selectedSkillName:t.selectedSkillName,setSelectedSkill:t.setSelectedSkill,setSkillDraft:t.setSkillDraft,deleteSkill:t.deleteSkill,renameSkill:t.renameSkill,getSkillDetail:t.getSkillDetail}}function Rp(t){return t.loadSkills}function Op(t){return t.scope==="project"}function Lp(t){return t.scope==="user"}function Fp(t,e){return t.localeCompare(e)}function Kp(t,e){return t.name.localeCompare(e.name)}function zp(t,e){return t.name.localeCompare(e.name)}const Up=()=>`custom:${Date.now()}-${Math.random().toString(16).slice(2)}`,_p=t=>{const e=t.trim(),a=e.startsWith("https://")?"https":e.startsWith("git@")?"ssh":"shorthand";if(a==="ssh")return`${e.split(":")[1].replace(/\.git$/i,"")}`;if(a==="https")return e.split("/").slice(3).filter(Boolean).join("/").replace(/\.git$/i,"");const n=e.match(/^([^/\s]+)\/([^/\s]+)(?:\/.+)?$/);return n?`${n[1]}/${n[2].replace(/\.git$/i,"")}`:e},$p=async()=>{try{const t=tn()?.settings;if(t)return(await t.load())?.settings||{};const e=await pt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},Vp=t=>{const e=mt.c(162),{open:a,onOpenChange:n}=t,{t:i}=at(),r=fn(Bp),l=fn(Hp),u=fn(Gp),p=fn(Wp),h=fn(qp),d=_n(Jp),w=_n(Qp),[c,N]=o.useState(""),[v,C]=o.useState(""),[y,S]=o.useState("");let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=[],e[0]=g):g=e[0];const[T,R]=o.useState(g),[A,j]=o.useState(null),[f,b]=o.useState(!1);let F;e[1]===Symbol.for("react.memo_cache_sentinel")?(F=[],e[1]=F):F=e[1];const[D,P]=o.useState(F),[I,U]=o.useState(null),q=o.useRef(0);let k;e[2]===Symbol.for("react.memo_cache_sentinel")?(k=Xe=>{q.current=q.current+1,b(!1),j(null),Xe?.clearIdentity&&(P([]),U(null))},e[2]=k):k=e[2];const $=k;let G,E;e[3]!==w||e[4]!==a?(G=()=>{a&&(q.current=q.current+1,N(""),C(""),S(""),j(null),b(!1),P([]),U(null),w(),(async()=>{const Xe=await $p(),ft=Array.isArray(Xe?.skillCatalogs)?Xe?.skillCatalogs:[];R(ft||[])})())},E=[a,w],e[3]=w,e[4]=a,e[5]=G,e[6]=E):(G=e[5],E=e[6]),o.useEffect(G,E);let J;e[7]!==v?(J=v.trim(),e[7]=v,e[8]=J):J=e[8];const X=J;let L;e[9]!==y?(L=y.trim(),e[9]=y,e[10]=L):L=e[10];const se=L;let z;if(e[11]!==T||e[12]!==X||e[13]!==se){let Xe;e[15]!==X||e[16]!==se?(Xe=ft=>{const ze=(ft.source||"").trim(),jt=(ft.subpath||"").trim();return ze===X&&jt===se},e[15]=X,e[16]=se,e[17]=Xe):Xe=e[17],z=T.some(Xe),e[11]=T,e[12]=X,e[13]=se,e[14]=z}else z=e[14];const V=z;let _;e[18]!==d||e[19]!==I||e[20]!==c||e[21]!==r||e[22]!==v||e[23]!==y||e[24]!==i?(_=async()=>{const Xe=v.trim();if(!Xe){M.error(i("settings.skills.catalog.add.toast.repositoryRequired"));return}c.trim()||N(_p(Xe)),b(!1),j(null);const ft=q.current+1;q.current=ft;const ze=await r({source:Xe,subpath:y.trim()||void 0,gitIdentityId:I||void 0});if(q.current!==ft)return;if(!ze.ok){if(ze.error?.kind==="authRequired"){if(us()){M.error(i("settings.skills.catalog.shared.toast.privateRepoNotSupportedVsCode"));return}const Te=ze.error.identities||[];if(P(Te),!I&&Te.length>0){const wt=d&&d!=="global"&&Te.some(Q=>Q.id===d)?d:Te[0].id;U(wt)}M.error(i("settings.skills.catalog.add.toast.authenticationRequiredScan"));return}M.error(ze.error?.message||i("settings.skills.catalog.add.toast.scanFailed"));return}const jt=ze.items?.length||0;if(j(jt),jt===0){M.error(i("settings.skills.catalog.add.toast.noSkillsFound")),b(!1);return}P([]),b(!0),M.success(i("settings.skills.catalog.shared.toast.foundSkills",{count:jt}))},e[18]=d,e[19]=I,e[20]=c,e[21]=r,e[22]=v,e[23]=y,e[24]=i,e[25]=_):_=e[25];const K=_;let Z;e[26]!==T||e[27]!==I||e[28]!==V||e[29]!==c||e[30]!==l||e[31]!==u||e[32]!==n||e[33]!==f||e[34]!==p||e[35]!==v||e[36]!==y||e[37]!==i?(Z=async()=>{const Xe=c.trim(),ft=v.trim(),ze=y.trim();if(!Xe){M.error(i("settings.skills.catalog.add.toast.catalogNameRequired"));return}if(!ft){M.error(i("settings.skills.catalog.add.toast.repositoryRequired"));return}if(!f){M.error(i("settings.skills.catalog.add.toast.scanBeforeAdd"));return}if(V){M.error(i("settings.skills.catalog.add.toast.catalogAlreadyExists"));return}const jt={id:Up(),label:Xe,source:ft,...ze?{subpath:ze}:{},...I?{gitIdentityId:I}:{}},Te=[...T,jt];try{await yt({skillCatalogs:Te}),R(Te),M.success(i("settings.skills.catalog.add.toast.catalogAdded")),await l({refresh:!0}),await u(jt.id,{refresh:!0}),p(jt.id),n(!1)}catch(wt){const Q=wt;M.error(Q instanceof Error?Q.message:i("settings.skills.catalog.add.toast.saveFailed"))}},e[26]=T,e[27]=I,e[28]=V,e[29]=c,e[30]=l,e[31]=u,e[32]=n,e[33]=f,e[34]=p,e[35]=v,e[36]=y,e[37]=i,e[38]=Z):Z=e[38];const Y=Z;let te;e[39]!==i?(te=i("settings.skills.catalog.add.title"),e[39]=i,e[40]=te):te=e[40];let ge;e[41]!==te?(ge=s.jsx(_t,{children:te}),e[41]=te,e[42]=ge):ge=e[42];let le;e[43]!==i?(le=i("settings.skills.catalog.add.descriptionPrefix"),e[43]=i,e[44]=le):le=e[44];let he;e[45]===Symbol.for("react.memo_cache_sentinel")?(he=s.jsx("code",{className:"font-mono",children:"SKILL.md"}),e[45]=he):he=e[45];let ne;e[46]!==i?(ne=i("settings.skills.catalog.add.descriptionSuffix"),e[46]=i,e[47]=ne):ne=e[47];let ae;e[48]!==le||e[49]!==ne?(ae=s.jsxs($t,{children:[le," ",he,ne]}),e[48]=le,e[49]=ne,e[50]=ae):ae=e[50];let me;e[51]!==ge||e[52]!==ae?(me=s.jsxs(Ut,{children:[ge,ae]}),e[51]=ge,e[52]=ae,e[53]=me):me=e[53];let Pe;e[54]!==i?(Pe=i("settings.skills.catalog.add.field.catalogName"),e[54]=i,e[55]=Pe):Pe=e[55];let Ne;e[56]!==Pe?(Ne=s.jsx("label",{className:"typography-ui-label text-foreground",children:Pe}),e[56]=Pe,e[57]=Ne):Ne=e[57];let Se;e[58]===Symbol.for("react.memo_cache_sentinel")?(Se=Xe=>N(Xe.target.value),e[58]=Se):Se=e[58];let be;e[59]!==i?(be=i("settings.skills.catalog.add.field.catalogNamePlaceholder"),e[59]=i,e[60]=be):be=e[60];let Ke;e[61]!==c||e[62]!==be?(Ke=s.jsx(Je,{value:c,onChange:Se,placeholder:be}),e[61]=c,e[62]=be,e[63]=Ke):Ke=e[63];let Le;e[64]!==Ne||e[65]!==Ke?(Le=s.jsxs("div",{className:"space-y-2",children:[Ne,Ke]}),e[64]=Ne,e[65]=Ke,e[66]=Le):Le=e[66];let oe;e[67]!==i?(oe=i("settings.skills.catalog.add.field.repository"),e[67]=i,e[68]=oe):oe=e[68];let xe;e[69]!==oe?(xe=s.jsx("label",{className:"typography-ui-label text-foreground",children:oe}),e[69]=oe,e[70]=xe):xe=e[70];let Ee;e[71]!==i?(Ee=i("settings.skills.catalog.add.field.repositoryHint"),e[71]=i,e[72]=Ee):Ee=e[72];let Ve;e[73]!==Ee?(Ve=s.jsx(Jt,{children:Ee}),e[73]=Ee,e[74]=Ve):Ve=e[74];let $e;e[75]!==xe||e[76]!==Ve?($e=s.jsxs("div",{className:"flex items-center gap-1",children:[xe,Ve]}),e[75]=xe,e[76]=Ve,e[77]=$e):$e=e[77];let We;e[78]===Symbol.for("react.memo_cache_sentinel")?(We=Xe=>{C(Xe.target.value),$({clearIdentity:!0})},e[78]=We):We=e[78];let Fe;e[79]!==i?(Fe=i("settings.skills.catalog.shared.field.repositoryPlaceholder"),e[79]=i,e[80]=Fe):Fe=e[80];let ie;e[81]!==v||e[82]!==Fe?(ie=s.jsx(Je,{value:v,onChange:We,placeholder:Fe}),e[81]=v,e[82]=Fe,e[83]=ie):ie=e[83];let re;e[84]!==$e||e[85]!==ie?(re=s.jsxs("div",{className:"space-y-2",children:[$e,ie]}),e[84]=$e,e[85]=ie,e[86]=re):re=e[86];let je;e[87]!==i?(je=i("settings.skills.catalog.add.field.optionalSubpath"),e[87]=i,e[88]=je):je=e[88];let ve;e[89]!==je?(ve=s.jsx("label",{className:"typography-ui-label text-foreground",children:je}),e[89]=je,e[90]=ve):ve=e[90];let Re;e[91]===Symbol.for("react.memo_cache_sentinel")?(Re=Xe=>{S(Xe.target.value),$({clearIdentity:!0})},e[91]=Re):Re=e[91];let Ae;e[92]!==i?(Ae=i("settings.skills.catalog.shared.field.subpathPlaceholder"),e[92]=i,e[93]=Ae):Ae=e[93];let ye;e[94]!==y||e[95]!==Ae?(ye=s.jsx(Je,{value:y,onChange:Re,placeholder:Ae}),e[94]=y,e[95]=Ae,e[96]=ye):ye=e[96];let He;e[97]!==ve||e[98]!==ye?(He=s.jsxs("div",{className:"space-y-2",children:[ve,ye]}),e[97]=ve,e[98]=ye,e[99]=He):He=e[99];let ue;e[100]!==I||e[101]!==D||e[102]!==i?(ue=D.length>0&&!us()?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:i("settings.skills.catalog.shared.auth.title")}),s.jsx("span",{className:"typography-meta text-muted-foreground ml-2",children:i("settings.skills.catalog.shared.auth.description")}),s.jsx(Jt,{className:"ml-1",children:i("settings.skills.catalog.shared.auth.footerHint")})]}),s.jsxs(Pt,{value:I||"",onValueChange:Xe=>{U(Xe),$()},children:[s.jsx(It,{className:"w-fit",children:s.jsx("span",{children:D.find(Xe=>Xe.id===I)?.name||i("settings.skills.catalog.shared.auth.chooseIdentity")})}),s.jsx(At,{align:"start",children:D.map(Yp)})]})]}):null,e[100]=I,e[101]=D,e[102]=i,e[103]=ue):ue=e[103];let Ce;e[104]!==A||e[105]!==i?(Ce=A!==null?s.jsx("div",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.add.scanResult",{count:A})}):null,e[104]=A,e[105]=i,e[106]=Ce):Ce=e[106];let De;e[107]!==V||e[108]!==i?(De=V?s.jsx("div",{className:"typography-meta text-muted-foreground",children:i("settings.skills.catalog.add.duplicateMessage")}):null,e[107]=V,e[108]=i,e[109]=De):De=e[109];let Ye;e[110]!==Le||e[111]!==re||e[112]!==He||e[113]!==ue||e[114]!==Ce||e[115]!==De?(Ye=s.jsxs("div",{className:"space-y-4",children:[Le,re,He,ue,Ce,De]}),e[110]=Le,e[111]=re,e[112]=He,e[113]=ue,e[114]=Ce,e[115]=De,e[116]=Ye):Ye=e[116];let W;e[117]!==n?(W=()=>n(!1),e[117]=n,e[118]=W):W=e[118];let ke;e[119]!==i?(ke=i("settings.common.actions.cancel"),e[119]=i,e[120]=ke):ke=e[120];let Ie;e[121]!==W||e[122]!==ke?(Ie=s.jsx(B,{size:"sm",variant:"ghost",onClick:W,children:ke}),e[121]=W,e[122]=ke,e[123]=Ie):Ie=e[123];let Ge;e[124]!==K?(Ge=()=>{K()},e[124]=K,e[125]=Ge):Ge=e[125];let it;e[126]!==h||e[127]!==v?(it=h||!v.trim(),e[126]=h,e[127]=v,e[128]=it):it=e[128];let nt;e[129]===Symbol.for("react.memo_cache_sentinel")?(nt=s.jsx(O,{name:"git-repository",className:"h-4 w-4"}),e[129]=nt):nt=e[129];let dt;e[130]!==h||e[131]!==i?(dt=i(h?"settings.skills.catalog.shared.actions.scanning":"settings.skills.catalog.shared.actions.scan"),e[130]=h,e[131]=i,e[132]=dt):dt=e[132];let xt;e[133]!==Ge||e[134]!==it||e[135]!==dt?(xt=s.jsxs(B,{size:"sm",className:"gap-2",variant:"ghost",onClick:Ge,disabled:it,children:[nt,dt]}),e[133]=Ge,e[134]=it,e[135]=dt,e[136]=xt):xt=e[136];let H;e[137]!==Y?(H=()=>{Y()},e[137]=Y,e[138]=H):H=e[138];let Be;e[139]!==V||e[140]!==c||e[141]!==f||e[142]!==v?(Be=!f||V||!c.trim()||!v.trim(),e[139]=V,e[140]=c,e[141]=f,e[142]=v,e[143]=Be):Be=e[143];let tt;e[144]!==i?(tt=i("settings.skills.catalog.add.actions.addCatalog"),e[144]=i,e[145]=tt):tt=e[145];let rt;e[146]!==H||e[147]!==Be||e[148]!==tt?(rt=s.jsx(B,{size:"sm",onClick:H,disabled:Be,children:tt}),e[146]=H,e[147]=Be,e[148]=tt,e[149]=rt):rt=e[149];let ut;e[150]!==Ie||e[151]!==xt||e[152]!==rt?(ut=s.jsxs(es,{children:[Ie,xt,rt]}),e[150]=Ie,e[151]=xt,e[152]=rt,e[153]=ut):ut=e[153];let Ct;e[154]!==me||e[155]!==Ye||e[156]!==ut?(Ct=s.jsxs(Kt,{className:"max-w-xl",children:[me,Ye,ut]}),e[154]=me,e[155]=Ye,e[156]=ut,e[157]=Ct):Ct=e[157];let et;return e[158]!==n||e[159]!==a||e[160]!==Ct?(et=s.jsx(Ft,{open:a,onOpenChange:n,children:Ct}),e[158]=n,e[159]=a,e[160]=Ct,e[161]=et):et=e[161],et};function Bp(t){return t.scanRepo}function Hp(t){return t.loadCatalog}function Gp(t){return t.loadSource}function Wp(t){return t.setSelectedSource}function qp(t){return t.isScanning}function Jp(t){return t.defaultGitIdentityId}function Qp(t){return t.loadDefaultGitIdentityId}function Yp(t){return s.jsx(ot,{value:t.id,children:t.name},t.id)}const Zp=t=>{const e=mt.c(85),{open:a,onOpenChange:n,conflicts:i,onConfirm:r}=t,{t:l}=at();let u;e[0]===Symbol.for("react.memo_cache_sentinel")?(u={},e[0]=u):u=e[0];const[p,h]=o.useState(u);let d,w;e[1]!==i||e[2]!==a?(d=()=>{if(!a)return;const Y={};for(const te of i)Y[te.skillName]="skip";h(Y)},w=[a,i],e[1]=i,e[2]=a,e[3]=d,e[4]=w):(d=e[3],w=e[4]),o.useEffect(d,w);let c;e[5]!==i?(c=Y=>{const te={};for(const ge of i)te[ge.skillName]=Y;h(te)},e[5]=i,e[6]=c):c=e[6];const N=c;let v;e[7]!==i||e[8]!==p?(v=i.length>0&&i.every(Y=>p[Y.skillName]),e[7]=i,e[8]=p,e[9]=v):v=e[9];const C=v;let y;e[10]!==l?(y=l("settings.skills.catalog.conflicts.title"),e[10]=l,e[11]=y):y=e[11];let S;e[12]!==y?(S=s.jsx(_t,{children:y}),e[12]=y,e[13]=S):S=e[13];let g;e[14]!==l?(g=l("settings.skills.catalog.conflicts.description"),e[14]=l,e[15]=g):g=e[15];let T;e[16]!==g?(T=s.jsx($t,{children:g}),e[16]=g,e[17]=T):T=e[17];let R;e[18]!==S||e[19]!==T?(R=s.jsxs(Ut,{children:[S,T]}),e[18]=S,e[19]=T,e[20]=R):R=e[20];let A;e[21]!==i.length||e[22]!==l?(A=l("settings.skills.catalog.conflicts.count",{count:i.length}),e[21]=i.length,e[22]=l,e[23]=A):A=e[23];let j;e[24]!==A?(j=s.jsx("span",{className:"typography-meta text-muted-foreground",children:A}),e[24]=A,e[25]=j):j=e[25];let f;e[26]!==N?(f=()=>N("skip"),e[26]=N,e[27]=f):f=e[27];let b;e[28]!==l?(b=l("settings.skills.catalog.conflicts.actions.skipAll"),e[28]=l,e[29]=b):b=e[29];let F;e[30]!==f||e[31]!==b?(F=s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:f,children:b}),e[30]=f,e[31]=b,e[32]=F):F=e[32];let D;e[33]!==N?(D=()=>N("overwrite"),e[33]=N,e[34]=D):D=e[34];let P;e[35]!==l?(P=l("settings.skills.catalog.conflicts.actions.overwriteAll"),e[35]=l,e[36]=P):P=e[36];let I;e[37]!==D||e[38]!==P?(I=s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:D,children:P}),e[37]=D,e[38]=P,e[39]=I):I=e[39];let U;e[40]!==F||e[41]!==I?(U=s.jsxs("div",{className:"flex items-center gap-2",children:[F,I]}),e[40]=F,e[41]=I,e[42]=U):U=e[42];let q;e[43]!==j||e[44]!==U?(q=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[j,U]}),e[43]=j,e[44]=U,e[45]=q):q=e[45];let k;if(e[46]!==i||e[47]!==p||e[48]!==l){let Y;e[50]!==p||e[51]!==l?(Y=te=>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:te.skillName}),s.jsx("div",{className:"typography-micro text-muted-foreground",children:l("settings.skills.catalog.conflicts.installedIn",{scope:te.scope==="project"?l("settings.skills.catalog.conflicts.scope.project"):l("settings.skills.catalog.conflicts.scope.user"),source:te.source==="agents"?l("settings.skills.catalog.conflicts.source.agents"):l("settings.skills.catalog.conflicts.source.opencode")})})]}),s.jsxs(Pt,{value:p[te.skillName]||"skip",onValueChange:ge=>h(le=>({...le,[te.skillName]:ge})),children:[s.jsx(It,{className:"w-fit",children:s.jsx("span",{className:"capitalize",children:(p[te.skillName]||"skip")==="overwrite"?l("settings.skills.catalog.conflicts.decision.overwrite"):l("settings.skills.catalog.conflicts.decision.skip")})}),s.jsxs(At,{align:"end",children:[s.jsx(ot,{value:"skip",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.skip")}),s.jsx(ot,{value:"overwrite",className:"pr-2 [&>span:first-child]:hidden",children:l("settings.skills.catalog.conflicts.decision.overwrite")})]})]})]},te.skillName),e[50]=p,e[51]=l,e[52]=Y):Y=e[52],k=i.map(Y),e[46]=i,e[47]=p,e[48]=l,e[49]=k}else k=e[49];let $;e[53]!==k?($=s.jsx("div",{className:"space-y-2",children:k}),e[53]=k,e[54]=$):$=e[54];let G;e[55]!==q||e[56]!==$?(G=s.jsxs("div",{className:"space-y-3",children:[q,$]}),e[55]=q,e[56]=$,e[57]=G):G=e[57];let E;e[58]!==n?(E=()=>n(!1),e[58]=n,e[59]=E):E=e[59];let J;e[60]!==l?(J=l("settings.common.actions.cancel"),e[60]=l,e[61]=J):J=e[61];let X;e[62]!==E||e[63]!==J?(X=s.jsx(B,{size:"sm",variant:"ghost",onClick:E,children:J}),e[62]=E,e[63]=J,e[64]=X):X=e[64];let L;e[65]!==p||e[66]!==r?(L=()=>r(p),e[65]=p,e[66]=r,e[67]=L):L=e[67];const se=!C;let z;e[68]!==l?(z=l("settings.skills.catalog.conflicts.actions.continue"),e[68]=l,e[69]=z):z=e[69];let V;e[70]!==L||e[71]!==se||e[72]!==z?(V=s.jsx(B,{size:"sm",onClick:L,disabled:se,children:z}),e[70]=L,e[71]=se,e[72]=z,e[73]=V):V=e[73];let _;e[74]!==X||e[75]!==V?(_=s.jsxs(es,{children:[X,V]}),e[74]=X,e[75]=V,e[76]=_):_=e[76];let K;e[77]!==R||e[78]!==G||e[79]!==_?(K=s.jsxs(Kt,{className:"max-w-2xl",children:[R,G,_]}),e[77]=R,e[78]=G,e[79]=_,e[80]=K):K=e[80];let Z;return e[81]!==n||e[82]!==a||e[83]!==K?(Z=s.jsx(Ft,{open:a,onOpenChange:n,children:K}),e[81]=n,e[82]=a,e[83]=K,e[84]=Z):Z=e[84],Z},yr=[{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 Ka(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 zl(t){if(t==="user-claude")return{scope:"user",source:"claude"};if(t==="project-claude")return{scope:"project",source:"claude"};const e=yr.find(a=>a.value===t);return e?{scope:e.scope,source:e.source}:{scope:"user",source:"opencode"}}const Xp=t=>{const e=mt.c(124),{open:a,onOpenChange:n,item:i}=t,{t:r}=at(),l=fn(em),u=fn(tm),[p,h]=o.useState("user"),[d,w]=o.useState("opencode"),c=Vs(sm),N=Vs(nm),[v,C]=o.useState(null),[y,S]=o.useState(!1);let g;e[0]===Symbol.for("react.memo_cache_sentinel")?(g=[],e[0]=g):g=e[0];const[T,R]=o.useState(g),[A,j]=o.useState(null);let f,b;e[1]!==N||e[2]!==a?(f=()=>{a&&(h("user"),w("opencode"),C(N),S(!1),R([]),j(null))},b=[a,N],e[1]=N,e[2]=a,e[3]=f,e[4]=b):(f=e[3],b=e[4]),o.useEffect(f,b);let F;e[5]!==r?(F=ye=>{switch(ye){case"project-opencode":return r("settings.skills.location.option.projectOpencode.label");case"user-agents":return r("settings.skills.location.option.userAgents.label");case"project-agents":return r("settings.skills.location.option.projectAgents.label");default:return r("settings.skills.location.option.userOpencode.label")}},e[5]=r,e[6]=F):F=e[6];const D=F;let P;e[7]!==r?(P=ye=>{switch(ye){case"project-opencode":return r("settings.skills.location.option.projectOpencode.description");case"user-agents":return r("settings.skills.location.option.userAgents.description");case"project-agents":return r("settings.skills.location.option.projectAgents.description");default:return r("settings.skills.location.option.userOpencode.description")}},e[7]=r,e[8]=P):P=e[8];const I=P;let U;e:{if(c.length===0){U=null;break e}if(v&&c.some(ye=>ye.id===v)){U=v;break e}if(N&&c.some(ye=>ye.id===N)){U=N;break e}U=c[0]?.id??null}const q=U;let k;e:{if(p!=="project"){k=null;break e}const ye=q;if(!ye){k=null;break e}let He;if(e[9]!==ye||e[10]!==c){let Ce;e[12]!==ye?(Ce=De=>De.id===ye,e[12]=ye,e[13]=Ce):Ce=e[13],He=c.find(Ce),e[9]=ye,e[10]=c,e[11]=He}else He=e[11];k=He?.path??null}const $=k;let G;e[14]!==l||e[15]!==i?.gitIdentityId||e[16]!==n||e[17]!==r?(G=async ye=>{const He=await l({source:ye.source,subpath:ye.subpath,gitIdentityId:i?.gitIdentityId,scope:ye.scope,targetSource:ye.targetSource,selections:[{skillDir:ye.skillDir}],conflictPolicy:"prompt",conflictDecisions:ye.conflictDecisions},{directory:ye.directoryOverride??null});if(He.ok){M.success(r("settings.skills.catalog.installSkill.toast.installed")),n(!1);return}if(He.error?.kind==="conflicts"){j({source:ye.source,subpath:ye.subpath,scope:ye.scope,targetSource:ye.targetSource,skillDir:ye.skillDir,directoryOverride:ye.directoryOverride??null}),R(He.error.conflicts),S(!0);return}if(He.error?.kind==="authRequired"){M.error(He.error.message||r("settings.skills.catalog.installSkill.toast.authRequired"));return}M.error(He.error?.message||r("settings.skills.catalog.installSkill.toast.installFailed"))},e[14]=l,e[15]=i?.gitIdentityId,e[16]=n,e[17]=r,e[18]=G):G=e[18];const E=G;if(!i)return null;let J;e[19]!==r?(J=r("settings.skills.catalog.installSkill.title"),e[19]=r,e[20]=J):J=e[20];let X;e[21]!==J?(X=s.jsx(_t,{children:J}),e[21]=J,e[22]=X):X=e[22];let L;e[23]!==r?(L=r("settings.skills.catalog.installSkill.descriptionPrefix"),e[23]=r,e[24]=L):L=e[24];let se;e[25]!==i.skillName?(se=s.jsx("span",{className:"font-semibold text-foreground",children:i.skillName}),e[25]=i.skillName,e[26]=se):se=e[26];let z;e[27]!==r?(z=r("settings.skills.catalog.installSkill.descriptionSuffix"),e[27]=r,e[28]=z):z=e[28];let V;e[29]!==L||e[30]!==se||e[31]!==z?(V=s.jsxs($t,{children:[L," ",se," ",z]}),e[29]=L,e[30]=se,e[31]=z,e[32]=V):V=e[32];let _;e[33]!==X||e[34]!==V?(_=s.jsxs(Ut,{children:[X,V]}),e[33]=X,e[34]=V,e[35]=_):_=e[35];let K;e[36]!==r?(K=r("settings.skills.catalog.installSkill.field.destination"),e[36]=r,e[37]=K):K=e[37];let Z;e[38]!==K?(Z=s.jsx("span",{className:"typography-ui-label text-foreground",children:K}),e[38]=K,e[39]=Z):Z=e[39];let Y;e[40]!==p||e[41]!==d?(Y=Ka(p,d),e[40]=p,e[41]=d,e[42]=Y):Y=e[42];let te;e[43]===Symbol.for("react.memo_cache_sentinel")?(te=ye=>{const He=zl(ye);h(He.scope),w(He.source==="agents"?"agents":"opencode")},e[43]=te):te=e[43];let ge;e[44]!==p?(ge=p==="user"?s.jsx(O,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(O,{name:"folder",className:"h-3.5 w-3.5"}),e[44]=p,e[45]=ge):ge=e[45];let le;e[46]!==d?(le=d==="agents"?s.jsx(O,{name:"robot-2",className:"h-3.5 w-3.5"}):null,e[46]=d,e[47]=le):le=e[47];let he;e[48]!==D||e[49]!==p||e[50]!==d?(he=D(Ka(p,d)),e[48]=D,e[49]=p,e[50]=d,e[51]=he):he=e[51];let ne;e[52]!==he?(ne=s.jsx("span",{children:he}),e[52]=he,e[53]=ne):ne=e[53];let ae;e[54]!==ge||e[55]!==le||e[56]!==ne?(ae=s.jsxs(It,{className:"w-fit gap-1.5",children:[ge,le,ne]}),e[54]=ge,e[55]=le,e[56]=ne,e[57]=ae):ae=e[57];let me;e[58]!==I||e[59]!==D?(me=yr.map(ye=>s.jsx(ot,{value:ye.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:[ye.scope==="user"?s.jsx(O,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(O,{name:"folder",className:"h-3.5 w-3.5"}),ye.source==="agents"?s.jsx(O,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:D(ye.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-5",children:I(ye.value)})]})},ye.value)),e[58]=I,e[59]=D,e[60]=me):me=e[60];let Pe;e[61]!==me?(Pe=s.jsx(At,{align:"start",children:me}),e[61]=me,e[62]=Pe):Pe=e[62];let Ne;e[63]!==Y||e[64]!==ae||e[65]!==Pe?(Ne=s.jsxs(Pt,{value:Y,onValueChange:te,children:[ae,Pe]}),e[63]=Y,e[64]=ae,e[65]=Pe,e[66]=Ne):Ne=e[66];let Se;e[67]!==Z||e[68]!==Ne?(Se=s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[Z,Ne]}),e[67]=Z,e[68]=Ne,e[69]=Se):Se=e[69];let be;e[70]!==c||e[71]!==q||e[72]!==p||e[73]!==r?(be=p==="project"&&s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:r("settings.skills.catalog.installSkill.field.project")}),c.length===0?s.jsx("span",{className:"typography-meta text-muted-foreground",children:r("settings.skills.catalog.installSkill.field.noProjects")}):s.jsxs(Pt,{value:q??"",onValueChange:ye=>C(ye),disabled:c.length===1,children:[s.jsx(It,{className:"w-fit",children:s.jsx(Rt,{placeholder:r("settings.skills.catalog.installSkill.field.chooseProjectPlaceholder")})}),s.jsx(At,{align:"start",children:c.map(am)})]})]}),e[70]=c,e[71]=q,e[72]=p,e[73]=r,e[74]=be):be=e[74];let Ke;e[75]!==i.warnings?(Ke=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]=Ke):Ke=e[76];let Le;e[77]!==Se||e[78]!==be||e[79]!==Ke?(Le=s.jsxs("div",{className:"mt-2 space-y-3",children:[Se,be,Ke]}),e[77]=Se,e[78]=be,e[79]=Ke,e[80]=Le):Le=e[80];let oe;e[81]!==n?(oe=()=>n(!1),e[81]=n,e[82]=oe):oe=e[82];let xe;e[83]!==r?(xe=r("settings.common.actions.cancel"),e[83]=r,e[84]=xe):xe=e[84];let Ee;e[85]!==oe||e[86]!==xe?(Ee=s.jsx(B,{size:"sm",variant:"ghost",onClick:oe,children:xe}),e[85]=oe,e[86]=xe,e[87]=Ee):Ee=e[87];const Ve=u||!i.installable||p==="project"&&!$;let $e;e[88]!==$||e[89]!==E||e[90]!==i.repoSource||e[91]!==i.repoSubpath||e[92]!==i.skillDir||e[93]!==p||e[94]!==d?($e=()=>{E({source:i.repoSource,subpath:i.repoSubpath,scope:p,targetSource:d,skillDir:i.skillDir,directoryOverride:$})},e[88]=$,e[89]=E,e[90]=i.repoSource,e[91]=i.repoSubpath,e[92]=i.skillDir,e[93]=p,e[94]=d,e[95]=$e):$e=e[95];let We;e[96]!==u||e[97]!==r?(We=r(u?"settings.skills.catalog.installSkill.actions.installing":"settings.skills.catalog.installSkill.actions.install"),e[96]=u,e[97]=r,e[98]=We):We=e[98];let Fe;e[99]!==Ve||e[100]!==$e||e[101]!==We?(Fe=s.jsx(B,{size:"sm",disabled:Ve,onClick:$e,children:We}),e[99]=Ve,e[100]=$e,e[101]=We,e[102]=Fe):Fe=e[102];let ie;e[103]!==Ee||e[104]!==Fe?(ie=s.jsxs(es,{children:[Ee,Fe]}),e[103]=Ee,e[104]=Fe,e[105]=ie):ie=e[105];let re;e[106]!==_||e[107]!==Le||e[108]!==ie?(re=s.jsxs(Kt,{className:"max-w-md",children:[_,Le,ie]}),e[106]=_,e[107]=Le,e[108]=ie,e[109]=re):re=e[109];let je;e[110]!==n||e[111]!==a||e[112]!==re?(je=s.jsx(Ft,{open:a,onOpenChange:n,children:re}),e[110]=n,e[111]=a,e[112]=re,e[113]=je):je=e[113];let ve;e[114]!==A||e[115]!==E?(ve=ye=>{A&&(E({source:A.source,subpath:A.subpath,scope:A.scope,targetSource:A.targetSource,skillDir:A.skillDir,conflictDecisions:ye,directoryOverride:A.directoryOverride??null}),S(!1))},e[114]=A,e[115]=E,e[116]=ve):ve=e[116];let Re;e[117]!==T||e[118]!==y||e[119]!==ve?(Re=s.jsx(Zp,{open:y,onOpenChange:S,conflicts:T,onConfirm:ve}),e[117]=T,e[118]=y,e[119]=ve,e[120]=Re):Re=e[120];let Ae;return e[121]!==je||e[122]!==Re?(Ae=s.jsxs(s.Fragment,{children:[je,Re]}),e[121]=je,e[122]=Re,e[123]=Ae):Ae=e[123],Ae};function em(t){return t.installSkills}function tm(t){return t.isInstalling}function sm(t){return t.projects}function nm(t){return t.activeProjectId}function am(t){return s.jsx(ot,{value:t.id,children:t.label||t.path},t.id)}const im=/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/,rm=t=>{const e=t.trim();return im.test(e)?`https://github.com/${e}`:null},om=t=>{const e=rm(t.repoSource);if(!e)return null;const a=[t.repoSubpath,t.skillDir].filter(Boolean).join("/");return a?`${e}/tree/HEAD/${a}`:e};let si=null;const lm=t=>{const e=hr();return(!si||si.locale!==e)&&(si={locale:e,formatter:new Intl.NumberFormat(e,{notation:"compact"})}),si.formatter.format(t)},cm=t=>{const e=Date.parse(t);if(Number.isNaN(e))return null;const a=Date.now()-e;if(a<6e4)return{key:"common.relative.justNow",count:0};const n=Math.floor(a/6e4);if(n<60)return{key:"common.relative.minutesAgoShort",count:n};const i=Math.floor(n/60);if(i<24)return{key:"common.relative.hoursAgoShort",count:i};const r=Math.floor(i/24);if(r<7)return{key:"common.relative.daysAgoShort",count:r};const l=Math.floor(r/7);return l<52?{key:"common.relative.weeksAgoShort",count:l}:{key:"common.relative.yearsAgoShort",count:Math.floor(r/365)}},dm=async()=>{try{const t=tn()?.settings;if(t)return(await t.load())?.settings||{};const e=await pt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});return e.ok?await e.json().catch(()=>null):null}catch{return null}},um=t=>{const e=mt.c(50),{source:a,isActive:n,isLoading:i,skillsCount:r,onSelect:l,t:u}=t,p=a.stars??null;let h,d,w,c,N,v,C,y,S,g;if(e[0]!==n||e[1]!==i||e[2]!==l||e[3]!==r||e[4]!==a.label||e[5]!==a.repoUpdatedAt||e[6]!==a.source||e[7]!==p||e[8]!==u){const j=a.repoUpdatedAt?cm(a.repoUpdatedAt):null;y="button",S=l,g=n;const f=n?"border-primary":"border-[var(--surface-subtle)] hover:border-[var(--interactive-border-hover)]";e[19]!==f?(d=we("w-full min-h-24 text-left rounded-lg border bg-[var(--surface-elevated)] p-3.5 flex gap-3 items-start transition-colors","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",f),e[19]=f,e[20]=d):d=e[20],N="min-w-0 flex-1 block";let b;e[21]!==a.label?(b=s.jsx("span",{className:"typography-ui-label font-medium text-foreground truncate",children:a.label}),e[21]=a.label,e[22]=b):b=e[22];let F;e[23]!==i||e[24]!==r||e[25]!==u?(F=i?s.jsx(O,{name:"refresh",className:"h-3 w-3 animate-spin text-muted-foreground shrink-0"}):r!==null&&s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:u("settings.skills.catalog.page.source.skillsCount",{count:r})}),e[23]=i,e[24]=r,e[25]=u,e[26]=F):F=e[26],e[27]!==b||e[28]!==F?(v=s.jsxs("span",{className:"flex items-center gap-2",children:[b,F]}),e[27]=b,e[28]=F,e[29]=v):v=e[29],e[30]!==a.source?(C=s.jsx("span",{className:"typography-micro font-mono text-muted-foreground block mt-0.5 truncate",children:a.source}),e[30]=a.source,e[31]=C):C=e[31],h="flex items-center gap-3 mt-1",e[32]!==p||e[33]!==u?(w=p!==null&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex items-center gap-1",title:u("settings.skills.catalog.page.source.stars",{count:p}),children:[s.jsx(O,{name:"star",className:"h-3 w-3"}),lm(p)]}),e[32]=p,e[33]=u,e[34]=w):w=e[34],c=j&&s.jsx("span",{className:"typography-micro text-muted-foreground",children:j.key==="common.relative.justNow"?u(j.key):u("settings.skills.catalog.page.source.updated",{time:u(j.key,{count:j.count})})}),e[0]=n,e[1]=i,e[2]=l,e[3]=r,e[4]=a.label,e[5]=a.repoUpdatedAt,e[6]=a.source,e[7]=p,e[8]=u,e[9]=h,e[10]=d,e[11]=w,e[12]=c,e[13]=N,e[14]=v,e[15]=C,e[16]=y,e[17]=S,e[18]=g}else h=e[9],d=e[10],w=e[11],c=e[12],N=e[13],v=e[14],C=e[15],y=e[16],S=e[17],g=e[18];let T;e[35]!==h||e[36]!==w||e[37]!==c?(T=s.jsxs("span",{className:h,children:[w,c]}),e[35]=h,e[36]=w,e[37]=c,e[38]=T):T=e[38];let R;e[39]!==T||e[40]!==N||e[41]!==v||e[42]!==C?(R=s.jsxs("span",{className:N,children:[v,C,T]}),e[39]=T,e[40]=N,e[41]=v,e[42]=C,e[43]=R):R=e[43];let A;return e[44]!==d||e[45]!==R||e[46]!==y||e[47]!==S||e[48]!==g?(A=s.jsx("button",{type:y,onClick:S,"aria-pressed":g,className:d,children:R}),e[44]=d,e[45]=R,e[46]=y,e[47]=S,e[48]=g,e[49]=A):A=e[49],A},pm=({mode:t,onModeChange:e,showModeTabs:a=!0})=>{const{t:n}=at(),{sources:i,itemsBySource:r,selectedSourceId:l,setSelectedSource:u,loadCatalog:p,loadSource:h,isLoadingCatalog:d,isLoadingSource:w,loadedSourceIds:c,lastCatalogError:N}=fn(Ds(E=>({sources:E.sources,itemsBySource:E.itemsBySource,selectedSourceId:E.selectedSourceId,setSelectedSource:E.setSelectedSource,loadCatalog:E.loadCatalog,loadSource:E.loadSource,isLoadingCatalog:E.isLoadingCatalog,isLoadingSource:E.isLoadingSource,loadedSourceIds:E.loadedSourceIds,lastCatalogError:E.lastCatalogError}))),[v,C]=o.useState(""),[y,S]=o.useState(!1),[g,T]=o.useState(!1),[R,A]=o.useState(null),[j,f]=o.useState(!1),[b,F]=o.useState(!1),D=o.useRef(null);o.useEffect(()=>{p()},[p]),o.useEffect(()=>{const E=i.filter(L=>!c[L.id]);if(E.length===0)return;let J=!1;return(async()=>{for(const L of E){if(J)return;await h(L.id)}})(),()=>{J=!0}},[i,c,h]),o.useEffect(()=>{!l||c[l]||h(l)},[l,c,h]),o.useEffect(()=>{const E=J=>{(J.metaKey||J.ctrlKey)&&J.key.toLowerCase()==="k"&&(J.preventDefault(),D.current?.focus())};return window.addEventListener("keydown",E),()=>window.removeEventListener("keydown",E)},[]);const P=v.trim().length>0,I=o.useMemo(()=>P?gi(i.flatMap(E=>r[E.id]||[]),v,E=>[E.skillName,E.frontmatterName,E.description]):l?r[l]||[]:[],[i,r,l,v,P]),U=o.useMemo(()=>i.find(E=>E.id===l)||null,[i,l]),q=!!(l&&l.startsWith("custom:")),k=async()=>{if(!(!l||!q)){f(!0);try{const E=await dm(),X=(Array.isArray(E?.skillCatalogs)?E?.skillCatalogs:[]).filter(L=>L.id!==l);await yt({skillCatalogs:X}),await p({refresh:!0}),F(!1)}finally{f(!1)}}},$=P?n("settings.skills.catalog.page.list.searchTitle"):U?.label??"",G=!P&&l!==null&&!c[l]&&(w||d);return s.jsxs(s.Fragment,{children:[s.jsxs(ns,{title:n("settings.skills.catalog.page.title"),showSaveStatus:!1,children:[a&&s.jsx("div",{className:"mb-4",children:s.jsx("div",{className:"h-10",children:s.jsx(vr,{items:[{id:"manual",label:n("settings.skills.catalog.page.mode.manual")},{id:"external",label:n("settings.skills.catalog.page.mode.external")}],activeId:t,onSelect:E=>e(E),layoutMode:"fit",variant:"animated",animateActivePill:!1,className:"h-full"})})}),s.jsx("p",{className:"typography-meta text-muted-foreground mb-4",children:n("settings.skills.catalog.page.subtitle")}),s.jsx("div",{"data-settings-item":"skills.catalog.search",className:"mb-5",children:s.jsxs("div",{className:"relative max-w-md",children:[s.jsx(O,{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(Je,{ref:D,value:v,onChange:E=>C(E.target.value),placeholder:n("settings.skills.catalog.page.searchAllPlaceholder"),className:we("h-8 pl-8 w-full",v&&"pr-8")}),v&&s.jsx("button",{type:"button",onClick:()=>{C(""),D.current?.focus()},className:"absolute right-2 top-1/2 -translate-y-1/2 flex items-center justify-center h-4 w-4 rounded text-muted-foreground hover:text-foreground transition-colors",title:n("settings.skills.catalog.page.search.clear"),children:s.jsx(O,{name:"close",className:"h-3 w-3"})})]})}),s.jsx(_e,{title:n("settings.skills.catalog.page.section.sources"),divider:!1,settingsItem:"skills.catalog.source",contentClassName:"space-y-0",children:s.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 py-1.5",children:[i.map(E=>s.jsx(um,{source:E,isActive:E.id===l,isLoading:w&&!c[E.id],skillsCount:c[E.id]?(r[E.id]||[]).length:null,onSelect:()=>u(E.id),t:n},E.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(O,{name:"add",className:"h-4 w-4"})}),s.jsxs("span",{className:"min-w-0",children:[s.jsx("span",{className:"typography-ui-label text-muted-foreground block",children:n("settings.skills.catalog.page.source.addOwnTitle")}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 block mt-0.5",children:n("settings.skills.catalog.page.source.addOwnDescription")})]})]})]})}),N&&s.jsx(_e,{children:s.jsxs("div",{className:"rounded-lg border border-[var(--status-error-border)] bg-[var(--status-error-background)] px-4 py-3",children:[s.jsx("div",{className:"typography-ui-label font-medium text-[var(--status-error)]",children:n("settings.skills.catalog.page.error.catalogTitle")}),s.jsx("div",{className:"typography-meta text-[var(--status-error)]/80 mt-1",children:N.message})]})}),s.jsxs(_e,{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:$}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:n("settings.skills.catalog.page.foundCount",{count:I.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:()=>{l&&!P?h(l,{refresh:!0}):p({refresh:!0})},disabled:d||w,title:n("settings.skills.catalog.page.actions.refreshTitle"),children:s.jsx(O,{name:"refresh",className:we("h-3.5 w-3.5",(d||w)&&"animate-spin")})}),q&&!P&&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:()=>F(!0),disabled:j,title:n("settings.skills.catalog.page.actions.removeCatalogTitle"),children:s.jsx(O,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),G||w&&I.length===0?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx(O,{name:"refresh",className:"mx-auto mb-3 h-5 w-5 animate-spin opacity-50"}),s.jsx("p",{className:"typography-meta",children:n("settings.skills.catalog.page.loading.skills")})]}):I.length===0?s.jsxs("div",{className:"py-8 text-center text-muted-foreground",children:[s.jsx("p",{className:"typography-body",children:n("settings.skills.catalog.page.empty.noSkillsTitle")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:n("settings.skills.catalog.page.empty.noSkillsDescription")})]}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:I.map(E=>{const J=E.installed?.isInstalled,X=E.installed?.scope,L=om(E);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:E.skillName}),J&&s.jsx("span",{className:"typography-micro text-[var(--status-success)] bg-[var(--status-success)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:n("settings.skills.catalog.page.badge.installed",{scope:X||n("settings.skills.catalog.page.badge.unknown")})}),!E.installable&&s.jsx("span",{className:"typography-micro text-[var(--status-warning)] bg-[var(--status-warning)]/10 px-1.5 py-0.5 rounded flex-shrink-0",children:n("settings.skills.catalog.page.badge.notInstallable")})]}),E.description?s.jsx("div",{className:"typography-meta text-muted-foreground mt-0.5 line-clamp-2",children:E.description}):s.jsx("div",{className:"typography-meta text-muted-foreground/50 mt-0.5 italic",children:n("settings.skills.catalog.shared.noDescription")}),s.jsxs("div",{className:"typography-micro text-muted-foreground/80 mt-1 flex items-center gap-2 min-w-0",children:[L?s.jsxs("a",{href:L,target:"_blank",rel:"noreferrer",className:"font-mono hover:underline truncate inline-flex items-center gap-1",title:n("settings.skills.catalog.page.skill.viewOnGithub"),children:[s.jsx(O,{name:"github",className:"h-3 w-3 shrink-0"}),E.repoSource]}):s.jsx("span",{className:"font-mono truncate",children:E.repoSource}),E.skillDir&&s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"opacity-40",children:"·"}),s.jsx("span",{className:"truncate",children:E.skillDir})]})]}),E.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:E.warnings.join(" · ")}):null]}),s.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[L&&s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal h-6 w-6 px-0",onClick:()=>window.open(L,"_blank","noreferrer"),title:n("settings.skills.catalog.page.skill.viewOnGithub"),children:s.jsx(O,{name:"external-link",className:"h-3.5 w-3.5"})}),J?s.jsx("span",{className:"text-[var(--status-success)] flex items-center justify-center w-7 h-7",title:n("settings.skills.catalog.page.badge.installed",{scope:X||""}),children:s.jsx(O,{name:"check",className:"h-4 w-4"})}):s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",disabled:!E.installable,onClick:()=>{A(E),T(!0)},children:n("settings.skills.catalog.shared.actions.install")})]})]})},`${E.sourceId}:${E.skillDir}`)})})]})]}),s.jsx(Vp,{open:y,onOpenChange:S}),s.jsx(Xp,{open:g,onOpenChange:T,item:R}),s.jsx(Ft,{open:b,onOpenChange:E=>{j||F(E)},children:s.jsxs(Kt,{className:"max-w-md",children:[s.jsxs(Ut,{children:[s.jsx(_t,{children:n("settings.skills.catalog.page.removeDialog.title")}),s.jsx($t,{children:n("settings.skills.catalog.page.removeDialog.description")})]}),s.jsxs(es,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>F(!1),disabled:j,children:n("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",variant:"destructive",onClick:()=>{k()},disabled:j,children:n("settings.skills.catalog.page.actions.removeCatalog")})]})]})})]})},mm=()=>{const t=mt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(pm,{mode:"external",onModeChange:ym,showModeTabs:!1}),t[0]=e):e=t[0],e},gm="SKILL.md",fm="h-[clamp(320px,58dvh,680px)] min-h-[260px] max-h-[calc(100dvh-220px)]",ui=(t,e)=>{const a=_d({description:t}).trimEnd(),n=e.trimStart();return`---
22
- ${a}
23
- ---${n?`
24
-
25
- ${n}`:`
26
- `}`},hm=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Ul=t=>{const e=t.match(/^---\r?\n([\s\S]*?)\r?\n---(?:\r?\n|$)([\s\S]*)$/);if(!e)return{description:null,instructions:t};let a=null;try{const n=$d(e[1]);if(hm(n)){const i=n.description;typeof i=="string"&&(a=i)}}catch{a=null}return{description:a,instructions:e[2].replace(/^\r?\n/,"")}},xm=(t,e)=>{const a=Ul(t);return ui(e,a.instructions)},vm=()=>{const{t}=at(),{currentTheme:e}=xr(),{selectedSkillName:a,getSkillByName:n,getSkillDetail:i,createSkill:r,updateSkill:l,skillDraft:u,setSkillDraft:p,setSelectedSkill:h}=$s(Ds(ue=>({selectedSkillName:ue.selectedSkillName,getSkillByName:ue.getSkillByName,getSkillDetail:ue.getSkillDetail,createSkill:ue.createSkill,updateSkill:ue.updateSkill,skillDraft:ue.skillDraft,setSkillDraft:ue.setSkillDraft,setSelectedSkill:ue.setSelectedSkill}))),d=Us(),w=$s(ue=>pr(ue,d)),c=a?n(a,d):null,N=!!(u&&u.name===a&&!c),v=!!(a&&!c&&!u),C=c?.path==="<built-in>";o.useEffect(()=>{v&&h(null)},[v,h]);const[y,S]=o.useState(""),[g,T]=o.useState("user"),[R,A]=o.useState("opencode"),[j,f]=o.useState(""),[b,F]=o.useState(""),[D,P]=o.useState(()=>ui("","")),[I,U]=o.useState("edit"),[q,k]=o.useState([]),[$,G]=o.useState([]),[E,J]=o.useState(!1),[X,L]=o.useState(!1),[se,z]=o.useState(""),[V,_]=o.useState(""),[K,Z]=o.useState(!1),[Y,te]=o.useState(""),[ge,le]=o.useState(""),[he,ne]=o.useState(null),[ae,me]=o.useState(!1),[Pe,Ne]=o.useState(""),[Se,be]=o.useState(null),[Ke,Le]=o.useState(!1),oe=N?y.trim()!==""||j.trim()!==""||b.trim()!==""||$.length>0:j!==se||b!==V,xe=he?ge!==Pe:Y.trim()!=="",Ee=o.useCallback(ue=>{switch(ue){case"project-opencode":return t("settings.skills.location.option.projectOpencode.label");case"user-claude":return t("settings.skills.location.option.userClaude.label");case"project-claude":return t("settings.skills.location.option.projectClaude.label");case"user-agents":return t("settings.skills.location.option.userAgents.label");case"project-agents":return t("settings.skills.location.option.projectAgents.label");default:return t("settings.skills.location.option.userOpencode.label")}},[t]),Ve=o.useCallback(ue=>{switch(ue){case"project-opencode":return t("settings.skills.location.option.projectOpencode.description");case"user-claude":return t("settings.skills.location.option.userClaude.description");case"project-claude":return t("settings.skills.location.option.projectClaude.description");case"user-agents":return t("settings.skills.location.option.userAgents.description");case"project-agents":return t("settings.skills.location.option.projectAgents.description");default:return t("settings.skills.location.option.userOpencode.description")}},[t]);o.useEffect(()=>{(async()=>{if(N&&u){const Ce=u.description||"",De=u.instructions||"";S(u.name||""),T(u.scope||"user"),A(u.source==="agents"?"agents":"opencode"),f(Ce),F(De),P(ui(Ce,De)),z(""),_(""),k([]),G(u.pendingFiles||[])}else if(a&&c){L(!0);try{const Ce=await i(a,d);if(Ce){const De=Ce.sources.md,Ye=De.description||"",W=De.instructions||"";f(Ye),F(W),P(ui(Ye,W)),z(Ye),_(W),k(De.supportingFiles||[])}}catch(Ce){console.error("Failed to load skill details:",Ce)}finally{L(!1)}}})()},[c,N,a,d,w,u,i]);const $e=de(ue=>ue.editorFontSize),We=o.useMemo(()=>{const ue=[Jr(e,{fontSize:$e})],Ce=Tr(gm);return Ce&&ue.push(Ce),ue.push(Yr.lineWrapping),ue},[e,$e]),Fe=o.useMemo(()=>{const ue=Y.trim()||"supporting-file.md",Ce=vc(ue),De=!!Ce&&Ce!=="markdown",Ye=[Jr(e,De?{syntaxColors:!1,fontSize:$e}:{fontSize:$e})],W=Tr(ue);return W&&Ye.push(W),De&&Ce&&Ye.push(Vd({language:Ce,themeName:e.metadata.id,theme:Hd(e)})),Ye.push(Yr.lineWrapping),Ye},[e,Y,$e]),ie=o.useCallback(ue=>{f(ue),P(Ce=>xm(Ce,ue))},[]),re=o.useCallback(ue=>{P(ue);const Ce=Ul(ue);f(Ce.description??""),F(Ce.instructions)},[]),je=async()=>{const ue=N?y.trim().replace(/\s+/g,"-").toLowerCase():a?.trim();if(!ue){M.error(t("settings.skills.page.toast.skillNameRequired"));return}if(!/^[a-z0-9][a-z0-9-]*[a-z0-9]$|^[a-z0-9]$/.test(ue)||ue.length>64){M.error(t("settings.skills.page.toast.invalidSkillName"));return}if(!j.trim()){M.error(t("settings.skills.page.toast.descriptionRequired"));return}if(N&&w.some(Ce=>Ce.name===ue)){M.error(t("settings.skills.page.toast.skillExists"));return}J(!0);try{const Ce={name:ue,description:j.trim(),instructions:b.trim()||void 0,scope:N?g:void 0,source:N?R:void 0,targetPath:N?void 0:c?.path,supportingFiles:N&&$.length>0?$:void 0};let De;if(N?(De=await r(Ce,d),De&&(p(null),G([]),h(ue))):(De=await l(ue,Ce,d),De&&(z(j.trim()),_(b.trim()))),De){const Ye=vn.getState().changes.some(W=>W.scope==="skills"&&W.id.startsWith(`skills:${ue}:`));M.success(t(Ye?"settings.view.pendingRestart.saved":N?"settings.skills.page.toast.skillCreated":"settings.skills.page.toast.skillUpdated"))}else M.error(t(N?"settings.skills.page.toast.createSkillFailed":"settings.skills.page.toast.updateSkillFailed"))}catch(Ce){console.error("Error saving skill:",Ce),M.error(t("settings.skills.page.toast.saveUnexpectedError"))}finally{J(!1)}},ve=()=>{ne(null),te(""),le(""),Ne(""),Z(!0)},Re=async ue=>{if(ne(ue),te(ue),N){const De=$.find(Ye=>Ye.path===ue)?.content||"";le(De),Ne(De),Z(!0);return}if(a){me(!0),Z(!0);try{const{readSupportingFile:Ce}=$s.getState(),De=await Ce(a,ue,d);le(De||""),Ne(De||"")}catch{M.error(t("settings.skills.page.toast.loadFileContentFailed")),le(""),Ne("")}finally{me(!1)}}},Ae=async()=>{if(!Y.trim()){M.error(t("settings.skills.page.toast.fileNameRequired"));return}const ue=Y.trim(),Ce=he!==null;if(N){if(Ce)G(W=>W.map(ke=>ke.path===he?{path:ue,content:ge}:ke)),M.success(t("settings.skills.page.toast.fileUpdated",{path:ue}));else{if($.some(W=>W.path===ue)){M.error(t("settings.skills.page.toast.fileExists"));return}G(W=>[...W,{path:ue,content:ge}]),M.success(t("settings.skills.page.toast.fileAdded",{path:ue}))}Z(!1),ne(null);return}if(!a){M.error(t("settings.skills.page.toast.noSkillSelected"));return}const{writeSupportingFile:De}=$s.getState();if(await De(a,ue,ge,d)){M.success(Ce?t("settings.skills.page.toast.fileUpdated",{path:ue}):t("settings.skills.page.toast.fileCreated",{path:ue})),Z(!1),ne(null);const W=await i(a,d);W&&k(W.sources.md.supportingFiles||[])}else M.error(t(Ce?"settings.skills.page.toast.updateFileFailed":"settings.skills.page.toast.createFileFailed"))},ye=ue=>{if(N){G(Ce=>Ce.filter(De=>De.path!==ue)),M.success(t("settings.skills.page.toast.fileRemoved",{path:ue}));return}a&&be(ue)},He=async()=>{if(!Se||!a)return;Le(!0);const{deleteSupportingFile:ue}=$s.getState();if(await ue(a,Se,d)){M.success(t("settings.skills.page.toast.fileDeleted",{path:Se}));const De=await i(a,d);De&&k(De.sources.md.supportingFiles||[]),be(null)}else M.error(t("settings.skills.page.toast.deleteFileFailed"));Le(!1)};return!a&&!u||v?s.jsx("div",{className:"flex h-full items-center justify-center px-4",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(O,{name:"book-open",className:"mx-auto mb-3 h-10 w-10 sm:h-12 sm:w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.skills.page.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.skills.page.empty.description")})]})}):X?s.jsx("div",{className:"flex h-full items-center justify-center px-4",children:s.jsx("div",{className:"text-center text-muted-foreground",children:s.jsx("p",{className:"typography-body",children:t("settings.skills.page.loading.details")})})}):s.jsxs(s.Fragment,{children:[s.jsxs(ns,{title:N?t("settings.skills.page.title.newSkill"):a,description:c?t("settings.skills.page.subtitle.skillLocation",{location:Ee(Ka(c.scope,c.source))}):t("settings.skills.page.subtitle.newSkill"),showSaveStatus:!1,children:[s.jsxs(_e,{title:t("settings.skills.page.section.basicInformation"),divider:!1,settingsItem:"skills.basic-information",contentClassName:"space-y-0",children:[N&&s.jsxs(Ot,{label:t("settings.skills.page.field.skillNameLocation"),info:t("settings.skills.page.field.skillNameHint"),children:[s.jsx(Je,{value:y,onChange:ue=>S(ue.target.value.toLowerCase().replace(/\s+/g,"-")),placeholder:t("settings.skills.page.field.skillNamePlaceholder"),className:"h-7 w-40 px-2"}),s.jsxs(Pt,{value:Ka(g,R),onValueChange:ue=>{const Ce=zl(ue);T(Ce.scope),A(Ce.source==="agents"?"agents":"opencode")},children:[s.jsxs(It,{size:Lt,className:"w-fit gap-1.5",children:[g==="user"?s.jsx(O,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(O,{name:"folder",className:"h-3.5 w-3.5"}),R==="agents"?s.jsx(O,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Ee(Ka(g,R))})]}),s.jsx(At,{align:"start",children:yr.map(ue=>s.jsx(ot,{value:ue.value,children:s.jsxs("div",{className:"flex flex-col gap-0.5",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[ue.scope==="user"?s.jsx(O,{name:"user-3",className:"h-3.5 w-3.5"}):s.jsx(O,{name:"folder",className:"h-3.5 w-3.5"}),ue.source==="agents"?s.jsx(O,{name:"robot-2",className:"h-3.5 w-3.5"}):null,s.jsx("span",{children:Ee(ue.value)})]}),s.jsx("span",{className:"typography-micro text-muted-foreground ml-6",children:Ve(ue.value)})]})},ue.value))})]})]}),s.jsx(qt,{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(Is,{value:j,onChange:ue=>ie(ue.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:C})})]}),s.jsx(_e,{title:t("settings.skills.page.section.instructions"),headerAction:s.jsx(Bd,{currentMode:I==="preview"?"preview":"edit",onToggle:()=>U(ue=>ue==="preview"?"edit":"preview")}),settingsItem:"skills.instructions",children:s.jsx("div",{className:we("overflow-hidden rounded-md border border-[var(--surface-subtle)] bg-background",fm),children:I==="preview"?s.jsx(Bs,{outerClassName:"h-full",className:"h-full",children:s.jsx("div",{className:"min-h-full px-4 py-3",children:s.jsx(yc,{content:D,className:"typography-markdown-body",stripFrontmatter:!0,enableFileReferences:!1})})}):s.jsx(Qr,{value:D,onChange:re,readOnly:C,extensions:We,className:"h-full",enableSearch:!0})})}),s.jsx(_e,{title:t("settings.skills.page.section.supportingFiles"),headerAction:s.jsxs(B,{variant:"outline",size:"xs",className:"!font-normal gap-1",onClick:ve,disabled:C,children:[s.jsx(O,{name:"add",className:"h-3.5 w-3.5"})," ",t("settings.skills.page.actions.addFile")]}),settingsItem:"skills.supporting-files",children:(()=>{const ue=N?$:q;return ue.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:ue.map(Ce=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5 cursor-pointer group",onClick:()=>Re(Ce.path),children:[s.jsx(O,{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:Ce.path}),N&&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")}),!C&&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:De=>{De.stopPropagation(),ye(Ce.path)},children:s.jsx(O,{name:"delete-bin",className:"h-3 w-3"})})]},Ce.path))})})()}),s.jsx(_e,{children:s.jsx(B,{onClick:je,disabled:C||E||!oe,size:"xs",className:"!font-normal",children:t(E?"settings.common.actions.saving":N?"settings.skills.page.actions.createSkill":"settings.common.actions.saveChanges")})})]}),s.jsx(Ft,{open:Se!==null,onOpenChange:ue=>{!ue&&!Ke&&be(null)},children:s.jsxs(Kt,{className:"max-w-md",children:[s.jsxs(Ut,{children:[s.jsx(_t,{children:t("settings.skills.page.deleteFileDialog.title")}),s.jsx($t,{children:t("settings.skills.page.deleteFileDialog.description",{path:Se??""})})]}),s.jsxs(es,{children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>be(null),disabled:Ke,children:t("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",variant:"destructive",onClick:He,disabled:Ke,children:t("settings.common.actions.delete")})]})]})}),s.jsx(Ft,{open:K,onOpenChange:ue=>{Z(ue),ue||ne(null)},children:s.jsxs(Kt,{className:"max-w-3xl max-h-[85vh] flex flex-col",children:[s.jsxs(Ut,{className:"flex-shrink-0",children:[s.jsx(_t,{children:t(he?"settings.skills.page.fileDialog.titleEdit":"settings.skills.page.fileDialog.titleAdd")}),s.jsx($t,{children:t(he?"settings.skills.page.fileDialog.descriptionEdit":"settings.skills.page.fileDialog.descriptionAdd")})]}),ae?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:Et,children:t("settings.skills.page.fileDialog.field.filePath")}),!he&&s.jsx(Jt,{children:t("settings.skills.page.fileDialog.field.filePathHint")})]}),s.jsx(Je,{value:Y,onChange:ue=>te(ue.target.value),placeholder:t("settings.skills.page.fileDialog.field.filePathPlaceholder"),className:"text-foreground placeholder:text-muted-foreground focus-visible:ring-[var(--primary-base)]",disabled:he!==null})]}),s.jsxs("div",{className:"space-y-2 flex-1 min-h-0 flex flex-col",children:[s.jsx("label",{className:`${Et} 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(Qr,{value:ge,onChange:le,extensions:Fe,className:"h-full",enableSearch:!0})})]})]}),s.jsxs(es,{className:"mt-4",children:[s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>{Z(!1),ne(null)},children:t("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",onClick:Ae,disabled:ae||!xe,children:t(he?"settings.common.actions.saveChanges":"settings.skills.page.actions.createFile")})]})]})})]})},go=t=>{const e=mt.c(2),{view:a}=t,n=a===void 0?"installed":a;let i;return e[0]!==n?(i=n==="catalog"?s.jsx(mm,{}):s.jsx(vm,{}),e[0]=n,e[1]=i):i=e[1],i};function ym(){}const bm=t=>{const e=mt.c(38),{onItemSelect:a}=t,{t:n}=at(),i=Vs(wm),r=de(jm),l=de(km),{currentTheme:u}=xr();let p;e[0]===Symbol.for("react.memo_cache_sentinel")?(p=us(),e[0]=p):p=e[0];const h=p,d=Nm;let w,c;e[1]!==i||e[2]!==r||e[3]!==l?(w=()=>{if(i.length===0){r!==null&&l(null);return}r&&i.some(f=>f.id===r)||l(i[0].id)},c=[i,r,l],e[1]=i,e[2]=r,e[3]=l,e[4]=w,e[5]=c):(w=e[4],c=e[5]),o.useEffect(w,c);let N;e[6]===Symbol.for("react.memo_cache_sentinel")?(N=we("border-b px-3","pt-4 pb-3"),e[6]=N):N=e[6];let v;e[7]!==n?(v=n("settings.page.projects.title"),e[7]=n,e[8]=v):v=e[8];let C;e[9]!==v?(C=s.jsx("h2",{className:`${on} mb-3`,children:v}),e[9]=v,e[10]=C):C=e[10];let y;e[11]!==i.length||e[12]!==n?(y=n("settings.projects.sidebar.total",{count:i.length}),e[11]=i.length,e[12]=n,e[13]=y):y=e[13];let S;e[14]!==y?(S=s.jsx("span",{className:"typography-meta text-muted-foreground",children:y}),e[14]=y,e[15]=S):S=e[15];let g;e[16]!==n?(g=!h&&s.jsx(B,{type:"button",variant:"ghost",size:"icon",className:"h-7 w-7 -my-1 text-muted-foreground",onClick:d,"aria-label":n("settings.projects.sidebar.actions.addProject"),children:s.jsx(O,{name:"add",className:"size-4"})}),e[16]=n,e[17]=g):g=e[17];let T;e[18]!==S||e[19]!==g?(T=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[S,g]}),e[18]=S,e[19]=g,e[20]=T):T=e[20];let R;e[21]!==T||e[22]!==C?(R=s.jsxs("div",{className:N,children:[C,T]}),e[21]=T,e[22]=C,e[23]=R):R=e[23];let A;if(e[24]!==u||e[25]!==a||e[26]!==i||e[27]!==r||e[28]!==l){let f;e[30]!==u||e[31]!==a||e[32]!==r||e[33]!==l?(f=b=>{const F=b.id===r,D=b.icon?wc[b.icon]:null,P=b.color?jc[b.color]??null:null,I=D?s.jsx(O,{name:D,className:we("h-4 w-4",F?"text-foreground":"text-muted-foreground/70"),style:P?{color:P}:void 0}):s.jsx(O,{name:"folder",className:we("h-4 w-4",F?"text-foreground":"text-muted-foreground/70"),style:P?{color:P}:void 0}),U=b.iconImage?s.jsx("span",{className:"inline-flex h-4 w-4 items-center justify-center overflow-hidden rounded-[2px]",style:b.iconBackground?{backgroundColor:b.iconBackground}:void 0,children:s.jsx(kc,{project:b,options:{themeVariant:u.metadata.variant,iconColor:u.colors.surface.foreground},className:"h-full w-full object-contain",fallback:I})}):I;return s.jsx(ar,{title:b.label||b.path,icon:U,selected:F,onSelect:()=>{l(b.id),a?.()}},b.id)},e[30]=u,e[31]=a,e[32]=r,e[33]=l,e[34]=f):f=e[34],A=i.map(f),e[24]=u,e[25]=a,e[26]=i,e[27]=r,e[28]=l,e[29]=A}else A=e[29];let j;return e[35]!==R||e[36]!==A?(j=s.jsx(Fl,{variant:"background",header:R,children:A}),e[35]=R,e[36]=A,e[37]=j):j=e[37],j};function wm(t){return t.projects}function jm(t){return t.settingsProjectsSelectedId}function km(t){return t.setSettingsProjectsSelectedId}function Nm(){bc.requestDirectoryDialog()}const Sm=()=>{const t=mt.c(30),{t:e}=at(),a=Vs(Cm),n=Vs(Pm),i=de(Im),r=de(Am);let l;e:{if(!i){l=null;break e}let y;t[0]!==a||t[1]!==i?(y=a.find(S=>S.id===i)??null,t[0]=a,t[1]=i,t[2]=y):y=t[2],l=y}const u=l;let p,h;t[3]!==a||t[4]!==i||t[5]!==r?(p=()=>{if(a.length===0){r(null);return}i&&a.some(y=>y.id===i)||r(a[0].id)},h=[a,i,r],t[3]=a,t[4]=i,t[5]=r,t[6]=p,t[7]=h):(p=t[6],h=t[7]),o.useEffect(p,h);let d;t[8]!==u||t[9]!==n?(d=async y=>{u&&n(u.id,{label:y.label,icon:y.icon,color:y.color,iconBackground:y.iconBackground,defaultModel:y.defaultModel??null,defaultVariant:y.defaultVariant??null})},t[8]=u,t[9]=n,t[10]=d):d=t[10];const w=d;if(!u){let y;t[11]!==e?(y=e("settings.page.projects.title"),t[11]=e,t[12]=y):y=t[12];let S;t[13]!==e?(S=e("settings.projects.page.empty.noProjects"),t[13]=e,t[14]=S):S=t[14];let g;t[15]!==S?(g=s.jsx("p",{className:"typography-meta text-muted-foreground",children:S}),t[15]=S,t[16]=g):g=t[16];let T;return t[17]!==y||t[18]!==g?(T=s.jsx(ns,{title:y,showSaveStatus:!0,children:g}),t[17]=y,t[18]=g,t[19]=T):T=t[19],T}let c;t[20]!==u.label||t[21]!==e?(c=u.label??e("settings.projects.page.title.default"),t[20]=u.label,t[21]=e,t[22]=c):c=t[22];const N=c;let v;t[23]!==w||t[24]!==u?(v=s.jsx(Od,{project:u,onIdentitySave:w}),t[23]=w,t[24]=u,t[25]=v):v=t[25];let C;return t[26]!==N||t[27]!==u.path||t[28]!==v?(C=s.jsx(ns,{title:N,description:u.path,showSaveStatus:!0,outerClassName:"bg-background",children:v}),t[26]=N,t[27]=u.path,t[28]=v,t[29]=C):C=t[29],C};function Cm(t){return t.projects}function Pm(t){return t.updateProjectMeta}function Im(t){return t.settingsProjectsSelectedId}function Am(t){return t.setSettingsProjectsSelectedId}const pi=()=>Math.floor(2e4+Math.random()*3e4),Tm=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")},Em=()=>{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"},fo=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}},ho=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.installingAiWorker";case"updating":return"settings.remoteInstances.page.phase.updatingAiWorker";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"}},Dm=new Set(["config_resolved","auth_check","master_connecting","remote_probe","installing","updating","server_detecting","server_starting","forwarding"]),br=t=>!!(t&&Dm.has(t)),xo=t=>t==="ready"?"ready":t==="error"?"error":t==="degraded"||br(t)?"connecting":"idle",vo=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"}},Mm=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 aiworker port")?"externalPort":null:null},yo={noRuntime:"settings.remoteInstances.page.error.hint.noRuntime",noOpencode:"settings.remoteInstances.page.error.hint.noOpencode"},Rm=t=>t==="noRuntime"?yo.noRuntime:t==="noOpencode"?yo.noOpencode:null,bo=t=>t==="ready"?"bg-[var(--status-success)] animate-pulse":t==="error"?"bg-[var(--status-error)] animate-pulse":t==="degraded"||br(t)?"bg-[var(--status-warning)] animate-pulse":"bg-muted-foreground/40",Om=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}`,Lm=()=>({id:`forward-${Date.now()}-${Math.random().toString(16).slice(2)}`,enabled:!0,type:"local",localHost:"127.0.0.1",localPort:pi(),remoteHost:"127.0.0.1",remotePort:80}),Fm=t=>t.trim().replace(/\*/g,"host").replace(/\?/g,"x")||"user@host",_s=t=>{const e=mt.c(7),{label:a,hint:n}=t;let i;e[0]!==a?(i=s.jsx("span",{children:a}),e[0]=a,e[1]=i):i=e[1];let r;e[2]!==n?(r=s.jsx(Jt,{contentClassName:"max-w-xs",children:n}),e[2]=n,e[3]=r):r=e[3];let l;return e[4]!==i||e[5]!==r?(l=s.jsxs("span",{className:`inline-flex items-center gap-1 ${Et}`,children:[i,r]}),e[4]=i,e[5]=r,e[6]=l):l=e[6],l},Km=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"}},wo=(t,e)=>{const a=(t||"").trim();return`${!a||a==="127.0.0.1"||a==="::1"?"localhost":a}:${e||0}`},zm=t=>{const e=(t||"").trim();return!e||e==="0.0.0.0"||e==="::"?"127.0.0.1":e},Um=t=>{const e=t.match(/^\[(\d{10,})\]\s*(?:\[([A-Z]+)\]\s*)?(.*)$/);if(!e)return t;const a=Number(e[1]),n=Number.isFinite(a)?new Date(a).toISOString():e[1],i=(e[2]||"INFO").toUpperCase(),r=e[3]||"";return`[${n}] [${i}] ${r}`},rr=(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}),_m=t=>t.trim().toLowerCase()==="authorization",_i=t=>{const e={};for(const a of t){const n=a.name.trim(),i=a.value.trim();n&&i&&!_m(n)&&(e[n]=i)}return Object.keys(e).length>0?e:void 0},$m=t=>Object.entries(t||{}).map(([e,a])=>rr(e,a)),_l=()=>{if(typeof window>"u")return null;const e=_a()||window.location.href;try{const a=Number(new URL(e).port||window.location.port);return Number.isFinite(a)&&a>0?a:null}catch{const a=Number(window.location.port);return Number.isFinite(a)&&a>0?a:null}},jo=t=>{try{const e=new URL(t).hostname.toLowerCase();return e==="localhost"||e==="127.0.0.1"||e==="::1"||e==="[::1]"}catch{return!1}},Vm=async()=>{const t=oa(_a())||window.location.origin;if(!os()||!$a())return t;let e;try{e=await pt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}})}catch{return t}if(!e.ok||(await e.json().catch(()=>null))?.desktopLanAccessActive!==!0)return t;const n=await kl(),i=_l();return!n||!i?t:`http://${n}:${i}`},ni=t=>{const e=t.trim();if(e)try{window.location.assign(e)}catch{window.location.href=e}},Bm=t=>{const e=t.sshCommand.trim(),a=t.nickname?.trim(),n=t.portForwards.map(i=>({...i,localHost:i.localHost?.trim()||"127.0.0.1",localPort:typeof i.localPort=="number"?Math.max(1,Math.min(65535,Math.round(i.localPort))):void 0,remoteHost:i.remoteHost?.trim(),remotePort:typeof i.remotePort=="number"?Math.max(1,Math.min(65535,Math.round(i.remotePort))):void 0}));return{...t,sshCommand:e,...a?{nickname:a}:{nickname:void 0},connectionTimeoutSec:Math.max(5,Math.min(240,Math.round(t.connectionTimeoutSec||60))),localForward:{...t.localForward,bindHost:t.localForward.bindHost==="localhost"||t.localForward.bindHost==="0.0.0.0"?t.localForward.bindHost:"127.0.0.1",preferredLocalPort:typeof t.localForward.preferredLocalPort=="number"?Math.max(1,Math.min(65535,Math.round(t.localForward.preferredLocalPort))):void 0},remoteOpenchamber:{...t.remoteOpenchamber,preferredPort:typeof t.remoteOpenchamber.preferredPort=="number"?Math.max(1,Math.min(65535,Math.round(t.remoteOpenchamber.preferredPort))):void 0},portForwards:n}},Hm=()=>{const{t}=at(),e=de(x=>x.timeFormatPreference),{clientAuth:a}=fl(),n=os(),i=Cs(x=>x.instances),r=Cs(x=>x.statusesById),l=Cs(x=>x.importCandidates),u=Cs(x=>x.isLoading),p=Cs(x=>x.isImportsLoading),h=Cs(x=>x.isSaving),d=Cs(x=>x.error),w=Cs(x=>x.load),c=Cs(x=>x.loadImports),N=Cs(x=>x.refreshStatuses),v=Cs(x=>x.upsertInstance),C=Cs(x=>x.createFromCommand),y=Cs(x=>x.removeInstance),S=Cs(x=>x.connect),g=Cs(x=>x.disconnect),T=Cs(x=>x.retry),R=de(x=>x.settingsRemoteInstancesSelectedId),A=de(x=>x.setSettingsRemoteInstancesSelectedId),j=o.useMemo(()=>R&&i.find(x=>x.id===R)||null,[i,R]),[f,b]=o.useState(null),[F,D]=o.useState(!1),[P,I]=o.useState(!1),[U,q]=o.useState(null),[k,$]=o.useState([]),[G,E]=o.useState(null),[J,X]=o.useState(""),[L,se]=o.useState(!1),[z,V]=o.useState({}),[_,K]=o.useState(!1),[Z,Y]=o.useState(!1),[te,ge]=o.useState(()=>Date.now()),[le,he]=o.useState([]),[ne,ae]=o.useState({}),[me,Pe]=o.useState("local"),[Ne,Se]=o.useState(!1),[be,Ke]=o.useState(!1),[Le,oe]=o.useState(""),[xe,Ee]=o.useState(""),[Ve,$e]=o.useState(""),[We,Fe]=o.useState([]),[ie,re]=o.useState(""),[je,ve]=o.useState(null),[Re,Ae]=o.useState(!1),[ye,He]=o.useState(!1),[ue,Ce]=o.useState(null),[De,Ye]=o.useState(""),[W,ke]=o.useState(""),[Ie,Ge]=o.useState(""),[it,nt]=o.useState([]),[dt,xt]=o.useState([]),[H,Be]=o.useState([]),[tt,rt]=o.useState(!1),[ut,Ct]=o.useState(""),[et,Xe]=o.useState(null),[ft,ze]=o.useState(null),[jt,Te]=o.useState(null),[wt,Q]=o.useState(null),[fe,Ue]=o.useState(!1),[Me,ct]=o.useState(!1),[lt,Qe]=o.useState("configure"),[Nt,xs]=o.useState(!1),[ts,Ms]=o.useState("relay"),[Bt,ls]=o.useState(!0),[Wt,vs]=o.useState(null),ps=o.useMemo(()=>dt.filter(x=>!!x.revokedAt).length,[dt]),[ys,ms]=o.useState(!1),[bs,ce]=o.useState("saved"),[ht,bt]=o.useState(""),[Qt,Yt]=o.useState(""),[Ht,as]=o.useState(""),[ws,cs]=o.useState(!1);o.useEffect(()=>{w(),c()},[w,c]);const St=o.useCallback(async()=>{Se(!0),ve(null);try{const x=await zr();he(x.hosts||[]),Pe(x.defaultHostId||"local")}catch(x){ve(x instanceof Error?x.message:String(x))}finally{Se(!1)}},[]);o.useEffect(()=>{St()},[St]);const Tt=o.useCallback(async(x,ee=me)=>{Ke(!0),ve(null);try{await Ur({hosts:x,defaultHostId:ee,initialHostChoiceCompleted:!0}),he(x),Pe(ee)}catch(Oe){ve(Oe instanceof Error?Oe.message:String(Oe))}finally{Ke(!1)}},[me]),Vt=o.useCallback(async()=>{const x=_r(xe);if(!x){ve(t("desktopHostSwitcher.error.invalidUrl"));return}const ee=x.persistedUrl,st={id:typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,label:Le.trim()||Na(ee),url:ee,apiUrl:ee,...Ve.trim()?{clientToken:Ve.trim()}:{},..._i(We)?{requestHeaders:_i(We)}:{}};await Tt([st,...le],me),oe(""),Ee(""),$e(""),Fe([]),Ae(!1),x.redeemUrl&&ni(x.redeemUrl)},[me,We,le,Le,Ve,xe,Tt,t]),Mt=o.useCallback(async()=>{const x=ld(ie);if(!x){ve(t("settings.remoteInstances.direct.error.invalidConnectLink"));return}const ee=await cd().catch(()=>""),Oe=JSON.stringify({pairingId:x.pairingId,secret:x.secret,clientLabel:x.label||"AiWorker Desktop",clientKind:"desktop",deviceName:"AiWorker Desktop",devicePlatform:Em(),...ee?{dedupeKey:`desktop:${ee}`}:{}}),st={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:Oe},zt=async Dt=>{if(!Dt.ok)return null;const Ks=await Dt.json().catch(()=>null);return(typeof Ks?.clientToken=="string"?Ks.clientToken.trim():"")||null},Ts=[...x.candidates].sort((Dt,Ks)=>(Dt.type==="relay"?1:0)-(Ks.type==="relay"?1:0));let ks=null;for(const Dt of Ts){if(Dt.type==="relay"){const wa=dd({relayUrl:Dt.relayUrl,serverId:Dt.serverId,hostEncPubJwk:Dt.hostEncPubJwk,...Dt.grant?{grant:Dt.grant}:{}});try{const Ja=await wa.fetch("/api/client-auth/pairing/redeem",st),Ir=await zt(Ja);if(Ir){ks={kind:"relay",relay:{relayUrl:Dt.relayUrl,serverId:Dt.serverId,hostEncPubJwk:Dt.hostEncPubJwk},token:Ir};break}}catch{}finally{wa.close()}continue}const Ks=oa(Dt.url);if(Ks)try{const wa=await fetch(`${Ks}/api/client-auth/pairing/redeem`,st),Ja=await zt(wa);if(Ja){ks={kind:"direct",url:Ks,token:Ja};break}}catch{}}if(!ks){ve(t("desktopHostSwitcher.error.invalidUrl"));return}const Rs=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`host-${Date.now()}-${Math.random().toString(16).slice(2)}`,gs=x.candidates.find(Dt=>Dt.type==="relay"),m=ks.kind==="relay"?ks.relay:gs?{relayUrl:gs.relayUrl,serverId:gs.serverId,hostEncPubJwk:gs.hostEncPubJwk}:void 0,vt=x.candidates.filter(Dt=>Dt.type!=="relay").map(Dt=>oa(Dt.url)).find(Dt=>!!Dt),Zt=ks.kind==="direct"?ks.url:vt,{token:Xt}=ks,kt=Zt||(m?ud(m.serverId):null);if(!kt){ve(t("desktopHostSwitcher.error.invalidUrl"));return}const Gt={url:kt,apiUrl:Zt||void 0,clientToken:Xt,...m?{relay:m}:{}},Ys=le.find(Dt=>m?Dt.relay?.serverId===m.serverId:!Dt.relay&&oa(Dt.apiUrl||Dt.url)===kt);if(Ys){const Dt=le.map(Ks=>Ks.id===Ys.id?{...Ks,label:x.label||Ks.label,...Gt}:Ks);await Tt(Dt,me)}else await Tt([{id:Rs(),label:x.label||Na(kt),...Gt},...le],me);re(""),ve(null),He(!1)},[ie,me,le,Tt,t]),is=o.useCallback(async x=>{const ee=le.filter(st=>st.id!==x);await Tt(ee,me===x?"local":me),ue===x&&Ce(null)},[me,ue,le,Tt]),As=o.useCallback(x=>{Ce(x.id),Ye(x.label),ke(x.apiUrl||x.url),Ge(x.clientToken||""),nt($m(x.requestHeaders)),ve(null)},[]),bi=o.useCallback(async()=>{if(!ue)return;const x=_r(W);if(!x){ve(t("desktopHostSwitcher.error.invalidUrl"));return}const ee=x.persistedUrl,Oe=le.map(st=>st.id===ue?{...st,label:De.trim()||Na(ee),url:ee,apiUrl:ee,clientToken:Ie.trim()||void 0,requestHeaders:_i(it)}:st);await Tt(Oe,me),Ce(null),x.redeemUrl&&ni(x.redeemUrl)},[me,it,De,Ie,W,ue,le,Tt,t]),Ba=o.useCallback(async()=>{const x=Qt.trim();if(!x){M.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}const ee=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{await C(ee,x,Ht.trim()||t("settings.remoteInstances.sidebar.newSshInstanceName")),A(ee),ms(!1),Yt(""),as(""),M.success(t("settings.remoteInstances.page.toast.instanceCreated"))}catch(Oe){M.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:Oe instanceof Error?Oe.message:String(Oe)})}},[C,A,Qt,Ht,t]),wi=o.useCallback(()=>{bt(""),ce(l.length>0?"saved":"manual"),ms(!0)},[l.length]),ji=o.useCallback(async x=>{await Tt(le,x)},[le,Tt]);o.useEffect(()=>{if(!n||le.length===0)return;let x=!1;return Promise.all(le.map(async ee=>{const Oe=()=>xd(ee.relay,{clientToken:ee.clientToken||null,requestHeaders:ee.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(ee.relay&&!ee.apiUrl)return[ee.id,await Oe()];const st=oa(pd(ee));if(!st)return[ee.id,ee.relay?await Oe():{status:"unreachable",latencyMs:0}];const zt=await md(st,{clientToken:ee.clientToken||null,requestHeaders:ee.requestHeaders||null}).catch(()=>({status:"unreachable",latencyMs:0}));if(zt.status==="unreachable"&&ee.relay){const Ts=await Oe();if(Ts.status==="ok")return[ee.id,Ts]}return[ee.id,zt]})).then(ee=>{x||ae(Object.fromEntries(ee))}),()=>{x=!0}},[le,n]);const Fs=o.useCallback(async x=>{if(a){x?.silent||rt(!0),x?.silent||Xe(null);try{const[ee,Oe]=await Promise.all([a.listClients(),a.listPendingPairings().catch(()=>null)]);xt(ee),Oe&&Be(Oe)}catch(ee){x?.silent||Xe(ee instanceof Error?ee.message:String(ee))}finally{x?.silent||rt(!1)}}},[a]),ga=o.useRef(!1);o.useEffect(()=>{if(!(!Me||lt!=="result"||!jt)){if(H.some(x=>x.id===jt)){ga.current=!0;return}ga.current&&(Te(null),ct(!1),dt.some(x=>x.pairingId===jt)&&M.success(t("settings.remoteInstances.clientAuth.addDevice.connectedToast")))}},[Me,lt,jt,H,dt,t]);const ki=o.useCallback(async x=>{if(a)try{await a.cancelPairing(x),Be(ee=>ee.filter(Oe=>Oe.id!==x)),await Fs({silent:!0})}catch(ee){Xe(ee instanceof Error?ee.message:String(ee))}},[a,Fs]);o.useEffect(()=>{if(!a)return;Fs();const x=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||Fs({silent:!0})},5e3);return()=>window.clearInterval(x)},[a,Fs]);const Ha=o.useCallback(async()=>{if(a?.getPairingTransports)try{const st=await a.getPairingTransports();return{localUrl:st.local,lanUrl:st.lan,relayAvailable:st.relayAvailable}}catch{}const x=_l(),ee=x?`http://127.0.0.1:${x}`:jo(window.location.origin)?window.location.origin:null;let Oe=null;try{const st=oa(await Vm());Oe=st&&!jo(st)?st:null}catch{}return{localUrl:ee,lanUrl:Oe,relayAvailable:!0}},[a]),Ni=o.useCallback(async()=>{Xe(null),ze(null),Q(null),Ue(!1),Te(null),Qe("configure"),ls(!0),ct(!0);const x=await Ha();vs(x),Ms(x.relayAvailable?"relay":x.lanUrl?"lan":"local")},[Ha]),Si=o.useCallback(async()=>{if(!(!a?.createPairingSession||!Wt)){Xe(null),xs(!0);try{const x=ut.trim()||void 0;let ee,Oe,st=!0;ts==="local"?(ee=Wt.localUrl??void 0,Oe=!1):ts==="lan"?(ee=Wt.lanUrl??void 0,Oe=Bt):Bt&&Wt.lanUrl?(ee=Wt.lanUrl,Oe=!0):(st=!1,Oe=!0);const{pairing:zt,server:Ts}=await a.createPairingSession({label:x,allowedClientKinds:["mobile","desktop"],serverUrl:ee,includeRelay:Oe,includeDirect:st}),ks=gd({pairingId:zt.id,secret:zt.secret,label:Ts.label,fingerprint:zt.fingerprint??void 0,expiresAt:zt.expiresAt,candidates:Ts.candidates}),Rs=fd(ks);ze(Rs),Q(await Tl.toDataURL(Rs,{width:1024,margin:2,errorCorrectionLevel:"L"})),Ue(!1),ga.current=!1,Te(zt.id),Qe("result"),await Fs({silent:!0})}catch(x){Xe(x instanceof Error?x.message:String(x))}finally{xs(!1)}}},[a,Wt,ts,Bt,ut,Fs]),Ci=o.useCallback(()=>{ft&&La(ft).then(x=>{x.ok&&(Ue(!0),window.setTimeout(()=>Ue(!1),2e3))})},[ft]),Pi=o.useCallback(async x=>{if(!a)return;const ee=x.clientKind==="desktop-local";Xe(null);try{if(await a.revokeClient(x.id),ee&&os()){const Oe=await zr();await Ur({hosts:Oe.hosts,defaultHostId:Oe.defaultHostId,initialHostChoiceCompleted:Oe.initialHostChoiceCompleted,localClientToken:null}),xt(st=>st.map(zt=>zt.id===x.id?{...zt,revokedAt:new Date().toISOString()}:zt)),hd({apiBaseUrl:_a(),clientToken:null,runtimeKey:"local"});return}await Fs()}catch(Oe){Xe(Oe instanceof Error?Oe.message:String(Oe))}},[a,Fs]),Ii=o.useCallback(async()=>{if(a){Xe(null);try{await a.purgeRevokedClients(),await Fs()}catch(x){Xe(x instanceof Error?x.message:String(x))}}},[a,Fs]);o.useEffect(()=>{b(j)},[j]),o.useEffect(()=>{cs(!1)},[R]),o.useEffect(()=>{if(!R)return;const x=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||N()},2e3);return()=>{window.clearInterval(x)}},[N,R]),o.useEffect(()=>{let x=null,ee=Date.now();const Oe=()=>{const zt=Date.now();zt-ee>=1e3&&(ge(zt),ee=zt),x=requestAnimationFrame(Oe)};(typeof document>"u"||document.visibilityState==="visible")&&(x=requestAnimationFrame(Oe));const st=()=>{document.visibilityState==="visible"&&x===null?x=requestAnimationFrame(Oe):document.visibilityState!=="visible"&&x!==null&&(cancelAnimationFrame(x),x=null)};return document.addEventListener("visibilitychange",st),()=>{document.removeEventListener("visibilitychange",st),x!==null&&cancelAnimationFrame(x)}},[]);const js=R?r[R]:null,Hs=js?.phase,Yn=Hs==="ready",ln=Hs==="degraded",kn=br(Hs),Qs=Yn||(kn||ln),Ai=js?Math.max(0,te-js.updatedAtMs):0,cn=ln&&Ai>12e3,dn=xo(Hs),un=dn==="error"?Mm(js?.detail):null,Rn=Rm(un),Zn=o.useMemo(()=>!f||!j?!1:JSON.stringify(f)!==JSON.stringify(j),[f,j]),pe=o.useCallback(x=>{b(ee=>ee&&x(ee))},[]),ds=o.useCallback(async()=>{if(!f)return;const x=Bm(f);if(!x.sshCommand.trim()){M.error(t("settings.remoteInstances.page.toast.sshCommandRequired"));return}if(x.remoteOpenchamber.mode==="external"&&!x.remoteOpenchamber.preferredPort){M.error(t("settings.remoteInstances.page.validation.externalPortRequired")),cs(!0);return}if(x.remoteOpenchamber.mode==="managed"&&x.remoteOpenchamber.bindHost==="0.0.0.0"&&!x.auth.aiworkerPassword?.value?.trim()){M.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),cs(!0),window.setTimeout(()=>pn.current?.focus(),0);return}if(!(x.localForward.bindHost==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces")))){if(x.auth.sshPassword?.enabled&&x.auth.sshPassword.value?.trim()&&x.auth.sshPassword.store!=="settings"){const ee=window.confirm(t("settings.remoteInstances.page.confirm.storeSshPasswordPlaintext"));x.auth.sshPassword.store=ee?"settings":"never",ee||(x.auth.sshPassword.value=void 0)}if(x.auth.aiworkerPassword?.enabled&&x.auth.aiworkerPassword.value?.trim()&&x.auth.aiworkerPassword.store!=="settings"){const ee=window.confirm(t("settings.remoteInstances.page.confirm.storeUiPasswordPlaintext"));x.auth.aiworkerPassword.store=ee?"settings":"never",ee||(x.auth.aiworkerPassword.value=void 0)}try{await v(x),M.success(t("settings.remoteInstances.page.toast.instanceSaved"))}catch(ee){M.error(t("settings.remoteInstances.page.toast.saveFailed"),{description:ee instanceof Error?ee.message:String(ee)})}}},[f,t,v]),On=o.useCallback(async(x,ee)=>{const Oe=`ssh-${Date.now()}-${Math.random().toString(16).slice(2)}`;try{return await C(Oe,`ssh ${ee}`,x),A(Oe),M.success(t("settings.remoteInstances.page.toast.instanceCreated")),!0}catch(st){return M.error(t("settings.remoteInstances.sidebar.toast.createFailed"),{description:st instanceof Error?st.message:String(st)}),!1}},[C,A,t]),Ln=o.useCallback(()=>{L||(E(null),X(""))},[L]),Ga=o.useCallback((x,ee)=>{if(ms(!1),ee){E(x),X(Fm(x));return}On(x,x)},[On]),fa=o.useMemo(()=>gi(l,ht,x=>[x.host,x.sshCommand]),[l,ht]),Wa=o.useCallback(x=>{const ee=(x||"").trim();if(!ee){M.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}ni(ee)},[t]),ha=o.useCallback(async()=>{const x=G,ee=J.trim();if(x){if(!ee){M.error(t("settings.remoteInstances.page.toast.destinationRequired"));return}se(!0);try{await On(x,ee)&&(E(null),X(""))}finally{se(!1)}}},[On,J,G,t]),Xn=o.useCallback(async()=>{if(j)try{await S(j.id);return}catch(x){if(!Tm(x)||!window.confirm(t("settings.remoteInstances.sidebar.confirm.localPortInUseRetry")))throw x;const Oe={...j,localForward:{...j.localForward,preferredLocalPort:pi()}};await v(Oe),await S(Oe.id),M.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}},[S,j,t,v]),pn=o.useRef(null),ea=o.useRef(null),qa=o.useCallback(async x=>{if(j){if(x==="localPort"){const ee={...j,localForward:{...j.localForward,preferredLocalPort:pi()}};try{await v(ee),await S(ee.id),M.success(t("settings.remoteInstances.sidebar.toast.retriedWithRandomPort"))}catch(Oe){M.error(t("settings.remoteInstances.page.toast.connectFailed"),{description:Oe instanceof Error?Oe.message:String(Oe)})}return}cs(!0),window.setTimeout(()=>{if(x==="uiPassword"){pn.current?.focus();return}ea.current?.scrollIntoView({block:"center"})},0)}},[S,j,t,v]),ta=o.useCallback(async x=>(await Nc(x,600)).map(Oe=>Um(Oe)),[]),sa=o.useCallback(async()=>{if(f){D(!0),I(!0),q(null);try{const x=await ta(f.id);$(x)}catch(x){$([]),q(x instanceof Error?x.message:String(x))}finally{I(!1)}}},[f,ta]);o.useEffect(()=>{if(!F||!f)return;let x=!1;const ee=async()=>{try{const st=await ta(f.id);x||($(st),q(null))}catch(st){x||q(st instanceof Error?st.message:String(st))}};ee();const Oe=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||ee()},1e3);return()=>{x=!0,window.clearInterval(Oe)}},[f,F,ta]);const Gs=o.useMemo(()=>k.join(`
27
- `),[k]),Nn=o.useCallback(()=>{if(!Gs.trim()){M.error(t("settings.remoteInstances.page.toast.noLogsToCopy"));return}La(Gs).then(x=>{x.ok&&M.success(t("settings.remoteInstances.page.toast.logsCopied"))})},[Gs,t]),Sn=o.useCallback(async()=>{if(f)try{await Sc(f.id),$([]),M.success(t("settings.remoteInstances.page.toast.logsCleared"))}catch(x){M.error(t("settings.remoteInstances.page.toast.clearLogsFailed"),{description:x instanceof Error?x.message:String(x)})}},[f,t]),na=o.useCallback(async()=>{if(!js?.localUrl){M.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}const x=js.localUrl.trim();if(!x){M.error(t("settings.remoteInstances.page.toast.instanceUrlUnavailable"));return}ni(x)},[js?.localUrl,t]),xa=o.useCallback(()=>{if(!f)return;if(!Qs&&f.remoteOpenchamber.mode==="external"&&!f.remoteOpenchamber.preferredPort){M.error(t("settings.remoteInstances.page.validation.externalPortRequired")),cs(!0);return}if(!Qs&&f.remoteOpenchamber.mode==="managed"&&f.remoteOpenchamber.bindHost==="0.0.0.0"&&!f.auth.aiworkerPassword?.value?.trim()){M.error(t("settings.remoteInstances.page.validation.remoteLanNeedsPassword")),cs(!0),window.setTimeout(()=>pn.current?.focus(),0);return}K(!0),(Qs?g(f.id):Xn()).catch(ee=>{const Oe=Qs?Yn?"settings.remoteInstances.page.toast.disconnectFailed":"settings.remoteInstances.page.toast.cancelConnectionFailed":"settings.remoteInstances.page.toast.connectFailed";M.error(t(Oe),{description:ee instanceof Error?ee.message:String(ee)})}).finally(()=>{K(!1)})},[Qs,Xn,g,f,Yn,t]),va=o.useCallback(()=>{if(!f||kn)return;Y(!0),(ln?g(f.id).then(()=>Xn()):T(f.id)).catch(ee=>{M.error(t("settings.remoteInstances.page.toast.retryFailed"),{description:ee instanceof Error?ee.message:String(ee)})}).finally(()=>{Y(!1)})},[Xn,g,f,kn,ln,T,t]),Ti=t(kn?"settings.remoteInstances.page.actions.connecting":ln?cn?"settings.remoteInstances.page.actions.reconnectNow":"settings.remoteInstances.page.actions.reconnecting":"settings.remoteInstances.sidebar.actions.retry"),Ei=!_&&!Z&&(Hs==="error"||Hs==="idle"||!Hs||ln&&cn)&&!kn,Di=t(Yn?"settings.remoteInstances.sidebar.actions.disconnect":Qs?"settings.remoteInstances.page.actions.cancel":"settings.remoteInstances.sidebar.actions.connect");if(!f)return s.jsxs(ns,{title:t("settings.page.remoteInstances.title"),children:[a?s.jsxs(_e,{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:()=>{Ni()},children:[s.jsx(O,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.clientAuth.actions.addDevice")]})}),s.jsxs("div",{className:"space-y-2.5",children:[ps>0?s.jsx("div",{className:"flex justify-end",children:s.jsx(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Ii()},children:t("settings.remoteInstances.clientAuth.actions.clearRevoked")})}):null,tt&&dt.length===0&&H.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.loading")}):dt.length===0&&H.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.clientAuth.state.empty")}):s.jsxs(s.Fragment,{children:[H.map(x=>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:x.label||t("settings.remoteInstances.clientAuth.field.labelPlaceholder")}),x.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:()=>{ki(x.id)},children:t("settings.common.actions.cancel")})]},`pending-${x.id}`)),dt.map(x=>{const ee=x.clientKind==="desktop-local",Oe=x.lastUsedAt?Date.parse(x.lastUsedAt):Number.NaN,st=!x.revokedAt&&(ee||Number.isFinite(Oe)&&Date.now()-Oe<9e4),zt=x.revokedAt?t("settings.remoteInstances.clientAuth.state.revoked"):st?x.lastTransport==="relay"&&!ee?t("settings.remoteInstances.clientAuth.state.connectedRelay"):t("settings.remoteInstances.clientAuth.state.connectedDirect"):Number.isFinite(Oe)?t("settings.remoteInstances.clientAuth.lastUsed",{date:Cc(Oe,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:we("h-2 w-2 shrink-0 rounded-full",x.revokedAt?"bg-muted-foreground/20":st?"bg-[var(--status-success)]":"bg-muted-foreground/30")}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:x.label}),fo(x.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:fo(x.devicePlatform)}):null,ee?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:we("typography-micro truncate",st&&!x.revokedAt?"text-[var(--status-success)]":"text-muted-foreground"),children:zt})]})}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{Pi(x)},disabled:!!x.revokedAt,children:t("settings.remoteInstances.clientAuth.actions.revoke")})]},x.id)})]})]}),et?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:et}):null]}):null,n?s.jsxs(_e,{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:()=>He(!0),disabled:be,children:t("settings.remoteInstances.direct.import.action")}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>Ae(!0),disabled:be,children:[s.jsx(O,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.direct.actions.add")]})]}),children:[s.jsx("div",{className:"space-y-2.5",children:Ne?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.loading")}):le.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.direct.state.empty")}):le.map(x=>{const ee=ne[x.id],Oe=ee?ee.status==="ok"?"desktopHostSwitcher.status.connected":ee.status==="auth"?"desktopHostSwitcher.status.authRequired":ee.status==="update-recommended"?"desktopHostSwitcher.status.updateRecommended":ee.status==="incompatible"?"desktopHostSwitcher.status.incompatible":ee.status==="wrong-service"?"desktopHostSwitcher.status.wrongService":"desktopHostSwitcher.status.unreachable":"desktopHostSwitcher.status.checking",st=ee?.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:we("h-2 w-2 shrink-0 rounded-full",ee?st?"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:Na(x.label)}),me===x.id?s.jsx("span",{className:"typography-micro text-muted-foreground shrink-0",children:t("desktopHostSwitcher.header.default")}):null,s.jsxs("span",{className:we("typography-micro shrink-0",st?"text-[var(--status-success)]":"text-muted-foreground"),children:[t(Oe),st&&typeof ee?.latencyMs=="number"?t("desktopHostSwitcher.status.ping",{ms:Math.max(0,Math.round(ee.latencyMs))}):""]})]}),s.jsx("p",{className:we("typography-micro text-muted-foreground truncate",x.apiUrl&&"font-mono"),children:x.relay&&!x.apiUrl?t("mobile.connect.relay.badge"):Na(x.apiUrl||x.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:()=>{ji(x.id)},disabled:be||me===x.id,"aria-label":t("desktopHostSwitcher.actions.setAsDefaultAria"),children:me===x.id?s.jsx(O,{name:"star-fill",className:"h-3.5 w-3.5"}):s.jsx(O,{name:"star",className:"h-3.5 w-3.5"})}),x.relay&&!x.apiUrl?null:s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>As(x),disabled:be,children:[s.jsx(O,{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:()=>{is(x.id)},disabled:be,children:[s.jsx(O,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]})},x.id)})}),je?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:je}):null]}):null,n?s.jsx(Ft,{open:Re,onOpenChange:Ae,children:s.jsxs(Kt,{className:"sm:max-w-lg",children:[s.jsxs(Ut,{children:[s.jsx(_t,{children:t("settings.remoteInstances.direct.actions.add")}),s.jsx($t,{children:t("settings.remoteInstances.direct.addDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:x=>{x.preventDefault(),Vt()},children:[s.jsx(Je,{className:"h-8",value:Le,onChange:x=>oe(x.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:be}),s.jsx(Je,{className:"h-8",value:xe,onChange:x=>Ee(x.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:be,autoFocus:!0}),s.jsxs("div",{className:"space-y-1",children:[s.jsx(Je,{className:"h-8",value:Ve,onChange:x=>$e(x.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:be}),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(Js,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(Jt,{children:t("settings.remoteInstances.direct.headers.description")})]}),We.map(x=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(Je,{className:"h-8 font-mono text-xs",value:x.name,onChange:ee=>Fe(Oe=>Oe.map(st=>st.id===x.id?{...st,name:ee.target.value}:st)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:be}),s.jsx(Je,{className:"h-8 font-mono text-xs",value:x.value,onChange:ee=>Fe(Oe=>Oe.map(st=>st.id===x.id?{...st,value:ee.target.value}:st)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:be}),s.jsx("button",{type:"button",onClick:()=>Fe(ee=>ee.filter(Oe=>Oe.id!==x.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:be,children:s.jsx(O,{name:"close",className:"h-4 w-4"})})]},x.id)),s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Fe(x=>[...x,rr()]),disabled:be,children:[s.jsx(O,{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:()=>Ae(!1),disabled:be,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:be||!xe.trim(),children:t("settings.remoteInstances.direct.actions.add")})]})]})]})}):null,n?s.jsx(Ft,{open:!!ue,onOpenChange:x=>{x||Ce(null)},children:s.jsxs(Kt,{className:"sm:max-w-lg",children:[s.jsxs(Ut,{children:[s.jsx(_t,{children:t("desktopHostSwitcher.actions.edit")}),s.jsx($t,{children:t("settings.remoteInstances.direct.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:x=>{x.preventDefault(),bi()},children:[s.jsx(Je,{className:"h-8",value:De,onChange:x=>Ye(x.target.value),placeholder:t("settings.remoteInstances.direct.field.labelPlaceholder"),disabled:be}),s.jsx(Je,{className:"h-8",value:W,onChange:x=>ke(x.target.value),placeholder:t("settings.remoteInstances.direct.field.urlPlaceholder"),disabled:be,autoFocus:!0}),s.jsx(Je,{className:"h-8",value:Ie,onChange:x=>Ge(x.target.value),placeholder:t("settings.remoteInstances.direct.field.tokenPlaceholder"),type:"password",disabled:be}),s.jsxs("div",{className:"space-y-2",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Js,{children:t("settings.remoteInstances.direct.headers.title")}),s.jsx(Jt,{children:t("settings.remoteInstances.direct.headers.description")})]}),it.map(x=>s.jsxs("div",{className:"flex w-full gap-2",children:[s.jsx(Je,{className:"h-8 font-mono text-xs",value:x.name,onChange:ee=>nt(Oe=>Oe.map(st=>st.id===x.id?{...st,name:ee.target.value}:st)),placeholder:t("settings.remoteInstances.direct.headers.field.namePlaceholder"),disabled:be}),s.jsx(Je,{className:"h-8 font-mono text-xs",value:x.value,onChange:ee=>nt(Oe=>Oe.map(st=>st.id===x.id?{...st,value:ee.target.value}:st)),placeholder:t("settings.remoteInstances.direct.headers.field.valuePlaceholder"),type:"password",disabled:be}),s.jsx("button",{type:"button",onClick:()=>nt(ee=>ee.filter(Oe=>Oe.id!==x.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:be,children:s.jsx(O,{name:"close",className:"h-4 w-4"})})]},x.id)),s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>nt(x=>[...x,rr()]),disabled:be,children:[s.jsx(O,{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:()=>Ce(null),disabled:be,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:be,children:t("settings.common.actions.saveChanges")})]})]})]})}):null,n?s.jsx(Ft,{open:ye,onOpenChange:He,children:s.jsxs(Kt,{className:"sm:max-w-lg",children:[s.jsxs(Ut,{children:[s.jsx(_t,{children:t("settings.remoteInstances.direct.import.action")}),s.jsx($t,{children:t("settings.remoteInstances.direct.import.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:x=>{x.preventDefault(),Mt()},children:[s.jsx(Je,{className:"h-8",value:ie,onChange:x=>re(x.target.value),placeholder:t("settings.remoteInstances.direct.import.placeholder"),disabled:be,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:()=>He(!1),disabled:be,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:be||!ie.trim(),children:t("settings.remoteInstances.direct.import.action")})]})]})]})}):null,s.jsx(Ft,{open:Me,onOpenChange:ct,children:s.jsxs(Kt,{className:lt==="result"?"sm:max-w-lg":"sm:max-w-md",children:[s.jsxs(Ut,{children:[s.jsx(_t,{children:t(lt==="result"?"settings.remoteInstances.clientAuth.qrDialogTitle":"settings.remoteInstances.clientAuth.actions.addDevice")}),s.jsx($t,{children:t(lt==="result"?"settings.remoteInstances.clientAuth.qrScanHint":"settings.remoteInstances.clientAuth.addDevice.subtitle")})]}),lt==="configure"?s.jsxs("form",{className:"space-y-4",onSubmit:x=>{x.preventDefault(),Si()},children:[s.jsx(Je,{className:"h-8",value:ut,onChange:x=>Ct(x.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:!!Wt?.relayAvailable},{key:"lan",label:t("settings.remoteInstances.clientAuth.addDevice.transport.lan"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.lanHint"),available:!!Wt?.lanUrl},{key:"local",label:t("settings.remoteInstances.clientAuth.addDevice.transport.local"),hint:t("settings.remoteInstances.clientAuth.addDevice.transport.localHint"),available:!!Wt?.localUrl}].map(x=>{const ee=ts===x.key;return s.jsxs("div",{className:we("flex items-start gap-2 py-0.5",x.available?"cursor-pointer":"opacity-45"),onClick:()=>{x.available&&Ms(x.key)},role:"presentation",children:[s.jsx(mr,{checked:ee,disabled:!x.available,onChange:()=>Ms(x.key),ariaLabel:x.label,className:"mt-0.5"}),s.jsxs("div",{className:"min-w-0",children:[s.jsx("p",{className:we("typography-ui-label font-normal",ee?"text-foreground":"text-foreground/70"),children:x.label}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:x.hint})]})]},x.key)})}),ts==="lan"?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(Xi,{checked:Bt,onChange:ls,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,ts==="relay"&&Wt?.lanUrl?s.jsxs("label",{className:"flex w-fit cursor-pointer items-center gap-2 pt-1",children:[s.jsx(Xi,{checked:Bt,onChange:ls,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]}),et?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:et}):null,s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ct(!1),disabled:Nt,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:Nt||!Wt,children:t("settings.remoteInstances.clientAuth.addDevice.create")})]})]}):s.jsxs("div",{className:"space-y-3",children:[wt?s.jsx("div",{className:"flex justify-center",children:s.jsx("img",{src:wt,alt:t("settings.remoteInstances.clientAuth.qrAlt"),className:"w-full max-w-[420px] rounded-md bg-white p-4"})}):null,ft?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:ft}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:Ci,children:[s.jsx(O,{name:fe?"check":"file-copy",className:we("h-3.5 w-3.5",fe&&"text-[var(--status-success)]")}),t(fe?"settings.remoteInstances.clientAuth.actions.copied":"settings.common.actions.copyAll")]})]}):null,s.jsx("div",{className:"flex justify-end",children:s.jsx(B,{type:"button",size:"xs",className:"!font-normal",onClick:()=>ct(!1),children:t("settings.remoteInstances.clientAuth.addDevice.done")})})]})]})}),n?s.jsx(_e,{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:wi,children:[s.jsx(O,{name:"add",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.addSshInstance")]}),contentClassName:"space-y-2.5",children:u?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.state.loadingInstances")}):i.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:l.length===1?t("settings.remoteInstances.page.empty.noInstancesWithOneImport"):l.length>1?t("settings.remoteInstances.page.empty.noInstancesWithImports",{count:l.length}):t("settings.remoteInstances.page.empty.noInstances")}):i.map(x=>{const ee=r[x.id],Oe=x.nickname?.trim()||x.sshParsed?.destination||x.id,st=ee?.phase,zt=st==="ready",Ts=xo(st),ks=Ts==="error"?ee?.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 ${bo(st)}`}),s.jsx("p",{className:"typography-ui-label text-foreground truncate",children:Oe})]}),s.jsxs("p",{className:"typography-micro text-muted-foreground truncate",children:[t(vo(Ts)),Ts==="connecting"?` · ${t(ho(st))}`:"",zt&&ee?.localUrl?` · ${ee.localUrl}`:""]})]}),s.jsxs("div",{className:"flex shrink-0 items-center gap-1",children:[zt?s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>Wa(ee?.localUrl),children:[s.jsx(O,{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:()=>{(zt?g(x.id):S(x.id)).catch(gs=>M.error(t(zt?"settings.remoteInstances.sidebar.toast.disconnectFailed":"settings.remoteInstances.sidebar.toast.connectFailed"),{description:gs instanceof Error?gs.message:String(gs)}))},children:[zt?s.jsx(O,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(O,{name:"plug-2",className:"h-3.5 w-3.5"}),t(zt?"settings.remoteInstances.sidebar.actions.disconnect":"settings.remoteInstances.sidebar.actions.connect")]}),s.jsxs(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>A(x.id),children:[s.jsx(O,{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"))&&y(x.id).catch(gs=>M.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:gs instanceof Error?gs.message:String(gs)}))},children:[s.jsx(O,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.delete")]})]})]}),ks?s.jsx("p",{className:"typography-micro text-[var(--status-error)] break-words",children:ks}):null]},x.id)})}):null,n?s.jsx(Ft,{open:ys,onOpenChange:ms,children:s.jsxs(Kt,{className:"sm:max-w-lg",children:[s.jsxs(Ut,{children:[s.jsx(_t,{children:t("settings.remoteInstances.sidebar.actions.addSshInstance")}),s.jsx($t,{children:t("settings.remoteInstances.page.addDialog.description")})]}),s.jsx(qs,{value:bs,onChange:ce,"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")}]}),bs==="saved"?s.jsxs("div",{className:"space-y-2",children:[s.jsx(Je,{className:"h-8",value:ht,onChange:x=>bt(x.target.value),placeholder:t("settings.remoteInstances.page.addDialog.searchPlaceholder"),autoFocus:!0}),p?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.import.loading")}):l.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.addDialog.emptySaved")}):fa.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:fa.map(x=>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:[x.host,x.pattern?` ${t("settings.remoteInstances.page.import.patternSuffix")}`:""]}),s.jsx("div",{className:"typography-meta text-muted-foreground truncate",children:x.sshCommand})]}),s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{Ga(x.host,x.pattern)},children:t("settings.remoteInstances.page.addDialog.use")})]},`${x.source}:${x.host}`))})]}):s.jsxs("form",{className:"space-y-3",onSubmit:x=>{x.preventDefault(),Ba()},children:[s.jsx(Je,{className:"h-8",value:Ht,onChange:x=>as(x.target.value),placeholder:t("settings.remoteInstances.page.field.nicknamePlaceholder"),disabled:h}),s.jsx(Je,{className:"h-8",value:Qt,onChange:x=>Yt(x.target.value),placeholder:t("settings.remoteInstances.page.field.sshCommandPlaceholder"),disabled:h,autoFocus:!0}),s.jsxs("div",{className:"flex justify-end gap-2",children:[s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>ms(!1),disabled:h,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:h||!Qt.trim(),children:t("settings.common.actions.create")})]})]})]})}):null,s.jsx(Ft,{open:!!G,onOpenChange:x=>{x||Ln()},children:s.jsxs(Kt,{className:"sm:max-w-md",children:[s.jsxs(Ut,{children:[s.jsx(_t,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx($t,{children:G?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:G}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:x=>{x.preventDefault(),ha()},children:[s.jsx(Je,{value:J,onChange:x=>X(x.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:Ln,disabled:L,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:L,children:t("settings.remoteInstances.page.actions.create")})]})]})]})})]});const Fn=f.remoteOpenchamber.mode==="managed",aa=Fn&&f.remoteOpenchamber.bindHost==="0.0.0.0",ya=aa&&!f.auth.aiworkerPassword?.value?.trim(),ba=f.nickname?.trim()||f.sshParsed?.destination||f.id;return s.jsx(Ft,{open:!!f,onOpenChange:x=>{x||A(null)},children:s.jsxs(Kt,{className:"sm:max-w-4xl max-h-[90vh] overflow-auto",children:[s.jsxs("div",{className:"mb-6 px-1",children:[s.jsx("h1",{className:`${Zi} truncate`,children:ba}),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 ${bo(Hs)}`}),s.jsx("span",{className:"text-foreground",children:t(vo(dn))}),dn==="connecting"?s.jsx("span",{children:t(ho(Hs))}):null,js?.localUrl?s.jsx("span",{className:"font-mono text-foreground/80",children:js.localUrl}):null,cn?s.jsx("span",{children:t("settings.remoteInstances.page.status.reconnectStale")}):null]})]}),s.jsxs(_e,{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:Qs?"outline":"default",size:"xs",className:"!font-normal",onClick:xa,disabled:_||Z,children:[Qs?s.jsx(O,{name:"stop",className:"h-3.5 w-3.5"}):s.jsx(O,{name:"plug-2",className:"h-3.5 w-3.5"}),Di]}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:va,disabled:!Ei,children:[s.jsx(O,{name:"refresh",className:`h-3.5 w-3.5 ${kn||ln&&!cn?"animate-spin":""}`}),Ti]}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{sa()},children:[s.jsx(O,{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"))&&y(f.id).then(()=>{A(null),M.success(t("settings.remoteInstances.page.toast.instanceRemoved"))}).catch(ee=>{M.error(t("settings.remoteInstances.page.toast.removeInstanceFailed"),{description:ee instanceof Error?ee.message:String(ee)})})},children:[s.jsx(O,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.sidebar.actions.remove")]})]}),dn==="error"&&js?.detail?s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--status-error)]/30 bg-[var(--status-error-background)] p-3",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)] break-words",children:js.detail}),Rn?s.jsx("p",{className:"typography-micro text-muted-foreground",children:t(Rn)}):null,un&&!Rn?s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{qa(un)},children:t(un==="uiPassword"?"settings.remoteInstances.page.error.action.setUiPassword":un==="localPort"?"settings.remoteInstances.page.error.action.pickRandomPort":"settings.remoteInstances.page.error.action.setRemotePort")}):null]}):null,js?.localUrl?s.jsxs("div",{className:"flex flex-wrap items-center gap-2 typography-meta text-muted-foreground",children:[s.jsx("span",{children:t("settings.remoteInstances.page.status.currentLocalUrl")}),s.jsx("span",{className:"font-mono text-foreground/90",children:js.localUrl})]}):null]}),s.jsxs(_e,{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(Je,{className:"h-7 md:max-w-xl",value:f.sshCommand,onChange:x=>pe(ee=>({...ee,sshCommand:x.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(Je,{className:"h-7 md:max-w-sm",value:f.nickname||"",onChange:x=>pe(ee=>({...ee,nickname:x.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(_s,{label:t("settings.remoteInstances.page.field.mode"),hint:t("settings.remoteInstances.page.field.modeHint")})}),s.jsxs(Pt,{value:f.remoteOpenchamber.mode,onValueChange:x=>pe(ee=>({...ee,remoteOpenchamber:{...ee.remoteOpenchamber,mode:x==="external"?"external":"managed"}})),children:[s.jsx(It,{size:Lt,className:"w-fit min-w-[140px]",children:s.jsx(Rt,{placeholder:t("settings.remoteInstances.page.field.modePlaceholder")})}),s.jsxs(At,{children:[s.jsx(ot,{value:"managed",children:t("settings.remoteInstances.page.field.modeManaged")}),s.jsx(ot,{value:"external",children:t("settings.remoteInstances.page.field.modeExternal")})]})]})]})]}),s.jsxs(bn,{open:ws,onOpenChange:cs,children:[s.jsxs(wn,{className:"mt-6 w-auto justify-start gap-1.5",children:[s.jsx("span",{className:hl,children:t("settings.remoteInstances.page.section.advanced")}),s.jsx(O,{name:ws?"arrow-up-s":"arrow-down-s",className:"h-4 w-4 text-muted-foreground"})]}),s.jsxs(jn,{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(Ss,{containerClassName:"w-fit",min:5,max:240,step:1,className:we(Ps,"tabular-nums"),value:f.connectionTimeoutSec,onValueChange:x=>{pe(ee=>({...ee,connectionTimeoutSec:Number.isFinite(x)?x:ee.connectionTimeoutSec}))}})]}),s.jsxs(_e,{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:ea,children:s.jsx(_s,{label:t("settings.remoteInstances.page.field.preferredRemotePort"),hint:t("settings.remoteInstances.page.field.preferredRemotePortHint")})}),s.jsx(Ss,{containerClassName:"w-fit",min:1,max:65535,step:1,className:we(Ps,"tabular-nums"),value:f.remoteOpenchamber.preferredPort,onValueChange:x=>{pe(ee=>({...ee,remoteOpenchamber:{...ee.remoteOpenchamber,preferredPort:Number.isFinite(x)&&x>0?x:void 0}}))},onClear:()=>{pe(x=>({...x,remoteOpenchamber:{...x.remoteOpenchamber,preferredPort:void 0}}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]}),Fn?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(_s,{label:t("settings.remoteInstances.page.field.installMethod"),hint:t("settings.remoteInstances.page.field.installMethodHint")})}),s.jsxs(Pt,{value:f.remoteOpenchamber.installMethod,onValueChange:x=>pe(ee=>({...ee,remoteOpenchamber:{...ee.remoteOpenchamber,installMethod:x==="npm"||x==="bun"?x:"auto"}})),children:[s.jsx(It,{size:Lt,className:"w-fit min-w-[140px]",children:s.jsx(Rt,{placeholder:t("settings.remoteInstances.page.field.selectInstallMethodPlaceholder")})}),s.jsxs(At,{children:[s.jsx(ot,{value:"auto",children:t("settings.remoteInstances.page.field.installMethodAuto")}),s.jsx(ot,{value:"bun",children:"bun"}),s.jsx(ot,{value:"npm",children:"npm"})]})]})]}):null,Fn?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(_s,{label:t("settings.remoteInstances.page.field.remoteLanAccess"),hint:t("settings.remoteInstances.page.field.remoteLanAccessHint")})}),s.jsx(li,{checked:aa,onCheckedChange:x=>pe(ee=>({...ee,remoteOpenchamber:{...ee.remoteOpenchamber,bindHost:x?"0.0.0.0":"127.0.0.1"}})),"aria-label":t("settings.remoteInstances.page.field.remoteLanAccess")})]}),aa?s.jsx("p",{className:"mt-2 typography-micro text-[var(--status-warning)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.remoteLanAccessWarning")}):null]}):null,Fn?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(_s,{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(li,{checked:f.remoteOpenchamber.keepRunning,onCheckedChange:x=>pe(ee=>({...ee,remoteOpenchamber:{...ee.remoteOpenchamber,keepRunning:x}}))})})]}):null]}),s.jsxs(_e,{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(_s,{label:t("settings.remoteInstances.page.field.bindHost"),hint:t("settings.remoteInstances.page.field.bindHostHint")})}),s.jsxs(Pt,{value:f.localForward.bindHost,onValueChange:x=>{x==="0.0.0.0"&&!window.confirm(t("settings.remoteInstances.page.confirm.bindAllInterfaces"))||pe(ee=>({...ee,localForward:{...ee.localForward,bindHost:x==="localhost"||x==="0.0.0.0"?x:"127.0.0.1"}}))},children:[s.jsx(It,{size:Lt,className:"w-fit min-w-[240px]",children:s.jsx(Rt,{placeholder:t("settings.remoteInstances.page.field.selectBindHostPlaceholder")})}),s.jsxs(At,{children:[s.jsx(ot,{value:"127.0.0.1",children:t("settings.remoteInstances.page.field.bindHostOption.loopback")}),s.jsx(ot,{value:"localhost",children:t("settings.remoteInstances.page.field.bindHostOption.localhost")}),s.jsx(ot,{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(_s,{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(Ss,{containerClassName:"w-fit",min:1,max:65535,step:1,className:we(Ps,"tabular-nums"),value:f.localForward.preferredLocalPort,onValueChange:x=>{pe(ee=>({...ee,localForward:{...ee.localForward,preferredLocalPort:Number.isFinite(x)&&x>0?x:void 0}}))},onClear:()=>{pe(x=>({...x,localForward:{...x.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:()=>pe(x=>({...x,localForward:{...x.localForward,preferredLocalPort:pi()}})),children:s.jsx(O,{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:`${f.localForward.bindHost}:${f.localForward.preferredLocalPort||"auto"} → ${f.sshParsed?.destination||f.nickname||"remote"}:${f.remoteOpenchamber.preferredPort||"auto"}`})]})]}),s.jsxs(_e,{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(_s,{label:t("settings.remoteInstances.page.field.sshPasswordOptional"),hint:t("settings.remoteInstances.page.field.sshPasswordHint")})}),s.jsx(Je,{className:"h-7 md:max-w-sm",type:"password",value:f.auth.sshPassword?.value||"",onChange:x=>pe(ee=>({...ee,auth:{...ee.auth,sshPassword:{enabled:x.target.value.trim().length>0,value:x.target.value,store:ee.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(_s,{label:t(aa?"settings.remoteInstances.page.field.uiPasswordRequired":"settings.remoteInstances.page.field.uiPasswordOptional"),hint:t(Fn?"settings.remoteInstances.page.field.uiPasswordHintManaged":"settings.remoteInstances.page.field.uiPasswordHintExternal")})}),s.jsx(Je,{className:we("h-7 md:max-w-sm",ya&&"border-[var(--status-error)]"),type:"password",ref:pn,"aria-invalid":ya,value:f.auth.aiworkerPassword?.value||"",onChange:x=>pe(ee=>({...ee,auth:{...ee.auth,aiworkerPassword:{enabled:x.target.value.trim().length>0,value:x.target.value,store:ee.auth.aiworkerPassword?.store||"never"}}})),placeholder:t("settings.remoteInstances.page.field.uiPasswordPlaceholder")})]}),ya?s.jsx("p",{className:"typography-micro text-[var(--status-error)] md:pl-[16rem]",children:t("settings.remoteInstances.page.field.uiPasswordMissingForLan")}):null]}),s.jsxs(_e,{title:t("settings.remoteInstances.page.section.portForwards"),info:t("settings.remoteInstances.page.section.portForwardsDescription"),contentClassName:"space-y-2",children:[f.portForwards.length===0?s.jsx("p",{className:"typography-micro text-muted-foreground/80",children:t("settings.remoteInstances.page.empty.noExtraForwards")}):null,f.portForwards.map((x,ee)=>{const Oe=kt=>{pe(Gt=>({...Gt,portForwards:Gt.portForwards.map((Ys,Dt)=>Dt===ee?kt(Ys):Ys)}))},st=x.type==="remote"?"Local target":"Local listen",zt=x.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.",Ts=x.type==="remote"?"Remote listen":"Remote target",ks=x.type==="remote"?"Remote host and port where SSH creates the -R listener.":"Remote host and port that receives traffic from local -L listener.",Rs=wo(x.localHost||"localhost",x.localPort),gs=wo(x.remoteHost||"localhost",x.remotePort),m=x.type==="local"&&typeof x.localPort=="number"&&x.localPort>0,vt=m?`http://${zm(x.localHost)}:${x.localPort}`:"",Zt=!!z[x.id],Xt=x.type==="local"?t("settings.remoteInstances.page.forwardType.local"):x.type==="remote"?t("settings.remoteInstances.page.forwardType.remote"):t("settings.remoteInstances.page.forwardType.dynamic");return s.jsxs(bn,{open:Zt,onOpenChange:kt=>{V(Gt=>({...Gt,[x.id]:kt}))},className:`${ee>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(wn,{className:"flex items-center gap-2 group",children:[s.jsx(O,{name:"arrow-down-s",className:`h-4 w-4 text-muted-foreground transition-transform ${Zt?"rotate-180":""}`}),s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:Om(x)}),s.jsx("span",{className:"typography-micro text-muted-foreground/70 shrink-0",children:Xt})]})}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(li,{checked:x.enabled,onCheckedChange:kt=>Oe(Gt=>({...Gt,enabled:kt})),"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:()=>pe(kt=>({...kt,portForwards:kt.portForwards.filter(Gt=>Gt.id!==x.id)})),children:s.jsx(O,{name:"delete-bin",className:"h-3.5 w-3.5"})})]})]}),s.jsx(jn,{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(_s,{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(Km(x.type))})]})})}),s.jsxs(Pt,{value:x.type,onValueChange:kt=>Oe(Gt=>({...Gt,type:kt==="dynamic"||kt==="remote"?kt:"local"})),children:[s.jsx(It,{size:Lt,className:"w-fit min-w-[140px]",children:s.jsx(Rt,{placeholder:t("settings.remoteInstances.page.field.typePlaceholder")})}),s.jsxs(At,{children:[s.jsx(ot,{value:"local",children:t("settings.remoteInstances.page.forwardType.local")}),s.jsx(ot,{value:"remote",children:t("settings.remoteInstances.page.forwardType.remote")}),s.jsx(ot,{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(_s,{label:st,hint:zt})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Je,{className:"h-7 w-32",value:x.localHost||"127.0.0.1",onChange:kt=>Oe(Gt=>({...Gt,localHost:kt.target.value})),placeholder:t("settings.remoteInstances.page.field.localHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(Ss,{containerClassName:"w-fit",min:1,max:65535,step:1,className:we(Ps,"tabular-nums"),value:x.localPort,onValueChange:kt=>{Oe(Gt=>({...Gt,localPort:Number.isFinite(kt)&&kt>0?kt:void 0}))},onClear:()=>{Oe(kt=>({...kt,localPort:void 0}))},emptyLabel:t("settings.remoteInstances.page.field.auto")})]})]}),x.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(_s,{label:Ts,hint:ks})}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Je,{className:"h-7 w-32",value:x.remoteHost||"",onChange:kt=>Oe(Gt=>({...Gt,remoteHost:kt.target.value})),placeholder:t("settings.remoteInstances.page.field.remoteHostPlaceholder")}),s.jsx("span",{className:"text-muted-foreground",children:":"}),s.jsx(Ss,{containerClassName:"w-fit",min:1,max:65535,step:1,className:we(Ps,"tabular-nums"),value:x.remotePort,onValueChange:kt=>{Oe(Gt=>({...Gt,remotePort:Number.isFinite(kt)&&kt>0?kt:void 0}))},onClear:()=>{Oe(kt=>({...kt,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:x.type==="dynamic"?s.jsxs(s.Fragment,{children:[s.jsx(O,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Rs}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.localSocks5")})]}):x.type==="remote"?s.jsxs(s.Fragment,{children:[s.jsx(O,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:gs}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")}),s.jsx(O,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(O,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Rs}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")})]}):s.jsxs(s.Fragment,{children:[s.jsx(O,{name:"computer",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:Rs}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.local")}),s.jsx(O,{name:"arrow-right",className:"h-3.5 w-3.5"}),s.jsx(O,{name:"server",className:"h-3.5 w-3.5"}),s.jsx("span",{className:"font-mono text-foreground",children:gs}),s.jsx("span",{children:t("settings.remoteInstances.page.preview.remote")})]})}),m?s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{yn(vt).then(kt=>{kt||M.error(t("settings.remoteInstances.page.toast.openLocalEndpointFailed"))})},children:[s.jsx(O,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.openLocal")]}):null]})]})})]},x.id)}),s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal mt-1",onClick:()=>{const x=Lm();pe(ee=>({...ee,portForwards:[...ee.portForwards,x]})),V(ee=>({...ee,[x.id]:!0}))},children:[s.jsx(O,{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:()=>{ds()},disabled:!Zn||h,children:t("settings.common.actions.saveChanges")}),js?.localUrl?s.jsxs(s.Fragment,{children:[s.jsxs(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{La(js.localUrl||"").then(x=>{x.ok&&M.success(t("settings.remoteInstances.page.toast.localUrlCopied"))})},children:[s.jsx(O,{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:()=>{na()},children:[s.jsx(O,{name:"external-link",className:"h-3.5 w-3.5"}),t("settings.remoteInstances.page.actions.open")]})]}):null,d?s.jsx("div",{className:"ml-auto typography-meta text-[var(--status-error)]",children:d}):null]})}),s.jsx(Ft,{open:F,onOpenChange:D,children:s.jsxs(Kt,{className:"sm:max-w-2xl",children:[s.jsxs(Ut,{children:[s.jsx(_t,{children:t("settings.remoteInstances.page.logsDialog.title")}),s.jsx($t,{children:f?.nickname?.trim()||f?.sshParsed?.destination||f?.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:Nn,disabled:P||!Gs.trim(),children:[s.jsx(O,{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:()=>{Sn()},disabled:P,children:[s.jsx(O,{name:"delete-bin",className:"h-3.5 w-3.5"}),t("settings.common.actions.clear")]})]}),P?s.jsx("div",{className:"typography-meta text-muted-foreground",children:t("settings.remoteInstances.page.logsDialog.loading")}):U?s.jsx("div",{className:"typography-meta text-[var(--status-error)]",children:U}):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:k.length>0?k.join(`
28
- `):t("settings.remoteInstances.page.logsDialog.empty")})]})}),s.jsx(Ft,{open:!!G,onOpenChange:x=>{x||Ln()},children:s.jsxs(Kt,{className:"sm:max-w-md",children:[s.jsxs(Ut,{children:[s.jsx(_t,{children:t("settings.remoteInstances.page.patternDialog.title")}),s.jsx($t,{children:G?t("settings.remoteInstances.page.patternDialog.descriptionWithHost",{host:G}):t("settings.remoteInstances.page.patternDialog.description")})]}),s.jsxs("form",{className:"space-y-3",onSubmit:x=>{x.preventDefault(),ha()},children:[s.jsx(Je,{value:J,onChange:x=>X(x.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:Ln,disabled:L,children:t("settings.common.actions.cancel")}),s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:L,children:t("settings.common.actions.create")})]})]})]})})]})})},Gm="__add_provider__",Wm=()=>{const t=hn.getDirectory();return typeof t=="string"&&t.trim().length>0?t.trim():null},qm=({onItemSelect:t})=>{const{t:e}=at(),a=Us(),n=Ze(v=>xl(v,a)),i=Ze(v=>v.selectedProviderId),r=Ze(v=>v.setSelectedProvider),l=Vs(v=>v.activeProjectId),[u,p]=o.useState({}),h=o.useMemo(()=>a||Wm(),[l,a]),d=Ze(v=>v.loadProviders);o.useEffect(()=>{a&&d({directory:a,source:"settings:providers"})},[d,a]),o.useEffect(()=>{if(n.length===0){p({});return}let v=!1;return(async()=>{const y=n.map(async S=>{try{const g=h?`?directory=${encodeURIComponent(h)}`:"",T=await pt(`/api/provider/${encodeURIComponent(S.id)}/source${g}`,{method:"GET",headers:{Accept:"application/json"}});if(!T.ok)return;const R=await T.json().catch(()=>null),A=R?.sources??R?.data?.sources;if(!A||v)return;p(j=>({...j,[S.id]:A}))}catch{}});await Promise.all(y)})(),()=>{v=!0}},[h,n]);const w="bg-background",c=o.useMemo(()=>n.filter(v=>!!u[v.id]?.project?.exists),[n,u]),N=o.useMemo(()=>n.filter(v=>!u[v.id]?.project?.exists),[n,u]);return s.jsxs("div",{className:we("flex h-full flex-col",w),children:[s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[s.jsx("h2",{className:`${on} mb-3`,children:e("settings.providers.sidebar.title")}),s.jsx(Va,{className:"mb-3"}),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("span",{className:"typography-meta text-muted-foreground",children:e("settings.providers.sidebar.total",{count:n.length})}),s.jsx(B,{size:"sm",variant:"ghost",className:"h-7 w-7 px-0 -my-1 text-muted-foreground",onClick:()=>{r(Gm),t?.()},"aria-label":e("settings.providers.sidebar.actions.connectProviderAria"),title:e("settings.providers.sidebar.actions.connectProviderTitle"),children:s.jsx(O,{name:"add",className:"h-3.5 w-3.5"})})]})]}),s.jsx(Bs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:n.length===0?s.jsxs("div",{className:"py-12 px-4 text-center text-muted-foreground",children:[s.jsx(O,{name:"stack",className:"mx-auto mb-3 h-10 w-10 opacity-50"}),s.jsx("p",{className:"typography-ui-label font-medium",children:e("settings.providers.sidebar.empty.title")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:e("settings.providers.sidebar.empty.description")})]}):s.jsxs(s.Fragment,{children:[N.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-2 pb-1.5 pt-2 text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:e("settings.providers.sidebar.section.userProviders")}),N.map(v=>s.jsx(ko,{provider:v,selectedProviderId:i,onSelect:()=>{r(v.id),t?.()}},v.id))]}),c.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:we("px-2 pb-1.5 text-xs font-semibold uppercase tracking-wide text-muted-foreground",N.length>0?"pt-3":"pt-2"),children:e("settings.providers.sidebar.section.projectProviders")}),c.map(v=>s.jsx(ko,{provider:v,selectedProviderId:i,onSelect:()=>{r(v.id),t?.()}},v.id))]})]})})]})},ko=t=>{const e=mt.c(17),{provider:a,selectedProviderId:n,onSelect:i}=t,r=Array.isArray(a.models)?a.models.length:0,l=a.id===n,u=a.id,p=l?"bg-interactive-selection":"hover:bg-interactive-hover";let h;e[0]!==p?(h=we("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",p),e[0]=p,e[1]=h):h=e[1];let d;e[2]!==a.id?(d=s.jsx(Un,{providerId:a.id,className:"h-4 w-4 flex-shrink-0"}),e[2]=a.id,e[3]=d):d=e[3];const w=a.name||a.id;let c;e[4]!==w?(c=s.jsx("span",{className:"typography-ui-label font-normal truncate flex-1 min-w-0 text-foreground",children:w}),e[4]=w,e[5]=c):c=e[5];let N;e[6]!==r?(N=s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:r}),e[6]=r,e[7]=N):N=e[7];let v;e[8]!==i||e[9]!==d||e[10]!==c||e[11]!==N?(v=s.jsxs("button",{type:"button",onClick:i,className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",tabIndex:0,children:[d,c,N]}),e[8]=i,e[9]=d,e[10]=c,e[11]=N,e[12]=v):v=e[12];let C;return e[13]!==a.id||e[14]!==h||e[15]!==v?(C=s.jsx("div",{className:h,children:v},u),e[13]=a.id,e[14]=h,e[15]=v,e[16]=C):C=e[16],C},Jm=t=>t,Qm=(t,e,a)=>t&&!e&&!a,No=t=>typeof t=="object"&&t!==null,$l=t=>{const e=typeof t.type=="string"?t.type:"",a=`${t.name??""} ${t.label??""}`.toLowerCase(),n=`${e} ${a}`.toLowerCase();return n.includes("oauth")?"oauth":n.includes("api")?"api":e.toLowerCase()},Ym=t=>{if(!No(t))return{};const e={};for(const[a,n]of Object.entries(t))Array.isArray(n)&&(e[a]=n.filter(i=>No(i)));return e},So=t=>t.length===0?!0:t.some(e=>$l(e)==="api"),Co=t=>t.map((e,a)=>({method:e,methodIndex:a})).filter(({method:e})=>$l(e)==="oauth"),Zm=t=>t!=="claude-code",Po=t=>typeof t.key=="string"&&t.key.trim().length>0||typeof t.optionsApiKey=="string"&&t.optionsApiKey.trim().length>0||t.envDeclared===!0?!0:t.authSourceExists===!0,Xm=t=>t.modelCount>0&&(!t.sourcesLoaded||t.hasCredentials||!!t.isEditableCustomProvider),eg=t=>!t.hasCredentials&&!t.userDismissed&&!t.isEditableCustomProvider,wr={"openai-chat":"@ai-sdk/openai-compatible","openai-responses":"@ai-sdk/openai","anthropic-messages":"@ai-sdk/anthropic"},Kn="__custom_provider__",tg=/^[a-z0-9][a-z0-9-_]*$/,Vl=/^https?:\/\//,sg=/^\{env:([^}]+)\}$/;let ng=0;const xi=()=>`row-${ng++}`,jr=()=>({row:xi(),id:"",name:""}),kr=()=>({row:xi(),key:"",value:""}),ag=()=>({providerID:"",name:"",protocol:"openai-chat",baseURL:"",apiKey:"",models:[jr()],headers:[kr()]});function ig(t){switch(t){case"@ai-sdk/openai":return"openai-responses";case"@ai-sdk/anthropic":return"anthropic-messages";default:return"openai-chat"}}function rg(t){const e=t.trim();if(!e)return{};const n=e.match(sg)?.[1]?.trim();return n?{env:n}:{key:e}}function og(t){const e=t.options&&typeof t.options=="object"?t.options:null,a=typeof e?.baseURL=="string"?e.baseURL.trim():"";return a&&Vl.test(a)?!0:(Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.values(t.models):[]).some(i=>{if(!i||typeof i!="object")return!1;const r="api"in i&&i.api&&typeof i.api=="object"?i.api:null;return typeof r?.npm=="string"&&new Set(Object.values(wr)).has(r.npm)})}function Io(t,e){return e?!!(e.user?.exists||e.project?.exists||e.custom?.exists)&&og(t):!1}function Ao(t){return t?.custom?.exists?"custom":t?.project?.exists?"project":"user"}function lg(t){const e=t.options&&typeof t.options=="object"?t.options:{},a=typeof e.baseURL=="string"?e.baseURL:"",n=e.headers&&typeof e.headers=="object"&&!Array.isArray(e.headers)?e.headers:{},i=Object.entries(n).filter(h=>typeof h[0]=="string"&&typeof h[1]=="string").map(([h,d])=>({row:xi(),key:h,value:d})),r=Array.isArray(t.models)?t.models:t.models&&typeof t.models=="object"?Object.entries(t.models).map(([h,d])=>({id:h,name:d&&typeof d=="object"&&"name"in d&&typeof d.name=="string"?d.name:h})):[],l=r.length>0?r.map(h=>({row:xi(),id:typeof h?.id=="string"?h.id:"",name:typeof h?.name=="string"?h.name:typeof h?.id=="string"?h.id:""})):[jr()],u=Array.isArray(t.env)?t.env.find(h=>typeof h=="string"&&h.trim().length>0)?.trim():void 0,p=r.find(h=>"api"in h);return{providerID:t.id,name:typeof t.name=="string"&&t.name.trim()?t.name:t.id,protocol:ig(p?.api?.npm),baseURL:a,apiKey:u?`{env:${u}}`:"",models:l,headers:i.length>0?i:[kr()]}}function cg(t){const e=t.form.providerID.trim(),a=t.form.name.trim(),n=t.form.baseURL.trim(),{env:i,key:r}=rg(t.form.apiKey),l=t.disabledProviders??[],u=t.editingProviderID?.trim(),p=e?tg.test(e)?void 0:t.t("settings.providers.page.custom.error.providerID.format"):t.t("settings.providers.page.custom.error.providerID.required"),h=a?void 0:t.t("settings.providers.page.custom.error.name.required"),d=n?Vl.test(n)?void 0:t.t("settings.providers.page.custom.error.baseURL.format"):t.t("settings.providers.page.custom.error.baseURL.required"),c=!!(i||r||u&&t.allowExistingAuth&&u===e)?void 0:t.t("settings.providers.page.custom.error.apiKey.required"),N=l.includes(e),C=p||!!(u&&u===e)?void 0:t.existingProviderIDs.has(e)&&!N?t.t("settings.providers.page.custom.error.providerID.exists"):void 0,y=new Set,S=t.form.models.map(D=>{const P=D.id.trim(),I=P?y.has(P)?t.t("settings.providers.page.custom.error.duplicate"):void y.add(P):t.t("settings.providers.page.custom.error.required"),U=D.name.trim()?void 0:t.t("settings.providers.page.custom.error.required");return{id:I,name:U}}),g=S.every(D=>!D.id&&!D.name),T=Object.fromEntries(t.form.models.map(D=>[D.id.trim(),{name:D.name.trim()}])),R=new Set,A=t.form.headers.map(D=>{const P=D.key.trim(),I=D.value.trim();if(!P&&!I)return{};const U=P?R.has(P.toLowerCase())?t.t("settings.providers.page.custom.error.duplicate"):void R.add(P.toLowerCase()):t.t("settings.providers.page.custom.error.required"),q=I?void 0:t.t("settings.providers.page.custom.error.required");return{key:U,value:q}}),j=A.every(D=>!D.key&&!D.value),f=Object.fromEntries(t.form.headers.map(D=>({key:D.key.trim(),value:D.value.trim()})).filter(D=>D.key&&D.value).map(D=>[D.key,D.value])),b={providerID:p??C,name:h,baseURL:d,apiKey:c};return!p&&!C&&!h&&!d&&!c&&g&&j?{err:b,models:S,headers:A,result:{providerID:e,name:a,apiKey:r,config:{npm:wr[t.form.protocol],name:a,...i?{env:[i]}:{},options:{baseURL:n,...Object.keys(f).length>0?{headers:f}:{}},models:T}}}:{err:b,models:S,headers:A}}function dg(t){return t.apiKey?{providerID:t.providerID,auth:{type:"api",key:t.apiKey}}:null}function ug(t,e){return{providerID:t.providerID,config:t.config,scope:e?.scope??"user"}}const To=t=>{const e=mt.c(234),{existingProviderIDs:a,disabledProviders:n,busy:i,mode:r,initialValues:l,allowExistingAuth:u,authFailureHint:p,onSubmit:h,onCancel:d,onDisconnect:w}=t;let c;e[0]!==n?(c=n===void 0?[]:n,e[0]=n,e[1]=c):c=e[1];const N=c,v=i===void 0?!1:i,C=r===void 0?"create":r,y=u===void 0?!1:u,S=p===void 0?null:p,{t:g}=at(),T=C==="edit";let R;e[2]!==l?(R=()=>l??ag(),e[2]=l,e[3]=R):R=e[3];const[A,j]=o.useState(R);let f;e[4]===Symbol.for("react.memo_cache_sentinel")?(f={},e[4]=f):f=e[4];const[b,F]=o.useState(f);let D;e[5]===Symbol.for("react.memo_cache_sentinel")?(D=[],e[5]=D):D=e[5];const[P,I]=o.useState(D);let U;e[6]===Symbol.for("react.memo_cache_sentinel")?(U=[],e[6]=U):U=e[6];const[q,k]=o.useState(U),$=o.useRef(null);let G,E;e[7]!==l||e[8]!==T?(G=()=>{l&&(T&&$.current===l.providerID||($.current=T?l.providerID:null,j(l),F({}),I([]),k([])))},E=[l,T],e[7]=l,e[8]=T,e[9]=G,e[10]=E):(G=e[9],E=e[10]),o.useEffect(G,E);let J;e[11]===Symbol.for("react.memo_cache_sentinel")?(J=(St,Tt)=>{j(Vt=>({...Vt,[St]:Tt})),F(Vt=>({...Vt,[St]:void 0}))},e[11]=J):J=e[11];const X=J;let L;e[12]===Symbol.for("react.memo_cache_sentinel")?(L=(St,Tt,Vt)=>{j(Mt=>({...Mt,models:Mt.models.map((is,As)=>As===St?{...is,[Tt]:Vt}:is)})),I(Mt=>{const is=[...Mt];return is[St]={...is[St]??{},[Tt]:void 0},is})},e[12]=L):L=e[12];const se=L;let z;e[13]===Symbol.for("react.memo_cache_sentinel")?(z=(St,Tt,Vt)=>{j(Mt=>({...Mt,headers:Mt.headers.map((is,As)=>As===St?{...is,[Tt]:Vt}:is)})),k(Mt=>{const is=[...Mt];return is[St]={...is[St]??{},[Tt]:void 0},is})},e[13]=z):z=e[13];const V=z;let _;e[14]!==y||e[15]!==v||e[16]!==N||e[17]!==a||e[18]!==A||e[19]!==T||e[20]!==h||e[21]!==g?(_=async St=>{if(St.preventDefault(),v)return;const Tt=cg({form:A,t:((Vt,Mt)=>g(Vt,Mt)),existingProviderIDs:a,disabledProviders:N,editingProviderID:T?A.providerID:void 0,allowExistingAuth:T&&y});F(Tt.err),I(Tt.models),k(Tt.headers),Tt.result&&await h(Tt.result)},e[14]=y,e[15]=v,e[16]=N,e[17]=a,e[18]=A,e[19]=T,e[20]=h,e[21]=g,e[22]=_):_=e[22];const K=_;let Z;e[23]!==T||e[24]!==g?(Z=g(T?"settings.providers.page.custom.editTitle":"settings.providers.page.custom.title"),e[23]=T,e[24]=g,e[25]=Z):Z=e[25];let Y;e[26]!==g?(Y=g("settings.providers.page.custom.description"),e[26]=g,e[27]=Y):Y=e[27];let te;e[28]!==Y?(te=s.jsx("p",{className:zn,children:Y}),e[28]=Y,e[29]=te):te=e[29];let ge;e[30]!==S?(ge=S?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",role:"status",children:S}):null,e[30]=S,e[31]=ge):ge=e[31];let le;e[32]!==g?(le=g("settings.providers.page.custom.field.providerID.label"),e[32]=g,e[33]=le):le=e[33];let he;e[34]!==g?(he=g("settings.providers.page.custom.field.providerID.info"),e[34]=g,e[35]=he):he=e[35];const ne=A.providerID;let ae;e[36]===Symbol.for("react.memo_cache_sentinel")?(ae=St=>X("providerID",St.target.value),e[36]=ae):ae=e[36];let me;e[37]!==g?(me=g("settings.providers.page.custom.field.providerID.placeholder"),e[37]=g,e[38]=me):me=e[38];const Pe=!T,Ne=T||v,Se=!!b.providerID;let be;e[39]!==g?(be=g("settings.providers.page.custom.field.providerID.label"),e[39]=g,e[40]=be):be=e[40];let Ke;e[41]!==A.providerID||e[42]!==me||e[43]!==Pe||e[44]!==Ne||e[45]!==Se||e[46]!==be?(Ke=s.jsx(Je,{value:ne,onChange:ae,placeholder:me,className:"h-8 rounded-md px-3 font-mono text-xs",autoFocus:Pe,disabled:Ne,"aria-invalid":Se,"aria-label":be}),e[41]=A.providerID,e[42]=me,e[43]=Pe,e[44]=Ne,e[45]=Se,e[46]=be,e[47]=Ke):Ke=e[47];let Le;e[48]!==b.providerID?(Le=b.providerID?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:b.providerID}):null,e[48]=b.providerID,e[49]=Le):Le=e[49];let oe;e[50]!==le||e[51]!==he||e[52]!==Ke||e[53]!==Le?(oe=s.jsxs(qt,{label:le,info:he,children:[Ke,Le]}),e[50]=le,e[51]=he,e[52]=Ke,e[53]=Le,e[54]=oe):oe=e[54];let xe;e[55]!==g?(xe=g("settings.providers.page.custom.field.protocol.label"),e[55]=g,e[56]=xe):xe=e[56];let Ee;e[57]!==g?(Ee=g("settings.providers.page.custom.field.protocol.info"),e[57]=g,e[58]=Ee):Ee=e[58];const Ve=A.protocol;let $e;e[59]===Symbol.for("react.memo_cache_sentinel")?($e=St=>{St in wr&&j(Tt=>({...Tt,protocol:St}))},e[59]=$e):$e=e[59];let We;e[60]!==g?(We=g("settings.providers.page.custom.field.protocol.label"),e[60]=g,e[61]=We):We=e[61];let Fe;e[62]===Symbol.for("react.memo_cache_sentinel")?(Fe=s.jsx(Rt,{}),e[62]=Fe):Fe=e[62];let ie;e[63]!==We?(ie=s.jsx(It,{"aria-label":We,className:"w-full",children:Fe}),e[63]=We,e[64]=ie):ie=e[64];let re;e[65]!==g?(re=g("settings.providers.page.custom.field.protocol.openaiChat"),e[65]=g,e[66]=re):re=e[66];let je;e[67]!==re?(je=s.jsx(ot,{value:"openai-chat",children:re}),e[67]=re,e[68]=je):je=e[68];let ve;e[69]!==g?(ve=g("settings.providers.page.custom.field.protocol.openaiResponses"),e[69]=g,e[70]=ve):ve=e[70];let Re;e[71]!==ve?(Re=s.jsx(ot,{value:"openai-responses",children:ve}),e[71]=ve,e[72]=Re):Re=e[72];let Ae;e[73]!==g?(Ae=g("settings.providers.page.custom.field.protocol.anthropicMessages"),e[73]=g,e[74]=Ae):Ae=e[74];let ye;e[75]!==Ae?(ye=s.jsx(ot,{value:"anthropic-messages",children:Ae}),e[75]=Ae,e[76]=ye):ye=e[76];let He;e[77]!==je||e[78]!==Re||e[79]!==ye?(He=s.jsxs(At,{children:[je,Re,ye]}),e[77]=je,e[78]=Re,e[79]=ye,e[80]=He):He=e[80];let ue;e[81]!==v||e[82]!==A.protocol||e[83]!==ie||e[84]!==He?(ue=s.jsxs(Pt,{value:Ve,onValueChange:$e,disabled:v,children:[ie,He]}),e[81]=v,e[82]=A.protocol,e[83]=ie,e[84]=He,e[85]=ue):ue=e[85];let Ce;e[86]!==xe||e[87]!==Ee||e[88]!==ue?(Ce=s.jsx(qt,{label:xe,info:Ee,children:ue}),e[86]=xe,e[87]=Ee,e[88]=ue,e[89]=Ce):Ce=e[89];let De;e[90]!==g?(De=g("settings.providers.page.custom.field.name.label"),e[90]=g,e[91]=De):De=e[91];let Ye;e[92]!==g?(Ye=g("settings.providers.page.custom.field.name.info"),e[92]=g,e[93]=Ye):Ye=e[93];const W=A.name;let ke;e[94]===Symbol.for("react.memo_cache_sentinel")?(ke=St=>X("name",St.target.value),e[94]=ke):ke=e[94];let Ie;e[95]!==g?(Ie=g("settings.providers.page.custom.field.name.placeholder"),e[95]=g,e[96]=Ie):Ie=e[96];const Ge=!!b.name;let it;e[97]!==g?(it=g("settings.providers.page.custom.field.name.label"),e[97]=g,e[98]=it):it=e[98];let nt;e[99]!==A.name||e[100]!==Ie||e[101]!==Ge||e[102]!==it?(nt=s.jsx(Je,{value:W,onChange:ke,placeholder:Ie,className:"h-8 rounded-md px-3","aria-invalid":Ge,"aria-label":it}),e[99]=A.name,e[100]=Ie,e[101]=Ge,e[102]=it,e[103]=nt):nt=e[103];let dt;e[104]!==b.name?(dt=b.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:b.name}):null,e[104]=b.name,e[105]=dt):dt=e[105];let xt;e[106]!==De||e[107]!==Ye||e[108]!==nt||e[109]!==dt?(xt=s.jsxs(qt,{label:De,info:Ye,children:[nt,dt]}),e[106]=De,e[107]=Ye,e[108]=nt,e[109]=dt,e[110]=xt):xt=e[110];let H;e[111]!==g?(H=g("settings.providers.page.custom.field.baseURL.label"),e[111]=g,e[112]=H):H=e[112];let Be;e[113]!==g?(Be=g("settings.providers.page.custom.field.baseURL.info"),e[113]=g,e[114]=Be):Be=e[114];const tt=A.baseURL;let rt;e[115]===Symbol.for("react.memo_cache_sentinel")?(rt=St=>X("baseURL",St.target.value),e[115]=rt):rt=e[115];let ut;e[116]!==g?(ut=g("settings.providers.page.custom.field.baseURL.placeholder"),e[116]=g,e[117]=ut):ut=e[117];const Ct=!!b.baseURL;let et;e[118]!==g?(et=g("settings.providers.page.custom.field.baseURL.label"),e[118]=g,e[119]=et):et=e[119];let Xe;e[120]!==A.baseURL||e[121]!==ut||e[122]!==Ct||e[123]!==et?(Xe=s.jsx(Je,{value:tt,onChange:rt,placeholder:ut,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":Ct,"aria-label":et}),e[120]=A.baseURL,e[121]=ut,e[122]=Ct,e[123]=et,e[124]=Xe):Xe=e[124];let ft;e[125]!==b.baseURL?(ft=b.baseURL?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:b.baseURL}):null,e[125]=b.baseURL,e[126]=ft):ft=e[126];let ze;e[127]!==H||e[128]!==Be||e[129]!==Xe||e[130]!==ft?(ze=s.jsxs(qt,{label:H,info:Be,children:[Xe,ft]}),e[127]=H,e[128]=Be,e[129]=Xe,e[130]=ft,e[131]=ze):ze=e[131];let jt;e[132]!==g?(jt=g("settings.providers.page.custom.field.apiKey.label"),e[132]=g,e[133]=jt):jt=e[133];let Te;e[134]!==y||e[135]!==T||e[136]!==g?(Te=g(T&&y?"settings.providers.page.custom.field.apiKey.editInfo":"settings.providers.page.custom.field.apiKey.info"),e[134]=y,e[135]=T,e[136]=g,e[137]=Te):Te=e[137];const wt=A.apiKey;let Q;e[138]===Symbol.for("react.memo_cache_sentinel")?(Q=St=>X("apiKey",St.target.value),e[138]=Q):Q=e[138];let fe;e[139]!==y||e[140]!==T||e[141]!==g?(fe=g(T&&y?"settings.providers.page.custom.field.apiKey.editPlaceholder":"settings.providers.page.custom.field.apiKey.placeholder"),e[139]=y,e[140]=T,e[141]=g,e[142]=fe):fe=e[142];const Ue=!!b.apiKey;let Me;e[143]!==g?(Me=g("settings.providers.page.custom.field.apiKey.label"),e[143]=g,e[144]=Me):Me=e[144];let ct;e[145]!==A.apiKey||e[146]!==fe||e[147]!==Ue||e[148]!==Me?(ct=s.jsx(Je,{type:"password",value:wt,onChange:Q,placeholder:fe,className:"h-8 rounded-md px-3 font-mono text-xs","aria-invalid":Ue,"aria-label":Me}),e[145]=A.apiKey,e[146]=fe,e[147]=Ue,e[148]=Me,e[149]=ct):ct=e[149];let lt;e[150]!==b.apiKey?(lt=b.apiKey?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:b.apiKey}):null,e[150]=b.apiKey,e[151]=lt):lt=e[151];let Qe;e[152]!==jt||e[153]!==Te||e[154]!==ct||e[155]!==lt?(Qe=s.jsxs(qt,{label:jt,info:Te,children:[ct,lt]}),e[152]=jt,e[153]=Te,e[154]=ct,e[155]=lt,e[156]=Qe):Qe=e[156];let Nt;e[157]!==Z||e[158]!==te||e[159]!==ge||e[160]!==oe||e[161]!==Ce||e[162]!==xt||e[163]!==ze||e[164]!==Qe?(Nt=s.jsxs(_e,{title:Z,divider:!1,settingsItem:"providers.custom",contentClassName:Ws,children:[te,ge,oe,Ce,xt,ze,Qe]}),e[157]=Z,e[158]=te,e[159]=ge,e[160]=oe,e[161]=Ce,e[162]=xt,e[163]=ze,e[164]=Qe,e[165]=Nt):Nt=e[165];let xs;e[166]!==g?(xs=g("settings.providers.page.custom.models.title"),e[166]=g,e[167]=xs):xs=e[167];let ts;if(e[168]!==A.models||e[169]!==P||e[170]!==g){let St;e[172]!==A.models.length||e[173]!==P||e[174]!==g?(St=(Tt,Vt)=>s.jsx("div",{className:`${zs} 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:Et,children:g("settings.providers.page.custom.models.idLabel")}),s.jsx(Je,{value:Tt.id,onChange:Mt=>se(Vt,"id",Mt.target.value),placeholder:g("settings.providers.page.custom.models.idPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":g("settings.providers.page.custom.models.idLabel")}),P[Vt]?.id?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:P[Vt]?.id}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:Et,children:g("settings.providers.page.custom.models.nameLabel")}),s.jsx(Je,{value:Tt.name,onChange:Mt=>se(Vt,"name",Mt.target.value),placeholder:g("settings.providers.page.custom.models.namePlaceholder"),className:"mt-1 h-8 rounded-md px-3","aria-label":g("settings.providers.page.custom.models.nameLabel")}),P[Vt]?.name?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:P[Vt]?.name}):null]})]}),s.jsx(B,{type:"button",variant:"ghost",size:"icon",className:fs,disabled:A.models.length<=1,onClick:()=>{A.models.length<=1||(j(Mt=>({...Mt,models:Mt.models.filter((is,As)=>As!==Vt)})),I(Mt=>Mt.filter((is,As)=>As!==Vt)))},"aria-label":g("settings.providers.page.custom.models.remove"),children:s.jsx(O,{name:"delete-bin",className:"size-4"})})]})},Tt.row),e[172]=A.models.length,e[173]=P,e[174]=g,e[175]=St):St=e[175],ts=A.models.map(St),e[168]=A.models,e[169]=P,e[170]=g,e[171]=ts}else ts=e[171];let Ms;e[176]===Symbol.for("react.memo_cache_sentinel")?(Ms=()=>{j(pg),I(mg)},e[176]=Ms):Ms=e[176];let Bt;e[177]!==g?(Bt=g("settings.providers.page.custom.models.add"),e[177]=g,e[178]=Bt):Bt=e[178];let ls;e[179]!==Bt?(ls=s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:Ms,children:Bt}),e[179]=Bt,e[180]=ls):ls=e[180];let Wt;e[181]!==xs||e[182]!==ts||e[183]!==ls?(Wt=s.jsxs(_e,{title:xs,contentClassName:Ws,children:[ts,ls]}),e[181]=xs,e[182]=ts,e[183]=ls,e[184]=Wt):Wt=e[184];let vs;e[185]!==g?(vs=g("settings.providers.page.custom.headers.title"),e[185]=g,e[186]=vs):vs=e[186];let ps;e[187]!==g?(ps=g("settings.providers.page.custom.headers.description"),e[187]=g,e[188]=ps):ps=e[188];let ys;e[189]!==ps?(ys=s.jsx("p",{className:zn,children:ps}),e[189]=ps,e[190]=ys):ys=e[190];let ms;if(e[191]!==A.headers||e[192]!==q||e[193]!==g){let St;e[195]!==A.headers.length||e[196]!==q||e[197]!==g?(St=(Tt,Vt)=>s.jsx("div",{className:`${zs} 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:Et,children:g("settings.providers.page.custom.headers.keyLabel")}),s.jsx(Je,{value:Tt.key,onChange:Mt=>V(Vt,"key",Mt.target.value),placeholder:g("settings.providers.page.custom.headers.keyPlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":g("settings.providers.page.custom.headers.keyLabel")}),q[Vt]?.key?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:q[Vt]?.key}):null]}),s.jsxs("div",{children:[s.jsx("label",{className:Et,children:g("settings.providers.page.custom.headers.valueLabel")}),s.jsx(Je,{value:Tt.value,onChange:Mt=>V(Vt,"value",Mt.target.value),placeholder:g("settings.providers.page.custom.headers.valuePlaceholder"),className:"mt-1 h-8 rounded-md px-3 font-mono text-xs","aria-label":g("settings.providers.page.custom.headers.valueLabel")}),q[Vt]?.value?s.jsx("p",{className:"mt-1 typography-meta text-[var(--status-error)]",children:q[Vt]?.value}):null]})]}),s.jsx(B,{type:"button",variant:"ghost",size:"icon",className:fs,disabled:A.headers.length<=1,onClick:()=>{A.headers.length<=1||(j(Mt=>({...Mt,headers:Mt.headers.filter((is,As)=>As!==Vt)})),k(Mt=>Mt.filter((is,As)=>As!==Vt)))},"aria-label":g("settings.providers.page.custom.headers.remove"),children:s.jsx(O,{name:"delete-bin",className:"size-4"})})]})},Tt.row),e[195]=A.headers.length,e[196]=q,e[197]=g,e[198]=St):St=e[198],ms=A.headers.map(St),e[191]=A.headers,e[192]=q,e[193]=g,e[194]=ms}else ms=e[194];let bs;e[199]===Symbol.for("react.memo_cache_sentinel")?(bs=()=>{j(gg),k(fg)},e[199]=bs):bs=e[199];let ce;e[200]!==g?(ce=g("settings.providers.page.custom.headers.add"),e[200]=g,e[201]=ce):ce=e[201];let ht;e[202]!==ce?(ht=s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:bs,children:ce}),e[202]=ce,e[203]=ht):ht=e[203];let bt;e[204]!==vs||e[205]!==ys||e[206]!==ms||e[207]!==ht?(bt=s.jsxs(_e,{title:vs,contentClassName:Ws,children:[ys,ms,ht]}),e[204]=vs,e[205]=ys,e[206]=ms,e[207]=ht,e[208]=bt):bt=e[208];let Qt;e[209]!==v||e[210]!==d||e[211]!==g?(Qt=d?s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:d,disabled:v,children:g("settings.providers.page.custom.actions.back")}):null,e[209]=v,e[210]=d,e[211]=g,e[212]=Qt):Qt=e[212];let Yt;e[213]!==v||e[214]!==w||e[215]!==g?(Yt=w?s.jsx(B,{type:"button",variant:"destructive",size:"xs",className:"!font-normal",onClick:()=>{w()},disabled:v,children:g("settings.providers.page.actions.disconnect")}):null,e[213]=v,e[214]=w,e[215]=g,e[216]=Yt):Yt=e[216];let Ht;e[217]!==v||e[218]!==T||e[219]!==g?(Ht=g(v?"settings.providers.page.actions.saving":T?"settings.providers.page.custom.actions.update":"settings.providers.page.custom.actions.save"),e[217]=v,e[218]=T,e[219]=g,e[220]=Ht):Ht=e[220];let as;e[221]!==v||e[222]!==Ht?(as=s.jsx(B,{type:"submit",size:"xs",className:"!font-normal",disabled:v,children:Ht}),e[221]=v,e[222]=Ht,e[223]=as):as=e[223];let ws;e[224]!==Qt||e[225]!==Yt||e[226]!==as?(ws=s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-4",children:[Qt,Yt,as]}),e[224]=Qt,e[225]=Yt,e[226]=as,e[227]=ws):ws=e[227];let cs;return e[228]!==K||e[229]!==Nt||e[230]!==Wt||e[231]!==bt||e[232]!==ws?(cs=s.jsxs("form",{onSubmit:K,className:"space-y-0",children:[Nt,Wt,bt,ws]}),e[228]=K,e[229]=Nt,e[230]=Wt,e[231]=bt,e[232]=ws,e[233]=cs):cs=e[233],cs};function pg(t){return{...t,models:[...t.models,jr()]}}function mg(t){return[...t,{}]}function gg(t){return{...t,headers:[...t.headers,kr()]}}function fg(t){return[...t,{}]}const hg=(t,e)=>!!e&&t!=="claude-code",xg=/[A-Z0-9]{4}-[A-Z0-9]{4,5}/,Qn=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),Ns=t=>typeof t=="string"&&t.length>0?t:void 0,vg=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!Qn(a))continue;const n=Ns(a.value);n!==void 0&&e.push({value:n,label:Ns(a.label)??n,...Ns(a.hint)?{hint:Ns(a.hint)}:{}})}return e},yg=t=>{if(!Qn(t))return;const e=Ns(t.key),a=t.op==="eq"||t.op==="neq"?t.op:void 0;if(!(!e||!a||typeof t.value!="string"))return{key:e,op:a,value:t.value}},bg=t=>{if(!Array.isArray(t))return[];const e=[];for(const a of t){if(!Qn(a))continue;const n=Ns(a.key);if(!n)continue;const i=a.type==="select"?"select":"text",r=i==="select"?vg(a.options):[];if(i==="select"&&r.length===0)continue;const l=yg(a.when);e.push({type:i,key:n,message:Ns(a.message)??n,options:r,...Ns(a.placeholder)?{placeholder:Ns(a.placeholder)}:{},...l?{when:l}:{}})}return e},wg=(t,e)=>{if(!t.when)return!0;const a=e[t.when.key]??"";return t.when.op==="eq"?a===t.when.value:a!==t.when.value},Nr=(t,e)=>t.filter(a=>wg(a,e)),jg=t=>{const e={};for(const a of t)e[a.key]=a.type==="select"?a.options[0]?.value??"":"";return e},kg=(t,e)=>Nr(t,e).find(a=>(e[a.key]??"").trim().length===0)??null,Ng=(t,e)=>{const a={};for(const n of Nr(t,e))a[n.key]=(e[n.key]??"").trim();return a},Sg=t=>{const e=Qn(t)?t:{},a=Qn(e.data)?e.data:e,n=Ns(a.url)??Ns(a.verification_uri_complete)??Ns(a.verification_uri),i=Ns(a.instructions)??Ns(a.message);if(!n&&!i)return null;const r=Ns(a.user_code)??Ns(a.userCode)??(i?xg.exec(i)?.[0]:void 0);return{method:a.method==="code"?"code":"auto",...n?{url:n}:{},...i?{instructions:i}:{},...r?{userCode:r}:{}}},Eo=(t,e,a)=>{const n=Qn(t)?t:{},i=Qn(n.data)?n.data:{};switch(n.name){case"ProviderAuthOauthMissing":return e("settings.providers.page.auth.oauth.error.sessionExpired");case"ProviderAuthOauthCodeMissing":return e("settings.providers.page.auth.oauth.error.codeRequired");case"ProviderAuthOauthCallbackFailed":return e("settings.providers.page.auth.oauth.error.declined");case"ProviderAuthValidationFailed":return Ns(i.message)??e("settings.providers.page.auth.oauth.error.invalidInput");default:return e(a)}},$i={phase:"idle"},Do=({providerId:t,methods:e,onConnected:a,className:n})=>{const{t:i}=at(),[r,l]=o.useState($i),[u,p]=o.useState({}),[h,d]=o.useState(""),w=o.useRef(null);o.useEffect(()=>()=>w.current?.abort(),[]);const c=r.phase==="idle"?null:r.methodIndex,N=r.phase==="authorizing"||r.phase==="waiting"||r.phase==="awaitingCode"&&r.submitting,v=async(f,b,F)=>{const D=await La(f);if(D.ok){M.success(i(b));return}console.error("Failed to copy OAuth value:",D.error),M.error(i(F))},C=async(f,b)=>{const F=new AbortController;w.current?.abort(),w.current=F;try{const D=await hn.getSdkClient().provider.oauth.callback({providerID:t,method:f,...b?{code:b}:{}},{signal:F.signal});if(F.signal.aborted)return;if(D.error)throw D.error;l($i),M.success(i("settings.providers.page.toast.oauthCompleted")),await a()}catch(D){if(F.signal.aborted)return;console.error("Failed to complete OAuth flow:",D),l({phase:"failed",methodIndex:f,message:Eo(D,i,"settings.providers.page.toast.oauthCompleteFailed")})}finally{w.current===F&&(w.current=null)}},y=async(f,b)=>{l({phase:"authorizing",methodIndex:f});let F;try{const D=await hn.getSdkClient().provider.oauth.authorize({providerID:t,method:f,...Object.keys(b).length>0?{inputs:b}:{}});if(D.error)throw D.error;const P=Sg(D.data);if(!P){l({phase:"failed",methodIndex:f,message:i("settings.providers.page.toast.oauthDetailsMissing")});return}F=P}catch(D){console.error("Failed to start OAuth flow:",D),l({phase:"failed",methodIndex:f,message:Eo(D,i,"settings.providers.page.toast.oauthStartFailed")});return}if(F.url&&hg(t,F.url)&&yn(F.url),F.method==="code"){d(""),l({phase:"awaitingCode",methodIndex:f,authorization:F,submitting:!1});return}l({phase:"waiting",methodIndex:f,authorization:F}),await C(f)},S=f=>{const b=bg(f.prompts);if(b.length===0){y(f.index,{});return}p(jg(b)),l({phase:"prompting",methodIndex:f.index,prompts:b,error:null})},g=()=>{if(r.phase!=="prompting")return;const f=kg(r.prompts,u);if(f){l({...r,error:i("settings.providers.page.auth.oauth.promptRequired",{field:f.message})});return}y(r.methodIndex,Ng(r.prompts,u))},T=()=>{if(r.phase!=="awaitingCode")return;const f=h.trim();f&&(l({...r,submitting:!0}),C(r.methodIndex,f))},R=()=>{w.current?.abort(),w.current=null,l($i)},A=f=>{const b=u[f.key]??"",F=D=>p(P=>({...P,[f.key]:D}));return s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("label",{className:"typography-ui-label text-foreground",children:f.message}),f.type==="select"?s.jsxs(Pt,{value:b,onValueChange:F,children:[s.jsx(It,{size:Lt,className:en,children:s.jsx(Rt,{children:D=>f.options.find(P=>P.value===D)?.label??null})}),s.jsx(At,{children:f.options.map(D=>s.jsx(ot,{value:D.value,children:D.hint?`${D.label} · ${D.hint}`:D.label},D.value))})]}):s.jsx(Je,{value:b,onChange:D=>F(D.target.value),placeholder:f.placeholder,className:"max-w-[24rem] text-xs"})]},f.key)},j=f=>s.jsxs(s.Fragment,{children:[f.instructions&&s.jsx("p",{className:"typography-meta text-[var(--primary-base)] bg-[var(--primary-base)]/10 px-2 py-1.5 rounded",children:f.instructions}),f.userCode&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Je,{value:f.userCode,readOnly:!0,"aria-label":i("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:()=>{v(f.userCode??"","settings.providers.page.toast.deviceCodeCopied","settings.providers.page.toast.deviceCodeCopyFailed")},children:i("settings.providers.page.actions.copyCode")})]}),f.url&&s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Je,{value:f.url,readOnly:!0,"aria-label":i("settings.providers.page.auth.oauth.linkLabel"),className:"text-xs text-muted-foreground"}),s.jsxs("div",{className:"flex gap-1 shrink-0",children:[s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{yn(f.url??"")},children:i("settings.providers.page.actions.open")}),s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{v(f.url??"","settings.providers.page.toast.oauthLinkCopied","settings.providers.page.toast.oauthLinkCopyFailed")},children:i("settings.providers.page.actions.copy")})]})]})]});return s.jsx("div",{className:we("space-y-4",n),children:e.map(f=>{const b=c===f.index;return s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:f.label}),s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal shrink-0",onClick:()=>S(f),disabled:N,children:i("settings.providers.page.actions.connect")})]}),b&&r.phase==="prompting"&&s.jsxs("div",{className:"space-y-3",children:[Nr(r.prompts,u).map(A),r.error&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:r.error}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(B,{size:"xs",className:"!font-normal",onClick:g,children:i("settings.providers.page.actions.continue")}),s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal",onClick:R,children:i("settings.providers.page.actions.cancel")})]})]}),b&&r.phase==="authorizing"&&s.jsxs("p",{className:"typography-meta text-muted-foreground flex items-center gap-2",children:[s.jsx(O,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),i("settings.providers.page.auth.oauth.starting")]}),b&&r.phase==="waiting"&&s.jsxs("div",{className:"space-y-3",children:[j(r.authorization),s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[s.jsxs("p",{className:"typography-meta text-muted-foreground flex items-center gap-2",children:[s.jsx(O,{name:"loader",className:"h-3.5 w-3.5 animate-spin"}),i("settings.providers.page.auth.oauth.waiting")]}),s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:R,children:i("settings.providers.page.actions.cancel")})]}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("settings.providers.page.auth.oauth.waitingHint")})]}),b&&r.phase==="awaitingCode"&&s.jsxs("div",{className:"space-y-3",children:[j(r.authorization),s.jsx("p",{className:"typography-meta text-muted-foreground",children:i("settings.providers.page.auth.oauth.codeHint")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Je,{value:h,onChange:F=>d(F.target.value),placeholder:i("settings.providers.page.auth.pasteAuthorizationCodePlaceholder"),className:"font-mono text-xs",disabled:r.submitting}),s.jsx(B,{size:"xs",className:"!font-normal shrink-0",onClick:T,disabled:r.submitting||h.trim().length===0,children:r.submitting?i("settings.providers.page.actions.saving"):i("settings.providers.page.actions.complete")}),s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal shrink-0",onClick:R,disabled:r.submitting,children:i("settings.providers.page.actions.cancel")})]})]}),b&&r.phase==="failed"&&s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:r.message}),s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>S(f),children:i("settings.providers.page.actions.tryAgain")})]})]},f.index)})})},Mo=t=>Array.isArray(t?.env)&&t.env.some(e=>e.trim().length>0),Cg=t=>new Intl.NumberFormat(hr(),{notation:"compact",compactDisplay:"short",maximumFractionDigits:1,minimumFractionDigits:0}).format(t),Ro=t=>{if(typeof t!="number"||Number.isNaN(t))return null;if(t===0)return"0";const e=Cg(t);return e.endsWith(".0")?e.slice(0,-2):e},Ia="__add_provider__",Bl=t=>typeof t=="object"&&t!==null,Oo=(t,e)=>t.map(({method:a,methodIndex:n})=>({index:n,label:a.label||a.name||e(n),prompts:a.prompts})),Pg=t=>{if(typeof t=="string")return{id:t};if(!Bl(t))return null;const e=typeof t.id=="string"&&t.id||typeof t.providerID=="string"&&t.providerID||typeof t.slug=="string"&&t.slug||typeof t.name=="string"&&t.name;if(!e)return null;const a=typeof t.name=="string"?t.name:void 0;return{id:e,name:a}},Ig=t=>{let e=[];Array.isArray(t)?e=t:Bl(t)&&(Array.isArray(t.all)?e=t.all:Array.isArray(t.providers)&&(e=t.providers));const a=e.map(i=>Pg(i)).filter(i=>!!i),n=new Set;return a.filter(i=>n.has(i.id)?!1:(n.add(i.id),!0))},Ag=()=>{const{t}=at(),e=Us(),a=Ze(W=>xl(W,e)),n=Ze(W=>W.selectedProviderId),i=Ze(W=>W.setSelectedProvider),r=Ze(W=>W.getModelMetadata),l=de(W=>W.hiddenModels),u=de(W=>W.toggleHiddenModel),p=de(W=>W.hideAllModels),h=de(W=>W.showAllModels),[d,w]=o.useState({}),[c,N]=o.useState(!1),[v,C]=o.useState({}),[y,S]=o.useState(null),[g,T]=o.useState(""),[R,A]=o.useState([]),[j,f]=o.useState(!1),[b,F]=o.useState(null),[D,P]=o.useState(""),[I,U]=o.useState(""),[q,k]=o.useState(!1),[$,G]=o.useState({}),[E,J]=o.useState(0),[X,L]=o.useState(!1),[se,z]=o.useState(null),[V,_]=o.useState(null),[K,Z]=o.useState(null),[Y,te]=o.useState(null),[ge,le]=o.useState(null),[he,ne]=o.useState(null),ae=n===Ia,me=ae&&D===Kn,Pe=!!(V&&n&&V===n&&!ae);o.useEffect(()=>{!n&&a.length>0&&i(a[0].id)},[a,n,i]),o.useEffect(()=>{if(!n)return;let W=!0;return(async()=>{N(!0);try{const Ie=await hn.getSdkClient().provider.auth();if(Ie.error)throw new Error(`provider.auth failed: ${String(Ie.error)}`);if(!W)return;w(Ym(Ie.data))}catch(Ie){if(!W)return;console.error("Failed to load provider auth methods:",Ie),M.error(t("settings.providers.page.toast.authMethodsLoadFailed"))}finally{W&&N(!1)}})(),()=>{W=!1}},[n,t]),o.useEffect(()=>{if(!Jm(ae))return;let W=!0;return(async()=>{f(!0),F(null);try{const Ie=await hn.getSdkClient().provider.list();if(Ie.error)throw new Error(`provider.list failed: ${String(Ie.error)}`);if(!W)return;A(Ig(Ie.data))}catch(Ie){if(!W)return;console.error("Failed to load available providers:",Ie),F(t("settings.providers.page.state.unableToLoadProviderList"))}finally{W&&f(!1)}})(),()=>{W=!1}},[ae,t]);const Ne=o.useMemo(()=>new Set(a.map(W=>W.id)),[a]),Se=o.useMemo(()=>R.filter(W=>!Ne.has(W.id)).sort((W,ke)=>{const Ie=(W.name||W.id).toLowerCase(),Ge=(ke.name||ke.id).toLowerCase();return Ie.localeCompare(Ge)}),[R,Ne]);o.useEffect(()=>{n===Ia&&D&&D!==Kn&&!Se.some(W=>W.id===D)&&P("")},[n,D,Se]),o.useEffect(()=>{if(n===Ia){L(!0),z(null),_(null),Z(null),te(null),le(null);return}L(!1),z(null),V&&V!==n&&(_(null),Z(null),te(null),le(null))},[n,V]),o.useEffect(()=>{if(!n||n===Ia)return;const W=$[n];if(!W)return;const ke=a.find(it=>it.id===n),Ie=Po({key:ke?.key,authSourceExists:W.auth.exists,optionsApiKey:ke?.options?.apiKey??null,envDeclared:Mo(ke)}),Ge=!!(ke&&Io(ke,W));eg({hasCredentials:Ie,userDismissed:se===n,isEditableCustomProvider:Ge})&&L(!0)},[n,$,a,se]),o.useEffect(()=>{if(!n||n===Ia)return;let W=!1;return(async()=>{try{const Ie=e?`?directory=${encodeURIComponent(e)}`:"",Ge=await pt(`/api/provider/${encodeURIComponent(n)}/source${Ie}`,{method:"GET",headers:{Accept:"application/json"}}),it=await Ge.json().catch(()=>null);if(!Ge.ok)throw new Error(it?.error||t("settings.providers.page.toast.providerSourcesLoadFailed"));const nt=it?.sources??it?.data?.sources;!W&&nt&&G(dt=>({...dt,[n]:nt}))}catch(Ie){W||console.error("Failed to load provider sources:",Ie)}})(),()=>{W=!0}},[n,E,e,t]);const be=o.useCallback(()=>{J(W=>W+1)},[]),Ke=o.useCallback(W=>{G(ke=>{const Ie=ke[W];return{...ke,[W]:{auth:{exists:!0,path:Ie?.auth.path??null},user:Ie?.user??{exists:!1,path:null},project:Ie?.project??{exists:!1,path:null},...Ie?.custom?{custom:Ie.custom}:{}}}}),z(null),L(!1),i(W),be()},[be,i]),Le=o.useCallback(async(W,ke)=>{try{return await vl({scopes:[W],mode:"active"}),"reloaded"}catch(Ie){if(Ie?.requiresManualRestart===!0)return ke&&$n(W,{id:ke}),"manual-restart";throw Ie}},[]),oe=a.find(W=>W.id===n),xe=n?$[n]:void 0,Ee=async W=>{const ke=v[W]?.trim()??"";if(!ke){M.error(t("settings.providers.page.toast.apiKeyRequired"));return}const Ie=`api:${W}`;S(Ie);try{if((await hn.getSdkClient().auth.set({providerID:W,auth:{type:"api",key:ke}})).error)throw new Error(t("settings.providers.page.toast.apiKeySaveFailed"));M.success(t("settings.providers.page.toast.apiKeySaved")),C(it=>({...it,[W]:""})),await Le("providers",W),Ke(W)}catch(Ge){console.error("Failed to save API key:",Ge),M.error(t("settings.providers.page.toast.apiKeySaveFailed"))}finally{S(null)}},Ve=async W=>{const ke=`custom:${W.providerID}`;S(ke),ne(W.providerID),le(null);try{const Ie=dg(W);if(Ie&&(await hn.getSdkClient().auth.set(Ie)).error)throw new Error(t("settings.providers.page.toast.apiKeySaveFailed"));const Ge=ug(W,{scope:V?Y??Ao($[V]):"user"}),it=await pt(`/api/provider${e?`?directory=${encodeURIComponent(e)}`:""}`,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(Ge)}),nt=await it.json().catch(()=>null);if(!it.ok)throw Ie&&le(t("settings.providers.page.custom.authFailure.configAfterAuth")),new Error(nt?.error||t("settings.providers.page.toast.customProviderSaveFailed"));M.success(t("settings.providers.page.toast.customProviderSaved",{provider:W.name})),P(""),_(null),Z(null),te(null),le(null),ne(null),await Le("providers",W.providerID),Ke(W.providerID)}catch(Ie){console.error("Failed to save custom provider:",Ie),M.error(Ie instanceof Error&&Ie.message?Ie.message:t("settings.providers.page.toast.customProviderSaveFailed"))}finally{S(null)}},$e=W=>t("settings.providers.page.auth.oauthMethodFallback",{index:String(W+1)}),We=W=>{L(!1),Zm(W)&&$n("providers",{id:W}),Ke(W)},Fe=async W=>{const ke=`disconnect:${W}`;S(ke);try{const Ie=await pt(`/api/provider/${encodeURIComponent(W)}/auth?scope=all${e?`&directory=${encodeURIComponent(e)}`:""}`,{method:"DELETE",headers:{Accept:"application/json"}}),Ge=await Ie.json().catch(()=>null);if(!Ie.ok)throw new Error(Ge?.error||t("settings.providers.page.toast.providerDisconnectFailed"));M.success(t("settings.providers.page.toast.providerDisconnected")),await Le("providers",W),z(null),be()}catch(Ie){console.error("Failed to disconnect provider:",Ie),M.error(t("settings.providers.page.toast.providerDisconnectFailed"))}finally{S(null)}},ie=async W=>{W&&(await Fe(W),_(null),Z(null),te(null),le(null),ne(null),P(""))};if(!ae&&a.length===0)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(O,{name:"stack",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.providers.page.empty.noProvidersDetected")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.providers.page.empty.checkOpenCodeConfiguration")})]})});if(ae)return s.jsxs(ns,{title:t("settings.providers.page.connect.title"),showSaveStatus:!1,children:[s.jsx(_e,{title:t("settings.providers.page.connect.selectProviderTitle"),divider:!1,settingsItem:"providers.connect",children:s.jsxs("div",{className:"flex flex-wrap items-center gap-2 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.connect.providerField")}),j?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.state.loading")}):b?s.jsx("p",{className:"typography-meta text-muted-foreground",children:b}):s.jsxs(an,{open:q,onOpenChange:W=>{k(W),W||U("")},children:[s.jsx(sn,{asChild:!0,children:s.jsxs("button",{type:"button",className:Mn,children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[D&&D!==Kn?s.jsx(Un,{providerId:D,className:"h-3.5 w-3.5 flex-shrink-0"}):null,s.jsx("span",{className:we("truncate typography-ui-label font-normal",D?"text-foreground":"text-muted-foreground"),children:D===Kn?t("settings.providers.page.custom.optionLabel"):D?Se.find(W=>W.id===D)?.name||D:t("settings.providers.page.connect.selectProviderPlaceholder")})]}),s.jsx(O,{name:"arrow-down-s",className:"h-4 w-4 flex-shrink-0 text-muted-foreground/50"})]})}),s.jsxs(nn,{align:"start",className:"w-[280px] p-0",onCloseAutoFocus:W=>W.preventDefault(),children:[s.jsxs("div",{className:"flex items-center gap-2 border-b border-[var(--surface-subtle)] px-3 py-2",onKeyDown:W=>W.stopPropagation(),children:[s.jsx(O,{name:"search",className:"h-4 w-4 text-muted-foreground"}),s.jsx("input",{type:"text",value:I,onChange:W=>U(W.target.value),onKeyDown:W=>W.stopPropagation(),placeholder:t("settings.providers.page.connect.searchProvidersPlaceholder"),className:"flex-1 bg-transparent typography-meta outline-none placeholder:text-muted-foreground",autoFocus:!0})]}),s.jsx(Bs,{outerClassName:"max-h-[240px]",className:"p-1",children:(()=>{const W=t("settings.providers.page.custom.optionLabel"),ke=Pc([W,"other","custom"],I),Ie=gi(Se,I,Ge=>[Ge.name||Ge.id,Ge.id]);return Ie.length===0&&!ke?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:[Ie.map(Ge=>s.jsxs(rn,{onSelect:()=>{P(Ge.id),k(!1),U("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(Un,{providerId:Ge.id,className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:Ge.name||Ge.id})]}),D===Ge.id&&s.jsx(O,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},Ge.id)),ke?s.jsxs(rn,{onSelect:()=>{P(Kn),k(!1),U("")},className:"flex items-center justify-between",children:[s.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[s.jsx(O,{name:"add",className:"h-4 w-4 flex-shrink-0"}),s.jsx("span",{className:"truncate",children:W})]}),D===Kn&&s.jsx(O,{name:"check",className:"h-4 w-4 text-[var(--primary-base)]"})]},Kn):null]})})()})]})]})]})}),me?s.jsx(To,{mode:"create",existingProviderIDs:Ne,busy:y?.startsWith("custom:")??!1,authFailureHint:ge,onCancel:()=>{P(""),le(null),ne(null)},onDisconnect:ge&&he?()=>{ie(he)}:void 0,onSubmit:Ve}):D?s.jsx(_e,{title:t("settings.providers.page.auth.title"),settingsItem:"providers.auth",contentClassName:"space-y-4",children:c?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsx(s.Fragment,{children:(()=>{const W=d[D]??[],ke=Oo(Co(W),$e),Ie=So(W);return s.jsxs(s.Fragment,{children:[Ie?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(Jt,{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(Je,{type:"password",value:v[D]??"",onChange:Ge=>C(it=>({...it,[D]:Ge.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:()=>Ee(D),disabled:y===`api:${D}`,children:y===`api:${D}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,ke.length>0?s.jsx(Do,{providerId:D,methods:ke,onConnected:()=>We(D),className:we(Ie&&"border-t border-[var(--surface-subtle)] pt-2")},D):null]})})()})}):null]});if(!oe)return s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(O,{name:"stack",className:"mx-auto mb-3 h-12 w-12 opacity-50"}),s.jsx("p",{className:"typography-body",children:t("settings.providers.page.empty.selectProviderFromSidebar")}),s.jsx("p",{className:"typography-meta mt-1 opacity-75",children:t("settings.providers.page.empty.reviewDetailsAndConfigureAuth")})]})});const re=Array.isArray(oe.models)?oe.models:[],je=d[oe.id]??[],ve=Oo(Co(je),$e),Re=So(je),Ae=!!xe,ye=Ae&&Io(oe,xe),He=Po({key:oe.key,authSourceExists:xe?.auth.exists,optionsApiKey:oe.options?.apiKey??null,envDeclared:Mo(oe)}),ue=Qm(Ae,He,ye),Ce=Xm({modelCount:re.length,sourcesLoaded:Ae,hasCredentials:He,isEditableCustomProvider:ye}),De=!Re&&ve.length>0?t("settings.providers.page.auth.useReconnectHint"):t("settings.providers.page.auth.incompleteHint"),Ye=gi(re,g,W=>[typeof W?.name=="string"?W.name:"",typeof W?.id=="string"?W.id:""]);return Pe&&ye&&K?s.jsx(ns,{title:oe.name||oe.id,titleLeading:s.jsx(Un,{providerId:oe.id,className:"h-5 w-5 shrink-0"}),description:s.jsx("span",{className:"font-mono typography-settings-description text-muted-foreground",children:oe.id}),showSaveStatus:!1,children:s.jsx(To,{mode:"edit",existingProviderIDs:Ne,initialValues:K,allowExistingAuth:He||!Ae,busy:y?.startsWith("custom:")??!1,authFailureHint:ge,onCancel:()=>{_(null),Z(null),te(null),le(null),ne(null)},onDisconnect:()=>{ie(oe.id)},onSubmit:Ve})}):s.jsxs(ns,{title:oe.name||oe.id,titleLeading:s.jsx(Un,{providerId:oe.id,className:"h-5 w-5 shrink-0"}),description:s.jsx("span",{className:"font-mono typography-settings-description text-muted-foreground",children:oe.id}),showSaveStatus:!1,children:[s.jsx(_e,{title:t("settings.providers.page.auth.title"),divider:!1,headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[ye?s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{le(null),Z(lg(oe)),te(Ao(xe)),_(oe.id)},children:t("settings.providers.page.actions.edit")}):null,s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const W=!X;L(W),z(W?null:oe.id)},children:t(X?"settings.providers.page.actions.hide":"settings.providers.page.actions.reconnect")})]}),settingsItem:"providers.auth",children:X?c?s.jsx("div",{className:"py-1.5 typography-meta text-muted-foreground",children:t("settings.providers.page.auth.loadingMethods")}):s.jsxs("div",{className:"space-y-4",children:[Re?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(Jt,{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(Je,{type:"password",value:v[oe.id]??"",onChange:W=>C(ke=>({...ke,[oe.id]:W.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:()=>Ee(oe.id),disabled:y===`api:${oe.id}`,children:y===`api:${oe.id}`?t("settings.providers.page.actions.saving"):t("settings.providers.page.actions.saveKey")})]})]}):null,ve.length>0&&s.jsx(Do,{providerId:oe.id,methods:ve,onConnected:()=>We(oe.id),className:we(Re&&"border-t border-[var(--surface-subtle)] pt-2")},oe.id)]}):ue?s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(O,{name:"alert",className:"w-4 h-4 text-[var(--status-warning)] shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.auth.incomplete")}),s.jsx(Jt,{children:De})]}):s.jsxs("div",{className:"flex items-center gap-1.5 py-1.5",children:[s.jsx(O,{name:"check",className:"w-4 h-4 text-[var(--status-success)] shrink-0"}),s.jsx("span",{className:"typography-ui-label text-foreground",children:t("settings.providers.page.auth.connected")}),s.jsx(Jt,{children:t("settings.providers.page.auth.useReconnectHint")})]})}),s.jsx(_e,{title:t("settings.providers.page.connectionDetails.title"),settingsItem:"providers.connection-details",children:s.jsxs("div",{className:"flex flex-col gap-2 py-1.5 @xl:flex-row @xl:items-center @xl:justify-between @xl:gap-8",children:[s.jsx("div",{className:"flex min-w-0 flex-col",children:xe&&(xe.auth.exists||xe.user.exists||xe.project.exists||xe.custom?.exists)?s.jsxs("span",{className:"typography-meta text-muted-foreground",children:[t("settings.providers.page.connectionDetails.configuredIn")," ",[xe.auth.exists?t("settings.providers.page.connectionDetails.source.authCredentials"):null,xe.user.exists?t("settings.providers.page.connectionDetails.source.userConfig"):null,xe.project.exists?t("settings.providers.page.connectionDetails.source.projectConfig"):null,xe.custom?.exists?t("settings.providers.page.connectionDetails.source.customConfig"):null].filter(Boolean).join(", ")]}):s.jsx("span",{className:"typography-meta text-muted-foreground",children:t("settings.providers.page.connectionDetails.noActiveSource")})}),s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal text-[var(--status-error)] hover:text-[var(--status-error)]",onClick:()=>Fe(oe.id),disabled:y===`disconnect:${oe.id}`,children:y===`disconnect:${oe.id}`?t("settings.providers.page.actions.disconnecting"):t("settings.providers.page.actions.disconnect")})]})}),Ce?s.jsxs(_e,{title:t("settings.providers.page.models.title"),titleAccessory:s.jsxs("span",{className:"typography-micro text-muted-foreground font-normal",children:["(",re.length,")"]}),headerAction:s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{const W=re.map(ke=>typeof ke?.id=="string"?ke.id:"").filter(ke=>ke.length>0);p(oe.id,W)},children:t("settings.providers.page.actions.hideAll")}),s.jsx(B,{variant:"outline",size:"xs",className:"!font-normal",onClick:()=>h(oe.id),children:t("settings.providers.page.actions.showAll")})]}),settingsItem:"providers.models",children:[s.jsxs("div",{className:"relative mb-2",children:[s.jsx(O,{name:"search",className:"absolute left-2 top-1/2 -translate-y-1/2 h-3.5 w-3.5 text-muted-foreground"}),s.jsx(Je,{value:g,onChange:W=>T(W.target.value),placeholder:t("settings.providers.page.models.filterPlaceholder"),className:"h-7 pl-8 w-full"})]}),Ye.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground py-4 text-center",children:t("settings.providers.page.models.noModelsMatchFilter")}):s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Ye.map(W=>{const ke=typeof W?.id=="string"?W.id:"",Ie=typeof W?.name=="string"?W.name:ke,Ge=ke?r(oe.id,ke):void 0,it=l.some(H=>H.providerID===oe.id&&H.modelID===ke),nt=Ro(Ge?.limit?.context),dt=Ro(Ge?.limit?.output),xt=[];return Ge?.tool_call&&xt.push({key:"tools",icon:"tools",label:t("settings.providers.page.models.capability.toolCalling")}),Ge?.reasoning&&xt.push({key:"reasoning",icon:"brain-ai-3",label:t("settings.providers.page.models.capability.reasoning")}),Ge?.attachment&&xt.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:we("flex items-center gap-3",it&&"opacity-50"),children:[s.jsx("span",{className:"typography-meta font-medium text-foreground truncate flex-1 min-w-0",children:Ie}),s.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[(nt||dt)&&s.jsxs("span",{className:"typography-micro text-muted-foreground flex-shrink-0 bg-[var(--surface-muted)] px-1.5 py-0.5 rounded",children:[nt?`${nt} ${t("settings.providers.page.models.tokenBadge.context")}`:"",nt&&dt?" · ":"",dt?`${dt} ${t("settings.providers.page.models.tokenBadge.output")}`:""]}),xt.length>0&&s.jsx("div",{className:"flex items-center gap-1 flex-shrink-0",children:xt.map(({key:H,icon:Be,label:tt})=>s.jsx("span",{className:"flex h-5 w-5 rounded items-center justify-center text-muted-foreground bg-[var(--surface-muted)]",title:tt,"aria-label":tt,children:s.jsx(O,{name:Be,className:"h-3 w-3"})},H))}),s.jsx("button",{type:"button",onClick:()=>u(oe.id,ke),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(it?"settings.providers.page.models.actions.showModelInSelectors":"settings.providers.page.models.actions.hideModelFromSelectors"),"aria-label":t(it?"settings.providers.page.models.actions.showModel":"settings.providers.page.models.actions.hideModel"),children:it?s.jsx(O,{name:"eye-off",className:"h-3.5 w-3.5"}):s.jsx(O,{name:"eye",className:"h-3.5 w-3.5"})})]})]})},ke)})})]}):null]})},Tg=t=>{const e=t?.windows??{},a=Object.values(e).map(n=>n.usedPercent).filter(n=>typeof n=="number");return a.length===0?null:Math.max(...a)},Eg=t=>{const e=mt.c(75),{onItemSelect:a}=t,{t:n}=at(),i=ss(Dg),r=ss(Mg),l=ss(Rg),u=ss(Og),p=ss(Lg),h=ss(Fg),d=ss(Kg),w=ss(zg);let c,N;e[0]!==w?(c=()=>{w()},N=[w],e[0]=w,e[1]=c,e[2]=N):(c=e[1],N=e[2]),o.useEffect(c,N);const v=Ug;let C;e[3]!==d?(C=te=>{te!=="usage"&&te!=="remaining"||(d(te),v({usageDisplayMode:te}))},e[3]=d,e[4]=C):C=e[4];const y=C;let S;e[5]===Symbol.for("react.memo_cache_sentinel")?(S=we("flex h-full flex-col","bg-background"),e[5]=S):S=e[5];let g;e[6]!==n?(g=n("settings.usage.sidebar.title"),e[6]=n,e[7]=g):g=e[7];let T;e[8]!==g?(T=s.jsx("h2",{className:`${on} mb-3`,children:g}),e[8]=g,e[9]=T):T=e[9];let R;e[10]!==n?(R=n("settings.usage.sidebar.total",{count:fi.length}),e[10]=n,e[11]=R):R=e[11];let A;e[12]!==R?(A=s.jsx("span",{className:"typography-meta text-muted-foreground",children:R}),e[12]=R,e[13]=A):A=e[13];let j;e[14]!==u?(j=()=>u(),e[14]=u,e[15]=j):j=e[15];let f;e[16]!==n?(f=n("settings.usage.sidebar.actions.refreshAria"),e[16]=n,e[17]=f):f=e[17];let b;e[18]!==n?(b=n("settings.usage.sidebar.actions.refreshTitle"),e[18]=n,e[19]=b):b=e[19];const F=p&&"animate-spin";let D;e[20]!==F?(D=we("h-3.5 w-3.5",F),e[20]=F,e[21]=D):D=e[21];let P;e[22]!==D?(P=s.jsx(O,{name:"refresh",className:D}),e[22]=D,e[23]=P):P=e[23];let I;e[24]!==p||e[25]!==f||e[26]!==b||e[27]!==P||e[28]!==j?(I=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:j,"aria-label":f,title:b,disabled:p,children:P})}),e[24]=p,e[25]=f,e[26]=b,e[27]=P,e[28]=j,e[29]=I):I=e[29];let U;e[30]!==I||e[31]!==A?(U=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[A,I]}),e[30]=I,e[31]=A,e[32]=U):U=e[32];let q;e[33]!==n?(q=n("settings.usage.sidebar.field.display"),e[33]=n,e[34]=q):q=e[34];let k;e[35]!==q?(k=s.jsx("span",{className:"typography-micro text-muted-foreground",children:q}),e[35]=q,e[36]=k):k=e[36];let $;e[37]!==n?($=n("settings.usage.sidebar.field.displayModePlaceholder"),e[37]=n,e[38]=$):$=e[38];let G;e[39]!==$?(G=s.jsx(It,{className:"w-fit",children:s.jsx(Rt,{placeholder:$})}),e[39]=$,e[40]=G):G=e[40];let E;e[41]!==n?(E=n("settings.usage.sidebar.field.displayModeUsage"),e[41]=n,e[42]=E):E=e[42];let J;e[43]!==E?(J=s.jsx(ot,{value:"usage",children:E}),e[43]=E,e[44]=J):J=e[44];let X;e[45]!==n?(X=n("settings.usage.sidebar.field.displayModeRemaining"),e[45]=n,e[46]=X):X=e[46];let L;e[47]!==X?(L=s.jsx(ot,{value:"remaining",children:X}),e[47]=X,e[48]=L):L=e[48];let se;e[49]!==J||e[50]!==L?(se=s.jsxs(At,{children:[J,L]}),e[49]=J,e[50]=L,e[51]=se):se=e[51];let z;e[52]!==y||e[53]!==G||e[54]!==se||e[55]!==h?(z=s.jsxs(Pt,{value:h,onValueChange:y,children:[G,se]}),e[52]=y,e[53]=G,e[54]=se,e[55]=h,e[56]=z):z=e[56];let V;e[57]!==k||e[58]!==z?(V=s.jsxs("div",{className:"mt-2 flex items-center justify-between gap-2",children:[k,z]}),e[57]=k,e[58]=z,e[59]=V):V=e[59];let _;e[60]!==U||e[61]!==V||e[62]!==T?(_=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[T,U,V]}),e[60]=U,e[61]=V,e[62]=T,e[63]=_):_=e[63];let K;e[64]!==a||e[65]!==i||e[66]!==r||e[67]!==l||e[68]!==n?(K=fi.map(te=>{const ge=i.find(Pe=>Pe.providerId===te.id),le=Tg(ge?.usage),he=yl(le),ne=te.id===r,ae=ge?.configured??!1,me=ae?he==="critical"?{backgroundColor:"var(--status-error)"}:he==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"}:{backgroundColor:"var(--surface-muted-foreground)",opacity:.4};return s.jsx("div",{className:we("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200",ne?"bg-interactive-selection":"hover:bg-interactive-hover"),children:s.jsxs("button",{type:"button",onClick:()=>{l(te.id),a?.()},className:"flex min-w-0 flex-1 items-center gap-2 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsx("span",{className:"h-2.5 w-2.5 rounded-full flex-shrink-0",style:me}),s.jsx(Un,{providerId:te.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:te.name}),!ae&&s.jsx("span",{className:"typography-micro text-muted-foreground/60 flex-shrink-0",children:n("settings.usage.sidebar.status.notSet")})]})},te.id)}),e[64]=a,e[65]=i,e[66]=r,e[67]=l,e[68]=n,e[69]=K):K=e[69];let Z;e[70]!==K?(Z=s.jsx(Bs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2 overflow-x-hidden",children:K}),e[70]=K,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 Dg(t){return t.results}function Mg(t){return t.selectedProviderId}function Rg(t){return t.setSelectedProvider}function Og(t){return t.fetchAllQuotas}function Lg(t){return t.isLoading}function Fg(t){return t.displayMode}function Kg(t){return t.setDisplayMode}function zg(t){return t.loadSettings}async function Ug(t){try{await yt(t)}catch(e){console.warn("Failed to save usage settings:",e)}}const _g=t=>{const e=mt.c(17),{percent:a,tonePercent:n,className:i}=t;let r;e[0]!==a?(r=Ic(a)??0,e[0]=a,e[1]=r):r=e[1];const l=r,u=n??a;let p;e[2]!==u?(p=yl(u),e[2]=u,e[3]=p):p=e[3];const h=p;let d;e[4]!==h?(d=h==="critical"?{backgroundColor:"var(--status-error)"}:h==="warn"?{backgroundColor:"var(--status-warning)"}:{backgroundColor:"var(--status-success)"},e[4]=h,e[5]=d):d=e[5];const w=d;let c;e[6]!==i?(c=we("relative h-2.5 rounded-full bg-[var(--interactive-border)] overflow-hidden",i),e[6]=i,e[7]=c):c=e[7];const N=`${l}%`;let v;e[8]!==w||e[9]!==N?(v={...w,width:N},e[8]=w,e[9]=N,e[10]=v):v=e[10];let C;e[11]!==l||e[12]!==v?(C=s.jsx("div",{className:"h-full transition-all duration-300",style:v,role:"progressbar","aria-valuenow":l,"aria-valuemin":0,"aria-valuemax":100}),e[11]=l,e[12]=v,e[13]=C):C=e[13];let y;return e[14]!==c||e[15]!==C?(y=s.jsx("div",{className:c,children:C}),e[14]=c,e[15]=C,e[16]=y):y=e[16],y},Vi=t=>{const e=mt.c(44),{title:a,window:n,subtitle:i,showToggle:r,toggleEnabled:l,onToggle:u}=t,p=r===void 0?!1:r,h=l===void 0?!1:l,d=ss($g),w=de(Vg),c=d==="remaining"?n.remainingPercent:n.usedPercent,N=d==="remaining"?"remaining":"used";let v;e[0]!==c||e[1]!==n.valueLabel?(v=Ac(n.valueLabel,c),e[0]=c,e[1]=n.valueLabel,e[2]=v):v=e[2];const C=v,y=n.resetAfterFormatted??n.resetAtFormatted;let S;e[3]!==y||e[4]!==w||e[5]!==n.resetAt?(S=Tc(n.resetAt,y,w),e[3]=y,e[4]=w,e[5]=n.resetAt,e[6]=S):S=e[6];const g=S;let T;e[7]!==a?(T=Ec(a),e[7]=a,e[8]=T):T=e[8];const R=T;let A;e[9]!==u||e[10]!==p||e[11]!==h?(A=p&&s.jsx(Xi,{checked:h,onChange:X=>u?.(X),ariaLabel:"Show in dropdown"}),e[9]=u,e[10]=p,e[11]=h,e[12]=A):A=e[12];let j;e[13]!==R?(j=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:R}),e[13]=R,e[14]=j):j=e[14];let f;e[15]!==i?(f=i&&s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:i}),e[15]=i,e[16]=f):f=e[16];let b;e[17]!==j||e[18]!==f?(b=s.jsxs("div",{className:"min-w-0 flex flex-col",children:[j,f]}),e[17]=j,e[18]=f,e[19]=b):b=e[19];let F;e[20]!==b||e[21]!==A?(F=s.jsxs("div",{className:"min-w-0 flex-1 flex items-center gap-2",children:[A,b]}),e[20]=b,e[21]=A,e[22]=F):F=e[22];const D=C==="-"?"":C;let P;e[23]!==D?(P=s.jsx("div",{className:"typography-ui-label text-foreground tabular-nums flex items-center justify-end",children:D}),e[23]=D,e[24]=P):P=e[24];let I;e[25]!==F||e[26]!==P?(I=s.jsxs("div",{className:"flex items-center justify-between gap-3",children:[F,P]}),e[25]=F,e[26]=P,e[27]=I):I=e[27];let U;e[28]!==c||e[29]!==n.usedPercent?(U=s.jsx(_g,{percent:c,tonePercent:n.usedPercent,className:"h-1.5"}),e[28]=c,e[29]=n.usedPercent,e[30]=U):U=e[30];const q=g?`Resets ${g}`:"";let k;e[31]!==q?(k=s.jsx("span",{className:"typography-micro text-muted-foreground",children:q}),e[31]=q,e[32]=k):k=e[32];let $;e[33]!==N?($=s.jsx("span",{className:"typography-micro text-muted-foreground",children:N}),e[33]=N,e[34]=$):$=e[34];let G;e[35]!==k||e[36]!==$?(G=s.jsxs("div",{className:"mt-1 flex items-center justify-between",children:[k,$]}),e[35]=k,e[36]=$,e[37]=G):G=e[37];let E;e[38]!==U||e[39]!==G?(E=s.jsxs("div",{className:"mt-2.5",children:[U,G]}),e[38]=U,e[39]=G,e[40]=E):E=e[40];let J;return e[41]!==I||e[42]!==E?(J=s.jsxs("div",{className:"py-3",children:[I,E]}),e[41]=I,e[42]=E,e[43]=J):J=e[43],J};function $g(t){return t.displayMode}function Vg(t){return t.timeFormatPreference}const Bg=({providerId:t,providerName:e})=>{const{t:a}=at(),[n,i]=o.useState(null),[r,l]=o.useState({}),[u,p]=o.useState(!1),h=`/api/quota/credentials/${t}`;o.useEffect(()=>{pt(h).then(async c=>{if(!c.ok)throw new Error;const N=await c.json();i(N),l({})}).catch(()=>i({configured:!1}))},[h]);const d=async(c,N,v)=>{p(!0);try{const C=await pt(c,{method:N,headers:v?{"Content-Type":"application/json"}:void 0,body:v?JSON.stringify(v):void 0}),y=await C.json().catch(()=>null);if(!C.ok)throw new Error(y?.error);y?.configured!==void 0&&i(y),l({}),M.success(a("settings.providers.page.quotaCredentials.saved",{provider:e}))}catch(C){M.error(C instanceof Error&&C.message?C.message:a("settings.providers.page.openCodeGo.saveFailed"))}finally{p(!1)}},w=(c,N,v)=>s.jsxs("label",{className:"block typography-ui-label text-foreground",children:[N,s.jsx(Je,{className:"mt-1 h-7 font-mono text-xs",type:"password",autoComplete:"off",value:r[c]??"",onChange:C=>l(y=>({...y,[c]:C.target.value})),placeholder:n?.secretMasked??v})]});return s.jsxs("div",{"data-settings-item":`usage.${t}-credentials`,className:"mb-8",children:[s.jsx("div",{className:"mb-1 px-1",children:s.jsx("h3",{className:"typography-ui-header font-medium text-foreground",children:e})}),s.jsxs("section",{className:"space-y-3 px-2 pb-2 pt-0",children:[t==="ollama-cloud"&&w("cookie",a("settings.providers.page.openCodeGo.authCookie"),"session=..."),t==="cursor"&&w("accessToken",a("settings.providers.page.quotaCredentials.accessToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),t==="cursor"&&w("refreshToken",a("settings.providers.page.quotaCredentials.refreshToken"),a("settings.providers.page.quotaCredentials.tokenPlaceholder")),s.jsxs("div",{className:"flex flex-wrap gap-2",children:[s.jsx(B,{size:"xs",disabled:u,onClick:()=>d(h,"PUT",r),children:n?.configured?a("settings.providers.page.openCodeGo.replace"):a("settings.providers.page.openCodeGo.save")}),n?.configured&&s.jsx(B,{variant:"outline",size:"xs",disabled:u,onClick:()=>d(`${h}/validate`,"POST"),children:a("settings.providers.page.openCodeGo.validate")}),t==="cursor"&&s.jsx(B,{variant:"outline",size:"xs",disabled:u,onClick:()=>d(`${h}/import`,"POST"),children:a("settings.providers.page.actions.connect")}),n?.configured&&s.jsx(B,{variant:"destructive",size:"xs",disabled:u,onClick:()=>d(h,"DELETE"),children:a("settings.providers.page.openCodeGo.delete")})]})]})]})},Lo=(t,e)=>{if(!t)return"-";try{return bl(t,e,{fallback:"-"})}catch{return"-"}},Hg=()=>{const{t}=at(),e=de(k=>k.timeFormatPreference),a=ss(k=>k.results),n=ss(k=>k.selectedProviderId),i=ss(k=>k.setSelectedProvider),r=ss(k=>k.loadSettings),l=ss(k=>k.fetchAllQuotas),u=ss(k=>k.isLoading),p=ss(k=>k.lastUpdated),h=ss(k=>k.error),d=ss(k=>k.dropdownProviderIds),w=ss(k=>k.setDropdownProviderIds),c=ss(k=>k.selectedModels),N=ss(k=>k.toggleModelSelected),v=ss(k=>k.applyDefaultSelections);Dc(),o.useEffect(()=>{r(),l()},[r,l]),o.useEffect(()=>{if(n||a.length===0)return;const k=a.find($=>$.configured)?.providerId;i(k??fi[0]?.id??null)},[a,n,i]);const C=a.find(k=>k.providerId===n)??null,S=fi.find(k=>k.id===n)?.name??n??t("settings.usage.sidebar.title"),g=C?.usage,T=C?.configured&&!C.ok?C.error:null,R=n?d.includes(n):!1,A=n==="ollama-cloud"||n==="cursor",j=o.useCallback(k=>{if(!n)return;const $=k?Array.from(new Set([...d,n])):d.filter(G=>G!==n);w($),yt({usageDropdownProviders:$})},[d,n,w]),f=o.useMemo(()=>g?.models?Object.entries(g.models).map(([k,$])=>({name:k,windows:$})).filter(k=>Object.keys(k.windows.windows).length>0):[],[g?.models]);o.useEffect(()=>{n&&f.length>0&&v(n,f.map(k=>k.name))},[n,f,v]);const b=o.useMemo(()=>!n||f.length===0?new Map:Mc(f,k=>k.name,n),[f,n]),F=o.useMemo(()=>{if(!n)return[];const k=Oc(n);return Rc(k)},[n]),[D,P]=o.useState(()=>({})),I=o.useCallback(k=>{P($=>({...$,[k]:!$[k]}))},[]),U=o.useCallback(k=>{if(!n)return;N(n,k);const $=c[n]??[],E=$.includes(k)?$.filter(X=>X!==k):[...$,k],J={...c,[n]:E};yt({usageSelectedModels:J})},[n,c,N]),q=n?c[n]??[]:[];return n?s.jsxs(ns,{title:t("settings.usage.page.header.providerUsage",{provider:S}),titleLeading:s.jsx(Un,{providerId:n,className:"h-5 w-5 shrink-0"}),description:u?s.jsx("span",{className:"animate-pulse typography-settings-description text-muted-foreground",children:t("settings.usage.page.header.refreshing")}):C?.planLabel?t("settings.usage.page.header.lastUpdatedWithPlan",{plan:C.planLabel,time:Lo(p,e)}):t("settings.usage.page.header.lastUpdated",{time:Lo(p,e)}),showSaveStatus:!0,children:[s.jsx(_e,{divider:!1,settingsItem:"usage.work-status-panel",children:s.jsx(gt,{checked:R,onChange:j,label:t("settings.usage.page.options.showInWorkStatus"),ariaLabel:t("settings.usage.page.options.showInWorkStatusAria"),info:t("settings.usage.page.options.showInWorkStatusTooltip")})}),!C&&s.jsx("p",{className:"typography-ui-label text-foreground pb-8",children:t("settings.usage.page.state.noData")}),(h||T)&&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:h??T})]}),C&&!C.configured&&!A&&s.jsxs("div",{className:"mb-8 rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] px-4 py-3",children:[s.jsx("p",{className:"typography-ui-label font-medium text-[var(--status-warning)]",children:t("settings.usage.page.state.providerNotConfiguredTitle")}),s.jsx("p",{className:"typography-meta text-[var(--status-warning)]/80 mt-1",children:t("settings.usage.page.state.providerNotConfiguredDescription")})]}),(n==="ollama-cloud"||n==="cursor")&&s.jsx(Bg,{providerId:n,providerName:S}),g?.windows&&Object.keys(g.windows).length>0&&s.jsx(_e,{settingsItem:"usage.model-quotas",children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)]",children:Object.entries(g.windows).map(([k,$])=>s.jsx(Vi,{title:k,window:$},k))})}),f.length>0&&s.jsxs(_e,{title:t("settings.usage.page.section.modelQuotas"),contentClassName:"space-y-3",children:[F.map(k=>{const $=b.get(k.id)??[];if($.length===0)return null;const G=D[k.id]??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(bn,{open:!G,onOpenChange:()=>I(k.id),children:[s.jsxs(wn,{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:k.label}),s.jsxs("span",{className:"typography-micro text-muted-foreground",children:["(",$.length,")"]})]}),G?s.jsx(O,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(O,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(jn,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:$.map(E=>{const J=Object.entries(E.windows.windows);if(J.length===0)return null;const[X,L]=J[0],se=q.includes(E.name);return s.jsx(Vi,{title:X,subtitle:Er(E.name),window:L,showToggle:!0,toggleEnabled:se,onToggle:()=>U(E.name)},E.name)})})})]})},k.id)}),(()=>{const k=b.get(null)??[];if(k.length===0)return null;const $=D.other??!1;return s.jsx("section",{className:"p-2",children:s.jsxs(bn,{open:!$,onOpenChange:()=>I("other"),children:[s.jsxs(wn,{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:["(",k.length,")"]})]}),$?s.jsx(O,{name:"arrow-right-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"}):s.jsx(O,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground group-hover:text-foreground transition-colors"})]}),s.jsx(jn,{children:s.jsx("div",{className:"divide-y divide-[var(--surface-subtle)] mt-1",children:k.map(G=>{const E=Object.entries(G.windows.windows);if(E.length===0)return null;const[J,X]=E[0],L=q.includes(G.name);return s.jsx(Vi,{title:J,subtitle:Er(G.name),window:X,showToggle:!0,toggleEnabled:L,onToggle:()=>U(G.name)},G.name)})})})]})})})()]}),C?.configured&&g&&Object.keys(g.windows??{}).length===0&&f.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")})})},Gg="git.commit.generate",or=Al(t=>({selectedPromptId:Gg,setSelectedPromptId:e=>{t(a=>a.selectedPromptId===e?a:{selectedPromptId:e})}})),Wg=t=>{const e=mt.c(24),{onItemSelect:a}=t,{t:n}=at(),i=or(qg),r=or(Jg);let l;e[0]===Symbol.for("react.memo_cache_sentinel")?(l={groupKey:"settings.magicPrompts.sidebar.group.git",items:[{id:"git.commit.generate",titleKey:"settings.magicPrompts.sidebar.item.gitCommitGenerate"},{id:"git.pr.generate",titleKey:"settings.magicPrompts.sidebar.item.gitPrGenerate"},{id:"git.conflict.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitConflictResolve"},{id:"git.integrate.cherrypick.resolve",titleKey:"settings.magicPrompts.sidebar.item.gitCherrypickConflictResolve"}]},e[0]=l):l=e[0];let u;e[1]===Symbol.for("react.memo_cache_sentinel")?(u={groupKey:"settings.magicPrompts.sidebar.group.github",items:[{id:"github.pr.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrReview"},{id:"github.issue.review",titleKey:"settings.magicPrompts.sidebar.item.githubIssueReview"},{id:"github.pr.checks.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrFailedChecksReview"},{id:"github.pr.comments.review",titleKey:"settings.magicPrompts.sidebar.item.githubPrCommentsReview"},{id:"github.pr.comment.single",titleKey:"settings.magicPrompts.sidebar.item.githubSinglePrCommentReview"}]},e[1]=u):u=e[1];let p;e[2]===Symbol.for("react.memo_cache_sentinel")?(p={groupKey:"settings.magicPrompts.sidebar.group.linear",items:[{id:"linear.issue.review",titleKey:"settings.magicPrompts.sidebar.item.linearIssueReview"}]},e[2]=p):p=e[2];let h;e[3]===Symbol.for("react.memo_cache_sentinel")?(h={groupKey:"settings.magicPrompts.sidebar.group.planning",items:[{id:"plan.todo",titleKey:"settings.magicPrompts.sidebar.item.planTodo"},{id:"plan.improve",titleKey:"settings.magicPrompts.sidebar.item.planImprove"},{id:"plan.implement",titleKey:"settings.magicPrompts.sidebar.item.planImplement"}]},e[3]=h):h=e[3];let d;e[4]===Symbol.for("react.memo_cache_sentinel")?(d=[l,u,p,h,{groupKey:"settings.magicPrompts.sidebar.group.session",items:[{id:"session.explore",titleKey:"settings.magicPrompts.sidebar.item.sessionExplore"},{id:"session.summary",titleKey:"settings.magicPrompts.sidebar.item.sessionSummary"},{id:"session.review",titleKey:"settings.magicPrompts.sidebar.item.sessionWorkspaceReview"},{id:"session.plan",titleKey:"settings.magicPrompts.sidebar.item.sessionFeaturePlan"},{id:"session.craftGoal",titleKey:"settings.magicPrompts.sidebar.item.sessionCraftGoal"},{id:"session.catchup",titleKey:"settings.magicPrompts.sidebar.item.sessionCatchUp"},{id:"session.debug",titleKey:"settings.magicPrompts.sidebar.item.sessionDebug"},{id:"session.weigh",titleKey:"settings.magicPrompts.sidebar.item.sessionWeigh"},{id:"session.fusion",titleKey:"settings.magicPrompts.sidebar.item.sessionFusion"}]}],e[4]=d):d=e[4];const w=d;let c;e[5]!==n?(c=n("settings.magicPrompts.sidebar.title"),e[5]=n,e[6]=c):c=e[6];let N;e[7]!==c?(N=s.jsx("h2",{className:on,children:c}),e[7]=c,e[8]=N):N=e[8];let v;e[9]!==n?(v=n("settings.magicPrompts.sidebar.description"),e[9]=n,e[10]=v):v=e[10];let C;e[11]!==v?(C=s.jsx("p",{className:"typography-meta mt-1 text-muted-foreground",children:v}),e[11]=v,e[12]=C):C=e[12];let y;e[13]!==N||e[14]!==C?(y=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[N,C]}),e[13]=N,e[14]=C,e[15]=y):y=e[15];let S;e[16]!==a||e[17]!==i||e[18]!==r||e[19]!==n?(S=s.jsx(Bs,{outerClassName:"flex-1 min-h-0",className:"space-y-3 px-3 py-2 overflow-x-hidden",children:w.map(T=>s.jsxs("div",{className:"space-y-1",children:[s.jsx("div",{className:"typography-micro px-1 text-muted-foreground",children:n(T.groupKey)}),T.items.map(R=>{const A=i===R.id;return s.jsx("button",{type:"button",onClick:()=>{r(R.id),a?.()},className:we("flex w-full items-center rounded-md px-2 py-1.5 text-left transition-colors",A?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:s.jsx("span",{className:"typography-ui-label truncate font-normal",children:n(R.titleKey)})},R.id)})]},T.groupKey))}),e[16]=a,e[17]=i,e[18]=r,e[19]=n,e[20]=S):S=e[20];let g;return e[21]!==y||e[22]!==S?(g=s.jsxs("div",{className:"flex h-full flex-col bg-background",children:[y,S]}),e[21]=y,e[22]=S,e[23]=g):g=e[23],g};function qg(t){return t.selectedPromptId}function Jg(t){return t.setSelectedPromptId}const Fo={"git.commit.generate":{titleKey:"settings.magicPrompts.page.group.gitCommitGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitCommitGenerate.description",blocks:[{id:"git.commit.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.commit.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.pr.generate":{titleKey:"settings.magicPrompts.page.group.gitPrGenerate.title",descriptionKey:"settings.magicPrompts.page.group.gitPrGenerate.description",blocks:[{id:"git.pr.generate.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.pr.generate.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.review":{titleKey:"settings.magicPrompts.page.group.githubPrReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrReview.description",blocks:[{id:"github.pr.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.issue.review":{titleKey:"settings.magicPrompts.page.group.githubIssueReview.title",descriptionKey:"settings.magicPrompts.page.group.githubIssueReview.description",blocks:[{id:"github.issue.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.issue.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"linear.issue.review":{titleKey:"settings.magicPrompts.page.group.linearIssueReview.title",descriptionKey:"settings.magicPrompts.page.group.linearIssueReview.description",blocks:[{id:"linear.issue.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"linear.issue.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.checks.review":{titleKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrFailedChecksReview.description",blocks:[{id:"github.pr.checks.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.checks.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comments.review":{titleKey:"settings.magicPrompts.page.group.githubPrCommentsReview.title",descriptionKey:"settings.magicPrompts.page.group.githubPrCommentsReview.description",blocks:[{id:"github.pr.comments.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comments.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"github.pr.comment.single":{titleKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.title",descriptionKey:"settings.magicPrompts.page.group.githubSinglePrCommentReview.description",blocks:[{id:"github.pr.comment.single.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"github.pr.comment.single.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.conflict.resolve":{titleKey:"settings.magicPrompts.page.group.gitConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitConflictResolve.description",blocks:[{id:"git.conflict.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.conflict.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"git.integrate.cherrypick.resolve":{titleKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.title",descriptionKey:"settings.magicPrompts.page.group.gitCherrypickConflictResolve.description",blocks:[{id:"git.integrate.cherrypick.resolve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"git.integrate.cherrypick.resolve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.improve":{titleKey:"settings.magicPrompts.page.group.planImprove.title",descriptionKey:"settings.magicPrompts.page.group.planImprove.description",blocks:[{id:"plan.improve.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.improve.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.todo":{titleKey:"settings.magicPrompts.page.group.planTodo.title",descriptionKey:"settings.magicPrompts.page.group.planTodo.description",blocks:[{id:"plan.todo.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.todo.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"plan.implement":{titleKey:"settings.magicPrompts.page.group.planImplement.title",descriptionKey:"settings.magicPrompts.page.group.planImplement.description",blocks:[{id:"plan.implement.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"plan.implement.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.summary":{titleKey:"settings.magicPrompts.page.group.sessionSummary.title",descriptionKey:"settings.magicPrompts.page.group.sessionSummary.description",blocks:[{id:"session.summary.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.summary.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.review":{titleKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.title",descriptionKey:"settings.magicPrompts.page.group.sessionWorkspaceReview.description",blocks:[{id:"session.review.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.review.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.plan":{titleKey:"settings.magicPrompts.page.group.sessionFeaturePlan.title",descriptionKey:"settings.magicPrompts.page.group.sessionFeaturePlan.description",blocks:[{id:"session.plan.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.plan.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.craftGoal":{titleKey:"settings.magicPrompts.page.group.sessionCraftGoal.title",descriptionKey:"settings.magicPrompts.page.group.sessionCraftGoal.description",blocks:[{id:"session.craftGoal.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.craftGoal.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.catchup":{titleKey:"settings.magicPrompts.page.group.sessionCatchUp.title",descriptionKey:"settings.magicPrompts.page.group.sessionCatchUp.description",blocks:[{id:"session.catchup.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.catchup.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.debug":{titleKey:"settings.magicPrompts.page.group.sessionDebug.title",descriptionKey:"settings.magicPrompts.page.group.sessionDebug.description",blocks:[{id:"session.debug.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.debug.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.weigh":{titleKey:"settings.magicPrompts.page.group.sessionWeigh.title",descriptionKey:"settings.magicPrompts.page.group.sessionWeigh.description",blocks:[{id:"session.weigh.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.weigh.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.explore":{titleKey:"settings.magicPrompts.page.group.sessionExplore.title",descriptionKey:"settings.magicPrompts.page.group.sessionExplore.description",blocks:[{id:"session.explore.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.explore.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]},"session.fusion":{titleKey:"settings.magicPrompts.page.group.sessionFusion.title",descriptionKey:"settings.magicPrompts.page.group.sessionFusion.description",blocks:[{id:"session.fusion.visible",titleKey:"settings.magicPrompts.page.block.visiblePrompt"},{id:"session.fusion.instructions",titleKey:"settings.magicPrompts.page.block.instructions"}]}},Ko=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),Bi=t=>t.endsWith(".visible"),Qg=()=>{const{t}=at(),e=o.useCallback(j=>t(j),[t]),a=or(j=>j.selectedPromptId),[n,i]=o.useState(!0),[r,l]=o.useState({}),[u,p]=o.useState({}),[h,d]=o.useState({}),[w,c]=o.useState({}),[N,v]=o.useState(!1);o.useEffect(()=>{let j=!0;return(async()=>{i(!0);try{const b=await zc();if(!j)return;l(b)}catch(b){console.warn("Failed to load magic prompts:",b),M.error(t("settings.magicPrompts.page.toast.loadFailed"))}finally{j&&i(!1)}})(),()=>{j=!1}},[t]);const C=Fo[a]??Fo["git.commit.generate"],y=o.useCallback(j=>Ko(r,j)?r[j]:Mi(j),[r]),S=o.useCallback(j=>u[j]??y(j),[u,y]),g=o.useCallback((j,f)=>{p(b=>b[j]===f?b:{...b,[j]:f})},[]),T=o.useCallback(async j=>{const f=S(j);if(Bi(j)&&f.trim().length===0){M.error(t("settings.magicPrompts.page.toast.visiblePromptRequired"));return}d(b=>({...b,[j]:!0}));try{const b=f===Mi(j)?await Dr(j):await Lc(j,f);l(b.overrides),M.success(t("settings.magicPrompts.page.toast.saved"))}catch(b){const F=b instanceof Error?b.message:String(b);M.error(t("settings.magicPrompts.page.toast.saveFailed"),{description:F})}finally{d(b=>({...b,[j]:!1}))}},[S,t]),R=o.useCallback(async j=>{c(f=>({...f,[j]:!0}));try{const f=await Dr(j);l(f.overrides),p(b=>({...b,[j]:Mi(j)})),M.success(t("settings.magicPrompts.page.toast.resetSuccess"))}catch(f){const b=f instanceof Error?f.message:String(f);M.error(t("settings.magicPrompts.page.toast.resetFailed"),{description:b})}finally{c(f=>({...f,[j]:!1}))}},[t]),A=o.useCallback(async()=>{v(!0);try{const j=await Fc();l(j.overrides),p({}),M.success(t("settings.magicPrompts.page.toast.resetAllSuccess"))}catch(j){const f=j instanceof Error?j.message:String(j);M.error(t("settings.magicPrompts.page.toast.resetAllFailed"),{description:f})}finally{v(!1)}},[t]);return n?s.jsxs("div",{className:"py-6 px-6 flex items-center gap-2 text-muted-foreground",children:[s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.magicPrompts.page.loading.aria")}),s.jsx("span",{className:"typography-ui",children:t("settings.magicPrompts.page.loading.text")})]}):s.jsx(ns,{title:e(C.titleKey),titleAccessory:s.jsx(Jt,{contentClassName:"max-w-xs",children:e(C.descriptionKey)}),headerEnd:s.jsx(B,{"data-settings-item":"magic-prompts.reset-overrides",variant:"outline",size:"sm",onClick:()=>{A()},disabled:N||Object.keys(r).length===0,children:t(N?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetAllOverrides")}),showSaveStatus:!1,children:C.blocks.map((j,f)=>{const b=Kc(j.id),F=y(j.id),D=S(j.id),P=Ko(r,j.id),I=D!==F,U=Bi(j.id)&&D.trim().length===0,q=h[j.id]===!0,k=w[j.id]===!0;return s.jsxs(_e,{title:e(j.titleKey),info:b.description,description:b.placeholders&&b.placeholders.length>0?`${t("settings.magicPrompts.page.placeholdersLabel")} ${b.placeholders.map($=>`{{${$.key}}}`).join(", ")}`:void 0,divider:f>0,settingsItem:Bi(j.id)?"magic-prompts.visible-prompt":"magic-prompts.instructions",contentClassName:"space-y-3",children:[s.jsx(Is,{value:D,onChange:$=>g(j.id,$.target.value),className:"min-h-[220px] font-mono text-sm"}),U&&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(I?"settings.magicPrompts.page.status.unsavedChanges":P?"settings.magicPrompts.page.status.usingSavedOverride":"settings.magicPrompts.page.status.usingBuiltinDefault")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(B,{variant:"outline",size:"sm",onClick:()=>{R(j.id)},disabled:!P||q||k,children:t(k?"settings.magicPrompts.page.actions.resetting":"settings.magicPrompts.page.actions.resetToDefault")}),s.jsx(B,{size:"sm",onClick:()=>{T(j.id)},disabled:!I||q||k||U,children:t(q?"settings.common.actions.saving":"settings.magicPrompts.page.actions.save")})]})]})]},j.id)})})},Yg=t=>{const e=mt.c(89),{onItemSelect:a}=t,{t:n}=at(),[i,r]=o.useState(null),[l,u]=o.useState(null),[p,h]=o.useState(null),{selectedSnippetName:d,snippets:w,setSelectedSnippet:c,setSnippetDraft:N,deleteSnippet:v,loadSnippets:C}=hi(Ds(Zg));let y,S;e[0]!==C?(y=()=>{C()},S=[C],e[0]=C,e[1]=y,e[2]=S):(y=e[1],S=e[2]),o.useEffect(y,S);let g;e[3]!==a||e[4]!==c||e[5]!==N||e[6]!==w?(g=async()=>{const Ne=new Set(w.map(Xg));let Se="new-snippet",be=1;for(;Ne.has(Se);)Se=`new-snippet-${be++}`;N({name:Se,scope:"global"}),c(Se),a?.()},e[3]=a,e[4]=c,e[5]=N,e[6]=w,e[7]=g):g=e[7];const T=g;let R;e[8]!==i||e[9]!==v||e[10]!==n?(R=async()=>{if(!i)return;await v(i.name)?(M.success(n("settings.snippets.sidebar.toast.deleted")),r(null)):M.error(n("settings.snippets.sidebar.toast.deleteFailed"))},e[8]=i,e[9]=v,e[10]=n,e[11]=R):R=e[11];const A=R;let j;e[12]!==w?(j=[...w].sort(ef),e[12]=w,e[13]=j):j=e[13];const f=j;let b;e[14]===Symbol.for("react.memo_cache_sentinel")?(b=we("flex h-full flex-col","bg-background"),e[14]=b):b=e[14];let F;e[15]!==n?(F=n("settings.snippets.sidebar.title"),e[15]=n,e[16]=F):F=e[16];let D;e[17]!==F?(D=s.jsx("h2",{className:`${on} mb-3`,children:F}),e[17]=F,e[18]=D):D=e[18];let P;e[19]!==w.length||e[20]!==n?(P=n("settings.snippets.sidebar.total",{count:w.length}),e[19]=w.length,e[20]=n,e[21]=P):P=e[21];let I;e[22]!==P?(I=s.jsx("span",{className:"typography-meta text-muted-foreground",children:P}),e[22]=P,e[23]=I):I=e[23];let U;e[24]!==n?(U=n("settings.snippets.sidebar.actions.create"),e[24]=n,e[25]=U):U=e[25];let q;e[26]===Symbol.for("react.memo_cache_sentinel")?(q=s.jsx(O,{name:"add",className:"h-3.5 w-3.5"}),e[26]=q):q=e[26];let k;e[27]!==T||e[28]!==U?(k=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:T,"aria-label":U,children:q}),e[27]=T,e[28]=U,e[29]=k):k=e[29];let $;e[30]!==I||e[31]!==k?($=s.jsxs("div",{className:"flex items-center justify-between gap-2",children:[I,k]}),e[30]=I,e[31]=k,e[32]=$):$=e[32];let G;e[33]!==$||e[34]!==D?(G=s.jsxs("div",{className:"border-b px-3 pt-4 pb-3",children:[D,$]}),e[33]=$,e[34]=D,e[35]=G):G=e[35];let E;if(e[36]!==a||e[37]!==l||e[38]!==p||e[39]!==d||e[40]!==c||e[41]!==f||e[42]!==n){let Ne;e[44]!==a||e[45]!==l||e[46]!==p||e[47]!==d||e[48]!==c||e[49]!==n?(Ne=Se=>s.jsxs(Jn,{open:p===Se.name,onOpenChange:be=>h(be?Se.name:null),children:[s.jsxs(qn,{render:s.jsx("div",{className:we("group relative flex items-center rounded-md px-1.5 py-1 transition-all duration-200 select-none",d===Se.name?"bg-interactive-selection":"hover:bg-interactive-hover"),onContextMenu:be=>{be.preventDefault(),h(Se.name)}}),children:[s.jsxs("button",{onClick:()=>{c(Se.name),a?.()},className:"flex min-w-0 flex-1 flex-col gap-0 rounded-sm text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsxs("span",{className:"typography-ui-label font-normal truncate text-foreground",children:["#",Se.name]}),s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:n(`snippets.source.${Se.source}`)})]}),s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:Se.description||Se.content.replace(/\s+/g," ").substring(0,80)})]}),s.jsxs(an,{open:l===Se.name,onOpenChange:be=>{be&&h(null),u(be?Se.name:null)},children:[s.jsx(sn,{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":n("settings.snippets.sidebar.actions.more",{name:Se.name}),children:s.jsx(O,{name:"more-2",className:"h-3.5 w-3.5"})})}),s.jsx(nn,{align:"end",className:"w-fit min-w-20",children:s.jsxs(rn,{onClick:be=>{be.stopPropagation(),r(Se)},className:"text-destructive focus:text-destructive",children:[s.jsx(O,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]})]}),s.jsx(Gn,{className:"w-fit min-w-20",children:s.jsxs(Wn,{onClick:be=>{be.stopPropagation(),r(Se)},className:"text-destructive focus:text-destructive",children:[s.jsx(O,{name:"delete-bin",className:"h-4 w-4 mr-px"}),n("settings.common.actions.delete")]})})]},`${Se.source}:${Se.filePath}`),e[44]=a,e[45]=l,e[46]=p,e[47]=d,e[48]=c,e[49]=n,e[50]=Ne):Ne=e[50],E=f.map(Ne),e[36]=a,e[37]=l,e[38]=p,e[39]=d,e[40]=c,e[41]=f,e[42]=n,e[43]=E}else E=e[43];let J;e[51]!==E?(J=s.jsx(Bs,{outerClassName:"flex-1 min-h-0",className:"space-y-1 px-3 py-2",children:E}),e[51]=E,e[52]=J):J=e[52];const X=i!==null;let L;e[53]===Symbol.for("react.memo_cache_sentinel")?(L=Ne=>{Ne||r(null)},e[53]=L):L=e[53];let se;e[54]!==n?(se=n("settings.snippets.sidebar.dialog.deleteTitle"),e[54]=n,e[55]=se):se=e[55];let z;e[56]!==se?(z=s.jsx(_t,{children:se}),e[56]=se,e[57]=z):z=e[57];const V=i?.name??"";let _;e[58]!==n||e[59]!==V?(_=n("settings.snippets.sidebar.dialog.deleteDescription",{name:V}),e[58]=n,e[59]=V,e[60]=_):_=e[60];let K;e[61]!==_?(K=s.jsx($t,{children:_}),e[61]=_,e[62]=K):K=e[62];let Z;e[63]!==z||e[64]!==K?(Z=s.jsxs(Ut,{children:[z,K]}),e[63]=z,e[64]=K,e[65]=Z):Z=e[65];let Y;e[66]===Symbol.for("react.memo_cache_sentinel")?(Y=()=>r(null),e[66]=Y):Y=e[66];let te;e[67]!==n?(te=n("settings.common.actions.cancel"),e[67]=n,e[68]=te):te=e[68];let ge;e[69]!==te?(ge=s.jsx(B,{size:"sm",variant:"ghost",onClick:Y,children:te}),e[69]=te,e[70]=ge):ge=e[70];let le;e[71]!==n?(le=n("settings.common.actions.delete"),e[71]=n,e[72]=le):le=e[72];let he;e[73]!==A||e[74]!==le?(he=s.jsx(B,{size:"sm",onClick:A,children:le}),e[73]=A,e[74]=le,e[75]=he):he=e[75];let ne;e[76]!==ge||e[77]!==he?(ne=s.jsxs(es,{children:[ge,he]}),e[76]=ge,e[77]=he,e[78]=ne):ne=e[78];let ae;e[79]!==Z||e[80]!==ne?(ae=s.jsxs(Kt,{className:"max-w-md",children:[Z,ne]}),e[79]=Z,e[80]=ne,e[81]=ae):ae=e[81];let me;e[82]!==X||e[83]!==ae?(me=s.jsx(Ft,{open:X,onOpenChange:L,children:ae}),e[82]=X,e[83]=ae,e[84]=me):me=e[84];let Pe;return e[85]!==G||e[86]!==J||e[87]!==me?(Pe=s.jsxs("div",{className:b,children:[G,J,me]}),e[85]=G,e[86]=J,e[87]=me,e[88]=Pe):Pe=e[88],Pe};function Zg(t){return{selectedSnippetName:t.selectedSnippetName,snippets:t.snippets,setSelectedSnippet:t.setSelectedSnippet,setSnippetDraft:t.setSnippetDraft,deleteSnippet:t.deleteSnippet,loadSnippets:t.loadSnippets}}function Xg(t){return t.name}function ef(t,e){return t.name.localeCompare(e.name)}const tf=()=>{const{t}=at(),{selectedSnippetName:e,snippets:a,snippetDraft:n,setSnippetDraft:i,updateSnippet:r,createSnippet:l}=hi(Ds(b=>({selectedSnippetName:b.selectedSnippetName,snippets:b.snippets,snippetDraft:b.snippetDraft,setSnippetDraft:b.setSnippetDraft,updateSnippet:b.updateSnippet,createSnippet:b.createSnippet}))),u=o.useMemo(()=>e?a.find(b=>b.name===e||b.aliases.includes(e))??null:null,[e,a]),p=!!(n&&n.name===e&&!u),[h,d]=o.useState(""),[w,c]=o.useState("global"),[N,v]=o.useState(""),[C,y]=o.useState(""),[S,g]=o.useState(""),[T,R]=o.useState(!1),A=o.useRef(null);o.useEffect(()=>{if(p&&n){const b={draftName:n.name||"",draftScope:n.scope||"global",description:n.description||"",aliases:(n.aliases||[]).join(", "),content:n.content||""};d(b.draftName),c(b.draftScope),v(b.description),y(b.aliases),g(b.content),A.current=b}else if(u){const b={draftName:"",draftScope:"global",description:u.description??"",aliases:u.aliases.join(", "),content:u.content};v(b.description),y(b.aliases),g(b.content),A.current=b}},[u,p,e,n]);const j=o.useMemo(()=>{const b=A.current;return b?p&&h!==b.draftName||p&&w!==b.draftScope?!0:N!==b.description||C!==b.aliases||S!==b.content:!1},[C,S,N,h,w,p]),f=async()=>{const b=p?h.trim().replace(/\s+/g,"-"):e?.trim();if(!b){M.error(t("settings.snippets.page.toast.nameRequired"));return}if(!S.trim()){M.error(t("settings.snippets.page.toast.contentRequired"));return}const F=C.split(",").map(D=>D.trim()).filter(Boolean);R(!0);try{if(!(p?await l(b,S,{aliases:F,description:N,scope:w}):await r(b,{content:S,aliases:F,description:N}))){M.error(t("settings.snippets.page.toast.saveFailed"));return}M.success(t("settings.snippets.page.toast.saved")),p&&i(null)}finally{R(!1)}};return e?s.jsxs(ns,{title:p?t("settings.snippets.page.title.new"):`#${e}`,description:u?u.filePath:void 0,showSaveStatus:!1,children:[s.jsxs(_e,{divider:!1,contentClassName:"space-y-0",children:[p?s.jsxs(Ot,{label:"#",children:[s.jsx(Je,{value:h,onChange:b=>d(b.target.value),placeholder:t("settings.snippets.page.field.namePlaceholder"),className:"h-7 w-44 px-2"}),s.jsxs(Pt,{value:w,onValueChange:b=>c(b),children:[s.jsx(It,{size:Lt,className:"w-fit min-w-[100px]",children:s.jsx(Rt,{})}),s.jsxs(At,{align:"end",children:[s.jsx(ot,{value:"global",children:t("settings.common.scope.global")}),s.jsx(ot,{value:"project",children:t("settings.common.scope.project")})]})]})]}):null,s.jsx(qt,{label:t("settings.common.field.description"),children:s.jsx(Je,{value:N,onChange:b=>v(b.target.value),placeholder:t("settings.snippets.page.field.descriptionPlaceholder"),className:"h-7 w-full max-w-sm px-2"})}),s.jsx(qt,{label:t("settings.snippets.page.field.aliases"),children:s.jsx(Je,{value:C,onChange:b=>y(b.target.value),placeholder:t("settings.snippets.page.field.aliasesPlaceholder"),className:"h-7 w-full max-w-sm px-2"})})]}),s.jsxs(_e,{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(Jt,{children:t("settings.snippets.page.hint")})]}),s.jsx(Is,{value:S,onChange:b=>g(b.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:f,disabled:T||!j,size:"xs",className:"!font-normal",children:t(T?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]}):s.jsx("div",{className:"flex h-full items-center justify-center",children:s.jsxs("div",{className:"text-center text-muted-foreground",children:[s.jsx(O,{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")})]})})},Hl=()=>{const{t}=at(),e=Ze(w=>w.settingsGitmojiEnabled),a=Ze(w=>w.setSettingsGitmojiEnabled),n=vd(),i=de(w=>w.gitChangesViewMode),r=de(w=>w.setGitChangesViewMode),[l,u]=o.useState(!0),p=o.useMemo(()=>[{id:"flat",label:t("settings.aiworker.git.option.flatList")},{id:"tree",label:t("settings.aiworker.git.option.treeView")}],[t]);o.useEffect(()=>{(async()=>{try{let c=null;if(!c){const N=tn()?.settings;if(N)try{const C=(await N.load())?.settings;C&&(c={gitmojiEnabled:typeof C.gitmojiEnabled=="boolean"?C.gitmojiEnabled:void 0,gitChangesViewMode:C.gitChangesViewMode==="flat"||C.gitChangesViewMode==="tree"?C.gitChangesViewMode:void 0})}catch{}}if(!c){const N=await pt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});N.ok&&(c=await N.json())}c&&(typeof c.gitmojiEnabled=="boolean"&&a(c.gitmojiEnabled),(c.gitChangesViewMode==="flat"||c.gitChangesViewMode==="tree")&&r(c.gitChangesViewMode))}catch(c){console.warn("Failed to load git settings:",c)}finally{u(!1)}})()},[r,a]);const h=o.useCallback(async w=>{a(w);try{await yt({gitmojiEnabled:w})}catch(c){console.warn("Failed to save gitmoji setting:",c)}},[a]),d=o.useCallback(w=>{w!==i&&(r(w),yt({gitChangesViewMode:w}))},[i,r]);return l?null:s.jsx(_e,{title:t("settings.aiworker.git.title"),children:s.jsxs("div",{className:hs,children:[s.jsx(Ls,{settingsItem:"git.changes-view",title:t("settings.aiworker.git.changesViewTitle"),children:s.jsx(mn,{"aria-label":t("settings.aiworker.git.changesViewAria"),children:p.map(w=>s.jsx(gn,{selected:i===w.id,onSelect:()=>{d(w.id)},label:w.label,ariaLabel:t("settings.aiworker.git.optionAria",{option:w.label})},w.id))})}),s.jsx(gt,{settingsItem:"git.gitmoji",checked:e,onChange:w=>{h(w)},label:t("settings.aiworker.git.enableGitmoji"),ariaLabel:t("settings.aiworker.git.enableGitmojiAria")}),s.jsx(gt,{settingsItem:"git.gitignored-files",checked:n,onChange:yd,label:t("settings.aiworker.git.showGitignored"),ariaLabel:t("settings.aiworker.git.showGitignoredAria")})]})})},zo=[{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)"}],sf=[{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"}],nf=({open:t,onOpenChange:e,profileId:a,importData:n})=>{const{t:i}=at(),r=_n(K=>K.getProfileById),l=_n(K=>K.createProfile),u=_n(K=>K.updateProfile),p=_n(K=>K.deleteProfile),h=o.useMemo(()=>a&&a!=="new"&&!n?r(a):null,[a,r,n]),d=a==="new"||n!=null,w=a==="global",[c,N]=o.useState(""),[v,C]=o.useState(""),[y,S]=o.useState(""),[g,T]=o.useState("ssh"),[R,A]=o.useState(""),[j,f]=o.useState(!1),[b,F]=o.useState(""),[D,P]=o.useState(""),[I,U]=o.useState("keyword"),[q,k]=o.useState("branch"),[$,G]=o.useState(!1),[E,J]=o.useState(!1),[X,L]=o.useState(!1);o.useEffect(()=>{if(t){if(n){const K=n.host.split("/"),Z=K.length>=3?K[K.length-1]:n.host;N(Z),C(n.username),S(""),T("token"),A(""),f(!1),F(""),P(n.host),U("string"),k("code")}else if(d)N(""),C(""),S(""),T("ssh"),A(""),f(!1),F(""),P(""),U("keyword"),k("branch");else if(h)N(h.name),C(h.userName),S(h.userEmail),T(h.authType||"ssh"),A(h.sshKey||""),f(h.signCommits===!0),F(h.signingKey||""),P(h.host||""),U(h.color||"keyword"),k(h.icon||"branch");else if(w){const K=r("global");K&&(N(K.name),C(K.userName),S(K.userEmail),T(K.authType||"ssh"),A(K.sshKey||""),f(!1),F(""),P(K.host||""),U(K.color||"keyword"),k(K.icon||"branch"))}}},[t,a,h,d,n,w,r]);const se=async()=>{if(!v.trim()||!y.trim()){M.error(i("settings.gitIdentities.editor.toast.userNameEmailRequired"));return}if(g==="token"&&!D.trim()){M.error(i("settings.gitIdentities.editor.toast.hostRequiredForToken"));return}if(j&&!b.trim()){M.error(i("settings.gitIdentities.editor.toast.signingKeyRequired"));return}G(!0);try{const K={name:c.trim()||v.trim(),userName:v.trim(),userEmail:y.trim(),authType:g,sshKey:g==="ssh"&&R.trim()||null,signCommits:j,signingKey:b.trim()||null,host:g==="token"&&D.trim()||null,color:I,icon:q};let Z;if(d)Z=await l(K);else if(a)Z=await u(a,K);else return;Z?(M.success(i(d?"settings.gitIdentities.editor.toast.profileCreated":"settings.gitIdentities.editor.toast.profileUpdated")),e(!1)):M.error(i(d?"settings.gitIdentities.editor.toast.createProfileFailed":"settings.gitIdentities.editor.toast.updateProfileFailed"))}catch(K){console.error("Error saving profile:",K),M.error(i("settings.gitIdentities.editor.toast.saveUnexpectedError"))}finally{G(!1)}},z=async()=>{if(!(!a||d)){L(!0);try{await p(a)?(M.success(i("settings.gitIdentities.editor.toast.profileDeleted")),J(!1),e(!1)):M.error(i("settings.gitIdentities.editor.toast.deleteProfileFailed"))}catch(K){console.error("Error deleting profile:",K),M.error(i("settings.gitIdentities.editor.toast.deleteUnexpectedError"))}finally{L(!1)}}},V=o.useMemo(()=>zo.find(Z=>Z.key===I)?.cssVar||"var(--syntax-keyword)",[I]),_=n?i("settings.gitIdentities.editor.title.importCredential"):d?i("settings.gitIdentities.editor.title.newIdentity"):w?i("settings.gitIdentities.editor.title.globalIdentity"):h?.name||i("settings.gitIdentities.editor.title.editIdentity");return s.jsxs(s.Fragment,{children:[s.jsx(Ft,{open:t,onOpenChange:e,children:s.jsxs(Kt,{className:"max-w-lg max-h-[85vh] overflow-y-auto",children:[s.jsxs(Ut,{children:[s.jsx(_t,{children:_}),s.jsx($t,{children:i(w?"settings.gitIdentities.editor.description.globalReadOnly":d?"settings.gitIdentities.editor.description.newProfile":"settings.gitIdentities.editor.description.editProfile")})]}),s.jsxs("div",{className:"space-y-5 py-2",children:[!w&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{children:[s.jsx("label",{className:`${Et} block mb-1.5`,children:i("settings.gitIdentities.editor.field.profileName")}),s.jsx(Je,{value:c,onChange:K=>N(K.target.value),placeholder:i("settings.gitIdentities.editor.field.profileNamePlaceholder"),className:"h-8"})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.color")}),s.jsx("div",{className:"flex gap-1.5",children:zo.map(K=>s.jsx("button",{type:"button",onClick:()=>U(K.key),className:we("w-6 h-6 rounded-md border-2 transition-all cursor-pointer",I===K.key?"border-foreground scale-110":"border-transparent hover:border-border"),style:{backgroundColor:K.cssVar},title:K.label},K.key))})]}),s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.icon")}),s.jsx("div",{className:"flex gap-1.5",children:sf.map(K=>{const Z=K.Icon;return s.jsx("button",{type:"button",onClick:()=>k(K.key),className:we("w-7 h-7 rounded-md border-2 transition-all flex items-center justify-center cursor-pointer",q===K.key?"border-[var(--interactive-border)] bg-[var(--surface-muted)]":"border-transparent hover:border-[var(--interactive-border)] hover:bg-[var(--surface-muted)]/50"),title:K.label,children:s.jsx(O,{name:Z,className:"w-3.5 h-3.5",style:{color:q===K.key?V:"var(--surface-muted-foreground)"}})},K.key)})})]})]}),!w&&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:Et,children:i("settings.gitIdentities.editor.field.userName")}),!w&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Jt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.userNameTooltip")})]}),s.jsx(Je,{value:v,onChange:K=>C(K.target.value),placeholder:i("settings.gitIdentities.editor.field.userNamePlaceholder"),required:!w,readOnly:w,disabled:w,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:Et,children:i("settings.gitIdentities.editor.field.emailAddress")}),!w&&s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Jt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.emailAddressTooltip")})]}),s.jsx(Je,{type:"email",value:y,onChange:K=>S(K.target.value),placeholder:i("settings.gitIdentities.editor.field.emailAddressPlaceholder"),required:!w,readOnly:w,disabled:w,className:"h-8"})]})]}),!w&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"border-t border-border/40"}),s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center justify-between gap-4",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:i("settings.gitIdentities.editor.field.authMethod")}),s.jsxs("div",{className:"flex items-center gap-1",children:[s.jsxs(B,{size:"sm",type:"button",variant:"chip","aria-pressed":g==="ssh",onClick:()=>T("ssh"),children:[s.jsx(O,{name:"lock-2",className:"w-3.5 h-3.5 mr-1"})," SSH"]}),s.jsxs(B,{size:"sm",type:"button",variant:"chip","aria-pressed":g==="token",onClick:()=>T("token"),children:[s.jsx(O,{name:"key",className:"w-3.5 h-3.5 mr-1"})," ",i("settings.gitIdentities.editor.field.authToken")]})]})]}),g==="ssh"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Et,children:i("settings.gitIdentities.editor.field.sshKeyPath")}),s.jsx(Jt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.sshKeyPathTooltip")})]}),s.jsx(Je,{value:R,onChange:K=>A(K.target.value),placeholder:i("settings.gitIdentities.editor.field.sshKeyPathPlaceholder"),className:"h-8 font-mono text-xs"})]}),s.jsxs("div",{className:"border-t border-border/40 pt-3 space-y-3",children:[s.jsx(gt,{checked:j,onChange:f,label:i("settings.gitIdentities.editor.field.signCommits"),info:i("settings.gitIdentities.editor.section.commitSigning"),ariaLabel:i("settings.gitIdentities.editor.field.signCommits")}),s.jsxs("div",{children:[s.jsx("div",{className:"flex items-center gap-1.5 mb-1.5",children:s.jsx("label",{className:Et,children:i("settings.gitIdentities.editor.field.signingKey")})}),s.jsx(Je,{value:b,onChange:K=>F(K.target.value),placeholder:i("settings.gitIdentities.editor.field.signingKeyPlaceholder"),disabled:!j,className:"h-8 font-mono text-xs"})]})]}),g==="token"&&s.jsxs("div",{children:[s.jsxs("div",{className:"flex items-center gap-1.5 mb-1.5",children:[s.jsx("label",{className:Et,children:i("settings.gitIdentities.editor.field.host")}),s.jsx("span",{className:"text-[var(--status-error)] text-xs",children:"*"}),s.jsx(Jt,{contentClassName:"max-w-xs",children:i("settings.gitIdentities.editor.field.hostTooltip")})]}),s.jsx(Je,{value:D,onChange:K=>P(K.target.value),placeholder:i("settings.gitIdentities.editor.field.hostPlaceholder"),required:!0,className:"h-8 font-mono text-xs"})]})]})]})]}),s.jsxs(es,{className:"gap-2",children:[!w&&!d&&s.jsxs(B,{variant:"outline",size:"sm",onClick:()=>J(!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(O,{name:"delete-bin",className:"w-3.5 h-3.5 mr-1"})," ",i("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:i(w?"settings.gitIdentities.editor.actions.close":"settings.common.actions.cancel")}),!w&&s.jsx(B,{size:"sm",onClick:se,disabled:$,children:i($?"settings.common.actions.saving":d?"settings.gitIdentities.editor.actions.create":"settings.gitIdentities.editor.actions.save")})]})]})}),s.jsx(Ft,{open:E,onOpenChange:K=>{X||J(K)},children:s.jsxs(Kt,{className:"max-w-md",children:[s.jsxs(Ut,{children:[s.jsx(_t,{children:i("settings.gitIdentities.page.deleteDialog.title")}),s.jsx($t,{children:i("settings.gitIdentities.page.deleteDialog.description",{name:h?.name||c})})]}),s.jsxs(es,{children:[s.jsx(B,{variant:"ghost",onClick:()=>J(!1),disabled:X,children:i("settings.common.actions.cancel")}),s.jsx(B,{size:"sm",variant:"destructive",onClick:()=>{z()},disabled:X,children:i("settings.common.actions.delete")})]})]})})]})},af={branch:"git-branch",briefcase:"briefcase",house:"home",graduation:"graduation-cap",code:"code",heart:"heart"},rf={keyword:"var(--syntax-keyword)",error:"var(--status-error)",string:"var(--syntax-string)",function:"var(--syntax-function)",type:"var(--syntax-type)"},of=()=>{const t=mt.c(112),{t:e}=at(),{profiles:a,globalIdentity:n,defaultGitIdentityId:i,deleteProfile:r,loadProfiles:l,loadGlobalIdentity:u,loadDiscoveredCredentials:p,loadDefaultGitIdentityId:h,setDefaultGitIdentityId:d,getUnimportedCredentials:w}=_n(Ds(cf)),[c,N]=o.useState(!1),[v,C]=o.useState(null),[y,S]=o.useState(null),[g,T]=o.useState(null),[R,A]=o.useState(!1);let j,f;t[0]!==h||t[1]!==p||t[2]!==u||t[3]!==l?(j=()=>{l(),u(),p(),h()},f=[l,u,p,h],t[0]=h,t[1]=p,t[2]=u,t[3]=l,t[4]=j,t[5]=f):(j=t[4],f=t[5]),o.useEffect(j,f);let b,F,D,P,I,U,q,k,$,G,E,J,X,L;if(t[6]!==i||t[7]!==g||t[8]!==r||t[9]!==w||t[10]!==n||t[11]!==a||t[12]!==d||t[13]!==e){const Ve=w();let $e;t[28]===Symbol.for("react.memo_cache_sentinel")?($e=(Ae,ye)=>{C(Ae),S(ye??null),N(!0)},t[28]=$e):$e=t[28];const We=$e;let Fe;t[29]!==i||t[30]!==d||t[31]!==e?(Fe=async Ae=>{const ye=i===Ae?null:Ae;if(!await d(ye)){M.error(e("settings.gitIdentities.page.toast.updateDefaultFailed"));return}M.success(e(ye?"settings.gitIdentities.page.toast.defaultUpdated":"settings.gitIdentities.page.toast.defaultUnset"))},t[29]=i,t[30]=d,t[31]=e,t[32]=Fe):Fe=t[32];const ie=Fe;let re;t[33]!==g||t[34]!==r||t[35]!==e?(re=async()=>{if(!g)return;A(!0),await r(g.id)?(M.success(e("settings.gitIdentities.page.toast.profileDeleted",{name:g.name})),T(null)):M.error(e("settings.gitIdentities.page.toast.deleteProfileFailed")),A(!1)},t[33]=g,t[34]=r,t[35]=e,t[36]=re):re=t[36],D=re,F=ns,t[37]!==e?(I=e("settings.page.git.title"),t[37]=e,t[38]=I):I=t[38],U=!0,b=_e,t[39]!==e?(J=e("settings.gitIdentities.page.section.title"),t[39]=e,t[40]=J):J=t[40],X=!1;let je,ve;t[41]===Symbol.for("react.memo_cache_sentinel")?(je=()=>We("new"),ve=s.jsx(O,{name:"add",className:"w-3.5 h-3.5 mr-1"}),t[41]=je,t[42]=ve):(je=t[41],ve=t[42]);let Re;t[43]!==e?(Re=e("settings.common.badge.new"),t[43]=e,t[44]=Re):Re=t[44],t[45]!==Re?(L=s.jsxs(B,{size:"sm",variant:"outline",onClick:je,children:[ve," ",Re]}),t[45]=Re,t[46]=L):L=t[46],P="git.identities",q="rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",k=n&&s.jsx(Uo,{profile:n,isDefault:i==="global",onEdit:()=>We("global"),onToggleDefault:()=>ie("global"),isReadOnly:!0,hasBorder:a.length>0||Ve.length>0}),$=a.map((Ae,ye)=>s.jsx(Uo,{profile:Ae,isDefault:i===Ae.id,onEdit:()=>We(Ae.id),onToggleDefault:()=>ie(Ae.id),onDelete:()=>T(Ae),hasBorder:ye<a.length-1||Ve.length>0},Ae.id)),G=!n&&a.length===0&&Ve.length===0&&s.jsxs("div",{className:"py-8 px-4 text-center text-muted-foreground",children:[s.jsx(O,{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")})]}),E=Ve.length>0&&s.jsxs(s.Fragment,{children:[s.jsx("div",{className:"px-4 py-2 border-t border-[var(--surface-subtle)]",children:s.jsx("span",{className:"typography-micro text-muted-foreground",children:e("settings.gitIdentities.page.discoveredCredentials.title")})}),Ve.map((Ae,ye)=>s.jsx(lf,{credential:Ae,onImport:()=>We("new",{host:Ae.host,username:Ae.username}),hasBorder:ye<Ve.length-1},`${Ae.host}-${Ae.username}`))]}),t[6]=i,t[7]=g,t[8]=r,t[9]=w,t[10]=n,t[11]=a,t[12]=d,t[13]=e,t[14]=b,t[15]=F,t[16]=D,t[17]=P,t[18]=I,t[19]=U,t[20]=q,t[21]=k,t[22]=$,t[23]=G,t[24]=E,t[25]=J,t[26]=X,t[27]=L}else b=t[14],F=t[15],D=t[16],P=t[17],I=t[18],U=t[19],q=t[20],k=t[21],$=t[22],G=t[23],E=t[24],J=t[25],X=t[26],L=t[27];let se;t[47]!==q||t[48]!==k||t[49]!==$||t[50]!==G||t[51]!==E?(se=s.jsxs("div",{className:q,children:[k,$,G,E]}),t[47]=q,t[48]=k,t[49]=$,t[50]=G,t[51]=E,t[52]=se):se=t[52];let z;t[53]!==b||t[54]!==P||t[55]!==se||t[56]!==J||t[57]!==X||t[58]!==L?(z=s.jsx(b,{title:J,divider:X,headerAction:L,settingsItem:P,children:se}),t[53]=b,t[54]=P,t[55]=se,t[56]=J,t[57]=X,t[58]=L,t[59]=z):z=t[59];let V;t[60]===Symbol.for("react.memo_cache_sentinel")?(V=s.jsx(Hl,{}),t[60]=V):V=t[60];let _;t[61]!==F||t[62]!==I||t[63]!==U||t[64]!==z?(_=s.jsxs(F,{title:I,showSaveStatus:U,children:[z,V]}),t[61]=F,t[62]=I,t[63]=U,t[64]=z,t[65]=_):_=t[65];let K;t[66]!==y||t[67]!==c||t[68]!==v?(K=s.jsx(nf,{open:c,onOpenChange:N,profileId:v,importData:y}),t[66]=y,t[67]=c,t[68]=v,t[69]=K):K=t[69];const Z=g!==null;let Y;t[70]!==R?(Y=Ve=>{R||Ve||T(null)},t[70]=R,t[71]=Y):Y=t[71];let te;t[72]!==e?(te=e("settings.gitIdentities.page.deleteDialog.title"),t[72]=e,t[73]=te):te=t[73];let ge;t[74]!==te?(ge=s.jsx(_t,{children:te}),t[74]=te,t[75]=ge):ge=t[75];const le=g?.name??"";let he;t[76]!==e||t[77]!==le?(he=e("settings.gitIdentities.page.deleteDialog.description",{name:le}),t[76]=e,t[77]=le,t[78]=he):he=t[78];let ne;t[79]!==he?(ne=s.jsx($t,{children:he}),t[79]=he,t[80]=ne):ne=t[80];let ae;t[81]!==ge||t[82]!==ne?(ae=s.jsxs(Ut,{children:[ge,ne]}),t[81]=ge,t[82]=ne,t[83]=ae):ae=t[83];let me;t[84]===Symbol.for("react.memo_cache_sentinel")?(me=()=>T(null),t[84]=me):me=t[84];let Pe;t[85]!==e?(Pe=e("settings.common.actions.cancel"),t[85]=e,t[86]=Pe):Pe=t[86];let Ne;t[87]!==R||t[88]!==Pe?(Ne=s.jsx(B,{variant:"ghost",onClick:me,disabled:R,children:Pe}),t[87]=R,t[88]=Pe,t[89]=Ne):Ne=t[89];let Se;t[90]!==D?(Se=()=>{D()},t[90]=D,t[91]=Se):Se=t[91];let be;t[92]!==e?(be=e("settings.common.actions.delete"),t[92]=e,t[93]=be):be=t[93];let Ke;t[94]!==R||t[95]!==Se||t[96]!==be?(Ke=s.jsx(B,{size:"sm",variant:"destructive",onClick:Se,disabled:R,children:be}),t[94]=R,t[95]=Se,t[96]=be,t[97]=Ke):Ke=t[97];let Le;t[98]!==Ne||t[99]!==Ke?(Le=s.jsxs(es,{children:[Ne,Ke]}),t[98]=Ne,t[99]=Ke,t[100]=Le):Le=t[100];let oe;t[101]!==ae||t[102]!==Le?(oe=s.jsxs(Kt,{className:"max-w-md",children:[ae,Le]}),t[101]=ae,t[102]=Le,t[103]=oe):oe=t[103];let xe;t[104]!==Z||t[105]!==Y||t[106]!==oe?(xe=s.jsx(Ft,{open:Z,onOpenChange:Y,children:oe}),t[104]=Z,t[105]=Y,t[106]=oe,t[107]=xe):xe=t[107];let Ee;return t[108]!==_||t[109]!==K||t[110]!==xe?(Ee=s.jsxs(s.Fragment,{children:[_,K,xe]}),t[108]=_,t[109]=K,t[110]=xe,t[111]=Ee):Ee=t[111],Ee},Uo=t=>{const e=mt.c(56),{profile:a,isDefault:n,onEdit:i,onToggleDefault:r,onDelete:l,isReadOnly:u,hasBorder:p}=t,{t:h}=at(),[d,w]=o.useState(!1),c=af[a.icon||"branch"]||"git-branch",N=rf[a.color||""],v=a.authType||"ssh";let C;e[0]!==i?(C=z=>{z.currentTarget===z.target&&(z.key!=="Enter"&&z.key!==" "||(z.preventDefault(),i()))},e[0]=i,e[1]=C):C=e[1];const y=C;let S;e[2]!==n||e[3]!==u||e[4]!==l||e[5]!==r||e[6]!==h?(S=z=>s.jsxs(s.Fragment,{children:[s.jsx(z,{onClick:V=>{V.stopPropagation(),r()},children:h(n?"settings.gitIdentities.page.actions.unsetDefault":"settings.gitIdentities.page.actions.setAsDefault")}),!u&&l&&s.jsxs(z,{onClick:V=>{V.stopPropagation(),l()},className:"text-destructive focus:text-destructive",children:[s.jsx(O,{name:"delete-bin",className:"h-4 w-4 mr-px"}),h("settings.common.actions.delete")]})]}),e[2]=n,e[3]=u,e[4]=l,e[5]=r,e[6]=h,e[7]=S):S=e[7];const g=S,T=p&&"border-b border-[var(--surface-subtle)]";let R;e[8]!==T?(R=we("group flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30 cursor-pointer",T),e[8]=T,e[9]=R):R=e[9];let A;e[10]===Symbol.for("react.memo_cache_sentinel")?(A=z=>{z.preventDefault(),w(!0)},e[10]=A):A=e[10];let j;e[11]!==y||e[12]!==i||e[13]!==R?(j=s.jsx("div",{className:R,onClick:i,role:"button",tabIndex:0,onKeyDown:y,onContextMenu:A}),e[11]=y,e[12]=i,e[13]=R,e[14]=j):j=e[14];let f;e[15]!==N?(f={color:N},e[15]=N,e[16]=f):f=e[16];let b;e[17]!==c||e[18]!==f?(b=s.jsx(O,{name:c,className:"w-4 h-4 shrink-0",style:f}),e[17]=c,e[18]=f,e[19]=b):b=e[19];let F;e[20]!==a.name?(F=s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:a.name}),e[20]=a.name,e[21]=F):F=e[21];let D;e[22]!==v?(D=s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:v}),e[22]=v,e[23]=D):D=e[23];let P;e[24]!==n||e[25]!==h?(P=n&&s.jsx("span",{className:"typography-micro text-primary bg-primary/12 px-1 rounded flex-shrink-0 leading-none pb-px border border-primary/25",children:h("settings.gitIdentities.page.badge.default")}),e[24]=n,e[25]=h,e[26]=P):P=e[26];let I;e[27]!==u||e[28]!==h?(I=u&&s.jsx("span",{className:"typography-micro text-muted-foreground bg-muted px-1 rounded flex-shrink-0 leading-none pb-px border border-border/50",children:h("settings.agents.sidebar.badge.system")}),e[27]=u,e[28]=h,e[29]=I):I=e[29];let U;e[30]!==D||e[31]!==P||e[32]!==I||e[33]!==F?(U=s.jsxs("div",{className:"flex items-center gap-1.5",children:[F,D,P,I]}),e[30]=D,e[31]=P,e[32]=I,e[33]=F,e[34]=U):U=e[34];const q=v==="token"&&a.host?a.host:a.userEmail;let k;e[35]!==q?(k=s.jsx("div",{className:"typography-micro text-muted-foreground/60 truncate leading-tight",children:q}),e[35]=q,e[36]=k):k=e[36];let $;e[37]!==U||e[38]!==k?($=s.jsxs("div",{className:"min-w-0",children:[U,k]}),e[37]=U,e[38]=k,e[39]=$):$=e[39];let G;e[40]!==$||e[41]!==b?(G=s.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[b,$]}),e[40]=$,e[41]=b,e[42]=G):G=e[42];let E;e[43]===Symbol.for("react.memo_cache_sentinel")?(E=s.jsx(sn,{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:df,children:s.jsx(O,{name:"more-2",className:"h-3.5 w-3.5"})})}),e[43]=E):E=e[43];let J;e[44]!==g?(J=s.jsxs(an,{children:[E,s.jsx(nn,{align:"end",className:"w-fit min-w-28",children:g(rn)})]}),e[44]=g,e[45]=J):J=e[45];let X;e[46]!==G||e[47]!==J||e[48]!==j?(X=s.jsxs(qn,{render:j,children:[G,J]}),e[46]=G,e[47]=J,e[48]=j,e[49]=X):X=e[49];let L;e[50]!==g?(L=s.jsx(Gn,{className:"w-fit min-w-28",children:g(Wn)}),e[50]=g,e[51]=L):L=e[51];let se;return e[52]!==d||e[53]!==X||e[54]!==L?(se=s.jsxs(Jn,{open:d,onOpenChange:w,children:[X,L]}),e[52]=d,e[53]=X,e[54]=L,e[55]=se):se=e[55],se},lf=t=>{const e=mt.c(21),{credential:a,onImport:n,hasBorder:i}=t,{t:r}=at();let l;e[0]!==a.host?(l=a.host.split("/"),e[0]=a.host,e[1]=l):l=e[1];const u=l,p=u.length>=3?u[u.length-1]:a.host,h=a.host.includes("/"),d=i&&"border-b border-[var(--surface-subtle)]";let w;e[2]!==d?(w=we("flex items-center justify-between gap-3 px-4 py-2.5 transition-colors hover:bg-[var(--interactive-hover)]/30",d),e[2]=d,e[3]=w):w=e[3];let c;e[4]!==p?(c=s.jsx("span",{className:"typography-ui-label text-foreground truncate block",children:p}),e[4]=p,e[5]=c):c=e[5];const N=h?a.host:a.username;let v;e[6]!==N?(v=s.jsx("span",{className:"typography-micro text-muted-foreground/60 truncate block leading-tight",children:N}),e[6]=N,e[7]=v):v=e[7];let C;e[8]!==c||e[9]!==v?(C=s.jsxs("div",{className:"min-w-0",children:[c,v]}),e[8]=c,e[9]=v,e[10]=C):C=e[10];let y;e[11]===Symbol.for("react.memo_cache_sentinel")?(y=s.jsx(O,{name:"download",className:"h-3 w-3"}),e[11]=y):y=e[11];let S;e[12]!==r?(S=r("settings.gitIdentities.page.actions.import"),e[12]=r,e[13]=S):S=e[13];let g;e[14]!==n||e[15]!==S?(g=s.jsxs(B,{size:"sm",variant:"ghost",onClick:n,className:"gap-1 shrink-0",children:[y,S]}),e[14]=n,e[15]=S,e[16]=g):g=e[16];let T;return e[17]!==g||e[18]!==w||e[19]!==C?(T=s.jsxs("div",{className:w,children:[C,g]}),e[17]=g,e[18]=w,e[19]=C,e[20]=T):T=e[20],T};function cf(t){return{profiles:t.profiles,globalIdentity:t.globalIdentity,defaultGitIdentityId:t.defaultGitIdentityId,deleteProfile:t.deleteProfile,loadProfiles:t.loadProfiles,loadGlobalIdentity:t.loadGlobalIdentity,loadDiscoveredCredentials:t.loadDiscoveredCredentials,loadDefaultGitIdentityId:t.loadDefaultGitIdentityId,setDefaultGitIdentityId:t.setDefaultGitIdentityId,getUnimportedCredentials:t.getUnimportedCredentials}}function df(t){return t.stopPropagation()}const uf=({embedded:t=!1})=>{const{t:e}=at(),{isMobile:a}=ma(),n=tn()?.github,i=Dn(k=>k.status),r=Dn(k=>k.isLoading),l=Dn(k=>k.hasChecked),u=Dn(k=>k.refreshStatus),p=Dn(k=>k.setStatus),h=o.useCallback(async k=>{await yn(k)},[]),[d,w]=o.useState(!1),[c,N]=o.useState(null),[v,C]=o.useState(null),y=o.useRef(null),S=o.useCallback(()=>{y.current!=null&&(window.clearInterval(y.current),y.current=null),C(null)},[]);o.useEffect(()=>((async()=>{try{l||await u(n)}catch(k){console.warn("Failed to load GitHub auth status:",k)}})(),()=>{S()}),[l,u,n,S]);const g=o.useCallback(async()=>{w(!0);try{const k=n?await n.authStart():await(async()=>{const G=await pt("/api/github/auth/start",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({})}),E=await G.json().catch(()=>null);if(!G.ok||!E||!("deviceCode"in E))throw new Error(E?.error||G.statusText);return E})();N(k),C(Math.max(1,k.interval)*1e3);const $=k.verificationUriComplete||k.verificationUri;h($)}catch(k){console.error("Failed to start GitHub connect:",k),M.error(e("settings.github.page.toast.startConnectFailed"))}finally{w(!1)}},[h,n,e]),T=o.useCallback(async k=>{if(n)return n.authComplete(k);const $=await pt("/api/github/auth/complete",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({deviceCode:k})}),G=await $.json().catch(()=>null);if(!$.ok||!G)throw new Error(G?.error||$.statusText);return G},[n]);o.useEffect(()=>{if(!(!c?.deviceCode||!v)&&y.current==null)return y.current=window.setInterval(()=>{(async()=>{try{const k=await T(c.deviceCode);if(k.connected){M.success(e("settings.github.page.toast.connected")),N(null),S(),await u(n,{force:!0});return}k.status==="slow_down"&&C($=>$?$+5e3:5e3),(k.status==="expired_token"||k.status==="access_denied")&&(M.error(k.error||e("settings.github.page.toast.authorizationFailed")),N(null),S())}catch(k){console.warn("GitHub polling failed:",k)}})()},v),()=>{y.current!=null&&(window.clearInterval(y.current),y.current=null)}},[c,v,T,u,n,S,e]);const R=o.useCallback(async k=>{w(!0);try{if(n)await n.authSetGhCliDisabled(k);else{const $=await pt("/api/github/auth/gh-cli",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({disabled:k})}),G=await $.json().catch(()=>null);if(!$.ok)throw new Error(G?.error||$.statusText)}M.success(e(k?"settings.github.page.toast.ghCliDisabled":"settings.github.page.toast.ghCliEnabled")),await u(n,{force:!0})}catch($){console.error("Failed to update gh CLI setting:",$),M.error(e("settings.github.page.toast.ghCliUpdateFailed"))}finally{w(!1)}},[u,n,e]),A=o.useCallback(async()=>{w(!0);try{if(S(),N(null),n)await n.authDisconnect();else{const k=await pt("/api/github/auth",{method:"DELETE",headers:{Accept:"application/json"}});if(!k.ok)throw new Error(k.statusText)}M.success(e("settings.github.page.toast.disconnected")),await u(n,{force:!0})}catch(k){console.error("Failed to disconnect GitHub:",k),M.error(e("settings.github.page.toast.disconnectFailed"))}finally{w(!1)}},[u,n,S,e]),j=o.useCallback(async k=>{if(k){w(!0);try{const $=n?await n.authActivate(k):await(async()=>{const G=await pt("/api/github/auth/activate",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({accountId:k})}),E=await G.json().catch(()=>null);if(!G.ok||!E)throw new Error(E?.error||G.statusText);return E})();p($),M.success(e("settings.github.page.toast.accountSwitched"))}catch($){console.error("Failed to switch GitHub account:",$),M.error(e("settings.github.page.toast.accountSwitchFailed"))}finally{w(!1)}}},[n,p,e]);if(r&&!l)return null;const f=!!i?.connected,b=i?.user,D=(i?.accounts??[]).filter(k=>!k.current),P=i?.ghCli??null,I=P?.active?e("settings.github.page.accountSource.cli"):e("settings.github.page.accountSource.oauth"),U=s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden flex flex-col",children:[f?s.jsxs("div",{className:we("px-4 py-3",a?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:we("flex min-w-0 items-center gap-4",a?"w-full":void 0),children:[b?.avatarUrl?s.jsx("img",{src:b.avatarUrl,alt:b.login?e("settings.github.page.avatarAlt.withLogin",{login:b.login}):e("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]"}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"typography-ui-label text-foreground",children:b?.name?.trim()||b?.login||"GitHub"}),s.jsxs("div",{className:we("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",a?"flex-wrap":"truncate"),children:[s.jsx(O,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:b?.login||e("settings.github.page.label.unknownUser")}),b?.email&&s.jsx("span",{className:"opacity-50",children:"•"}),b?.email&&s.jsx("span",{children:b.email}),s.jsx("span",{className:"opacity-50",children:"•"}),s.jsx("span",{children:I})]}),i?.scope&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:e("settings.github.page.label.scopes",{value:i.scope})}),P?.active&&s.jsx("div",{className:"typography-micro text-muted-foreground/70 mt-0.5",children:e("settings.github.page.ghCli.activeDescription")})]})]}),P?.active?s.jsx(B,{size:"sm",variant:"outline",onClick:()=>R(!0),disabled:d,className:we(a?"w-full":void 0),children:e("settings.github.page.ghCli.actions.disable")}):s.jsx(B,{size:"sm",variant:"outline",onClick:A,disabled:d,className:we("text-[var(--status-error)] hover:text-[var(--status-error)]",a?"w-full":void 0),children:e("settings.github.page.actions.disconnect")})]}):s.jsxs("div",{className:"flex items-center justify-between gap-4 px-4 py-4",children:[s.jsx("div",{className:"flex min-w-0 flex-col",children:s.jsx("span",{className:"typography-ui-label text-foreground",children:e("settings.github.page.status.notConnected")})}),s.jsx(B,{size:"sm",variant:"default",onClick:g,disabled:d,children:e("settings.github.page.actions.connect")})]}),D.length>0&&s.jsxs("div",{className:"mt-2 border-t border-[var(--surface-subtle)] pt-2 px-2 pb-1",children:[s.jsx("div",{className:"typography-micro text-muted-foreground mb-2 px-1",children:e("settings.github.page.label.otherAccounts")}),s.jsx("div",{className:"space-y-1",children:D.map(k=>{const $=k.user,G=k.source==="gh-cli"?e("settings.github.page.accountSource.cli"):e("settings.github.page.accountSource.oauth");return s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] px-3 py-2",children:[s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[$?.avatarUrl?s.jsx("img",{src:$.avatarUrl,alt:$.login?e("settings.github.page.avatarAlt.withLogin",{login:$.login}):e("settings.github.page.avatarAlt.fallback"),className:"h-6 w-6 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-6 w-6 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(O,{name:"github-fill",className:"h-3 w-3 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex flex-col",children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:$?.name?.trim()||$?.login||"GitHub"}),$?.login&&s.jsxs("span",{className:"typography-micro text-muted-foreground truncate",children:[s.jsx("span",{className:"font-mono",children:$.login}),s.jsx("span",{className:"mx-1 opacity-50",children:"·"}),s.jsx("span",{children:G})]})]})]}),s.jsx(B,{size:"sm",variant:"ghost",onClick:()=>j(k.id),disabled:d,children:e("settings.github.page.actions.switchTo")})]},k.id)})})]})]}),f&&s.jsx("div",{className:"mt-2 px-2 pb-2",children:s.jsx(B,{size:"sm",variant:"outline",onClick:g,disabled:d,className:we(a?"w-full":void 0),children:e("settings.github.page.actions.addAccount")})}),c&&s.jsxs("div",{className:"mt-4 rounded-lg bg-[var(--surface-elevated)]/70 p-4 border border-[var(--interactive-border)]",children:[s.jsxs("div",{className:"space-y-1",children:[s.jsx(Js,{children:e("settings.github.page.flow.title")}),s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.github.page.flow.description")})]}),s.jsxs("div",{className:"flex items-center justify-between gap-3 mt-4",children:[s.jsx("div",{className:"font-mono text-xl tracking-widest text-foreground bg-[var(--surface-muted)] px-3 py-1.5 rounded-md border border-[var(--interactive-border)]",children:c.userCode}),s.jsx(B,{size:"sm",asChild:!0,children:s.jsx("a",{href:c.verificationUriComplete||c.verificationUri,target:"_blank",rel:"noopener noreferrer",children:e("settings.github.page.actions.openGithub")})})]}),s.jsxs("div",{className:"mt-4 flex items-center justify-between",children:[s.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:e("settings.github.page.flow.waiting")}),s.jsx(B,{size:"sm",variant:"ghost",disabled:d,onClick:()=>{S(),N(null)},children:e("settings.common.actions.cancel")})]})]})]}),q=P?.available&&!P?.active&&(!P.user||P.disabled)?s.jsx(s.Fragment,{children:s.jsx("div",{className:"rounded-lg bg-[var(--surface-elevated)]/70 overflow-hidden",children:s.jsxs("div",{className:we("px-4 py-3",a?"flex flex-col gap-3":"flex items-center justify-between gap-4"),children:[s.jsxs("div",{className:we("flex min-w-0 items-center gap-4",a?"w-full":void 0),children:[P.user?.avatarUrl?s.jsx("img",{src:P.user.avatarUrl,alt:P.user.login?e("settings.github.page.avatarAlt.withLogin",{login:P.user.login}):e("settings.github.page.avatarAlt.fallback"),className:"h-10 w-10 shrink-0 rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)] object-cover",loading:"lazy",referrerPolicy:"no-referrer"}):s.jsx("div",{className:"flex h-10 w-10 shrink-0 items-center justify-center rounded-full border border-[var(--interactive-border)] bg-[var(--surface-muted)]",children:s.jsx(O,{name:"github-fill",className:"h-4 w-4 text-muted-foreground"})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[!P.disabled&&P.user&&s.jsx("div",{className:"typography-ui-label text-foreground truncate",children:P.user.name?.trim()||P.user.login||"GitHub"}),!P.disabled&&P.user?.login&&s.jsxs("div",{className:we("flex items-center gap-2 typography-meta text-muted-foreground mt-0.5",a?"flex-wrap":"truncate"),children:[s.jsx(O,{name:"github-fill",className:"h-3.5 w-3.5 shrink-0"}),s.jsx("span",{className:"font-mono",children:P.user.login}),P.user.email&&s.jsx("span",{className:"opacity-50",children:"•"}),P.user.email&&s.jsx("span",{children:P.user.email})]}),s.jsx("div",{className:we("typography-meta text-muted-foreground",P.disabled?"opacity-60":void 0),children:P.disabled?e("settings.github.page.ghCli.disabledDescription"):e("settings.github.page.ghCli.fallbackDescription")})]})]}),s.jsx(B,{size:"sm",variant:"outline",onClick:()=>R(!P.disabled),disabled:d,className:we(a?"w-full":void 0),children:P.disabled?e("settings.github.page.ghCli.actions.enable"):e("settings.github.page.ghCli.actions.disable")})]})})}):null;return t?s.jsxs("div",{className:"space-y-4",children:[U,q?s.jsxs("div",{className:"space-y-2",children:[s.jsx(Js,{children:e("settings.github.page.ghCli.title")}),q]}):null]}):s.jsxs(s.Fragment,{children:[s.jsx(_e,{title:e("settings.github.page.oauth.title"),divider:!1,settingsItem:"git.github-account",info:e("settings.github.page.tooltip.connectAccount"),children:U}),q?s.jsx(_e,{title:e("settings.github.page.ghCli.title"),children:q}):null]})},pf=()=>{const t=mt.c(37),{t:e}=at(),a=Dn(mf),n=Dn(gf),i=Dn(ff),[r,l]=o.useState(!1),u=a?.connected===!0;let p;t[0]!==u||t[1]!==i||t[2]!==n||t[3]!==a?.user?.login||t[4]!==e?(p=n&&!i?e("common.loading"):u?a?.user?.login?.trim()||e("settings.github.page.status.active"):e("settings.integrations.github.status.notConnected"),t[0]=u,t[1]=i,t[2]=n,t[3]=a?.user?.login,t[4]=e,t[5]=p):p=t[5];const h=p,d=u?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground";let w;t[6]===Symbol.for("react.memo_cache_sentinel")?(w=s.jsx("div",{className:"flex size-10 shrink-0 items-center justify-center rounded-[10px] bg-[var(--surface-muted)]",children:s.jsx(O,{name:"github-fill",className:"size-5 text-foreground"})}),t[6]=w):w=t[6];let c;t[7]!==e?(c=e("settings.integrations.github.title"),t[7]=e,t[8]=c):c=t[8];let N;t[9]!==c?(N=s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:c}),t[9]=c,t[10]=N):N=t[10];let v;t[11]!==e?(v=e("settings.integrations.github.description"),t[11]=e,t[12]=v):v=t[12];let C;t[13]!==v?(C=s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:v}),t[13]=v,t[14]=C):C=t[14];let y;t[15]!==N||t[16]!==C?(y=s.jsxs("div",{className:"min-w-0 flex-1",children:[N,C]}),t[15]=N,t[16]=C,t[17]=y):y=t[17];let S;t[18]!==d?(S=we("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",d),t[18]=d,t[19]=S):S=t[19];let g;t[20]!==h||t[21]!==S?(g=s.jsx("span",{"aria-live":"polite",className:S,children:h}),t[20]=h,t[21]=S,t[22]=g):g=t[22];const T=r&&"rotate-180";let R;t[23]!==T?(R=we("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",T),t[23]=T,t[24]=R):R=t[24];let A;t[25]!==R?(A=s.jsx(O,{name:"arrow-down-s",className:R}),t[25]=R,t[26]=A):A=t[26];let j;t[27]!==A||t[28]!==y||t[29]!==g?(j=s.jsxs(wn,{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:[w,y,g,A]}),t[27]=A,t[28]=y,t[29]=g,t[30]=j):j=t[30];let f;t[31]===Symbol.for("react.memo_cache_sentinel")?(f=s.jsx(jn,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsx(uf,{embedded:!0})}),t[31]=f):f=t[31];let b;t[32]!==j?(b=s.jsxs("div",{"data-settings-item":"integrations.github",className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[j,f]}),t[32]=j,t[33]=b):b=t[33];let F;return t[34]!==r||t[35]!==b?(F=s.jsx(bn,{open:r,onOpenChange:l,children:b}),t[34]=r,t[35]=b,t[36]=F):F=t[36],F};function mf(t){return t.status}function gf(t){return t.isLoading}function ff(t){return t.hasChecked}const ai="__none__",ii="__inherit__";function hf({linear:t,connected:e,organizationId:a}){const{t:n}=at(),i=Vs(y=>y.projects),[r,l]=o.useState(null),[u,p]=o.useState(!1),[h,d]=o.useState(!1),w=o.useCallback(async()=>{if(!e){l(null),p(!1);return}try{const y=await t.mappingGet();if(y.connected===!1){l(null),p(!1);return}l(y),p(!1)}catch(y){console.error("Failed to load Linear mapping:",y),p(!0)}},[e,t]);o.useEffect(()=>{w()},[w,a]);const c=o.useCallback(async y=>{const S={};for(const g of y.teams??[])g.projectPath&&(S[g.id]=g.projectPath);d(!0),xn("saving");try{const g=await t.mappingSet({defaultProjectPath:y.defaultProjectPath??null,teamProjectPaths:S});if(g.connected===!1){l(null),xn("error");return}l(g),p(!1),xn("saved")}catch(g){console.error("Failed to save Linear mapping:",g),xn("error")}finally{d(!1)}},[t]);if(!e)return null;if(u&&!r)return s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.loadFailed")});if(!r)return null;const N=y=>i.find(g=>g.path===y)?.label?.trim()||y,v=y=>!y||y===ai?n("settings.integrations.linear.mapping.defaultProject.placeholder"):N(y),C=y=>!y||y===ii?n("settings.integrations.linear.mapping.teams.useDefault"):N(y);return s.jsxs("div",{className:Ws,children:[i.length===0?s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.emptyProjects")}):null,s.jsx(Ot,{label:n("settings.integrations.linear.mapping.defaultProject"),info:n("settings.integrations.linear.mapping.defaultProject.info"),settingsItem:"integrations.linear.mapping",children:s.jsxs(Pt,{value:r.defaultProjectPath||ai,disabled:h||i.length===0,onValueChange:y=>{c({...r,defaultProjectPath:y===ai?null:y})},children:[s.jsx(It,{size:Lt,className:en,"aria-label":n("settings.integrations.linear.mapping.defaultProject.aria"),children:s.jsx(Rt,{placeholder:n("settings.integrations.linear.mapping.defaultProject.placeholder"),children:v})}),s.jsxs(At,{children:[s.jsx(ot,{value:ai,children:n("settings.integrations.linear.mapping.defaultProject.placeholder")}),r.defaultProjectPath&&!i.some(y=>y.path===r.defaultProjectPath)?s.jsx(ot,{value:r.defaultProjectPath,children:r.defaultProjectPath}):null,i.map(y=>s.jsx(ot,{value:y.path,children:N(y.path)},y.id))]})]})}),s.jsx(Ls,{title:n("settings.integrations.linear.mapping.teams"),info:n("settings.integrations.linear.mapping.teams.info"),children:(r.teams??[]).length===0?s.jsx("p",{className:"text-xs text-muted-foreground",children:n("settings.integrations.linear.mapping.emptyTeams")}):s.jsx("div",{className:Ws,children:(r.teams??[]).map(y=>s.jsx(Ot,{label:`${y.key} · ${y.name}`,children:s.jsxs(Pt,{value:y.projectPath||ii,disabled:h||i.length===0,onValueChange:S=>{c({...r,teams:(r.teams??[]).map(g=>g.id===y.id?{...g,projectPath:S===ii?null:S}:g)})},children:[s.jsx(It,{size:Lt,className:en,"aria-label":n("settings.integrations.linear.mapping.teams.aria",{team:y.key}),children:s.jsx(Rt,{placeholder:n("settings.integrations.linear.mapping.teams.useDefault"),children:C})}),s.jsxs(At,{children:[s.jsx(ot,{value:ii,children:n("settings.integrations.linear.mapping.teams.useDefault")}),y.projectPath&&!i.some(S=>S.path===y.projectPath)?s.jsx(ot,{value:y.projectPath,children:y.projectPath}):null,i.map(S=>s.jsx(ot,{value:S.path,children:N(S.path)},S.id))]})]})},y.id))})})]})}function xf({linear:t,connected:e}){const{t:a}=at(),[n,i]=o.useState(null),[r,l]=o.useState(!1),[u,p]=o.useState(!1);o.useEffect(()=>{if(!e){i(null),l(!1);return}let d=!1;return t.preferencesGet().then(w=>{d||(i(w.sessionComments),l(!1))}).catch(()=>{d||l(!0)}),()=>{d=!0}},[e,t]);const h=o.useCallback(async d=>{const w=n;i(d),p(!0);try{const c=await t.preferencesSet({sessionComments:d});i(c.sessionComments),xn("saved")}catch{i(w),xn("error")}finally{p(!1)}},[n,t]);return e?r?s.jsx("p",{className:"text-xs text-muted-foreground",children:a("settings.integrations.linear.sessionComments.loadFailed")}):s.jsx("div",{className:Ws,children:s.jsx(Ot,{label:a("settings.integrations.linear.sessionComments.label"),info:a("settings.integrations.linear.sessionComments.info"),settingsItem:"integrations.linear.session-comments",children:s.jsx(li,{checked:n===!0,disabled:n===null||u,onCheckedChange:d=>{h(d)},"aria-label":a("settings.integrations.linear.sessionComments.aria")})})}):null}const vf=3*6e4,yf=1500;function _o(t){const e=t?.workspaces??[],a=e.find(n=>n.current);return{connected:!!t?.connected,ids:e.map(n=>n.id).slice().sort().join(","),currentId:a?.id||t?.organization?.id||"",currentAuthorizedAt:a?.authorizedAt??0}}function bf(t,e){return e.connected?t.connected?e.ids!==t.ids||e.currentId!==t.currentId||e.currentAuthorizedAt!==t.currentAuthorizedAt:!0:!1}const wf=()=>{const{t}=at(),e=tn()?.linear,a=ia(P=>P.status),n=ia(P=>P.isLoading),i=ia(P=>P.hasChecked),r=ia(P=>P.refreshStatus),l=ia(P=>P.setStatus),[u,p]=o.useState(!1),[h,d]=o.useState(!1),[w,c]=o.useState(!1),N=o.useRef(null),v=o.useCallback(()=>{N.current!=null&&(window.clearInterval(N.current),N.current=null),d(!1)},[]);o.useEffect(()=>{if(e)return i||r(e),()=>{v()}},[i,r,e,v]);const C=o.useCallback(async()=>{if(!e)return;v(),p(!0);const P=_o(ia.getState().status);try{const I=await e.authStart(os()?"desktop":"web");d(!0),c(!0),yn(I.authorizationUrl);const U=Date.now()+vf;N.current=window.setInterval(()=>{(async()=>{if(Date.now()>U){v(),M.error(t("settings.integrations.linear.toast.authorizationFailed"));return}const q=await r(e,{force:!0});bf(P,_o(q))&&(v(),M.success(t("settings.integrations.linear.toast.connected")),bd())})()},yf)}catch(I){console.error("Failed to start Linear connect:",I),M.error(t("settings.integrations.linear.toast.startConnectFailed")),v()}finally{p(!1)}},[r,e,v,t]),y=o.useCallback(async P=>{if(!(!e||!P)){p(!0);try{const I=await e.authActivate(P);l(I),M.success(t("settings.integrations.linear.toast.workspaceSwitched"))}catch(I){console.error("Failed to switch Linear workspace:",I),M.error(t("settings.integrations.linear.toast.workspaceSwitchFailed"))}finally{p(!1)}}},[e,l,t]),S=o.useCallback(async()=>{if(e){p(!0);try{v(),await e.authDisconnect(),M.success(t("settings.integrations.linear.toast.disconnected")),await r(e,{force:!0})}catch(P){console.error("Failed to disconnect Linear:",P),M.error(t("settings.integrations.linear.toast.disconnectFailed"))}finally{p(!1)}}},[r,e,v,t]);if(!e)return null;const g=!!a?.connected,T=a?.user,R=a?.organization,j=(a?.workspaces??[]).filter(P=>!P.current),f=T?.displayName?.trim()||T?.name?.trim()||t("settings.integrations.linear.label.unknownUser"),b=h?t("settings.integrations.linear.status.waiting"):n&&!i?t("common.loading"):g?R?.name?.trim()||t("settings.integrations.linear.status.connected"):t("settings.integrations.linear.status.notConnected"),F=h?"bg-[var(--status-warning)]/15 text-[var(--status-warning)]":g?"bg-[var(--status-success)]/15 text-[var(--status-success)]":"bg-[var(--surface-muted)] text-muted-foreground",D=h||w;return s.jsx(bn,{open:D,onOpenChange:P=>{if(h){c(!0);return}c(P)},children:s.jsxs("div",{"data-settings-item":"integrations.linear",className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[s.jsxs(wn,{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(O,{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:we("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",F),children:b}),s.jsx(O,{name:"arrow-down-s",className:we("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",D&&"rotate-180")})]}),s.jsx(jn,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsxs("div",{className:"space-y-3",children:[g?s.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[T?.avatarUrl?s.jsx("img",{src:T.avatarUrl,alt:t("settings.integrations.linear.avatarAlt.withName",{name:f}),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(O,{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:f}),s.jsx("p",{className:"mt-0.5 truncate text-xs text-muted-foreground",children:[R?.name,T?.email].filter(Boolean).join(" · ")})]})]}):h?s.jsx("p",{className:"text-xs text-muted-foreground",children:t("settings.integrations.linear.flow.description")}):null,g?s.jsxs(s.Fragment,{children:[s.jsx(hf,{linear:e,connected:g,organizationId:R?.id??null}),s.jsx(xf,{linear:e,connected:g}),j.length>0?s.jsxs("div",{className:"space-y-2",children:[s.jsx("p",{className:"typography-micro text-muted-foreground",children:t("settings.integrations.linear.label.otherWorkspaces")}),s.jsx("div",{className:"space-y-1",children:j.map(P=>{const I=P.user,U=P.name?.trim()||t("settings.integrations.linear.status.connected");return s.jsxs("div",{className:"flex items-center justify-between gap-3 rounded-md border border-[var(--surface-subtle)] bg-[var(--surface-muted)] px-3 py-2",children:[s.jsxs("div",{className:"min-w-0",children:[s.jsx("div",{className:"truncate text-sm font-medium text-foreground",children:U}),I?.email?s.jsx("p",{className:"truncate text-xs text-muted-foreground",children:I.email}):null]}),s.jsx(B,{type:"button",size:"sm",variant:"ghost",onClick:()=>{y(P.id)},disabled:u,children:t("settings.integrations.linear.actions.switchTo")})]},P.id)})})]}):null,s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx(B,{type:"button",size:"sm",variant:"outline",onClick:()=>{C()},disabled:u||h,"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:u,children:t("settings.integrations.linear.actions.disconnect")})]})]}):h?s.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[s.jsx("span",{className:"typography-micro text-muted-foreground animate-pulse",children:t("settings.integrations.linear.flow.waiting")}),s.jsx(B,{type:"button",size:"sm",variant:"ghost",disabled:u,onClick:v,children:t("settings.common.actions.cancel")})]}):s.jsxs(B,{type:"button",size:"sm",variant:"default",onClick:()=>{C()},disabled:u||n&&!i,children:[u?s.jsx(O,{name:"loader-4",className:"size-3.5 animate-spin"}):null,t("settings.integrations.linear.actions.connect")]})]})})]})})},Hi=[{id:"opencode-claude",packageName:"@aiworker/opencode-claude",providerId:"claude-code",icon:"claude-code",brandClassName:"text-[#D97757]",nameKey:"settings.integrations.thirdParty.opencodeClaude.name",descriptionKey:"settings.integrations.thirdParty.opencodeClaude.description",homepage:"https://github.com/openchamber/opencode-claude"},{id:"opencode-cursor-oauth",packageName:"@aiworker/opencode-cursor",providerId:"cursor",icon:"cursor",brandClassName:"text-foreground",nameKey:"settings.integrations.thirdParty.opencodeCursorOauth.name",descriptionKey:"settings.integrations.thirdParty.opencodeCursorOauth.description",homepage:"https://github.com/openchamber/opencode-cursor"}],jf=(t,e)=>t===e||t.startsWith(`${e}@`);function Gi(t,e,a){const n=t.filter(p=>jf(p.spec,e)),i=n.filter(p=>p.scope==="user"),r=n.filter(p=>p.scope==="project"),l=i.length===1?i[0]:null,u=a[l?.spec??e]??a[e]??null;return{userEntry:l,userEntryIsAmbiguous:i.length>1,projectEntries:r,registry:u}}function lr(t,e){return e?.kind!=="npm-ok"||e.name!==t||!e.latestVersion?null:`${t}@${e.latestVersion}`}function $o(t,e){if(t.userEntryIsAmbiguous)return"manage";if(!t.userEntry)return"install";const a=lr(e,t.registry);return a&&a!==t.userEntry.spec?"update":"setup"}function kf(t,e={}){const a=t.registry?.kind==="npm-ok"?t.registry.latestVersion:null;return t.userEntryIsAmbiguous?{status:"ambiguous",latestVersion:a}:e.restartRequired?{status:"restart-required",latestVersion:a}:e.providerUnavailable?{status:"provider-unavailable",latestVersion:a}:e.registryUnavailable?{status:"registry-unavailable",latestVersion:a}:t.userEntry?t.registry?.kind==="npm-ok"&&t.registry.currentVersion===t.registry.latestVersion?{status:"installed-version",latestVersion:a}:t.registry?.kind==="npm-ok"&&t.registry.currentVersion===null?{status:"unpinned",latestVersion:a}:t.registry?.kind==="npm-ok"&&a?{status:"update-available",latestVersion:a}:{status:"installed",latestVersion:a}:{status:"not-installed",latestVersion:a}}const Nf=t=>t.restartDeferred===!0||t.requiresManualRestart===!0||t.reloadFailed===!0,Sf=({divider:t=!0,onOpenProviderSetup:e,onOpenPluginManager:a})=>{const{t:n}=at(),{entries:i,registryInfo:r,loadPlugins:l,loadRegistryInfo:u,createEntry:p,updateEntry:h,deleteEntry:d}=rs(Ds(E=>({entries:E.entries,registryInfo:E.registryInfo,loadPlugins:E.loadPlugins,loadRegistryInfo:E.loadRegistryInfo,createEntry:E.createEntry,updateEntry:E.updateEntry,deleteEntry:E.deleteEntry}))),[w,c]=o.useState(!1),[N,v]=o.useState(null),[C,y]=o.useState(()=>new Set),[S,g]=o.useState(()=>new Set),[T,R]=o.useState(null),[A,j]=o.useState(()=>new Set),f=o.useCallback(async()=>{if(!await l({force:!0})){c(!0);return}const J=rs.getState().entries,X=new Set(Hi.map(se=>se.packageName));for(const se of J)Hi.some(z=>se.spec===z.packageName||se.spec.startsWith(`${z.packageName}@`))&&X.add(se.spec);const L=await u({specs:[...X],force:!0});c(!L)},[l,u]);o.useEffect(()=>{f()},[f]);const b=vn(E=>E.changes.filter(J=>J.scope==="plugins").length),F=vn(E=>E.isApplying),D=o.useRef(b);o.useEffect(()=>{const E=D.current;D.current=b,!F&&(E<=0||b>0||(y(new Set),g(new Set),f()))},[F,b,f]);const P=o.useCallback((E,J)=>{y(X=>{const L=new Set(X);return J?L.add(E):L.delete(E),L})},[]),I=o.useCallback((E,J)=>{g(X=>{const L=new Set(X);return J?L.add(E):L.delete(E),L})},[]),U=o.useCallback(async(E,J,X)=>{v({pluginId:E.id,action:J});try{const L=await X();if(!L.ok){M.error(n("settings.integrations.thirdParty.toast.actionFailed"));return}I(E.id,!1);const se=Nf(L);P(E.id,se);const z=se?{description:n("settings.integrations.thirdParty.toast.restartRequired")}:void 0;J==="install"?M.success(n("settings.integrations.thirdParty.toast.installed",{name:n(E.nameKey)}),z):J==="update"?M.success(n("settings.integrations.thirdParty.toast.updated",{name:n(E.nameKey)}),z):M.success(n("settings.integrations.thirdParty.toast.removed",{name:n(E.nameKey)}),z),await f()}finally{v(null)}},[f,I,P,n]),q=o.useCallback(async E=>{const J=Gi(i,E.packageName,r),X=$o(J,E.packageName);if(X==="manage"){a();return}if(X==="setup"){v({pluginId:E.id,action:X});try{const se=await e(E.providerId);I(E.id,!se),se||M.error(n("settings.integrations.thirdParty.toast.providerUnavailable"))}finally{v(null)}return}const L=lr(E.packageName,J.registry);if(!L){c(!0);return}if(X==="install"){await U(E,"install",()=>p({spec:L,scope:"user"}));return}J.userEntry&&await U(E,"update",()=>h(J.userEntry.id,{spec:L}))},[p,i,a,e,r,U,I,n,h]),k=o.useCallback(async()=>{const E=T;if(!E)return;const J=Gi(i,E.packageName,r);if(!J.userEntry||J.userEntryIsAmbiguous){R(null),a();return}R(null),await U(E,"remove",()=>d(J.userEntry.id))},[d,i,a,r,T,U]),$=o.useCallback((E,J)=>{j(X=>{const L=new Set(X);return J?L.add(E):L.delete(E),L})},[]),G=E=>{const J=Gi(i,E.packageName,r),X=$o(J,E.packageName),L=lr(E.packageName,J.registry),se=N?.pluginId===E.id,z=C.has(E.id),V=S.has(E.id),_=w||J.registry?.kind==="npm-network",K=se||z||(X==="install"||X==="update")&&(_||!L),Z=kf(J,{registryUnavailable:_,restartRequired:z,providerUnavailable:V});let Y;switch(Z.status){case"installed-version":Y=Z.latestVersion?n("settings.integrations.thirdParty.status.installedVersion",{version:Z.latestVersion}):n("settings.integrations.thirdParty.status.installed");break;case"update-available":Y=Z.latestVersion?n("settings.integrations.thirdParty.status.updateAvailable",{version:Z.latestVersion}):n("settings.integrations.thirdParty.status.unpinned");break;case"not-installed":Y=n("settings.integrations.thirdParty.status.notInstalled");break;case"installed":Y=n("settings.integrations.thirdParty.status.installed");break;case"unpinned":Y=n("settings.integrations.thirdParty.status.unpinned");break;case"ambiguous":Y=n("settings.integrations.thirdParty.status.ambiguous");break;case"restart-required":Y=n("settings.integrations.thirdParty.status.restartRequired");break;case"registry-unavailable":Y=n("settings.integrations.thirdParty.status.registryUnavailable");break;case"provider-unavailable":Y=n("settings.integrations.thirdParty.status.providerUnavailable");break}const te=Z.status==="installed-version"?"bg-[var(--status-success)]/15 text-[var(--status-success)]":Z.status==="update-available"||Z.status==="ambiguous"||Z.status==="restart-required"||Z.status==="registry-unavailable"||Z.status==="provider-unavailable"?"bg-[var(--status-warning)]/15 text-[var(--status-warning)]":"bg-[var(--surface-muted)] text-muted-foreground",ge={install:n("settings.integrations.thirdParty.actions.install"),update:n("settings.integrations.thirdParty.actions.update"),setup:n("settings.integrations.thirdParty.actions.setup"),manage:n("settings.integrations.thirdParty.actions.managePlugins")}[X],le=A.has(E.id);return s.jsx(bn,{open:le,onOpenChange:he=>$(E.id,he),children:s.jsxs("div",{"data-settings-item":`integrations.third-party.${E.id}`,className:"overflow-hidden rounded-xl border border-[var(--interactive-border)] bg-[var(--surface-elevated)]",children:[s.jsxs(wn,{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(O,{name:E.icon,className:we("size-5",E.brandClassName)})}),s.jsxs("div",{className:"min-w-0 flex-1",children:[s.jsx("div",{className:"truncate text-sm font-semibold text-foreground",children:n(E.nameKey)}),s.jsx("p",{className:"mt-0.5 line-clamp-1 text-xs leading-snug text-muted-foreground",children:n(E.descriptionKey)})]}),s.jsx("span",{"aria-live":"polite",className:we("max-w-36 shrink-0 truncate rounded-full px-2 py-0.5 text-[10px] font-medium",te),children:Y}),s.jsx(O,{name:"arrow-down-s",className:we("size-4 shrink-0 text-muted-foreground transition-transform duration-150 ease-out motion-reduce:transition-none",le&&"rotate-180")})]}),s.jsx(jn,{className:"border-t border-[var(--interactive-border)] px-4 py-4",children:s.jsxs("div",{className:"space-y-3",children:[J.projectEntries.length>0?s.jsx("p",{className:"text-xs text-muted-foreground",children:n("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:X==="manage"?"outline":"default",onClick:()=>{q(E)},disabled:K,children:[se?s.jsx(O,{name:"loader-4",className:"size-3.5 animate-spin"}):X==="setup"?s.jsx(O,{name:"plug-2",className:"size-3.5"}):null,ge]}),s.jsxs(B,{type:"button",size:"sm",variant:"secondary",onClick:()=>{yn(E.homepage)},children:[s.jsx(O,{name:"external-link",className:"size-3.5"}),n("settings.integrations.thirdParty.actions.docs")]}),J.userEntry&&!J.userEntryIsAmbiguous?s.jsxs(B,{type:"button",size:"sm",variant:"destructive",onClick:()=>R(E),disabled:se,children:[s.jsx(O,{name:"delete-bin",className:"size-3.5"}),n("settings.integrations.thirdParty.actions.remove")]}):null]})]})})]})},E.id)};return s.jsxs(s.Fragment,{children:[s.jsxs(_e,{title:n("settings.integrations.thirdParty.title"),info:n("settings.integrations.thirdParty.info"),divider:t,settingsItem:"integrations.third-party",contentClassName:"space-y-3",children:[s.jsxs("div",{role:"alert",className:"flex items-start gap-2 rounded-lg border border-[var(--status-warning-border)] bg-[var(--status-warning-background)] p-3",children:[s.jsx(O,{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:n("settings.integrations.experimentalWarning")})]}),Hi.map(G)]}),s.jsx(Ft,{open:T!==null,onOpenChange:E=>!E&&R(null),children:s.jsxs(Kt,{className:"max-w-md",children:[s.jsxs(Ut,{children:[s.jsx(_t,{children:n("settings.integrations.thirdParty.dialog.remove.title")}),s.jsx($t,{children:n("settings.integrations.thirdParty.dialog.remove.description",{name:T?n(T.nameKey):""})})]}),s.jsxs(es,{children:[s.jsx(B,{type:"button",size:"sm",variant:"ghost",onClick:()=>R(null),children:n("settings.common.actions.cancel")}),s.jsx(B,{type:"button",size:"sm",variant:"destructive",onClick:()=>{k()},children:n("settings.integrations.thirdParty.actions.remove")})]})]})})]})},Cf=t=>{const e=mt.c(15),{onOpenProviderSetup:a,onOpenPluginManager:n}=t,{t:i}=at();let r;e[0]===Symbol.for("react.memo_cache_sentinel")?(r=us(),e[0]=r):r=e[0];const l=!r,u=!!tn()?.linear,p=l||u;let h;e[1]!==i?(h=i("settings.page.integrations.title"),e[1]=i,e[2]=h):h=e[2];let d;e[3]!==i?(d=i("settings.page.integrations.description"),e[3]=i,e[4]=d):d=e[4];let w;e[5]!==i?(w=p?s.jsxs(_e,{title:i("settings.integrations.firstParty.title"),info:i("settings.integrations.firstParty.info"),divider:!1,settingsItem:"integrations.first-party",contentClassName:"space-y-3",children:[l?s.jsx(pf,{}):null,u?s.jsx(wf,{}):null]}):null,e[5]=i,e[6]=w):w=e[6];let c;e[7]!==n||e[8]!==a?(c=s.jsx(Sf,{divider:p,onOpenProviderSetup:a,onOpenPluginManager:n}),e[7]=n,e[8]=a,e[9]=c):c=e[9];let N;return e[10]!==h||e[11]!==d||e[12]!==w||e[13]!==c?(N=s.jsxs(ns,{title:h,description:d,showSaveStatus:!0,children:[w,c]}),e[10]=h,e[11]=d,e[12]=w,e[13]=c,e[14]=N):N=e[14],N},Pf=[{value:"system",labelKey:"settings.aiworker.visual.option.themeMode.system",descriptionKey:"settings.aiworker.visual.option.themeMode.system.description"},{value:"light",labelKey:"settings.aiworker.visual.option.themeMode.light",descriptionKey:"settings.aiworker.visual.option.themeMode.light.description"},{value:"dark",labelKey:"settings.aiworker.visual.option.themeMode.dark",descriptionKey:"settings.aiworker.visual.option.themeMode.dark.description"}],If=[{id:"dynamic",labelKey:"settings.aiworker.visual.option.diffLayout.dynamic.label",descriptionKey:"settings.aiworker.visual.option.diffLayout.dynamic.description"},{id:"inline",labelKey:"settings.aiworker.visual.option.diffLayout.inline.label",descriptionKey:"settings.aiworker.visual.option.diffLayout.inline.description"},{id:"side-by-side",labelKey:"settings.aiworker.visual.option.diffLayout.sideBySide.label",descriptionKey:"settings.aiworker.visual.option.diffLayout.sideBySide.description"}],Af=[{id:"svg",labelKey:"settings.aiworker.visual.option.mermaidRendering.svg.label",descriptionKey:"settings.aiworker.visual.option.mermaidRendering.svg.description"},{id:"ascii",labelKey:"settings.aiworker.visual.option.mermaidRendering.ascii.label",descriptionKey:"settings.aiworker.visual.option.mermaidRendering.ascii.description"}],Aa="AiWorker - AI Coding Assistant",Vo=[{id:"system",labelKey:"settings.aiworker.visual.option.pwaOrientation.system.label",descriptionKey:"settings.aiworker.visual.option.pwaOrientation.system.description"},{id:"portrait",labelKey:"settings.aiworker.visual.option.pwaOrientation.portrait.label",descriptionKey:"settings.aiworker.visual.option.pwaOrientation.portrait.description"},{id:"landscape",labelKey:"settings.aiworker.visual.option.pwaOrientation.landscape.label",descriptionKey:"settings.aiworker.visual.option.pwaOrientation.landscape.description"}],Bo=[{id:"native",labelKey:"settings.aiworker.visual.option.mobileKeyboardMode.native.label",descriptionKey:"settings.aiworker.visual.option.mobileKeyboardMode.native.description"},{id:"resize-content",labelKey:"settings.aiworker.visual.option.mobileKeyboardMode.resizeContent.label",descriptionKey:"settings.aiworker.visual.option.mobileKeyboardMode.resizeContent.description"}],Wi=t=>t==="portrait"||t==="landscape"?t:"system",Tf=[{id:"markdown",labelKey:"settings.aiworker.visual.option.userMessageRendering.markdown.label",descriptionKey:"settings.aiworker.visual.option.userMessageRendering.markdown.description"},{id:"plain",labelKey:"settings.aiworker.visual.option.userMessageRendering.plain.label",descriptionKey:"settings.aiworker.visual.option.userMessageRendering.plain.description"}],Ef=[{id:"sorted",labelKey:"settings.aiworker.visual.option.chatRenderMode.sorted.label",descriptionKey:"settings.aiworker.visual.option.chatRenderMode.sorted.description"},{id:"live",labelKey:"settings.aiworker.visual.option.chatRenderMode.live.label",descriptionKey:"settings.aiworker.visual.option.chatRenderMode.live.description"}],Ho=[{id:"auto",labelKey:"settings.aiworker.visual.option.messageTransport.auto.label",descriptionKey:"settings.aiworker.visual.option.messageTransport.auto.description"},{id:"ws",labelKey:"settings.aiworker.visual.option.messageTransport.ws.label",descriptionKey:"settings.aiworker.visual.option.messageTransport.ws.description"},{id:"sse",labelKey:"settings.aiworker.visual.option.messageTransport.sse.label",descriptionKey:"settings.aiworker.visual.option.messageTransport.sse.description"}],Df=[{id:"collapsed",labelKey:"settings.aiworker.visual.option.activityRenderMode.collapsed.label",descriptionKey:"settings.aiworker.visual.option.activityRenderMode.collapsed.description"},{id:"summary",labelKey:"settings.aiworker.visual.option.activityRenderMode.summary.label",descriptionKey:"settings.aiworker.visual.option.activityRenderMode.summary.description"}],Go=[{id:"auto",labelKey:"settings.aiworker.visual.option.timeFormat.auto.label",descriptionKey:"settings.aiworker.visual.option.timeFormat.auto.description"},{id:"24h",labelKey:"settings.aiworker.visual.option.timeFormat.24h.label",descriptionKey:"settings.aiworker.visual.option.timeFormat.24h.description"},{id:"12h",labelKey:"settings.aiworker.visual.option.timeFormat.12h.label",descriptionKey:"settings.aiworker.visual.option.timeFormat.12h.description"}],Wo=[{id:"auto",labelKey:"settings.aiworker.visual.option.weekStart.auto.label",descriptionKey:"settings.aiworker.visual.option.weekStart.auto.description"},{id:"monday",labelKey:"settings.aiworker.visual.option.weekStart.monday.label"},{id:"sunday",labelKey:"settings.aiworker.visual.option.weekStart.sunday.label"}],Mf=[{id:"steer",labelKey:"settings.aiworker.visual.option.followUpBehavior.steer.label"},{id:"queue",labelKey:"settings.aiworker.visual.option.followUpBehavior.queue.label"}],Rf=[{id:"ask",labelKey:"settings.aiworker.visual.option.largeTextPaste.ask.label"},{id:"attach",labelKey:"settings.aiworker.visual.option.largeTextPaste.attach.label"},{id:"inline",labelKey:"settings.aiworker.visual.option.largeTextPaste.inline.label"}],Of=t=>t==="markdown"?"markdown":"plain",Lf=[{id:"left",labelKey:"settings.aiworker.desktopNetwork.option.windowControlsLeft"},{id:"right",labelKey:"settings.aiworker.desktopNetwork.option.windowControlsRight"}],Ff=[{id:"classic",labelKey:"settings.aiworker.desktopNetwork.option.windowControlsClassic"},{id:"traffic-lights",labelKey:"settings.aiworker.desktopNetwork.option.windowControlsTrafficLights"}],yi=({visibleSettings:t})=>{const{locale:e,locales:a,setLocale:n,label:i,t:r}=at(),l=o.useCallback(m=>r(m),[r]),{isMobile:u}=ma(),{terminal:p}=fl(),{browserTab:h}=Ld(),d=wd(),w=de(m=>m.showReasoningTraces),c=de(m=>m.sessionRecapEnabled),N=de(m=>m.sessionSuggestionEnabled),v=de(m=>m.setSessionRecapEnabled),C=de(m=>m.setSessionSuggestionEnabled),y=de(m=>m.sessionGoalEnabled),S=de(m=>m.setSessionGoalEnabled),g=de(m=>m.sessionGoalDefaultBudgetEnabled),T=de(m=>m.setSessionGoalDefaultBudgetEnabled),R=de(m=>m.sessionGoalDefaultBudget),A=de(m=>m.setSessionGoalDefaultBudget),j=de(m=>m.setShowReasoningTraces),f=de(m=>m.streamingAutoFollowEnabled),b=de(m=>m.setStreamingAutoFollowEnabled),F=de(m=>m.collapsibleThinkingBlocks),D=de(m=>m.setCollapsibleThinkingBlocks),P=de(m=>m.mermaidRenderingMode),I=de(m=>m.setMermaidRenderingMode),U=de(m=>m.userMessageRenderingMode),q=de(m=>m.setUserMessageRenderingMode),k=de(m=>m.collapsibleUserMessages),$=de(m=>m.setCollapsibleUserMessages),G=de(m=>m.stickyUserHeader),E=de(m=>m.promptNavigatorEnabled),J=de(m=>m.setStickyUserHeader),X=de(m=>m.setPromptNavigatorEnabled),L=de(m=>m.autoSaveEnabled),se=de(m=>m.setAutoSaveEnabled),z=de(m=>m.wideChatLayoutEnabled),V=de(m=>m.setWideChatLayoutEnabled),_=de(m=>m.codeBlockLineWrap),K=de(m=>m.setCodeBlockLineWrap),Z=de(m=>m.chatRenderMode),Y=de(m=>m.setChatRenderMode),te=de(m=>m.activityRenderMode),ge=de(m=>m.setActivityRenderMode),le=de(m=>m.fontSize),he=de(m=>m.setFontSize),ne=de(m=>m.terminalFontSize),ae=de(m=>m.setTerminalFontSize),me=de(m=>m.terminalShell),Pe=de(m=>m.setTerminalShell),Ne=de(m=>m.terminalLoginShells),Se=de(m=>m.setTerminalLoginShells),be=de(m=>m.editorFontSize),Ke=de(m=>m.setEditorFontSize),Le=de(m=>m.uiFont),oe=de(m=>m.setUiFont),xe=de(m=>m.monoFont),Ee=de(m=>m.setMonoFont),Ve=de(m=>m.padding),$e=de(m=>m.setPadding),We=de(m=>m.inputBarOffset),Fe=de(m=>m.setInputBarOffset),ie=de(m=>m.mobileKeyboardMode),re=de(m=>m.setMobileKeyboardMode),je=de(m=>m.diffLayoutPreference),ve=de(m=>m.setDiffLayoutPreference),Re=de(m=>m.showTerminalQuickKeysOnDesktop),Ae=de(m=>m.sessionTabsEnabled),ye=de(m=>m.setSessionTabsEnabled),He=de(m=>m.setShowTerminalQuickKeysOnDesktop),ue=de(m=>m.fileEditorKeymap),Ce=de(m=>m.setFileEditorKeymap),De=$r(m=>m.followUpBehavior),Ye=$r(m=>m.setFollowUpBehavior),W=de(m=>m.persistChatDraft),ke=de(m=>m.setPersistChatDraft),Ie=de(m=>m.inputSpellcheckEnabled),Ge=de(m=>m.setInputSpellcheckEnabled),it=de(m=>m.largeTextPasteBehavior),nt=de(m=>m.setLargeTextPasteBehavior),dt=de(m=>m.showToolFileIcons),xt=de(m=>m.setShowToolFileIcons),H=de(m=>m.showTurnChangedFiles),Be=de(m=>m.setShowTurnChangedFiles),tt=de(m=>m.showExpandedBashTools),rt=de(m=>m.setShowExpandedBashTools),ut=de(m=>m.showExpandedEditTools),Ct=de(m=>m.setShowExpandedEditTools),et=de(m=>m.timeFormatPreference),Xe=de(m=>m.setTimeFormatPreference),ft=de(m=>m.weekStartPreference),ze=de(m=>m.setWeekStartPreference),jt=de(m=>m.showSplitAssistantMessageActions),Te=de(m=>m.setShowSplitAssistantMessageActions),wt=de(m=>m.allowPromptingSubagentSessions),Q=de(m=>m.setAllowPromptingSubagentSessions),fe=de(m=>m.draftStartersVisible),Ue=de(m=>m.setDraftStartersVisible),Me=Ze(m=>m.settingsMessageStreamTransport),ct=Ze(m=>m.setSettingsMessageStreamTransport),lt=Me,Qe=Ze(m=>m.settingsDefaultFileViewerPreview),Nt=Ze(m=>m.setSettingsDefaultFileViewerPreview),xs=de(m=>m.isSettingsDialogOpen),{themeMode:ts,setThemeMode:Ms,availableThemes:Bt,customThemesLoading:ls,reloadCustomThemes:Wt,lightThemeId:vs,darkThemeId:ps,setLightThemePreference:ys,setDarkThemePreference:ms}=xr(),[bs,ce]=o.useState(!1),ht=o.useMemo(()=>os()&&typeof window<"u"&&window.__AIWORKER_PLATFORM__==="darwin",[]),bt=de(m=>m.dockBadgeEnabled),Qt=de(m=>m.setDockBadgeEnabled),Yt=jd(),Ht=de(m=>m.desktopWindowControlsPosition),as=de(m=>m.setDesktopWindowControlsPosition),ws=de(m=>m.desktopWindowControlsStyle),cs=de(m=>m.setDesktopWindowControlsStyle),[St,Tt]=o.useState(0),Vt=de(m=>m.reportUsage),Mt=de(m=>m.setReportUsage),is=o.useCallback(m=>{Mt(m),yt({reportUsage:m})},[Mt]),As=o.useCallback(m=>{as(m),yt({desktopWindowControlsPosition:m})},[as]),bi=o.useCallback(m=>{cs(m),yt({desktopWindowControlsStyle:m})},[cs]),Ba=(xs||u||us())&&(t?t.includes("chatRenderMode"):!0);o.useEffect(()=>{if(!Ba)return;let m=null,vt=Date.now();const Zt=()=>{const kt=Date.now();kt-vt>=420&&(Tt(Gt=>(Gt+1)%24),vt=kt),m=requestAnimationFrame(Zt)};(typeof document>"u"||document.visibilityState==="visible")&&(m=requestAnimationFrame(Zt));const Xt=()=>{document.visibilityState==="visible"&&m===null?m=requestAnimationFrame(Zt):document.visibilityState!=="visible"&&m!==null&&(cancelAnimationFrame(m),m=null)};return document.addEventListener("visibilitychange",Xt),()=>{document.removeEventListener("visibilitychange",Xt),m!==null&&cancelAnimationFrame(m)}},[Ba]);const wi=o.useCallback(m=>{q(m),yt({userMessageRenderingMode:m})},[q]),ji=o.useCallback(m=>{J(m),yt({stickyUserHeader:m})},[J]),Fs=o.useCallback(m=>{X(m),yt({promptNavigatorEnabled:m})},[X]),ga=o.useCallback(m=>{Ue(m),yt({draftStartersVisible:m})},[Ue]),ki=o.useCallback(m=>{$(m),yt({collapsibleUserMessages:m})},[$]),Ha=o.useCallback(m=>{V(m),yt({wideChatLayoutEnabled:m})},[V]),Ni=o.useCallback(m=>{Te(m),yt({showSplitAssistantMessageActions:m})},[Te]),Si=o.useCallback(m=>{Ge(m),yt({inputSpellcheckEnabled:m})},[Ge]),Ci=o.useCallback(m=>{Y(m),yt({chatRenderMode:m})},[Y]),Pi=o.useCallback(m=>{ct(m),yt({messageStreamTransport:m})},[ct]),Ii=o.useCallback(m=>{ge(m),yt({activityRenderMode:m})},[ge]),js=o.useCallback(m=>{I(m),yt({mermaidRenderingMode:m})},[I]),Hs=o.useCallback(m=>{xt(m),yt({showToolFileIcons:m})},[xt]),Yn=o.useCallback(m=>{Be(m),yt({showTurnChangedFiles:m})},[Be]),ln=o.useCallback(m=>{Nt(m),yt({defaultFileViewerPreview:m}),window.dispatchEvent(new CustomEvent("aiworker:file-viewer-preview-mode-changed",{detail:{enabled:m}}))},[Nt]),kn=o.useCallback(m=>{rt(m),yt({showExpandedBashTools:m})},[rt]),Pr=o.useCallback(m=>{Ct(m),yt({showExpandedEditTools:m})},[Ct]),Qs=o.useCallback(m=>{Xe(m),yt({timeFormatPreference:m})},[Xe]),Ai=o.useCallback(m=>{ze(m),yt({weekStartPreference:m})},[ze]),cn=o.useMemo(()=>Bt.filter(m=>m.metadata.variant==="light").sort((m,vt)=>m.metadata.name.localeCompare(vt.metadata.name)),[Bt]),dn=o.useMemo(()=>Bt.filter(m=>m.metadata.variant==="dark").sort((m,vt)=>m.metadata.name.localeCompare(vt.metadata.name)),[Bt]),un=o.useMemo(()=>cn.find(m=>m.metadata.id===vs)??cn[0],[cn,vs]),Rn=o.useMemo(()=>dn.find(m=>m.metadata.id===ps)??dn[0],[dn,ps]),Zn=o.useCallback((m,vt)=>{const Zt=vt==="dark"?" Dark":" Light";return m.endsWith(Zt)?m.slice(0,-Zt.length):m},[]),pe=m=>t?t.includes(m):!0,ds=us(),On=pe("theme")&&!ds,Ln=pe("windowControlsPosition")&&Yt,Ga=pe("theme")||pe("timeFormat")||pe("weekStart"),fa=ds?Ga:pe("theme")||Ln||pe("pwaInstallName")||pe("pwaOrientation")||pe("timeFormat")||pe("weekStart"),Wa=pe("fontSize")||pe("terminalFontSize")||pe("editorFontSize")||pe("spacing")||pe("inputBarOffset")&&u,ha=pe("terminalQuickKeys")&&!u||(pe("terminalShell")||pe("terminalLoginShell"))&&!ds||pe("fileEditorKeymap")||pe("autoSaveEnabled")||pe("sessionTabs")&&!ds&&!u,Xn=pe("mermaidRendering")||pe("sessionGoal")&&!ds||pe("userMessageRendering")||pe("chatRenderMode")||pe("messageTransport")||pe("activityRenderMode")&&Z==="sorted"||pe("collapsibleUserMessages")||pe("stickyUserHeader")||pe("promptNavigatorEnabled")&&!ds||pe("wideChatLayout")||pe("codeBlockLineWrap")||pe("splitAssistantMessageActions")||pe("subagentReadOnlyBanner")||pe("diffLayout")||pe("dotfiles")||pe("fileViewerPreview")||pe("reasoning")||pe("followUpBehavior")||pe("persistDraft")||pe("largeTextPaste")||pe("showToolFileIcons")||pe("expandedTools")||!u&&pe("inputSpellcheck"),pn=pe("chatRenderMode")||pe("activityRenderMode")&&Z==="sorted",ea=pe("messageTransport"),qa=pe("userMessageRendering")||pe("mermaidRendering")||pe("diffLayout")&&!ds||pe("followUpBehavior"),ta=pe("sessionAssist")||pe("sessionGoal")&&!ds||pe("subagentReadOnlyBanner")||pe("collapsibleUserMessages")||pe("stickyUserHeader")||pe("promptNavigatorEnabled")&&!ds||pe("wideChatLayout")||pe("codeBlockLineWrap")||pe("splitAssistantMessageActions")||pe("dotfiles")||pe("fileViewerPreview")||pe("persistDraft")||pe("largeTextPaste")||pe("showToolFileIcons")||pe("showTurnChangedFiles")||!u&&pe("inputSpellcheck")||pe("reasoning")||pe("expandedTools"),sa=fa||Wa||ha,Gs=pe("pwaInstallName")&&Vn()&&h&&!os()&&!ds,Nn=pe("pwaOrientation")&&Vn()&&!os()&&!ds,Sn=pe("mobileKeyboardMode")&&Vn()&&!os()&&!ds&&kd(),na=(pe("terminalShell")||pe("terminalLoginShell"))&&!ds,[xa,va]=o.useState([]),[Ti,Ei]=o.useState(0);o.useEffect(()=>Nl(()=>{va([]),Ei(m=>m+1)}),[]),o.useEffect(()=>{let m=!1;if(!(!na||!p.listShells))return p.listShells().then(vt=>{m||va(vt)}).catch(()=>{m||va([])}),()=>{m=!0}},[na,p,Ti]);const Di=o.useMemo(()=>{const m=xa.filter(vt=>vt.id!=="auto");return me==="auto"||m.some(vt=>vt.id===me)?m:[{id:me,name:me,supportsLogin:!1},...m]},[xa,me]),Fn=xa.find(m=>m.id===me)?.supportsLogin===!0,aa=Ne.includes(me),ya=m=>{Se(m?[...Ne.filter(vt=>vt!==me),me]:Ne.filter(vt=>vt!==me))},[ba,x]=o.useState(""),[ee,Oe]=o.useState("system"),st=o.useMemo(()=>{const m=Go.find(vt=>vt.id===et);return l(m?.labelKey??"settings.aiworker.visual.option.timeFormat.auto.label")},[et,l]),zt=o.useMemo(()=>{const m=Wo.find(vt=>vt.id===ft);return l(m?.labelKey??"settings.aiworker.visual.option.weekStart.auto.label")},[ft,l]),Ts=o.useMemo(()=>{const m=Vo.find(vt=>vt.id===ee);return m?l(m.labelKey):void 0},[ee,l]),ks=o.useMemo(()=>{const m=Bo.find(vt=>vt.id===ie);return m?l(m.labelKey):void 0},[ie,l]),Rs=o.useCallback(async m=>{if(typeof window>"u")return;const vt=window,Xt=m.trim().replace(/\s+/g," ").slice(0,64);if(await yt({pwaAppName:Xt}),typeof vt.__AIWORKER_SET_PWA_INSTALL_NAME__=="function"){const kt=vt.__AIWORKER_SET_PWA_INSTALL_NAME__(Xt);x(kt);return}x(Xt||Aa),vt.__AIWORKER_UPDATE_PWA_MANIFEST__?.()},[]),gs=o.useCallback(async m=>{if(typeof window>"u")return;const vt=window,Zt=Wi(m);if(await yt({pwaOrientation:Zt}),typeof vt.__AIWORKER_SET_PWA_ORIENTATION__=="function"){const Xt=vt.__AIWORKER_SET_PWA_ORIENTATION__(Zt);Oe(Xt);return}Oe(Zt),vt.__AIWORKER_UPDATE_PWA_MANIFEST__?.()},[]);return o.useEffect(()=>{if(typeof window>"u"||!Gs&&!Nn&&!Sn)return;let m=!1;return(async()=>{try{const Zt=await pt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"},cache:"no-store"});if(!Zt.ok){m||x(Aa);return}const Xt=await Zt.json().catch(()=>({})),Gt=(typeof Xt?.pwaAppName=="string"?Xt.pwaAppName:"").trim().replace(/\s+/g," ").slice(0,64),Ys=Wi(Xt?.pwaOrientation),Dt=Wr(Xt?.mobileKeyboardMode);m||(Gs&&x(Gt||Aa),Nn&&Oe(Ys),Sn&&re(Dt))}catch{m||(Gs&&x(Aa),Nn&&Oe("system"),Sn&&re("native"))}})(),()=>{m=!0}},[re,Sn,Gs,Nn]),s.jsxs("div",{className:"space-y-0",children:[fa&&s.jsxs("div",{className:"space-y-0",children:[On&&s.jsxs(_e,{title:r("settings.aiworker.visual.section.colorModeAndTheme"),divider:!1,children:[s.jsxs(En,{children:[s.jsx("div",{className:Ws,children:s.jsx(mn,{"aria-label":r("settings.aiworker.visual.section.colorMode"),children:Pf.map(m=>s.jsx(gn,{selected:ts===m.value,onSelect:()=>Ms(m.value),label:l(m.labelKey),ariaLabel:l(m.labelKey)},m.value))})}),s.jsxs("div",{className:Ws,children:[s.jsx(qt,{label:r("settings.aiworker.visual.field.lightTheme"),settingsItem:"appearance.light-theme",children:s.jsxs(Pt,{value:un?.metadata.id??"",onValueChange:ys,children:[s.jsx(It,{"aria-label":r("settings.aiworker.visual.field.selectLightThemeAria"),size:Lt,className:Cn,children:s.jsx(Rt,{placeholder:r("settings.aiworker.visual.field.selectThemePlaceholder"),children:un?Zn(un.metadata.name,"light"):void 0})}),s.jsx(At,{children:cn.map(m=>s.jsx(ot,{value:m.metadata.id,children:Zn(m.metadata.name,"light")},m.metadata.id))})]})}),s.jsx(qt,{label:r("settings.aiworker.visual.field.darkTheme"),settingsItem:"appearance.dark-theme",children:s.jsxs(Pt,{value:Rn?.metadata.id??"",onValueChange:ms,children:[s.jsx(It,{"aria-label":r("settings.aiworker.visual.field.selectDarkThemeAria"),size:Lt,className:Cn,children:s.jsx(Rt,{placeholder:r("settings.aiworker.visual.field.selectThemePlaceholder"),children:Rn?Zn(Rn.metadata.name,"dark"):void 0})}),s.jsx(At,{children:dn.map(m=>s.jsx(ot,{value:m.metadata.id,children:Zn(m.metadata.name,"dark")},m.metadata.id))})]})}),s.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[s.jsxs("button",{type:"button",disabled:ls||bs,onClick:()=>{const m=Date.now();ce(!0),Wt().finally(()=>{const vt=Date.now()-m;if(vt<500){window.setTimeout(()=>{ce(!1)},500-vt);return}ce(!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(O,{name:"restart",className:we("h-3.5 w-3.5",bs&&"animate-spin")}),r(bs?"settings.aiworker.visual.actions.reloadingThemes":"settings.aiworker.visual.actions.reloadThemes")]}),s.jsx(Jt,{children:r("settings.aiworker.visual.field.themeImportInfoTooltip")})]})]})]}),ht&&s.jsx(Ua,{settingsItem:"appearance.dock-badge",children:s.jsx(gt,{checked:bt,onChange:Qt,label:r("settings.aiworker.visual.field.dockBadge"),info:r("settings.aiworker.visual.field.dockBadgeHint"),ariaLabel:r("settings.aiworker.visual.field.dockBadge")})})]}),Ln&&s.jsx(_e,{title:r("settings.aiworker.desktopNetwork.field.windowControls"),info:r("settings.aiworker.desktopNetwork.field.windowControlsPositionDescription"),divider:On,children:s.jsxs(En,{children:[s.jsx(qt,{label:r("settings.aiworker.desktopNetwork.field.windowControlsPosition"),settingsItem:"sessions.desktop-window-controls-position",children:s.jsx(qs,{value:Ht,options:Lf.map(m=>({value:m.id,label:l(m.labelKey)})),onChange:As,"aria-label":r("settings.aiworker.desktopNetwork.field.windowControlsPositionAria")})}),s.jsx(qt,{label:r("settings.aiworker.desktopNetwork.field.windowControlsStyle"),settingsItem:"sessions.desktop-window-controls-style",children:s.jsx(qs,{value:ws,options:Ff.map(m=>({value:m.id,label:l(m.labelKey)})),onChange:bi,"aria-label":r("settings.aiworker.desktopNetwork.field.windowControlsStyleAria")})})]})}),Ga&&s.jsx(_e,{title:r("settings.aiworker.visual.section.localization"),children:s.jsxs(En,{children:[s.jsx(qt,{label:r("settings.appearance.language.label"),info:r("settings.appearance.language.description"),settingsItem:"appearance.language",children:s.jsxs(Pt,{value:e,onValueChange:m=>n(m),children:[s.jsx(It,{"aria-label":r("settings.appearance.language.select"),size:Lt,className:Cn,children:s.jsx(Rt,{children:i(e)})}),s.jsx(At,{children:a.map(m=>s.jsx(ot,{value:m,children:i(m)},m))})]})}),(pe("timeFormat")||pe("weekStart"))&&s.jsxs("div",{className:Ws,children:[pe("timeFormat")&&s.jsx(qt,{label:r("settings.aiworker.visual.field.timeFormat"),settingsItem:"appearance.time-format",children:s.jsxs(Pt,{value:et,onValueChange:m=>Qs(m),children:[s.jsx(It,{"aria-label":r("settings.aiworker.visual.field.selectTimeFormatAria"),size:Lt,className:Cn,children:s.jsx(Rt,{children:st})}),s.jsx(At,{children:Go.map(m=>s.jsx(ot,{value:m.id,children:l(m.labelKey)},m.id))})]})}),pe("weekStart")&&s.jsx(qt,{label:r("settings.aiworker.visual.field.weekStartsOn"),settingsItem:"appearance.week-start",children:s.jsxs(Pt,{value:ft,onValueChange:m=>Ai(m),children:[s.jsx(It,{"aria-label":r("settings.aiworker.visual.field.selectWeekStartAria"),size:Lt,className:Cn,children:s.jsx(Rt,{children:zt})}),s.jsx(At,{children:Wo.map(m=>s.jsx(ot,{value:m.id,children:l(m.labelKey)},m.id))})]})})]})]})}),(Gs||Nn||Sn)&&s.jsxs(_e,{title:r("settings.aiworker.visual.section.appInstall"),contentClassName:Ws,children:[Gs&&s.jsxs(Ot,{label:r("settings.aiworker.visual.field.installAppName"),info:r("settings.aiworker.visual.field.installAppNameHint"),settingsItem:"appearance.pwa-install-name",alignEnd:!1,controlClassName:zs,children:[s.jsx(Je,{value:ba,onChange:m=>{x(m.target.value)},onBlur:()=>{Rs(ba)},onKeyDown:m=>{m.key==="Enter"&&(m.preventDefault(),Rs(ba))},className:"min-w-0 flex-1",maxLength:64,"aria-label":r("settings.aiworker.visual.field.pwaInstallAppNameAria")}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>{x(Aa),Rs("")},className:fs,"aria-label":r("settings.aiworker.visual.actions.resetInstallAppNameAria"),title:r("settings.common.actions.reset"),children:s.jsx(O,{name:"restart",className:"h-3.5 w-3.5"})})]}),Nn&&s.jsxs(Ot,{label:r("settings.aiworker.visual.field.installOrientation"),description:r("settings.aiworker.visual.field.installOrientationHint"),settingsItem:"appearance.pwa-orientation",alignEnd:!1,controlClassName:zs,children:[s.jsxs(Pt,{value:ee,onValueChange:m=>{const vt=Wi(m);Oe(vt),gs(vt)},children:[s.jsx(It,{"aria-label":r("settings.aiworker.visual.field.pwaInstallOrientationAria"),size:Lt,className:Mr,children:s.jsx(Rt,{placeholder:r("settings.aiworker.visual.field.selectOrientationPlaceholder"),children:Ts})}),s.jsx(At,{children:Vo.map(m=>s.jsx(ot,{value:m.id,children:l(m.labelKey)},m.id))})]}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>{Oe("system"),gs("system")},disabled:ee==="system",className:fs,"aria-label":r("settings.aiworker.visual.actions.resetInstallOrientationAria"),title:r("settings.common.actions.reset"),children:s.jsx(O,{name:"restart",className:"h-3.5 w-3.5"})})]}),Sn&&s.jsxs(Ot,{label:r("settings.aiworker.visual.field.mobileKeyboardMode"),info:r("settings.aiworker.visual.field.mobileKeyboardModeHint"),settingsItem:"appearance.mobile-keyboard-mode",alignEnd:!1,controlClassName:zs,children:[s.jsxs(Pt,{value:ie,onValueChange:m=>{const vt=Wr(m);re(vt),yt({mobileKeyboardMode:vt})},children:[s.jsx(It,{"aria-label":r("settings.aiworker.visual.field.mobileKeyboardModeAria"),size:Lt,className:Mr,children:s.jsx(Rt,{placeholder:r("settings.aiworker.visual.field.selectMobileKeyboardModePlaceholder"),children:ks})}),s.jsx(At,{children:Bo.map(m=>s.jsx(ot,{value:m.id,children:l(m.labelKey)},m.id))})]}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>{re("native"),yt({mobileKeyboardMode:"native"})},disabled:ie==="native",className:fs,"aria-label":r("settings.aiworker.visual.actions.resetMobileKeyboardModeAria"),title:r("settings.common.actions.reset"),children:s.jsx(O,{name:"restart",className:"h-3.5 w-3.5"})})]})]})]}),Wa&&s.jsxs(_e,{title:r("settings.aiworker.visual.section.densityAndType"),contentClassName:Ws,children:[pe("fontSize")&&!u||pe("terminalFontSize")?s.jsxs(En,{children:[pe("fontSize")&&!u&&s.jsxs(qt,{label:r("settings.aiworker.visual.field.interfaceFont"),settingsItem:"appearance.interface-font-size",controlClassName:"w-full",children:[s.jsxs(Pt,{value:Le,onValueChange:m=>oe(m),children:[s.jsx(It,{"aria-label":r("settings.aiworker.visual.field.selectInterfaceFontAria"),size:Lt,className:Cn,children:s.jsx(Rt,{children:Vr.find(m=>m.id===Le)?.label})}),s.jsx(At,{children:Vr.map(m=>s.jsx(ot,{value:m.id,children:s.jsx("span",{style:{fontFamily:m.stack},children:m.label})},m.id))})]}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>oe(Br),disabled:Le===Br,className:fs,"aria-label":r("settings.aiworker.visual.actions.resetInterfaceFontAria"),title:r("settings.common.actions.reset"),children:s.jsx(O,{name:"restart",className:"h-3.5 w-3.5"})})]}),pe("terminalFontSize")&&s.jsxs(qt,{label:r("settings.aiworker.visual.field.codeFont"),controlClassName:"w-full",children:[s.jsxs(Pt,{value:xe,onValueChange:m=>Ee(m),children:[s.jsx(It,{"aria-label":r("settings.aiworker.visual.field.selectCodeFontAria"),size:Lt,className:Cn,children:s.jsx(Rt,{children:Hr.find(m=>m.id===xe)?.label})}),s.jsx(At,{children:Hr.map(m=>s.jsx(ot,{value:m.id,children:s.jsx("span",{style:{fontFamily:m.stack},children:m.label})},m.id))})]}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>Ee(Gr),disabled:xe===Gr,className:fs,"aria-label":r("settings.aiworker.visual.actions.resetCodeFontAria"),title:r("settings.common.actions.reset"),children:s.jsx(O,{name:"restart",className:"h-3.5 w-3.5"})})]})]}):null,pe("fontSize")&&!u||pe("terminalFontSize")||pe("editorFontSize")?s.jsxs(En,{children:[pe("fontSize")&&!u&&s.jsx(qt,{label:r("settings.aiworker.visual.field.interfaceFontSize"),controlClassName:"w-full",children:s.jsxs("div",{className:ja,children:[s.jsx(Ss,{value:le,onValueChange:he,min:50,max:200,step:5,className:Ps,"aria-label":r("settings.aiworker.visual.field.fontSizePercentageAria")}),s.jsx("span",{className:ka,children:"%"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>he(100),disabled:le===100,className:fs,"aria-label":r("settings.aiworker.visual.actions.resetFontSizeAria"),title:r("settings.common.actions.reset"),children:s.jsx(O,{name:"restart",className:"h-3.5 w-3.5"})})]})}),pe("terminalFontSize")&&s.jsx(qt,{label:r("settings.aiworker.visual.field.terminalFontSize"),settingsItem:"appearance.terminal-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:ja,children:[s.jsx(Ss,{value:ne,onValueChange:ae,min:9,max:52,step:1,className:Ps}),s.jsx("span",{className:ka,children:"px"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>ae(13),disabled:ne===13,className:fs,"aria-label":r("settings.aiworker.visual.actions.resetTerminalFontSizeAria"),title:r("settings.common.actions.reset"),children:s.jsx(O,{name:"restart",className:"h-3.5 w-3.5"})})]})}),pe("editorFontSize")&&s.jsx(qt,{label:r("settings.aiworker.visual.field.editorFontSize"),settingsItem:"appearance.editor-font-size",controlClassName:"w-full",children:s.jsxs("div",{className:ja,children:[s.jsx(Ss,{value:be,onValueChange:Ke,min:9,max:32,step:1,className:Ps}),s.jsx("span",{className:ka,children:"px"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>Ke(13),disabled:be===13,className:fs,"aria-label":r("settings.aiworker.visual.actions.resetEditorFontSizeAria"),title:r("settings.common.actions.reset"),children:s.jsx(O,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null,pe("spacing")||pe("inputBarOffset")&&u?s.jsxs(En,{children:[pe("spacing")&&s.jsx(qt,{label:r("settings.aiworker.visual.field.spacingDensity"),settingsItem:"appearance.spacing-density",controlClassName:"w-full",children:s.jsxs("div",{className:ja,children:[s.jsx(Ss,{value:Ve,onValueChange:$e,min:50,max:200,step:5,className:Ps}),s.jsx("span",{className:ka,children:"%"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>$e(100),disabled:Ve===100,className:fs,"aria-label":r("settings.aiworker.visual.actions.resetSpacingAria"),title:r("settings.common.actions.reset"),children:s.jsx(O,{name:"restart",className:"h-3.5 w-3.5"})})]})}),pe("inputBarOffset")&&u&&s.jsx(qt,{label:r("settings.aiworker.visual.field.inputBarOffset"),info:r("settings.aiworker.visual.field.inputBarOffsetTooltip"),settingsItem:"appearance.input-bar-offset",controlClassName:"w-full",children:s.jsxs("div",{className:ja,children:[s.jsx(Ss,{value:We,onValueChange:Fe,min:0,max:100,step:5,className:Ps}),s.jsx("span",{className:ka,children:"px"}),s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:()=>Fe(0),disabled:We===0,className:fs,"aria-label":r("settings.aiworker.visual.actions.resetInputBarOffsetAria"),title:r("settings.common.actions.reset"),children:s.jsx(O,{name:"restart",className:"h-3.5 w-3.5"})})]})})]}):null]}),ha&&s.jsxs(_e,{title:r("settings.aiworker.visual.section.navigation"),contentClassName:"space-y-4",children:[pe("fileEditorKeymap")&&s.jsx(Ls,{title:r("settings.aiworker.visual.field.fileEditorKeymap"),settingsItem:"appearance.file-editor-keymap",children:s.jsx(mn,{"aria-label":r("settings.aiworker.visual.field.fileEditorKeymap"),children:["default","vim"].map(m=>s.jsx(gn,{selected:ue===m,onSelect:()=>Ce(m),label:r(`settings.aiworker.visual.option.fileEditorKeymap.${m}`),ariaLabel:r(`settings.aiworker.visual.option.fileEditorKeymap.${m}`)},m))})}),s.jsxs("div",{className:hs,children:[pe("autoSaveEnabled")&&s.jsx(gt,{checked:L,onChange:se,label:r("settings.aiworker.visual.field.autoSaveEnabled"),ariaLabel:r("settings.aiworker.visual.field.autoSaveEnabledAria"),info:r("settings.aiworker.visual.field.autoSaveEnabledInfo"),settingsItem:"appearance.auto-save-enabled"}),na&&s.jsx(qt,{label:r("settings.aiworker.visual.field.terminalShell"),info:r("settings.aiworker.visual.field.terminalShellHint"),settingsItem:"appearance.terminal-shell",className:"pt-2",children:s.jsxs(Pt,{value:me,onValueChange:m=>{Nd(m)&&Pe(m)},children:[s.jsx(It,{"aria-label":r("settings.aiworker.visual.field.terminalShellAria"),size:Lt,className:Cn,children:s.jsx(Rt,{})}),s.jsxs(At,{children:[s.jsx(ot,{value:"auto",children:r("settings.aiworker.visual.option.terminalShell.auto")}),Di.map(m=>s.jsx(ot,{value:m.id,children:m.name},m.id))]})]})}),na&&Fn&&s.jsx(gt,{checked:aa,onChange:ya,label:r("settings.aiworker.visual.field.terminalLoginShell"),ariaLabel:r("settings.aiworker.visual.field.terminalLoginShell"),settingsItem:"appearance.terminal-login-shell"}),pe("terminalQuickKeys")&&!u&&s.jsx(gt,{checked:Re,onChange:He,label:r("settings.aiworker.visual.field.terminalQuickKeys"),ariaLabel:r("settings.aiworker.visual.field.terminalQuickKeysAria"),settingsItem:"appearance.terminal-quick-keys",info:r("settings.aiworker.visual.field.terminalQuickKeysTooltip",{control:Hn("ctrl"),alt:Hn("alt")})})]}),pe("sessionTabs")&&!ds&&!u&&s.jsx(Ls,{title:r("settings.aiworker.visual.field.sessionTabsGroup"),settingsItem:"appearance.session-tabs",children:s.jsx(gt,{checked:Ae,onChange:ye,label:r("settings.aiworker.visual.field.sessionTabs"),ariaLabel:r("settings.aiworker.visual.field.sessionTabsAria"),info:r("settings.aiworker.visual.field.sessionTabsInfo")})})]}),Xn&&s.jsxs(s.Fragment,{children:[pn&&s.jsxs(_e,{title:r("settings.aiworker.visual.section.chatDisplay"),divider:sa,contentClassName:"space-y-6",children:[pe("chatRenderMode")&&s.jsx(Ls,{title:r("settings.aiworker.visual.section.chatRenderMode"),settingsItem:"chat.render-mode",children:s.jsx("div",{role:"radiogroup","aria-label":r("settings.aiworker.visual.section.chatRenderModeAria"),className:"grid w-full max-w-[26rem] grid-cols-1 gap-3 @xl:grid-cols-2",children:Ef.map(m=>{const vt=Z===m.id,Zt=St%12;return s.jsxs("button",{type:"button",onClick:()=>Ci(m.id),"aria-pressed":vt,className:we("flex flex-col items-start gap-1 rounded-lg border p-3 text-left transition-colors",vt?"border-primary bg-primary/5":"border-border hover:border-border/80 hover:bg-muted/50"),children:[s.jsx("span",{className:we("typography-ui-label",vt?"text-foreground":"text-muted-foreground"),children:l(m.labelKey)}),s.jsx("div",{className:"mt-2 w-full rounded-md border border-border/60 bg-muted/30 p-2",children:m.id==="live"?s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Xt=>{const kt=Xt*3+1,Gt=Zt-kt+1,Ys=Gt<=0?0:Gt===1?42:Gt===2?68:92,Dt=Ys>0;return s.jsxs("div",{className:we("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",Dt?"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:`${Ys}%`}})]},Xt)})}):s.jsx("div",{className:"space-y-1.5",children:[0,1,2].map(Xt=>{const kt=Zt>=(Xt+1)*3;return s.jsxs("div",{className:we("flex items-center gap-1.5 transition-all duration-300 motion-reduce:transition-none",kt?"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%"}})]},Xt)})})})]},m.id)})})}),pe("activityRenderMode")&&Z==="sorted"&&s.jsx(Ls,{title:r("settings.aiworker.visual.section.activityDefault"),children:s.jsx(mn,{"aria-label":r("settings.aiworker.visual.section.activityDefaultAria"),children:Df.map(m=>s.jsx(gn,{selected:te===m.id,onSelect:()=>Ii(m.id),label:l(m.labelKey),ariaLabel:r("settings.aiworker.visual.field.activityDefaultModeAria",{option:l(m.labelKey)})},m.id))})})]}),ea&&s.jsxs(_e,{title:r("settings.aiworker.visual.section.messageStreamTransport"),divider:pn||sa,settingsItem:"chat.message-transport",contentClassName:"space-y-2",children:[s.jsx(qs,{value:lt,options:Ho.map(m=>({value:m.id,label:l(m.labelKey)})),onChange:Pi,"aria-label":r("settings.aiworker.visual.section.messageStreamTransport")}),(()=>{const m=Ho.find(vt=>vt.id===lt);return m?.descriptionKey?s.jsx("span",{className:"typography-meta text-muted-foreground",children:l(m.descriptionKey)}):null})()]}),qa&&s.jsx(_e,{title:r("settings.aiworker.visual.section.chatMessageOptions"),divider:pn||ea||sa,children:s.jsxs(En,{className:"lg:gap-y-6",children:[pe("userMessageRendering")&&s.jsx(Ls,{title:r("settings.aiworker.visual.section.userMessageRendering"),children:s.jsx(mn,{"aria-label":r("settings.aiworker.visual.section.userMessageRenderingAria"),children:Tf.map(m=>s.jsx(gn,{selected:Of(U)===m.id,onSelect:()=>wi(m.id),label:l(m.labelKey),ariaLabel:r("settings.aiworker.visual.field.userMessageRenderingAria",{option:l(m.labelKey)})},m.id))})}),pe("mermaidRendering")&&s.jsx(Ls,{title:r("settings.aiworker.visual.section.mermaidRendering"),children:s.jsx(mn,{"aria-label":r("settings.aiworker.visual.section.mermaidRenderingAria"),children:Af.map(m=>s.jsx(gn,{selected:P===m.id,onSelect:()=>js(m.id),label:l(m.labelKey),ariaLabel:r("settings.aiworker.visual.field.mermaidRenderingAria",{option:l(m.labelKey)})},m.id))})}),pe("diffLayout")&&!ds&&s.jsx(Ls,{title:r("settings.aiworker.visual.section.diffLayout"),children:s.jsx(mn,{"aria-label":r("settings.aiworker.visual.section.diffLayoutAria"),children:If.map(m=>s.jsx(gn,{selected:je===m.id,onSelect:()=>ve(m.id),label:l(m.labelKey),ariaLabel:r("settings.aiworker.visual.field.diffLayoutAria",{option:l(m.labelKey)})},m.id))})}),pe("followUpBehavior")&&s.jsx(Ls,{title:r("settings.aiworker.visual.section.followUpBehavior"),settingsItem:"chat.follow-up-behavior",children:s.jsx(mn,{"aria-label":r("settings.aiworker.visual.section.followUpBehaviorAria"),children:Mf.map(m=>s.jsx(gn,{selected:De===m.id,onSelect:()=>Ye(m.id),label:l(m.labelKey),ariaLabel:r("settings.aiworker.visual.field.followUpBehaviorAria",{option:l(m.labelKey)})},m.id))})})]})}),ta&&s.jsxs(s.Fragment,{children:[pe("expandedTools")&&s.jsxs(_e,{title:r("settings.aiworker.visual.section.showToolsOpenedByDefault"),divider:pn||ea||qa||sa,contentClassName:hs,children:[s.jsx(gt,{checked:tt,onChange:kn,label:r("settings.aiworker.visual.field.bash"),ariaLabel:r("settings.aiworker.visual.field.showExpandedBashToolsAria")}),s.jsx(gt,{checked:ut,onChange:Pr,label:r("settings.aiworker.visual.field.editTools"),ariaLabel:r("settings.aiworker.visual.field.showExpandedEditToolsAria")})]}),s.jsxs(_e,{title:r("settings.aiworker.visual.section.sessionAssistance"),settingsItem:"chat.session-assistance",contentClassName:hs,children:[s.jsx(gt,{checked:fe,onChange:ga,label:r("settings.aiworker.visual.field.draftStartersVisible"),ariaLabel:r("settings.aiworker.visual.field.draftStartersVisibleAria"),settingsItem:"chat.draft-starters-visible"}),pe("sessionAssist")&&s.jsxs(s.Fragment,{children:[s.jsx(gt,{checked:c,onChange:v,label:r("settings.aiworker.visual.field.sessionRecap"),ariaLabel:r("settings.aiworker.visual.field.sessionRecapAria"),settingsItem:"chat.session-recap"}),s.jsx(gt,{checked:N,onChange:C,label:r("settings.aiworker.visual.field.sessionSuggestion"),ariaLabel:r("settings.aiworker.visual.field.sessionSuggestionAria"),settingsItem:"chat.session-suggestion"})]}),pe("subagentReadOnlyBanner")&&s.jsx(gt,{checked:wt,onChange:Q,label:r("settings.aiworker.visual.field.allowPromptingSubagentSessions"),ariaLabel:r("settings.aiworker.visual.field.allowPromptingSubagentSessionsAria"),settingsItem:"chat.subagent-read-only-banner"})]}),pe("sessionGoal")&&!ds&&s.jsxs(_e,{title:r("settings.aiworker.visual.goal.sectionTitle"),info:r("settings.aiworker.visual.goal.description"),contentClassName:hs,children:[s.jsx(gt,{checked:y,onChange:S,label:r("settings.aiworker.visual.field.sessionGoal"),ariaLabel:r("settings.aiworker.visual.field.sessionGoalAria"),settingsItem:"chat.session-goal"}),s.jsxs("div",{"data-settings-item":"chat.session-goal-budget",className:"flex items-center gap-2",children:[s.jsx(gt,{checked:g,onChange:T,disabled:!y,label:r("settings.aiworker.visual.goal.budgetLabel"),ariaLabel:r("settings.aiworker.visual.goal.budgetAria")}),y&&g?s.jsx(Ss,{value:R,onValueChange:m=>{typeof m=="number"&&Number.isFinite(m)&&m>0&&A(Math.floor(m))},min:1e3,max:1e8,step:5e4}):null]})]}),pe("reasoning")&&s.jsxs(_e,{title:r("settings.aiworker.visual.section.reasoning"),settingsItem:"chat.reasoning",contentClassName:hs,children:[s.jsx(gt,{checked:w,onChange:j,label:r("settings.aiworker.visual.field.showReasoningTraces"),ariaLabel:r("settings.aiworker.visual.field.showReasoningTracesAria"),settingsItem:"chat.reasoning-traces"}),w&&s.jsx(gt,{checked:F,onChange:D,label:r("settings.aiworker.visual.field.collapsibleThinkingBlocks"),ariaLabel:r("settings.aiworker.visual.field.collapsibleThinkingBlocksAria")})]}),s.jsx(_e,{title:r("settings.aiworker.visual.section.streaming"),settingsItem:"chat.streaming",contentClassName:hs,children:s.jsx(gt,{checked:f,onChange:b,label:r("settings.aiworker.visual.field.streamingAutoFollow"),ariaLabel:r("settings.aiworker.visual.field.streamingAutoFollowAria"),info:r("settings.aiworker.visual.field.streamingAutoFollowInfo"),settingsItem:"chat.streaming-auto-follow"})}),(pe("collapsibleUserMessages")||pe("stickyUserHeader")||pe("promptNavigatorEnabled")&&!ds||pe("wideChatLayout")||pe("splitAssistantMessageActions")||pe("codeBlockLineWrap"))&&s.jsxs(_e,{title:r("settings.aiworker.visual.section.messageAppearance"),settingsItem:"chat.message-appearance",contentClassName:hs,children:[pe("collapsibleUserMessages")&&s.jsx(gt,{checked:k,onChange:ki,label:r("settings.aiworker.visual.field.collapsibleUserMessages"),ariaLabel:r("settings.aiworker.visual.field.collapsibleUserMessagesAria"),settingsItem:"chat.collapsible-user-messages"}),pe("stickyUserHeader")&&s.jsx(gt,{checked:G,onChange:ji,label:r("settings.aiworker.visual.field.stickyUserHeader"),ariaLabel:r("settings.aiworker.visual.field.stickyUserHeaderAria"),settingsItem:"chat.sticky-user-header"}),pe("promptNavigatorEnabled")&&!ds&&s.jsx(gt,{checked:E,onChange:Fs,label:r("settings.aiworker.visual.field.promptNavigatorEnabled"),ariaLabel:r("settings.aiworker.visual.field.promptNavigatorEnabledAria"),settingsItem:"chat.prompt-navigator"}),pe("wideChatLayout")&&s.jsx(gt,{checked:z,onChange:Ha,label:r("settings.aiworker.visual.field.wideChatLayout"),ariaLabel:r("settings.aiworker.visual.field.wideChatLayoutAria"),settingsItem:"chat.wide-layout"}),pe("splitAssistantMessageActions")&&s.jsx(gt,{checked:jt,onChange:Ni,label:r("settings.aiworker.visual.field.showSplitAssistantMessageActions"),ariaLabel:r("settings.aiworker.visual.field.showSplitAssistantMessageActionsAria"),settingsItem:"chat.inline-assistant-actions",info:r("settings.aiworker.visual.field.showSplitAssistantMessageActionsTooltip")}),pe("codeBlockLineWrap")&&s.jsx(gt,{checked:_,onChange:K,label:r("settings.aiworker.visual.field.codeBlockLineWrap"),ariaLabel:r("settings.aiworker.visual.field.codeBlockLineWrapAria"),settingsItem:"chat.code-block-line-wrap"})]}),(pe("showToolFileIcons")||pe("showTurnChangedFiles")||pe("dotfiles")&&!us()||pe("fileViewerPreview"))&&s.jsxs(_e,{title:r("settings.aiworker.visual.section.toolsAndFiles"),settingsItem:"chat.tools-and-files",contentClassName:hs,children:[pe("showToolFileIcons")&&s.jsx(gt,{checked:dt,onChange:Hs,label:r("settings.aiworker.visual.field.showToolFileIcons"),ariaLabel:r("settings.aiworker.visual.field.showToolFileIconsAria"),settingsItem:"chat.tool-file-icons"}),pe("showTurnChangedFiles")&&s.jsx(gt,{checked:H,onChange:Yn,label:r("settings.aiworker.visual.field.showTurnChangedFiles"),ariaLabel:r("settings.aiworker.visual.field.showTurnChangedFilesAria"),settingsItem:"chat.changed-files"}),pe("dotfiles")&&!us()&&s.jsx(gt,{checked:d,onChange:Sd,label:r("settings.aiworker.visual.field.showDotfiles"),ariaLabel:r("settings.aiworker.visual.field.showDotfilesAria"),settingsItem:"chat.dotfiles"}),pe("fileViewerPreview")&&s.jsx(gt,{checked:Qe,onChange:ln,label:r("settings.aiworker.defaults.field.openFilesPreview"),ariaLabel:r("settings.aiworker.defaults.field.openFilesPreviewAria")})]}),(pe("persistDraft")||pe("largeTextPaste")||!u&&pe("inputSpellcheck"))&&s.jsxs(_e,{title:r("settings.aiworker.visual.section.composer"),settingsItem:"chat.composer",contentClassName:hs,children:[pe("persistDraft")&&s.jsx(gt,{checked:W,onChange:ke,label:r("settings.aiworker.visual.field.persistDraftMessages"),ariaLabel:r("settings.aiworker.visual.field.persistDraftMessagesAria"),settingsItem:"chat.persist-drafts"}),!u&&pe("inputSpellcheck")&&s.jsx(gt,{checked:Ie,onChange:Si,label:r("settings.aiworker.visual.field.enableSpellcheckInTextInputs"),ariaLabel:r("settings.aiworker.visual.field.enableSpellcheckInTextInputsAria"),settingsItem:"chat.spellcheck"}),pe("largeTextPaste")&&s.jsx(Ls,{title:r("settings.aiworker.visual.field.largeTextPaste"),info:r("settings.aiworker.visual.field.largeTextPasteHint"),settingsItem:"chat.large-text-paste",children:s.jsx(mn,{"aria-label":r("settings.aiworker.visual.field.largeTextPasteAria"),children:Rf.map(m=>s.jsx(gn,{selected:it===m.id,onSelect:()=>nt(m.id),label:l(m.labelKey),ariaLabel:r("settings.aiworker.visual.field.largeTextPasteOptionAria",{option:l(m.labelKey)})},m.id))})})]})]})]}),pe("reportUsage")&&s.jsx(_e,{title:r("settings.aiworker.visual.section.privacy"),children:s.jsx(gt,{checked:Vt,onChange:is,label:r("settings.aiworker.visual.field.sendAnonymousUsageReports"),info:r("settings.aiworker.visual.field.sendAnonymousUsageReportsHint"),ariaLabel:r("settings.aiworker.visual.field.sendAnonymousUsageReportsAria"),settingsItem:"appearance.usage-reports"})})]})},Kf=1,zf=365,qo=30,Uf=[{value:"archive",labelKey:"settings.aiworker.sessionRetention.action.archive"},{value:"delete",labelKey:"settings.aiworker.sessionRetention.action.delete"}],Gl=()=>{const t=mt.c(88),{t:e}=at(),a=de(_f),n=de($f),i=de(Vf),r=de(Bf),l=de(Hf),u=de(Gf);let p;t[0]===Symbol.for("react.memo_cache_sentinel")?(p={autoRun:!1},t[0]=p):p=t[0];const{candidates:h,isRunning:d,runCleanup:w,action:c}=Uc(p),N=h.length;let v;t[1]!==w||t[2]!==e?(v=async()=>{const le=await w({force:!0});if(le.completedIds.length===0&&le.failedIds.length===0){M.message(le.action==="archive"?e("settings.aiworker.sessionRetention.toast.noneEligibleArchive"):e("settings.aiworker.sessionRetention.toast.noneEligibleDelete"));return}le.completedIds.length>0&&M.success(le.action==="archive"?e("settings.aiworker.sessionRetention.toast.archivedCount",{count:le.completedIds.length}):e("settings.aiworker.sessionRetention.toast.deletedCount",{count:le.completedIds.length})),le.failedIds.length>0&&M.error(le.action==="archive"?e("settings.aiworker.sessionRetention.toast.failedArchiveCount",{count:le.failedIds.length}):e("settings.aiworker.sessionRetention.toast.failedDeleteCount",{count:le.failedIds.length}))},t[1]=w,t[2]=e,t[3]=v):v=t[3];const C=v;let y;t[4]!==e?(y=e("settings.aiworker.sessionRetention.title"),t[4]=e,t[5]=y):y=t[5];let S;t[6]!==e?(S=e("settings.aiworker.sessionRetention.tooltip"),t[6]=e,t[7]=S):S=t[7];let g;t[8]!==e?(g=e("settings.aiworker.sessionRetention.field.enableAutoCleanup"),t[8]=e,t[9]=g):g=t[9];let T;t[10]!==e?(T=e("settings.aiworker.sessionRetention.field.enableAutoCleanupAria"),t[10]=e,t[11]=T):T=t[11];let R;t[12]!==a||t[13]!==r||t[14]!==g||t[15]!==T?(R=s.jsx(gt,{settingsItem:"sessions.auto-cleanup",checked:a,onChange:r,label:g,ariaLabel:T}),t[12]=a,t[13]=r,t[14]=g,t[15]=T,t[16]=R):R=t[16];let A;t[17]!==e?(A=e("settings.aiworker.sessionRetention.field.retentionPeriod"),t[17]=e,t[18]=A):A=t[18];let j;t[19]!==e?(j=e("settings.aiworker.sessionRetention.field.retentionPeriodAria"),t[19]=e,t[20]=j):j=t[20];let f;t[21]===Symbol.for("react.memo_cache_sentinel")?(f=we(Ps,"tabular-nums"),t[21]=f):f=t[21];let b;t[22]!==n||t[23]!==l||t[24]!==j?(b=s.jsx(Ss,{value:n,onValueChange:l,min:Kf,max:zf,step:1,"aria-label":j,className:f}),t[22]=n,t[23]=l,t[24]=j,t[25]=b):b=t[25];let F;t[26]!==e?(F=e("settings.aiworker.sessionRetention.field.days"),t[26]=e,t[27]=F):F=t[27];let D;t[28]!==F?(D=s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:F}),t[28]=F,t[29]=D):D=t[29];let P;t[30]!==l?(P=()=>l(qo),t[30]=l,t[31]=P):P=t[31];const I=n===qo;let U;t[32]!==e?(U=e("settings.aiworker.sessionRetention.actions.resetRetentionAria"),t[32]=e,t[33]=U):U=t[33];let q;t[34]!==e?(q=e("settings.common.actions.reset"),t[34]=e,t[35]=q):q=t[35];let k;t[36]===Symbol.for("react.memo_cache_sentinel")?(k=s.jsx(O,{name:"restart",className:"h-3.5 w-3.5"}),t[36]=k):k=t[36];let $;t[37]!==P||t[38]!==I||t[39]!==U||t[40]!==q?($=s.jsx(B,{size:"sm",type:"button",variant:"ghost",onClick:P,disabled:I,className:fs,"aria-label":U,title:q,children:k}),t[37]=P,t[38]=I,t[39]=U,t[40]=q,t[41]=$):$=t[41];let G;t[42]!==b||t[43]!==D||t[44]!==$||t[45]!==A?(G=s.jsxs(Ot,{settingsItem:"sessions.retention-period",label:A,children:[b,D,$]}),t[42]=b,t[43]=D,t[44]=$,t[45]=A,t[46]=G):G=t[46];let E;t[47]!==e?(E=e("settings.aiworker.sessionRetention.field.whenSessionsExpire"),t[47]=e,t[48]=E):E=t[48];let J;t[49]!==e?(J=Uf.map(le=>({value:le.value,label:e(le.labelKey)})),t[49]=e,t[50]=J):J=t[50];let X;t[51]!==i||t[52]!==u||t[53]!==J?(X=s.jsx(qs,{value:i,onChange:u,options:J}),t[51]=i,t[52]=u,t[53]=J,t[54]=X):X=t[54];let L;t[55]!==E||t[56]!==X?(L=s.jsx(Ot,{settingsItem:"sessions.retention-action",label:E,children:X}),t[55]=E,t[56]=X,t[57]=L):L=t[57];let se;t[58]!==G||t[59]!==L?(se=s.jsxs(Ua,{className:"space-y-0",children:[G,L]}),t[58]=G,t[59]=L,t[60]=se):se=t[60];let z;t[61]!==e?(z=e("settings.aiworker.sessionRetention.manualCleanup.title"),t[61]=e,t[62]=z):z=t[62];let V;t[63]!==d||t[64]!==e?(V=e(d?"settings.aiworker.sessionRetention.actions.cleaningUp":"settings.aiworker.sessionRetention.actions.runCleanupNow"),t[63]=d,t[64]=e,t[65]=V):V=t[65];let _;t[66]!==C||t[67]!==d||t[68]!==V?(_=s.jsx(B,{type:"button",variant:"outline",size:"xs",onClick:C,disabled:d,className:"!font-normal",children:V}),t[66]=C,t[67]=d,t[68]=V,t[69]=_):_=t[69];let K;t[70]!==z||t[71]!==_?(K=s.jsx(Ot,{label:z,children:_}),t[70]=z,t[71]=_,t[72]=K):K=t[72];let Z;t[73]!==c||t[74]!==N||t[75]!==e?(Z=c==="archive"?e("settings.aiworker.sessionRetention.manualCleanup.eligibleArchiveNow",{count:N}):e("settings.aiworker.sessionRetention.manualCleanup.eligibleDeleteNow",{count:N}),t[73]=c,t[74]=N,t[75]=e,t[76]=Z):Z=t[76];let Y;t[77]!==Z?(Y=s.jsx("p",{className:"typography-meta text-muted-foreground",children:Z}),t[77]=Z,t[78]=Y):Y=t[78];let te;t[79]!==K||t[80]!==Y?(te=s.jsxs("div",{className:"mt-1 py-1.5 space-y-1",children:[K,Y]}),t[79]=K,t[80]=Y,t[81]=te):te=t[81];let ge;return t[82]!==y||t[83]!==se||t[84]!==S||t[85]!==te||t[86]!==R?(ge=s.jsxs(_e,{title:y,info:S,children:[R,se,te]}),t[82]=y,t[83]=se,t[84]=S,t[85]=te,t[86]=R,t[87]=ge):ge=t[87],ge};function _f(t){return t.autoDeleteEnabled}function $f(t){return t.autoDeleteAfterDays}function Vf(t){return t.sessionRetentionAction}function Bf(t){return t.setAutoDeleteEnabled}function Hf(t){return t.setAutoDeleteAfterDays}function Gf(t){return t.setSessionRetentionAction}const Jo=(t,e,a)=>!t||!Number.isFinite(t)?e:new Intl.DateTimeFormat(hr(),{dateStyle:"medium",timeStyle:"short",hour12:a==="auto"?void 0:a==="12h"}).format(t),Wl=()=>{const{t}=at(),e=de(f=>f.timeFormatPreference),[a,n]=o.useState(!1),[i,r]=o.useState(!0),[l,u]=o.useState(!1),[p,h]=o.useState(null),[d,w]=o.useState(!1),[c,N]=o.useState([]),[v,C]=o.useState(_c),[y,S]=o.useState(""),g=o.useMemo(()=>$c(),[]),T=o.useCallback(async()=>{r(!0),S("");try{const f=await Vc();N(f)}catch(f){const b=f instanceof Error?f.message:t("settings.aiworker.passkeys.toast.loadFailed");S(b)}finally{r(!1)}},[t]);o.useEffect(()=>{let f=!1;return(async()=>{try{if(!g.supported){f||(n(!1),r(!1));return}f||n(!0)}catch{f||n(!1)}if(!f){const b=await Ri();if(C(b),!b.enabled){N([]),r(!1);return}await T()}})(),()=>{f=!0,Rr()}},[T,g.supported]);const R=o.useCallback(async()=>{if(!v.enabled){const f=t("settings.aiworker.passkeys.toast.enableUiPasswordFirst");S(f),M.message(f);return}if(!a){S(g.reason),M.message(g.reason);return}if(l){Rr(),u(!1);return}S(""),u(!0);try{await Bc(),C(await Ri()),await T(),M.success(t("settings.aiworker.passkeys.toast.added"))}catch(f){if(Hc(f)){M.message(t("settings.aiworker.passkeys.toast.setupCanceled"));return}const b=f instanceof Error?f.message:t("settings.aiworker.passkeys.toast.addFailed");S(b),M.error(b)}finally{u(!1)}},[l,T,v.enabled,g.reason,a,t]),A=o.useCallback(async f=>{h(f),S("");try{await Gc(f),C(await Ri()),await T(),M.success(t("settings.aiworker.passkeys.toast.removed"))}catch(b){const F=b instanceof Error?b.message:t("settings.aiworker.passkeys.toast.removeFailed");S(F),M.error(F)}finally{h(null)}},[T,t]),j=o.useCallback(async()=>{w(!0),S("");try{await Wc(),window.location.reload()}catch(f){const b=f instanceof Error?f.message:t("settings.aiworker.passkeys.toast.clearAuthFailed");S(b),M.error(b),w(!1)}},[t]);return s.jsxs(_e,{title:t("settings.aiworker.passkeys.title"),children:[s.jsxs("div",{className:"space-y-2",children:[s.jsxs(Ot,{label:t("settings.aiworker.passkeys.field.currentDevice"),children:[s.jsx(B,{type:"button",variant:l?"secondary":"outline",size:"xs",onClick:()=>{R()},disabled:i||d,className:"!font-normal",children:t(l?"settings.aiworker.passkeys.actions.cancelSetup":"settings.aiworker.passkeys.actions.add")}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",onClick:()=>{j()},disabled:i||l||d,className:"!font-normal text-muted-foreground hover:text-foreground",children:t(d?"settings.aiworker.passkeys.actions.signingOut":"settings.aiworker.passkeys.actions.signOutEverywhere")})]}),!v.enabled&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.aiworker.passkeys.state.uiPasswordRequired")}),v.enabled&&!a&&s.jsx("p",{className:"typography-meta text-muted-foreground",children:g.reason}),i?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.aiworker.passkeys.state.loading")}):c.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:t("settings.aiworker.passkeys.state.noneSaved")}):s.jsx("div",{className:"space-y-1 pt-1",children:c.map(f=>s.jsxs(Ot,{label:s.jsx("span",{title:f.label,children:f.label}),alignEnd:!1,controlClassName:"justify-between sm:flex-1",children:[s.jsx("span",{className:"typography-meta text-muted-foreground truncate",children:f.lastUsedAt?t("settings.aiworker.passkeys.item.lastUsed",{time:Jo(f.lastUsedAt,t("settings.aiworker.passkeys.time.neverUsed"),e)}):t("settings.aiworker.passkeys.item.added",{time:Jo(f.createdAt,t("settings.aiworker.passkeys.time.neverUsed"),e)})}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",onClick:()=>{A(f.id)},disabled:p===f.id,className:"!font-normal text-muted-foreground hover:text-foreground",children:p===f.id?t("settings.aiworker.passkeys.actions.removing"):t("settings.common.actions.delete")})]},f.id))})]}),y&&s.jsx("div",{className:"mt-1 py-1.5",children:s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:y})})]})},ql=()=>{const t=mt.c(14),{t:e}=at(),a=Or(Wf),n=Or(qf);let i;t[0]!==e?(i=e("settings.aiworker.appLinks.title"),t[0]=e,t[1]=i):i=t[1];let r;t[2]!==e?(r=e("settings.aiworker.appLinks.info"),t[2]=e,t[3]=r):r=t[3];let l;t[4]!==n||t[5]!==e||t[6]!==a?(l=a.length===0?s.jsx("p",{className:"typography-meta text-muted-foreground",children:e("settings.aiworker.appLinks.empty")}):a.map(h=>s.jsxs("div",{className:"flex items-center justify-between gap-2 py-0.5",children:[s.jsx("span",{className:"min-w-0 truncate font-mono text-[13px]",children:`${h}://`}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",onClick:()=>n(h),className:"!font-normal text-muted-foreground hover:text-foreground","aria-label":e("settings.aiworker.appLinks.removeAria",{scheme:`${h}://`}),children:e("settings.common.actions.delete")})]},h)),t[4]=n,t[5]=e,t[6]=a,t[7]=l):l=t[7];let u;t[8]!==l?(u=s.jsx("div",{className:"space-y-1","data-settings-item":"general.app-links",children:l}),t[8]=l,t[9]=u):u=t[9];let p;return t[10]!==i||t[11]!==r||t[12]!==u?(p=s.jsx(_e,{title:i,description:r,children:u}),t[10]=i,t[11]=r,t[12]=u,t[13]=p):p=t[13],p};function Wf(t){return t.trustedSchemes}function qf(t){return t.removeTrustedScheme}const qi=t=>{const e=da(t);return e||{providerId:"",modelId:""}},Jl=()=>{const{t}=at(),e=Ze(ne=>ne.setProvider),a=Ze(ne=>ne.setModel),n=Ze(ne=>ne.setAgent),i=Ze(ne=>ne.setCurrentVariant),r=Ze(ne=>ne.setCurrentVariantOverride),l=Ze(ne=>ne.setSettingsDefaultModel),u=Ze(ne=>ne.setSettingsDefaultVariant),p=Ze(ne=>ne.setSettingsDefaultAgent),h=Ze(ne=>ne.selectionSource==="manual"),d=qc(ne=>ne.currentSessionId),w=Lr(ne=>ne.getSessionModelSelection),c=Lr(ne=>ne.getSessionAgentSelection),N=!!(h&&d&&w(d)),v=!!(h&&d&&c(d)),C=de(ne=>ne.showDeletionDialog),y=de(ne=>ne.setShowDeletionDialog),S=Ze(ne=>ne.providers),g=Ze(ne=>ne.modelsMetadata),[T,R]=o.useState(),[A,j]=o.useState(),[f,b]=o.useState(),[F,D]=o.useState(!0),[P,I]=o.useState(),[U,q]=o.useState([]),[k,$]=o.useState(),[G,E]=o.useState(!0),J=o.useMemo(()=>qi(T),[T]);o.useEffect(()=>{(async()=>{try{let ae=null;if(!ae){const me=tn()?.settings;if(me)try{const Ne=(await me.load())?.settings;if(Ne){const Se=Ne;ae={defaultModel:typeof Ne.defaultModel=="string"?Ne.defaultModel:void 0,defaultVariant:typeof Se.defaultVariant=="string"?Se.defaultVariant:void 0,defaultAgent:typeof Ne.defaultAgent=="string"?Ne.defaultAgent:void 0,smallModelUseDefault:typeof Se.smallModelUseDefault=="boolean"?Se.smallModelUseDefault:void 0,smallModelOverride:typeof Se.smallModelOverride=="string"?Se.smallModelOverride:void 0,walkthroughModelOverride:typeof Se.walkthroughModelOverride=="string"?Se.walkthroughModelOverride:void 0}}}catch{}}if(!ae){const me=await pt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});me.ok&&(ae=await me.json())}if(ae){const me=typeof ae.defaultModel=="string"&&ae.defaultModel.trim().length>0?ae.defaultModel.trim():void 0,Pe=typeof ae.defaultVariant=="string"&&ae.defaultVariant.trim().length>0?ae.defaultVariant.trim():void 0,Ne=typeof ae.defaultAgent=="string"&&ae.defaultAgent.trim().length>0?ae.defaultAgent.trim():void 0;me!==void 0&&R(me),Pe!==void 0&&j(Pe),Ne!==void 0&&b(Ne),typeof ae.smallModelUseDefault=="boolean"&&D(ae.smallModelUseDefault),typeof ae.smallModelOverride=="string"&&ae.smallModelOverride.trim()&&I(ae.smallModelOverride.trim()),typeof ae.walkthroughModelOverride=="string"&&ae.walkthroughModelOverride.trim()&&$(ae.walkthroughModelOverride.trim())}}catch(ae){console.warn("Failed to load defaults settings:",ae)}finally{E(!1)}})()},[]);const X=o.useCallback(async(ne,ae)=>{const me=ne&&ae?`${ne}/${ae}`:void 0;R(me),j(void 0),u(void 0),l(me),N||(i(void 0),ne&&ae&&S.find(Ne=>Ne.id===ne)&&(e(ne),a(ae)));try{await yt({defaultModel:me??"",defaultVariant:""});const Pe=await pt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultModel:me})});Pe.ok||console.warn("Failed to save default model to server:",Pe.status,Pe.statusText)}catch(Pe){console.warn("Failed to save default model:",Pe)}},[N,S,i,a,e,l,u]),L="__default__",se=o.useCallback(ne=>ne===L?t("settings.aiworker.defaults.option.default"):ne.charAt(0).toUpperCase()+ne.slice(1),[t]),z=o.useCallback(async ne=>{const ae=ne===L?void 0:ne||void 0;j(ae),u(ae),N||r(ae??null,ae);try{await yt({defaultVariant:ae??""})}catch(me){console.warn("Failed to save default variant:",me)}},[N,r,u]),V=o.useCallback(async ne=>{const ae=ne||void 0;b(ae),p(ae),ne&&!v&&n(ne);try{await yt({defaultAgent:ae??""})}catch(me){console.warn("Failed to save default agent:",me)}},[v,n,p]),_=o.useCallback(async ne=>{D(ne);try{await yt({smallModelUseDefault:ne})}catch(ae){console.warn("Failed to save small model preference:",ae)}},[]),K=o.useCallback(async(ne,ae)=>{const me=ne&&ae?`${ne}/${ae}`:void 0;I(me);try{await yt({smallModelOverride:me??""})}catch(Pe){console.warn("Failed to save small model override:",Pe)}},[]),Z=o.useCallback(async(ne,ae)=>{const me=ne&&ae?`${ne}/${ae}`:void 0;$(me);try{await yt({walkthroughModelOverride:me??""})}catch(Pe){console.warn("Failed to save walkthrough model override:",Pe)}},[]),Y=o.useCallback((ne,ae)=>g.get(`${ne}/${ae}`)?.structured_output!==!1,[g]),te=o.useMemo(()=>qi(P),[P]),ge=o.useMemo(()=>qi(k),[k]);o.useEffect(()=>{let ne=!1;return(async()=>{try{const ae=await pt("/api/small-model",{method:"GET",headers:{Accept:"application/json"}});if(!ae.ok)return;const me=await ae.json().catch(()=>null);!ne&&Array.isArray(me?.authenticatedProviders)&&q(me.authenticatedProviders.filter(Pe=>typeof Pe=="string"))}catch{}})(),()=>{ne=!0}},[]);const le=o.useMemo(()=>{if(!J.providerId||!J.modelId)return[];const me=S.find(Pe=>Pe.id===J.providerId)?.models.find(Pe=>Pe.id===J.modelId)?.variants;return me?Object.keys(me):[]},[J.modelId,J.providerId,S]),he=le.length>0;return o.useEffect(()=>{!he&&A&&(j(void 0),u(void 0),N||i(void 0),yt({defaultVariant:""}).catch(()=>{}))},[N,A,i,u,he]),G?null:s.jsx(s.Fragment,{children:s.jsx(_e,{title:t("settings.aiworker.defaults.title"),divider:!1,children:s.jsxs("div",{className:"space-y-0",children:[s.jsxs("div",{className:"mt-0 mb-1 typography-meta text-muted-foreground",children:[t("settings.aiworker.defaults.summaryPrefix")," ",J.providerId?s.jsxs("span",{className:"text-foreground",children:[J.providerId,"/",J.modelId,he?` (${A??t("settings.aiworker.defaults.option.defaultLowercase")})`:""]}):s.jsx("span",{className:"text-foreground",children:t("settings.aiworker.defaults.summaryOpenCodeDefault")}),f&&s.jsxs(s.Fragment,{children:[" / ",s.jsx("span",{className:"text-foreground",children:f})]})]}),s.jsxs("div",{children:[s.jsx(Ot,{settingsItem:"sessions.default-model",label:t("settings.aiworker.defaults.field.defaultModel"),children:s.jsx(Oa,{providerId:J.providerId,modelId:J.modelId,onChange:X,className:Mn})}),s.jsx(Ot,{settingsItem:"sessions.default-thinking",label:t("settings.aiworker.defaults.field.defaultThinking"),children:s.jsxs(Pt,{value:A??L,onValueChange:z,disabled:!he,children:[s.jsx(It,{size:Lt,className:en,children:s.jsx(Rt,{placeholder:t("settings.aiworker.defaults.field.thinkingPlaceholder"),children:se(A??L)})}),s.jsxs(At,{children:[s.jsx(ot,{value:L,children:t("settings.aiworker.defaults.option.default")}),le.map(ne=>s.jsx(ot,{value:ne,children:se(ne)},ne))]})]})}),s.jsx(Ot,{settingsItem:"sessions.default-agent",label:t("settings.aiworker.defaults.field.defaultAgent"),children:s.jsx(ul,{agentName:f||"",onChange:V,filter:ne=>Jc(ne.mode),className:Mn})})]}),s.jsx(Ua,{className:hs,children:s.jsx(gt,{settingsItem:"sessions.deletion-dialog",checked:C,onChange:y,label:t("settings.aiworker.defaults.field.showDeletionDialog"),ariaLabel:t("settings.aiworker.defaults.field.showDeletionDialogAria")})}),s.jsxs("div",{className:"space-y-3 pt-6",children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Js,{children:t("settings.aiworker.defaults.smallModel.title")}),s.jsx(Jt,{children:t("settings.aiworker.defaults.smallModel.description")})]}),s.jsx(gt,{settingsItem:"sessions.small-model",checked:F,onChange:ne=>{_(ne)},label:t("settings.aiworker.defaults.smallModel.useDefault"),ariaLabel:t("settings.aiworker.defaults.smallModel.useDefaultAria")}),F?null:s.jsx(Ot,{label:t("settings.aiworker.defaults.smallModel.overrideModel"),children:s.jsx(Oa,{providerId:te.providerId,modelId:te.modelId,onChange:K,allowedProviderIds:U,className:Mn})}),s.jsxs(Ua,{className:hs,children:[s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx(Js,{children:t("settings.aiworker.defaults.walkthroughModel.title")}),s.jsx(Jt,{children:t("settings.aiworker.defaults.walkthroughModel.description")})]}),s.jsx(Ot,{settingsItem:"sessions.walkthrough-model",label:t("settings.aiworker.defaults.walkthroughModel.overrideModel"),children:s.jsx(Oa,{providerId:ge.providerId,modelId:ge.modelId,onChange:Z,allowedProviderIds:U,isModelAllowed:Y,placeholder:t("settings.aiworker.defaults.walkthroughModel.usesSmallModel"),className:Mn})})]})]})]})})})},Qo={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"}},Jf={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"},Qf=()=>{const{t}=at(),e=o.useMemo(()=>os(),[]),a=o.useMemo(()=>us(),[]),n=o.useMemo(()=>typeof window>"u"?!1:window.Capacitor?.isNativePlatform?.()===!0||window.location.protocol==="capacitor:",[]),i=!e&&!a&&!n,r=de(z=>z.nativeNotificationsEnabled),l=de(z=>z.setNativeNotificationsEnabled),u=de(z=>z.notificationMode),p=de(z=>z.setNotificationMode),h=de(z=>z.notifyOnSubtasks),d=de(z=>z.setNotifyOnSubtasks),w=de(z=>z.notifyOnCompletion),c=de(z=>z.setNotifyOnCompletion),N=de(z=>z.notifyOnError),v=de(z=>z.setNotifyOnError),C=de(z=>z.notifyOnQuestion),y=de(z=>z.setNotifyOnQuestion),S=de(z=>z.notificationTemplates),g=de(z=>z.setNotificationTemplates),[T,R]=o.useState("default"),[A,j]=o.useState(!1),[f,b]=o.useState(!1),[F,D]=o.useState(!1);o.useEffect(()=>{if(!i){j(!1),b(!1);return}typeof Notification<"u"&&R(Notification.permission);const z=typeof window<"u"&&"serviceWorker"in navigator&&"PushManager"in window&&"Notification"in window;j(z),(async()=>{if(!z){b(!1);return}try{const _=await navigator.serviceWorker.getRegistration();if(!_){b(!1);return}const K=await _.pushManager.getSubscription();b(!!K)}catch{b(!1)}})()},[i]);const P=async z=>{if(e){l(z);return}if(!i){l(z);return}if(z&&typeof Notification<"u"&&Notification.permission==="default")try{const V=await Notification.requestPermission();R(V),V==="granted"?l(!0):M.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.description")})}catch(V){console.error("Failed to request notification permission:",V),M.error(t("settings.notifications.page.toast.requestPermissionFailed"))}else l(!!(z&&T==="granted"))},I=e||a||n||i&&typeof Notification<"u"&&Notification.permission==="granted",U=(z,V,_)=>{g(K=>({...K,[z]:{...K[z],[V]:_}}))},q=z=>{const V="=".repeat((4-z.length%4)%4),_=(z+V).replace(/-/g,"+").replace(/_/g,"/"),K=atob(_),Z=new Uint8Array(K.length);for(let Y=0;Y<K.length;Y+=1)Z[Y]=K.charCodeAt(Y);return Z},k=async(z,V,_)=>{let K=null;const Z=new Promise((Y,te)=>{K=setTimeout(()=>{te(new Error(_))},V)});try{return await Promise.race([z,Z])}finally{K&&clearTimeout(K)}},$=async z=>{if(z.active)return;const V=z.installing||z.waiting;V&&V.state!=="activated"&&await k(new Promise(_=>{const K=()=>{V.state==="activated"&&(V.removeEventListener("statechange",K),_())};V.addEventListener("statechange",K),K()}),15e3,"Service worker activation timed out")},G=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 V=null;for(const _ of z)try{const K=_.opts?navigator.serviceWorker.register("/sw.js",_.opts):navigator.serviceWorker.register("/sw.js");return await k(K,1e4,`Service worker registration timed out (${_.label})`)}catch(K){V=K}throw V instanceof Error?V:new Error("Service worker registration failed")},E=async()=>{if(!("serviceWorker"in navigator))throw new Error("Service worker not supported");const z=await navigator.serviceWorker.getRegistration();if(z)return z;const V=await G();try{await V.update()}catch{}return await $(V),V},J=z=>{const V=z,_=[`type=${typeof z}`,`toString=${String(z)}`,`name=${String(V?.name??"")}`,`message=${String(V?.message??"")}`];let K="";try{K=JSON.stringify(z)}catch{}return{summary:_.filter(Boolean).join(" | "),json:K,stack:typeof V?.stack=="string"?V.stack:""}},X=async()=>{const z=tn();if(!z?.notifications){M.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"})?M.success(t("settings.notifications.page.toast.testNotificationSent")):M.error(t("settings.notifications.page.toast.testNotificationFailed"))}catch(V){console.error("Test notification failed:",V),M.error(t("settings.notifications.page.toast.testNotificationFailed"))}},L=async()=>{if(!A){M.error(t("settings.notifications.page.toast.pushUnsupported"));return}const z=tn();if(!z?.push){M.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}D(!0);try{if(typeof Notification<"u"&&Notification.permission==="default"){const le=await Notification.requestPermission();if(R(le),le!=="granted"){M.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}}if(typeof Notification<"u"&&Notification.permission!=="granted"){M.error(t("settings.notifications.page.toast.permissionDenied.title"),{description:t("settings.notifications.page.toast.permissionDenied.enableInBrowser")});return}const V=await z.push.getVapidPublicKey();if(!V?.publicKey){M.error(t("settings.notifications.page.toast.pushKeyLoadFailed"));return}const _=await E();await $(_);const K=await _.pushManager.getSubscription();if(!("pushManager"in _)||!_.pushManager)throw new Error("PushManager unavailable (requires installed PWA + iOS 16.4+)");const Y=(K??await k(_.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:q(V.publicKey)}),15e3,"Push subscription timed out")).toJSON(),te=Y.keys;if(!Y.endpoint||!te?.p256dh||!te.auth)throw new Error("Push subscription missing keys");if(!(await k(z.push.subscribe({endpoint:Y.endpoint,keys:{p256dh:te.p256dh,auth:te.auth},origin:typeof window<"u"?window.location.origin:void 0,platform:Cd()}),15e3,"Push subscribe request timed out"))?.ok){M.error(t("settings.notifications.page.toast.enableBackgroundFailed"));return}b(!0),M.success(t("settings.notifications.page.toast.backgroundEnabled"))}catch(V){console.error("[Push] Enable failed:",V);const _=J(V);M.error(t("settings.notifications.page.toast.enableBackgroundFailed"),{description:_.summary})}finally{D(!1)}},se=async()=>{if(!A){b(!1);return}const z=tn();if(!z?.push){M.error(t("settings.notifications.page.toast.pushApiUnavailable"));return}D(!0);try{const _=await(await E()).pushManager.getSubscription();if(!_){b(!1);return}const K=_.endpoint;await _.unsubscribe(),await z.push.unsubscribe({endpoint:K}),b(!1),M.success(t("settings.notifications.page.toast.backgroundDisabled"))}finally{D(!1)}};return s.jsxs(s.Fragment,{children:[s.jsxs(_e,{settingsItem:"notifications.delivery",title:t("settings.notifications.page.delivery.title"),divider:!1,children:[s.jsxs("div",{className:hs,children:[s.jsx(gt,{checked:r&&I,onChange:z=>{P(z)},label:t("settings.notifications.page.delivery.enableLabel"),info:i?t("settings.notifications.page.delivery.browserPermissionHint"):a?t("settings.notifications.page.delivery.vscodeHint"):void 0,ariaLabel:t("settings.notifications.page.delivery.enableAria")}),r&&I&&!n&&s.jsxs(s.Fragment,{children:[s.jsx(gt,{checked:u==="always",onChange:z=>p(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:()=>{X()},children:t("settings.notifications.page.delivery.testAction")})})]})]}),i&&s.jsxs("div",{className:"mt-1",children:[T==="denied"&&s.jsx("p",{className:"typography-meta text-[var(--status-error)] mt-1",children:t("settings.notifications.page.delivery.permissionDenied")}),T==="granted"&&!r&&s.jsx("p",{className:"typography-meta text-muted-foreground/70 mt-1",children:t("settings.notifications.page.delivery.permissionGrantedButDisabled")})]})]}),r&&I&&s.jsxs(s.Fragment,{children:[s.jsx(_e,{settingsItem:"notifications.events",title:t("settings.notifications.page.events.title"),children:s.jsxs("div",{className:hs,children:[s.jsx(gt,{checked:w,onChange:c,label:t("settings.notifications.page.events.completionLabel"),ariaLabel:t("settings.notifications.page.events.completionAria")}),s.jsx(gt,{checked:h,onChange:d,label:t("settings.notifications.page.events.subtaskLabel"),ariaLabel:t("settings.notifications.page.events.subtaskAria")}),s.jsx(gt,{checked:N,onChange:v,label:t("settings.notifications.page.events.errorLabel"),ariaLabel:t("settings.notifications.page.events.errorAria")}),s.jsx(gt,{checked:C,onChange:y,label:t("settings.notifications.page.events.questionLabel"),ariaLabel:t("settings.notifications.page.events.questionAria")})]})}),!n&&s.jsx(_e,{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(--primary-base)]",children:"{project_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{worktree}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{branch}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{session_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{agent_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{model_name}"})," ",s.jsx("code",{className:"text-[var(--primary-base)]",children:"{last_message}"})]}),children:s.jsx(En,{className:"gap-2 md:grid-cols-2 md:gap-3 lg:gap-3",children:["completion","subtask","error","question"].map(z=>s.jsxs("section",{className:"p-2",children:[s.jsx(Js,{className:"capitalize",children:t(Jf[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(Je,{value:S[z].title,onChange:V=>U(z,"title",V.target.value),className:"h-7",placeholder:t(Qo[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(Je,{value:S[z].message,onChange:V=>U(z,"message",V.target.value),className:"h-7",placeholder:t(Qo[z].messageKey)})]})]})]},z))})})]}),i&&s.jsx(_e,{settingsItem:"notifications.push",title:t("settings.notifications.page.push.title"),children:s.jsx(gt,{checked:A?f:!1,disabled:!A||F,onChange:z=>{z?L():se()},label:t("settings.notifications.page.push.enableLabel"),description:A?void 0:t("settings.notifications.page.push.unsupportedHint"),info:A?t("settings.notifications.page.push.supportedHint"):void 0,ariaLabel:t("settings.notifications.page.push.enableAria"),labelAccessory:F?s.jsx("span",{className:"inline-block h-1.5 w-1.5 rounded-full bg-current text-muted-foreground animate-busy-pulse","aria-label":t("settings.notifications.page.push.loadingAria")}):null})})]})},Es=t=>{if(!t)return;t.pause();const{src:e}=t;e.startsWith("blob:")&&URL.revokeObjectURL(e),t.removeAttribute("src"),t.load()},Yf=[{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"}],Yo=t=>{const e=mt.c(8),{value:a,label:n}=t,i=`${n}: ${a}/5`,r=`${a/5*100}%`;let l;e[0]!==r?(l=s.jsx("span",{className:"h-1.5 w-12 flex-shrink-0 overflow-hidden rounded-full bg-[var(--interactive-border)]","aria-hidden":"true",children:s.jsx("span",{className:"block h-full rounded-full bg-[var(--primary-base)]",style:{width:r}})}),e[0]=r,e[1]=l):l=e[1];let u;e[2]!==n?(u=s.jsx("span",{className:"typography-ui-compact text-muted-foreground",children:n}),e[2]=n,e[3]=u):u=e[3];let p;return e[4]!==i||e[5]!==l||e[6]!==u?(p=s.jsxs("span",{className:"flex items-center gap-1.5",title:i,children:[l,u]}),e[4]=i,e[5]=l,e[6]=u,e[7]=p):p=e[7],p},Zf=({selectedModelId:t,onSelect:e})=>{const{t:a}=at(),n=qe.useCallback(c=>a(c),[a]),[i,r]=qe.useState(new Map),[l,u]=qe.useState(null),p=qe.useCallback(async()=>{try{const c=await pt("/api/dictation/status",{query:{provider:"local"}});if(!c.ok)return;const N=await c.json();Array.isArray(N?.models)&&r(new Map(N.models.map(v=>[v.id,v])))}catch{}},[]);qe.useEffect(()=>{p()},[p]);const h=Array.from(i.values()).some(c=>c.downloading);qe.useEffect(()=>{if(!h)return;const c=setInterval(()=>{p()},2e3);return()=>clearInterval(c)},[h,p]);const d=async c=>{u(c);try{await pt(`/api/dictation/models/${encodeURIComponent(c)}/download`,{method:"POST"}),await p()}catch{}finally{u(null)}},w=async c=>{u(c);try{await pt(`/api/dictation/models/${encodeURIComponent(c)}`,{method:"DELETE"}),await p()}catch{}finally{u(null)}};return s.jsx("div",{role:"radiogroup","aria-label":a("settings.voice.page.field.model"),className:"mt-1.5 grid w-full grid-cols-1 gap-3 @xl:grid-cols-2",children:Yf.map(c=>{const N=t===c.id,v=i.get(c.id)??null;return s.jsx("div",{className:we("rounded-lg border border-[var(--interactive-border)] p-3",N&&"border-[var(--primary-base)] bg-[var(--primary-base)]/5"),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(c.id),onKeyDown:C=>{(C.key===" "||C.key==="Enter")&&(C.preventDefault(),e(c.id))},children:[s.jsx("div",{className:"pt-0.5",children:s.jsx(mr,{checked:N,onChange:()=>e(c.id),ariaLabel:n(c.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:we("typography-ui-label font-normal",N?"text-foreground":"text-foreground/50"),children:n(c.labelKey)}),c.badgeKey?s.jsx("span",{className:"rounded border border-[var(--status-success-border)] bg-[var(--status-success-background)] px-1 text-[9px] font-medium uppercase leading-[14px] tracking-wide text-[var(--status-success)]",children:n(c.badgeKey)}):null]}),s.jsxs("div",{className:"flex flex-col gap-1.5",children:[s.jsx(Yo,{value:c.accuracy,label:a("settings.voice.page.stt.meta.accuracy")}),s.jsx(Yo,{value:c.speed,label:a("settings.voice.page.stt.meta.speed")}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:c.size})]}),v?.downloadError?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:v.downloadError}):null]})]}),s.jsx("div",{className:"flex shrink-0 items-center gap-1",children:v?.installed?s.jsxs(s.Fragment,{children:[s.jsx(B,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0 text-muted-foreground hover:text-[var(--status-error)]",disabled:l===c.id,onClick:()=>{w(c.id)},title:a("settings.voice.page.stt.modelDelete"),"aria-label":a("settings.voice.page.stt.modelDelete"),children:s.jsx(O,{name:"delete-bin",className:"h-4 w-4"})}),s.jsx(O,{name:"checkbox-circle",className:"h-4 w-4 flex-shrink-0 text-[var(--status-success)]","aria-label":a("settings.voice.page.stt.modelInstalled")})]}):v?.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(O,{name:"loader-4",className:"h-3.5 w-3.5 animate-spin text-muted-foreground"}),s.jsx("span",{className:"typography-ui-compact tabular-nums text-muted-foreground",children:typeof v.downloadProgress=="number"?`${v.downloadProgress}%`:""})]}):s.jsx(B,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:l===c.id,onClick:()=>{d(c.id)},title:a("settings.voice.page.stt.modelDownload"),"aria-label":a("settings.voice.page.stt.modelDownload"),children:s.jsx(O,{name:"download",className:"h-4 w-4"})})})]})},c.id)})})},Xf=[{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)"}],cr="kokoro-en-v0_19",eh="kokoro-multi-lang-v1_1",th=[{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)"}],Ta=(t,e)=>`${t}:${e}`,sh=()=>{const[t,e]=qe.useState([]),[a,n]=qe.useState(null),i=qe.useCallback(async()=>{try{const u=await pt("/api/dictation/status",{query:{provider:"local"}});if(!u.ok)return;const p=await u.json();Array.isArray(p?.ttsModels)&&e(p.ttsModels)}catch{}},[]);qe.useEffect(()=>{i()},[i]);const r=t.some(u=>u.downloading);qe.useEffect(()=>{if(!r)return;const u=setInterval(()=>{i()},2e3);return()=>clearInterval(u)},[r,i]);const l=qe.useCallback(async(u,p)=>{n(u);try{const h=p==="POST"?`/api/dictation/models/${u}/download`:`/api/dictation/models/${u}`;await pt(h,{method:p}),await i()}catch{}finally{n(null)}},[i]);return{models:t,requestingId:a,request:l,refresh:i}},nh=t=>{const e=Xf.map(a=>({modelId:cr,speakerId:a.id,label:a.label}));for(const a of t)if(!(a.id===cr||!a.installed)){if(a.id===eh){for(const n of th)e.push({modelId:a.id,speakerId:n.id,label:`${n.label} · Kokoro zh/en`});continue}e.push({modelId:a.id,speakerId:0,label:a.description??a.id})}return e},ah=t=>{const e=mt.c(14),{models:a,requestingId:n,request:i}=t,{t:r}=at();let l,u,p;if(e[0]!==a||e[1]!==i||e[2]!==n||e[3]!==r){p=Symbol.for("react.early_return_sentinel");e:{const d=a.filter(oh);if(d.length===0){p=null;break e}l="flex flex-col";let w;e[7]!==i||e[8]!==n||e[9]!==r?(w=c=>s.jsxs("div",{className:"flex items-center gap-2 py-1.5",children:[s.jsx("span",{className:"typography-ui-label text-foreground",children:c.description??c.id}),c.installed?s.jsxs(s.Fragment,{children:[s.jsx(O,{name:"checkbox-circle",className:"h-4 w-4 text-[var(--status-success)]","aria-label":r("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:n!==null,onClick:()=>{i(c.id,"DELETE")},title:r("settings.voice.page.stt.modelDelete"),"aria-label":r("settings.voice.page.stt.modelDelete"),children:s.jsx(O,{name:"delete-bin",className:"h-4 w-4"})})]}):c.downloading?s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx(O,{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 c.downloadProgress=="number"?`${c.downloadProgress}%`:""})]}):s.jsx(B,{variant:"ghost",size:"xs",className:"h-6 w-6 p-0",disabled:n!==null,onClick:()=>{i(c.id,"POST")},title:r("settings.voice.page.stt.modelDownload"),"aria-label":r("settings.voice.page.stt.modelDownload"),children:s.jsx(O,{name:"download",className:"h-4 w-4"})}),c.downloadError?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:c.downloadError}):null]},c.id),e[7]=i,e[8]=n,e[9]=r,e[10]=w):w=e[10],u=d.map(w)}e[0]=a,e[1]=i,e[2]=n,e[3]=r,e[4]=l,e[5]=u,e[6]=p}else l=e[4],u=e[5],p=e[6];if(p!==Symbol.for("react.early_return_sentinel"))return p;let h;return e[11]!==l||e[12]!==u?(h=s.jsx("div",{className:l,children:u}),e[11]=l,e[12]=u,e[13]=h):h=e[13],h},ih=[{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"}],rh=()=>{const{t}=at(),{isMobile:e}=ma(),a=Ze(H=>H.voiceProvider),n=Ze(H=>H.setVoiceProvider),i=Ze(H=>H.speechRate),r=Ze(H=>H.setSpeechRate),l=Ze(H=>H.speechPitch),u=Ze(H=>H.setSpeechPitch),p=Ze(H=>H.speechVolume),h=Ze(H=>H.setSpeechVolume),d=Ze(H=>H.sayVoice),w=Ze(H=>H.setSayVoice),c=Ze(H=>H.localTtsVoiceId),N=Ze(H=>H.localTtsModelId),v=Ze(H=>H.setLocalTtsModelId),C=sh(),y=qe.useMemo(()=>nh(C.models),[C.models]),S=Ze(H=>H.ttsFollowTextLanguage),g=Ze(H=>H.setTtsFollowTextLanguage),T=Ze(H=>H.setLocalTtsVoiceId),{speak:R,stop:A,isPlaying:j,error:f}=Qc(),b=qe.useCallback(()=>{if(j){A();return}const H=y.find(Be=>Be.modelId===N&&Be.speakerId===c)?.label??String(c);R(t("settings.voice.page.preview.voiceLine",{voiceName:H}),{model:N,speakerId:c,speed:Ze.getState().speechRate})},[j,N,c,y,R,A,t]),F=Ze(H=>H.browserVoice),D=Ze(H=>H.setBrowserVoice),P=Ze(H=>H.openaiVoice),I=Ze(H=>H.setOpenaiVoice),U=Ze(H=>H.openaiApiKey),q=Ze(H=>H.setOpenaiApiKey),k=Ze(H=>H.openaiCompatibleUrl),$=Ze(H=>H.setOpenaiCompatibleUrl),G=Ze(H=>H.openaiCompatibleApiKey),E=Ze(H=>H.setOpenaiCompatibleApiKey),J=Ze(H=>H.openaiCompatibleVoice),X=Ze(H=>H.setOpenaiCompatibleVoice),L=Ze(H=>H.openaiCompatibleTtsModel),se=Ze(H=>H.setOpenaiCompatibleTtsModel),z=Ze(H=>H.showMessageTTSButtons),V=Ze(H=>H.ttsInputMode),_=Ze(H=>H.setTtsInputMode),K=Ze(H=>H.sttProvider),Z=Ze(H=>H.setSttProvider),Y=Ze(H=>H.sttServerUrl),te=Ze(H=>H.setSttServerUrl),ge=Ze(H=>H.sttApiKey),le=Ze(H=>H.setSttApiKey),he=Ze(H=>H.sttModel),ne=Ze(H=>H.setSttModel),ae=Ze(H=>H.sttLocalModel),me=Ze(H=>H.setSttLocalModel),Pe=Ze(H=>H.sttLanguage),Ne=Ze(H=>H.setSttLanguage),Se=Ze(H=>H.setShowMessageTTSButtons),be=Ze(H=>H.dictationEnabled),Ke=Ze(H=>H.setDictationEnabled),[Le,oe]=qe.useState(!1),[xe,Ee]=qe.useState([]),[Ve,$e]=qe.useState(!1),[We,Fe]=qe.useState(null),[ie,re]=qe.useState(!1),[je,ve]=qe.useState(!1),[Re,Ae]=qe.useState(null),[ye,He]=qe.useState(!1),[ue,Ce]=qe.useState(null),[De,Ye]=qe.useState([]),[W,ke]=qe.useState(!1);qe.useEffect(()=>((async()=>{const Be=await Oi.waitForVoices();Ye(Be)})(),"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=()=>{Ye(window.speechSynthesis.getVoices())}),()=>{"speechSynthesis"in window&&(window.speechSynthesis.onvoiceschanged=null)}),[]);const Ie=qe.useMemo(()=>De.filter(H=>H.lang).sort((H,Be)=>{const tt=H.lang.startsWith("en"),rt=Be.lang.startsWith("en");if(tt&&!rt)return-1;if(!tt&&rt)return 1;const ut=H.lang.localeCompare(Be.lang);return ut!==0?ut:H.name.localeCompare(Be.name)}),[De]),Ge=qe.useCallback(()=>{if(W){Oi.cancelSpeech(),ke(!1);return}const H=De.find(ut=>ut.name===F),Be=H?.name??t("settings.voice.page.preview.browserVoiceFallback"),tt=t("settings.voice.page.preview.voiceLine",{voiceName:Be});ke(!0);const rt=new SpeechSynthesisUtterance(tt);rt.rate=i,rt.pitch=l,rt.volume=p,H&&(rt.voice=H,rt.lang=H.lang),rt.onend=()=>ke(!1),rt.onerror=()=>ke(!1),window.speechSynthesis.cancel(),window.speechSynthesis.speak(rt)},[F,De,i,l,p,W,t]);qe.useEffect(()=>()=>{W&&Oi.cancelSpeech()},[W]),qe.useEffect(()=>{if(!z||a!=="openai"&&a!=="openai-compatible"){re(U.trim().length>0);return}(async()=>{try{const rt=(await(await pt("/api/tts/status")).json()).available,ut=U.trim().length>0;re(rt||ut)}catch{re(U.trim().length>0)}})()},[U,z,a]),qe.useEffect(()=>{if(!z){oe(!1),Ee([]);return}pt("/api/tts/say/status").then(H=>H.json()).then(H=>{if(oe(H.available),H.voices){const Be=H.voices.filter((tt,rt,ut)=>ut.findIndex(Ct=>Ct.name===tt.name)===rt).sort((tt,rt)=>tt.name.localeCompare(rt.name));Ee(Be)}}).catch(()=>{oe(!1)})},[z]);const it=qe.useCallback(async()=>{if(We){Es(We),Fe(null),$e(!1);return}$e(!0);let H=null;try{const Be=await pt("/api/tts/say/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:d}),voice:d,rate:Math.round(100+(i-.5)*200)})});if(!Be.ok)throw new Error("Preview failed");const tt=await Be.blob(),rt=URL.createObjectURL(tt);H=new Audio(rt),H.onended=()=>{Es(H),Fe(null),$e(!1)},H.onerror=()=>{Es(H),Fe(null),$e(!1)},Fe(H),await H.play()}catch{Es(H),Fe(null),$e(!1)}},[d,i,We,t]);qe.useEffect(()=>()=>{Es(We)},[We]);const nt=qe.useCallback(async()=>{if(Re){Es(Re),Ae(null),ve(!1);return}ve(!0);let H=null;try{const Be=await pt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.voiceLine",{voiceName:P}),voice:P,speed:i,apiKey:U||void 0})});if(!Be.ok){const ut=await Be.json().catch(()=>({error:"Unknown error"}));throw new Error(ut.error||`HTTP ${Be.status}`)}const tt=await Be.blob(),rt=URL.createObjectURL(tt);H=new Audio(rt),H.onended=()=>{Es(H),Ae(null),ve(!1)},H.onerror=()=>{Es(H),Ae(null),ve(!1)},Ae(H),await H.play()}catch{Es(H),Ae(null),ve(!1)}},[P,i,Re,U,t]);qe.useEffect(()=>()=>{Es(Re)},[Re]);const dt=qe.useCallback(async()=>{if(ue){Es(ue),Ce(null),He(!1);return}if(!k.trim())return;He(!0);let H=null;try{const Be=await pt("/api/tts/speak",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:t("settings.voice.page.preview.customServerLine"),voice:J,model:L||void 0,speed:i,baseURL:k,apiKey:G||void 0})});if(!Be.ok){const ut=await Be.json().catch(()=>({error:"Unknown error"}));throw new Error(ut.error||`HTTP ${Be.status}`)}const tt=await Be.blob(),rt=URL.createObjectURL(tt);H=new Audio(rt),H.onended=()=>{Es(H),Ce(null),He(!1)},H.onerror=()=>{Es(H),Ce(null),He(!1)},Ce(H),await H.play()}catch{Es(H),Ce(null),He(!1)}},[k,J,L,G,i,ue,t]);qe.useEffect(()=>()=>{Es(ue)},[ue]);const xt="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(_e,{settingsItem:"voice.playback",title:t("settings.voice.page.section.playbackAndSummary"),divider:!1,contentClassName:"space-y-4",children:[s.jsx(gt,{checked:z,onChange:Se,label:t("settings.voice.page.field.messageReadAloudButton"),ariaLabel:t("settings.voice.page.field.messageReadAloudButtonAria")}),z&&s.jsxs(s.Fragment,{children:[s.jsx(Ls,{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(qs,{value:a,onChange:n,"aria-label":t("settings.voice.page.field.provider"),className:"w-full gap-1.5 sm:gap-2",options:[{value:"browser",label:t("settings.voice.page.provider.browser")},{value:"local",label:t("settings.voice.page.provider.local")},{value:"openai",label:t("settings.voice.page.provider.openai")},{value:"openai-compatible",label:t("settings.voice.page.provider.custom")},...Le?[{value:"say",label:s.jsxs(s.Fragment,{children:[s.jsx(O,{name:"apple",className:"mr-0.5 h-3.5 w-3.5"}),t("settings.voice.page.provider.say")]})}]:[]]})}),a==="openai"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:we(Et,!ie&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.apiKey")}),s.jsx("span",{className:we(zn,!ie&&"text-[var(--status-error)]/80"),children:t(ie&&!U?"settings.voice.page.field.apiKeyHintUsingConfig":ie?"settings.voice.page.field.apiKeyHintProvide":"settings.voice.page.field.apiKeyHintRequired")}),s.jsxs("div",{className:we("relative",zs),children:[s.jsx("input",{type:"password",value:U,onChange:H=>q(H.target.value),placeholder:"sk-...",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),U&&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(O,{name:"close",className:"w-3.5 h-3.5"})})]})]}),a==="openai-compatible"&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:we(Et,!k.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(Jt,{children:t("settings.voice.page.field.serverUrlHint")})]}),s.jsxs("div",{className:we("relative",zs),children:[s.jsx("input",{type:"text",value:k,onChange:H=>$(H.target.value),placeholder:"http://localhost:8880/v1",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),k&&s.jsx("button",{type:"button",onClick:()=>$(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(O,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Et,children:"API Key"}),s.jsx("span",{className:zn,children:"Optional"}),s.jsxs("div",{className:we("relative",zs),children:[s.jsx("input",{type:"password",value:G,onChange:H=>E(H.target.value),placeholder:"sk-...",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),G&&s.jsx("button",{type:"button",onClick:()=>E(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(O,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Et,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:we("relative",zs),children:s.jsx("input",{type:"text",value:L,onChange:H=>se(H.target.value),placeholder:"speaches-ai/Kokoro-82M-v1.0-ONNX",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Et,children:t("settings.voice.page.field.voice")}),s.jsx(Jt,{children:t("settings.voice.page.field.voiceIdentifierHint")})]}),s.jsxs("div",{className:we("flex items-center gap-2",zs),children:[s.jsx("div",{className:"relative min-w-0 flex-1",children:s.jsx("input",{type:"text",value:J,onChange:H=>X(H.target.value),placeholder:"af_sky",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})}),s.jsx(B,{size:"xs",variant:"ghost",onClick:dt,title:t("settings.voice.page.actions.preview"),disabled:!k.trim(),children:ye?s.jsx(O,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(O,{name:"play",className:"w-3.5 h-3.5"})})]})]})]}),a==="local"&&s.jsx(ah,{...C}),(a==="local"||a==="say")&&s.jsx(gt,{checked:S,onChange:g,label:t("settings.voice.page.field.followTextLanguage"),ariaLabel:t("settings.voice.page.field.followTextLanguageAria"),info:t("settings.voice.page.field.followTextLanguageInfo")}),s.jsxs(Ot,{label:t("settings.voice.page.field.voice"),children:[a==="local"&&s.jsxs(s.Fragment,{children:[s.jsxs(Pt,{value:Ta(N,c),onValueChange:H=>{const Be=y.find(tt=>Ta(tt.modelId,tt.speakerId)===H);Be&&(v(Be.modelId),T(Be.speakerId))},children:[s.jsx(It,{size:Lt,className:en,children:s.jsx(Rt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder"),children:H=>y.find(Be=>Ta(Be.modelId,Be.speakerId)===H)?.label??H})}),s.jsx(At,{children:y.map(H=>s.jsx(ot,{value:Ta(H.modelId,H.speakerId),children:H.label},Ta(H.modelId,H.speakerId)))})]}),s.jsx(B,{size:"xs",variant:"ghost",onClick:b,title:t("settings.voice.page.actions.preview"),children:j?s.jsx(O,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(O,{name:"play",className:"w-3.5 h-3.5"})}),f?s.jsx("span",{className:"typography-meta text-[var(--status-error)]",children:f}):null]}),a==="openai"&&ie&&s.jsxs(s.Fragment,{children:[s.jsxs(Pt,{value:P,onValueChange:I,children:[s.jsx(It,{size:Lt,className:en,children:s.jsx(Rt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(At,{children:ih.map(H=>s.jsx(ot,{value:H.value,children:H.label},H.value))})]}),s.jsx(B,{size:"xs",variant:"ghost",onClick:nt,title:t("settings.voice.page.actions.preview"),children:je?s.jsx(O,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(O,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="openai-compatible"&&s.jsx("span",{className:zn,children:t("settings.voice.page.field.configuredAbove")}),a==="say"&&Le&&xe.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Pt,{value:d,onValueChange:w,children:[s.jsx(It,{size:Lt,className:en,children:s.jsx(Rt,{placeholder:t("settings.voice.page.field.selectVoicePlaceholder")})}),s.jsx(At,{children:xe.map(H=>s.jsx(ot,{value:H.name,children:H.name},H.name))})]}),s.jsx(B,{size:"xs",variant:"ghost",onClick:it,title:t("settings.voice.page.actions.preview"),children:Ve?s.jsx(O,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(O,{name:"play",className:"w-3.5 h-3.5"})})]}),a==="browser"&&Ie.length>0&&s.jsxs(s.Fragment,{children:[s.jsxs(Pt,{value:F||"$auto",onValueChange:H=>D(H==="$auto"?"":H),children:[s.jsx(It,{size:Lt,className:en,children:s.jsx(Rt,{placeholder:t("settings.voice.page.field.auto")})}),s.jsxs(At,{children:[s.jsx(ot,{value:"$auto",children:t("settings.voice.page.field.auto")}),Ie.map(H=>s.jsxs(ot,{value:H.name,children:[H.name," (",H.lang,")"]},H.name))]})]}),s.jsx(B,{size:"xs",variant:"ghost",onClick:Ge,title:t("settings.voice.page.actions.preview"),children:W?s.jsx(O,{name:"stop",className:"w-3.5 h-3.5"}):s.jsx(O,{name:"play",className:"w-3.5 h-3.5"})})]})]}),s.jsxs(Ot,{label:t("settings.voice.page.field.speechRate"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:i,onChange:H=>r(Number(H.target.value)),className:xt}),s.jsx(Ss,{value:i,onValueChange:r,min:.5,max:2,step:.1,className:we(Ps,"tabular-nums")})]}),s.jsxs(Ot,{label:t("settings.voice.page.field.speechPitch"),children:[!e&&s.jsx("input",{type:"range",min:.5,max:2,step:.1,value:l,onChange:H=>u(Number(H.target.value)),className:xt}),s.jsx(Ss,{value:l,onValueChange:u,min:.5,max:2,step:.1,className:we(Ps,"tabular-nums")})]}),s.jsxs(Ot,{label:t("settings.voice.page.field.speechVolume"),children:[!e&&s.jsx("input",{type:"range",min:0,max:1,step:.1,value:p,onChange:H=>h(Number(H.target.value)),className:xt}),e?s.jsx(Ss,{value:Math.round(p*100),onValueChange:H=>h(H/100),min:0,max:100,step:10,className:we(Ps,"tabular-nums")}):s.jsxs("span",{className:"typography-ui-label text-foreground tabular-nums min-w-[3rem] text-right",children:[Math.round(p*100),"%"]})]}),s.jsx(Ls,{title:t("settings.voice.page.field.ttsInputMode"),children:s.jsx(qs,{value:V,onChange:_,"aria-label":t("settings.voice.page.field.ttsInputMode"),className:"w-full gap-1.5 sm:gap-2",options:[{value:"sanitized",label:t("settings.voice.page.field.ttsInputModeSanitized")},{value:"raw",label:t("settings.voice.page.field.ttsInputModeRaw")},{value:"summarized",label:t("settings.voice.page.field.ttsInputModeSummarized")}]})})]})]}),s.jsxs(_e,{settingsItem:"voice.speech-recognition",title:t("settings.voice.page.section.speechRecognition"),contentClassName:"space-y-4",children:[s.jsx(gt,{checked:be,onChange:Ke,label:t("settings.voice.page.field.enableVoiceInput"),ariaLabel:t("settings.voice.page.field.enableVoiceInputAria")}),be&&s.jsxs(s.Fragment,{children:[s.jsx(Ls,{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(qs,{value:K,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")}]})}),K==="local"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Et,children:t("settings.voice.page.field.model")}),s.jsx(Zf,{selectedModelId:ae,onSelect:me})]}),K==="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:we(Et,!Y.trim()&&"text-[var(--status-error)]"),children:t("settings.voice.page.field.serverUrl")}),s.jsx(Jt,{children:t("settings.voice.page.field.sttServerUrlHint")})]}),s.jsxs("div",{className:we("relative",zs),children:[s.jsx("input",{type:"text",value:Y,onChange:H=>te(H.target.value),placeholder:"http://localhost:8001/v1",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),Y&&s.jsx("button",{type:"button",onClick:()=>te(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(O,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Et,children:"API Key"}),s.jsx("span",{className:zn,children:"Optional"}),s.jsxs("div",{className:we("relative",zs),children:[s.jsx("input",{type:"password",value:ge,onChange:H=>le(H.target.value),placeholder:"sk-...",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"}),ge&&s.jsx("button",{type:"button",onClick:()=>le(""),className:"absolute right-2 top-1/2 -translate-y-1/2 text-muted-foreground hover:text-foreground",children:s.jsx(O,{name:"close",className:"w-3.5 h-3.5"})})]})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("span",{className:Et,children:t("settings.voice.page.field.model")}),s.jsx("div",{className:we("relative",zs),children:s.jsx("input",{type:"text",value:he,onChange:H=>ne(H.target.value),placeholder:"deepdml/faster-whisper-large-v3-turbo-ct2",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]}),s.jsxs("div",{className:"space-y-1.5",children:[s.jsxs("span",{className:"flex items-center gap-1.5",children:[s.jsx("span",{className:Et,children:t("settings.voice.page.field.language")}),s.jsx(Jt,{children:t("settings.voice.page.field.sttLanguageHint")})]}),s.jsx("div",{className:"relative max-w-[8rem]",children:s.jsx("input",{type:"text",value:Pe,onChange:H=>Ne(H.target.value),placeholder:"auto",className:"w-full h-7 rounded-lg border border-input bg-transparent px-2 typography-ui-label text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-1 focus:ring-primary/50 focus:border-primary/70"})})]})]})]})]})]})};function oh(t){return t.id===cr||t.installed||t.downloading}const ri=[{value:"1800000",label:"30m",ms:1800*1e3},{value:"180000",label:"3m",ms:180*1e3},{value:"7200000",label:"2h",ms:7200*1e3},{value:"28800000",label:"8h",ms:480*60*1e3},{value:"86400000",label:"24h",ms:1440*60*1e3}],oi=[{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}],lh="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/get-started/create-remote-tunnel/",ch="https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/do-more-with-tunnels/local-management/configuration-file/",Ji=[{value:"quick",labelKey:"settings.aiworker.tunnel.option.mode.quick.label",tooltipKey:"settings.aiworker.tunnel.option.mode.quick.tooltip"},{value:"managed-remote",labelKey:"settings.aiworker.tunnel.option.mode.managedRemote.label",tooltipKey:"settings.aiworker.tunnel.option.mode.managedRemote.tooltip"},{value:"managed-local",labelKey:"settings.aiworker.tunnel.option.mode.managedLocal.label",tooltipKey:"settings.aiworker.tunnel.option.mode.managedLocal.tooltip"}],dh=[".yml",".yaml",".json"],uh="settings.aiworker.tunnel.error.invalidConfigExtension",Ea=t=>{const e=t.trim().toLowerCase();return dh.some(a=>e.endsWith(a))},ph=t=>t==="ngrok"?"ngrok":"cloudflared",Ql=()=>{if(typeof window<"u"&&typeof window.__AIWORKER_PLATFORM__=="string"){const e=window.__AIWORKER_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"},mh=(t,e=Ql())=>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/",Qi=(t,e)=>{const a=typeof e?.provider=="string"&&e.provider.trim().length>0?e.provider.trim().toLowerCase():t,n=typeof e?.dependency=="string"&&e.dependency.trim().length>0?e.dependency.trim():ph(a),i=typeof e?.platform=="string"&&e.platform.trim().length>0?e.platform.trim():Ql(),r=typeof e?.installCommand=="string"&&e.installCommand.trim().length>0?e.installCommand.trim():mh(a,i);return{provider:a,dependency:n,installCommand:r}},Yl=t=>t==="cloudflare"?"Cloudflare":t==="ngrok"?"Ngrok":t,Zo=t=>{const e=mt.c(11),{provider:a}=t;let n;e[0]!==a?(n=Yl(a),e[0]=a,e[1]=n):n=e[1];const i=n,u=a==="cloudflare"||a==="ngrok"?"text-[var(--status-warning)]":"text-muted-foreground";let p;e[2]!==u?(p=we("size-4 shrink-0",u),e[2]=u,e[3]=p):p=e[3];let h;e[4]!==p?(h=s.jsx(O,{name:"cloud",className:p}),e[4]=p,e[5]=h):h=e[5];let d;e[6]!==i?(d=s.jsx("span",{children:i}),e[6]=i,e[7]=d):d=e[7];let w;return e[8]!==h||e[9]!==d?(w=s.jsxs("span",{className:"flex items-center gap-2",children:[h,d]}),e[8]=h,e[9]=d,e[10]=w):w=e[10],w},Tn=t=>t==="quick"?"quick":t==="managed-remote"?"managed-remote":t==="managed-local"?"managed-local":"quick",dr=(t,e,a)=>t.find(i=>i.ms===e)?.value||a,Xo=(t,e,a)=>{const n=dr(t,e,a);return t.find(i=>i.value===n)?.label||n},el=t=>{const e=Math.max(0,t),a=Math.floor(e/1e3),n=Math.floor(a/3600),i=Math.floor(a%3600/60),r=a%60;return n>0?`${n}h ${i}m`:i>0?`${i}m ${r}s`:`${r}s`},gh=(t,e)=>bl(t,e,{hour:"2-digit",precision:"second"}),mi=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()}},fh=t=>{if(!Array.isArray(t))return[];const e=new Set,a=new Set,n=[];for(const i of t){if(!i||typeof i!="object")continue;const r=i,l=typeof r.id=="string"?r.id.trim():"",u=typeof r.name=="string"?r.name.trim():"",p=mi(typeof r.hostname=="string"?r.hostname:"");!l||!u||!p||e.has(l)||a.has(p)||(e.add(l),a.add(p),n.push({id:l,name:u,hostname:p}))}return n},hh=()=>typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2,10)}`,xh=()=>{const{t}=at(),e=de(Q=>Q.timeFormatPreference),a=o.useCallback(Q=>t(Q),[t]),[n,i]=o.useState("checking"),[r,l]=o.useState(null),[u,p]=o.useState(null),[h,d]=o.useState(null),[w,c]=o.useState(null),[N,v]=o.useState(null),[C,y]=o.useState(!1),[S,g]=o.useState(!1),[T,R]=o.useState(!1),[A,j]=o.useState("cloudflare"),[f,b]=o.useState(()=>Qi("cloudflare")),[F,D]=o.useState([]),[P,I]=o.useState("quick"),[U,q]=o.useState(null),[k,$]=o.useState([]),[G,E]=o.useState({}),[J,X]=o.useState(""),[L,se]=o.useState({}),[z,V]=o.useState(new Set),[_,K]=o.useState(!1),[Z,Y]=o.useState(""),[te,ge]=o.useState(""),[le,he]=o.useState(""),[ne,ae]=o.useState(1800*1e3),[me,Pe]=o.useState(480*60*1e3),[Ne,Se]=o.useState(""),[be,Ke]=o.useState([]),[Le,oe]=o.useState(()=>Date.now()),[xe,Ee]=o.useState(null),Ve=t(uh),$e=o.useRef(null),We=o.useMemo(()=>U?!Ea(U):!1,[U]),Fe=o.useMemo(()=>k.find(Q=>Q.id===J)||k[0]||null,[k,J]),ie=o.useMemo(()=>be.map(Q=>{const fe=Q.expiresAt<=Le,Ue=Q.status==="active"&&!fe,Me=Ue?el(Q.expiresAt-Le):Q.inactiveReason==="expired"||fe?"expired":"inactive",ct=Me==="expired"?t("settings.aiworker.tunnel.state.expired"):Q.inactiveReason==="tunnel-revoked"?t("settings.aiworker.tunnel.state.revoked"):t("settings.aiworker.tunnel.state.inactive"),lt=Tn(Q.mode);return{...Q,isActive:Ue,mode:lt,remainingTextForSession:Me,inactiveLabel:ct}}),[Le,be,t]),re=o.useMemo(()=>r?.connectUrl?r.bootstrapExpiresAt===null?!0:r.bootstrapExpiresAt>Le:!1,[Le,r?.bootstrapExpiresAt,r?.connectUrl]),je=o.useMemo(()=>!r||n!=="active"&&n!=="stopping"?!1:u===P,[u,n,r,P]),ve=o.useMemo(()=>!r||n!=="active"||!u?!1:u!==P,[u,n,r,P]),Re=o.useMemo(()=>{if(typeof xe=="number"&&Number.isFinite(xe)&&xe>0)return xe;if(typeof window>"u")return null;const fe=_a()||window.location.href;let Ue=0;try{Ue=Number(new URL(fe).port)}catch{Ue=Number(window.location.port)}return Number.isFinite(Ue)&&Ue>0?Ue:null},[xe]),Ae=o.useMemo(()=>F.find(Q=>Q.provider===A)??null,[F,A]),ye=o.useMemo(()=>{const Q=new Set(Ae?.modes?.map(fe=>fe.key).filter(fe=>fe==="quick"||fe==="managed-remote"||fe==="managed-local"));return Q.size===0?Ji:Ji.filter(fe=>Q.has(fe.value))},[Ae]),He=o.useMemo(()=>ye.some(Q=>Q.value==="managed-remote"||Q.value==="managed-local"),[ye]),ue=o.useMemo(()=>f.provider===A?f:Qi(A),[f,A]),Ce=o.useCallback(async Q=>{await yn(Q)},[]),De=o.useCallback((Q,fe)=>(b(Qi(fe,Q)),Q.available===!0),[]),Ye=o.useCallback(async(Q,fe)=>{try{const Ue=await pt("/api/openchamber/tunnel/check",{query:{provider:Q},...fe?{signal:fe}:{}});if(!Ue.ok)return null;const Me=await Ue.json();if(fe?.aborted)return null;const ct=De(Me,Q);return i(lt=>lt==="checking"||lt==="starting"||lt==="active"||lt==="stopping"?lt:ct?"idle":"not-available"),ct}catch{return null}},[De]),W=o.useCallback(async Q=>{try{const[fe,Ue,Me,ct]=await Promise.all([pt("/api/openchamber/tunnel/check",{signal:Q}),pt("/api/openchamber/tunnel/status",{signal:Q}),pt("/api/config/settings",{signal:Q,headers:{Accept:"application/json"}}),pt("/api/openchamber/tunnel/providers",{signal:Q})]),lt=await fe.json(),Qe=await Ue.json(),Nt=Me.ok?await Me.json():{},xs=ct.ok?await ct.json():{},ts=Qe.ttlConfig?.bootstrapTtlMs??(Nt?.tunnelBootstrapTtlMs===null?null:typeof Nt?.tunnelBootstrapTtlMs=="number"?Nt.tunnelBootstrapTtlMs:1800*1e3),Ms=typeof Qe.ttlConfig?.sessionTtlMs=="number"?Qe.ttlConfig.sessionTtlMs:typeof Nt?.tunnelSessionTtlMs=="number"?Nt.tunnelSessionTtlMs:480*60*1e3,Bt=Tn(Qe.mode??Nt?.tunnelMode),ls=typeof Nt?.tunnelProvider=="string"&&Nt.tunnelProvider.trim().length>0?Nt.tunnelProvider.trim().toLowerCase():"cloudflare",Wt=typeof Nt?.managedLocalTunnelConfigPath=="string"&&Nt.managedLocalTunnelConfigPath.trim()||null,vs=De(lt,ls),ps=fh(Qe?.managedRemoteTunnelPresets),ys=typeof Qe.managedRemoteTunnelHostname=="string"?Qe.managedRemoteTunnelHostname:"",ms=ps.length>0?ps:ys?[{id:`legacy-${mi(ys)}`,name:ys,hostname:mi(ys)}]:[],bs=ms[0]?.id||"";if(ae(ts),Pe(Ms),j(ls),D(Array.isArray(xs?.providers)?xs.providers:[]),I(Bt),q(Wt),$(ms),X(bs),Ke(Array.isArray(Qe.activeSessions)?Qe.activeSessions:[]),p(Qe.activeTunnelMode?Tn(Qe.activeTunnelMode):Qe.active&&Qe.mode?Tn(Qe.mode):null),V(new Set(Array.isArray(Qe.managedRemoteTunnelTokenPresetIds)?Qe.managedRemoteTunnelTokenPresetIds:[])),Ee(typeof Qe.localPort=="number"?Qe.localPort:null),Qe.active&&Qe.url){l({url:Qe.url,connectUrl:null,bootstrapExpiresAt:typeof Qe.bootstrapExpiresAt=="number"?Qe.bootstrapExpiresAt:null}),i("active");return}i(vs?"idle":"not-available")}catch{Q.aborted||(i("error"),c(t("settings.aiworker.tunnel.toast.checkAvailabilityFailed")))}},[De,t]);o.useEffect(()=>{const Q=new AbortController;return W(Q.signal),()=>Q.abort()},[W]),o.useEffect(()=>{if(!r?.connectUrl){d(null);return}let Q=!1;return Tl.toDataURL(r.connectUrl,{width:256,margin:2,color:{dark:"#000000",light:"#ffffff"}}).then(fe=>{Q||d(fe)}).catch(()=>{Q||d(null)}),()=>{Q=!0}},[r?.connectUrl]),o.useEffect(()=>{if(!r?.bootstrapExpiresAt){Se(t("settings.aiworker.tunnel.state.noExpiry"));return}let Q=null,fe=Date.now();const Ue=()=>{const lt=r.bootstrapExpiresAt?r.bootstrapExpiresAt-Date.now():0;lt<=0?Se(t("settings.aiworker.tunnel.state.expired")):Se(el(lt))},Me=()=>{const lt=Date.now();lt-fe>=1e3&&(Ue(),fe=lt),Q=requestAnimationFrame(Me)};Ue(),(typeof document>"u"||document.visibilityState==="visible")&&(Q=requestAnimationFrame(Me));const ct=()=>{document.visibilityState==="visible"&&Q===null?Q=requestAnimationFrame(Me):document.visibilityState!=="visible"&&Q!==null&&(cancelAnimationFrame(Q),Q=null)};return document.addEventListener("visibilitychange",ct),()=>{document.removeEventListener("visibilitychange",ct),Q!==null&&cancelAnimationFrame(Q)}},[t,r?.bootstrapExpiresAt]),o.useEffect(()=>{let Q=null,fe=Date.now();const Ue=()=>{const ct=Date.now();ct-fe>=1e3&&(oe(ct),fe=ct),Q=requestAnimationFrame(Ue)};(typeof document>"u"||document.visibilityState==="visible")&&(Q=requestAnimationFrame(Ue));const Me=()=>{document.visibilityState==="visible"&&Q===null?Q=requestAnimationFrame(Ue):document.visibilityState!=="visible"&&Q!==null&&(cancelAnimationFrame(Q),Q=null)};return document.addEventListener("visibilitychange",Me),()=>{document.removeEventListener("visibilitychange",Me),Q!==null&&cancelAnimationFrame(Q)}},[]),o.useEffect(()=>{if(n==="starting"||n==="stopping"||n==="checking")return;let Q=!1;const fe=async()=>{try{const Me=await pt("/api/openchamber/tunnel/status");if(!Me.ok||Q)return;const ct=await Me.json();if(Q)return;Ke(Array.isArray(ct.activeSessions)?ct.activeSessions:[]),V(new Set(Array.isArray(ct.managedRemoteTunnelTokenPresetIds)?ct.managedRemoteTunnelTokenPresetIds:[])),Ee(typeof ct.localPort=="number"?ct.localPort:null)}catch{}},Ue=window.setInterval(()=>{typeof document<"u"&&document.visibilityState!=="visible"||fe()},5e3);return()=>{Q=!0,window.clearInterval(Ue)}},[n]);const ke=o.useCallback(async Q=>{R(!0);try{await yt(Q),Object.prototype.hasOwnProperty.call(Q,"tunnelMode")&&Q.tunnelMode&&I(Q.tunnelMode),Object.prototype.hasOwnProperty.call(Q,"tunnelProvider")&&typeof Q.tunnelProvider=="string"&&j(Q.tunnelProvider),Object.prototype.hasOwnProperty.call(Q,"managedLocalTunnelConfigPath")&&q(Q.managedLocalTunnelConfigPath??null),Object.prototype.hasOwnProperty.call(Q,"managedRemoteTunnelPresets")&&Q.managedRemoteTunnelPresets&&$(Q.managedRemoteTunnelPresets)}catch{M.error(t("settings.aiworker.tunnel.toast.saveSettingsFailed"))}finally{R(!1)}},[t]),Ie=o.useCallback(async(Q,fe)=>{g(!0);try{await yt({tunnelBootstrapTtlMs:Q,tunnelSessionTtlMs:fe})}catch{M.error(t("settings.aiworker.tunnel.toast.saveTtlFailed"))}finally{g(!1)}},[t]),Ge=o.useCallback(async Q=>{const fe=Q.token.trim();if(fe)try{const Ue={...L,[Q.presetId]:fe};await yt({managedRemoteTunnelPresetTokens:Ue}),V(Me=>{const ct=new Set(Me);return ct.add(Q.presetId),ct})}catch{M.error(t("settings.aiworker.tunnel.toast.saveTokenFailed"))}},[L,t]),it=o.useCallback(async Q=>{v(null),c(null);const fe=F.find(Me=>Me.provider===Q),Ue=fe?.modes?.some(Me=>Me.key===P)?P:Tn(fe?.modes?.[0]?.key);await ke({tunnelProvider:Q,tunnelMode:Ue}),Ye(Q)},[F,Ye,ke,P]),nt=o.useCallback(async()=>{const Q=await Sl({filters:[{name:"Config",extensions:["yml","yaml","json"]}]});if(Q.success&&typeof Q.path=="string"&&Q.path.trim().length>0){const fe=Q.path.trim();if(!Ea(fe)){M.error(Ve);return}q(fe),await ke({managedLocalTunnelConfigPath:fe});return}$e.current?.click()},[Ve,ke]),dt=o.useCallback(Q=>{const fe=Q.trim();q(fe.length>0?fe:null)},[]),xt=o.useCallback(async()=>{if(U&&!Ea(U)){M.error(Ve);return}await ke({managedLocalTunnelConfigPath:U})},[Ve,U,ke]),H=o.useCallback(async()=>{q(null),await ke({managedLocalTunnelConfigPath:null})},[ke]),Be=o.useCallback(async Q=>{const fe=Q.target.files?.[0];if(!fe)return;const Ue=fe.name.trim();if(Ue.length!==0){if(!Ea(Ue)){M.error(Ve);return}q(Ue),await ke({managedLocalTunnelConfigPath:Ue}),Q.target.value=""}},[Ve,ke]),tt=o.useCallback(async()=>{if(c(null),v(null),P==="managed-local"&&U&&!Ea(U)){c(Ve),M.error(Ve);return}i("starting");try{let Q="",fe="";if(P==="managed-remote"){if(!Fe){i("idle"),v(t("settings.aiworker.tunnel.toast.selectOrAddManagedRemoteFirst")),M.error(t("settings.aiworker.tunnel.toast.selectOrAddManagedRemoteFirst"));return}Q=Fe.hostname,fe=(L[Fe.id]||"").trim(),await ke({tunnelMode:"managed-remote",managedRemoteTunnelPresets:k})}const Ue=await pt("/api/openchamber/tunnel/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({provider:A,mode:P,...P==="managed-remote"&&Fe?{managedRemoteTunnelPresetId:Fe.id,managedRemoteTunnelPresetName:Fe.name}:{},...P==="managed-remote"&&Q?{managedRemoteTunnelHostname:Q}:{},...P==="managed-remote"&&fe?{managedRemoteTunnelToken:fe}:{},...P==="managed-local"&&U?{configPath:U}:{}})}),Me=await Ue.json();if(!Ue.ok||!Me.ok){if(P==="managed-remote"&&typeof Me.error=="string"&&Me.error.includes("Managed remote tunnel token is required")){i("idle"),v(t("settings.aiworker.tunnel.toast.managedRemoteTokenRequiredBeforeStarting")),M.error(t("settings.aiworker.tunnel.toast.addManagedRemoteTokenBeforeStarting"));return}i("error"),c(Me.error||t("settings.aiworker.tunnel.toast.startFailed")),M.error(Me.error||t("settings.aiworker.tunnel.toast.startFailed"));return}const ct=typeof Me.url=="string"?Me.url:"";if(!ct){i("error"),c(t("settings.aiworker.tunnel.toast.startedButNoPublicUrl")),M.error(t("settings.aiworker.tunnel.toast.startedButNoPublicUrl"));return}if(l({url:ct,connectUrl:typeof Me.connectUrl=="string"?Me.connectUrl:null,bootstrapExpiresAt:typeof Me.bootstrapExpiresAt=="number"?Me.bootstrapExpiresAt:null}),p(Me.activeTunnelMode?Tn(Me.activeTunnelMode):Me.mode?Tn(Me.mode):P),Ke(Array.isArray(Me.activeSessions)?Me.activeSessions:[]),Array.isArray(Me.managedRemoteTunnelTokenPresetIds)&&V(new Set(Me.managedRemoteTunnelTokenPresetIds)),typeof Me.localPort=="number"&&Ee(Me.localPort),typeof Me.mode=="string"&&I(Tn(Me.mode)),i("active"),Me.replacedTunnel){const lt=typeof Me.revokedBootstrapCount=="number"?Me.revokedBootstrapCount:0,Qe=typeof Me.invalidatedSessionCount=="number"?Me.invalidatedSessionCount:0;lt===1&&Qe===1?M.warning(t("settings.aiworker.tunnel.toast.replacedTunnelSingleSingle")):lt===1?M.warning(t("settings.aiworker.tunnel.toast.replacedTunnelSingleManySessions",{invalidatedSessionCount:Qe})):Qe===1?M.warning(t("settings.aiworker.tunnel.toast.replacedTunnelManyLinksSingleSession",{revokedBootstrapCount:lt})):M.warning(t("settings.aiworker.tunnel.toast.replacedTunnelManyMany",{revokedBootstrapCount:lt,invalidatedSessionCount:Qe}))}else M.success(t("settings.aiworker.tunnel.toast.linkReady"))}catch{i("error"),c(t("settings.aiworker.tunnel.toast.startFailed")),M.error(t("settings.aiworker.tunnel.toast.startFailed"))}},[Ve,k,ke,Fe,L,t,A,P,U]),rt=o.useCallback(async()=>{i("stopping");try{await pt("/api/openchamber/tunnel/stop",{method:"POST"});const Q=await pt("/api/openchamber/tunnel/status");if(Q.ok){const fe=await Q.json();Ke(Array.isArray(fe.activeSessions)?fe.activeSessions:[]),V(new Set(Array.isArray(fe.managedRemoteTunnelTokenPresetIds)?fe.managedRemoteTunnelTokenPresetIds:[])),Ee(typeof fe.localPort=="number"?fe.localPort:null)}l(null),p(null),d(null),i("idle"),M.success(t("settings.aiworker.tunnel.toast.stopped"))}catch{i("error"),c(t("settings.aiworker.tunnel.toast.stopFailed")),M.error(t("settings.aiworker.tunnel.toast.stopFailed"))}},[t]),ut=o.useCallback(async()=>{if(r?.connectUrl)try{await navigator.clipboard.writeText(r.connectUrl),y(!0),M.success(t("settings.aiworker.tunnel.toast.connectLinkCopied")),setTimeout(()=>y(!1),2e3)}catch{M.error(t("settings.aiworker.tunnel.toast.copyUrlFailed"))}},[t,r?.connectUrl]),Ct=o.useCallback(async Q=>{const fe=ri.find(Ue=>Ue.value===Q);fe&&(ae(fe.ms),await Ie(fe.ms,me))},[Ie,me]),et=o.useCallback(async Q=>{const fe=oi.find(Ue=>Ue.value===Q);!fe||fe.ms===null||(Pe(fe.ms),await Ie(ne,fe.ms))},[ne,Ie]),Xe=o.useCallback(async Q=>{v(null),c(null),n!=="active"&&n!=="stopping"&&n!=="starting"&&i("idle"),await ke({tunnelMode:Q,managedRemoteTunnelPresets:k})},[k,ke,n]),ft=o.useCallback(async(Q,fe)=>{try{await yt({managedRemoteTunnelPresets:fe})}catch{M.error(t("settings.aiworker.tunnel.toast.saveSelectedManagedRemoteFailed"))}},[t]),ze=o.useCallback(Q=>{const fe=k.find(Ue=>Ue.id===Q);fe&&(X(fe.id),v(null),ft(fe,k))},[k,ft]),jt=o.useCallback(async()=>{const Q=Z.trim(),fe=mi(te),Ue=le.trim();if(!Q){M.error(t("settings.aiworker.tunnel.toast.tunnelNameRequired"));return}if(!fe){M.error(t("settings.aiworker.tunnel.toast.managedRemoteHostnameRequired"));return}if(!Ue){M.error(t("settings.aiworker.tunnel.toast.managedRemoteTokenRequired"));return}if(k.some(lt=>lt.hostname===fe)){M.error(t("settings.aiworker.tunnel.toast.hostnameAlreadyExists"));return}const Me={id:hh(),name:Q,hostname:fe},ct=[...k,Me];$(ct),X(Me.id),E(lt=>({...lt,[Me.id]:!0})),se(lt=>({...lt,[Me.id]:Ue})),v(null),K(!1),Y(""),ge(""),he(""),await ke({tunnelMode:"managed-remote",managedRemoteTunnelPresets:ct,managedRemoteTunnelPresetTokens:{...L,[Me.id]:Ue}}),await Ge({presetId:Me.id,presetName:Me.name,hostname:Me.hostname,token:Ue}),M.success(t("settings.aiworker.tunnel.toast.managedRemoteSaved"))},[k,te,Z,le,Ge,ke,L,t]),Te=o.useCallback(async Q=>{const fe=k.find(Qe=>Qe.id===Q);if(!fe)return;const Ue=k.filter(Qe=>Qe.id!==fe.id),Me=Ue[0]?.id||"",ct=J===fe.id?Me:J,lt=Object.fromEntries(Object.entries(L).filter(([Qe,Nt])=>Qe!==fe.id&&Nt.trim().length>0));$(Ue),X(ct),E(Qe=>{const Nt={...Qe};return delete Nt[fe.id],Nt}),se(Qe=>{const Nt={...Qe};return delete Nt[fe.id],Nt}),V(Qe=>{const Nt=new Set(Qe);return Nt.delete(fe.id),Nt}),v(null),await ke({managedRemoteTunnelPresets:Ue,managedRemoteTunnelPresetTokens:lt}),M.success(t("settings.aiworker.tunnel.toast.managedRemoteRemoved"))},[k,ke,J,L,t]),wt="gap-2 border-[var(--primary-base)] bg-[var(--primary-base)] text-[var(--primary-foreground)] hover:bg-[var(--primary-hover)] hover:text-[var(--primary-foreground)]";return n==="checking"?s.jsx("div",{className:"flex items-center justify-center py-12",children:s.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-current animate-busy-pulse","aria-label":t("settings.aiworker.tunnel.state.loading")})}):s.jsx(_e,{title:t("settings.aiworker.tunnel.title"),info:s.jsxs("div",{className:"space-y-1",children:[s.jsx("p",{children:t("settings.aiworker.tunnel.description")}),s.jsx("p",{children:t("settings.aiworker.tunnel.note.serverSideEnforced")}),s.jsx("p",{children:t("settings.aiworker.tunnel.note.connectLinksOneTime")})]}),divider:!1,children:s.jsxs("div",{className:"space-y-6",children:[ie.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(O,{name:"information",className:"size-4 text-[var(--status-info)]"}),s.jsx("p",{className:Fr,children:t("settings.aiworker.tunnel.section.redeemedAccessLinks")})]}),s.jsx("div",{className:"space-y-1",children:ie.map(Q=>{const fe=Q.mode==="quick",Ue=Q.mode==="managed-remote",Me=fe?"border-[var(--status-warning-border)] bg-[var(--status-warning-background)] text-[var(--status-warning)]":Ue?"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)]",ct=Q.isActive?fe?"text-[var(--status-warning)]":Ue?"text-[var(--status-info)]":"text-[var(--status-success)]":"text-muted-foreground/50",lt=t(fe?"settings.aiworker.tunnel.badge.quick":Ue?"settings.aiworker.tunnel.badge.remote":"settings.aiworker.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(O,{name:"checkbox-blank-circle-fill",className:we("size-2.5 shrink-0",ct)}),s.jsx("span",{className:we("typography-micro rounded border px-1.5 py-0.5 uppercase",Me),children:lt}),s.jsx("span",{className:"typography-meta text-muted-foreground/80",children:t("settings.aiworker.tunnel.session.redeemedAt",{time:gh(Q.createdAt,e)})}),s.jsx("span",{className:"typography-meta text-foreground",children:Q.isActive?t("settings.aiworker.tunnel.session.expiresIn",{remaining:Q.remainingTextForSession}):Q.inactiveLabel===t("settings.aiworker.tunnel.state.inactive")?t("settings.aiworker.tunnel.state.inactive"):t("settings.aiworker.tunnel.session.inactiveWithReason",{reason:Q.inactiveLabel})})]},Q.sessionId)})})]})}),n==="not-available"&&s.jsx("section",{className:"space-y-2 px-2 pb-2 pt-0",children:s.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-[var(--status-warning)]/30 bg-[var(--status-warning)]/5 p-3",children:[s.jsx(O,{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:Fr,children:t("settings.aiworker.tunnel.notAvailable.dependencyNotFound",{dependency:ue.dependency})}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.aiworker.tunnel.notAvailable.installHint")}),s.jsx("code",{className:"typography-code block rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:ue.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:Et,children:t("settings.aiworker.tunnel.field.provider")}),s.jsxs(Pt,{value:A,onValueChange:Q=>{it(Q)},disabled:T||n==="starting"||n==="stopping",children:[s.jsx(It,{size:Lt,className:"max-w-[16rem]",children:s.jsx(Rt,{placeholder:t("settings.aiworker.tunnel.field.providerPlaceholder"),children:Yl(A)})}),s.jsxs(At,{children:[F.length>0?F.map(Q=>s.jsx(ot,{value:Q.provider,children:s.jsx(Zo,{provider:Q.provider})},Q.provider)):s.jsx(ot,{value:"cloudflare",children:s.jsx(Zo,{provider:"cloudflare"})}),s.jsx(ot,{value:"__more-soon",disabled:!0,children:t("settings.aiworker.tunnel.option.moreProvidersSoon")})]})]})]}),s.jsxs("div",{"data-settings-item":"tunnel.type",className:"space-y-1.5",children:[s.jsx("p",{className:Et,children:t("settings.aiworker.tunnel.field.tunnelType")}),s.jsx("div",{className:"flex flex-wrap items-center gap-1",children:ye.map(Q=>s.jsxs(gr,{children:[s.jsx(fr,{asChild:!0,children:s.jsx(B,{variant:"chip",size:"xs","aria-pressed":P===Q.value,className:"!font-normal",onClick:()=>{Xe(Q.value)},disabled:T||n==="starting"||n==="stopping",children:a(Q.labelKey)})}),s.jsx(gl,{sideOffset:8,className:"max-w-xs",children:a(Q.tooltipKey)})]},Q.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:we(Et,"shrink-0"),children:t("settings.aiworker.tunnel.field.connectLinkTtl")}),s.jsxs(Pt,{value:dr(ri,ne,"1800000"),onValueChange:Q=>{Ct(Q)},disabled:S||T||n==="starting"||n==="stopping",children:[s.jsx(It,{size:Lt,className:"max-w-[11rem] min-w-0",children:s.jsx(Rt,{className:"truncate",children:Xo(ri,ne,"1800000")})}),s.jsx(At,{children:ri.map(Q=>s.jsx(ot,{value:Q.value,children:Q.label},Q.value))})]})]}),s.jsxs("div",{className:"flex min-w-0 items-center gap-2",children:[s.jsx("span",{className:we(Et,"shrink-0"),children:t("settings.aiworker.tunnel.field.tunnelSessionTtl")}),s.jsxs(Pt,{value:dr(oi,me,"28800000"),onValueChange:Q=>{et(Q)},disabled:S||T||n==="starting"||n==="stopping",children:[s.jsx(It,{size:Lt,className:"max-w-[11rem] min-w-0",children:s.jsx(Rt,{className:"truncate",children:Xo(oi,me,"28800000")})}),s.jsx(At,{children:oi.map(Q=>s.jsx(ot,{value:Q.value,children:Q.label},Q.value))})]})]})]}),P==="quick"&&s.jsx("div",{className:"rounded-lg border border-[var(--status-warning)]/35 bg-[var(--status-warning)]/10 p-3",children:s.jsxs("div",{className:"flex items-start gap-2",children:[s.jsx(O,{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.aiworker.tunnel.option.mode.quick.tooltip")}),He&&s.jsx("p",{className:"typography-meta mt-1 text-[var(--status-warning)]",children:t("settings.aiworker.tunnel.warning.quickModeReliability")})]})]})}),P==="managed-remote"&&s.jsxs("div",{"data-settings-item":"tunnel.managed-remote",className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:[typeof Re=="number"&&s.jsx("div",{className:"rounded-md border border-[var(--status-info-border)] bg-[var(--status-info-background)]/35 px-2 py-1.5",children:s.jsxs("p",{className:"typography-meta text-[var(--status-info)]",children:[t("settings.aiworker.tunnel.note.cloudflareConnectorTarget")," ",s.jsxs("code",{children:["http://localhost:",Re]})]})}),s.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[s.jsx(Js,{children:t("settings.aiworker.tunnel.section.savedManagedRemoteTunnels")}),s.jsxs(B,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>K(Q=>!Q),disabled:n==="starting"||n==="stopping"||T,children:[s.jsx(O,{name:"add",className:"h-3.5 w-3.5"}),t("settings.common.actions.create")]})]}),k.length>0?s.jsx("div",{className:"overflow-hidden rounded-md border border-[var(--surface-subtle)]",children:k.map((Q,fe)=>{const Ue=L[Q.id]||"",Me=z.has(Q.id),ct=G[Q.id]??!1;return s.jsx("div",{className:we(fe<k.length-1&&"border-b border-[var(--surface-subtle)]"),children:s.jsxs(bn,{open:ct,onOpenChange:lt=>{E(Qe=>({...Qe,[Q.id]:lt})),lt&&ze(Q.id)},className:"py-1.5",children:[s.jsxs("div",{className:"flex items-start gap-2 px-3",children:[s.jsxs(wn,{type:"button",className:"group flex-1 justify-start gap-2 rounded-md px-0 py-1 pr-1 text-left hover:bg-[var(--interactive-hover)]",disabled:n==="starting"||n==="stopping"||T,children:[ct?s.jsx(O,{name:"arrow-down-s",className:"h-4 w-4 text-muted-foreground"}):s.jsx(O,{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:Q.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.aiworker.tunnel.actions.removePresetAria",{name:Q.name}),onClick:()=>{Te(Q.id)},disabled:n==="starting"||n==="stopping"||T,children:s.jsx(O,{name:"delete-bin",className:"h-3.5 w-3.5"})})]}),s.jsx(jn,{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.aiworker.tunnel.field.hostnameLabel")," ",s.jsx("code",{children:Q.hostname})]}),s.jsx(Je,{type:"password",value:Ue,onChange:lt=>{const Qe=lt.target.value;v(null),se(Nt=>({...Nt,[Q.id]:Qe}))},onBlur:lt=>{const Qe=lt.currentTarget.value.trim();Qe&&Ge({presetId:Q.id,presetName:Q.name,hostname:Q.hostname,token:Qe})},placeholder:t(Me?"settings.aiworker.tunnel.field.savedTokenAvailablePlaceholder":"settings.aiworker.tunnel.field.pasteTokenPlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"}),s.jsx("div",{className:"flex items-center justify-end",children:s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal",disabled:n==="starting"||n==="stopping"||Ue.trim().length===0,onClick:()=>{Ge({presetId:Q.id,presetName:Q.name,hostname:Q.hostname,token:Ue})},children:t("settings.aiworker.tunnel.actions.saveToken")})})]})})]})},Q.id)})}):s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t("settings.aiworker.tunnel.empty.noManagedRemoteTunnels")}),_&&s.jsxs("div",{className:"space-y-2 rounded-md border border-[var(--surface-subtle)] p-2",children:[s.jsx(Je,{value:Z,onChange:Q=>Y(Q.target.value),placeholder:t("settings.aiworker.tunnel.field.newPresetNamePlaceholder"),className:"h-7",disabled:T||n==="starting"||n==="stopping"}),s.jsx(Je,{value:te,onChange:Q=>ge(Q.target.value),placeholder:t("settings.aiworker.tunnel.field.newPresetHostnamePlaceholder"),className:"h-7",disabled:T||n==="starting"||n==="stopping"}),s.jsx(Je,{type:"password",value:le,onChange:Q=>he(Q.target.value),placeholder:t("settings.aiworker.tunnel.field.newPresetTokenPlaceholder"),className:"h-7",disabled:T||n==="starting"||n==="stopping"}),typeof Re=="number"&&s.jsxs("p",{className:"typography-meta text-muted-foreground/70",children:[t("settings.aiworker.tunnel.note.cloudflareConnectorTargetUse")," ",s.jsxs("code",{children:["http://localhost:",Re]}),"."]}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{jt()},disabled:T||n==="starting"||n==="stopping",children:t("settings.common.actions.saveChanges")}),s.jsx(B,{variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>{K(!1),Y(""),ge(""),he("")},disabled:T||n==="starting"||n==="stopping",children:t("settings.common.actions.cancel")})]})]}),s.jsxs("div",{className:"flex items-center gap-1.5",children:[s.jsx("p",{className:"typography-meta text-muted-foreground/80",children:t("settings.aiworker.tunnel.note.tokensSavedPerTunnel")}),s.jsx(Jt,{children:t("settings.aiworker.tunnel.tooltip.tokensSavedPath")})]}),!Fe&&N&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:N})]}),P==="managed-local"&&s.jsx("div",{"data-settings-item":"tunnel.managed-local-config",className:"space-y-2 rounded-lg border border-[var(--interactive-border)] bg-[var(--surface-elevated)] p-3",children:s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:Et,children:t("settings.aiworker.tunnel.field.configurationFile")}),s.jsx("input",{ref:$e,type:"file",accept:".yml,.yaml,.json",className:"hidden",onChange:Q=>{Be(Q)}}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx(Je,{value:U||"",onChange:Q=>{dt(Q.target.value)},onBlur:()=>{xt()},placeholder:t("settings.aiworker.tunnel.field.configurationFilePlaceholder"),className:"h-7",disabled:n==="starting"||n==="stopping"||T}),s.jsx(B,{variant:"outline",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.aiworker.tunnel.actions.browseConfigFileAria"),onClick:()=>{nt()},disabled:n==="starting"||n==="stopping"||T,children:s.jsx(O,{name:"folder",className:"size-3.5"})}),U&&s.jsx(B,{variant:"ghost",size:"xs",className:"h-7 w-7 p-0","aria-label":t("settings.aiworker.tunnel.actions.clearConfigFileAria"),onClick:()=>{H()},disabled:n==="starting"||n==="stopping"||T,children:s.jsx(O,{name:"close",className:"size-3.5"})})]}),s.jsx("p",{className:"typography-meta text-muted-foreground/70",children:t(U?"settings.aiworker.tunnel.note.customConfigUsed":"settings.aiworker.tunnel.note.defaultConfigUsed")}),We&&s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:Ve})]})}),!je&&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(O,{name:"information",className:"mt-0.5 size-4 shrink-0 text-[var(--status-info)]"}),s.jsxs("div",{className:"space-y-1",children:[P==="managed-remote"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.aiworker.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:()=>{Ce(lh)},children:[t("settings.aiworker.tunnel.actions.openManagedRemoteDocs"),s.jsx(O,{name:"external-link",className:"size-3.5"})]})]}),P==="managed-local"&&s.jsxs(s.Fragment,{children:[s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.aiworker.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:()=>{Ce(ch)},children:[t("settings.aiworker.tunnel.actions.openManagedLocalDocs"),s.jsx(O,{name:"external-link",className:"size-3.5"})]})]}),s.jsx("p",{className:"typography-meta text-[var(--status-info)]",children:t("settings.aiworker.tunnel.note.startModeAndGenerateLink",{mode:a(Ji.find(Q=>Q.value===P)?.labelKey??"settings.aiworker.tunnel.option.mode.quick.label")})})]})]})}),P==="managed-remote"&&s.jsxs("div",{className:"space-y-1.5",children:[s.jsx("p",{className:Et,children:t("settings.aiworker.tunnel.field.managedRemoteTunnelToConnect")}),s.jsxs(Pt,{value:J||(k[0]?.id??""),onValueChange:Q=>{ze(Q)},disabled:T||n==="starting"||n==="stopping"||k.length<=1,children:[s.jsx(It,{size:Lt,children:s.jsx(Rt,{placeholder:t("settings.aiworker.tunnel.field.selectSavedTunnelPlaceholder"),children:Fe?.name})}),s.jsx(At,{fitContent:!0,children:k.map(Q=>s.jsx(ot,{value:Q.id,children:Q.name},Q.id))})]})]}),ve&&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(O,{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.aiworker.tunnel.warning.replacesActiveTunnel")})]})}),s.jsx(B,{size:"sm",variant:"outline",onClick:tt,disabled:n==="starting"||T||P==="managed-remote"&&!Fe||P==="managed-local"&&We,className:we(wt,n==="starting"&&"opacity-70"),children:n==="starting"?s.jsxs(s.Fragment,{children:[s.jsx(O,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.aiworker.tunnel.actions.startingTunnel")]}):t("settings.aiworker.tunnel.actions.startTunnel")})]})]}),je&&r&&s.jsxs("section",{"data-settings-item":"tunnel.start",className:"space-y-4 px-2 pb-2 pt-0",children:[s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("div",{className:"size-2 shrink-0 rounded-full bg-[var(--status-success)]"}),s.jsx("p",{className:"typography-meta font-medium text-foreground",children:t("settings.aiworker.tunnel.state.tunnelReady")})]}),s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.aiworker.tunnel.field.publicUrlHint")}),s.jsx("code",{className:"typography-code block truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:r.url})]}),re&&r.connectUrl&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{children:[s.jsx("p",{className:"typography-meta mb-1 text-muted-foreground/70",children:t("settings.aiworker.tunnel.field.connectLink")}),s.jsxs("div",{className:"flex items-center gap-2",children:[s.jsx("code",{className:"typography-code flex-1 truncate rounded bg-muted/50 px-2 py-1 text-xs text-foreground",children:r.connectUrl}),s.jsxs(B,{size:"sm",variant:"ghost",onClick:ut,className:"shrink-0 gap-1.5",children:[C?s.jsx(O,{name:"check",className:"size-3.5 text-[var(--status-success)]"}):s.jsx(O,{name:"file-copy",className:"size-3.5"}),t(C?"settings.aiworker.tunnel.actions.copied":"settings.common.actions.copyAll")]})]}),s.jsxs("p",{className:"typography-meta mt-1 text-muted-foreground/70",children:[t("settings.aiworker.tunnel.field.expires"),": ",r.bootstrapExpiresAt?Ne:t("settings.aiworker.tunnel.state.never")]})]}),s.jsxs("div",{className:"flex flex-col items-center gap-2 rounded-lg border border-border/50 bg-[var(--surface-elevated)] p-4",children:[h?s.jsx("img",{src:h,alt:t("settings.aiworker.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.aiworker.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:tt,disabled:n==="stopping"||T||P==="managed-local"&&We,className:wt,children:[s.jsx(O,{name:"restart",className:"size-3.5"}),t("settings.aiworker.tunnel.actions.newConnectLink")]}),s.jsx(B,{size:"sm",variant:"ghost",onClick:rt,disabled:n==="stopping"||T,className:"gap-2 text-[var(--status-error)]",children:n==="stopping"?s.jsxs(s.Fragment,{children:[s.jsx(O,{name:"loader-4",className:"size-3.5 animate-spin"})," ",t("settings.aiworker.tunnel.actions.stopping")]}):t("settings.aiworker.tunnel.actions.stopTunnel")})]})})]}),n==="error"&&w&&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:w}),s.jsx(B,{size:"sm",variant:"ghost",onClick:tt,children:t("settings.aiworker.tunnel.actions.retry")})]})]})})},Zl=()=>{const{t}=at(),[e,a]=qe.useState(""),[n,i]=qe.useState(!0),[r,l]=qe.useState(!1),u=de(c=>c.showOpenCodeUpdateNotifications),p=de(c=>c.setShowOpenCodeUpdateNotifications);qe.useEffect(()=>{let c=!1;return(async()=>{try{const N=await pt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!N.ok)return;const v=await N.json().catch(()=>null);if(c||!v)return;const C=typeof v.opencodeBinary=="string"?v.opencodeBinary.trim():"";a(C)}catch{}finally{c||i(!1)}})(),()=>{c=!0}},[]);const h=qe.useCallback(async()=>{if(!(typeof window>"u")&&os())try{const c=await Sl();c.success&&c.path&&c.path.trim().length>0&&a(c.path.trim())}catch{}},[]),d=qe.useCallback(async()=>{l(!0);try{const c=e.trim(),N=c.length>=2&&(c.startsWith('"')&&c.endsWith('"')||c.startsWith("'")&&c.endsWith("'"))?c.slice(1,-1).trim():c;await yt({opencodeBinary:N}),$n("cli",{id:"opencode-binary"}),M.success(t("settings.view.pendingRestart.saved"))}finally{l(!1)}},[t,e]),w=qe.useCallback(c=>{p(c),yt({showOpenCodeUpdateNotifications:c})},[p]);return s.jsx(_e,{title:t("settings.aiworker.opencodeCli.title"),children:s.jsxs("div",{className:"space-y-0.5",children:[s.jsxs(Ot,{settingsItem:"sessions.opencode-binary",label:t("settings.aiworker.opencodeCli.field.binaryPath"),info:s.jsxs(s.Fragment,{children:[t("settings.aiworker.opencodeCli.tipPrefix")," ",s.jsx("span",{className:"font-mono",children:"OPENCODE_BINARY"})," ",t("settings.aiworker.opencodeCli.tipMiddle")," ",s.jsx("span",{className:"font-mono",children:"~/.config/openchamber/settings.json"}),"."]}),alignEnd:!1,controlClassName:"@xl:w-[20rem]",children:[s.jsx(Je,{value:e,onChange:c=>a(c.target.value),placeholder:t("settings.aiworker.opencodeCli.field.binaryPathPlaceholder"),disabled:n||r,className:"h-8 min-w-0 flex-1 font-mono text-xs"}),s.jsx(B,{type:"button",variant:"outline",size:"xs",onClick:h,disabled:n||r||!os(),className:fs,"aria-label":t("settings.aiworker.opencodeCli.actions.browseAria"),title:t("settings.aiworker.opencodeCli.actions.browse"),children:s.jsx(O,{name:"folder",className:"h-4 w-4"})})]}),s.jsxs(Ua,{className:hs,children:[!Cl()&&s.jsx(gt,{settingsItem:"sessions.opencode-update-notifications",checked:u,onChange:w,label:t("settings.aiworker.opencodeCli.field.showUpdateNotifications"),ariaLabel:t("settings.aiworker.opencodeCli.field.showUpdateNotificationsAria")}),s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(B,{type:"button",size:"xs",onClick:d,disabled:n||r,className:"shrink-0 !font-normal",children:t(r?"settings.common.actions.saving":"settings.common.actions.saveChanges")})})]})]})})},Xl=()=>{const t=mt.c(44),{t:e}=at(),a=de(vh),n=de(yh),i=de(bh),r=de(wh),l=de(jh),u=de(kh),p=de(Nh);let h;t[0]!==n?(h=P=>{n(P),yt({agentControlToolEnabled:P}),$n("cli",{id:"agent-control-tool"})},t[0]=n,t[1]=h):h=t[1];const d=h;let w;t[2]!==r?(w=P=>{r(P),yt({agentWebToolEnabled:P}),$n("cli",{id:"agent-web-tool"})},t[2]=r,t[3]=w):w=t[3];const c=w;let N;t[4]!==p?(N=P=>{p(P),yt({agentMemoryToolEnabled:P}).finally(()=>{P&&Yc.getState().refresh()}),$n("cli",{id:"agent-memory-tool"})},t[4]=p,t[5]=N):N=t[5];const v=N;let C;t[6]!==e?(C=e("settings.aiworker.tools.title"),t[6]=e,t[7]=C):C=t[7];let y;t[8]!==e?(y=e("settings.aiworker.tools.field.agentControlTool"),t[8]=e,t[9]=y):y=t[9];let S;t[10]!==e?(S=e("settings.aiworker.tools.field.agentControlToolAria"),t[10]=e,t[11]=S):S=t[11];let g;t[12]!==e?(g=e("settings.aiworker.tools.field.agentControlToolInfo"),t[12]=e,t[13]=g):g=t[13];let T;t[14]!==a||t[15]!==d||t[16]!==y||t[17]!==S||t[18]!==g?(T=s.jsx(gt,{settingsItem:"sessions.agent-control-tool",checked:a,onChange:d,label:y,ariaLabel:S,info:g}),t[14]=a,t[15]=d,t[16]=y,t[17]=S,t[18]=g,t[19]=T):T=t[19];let R;t[20]!==e?(R=e("settings.aiworker.tools.field.agentWebTool"),t[20]=e,t[21]=R):R=t[21];let A;t[22]!==e?(A=e("settings.aiworker.tools.field.agentWebToolAria"),t[22]=e,t[23]=A):A=t[23];let j;t[24]!==e?(j=e("settings.aiworker.tools.field.agentWebToolInfo"),t[24]=e,t[25]=j):j=t[25];let f;t[26]!==i||t[27]!==c||t[28]!==j||t[29]!==R||t[30]!==A?(f=s.jsx(gt,{settingsItem:"sessions.agent-web-tool",checked:i,onChange:c,label:R,ariaLabel:A,info:j}),t[26]=i,t[27]=c,t[28]=j,t[29]=R,t[30]=A,t[31]=f):f=t[31];let b;t[32]!==u||t[33]!==l||t[34]!==v||t[35]!==e?(b=u?s.jsx(gt,{settingsItem:"sessions.agent-memory-tool",checked:l,onChange:v,label:e("settings.aiworker.tools.field.agentMemoryTool"),ariaLabel:e("settings.aiworker.tools.field.agentMemoryToolAria"),info:e("settings.aiworker.tools.field.agentMemoryToolInfo")}):null,t[32]=u,t[33]=l,t[34]=v,t[35]=e,t[36]=b):b=t[36];let F;t[37]!==f||t[38]!==b||t[39]!==T?(F=s.jsxs("div",{className:hs,children:[T,f,b]}),t[37]=f,t[38]=b,t[39]=T,t[40]=F):F=t[40];let D;return t[41]!==F||t[42]!==C?(D=s.jsx(_e,{title:C,children:F}),t[41]=F,t[42]=C,t[43]=D):D=t[43],D};function vh(t){return t.agentControlToolEnabled}function yh(t){return t.setAgentControlToolEnabled}function bh(t){return t.agentWebToolEnabled}function wh(t){return t.setAgentWebToolEnabled}function jh(t){return t.agentMemoryToolEnabled}function kh(t){return t.agentMemoryFeatureAvailable}function Nh(t){return t.setAgentMemoryToolEnabled}const ec=()=>{const{t}=at(),e=os()&&$a(),a=e&&typeof window<"u"&&window.__AIWORKER_PLATFORM__==="darwin",[n,i]=qe.useState(!1),[r,l]=qe.useState(!1),[u,p]=qe.useState(""),[h,d]=qe.useState(""),[w,c]=qe.useState(!1),[N,v]=qe.useState(!1),[C,y]=qe.useState(null),[S,g]=qe.useState(!0),[T,R]=qe.useState(!1),[A,j]=qe.useState(!1),[f,b]=qe.useState(!1),[F,D]=qe.useState(!1),[P,I]=qe.useState(!1),[U,q]=qe.useState(!1),[k,$]=qe.useState(!1),[G,E]=qe.useState(!0),[J,X]=qe.useState(!0),[L,se]=qe.useState(!1),[z,V]=qe.useState(!1),[_,K]=qe.useState(!1),[Z,Y]=qe.useState(null),[te,ge]=qe.useState(null);qe.useEffect(()=>{if(!e){g(!1);return}let oe=!1;return(async()=>{try{const xe=await pt("/api/config/settings",{method:"GET",headers:{Accept:"application/json"}});if(!xe.ok)throw new Error(t("settings.aiworker.desktopNetwork.error.loadFailed"));const Ee=await xe.json().catch(()=>null);if(oe)return;const Ve=Ee?.desktopLanAccessEnabled===!0,$e=typeof Ee?.desktopUiPassword=="string"?Ee.desktopUiPassword:"";i(Ve),l(Ve),p($e),d($e),v(Ee?.desktopLanAccessActive===!0),y(typeof Ee?.desktopLanAccessBlockedReason=="string"?Ee.desktopLanAccessBlockedReason:null);const We=Ee?.desktopMacMenuBarEnabled!==!1;E(We),X(We),Y(null)}catch(xe){oe||Y(xe instanceof Error?xe.message:t("settings.aiworker.desktopNetwork.error.loadFailed"))}finally{oe||g(!1)}})(),()=>{oe=!0}},[e,t]),qe.useEffect(()=>{if(!e){j(!1);return}let oe=!1;return(async()=>{const xe=await Pd();oe||(j(xe?.supported===!0),b(xe?.enabled===!0))})(),()=>{oe=!0}},[e]),qe.useEffect(()=>{if(!e){I(!1);return}let oe=!1;return(async()=>{const xe=await Id();oe||(I(xe?.supported===!0),q(xe?.enabled===!0))})(),()=>{oe=!0}},[e]),qe.useEffect(()=>{if(!e){se(!1);return}let oe=!1;return(async()=>{const xe=await Ad();oe||(se(xe?.supported===!0),V(xe?.enabled===!0))})(),()=>{oe=!0}},[e]),qe.useEffect(()=>{if(!e||!r){ge(null);return}let oe=!1;return(async()=>{const xe=await kl();oe||ge(xe)})(),()=>{oe=!0}},[r,e]);const le=r!==n||h!==u||J!==G,he=qe.useMemo(()=>{if(typeof window>"u")return null;const xe=_a()||window.location.href;let Ee=0;try{Ee=Number(new URL(xe).port)}catch{Ee=Number(window.location.port)}return Number.isFinite(Ee)&&Ee>0?Ee:null},[]),ne=r&&N&&te&&he?`http://${te}:${he}`:null,ae=r&&!h.trim(),me=n&&!N&&C==="missing-password",Pe=S||T||!le||ae,Ne=qe.useCallback(oe=>{d(oe),oe.trim()||l(!1)},[]),Se=qe.useCallback(async()=>{if(!A||F)return;const oe=!f;b(oe),D(!0),Y(null);try{const xe=await Td(oe);if(!xe?.supported)throw new Error(t("settings.aiworker.desktopNetwork.error.launchAtLoginUnsupported"));b(xe.enabled)}catch(xe){b(!oe),Y(xe instanceof Error?xe.message:t("settings.aiworker.desktopNetwork.error.launchAtLoginSaveFailed"))}finally{D(!1)}},[F,f,A,t]),be=qe.useCallback(async()=>{if(!P||k)return;const oe=!U;q(oe),$(!0),Y(null);try{const xe=await Ed(oe);if(!xe)throw new Error(t("settings.aiworker.desktopNetwork.error.minimizeToTraySaveFailed"));if(!xe.supported)throw new Error(t("settings.aiworker.desktopNetwork.error.minimizeToTrayUnsupported"));q(xe.enabled)}catch(xe){q(!oe),Y(xe instanceof Error?xe.message:t("settings.aiworker.desktopNetwork.error.minimizeToTraySaveFailed"))}finally{$(!1)}},[k,U,P,t]),Ke=qe.useCallback(async()=>{if(!L||_)return;const oe=!z;V(oe),K(!0),Y(null);try{const xe=await Dd(oe);if(!xe?.supported)throw new Error(t("settings.aiworker.desktopNetwork.error.keepAwakeUnsupported"));V(xe.enabled)}catch(xe){V(!oe),Y(xe instanceof Error?xe.message:t("settings.aiworker.desktopNetwork.error.keepAwakeSaveFailed"))}finally{K(!1)}},[_,z,L,t]),Le=qe.useCallback(async()=>{if(le){R(!0),Y(null);try{if(!(await pt("/api/config/settings",{method:"PUT",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({desktopLanAccessEnabled:r,desktopUiPassword:h,desktopMacMenuBarEnabled:J})})).ok)throw new Error(t("settings.aiworker.desktopNetwork.error.saveFailed"));if(i(r),p(h),E(J),!await Md())throw new Error(t("settings.aiworker.desktopNetwork.error.savedRestartFailed"))}catch(oe){Y(oe instanceof Error?oe.message:t("settings.aiworker.desktopNetwork.error.saveFailed")),R(!1)}}},[J,h,r,le,t]);return e?s.jsx(_e,{title:t("settings.aiworker.desktopNetwork.title"),children:s.jsxs("div",{className:"space-y-3",children:[A||a||P||L?s.jsxs("div",{className:hs,children:[A?s.jsx(gt,{settingsItem:"sessions.desktop-launch-at-login",checked:f,onChange:oe=>{oe!==f&&Se()},disabled:F,label:t("settings.aiworker.desktopNetwork.field.launchAtLogin"),info:t("settings.aiworker.desktopNetwork.field.launchAtLoginDescription"),ariaLabel:t("settings.aiworker.desktopNetwork.field.launchAtLoginAria")}):null,a?s.jsx(gt,{settingsItem:"sessions.desktop-mac-menu-bar",checked:J,onChange:X,disabled:S||T,label:t("settings.aiworker.desktopNetwork.field.macMenuBar"),info:t("settings.aiworker.desktopNetwork.field.macMenuBarDescription"),ariaLabel:t("settings.aiworker.desktopNetwork.field.macMenuBarAria")}):null,P?s.jsx(gt,{settingsItem:"sessions.desktop-minimize-to-tray",checked:U,onChange:oe=>{oe!==U&&be()},disabled:k,label:t("settings.aiworker.desktopNetwork.field.minimizeToTray"),info:t("settings.aiworker.desktopNetwork.field.minimizeToTrayDescription"),ariaLabel:t("settings.aiworker.desktopNetwork.field.minimizeToTrayAria")}):null,L?s.jsx(gt,{settingsItem:"sessions.desktop-keep-awake",checked:z,onChange:oe=>{oe!==z&&Ke()},disabled:_,label:t("settings.aiworker.desktopNetwork.field.keepAwake"),info:t("settings.aiworker.desktopNetwork.field.keepAwakeDescription"),ariaLabel:t("settings.aiworker.desktopNetwork.field.keepAwakeAria")}):null]}):null,s.jsxs(qt,{settingsItem:"sessions.desktop-ui-password",label:s.jsx("label",{htmlFor:"desktop-ui-password",children:t("settings.aiworker.desktopPassword.field.password")}),info:t("settings.aiworker.desktopPassword.field.passwordDescription"),children:[s.jsx(Je,{id:"desktop-ui-password",type:w?"text":"password",className:"h-8 min-w-0 flex-1",value:h,onChange:oe=>Ne(oe.target.value),placeholder:t("settings.aiworker.desktopPassword.field.passwordPlaceholder"),disabled:S||T,required:r,"aria-invalid":ae}),s.jsx(B,{type:"button",variant:"ghost",size:"xs",onClick:()=>c(oe=>!oe),className:fs,"aria-label":t(w?"settings.aiworker.desktopPassword.actions.hidePassword":"settings.aiworker.desktopPassword.actions.showPassword"),"aria-pressed":w,children:s.jsx(O,{name:w?"eye-off":"eye",className:"h-4 w-4"})})]}),s.jsx("div",{className:hs,children:s.jsx(gt,{settingsItem:"sessions.desktop-lan-access",checked:r,onChange:l,disabled:S||T,label:t("settings.aiworker.desktopNetwork.field.allowLanAccess"),info:t("settings.aiworker.desktopNetwork.field.allowLanAccessDescription"),description:s.jsxs(s.Fragment,{children:[s.jsx("span",{className:"block text-[var(--status-warning)]/85",children:t("settings.aiworker.desktopNetwork.field.warning")}),ae||me?s.jsx("span",{className:"block text-[var(--status-warning)]/85",children:t("settings.aiworker.desktopNetwork.field.passwordRequiredWarning")}):null]}),ariaLabel:t("settings.aiworker.desktopNetwork.field.allowLanAccessAria")})}),Z?s.jsx("div",{className:"typography-micro text-[var(--status-error)]",children:Z}):null,ne?s.jsxs("div",{className:"typography-micro text-muted-foreground/80",children:[t(le&&!n?"settings.aiworker.desktopNetwork.hint.openAfterRestart":"settings.aiworker.desktopNetwork.hint.openNow"),s.jsx("span",{className:"font-mono text-foreground",children:ne})]}):null,s.jsx("div",{className:"flex justify-start py-1.5",children:s.jsx(B,{type:"button",size:"xs",onClick:Le,disabled:Pe,className:"shrink-0 !font-normal",children:t(T?"settings.common.actions.saving":"settings.aiworker.desktopNetwork.actions.saveAndRestart")})})]})}):null},tc=new Set(["shift","control","alt","meta"]),Sr=3,Sh=3e3;function Cr(t,e=!1){const a=new Set;return t.altKey&&a.add("alt"),t.ctrlKey&&a.add("control"),t.metaKey&&a.add("meta"),t.shiftKey&&a.add("shift"),e&&a.add(t.key.toLowerCase()),a.size}function Ch(t){return t.action.customizable}function tl(t){if(Cr(t)>Sr)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?vi(e.join("+")):null}function Ph(t){if(tc.has(t.key.toLowerCase())||Cr(t,!0)>Sr)return null;const e=ed(td(t));if(!e)return null;const a=[];return(t.metaKey||t.ctrlKey)&&a.push("mod"),t.shiftKey&&a.push("shift"),t.altKey&&a.push("alt"),a.push(e),vi(a.join("+"))}function Ih(t){const e=t.key.toLowerCase();if(!tc.has(e)||Cr(t,!0)>Sr)return null;const a=[];return(t.metaKey||t.ctrlKey||e==="meta"||e==="control")&&a.push("mod"),(t.shiftKey||e==="shift")&&a.push("shift"),(t.altKey||e==="alt")&&a.push("alt"),a.length>0?vi(a.join("+")):null}function sl(t){return t.chords.length>0?{...t,livePreview:null,settled:!0}:t}function Ah(t,e,a){if(e.repeat||e.isComposing)return t;if(a==="keyup")return{...t,livePreview:tl(e)};if(e.key==="Backspace")return{chords:t.chords.slice(0,-1),livePreview:null,settled:!1};const n=Ph(e);if(n){if(t.settled)return{chords:[n],livePreview:null,settled:!1};const i=t.chords.length<2?[...t.chords,n]:t.chords;return{chords:i,livePreview:null,settled:i.length===2}}return{...t,livePreview:tl(e)}}const Th=t=>{const e=mt.c(117),{action:a,overrides:n,onSave:i,onOpenChange:r}=t,{t:l}=at();let u;e[0]!==l?(u=ae=>l(ae.settingsLabelKey),e[0]=l,e[1]=u):u=e[1];const p=u;let h;e[2]!==p?(h=ae=>ae.action.customizable?p(ae.action):Hn(ae.action.defaultBinding),e[2]=p,e[3]=h):h=e[3];const d=h;let w;e[4]===Symbol.for("react.memo_cache_sentinel")?(w={chords:[],livePreview:null,settled:!1},e[4]=w):w=e[4];const[c,N]=o.useState(w),v=o.useRef(null);let C,y;e[5]!==a?(C=()=>{a&&(N({chords:[],livePreview:null,settled:!1}),v.current?.focus())},y=[a],e[5]=a,e[6]=C,e[7]=y):(C=e[6],y=e[7]),o.useEffect(C,y);const S=c.chords.length===1&&!c.settled;let g,T;e[8]!==S?(g=()=>{if(!S)return;const ae=window.setTimeout(()=>N(sl),Sh);return()=>window.clearTimeout(ae)},T=[S],e[8]=S,e[9]=g,e[10]=T):(g=e[9],T=e[10]),o.useEffect(g,T);let R;e[11]!==c.chords?(R=vi(c.chords.join(" ")),e[11]=c.chords,e[12]=R):R=e[12];const A=R;let j;e[13]!==a||e[14]!==A||e[15]!==n?(j=a&&A?Zc(a.id,A,n):[],e[13]=a,e[14]=A,e[15]=n,e[16]=j):j=e[16];const f=j;let b;e[17]!==f?(b=f.find(Eh),e[17]=f,e[18]=b):b=e[18];const F=b;let D,P,I,U,q,k,$,G,E,J,X,L,se,z,V;if(e[19]!==a||e[20]!==p||e[21]!==A||e[22]!==d||e[23]!==f||e[24]!==r||e[25]!==i||e[26]!==F||e[27]!==c||e[28]!==l){const ae=f.filter(Ch);q=ae.find(Dh);const me=ae.find(Mh),Pe=f.find(Rh);let Ne;e[44]!==r?(Ne=()=>r(!1),e[44]=r,e[45]=Ne):Ne=e[45],I=Ne,U=()=>{c.settled||N(sl),!(!a||!A||F||q)&&(i(a.id,A,me?.action.id),I())};let Se;e[46]!==a||e[47]!==c?(Se=(je,ve)=>{je.preventDefault(),je.stopPropagation();const Re=!!(a&&"prefixStyle"in a&&a.prefixStyle);if(ve==="keyup"&&Re&&c.chords.length===0){const ye=Ih(je);if(ye){N({chords:[ye],livePreview:null,settled:!0});return}}const Ae=Ah(c,{altKey:je.altKey,code:je.nativeEvent.code,ctrlKey:je.ctrlKey,isComposing:je.nativeEvent.isComposing,key:je.key,metaKey:je.metaKey,repeat:je.repeat,shiftKey:je.shiftKey},ve);N(Re&&Ae.chords.length>1?c:Ae)},e[46]=a,e[47]=c,e[48]=Se):Se=e[48];const be=Se;P=Ft,z=a!==null,V=Oh,D=Kt,k="max-w-md",$=v,G=!1;let Ke;e[49]!==a||e[50]!==p||e[51]!==l?(Ke=a?l("settings.aiworker.keyboardShortcuts.dialog.title",{action:p(a)}):"",e[49]=a,e[50]=p,e[51]=l,e[52]=Ke):Ke=e[52];let Le;e[53]!==Ke?(Le=s.jsx(_t,{children:Ke}),e[53]=Ke,e[54]=Le):Le=e[54];let oe;e[55]!==l?(oe=l("settings.aiworker.keyboardShortcuts.dialog.instructions"),e[55]=l,e[56]=oe):oe=e[56];let xe;e[57]!==oe?(xe=s.jsx($t,{children:oe}),e[57]=oe,e[58]=xe):xe=e[58],e[59]!==Le||e[60]!==xe?(E=s.jsxs(Ut,{children:[Le,xe]}),e[59]=Le,e[60]=xe,e[61]=E):E=e[61];let Ee,Ve;e[62]!==be?(Ee=je=>be(je,"keydown"),Ve=je=>be(je,"keyup"),e[62]=be,e[63]=Ee,e[64]=Ve):(Ee=e[63],Ve=e[64]);let $e;e[65]===Symbol.for("react.memo_cache_sentinel")?($e=()=>N(Lh),e[65]=$e):$e=e[65];let We;e[66]!==c.chords?(We=c.chords.map(Fh),e[66]=c.chords,e[67]=We):We=e[67];let Fe;e[68]!==c.livePreview?(Fe=c.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:Hn(c.livePreview)}):null,e[68]=c.livePreview,e[69]=Fe):Fe=e[69];let ie;e[70]!==c.chords.length||e[71]!==c.livePreview||e[72]!==l?(ie=c.chords.length===0&&!c.livePreview?s.jsx("span",{className:"typography-ui-label text-muted-foreground",children:l("settings.aiworker.keyboardShortcuts.dialog.recording")}):null,e[70]=c.chords.length,e[71]=c.livePreview,e[72]=l,e[73]=ie):ie=e[73];let re;e[74]!==We||e[75]!==Fe||e[76]!==ie?(re=s.jsxs("div",{className:"flex flex-wrap items-center justify-center gap-2",children:[We,Fe,ie]}),e[74]=We,e[75]=Fe,e[76]=ie,e[77]=re):re=e[77],e[78]!==Ee||e[79]!==Ve||e[80]!==re?(J=s.jsx("div",{className:"flex min-h-28 items-center justify-center rounded-lg border border-border bg-[var(--surface-elevated)] px-4 py-5 text-center outline-none focus-visible:ring-2 focus-visible:ring-ring",tabIndex:0,ref:v,onKeyDown:Ee,onKeyUp:Ve,onBlur:$e,children:re}),e[78]=Ee,e[79]=Ve,e[80]=re,e[81]=J):J=e[81],X=c.settled&&F?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.aiworker.keyboardShortcuts.error.internalConflict")}):c.settled&&q?s.jsx("p",{className:"typography-meta text-[var(--status-error)]",children:l("settings.aiworker.keyboardShortcuts.error.prefixConflict",{action:p(q.action)})}):null,L=c.settled&&me&&!F&&!q?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.aiworker.keyboardShortcuts.error.exactConflict",{action:p(me.action)})}):null,se=c.settled&&Pe&&!F&&!q?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.aiworker.keyboardShortcuts.warning.contextualPrefix",{action:d(Pe)})}):null,e[19]=a,e[20]=p,e[21]=A,e[22]=d,e[23]=f,e[24]=r,e[25]=i,e[26]=F,e[27]=c,e[28]=l,e[29]=D,e[30]=P,e[31]=I,e[32]=U,e[33]=q,e[34]=k,e[35]=$,e[36]=G,e[37]=E,e[38]=J,e[39]=X,e[40]=L,e[41]=se,e[42]=z,e[43]=V}else D=e[29],P=e[30],I=e[31],U=e[32],q=e[33],k=e[34],$=e[35],G=e[36],E=e[37],J=e[38],X=e[39],L=e[40],se=e[41],z=e[42],V=e[43];let _;e[82]!==A||e[83]!==c.settled||e[84]!==l?(_=c.settled&&A&&Xc(A)?s.jsx("p",{className:"typography-meta text-[var(--status-warning)]",children:l("settings.aiworker.keyboardShortcuts.warning.riskyBrowserShortcut")}):null,e[82]=A,e[83]=c.settled,e[84]=l,e[85]=_):_=e[85];let K;e[86]!==l?(K=l("settings.common.actions.cancel"),e[86]=l,e[87]=K):K=e[87];let Z;e[88]!==I||e[89]!==K?(Z=s.jsx(B,{type:"button",variant:"ghost",size:"sm",onClick:I,children:K}),e[88]=I,e[89]=K,e[90]=Z):Z=e[90];const Y=!A||c.settled&&(!!F||!!q);let te;e[91]!==l?(te=l("settings.aiworker.keyboardShortcuts.actions.confirm"),e[91]=l,e[92]=te):te=e[92];let ge;e[93]!==U||e[94]!==Y||e[95]!==te?(ge=s.jsx(B,{type:"button",size:"sm",disabled:Y,onClick:U,children:te}),e[93]=U,e[94]=Y,e[95]=te,e[96]=ge):ge=e[96];let le;e[97]!==Z||e[98]!==ge?(le=s.jsxs(es,{children:[Z,ge]}),e[97]=Z,e[98]=ge,e[99]=le):le=e[99];let he;e[100]!==D||e[101]!==k||e[102]!==$||e[103]!==G||e[104]!==E||e[105]!==J||e[106]!==X||e[107]!==L||e[108]!==se||e[109]!==_||e[110]!==le?(he=s.jsxs(D,{className:k,initialFocus:$,showCloseButton:G,children:[E,J,X,L,se,_,le]}),e[100]=D,e[101]=k,e[102]=$,e[103]=G,e[104]=E,e[105]=J,e[106]=X,e[107]=L,e[108]=se,e[109]=_,e[110]=le,e[111]=he):he=e[111];let ne;return e[112]!==P||e[113]!==z||e[114]!==V||e[115]!==he?(ne=s.jsx(P,{open:z,onOpenChange:V,children:he}),e[112]=P,e[113]=z,e[114]=V,e[115]=he,e[116]=ne):ne=e[116],ne};function Eh(t){return!t.action.customizable&&t.kind!=="contextual-prefix"}function Dh(t){return t.kind==="prefix"}function Mh(t){return t.kind==="exact"}function Rh(t){return t.kind==="contextual-prefix"}function Oh(t,e){t||e.cancel()}function Lh(t){return{...t,livePreview:null}}function Fh(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:Hn(t)},`${t}-${e}`)}const Kh=["session","models","panels","navigation","application"],zh=()=>{const t=mt.c(24),{t:e}=at(),a=de(Uh),n=de(_h),i=de($h),r=de(Vh),[l,u]=o.useState(null);let p;if(t[0]===Symbol.for("react.memo_cache_sentinel")){const A=sd();p=us()?A.filter(Bh):A,t[0]=p}else p=t[0];const h=p,d=Hh;let w;t[1]!==n||t[2]!==a?(w=(A,j,f)=>{const b={...a,[A]:j};f&&(b[f]=Li),n(A,j),f&&n(f,Li),d(b)},t[1]=n,t[2]=a,t[3]=w):w=t[3];const c=w;let N;t[4]!==i||t[5]!==a?(N=A=>{const j={...a};delete j[A],i(A),d(j)},t[4]=i,t[5]=a,t[6]=N):N=t[6];const v=N;let C;t[7]!==a||t[8]!==e?(C=A=>{const j="prefixStyle"in A&&A.prefixStyle,f=j?nd(A.id,a):wl(A.id,a),b=Hn(f,e("settings.aiworker.keyboardShortcuts.unassigned"));if(!j||!f||f===Li)return b;const F=A.id==="switch_session_tab"?e("settings.aiworker.keyboardShortcuts.action.switch_session_tab.suffix"):e("settings.aiworker.keyboardShortcuts.action.switch_context_surface.suffix");return`${b}${F}`},t[7]=a,t[8]=e,t[9]=C):C=t[9];const y=C;let S;t[10]!==r||t[11]!==v||t[12]!==y||t[13]!==a||t[14]!==e?(S=Kh.map((A,j)=>{const f=h.filter(b=>b.category===A);return f.length===0?null:s.jsx(_e,{settingsItem:j===0?"shortcuts.keyboard-shortcuts":void 0,title:e(`settings.aiworker.keyboardShortcuts.category.${A}`),divider:j!==0,info:j===0?e("settings.aiworker.keyboardShortcuts.tooltip"):void 0,headerAction:j===0?s.jsx(B,{type:"button",variant:"outline",size:"xs",className:"!font-normal",onClick:()=>{r(),d({})},children:e("settings.aiworker.keyboardShortcuts.actions.resetAll")}):void 0,children:s.jsx("div",{className:"space-y-2",children:f.map(b=>s.jsxs(Ot,{label:e(b.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(b)}),s.jsx(B,{type:"button",variant:"secondary",size:"xs",className:"!font-normal",onClick:()=>u(b),children:e("settings.aiworker.keyboardShortcuts.actions.edit")}),b.id in a?s.jsx(B,{type:"button",variant:"ghost",size:"xs",className:"!font-normal",onClick:()=>v(b.id),children:e("settings.common.actions.reset")}):null]},b.id))})},A)}),t[10]=r,t[11]=v,t[12]=y,t[13]=a,t[14]=e,t[15]=S):S=t[15];let g;t[16]===Symbol.for("react.memo_cache_sentinel")?(g=A=>{A||u(null)},t[16]=g):g=t[16];let T;t[17]!==l||t[18]!==c||t[19]!==a?(T=s.jsx(Th,{action:l,overrides:a,onSave:c,onOpenChange:g}),t[17]=l,t[18]=c,t[19]=a,t[20]=T):T=t[20];let R;return t[21]!==S||t[22]!==T?(R=s.jsxs(s.Fragment,{children:[S,T]}),t[21]=S,t[22]=T,t[23]=R):R=t[23],R};function Uh(t){return t.shortcutOverrides}function _h(t){return t.setShortcutOverride}function $h(t){return t.clearShortcutOverride}function Vh(t){return t.resetAllShortcutOverrides}function Bh(t){return t.id!=="toggle_prompt_navigator"}function Hh(t){yt({shortcutOverrides:t})}const sc=()=>{const t=mt.c(2),[e,a]=o.useState(0);let n,i;return t[0]===Symbol.for("react.memo_cache_sentinel")?(n=()=>Nl(()=>a(sx)),i=[],t[0]=n,t[1]=i):(n=t[0],i=t[1]),o.useEffect(n,i),e},Gh=t=>{const e=mt.c(80),{section:a}=t,{t:n}=at(),{isMobile:i}=ma();sc();let r;e[0]!==i?(r=i&&Vn(),e[0]=i,e[1]=r):r=e[1];const l=r;let u;e[2]===Symbol.for("react.memo_cache_sentinel")?(u=us(),e[2]=u):u=e[2];const p=u;let h;e[3]===Symbol.for("react.memo_cache_sentinel")?(h=os()&&$a(),e[3]=h):h=e[3];const d=h;if(!a){let L,se,z,V,_,K,Z,Y;e[4]===Symbol.for("react.memo_cache_sentinel")?(z=s.jsx(yi,{}),V=s.jsx(Jl,{}),_=d&&s.jsx(ec,{}),K=!p&&s.jsx(Zl,{}),Z=!p&&s.jsx(Xl,{}),Y=s.jsx(Gl,{}),L=s.jsx(ql,{}),se=Vn()&&!os()&&!p&&!Pl()&&s.jsx(Wl,{}),e[4]=L,e[5]=se,e[6]=z,e[7]=V,e[8]=_,e[9]=K,e[10]=Z,e[11]=Y):(L=e[4],se=e[5],z=e[6],V=e[7],_=e[8],K=e[9],Z=e[10],Y=e[11]);let te;e[12]!==l?(te=l&&s.jsx(El,{}),e[12]=l,e[13]=te):te=e[13];let ge;return e[14]!==te?(ge=s.jsxs(ns,{showSaveStatus:!0,className:"openchamber-page-body space-y-3 sm:space-y-6",children:[z,V,_,K,Z,Y,L,se,te]}),e[14]=te,e[15]=ge):ge=e[15],ge}let w;e[16]!==a?(w=()=>{switch(a){case"general":return s.jsx(qh,{});case"visual":return s.jsx(Jh,{});case"chat":return s.jsx(Qh,{});case"sessions":return s.jsx(Yh,{});case"shortcuts":return s.jsx(Wh,{});case"git":return s.jsx(Zh,{});case"notifications":return s.jsx(Xh,{});case"voice":return s.jsx(ex,{});case"tunnel":return s.jsx(tx,{});default:return null}},e[16]=a,e[17]=w):w=e[17];const c=w;let N;e[18]!==n?(N=n("settings.page.general.title"),e[18]=n,e[19]=N):N=e[19];let v;e[20]!==n?(v=n("settings.page.appearance.title"),e[20]=n,e[21]=v):v=e[21];let C;e[22]!==n?(C=n("settings.page.chat.title"),e[22]=n,e[23]=C):C=e[23];let y;e[24]!==n?(y=n("settings.page.sessions.title"),e[24]=n,e[25]=y):y=e[25];let S;e[26]!==n?(S=n("settings.page.shortcuts.title"),e[26]=n,e[27]=S):S=e[27];let g;e[28]!==n?(g=n("settings.page.git.title"),e[28]=n,e[29]=g):g=e[29];let T;e[30]!==n?(T=n("settings.page.git.title"),e[30]=n,e[31]=T):T=e[31];let R;e[32]!==n?(R=n("settings.page.notifications.title"),e[32]=n,e[33]=R):R=e[33];let A;e[34]!==n?(A=n("settings.page.voice.title"),e[34]=n,e[35]=A):A=e[35];let j;e[36]!==n?(j=n("settings.page.tunnel.title"),e[36]=n,e[37]=j):j=e[37];let f;e[38]!==g||e[39]!==T||e[40]!==R||e[41]!==A||e[42]!==j||e[43]!==N||e[44]!==v||e[45]!==C||e[46]!==y||e[47]!==S?(f={general:N,visual:v,chat:C,sessions:y,shortcuts:S,git:g,github:T,notifications:R,voice:A,tunnel:j},e[38]=g,e[39]=T,e[40]=R,e[41]=A,e[42]=j,e[43]=N,e[44]=v,e[45]=C,e[46]=y,e[47]=S,e[48]=f):f=e[48];const b=f[a];let F;e[49]!==n?(F=n("settings.page.general.description"),e[49]=n,e[50]=F):F=e[50];let D;e[51]!==n?(D=n("settings.page.appearance.description"),e[51]=n,e[52]=D):D=e[52];let P;e[53]!==n?(P=n("settings.page.chat.description"),e[53]=n,e[54]=P):P=e[54];let I;e[55]!==n?(I=n("settings.page.sessions.description"),e[55]=n,e[56]=I):I=e[56];let U;e[57]!==n?(U=n("settings.page.shortcuts.description"),e[57]=n,e[58]=U):U=e[58];let q;e[59]!==n?(q=n("settings.page.notifications.description"),e[59]=n,e[60]=q):q=e[60];let k;e[61]!==n?(k=n("settings.page.voice.description"),e[61]=n,e[62]=k):k=e[62];let $;e[63]!==n?($=n("settings.page.tunnel.description"),e[63]=n,e[64]=$):$=e[64];let G;e[65]!==F||e[66]!==D||e[67]!==P||e[68]!==I||e[69]!==U||e[70]!==q||e[71]!==k||e[72]!==$?(G={general:F,visual:D,chat:P,sessions:I,shortcuts:U,git:void 0,github:void 0,notifications:q,voice:k,tunnel:$},e[65]=F,e[66]=D,e[67]=P,e[68]=I,e[69]=U,e[70]=q,e[71]=k,e[72]=$,e[73]=G):G=e[73];const E=G[a];let J;e[74]!==c?(J=c(),e[74]=c,e[75]=J):J=e[75];let X;return e[76]!==E||e[77]!==b||e[78]!==J?(X=s.jsx(ns,{title:b,description:E,showSaveStatus:!0,className:"openchamber-page-body",children:J}),e[76]=E,e[77]=b,e[78]=J,e[79]=X):X=e[79],X},Wh=()=>{const t=mt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(zh,{}),t[0]=e):e=t[0],e},qh=()=>{const t=mt.c(10);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=us(),t[0]=e):e=t[0];const a=e;sc();let n;t[1]===Symbol.for("react.memo_cache_sentinel")?(n=os()&&$a(),t[1]=n):n=t[1];const i=n;let r;t[2]===Symbol.for("react.memo_cache_sentinel")?(r=Vn()&&!os()&&!a&&!Pl(),t[2]=r):r=t[2];const l=r;let u,p,h,d,w;t[3]===Symbol.for("react.memo_cache_sentinel")?(u=i&&s.jsx(ec,{}),p=l&&s.jsx(Wl,{}),h=s.jsx(ql,{}),d=!a&&s.jsx(Zl,{}),w=!a&&s.jsx(Xl,{}),t[3]=u,t[4]=p,t[5]=h,t[6]=d,t[7]=w):(u=t[3],p=t[4],h=t[5],d=t[6],w=t[7]);let c;t[8]===Symbol.for("react.memo_cache_sentinel")?(c=a?[]:["sessionTabs"],t[8]=c):c=t[8];let N;return t[9]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsxs(s.Fragment,{children:[u,p,h,d,w,s.jsx(yi,{visibleSettings:["fileEditorKeymap",...c,"autoSaveEnabled",...a?[]:["terminalQuickKeys"],...a?[]:["terminalShell"],...a?[]:["terminalLoginShell"],"messageTransport","reportUsage"]})]}),t[9]=N):N=t[9],N},Jh=()=>{const t=mt.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=us(),t[0]=e):e=t[0];const a=e;let n;return t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx(yi,{visibleSettings:["theme","windowControlsPosition","pwaInstallName","pwaOrientation","mobileKeyboardMode","timeFormat",...a?[]:["weekStart"],"fontSize","terminalFontSize","editorFontSize","spacing","inputBarOffset"]}),t[1]=n):n=t[1],n},Qh=()=>{const t=mt.c(2);let e;t[0]===Symbol.for("react.memo_cache_sentinel")?(e=us(),t[0]=e):e=t[0];const a=e;let n;return t[1]===Symbol.for("react.memo_cache_sentinel")?(n=s.jsx(yi,{visibleSettings:["sessionGoal","sessionAssist","chatRenderMode","activityRenderMode","userMessageRendering","mermaidRendering","reasoning","showToolFileIcons","showTurnChangedFiles","expandedTools","collapsibleUserMessages","stickyUserHeader",...a?[]:["promptNavigatorEnabled"],"wideChatLayout","codeBlockLineWrap","splitAssistantMessageActions","subagentReadOnlyBanner","diffLayout","dotfiles","fileViewerPreview","followUpBehavior","persistDraft","inputSpellcheck","largeTextPaste"]}),t[1]=n):n=t[1],n},Yh=()=>{const t=mt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsxs(s.Fragment,{children:[s.jsx(Jl,{}),s.jsx(Gl,{})]}),t[0]=e):e=t[0],e},Zh=()=>{const t=mt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Hl,{}),t[0]=e):e=t[0],e},Xh=()=>{const t=mt.c(1);let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(Qf,{}),t[0]=e):e=t[0],e},ex=()=>{const t=mt.c(1);if(us())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(rh,{}),t[0]=e):e=t[0],e},tx=()=>{const t=mt.c(1);if(us())return null;let e;return t[0]===Symbol.for("react.memo_cache_sentinel")?(e=s.jsx(xh,{}),t[0]=e):e=t[0],e};function sx(t){return t+1}const nx=t=>{const e=mt.c(85),{className:a}=t,{t:n}=at(),i=vn(jl),r=vn(ax),l=de(ix),u=de(rx),[p,h]=qe.useState(!1),[d,w]=qe.useState(!1),c=i>0;let N;e[0]!==n?(N=async()=>{try{const Ne=await ad({message:n("settings.view.pendingRestart.applying")});if(Ne.requiresManualRestart){M.warning(n("settings.view.pendingRestart.manualRestartRequired"));return}Ne.ok&&M.success(n("settings.view.pendingRestart.applied"))}catch(Ne){const Se=Ne,be=Se instanceof Error&&Se.message?Se.message:n("settings.view.pendingRestart.applyFailed");M.error(be)}},e[0]=n,e[1]=N):N=e[1];const v=N;let C;e[2]!==n?(C=async()=>{try{await vl({message:n("settings.view.pendingRestart.applying"),mode:"projects",scopes:["all"]}),vn.getState().clear()}catch{}},e[2]=n,e[3]=C):C=e[3];const y=C;let S;e[4]!==d||e[5]!==v||e[6]!==u?(S=()=>{d&&u(!1),h(!1),w(!1),v()},e[4]=d,e[5]=v,e[6]=u,e[7]=S):S=e[7];const g=S;let T;e[8]!==c||e[9]!==v||e[10]!==y||e[11]!==l?(T=()=>{if(!c){y();return}if(l){w(!1),h(!0);return}v()},e[8]=c,e[9]=v,e[10]=y,e[11]=l,e[12]=T):T=e[12];const R=T;let A;e[13]!==c||e[14]!==r||e[15]!==n?(A=n(c?r?"settings.view.pendingRestart.applying":"settings.view.actions.applyAndRestartOpenCode":"settings.view.actions.reloadOpenCode"),e[13]=c,e[14]=r,e[15]=n,e[16]=A):A=e[16];const j=A;let f;e[17]!==c||e[18]!==i||e[19]!==n?(f=c?i===1?n("settings.view.actions.applyAndRestartOpenCodeTooltipSingle"):n("settings.view.actions.applyAndRestartOpenCodeTooltipPlural",{count:i}):n("settings.view.actions.reloadOpenCodeTooltip"),e[17]=c,e[18]=i,e[19]=n,e[20]=f):f=e[20];const b=f,F=c?"bg-primary text-primary-foreground typography-ui-label font-semibold hover:bg-primary/90":"text-sm font-semibold text-sidebar-foreground/90 hover:text-sidebar-foreground hover:bg-interactive-hover",D=r&&"opacity-80";let P;e[21]!==a||e[22]!==F||e[23]!==D?(P=we("flex w-full items-center gap-2 rounded-md overflow-hidden whitespace-nowrap","h-11 px-3 sm:h-8 sm:px-2","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",F,D,a),e[21]=a,e[22]=F,e[23]=D,e[24]=P):P=e[24];let I;e[25]!==c||e[26]!==i?(I=c?s.jsx("span",{className:we("inline-flex h-5 min-w-5 shrink-0 items-center justify-center rounded-full px-1.5","bg-background text-foreground typography-micro font-semibold tabular-nums"),"aria-hidden":"true",children:i}):s.jsx(O,{name:"restart",className:"h-4 w-4 shrink-0"}),e[25]=c,e[26]=i,e[27]=I):I=e[27];let U;e[28]!==j?(U=s.jsx("span",{className:"truncate",children:j}),e[28]=j,e[29]=U):U=e[29];let q;e[30]!==R||e[31]!==r||e[32]!==I||e[33]!==U||e[34]!==P||e[35]!==b?(q=s.jsxs("button",{type:"button",disabled:r,title:b,"aria-label":b,onClick:R,className:P,children:[I,U]}),e[30]=R,e[31]=r,e[32]=I,e[33]=U,e[34]=P,e[35]=b,e[36]=q):q=e[36];let k;e[37]===Symbol.for("react.memo_cache_sentinel")?(k=Ne=>{h(Ne),Ne||w(!1)},e[37]=k):k=e[37];let $;e[38]!==n?($=n("settings.view.pendingRestart.confirm.title"),e[38]=n,e[39]=$):$=e[39];let G;e[40]!==$?(G=s.jsx(_t,{children:$}),e[40]=$,e[41]=G):G=e[41];let E;e[42]!==n?(E=n("settings.view.pendingRestart.confirm.description"),e[42]=n,e[43]=E):E=e[43];let J;e[44]!==E?(J=s.jsx($t,{children:E}),e[44]=E,e[45]=J):J=e[45];let X;e[46]!==G||e[47]!==J?(X=s.jsxs(Ut,{children:[G,J]}),e[46]=G,e[47]=J,e[48]=X):X=e[48];let L;e[49]===Symbol.for("react.memo_cache_sentinel")?(L={width:"40%"},e[49]=L):L=e[49];let se;e[50]===Symbol.for("react.memo_cache_sentinel")?(se=()=>h(!1),e[50]=se):se=e[50];let z;e[51]!==n?(z=n("settings.view.pendingRestart.confirm.cancel"),e[51]=n,e[52]=z):z=e[52];let V;e[53]!==z?(V=s.jsx("div",{className:"min-w-0 shrink-0",style:L,children:s.jsx(B,{type:"button",variant:"outline",className:"h-9 w-full normal-case",onClick:se,children:z})}),e[53]=z,e[54]=V):V=e[54];let _;e[55]===Symbol.for("react.memo_cache_sentinel")?(_={width:"40%"},e[55]=_):_=e[55];let K;e[56]!==n?(K=n("settings.view.actions.applyAndRestartOpenCode"),e[56]=n,e[57]=K):K=e[57];let Z;e[58]!==g||e[59]!==K?(Z=s.jsx("div",{className:"min-w-0 shrink-0",style:_,children:s.jsx(B,{type:"button",variant:"default",className:"h-9 w-full normal-case",onClick:g,children:K})}),e[58]=g,e[59]=K,e[60]=Z):Z=e[60];let Y;e[61]!==V||e[62]!==Z?(Y=s.jsxs("div",{className:"flex w-full items-stretch justify-center gap-3",children:[V,Z]}),e[61]=V,e[62]=Z,e[63]=Y):Y=e[63];let te;e[64]===Symbol.for("react.memo_cache_sentinel")?(te=()=>w(ox),e[64]=te):te=e[64];let ge;e[65]!==d?(ge=d?s.jsx(O,{name:"checkbox",className:"h-4 w-4 text-primary"}):s.jsx(O,{name:"checkbox-blank",className:"h-4 w-4"}),e[65]=d,e[66]=ge):ge=e[66];let le;e[67]!==n?(le=n("settings.view.pendingRestart.confirm.dontShowAgain"),e[67]=n,e[68]=le):le=e[68];let he;e[69]!==d||e[70]!==ge||e[71]!==le?(he=s.jsxs("button",{type:"button",onClick:te,className:"inline-flex items-center justify-center gap-1.5 typography-ui-label text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-primary/50","aria-pressed":d,children:[ge,le]}),e[69]=d,e[70]=ge,e[71]=le,e[72]=he):he=e[72];let ne;e[73]!==Y||e[74]!==he?(ne=s.jsxs("div",{className:"flex w-full flex-col items-center gap-3",children:[Y,he]}),e[73]=Y,e[74]=he,e[75]=ne):ne=e[75];let ae;e[76]!==X||e[77]!==ne?(ae=s.jsxs(Kt,{showCloseButton:!1,className:"max-w-md gap-5",children:[X,ne]}),e[76]=X,e[77]=ne,e[78]=ae):ae=e[78];let me;e[79]!==p||e[80]!==ae?(me=s.jsx(Ft,{open:p,onOpenChange:k,children:ae}),e[79]=p,e[80]=ae,e[81]=me):me=e[81];let Pe;return e[82]!==q||e[83]!==me?(Pe=s.jsxs(s.Fragment,{children:[q,me]}),e[82]=q,e[83]=me,e[84]=Pe):Pe=e[84],Pe};function ax(t){return t.isApplying}function ix(t){return t.showOpenCodeRestartConfirm}function rx(t){return t.setShowOpenCodeRestartConfirm}function ox(t){return!t}const lx=[{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.aiworker.visual.field.timeFormat",keywords:["clock","12h","24h"]},{id:"appearance.week-start",page:"appearance",titleKey:"settings.aiworker.visual.field.weekStartsOn",keywords:["calendar","monday","sunday"]},{id:"appearance.light-theme",page:"appearance",titleKey:"settings.aiworker.visual.field.lightTheme",keywords:["theme","color","light mode"],isAvailable:t=>!t.isVSCode},{id:"appearance.dark-theme",page:"appearance",titleKey:"settings.aiworker.visual.field.darkTheme",keywords:["theme","color","dark mode"],isAvailable:t=>!t.isVSCode},{id:"appearance.dock-badge",page:"appearance",titleKey:"settings.aiworker.visual.field.dockBadge",descriptionKey:"settings.aiworker.visual.field.dockBadgeHint",keywords:["dock","badge","unread","unseen","counter","count","notification","macos"],isAvailable:t=>t.isMac},{id:"appearance.pwa-install-name",page:"appearance",titleKey:"settings.aiworker.visual.field.installAppName",descriptionKey:"settings.aiworker.visual.field.installAppNameHint",keywords:["pwa","installed app"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.pwa-orientation",page:"appearance",titleKey:"settings.aiworker.visual.field.installOrientation",descriptionKey:"settings.aiworker.visual.field.installOrientationHint",keywords:["pwa","portrait","landscape"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.mobile-keyboard-mode",page:"appearance",titleKey:"settings.aiworker.visual.field.mobileKeyboardMode",descriptionKey:"settings.aiworker.visual.field.mobileKeyboardModeHint",keywords:["mobile","keyboard","resize"],isAvailable:t=>t.isMobile&&t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"appearance.interface-font-size",page:"appearance",titleKey:"settings.aiworker.visual.field.interfaceFontSize",keywords:["font","text size","ui scale"],isAvailable:t=>!t.isMobile},{id:"appearance.terminal-font-size",page:"appearance",titleKey:"settings.aiworker.visual.field.terminalFontSize",keywords:["terminal","font","text size"]},{id:"appearance.terminal-shell",page:"general",titleKey:"settings.aiworker.visual.field.terminalShell",descriptionKey:"settings.aiworker.visual.field.terminalShellHint",keywords:["terminal","shell","bash","zsh","fish","pwsh","powershell"],isAvailable:t=>!t.isVSCode},{id:"appearance.editor-font-size",page:"appearance",titleKey:"settings.aiworker.visual.field.editorFontSize",keywords:["editor","font","text size","code"]},{id:"appearance.spacing-density",page:"appearance",titleKey:"settings.aiworker.visual.field.spacingDensity",keywords:["density","compact","comfortable","spacing"]},{id:"appearance.input-bar-offset",page:"appearance",titleKey:"settings.aiworker.visual.field.inputBarOffset",descriptionKey:"settings.aiworker.visual.field.inputBarOffsetTooltip",keywords:["input","home bar","offset"],isAvailable:t=>t.isMobile},{id:"appearance.auto-save-enabled",page:"general",titleKey:"settings.aiworker.visual.field.autoSaveEnabled",descriptionKey:"settings.aiworker.visual.field.autoSaveEnabledInfo",keywords:["editor","autosave","auto-save","files","save"]},{id:"appearance.file-editor-keymap",page:"general",titleKey:"settings.aiworker.visual.field.fileEditorKeymap",keywords:["editor","vim","keymap"]},{id:"appearance.session-tabs",page:"general",titleKey:"settings.aiworker.visual.field.sessionTabsGroup",descriptionKey:"settings.aiworker.visual.field.sessionTabsInfo",keywords:["session","tabs","header","working set"],isAvailable:t=>!t.isMobile&&!t.isVSCode},{id:"appearance.terminal-quick-keys",page:"general",titleKey:"settings.aiworker.visual.field.terminalQuickKeys",descriptionKey:"settings.aiworker.visual.field.terminalQuickKeysTooltip",keywords:["terminal","keyboard","esc","ctrl","arrows"],isAvailable:t=>!t.isMobile&&!t.isVSCode},{id:"appearance.usage-reports",page:"general",titleKey:"settings.aiworker.visual.field.sendAnonymousUsageReports",descriptionKey:"settings.aiworker.visual.field.sendAnonymousUsageReportsHint",keywords:["telemetry","analytics"]},{id:"general.app-links",page:"general",titleKey:"settings.aiworker.appLinks.title",descriptionKey:"settings.aiworker.appLinks.info",keywords:["security","app link","deep link","scheme","protocol","obsidian","notion"]},{id:"chat.render-mode",page:"chat",titleKey:"settings.aiworker.visual.section.chatRenderMode",keywords:["messages","conversation","rendering"]},{id:"chat.message-transport",page:"general",titleKey:"settings.aiworker.visual.section.messageStreamTransport",keywords:["streaming","sse","websocket"]},{id:"chat.session-recap",page:"chat",titleKey:"settings.aiworker.visual.field.sessionRecap",keywords:["recap","assist","small model","summary"]},{id:"chat.session-assistance",page:"chat",titleKey:"settings.aiworker.visual.section.sessionAssistance",keywords:["recap","suggestion","subagent"]},{id:"chat.session-suggestion",page:"chat",titleKey:"settings.aiworker.visual.field.sessionSuggestion",keywords:["suggestion","assist","small model","follow up"]},{id:"chat.session-goal",page:"chat",titleKey:"settings.aiworker.visual.field.sessionGoal",keywords:["goal","objective","auto continue","small model"],isAvailable:t=>!t.isVSCode},{id:"chat.session-goal-budget",page:"chat",titleKey:"settings.aiworker.visual.goal.budgetLabel",keywords:["goal","budget","tokens","limit"],isAvailable:t=>!t.isVSCode},{id:"chat.reasoning-traces",page:"chat",titleKey:"settings.aiworker.visual.field.showReasoningTraces",keywords:["thinking","reasoning"]},{id:"chat.reasoning",page:"chat",titleKey:"settings.aiworker.visual.section.reasoning",keywords:["thinking","traces"]},{id:"chat.streaming",page:"chat",titleKey:"settings.aiworker.visual.section.streaming",keywords:["stream","scroll"]},{id:"chat.streaming-auto-follow",page:"chat",titleKey:"settings.aiworker.visual.field.streamingAutoFollow",descriptionKey:"settings.aiworker.visual.field.streamingAutoFollowInfo",keywords:["autoscroll","auto-scroll","follow","stick to bottom","streaming"]},{id:"chat.sticky-user-header",page:"chat",titleKey:"settings.aiworker.visual.field.stickyUserHeader",keywords:["messages","header"]},{id:"chat.prompt-navigator",page:"chat",titleKey:"settings.aiworker.visual.field.promptNavigatorEnabled",keywords:["prompt","navigator","navigation","timeline","scroll"],isAvailable:t=>!t.isVSCode},{id:"chat.collapsible-user-messages",page:"chat",titleKey:"settings.aiworker.visual.field.collapsibleUserMessages",keywords:["collapse","expand","clamp","long messages","user messages"]},{id:"chat.wide-layout",page:"chat",titleKey:"settings.aiworker.visual.field.wideChatLayout",keywords:["layout","wide","messages"]},{id:"chat.message-appearance",page:"chat",titleKey:"settings.aiworker.visual.section.messageAppearance",keywords:["layout","messages","appearance"]},{id:"chat.code-block-line-wrap",page:"chat",titleKey:"settings.aiworker.visual.field.codeBlockLineWrap",keywords:["code","wrap","line wrap","markdown"]},{id:"chat.inline-assistant-actions",page:"chat",titleKey:"settings.aiworker.visual.field.showSplitAssistantMessageActions",descriptionKey:"settings.aiworker.visual.field.showSplitAssistantMessageActionsTooltip",keywords:["copy","save image","read aloud"]},{id:"chat.draft-starters-visible",page:"chat",titleKey:"settings.aiworker.visual.field.draftStartersVisible",keywords:["starter","starters","new session","welcome","suggestions"]},{id:"chat.subagent-read-only-banner",page:"chat",titleKey:"settings.aiworker.visual.field.allowPromptingSubagentSessions",keywords:["subagent","read only","prompt","banner"]},{id:"chat.tool-file-icons",page:"chat",titleKey:"settings.aiworker.visual.field.showToolFileIcons",keywords:["tools","files","icons"]},{id:"chat.tools-and-files",page:"chat",titleKey:"settings.aiworker.visual.section.toolsAndFiles",keywords:["tools","files","dotfiles"]},{id:"chat.changed-files",page:"chat",titleKey:"settings.aiworker.visual.field.showTurnChangedFiles",keywords:["changed files","turns"]},{id:"chat.dotfiles",page:"chat",titleKey:"settings.aiworker.visual.field.showDotfiles",keywords:["hidden files"],isAvailable:t=>!t.isVSCode},{id:"chat.follow-up-behavior",page:"chat",titleKey:"settings.aiworker.visual.section.followUpBehavior",descriptionKey:"settings.aiworker.visual.field.followUpBehaviorDescription",keywords:["follow up","queue","steer","send immediately"]},{id:"chat.persist-drafts",page:"chat",titleKey:"settings.aiworker.visual.field.persistDraftMessages",keywords:["draft","message"]},{id:"chat.composer",page:"chat",titleKey:"settings.aiworker.visual.section.composer",keywords:["input","draft","spellcheck","paste"]},{id:"chat.spellcheck",page:"chat",titleKey:"settings.aiworker.visual.field.enableSpellcheckInTextInputs",keywords:["spelling","input"],isAvailable:t=>!t.isMobile},{id:"chat.large-text-paste",page:"chat",titleKey:"settings.aiworker.visual.field.largeTextPaste",descriptionKey:"settings.aiworker.visual.field.largeTextPasteHint",keywords:["paste","clipboard","attachment","large","text","file"]},{id:"sessions.default-model",page:"sessions",titleKey:"settings.aiworker.defaults.field.defaultModel",keywords:["model","provider","new sessions"]},{id:"sessions.default-thinking",page:"sessions",titleKey:"settings.aiworker.defaults.field.defaultThinking",keywords:["thinking","reasoning","variant"]},{id:"sessions.default-agent",page:"sessions",titleKey:"settings.aiworker.defaults.field.defaultAgent",keywords:["agent","new sessions"]},{id:"sessions.deletion-dialog",page:"sessions",titleKey:"settings.aiworker.defaults.field.showDeletionDialog",keywords:["delete","confirmation"]},{id:"sessions.small-model",page:"sessions",titleKey:"settings.aiworker.defaults.smallModel.title",descriptionKey:"settings.aiworker.defaults.smallModel.description",keywords:["small model","utility","summary","recap","cheap","override"]},{id:"sessions.walkthrough-model",page:"sessions",titleKey:"settings.aiworker.defaults.walkthroughModel.title",descriptionKey:"settings.aiworker.defaults.walkthroughModel.description",keywords:["walkthrough","diff","review","changes","structured output","model","override"]},{id:"sessions.auto-cleanup",page:"sessions",titleKey:"settings.aiworker.sessionRetention.field.enableAutoCleanup",descriptionKey:"settings.aiworker.sessionRetention.tooltip",keywords:["retention","archive","delete"]},{id:"sessions.retention-period",page:"sessions",titleKey:"settings.aiworker.sessionRetention.field.retentionPeriod",keywords:["days","cleanup","retention"]},{id:"sessions.retention-action",page:"sessions",titleKey:"settings.aiworker.sessionRetention.field.whenSessionsExpire",keywords:["archive","delete","expire"]},{id:"sessions.desktop-launch-at-login",page:"general",titleKey:"settings.aiworker.desktopNetwork.field.launchAtLogin",descriptionKey:"settings.aiworker.desktopNetwork.field.launchAtLoginDescription",keywords:["desktop","startup","login","launch","background","autostart"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-window-controls-position",page:"appearance",titleKey:"settings.aiworker.desktopNetwork.field.windowControlsPosition",descriptionKey:"settings.aiworker.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.aiworker.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.aiworker.desktopNetwork.field.macMenuBar",descriptionKey:"settings.aiworker.desktopNetwork.field.macMenuBarDescription",keywords:["desktop","menu bar","tray","status item","macos","background"],isAvailable:t=>t.isDesktopLocalOrigin&&t.isMac},{id:"sessions.desktop-minimize-to-tray",page:"general",titleKey:"settings.aiworker.desktopNetwork.field.minimizeToTray",descriptionKey:"settings.aiworker.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.aiworker.desktopNetwork.field.keepAwake",descriptionKey:"settings.aiworker.desktopNetwork.field.keepAwakeDescription",keywords:["desktop","sleep","awake","server","mobile","phone"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-ui-password",page:"general",titleKey:"settings.aiworker.desktopPassword.field.password",descriptionKey:"settings.aiworker.desktopPassword.field.passwordDescription",keywords:["desktop","password","auth","login"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.desktop-lan-access",page:"general",titleKey:"settings.aiworker.desktopNetwork.field.allowLanAccess",descriptionKey:"settings.aiworker.desktopNetwork.field.allowLanAccessDescription",keywords:["desktop","lan","network","phone","tablet"],isAvailable:t=>t.isDesktopLocalOrigin},{id:"sessions.opencode-binary",page:"general",titleKey:"settings.aiworker.opencodeCli.field.binaryPath",keywords:["opencode","cli","binary","path"],isAvailable:t=>!t.isVSCode},{id:"sessions.opencode-update-notifications",page:"general",titleKey:"settings.aiworker.opencodeCli.field.showUpdateNotifications",keywords:["opencode","cli","updates"],isAvailable:t=>!t.isVSCode&&!t.isWindowsArm64},{id:"sessions.agent-control-tool",page:"general",titleKey:"settings.aiworker.tools.field.agentControlTool",descriptionKey:"settings.aiworker.tools.field.agentControlToolInfo",keywords:["agent","tool","orchestration","aiworker","sessions","schedule","control"],isAvailable:t=>!t.isVSCode},{id:"sessions.agent-web-tool",page:"general",titleKey:"settings.aiworker.tools.field.agentWebTool",descriptionKey:"settings.aiworker.tools.field.agentWebToolInfo",keywords:["agent","tool","web","browser","page","preview","aiworker"],isAvailable:t=>!t.isVSCode},{id:"sessions.agent-memory-tool",page:"general",titleKey:"settings.aiworker.tools.field.agentMemoryTool",descriptionKey:"settings.aiworker.tools.field.agentMemoryToolInfo",keywords:["agent","tool","memory","remember","recall","preferences","aiworker"],isAvailable:t=>!t.isVSCode&&de.getState().agentMemoryFeatureAvailable},{id:"git.identities",page:"git",titleKey:"settings.gitIdentities.page.section.title",descriptionKey:"settings.gitIdentities.page.empty.description",keywords:["identity","profile","author","email","credentials","signing","commit signing","ssh signing","gpg"]},{id:"git.changes-view",page:"git",titleKey:"settings.aiworker.git.changesViewTitle",keywords:["changes","flat list","tree view"]},{id:"git.gitmoji",page:"git",titleKey:"settings.aiworker.git.enableGitmoji",keywords:["commit","emoji"]},{id:"git.gitignored-files",page:"git",titleKey:"settings.aiworker.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-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.aiworker.worktrees.setup.waitForCommands",keywords:["worktree","setup commands","bootstrap","wait"]},{id:"remote-instances.client-auth",page:"remote-instances",titleKey:"settings.remoteInstances.clientAuth.title",descriptionKey:"settings.remoteInstances.clientAuth.description",keywords:["pairing link","client token","connect desktop","remote access","relay","devices","connect from anywhere"],isAvailable:t=>!t.isVSCode},{id:"remote-instances.direct-hosts",page:"remote-instances",titleKey:"settings.remoteInstances.direct.title",descriptionKey:"settings.remoteInstances.direct.description",keywords:["server url","connection token","import link","host switcher","additional headers","request headers","cloudflare access","service token"],isAvailable:t=>t.isDesktop},{id:"behavior.system-prompt-optimization",page:"behavior",titleKey:"settings.behavior.page.section.systemPromptOptimization",descriptionKey:"settings.behavior.page.systemPromptOptimization.info",keywords:["system prompt","tokens","context","optimize","minimal"],isAvailable:t=>!t.isVSCode},{id:"behavior.system-prompt",page:"behavior",titleKey:"settings.behavior.page.section.systemPrompt",descriptionKey:"settings.behavior.page.warning.title",keywords:["agents.md","global instructions","system prompt"]},{id:"behavior.response-style",page:"behavior",titleKey:"settings.behavior.page.section.responseStyle",descriptionKey:"settings.behavior.page.responseStyle.tooltip",keywords:["tone","concise","detailed","custom instructions"]},{id:"agents.create",page:"agents",titleKey:"settings.agents.page.title.new",keywords:["create","add","new agent"]},{id:"agents.name",page:"agents",titleKey:"settings.agents.page.field.agentName",keywords:["agent","name"]},{id:"agents.mode",page:"agents",titleKey:"settings.agents.page.field.mode",descriptionKey:"settings.agents.page.field.modeTooltip",keywords:["primary","subagent","visibility"]},{id:"agents.model",page:"agents",titleKey:"settings.agents.page.field.overrideModel",keywords:["model","provider"]},{id:"agents.variant",page:"agents",titleKey:"settings.agents.page.field.variant",descriptionKey:"settings.agents.page.field.variantTooltip",keywords:["thinking","reasoning","variant","depth"]},{id:"agents.temperature",page:"agents",titleKey:"settings.agents.page.field.temperature",descriptionKey:"settings.agents.page.field.temperatureTooltip",keywords:["randomness","creative"]},{id:"agents.top-p",page:"agents",titleKey:"settings.agents.page.field.topP",descriptionKey:"settings.agents.page.field.topPTooltip",keywords:["sampling","nucleus"]},{id:"agents.system-prompt",page:"agents",titleKey:"settings.agents.page.section.systemPrompt",keywords:["prompt","instructions"]},{id:"agents.permissions",page:"agents",titleKey:"settings.agents.page.section.toolPermissions",keywords:["tools","permissions","allow","ask","deny"]},{id:"commands.create",page:"commands",titleKey:"settings.commands.page.title.new",keywords:["create","add","new command"]},{id:"commands.name",page:"commands",titleKey:"settings.commands.page.field.commandName",keywords:["slash command","name"]},{id:"commands.agent",page:"commands",titleKey:"settings.commands.page.field.overrideAgent",keywords:["agent","execution"]},{id:"commands.model",page:"commands",titleKey:"settings.agents.page.field.overrideModel",keywords:["model","provider"]},{id:"commands.template",page:"commands",titleKey:"settings.commands.page.section.template",keywords:["prompt","template","arguments","shell","file"]},{id:"mcp.create",page:"mcp",titleKey:"settings.mcp.sidebar.actions.addServerTitle",keywords:["create","add","server"]},{id:"mcp.server",page:"mcp",titleKey:"settings.mcp.page.server.title",keywords:["server","name","transport"]},{id:"mcp.command",page:"mcp",titleKey:"settings.mcp.page.connection.command",keywords:["stdio","local","command"]},{id:"mcp.environment",page:"mcp",titleKey:"settings.mcp.page.env.title",keywords:["env","variables","api key"]},{id:"mcp.advanced",page:"mcp",titleKey:"settings.mcp.page.advanced.title",keywords:["oauth","headers","timeout"]},{id:"plugins.create",page:"plugins",titleKey:"settings.plugins.sidebar.actions.addTitle",keywords:["add","plugin","npm","path","file"]},{id:"plugins.spec",page:"plugins",titleKey:"settings.plugins.page.field.spec",keywords:["npm","package","path"]},{id:"plugins.options",page:"plugins",titleKey:"settings.plugins.page.field.options",keywords:["json","configuration"]},{id:"plugins.content",page:"plugins",titleKey:"settings.plugins.page.field.content",keywords:["file","code"]},{id:"snippets.create",page:"snippets",titleKey:"settings.snippets.sidebar.actions.create",keywords:["add","new snippet"]},{id:"snippets.content",page:"snippets",titleKey:"settings.snippets.page.field.content",keywords:["markdown","prompt","template"]},{id:"providers.connect",page:"providers",titleKey:"settings.providers.page.connect.title",keywords:["add provider","connect provider","credentials"]},{id:"providers.custom",page:"providers",titleKey:"settings.providers.page.custom.title",descriptionKey:"settings.providers.page.custom.description",keywords:["other","custom","openai-compatible","base url","api key"]},{id:"providers.auth",page:"providers",titleKey:"settings.providers.page.auth.title",keywords:["api key","oauth","credentials"]},{id:"providers.connection-details",page:"providers",titleKey:"settings.providers.page.connectionDetails.title",keywords:["config","source","disconnect"]},{id:"providers.models",page:"providers",titleKey:"settings.providers.page.models.title",keywords:["models","hide","show"]},{id:"skills.create",page:"skills.installed",titleKey:"settings.skills.page.title.newSkill",keywords:["create","add","new skill"]},{id:"skills.basic-information",page:"skills.installed",titleKey:"settings.skills.page.section.basicInformation",keywords:["name","location","description"]},{id:"skills.instructions",page:"skills.installed",titleKey:"settings.skills.page.section.instructions",keywords:["markdown","skill.md","content"]},{id:"skills.supporting-files",page:"skills.installed",titleKey:"settings.skills.page.section.supportingFiles",keywords:["files","resources"]},{id:"skills.catalog.source",page:"skills.catalog",titleKey:"settings.skills.catalog.page.section.sourceRepository",keywords:["catalog","repository","source","refresh"]},{id:"skills.catalog.search",page:"skills.catalog",titleKey:"settings.skills.catalog.shared.field.searchSkillsPlaceholder",keywords:["find skills","install skills","catalog search"]},{id:"skills.catalog.add-catalog",page:"skills.catalog",titleKey:"settings.skills.catalog.page.actions.addCatalog",keywords:["external repository","add source","catalog"]},{id:"magic-prompts.visible-prompt",page:"magic-prompts",titleKey:"settings.magicPrompts.page.block.visiblePrompt",keywords:["prompt text","user message","template"],isAvailable:t=>!t.isVSCode},{id:"magic-prompts.instructions",page:"magic-prompts",titleKey:"settings.magicPrompts.page.block.instructions",keywords:["hidden prompt","instructions","template"],isAvailable:t=>!t.isVSCode},{id:"magic-prompts.reset-overrides",page:"magic-prompts",titleKey:"settings.magicPrompts.page.actions.resetAllOverrides",keywords:["reset","default prompts","overrides"],isAvailable:t=>!t.isVSCode},{id:"shortcuts.keyboard-shortcuts",page:"shortcuts",titleKey:"settings.aiworker.keyboardShortcuts.title",descriptionKey:"settings.aiworker.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.aiworker.tunnel.field.provider",descriptionKey:"settings.aiworker.tunnel.description",keywords:["remote access","cloudflare","ngrok"],isAvailable:t=>!t.isVSCode},{id:"tunnel.type",page:"tunnel",titleKey:"settings.aiworker.tunnel.field.tunnelType",keywords:["quick","managed remote","managed local"],isAvailable:t=>!t.isVSCode},{id:"tunnel.ttl",page:"tunnel",titleKey:"settings.aiworker.tunnel.field.connectLinkTtl",descriptionKey:"settings.aiworker.tunnel.field.tunnelSessionTtl",keywords:["expiry","expiration","session ttl","connect link ttl"],isAvailable:t=>!t.isVSCode},{id:"tunnel.managed-remote",page:"tunnel",titleKey:"settings.aiworker.tunnel.section.savedManagedRemoteTunnels",keywords:["cloudflare","hostname","token","managed remote"],isAvailable:t=>!t.isVSCode},{id:"tunnel.managed-local-config",page:"tunnel",titleKey:"settings.aiworker.tunnel.field.configurationFile",descriptionKey:"settings.aiworker.tunnel.note.managedLocalUsesConfig",keywords:["cloudflared","config","yaml","json","managed local"],isAvailable:t=>!t.isVSCode},{id:"tunnel.start",page:"tunnel",titleKey:"settings.aiworker.tunnel.actions.startTunnel",descriptionKey:"settings.aiworker.tunnel.note.connectLinksOneTime",keywords:["connect link","qr code","public url","remote access"],isAvailable:t=>!t.isVSCode},{id:"notifications.delivery",page:"notifications",titleKey:"settings.notifications.page.delivery.title",keywords:["desktop notifications","system notifications"]},{id:"notifications.events",page:"notifications",titleKey:"settings.notifications.page.events.title",keywords:["completion","subtasks","errors","questions"]},{id:"notifications.push",page:"notifications",titleKey:"settings.notifications.page.push.title",keywords:["background","push"],isAvailable:t=>t.isWeb&&!t.isDesktop&&!t.isVSCode},{id:"integrations.first-party",page:"integrations",titleKey:"settings.integrations.firstParty.title",descriptionKey:"settings.integrations.firstParty.info",keywords:["built-in","first-party","native","github","linear"],isAvailable:t=>!t.isVSCode},{id:"integrations.github",page:"integrations",titleKey:"settings.integrations.github.title",descriptionKey:"settings.integrations.github.description",keywords:["github","account","oauth","gh","cli","prs","pull request","issues","connect"],isAvailable:t=>!t.isVSCode},{id:"integrations.linear",page:"integrations",titleKey:"settings.integrations.linear.title",descriptionKey:"settings.integrations.linear.description",keywords:["linear","issues","oauth","connect","workspace"],isAvailable:t=>!t.isVSCode},{id:"integrations.linear.add-workspace",page:"integrations",titleKey:"settings.integrations.linear.actions.addWorkspace",descriptionKey:"settings.integrations.linear.description",keywords:["linear","workspace","add","connect","oauth"],isAvailable:t=>!t.isVSCode},{id:"integrations.linear.mapping",page:"integrations",titleKey:"settings.integrations.linear.mapping.defaultProject",descriptionKey:"settings.integrations.linear.mapping.defaultProject.info",keywords:["linear","project","team","map","workspace","directory"],isAvailable:t=>!t.isVSCode},{id:"integrations.third-party",page:"integrations",titleKey:"settings.integrations.thirdParty.title",keywords:["plugin","provider","oauth","install","update","remove"]},{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","@aiworker/opencode-claude"]},{id:"integrations.third-party.opencode-cursor-oauth",page:"integrations",titleKey:"settings.integrations.thirdParty.opencodeCursorOauth.name",descriptionKey:"settings.integrations.thirdParty.opencodeCursorOauth.description",keywords:["cursor","oauth","subscription","openai compatible","@aiworker/opencode-cursor"]}];function nl(t){return t.trim().toLocaleLowerCase()}function cx({query:t,runtimeCtx:e,visiblePageSlugs:a,t:n,getPageTitle:i}){const r=nl(t);if(!r)return[];const l=a?new Set(a):null,u=r.split(/\s+/).filter(Boolean);return lx.flatMap(p=>{if(l&&!l.has(p.page))return[];const h=Ma(p.page);if(!h||h.isAvailable&&!h.isAvailable(e)||p.isAvailable&&!p.isAvailable(e))return[];const d=n(p.titleKey),w=p.descriptionKey?n(p.descriptionKey):null,c=nl([d,w,i(p.page),...p.keywords??[]].filter(Boolean).join(" "));return u.every(N=>c.includes(N))?[{...p,title:d,description:w,pageTitle:i(p.page)}]:[]})}const al=256,il=280,nc="__aiworkerSettingsDetail",dx=["general","appearance","chat","notifications","sessions","shortcuts","voice","integrations","usage","about","projects","remote-instances","tunnel","git","providers","agents","behavior","commands","mcp","plugins","magic-prompts","snippets","skills.installed","skills.catalog"],ux=["general","projects","opencode","content"],px="__add_provider__";function mx(t,e){const a=us(),n=!t&&Vn();return{isVSCode:a,isWeb:n,isDesktop:t,isMobile:e}}function rl(t,e){return t.isAvailable?t.isAvailable(e):!0}function ur(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}function Da(t,e){const a=new Set(e);let n=t,i=1;for(;a.has(n);)n=`${t}-${i}`,i+=1;return n}function Yi(t){if(!ur(t))return null;const e=t[nc];if(!ur(e))return null;const a=e.page,n=e.stage;return typeof a!="string"||n!=="page-content"?null:{page:Il(a),stage:n}}function gx(){return typeof window>"u"||!ur(window.history.state)?{}:window.history.state}const Sx=({onClose:t,forceMobile:e,isWindowed:a,visiblePageSlugs:n,initialMobileStage:i="nav"})=>{const{t:r}=at(),l=ma(),u=e??l.isMobile,p=vn(jl),h=de(ie=>ie.settingsPage),d=de(ie=>ie.isSettingsDialogOpen),w=de(ie=>ie.setSettingsPage),c=de(ie=>ie.shortcutOverrides.open_settings),N=Il(h),[v,C]=o.useState(i),y=o.useRef(i==="nav"?N:null);o.useEffect(()=>{!u&&N==="home"&&w("general")},[u,w,N]);const[S,g]=o.useState(""),[T,R]=o.useState(null),[A,j]=o.useState(0),f=o.useRef(null),b=o.useRef(!1),F=o.useRef([]),D=o.useRef(0),P=o.useRef(!1),I=o.useMemo(()=>os(),[]),U=o.useMemo(()=>os()&&$a(),[]),q=o.useMemo(()=>os()&&typeof window<"u"&&window.__AIWORKER_PLATFORM__==="darwin",[]),k=o.useMemo(()=>os()&&typeof window<"u"&&window.__AIWORKER_PLATFORM__==="win32",[]),$=o.useMemo(()=>os()&&typeof window<"u"&&window.__AIWORKER_PLATFORM__==="linux",[]),G=o.useMemo(()=>Cl(),[]),E=o.useMemo(()=>mx(I,u),[I,u]),J=o.useMemo(()=>{const ie=n?new Set(n):null;return Fd.filter(re=>re.slug!=="home").filter(re=>!ie||ie.has(re.slug)).filter(re=>rl(re,E)).filter(re=>!(E.isVSCode&&re.slug==="projects")).filter(re=>!(u&&re.slug==="shortcuts"))},[E,u,n]),X=o.useMemo(()=>{const ie=new Map(dx.map((re,je)=>[re,je]));return J.slice().sort((re,je)=>(ie.get(re.slug)??999)-(ie.get(je.slug)??999))},[J]),L=Vs(ie=>ie.activeProjectId),se=Us();o.useEffect(()=>{if(!(!d&&!E.isVSCode&&!a)){if(N==="agents"){Bn.getState().loadAgents(se);return}if(N==="commands"){ua.getState().loadCommands(se);return}if(N==="mcp"){pa.getState().loadMcpConfigs({directory:se});return}if(N==="plugins"){rs.getState().loadPlugins();return}(N==="skills.installed"||N==="skills.catalog")&&($s.getState().loadSkills(se),fn.getState().loadCatalog()),N==="snippets"&&hi.getState().loadSnippets()}},[L,d,a,E.isVSCode,se,N]);const z=o.useCallback(ie=>{if(w(ie),y.current=ie,!u)return;const re=Ma(ie);if(!re||re.slug==="home"){C("nav");return}C(re.kind==="split"?"page-sidebar":"page-content")},[u,w]),V=o.useCallback(async ie=>{const re=Ze.getState();return await re.loadProviders({source:"settings:third-party-provider-setup"}),Ze.getState().providers.some(ve=>ve.id===ie)?(re.setSelectedProvider(ie),z("providers"),u&&C("page-content"),!0):!1},[u,z]),_=o.useMemo(()=>Ma(N),[N]),K=o.useMemo(()=>({general:"general",appearance:"visual",chat:"chat",shortcuts:"shortcuts",sessions:"sessions",notifications:"notifications",voice:"voice",tunnel:"tunnel"}),[]),Z=o.useCallback(ie=>{switch(ie){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"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"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"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"about":return r("settings.page.about.title");default:return r("settings.view.home.title")}},[r]),Y=o.useMemo(()=>cx({query:S,runtimeCtx:{...E,isDesktopLocalOrigin:U,isMac:q,isWindows:k,isLinux:$,isWindowsArm64:G},visiblePageSlugs:n,t:r,getPageTitle:Z}),[Z,G,U,q,k,$,E,S,r,n]),te=o.useCallback(ie=>{if(ie.id.startsWith("agents.")){const re=Bn.getState(),je=Da("new-agent",re.agents.map(ve=>ve.name));return re.setAgentDraft({name:je,scope:"user"}),re.setSelectedAgent(je),ie.id==="agents.create"?"agents.name":ie.id}if(ie.id.startsWith("commands.")){const re=ua.getState(),je=Da("new-command",re.commands.map(ve=>ve.name));return re.setCommandDraft({name:je,scope:"user"}),re.setSelectedCommand(je),ie.id==="commands.create"?"commands.name":ie.id}if(ie.id.startsWith("mcp.")){const re=pa.getState(),je=Da("new-mcp-server",re.mcpServers.map(ve=>ve.name));return re.setMcpDraft({name:je,scope:"user",type:"local",command:[],url:"",environment:[],headers:[],oauthEnabled:!0,oauthClientId:"",oauthClientSecret:"",oauthScope:"",oauthRedirectUri:"",timeout:"",enabled:!0}),re.setSelectedMcp(je),ie.id==="mcp.create"?"mcp.server":ie.id}if(ie.id.startsWith("snippets.")){const re=hi.getState(),je=Da("new-snippet",re.snippets.map(ve=>ve.name));return re.setSnippetDraft({name:je,scope:"global"}),re.setSelectedSnippet(je),ie.id==="snippets.create"?"snippets.content":ie.id}if(ie.id.startsWith("skills.")){const re=$s.getState(),je=Da("new-skill",re.skills.map(ve=>ve.name));return re.setSkillDraft({name:je,scope:"user",source:"opencode",description:"",instructions:""}),re.setSelectedSkill(je),ie.id==="skills.create"?"skills.basic-information":ie.id}return ie.id==="providers.connect"&&Ze.getState().setSelectedProvider(px),ie.id==="plugins.create"?"plugins.spec":ie.id},[]),ge=o.useMemo(()=>{const ie=[],re=new Map;for(const je of Y){let ve=re.get(je.page);ve||(ve={page:je.page,pageTitle:je.pageTitle,results:[]},re.set(je.page,ve),ie.push(ve)),ve.results.push(je)}return ie},[Y]);o.useEffect(()=>{j(0),D.current=0,P.current=!1},[S]),o.useEffect(()=>{D.current=A},[A]),o.useEffect(()=>{F.current[A]?.scrollIntoView({block:"nearest"})},[A]),o.useEffect(()=>{A>=Y.length&&j(Math.max(0,Y.length-1)),F.current.length=Y.length},[A,Y.length]);const le=o.useCallback(ie=>{const re=te(ie);R(re),z(ie.page),u&&C("page-content"),ie.id==="plugins.create"&&typeof window<"u"&&window.setTimeout(()=>{window.dispatchEvent(new CustomEvent("aiworker:settings-open-plugin-add"))},50)},[u,z,te]),he=o.useCallback(ie=>{if(S.trim()){if(ie.key==="Escape"){ie.preventDefault(),g("");return}if(Y.length!==0){if(ie.key==="ArrowDown"){ie.preventDefault(),P.current=!0,j(re=>(re+1)%Y.length);return}if(ie.key==="ArrowUp"){ie.preventDefault(),P.current=!0,j(re=>(re-1+Y.length)%Y.length);return}if(ie.key==="Enter"){ie.preventDefault();const re=(D.current%Y.length+Y.length)%Y.length,je=Y[re]??Y[0];je&&le(je)}}}},[le,S,Y]);o.useEffect(()=>{const ie=T;if(!ie)return;let re=!1;const je=window.requestAnimationFrame(()=>{if(re)return;const ve=typeof CSS<"u"&&CSS.escape?CSS.escape(ie):ie.replace(/[^a-zA-Z0-9_-]/g,"\\$&"),Re=f.current?.querySelector(`[data-settings-item="${ve}"]`);Re&&(R(null),Re.scrollIntoView({block:"center",behavior:"smooth"}),Re.setAttribute("data-settings-search-highlight","true"),window.setTimeout(()=>{Re.removeAttribute("data-settings-search-highlight")},1600))});return()=>{re=!0,window.cancelAnimationFrame(je)}},[T,N]);const ne=o.useCallback(()=>s.jsx("div",{className:"flex h-full items-center justify-center px-6",children:s.jsxs("div",{className:"max-w-md text-center",children:[s.jsx("div",{className:hl,children:r("settings.view.unavailable.title")}),s.jsx("p",{className:"typography-ui text-muted-foreground mt-1",children:r("settings.view.unavailable.description")})]})}),[r]),ae=o.useCallback((ie,re)=>{switch(ie){case"projects":return s.jsx(bm,{onItemSelect:re.onItemSelect});case"agents":return s.jsx(ru,{onItemSelect:re.onItemSelect});case"commands":return s.jsx(ku,{onItemSelect:re.onItemSelect});case"mcp":return s.jsx(Eu,{onItemSelect:re.onItemSelect});case"plugins":return s.jsx(vp,{onItemSelect:re.onItemSelect});case"skills.installed":return s.jsx(Dp,{onItemSelect:re.onItemSelect});case"providers":return s.jsx(qm,{onItemSelect:re.onItemSelect});case"usage":return s.jsx(Eg,{onItemSelect:re.onItemSelect});case"magic-prompts":return s.jsx(Wg,{onItemSelect:re.onItemSelect});case"snippets":return s.jsx(Yg,{onItemSelect:re.onItemSelect});default:return null}},[]),me=o.useCallback(ie=>{const re=Ma(ie);if(re&&!rl(re,E))return ne();switch(ie){case"projects":return s.jsx(Sm,{});case"remote-instances":return s.jsx(Hm,{});case"agents":return s.jsx(xu,{});case"behavior":return s.jsx(ju,{});case"commands":return s.jsx(Tu,{});case"mcp":return s.jsx(Xu,{});case"plugins":return s.jsx(Tp,{});case"skills.installed":return s.jsx(go,{view:"installed"});case"skills.catalog":return s.jsx(go,{view:"catalog"});case"providers":return s.jsx(Ag,{});case"usage":return s.jsx(Hg,{});case"about":return s.jsx(ns,{title:r("settings.page.about.title"),showSaveStatus:!1,children:s.jsx(El,{})});case"magic-prompts":return s.jsx(Qg,{});case"snippets":return s.jsx(tf,{});case"git":return s.jsx(of,{});case"integrations":return s.jsx(Cf,{onOpenProviderSetup:V,onOpenPluginManager:()=>z("plugins")});case"general":case"appearance":case"chat":case"shortcuts":case"sessions":case"notifications":case"voice":case"tunnel":{const je=K[ie]??"visual";return s.jsx(Gh,{section:je})}default:return null}},[K,z,V,ne,E,r]);o.useEffect(()=>{if(!u||v!=="nav"||N==="home"||y.current===N)return;const ie=Ma(N);!ie||ie.slug==="home"||(y.current=N,C(ie.kind==="split"?"page-sidebar":"page-content"))},[u,v,N]);const Pe=u&&v!=="nav",Ne=u&&v==="page-content"&&N==="skills.installed",Se=v==="page-content"&&_?.kind==="split"&&!Ne,be=r(Ne?"settings.view.actions.back":Pe?"settings.view.actions.backToSettings":"settings.view.actions.closeSettings"),Ke=wl("open_settings",c===void 0?void 0:{open_settings:c}),Le=Ke?r("settings.view.actions.closeSettingsWithShortcut",{shortcut:Hn(Ke)}):r("settings.view.actions.closeSettings"),oe=o.useCallback(ie=>{if(typeof window>"u"||E.isVSCode)return;const re=Yi(window.history.state);re?.page===ie&&re.stage==="page-content"||window.history.pushState({...gx(),[nc]:{page:ie,stage:"page-content"}},"",window.location.href)},[E.isVSCode]),xe=o.useCallback(()=>{b.current=!0,C("page-content"),N==="skills.installed"&&oe(N)},[oe,N]);o.useEffect(()=>{if(!u||v!=="page-content"||!b.current)return;b.current=!1;const ie=window.requestAnimationFrame(()=>{f.current?.querySelector("[data-settings-page-heading]")?.focus({preventScroll:!0})});return()=>{window.cancelAnimationFrame(ie)}},[u,v,N]);const Ee=o.useCallback(()=>{if(Ne){if((typeof window<"u"?Yi(window.history.state):null)?.page===N&&!E.isVSCode){window.history.back();return}C("page-sidebar");return}C("nav")},[Ne,E.isVSCode,N]);o.useEffect(()=>{if(!u||E.isVSCode)return;const ie=re=>{if(N!=="skills.installed")return;if(Yi(re.state)?.page==="skills.installed"){C("page-content");return}C(ve=>ve==="page-content"?"page-sidebar":ve)};return window.addEventListener("popstate",ie),()=>{window.removeEventListener("popstate",ie)}},[u,E.isVSCode,N]);const Ve=o.useCallback(()=>{C("page-sidebar")},[]),$e=()=>{const ie=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:"flex h-10 items-center gap-1.5 rounded-md border border-border bg-background/70 px-2 text-muted-foreground focus-within:ring-2 focus-within:ring-primary/40 sm:h-8",children:[s.jsx(O,{name:"search",className:"h-4 w-4 shrink-0"}),s.jsx("input",{value:S,onChange:re=>g(re.target.value),onKeyDown:he,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"}),ie&&s.jsx("button",{type:"button",onClick:()=>g(""),"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(O,{name:"close",className:"h-3.5 w-3.5"})})]})}),s.jsx("div",{className:"flex-1 min-h-0 overflow-y-auto overflow-x-hidden",children:s.jsx("div",{className:"flex flex-col gap-0.5 px-4 pt-4 pb-2",children:ie?Y.length>0?(()=>{let re=0;return ge.map(je=>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:je.pageTitle}),je.results.map(ve=>{const Re=re;re+=1;const Ae=Re===A,ye=!!ve.description;return s.jsxs("button",{type:"button",ref:He=>{F.current[Re]=He},onMouseMove:()=>{P.current=!1,j(Re)},onClick:()=>le(ve),className:we("flex w-full flex-col rounded-md px-2 text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-primary/50",ye?"min-h-11 py-1.5":"py-2",Ae?"bg-interactive-selection":"hover:bg-interactive-hover"),children:[s.jsx("span",{className:"typography-ui-label text-foreground truncate",children:ve.title}),ye&&s.jsx("span",{className:"typography-micro text-muted-foreground/70 line-clamp-2",children:ve.description})]},ve.id)})]},je.page))})():s.jsx("div",{className:"px-2 py-6 text-center typography-ui text-muted-foreground",children:r("settings.view.search.noResults")}):(()=>{const re=new Map;for(const ve of X){const Re=ve.group,Ae=re.get(Re);Ae?Ae.push(ve):re.set(Re,[ve])}return ux.map(ve=>({group:ve,pages:re.get(ve)??[]})).filter(ve=>ve.pages.length>0).map(({group:ve,pages:Re},Ae)=>s.jsxs("div",{className:"space-y-0.5",children:[s.jsx("div",{className:we("px-3 pb-1 typography-micro font-semibold uppercase tracking-wide text-muted-foreground sm:px-2 sm:pb-0.5",Ae===0?"pt-1":"pt-4 sm:pt-3"),children:r(`settings.view.nav.group.${ve}`)}),Re.map(ye=>{const He=N===ye.slug&&!(u&&v==="nav"),ue=Kd(ye.slug);return!ue&&ye.slug!=="mcp"?null:s.jsx(gr,{children:s.jsx(fr,{asChild:!0,children:s.jsxs("button",{type:"button",onClick:()=>z(ye.slug),"aria-current":He?"page":void 0,className:we("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",He?"bg-interactive-selection text-foreground":"text-foreground hover:bg-interactive-hover"),children:[ye.slug==="mcp"?s.jsx(id,{className:"h-[18px] w-[18px] shrink-0 sm:h-4 sm:w-4"}):s.jsx(O,{name:ue,className:"h-[18px] w-[18px] shrink-0 sm:h-4 sm:w-4"}),s.jsxs("span",{className:"flex items-center gap-1.5 whitespace-nowrap overflow-hidden transition-opacity duration-150 opacity-100",children:[s.jsx("span",{className:"typography-ui-label font-normal truncate",children:Z(ye.slug)}),ye.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")})]})]})})},ye.slug)})]},ve))})()})}),s.jsx("div",{className:"overflow-hidden transition-opacity duration-150 opacity-100",children:s.jsx("div",{className:"border-t border-border bg-background px-4 py-1.5 space-y-0.5 sm:bg-sidebar",children:(!E.isVSCode||p>0)&&s.jsx(nx,{})})})]})},We=()=>{if(v==="nav")return s.jsx("div",{className:"flex-1 min-h-0 overflow-hidden bg-background",children:s.jsx("div",{className:"flex h-full min-h-0 flex-col",children:s.jsx(Pn,{children:$e()})})});if(!_)return s.jsx("div",{className:"flex-1 bg-background"});if(v==="page-sidebar"){if(_.kind!=="split"){const re=me(N);return s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(Pn,{children:re})})}return s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(Pn,{children:ae(N,{onItemSelect:xe})})})}const ie=me(N);return s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(Pn,{children:ie})})},Fe=()=>!_||N==="home"?null:_.kind==="split"?s.jsxs("div",{className:"flex h-full min-h-0 overflow-hidden",children:[s.jsx("div",{className:we("border-r",E.isVSCode?"bg-background":"bg-sidebar"),style:{width:il,minWidth:il,borderColor:"var(--interactive-border)"},children:s.jsx(Pn,{children:ae(N,{})})}),s.jsx("div",{className:"flex-1 min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(Pn,{children:me(N)})})]}):s.jsx("div",{className:"h-full min-h-0 overflow-y-scroll overflow-x-hidden bg-background",children:s.jsx(Pn,{children:me(N)})});return s.jsxs("div",{ref:f,"data-settings-view":"true",className:we("relative flex h-full min-h-0 flex-col overflow-hidden bg-background"),children:[u?s.jsxs("div",{className:we("flex h-[var(--oc-header-height,56px)] shrink-0 items-center gap-2 px-3",v!=="nav"&&"border-b","bg-background"),style:v!=="nav"?{borderColor:"var(--interactive-border)"}:void 0,children:[Pe?s.jsx("button",{type:"button",onClick:Ee,"aria-label":be,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-primary",children:s.jsx(O,{name:"arrow-left-s",className:"h-5 w-5"})}):null,s.jsx("div",{className:"min-w-0 flex-1 px-2 typography-ui-label font-medium text-foreground truncate",children:v==="nav"?r("settings.view.home.title"):_?Z(_.slug):r("settings.view.home.title")}),Se&&s.jsx("button",{type:"button",onClick:Ve,"aria-label":r("settings.view.actions.openSectionList"),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-primary",children:s.jsx(O,{name:"list-unordered",className:"h-5 w-5"})}),t&&s.jsx("button",{type:"button",onClick:t,"aria-label":r("settings.view.actions.closeSettings"),title:Le,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-primary",children:s.jsx(O,{name:"close",className:"h-5 w-5"})})]}):s.jsxs(s.Fragment,{children:[Pe&&s.jsx("div",{className:we("absolute left-3 z-50",a?"top-2":"top-3"),children:s.jsx("button",{type:"button",onClick:Ee,"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-primary",children:s.jsx(O,{name:"arrow-left-s",className:"h-5 w-5"})})}),t&&s.jsx("div",{className:we("absolute right-0.5 z-50",a?"top-0.5":"top-1"),children:s.jsx("button",{type:"button",onClick:t,"aria-label":r("settings.view.actions.closeSettings"),title:Le,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-primary",children:s.jsx(O,{name:"close",className:"h-5 w-5"})})})]}),s.jsx("div",{className:"flex flex-1 min-h-0 overflow-hidden",children:u?We():s.jsxs(s.Fragment,{children:[s.jsx("div",{className:we("relative flex h-full min-h-0 flex-col overflow-hidden border-r",I?"bg-sidebar":E.isVSCode?"bg-background":"bg-sidebar"),style:{width:`${al}px`,minWidth:`${al}px`,borderColor:"var(--interactive-border)"},children:s.jsx(Pn,{children:$e()})}),s.jsx("div",{className:"flex-1 overflow-hidden bg-background",children:Fe()})]})})]})};export{El as A,Sx as S};