@xopcai/xopc 0.0.162 → 0.0.163

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 (230) hide show
  1. package/README.md +4 -2
  2. package/README.zh-CN.md +4 -2
  3. package/dist/browser-ext/manifest.json +1 -1
  4. package/dist/extensions/telegram/xopc.extension.json +1 -1
  5. package/dist/gateway/static/root/assets/{activity-store-hpcNv9MZ.js → activity-store-Xj95LzTv.js} +1 -1
  6. package/dist/gateway/static/root/assets/{agent-avatar-dicebear-Zf9UQEmQ.js → agent-avatar-dicebear-C-QeUFwU.js} +1 -1
  7. package/dist/gateway/static/root/assets/agents-DVKlWKJE.js +2 -0
  8. package/dist/gateway/static/root/assets/{api-Dnatri09.js → api-BTLmAm1_.js} +1 -1
  9. package/dist/gateway/static/root/assets/{app-management-settings-panel-BBTR9wJP.js → app-management-settings-panel-zc6Gf-S5.js} +1 -1
  10. package/dist/gateway/static/root/assets/{appearance-settings-C2zpLCHD.js → appearance-settings-0fMLnOWn.js} +1 -1
  11. package/dist/gateway/static/root/assets/apps-page-BZXEJDIV.js +1 -0
  12. package/dist/gateway/static/root/assets/{archive-plugin-9eR_ODY1.js → archive-plugin-DOiR_E21.js} +1 -1
  13. package/dist/gateway/static/root/assets/{attachment-load-DPuWYUeX.js → attachment-load-BxmYl1D1.js} +1 -1
  14. package/dist/gateway/static/root/assets/{automation-suggestion-card-Dw49OJRl.js → automation-suggestion-card-BhZOirad.js} +1 -1
  15. package/dist/gateway/static/root/assets/automations-page-B8CnkoXv.js +6 -0
  16. package/dist/gateway/static/root/assets/{binary-plugins-BdkJpDFm.js → binary-plugins-DTTKsvgk.js} +1 -1
  17. package/dist/gateway/static/root/assets/{block-editor-CAi7SXYU.js → block-editor-C7se7iqg.js} +31 -31
  18. package/dist/gateway/static/root/assets/browser-settings-page-BCPWKI9V.js +8 -0
  19. package/dist/gateway/static/root/assets/{browser-workflow-inputs-Dx6wkGz1.js → browser-workflow-inputs-kxmStCcv.js} +1 -1
  20. package/dist/gateway/static/root/assets/{browser-workflows-page-Skertc-A.js → browser-workflows-page-CwYf9OM_.js} +2 -2
  21. package/dist/gateway/static/root/assets/capabilities-settings-panel-C7lr_mX2.js +2 -0
  22. package/dist/gateway/static/root/assets/{capability-presets-api-CNFl7dM3.js → capability-presets-api-BZKh2cWX.js} +1 -1
  23. package/dist/gateway/static/root/assets/capability-presets-settings-panel-Ble9kHRu.js +2 -0
  24. package/dist/gateway/static/root/assets/{channel-recipient-api-DYQyGDw4.js → channel-recipient-api-r7tdbnJE.js} +1 -1
  25. package/dist/gateway/static/root/assets/channels-settings-CtQQQHrv.js +1 -0
  26. package/dist/gateway/static/root/assets/channels-status-swr-_VirfMKW.js +1 -0
  27. package/dist/gateway/static/root/assets/{connector-logo-Bng6kxYF.js → connector-logo-BpnQYAxA.js} +1 -1
  28. package/dist/gateway/static/root/assets/connectors-page-BXWJSJeY.js +2 -0
  29. package/dist/gateway/static/root/assets/desktop-pet-B86W4a5c.js +1 -0
  30. package/dist/gateway/static/root/assets/{desktop-pet-settings-BVUyefSd.js → desktop-pet-settings-uv8Grtgk.js} +1 -1
  31. package/dist/gateway/static/root/assets/{directory-picker-path-field-DjSZAPz_.js → directory-picker-path-field-C4TTvf7p.js} +1 -1
  32. package/dist/gateway/static/root/assets/{dreaming-settings-CAZk2AM4.js → dreaming-settings-CzJAUPvM.js} +2 -2
  33. package/dist/gateway/static/root/assets/{extension-debug-page-C2F6vTTd.js → extension-debug-page-Ci2mOYUt.js} +1 -1
  34. package/dist/gateway/static/root/assets/{extension-page-AnIt4bn4.js → extension-page-DeXdmhXQ.js} +1 -1
  35. package/dist/gateway/static/root/assets/extension-settings-page-C93vaOsU.js +1 -0
  36. package/dist/gateway/static/root/assets/{gateway-config-api-DLFyZv33.js → gateway-config-api-C31Hlblp.js} +1 -1
  37. package/dist/gateway/static/root/assets/{gateway-settings-DnQAA-qq.js → gateway-settings-D3zS6RZh.js} +1 -1
  38. package/dist/gateway/static/root/assets/{gateway-startup-retry-DbzLyJ3R.js → gateway-startup-retry-CSRvCqxh.js} +1 -1
  39. package/dist/gateway/static/root/assets/{goal-create-dialog-DrnKFC6M.js → goal-create-dialog-CWp2b7__.js} +1 -1
  40. package/dist/gateway/static/root/assets/goal-detail-page-Dtm29FxD.js +4 -0
  41. package/dist/gateway/static/root/assets/{goals-config-api-REmr3QCr.js → goals-config-api-D4wYNRrf.js} +1 -1
  42. package/dist/gateway/static/root/assets/goals-page-jMzBJs6e.js +2 -0
  43. package/dist/gateway/static/root/assets/{goals-settings-Dz0F3uRO.js → goals-settings-Bx2jVvhQ.js} +1 -1
  44. package/dist/gateway/static/root/assets/{heartbeat-settings-CQFY5gYs.js → heartbeat-settings-BEIF1eXy.js} +1 -1
  45. package/dist/gateway/static/root/assets/index-BXtJvaQl.css +1 -0
  46. package/dist/gateway/static/root/assets/{index-C8JkTS6d.js → index-HZdBKfk_.js} +70 -70
  47. package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-BnOQXU5k.js → keyboard-shortcuts-settings-DOEDpvTM.js} +1 -1
  48. package/dist/gateway/static/root/assets/local-app-workbench-page-CseW9jD3.js +2 -0
  49. package/dist/gateway/static/root/assets/{local-apps-page-KsOtWOyM.js → local-apps-page-B0OpGpxv.js} +1 -1
  50. package/dist/gateway/static/root/assets/{locale-store-0lpYdNDr.js → locale-store-Ys6RP7Be.js} +1 -1
  51. package/dist/gateway/static/root/assets/logs-page-DVqPbth5.js +7 -0
  52. package/dist/gateway/static/root/assets/{markdown-split-D5GRg10r.js → markdown-split-CEZwysCH.js} +1 -1
  53. package/dist/gateway/static/root/assets/{media-plugins-C1ryULGs.js → media-plugins-CpGKE7B0.js} +1 -1
  54. package/dist/gateway/static/root/assets/messages-BzI9Wx30.js +5 -0
  55. package/dist/gateway/static/root/assets/{notes-page-CIeZ1_DT.js → notes-page-CdiuDZ5a.js} +1 -1
  56. package/dist/gateway/static/root/assets/notes-workbench-mrc3xtpn.js +4 -0
  57. package/dist/gateway/static/root/assets/{page-tabs-Caj1-E_X.js → page-tabs-BkH5AVV2.js} +1 -1
  58. package/dist/gateway/static/root/assets/{preview-open-alternatives-DKwEce-9.js → preview-open-alternatives-CQai8f9D.js} +1 -1
  59. package/dist/gateway/static/root/assets/{product-open-page-B90ZskkN.js → product-open-page-B2kSdB2b.js} +1 -1
  60. package/dist/gateway/static/root/assets/project-detail-page-CfhPJLkH.js +1 -0
  61. package/dist/gateway/static/root/assets/projects-page-BfMoKjdm.js +1 -0
  62. package/dist/gateway/static/root/assets/remote-access-hub-CrDtcsZ9.js +1 -0
  63. package/dist/gateway/static/root/assets/{save-bar-controls-BDYt53uQ.js → save-bar-controls-NGYnO7n7.js} +1 -1
  64. package/dist/gateway/static/root/assets/schedule-field-nLOphnv3.js +1 -0
  65. package/dist/gateway/static/root/assets/{schema-form-D7oCARF7.js → schema-form-D0e90ndE.js} +1 -1
  66. package/dist/gateway/static/root/assets/sessions-page-D3DbF3dV.js +1 -0
  67. package/dist/gateway/static/root/assets/settings-advanced-gate-BZp0O2dH.js +1 -0
  68. package/dist/gateway/static/root/assets/{settings-form-section-CARTHCxH.js → settings-form-section-X2Sl-EAk.js} +1 -1
  69. package/dist/gateway/static/root/assets/{settings-loading-skeleton-DEwYqESe.js → settings-loading-skeleton-DOnUabm7.js} +1 -1
  70. package/dist/gateway/static/root/assets/{settings-page-B6vVdHeQ.js → settings-page-C4UUNi1n.js} +1 -1
  71. package/dist/gateway/static/root/assets/{settings-page-layout-D3srt5Bi.js → settings-page-layout-C1yYqbT6.js} +1 -1
  72. package/dist/gateway/static/root/assets/setup-status-panel-84iao4DZ.js +1 -0
  73. package/dist/gateway/static/root/assets/{share-preview-page-Ck9SxiXw.js → share-preview-page-Cfy_pH7V.js} +1 -1
  74. package/dist/gateway/static/root/assets/shares-settings-DtcwQvRG.js +1 -0
  75. package/dist/gateway/static/root/assets/skill-reload-api-L7j5Gc8Z.js +1 -0
  76. package/dist/gateway/static/root/assets/skills-page-1Ps8PjsP.js +2 -0
  77. package/dist/gateway/static/root/assets/{system-settings-panel-DLBUQSk2.js → system-settings-panel-Da81RJ6G.js} +1 -1
  78. package/dist/gateway/static/root/assets/{theme-store-C1oaqeD2.js → theme-store-DflSp9o4.js} +1 -1
  79. package/dist/gateway/static/root/assets/time-picker-BIkOW-2L.js +1 -0
  80. package/dist/gateway/static/root/assets/{typed-models-lib-Divbg_C4.js → typed-models-lib--HptwFcD.js} +1 -1
  81. package/dist/gateway/static/root/assets/{use-channel-catalog-CP9a_rAf.js → use-channel-catalog-CMHY4ZfW.js} +1 -1
  82. package/dist/gateway/static/root/assets/user-context-page-BYAAs2iW.js +1 -0
  83. package/dist/gateway/static/root/assets/voice-api-key-field-nvIZerol.js +1 -0
  84. package/dist/gateway/static/root/assets/work-discovery-page-J35JkJ7_.js +1 -0
  85. package/dist/gateway/static/root/assets/work-item-detail-page-C4wYDYqV.js +1 -0
  86. package/dist/gateway/static/root/assets/work-page-DMvitV6c.js +1 -0
  87. package/dist/gateway/static/root/assets/{workflow-run-setup-panel-DbDPYQwB.js → workflow-run-setup-panel-D96MHABy.js} +2 -2
  88. package/dist/gateway/static/root/assets/workflows-page-JMN0nMbM.js +11 -0
  89. package/dist/gateway/static/root/index.html +7 -7
  90. package/dist/package.js +1 -1
  91. package/dist/src/agent/client-error-format.d.ts +1 -1
  92. package/dist/src/agent/client-error-format.js +6 -2
  93. package/dist/src/agent/embedded/run-for-session.js +38 -31
  94. package/dist/src/agent/embedded/session-runner.d.ts +1 -0
  95. package/dist/src/agent/embedded/session-runner.js +12 -4
  96. package/dist/src/agent/failover-error.d.ts +1 -1
  97. package/dist/src/agent/image/generation/openai-compatible-image-provider.d.ts +2 -6
  98. package/dist/src/agent/image/generation/openai-compatible-image-provider.js +1 -3
  99. package/dist/src/agent/image/generation/provider-registry.d.ts +5 -46
  100. package/dist/src/agent/image/generation/provider-registry.js +24 -73
  101. package/dist/{extensions/dashscope/src/image-generation-provider.d.ts → src/agent/image/generation/providers/dashscope.d.ts} +3 -6
  102. package/dist/{extensions/dashscope/src/image-generation-provider.js → src/agent/image/generation/providers/dashscope.js} +36 -59
  103. package/dist/{extensions/fal/src/image-generation-provider.d.ts → src/agent/image/generation/providers/fal.d.ts} +1 -1
  104. package/dist/{extensions/fal/src/image-generation-provider.js → src/agent/image/generation/providers/fal.js} +19 -29
  105. package/dist/{extensions/google/src/image-generation-provider.d.ts → src/agent/image/generation/providers/google.d.ts} +2 -2
  106. package/dist/{extensions/google/src/image-generation-provider.js → src/agent/image/generation/providers/google.js} +23 -30
  107. package/dist/{extensions/minimax/src/image-generation-provider.d.ts → src/agent/image/generation/providers/minimax.d.ts} +2 -5
  108. package/dist/{extensions/minimax/src/image-generation-provider.js → src/agent/image/generation/providers/minimax.js} +35 -51
  109. package/dist/{extensions/openai/src/image-generation-provider.d.ts → src/agent/image/generation/providers/openai.d.ts} +2 -2
  110. package/dist/{extensions/openai/src/image-generation-provider.js → src/agent/image/generation/providers/openai.js} +13 -38
  111. package/dist/src/agent/image/generation/runtime-types.d.ts +1 -0
  112. package/dist/src/agent/image/generation/runtime.d.ts +1 -3
  113. package/dist/src/agent/image/generation/runtime.js +6 -6
  114. package/dist/src/agent/image/generation/types.d.ts +23 -3
  115. package/dist/src/agent/image/index.d.ts +1 -1
  116. package/dist/src/agent/image/index.js +2 -2
  117. package/dist/src/agent/media-generation/runtime-shared.d.ts +2 -0
  118. package/dist/src/agent/media-generation/runtime-shared.js +1 -0
  119. package/dist/src/agent/tools/factory.js +4 -1
  120. package/dist/src/agent/tools/image-generate-tool.d.ts +2 -0
  121. package/dist/src/agent/tools/image-generate-tool.js +14 -7
  122. package/dist/src/auth/sync-provider-auth.d.ts +3 -0
  123. package/dist/src/auth/sync-provider-auth.js +12 -1
  124. package/dist/src/cli/commands/models.js +2 -5
  125. package/dist/src/cli/commands/onboard/model.js +3 -2
  126. package/dist/src/cli/commands/setup-shared/types.d.ts +1 -1
  127. package/dist/src/config/index.js +2 -2
  128. package/dist/src/config/models-json.d.ts +6 -0
  129. package/dist/src/config/models-json.js +2 -6
  130. package/dist/src/config/schema.d.ts +26 -15
  131. package/dist/src/config/schema.js +23 -12
  132. package/dist/src/gateway/hono/app.js +12 -6
  133. package/dist/src/gateway/hono/lib/safe-providers-config.d.ts +0 -3
  134. package/dist/src/gateway/hono/lib/safe-providers-config.js +1 -3
  135. package/dist/src/gateway/hono/middleware/strict-rate-limit.d.ts +4 -0
  136. package/dist/src/gateway/hono/middleware/strict-rate-limit.js +8 -1
  137. package/dist/src/gateway/hono/routes/config-patch/misc.js +2 -11
  138. package/dist/src/gateway/hono/routes/deps.d.ts +1 -0
  139. package/dist/src/gateway/hono/routes/lazy-bundles.js +9 -2
  140. package/dist/src/gateway/hono/routes/models.js +151 -129
  141. package/dist/src/gateway/image-generation-setup.d.ts +40 -0
  142. package/dist/src/gateway/image-generation-setup.js +130 -0
  143. package/dist/src/gateway/rate-limit/buckets.d.ts +3 -0
  144. package/dist/src/gateway/rate-limit/buckets.js +12 -0
  145. package/dist/src/gateway/service.d.ts +3 -0
  146. package/dist/src/gateway/service.js +10 -0
  147. package/dist/src/media-shared/http/private-network.d.ts +1 -1
  148. package/dist/src/media-shared/http/private-network.js +1 -1
  149. package/dist/src/providers/auth-runtime/resolve-api-key.d.ts +2 -4
  150. package/dist/src/providers/auth-runtime/resolve-api-key.js +2 -4
  151. package/dist/src/providers/auth-runtime/resolve-auth.d.ts +3 -4
  152. package/dist/src/providers/auth-runtime/resolve-auth.js +18 -18
  153. package/dist/src/providers/domestic-presets.d.ts +22 -0
  154. package/dist/src/providers/domestic-presets.js +25 -0
  155. package/dist/src/providers/model-catalog-store.d.ts +71 -0
  156. package/dist/src/providers/model-catalog-store.js +102 -0
  157. package/dist/src/providers/model-catalog-sync-service.d.ts +41 -0
  158. package/dist/src/providers/model-catalog-sync-service.js +142 -0
  159. package/dist/src/providers/model-reference-auditor.d.ts +14 -0
  160. package/dist/src/providers/model-reference-auditor.js +71 -0
  161. package/dist/src/providers/model-registry.d.ts +4 -1
  162. package/dist/src/providers/model-registry.js +35 -2
  163. package/dist/src/providers/presentation.js +2 -0
  164. package/dist/src/providers/xopc-cloud-connection.d.ts +51 -0
  165. package/dist/src/providers/xopc-cloud-connection.js +196 -0
  166. package/dist/src/session/index.d.ts +1 -1
  167. package/dist/src/session/index.js +2 -2
  168. package/dist/src/session/session-title.d.ts +2 -0
  169. package/dist/src/session/session-title.js +24 -3
  170. package/package.json +5 -7
  171. package/dist/extensions/dashscope/src/index.d.ts +0 -4
  172. package/dist/extensions/dashscope/src/index.js +0 -2
  173. package/dist/extensions/dashscope/xopc.extension.json +0 -15
  174. package/dist/extensions/fal/src/index.d.ts +0 -4
  175. package/dist/extensions/fal/src/index.js +0 -2
  176. package/dist/extensions/fal/xopc.extension.json +0 -14
  177. package/dist/extensions/google/src/index.d.ts +0 -4
  178. package/dist/extensions/google/src/index.js +0 -2
  179. package/dist/extensions/google/xopc.extension.json +0 -14
  180. package/dist/extensions/minimax/src/index.d.ts +0 -4
  181. package/dist/extensions/minimax/src/index.js +0 -2
  182. package/dist/extensions/minimax/xopc.extension.json +0 -15
  183. package/dist/extensions/openai/src/index.d.ts +0 -4
  184. package/dist/extensions/openai/src/index.js +0 -2
  185. package/dist/extensions/openai/xopc.extension.json +0 -14
  186. package/dist/gateway/static/root/assets/agents-DfVkZlHc.js +0 -2
  187. package/dist/gateway/static/root/assets/apps-page-BMtAa4Ra.js +0 -1
  188. package/dist/gateway/static/root/assets/automations-page-BiSAMYTr.js +0 -6
  189. package/dist/gateway/static/root/assets/browser-settings-page-DHmaEJS2.js +0 -8
  190. package/dist/gateway/static/root/assets/capabilities-settings-panel-B5wSgf4f.js +0 -2
  191. package/dist/gateway/static/root/assets/capability-presets-settings-panel-DyvFZwBj.js +0 -2
  192. package/dist/gateway/static/root/assets/channels-settings-BBKEqDZn.js +0 -1
  193. package/dist/gateway/static/root/assets/channels-status-swr-Drk110ve.js +0 -1
  194. package/dist/gateway/static/root/assets/connectors-page-HpgaUDQ1.js +0 -2
  195. package/dist/gateway/static/root/assets/desktop-pet-Bpf6oegd.js +0 -1
  196. package/dist/gateway/static/root/assets/extension-settings-page-CLSc6682.js +0 -1
  197. package/dist/gateway/static/root/assets/goal-detail-page-Cw1hpJkZ.js +0 -4
  198. package/dist/gateway/static/root/assets/goals-page-BDGkTVma.js +0 -2
  199. package/dist/gateway/static/root/assets/index-hmrG55qg.css +0 -1
  200. package/dist/gateway/static/root/assets/local-app-workbench-page-Bdef1b7F.js +0 -2
  201. package/dist/gateway/static/root/assets/logs-page-CwLPgrWh.js +0 -7
  202. package/dist/gateway/static/root/assets/messages-BwQ3WssU.js +0 -5
  203. package/dist/gateway/static/root/assets/notes-workbench-Cf06q19x.js +0 -4
  204. package/dist/gateway/static/root/assets/project-detail-page-SHTurM4t.js +0 -1
  205. package/dist/gateway/static/root/assets/projects-page-BcC2qUAw.js +0 -1
  206. package/dist/gateway/static/root/assets/remote-access-hub-6vGefBHv.js +0 -1
  207. package/dist/gateway/static/root/assets/schedule-field-Bcdni4Pj.js +0 -1
  208. package/dist/gateway/static/root/assets/sessions-page-C5014a53.js +0 -1
  209. package/dist/gateway/static/root/assets/settings-advanced-gate-CDY3ZI1K.js +0 -1
  210. package/dist/gateway/static/root/assets/settings-collapsible-section-6eNF8Jey.js +0 -1
  211. package/dist/gateway/static/root/assets/setup-status-panel-z-rF0Hdg.js +0 -1
  212. package/dist/gateway/static/root/assets/shares-settings-CHZFXE_d.js +0 -1
  213. package/dist/gateway/static/root/assets/skill-reload-api-B7p2QNXt.js +0 -1
  214. package/dist/gateway/static/root/assets/skills-page-ncw3tX9P.js +0 -2
  215. package/dist/gateway/static/root/assets/user-context-page-iYfeSLKI.js +0 -1
  216. package/dist/gateway/static/root/assets/voice-api-key-field-CrwkicvT.js +0 -1
  217. package/dist/gateway/static/root/assets/work-discovery-page-BQWxyPg8.js +0 -1
  218. package/dist/gateway/static/root/assets/work-item-detail-page-50ZzGay5.js +0 -1
  219. package/dist/gateway/static/root/assets/work-page-DPqEahx7.js +0 -1
  220. package/dist/gateway/static/root/assets/workflows-page-C3eIC5HZ.js +0 -11
  221. package/dist/src/agent/image/generation/bundled-registry.d.ts +0 -18
  222. package/dist/src/agent/image/generation/bundled-registry.js +0 -35
  223. package/dist/src/agent/image/generation/bundled.d.ts +0 -10
  224. package/dist/src/agent/image/generation/bundled.js +0 -15
  225. package/dist/src/agent/image/generation/image-provider-ui.d.ts +0 -20
  226. package/dist/src/agent/image/generation/image-provider-ui.js +0 -1
  227. package/dist/src/gateway/image-capabilities.d.ts +0 -28
  228. package/dist/src/gateway/image-capabilities.js +0 -78
  229. package/dist/src/generated/bundled-image-generation-providers.d.ts +0 -14
  230. package/dist/src/generated/bundled-image-generation-providers.js +0 -17
@@ -0,0 +1,2 @@
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{d as i,l as a,r as o,t as s,u as c}from"./chunk-KS7C4IRE-uQ0fehio.js";import{t as l}from"./cn-JdwAhgNB.js";import{t as u}from"./messages-BzI9Wx30.js";import{l as d,n as f,o as p,r as m,s as h}from"./locale-store-Ys6RP7Be.js";import{i as g}from"./vendor-swr-BIWyz7Rc.js";import{Ac as _,An as v,Bn as y,Bo as b,Bt as x,Cn as S,Dn as C,Ds as w,El as T,En as E,Es as D,Eu as O,Fn as k,Fs as A,Gc as j,Gn as M,Hn as N,Ho as P,Is as F,Kn as I,Ln as L,Mn as R,Mr as z,Mt as B,Nn as ee,Oc as V,On as te,Os as H,Pc as ne,Pn as re,Qa as U,Qc as W,Rn as ie,Ro as G,Sn as ae,Ss as K,Tn as oe,Ts as q,Un as J,Uo as se,Us as ce,Vl as le,Vn as ue,Vo as de,Vt as fe,Wn as pe,Wo as me,Ws as he,Xa as ge,Xc as _e,Xn as ve,Xo as ye,Yo as be,Za as xe,_l as Se,_s as Ce,bn as we,cs as Te,dc as Ee,es as De,fu as Oe,gs as ke,jn as Ae,js as je,jt as Me,kc as Ne,kn as Pe,ls as Fe,mc as Ie,oc as Le,pl as Re,qo as ze,rs as Y,tc as Be,ts as X,uu as Ve,wn as He,xc as Ue,xn as We,xs as Ge,yn as Ke,ys as qe,zn as Je,zo as Ye,zr as Xe,zt as Ze}from"./index-HZdBKfk_.js";import{n as Qe,r as $e}from"./settings-page-layout-C1yYqbT6.js";import{t as et}from"./settings-loading-skeleton-DOnUabm7.js";import{c as tt,d as nt,i as rt,l as it,n as at,o as ot,r as st,s as ct,t as lt,u as ut}from"./voice-api-key-field-nvIZerol.js";import{t as dt}from"./settings-advanced-gate-BZp0O2dH.js";import{n as ft,t as pt}from"./settings-form-section-X2Sl-EAk.js";import{t as mt}from"./page-tabs-BkH5AVV2.js";import{n as ht,r as gt,t as _t}from"./save-bar-controls-NGYnO7n7.js";var Z=n(),Q=e(t(),1),$=r(),vt={en:{title:`Image generation`,intro:`Choose an agent and a built-in provider. One action stores the credential and enables the model.`,agent:`Agent`,provider:`Provider`,model:`Model`,apiKey:`API key`,apiKeyHint:`Stored in the local credential store, never in xopc.json.`,existingKey:`A credential or environment variable is already available. Leave this blank to reuse it.`,region:`Service region`,cn:`China`,intl:`International`,advanced:`Custom endpoint`,baseUrl:`Base URL (optional)`,enable:`Enable image generation`,enabling:`Verifying and enabling…`,enabled:`Image generation is ready.`,enabledWithoutVerify:`Image generation is enabled. This provider does not expose a lightweight credential check.`,current:`Current`,configured:`Credential ready`,needsKey:`API key required`,connect:`Connect to a gateway to continue.`,loadError:`Unable to load image generation settings.`,selectAgent:`Select an agent`,selectModel:`Select a model`,show:`Show key`,hide:`Hide key`,copy:`Copy key`,copied:`Copied`},zh:{title:`图片生成`,intro:`选择 Agent 和内置 Provider,一次操作完成凭据保存与模型启用。`,agent:`Agent`,provider:`Provider`,model:`模型`,apiKey:`API Key`,apiKeyHint:`密钥只保存在本机凭据存储中,不会写入 xopc.json。`,existingKey:`已有凭据或环境变量;留空即可继续使用。`,region:`服务地域`,cn:`中国站`,intl:`国际站`,advanced:`自定义服务地址`,baseUrl:`Base URL(可选)`,enable:`启用图片生成`,enabling:`正在验证并启用…`,enabled:`图片生成已可用。`,enabledWithoutVerify:`图片生成已启用;该 Provider 暂无轻量凭据验证接口。`,current:`当前使用`,configured:`凭据已就绪`,needsKey:`需要 API Key`,connect:`请先连接网关。`,loadError:`无法加载图片生成设置。`,selectAgent:`选择 Agent`,selectModel:`选择模型`,show:`显示密钥`,hide:`隐藏密钥`,copy:`复制密钥`,copied:`已复制`}};async function yt(){let e=await h(m(`/api/image-generation/catalog`));if(!Array.isArray(e.payload?.providers))throw Error(`Invalid image provider catalog`);return e.payload.providers}async function bt(e){let t=await h(m(`/api/agents/${encodeURIComponent(e)}/image-generation`));if(!t.payload)throw Error(`Invalid agent image generation response`);return t.payload}function xt(e){let t=e?.indexOf(`/`)??-1;return t>0?e.slice(0,t):void 0}function St(e){let t=e?.indexOf(`/`)??-1;return t>0?e.slice(t+1):void 0}function Ct(){let e=(0,Z.c)(2),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(U,{className:`h-24 rounded-xl`}),e[0]=t):t=e[0];let n;return e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsxs)(`div`,{className:`grid gap-4`,"aria-hidden":`true`,children:[t,(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 xl:grid-cols-3`,children:Array.from({length:5}).map(wt)}),(0,$.jsx)(U,{className:`h-64 rounded-xl`})]}),e[1]=n):n=e[1],n}function wt(e,t){return(0,$.jsx)(U,{className:`h-24 rounded-xl`},t)}function Tt(){let e=f(e=>e.language),t=vt[e],n=u(e),r=!!d(e=>e.token),[i,a]=(0,Q.useState)(``),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(``),[p,_]=(0,Q.useState)(``),[v,y]=(0,Q.useState)(e===`zh`?`cn`:`intl`),[b,x]=(0,Q.useState)(``),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(),[E,D]=(0,Q.useState)(),{data:O,isLoading:k,error:A}=g(r?`image-generation-agents`:null,Xe,{revalidateOnFocus:!1}),{data:j,isLoading:M,error:N,mutate:P}=g(r?m(`/api/image-generation/catalog`):null,yt,{revalidateOnFocus:!1});(0,Q.useEffect)(()=>{!O||i||a(O.defaultId||O.agents[0]?.id||``)},[i,O]);let{data:F,isLoading:I,error:L,mutate:R}=g(r&&i?[`agent-image-generation`,i]:null,()=>bt(i),{revalidateOnFocus:!1});(0,Q.useEffect)(()=>{if(!j||!F)return;let e=xt(F.model?.primary),t=j.find(t=>t.id===e)??j.find(e=>e.configured)??j[0];t&&(s(t.id),l(t.id===e&&St(F.model?.primary)||t.defaultModel),_(``))},[F,j]),(0,Q.useEffect)(()=>{T(void 0),D(void 0)},[i]);let B=j?.find(e=>e.id===o),ee=(0,Q.useMemo)(()=>(O?.agents??[]).map(e=>({value:e.id,label:z(e,n.agentsSettings)})),[O?.agents,n.agentsSettings]),V=(0,Q.useMemo)(()=>(B?.models??[]).map(e=>({value:e,label:e})),[B?.models]),te=F?.model?.primary,ne=!!(i&&B&&c&&(B.configured||p.trim()));if(!r)return(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.connect});if(k||M||I)return(0,$.jsx)(Ct,{});if(A||N||L||!j||!O)return(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:t.loadError});let re=e=>{s(e.id),l(e.defaultModel),_(``),x(``),T(void 0),D(void 0)},U=async()=>{if(!(!B||!ne)){C(!0),T(void 0),D(void 0);try{let e=await h(m(`/api/agents/${encodeURIComponent(i)}/image-generation/setup`),{method:`POST`,body:JSON.stringify({providerId:B.id,modelId:c,...p.trim()?{apiKey:p.trim()}:{},...B.requiresRegion?{region:v}:{},...b.trim()?{baseUrl:b.trim()}:{}})});if(!e.payload)throw Error(`Invalid setup response`);await Promise.all([R(e.payload.agent,{revalidate:!1}),P(e.payload.providers,{revalidate:!1})]),_(``),D(e.payload.verification.supported?t.enabled:t.enabledWithoutVerify)}catch(e){T(e instanceof Error?e.message:String(e))}finally{C(!1)}}};return(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`section`,{className:`rounded-xl border border-edge bg-surface-base p-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,$.jsx)(`div`,{className:`rounded-lg bg-accent/10 p-2 text-accent`,children:(0,$.jsx)(Se,{className:`size-5`})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:t.title}),(0,$.jsx)(`p`,{className:`mt-1 text-sm leading-relaxed text-fg-muted`,children:t.intro})]})]}),(0,$.jsxs)(`label`,{className:`mt-4 block text-xs font-medium text-fg-muted`,children:[t.agent,(0,$.jsx)(De,{value:i,options:ee,placeholder:t.selectAgent,allowEmpty:!1,onChange:a,triggerClassName:`mt-1.5 max-w-md`})]})]}),(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h3`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-fg-subtle`,children:t.provider}),(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 xl:grid-cols-3`,children:j.map(e=>{let n=e.id===o,r=e.id===xt(te);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>re(e),className:`rounded-xl border p-4 text-left transition-colors ${n?`border-accent bg-accent/5 ring-1 ring-accent/20`:`border-edge bg-surface-base hover:border-edge-strong`}`,children:[(0,$.jsxs)(`span`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`font-medium text-fg`,children:e.label}),r?(0,$.jsx)(`span`,{className:`rounded-full bg-accent/10 px-2 py-0.5 text-[11px] font-medium text-accent`,children:t.current}):null]}),(0,$.jsxs)(`span`,{className:`mt-2 flex items-center gap-1.5 text-xs ${e.configured?`text-emerald-600 dark:text-emerald-400`:`text-fg-muted`}`,children:[e.configured?(0,$.jsx)(Ve,{className:`size-3.5`}):(0,$.jsx)(Re,{className:`size-3.5`}),e.configured?t.configured:t.needsKey]})]},e.id)})})]}),B?(0,$.jsxs)(`section`,{className:`rounded-xl border border-edge bg-surface-base p-4`,children:[(0,$.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:`block text-xs font-medium text-fg-muted`,children:[t.model,(0,$.jsx)(De,{value:c,options:V,placeholder:t.selectModel,allowEmpty:!1,onChange:l,triggerClassName:`mt-1.5`})]}),B.requiresRegion?(0,$.jsxs)(`label`,{className:`block text-xs font-medium text-fg-muted`,children:[t.region,(0,$.jsx)(De,{value:v,options:[{value:`cn`,label:t.cn},{value:`intl`,label:t.intl}],placeholder:t.region,allowEmpty:!1,onChange:e=>y(e),triggerClassName:`mt-1.5`})]}):null]}),(0,$.jsxs)(`label`,{className:`mt-4 block text-xs font-medium text-fg-muted`,children:[t.apiKey,(0,$.jsx)(qe,{value:p,onChange:_,placeholder:B.configured?t.existingKey:t.needsKey,labels:{show:t.show,hide:t.hide,copy:t.copy,copied:t.copied},className:`mt-1.5`,autoComplete:`new-password`}),(0,$.jsx)(`span`,{className:`mt-1.5 block font-normal leading-relaxed text-fg-subtle`,children:B.configured?t.existingKey:t.apiKeyHint})]}),(0,$.jsxs)(`details`,{className:`mt-4 rounded-lg border border-edge bg-surface-subtle px-3 py-2.5`,children:[(0,$.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 text-sm font-medium text-fg-muted`,children:[(0,$.jsx)(Le,{className:`size-4`}),t.advanced]}),(0,$.jsxs)(`label`,{className:`mt-3 block text-xs font-medium text-fg-muted`,children:[t.baseUrl,(0,$.jsx)(`input`,{value:b,onChange:e=>x(e.target.value),placeholder:`https://…`,className:`mt-1.5 h-10 w-full rounded-lg border border-edge bg-surface-panel px-3 text-sm text-fg outline-none focus:border-accent focus:ring-2 focus:ring-accent/20`})]})]}),w?(0,$.jsx)(`p`,{className:`mt-4 rounded-lg bg-red-500/10 px-3 py-2 text-sm text-red-600 dark:text-red-400`,children:w}):null,E?(0,$.jsx)(`p`,{className:`mt-4 rounded-lg bg-emerald-500/10 px-3 py-2 text-sm text-emerald-700 dark:text-emerald-400`,children:E}):null,(0,$.jsx)(`div`,{className:`mt-4 flex justify-end`,children:(0,$.jsxs)(H,{variant:`primary`,disabled:!ne||S,onClick:()=>void U(),children:[S?(0,$.jsx)(W,{className:`size-4 animate-spin`}):(0,$.jsx)(Ve,{className:`size-4`}),S?t.enabling:t.enable]})})]}):null]})}var Et=q;function Dt(e){switch(e){case`alibaba`:return`(DASHSCOPE_API_KEY)`;case`openai`:return`(OPENAI_API_KEY)`;case`groq`:return`(GROQ_API_KEY)`;default:return``}}function Ot(e){switch(e){case`alibaba`:return`(DASHSCOPE_API_KEY)`;case`openai`:return`(OPENAI_API_KEY)`;case`minimax`:return`(MINIMAX_API_KEY)`;default:return``}}function kt(){return l(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,w,`dark:border-edge`)}function At(){return l(D,q)}function jt(e){return!e||e<=0?``:e<1024*1024?`${Math.round(e/1024)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function Mt(e,t){let n=window.atob(e),r=new Uint8Array(n.length);for(let e=0;e<n.length;e++)r[e]=n.charCodeAt(e);return URL.createObjectURL(new Blob([r],{type:t}))}var Nt=[{id:`paraformer-v2`,name:`Paraformer v2`},{id:`paraformer-v1`,name:`Paraformer v1`}],Pt=[{id:`whisper-1`,name:`Whisper-1`}],Ft=[{id:`whisper-large-v3-turbo`,name:`Whisper Large v3 Turbo`},{id:`whisper-large-v3`,name:`Whisper Large v3`}],It=[{id:`tts-1`,name:`TTS-1`},{id:`tts-1-hd`,name:`TTS-1 HD`}],Lt=[{id:`alloy`,name:`Alloy`},{id:`echo`,name:`Echo`}],Rt=[{id:`qwen-tts`,name:`Qwen TTS`},{id:`qwen3-tts-flash`,name:`Qwen3 TTS Flash`}],zt=[{id:`Cherry`,name:`Cherry`},{id:`longxiaochun`,name:`Long Xiao Chun`}],Bt=[{id:`en-US-MichelleNeural`,name:`Michelle (US English)`},{id:`zh-CN-XiaoxiaoNeural`,name:`Xiaoxiao (Chinese)`}],Vt=[{id:`speech-2.8-hd`,name:`Speech 2.8 HD (Recommended)`},{id:`speech-2.8-turbo`,name:`Speech 2.8 Turbo (Fast)`}],Ht=[{id:`male-qn-qingse`,name:`Male Qingse (青涩男声)`},{id:`female-shaonv`,name:`Female Shaonv (少女音)`}],Ut=[{id:`piper`,command:`piper --model /path/to/voice.onnx --output_file "{{OutputPath}}"`,outputFormat:`wav`},{id:`sherpa-onnx`,command:`sherpa-onnx-offline-tts --text "{{Text}}" --output-filename "{{OutputPath}}"`,outputFormat:`wav`},{id:`mlx-audio`,command:`python -m mlx_audio.tts.generate --text "{{Text}}" --file_prefix "{{OutputBase}}"`,outputFormat:`wav`}];function Wt(e,t){switch(e){case`xopc-local`:return t.stt.localProvider;case`openai`:return t.stt.openai;case`alibaba`:return t.stt.alibaba;case`groq`:return`Groq`;default:return e}}function Gt(e,t){switch(e){case`openai`:return t.tts.providerOpenai;case`alibaba`:return t.stt.alibaba;case`edge`:return t.tts.providerEdge;case`tts-local-cli`:return t.tts.providerLocalCli;case`minimax`:return`MiniMax`;default:return e}}function Kt(e,t){switch(e){case`off`:return t.tts.triggerOff;case`always`:return t.tts.triggerAlways;case`inbound`:return t.tts.triggerInbound;case`tagged`:return t.tts.triggerTagged}}function qt(e,t){switch(e){case`edge`:return t.tts.providerHints.edge;case`openai`:return t.tts.providerHints.openai;case`alibaba`:return t.tts.providerHints.alibaba;case`minimax`:return t.tts.providerHints.minimax;case`tts-local-cli`:return t.tts.providerHints.localCli;default:return t.tts.providerHints.generic}}function Jt(e){return{maskedHelp:e.apiKeyMaskedHelp,copy:e.apiKeyCopy,copied:e.apiKeyCopied,show:e.apiKeyShow,hide:e.apiKeyHide,notInConfigFile:e.apiKeyNotInConfigFile,loadFailed:e.apiKeyRevealFailed}}function Yt(e,t){let n=e[t.key];return typeof n==`string`||typeof n==`number`||typeof n==`boolean`?n:t.defaultValue===void 0?t.type===`boolean`?!1:``:t.defaultValue}function Xt(e,t){if(e.type===`boolean`)return!!t;if(e.type!==`number`)return t;let n=String(t).trim();if(!n)return;let r=Number(n);return Number.isFinite(r)?r:void 0}function Zt(e,t){switch(t.type){case`reset`:return{form:null,baseline:null};case`sync`:{let e=structuredClone(t.value);return{form:e,baseline:structuredClone(e)}}case`update`:return{...e,form:t.updater(e.form)};case`discard`:return e.baseline?{form:structuredClone(e.baseline),baseline:e.baseline}:e;case`saved`:{let e=structuredClone(t.value);return{form:e,baseline:structuredClone(e)}}}}function Qt(){let e=f(e=>e.language),t=u(e).voiceSettings,n=!!d(e=>e.token),[r,i]=(0,Q.useReducer)(Zt,{form:null,baseline:null}),a=r.form,o=r.baseline,[s,c]=(0,Q.useState)(null),[l,p]=(0,Q.useState)(!1),[h,_]=(0,Q.useState)(null),v=(0,Q.useRef)(!1),y=(0,Q.useRef)({parsed:null,models:void 0}),{data:b,error:x,isLoading:S,mutate:C}=xe(n),{data:w,error:T,isLoading:E,mutate:D}=g(n?m(`/api/voice/models`):null,st,{revalidateOnFocus:!1}),{data:O,error:k,isLoading:A}=g(n?m(`/api/voice/providers`):null,rt,{revalidateOnFocus:!1}),{data:j,error:M,isLoading:N}=g(n?m(`/api/voice/stt-providers`):null,ot,{revalidateOnFocus:!1}),P=(0,Q.useMemo)(()=>O?.providers??[],[O]),F=(0,Q.useMemo)(()=>j?.providers??[],[j]),I=(0,Q.useMemo)(()=>b?.payload?.config===void 0?null:tt(b.payload.config),[b]),L=(0,Q.useMemo)(()=>!a||!o?!1:JSON.stringify(a)!==JSON.stringify(o),[a,o]);n?I!==null&&w!==void 0&&!v.current&&(y.current.parsed!==I||y.current.models!==w)&&(y.current={parsed:I,models:w},i({type:`sync`,value:I}),c(w)):(y.current.parsed!==null||y.current.models!==void 0)&&(y.current={parsed:null,models:void 0},i({type:`reset`}),c(null),v.current=!1);let R=!!(n&&(I===null||w===void 0||O===void 0||j===void 0)&&(S||E||A||N)),z=x instanceof Error?x.message:x?String(x):T instanceof Error?T.message:T?String(T):k instanceof Error?k.message:k?String(k):M instanceof Error?M.message:M?String(M):null,B=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>t?{...t,stt:{...t.stt,...e}}:null})},[]),ee=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>t?{...t,stt:{...t.stt,alibaba:{...t.stt.alibaba,...e}}}:null})},[]),V=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>t?{...t,stt:{...t.stt,openai:{...t.stt.openai,...e}}}:null})},[]),te=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>{if(!t)return null;let n=t.stt.fallback??{enabled:!1,order:[`xopc-local`]};return{...t,stt:{...t.stt,fallback:{...n,...e}}}}})},[]),ne=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>t?{...t,voice:{...t.voice,input:{...t.voice.input,refinement:{...t.voice.input.refinement,...e}}}}:null})},[]),re=(0,Q.useCallback)(t=>{v.current=!0,i({type:`update`,updater:n=>n?{...n,voice:{...n.voice,languageMode:t,...t===`auto`?{language:e}:{}}}:null})},[e]),U=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>t?{...t,tts:{...t.tts,...e}}:null})},[]),W=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>t?{...t,tts:{...t.tts,alibaba:{...t.tts.alibaba,...e}}}:null})},[]),ie=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>t?{...t,tts:{...t.tts,openai:{...t.tts.openai,...e}}}:null})},[]),G=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>t?{...t,voice:e.voice!==void 0||e.lang!==void 0?{...t.voice,languageMode:`manual`}:t.voice,tts:{...t.tts,edge:{...t.tts.edge,...e}}}:null})},[]),ae=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>t?{...t,tts:{...t.tts,minimax:{...t.tts.minimax,...e}}}:null})},[]),K=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>t?{...t,tts:{...t.tts,"tts-local-cli":{...t.tts[`tts-local-cli`],...e}}}:null})},[]);if(ht({id:`voice`,dirty:L,saving:l,save:(0,Q.useCallback)(async()=>{if(!(!a||l)){p(!0),_(null);try{await it(a),i({type:`saved`,value:a}),v.current=!1}catch(e){_(e instanceof Error?e.message:t.saveError)}finally{p(!1)}}},[a,l,t.saveError]),discard:(0,Q.useCallback)(()=>{o&&(v.current=!1,i({type:`discard`}),_(null))},[o])}),!n)return(0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.needToken})});if(R)return(0,$.jsx)(et,{rows:4});if(!a||s===null)return(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:h??z??t.loadError}),(0,$.jsx)(H,{type:`button`,variant:`secondary`,onClick:()=>{C(),D()},children:t.retry})]});let oe=a.stt,q=a.tts,J=a.voice.input.refinement,se=Jt(t);return(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[h?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:h}):null,(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsx)($t,{v:t,voice:a.voice,updateLanguageMode:re}),(0,$.jsx)(en,{v:t,stt:oe,tts:q}),(0,$.jsx)(nn,{v:t,apiKeyLabels:se,stt:oe,models:s,sttProviders:F,refinement:J,updateStt:B,updateSttAlibaba:ee,updateSttOpenai:V,updateSttFallback:te,updateRefinement:ne}),(0,$.jsx)(dn,{v:t,apiKeyLabels:se,tts:q,models:s,ttsProviders:P,updateTts:U,updateTtsAlibaba:W,updateTtsOpenai:ie,updateTtsEdge:G,updateTtsMinimax:ae,updateTtsLocalCli:K})]}),(0,$.jsxs)(`div`,{className:`rounded-xl border border-accent/25 bg-accent/5 px-4 py-3 dark:border-accent/30 dark:bg-accent/10`,children:[(0,$.jsxs)(`p`,{className:`text-sm text-fg`,children:[(0,$.jsx)(`strong`,{className:`text-accent`,children:t.notes.title}),` `,t.notes.duration]}),(0,$.jsx)(`p`,{className:`mt-2 text-xs text-fg-muted`,children:t.notes.envVars})]})]})}function $t(e){let t=(0,Z.c)(22),{v:n,voice:r,updateLanguageMode:i}=e,a;t[0]===n.language.title?a=t[1]:(a=(0,$.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:n.language.title}),t[0]=n.language.title,t[1]=a);let o=r.languageMode===`auto`?n.language.autoDescription:n.language.manualDescription,s;t[2]===o?s=t[3]:(s=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:o}),t[2]=o,t[3]=s);let c;t[4]!==a||t[5]!==s?(c=(0,$.jsxs)(`div`,{children:[a,s]}),t[4]=a,t[5]=s,t[6]=c):c=t[6];let l;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(l=At(),t[7]=l):l=t[7];let u;t[8]===i?u=t[9]:(u=e=>i(e.target.value),t[8]=i,t[9]=u);let d;t[10]===n.language.auto?d=t[11]:(d=(0,$.jsx)(Y,{value:`auto`,children:n.language.auto}),t[10]=n.language.auto,t[11]=d);let f;t[12]===n.language.manual?f=t[13]:(f=(0,$.jsx)(Y,{value:`manual`,children:n.language.manual}),t[12]=n.language.manual,t[13]=f);let p;t[14]!==u||t[15]!==d||t[16]!==f||t[17]!==r.languageMode?(p=(0,$.jsxs)(X,{className:l,value:r.languageMode,onChange:u,children:[d,f]}),t[14]=u,t[15]=d,t[16]=f,t[17]=r.languageMode,t[18]=p):p=t[18];let m;return t[19]!==c||t[20]!==p?(m=(0,$.jsx)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-[minmax(0,1fr)_minmax(12rem,18rem)] sm:items-center`,children:[c,p]})}),t[19]=c,t[20]=p,t[21]=m):m=t[21],m}function en(e){let t=(0,Z.c)(39),{v:n,stt:r,tts:i}=e,a=i.provider===`openai`?i.openai?.voice:i.provider===`alibaba`?i.alibaba?.voice:i.provider===`minimax`?i.minimax?.voice:i.provider===`edge`?i.edge?.voice:void 0,o;t[0]===n.overview.title?o=t[1]:(o=(0,$.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:n.overview.title}),t[0]=n.overview.title,t[1]=o);let s;t[2]===n.overview.description?s=t[3]:(s=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:n.overview.description}),t[2]=n.overview.description,t[3]=s);let c;t[4]!==o||t[5]!==s?(c=(0,$.jsxs)(`div`,{className:`mb-4`,children:[o,s]}),t[4]=o,t[5]=s,t[6]=c):c=t[6];let l;t[7]!==r.enabled||t[8]!==r.provider||t[9]!==n?(l=r.enabled?`${n.overview.ready} · ${Wt(r.provider,n)}`:n.overview.off,t[7]=r.enabled,t[8]=r.provider,t[9]=n,t[10]=l):l=t[10];let u;t[11]!==r.enabled||t[12]!==l||t[13]!==n.overview.input?(u=(0,$.jsx)(tn,{label:n.overview.input,value:l,ready:r.enabled}),t[11]=r.enabled,t[12]=l,t[13]=n.overview.input,t[14]=u):u=t[14];let d;t[15]!==i.enabled||t[16]!==i.trigger||t[17]!==n?(d=i.enabled?Kt(i.trigger,n):n.overview.off,t[15]=i.enabled,t[16]=i.trigger,t[17]=n,t[18]=d):d=t[18];let f=i.enabled&&i.trigger!==`off`,p;t[19]!==d||t[20]!==f||t[21]!==n.overview.replies?(p=(0,$.jsx)(tn,{label:n.overview.replies,value:d,ready:f}),t[19]=d,t[20]=f,t[21]=n.overview.replies,t[22]=p):p=t[22];let m;t[23]!==a||t[24]!==i.enabled||t[25]!==i.provider||t[26]!==n?(m=i.enabled?`${Gt(i.provider,n)}${a?` · ${a}`:``}`:n.overview.off,t[23]=a,t[24]=i.enabled,t[25]=i.provider,t[26]=n,t[27]=m):m=t[27];let h;t[28]!==m||t[29]!==i.enabled||t[30]!==n.overview.voice?(h=(0,$.jsx)(tn,{label:n.overview.voice,value:m,ready:i.enabled}),t[28]=m,t[29]=i.enabled,t[30]=n.overview.voice,t[31]=h):h=t[31];let g;t[32]!==h||t[33]!==u||t[34]!==p?(g=(0,$.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-3`,children:[u,p,h]}),t[32]=h,t[33]=u,t[34]=p,t[35]=g):g=t[35];let _;return t[36]!==g||t[37]!==c?(_=(0,$.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[c,g]}),t[36]=g,t[37]=c,t[38]=_):_=t[38],_}function tn(e){let t=(0,Z.c)(10),{label:n,value:r,ready:i}=e,a;t[0]===n?a=t[1]:(a=(0,$.jsx)(`div`,{className:`text-xs text-fg-muted`,children:n}),t[0]=n,t[1]=a);let o=i?`text-fg`:`text-fg-muted`,s;t[2]===o?s=t[3]:(s=l(`mt-1 text-sm font-medium`,o),t[2]=o,t[3]=s);let c;t[4]!==s||t[5]!==r?(c=(0,$.jsx)(`div`,{className:s,children:r}),t[4]=s,t[5]=r,t[6]=c):c=t[6];let u;return t[7]!==a||t[8]!==c?(u=(0,$.jsxs)(`div`,{className:`rounded-xl bg-surface-panel/80 px-3 py-2.5 shadow-surface`,children:[a,c]}),t[7]=a,t[8]=c,t[9]=u):u=t[9],u}function nn(e){let t=(0,Z.c)(49),{v:n,apiKeyLabels:r,stt:i,models:a,sttProviders:o,refinement:s,updateStt:c,updateSttAlibaba:u,updateSttOpenai:d,updateSttFallback:f,updateRefinement:p}=e,m=a?.stt?.alibaba?.length?a.stt.alibaba:Nt,h=a?.stt?.openai?.length?a.stt.openai:Pt,g;if(t[0]!==o){let e=new Set;g=[];for(let t of o)e.has(t.id)||(e.add(t.id),g.push(t));t[0]=o,t[1]=g}else g=t[1];let _=g,v,y,b,x,S;if(t[2]!==m||t[3]!==r||t[4]!==a?.stt||t[5]!==h||t[6]!==_||t[7]!==s||t[8]!==i||t[9]!==p||t[10]!==c||t[11]!==u||t[12]!==f||t[13]!==d||t[14]!==n){let e=_.find(e=>e.id===i.provider),o=i.providers?.[i.provider],g=typeof o?.apiKey==`string`?o.apiKey:``,C=typeof o?.model==`string`?o.model:``,w={...i.provider===`alibaba`?i.alibaba??{}:{},...i.provider===`openai`?i.openai??{}:{},...o??{}},T=(e?.fields??[]).filter(cn),E;t[20]!==i.provider||t[21]!==i.providers||t[22]!==c?(E=e=>{c({providers:{...i.providers??{},[i.provider]:{...i.providers?.[i.provider]??{},...e}}})},t[20]=i.provider,t[21]=i.providers,t[22]=c,t[23]=E):E=t[23];let D=E;x=`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`;let O;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,$.jsx)(j,{className:`size-4 text-accent`,strokeWidth:1.75}),t[24]=O):O=t[24];let k;t[25]===n.stt.title?k=t[26]:(k=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[O,n.stt.title]}),t[25]=n.stt.title,t[26]=k);let A;t[27]===n.stt.description?A=t[28]:(A=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:n.stt.description}),t[27]=n.stt.description,t[28]=A),t[29]!==k||t[30]!==A?(S=(0,$.jsxs)(`div`,{className:`mb-4`,children:[k,A]}),t[29]=k,t[30]=A,t[31]=S):S=t[31],v=`space-y-4`;let M;t[32]===c?M=t[33]:(M=e=>c({enabled:e}),t[32]=c,t[33]=M),t[34]!==i.enabled||t[35]!==M||t[36]!==n.overview.off||t[37]!==n.overview.ready||t[38]!==n.stt.enable||t[39]!==n.stt.enableDesc?(y=(0,$.jsx)(fn,{checked:i.enabled,title:n.stt.enable,description:n.stt.enableDesc,onLabel:n.overview.ready,offLabel:n.overview.off,onChange:M}),t[34]=i.enabled,t[35]=M,t[36]=n.overview.off,t[37]=n.overview.ready,t[38]=n.stt.enable,t[39]=n.stt.enableDesc,t[40]=y):y=t[40],b=i.enabled?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,Et),children:[(0,$.jsx)(hn,{children:n.stt.provider}),(0,$.jsx)(X,{className:At(),value:i.provider,onChange:e=>c({provider:e.target.value}),children:_.map(e=>(0,$.jsxs)(Y,{value:e.id,children:[Wt(e.id,n),e.configured?``:` *`]},e.id))})]}),(0,$.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,Et),children:[(0,$.jsx)(hn,{children:n.stt.model}),i.provider===`xopc-local`?(0,$.jsx)(X,{className:At(),value:C||`sensevoice-small`,onChange:e=>D({model:e.target.value}),children:(a?.stt?.[`xopc-local`]??[]).map(sn)}):i.provider===`alibaba`?(0,$.jsx)(X,{className:At(),value:i.alibaba?.model??``,onChange:e=>u({model:e.target.value}),children:m.map(on)}):i.provider===`openai`?(0,$.jsx)(X,{className:At(),value:i.openai?.model??``,onChange:e=>d({model:e.target.value}),children:h.map(an)}):i.provider===`groq`?(0,$.jsx)(X,{className:At(),value:C||Ft[0].id,onChange:e=>D({model:e.target.value}),children:Ft.map(rn)}):(0,$.jsx)(`input`,{className:kt(),value:C,onChange:e=>D({model:e.target.value}),placeholder:i.provider})]}),e?.diagnostics.requiresApiKey===!1?null:(0,$.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,Et),children:[(0,$.jsx)(hn,{children:n.stt.apiKey}),(0,$.jsx)(lt,{kind:`stt`,providerId:i.provider,fieldId:`voice-stt-${i.provider}-api-key`,value:i.provider===`alibaba`?i.alibaba?.apiKey??``:i.provider===`openai`?i.openai?.apiKey??``:g,onChange:e=>{i.provider===`alibaba`?u({apiKey:e}):i.provider===`openai`?d({apiKey:e}):D({apiKey:e})},labels:r,placeholder:i.provider===`groq`?`gsk_...`:`sk-...`}),(0,$.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.stt.apiKeyDesc,Dt(i.provider)?` ${Dt(i.provider)}`:``]})]})]}),T.length>0?(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:T.map(e=>(0,$.jsx)(pn,{field:e,value:Yt(w,e),onChange:t=>D({[e.key]:t}),className:e.type===`textarea`?`sm:col-span-2`:Et},e.key))}):null,i.provider===`xopc-local`?(0,$.jsx)(un,{v:n}):null,(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.stt.fallback}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.stt.fallbackDesc})]}),(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:i.fallback?.enabled??!1,onChange:e=>f({enabled:e.target.checked})})]}),(0,$.jsxs)(`div`,{className:`grid gap-3 rounded-xl bg-surface-hover/50 p-3 dark:bg-surface-hover/35 sm:grid-cols-[minmax(0,1fr)_minmax(12rem,18rem)] sm:items-center`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.stt.refinement}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.stt.refinementDesc})]}),(0,$.jsxs)(X,{className:At(),value:s.mode,onChange:e=>p({mode:e.target.value}),children:[(0,$.jsx)(Y,{value:`off`,children:n.stt.refinementOff}),(0,$.jsx)(Y,{value:`punctuation`,children:n.stt.refinementPunctuation}),(0,$.jsx)(Y,{value:`light`,children:n.stt.refinementLight})]})]})]}):null,t[2]=m,t[3]=r,t[4]=a?.stt,t[5]=h,t[6]=_,t[7]=s,t[8]=i,t[9]=p,t[10]=c,t[11]=u,t[12]=f,t[13]=d,t[14]=n,t[15]=v,t[16]=y,t[17]=b,t[18]=x,t[19]=S}else v=t[15],y=t[16],b=t[17],x=t[18],S=t[19];let C;t[41]!==v||t[42]!==y||t[43]!==b?(C=(0,$.jsxs)(`div`,{className:v,children:[y,b]}),t[41]=v,t[42]=y,t[43]=b,t[44]=C):C=t[44];let w;return t[45]!==x||t[46]!==S||t[47]!==C?(w=(0,$.jsxs)(`section`,{className:x,children:[S,C]}),t[45]=x,t[46]=S,t[47]=C,t[48]=w):w=t[48],w}function rn(e){return(0,$.jsx)(Y,{value:e.id,children:e.name},e.id)}function an(e){return(0,$.jsx)(Y,{value:e.id,children:e.name},e.id)}function on(e){return(0,$.jsx)(Y,{value:e.id,children:e.name},e.id)}function sn(e){return(0,$.jsx)(Y,{value:e.id,children:e.name},e.id)}function cn(e){return e.key!==`apiKey`&&e.key!==`model`}function ln(e){return`${Math.round(e/1024/1024)} MB`}function un({v:e}){let{data:t,error:n,mutate:r}=g(m(`/api/voice/local/status`),at,{revalidateOnFocus:!1,refreshInterval:e=>e?.models.some(e=>e.state===`downloading`)?1e3:0}),[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(null),c=(0,Q.useCallback)(async(e,t)=>{a(e.id),s(null);try{t===`install`?await ct(e.id):await ut(e.id),await r()}catch(e){s(e instanceof Error?e.message:String(e))}finally{a(null)}},[r]);return(0,$.jsxs)(`div`,{className:`rounded-xl border border-edge bg-surface-panel/60 p-3`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.stt.localModels}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:e.stt.localModelsDesc}),n?(0,$.jsx)(`p`,{className:`mt-3 text-xs text-red-600 dark:text-red-400`,children:String(n)}):null,o?(0,$.jsx)(`p`,{className:`mt-3 text-xs text-red-600 dark:text-red-400`,children:o}):null,(0,$.jsx)(`div`,{className:`mt-3 grid gap-2`,children:(t?.models??[]).map(t=>{let n=i===t.id||t.state===`downloading`;return(0,$.jsxs)(`div`,{className:l(`flex items-center justify-between gap-3 rounded-lg bg-surface-base px-3 py-2.5`,t.recommended?`ring-1 ring-accent/40`:``),children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-sm font-medium text-fg`,children:[t.name,t.recommended?(0,$.jsx)(`span`,{className:`rounded-full bg-accent/10 px-2 py-0.5 text-[10px] font-medium text-accent`,children:e.stt.localRecommended}):null]}),(0,$.jsxs)(`div`,{className:`text-xs text-fg-muted`,children:[ln(t.approximateBytes),` · `,t.description]}),(0,$.jsxs)(`div`,{className:`mt-0.5 text-[11px] text-fg-subtle`,children:[t.engine,` · `,t.languages.join(` / `)]}),t.state===`downloading`?(0,$.jsxs)(`div`,{className:`mt-1 text-xs text-accent`,children:[e.stt.localDownloading,` `,Math.round((t.progress??0)*100),`%`]}):t.state===`error`?(0,$.jsx)(`div`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:t.error}):null]}),(0,$.jsx)(H,{type:`button`,variant:`secondary`,disabled:n,onClick:()=>void c(t,t.state===`ready`?`remove`:`install`),children:n?(0,$.jsx)(W,{className:`size-4 animate-spin`}):t.state===`ready`?e.stt.localRemove:e.stt.localInstall})]},t.id)})})]})}function dn({v:e,apiKeyLabels:t,tts:n,models:r,ttsProviders:i,updateTts:a,updateTtsAlibaba:o,updateTtsOpenai:s,updateTtsEdge:c,updateTtsMinimax:u,updateTtsLocalCli:d}){let f=r?.tts?.openai?.length?r.tts.openai:It,p=r?.ttsVoices?.openai?.length?r.ttsVoices.openai:Lt,m=r?.tts?.alibaba?.length?r.tts.alibaba:Rt,h=r?.ttsVoices?.alibaba?.length?r.ttsVoices.alibaba:zt,g=r?.ttsVoices?.edge?.length?r.ttsVoices.edge:Bt,v=r?.tts?.minimax?.length?r.tts.minimax:Vt,y=r?.ttsVoices?.minimax?.length?r.ttsVoices.minimax:Ht,[b,x]=(0,Q.useState)(e.tts.test.sampleText),[S,C]=(0,Q.useState)({status:`idle`}),w=(0,Q.useRef)(null),T=(0,Q.useRef)(null),E=(0,Q.useCallback)(()=>{w.current?.pause(),w.current=null,T.current&&=(URL.revokeObjectURL(T.current),null)},[]),D=(0,Q.useMemo)(()=>{let e=new Set,t=[];for(let n of i)e.has(n.id)||(e.add(n.id),t.push(n));return t},[i]),O=D.find(e=>e.id===n.provider),k=n.providers?.[n.provider],j={...n.provider===`openai`?n.openai??{}:{},...n.provider===`alibaba`?n.alibaba??{}:{},...n.provider===`edge`?n.edge??{}:{},...n.provider===`minimax`?n.minimax??{}:{},...n.provider===`tts-local-cli`?n[`tts-local-cli`]??{}:{},...k??{}},M=(O?.fields??[]).filter(e=>![`apiKey`,`model`,`voice`].includes(e.key)),N=!!O?.diagnostics.requiresApiKey,P=!!O?.configured||!N,F=n.enabled?P?`ready`:`action`:`muted`,I=n.provider===`openai`?n.openai?.model:n.provider===`alibaba`?n.alibaba?.model:n.provider===`minimax`?n.minimax?.model:void 0,L=n.provider===`openai`?n.openai?.voice:n.provider===`alibaba`?n.alibaba?.voice:n.provider===`minimax`?n.minimax?.voice:n.provider===`edge`?n.edge?.voice:void 0;(0,Q.useEffect)(()=>()=>E(),[E]);let R=(0,Q.useCallback)(e=>{a({provider:e}),C({status:`idle`})},[a]),z=(0,Q.useCallback)(async()=>{let t=b.trim();if(!t){C({status:`error`,message:e.tts.test.emptyText});return}E(),C({status:`loading`});try{let r=await nt({text:t,provider:n.provider,providerConfig:j,...I?{model:I}:{},...L?{voice:L}:{}}),i=Mt(r.audio,r.mimeType);T.current=i;let a=new Audio(i);w.current=a;let o=[r.provider,r.format,r.latencyMs===void 0?void 0:`${r.latencyMs}ms`,jt(r.audioSize)].filter(Boolean).join(` · `);a.addEventListener(`ended`,()=>C({status:`done`,summary:o}),{once:!0}),a.addEventListener(`error`,()=>C({status:`error`,message:e.tts.test.playFailed}),{once:!0}),await a.play(),C({status:`playing`,summary:o})}catch(e){E(),C({status:`error`,message:e instanceof Error?e.message:String(e)})}},[I,L,j,E,b,n.provider,e.tts.test.emptyText,e.tts.test.playFailed]),B=(0,Q.useCallback)(e=>{a({providers:{...n.providers??{},[n.provider]:{...n.providers?.[n.provider]??{},...e}}})},[n.provider,n.providers,a]),ee=(0,Q.useCallback)((e,t)=>{let r={[e.key]:t};B(r),n.provider===`openai`&&e.key===`baseUrl`?s(r):n.provider===`minimax`&&(e.key===`baseUrl`||e.key===`groupId`)?u(r):n.provider===`edge`&&e.key===`lang`&&c(r)},[n.provider,B,c,u,s]);return(0,$.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[(0,$.jsxs)(`div`,{className:`mb-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,$.jsx)(A,{className:`size-4 text-accent`,strokeWidth:1.75}),e.tts.title]}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:e.tts.description})]}),(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(fn,{checked:n.enabled,title:e.tts.enable,description:e.tts.enableDesc,onLabel:e.overview.ready,offLabel:e.overview.off,onChange:e=>a({enabled:e})}),(0,$.jsxs)(`div`,{className:l(`rounded-xl border px-3 py-2.5 text-sm`,F===`ready`?`border-emerald-500/25 bg-emerald-500/10 text-emerald-800 dark:text-emerald-100`:F===`action`?`border-amber-300/50 bg-amber-50 text-amber-900 dark:border-amber-300/30 dark:bg-amber-400/10 dark:text-amber-100`:`border-edge bg-surface-panel text-fg-muted`),children:[(0,$.jsx)(`div`,{className:`font-medium text-fg`,children:e.tts.statusTitle}),(0,$.jsx)(`p`,{className:`mt-1 text-xs`,children:n.enabled?P?`${e.tts.statusReady} ${Gt(n.provider,e)}${L?` · ${L}`:``}`:`${e.tts.statusNeedsSetup} ${Gt(n.provider,e)} · ${O?.diagnostics.envKeys?.join(`, `)??e.stt.apiKey}`:e.tts.statusOff})]}),n.enabled?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,Et),children:[(0,$.jsx)(hn,{children:e.tts.trigger}),(0,$.jsxs)(X,{className:At(),value:n.trigger,onChange:e=>a({trigger:e.target.value}),children:[(0,$.jsx)(Y,{value:`off`,children:e.tts.triggerOff}),(0,$.jsx)(Y,{value:`inbound`,children:e.tts.triggerInbound}),(0,$.jsx)(Y,{value:`tagged`,children:e.tts.triggerTagged}),(0,$.jsx)(Y,{value:`always`,children:e.tts.triggerAlways})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.triggerHelp})]}),(0,$.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,Et),children:[(0,$.jsx)(hn,{children:e.tts.provider}),(0,$.jsx)(X,{className:At(),value:n.provider,onChange:e=>R(e.target.value),children:D.map(t=>(0,$.jsx)(Y,{value:t.id,children:Gt(t.id,e)},t.id))}),(0,$.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[O?.configured?e.tts.configured:O?.diagnostics.requiresApiKey?`${e.tts.needsKey} · ${O.diagnostics.envKeys?.join(`, `)??e.stt.apiKey}`:e.tts.noKeyNeeded,` · `,O?.description??qt(n.provider,e)]})]})]}),(0,$.jsxs)(`details`,{className:`rounded-xl bg-surface-panel/80 p-3 shadow-surface`,open:!P||n.provider===`tts-local-cli`,children:[(0,$.jsxs)(`summary`,{className:`cursor-pointer text-sm font-medium text-fg marker:text-fg-muted`,children:[e.tts.advanced.title,(0,$.jsx)(`span`,{className:`ml-2 text-xs font-normal text-fg-muted`,children:e.tts.advanced.description})]}),(0,$.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[n.provider===`openai`||n.provider===`alibaba`||n.provider===`minimax`?(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,Et),children:[(0,$.jsx)(hn,{children:e.stt.apiKey}),(0,$.jsx)(lt,{kind:`tts`,providerId:n.provider,fieldId:`voice-tts-${n.provider}-api-key`,value:n.provider===`openai`?n.openai?.apiKey??``:n.provider===`alibaba`?n.alibaba?.apiKey??``:n.minimax?.apiKey??``,onChange:e=>{n.provider===`openai`?s({apiKey:e}):n.provider===`alibaba`?o({apiKey:e}):u({apiKey:e})},labels:t,placeholder:n.provider===`minimax`?`eyJ...`:`sk-...`}),(0,$.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,Ot(n.provider)?` ${Ot(n.provider)}`:``]})]}),(0,$.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,Et),children:[(0,$.jsx)(hn,{children:e.stt.model}),(0,$.jsx)(X,{className:At(),value:n.provider===`openai`?n.openai?.model??``:n.provider===`alibaba`?n.alibaba?.model??``:n.minimax?.model??``,onChange:e=>{n.provider===`openai`?s({model:e.target.value}):n.provider===`alibaba`?o({model:e.target.value}):u({model:e.target.value})},children:(n.provider===`openai`?f:n.provider===`alibaba`?m:v).map(e=>(0,$.jsx)(Y,{value:e.id,children:e.name},e.id))})]}),(0,$.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,Et),children:[(0,$.jsx)(hn,{children:e.tts.voice}),(0,$.jsx)(X,{className:At(),value:n.provider===`openai`?n.openai?.voice??``:n.provider===`alibaba`?n.alibaba?.voice??``:n.minimax?.voice??``,onChange:e=>{n.provider===`openai`?s({voice:e.target.value}):n.provider===`alibaba`?o({voice:e.target.value}):u({voice:e.target.value})},children:(n.provider===`openai`?p:n.provider===`alibaba`?h:y).map(e=>(0,$.jsx)(Y,{value:e.id,children:e.name},e.id))})]})]}):null,n.provider===`edge`?(0,$.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,Et),children:[(0,$.jsx)(hn,{children:e.tts.voice}),(0,$.jsx)(X,{className:At(),value:n.edge?.voice??``,onChange:e=>c({voice:e.target.value}),children:g.map(e=>(0,$.jsx)(Y,{value:e.id,children:e.name},e.id))}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.edgeHint})]}):null,n.provider===`tts-local-cli`?(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,$.jsx)(hn,{children:e.tts.localCli.preset}),(0,$.jsxs)(X,{className:At(),value:``,onChange:e=>{let t=Ut.find(t=>t.id===e.target.value);t&&d({command:t.command,outputFormat:t.outputFormat})},children:[(0,$.jsx)(Y,{value:``,children:e.tts.localCli.presetPlaceholder}),Ut.map(e=>(0,$.jsx)(Y,{value:e.id,children:e.id},e.id))]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.presetDesc})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,$.jsx)(hn,{children:e.tts.localCli.command}),(0,$.jsx)(`input`,{className:l(kt(),`font-mono text-xs`),type:`text`,autoComplete:`off`,spellCheck:!1,value:n[`tts-local-cli`]?.command??``,onChange:e=>d({command:e.target.value}),placeholder:e.tts.localCli.commandPlaceholder}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.commandDesc})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(hn,{children:e.tts.localCli.cwd}),(0,$.jsx)(`input`,{className:l(kt(),`font-mono text-xs`),type:`text`,autoComplete:`off`,spellCheck:!1,value:n[`tts-local-cli`]?.cwd??``,onChange:e=>d({cwd:e.target.value}),placeholder:`/path/to/cwd`}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.cwdDesc})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(hn,{children:e.tts.localCli.outputFormat}),(0,$.jsxs)(X,{className:At(),value:n[`tts-local-cli`]?.outputFormat??`wav`,onChange:e=>d({outputFormat:e.target.value}),children:[(0,$.jsx)(Y,{value:`wav`,children:`wav`}),(0,$.jsx)(Y,{value:`mp3`,children:`mp3`}),(0,$.jsx)(Y,{value:`opus`,children:`opus`})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.outputFormatDesc})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,$.jsx)(hn,{children:e.tts.localCli.timeoutMs}),(0,$.jsx)(`input`,{className:kt(),type:`number`,min:0,step:1e3,value:typeof n[`tts-local-cli`]?.timeoutMs==`number`?String(n[`tts-local-cli`].timeoutMs):``,onChange:e=>{let t=e.target.value.trim();if(t===``){d({timeoutMs:void 0});return}let n=Number(t);Number.isFinite(n)&&n>=0&&d({timeoutMs:n})},placeholder:`30000`}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.timeoutMsDesc})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle sm:col-span-2`,children:e.tts.localCli.hint})]}):null,M.length>0?(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:M.map(e=>(0,$.jsx)(pn,{field:e,value:Yt(j,e),onChange:t=>ee(e,t),className:e.type===`textarea`?`sm:col-span-2`:Et},e.key))}):null]})]}),(0,$.jsxs)(`div`,{className:`rounded-xl bg-surface-panel/80 p-3 shadow-surface`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.tts.test.title}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:e.tts.test.description})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[(0,$.jsxs)(H,{type:`button`,variant:`primary`,onClick:()=>void z(),disabled:S.status===`loading`,className:`h-9`,children:[S.status===`loading`?(0,$.jsx)(W,{className:`size-4 animate-spin`}):(0,$.jsx)(_,{className:`size-4`}),S.status===`loading`?e.tts.test.generating:e.tts.test.play]}),(0,$.jsxs)(H,{type:`button`,variant:`secondary`,onClick:()=>{E(),C(e=>e.status===`playing`?{status:`done`,summary:e.summary}:{status:`idle`})},disabled:S.status!==`playing`,className:`h-9`,children:[(0,$.jsx)(Be,{className:`size-4`}),e.tts.test.stop]})]})]}),(0,$.jsx)(`textarea`,{className:l(kt(),`mt-3 min-h-20 resize-y`),value:b,onChange:e=>x(e.target.value),maxLength:1e3}),(0,$.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center justify-between gap-2 text-xs`,children:[(0,$.jsxs)(`span`,{className:`text-fg-subtle`,children:[b.length,`/1000`]}),S.status===`playing`||S.status===`done`?(0,$.jsxs)(`span`,{className:`text-emerald-700 dark:text-emerald-200`,children:[S.status===`playing`?e.tts.test.playing:e.tts.test.ready,` · `,S.summary]}):null,S.status===`error`?(0,$.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:S.message}):null]})]})]}):null]})]})}function fn(e){let t=(0,Z.c)(33),{checked:n,title:r,description:i,onLabel:a,offLabel:o,onChange:s}=e,c;t[0]!==n||t[1]!==s?(c=()=>s(!n),t[0]=n,t[1]=s,t[2]=c):c=t[2];let u=n?`bg-accent/10 text-fg ring-1 ring-accent/45 dark:bg-accent/15`:`bg-surface-panel/80 text-fg hover:bg-surface-hover`,d;t[3]===u?d=t[4]:(d=l(`group flex w-full items-center justify-between gap-4 rounded-2xl px-4 py-3 text-left shadow-surface transition-colors`,w,u),t[3]=u,t[4]=d);let f=n?`bg-accent text-white`:`bg-surface-hover text-fg-muted`,p;t[5]===f?p=t[6]:(p=l(`rounded-full px-2 py-0.5 text-[11px] font-medium`,f),t[5]=f,t[6]=p);let m=n?a:o,h;t[7]!==p||t[8]!==m?(h=(0,$.jsx)(`span`,{className:p,children:m}),t[7]=p,t[8]=m,t[9]=h):h=t[9];let g;t[10]!==h||t[11]!==r?(g=(0,$.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-sm font-semibold text-fg`,children:[r,h]}),t[10]=h,t[11]=r,t[12]=g):g=t[12];let _;t[13]===i?_=t[14]:(_=(0,$.jsx)(`span`,{className:`mt-1 block text-xs leading-relaxed text-fg-muted`,children:i}),t[13]=i,t[14]=_);let v;t[15]!==g||t[16]!==_?(v=(0,$.jsxs)(`span`,{className:`min-w-0`,children:[g,_]}),t[15]=g,t[16]=_,t[17]=v):v=t[17];let y=n?`border-accent bg-accent`:`border-edge bg-surface-hover group-hover:border-accent/40`,b;t[18]===y?b=t[19]:(b=l(`relative inline-flex h-6 w-11 shrink-0 items-center rounded-full border transition-colors`,y),t[18]=y,t[19]=b);let x=n?`translate-x-5`:`translate-x-0.5`,S;t[20]===x?S=t[21]:(S=l(`size-5 rounded-full bg-white shadow-surface transition-transform`,x),t[20]=x,t[21]=S);let C;t[22]===S?C=t[23]:(C=(0,$.jsx)(`span`,{className:S}),t[22]=S,t[23]=C);let T;t[24]!==b||t[25]!==C?(T=(0,$.jsx)(`span`,{className:b,"aria-hidden":!0,children:C}),t[24]=b,t[25]=C,t[26]=T):T=t[26];let E;return t[27]!==n||t[28]!==c||t[29]!==v||t[30]!==T||t[31]!==d?(E=(0,$.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":n,onClick:c,className:d,children:[v,T]}),t[27]=n,t[28]=c,t[29]=v,t[30]=T,t[31]=d,t[32]=E):E=t[32],E}function pn(e){let t=(0,Z.c)(36),{field:n,value:r,onChange:i,className:a}=e,o=`voice-schema-field-${n.key}`,s=n.description;if(n.type===`boolean`){let e;t[0]===a?e=t[1]:(e=l(`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,a),t[0]=a,t[1]=e);let o;t[2]===n.label?o=t[3]:(o=(0,$.jsx)(`span`,{className:`block text-sm font-medium text-fg`,children:n.label}),t[2]=n.label,t[3]=o);let c;t[4]===s?c=t[5]:(c=s?(0,$.jsx)(`span`,{className:`mt-1 block text-xs text-fg-subtle`,children:s}):null,t[4]=s,t[5]=c);let u;t[6]!==o||t[7]!==c?(u=(0,$.jsxs)(`span`,{children:[o,c]}),t[6]=o,t[7]=c,t[8]=u):u=t[8];let d=!!r,f;t[9]!==n||t[10]!==i?(f=e=>i(Xt(n,e.target.checked)),t[9]=n,t[10]=i,t[11]=f):f=t[11];let p;t[12]!==d||t[13]!==f?(p=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:d,onChange:f}),t[12]=d,t[13]=f,t[14]=p):p=t[14];let m;return t[15]!==e||t[16]!==u||t[17]!==p?(m=(0,$.jsxs)(`label`,{className:e,children:[u,p]}),t[15]=e,t[16]=u,t[17]=p,t[18]=m):m=t[18],m}let c=typeof r==`boolean`?``:String(r),u;t[19]===a?u=t[20]:(u=l(`flex flex-col gap-1.5`,a),t[19]=a,t[20]=u);let d;t[21]===n.label?d=t[22]:(d=(0,$.jsx)(hn,{children:n.label}),t[21]=n.label,t[22]=d);let f;t[23]!==a||t[24]!==n||t[25]!==c||t[26]!==o||t[27]!==i?(f=n.type===`select`?(0,$.jsx)(X,{id:o,className:At(),value:c,required:n.required,onChange:e=>i(Xt(n,e.target.value)),children:(n.options??[]).map(mn)}):n.type===`textarea`?(0,$.jsx)(`textarea`,{id:o,className:l(kt(),`min-h-24 resize-y`),value:c,required:n.required,placeholder:n.placeholder,onChange:e=>i(Xt(n,e.target.value))}):n.type===`password`?(0,$.jsx)(qe,{id:o,className:a,value:c,onChange:e=>i(Xt(n,e)),placeholder:n.placeholder,labels:ke}):(0,$.jsx)(`input`,{id:o,className:kt(),type:n.type===`number`?`number`:`text`,autoComplete:n.secret?`new-password`:`off`,spellCheck:!1,value:c,required:n.required,placeholder:n.placeholder,onChange:e=>i(Xt(n,e.target.value))}),t[23]=a,t[24]=n,t[25]=c,t[26]=o,t[27]=i,t[28]=f):f=t[28];let p;t[29]===s?p=t[30]:(p=s?(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:s}):null,t[29]=s,t[30]=p);let m;return t[31]!==u||t[32]!==d||t[33]!==f||t[34]!==p?(m=(0,$.jsxs)(`div`,{className:u,children:[d,f,p]}),t[31]=u,t[32]=d,t[33]=f,t[34]=p,t[35]=m):m=t[35],m}function mn(e){return(0,$.jsx)(Y,{value:e.id,children:e.name},e.id)}function hn(e){let t=(0,Z.c)(2),{children:n}=e,r;return t[0]===n?r=t[1]:(r=(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n}),t[0]=n,t[1]=r),r}function gn(e){let t=e&&typeof e==`object`&&`tools`in e?e.tools:void 0,n=t&&typeof t==`object`&&`web`in t?t.web:void 0,r=n&&typeof n==`object`&&`region`in n?n.region:void 0,i=r===`cn`||r===`global`?r:`auto`,a=n&&typeof n==`object`&&`search`in n?n.search:void 0,o=a&&typeof a==`object`?a:{},s=typeof o.maxResults==`number`&&Number.isFinite(o.maxResults)?Math.floor(o.maxResults):5,c=n&&typeof n==`object`&&`blocklist`in n?n.blocklist:void 0,l=c&&typeof c==`object`?c:{},u=Array.isArray(l.domains)?l.domains.filter(e=>typeof e==`string`&&e.trim().length>0):[],d=o.providers;return{regionMode:i,maxResults:s,providers:Array.isArray(d)?d.map(e=>{let t=e&&typeof e==`object`?e:{},n=t.type;return{type:n===`brave`||n===`tavily`||n===`bing`||n===`searxng`?n:`brave`,apiKey:typeof t.apiKey==`string`?t.apiKey:``,url:typeof t.url==`string`?t.url:``,disabled:t.disabled===!0}}):[],blocklistEnabled:l.enabled===!0,blocklistDomains:u}}async function _n(e){let t=e.regionMode===`auto`?`auto`:e.regionMode===`cn`?`cn`:`global`,n={maxResults:e.maxResults,providers:e.providers.map(e=>{let t={type:e.type,apiKey:e.apiKey};return e.type===`searxng`&&e.url.trim()&&(t.url=e.url.trim().replace(/\/+$/,``)),e.disabled&&(t.disabled=!0),t})};await h(m(`/api/config`),{method:`PATCH`,body:JSON.stringify({tools:{web:{region:t,search:n,blocklist:{enabled:e.blocklistEnabled,domains:e.blocklistDomains}}}})}),ge()}async function vn(e){let t=await h(m(`/api/tools/web/reveal-search-api-key`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({index:e})});if(!t.ok||!t.payload)throw Error(t.error?.message??`Reveal failed`);return t.payload}function yn(e){let t=(0,Z.c)(8),{label:n,description:r,children:i}=e,a;t[0]===n?a=t[1]:(a=(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n}),t[0]=n,t[1]=a);let o;t[2]===r?o=t[3]:(o=(0,$.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:r}),t[2]=r,t[3]=o);let s;return t[4]!==i||t[5]!==a||t[6]!==o?(s=(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[a,i,o]}),t[4]=i,t[5]=a,t[6]=o,t[7]=s):s=t[7],s}function bn(){return l(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,w,`dark:border-edge`)}function xn(){return l(D,q)}var Sn=[`brave`,`tavily`,`bing`,`searxng`];function Cn(){return{type:`brave`,apiKey:``,url:``,disabled:!1}}var wn=Me();function Tn(){let e=u(f(e=>e.language)),t=e.webSearchSettings,n=e.logs,r=!!d(e=>e.token),[i,a]=(0,Q.useReducer)(wn,{form:null,baseline:null}),o=i.form,s=i.baseline,[c,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(null),g=(0,Q.useRef)(!1),_=(0,Q.useRef)(null),{data:v,error:y,isLoading:b,mutate:x}=xe(r);B({enabled:r,parsed:(0,Q.useMemo)(()=>v?.payload?.config===void 0?null:gn(v.payload.config),[v]),dirty:g.current,trackedParsedRef:_,dispatch:a,onResetDirty:()=>{g.current=!1}});let S=!!(r&&b&&v===void 0&&!y),C=y instanceof Error?y.message:y?String(y):null,w=(0,Q.useMemo)(()=>!o||!s?!1:JSON.stringify(o)!==JSON.stringify(s),[o,s]),T=(0,Q.useCallback)(e=>{g.current=!0,a({type:`patch`,patch:e})},[]);return ht({id:`search`,dirty:w,saving:c,save:(0,Q.useCallback)(async()=>{if(!(!o||c)){p(!0),h(null);try{await _n(o),g.current=!1,a({type:`saved`,value:o})}catch(e){h(e instanceof Error?e.message:t.saveError)}finally{p(!1)}}},[o,c,t.saveError]),discard:(0,Q.useCallback)(()=>{s&&(g.current=!1,a({type:`discard`}),h(null))},[s])}),r?S?(0,$.jsx)(et,{rows:3}):o?(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[m?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:m}):null,(0,$.jsxs)(pt,{children:[(0,$.jsx)(ft,{icon:Ie,title:t.sectionRegion,subtitle:t.sectionRegionHint}),(0,$.jsx)(`div`,{className:`flex max-w-md flex-col gap-4`,children:(0,$.jsx)(yn,{label:t.regionLabel,description:t.regionDesc,children:(0,$.jsxs)(X,{className:xn(),value:o.regionMode,onChange:e=>T({regionMode:e.target.value}),children:[(0,$.jsx)(Y,{value:`auto`,children:t.regionAuto}),(0,$.jsx)(Y,{value:`cn`,children:t.regionCn}),(0,$.jsx)(Y,{value:`global`,children:t.regionGlobal})]})})})]}),(0,$.jsx)(dt,{children:(0,$.jsxs)(pt,{children:[(0,$.jsx)(ft,{icon:O,title:t.sectionBlocklist,subtitle:t.sectionBlocklistHint}),(0,$.jsxs)(`div`,{className:`flex max-w-xl flex-col gap-4`,children:[(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:o.blocklistEnabled,onChange:e=>T({blocklistEnabled:e.target.checked})}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`font-medium`,children:t.blocklistEnabled}),(0,$.jsx)(`span`,{className:`mt-0.5 block text-xs text-fg-subtle`,children:t.blocklistEnabledDesc})]})]}),(0,$.jsx)(yn,{label:t.blocklistDomains,description:t.blocklistDomainsDesc,children:(0,$.jsx)(`textarea`,{className:l(bn(),`min-h-[6rem] font-mono text-xs`),value:o.blocklistDomains.join(`
2
+ `),placeholder:t.blocklistDomainsPlaceholder,disabled:!o.blocklistEnabled,onChange:e=>{T({blocklistDomains:e.target.value.split(/\r?\n/).flatMap(e=>{let t=e.trim().toLowerCase();return t?[t]:[]})})}})})]})]})}),(0,$.jsxs)(pt,{children:[(0,$.jsx)(ft,{icon:Ie,title:t.sectionSearch,subtitle:t.sectionSearchHint}),(0,$.jsxs)(`div`,{className:`flex max-w-xl flex-col gap-6`,children:[(0,$.jsx)(yn,{label:t.maxResultsLabel,description:t.maxResultsDesc,children:(0,$.jsx)(`input`,{type:`number`,min:1,max:50,className:bn(),value:o.maxResults,onChange:e=>T({maxResults:Math.max(1,Math.min(50,Number(e.target.value)||5))})})}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.providersTitle}),o.providers.map((n,r)=>(0,$.jsx)(En,{row:n,providerIndex:r,labels:t,secretLabels:Ce(e.providersSettings),onChange:e=>{let t=[...o.providers];t[r]=e,T({providers:t})},onRemove:()=>{T({providers:o.providers.filter((e,t)=>t!==r)})}},`${n.type}:${n.url}:${n.apiKey}:${n.disabled}`)),(0,$.jsxs)(H,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5 text-sm`,onClick:()=>T({providers:[...o.providers,Cn()]}),children:[(0,$.jsx)(V,{className:`size-4`}),t.addProvider]})]})]})]}),(0,$.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:t.footerHint})]}):(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:m??C??t.loadError}),(0,$.jsx)(H,{type:`button`,variant:`secondary`,onClick:()=>void x(),children:n.refresh})]}):(0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.needToken})})}function En(e){let t=(0,Z.c)(54),{row:n,providerIndex:r,labels:i,secretLabels:a,onChange:o,onRemove:s}=e,c;t[0]===r?c=t[1]:(c=()=>vn(r).then(Dn),t[0]=r,t[1]=c);let u=c,d;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(d=l(xn(),`min-w-[8rem]`),t[2]=d):d=t[2];let f=n.type,p;t[3]!==o||t[4]!==n?(p=e=>o({...n,type:e.target.value,url:e.target.value===`searxng`?n.url:``}),t[3]=o,t[4]=n,t[5]=p):p=t[5];let m;t[6]===i.providerTypes?m=t[7]:(m=Sn.map(e=>(0,$.jsx)(Y,{value:e,children:i.providerTypes[e]},e)),t[6]=i.providerTypes,t[7]=m);let h;t[8]!==n.type||t[9]!==p||t[10]!==m?(h=(0,$.jsx)(X,{className:d,value:f,onChange:p,children:m}),t[8]=n.type,t[9]=p,t[10]=m,t[11]=h):h=t[11];let g;t[12]!==o||t[13]!==n?(g=e=>o({...n,disabled:e.target.checked}),t[12]=o,t[13]=n,t[14]=g):g=t[14];let _;t[15]!==n.disabled||t[16]!==g?(_=(0,$.jsx)(`input`,{type:`checkbox`,className:`size-3.5 rounded border-edge`,checked:n.disabled,onChange:g}),t[15]=n.disabled,t[16]=g,t[17]=_):_=t[17];let v;t[18]!==i.disabled||t[19]!==_?(v=(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1.5 text-xs text-fg-muted`,children:[_,i.disabled]}),t[18]=i.disabled,t[19]=_,t[20]=v):v=t[20];let y;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,$.jsx)(he,{className:`size-4`}),t[21]=y):y=t[21];let b;t[22]===s?b=t[23]:(b=(0,$.jsx)(H,{type:`button`,variant:`ghost`,className:`h-8 px-2 text-fg-muted`,onClick:s,children:y}),t[22]=s,t[23]=b);let x;t[24]!==b||t[25]!==v?(x=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[v,b]}),t[24]=b,t[25]=v,t[26]=x):x=t[26];let S;t[27]!==x||t[28]!==h?(S=(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[h,x]}),t[27]=x,t[28]=h,t[29]=S):S=t[29];let C;t[30]!==i.urlDesc||t[31]!==i.urlLabel||t[32]!==o||t[33]!==n?(C=n.type===`searxng`?(0,$.jsx)(yn,{label:i.urlLabel,description:i.urlDesc,children:(0,$.jsx)(`input`,{type:`url`,className:bn(),value:n.url,placeholder:`http://localhost:8080`,onChange:e=>o({...n,url:e.target.value})})}):null,t[30]=i.urlDesc,t[31]=i.urlLabel,t[32]=o,t[33]=n,t[34]=C):C=t[34];let w;t[35]!==o||t[36]!==n?(w=e=>o({...n,apiKey:e}),t[35]=o,t[36]=n,t[37]=w):w=t[37];let T;t[38]!==i.keyPlaceholder||t[39]!==i.keyPlaceholderMasked||t[40]!==i.saveError||t[41]!==u||t[42]!==n.apiKey||t[43]!==a||t[44]!==w?(T=(0,$.jsx)(qe,{value:n.apiKey,onChange:w,placeholder:i.keyPlaceholder,labels:a,reveal:u,loadFailedLabel:i.saveError,notInConfigFile:i.keyPlaceholderMasked}),t[38]=i.keyPlaceholder,t[39]=i.keyPlaceholderMasked,t[40]=i.saveError,t[41]=u,t[42]=n.apiKey,t[43]=a,t[44]=w,t[45]=T):T=t[45];let E;t[46]!==i.apiKeyDesc||t[47]!==i.apiKeyLabel||t[48]!==T?(E=(0,$.jsx)(yn,{label:i.apiKeyLabel,description:i.apiKeyDesc,children:T}),t[46]=i.apiKeyDesc,t[47]=i.apiKeyLabel,t[48]=T,t[49]=E):E=t[49];let D;return t[50]!==S||t[51]!==C||t[52]!==E?(D=(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-xl bg-surface-panel/70 p-4 shadow-surface`,children:[S,C,E]}),t[50]=S,t[51]=C,t[52]=E,t[53]=D):D=t[53],D}function Dn(e){return e.apiKey??null}async function On(e){let t=await p(m(`/api/auth/oauth-async/start`),{method:`POST`,body:JSON.stringify({provider:e})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error||`OAuth start failed: ${t.status}`)}return(await t.json()).payload}async function kn(e){let t=await p(m(`/api/auth/oauth-async/${encodeURIComponent(e)}/status`));if(!t.ok)throw Error(`OAuth status: ${t.status}`);return(await t.json()).payload}async function An(e,t){let n=await p(m(`/api/auth/oauth-async/${encodeURIComponent(e)}/code`),{method:`POST`,body:JSON.stringify({code:t})});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error||`Submit code failed: ${n.status}`)}}async function jn(e){let t=await p(m(`/api/auth/oauth-async/${encodeURIComponent(e)}/cancel`),{method:`POST`});if(!t.ok)throw Error(`Cancel OAuth failed: ${t.status}`)}async function Mn(e){let t=await p(m(`/api/auth/oauth-async/${encodeURIComponent(e)}`),{method:`DELETE`});if(!t.ok)throw Error(`Cleanup session failed: ${t.status}`)}async function Nn(e){let t=await p(m(`/api/auth/oauth/${encodeURIComponent(e)}`),{method:`DELETE`});if(!t.ok)throw Error(`Revoke OAuth failed: ${t.status}`)}var Pn=[`common`,`domestic`,`specialty`,`enterprise`,`oauth`,`extension`];function Fn(e){let t=new Map;for(let e of Pn)t.set(e,[]);for(let n of e){let e=n.category||`specialty`,r=t.get(e)??[];r.push(n),t.set(e,r)}return t}function In(e){let t=(0,Z.c)(22),{open:n,onOpenChange:r,builtinRows:i,customConfig:a,labels:o,language:s,onSaved:c}=e,u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u={type:`pick`},t[0]=u):u=t[0];let[d,f]=(0,Q.useState)(u),[p,m]=(0,Q.useState)(``),h;t[1]===r?h=t[2]:(h=e=>{e||window.setTimeout(()=>{f({type:`pick`}),m(``)},200),r(e)},t[1]=r,t[2]=h);let g=h,_;t[3]!==g||t[4]!==c?(_=()=>{c(),g(!1)},t[3]=g,t[4]=c,t[5]=_):_=t[5];let y=_,x;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,$.jsx)(P,{className:l(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,Fe)}),t[6]=x):x=t[6];let S;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(S=l(`fixed left-1/2 top-1/2 flex max-h-[85vh] w-full max-w-lg -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-2xl border border-edge-subtle bg-surface-base shadow-xl`,Te),t[7]=S):S=t[7];let C;t[8]!==i||t[9]!==a||t[10]!==y||t[11]!==o||t[12]!==s||t[13]!==p||t[14]!==d.presetKey||t[15]!==d.providerId||t[16]!==d.type?(C=(0,$.jsxs)(se,{children:[x,(0,$.jsx)(b,{className:S,children:d.type===`pick`?(0,$.jsx)(Bn,{builtinRows:i,searchQuery:p,onSearchChange:m,labels:o,onPickBuiltin:e=>{if(e===`xopc-cloud`){f({type:`xopcCloud`});return}let t=v(e);f(t?{type:`custom`,presetKey:t}:{type:`builtin`,providerId:e})},onPickCustom:()=>f({type:`custom`})}):d.type===`xopcCloud`?(0,$.jsx)(Rn,{connected:i.some(Ln),labels:o,onBack:()=>f({type:`pick`}),onConnected:y}):d.type===`builtin`?(0,$.jsx)(Vn,{providerId:d.providerId,builtinRows:i,labels:o,language:s,onBack:()=>f({type:`pick`}),onSaved:y}):(0,$.jsx)(Wn,{initialPresetKey:d.presetKey,customConfig:a,labels:o,language:s,onBack:()=>f({type:`pick`}),onSaved:y})})]}),t[8]=i,t[9]=a,t[10]=y,t[11]=o,t[12]=s,t[13]=p,t[14]=d.presetKey,t[15]=d.providerId,t[16]=d.type,t[17]=C):C=t[17];let w;return t[18]!==g||t[19]!==n||t[20]!==C?(w=(0,$.jsx)(G,{open:n,onOpenChange:g,children:C}),t[18]=g,t[19]=n,t[20]=C,t[21]=w):w=t[21],w}function Ln(e){return e.id===`xopc-cloud`&&e.configured}function Rn(e){let t=(0,Z.c)(17),{connected:n,labels:r,onBack:i,onConnected:a}=e,o;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=l(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,K.press),t[0]=o):o=t[0];let s;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(s=(0,$.jsx)(Oe,{className:`size-4 rotate-180`,"aria-hidden":!0}),t[1]=s):s=t[1];let c;t[2]!==r.back||t[3]!==i?(c=(0,$.jsx)(`button`,{type:`button`,onClick:i,className:o,"aria-label":r.back,children:s}),t[2]=r.back,t[3]=i,t[4]=c):c=t[4];let u;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,$.jsx)(me,{className:`min-w-0 flex-1 text-base font-semibold text-fg`,children:`XOPC Model Service`}),t[5]=u):u=t[5];let d;t[6]===r.close?d=t[7]:(d=(0,$.jsx)(zn,{label:r.close}),t[6]=r.close,t[7]=d);let f;t[8]!==c||t[9]!==d?(f=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-edge-subtle px-5 py-4`,children:[c,u,d]}),t[8]=c,t[9]=d,t[10]=f):f=t[10];let p;t[11]!==n||t[12]!==a?(p=(0,$.jsx)(`div`,{className:`px-5 py-4`,children:(0,$.jsx)(re,{connected:n,onConnected:a})}),t[11]=n,t[12]=a,t[13]=p):p=t[13];let m;return t[14]!==f||t[15]!==p?(m=(0,$.jsxs)($.Fragment,{children:[f,p]}),t[14]=f,t[15]=p,t[16]=m):m=t[16],m}function zn(e){let t=(0,Z.c)(4),{label:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=l(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,K.press),t[0]=r):r=t[0];let i;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(je,{className:`size-4`,"aria-hidden":!0}),t[1]=i):i=t[1];let a;return t[2]===n?a=t[3]:(a=(0,$.jsx)(Ye,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:r,"aria-label":n,children:i})}),t[2]=n,t[3]=a),a}function Bn(e){let t=(0,Z.c)(42),{builtinRows:n,searchQuery:r,onSearchChange:i,labels:a,onPickBuiltin:o,onPickCustom:s}=e,c;t[0]===r?c=t[1]:(c=r.trim().toLowerCase(),t[0]=r,t[1]=c);let u=c,d;bb0:{if(!u){d=n;break bb0}let e;if(t[2]!==n||t[3]!==u){let r;t[5]===u?r=t[6]:(r=e=>{let t=Ze[e.id]?.aliases??[];return e.id.toLowerCase().includes(u)||e.name.toLowerCase().includes(u)||t.some(e=>e.toLowerCase().includes(u))},t[5]=u,t[6]=r),e=n.filter(r),t[2]=n,t[3]=u,t[4]=e}else e=t[4];d=e}let f=d,p;t[7]===f?p=t[8]:(p=Fn(f),t[7]=f,t[8]=p);let m=p,h;t[9]===a.step1Title?h=t[10]:(h=(0,$.jsx)(me,{className:`min-w-0 flex-1 text-base font-semibold text-fg`,children:a.step1Title}),t[9]=a.step1Title,t[10]=h);let g;t[11]===a.close?g=t[12]:(g=(0,$.jsx)(zn,{label:a.close}),t[11]=a.close,t[12]=g);let _;t[13]!==h||t[14]!==g?(_=(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b border-edge-subtle px-5 py-4`,children:[h,g]}),t[13]=h,t[14]=g,t[15]=_):_=t[15];let v;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(Ie,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-fg-subtle`,strokeWidth:1.75,"aria-hidden":!0}),t[16]=v):v=t[16];let y;t[17]===i?y=t[18]:(y=e=>i(e.target.value),t[17]=i,t[18]=y);let b=a.searchPlaceholder,x;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(x=l(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-10 pr-3 text-sm text-fg placeholder:text-fg-subtle`,w),t[19]=x):x=t[19];let S;t[20]!==a.searchPlaceholder||t[21]!==r||t[22]!==y?(S=(0,$.jsx)(`div`,{className:`px-5 pt-3`,children:(0,$.jsxs)(`div`,{className:`relative`,children:[v,(0,$.jsx)(`input`,{type:`search`,value:r,onChange:y,placeholder:b,autoComplete:`off`,className:x})]})}),t[20]=a.searchPlaceholder,t[21]=r,t[22]=y,t[23]=S):S=t[23];let C;t[24]!==a.addCustom||t[25]!==a.customDescription||t[26]!==s||t[27]!==u?(C=u?null:(0,$.jsxs)(`button`,{type:`button`,onClick:s,className:l(`mb-3 flex w-full items-center gap-3 rounded-xl border border-dashed border-edge-subtle bg-surface-panel/40 px-4 py-3 text-left transition-colors`,`hover:bg-surface-hover/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,K.press),children:[(0,$.jsx)(T,{className:`size-5 shrink-0 text-fg-subtle`,strokeWidth:1.75,"aria-hidden":!0}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:a.addCustom}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:a.customDescription})]}),(0,$.jsx)(Oe,{className:`size-4 shrink-0 text-fg-subtle`,"aria-hidden":!0})]}),t[24]=a.addCustom,t[25]=a.customDescription,t[26]=s,t[27]=u,t[28]=C):C=t[28];let E;t[29]!==f.length||t[30]!==m||t[31]!==a.categories||t[32]!==a.noResults||t[33]!==o?(E=f.length===0?(0,$.jsx)(`p`,{className:`py-6 text-center text-sm text-fg-muted`,children:a.noResults}):(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:Pn.map(e=>{let t=m.get(e)??[];return t.length===0?null:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`mb-1 px-1 text-[11px] font-semibold uppercase tracking-wide text-fg-subtle`,children:a.categories[e]??e}),(0,$.jsx)(`div`,{className:`flex flex-col gap-0.5`,children:t.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>o(e.id),className:l(`flex w-full items-center justify-between gap-2 rounded-lg px-3 py-2.5 text-left transition-colors`,`hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,K.press),children:[(0,$.jsx)(`span`,{className:`truncate text-sm text-fg`,children:e.name}),e.configured?(0,$.jsx)(Ve,{className:`size-3.5 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):null]},e.id))})]},e)})}),t[29]=f.length,t[30]=m,t[31]=a.categories,t[32]=a.noResults,t[33]=o,t[34]=E):E=t[34];let D;t[35]!==C||t[36]!==E?(D=(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto px-5 py-3`,children:[C,E]}),t[35]=C,t[36]=E,t[37]=D):D=t[37];let O;return t[38]!==S||t[39]!==D||t[40]!==_?(O=(0,$.jsxs)($.Fragment,{children:[_,S,D]}),t[38]=S,t[39]=D,t[40]=_,t[41]=O):O=t[41],O}function Vn({providerId:e,builtinRows:t,labels:n,language:r,onBack:i,onSaved:a}){let o=t.find(t=>t.id===e),s=Ze[e],[c,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(!1),v=(0,Q.useRef)(null),y=u(r).providersSettings,b=Ce(y),S=(0,Q.useMemo)(()=>x(e,r),[e,r]),C=o?.supportsApiKey!==!1,T=o?.supportsOAuth===!0,[E,D]=(0,Q.useState)(null),[O,k]=(0,Q.useState)(null),[A,j]=(0,Q.useState)(`idle`),[M,N]=(0,Q.useState)(null),[P,F]=(0,Q.useState)(null),[I,L]=(0,Q.useState)(``),R=A===`waiting`||A===`waiting_code`;(0,Q.useEffect)(()=>{if(!E||!R)return;let e=window.setInterval(()=>{(async()=>{try{let t=await kn(E);t.status===`waiting_auth`||t.status===`waiting_code`?(j(t.status===`waiting_code`?`waiting_code`:`waiting`),k(t.message??null),N(t.authUrl??null),F(t.instructions??null)):t.status===`completed`?(window.clearInterval(e),j(`success`),k(t.message??y.saved),window.setTimeout(a,600)):(t.status===`failed`||t.status===`cancelled`)&&(window.clearInterval(e),j(`error`),k(t.error??t.message??y.revokeFailed))}catch{}})()},1e3);return()=>window.clearInterval(e)},[E,R,a,y.revokeFailed,y.saved]),(0,Q.useEffect)(()=>()=>{E&&Mn(E).catch(()=>{})},[E]);let z=async()=>{j(`waiting`),k(y.oauthStarting),h(null);try{D((await On(e)).sessionId)}catch(e){j(`error`),k(e instanceof Error?e.message:y.revokeFailed)}},B=async()=>{if(E){try{await jn(E)}catch{}j(`idle`),k(null),D(null),N(null),F(null)}},ee=async()=>{if(!(!E||!I.trim()))try{await An(E,I.trim()),L(``),k(y.oauthProcessingCode)}catch(e){j(`error`),k(e instanceof Error?e.message:y.revokeFailed)}},V=async()=>{let t=c.trim();if(!(!t||!C)){p(!0),h(null);try{await Je({[e]:t}),_(!0),window.setTimeout(a,600)}catch(e){h(e instanceof Error?e.message:n.saveError)}finally{p(!1)}}};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-edge-subtle px-5 py-4`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:i,className:l(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,K.press),"aria-label":n.back,children:(0,$.jsx)(Oe,{className:`size-4 rotate-180`,"aria-hidden":!0})}),(0,$.jsx)(me,{className:`min-w-0 flex-1 text-base font-semibold text-fg`,children:o?.name??e}),(0,$.jsx)(zn,{label:n.close})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 px-5 py-4`,children:[s?.description?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:s.description}):null,C?(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`builtin-api-key`,className:`text-sm font-medium text-fg`,children:n.apiKeyLabel}),(0,$.jsx)(qe,{id:`builtin-api-key`,value:c,onChange:d,placeholder:n.apiKeyPlaceholder,labels:b,inputRef:v,onKeyDown:e=>{e.key===`Enter`&&V()}})]}):null,T?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-lg border border-edge-subtle bg-surface-panel/60 p-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:y.oauth}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:y.oauthHint})]}),(0,$.jsxs)(H,{type:`button`,variant:`primary`,className:`gap-1.5`,disabled:R,onClick:()=>void z(),children:[R?(0,$.jsx)(W,{className:`size-3.5 animate-spin`,"aria-hidden":!0}):null,y.oauth]})]}),O?(0,$.jsx)(`p`,{className:l(`text-xs`,A===`error`?`text-red-600 dark:text-red-400`:`text-fg-muted`),children:O}):null,A===`waiting`||A===`waiting_code`?(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[M?(0,$.jsxs)(`a`,{href:M,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1.5 rounded-md bg-accent px-3 py-2 text-sm font-medium text-white hover:bg-accent-hover`,children:[y.openAuthPage,(0,$.jsx)(`span`,{className:`size-3`,"aria-hidden":!0,children:`↗`})]}):null,(0,$.jsx)(H,{type:`button`,variant:`secondary`,onClick:()=>void B(),children:y.cancelOAuth})]}):null,P?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:P}):null,A===`waiting_code`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,$.jsx)(`input`,{type:`text`,value:I,onChange:e=>L(e.target.value),onKeyDown:e=>e.key===`Enter`&&void ee(),placeholder:y.pasteRedirectUrl,className:l(`min-w-0 flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,w)}),(0,$.jsx)(H,{type:`button`,variant:`primary`,onClick:()=>void ee(),children:y.submitCode})]}):null]}):null,S.length>0&&C?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:S.map(({kind:e,href:t})=>(0,$.jsxs)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent hover:underline`,children:[fe(e,n),(0,$.jsx)(`span`,{className:`size-3`,"aria-hidden":!0,children:`↗`})]},e))}):null,m?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:m}):null,(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,$.jsx)(H,{type:`button`,variant:`secondary`,onClick:i,children:n.cancel}),C?(0,$.jsx)(H,{type:`button`,variant:`primary`,disabled:!c.trim()||f||g,onClick:()=>void V(),children:g?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(Ve,{className:`size-3.5`,"aria-hidden":!0}),n.saved]}):f?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(W,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),n.saving]}):n.save}):null]})]})]})}function Hn(e=`custom`){if(e!==`custom`&&E[e]){let t=E[e].config;return{preset:e,providerId:R(e),baseUrl:t.baseUrl??``,api:t.api??`openai-completions`,apiKey:t.apiKey??``,modelIds:t.models?.map(e=>e.id)??[``],error:null}}return{preset:`custom`,providerId:``,baseUrl:``,api:`openai-completions`,apiKey:``,modelIds:[``],error:null}}function Un(e,t){switch(t.type){case`applyPreset`:return t.key===`custom`?{...e,preset:`custom`,error:null}:E[t.key]?Hn(t.key):e;case`setProviderId`:return{...e,providerId:t.value};case`setBaseUrl`:return{...e,baseUrl:t.value};case`setApi`:return{...e,api:t.value};case`setApiKey`:return{...e,apiKey:t.value};case`addModelSlot`:return{...e,modelIds:[...e.modelIds,``]};case`updateModelId`:return{...e,modelIds:e.modelIds.map((e,n)=>n===t.index?t.value:e)};case`setModelIds`:return{...e,modelIds:t.values.length>0?t.values:[``]};case`removeModelSlot`:return{...e,modelIds:e.modelIds.filter((e,n)=>n!==t.index)};case`setError`:return{...e,error:t.value}}}function Wn({initialPresetKey:e,customConfig:t,labels:n,language:r,onBack:i,onSaved:a}){let[o,s]=(0,Q.useReducer)(Un,void 0,()=>Hn(e)),[c,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(!1),m=Ce(u(r).providersSettings),{preset:h,providerId:g,baseUrl:_,api:v,apiKey:y,modelIds:b,error:x}=o,S=async()=>{let e=g.trim(),r=_.trim();if(!e){s({type:`setError`,value:n.providerIdRequired});return}if(!r){s({type:`setError`,value:n.baseUrlRequired});return}let i=b.map(e=>e.trim()).filter(Boolean);d(!0),s({type:`setError`,value:null});try{let n=t?.providers??{},o=h===`custom`?void 0:E[h]?.config,s={...o??{},baseUrl:r,api:v,apiKey:y.trim()||void 0,models:i.map(e=>o?.models?.find(t=>t.id===e)??{id:e})};await He({providers:{...n,[e]:s}}),a()}catch(e){s({type:`setError`,value:e instanceof Error?e.message:n.saveError})}finally{d(!1)}},T=async()=>{let e=g.trim()||R(h)||`custom`,t=_.trim();if(!t){s({type:`setError`,value:n.baseUrlRequired});return}p(!0),s({type:`setError`,value:null});try{let r=h===`custom`?void 0:E[h]?.config,i=(await We({providerId:e,baseUrl:t,apiKey:y.trim()||void 0,api:v,headers:r?.headers})).map(e=>e.id).filter(e=>e&&!e.includes(`/`));s({type:`setModelIds`,values:i}),i.length===0&&s({type:`setError`,value:n.discoverModelsHint})}catch(e){s({type:`setError`,value:e instanceof Error?e.message:n.discoverModelsHint})}finally{p(!1)}},D=g.trim()&&_.trim(),O=(v===`openai-completions`||v===`openai-responses`)&&_.trim();return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-edge-subtle px-5 py-4`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:i,className:l(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,K.press),"aria-label":n.back,children:(0,$.jsx)(Oe,{className:`size-4 rotate-180`,"aria-hidden":!0})}),(0,$.jsx)(me,{className:`min-w-0 flex-1 text-base font-semibold text-fg`,children:n.step2CustomTitle}),(0,$.jsx)(zn,{label:n.close})]}),(0,$.jsxs)(`div`,{className:`flex max-h-[60vh] flex-col gap-4 overflow-y-auto px-5 py-4`,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.customDescription}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`custom-preset`,className:`text-sm font-medium text-fg`,children:n.presetLabel}),(0,$.jsxs)(X,{id:`custom-preset`,value:h,onChange:e=>s({type:`applyPreset`,key:e.target.value}),className:ee(),children:[(0,$.jsx)(Y,{value:`custom`,children:n.presetCustom}),C.map(e=>(0,$.jsx)(Y,{value:e.key,children:e.label},e.key))]})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`custom-provider-id`,className:`text-sm font-medium text-fg`,children:n.providerIdLabel}),(0,$.jsx)(`input`,{id:`custom-provider-id`,type:`text`,autoComplete:`off`,value:g,onChange:e=>s({type:`setProviderId`,value:e.target.value}),placeholder:n.providerIdPlaceholder,className:l(`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,w)})]}),(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`custom-base-url`,className:`text-sm font-medium text-fg`,children:n.baseUrlLabel}),(0,$.jsx)(`input`,{id:`custom-base-url`,type:`url`,autoComplete:`off`,value:_,onChange:e=>s({type:`setBaseUrl`,value:e.target.value}),placeholder:n.baseUrlPlaceholder,className:l(`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,w)})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`custom-api-type`,className:`text-sm font-medium text-fg`,children:n.apiTypeLabel}),(0,$.jsx)(X,{id:`custom-api-type`,value:v,onChange:e=>s({type:`setApi`,value:e.target.value}),className:ee(),children:Ke.map(e=>(0,$.jsx)(Y,{value:e.value,children:e.label},e.value))})]})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`custom-api-key`,className:`text-sm font-medium text-fg`,children:n.apiKeyLabel}),(0,$.jsx)(qe,{id:`custom-api-key`,value:y,onChange:e=>s({type:`setApiKey`,value:e}),placeholder:n.apiKeyPlaceholder,labels:m})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:n.modelIdLabel}),(0,$.jsxs)(H,{type:`button`,variant:`secondary`,className:`gap-1.5`,disabled:!O||f,onClick:()=>void T(),children:[f?(0,$.jsx)(W,{className:`size-3.5 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Ie,{className:`size-3.5`,"aria-hidden":!0}),f?n.discoveringModels:n.discoverModels]})]}),b.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`text`,autoComplete:`off`,value:e,onChange:e=>s({type:`updateModelId`,index:t,value:e.target.value}),placeholder:n.modelIdPlaceholder,className:l(`flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,w)}),b.length>1?(0,$.jsx)(`button`,{type:`button`,onClick:()=>s({type:`removeModelSlot`,index:t}),className:l(`rounded-lg p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,K.press),children:(0,$.jsx)(je,{className:`size-3.5`,"aria-hidden":!0})}):null]},e||`model-slot-${t}`)),(0,$.jsxs)(H,{type:`button`,variant:`ghost`,className:`w-fit gap-1.5 text-fg-muted`,onClick:()=>s({type:`addModelSlot`}),children:[(0,$.jsx)(V,{className:`size-3.5`,"aria-hidden":!0}),n.addModel]})]}),x?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:x}):null]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t border-edge-subtle px-5 py-3`,children:[(0,$.jsx)(H,{type:`button`,variant:`secondary`,onClick:i,children:n.cancel}),(0,$.jsx)(H,{type:`button`,variant:`primary`,disabled:!D||c,onClick:()=>void S(),children:c?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(W,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),n.saving]}):n.save})]})]})}function Gn(){let e=(0,Z.c)(31),t=d(Xn),n=!!t,{data:r,isLoading:i}=xe(n),a;e[0]===n?a=e[1]:(a=n?m(`/api/providers/meta`):null,e[0]=n,e[1]=a);let o;e[2]===t?o=e[3]:(o=async e=>{let{payload:n}=await(await fetch(e,{headers:{Authorization:`Bearer ${t}`}})).json();return n?.providers??[]},e[2]=t,e[3]=o);let s;e[4]===Symbol.for(`react.memo_cache_sentinel`)?(s={revalidateOnFocus:!1},e[4]=s):s=e[4];let{data:c,isLoading:l}=g(a,o,s),u;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(u={revalidateOnFocus:!1},e[5]=u):u=e[5];let{data:f,isLoading:p}=g(n?M:null,Yn,u),h;e[6]===f?h=e[7]:(h=f===void 0?[]:f,e[6]=f,e[7]=h);let _=h,v;e[8]===Symbol.for(`react.memo_cache_sentinel`)?(v={revalidateOnFocus:!1},e[8]=v):v=e[8];let{data:b}=g(n?N:null,Jn,v),x;bb0:{if(!c||r===void 0){let t;e[9]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[9]=t):t=e[9],x=t;break bb0}let t;e[10]!==r?.payload?.config||e[11]!==c||e[12]!==_?(t=ie(c,y(r?.payload?.config),_),e[10]=r?.payload?.config,e[11]=c,e[12]=_,e[13]=t):t=e[13],x=t}let C=x,w;bb1:{if(!b){w=null;break bb1}let t;e[14]===b.config?t=e[15]:(t=S(b.config),e[14]=b.config,e[15]=t),w=t}let T=w,E;if(e[16]!==C||e[17]!==T||e[18]!==c||e[19]!==_){E=[];let t=new Set((c??[]).filter(qn).map(Kn)),n;e[21]===T?n=e[22]:(n=new Set(T?Object.keys(T.providers):[]),e[21]=T,e[22]=n);let r=n;for(let e of C){if(!t.has(e.id))continue;let n=r.has(e.id),i=n?T.providers[e.id]?.models?.length??0:_.filter(t=>t.provider===e.id).length;E.push({id:e.id,name:e.name,configured:!0,isCustom:n,modelCount:i})}if(T){let t;e[23]===T.providers?t=e[24]:(t=Object.entries(T.providers),e[23]=T.providers,e[24]=t);for(let[e,n]of t)E.some(t=>t.id===e)||E.push({id:e,name:e,configured:!0,isCustom:!0,modelCount:n.models?.length??0})}e[16]=C,e[17]=T,e[18]=c,e[19]=_,e[20]=E}else E=e[20];let D=E,O=i||l||p,k;return e[25]!==C||e[26]!==D||e[27]!==T||e[28]!==O||e[29]!==_?(k={cards:D,loading:O,builtinRows:C,customConfig:T,allModels:_},e[25]=C,e[26]=D,e[27]=T,e[28]=O,e[29]=_,e[30]=k):k=e[30],k}function Kn(e){return e.id}function qn(e){return e.configured}function Jn(){return ae()}function Yn(){return I()}function Xn(e){return e.token}function Zn(e){let t=(0,Z.c)(16),{labels:n,onAdd:r,onManage:i}=e,{cards:a,loading:o}=Gn();if(o){let e;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(U,{className:`h-6 w-48 max-w-full`}),t[0]=e):e=t[0];let n;return t[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,"aria-busy":`true`,children:[e,(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:[1,2,3].map($n)})]}),t[1]=n):n=t[1],n}let s;if(t[2]!==a||t[3]!==n||t[4]!==r||t[5]!==i){let e=a.filter(Qn),o=e.length>0?n.titleCount.replace(`{{count}}`,String(e.length)):n.title,c;t[7]===o?c=t[8]:(c=(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:o}),t[7]=o,t[8]=c);let l;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(V,{className:`size-3.5`,strokeWidth:2,"aria-hidden":!0}),t[9]=l):l=t[9];let u;t[10]!==n.addProvider||t[11]!==r?(u=(0,$.jsxs)(H,{type:`button`,variant:`primary`,className:`gap-1.5`,onClick:r,children:[l,n.addProvider]}),t[10]=n.addProvider,t[11]=r,t[12]=u):u=t[12];let d;t[13]!==c||t[14]!==u?(d=(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[c,u]}),t[13]=c,t[14]=u,t[15]=d):d=t[15],s=(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[d,e.length===0?(0,$.jsxs)(`div`,{className:`rounded-2xl bg-surface-panel/60 px-6 py-10 text-center shadow-surface`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:n.empty}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.emptyHint}),(0,$.jsxs)(H,{type:`button`,variant:`primary`,className:`mt-4 gap-1.5`,onClick:r,children:[(0,$.jsx)(V,{className:`size-3.5`,strokeWidth:2,"aria-hidden":!0}),n.addProvider]})]}):(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:e.map(e=>(0,$.jsx)(er,{card:e,labels:n,onManage:()=>i(e.id,e.isCustom)},e.id))})]}),t[2]=a,t[3]=n,t[4]=r,t[5]=i,t[6]=s}else s=t[6];return s}function Qn(e){return e.configured}function $n(e){return(0,$.jsx)(U,{className:`h-32 rounded-2xl`},e)}function er(e){let t=(0,Z.c)(28),{card:n,labels:r,onManage:i}=e,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=l(`group relative flex flex-col justify-between rounded-2xl bg-surface-base p-4 text-left shadow-surface transition-colors`,`hover:bg-surface-hover/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,K.pressCard),t[0]=a):a=t[0];let o;t[1]===n.name?o=t[2]:(o=(0,$.jsx)(`span`,{className:`truncate text-sm font-semibold text-fg`,children:n.name}),t[1]=n.name,t[2]=o);let s;t[3]!==n.isCustom||t[4]!==r.custom?(s=n.isCustom?(0,$.jsx)(`span`,{className:`shrink-0 rounded bg-surface-hover px-1.5 py-0.5 text-[10px] font-medium text-fg-subtle`,children:r.custom}):null,t[3]=n.isCustom,t[4]=r.custom,t[5]=s):s=t[5];let c;t[6]!==o||t[7]!==s?(c=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[o,s]}),t[6]=o,t[7]=s,t[8]=c):c=t[8];let u;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,$.jsx)(Ve,{className:`size-4 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}),t[9]=u):u=t[9];let d;t[10]===c?d=t[11]:(d=(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[c,u]}),t[10]=c,t[11]=d);let f;t[12]!==n.modelCount||t[13]!==r.modelsCount||t[14]!==r.noModels?(f=n.modelCount>0?r.modelsCount.replace(`{{count}}`,String(n.modelCount)):r.noModels,t[12]=n.modelCount,t[13]=r.modelsCount,t[14]=r.noModels,t[15]=f):f=t[15];let p;t[16]===f?p=t[17]:(p=(0,$.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:f}),t[16]=f,t[17]=p);let m;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)(Ee,{className:`size-3`,"aria-hidden":!0}),t[18]=m):m=t[18];let h;t[19]===r.manage?h=t[20]:(h=(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-xs font-medium text-accent-fg opacity-0 transition-opacity group-hover:opacity-100`,children:[m,r.manage]}),t[19]=r.manage,t[20]=h);let g;t[21]!==h||t[22]!==p?(g=(0,$.jsxs)(`div`,{className:`mt-2.5 flex items-center justify-between`,children:[p,h]}),t[21]=h,t[22]=p,t[23]=g):g=t[23];let _;return t[24]!==i||t[25]!==g||t[26]!==d?(_=(0,$.jsxs)(`button`,{type:`button`,onClick:i,className:a,children:[d,g]}),t[24]=i,t[25]=g,t[26]=d,t[27]=_):_=t[27],_}function tr(e){let t=(0,Z.c)(156),{model:n,isNew:r,providerId:i,onSave:a,onClose:o,m:s}=e,c;t[0]===n?c=t[1]:(c=()=>n?{...n}:we(``),t[0]=n,t[1]=c);let[u,d]=(0,Q.useState)(c),[f,p]=(0,Q.useState)(nr),m;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(m=(e,t)=>{d(n=>({...n,[e]:t})),p(t=>{let n=new Map(t);return n.delete(e),n})},t[2]=m):m=t[2];let h=m,g;t[3]!==u.contextWindow||t[4]!==u.id||t[5]!==u.maxTokens||t[6]!==s.modelIdRequired||t[7]!==s.mustBePositive?(g=()=>{let e=new Map;return(u.id||``).trim()||e.set(`id`,s.modelIdRequired),u.contextWindow!==void 0&&u.contextWindow<=0&&e.set(`contextWindow`,s.mustBePositive),u.maxTokens!==void 0&&u.maxTokens<=0&&e.set(`maxTokens`,s.mustBePositive),p(e),e.size===0},t[3]=u.contextWindow,t[4]=u.id,t[5]=u.maxTokens,t[6]=s.modelIdRequired,t[7]=s.mustBePositive,t[8]=g):g=t[8];let _=g,v;t[9]!==u||t[10]!==o||t[11]!==a||t[12]!==_?(v=()=>{if(!_())return;let e=(u.id||``).trim();a({...u,id:e,name:u.name?.trim()||e,reasoning:u.reasoning||!1,input:u.input||[`text`],contextWindow:u.contextWindow??128e3,maxTokens:u.maxTokens??16384,cost:{input:u.cost?.input??0,output:u.cost?.output??0,cacheRead:u.cost?.cacheRead??0,cacheWrite:u.cost?.cacheWrite??0}}),o()},t[9]=u,t[10]=o,t[11]=a,t[12]=_,t[13]=v):v=t[13];let y=v,b=u,x;t[14]===b?x=t[15]:(x=Ae(b),t[14]=b,t[15]=x);let S=x,C=r?s.addModelTitle:s.editModelTitle,w;t[16]===C?w=t[17]:(w=(0,$.jsx)(me,{className:`text-base font-semibold text-fg`,children:C}),t[16]=C,t[17]=w);let T;t[18]!==s.modelProviderLabel||t[19]!==i?(T=i?(0,$.jsxs)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:[s.modelProviderLabel,`: `,i]}):null,t[18]=s.modelProviderLabel,t[19]=i,t[20]=T):T=t[20];let E;t[21]!==w||t[22]!==T?(E=(0,$.jsxs)(`div`,{children:[w,T]}),t[21]=w,t[22]=T,t[23]=E):E=t[23];let D;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(D=l(Ge,`p-1.5 hover:bg-surface-base`),t[24]=D):D=t[24];let O;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,$.jsx)(je,{className:`size-4`}),t[25]=O):O=t[25];let k;t[26]===s.close?k=t[27]:(k=(0,$.jsx)(Ye,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:D,"aria-label":s.close,children:O})}),t[26]=s.close,t[27]=k);let A;t[28]!==E||t[29]!==k?(A=(0,$.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[E,k]}),t[28]=E,t[29]=k,t[30]=A):A=t[30];let j;t[31]===Symbol.for(`react.memo_cache_sentinel`)?(j=(0,$.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`}),t[31]=j):j=t[31];let M;t[32]===s.modelId?M=t[33]:(M=(0,$.jsxs)(`label`,{className:`mb-1 block text-xs font-medium text-fg`,children:[s.modelId,j]}),t[32]=s.modelId,t[33]=M);let N;t[34]===f?N=t[35]:(N=l(te(),f.has(`id`)&&`border-red-500`),t[34]=f,t[35]=N);let P=u.id||``,F;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(F=e=>h(`id`,e.target.value),t[36]=F):F=t[36];let I=!r,L;t[37]!==N||t[38]!==P||t[39]!==I?(L=(0,$.jsx)(`input`,{className:N,value:P,onChange:F,placeholder:`e.g. llama3.1:8b`,disabled:I}),t[37]=N,t[38]=P,t[39]=I,t[40]=L):L=t[40];let R;t[41]===f?R=t[42]:(R=f.has(`id`)?(0,$.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:f.get(`id`)}):null,t[41]=f,t[42]=R);let z;t[43]!==M||t[44]!==L||t[45]!==R?(z=(0,$.jsxs)(`div`,{children:[M,L,R]}),t[43]=M,t[44]=L,t[45]=R,t[46]=z):z=t[46];let B;t[47]===s.displayName?B=t[48]:(B=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.displayName}),t[47]=s.displayName,t[48]=B);let V;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(V=te(),t[49]=V):V=t[49];let ne=u.name||``,re;t[50]===Symbol.for(`react.memo_cache_sentinel`)?(re=e=>h(`name`,e.target.value),t[50]=re):re=t[50];let U;t[51]===ne?U=t[52]:(U=(0,$.jsx)(`input`,{className:V,value:ne,onChange:re}),t[51]=ne,t[52]=U);let W;t[53]!==B||t[54]!==U?(W=(0,$.jsxs)(`div`,{children:[B,U]}),t[53]=B,t[54]=U,t[55]=W):W=t[55];let ie;t[56]===s.inputTypes?ie=t[57]:(ie=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.inputTypes}),t[56]=s.inputTypes,t[57]=ie);let G;t[58]===Symbol.for(`react.memo_cache_sentinel`)?(G=ee(),t[58]=G):G=t[58];let ae;t[59]===Symbol.for(`react.memo_cache_sentinel`)?(ae=e=>h(`input`,Pe(e.target.value)),t[59]=ae):ae=t[59];let K;t[60]===s?K=t[61]:(K=oe.map(e=>(0,$.jsx)(Y,{value:e.value,children:s[e.labelKey]},e.value)),t[60]=s,t[61]=K);let q;t[62]!==S||t[63]!==K?(q=(0,$.jsx)(X,{className:G,value:S,onChange:ae,children:K}),t[62]=S,t[63]=K,t[64]=q):q=t[64];let J;t[65]!==ie||t[66]!==q?(J=(0,$.jsxs)(`div`,{children:[ie,q]}),t[65]=ie,t[66]=q,t[67]=J):J=t[67];let se=u.reasoning||!1,ce;t[68]===Symbol.for(`react.memo_cache_sentinel`)?(ce=e=>h(`reasoning`,e.target.checked),t[68]=ce):ce=t[68];let le;t[69]===se?le=t[70]:(le=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:se,onChange:ce}),t[69]=se,t[70]=le);let ue;t[71]!==s.reasoning||t[72]!==le?(ue=(0,$.jsxs)(`label`,{className:`mt-6 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[le,s.reasoning]}),t[71]=s.reasoning,t[72]=le,t[73]=ue):ue=t[73];let de;t[74]!==J||t[75]!==ue?(de=(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[J,ue]}),t[74]=J,t[75]=ue,t[76]=de):de=t[76];let fe;t[77]===s.contextWindow?fe=t[78]:(fe=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.contextWindow}),t[77]=s.contextWindow,t[78]=fe);let pe;t[79]===f?pe=t[80]:(pe=l(te(),f.has(`contextWindow`)&&`border-red-500`),t[79]=f,t[80]=pe);let he=u.contextWindow??128e3,ge;t[81]===Symbol.for(`react.memo_cache_sentinel`)?(ge=e=>h(`contextWindow`,parseInt(e.target.value,10)||0),t[81]=ge):ge=t[81];let _e;t[82]!==pe||t[83]!==he?(_e=(0,$.jsx)(`input`,{type:`number`,min:1,className:pe,value:he,onChange:ge}),t[82]=pe,t[83]=he,t[84]=_e):_e=t[84];let ve;t[85]===f?ve=t[86]:(ve=f.has(`contextWindow`)?(0,$.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:f.get(`contextWindow`)}):null,t[85]=f,t[86]=ve);let ye;t[87]!==fe||t[88]!==_e||t[89]!==ve?(ye=(0,$.jsxs)(`div`,{children:[fe,_e,ve]}),t[87]=fe,t[88]=_e,t[89]=ve,t[90]=ye):ye=t[90];let be;t[91]===s.maxOutputTokens?be=t[92]:(be=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.maxOutputTokens}),t[91]=s.maxOutputTokens,t[92]=be);let xe;t[93]===f?xe=t[94]:(xe=l(te(),f.has(`maxTokens`)&&`border-red-500`),t[93]=f,t[94]=xe);let Se=u.maxTokens??16384,Ce;t[95]===Symbol.for(`react.memo_cache_sentinel`)?(Ce=e=>h(`maxTokens`,parseInt(e.target.value,10)||0),t[95]=Ce):Ce=t[95];let Te;t[96]!==xe||t[97]!==Se?(Te=(0,$.jsx)(`input`,{type:`number`,min:1,className:xe,value:Se,onChange:Ce}),t[96]=xe,t[97]=Se,t[98]=Te):Te=t[98];let Ee;t[99]===f?Ee=t[100]:(Ee=f.has(`maxTokens`)?(0,$.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:f.get(`maxTokens`)}):null,t[99]=f,t[100]=Ee);let De;t[101]!==be||t[102]!==Te||t[103]!==Ee?(De=(0,$.jsxs)(`div`,{children:[be,Te,Ee]}),t[101]=be,t[102]=Te,t[103]=Ee,t[104]=De):De=t[104];let Oe;t[105]!==ye||t[106]!==De?(Oe=(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[ye,De]}),t[105]=ye,t[106]=De,t[107]=Oe):Oe=t[107];let ke;t[108]===s.costSection?ke=t[109]:(ke=(0,$.jsx)(`p`,{className:`mb-2 text-xs font-semibold text-fg`,children:s.costSection}),t[108]=s.costSection,t[109]=ke);let Me;t[110]===s.costInput?Me=t[111]:(Me=(0,$.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:s.costInput}),t[110]=s.costInput,t[111]=Me);let Ne;t[112]===Symbol.for(`react.memo_cache_sentinel`)?(Ne=te(),t[112]=Ne):Ne=t[112];let Fe=u.cost?.input??0,Ie;t[113]===u.cost?Ie=t[114]:(Ie=e=>h(`cost`,{...u.cost,input:parseFloat(e.target.value)||0,output:u.cost?.output??0,cacheRead:u.cost?.cacheRead??0,cacheWrite:u.cost?.cacheWrite??0}),t[113]=u.cost,t[114]=Ie);let Le;t[115]!==Fe||t[116]!==Ie?(Le=(0,$.jsx)(`input`,{type:`number`,step:`any`,min:0,className:Ne,value:Fe,onChange:Ie}),t[115]=Fe,t[116]=Ie,t[117]=Le):Le=t[117];let Re;t[118]!==Me||t[119]!==Le?(Re=(0,$.jsxs)(`div`,{children:[Me,Le]}),t[118]=Me,t[119]=Le,t[120]=Re):Re=t[120];let ze;t[121]===s.costOutput?ze=t[122]:(ze=(0,$.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:s.costOutput}),t[121]=s.costOutput,t[122]=ze);let Be;t[123]===Symbol.for(`react.memo_cache_sentinel`)?(Be=te(),t[123]=Be):Be=t[123];let Ve=u.cost?.output??0,He;t[124]===u.cost?He=t[125]:(He=e=>h(`cost`,{...u.cost,input:u.cost?.input??0,output:parseFloat(e.target.value)||0,cacheRead:u.cost?.cacheRead??0,cacheWrite:u.cost?.cacheWrite??0}),t[124]=u.cost,t[125]=He);let Ue;t[126]!==Ve||t[127]!==He?(Ue=(0,$.jsx)(`input`,{type:`number`,step:`any`,min:0,className:Be,value:Ve,onChange:He}),t[126]=Ve,t[127]=He,t[128]=Ue):Ue=t[128];let We;t[129]!==ze||t[130]!==Ue?(We=(0,$.jsxs)(`div`,{children:[ze,Ue]}),t[129]=ze,t[130]=Ue,t[131]=We):We=t[131];let Ke;t[132]!==Re||t[133]!==We?(Ke=(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[Re,We]}),t[132]=Re,t[133]=We,t[134]=Ke):Ke=t[134];let qe;t[135]!==ke||t[136]!==Ke?(qe=(0,$.jsxs)(`div`,{className:`border-t border-edge-subtle pt-2 dark:border-edge`,children:[ke,Ke]}),t[135]=ke,t[136]=Ke,t[137]=qe):qe=t[137];let Je;t[138]!==z||t[139]!==W||t[140]!==de||t[141]!==Oe||t[142]!==qe?(Je=(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[z,W,de,Oe,qe]}),t[138]=z,t[139]=W,t[140]=de,t[141]=Oe,t[142]=qe,t[143]=Je):Je=t[143];let Xe;t[144]===s.cancel?Xe=t[145]:(Xe=(0,$.jsx)(Ye,{asChild:!0,children:(0,$.jsx)(H,{type:`button`,variant:`secondary`,children:s.cancel})}),t[144]=s.cancel,t[145]=Xe);let Ze=r?s.addModelConfirm:s.saveModelConfirm,Qe;t[146]!==y||t[147]!==Ze?(Qe=(0,$.jsx)(H,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:y,children:Ze}),t[146]=y,t[147]=Ze,t[148]=Qe):Qe=t[148];let $e;t[149]!==Xe||t[150]!==Qe?($e=(0,$.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2 border-t border-edge-subtle pt-3 dark:border-edge`,children:[Xe,Qe]}),t[149]=Xe,t[150]=Qe,t[151]=$e):$e=t[151];let et;return t[152]!==A||t[153]!==Je||t[154]!==$e?(et=(0,$.jsxs)($.Fragment,{children:[A,Je,$e]}),t[152]=A,t[153]=Je,t[154]=$e,t[155]=et):et=t[155],et}function nr(){return new Map}function rr(e){let t=(0,Z.c)(16),{open:n,onOpenChange:r,providerId:i,model:a,isNew:o,onSave:s,m:c}=e,u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,$.jsx)(P,{className:l(`xopc-dialog-overlay fixed inset-0 bg-scrim`,Fe)}),t[0]=u):u=t[0];let d;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(d=l(`xopc-dialog-content fixed left-1/2 top-1/2 max-h-[min(90vh,720px)] w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2`,Te,`overflow-y-auto rounded-xl border border-edge bg-surface-panel p-4 shadow-popover dark:border-edge`),t[1]=d):d=t[1];let f;t[2]!==o||t[3]!==c||t[4]!==a||t[5]!==r||t[6]!==s||t[7]!==n||t[8]!==i?(f=n?(0,$.jsx)(tr,{model:a,isNew:o,providerId:i,onSave:s,onClose:()=>r(!1),m:c},`${i??`none`}-${a?.id??`new`}`):null,t[2]=o,t[3]=c,t[4]=a,t[5]=r,t[6]=s,t[7]=n,t[8]=i,t[9]=f):f=t[9];let p;t[10]===f?p=t[11]:(p=(0,$.jsxs)(se,{children:[u,(0,$.jsx)(b,{className:d,onOpenAutoFocus:ir,children:f})]}),t[10]=f,t[11]=p);let m;return t[12]!==r||t[13]!==n||t[14]!==p?(m=(0,$.jsx)(G,{open:n,onOpenChange:r,children:p}),t[12]=r,t[13]=n,t[14]=p,t[15]=m):m=t[15],m}function ir(e){return e.preventDefault()}function ar(e){let t=(0,Z.c)(14),{providerId:n,inputId:r,value:i,onChange:a,labels:o}=e,s;t[0]===n?s=t[1]:(s=()=>ue(n).then(or),t[0]=n,t[1]=s);let c=s,l;t[2]!==r||t[3]!==o.apiKeyLabel?(l=(0,$.jsx)(`label`,{htmlFor:r,className:`text-sm font-medium text-fg`,children:o.apiKeyLabel}),t[2]=r,t[3]=o.apiKeyLabel,t[4]=l):l=t[4];let u;t[5]!==r||t[6]!==o||t[7]!==a||t[8]!==c||t[9]!==i?(u=(0,$.jsx)(qe,{id:r,value:i,onChange:a,placeholder:o.apiKeyPlaceholder,labels:o,reveal:c,loadFailedLabel:o.loadFailed,maskedHelp:o.maskedHelp,notInConfigFile:o.notInConfigFile}),t[5]=r,t[6]=o,t[7]=a,t[8]=c,t[9]=i,t[10]=u):u=t[10];let d;return t[11]!==l||t[12]!==u?(d=(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[l,u]}),t[11]=l,t[12]=u,t[13]=d):d=t[13],d}function or(e){return e.apiKey??null}function sr(e){let t=(0,Z.c)(16),{open:n,onOpenChange:r,providerId:i,isCustom:a,builtinRows:o,customConfig:s,allModels:c,labels:u,language:d,onSaved:f}=e,p;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(P,{className:l(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,Fe)}),t[0]=p):p=t[0];let m;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(m=l(`fixed left-1/2 top-1/2 flex max-h-[85vh] w-[calc(100%-2rem)] max-w-lg -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-2xl border border-edge-subtle bg-surface-base shadow-xl`,Te),t[1]=m):m=t[1];let h;t[2]!==c||t[3]!==o||t[4]!==s||t[5]!==a||t[6]!==u||t[7]!==d||t[8]!==r||t[9]!==f||t[10]!==i?(h=(0,$.jsxs)(se,{children:[p,(0,$.jsx)(b,{className:m,children:i===`xopc-cloud`?(0,$.jsx)(cr,{allModels:c,labels:u,language:d,onSaved:f}):a?(0,$.jsx)(fr,{providerId:i,customConfig:s,labels:u,language:d,onClose:()=>r(!1),onSaved:f}):(0,$.jsx)(dr,{providerId:i,builtinRows:o,allModels:c,labels:u,language:d,onClose:()=>r(!1),onSaved:f})})]}),t[2]=c,t[3]=o,t[4]=s,t[5]=a,t[6]=u,t[7]=d,t[8]=r,t[9]=f,t[10]=i,t[11]=h):h=t[11];let g;return t[12]!==r||t[13]!==n||t[14]!==h?(g=(0,$.jsx)(G,{open:n,onOpenChange:r,children:h}),t[12]=r,t[13]=n,t[14]=h,t[15]=g):g=t[15],g}function cr(e){let t=(0,Z.c)(33),{allModels:n,labels:r,language:i,onSaved:a}=e,o;t[0]===n?o=t[1]:(o=n.filter(ur).sort(lr),t[0]=n,t[1]=o);let s=o,c=i===`zh`,u;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,$.jsx)(me,{className:`text-base font-semibold text-fg`,children:`XOPC Model Service`}),t[2]=u):u=t[2];let d=c?`当前可使用 ${s.length} 个模型`:`${s.length} models available`,f;t[3]===d?f=t[4]:(f=(0,$.jsxs)(`div`,{className:`min-w-0`,children:[u,(0,$.jsx)(de,{className:`mt-0.5 text-xs text-fg-muted`,children:d})]}),t[3]=d,t[4]=f);let p;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(p=l(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,K.press),t[5]=p):p=t[5];let m;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)(je,{className:`size-4`,"aria-hidden":!0}),t[6]=m):m=t[6];let h;t[7]===r.close?h=t[8]:(h=(0,$.jsx)(Ye,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:p,"aria-label":r.close,children:m})}),t[7]=r.close,t[8]=h);let g;t[9]!==f||t[10]!==h?(g=(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-edge-subtle px-5 py-4`,children:[f,h]}),t[9]=f,t[10]=h,t[11]=g):g=t[11];let _;t[12]===a?_=t[13]:(_=(0,$.jsx)(re,{connected:!0,onConnected:a}),t[12]=a,t[13]=_);let v=c?`可用模型`:`Available models`,y;t[14]===v?y=t[15]:(y=(0,$.jsx)(`h3`,{id:`xopc-cloud-models-heading`,className:`text-sm font-medium text-fg`,children:v}),t[14]=v,t[15]=y);let b;t[16]===s.length?b=t[17]:(b=(0,$.jsx)(`span`,{className:`text-xs tabular-nums text-fg-subtle`,children:s.length}),t[16]=s.length,t[17]=b);let x;t[18]!==y||t[19]!==b?(x=(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[y,b]}),t[18]=y,t[19]=b,t[20]=x):x=t[20];let S;t[21]!==s||t[22]!==c?(S=s.length>0?(0,$.jsx)(`div`,{className:`divide-y divide-edge-subtle overflow-hidden rounded-xl border border-edge-subtle bg-surface-panel/40`,children:s.map(e=>{let t=e.id.includes(`/`)?e.id.split(`/`).pop():e.id;return(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-3 px-3 py-3`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,$.jsx)(`span`,{className:`truncate text-sm font-medium text-fg`,children:e.name||t}),e.recommended?(0,$.jsx)(`span`,{className:`rounded-md bg-accent/10 px-1.5 py-0.5 text-[10px] font-medium text-accent-fg`,children:c?`推荐`:`Recommended`}):null]}),(0,$.jsx)(`code`,{className:`mt-1 block truncate text-xs text-fg-subtle`,children:t})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap justify-end gap-1`,children:[e.reasoning?(0,$.jsx)(`span`,{className:`rounded-md bg-surface-hover px-1.5 py-0.5 text-[10px] text-fg-muted`,children:c?`思考`:`Reasoning`}):null,e.vision?(0,$.jsx)(`span`,{className:`rounded-md bg-surface-hover px-1.5 py-0.5 text-[10px] text-fg-muted`,children:c?`视觉`:`Vision`}):null]})]},e.id)})}):(0,$.jsx)(`div`,{className:`flex items-center justify-center rounded-xl border border-dashed border-edge px-4 py-8 text-center text-sm text-fg-muted`,children:c?`暂未同步到可用模型,请重新连接后再试。`:`No models are available yet. Reconnect and try again.`}),t[21]=s,t[22]=c,t[23]=S):S=t[23];let C;t[24]!==x||t[25]!==S?(C=(0,$.jsxs)(`section`,{className:`flex min-h-0 flex-col gap-2`,"aria-labelledby":`xopc-cloud-models-heading`,children:[x,S]}),t[24]=x,t[25]=S,t[26]=C):C=t[26];let w;t[27]!==C||t[28]!==_?(w=(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-col gap-4 overflow-y-auto px-5 py-4`,children:[_,C]}),t[27]=C,t[28]=_,t[29]=w):w=t[29];let T;return t[30]!==w||t[31]!==g?(T=(0,$.jsxs)(`div`,{className:`flex min-h-0 flex-col`,children:[g,w]}),t[30]=w,t[31]=g,t[32]=T):T=t[32],T}function lr(e,t){return Number(t.recommended===!0)-Number(e.recommended===!0)||e.name.localeCompare(t.name)}function ur(e){return e.provider===`xopc-cloud`}function dr({providerId:e,builtinRows:t,allModels:n,labels:r,language:i,onClose:a,onSaved:o}){let c=t.find(t=>t.id===e),d=Ze[e],f=n.filter(t=>t.provider===e),[p,m]=(0,Q.useState)(c?.apiKey??``),[h,g]=(0,Q.useState)(!1),[_,v]=(0,Q.useState)(!1),[y,b]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(!1),T=u(i).providersSettings,E=c?.supportsApiKey!==!1,D=c?.supportsOAuth===!0,O=c?.authMode===`oauth`&&c.authStatus===`connected`,A=c?.configured===!0&&c.activeKeySource!==`env`&&c.activeKeySource!==`extension`&&c.activeKeySource!==`models_json`,[j,M]=(0,Q.useState)(null),[N,P]=(0,Q.useState)(null),[F,I]=(0,Q.useState)(`idle`),[R,z]=(0,Q.useState)(null),[B,ee]=(0,Q.useState)(null),[V,te]=(0,Q.useState)(``),ne=F===`waiting`||F===`waiting_code`,re=(0,Q.useMemo)(()=>x(e,i),[e,i]),U=p!==(c?.apiKey??``),ie=async()=>{let t=p.trim();if(!(!t||!E||L(t))){g(!0),b(null);try{await Je({[e]:t}),v(!0),window.setTimeout(()=>{o(),a()},600)}catch(e){b(e instanceof Error?e.message:r.saveError)}finally{g(!1)}}};(0,Q.useEffect)(()=>{if(!j||!ne)return;let e=window.setInterval(()=>{(async()=>{try{let t=await kn(j);t.status===`waiting_auth`||t.status===`waiting_code`?(I(t.status===`waiting_code`?`waiting_code`:`waiting`),P(t.message??null),z(t.authUrl??null),ee(t.instructions??null)):t.status===`completed`?(window.clearInterval(e),I(`success`),P(t.message??T.saved),window.setTimeout(()=>{o(),a()},600)):(t.status===`failed`||t.status===`cancelled`)&&(window.clearInterval(e),I(`error`),P(t.error??t.message??T.revokeFailed))}catch{}})()},1e3);return()=>window.clearInterval(e)},[j,ne,a,o,T.revokeFailed,T.saved]),(0,Q.useEffect)(()=>()=>{j&&Mn(j).catch(()=>{})},[j]);let G=async()=>{try{await k(e),o(),a()}catch{}},ae=async()=>{I(`waiting`),P(T.oauthStarting),b(null);try{M((await On(e)).sessionId)}catch(e){I(`error`),P(e instanceof Error?e.message:T.revokeFailed)}},oe=async()=>{if(j){try{await jn(j)}catch{}I(`idle`),P(null),M(null),z(null),ee(null)}},q=async()=>{if(!(!j||!V.trim()))try{await An(j,V.trim()),te(``),P(T.oauthProcessingCode)}catch(e){I(`error`),P(e instanceof Error?e.message:T.revokeFailed)}},J=async()=>{try{await Nn(e),o(),a()}catch(e){b(e instanceof Error?e.message:T.revokeFailed)}};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-edge-subtle px-5 py-4`,children:[(0,$.jsx)(me,{className:`text-base font-semibold text-fg`,children:c?.name??e}),(0,$.jsx)(Ye,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:l(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,K.press),children:(0,$.jsx)(je,{className:`size-4`,"aria-hidden":!0})})})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 overflow-y-auto px-5 py-4`,children:[d?.description?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:d.description}):null,c?.baseUrl?(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:r.apiUrlLabel}),(0,$.jsx)(`code`,{className:`break-all rounded-lg border border-edge-subtle bg-surface-panel/60 px-3 py-2 font-mono text-xs text-fg-muted`,children:c.baseUrl})]}):c?.category===`extension`?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:r.apiUrlExtensionHint}):null,E?(0,$.jsx)(ar,{providerId:e,inputId:`manage-api-key`,value:p,onChange:e=>{m(e),v(!1)},labels:{apiKeyLabel:r.apiKeyLabel,apiKeyPlaceholder:r.apiKeyPlaceholder,maskedHelp:r.maskedHelp,copy:r.copy,copied:r.copied,show:r.showKey,hide:r.hideKey,notInConfigFile:r.notInConfigFile,loadFailed:r.loadFailed}}):c?.category===`extension`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-lg border border-edge-subtle bg-surface-panel/60 px-3 py-2 text-sm text-fg-muted`,children:[(0,$.jsx)(`p`,{children:r.extensionKeyHint}),c?.extensionId?(0,$.jsxs)(s,{to:`/settings/ext/${encodeURIComponent(c.extensionId)}`,className:`inline-flex w-fit items-center gap-1 font-medium text-accent hover:underline`,title:r.extensionSettingsLinkTitle,onClick:a,children:[r.openExtensionSettings,(0,$.jsx)(le,{className:`size-3`,"aria-hidden":!0})]}):null]}):null,D?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-lg border border-edge-subtle bg-surface-panel/60 p-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:T.oauth}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:O?T.sourceOauth:T.oauthHint})]}),O?(0,$.jsx)(H,{type:`button`,variant:`secondary`,className:`gap-1.5 text-red-600 dark:text-red-400`,onClick:()=>void J(),children:T.revoke}):(0,$.jsxs)(H,{type:`button`,variant:`primary`,className:`gap-1.5`,disabled:ne,onClick:()=>void ae(),children:[ne?(0,$.jsx)(W,{className:`size-3.5 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(_e,{className:`size-3.5`,"aria-hidden":!0}),T.oauth]})]}),N?(0,$.jsx)(`p`,{className:l(`text-xs`,F===`error`?`text-red-600 dark:text-red-400`:`text-fg-muted`),children:N}):null,F===`waiting`||F===`waiting_code`?(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[R?(0,$.jsxs)(`a`,{href:R,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1.5 rounded-md bg-accent px-3 py-2 text-sm font-medium text-white hover:bg-accent-hover`,children:[(0,$.jsx)(le,{className:`size-4`,"aria-hidden":!0}),T.openAuthPage]}):null,(0,$.jsx)(H,{type:`button`,variant:`secondary`,onClick:()=>void oe(),children:T.cancelOAuth})]}):null,B?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:B}):null,F===`waiting_code`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,$.jsx)(`input`,{type:`text`,value:V,onChange:e=>te(e.target.value),onKeyDown:e=>e.key===`Enter`&&void q(),placeholder:T.pasteRedirectUrl,className:l(`min-w-0 flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,w)}),(0,$.jsx)(H,{type:`button`,variant:`primary`,onClick:()=>void q(),children:T.submitCode})]}):null]}):null,re.length>0&&E?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:re.map(({kind:e,href:t})=>(0,$.jsxs)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent hover:underline`,children:[fe(e,r),(0,$.jsx)(le,{className:`size-3`,"aria-hidden":!0})]},e))}):null,f.length>0?(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsxs)(`span`,{className:`text-sm font-medium text-fg`,children:[r.modelsLabel,` (`,f.length,`)`]}),(0,$.jsx)(`div`,{className:`max-h-40 overflow-y-auto rounded-lg border border-edge-subtle bg-surface-panel/40 p-2`,children:(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:f.map(e=>(0,$.jsx)(`span`,{className:`inline-block rounded-md bg-surface-hover px-2 py-1 text-xs text-fg-muted`,children:e.id.includes(`/`)?e.id.split(`/`).pop():e.id},e.id))})})]}):(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:r.noModels}),y?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:y}):null]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-t border-edge-subtle px-5 py-3`,children:[A?(0,$.jsxs)(H,{type:`button`,variant:`ghost`,className:`gap-1.5 text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300`,onClick:()=>C(!0),children:[(0,$.jsx)(he,{className:`size-3.5`,"aria-hidden":!0}),r.remove]}):(0,$.jsx)(`span`,{}),(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:E&&U&&!L(p.trim())?(0,$.jsx)(H,{type:`button`,variant:`primary`,disabled:!p.trim()||h||_,onClick:()=>void ie(),children:_?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(Ve,{className:`size-3.5`,"aria-hidden":!0}),r.saved]}):h?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(W,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),r.saving]}):r.save}):null})]}),(0,$.jsx)(ve,{open:S,title:r.removeConfirmTitle,description:r.removeConfirmDescription.replace(`{{provider}}`,c?.name??e),confirmLabel:r.removeConfirmAction,cancelLabel:r.cancel,destructive:!0,onConfirm:()=>void G(),onCancel:()=>C(!1)})]})}function fr({providerId:e,customConfig:t,labels:n,language:r,onClose:i,onSaved:a}){let o=u(r).modelsSettings,s=t?.providers[e],[c,d]=(0,Q.useState)(s?.baseUrl??``),[f,p]=(0,Q.useState)(s?.apiKey??``),[m,h]=(0,Q.useState)(s?.models??[]),[g,_]=(0,Q.useState)(s?.modelDiscovery?.enabled===!0),[v,y]=(0,Q.useState)(!1),[b,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(!1),[T,E]=(0,Q.useState)(null),[D,O]=(0,Q.useState)(!1),[k,A]=(0,Q.useState)(null),j=n=>{if(!t)return null;let r=f.trim(),i={...s,baseUrl:c.trim()||void 0,apiKey:L(r)?s?.apiKey:r||void 0,...n};return{providers:{...t.providers,[e]:i}}},M=async()=>{let e=j({models:m,modelDiscovery:{enabled:g}});if(e){y(!0),x(null);try{await He(e),a(),i()}catch(e){x(e instanceof Error?e.message:n.saveError)}finally{y(!1)}}},N=async()=>{if(t)try{let{[e]:n,...r}=t.providers;await He({providers:r}),a(),i()}catch{}},P=(e,t)=>{A({model:e,isNew:t}),O(!0)},F=async e=>{if(!k)return;let t=k.isNew?[...m,e]:m.map(t=>t.id===e.id?e:t);h(t);let r=j({models:t});if(r)try{await He(r),a()}catch(e){x(e instanceof Error?e.message:n.saveError)}},I=async e=>{let t=m.filter(t=>t.id!==e);h(t),E(null);let r=j({models:t});if(r)try{await He(r),a()}catch(e){x(e instanceof Error?e.message:n.saveError)}};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-edge-subtle px-5 py-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(me,{className:`text-base font-semibold text-fg`,children:e}),(0,$.jsx)(`span`,{className:`rounded bg-surface-hover px-1.5 py-0.5 text-[10px] font-medium text-fg-subtle`,children:n.custom})]}),(0,$.jsx)(Ye,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:l(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,K.press),children:(0,$.jsx)(je,{className:`size-4`,"aria-hidden":!0})})})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 overflow-y-auto px-5 py-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`manage-base-url`,className:`text-sm font-medium text-fg`,children:n.baseUrlLabel}),(0,$.jsx)(`input`,{id:`manage-base-url`,type:`url`,autoComplete:`off`,value:c,onChange:e=>d(e.target.value),className:l(`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,w)})]}),(0,$.jsx)(ar,{providerId:e,inputId:`manage-custom-api-key`,value:f,onChange:p,labels:{apiKeyLabel:n.apiKeyLabel,apiKeyPlaceholder:n.apiKeyPlaceholder,maskedHelp:n.maskedHelp,copy:n.copy,copied:n.copied,show:n.showKey,hide:n.hideKey,notInConfigFile:n.notInConfigFile,loadFailed:n.loadFailed}}),(0,$.jsxs)(`label`,{className:`flex items-start gap-3 rounded-xl border border-edge-subtle bg-surface-panel/40 p-3`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked),className:`mt-0.5 size-4 rounded border-edge accent-accent`}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`block text-sm font-medium text-fg`,children:r===`zh`?`自动同步模型目录`:`Automatically sync model catalog`}),(0,$.jsx)(`span`,{className:`mt-0.5 block text-xs text-fg-muted`,children:r===`zh`?`启动时及定时从此服务的 /models 接口更新模型。`:`Update models from this service’s /models endpoint at startup and on schedule.`})]})]}),(0,$.jsxs)(`div`,{className:`border-t border-edge-subtle pt-3`,children:[(0,$.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,$.jsxs)(`span`,{className:`text-sm font-semibold text-fg`,children:[o.modelsSection,m.length>0?` (${m.length})`:``]}),(0,$.jsxs)(H,{type:`button`,variant:`primary`,className:`gap-1.5 px-2 py-1 text-xs`,onClick:()=>P(null,!0),children:[(0,$.jsx)(V,{className:`size-3.5`,"aria-hidden":!0}),o.addModel]})]}),m.length===0?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:o.modelsEmpty}):(0,$.jsx)(`ul`,{className:`space-y-2`,children:m.map(e=>(0,$.jsxs)(`li`,{className:`flex items-center justify-between gap-2 rounded-lg border border-edge-subtle bg-surface-panel/40 px-3 py-2`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`truncate text-sm font-medium text-fg`,children:e.id}),e.name&&e.name!==e.id?(0,$.jsx)(`div`,{className:`truncate text-xs text-fg-muted`,children:e.name}):null]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(0,$.jsx)(`button`,{type:`button`,className:l(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,K.press),onClick:()=>P(e,!1),"aria-label":o.editModel,children:(0,$.jsx)(ne,{className:`size-3.5`,"aria-hidden":!0})}),(0,$.jsx)(`button`,{type:`button`,className:l(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-red-600 dark:hover:text-red-400`,K.press),onClick:()=>E(e.id),"aria-label":o.removeModel,children:(0,$.jsx)(he,{className:`size-3.5`,"aria-hidden":!0})})]})]},e.id))})]}),b?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:b}):null]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-t border-edge-subtle px-5 py-3`,children:[(0,$.jsxs)(H,{type:`button`,variant:`ghost`,className:`gap-1.5 text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300`,onClick:()=>C(!0),children:[(0,$.jsx)(he,{className:`size-3.5`,"aria-hidden":!0}),n.remove]}),(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsx)(H,{type:`button`,variant:`primary`,disabled:v,onClick:()=>void M(),children:v?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(W,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),n.saving]}):n.save})})]}),(0,$.jsx)(ve,{open:S,title:n.removeConfirmTitle,description:n.removeConfirmDescription.replace(`{{provider}}`,e),confirmLabel:n.removeConfirmAction,cancelLabel:n.cancel,destructive:!0,onConfirm:()=>void N(),onCancel:()=>C(!1)}),(0,$.jsx)(ve,{open:T!==null,title:o.removeModel,description:o.removeModelConfirm.replace(`{{id}}`,T??``),confirmLabel:n.removeConfirmAction,cancelLabel:n.cancel,destructive:!0,onConfirm:()=>{T&&I(T)},onCancel:()=>E(null)}),(0,$.jsx)(rr,{open:D,onOpenChange:e=>{O(e),e||A(null)},providerId:e,model:k?.model??null,isNew:k?.isNew??!1,onSave:e=>void F(e),m:o})]})}async function pr(){let e=await p(m(`/api/models/catalog`)),t=await e.json().catch(()=>null);if(!e.ok||!t?.ok||!t.payload)throw Error(t?.error?.message??`HTTP ${e.status}`);return t.payload}function mr(){let e=f(e=>e.language)===`zh`,{data:t,error:n,isLoading:r}=g(J,pr,{revalidateOnFocus:!1}),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(null);if(r)return(0,$.jsx)(U,{className:`h-24 w-full rounded-2xl`});let c=Object.values(t?.sources??{}),l=c.reduce((e,t)=>e+t.models.filter(e=>e.availability===`available`).length,0),u=(t?.references??[]).filter(e=>e.availability===`unavailable`),d=t?.sync.lastSuccessAt??Math.max(0,...c.map(e=>e.lastSuccessAt)),h=o??(n instanceof Error?n.message:t?.sync.lastError??Object.values(t?.sync.sourceErrors??{})[0]),_=async()=>{a(!0),s(null);try{let e=await p(m(`/api/models/catalog/refresh`),{method:`POST`});if(!e.ok)throw Error(`HTTP ${e.status}`);await pe()}catch(t){s(t instanceof Error?t.message:e?`模型目录刷新失败`:`Model catalog refresh failed`)}finally{a(!1)}};return(0,$.jsx)(`div`,{className:`rounded-2xl border border-edge-subtle bg-surface-panel/40 p-4`,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[h||u.length>0?(0,$.jsx)(ce,{className:`size-4 text-amber-500`,"aria-hidden":!0}):(0,$.jsx)(Ve,{className:`size-4 text-emerald-500`,"aria-hidden":!0}),(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:e?`模型目录同步`:`Model catalog sync`})]}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e?`${c.length} 个来源,${l} 个可用模型${d?` · 最近同步 ${new Date(d).toLocaleString()}`:``}`:`${c.length} sources, ${l} available models${d?` · Last synced ${new Date(d).toLocaleString()}`:``}`}),u.length>0?(0,$.jsx)(`div`,{className:`mt-2 space-y-1 text-sm text-amber-700 dark:text-amber-300`,children:u.slice(0,3).map(t=>(0,$.jsxs)(`p`,{children:[t.ref,` `,e?`不可用`:`is unavailable`,t.suggestedRef?` · ${e?`建议`:`Suggested`} ${t.suggestedRef}`:``,` · ${t.locations.length} ${e?`处引用`:`references`}`]},t.ref))}):null,h?(0,$.jsx)(`p`,{className:`mt-2 text-sm text-danger`,children:h}):null]}),(0,$.jsxs)(H,{type:`button`,variant:`secondary`,disabled:i,onClick:()=>void _(),children:[i?(0,$.jsx)(W,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Ue,{className:`size-4`,"aria-hidden":!0}),i?e?`刷新中…`:`Refreshing…`:e?`立即刷新`:`Refresh now`]})]})})}function hr(e){return ze.includes(e)}function gr(){let e=(0,Z.c)(80),t=f(br),n;e[0]===t?n=e[1]:(n=u(t),e[0]=t,e[1]=n);let r=n,l=r.capabilitiesSettings,d=a(),[p,m]=i(),{capability:h}=c(),g=gt(yr),[_,v]=(0,Q.useState)(!1),[y,b]=(0,Q.useState)(null),x=Gn(),S,C;e[2]!==h||e[3]!==p||e[4]!==m?(S=()=>{if(h!==`models`||p.get(`add`)!==`1`)return;v(!0);let e=new URLSearchParams(p);e.delete(`add`),m(e,{replace:!0})},C=[h,p,m],e[2]=h,e[3]=p,e[4]=m,e[5]=S,e[6]=C):(S=e[5],C=e[6]),(0,Q.useEffect)(S,C);let w;e[7]!==l.unsavedChanges||e[8]!==g?(w=e=>g.get(e)?.dirty?(0,$.jsx)(`span`,{className:`size-1.5 rounded-full bg-amber-500`,"aria-label":l.unsavedChanges,title:l.unsavedChanges}):void 0,e[7]=l.unsavedChanges,e[8]=g,e[9]=w):w=e[9];let T=w,E;e[10]!==l.modelsHint||e[11]!==l.tabs.models?(E={id:`models`,icon:Ne,label:l.tabs.models,hint:l.modelsHint},e[10]=l.modelsHint,e[11]=l.tabs.models,e[12]=E):E=e[12];let D=l.tabs.image,O=l.imageHint,k;e[13]===T?k=e[14]:(k=T(`image-models`),e[13]=T,e[14]=k);let A;e[15]!==l.imageHint||e[16]!==l.tabs.image||e[17]!==k?(A={id:`image`,icon:Se,label:D,hint:O,suffix:k},e[15]=l.imageHint,e[16]=l.tabs.image,e[17]=k,e[18]=A):A=e[18];let M=l.tabs.voice,N=l.voiceHint,P;e[19]===T?P=e[20]:(P=T(`voice`),e[19]=T,e[20]=P);let I;e[21]!==l.tabs.voice||e[22]!==l.voiceHint||e[23]!==P?(I={id:`voice`,icon:j,label:M,hint:N,suffix:P},e[21]=l.tabs.voice,e[22]=l.voiceHint,e[23]=P,e[24]=I):I=e[24];let L=l.tabs.search,R=l.searchHint,z;e[25]===T?z=e[26]:(z=T(`search`),e[25]=T,e[26]=z);let B;e[27]!==l.searchHint||e[28]!==l.tabs.search||e[29]!==z?(B={id:`search`,icon:Ie,label:L,hint:R,suffix:z},e[27]=l.searchHint,e[28]=l.tabs.search,e[29]=z,e[30]=B):B=e[30];let ee;e[31]!==I||e[32]!==B||e[33]!==E||e[34]!==A?(ee=[E,A,I,B],e[31]=I,e[32]=B,e[33]=E,e[34]=A,e[35]=ee):ee=e[35];let V=ee,te;e[36]===d?te=e[37]:(te=e=>d(be(e)),e[36]=d,e[37]=te);let ne=te,U=vr;if(!hr(h)){let t;return e[38]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(o,{to:be(`models`),replace:!0}),e[38]=t):t=e[38],t}let W=r.nav.settingsCapabilities,ie=l.subtitle,G;e[39]===t?G=e[40]:(G=ye(t,`configuration`),e[39]=t,e[40]=G);let ae;e[41]===Symbol.for(`react.memo_cache_sentinel`)?(ae=(0,$.jsx)(F,{className:`size-4`,"aria-hidden":!0}),e[41]=ae):ae=e[41];let K;e[42]===l.agentSettingsLink?K=e[43]:(K=(0,$.jsx)(H,{asChild:!0,variant:`secondary`,children:(0,$.jsxs)(s,{to:`/agents`,children:[ae,l.agentSettingsLink]})}),e[42]=l.agentSettingsLink,e[43]=K);let oe;e[44]!==l.docsLink||e[45]!==l.subtitle||e[46]!==r.nav.settingsCapabilities||e[47]!==G||e[48]!==K?(oe=(0,$.jsx)(Qe,{title:W,subtitle:ie,docsLink:G,docsLabel:l.docsLink,actions:K}),e[44]=l.docsLink,e[45]=l.subtitle,e[46]=r.nav.settingsCapabilities,e[47]=G,e[48]=K,e[49]=oe):oe=e[49];let q;e[50]===Symbol.for(`react.memo_cache_sentinel`)?(q=(0,$.jsx)(_t,{}),e[50]=q):q=e[50];let J;e[51]!==l.tabsAria||e[52]!==h||e[53]!==V||e[54]!==ne?(J=(0,$.jsx)(mt,{items:V,activeTab:h,onChange:ne,ariaLabel:l.tabsAria,tabIdPrefix:`capability-tab`,panelIdPrefix:`capability-panel`}),e[51]=l.tabsAria,e[52]=h,e[53]=V,e[54]=ne,e[55]=J):J=e[55];let se;e[56]!==l.connectedProviders||e[57]!==h||e[58]!==x.cards||e[59]!==V?(se=V.map(e=>(0,$.jsx)(Sr,{id:e.id,activeSection:h,hint:e.hint,children:e.id===`models`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(re,{connected:x.cards.some(_r)}),(0,$.jsx)(mr,{}),(0,$.jsx)(Zn,{labels:l.connectedProviders,onAdd:()=>v(!0),onManage:(e,t)=>b({providerId:e,isCustom:t})})]}):(0,$.jsx)(xr,{section:e.id})},e.id)),e[56]=l.connectedProviders,e[57]=h,e[58]=x.cards,e[59]=V,e[60]=se):se=e[60];let ce;e[61]!==_||e[62]!==l.addProviderDialog||e[63]!==t||e[64]!==x.builtinRows||e[65]!==x.customConfig?(ce=(0,$.jsx)(In,{open:_,onOpenChange:v,builtinRows:x.builtinRows,customConfig:x.customConfig,labels:l.addProviderDialog,language:t,onSaved:U}),e[61]=_,e[62]=l.addProviderDialog,e[63]=t,e[64]=x.builtinRows,e[65]=x.customConfig,e[66]=ce):ce=e[66];let le;e[67]!==l.manageProviderDialog||e[68]!==t||e[69]!==y||e[70]!==x.allModels||e[71]!==x.builtinRows||e[72]!==x.customConfig?(le=y?(0,$.jsx)(sr,{open:!0,onOpenChange:e=>{e||b(null)},providerId:y.providerId,isCustom:y.isCustom,builtinRows:x.builtinRows,customConfig:x.customConfig,allModels:x.allModels,labels:l.manageProviderDialog,language:t,onSaved:U}):null,e[67]=l.manageProviderDialog,e[68]=t,e[69]=y,e[70]=x.allModels,e[71]=x.builtinRows,e[72]=x.customConfig,e[73]=le):le=e[73];let ue;return e[74]!==oe||e[75]!==J||e[76]!==se||e[77]!==ce||e[78]!==le?(ue=(0,$.jsxs)($e,{children:[oe,q,J,se,ce,le]}),e[74]=oe,e[75]=J,e[76]=se,e[77]=ce,e[78]=le,e[79]=ue):ue=e[79],ue}function _r(e){return e.id===`xopc-cloud`}function vr(){pe()}function yr(e){return e.sections}function br(e){return e.language}function xr(e){let t=(0,Z.c)(3),{section:n}=e;switch(n){case`models`:return null;case`image`:{let e;return t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Tt,{}),t[0]=e):e=t[0],e}case`voice`:{let e;return t[1]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Qt,{}),t[1]=e):e=t[1],e}case`search`:{let e;return t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Tn,{}),t[2]=e):e=t[2],e}}}function Sr({id:e,activeSection:t,hint:n,children:r}){let i=e===t,a=(0,Q.useRef)(i);return i&&(a.current=!0),a.current?(0,$.jsxs)(`div`,{role:`tabpanel`,id:`capability-panel-${e}`,"aria-labelledby":`capability-tab-${e}`,hidden:!i,className:l(`min-w-0 rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,i?`flex flex-col gap-3`:void 0),children:[i?(0,$.jsx)(`p`,{className:`text-sm leading-relaxed text-fg-muted`,children:n}):null,r]}):null}export{gr as CapabilitiesSettingsPanel};
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,t as n}from"./vendor-react-BOUWij0V.js";import{r,s as i}from"./locale-store-0lpYdNDr.js";import{i as a}from"./vendor-swr-BIWyz7Rc.js";import{Bs as o,Gn as s,It as c,Kn as l,wc as u,ws as d}from"./index-C8JkTS6d.js";import{s as f}from"./typed-models-lib-Divbg_C4.js";var p=[{key:`code-intelligence`,toolIds:[`code_search`,`code_read_symbol`,`code_trace`,`code_impact`,`code_architecture`]},{key:`workspace`,toolIds:[`read_file`,`write_file`,`apply_patch`,`list_dir`,`grep`,`find`]},{key:`execution`,toolIds:[`exec_command`,`execute_code`]},{key:`messaging`,toolIds:[`send_message`,`send_media`,`text_to_speech`]},{key:`memory`,toolIds:[`memory_search`,`memory_get`,`curated_memory`,`session_search`]},{key:`media`,toolIds:[`image`,`image_generate`,`read_media`,`create_share`]},{key:`web`,toolIds:[`web_search`,`web_fetch`,`web_extract`,`browser_use`]},{key:`misc`,toolIds:[`session_status`,`dreaming`,`tool_manual`,`clarify`,`todo`,`update_plan`,`automation`,`workflow`,`delegate_task`]},{key:`unknown`,toolIds:[`skills_list`,`skill_view`,`skill_manage`]},{key:`extensions`,toolIds:[`extensions`]},{key:`mcp`,toolIds:[`bundle-mcp`]}],m=new Set(p.flatMap(e=>[...e.toolIds].map(e=>String(e))));function h(e){return e.filter(e=>e&&!m.has(e)).sort((e,t)=>e.localeCompare(t))}var g=e(t(),1),_=n(),v=[`deep`,`fast`,`cheap`,`code`,`review`];function y(e){return v.includes(e)}function b(e){let{rows:t,onChange:n,disabled:r,defaultRole:i,chat:p,labels:m}=e,{data:h=[]}=a(s,l,{revalidateOnFocus:!1}),b=(0,g.useMemo)(()=>new Set(h.filter(e=>e.vision===!0).map(e=>e.id)),[h]),x=(0,g.useRef)([]),S=(0,g.useRef)(0);for(;x.current.length<t.length;)x.current.push(`typed-model-row-${S.current++}`);x.current.length>t.length&&(x.current.length=t.length);let C=(e,r)=>{n(t.map((t,n)=>n===e?{...t,...r}:t))},w=(e,n,r)=>{let i=t[e];if(!i)return;let a=[...i.fallbacks??[]];a[n]=r,C(e,{fallbacks:a})},T=e=>{let n=t[e];n&&C(e,{fallbacks:[...n.fallbacks??[],``]})},E=(e,n)=>{let r=t[e];r&&C(e,{fallbacks:(r.fallbacks??[]).filter((e,t)=>t!==n)})},D=e=>{x.current.splice(e,1),n(t.filter((t,n)=>n!==e))},O=e=>{x.current.push(`typed-model-row-${S.current++}`),n([...t,e])},k=t.find(e=>e.model.trim())?.model??``,A=t.map((e,t)=>({row:e,index:t})),j=v.map(e=>A.find(t=>t.row.id===e)).filter(e=>!!e),M=A.filter(e=>!y(e.row.id)),N=v.filter(e=>!t.some(t=>t.id===e)),P=(e,t)=>{let{row:n,index:a}=e,s=n.id===i,l=[n.model,...n.fallbacks??[]].some(e=>b.has(e.trim())),h=y(n.id)?m.roleNames[n.id]:m.id,g=y(n.id)?m.roleDescriptions[n.id]:``;return(0,_.jsxs)(`div`,{className:`grid gap-3 rounded-lg bg-surface-panel/70 p-3 shadow-surface lg:grid-cols-[minmax(0,11rem)_minmax(0,1fr)_auto] lg:items-start`,children:[t.recommended?(0,_.jsxs)(`div`,{className:`min-w-0`,children:[(0,_.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,_.jsx)(`span`,{className:`truncate text-sm font-medium text-fg`,children:h}),s?(0,_.jsx)(`span`,{className:`shrink-0 rounded-full border border-accent/25 bg-accent/10 px-2 py-0.5 text-[11px] font-medium text-accent`,children:m.defaultBadge}):null,l?(0,_.jsx)(`span`,{className:`shrink-0 rounded-full border border-accent/25 bg-accent/10 px-2 py-0.5 text-[11px] font-medium text-accent`,children:m.visionBadge}):null]}),(0,_.jsx)(`div`,{className:`mt-1 truncate font-mono text-[11px] text-fg-subtle`,children:n.id}),g?(0,_.jsx)(`div`,{className:`mt-1 line-clamp-2 text-xs text-fg-muted`,children:g}):null]}):(0,_.jsxs)(`div`,{className:`min-w-0`,children:[(0,_.jsxs)(`div`,{className:`mb-1 flex items-center gap-2 text-xs font-medium text-fg-muted`,children:[(0,_.jsx)(`span`,{children:m.id}),l?(0,_.jsx)(`span`,{className:`shrink-0 rounded-full border border-accent/25 bg-accent/10 px-2 py-0.5 text-[11px] font-medium text-accent`,children:m.visionBadge}):null]}),(0,_.jsx)(`input`,{type:`text`,className:f(),value:n.id,disabled:r,placeholder:m.idPlaceholder,"aria-label":m.id,onChange:e=>C(a,{id:e.target.value.toLowerCase()})})]}),(0,_.jsxs)(`div`,{className:`grid min-w-0 gap-2`,children:[(0,_.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,_.jsx)(`div`,{className:`text-xs font-medium text-fg-muted`,children:m.primaryModel}),(0,_.jsx)(c,{value:n.model,disabled:r,placeholder:p.modelPlaceholder,searchPlaceholder:p.modelSearchPlaceholder,noMatches:p.modelNoMatches,className:`w-full max-w-none`,contentAlign:`start`,onChange:e=>C(a,{model:e})}),l?(0,_.jsx)(`div`,{className:`text-xs leading-relaxed text-fg-muted`,children:m.visionAutoHint}):null]}),(0,_.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,_.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,_.jsx)(`div`,{className:`text-xs font-medium text-fg-muted`,children:m.fallbackModels}),(0,_.jsxs)(d,{type:`button`,variant:`secondary`,className:`h-7 gap-1 px-2 text-xs`,disabled:r,onClick:()=>T(a),children:[(0,_.jsx)(u,{className:`size-3.5`,strokeWidth:1.75}),m.addFallback]})]}),(n.fallbacks??[]).length>0?(0,_.jsx)(`div`,{className:`grid gap-1.5`,children:(n.fallbacks??[]).map((e,t)=>(0,_.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] gap-2`,children:[(0,_.jsx)(c,{value:e,disabled:r,placeholder:m.fallbackPlaceholder,searchPlaceholder:p.modelSearchPlaceholder,noMatches:p.modelNoMatches,className:`w-full max-w-none`,contentAlign:`start`,onChange:e=>w(a,t,e)}),(0,_.jsx)(d,{type:`button`,variant:`secondary`,className:`shrink-0 px-2`,disabled:r,"aria-label":m.removeFallback,onClick:()=>E(a,t),children:(0,_.jsx)(o,{className:`size-4`,strokeWidth:1.75})})]},`${x.current[a]??a}-fallback-${t}`))}):(0,_.jsx)(`div`,{className:`rounded-lg bg-surface-panel/60 px-3 py-2 text-xs text-fg-muted shadow-surface`,children:m.fallbackEmptyHint})]}),(0,_.jsx)(`input`,{type:`text`,className:f(),value:n.description,disabled:r,placeholder:m.descriptionPlaceholder,"aria-label":m.description,onChange:e=>C(a,{description:e.target.value})})]}),(0,_.jsx)(d,{type:`button`,variant:`secondary`,className:`shrink-0 sm:mt-0`,disabled:r||s,"aria-label":m.remove,onClick:()=>D(a),children:(0,_.jsx)(o,{className:`size-4`,strokeWidth:1.75})})]},x.current[a]??`typed-model-row-${a}`)};return(0,_.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,_.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,_.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-fg-muted`,children:m.recommendedTitle}),j.map(e=>P(e,{recommended:!0})),N.length>0?(0,_.jsx)(`div`,{className:`flex flex-wrap gap-2 pt-1`,children:N.map(e=>(0,_.jsxs)(d,{type:`button`,variant:`secondary`,className:`h-8 gap-1.5 rounded-lg px-2.5 text-xs`,disabled:r,onClick:()=>O({id:e,description:m.roleDescriptions[e],model:k,fallbacks:[]}),children:[(0,_.jsx)(u,{className:`size-3.5 shrink-0`,strokeWidth:1.75}),m.addPurpose.replace(`{name}`,m.roleNames[e])]},e))}):null]}),(0,_.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,_.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-fg-muted`,children:m.customTitle}),M.length>0?M.map(e=>P(e,{recommended:!1})):(0,_.jsx)(`div`,{className:`rounded-lg bg-surface-panel/60 px-3 py-2 text-sm text-fg-muted shadow-surface`,children:m.noCustomRoles})]}),(0,_.jsxs)(d,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,disabled:r,onClick:()=>O({id:``,description:``,model:k,fallbacks:[]}),children:[(0,_.jsx)(u,{className:`size-4 shrink-0`,strokeWidth:1.75}),m.add]})]})}async function x(){let e=await i(r(`/api/capability-presets`));if(!Array.isArray(e.payload?.presets)||typeof e.payload.defaultPresetId!=`string`||!Array.isArray(e.payload.agents)||!Array.isArray(e.payload.builtinToolIds))throw Error(`Invalid /api/capability-presets response`);return e.payload}async function S(e){let t=await i(r(`/api/capability-presets`),{method:`POST`,body:JSON.stringify(e)}),n=t.payload?.presetId,a=t.payload?.presets;if(!n||!a||typeof a.defaultPresetId!=`string`||!Array.isArray(a.presets)||!Array.isArray(a.agents)||!Array.isArray(a.builtinToolIds))throw Error(`Invalid create capability preset response`);return{presetId:n,presets:a}}async function C(e,t){let n=await i(r(`/api/capability-presets/${encodeURIComponent(e)}`),{method:`PATCH`,body:JSON.stringify(t)});if(!Array.isArray(n.payload?.presets)||typeof n.payload.defaultPresetId!=`string`||!Array.isArray(n.payload.agents)||!Array.isArray(n.payload.builtinToolIds))throw Error(`Invalid update capability preset response`);return n.payload}async function w(e){let t=await i(r(`/api/capability-presets/${encodeURIComponent(e)}`),{method:`DELETE`});if(!Array.isArray(t.payload?.presets)||typeof t.payload.defaultPresetId!=`string`||!Array.isArray(t.payload.agents)||!Array.isArray(t.payload.builtinToolIds))throw Error(`Invalid delete capability preset response`);return t.payload}export{b as a,C as i,w as n,p as o,x as r,h as s,S as t};
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,t as n}from"./vendor-react-BOUWij0V.js";import{r,s as i}from"./locale-store-Ys6RP7Be.js";import{i as a}from"./vendor-swr-BIWyz7Rc.js";import{Gn as o,It as s,Kn as c,Oc as l,Os as u,Ws as d}from"./index-HZdBKfk_.js";import{s as f}from"./typed-models-lib--HptwFcD.js";var p=[{key:`code-intelligence`,toolIds:[`code_search`,`code_read_symbol`,`code_trace`,`code_impact`,`code_architecture`]},{key:`workspace`,toolIds:[`read_file`,`write_file`,`apply_patch`,`list_dir`,`grep`,`find`]},{key:`execution`,toolIds:[`exec_command`,`execute_code`]},{key:`messaging`,toolIds:[`send_message`,`send_media`,`text_to_speech`]},{key:`memory`,toolIds:[`memory_search`,`memory_get`,`curated_memory`,`session_search`]},{key:`media`,toolIds:[`image`,`image_generate`,`read_media`,`create_share`]},{key:`web`,toolIds:[`web_search`,`web_fetch`,`web_extract`,`browser_use`]},{key:`misc`,toolIds:[`session_status`,`dreaming`,`tool_manual`,`clarify`,`todo`,`update_plan`,`automation`,`workflow`,`delegate_task`]},{key:`unknown`,toolIds:[`skills_list`,`skill_view`,`skill_manage`]},{key:`extensions`,toolIds:[`extensions`]},{key:`mcp`,toolIds:[`bundle-mcp`]}],m=new Set(p.flatMap(e=>[...e.toolIds].map(e=>String(e))));function h(e){return e.filter(e=>e&&!m.has(e)).sort((e,t)=>e.localeCompare(t))}var g=e(t(),1),_=n(),v=[`deep`,`fast`,`cheap`,`code`,`review`];function y(e){return v.includes(e)}function b(e){let{rows:t,onChange:n,disabled:r,defaultRole:i,chat:p,labels:m}=e,{data:h=[]}=a(o,c,{revalidateOnFocus:!1}),b=(0,g.useMemo)(()=>new Set(h.filter(e=>e.vision===!0).map(e=>e.id)),[h]),x=(0,g.useRef)([]),S=(0,g.useRef)(0);for(;x.current.length<t.length;)x.current.push(`typed-model-row-${S.current++}`);x.current.length>t.length&&(x.current.length=t.length);let C=(e,r)=>{n(t.map((t,n)=>n===e?{...t,...r}:t))},w=(e,n,r)=>{let i=t[e];if(!i)return;let a=[...i.fallbacks??[]];a[n]=r,C(e,{fallbacks:a})},T=e=>{let n=t[e];n&&C(e,{fallbacks:[...n.fallbacks??[],``]})},E=(e,n)=>{let r=t[e];r&&C(e,{fallbacks:(r.fallbacks??[]).filter((e,t)=>t!==n)})},D=e=>{x.current.splice(e,1),n(t.filter((t,n)=>n!==e))},O=e=>{x.current.push(`typed-model-row-${S.current++}`),n([...t,e])},k=t.find(e=>e.model.trim())?.model??``,A=t.map((e,t)=>({row:e,index:t})),j=v.map(e=>A.find(t=>t.row.id===e)).filter(e=>!!e),M=A.filter(e=>!y(e.row.id)),N=v.filter(e=>!t.some(t=>t.id===e)),P=(e,t)=>{let{row:n,index:a}=e,o=n.id===i,c=[n.model,...n.fallbacks??[]].some(e=>b.has(e.trim())),h=y(n.id)?m.roleNames[n.id]:m.id,g=y(n.id)?m.roleDescriptions[n.id]:``;return(0,_.jsxs)(`div`,{className:`grid gap-3 rounded-lg bg-surface-panel/70 p-3 shadow-surface lg:grid-cols-[minmax(0,11rem)_minmax(0,1fr)_auto] lg:items-start`,children:[t.recommended?(0,_.jsxs)(`div`,{className:`min-w-0`,children:[(0,_.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,_.jsx)(`span`,{className:`truncate text-sm font-medium text-fg`,children:h}),o?(0,_.jsx)(`span`,{className:`shrink-0 rounded-full border border-accent/25 bg-accent/10 px-2 py-0.5 text-[11px] font-medium text-accent`,children:m.defaultBadge}):null,c?(0,_.jsx)(`span`,{className:`shrink-0 rounded-full border border-accent/25 bg-accent/10 px-2 py-0.5 text-[11px] font-medium text-accent`,children:m.visionBadge}):null]}),(0,_.jsx)(`div`,{className:`mt-1 truncate font-mono text-[11px] text-fg-subtle`,children:n.id}),g?(0,_.jsx)(`div`,{className:`mt-1 line-clamp-2 text-xs text-fg-muted`,children:g}):null]}):(0,_.jsxs)(`div`,{className:`min-w-0`,children:[(0,_.jsxs)(`div`,{className:`mb-1 flex items-center gap-2 text-xs font-medium text-fg-muted`,children:[(0,_.jsx)(`span`,{children:m.id}),c?(0,_.jsx)(`span`,{className:`shrink-0 rounded-full border border-accent/25 bg-accent/10 px-2 py-0.5 text-[11px] font-medium text-accent`,children:m.visionBadge}):null]}),(0,_.jsx)(`input`,{type:`text`,className:f(),value:n.id,disabled:r,placeholder:m.idPlaceholder,"aria-label":m.id,onChange:e=>C(a,{id:e.target.value.toLowerCase()})})]}),(0,_.jsxs)(`div`,{className:`grid min-w-0 gap-2`,children:[(0,_.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,_.jsx)(`div`,{className:`text-xs font-medium text-fg-muted`,children:m.primaryModel}),(0,_.jsx)(s,{value:n.model,disabled:r,placeholder:p.modelPlaceholder,searchPlaceholder:p.modelSearchPlaceholder,noMatches:p.modelNoMatches,className:`w-full max-w-none`,contentAlign:`start`,onChange:e=>C(a,{model:e})}),c?(0,_.jsx)(`div`,{className:`text-xs leading-relaxed text-fg-muted`,children:m.visionAutoHint}):null]}),(0,_.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,_.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,_.jsx)(`div`,{className:`text-xs font-medium text-fg-muted`,children:m.fallbackModels}),(0,_.jsxs)(u,{type:`button`,variant:`secondary`,className:`h-7 gap-1 px-2 text-xs`,disabled:r,onClick:()=>T(a),children:[(0,_.jsx)(l,{className:`size-3.5`,strokeWidth:1.75}),m.addFallback]})]}),(n.fallbacks??[]).length>0?(0,_.jsx)(`div`,{className:`grid gap-1.5`,children:(n.fallbacks??[]).map((e,t)=>(0,_.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] gap-2`,children:[(0,_.jsx)(s,{value:e,disabled:r,placeholder:m.fallbackPlaceholder,searchPlaceholder:p.modelSearchPlaceholder,noMatches:p.modelNoMatches,className:`w-full max-w-none`,contentAlign:`start`,onChange:e=>w(a,t,e)}),(0,_.jsx)(u,{type:`button`,variant:`secondary`,className:`shrink-0 px-2`,disabled:r,"aria-label":m.removeFallback,onClick:()=>E(a,t),children:(0,_.jsx)(d,{className:`size-4`,strokeWidth:1.75})})]},`${x.current[a]??a}-fallback-${t}`))}):(0,_.jsx)(`div`,{className:`rounded-lg bg-surface-panel/60 px-3 py-2 text-xs text-fg-muted shadow-surface`,children:m.fallbackEmptyHint})]}),(0,_.jsx)(`input`,{type:`text`,className:f(),value:n.description,disabled:r,placeholder:m.descriptionPlaceholder,"aria-label":m.description,onChange:e=>C(a,{description:e.target.value})})]}),(0,_.jsx)(u,{type:`button`,variant:`secondary`,className:`shrink-0 sm:mt-0`,disabled:r||o,"aria-label":m.remove,onClick:()=>D(a),children:(0,_.jsx)(d,{className:`size-4`,strokeWidth:1.75})})]},x.current[a]??`typed-model-row-${a}`)};return(0,_.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,_.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,_.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-fg-muted`,children:m.recommendedTitle}),j.map(e=>P(e,{recommended:!0})),N.length>0?(0,_.jsx)(`div`,{className:`flex flex-wrap gap-2 pt-1`,children:N.map(e=>(0,_.jsxs)(u,{type:`button`,variant:`secondary`,className:`h-8 gap-1.5 rounded-lg px-2.5 text-xs`,disabled:r,onClick:()=>O({id:e,description:m.roleDescriptions[e],model:k,fallbacks:[]}),children:[(0,_.jsx)(l,{className:`size-3.5 shrink-0`,strokeWidth:1.75}),m.addPurpose.replace(`{name}`,m.roleNames[e])]},e))}):null]}),(0,_.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,_.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-fg-muted`,children:m.customTitle}),M.length>0?M.map(e=>P(e,{recommended:!1})):(0,_.jsx)(`div`,{className:`rounded-lg bg-surface-panel/60 px-3 py-2 text-sm text-fg-muted shadow-surface`,children:m.noCustomRoles})]}),(0,_.jsxs)(u,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,disabled:r,onClick:()=>O({id:``,description:``,model:k,fallbacks:[]}),children:[(0,_.jsx)(l,{className:`size-4 shrink-0`,strokeWidth:1.75}),m.add]})]})}async function x(){let e=await i(r(`/api/capability-presets`));if(!Array.isArray(e.payload?.presets)||typeof e.payload.defaultPresetId!=`string`||!Array.isArray(e.payload.agents)||!Array.isArray(e.payload.builtinToolIds))throw Error(`Invalid /api/capability-presets response`);return e.payload}async function S(e){let t=await i(r(`/api/capability-presets`),{method:`POST`,body:JSON.stringify(e)}),n=t.payload?.presetId,a=t.payload?.presets;if(!n||!a||typeof a.defaultPresetId!=`string`||!Array.isArray(a.presets)||!Array.isArray(a.agents)||!Array.isArray(a.builtinToolIds))throw Error(`Invalid create capability preset response`);return{presetId:n,presets:a}}async function C(e,t){let n=await i(r(`/api/capability-presets/${encodeURIComponent(e)}`),{method:`PATCH`,body:JSON.stringify(t)});if(!Array.isArray(n.payload?.presets)||typeof n.payload.defaultPresetId!=`string`||!Array.isArray(n.payload.agents)||!Array.isArray(n.payload.builtinToolIds))throw Error(`Invalid update capability preset response`);return n.payload}async function w(e){let t=await i(r(`/api/capability-presets/${encodeURIComponent(e)}`),{method:`DELETE`});if(!Array.isArray(t.payload?.presets)||typeof t.payload.defaultPresetId!=`string`||!Array.isArray(t.payload.agents)||!Array.isArray(t.payload.builtinToolIds))throw Error(`Invalid delete capability preset response`);return t.payload}export{b as a,C as i,w as n,p as o,x as r,h as s,S as t};
@@ -0,0 +1,2 @@
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{d as i,t as a}from"./chunk-KS7C4IRE-uQ0fehio.js";import{t as o}from"./cn-JdwAhgNB.js";import{t as s}from"./messages-BzI9Wx30.js";import{l as c,n as l}from"./locale-store-Ys6RP7Be.js";import{i as u}from"./vendor-swr-BIWyz7Rc.js";import{Au as d,Bl as f,Bo as p,Br as m,Cu as h,Ho as g,Jl as _,Ms as v,Oc as y,Os as b,Ou as x,Qc as S,Ro as C,Tc as w,Uo as T,Vo as E,Wo as D,Ws as O,_c as k,cs as A,fl as j,is as M,js as N,ls as P,oc as F,rs as I,ts as ee,xs as te,zo as ne}from"./index-HZdBKfk_.js";import{n as re,r as ie}from"./settings-page-layout-C1yYqbT6.js";import{n as ae,r as L}from"./settings-loading-skeleton-DOnUabm7.js";import{n as R,t as oe}from"./settings-form-section-X2Sl-EAk.js";import{a as se,i as ce,n as le,o as ue,r as de,s as fe,t as pe}from"./capability-presets-api-BZKh2cWX.js";import{a as me,i as he,o as z,t as ge}from"./typed-models-lib--HptwFcD.js";var B=e(t(),1),V=n(),H=r();function _e(e){let t=(0,V.c)(34),{extendsIds:n,onExtendsChange:r,presetOptions:i,jsonFields:a,onJsonFieldsChange:o,disabled:s,labels:c}=e,l;t[0]===a?l=t[1]:(l=Object.keys(a),t[0]=a,t[1]=l);let u=l,d;t[2]===c.inheritanceTitle?d=t[3]:(d=(0,H.jsx)(`h4`,{className:`text-sm font-semibold text-fg`,children:c.inheritanceTitle}),t[2]=c.inheritanceTitle,t[3]=d);let f;t[4]===c.inheritanceHint?f=t[5]:(f=(0,H.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-fg-muted`,children:c.inheritanceHint}),t[4]=c.inheritanceHint,t[5]=f);let p;t[6]!==s||t[7]!==n||t[8]!==c.inheritanceEmpty||t[9]!==r||t[10]!==i?(p=i.length>0?(0,H.jsx)(`div`,{className:`mt-3 grid gap-2 sm:grid-cols-2`,children:i.map(e=>{let t=n.includes(e.id);return(0,H.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 rounded-lg bg-surface-panel/70 px-3 py-2.5 shadow-surface`,children:[(0,H.jsx)(`input`,{type:`checkbox`,className:`mt-0.5 shrink-0 rounded border-edge`,checked:t,disabled:s,onChange:()=>r(t?n.filter(t=>t!==e.id):[...n,e.id])}),(0,H.jsxs)(`span`,{className:`min-w-0`,children:[(0,H.jsx)(`span`,{className:`block truncate text-sm font-medium text-fg`,children:e.name}),(0,H.jsx)(`span`,{className:`mt-0.5 block font-mono text-[11px] text-fg-subtle`,children:e.id})]})]},e.id)})}):(0,H.jsx)(`p`,{className:`mt-3 text-sm text-fg-muted`,children:c.inheritanceEmpty}),t[6]=s,t[7]=n,t[8]=c.inheritanceEmpty,t[9]=r,t[10]=i,t[11]=p):p=t[11];let m;t[12]!==d||t[13]!==f||t[14]!==p?(m=(0,H.jsxs)(`section`,{children:[d,f,p]}),t[12]=d,t[13]=f,t[14]=p,t[15]=m):m=t[15];let h;t[16]===c.jsonTitle?h=t[17]:(h=(0,H.jsx)(`h4`,{className:`text-sm font-semibold text-fg`,children:c.jsonTitle}),t[16]=c.jsonTitle,t[17]=h);let g;t[18]===c.jsonHint?g=t[19]:(g=(0,H.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-fg-muted`,children:c.jsonHint}),t[18]=c.jsonHint,t[19]=g);let _;t[20]!==s||t[21]!==u||t[22]!==a||t[23]!==c.fieldHints||t[24]!==c.fieldLabels||t[25]!==o?(_=(0,H.jsx)(`div`,{className:`mt-3 grid gap-4 lg:grid-cols-2`,children:u.map(e=>(0,H.jsxs)(`label`,{className:`flex min-w-0 flex-col gap-1.5`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:c.fieldLabels[e]}),(0,H.jsx)(`span`,{className:`min-h-8 text-xs leading-relaxed text-fg-muted`,children:c.fieldHints[e]}),(0,H.jsx)(`textarea`,{className:`min-h-36 resize-y rounded-lg border border-edge bg-surface-base px-3 py-2 font-mono text-xs leading-relaxed text-fg placeholder:text-fg-subtle focus:border-edge-strong focus:outline-none`,value:a[e],disabled:s,spellCheck:!1,placeholder:`{}`,onChange:t=>o({...a,[e]:t.target.value})})]},e))}),t[20]=s,t[21]=u,t[22]=a,t[23]=c.fieldHints,t[24]=c.fieldLabels,t[25]=o,t[26]=_):_=t[26];let v;t[27]!==h||t[28]!==g||t[29]!==_?(v=(0,H.jsxs)(`section`,{children:[h,g,_]}),t[27]=h,t[28]=g,t[29]=_,t[30]=v):v=t[30];let y;return t[31]!==m||t[32]!==v?(y=(0,H.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[m,v]}),t[31]=m,t[32]=v,t[33]=y):y=t[33],y}function U(e){return e.name||e.directoryId}function ve(e){let t=(0,V.c)(56),{mode:n,selected:r,catalog:i,loading:a,disabled:s,onModeChange:c,onSelectedChange:l,labels:u}=e,d=n===`allowlist`||n===`denylist`,f;t[0]===i?f=t[1]:(f=i.map(U).filter(Boolean),t[0]=i,t[1]=f);let p=f,m;bb0:{if(n===`inherit`){m=u.inheritSummary;break bb0}if(n===`all`){m=u.allSummary;break bb0}if(n===`off`){m=u.offSummary;break bb0}let e=n===`allowlist`?u.allowSummary:u.denySummary,i;t[2]!==r.size||t[3]!==e?(i=e.replace(`{{count}}`,String(r.size)),t[2]=r.size,t[3]=e,t[4]=i):i=t[4],m=i}let g=m,_;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,H.jsx)(h,{className:`size-3.5`,"aria-hidden":!0}),t[5]=_):_=t[5];let v;t[6]===u.overrideSummaryTitle?v=t[7]:(v=(0,H.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-medium text-fg-muted`,children:[_,u.overrideSummaryTitle]}),t[6]=u.overrideSummaryTitle,t[7]=v);let y;t[8]===g?y=t[9]:(y=(0,H.jsx)(`p`,{className:`mt-1 text-sm text-fg`,children:g}),t[8]=g,t[9]=y);let x;t[10]!==v||t[11]!==y?(x=(0,H.jsxs)(`div`,{className:`rounded-lg bg-surface-panel/70 px-3 py-2 shadow-surface`,children:[v,y]}),t[10]=v,t[11]=y,t[12]=x):x=t[12];let S;t[13]===u.modeLabel?S=t[14]:(S=(0,H.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:u.modeLabel}),t[13]=u.modeLabel,t[14]=S);let C;t[15]===u.modeInherit?C=t[16]:(C=[`inherit`,u.modeInherit],t[15]=u.modeInherit,t[16]=C);let w;t[17]===u.modeAll?w=t[18]:(w=[`all`,u.modeAll],t[17]=u.modeAll,t[18]=w);let T;t[19]===u.modeAllowlist?T=t[20]:(T=[`allowlist`,u.modeAllowlist],t[19]=u.modeAllowlist,t[20]=T);let E;t[21]===u.modeDenylist?E=t[22]:(E=[`denylist`,u.modeDenylist],t[21]=u.modeDenylist,t[22]=E);let D;t[23]===u.modeOff?D=t[24]:(D=[`off`,u.modeOff],t[23]=u.modeOff,t[24]=D);let O;t[25]!==E||t[26]!==D||t[27]!==C||t[28]!==w||t[29]!==T?(O=[C,w,T,E,D],t[25]=E,t[26]=D,t[27]=C,t[28]=w,t[29]=T,t[30]=O):O=t[30];let k=O,A;t[31]!==s||t[32]!==n||t[33]!==c||t[34]!==k?(A=(0,H.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:k.map(e=>{let[t,r]=e;return(0,H.jsx)(`button`,{type:`button`,className:o(`rounded-lg px-3 py-2 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,n===t?`bg-accent-soft text-accent-fg`:`bg-surface-panel text-fg hover:bg-surface-hover/55`),disabled:s,onClick:()=>c(t),children:r},t)})}),t[31]=s,t[32]=n,t[33]=c,t[34]=k,t[35]=A):A=t[35];let j;t[36]!==A||t[37]!==S?(j=(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[S,A]}),t[36]=A,t[37]=S,t[38]=j):j=t[38];let M;t[39]!==i||t[40]!==p||t[41]!==s||t[42]!==u.emptyCatalog||t[43]!==u.noDescription||t[44]!==u.quickActionsLabel||t[45]!==u.quickClear||t[46]!==u.quickSelectAll||t[47]!==a||t[48]!==l||t[49]!==d||t[50]!==r?(M=d?(0,H.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:u.quickActionsLabel}),(0,H.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,H.jsx)(b,{type:`button`,variant:`secondary`,className:z,disabled:s||a||p.length===0,onClick:()=>l(new Set(p)),children:u.quickSelectAll}),(0,H.jsx)(b,{type:`button`,variant:`secondary`,className:z,disabled:s||a||r.size===0,onClick:()=>l(new Set),children:u.quickClear})]})]}),a?(0,H.jsx)(L,{rows:3}):i.length===0?(0,H.jsx)(`p`,{className:`text-sm text-fg-muted`,children:u.emptyCatalog}):(0,H.jsx)(`ul`,{className:`flex flex-col gap-2.5 text-sm`,children:i.map(e=>{let t=U(e),n=r.has(t),i=typeof e.description==`string`?e.description.trim():``,a=i||u.noDescription;return(0,H.jsx)(`li`,{className:`h-16 shrink-0 overflow-hidden rounded-xl bg-surface-panel/70 px-3 shadow-surface`,children:(0,H.jsxs)(`label`,{className:`flex h-full cursor-pointer items-center gap-3 text-sm`,children:[(0,H.jsx)(`input`,{type:`checkbox`,className:`shrink-0 rounded border-edge`,checked:n,disabled:s,onChange:()=>{let e=new Set(r);n?e.delete(t):e.add(t),l(e)},"aria-label":t}),(0,H.jsxs)(`div`,{className:`min-w-0 flex-1 overflow-hidden`,children:[(0,H.jsx)(`div`,{className:`truncate font-mono text-xs font-medium text-fg`,title:t,children:t}),(0,H.jsx)(`p`,{className:o(`mt-0.5 truncate text-xs leading-tight text-fg-muted`,!i&&`italic text-fg-subtle`),title:a,children:a})]})]})},t)})})]}):null,t[39]=i,t[40]=p,t[41]=s,t[42]=u.emptyCatalog,t[43]=u.noDescription,t[44]=u.quickActionsLabel,t[45]=u.quickClear,t[46]=u.quickSelectAll,t[47]=a,t[48]=l,t[49]=d,t[50]=r,t[51]=M):M=t[51];let N;return t[52]!==j||t[53]!==M||t[54]!==x?(N=(0,H.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[x,j,M]}),t[52]=j,t[53]=M,t[54]=x,t[55]=N):N=t[55],N}var W=[`write_file`,`apply_patch`,`exec_command`,`execute_code`],G=[`exec_command`,`execute_code`,`automation`,`extensions`,`bundle-mcp`,`skill_manage`],K=[`send_message`,`send_media`,`text_to_speech`,`create_share`],ye=[`read_file`,`list_dir`,`grep`,`find`,`web_search`,`web_fetch`,`web_extract`],be=[...W,...K],q=[`read_file`,`write_file`,`apply_patch`,`list_dir`,`grep`,`find`,`web_search`,`web_fetch`],xe=[`send_message`,`send_media`];function Se(e,t){let n={};for(let[r,i]of t)for(let t of r)e.has(t)&&(n[t]={mode:i});return n}function Ce(e){let t=(0,V.c)(105),{builtinToolIds:n,toolPolicies:r,onChange:i,disabled:a,getToolDescription:s,getGroupTitle:c,labels:l}=e,u;t[0]===n?u=t[1]:(u=new Set(n),t[0]=n,t[1]=u);let d=u,f;t[2]!==d||t[3]!==r?(f=Object.entries(r).filter(e=>{let[t]=e;return d.has(t)}).toSorted(J),t[2]=d,t[3]=r,t[4]=f):f=t[4];let p=f,m;if(t[5]!==d||t[6]!==n){m=[];for(let e of ue){let t=e.toolIds.filter(e=>d.has(e));t.length>0&&m.push({key:e.key,ids:[...t]})}let e;t[8]===n?e=t[9]:(e=fe(n),t[8]=n,t[9]=e);let r=e;if(r.length>0){let e;t[10]===r?e=t[11]:(e={key:`misc`,ids:r},t[10]=r,t[11]=e),m.push(e)}t[5]=d,t[6]=n,t[7]=m}else m=t[7];let h=m,g;t[12]!==i||t[13]!==r?(g=(e,t)=>{let n={...r};t===`inherit`?delete n[e]:n[e]={...n[e],mode:t},i(n)},t[12]=i,t[13]=r,t[14]=g):g=t[14];let _=g,v;t[15]!==i||t[16]!==r?(v=(e,t)=>{let n=r[e];n&&i({...r,[e]:t(n)})},t[15]=i,t[16]=r,t[17]=v):v=t[17];let y=v,x;t[18]!==d||t[19]!==i?(x=e=>{i(Se(d,e))},t[18]=d,t[19]=i,t[20]=x):x=t[20];let S=x;if(n.length===0){let e;return t[21]===l.emptyBuiltin?e=t[22]:(e=(0,H.jsx)(`p`,{className:`text-sm text-fg-muted`,children:l.emptyBuiltin}),t[21]=l.emptyBuiltin,t[22]=e),e}let C;t[23]===l.quickActionsLabel?C=t[24]:(C=(0,H.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:l.quickActionsLabel}),t[23]=l.quickActionsLabel,t[24]=C);let w;t[25]===i?w=t[26]:(w=()=>i({}),t[25]=i,t[26]=w);let T;t[27]!==a||t[28]!==l.quickClearOverrides||t[29]!==w?(T=(0,H.jsx)(b,{type:`button`,variant:`secondary`,className:z,disabled:a,onClick:w,children:l.quickClearOverrides}),t[27]=a,t[28]=l.quickClearOverrides,t[29]=w,t[30]=T):T=t[30];let E;t[31]===S?E=t[32]:(E=()=>S([[W,`deny`]]),t[31]=S,t[32]=E);let D;t[33]!==a||t[34]!==l.quickReadOnlyWorkspace||t[35]!==E?(D=(0,H.jsx)(b,{type:`button`,variant:`secondary`,className:z,disabled:a,onClick:E,children:l.quickReadOnlyWorkspace}),t[33]=a,t[34]=l.quickReadOnlyWorkspace,t[35]=E,t[36]=D):D=t[36];let O;t[37]===S?O=t[38]:(O=()=>S([[G,`deny`]]),t[37]=S,t[38]=O);let k;t[39]!==a||t[40]!==l.quickHighRiskOff||t[41]!==O?(k=(0,H.jsx)(b,{type:`button`,variant:`secondary`,className:z,disabled:a,onClick:O,children:l.quickHighRiskOff}),t[39]=a,t[40]=l.quickHighRiskOff,t[41]=O,t[42]=k):k=t[42];let A;t[43]===S?A=t[44]:(A=()=>S([[K,`deny`]]),t[43]=S,t[44]=A);let j;t[45]!==a||t[46]!==l.quickNoOutbound||t[47]!==A?(j=(0,H.jsx)(b,{type:`button`,variant:`secondary`,className:z,disabled:a,onClick:A,children:l.quickNoOutbound}),t[45]=a,t[46]=l.quickNoOutbound,t[47]=A,t[48]=j):j=t[48];let M;t[49]===S?M=t[50]:(M=()=>S([[ye,`allow`],[be,`deny`]]),t[49]=S,t[50]=M);let N;t[51]!==a||t[52]!==l.quickResearchMode||t[53]!==M?(N=(0,H.jsx)(b,{type:`button`,variant:`secondary`,className:z,disabled:a,onClick:M,children:l.quickResearchMode}),t[51]=a,t[52]=l.quickResearchMode,t[53]=M,t[54]=N):N=t[54];let P;t[55]===S?P=t[56]:(P=()=>S([[q,`allow`],[xe,`deny`]]),t[55]=S,t[56]=P);let F;t[57]!==a||t[58]!==l.quickCodingMode||t[59]!==P?(F=(0,H.jsx)(b,{type:`button`,variant:`secondary`,className:z,disabled:a,onClick:P,children:l.quickCodingMode}),t[57]=a,t[58]=l.quickCodingMode,t[59]=P,t[60]=F):F=t[60];let te;t[61]!==k||t[62]!==j||t[63]!==N||t[64]!==F||t[65]!==T||t[66]!==D?(te=(0,H.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[T,D,k,j,N,F]}),t[61]=k,t[62]=j,t[63]=N,t[64]=F,t[65]=T,t[66]=D,t[67]=te):te=t[67];let ne;t[68]!==te||t[69]!==C?(ne=(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[C,te]}),t[68]=te,t[69]=C,t[70]=ne):ne=t[70];let re;t[71]===l.overrideSummaryTitle?re=t[72]:(re=(0,H.jsx)(`div`,{className:`text-xs font-medium text-fg-muted`,children:l.overrideSummaryTitle}),t[71]=l.overrideSummaryTitle,t[72]=re);let ie;t[73]!==l.modeAllow||t[74]!==l.modeConfirm||t[75]!==l.modeDeny||t[76]!==l.noOverrides||t[77]!==p?(ie=p.length>0?(0,H.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-1.5`,children:p.map(e=>{let[t,n]=e;return(0,H.jsxs)(`span`,{className:o(`inline-flex items-center gap-1 rounded-full border px-2 py-0.5 font-mono text-[11px]`,n.mode===`deny`&&`border-red-500/25 bg-red-500/10 text-red-700 dark:text-red-300`,n.mode===`confirm`&&`border-amber-500/25 bg-amber-500/10 text-amber-700 dark:text-amber-300`,n.mode===`allow`&&`border-accent/25 bg-accent/10 text-accent`),children:[t,(0,H.jsx)(`span`,{className:`font-sans opacity-80`,children:n.mode===`allow`?l.modeAllow:n.mode===`confirm`?l.modeConfirm:l.modeDeny})]},t)})}):(0,H.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:l.noOverrides}),t[73]=l.modeAllow,t[74]=l.modeConfirm,t[75]=l.modeDeny,t[76]=l.noOverrides,t[77]=p,t[78]=ie):ie=t[78];let ae;t[79]!==re||t[80]!==ie?(ae=(0,H.jsxs)(`div`,{className:`rounded-lg bg-surface-panel/70 px-3 py-2 shadow-surface`,children:[re,ie]}),t[79]=re,t[80]=ie,t[81]=ae):ae=t[81];let L;t[82]!==a||t[83]!==c||t[84]!==s||t[85]!==h||t[86]!==l.inheritedMode||t[87]!==l.maxCallsLabel||t[88]!==l.modeAllow||t[89]!==l.modeConfirm||t[90]!==l.modeDeny||t[91]!==l.scopeInherit||t[92]!==l.scopeLabel||t[93]!==l.scopeReadonly||t[94]!==l.scopeUnrestricted||t[95]!==l.scopeWorkspace||t[96]!==l.timeoutLabel||t[97]!==_||t[98]!==r||t[99]!==y?(L=(0,H.jsx)(`div`,{className:`flex flex-col gap-5`,children:h.map(e=>{let{key:t,ids:n}=e;return(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-fg-muted`,children:c(t)}),(0,H.jsx)(`ul`,{className:`flex flex-col gap-2.5`,children:n.map(e=>{let t=s(e),n=r[e],i=n?n.mode:`inherit`;return(0,H.jsxs)(`li`,{className:o(`rounded-xl px-3 py-2.5 shadow-surface transition-colors`,i===`inherit`?`bg-surface-panel/50`:`bg-surface-panel`),children:[(0,H.jsxs)(`div`,{className:`grid gap-2 md:grid-cols-[minmax(0,1fr)_auto] md:items-center`,children:[(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsx)(`div`,{className:`font-mono text-xs font-medium text-fg`,children:e}),t?(0,H.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-fg-muted`,children:t}):null]}),(0,H.jsx)(`div`,{className:`inline-flex w-fit rounded-lg border border-edge-subtle bg-surface-base p-0.5`,children:[`inherit`,`allow`,`confirm`,`deny`].map(t=>(0,H.jsx)(`button`,{type:`button`,className:o(`rounded-md px-2.5 py-1.5 text-xs font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,i===t?`bg-surface-panel text-fg shadow-surface`:`text-fg-muted hover:text-fg`),disabled:a,onClick:()=>_(e,t),children:t===`inherit`?l.inheritedMode:t===`allow`?l.modeAllow:t===`confirm`?l.modeConfirm:l.modeDeny},t))})]}),n?(0,H.jsxs)(`div`,{className:`mt-3 grid gap-2 border-t border-edge-subtle pt-3 sm:grid-cols-3 dark:border-edge`,children:[(0,H.jsxs)(`label`,{className:`flex flex-col gap-1 text-xs text-fg-muted`,children:[l.scopeLabel,(0,H.jsxs)(ee,{value:n.scope??``,disabled:a,onChange:t=>y(e,e=>{let n=t.target.value;if(!n){let{scope:t,...n}=e;return n}return{...e,scope:n}}),children:[(0,H.jsx)(I,{value:``,children:l.scopeInherit}),(0,H.jsx)(I,{value:`readonly`,children:l.scopeReadonly}),(0,H.jsx)(I,{value:`workspace`,children:l.scopeWorkspace}),(0,H.jsx)(I,{value:`unrestricted`,children:l.scopeUnrestricted})]})]}),(0,H.jsx)(Te,{label:l.maxCallsLabel,value:n.limits?.maxCallsPerTurn,disabled:a,onChange:t=>y(e,e=>we(e,`maxCallsPerTurn`,t))}),(0,H.jsx)(Te,{label:l.timeoutLabel,value:n.limits?.timeoutMs,disabled:a,onChange:t=>y(e,e=>we(e,`timeoutMs`,t))})]}):null]},e)})})]},t)})}),t[82]=a,t[83]=c,t[84]=s,t[85]=h,t[86]=l.inheritedMode,t[87]=l.maxCallsLabel,t[88]=l.modeAllow,t[89]=l.modeConfirm,t[90]=l.modeDeny,t[91]=l.scopeInherit,t[92]=l.scopeLabel,t[93]=l.scopeReadonly,t[94]=l.scopeUnrestricted,t[95]=l.scopeWorkspace,t[96]=l.timeoutLabel,t[97]=_,t[98]=r,t[99]=y,t[100]=L):L=t[100];let R;return t[101]!==ne||t[102]!==ae||t[103]!==L?(R=(0,H.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[ne,ae,L]}),t[101]=ne,t[102]=ae,t[103]=L,t[104]=R):R=t[104],R}function J(e,t){let[n]=e,[r]=t;return n.localeCompare(r)}function we(e,t,n){let r={...e.limits};if(n===void 0?delete r[t]:r[t]=n,Object.keys(r).length===0){let{limits:t,...n}=e;return n}return{...e,limits:r}}function Te(e){let t=(0,V.c)(9),n=e.value??``,r;t[0]===e?r=t[1]:(r=t=>{let n=t.target.value.trim();e.onChange(n?Number(n):void 0)},t[0]=e,t[1]=r);let i;t[2]!==e.disabled||t[3]!==n||t[4]!==r?(i=(0,H.jsx)(`input`,{type:`number`,min:1,step:1,className:`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg focus:border-edge-strong focus:outline-none`,value:n,disabled:e.disabled,onChange:r}),t[2]=e.disabled,t[3]=n,t[4]=r,t[5]=i):i=t[5];let a;return t[6]!==e.label||t[7]!==i?(a=(0,H.jsxs)(`label`,{className:`flex flex-col gap-1 text-xs text-fg-muted`,children:[e.label,i]}),t[6]=e.label,t[7]=i,t[8]=a):a=t[8],a}var Ee=[`blank`,`safe-coder`,`read-only`,`low-cost`],De=[{id:`overview`,icon:_},{id:`models`,icon:j},{id:`tools`,icon:v},{id:`skills`,icon:w},{id:`advanced`,icon:F},{id:`impact`,icon:f}];function Oe(e){return he(Object.entries(e?.models?.roles??{}).map(([e,t])=>({id:e,model:t.model,fallbacks:t.fallbacks??[],description:t.description})))}function ke(e){return structuredClone(e?.tools?.builtin??{})}function Ae(e){let t=e?.skills;if(!t)return new Set;let n=t.mode===`denylist`?t.deny:t.allow;return new Set(n??[])}function je(){return{primary:``,fallbacks:``,timeoutMs:``,autoProviderFallback:``}}function Me(e){return{primary:e?.primary??``,fallbacks:e?.fallbacks?.join(`
2
+ `)??``,timeoutMs:e?.timeoutMs?String(e.timeoutMs):``,autoProviderFallback:e?.autoProviderFallback===void 0?``:e.autoProviderFallback?`true`:`false`}}function Ne(){return{imageModel:je(),imageGenerationModel:je(),allowFallbacks:``,maxCostTier:``}}function Y(e){return{imageModel:Me(e?.models?.imageModel),imageGenerationModel:Me(e?.models?.imageGenerationModel),allowFallbacks:e?.models?.policy?.allowFallbacks===void 0?``:e.models.policy.allowFallbacks?`true`:`false`,maxCostTier:e?.models?.policy?.maxCostTier??``}}function X(e){return e===void 0?``:JSON.stringify(e,null,2)}function Z(){return{mcp:``,workflows:``,boundaries:``,runtime:``,locks:``}}function Pe(e){return{mcp:X(e?.tools?.mcp),workflows:X(e?.workflows),boundaries:X(e?.boundaries),runtime:X(e?.runtime),locks:X(e?.locks)}}function Fe(e){return{id:e?.id??``,name:e?.name??``,description:e?.description??``,modelRows:Oe(e),modelAdvanced:Y(e),toolPolicies:ke(e),skillMode:e?.skills?.mode??`inherit`,skillPick:Ae(e),extendsIds:[...e?.extends??[]],jsonFields:Pe(e)}}function Ie(e){let t=e.primary.trim();if(!t)return;let n=e.fallbacks.split(/\r?\n|,/).map(e=>e.trim()).filter(Boolean),r=e.timeoutMs.trim()?Number(e.timeoutMs):void 0,i=e.autoProviderFallback===``?void 0:e.autoProviderFallback===`true`;return{primary:t,...n.length>0?{fallbacks:n}:{},...r?{timeoutMs:r}:{},...i===void 0?{}:{autoProviderFallback:i}}}function Le(e,t){let n=ge(e.modelRows),r=Ie(e.modelAdvanced.imageModel),i=Ie(e.modelAdvanced.imageGenerationModel),a=e.modelAdvanced.allowFallbacks||e.modelAdvanced.maxCostTier?{...e.modelAdvanced.allowFallbacks?{allowFallbacks:e.modelAdvanced.allowFallbacks===`true`}:{},...e.modelAdvanced.maxCostTier?{maxCostTier:e.modelAdvanced.maxCostTier}:{}}:void 0,o={...t?.models?.defaultRole?{defaultRole:t.models.defaultRole}:{},...n?.roles?{roles:n.roles}:{},...r?{imageModel:r}:{},...i?{imageGenerationModel:i}:{},...a?{policy:a}:{}};return Object.keys(o).length>0?o:null}function Re(e){return e.trim()?JSON.parse(e):void 0}function Q(e){if(!e.trim())return``;try{return JSON.stringify(JSON.parse(e))}catch{return`!invalid:${e}`}}function $(e){let t=Object.fromEntries(Object.entries(e.toolPolicies).toSorted(([e],[t])=>e.localeCompare(t))),n=Re(e.jsonFields.mcp);return Object.keys(t).length>0||n?{builtin:t,...n?{mcp:n}:{}}:null}function ze(e){return Object.fromEntries(Object.entries(e??{}).toSorted(([e],[t])=>e.localeCompare(t)))}function Be(e){if(e.skillMode===`inherit`)return null;let t=[...e.skillPick].toSorted((e,t)=>e.localeCompare(t));return e.skillMode===`allowlist`?{mode:`allowlist`,allow:t}:e.skillMode===`denylist`?{mode:`denylist`,deny:t}:{mode:e.skillMode}}function Ve(e,t){return{id:e.id.trim(),name:e.name.trim(),description:e.description.trim(),models:Le(e,t),tools:{builtin:ze(e.toolPolicies),mcp:Q(e.jsonFields.mcp)},skills:Be(e),extends:[...e.extendsIds].toSorted(),workflows:Q(e.jsonFields.workflows),boundaries:Q(e.jsonFields.boundaries),runtime:Q(e.jsonFields.runtime),locks:Q(e.jsonFields.locks)}}function He(e){return e?{id:e.id,name:e.name,description:e.description??``,models:e.models??null,tools:{builtin:ze(e.tools?.builtin),mcp:Q(X(e.tools?.mcp))},skills:e.skills??null,extends:[...e.extends??[]].toSorted(),workflows:Q(X(e.workflows)),boundaries:Q(X(e.boundaries)),runtime:Q(X(e.runtime)),locks:Q(X(e.locks))}:null}function Ue(e,t){return[e.models?.roles?t.summaryModels.replace(`{{count}}`,String(Object.keys(e.models.roles).length)):``,e.tools?.builtin?t.summaryTools.replace(`{{count}}`,String(Object.keys(e.tools.builtin).length)):``,e.skills?t.summarySkills.replace(`{{mode}}`,t.skillModeLabels[e.skills.mode]):``].filter(Boolean).join(` · `)||t.summaryEmpty}function We(){return{modelAdvanced:Ne(),extendsIds:[],jsonFields:Z()}}function Ge(e,t){return{extends:[...e.extendsIds],models:Le(e,t)??void 0,tools:$(e)??void 0,skills:Be(e)??void 0,workflows:Re(e.jsonFields.workflows),boundaries:Re(e.jsonFields.boundaries),runtime:Re(e.jsonFields.runtime),locks:Re(e.jsonFields.locks)}}function Ke(e,t){return e===`safe-coder`?{id:`safe-coder`,name:t.starters[`safe-coder`].title,description:t.starters[`safe-coder`].description,modelRows:[{id:`deep`,model:``,fallbacks:[],description:t.modelRoleDescriptions.deep},{id:`code`,model:``,fallbacks:[],description:t.modelRoleDescriptions.code},{id:`review`,model:``,fallbacks:[],description:t.modelRoleDescriptions.review}],toolPolicies:{exec_command:{mode:`deny`},send_message:{mode:`deny`},send_media:{mode:`deny`}},skillMode:`allowlist`,skillPick:new Set([`diagnose`,`tdd`]),...We()}:e===`read-only`?{id:`read-only-research`,name:t.starters[`read-only`].title,description:t.starters[`read-only`].description,modelRows:[{id:`deep`,model:``,fallbacks:[],description:t.modelRoleDescriptions.deep},{id:`fast`,model:``,fallbacks:[],description:t.modelRoleDescriptions.fast}],toolPolicies:{write_file:{mode:`deny`},apply_patch:{mode:`deny`},exec_command:{mode:`deny`},send_message:{mode:`deny`},send_media:{mode:`deny`}},skillMode:`all`,skillPick:new Set,...We()}:e===`low-cost`?{id:`low-cost-assistant`,name:t.starters[`low-cost`].title,description:t.starters[`low-cost`].description,modelRows:[{id:`deep`,model:``,fallbacks:[],description:t.modelRoleDescriptions.deep},{id:`fast`,model:``,fallbacks:[],description:t.modelRoleDescriptions.fast},{id:`cheap`,model:``,fallbacks:[],description:t.modelRoleDescriptions.cheap}],toolPolicies:{},skillMode:`inherit`,skillPick:new Set,...We()}:{id:``,name:``,description:``,modelRows:[],toolPolicies:{},skillMode:`inherit`,skillPick:new Set,...We()}}function qe(){let e=s(l(e=>e.language)),t=e.capabilityPresetsSettings,n=(0,H.jsx)(b,{asChild:!0,type:`button`,variant:`secondary`,children:(0,H.jsxs)(a,{to:`/agents`,children:[t.manageAgents,(0,H.jsx)(x,{className:`size-4`,"aria-hidden":!0})]})}),r=!!c(e=>e.token),{data:h,error:I,isLoading:ee,mutate:L}=u(r?`settings-capability-presets`:null,de,{revalidateOnFocus:!1}),{data:ue=[],isLoading:fe}=u(r?`settings-capability-presets-skills-catalog`:null,m,{revalidateOnFocus:!1}),[he,z]=i(),[ge,V]=(0,B.useState)(``),[U,W]=(0,B.useState)(`overview`),[G,K]=(0,B.useState)(()=>Ke(`blank`,t)),[ye,be]=(0,B.useState)(null),[q,xe]=(0,B.useState)(!1),[Se,J]=(0,B.useState)(null),[we,Te]=(0,B.useState)(!1),[Oe,ke]=(0,B.useState)(null),[Ae,je]=(0,B.useState)(null),Me=h?.presets??[],Ne=h?.defaultPresetId??`default`,Y=Me.find(e=>e.id===Ne)??null,X=Me.filter(e=>e.id!==Ne),Z=(0,B.useMemo)(()=>Me.find(e=>e.id===ge)??Me[0]??null,[Me,ge]),Pe=!Z||G.id.trim()!==Z.id,Ie=!!(Z&&Z.id===Ne),Le=JSON.stringify(Ve(G,Z))!==JSON.stringify(He(Z)),Q=Ve(G,Z),$=He(Z),ze=[Q.id!==$?.id||Q.name!==$?.name||Q.description!==$?.description?t.tabs.overview:``,JSON.stringify(Q.models)===JSON.stringify($?.models)?``:t.tabs.models,JSON.stringify(Q.tools)===JSON.stringify($?.tools)?``:t.tabs.tools,JSON.stringify(Q.skills)===JSON.stringify($?.skills)?``:t.tabs.skills,JSON.stringify({extends:Q.extends,workflows:Q.workflows,boundaries:Q.boundaries,runtime:Q.runtime,locks:Q.locks})===JSON.stringify({extends:$?.extends,workflows:$?.workflows,boundaries:$?.boundaries,runtime:$?.runtime,locks:$?.locks})?``:t.tabs.advanced].filter(Boolean),Be=Se??(I instanceof Error?I.message:null),We=he.get(`action`)===`new`||!!he.get(`preset`),qe=he.get(`action`)===`new`&&ye===null,Xe=Pe?t.newPreset:Z?.name??t.editorTitle,Ze=t=>e.agentsSettings.toolsDisableGroups[t],Qe=t=>t in e.agentsSettings.toolDescriptions?e.agentsSettings.toolDescriptions[t]:``;(0,B.useEffect)(()=>{if(!h||q)return;if(he.get(`action`)===`new`){V(``),K(Ke(`blank`,t)),W(`overview`);return}let e=he.get(`preset`)?.trim(),n=e?h.presets.find(t=>t.id===e):null;if(n){V(n.id),K(Fe(n)),W(he.get(`tab`)??`overview`);return}Z&&(V(Z.id),K(e=>e.id===Z.id?e:Fe(Z)))},[q,h,he,Z]);function $e(e){be(null),V(e.id),K(Fe(e)),z({preset:e.id},{replace:!0}),W(`overview`)}function et(){be(null),V(``),K(Ke(`blank`,t)),J(null),z({action:`new`},{replace:!0}),W(`overview`)}function tt(e){be(e),K(Ke(e,t)),J(null),W(`overview`)}function nt(){if(ye){let e=Ke(ye,t);if(JSON.stringify(Ve(G,null))!==JSON.stringify(Ve(e,null))&&!window.confirm(t.changeTemplateConfirm))return}be(null),J(null)}function rt(){!qe&&Le&&!window.confirm(t.discardConfirm)||(Te(!1),ke(null),z({},{replace:!0}),be(null),J(null),K(Fe(Z)),W(`overview`))}async function it(){let e=me(G.modelRows,{invalidId:t.invalidModelRoleId,duplicateId:t.duplicateModelRoleId,invalidModel:t.invalidModelRef});if(e){J(e),W(`models`);return}for(let e of[G.modelAdvanced.imageModel,G.modelAdvanced.imageGenerationModel]){if([e.primary,...e.fallbacks.split(/\r?\n|,/)].map(e=>e.trim()).filter(Boolean).some(e=>!/^[^/\s]+\/.+/.test(e))){J(t.invalidModelRef),W(`models`);return}if(e.timeoutMs.trim()&&(!Number.isInteger(Number(e.timeoutMs))||Number(e.timeoutMs)<=0)){J(t.advancedPositiveIntegerError),W(`models`);return}}for(let e of Object.values(G.toolPolicies))if([e.limits?.maxCallsPerTurn,e.limits?.timeoutMs].filter(e=>e!==void 0).some(e=>!Number.isInteger(e)||e<=0)){J(t.advancedPositiveIntegerError),W(`tools`);return}for(let e of Object.keys(G.jsonFields))try{Re(G.jsonFields[e])}catch{J(t.advancedJsonError.replace(`{{field}}`,t.advancedFieldLabels[e])),W(`advanced`);return}xe(!0),J(null);try{let e=Ge(G,Z);if(Pe){let t=await pe({id:G.id.trim(),name:G.name.trim(),...G.description.trim()?{description:G.description.trim()}:{},...e});await L(t.presets,{revalidate:!1}),V(t.presetId),be(null),z({preset:t.presetId},{replace:!0})}else Z&&await L(await ce(Z.id,{name:G.name.trim(),description:G.description.trim()||null,extends:e.extends??null,models:e.models??null,tools:e.tools??null,skills:e.skills??null,workflows:e.workflows??null,boundaries:e.boundaries??null,runtime:e.runtime??null,locks:e.locks??null}),{revalidate:!1})}catch(e){J(e instanceof Error?e.message:t.saveError)}finally{xe(!1)}}async function at(){if(Z){xe(!0),J(null),ke(null);try{await L(await le(Z.id),{revalidate:!1}),Te(!1),V(``),be(null),K(Ke(`blank`,t)),W(`overview`),z({},{replace:!0})}catch(e){ke(e instanceof Error?e.message:t.deleteError)}finally{xe(!1)}}}return r?(0,H.jsxs)(ie,{gap:`gap-5`,className:`pb-24`,children:[(0,H.jsx)(re,{title:t.title,subtitle:t.subtitle,actions:(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[n,(0,H.jsxs)(b,{type:`button`,onClick:et,disabled:q,children:[(0,H.jsx)(y,{className:`size-4`,"aria-hidden":!0}),t.newPreset]})]})}),Be?(0,H.jsx)(`div`,{className:`rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-800 dark:border-red-900/50 dark:bg-red-950/40 dark:text-red-200`,children:Be}):null,ee?(0,H.jsx)(ae,{sections:2}):(0,H.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[Y?(0,H.jsxs)(oe,{children:[(0,H.jsx)(R,{icon:j,title:t.globalDefaultsTitle,subtitle:t.globalDefaultsHint}),(0,H.jsxs)(`button`,{type:`button`,onClick:()=>$e(Y),className:`group rounded-lg bg-accent/5 px-4 py-3 text-left text-fg shadow-surface transition-colors hover:bg-accent/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,H.jsx)(`span`,{className:`text-sm font-semibold text-fg`,children:Y.name}),(0,H.jsx)(`span`,{className:`rounded-full bg-surface-panel px-2 py-0.5 text-[11px] font-medium text-accent`,children:t.globalDefaultsBadge})]}),(0,H.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-fg-subtle`,children:Y.id})]}),(0,H.jsx)(`span`,{className:`shrink-0 rounded-full bg-surface-panel px-2 py-0.5 text-[11px] font-medium text-fg-muted`,children:t.globalDefaultsInherited})]}),Y.description?(0,H.jsx)(`p`,{className:`mt-3 line-clamp-2 text-xs leading-relaxed text-fg-muted`,children:Y.description}):null,(0,H.jsx)(`div`,{className:`mt-3 text-xs text-fg-subtle`,children:Ue(Y,t)})]})]}):null,(0,H.jsxs)(oe,{children:[(0,H.jsx)(R,{icon:j,title:t.listTitle,subtitle:t.listHint}),X.length===0?(0,H.jsxs)(`div`,{className:`flex flex-col items-start gap-3 rounded-lg bg-surface-panel/70 px-3 py-4 text-sm text-fg-muted shadow-surface`,children:[(0,H.jsx)(`p`,{children:t.empty}),(0,H.jsxs)(b,{type:`button`,variant:`secondary`,onClick:et,disabled:q,children:[(0,H.jsx)(y,{className:`size-4`,"aria-hidden":!0}),t.newPreset]})]}):(0,H.jsx)(`div`,{className:`grid gap-3 md:grid-cols-2 xl:grid-cols-3`,children:X.map(e=>(0,H.jsxs)(`button`,{type:`button`,onClick:()=>$e(e),className:`group min-h-36 rounded-lg bg-surface-panel/80 px-4 py-3 text-left text-fg shadow-surface transition-colors hover:bg-surface-hover/55 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:[(0,H.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsx)(`div`,{className:`truncate text-sm font-semibold text-fg`,children:e.name}),(0,H.jsx)(`div`,{className:`mt-1 truncate font-mono text-[11px] text-fg-subtle`,children:e.id})]}),(0,H.jsx)(`span`,{className:`shrink-0 rounded-full bg-surface-hover px-2 py-0.5 text-[11px] font-medium text-fg-muted`,children:e.usage.length})]}),e.description?(0,H.jsx)(`p`,{className:`mt-3 line-clamp-2 text-xs leading-relaxed text-fg-muted`,children:e.description}):null,(0,H.jsx)(`div`,{className:`mt-3 truncate text-xs text-fg-subtle`,children:Ue(e,t)})]},e.id))})]})]}),(0,H.jsx)(C,{open:We,onOpenChange:e=>{e||rt()},children:(0,H.jsxs)(T,{children:[(0,H.jsx)(g,{className:o(`xopc-dialog-overlay fixed inset-0 bg-scrim`,P)}),(0,H.jsx)(p,{ref:je,className:o(`xopc-dialog-content fixed left-1/2 top-1/2 flex h-[min(90vh,760px)] w-[min(100%-2rem,64rem)] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-edge bg-surface-panel shadow-popover dark:border-edge`,A),onOpenAutoFocus:e=>e.preventDefault(),children:(0,H.jsxs)(M,{layer:`modal`,portalContainer:Ae,children:[(0,H.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge-subtle px-4 py-3 dark:border-edge`,children:[(0,H.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2`,children:[!qe&&Pe&&ye?(0,H.jsx)(`button`,{type:`button`,className:o(te,`shrink-0 p-1.5 hover:bg-surface-base`),onClick:nt,"aria-label":t.changeTemplate,title:t.changeTemplate,children:(0,H.jsx)(d,{className:`size-4`,"aria-hidden":!0})}):null,(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsx)(D,{className:`truncate text-base font-semibold text-fg`,children:Xe}),(0,H.jsx)(E,{className:`mt-0.5 truncate text-xs text-fg-muted`,children:qe?t.templatePickerSubtitle:Pe&&ye?`${t.editorHint} · ${t.basedOnTemplate.replace(`{{template}}`,t.starters[ye].title)}`:Pe?t.editorHint:G.id})]})]}),(0,H.jsx)(ne,{asChild:!0,children:(0,H.jsx)(`button`,{type:`button`,className:o(te,`shrink-0 p-1.5 hover:bg-surface-base`),"aria-label":t.closeDialog,children:(0,H.jsx)(N,{className:`size-4`,"aria-hidden":!0})})})]}),qe?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-4 sm:p-5`,children:(0,H.jsx)(`div`,{className:`mx-auto grid max-w-3xl gap-3 sm:grid-cols-2`,children:Ee.map(e=>(0,H.jsxs)(`button`,{type:`button`,className:`group min-h-32 rounded-xl border border-edge-subtle bg-surface-base px-4 py-4 text-left text-fg transition-colors hover:border-edge hover:bg-surface-hover/55 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,onClick:()=>tt(e),children:[(0,H.jsxs)(`span`,{className:`flex items-center justify-between gap-3`,children:[(0,H.jsx)(`span`,{className:`font-medium`,children:t.starters[e].title}),e===`blank`?(0,H.jsx)(`span`,{className:`rounded-full bg-accent-soft px-2 py-0.5 text-[11px] font-medium text-accent-fg`,children:t.templateRecommended}):null]}),(0,H.jsx)(`span`,{className:`mt-2 block text-xs leading-relaxed text-fg-muted`,children:t.starters[e].description})]},e))})}),(0,H.jsx)(`div`,{className:`flex shrink-0 justify-end border-t border-edge-subtle px-4 py-3 dark:border-edge`,children:(0,H.jsx)(b,{type:`button`,variant:`secondary`,onClick:rt,children:t.cancel})})]}):(0,H.jsxs)(H.Fragment,{children:[Be?(0,H.jsx)(`div`,{className:`mx-4 mt-3 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-800 dark:border-red-900/50 dark:bg-red-950/40 dark:text-red-200`,children:Be}):null,(0,H.jsx)(`div`,{className:`flex shrink-0 flex-wrap gap-2 border-b border-edge-subtle bg-surface-base px-4 py-2 dark:border-edge`,children:De.map(({id:e,icon:n})=>(0,H.jsxs)(`button`,{type:`button`,className:o(`inline-flex items-center gap-1.5 rounded-lg px-3 py-2 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,U===e?`bg-surface-panel text-fg shadow-surface`:`text-fg-muted hover:bg-surface-hover hover:text-fg`),onClick:()=>W(e),children:[(0,H.jsx)(n,{className:`size-4`,"aria-hidden":!0}),t.tabs[e]]},e))}),(0,H.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-4`,children:(0,H.jsxs)(`div`,{className:`w-full`,children:[U===`overview`?(0,H.jsxs)(oe,{children:[(0,H.jsx)(R,{icon:_,title:t.overviewTitle,subtitle:t.overviewHint}),(0,H.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,H.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,H.jsx)(`span`,{className:`font-medium text-fg`,children:t.idLabel}),(0,H.jsx)(`input`,{className:`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle focus:border-edge-strong focus:outline-none`,value:G.id,disabled:q||!Pe,onChange:e=>K(t=>({...t,id:e.target.value.toLowerCase()})),placeholder:`safe-coder`})]}),!Pe&&Z?(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,H.jsx)(`span`,{className:`font-medium text-fg`,children:t.versionLabel}),(0,H.jsx)(`div`,{className:`rounded-lg border border-edge bg-surface-base px-3 py-2 text-sm text-fg-muted`,children:t.versionAutomatic.replace(`{{version}}`,String(Z.version))})]}):null,(0,H.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm sm:col-span-2`,children:[(0,H.jsx)(`span`,{className:`font-medium text-fg`,children:t.nameLabel}),(0,H.jsx)(`input`,{className:`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle focus:border-edge-strong focus:outline-none`,value:G.name,disabled:q,onChange:e=>K(t=>({...t,name:e.target.value})),placeholder:t.namePlaceholder})]}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm sm:col-span-2`,children:[(0,H.jsx)(`span`,{className:`font-medium text-fg`,children:t.descriptionLabel}),(0,H.jsx)(`textarea`,{className:`min-h-24 w-full resize-y rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle focus:border-edge-strong focus:outline-none`,value:G.description,disabled:q,onChange:e=>K(t=>({...t,description:e.target.value})),placeholder:t.descriptionPlaceholder})]})]}),(0,H.jsxs)(`div`,{className:`mt-5 grid gap-2 sm:grid-cols-3`,children:[(0,H.jsx)(Je,{icon:j,label:t.modelsTitle,value:String(G.modelRows.length)}),(0,H.jsx)(Je,{icon:v,label:t.toolsTitle,value:String(Object.keys(G.toolPolicies).length)}),(0,H.jsx)(Je,{icon:w,label:t.skillsTitle,value:t.skillModeLabels[G.skillMode]})]})]}):null,U===`models`?(0,H.jsxs)(oe,{children:[(0,H.jsx)(R,{icon:j,title:t.modelsTitle,subtitle:t.modelsHint}),(0,H.jsx)(se,{rows:G.modelRows,onChange:e=>K(t=>({...t,modelRows:e})),disabled:q,defaultRole:Z?.models?.defaultRole,chat:e.chat,labels:{id:t.modelRoleIdLabel,description:t.modelRoleDescriptionLabel,primaryModel:t.modelPrimaryModelLabel,fallbackModels:t.modelFallbackModelsLabel,addFallback:t.modelAddFallback,removeFallback:t.modelRemoveFallback,fallbackPlaceholder:t.modelFallbackPlaceholder,fallbackEmptyHint:t.modelFallbackEmptyHint,add:t.addModelRole,remove:t.removeModelRole,recommendedTitle:t.modelRecommendedTitle,customTitle:t.modelCustomTitle,defaultBadge:t.modelDefaultBadge,visionBadge:t.modelVisionBadge,visionAutoHint:t.modelVisionAutoHint,addPurpose:t.addModelPurpose,noCustomRoles:t.noCustomModelRoles,idPlaceholder:`deep`,descriptionPlaceholder:t.modelRoleDescriptionPlaceholder,roleNames:t.modelRoleNames,roleDescriptions:t.modelRoleDescriptions}}),(0,H.jsx)(Ye,{value:G.modelAdvanced,onChange:e=>K(t=>({...t,modelAdvanced:e})),disabled:q,cp:t})]}):null,U===`tools`?(0,H.jsxs)(oe,{children:[(0,H.jsx)(R,{icon:v,title:t.toolsTitle,subtitle:t.toolsHint}),(0,H.jsx)(Ce,{builtinToolIds:h?.builtinToolIds??[],toolPolicies:G.toolPolicies,onChange:e=>K(t=>({...t,toolPolicies:e})),disabled:q,getToolDescription:Qe,getGroupTitle:Ze,labels:{quickActionsLabel:t.toolsQuickActionsLabel,quickClearOverrides:t.toolsQuickClearOverrides,quickReadOnlyWorkspace:t.toolsQuickReadOnlyWorkspace,quickHighRiskOff:t.toolsQuickHighRiskOff,quickNoOutbound:t.toolsQuickNoOutbound,quickResearchMode:t.toolsQuickResearchMode,quickCodingMode:t.toolsQuickCodingMode,emptyBuiltin:t.toolsEmptyBuiltin,overrideSummaryTitle:t.toolsOverrideSummaryTitle,noOverrides:t.toolsNoOverrides,inheritedMode:t.toolModes.inherit,modeAllow:t.toolModes.allow,modeConfirm:t.toolModes.confirm,modeDeny:t.toolModes.deny,scopeLabel:t.toolScopeLabel,scopeInherit:t.toolScopeInherit,scopeReadonly:t.toolScopeReadonly,scopeWorkspace:t.toolScopeWorkspace,scopeUnrestricted:t.toolScopeUnrestricted,maxCallsLabel:t.toolMaxCallsLabel,timeoutLabel:t.toolTimeoutLabel}})]}):null,U===`skills`?(0,H.jsxs)(oe,{children:[(0,H.jsx)(R,{icon:w,title:t.skillsTitle,subtitle:t.skillsHint}),(0,H.jsx)(ve,{mode:G.skillMode,selected:G.skillPick,catalog:ue,loading:fe,disabled:q,onModeChange:e=>K(t=>({...t,skillMode:e})),onSelectedChange:e=>K(t=>({...t,skillPick:e})),labels:{modeLabel:t.skillsModeLabel,modeInherit:t.skillsModeInherit,modeAll:t.skillsModeAll,modeAllowlist:t.skillsModeAllowlist,modeDenylist:t.skillsModeDenylist,modeOff:t.skillsModeOff,quickActionsLabel:t.skillsQuickActionsLabel,quickSelectAll:t.skillsQuickSelectAll,quickClear:t.skillsQuickClear,catalogLoading:t.skillsCatalogLoading,emptyCatalog:t.skillsEmptyCatalog,noDescription:t.skillsNoDescription,overrideSummaryTitle:t.skillsOverrideSummaryTitle,inheritSummary:t.skillsInheritSummary,allSummary:t.skillsAllSummary,offSummary:t.skillsOffSummary,allowSummary:t.skillsAllowSummary,denySummary:t.skillsDenySummary}})]}):null,U===`advanced`?(0,H.jsxs)(oe,{children:[(0,H.jsx)(R,{icon:F,title:t.advancedTitle,subtitle:t.advancedHint}),(0,H.jsx)(_e,{extendsIds:G.extendsIds,onExtendsChange:e=>K(t=>({...t,extendsIds:e})),presetOptions:Me.filter(e=>e.id!==Z?.id&&e.id!==Ne),jsonFields:G.jsonFields,onJsonFieldsChange:e=>K(t=>({...t,jsonFields:e})),disabled:q,labels:{inheritanceTitle:t.advancedInheritanceTitle,inheritanceHint:t.advancedInheritanceHint,inheritanceEmpty:t.advancedInheritanceEmpty,jsonTitle:t.advancedJsonTitle,jsonHint:t.advancedJsonHint,fieldLabels:t.advancedFieldLabels,fieldHints:t.advancedFieldHints}})]}):null,U===`impact`?(0,H.jsxs)(oe,{children:[(0,H.jsx)(R,{icon:f,title:t.usageTitle,subtitle:t.usageHint}),(0,H.jsxs)(`div`,{className:`mb-4 rounded-lg bg-surface-panel/70 px-3 py-2 shadow-surface`,children:[(0,H.jsx)(`div`,{className:`text-xs font-medium text-fg-muted`,children:t.changePreviewTitle}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-fg`,children:ze.length>0?t.changePreviewSections.replace(`{{sections}}`,ze.join(`、`)):t.changePreviewEmpty})]}),Z?.usage.length?(0,H.jsx)(`div`,{className:`grid gap-2`,children:Z.usage.map(e=>(0,H.jsxs)(`div`,{className:`rounded-lg bg-surface-panel/80 px-3 py-2 shadow-surface`,children:[(0,H.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.agentName||e.agentId}),(0,H.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-fg-muted`,children:e.agentId}),(0,H.jsx)(`div`,{className:`mt-1 text-[11px] text-fg-subtle`,children:e.direct?t.usageDirect:t.usageIndirect})]},e.agentId))}):(0,H.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.noUsage})]}):null]})}),(0,H.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-between gap-3 border-t border-edge-subtle px-4 py-3 dark:border-edge`,children:[(0,H.jsxs)(`div`,{className:`min-w-0 text-sm`,children:[(0,H.jsx)(`div`,{className:`font-medium text-fg`,children:Le?t.unsavedTitle:t.noUnsavedTitle}),(0,H.jsx)(`div`,{className:`text-xs text-fg-muted`,children:Le?(Z?.usage.length??0)>0?t.unsavedImpact.replace(`{{count}}`,String(Z?.usage.length??0)):t.unsavedNoImpact:t.noUnsavedHint})]}),(0,H.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[Le?(0,H.jsx)(b,{type:`button`,variant:`secondary`,disabled:q,onClick:()=>K(Fe(Z)),children:t.discard}):null,Z&&!Ie?(0,H.jsxs)(b,{type:`button`,variant:`secondary`,disabled:q,onClick:()=>{ke(null),Te(!0)},children:[(0,H.jsx)(O,{className:`size-4`,"aria-hidden":!0}),t.delete]}):null,(0,H.jsxs)(b,{type:`button`,disabled:q||!G.id.trim()||!G.name.trim()||!Le,onClick:()=>void it(),children:[(0,H.jsx)(k,{className:`size-4`,"aria-hidden":!0}),t.savePreset]})]})]})]})]})})]})}),(0,H.jsx)(C,{open:we,onOpenChange:e=>{q||(Te(e),e||ke(null))},children:(0,H.jsxs)(T,{children:[(0,H.jsx)(g,{className:o(`xopc-dialog-overlay fixed inset-0 bg-scrim`,P)}),(0,H.jsxs)(p,{className:o(`xopc-dialog-content fixed left-1/2 top-1/2 w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2 overflow-hidden rounded-xl border border-edge bg-surface-panel shadow-popover dark:border-edge`,A),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,H.jsxs)(`div`,{className:`border-b border-edge-subtle px-4 py-3 dark:border-edge`,children:[(0,H.jsx)(D,{className:`text-base font-semibold text-fg`,children:t.deleteDialogTitle}),(0,H.jsx)(E,{className:`mt-1 text-sm leading-relaxed text-fg-muted`,children:Z?t.deleteConfirm.replace(`{{name}}`,Z.name):t.deleteConfirmFallback})]}),Oe?(0,H.jsx)(`div`,{className:`mx-4 mt-4 rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-800 dark:border-red-900/50 dark:bg-red-950/40 dark:text-red-200`,children:Oe}):null,(0,H.jsxs)(`div`,{className:`flex justify-end gap-2 px-4 py-3`,children:[(0,H.jsx)(b,{type:`button`,variant:`secondary`,disabled:q,onClick:()=>Te(!1),children:t.cancel}),(0,H.jsxs)(b,{type:`button`,disabled:q||!Z,className:`bg-red-600 text-white shadow-surface hover:bg-red-700 focus-visible:ring-red-600 dark:bg-red-500 dark:hover:bg-red-600`,onClick:()=>void at(),children:[q?(0,H.jsx)(S,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,H.jsx)(O,{className:`size-4`,"aria-hidden":!0}),q?t.deleting:t.delete]})]})]})]})})]}):(0,H.jsxs)(ie,{gap:`gap-3`,children:[(0,H.jsx)(re,{title:t.title,actions:n}),(0,H.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.needToken})]})}function Je(e){let t=(0,V.c)(10),{icon:n,label:r,value:i}=e,a;t[0]===n?a=t[1]:(a=(0,H.jsx)(n,{className:`size-3.5`,"aria-hidden":!0}),t[0]=n,t[1]=a);let o;t[2]!==r||t[3]!==a?(o=(0,H.jsxs)(`div`,{className:`flex items-center gap-2 text-xs text-fg-muted`,children:[a,r]}),t[2]=r,t[3]=a,t[4]=o):o=t[4];let s;t[5]===i?s=t[6]:(s=(0,H.jsx)(`div`,{className:`mt-1 text-sm font-medium text-fg`,children:i}),t[5]=i,t[6]=s);let c;return t[7]!==o||t[8]!==s?(c=(0,H.jsxs)(`div`,{className:`rounded-lg bg-surface-panel/80 px-3 py-2 shadow-surface`,children:[o,s]}),t[7]=o,t[8]=s,t[9]=c):c=t[9],c}function Ye(e){let t=(0,V.c)(77),{value:n,onChange:r,disabled:i,cp:a}=e,o;t[0]!==r||t[1]!==n?(o=(e,t)=>{r({...n,[e]:t})},t[0]=r,t[1]=n,t[2]=o):o=t[2];let s=o,c;t[3]===a.modelAdvancedTitle?c=t[4]:(c=(0,H.jsx)(`h4`,{className:`text-sm font-semibold text-fg`,children:a.modelAdvancedTitle}),t[3]=a.modelAdvancedTitle,t[4]=c);let l;t[5]===a.modelAdvancedHint?l=t[6]:(l=(0,H.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-fg-muted`,children:a.modelAdvancedHint}),t[5]=a.modelAdvancedHint,t[6]=l);let u;t[7]===s?u=t[8]:(u=e=>s(`imageModel`,e),t[7]=s,t[8]=u);let d;t[9]!==a||t[10]!==i||t[11]!==u||t[12]!==n.imageModel?(d=(0,H.jsx)(Xe,{title:a.imageUnderstandingTitle,value:n.imageModel,onChange:u,disabled:i,cp:a}),t[9]=a,t[10]=i,t[11]=u,t[12]=n.imageModel,t[13]=d):d=t[13];let f;t[14]===s?f=t[15]:(f=e=>s(`imageGenerationModel`,e),t[14]=s,t[15]=f);let p;t[16]!==a||t[17]!==i||t[18]!==f||t[19]!==n.imageGenerationModel?(p=(0,H.jsx)(Xe,{title:a.imageGenerationTitle,value:n.imageGenerationModel,onChange:f,disabled:i,cp:a}),t[16]=a,t[17]=i,t[18]=f,t[19]=n.imageGenerationModel,t[20]=p):p=t[20];let m;t[21]!==d||t[22]!==p?(m=(0,H.jsxs)(`div`,{className:`mt-4 grid gap-4 lg:grid-cols-2`,children:[d,p]}),t[21]=d,t[22]=p,t[23]=m):m=t[23];let h;t[24]===a.modelAllowFallbacksLabel?h=t[25]:(h=(0,H.jsx)(`span`,{className:`font-medium text-fg`,children:a.modelAllowFallbacksLabel}),t[24]=a.modelAllowFallbacksLabel,t[25]=h);let g;t[26]!==r||t[27]!==n?(g=e=>r({...n,allowFallbacks:e.target.value}),t[26]=r,t[27]=n,t[28]=g):g=t[28];let _;t[29]===a.policyInherit?_=t[30]:(_=(0,H.jsx)(I,{value:``,children:a.policyInherit}),t[29]=a.policyInherit,t[30]=_);let v;t[31]===a.policyEnabled?v=t[32]:(v=(0,H.jsx)(I,{value:`true`,children:a.policyEnabled}),t[31]=a.policyEnabled,t[32]=v);let y;t[33]===a.policyDisabled?y=t[34]:(y=(0,H.jsx)(I,{value:`false`,children:a.policyDisabled}),t[33]=a.policyDisabled,t[34]=y);let b;t[35]!==i||t[36]!==_||t[37]!==v||t[38]!==y||t[39]!==g||t[40]!==n.allowFallbacks?(b=(0,H.jsxs)(ee,{value:n.allowFallbacks,disabled:i,onChange:g,children:[_,v,y]}),t[35]=i,t[36]=_,t[37]=v,t[38]=y,t[39]=g,t[40]=n.allowFallbacks,t[41]=b):b=t[41];let x;t[42]!==b||t[43]!==h?(x=(0,H.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[h,b]}),t[42]=b,t[43]=h,t[44]=x):x=t[44];let S;t[45]===a.modelMaxCostTierLabel?S=t[46]:(S=(0,H.jsx)(`span`,{className:`font-medium text-fg`,children:a.modelMaxCostTierLabel}),t[45]=a.modelMaxCostTierLabel,t[46]=S);let C;t[47]!==r||t[48]!==n?(C=e=>r({...n,maxCostTier:e.target.value}),t[47]=r,t[48]=n,t[49]=C):C=t[49];let w;t[50]===a.policyInherit?w=t[51]:(w=(0,H.jsx)(I,{value:``,children:a.policyInherit}),t[50]=a.policyInherit,t[51]=w);let T;t[52]===a.costTierLow?T=t[53]:(T=(0,H.jsx)(I,{value:`low`,children:a.costTierLow}),t[52]=a.costTierLow,t[53]=T);let E;t[54]===a.costTierMedium?E=t[55]:(E=(0,H.jsx)(I,{value:`medium`,children:a.costTierMedium}),t[54]=a.costTierMedium,t[55]=E);let D;t[56]===a.costTierHigh?D=t[57]:(D=(0,H.jsx)(I,{value:`high`,children:a.costTierHigh}),t[56]=a.costTierHigh,t[57]=D);let O;t[58]!==i||t[59]!==C||t[60]!==w||t[61]!==T||t[62]!==E||t[63]!==D||t[64]!==n.maxCostTier?(O=(0,H.jsxs)(ee,{value:n.maxCostTier,disabled:i,onChange:C,children:[w,T,E,D]}),t[58]=i,t[59]=C,t[60]=w,t[61]=T,t[62]=E,t[63]=D,t[64]=n.maxCostTier,t[65]=O):O=t[65];let k;t[66]!==S||t[67]!==O?(k=(0,H.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[S,O]}),t[66]=S,t[67]=O,t[68]=k):k=t[68];let A;t[69]!==x||t[70]!==k?(A=(0,H.jsxs)(`div`,{className:`mt-4 grid gap-3 rounded-lg bg-surface-panel/70 p-3 shadow-surface sm:grid-cols-2`,children:[x,k]}),t[69]=x,t[70]=k,t[71]=A):A=t[71];let j;return t[72]!==c||t[73]!==l||t[74]!==A||t[75]!==m?(j=(0,H.jsxs)(`div`,{className:`mt-6 border-t border-edge-subtle pt-5 dark:border-edge`,children:[c,l,m,A]}),t[72]=c,t[73]=l,t[74]=A,t[75]=m,t[76]=j):j=t[76],j}function Xe(e){let t=(0,V.c)(64),{title:n,value:r,onChange:i,disabled:a,cp:s}=e,c;t[0]===n?c=t[1]:(c=(0,H.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n}),t[0]=n,t[1]=c);let l=s.modelToolPrimaryLabel,u;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(u=o(`rounded-lg border border-edge bg-surface-base px-3 py-2 text-sm text-fg placeholder:text-fg-subtle focus:border-edge-strong focus:outline-none`,`font-mono text-xs`),t[2]=u):u=t[2];let d;t[3]!==i||t[4]!==r?(d=e=>i({...r,primary:e.target.value}),t[3]=i,t[4]=r,t[5]=d):d=t[5];let f;t[6]!==a||t[7]!==d||t[8]!==r.primary?(f=(0,H.jsx)(`input`,{className:u,value:r.primary,disabled:a,placeholder:`provider/model`,onChange:d}),t[6]=a,t[7]=d,t[8]=r.primary,t[9]=f):f=t[9];let p;t[10]!==s.modelToolPrimaryLabel||t[11]!==f?(p=(0,H.jsxs)(`label`,{className:`flex flex-col gap-1 text-xs text-fg-muted`,children:[l,f]}),t[10]=s.modelToolPrimaryLabel,t[11]=f,t[12]=p):p=t[12];let m=s.modelToolFallbacksLabel,h;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(h=o(`rounded-lg border border-edge bg-surface-base px-3 py-2 text-sm text-fg placeholder:text-fg-subtle focus:border-edge-strong focus:outline-none`,`min-h-20 resize-y font-mono text-xs`),t[13]=h):h=t[13];let g;t[14]!==i||t[15]!==r?(g=e=>i({...r,fallbacks:e.target.value}),t[14]=i,t[15]=r,t[16]=g):g=t[16];let _;t[17]!==s.modelToolFallbacksPlaceholder||t[18]!==a||t[19]!==g||t[20]!==r.fallbacks?(_=(0,H.jsx)(`textarea`,{className:h,value:r.fallbacks,disabled:a,placeholder:s.modelToolFallbacksPlaceholder,onChange:g}),t[17]=s.modelToolFallbacksPlaceholder,t[18]=a,t[19]=g,t[20]=r.fallbacks,t[21]=_):_=t[21];let v;t[22]!==s.modelToolFallbacksLabel||t[23]!==_?(v=(0,H.jsxs)(`label`,{className:`flex flex-col gap-1 text-xs text-fg-muted`,children:[m,_]}),t[22]=s.modelToolFallbacksLabel,t[23]=_,t[24]=v):v=t[24];let y;t[25]!==i||t[26]!==r?(y=e=>i({...r,timeoutMs:e.target.value}),t[25]=i,t[26]=r,t[27]=y):y=t[27];let b;t[28]!==a||t[29]!==y||t[30]!==r.timeoutMs?(b=(0,H.jsx)(`input`,{type:`number`,min:1,step:1,className:`rounded-lg border border-edge bg-surface-base px-3 py-2 text-sm text-fg placeholder:text-fg-subtle focus:border-edge-strong focus:outline-none`,value:r.timeoutMs,disabled:a,onChange:y}),t[28]=a,t[29]=y,t[30]=r.timeoutMs,t[31]=b):b=t[31];let x;t[32]!==s.toolTimeoutLabel||t[33]!==b?(x=(0,H.jsxs)(`label`,{className:`flex flex-col gap-1 text-xs text-fg-muted`,children:[s.toolTimeoutLabel,b]}),t[32]=s.toolTimeoutLabel,t[33]=b,t[34]=x):x=t[34];let S;t[35]!==i||t[36]!==r?(S=e=>i({...r,autoProviderFallback:e.target.value}),t[35]=i,t[36]=r,t[37]=S):S=t[37];let C;t[38]===s.policyInherit?C=t[39]:(C=(0,H.jsx)(I,{value:``,children:s.policyInherit}),t[38]=s.policyInherit,t[39]=C);let w;t[40]===s.policyEnabled?w=t[41]:(w=(0,H.jsx)(I,{value:`true`,children:s.policyEnabled}),t[40]=s.policyEnabled,t[41]=w);let T;t[42]===s.policyDisabled?T=t[43]:(T=(0,H.jsx)(I,{value:`false`,children:s.policyDisabled}),t[42]=s.policyDisabled,t[43]=T);let E;t[44]!==a||t[45]!==S||t[46]!==C||t[47]!==w||t[48]!==T||t[49]!==r.autoProviderFallback?(E=(0,H.jsxs)(ee,{value:r.autoProviderFallback,disabled:a,onChange:S,children:[C,w,T]}),t[44]=a,t[45]=S,t[46]=C,t[47]=w,t[48]=T,t[49]=r.autoProviderFallback,t[50]=E):E=t[50];let D;t[51]!==s.modelAutoProviderFallbackLabel||t[52]!==E?(D=(0,H.jsxs)(`label`,{className:`flex flex-col gap-1 text-xs text-fg-muted`,children:[s.modelAutoProviderFallbackLabel,E]}),t[51]=s.modelAutoProviderFallbackLabel,t[52]=E,t[53]=D):D=t[53];let O;t[54]!==x||t[55]!==D?(O=(0,H.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[x,D]}),t[54]=x,t[55]=D,t[56]=O):O=t[56];let k;t[57]!==v||t[58]!==O||t[59]!==p?(k=(0,H.jsxs)(`div`,{className:`mt-3 grid gap-3`,children:[p,v,O]}),t[57]=v,t[58]=O,t[59]=p,t[60]=k):k=t[60];let A;return t[61]!==c||t[62]!==k?(A=(0,H.jsxs)(`div`,{className:`rounded-lg bg-surface-panel/70 p-3 shadow-surface`,children:[c,k]}),t[61]=c,t[62]=k,t[63]=A):A=t[63],A}export{qe as CapabilityPresetsSettingsPanel};
@@ -1 +1 @@
1
- import{r as e,s as t}from"./locale-store-0lpYdNDr.js";function n(e,t){let n=Date.now()-new Date(e).getTime();return n<6e4?t.justNow:n<36e5?t.minutesAgo.replace(`{{count}}`,String(Math.floor(n/6e4))):n<864e5?t.hoursAgo.replace(`{{count}}`,String(Math.floor(n/36e5))):n<6048e5?t.daysAgo.replace(`{{count}}`,String(Math.floor(n/864e5))):new Date(e).toLocaleDateString()}function r(e,t){let r=n(e.lastActive,t);return e.channel===`telegram`&&e.peerId?`${e.accountId??`default`} · ${e.peerKind??``} · ${e.peerId} · ${r}`:`${e.channel}: ${e.chatId} · ${r}`}async function i(){return(await t(e(`/api/channels/status`))).payload?.channels||[]}async function a(n){return(await t(e(`/api/sessions/chat-ids${n?`?channel=${encodeURIComponent(n)}`:``}`))).payload?.chatIds||[]}export{i as n,a as r,r as t};
1
+ import{r as e,s as t}from"./locale-store-Ys6RP7Be.js";function n(e,t){let n=Date.now()-new Date(e).getTime();return n<6e4?t.justNow:n<36e5?t.minutesAgo.replace(`{{count}}`,String(Math.floor(n/6e4))):n<864e5?t.hoursAgo.replace(`{{count}}`,String(Math.floor(n/36e5))):n<6048e5?t.daysAgo.replace(`{{count}}`,String(Math.floor(n/864e5))):new Date(e).toLocaleDateString()}function r(e,t){let r=n(e.lastActive,t);return e.channel===`telegram`&&e.peerId?`${e.accountId??`default`} · ${e.peerKind??``} · ${e.peerId} · ${r}`:`${e.channel}: ${e.chatId} · ${r}`}async function i(){return(await t(e(`/api/channels/status`))).payload?.channels||[]}async function a(n){return(await t(e(`/api/sessions/chat-ids${n?`?channel=${encodeURIComponent(n)}`:``}`))).payload?.chatIds||[]}export{i as n,a as r,r as t};
@@ -0,0 +1 @@
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{l as i,u as a}from"./chunk-KS7C4IRE-uQ0fehio.js";import{t as o}from"./circle-alert-BEjgurr2.js";import{t as s}from"./cn-JdwAhgNB.js";import{t as c}from"./messages-BzI9Wx30.js";import{l,n as u,o as d,r as f,s as p}from"./locale-store-Ys6RP7Be.js";import{i as m}from"./vendor-swr-BIWyz7Rc.js";import{$a as h,$r as g,$s as _,Bo as v,Et as y,Ho as b,Ja as x,Mr as S,Os as C,Qa as w,Qc as T,Qr as E,Ro as D,Uo as O,Us as k,Vl as A,Vo as j,Wo as M,Zr as N,bo as P,cs as F,dc as I,ea as ee,es as te,is as ne,js as L,ls as R,uu as z,wc as re,xs as ie,yc as ae,zo as oe}from"./index-HZdBKfk_.js";import{n as se,r as ce}from"./settings-page-layout-C1yYqbT6.js";import{n as le}from"./settings-loading-skeleton-DOnUabm7.js";import{t as ue}from"./schema-form-D0e90ndE.js";import{t as de}from"./browser-BLJWD7WI.js";import{n as fe,t as pe}from"./channels-status-swr-_VirfMKW.js";import{t as me}from"./use-channel-catalog-CMHY4ZfW.js";var B=e(t(),1),V=n();function he(e){let t=e.actions??{};for(let e of[`login.start`,`setup.start`]){let n=t[e];if(n?.result===`qr`)return[e,n]}let n=Object.entries(t).find(([,e])=>e.result===`qr`);if(n)return n;let r=e.ui?.card?.primaryAction;if(r&&t[r])return[r,t[r]];for(let e of[`login.start`,`setup.start`]){let n=t[e];if(n)return[e,n]}return Object.entries(t).find(([,e])=>e.result===`form`)??null}var ge=e(de(),1),H=r();async function _e(e){let t=await d(f(`/api/channels/${encodeURIComponent(e.channelId)}/actions/${encodeURIComponent(e.actionId)}?locale=${encodeURIComponent(e.locale)}`),{method:`POST`,body:JSON.stringify({...e.accountId?{accountId:e.accountId}:{},...e.input===void 0?{}:{input:e.input}})}),n=await t.json().catch(()=>({}));if(!t.ok||n.ok===!1)throw Error(n.error?.message??t.statusText);return n.payload??{type:`ok`}}function U(e){return e?.type===`poll`&&e.phase===`done`}function W(e){return e&&`message`in e&&typeof e.message==`string`?e.message:null}function G(e,t){return e?.type!==`qr`&&e?.type!==`poll`?null:e.qrPayload?e.qrPayload:t===`weixin`&&e.qrcodeUrl?e.qrcodeUrl:null}function K(e){return e?.type!==`qr`&&e?.type!==`poll`?null:e.qrcodeUrl??null}function ve({entry:e,locale:t,messages:n,onChanged:r,compact:i=!1}){let a=(0,B.useMemo)(()=>he(e),[e]),o=(0,B.useMemo)(()=>({defaultBooleanLabel:n.schemaBooleanDefault,unsupportedArrayType:n.schemaUnsupportedArrayType,arrayAddPlaceholder:n.schemaArrayAddPlaceholder,unsupportedFieldType:(e,t)=>n.schemaUnsupportedFieldType.replace(`{{title}}`,e).replace(`{{type}}`,t?` (${t})`:``)}),[n]),[c,l]=(0,B.useState)({payload:null,poll:null,busy:!1,error:null,formDraft:{},generatedQr:null});(0,B.useEffect)(()=>{l({payload:null,poll:null,busy:!1,error:null,formDraft:{},generatedQr:null})},[e.id]);let u=(0,B.useCallback)(async(n,i)=>{l(e=>({...e,busy:!0,error:null}));try{let a=await _e({channelId:e.id,actionId:n,locale:t,input:i});l(e=>({...e,payload:a,poll:a.type===`qr`&&a.statusAction&&a.sessionKey?{actionId:a.statusAction,sessionKey:a.sessionKey,intervalMs:Math.max(1e3,a.pollIntervalMs??2500)}:null,busy:!1,formDraft:a.type===`form`?a.values??{}:e.formDraft})),`configChanged`in a&&a.configChanged===!0&&await r()}catch(e){l(t=>({...t,busy:!1,error:e instanceof Error?e.message:String(e)}))}},[e.id,t,r]);(0,B.useEffect)(()=>{let t=G(c.payload,e.id);if(!t){l(e=>e.generatedQr?{...e,generatedQr:null}:e);return}let n=!1;return l(e=>e.generatedQr?{...e,generatedQr:null}:e),ge.toDataURL(t,{width:220,margin:1}).then(e=>{n||l(t=>({...t,generatedQr:e}))}),()=>{n=!0}},[e.id,c.payload]),(0,B.useEffect)(()=>{let n=c.poll;if(!n)return;let i=!1,a=window.setInterval(()=>{i||_e({channelId:e.id,actionId:n.actionId,locale:t,input:{sessionKey:n.sessionKey}}).then(async e=>{i||(l(t=>({...t,payload:e,poll:U(e)?null:t.poll,error:null})),`configChanged`in e&&e.configChanged===!0&&await r(),U(e)&&window.clearInterval(a))}).catch(e=>{i||l(t=>({...t,error:e instanceof Error?e.message:String(e)}))})},n.intervalMs);return()=>{i=!0,window.clearInterval(a)}},[e.id,t,r,c.poll]);let d=a?.[1].label??(e.configured?n.reconnect:n.connect),f=e.actions?.[`doctor.run`]?.label??n.diagnose,p=W(c.payload),m=G(c.payload,e.id),h=m?c.generatedQr:K(c.payload),g=a?.[1].result===`qr`&&(c.busy||c.payload?.type===`qr`||c.payload?.type===`poll`),v=c.payload?.type===`form`?c.payload:null,y=c.payload?.type===`diagnostics`?c.payload.checks:null;return(0,H.jsxs)(`div`,{className:i?`space-y-3`:`rounded-lg bg-surface-panel/80 p-4 shadow-surface`,children:[(0,H.jsxs)(`div`,{className:s(`flex flex-wrap items-start gap-3`,i?`justify-end`:`justify-between`),children:[i?null:(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:n.setupTitle}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e.configured?n.setupConfiguredHint:n.setupEmptyHint})]}),(0,H.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[a?(0,H.jsxs)(C,{type:`button`,variant:`primary`,disabled:c.busy,onClick:()=>void u(a[0]),children:[c.busy?(0,H.jsx)(T,{className:`size-4 animate-spin`}):(0,H.jsx)(re,{className:`size-4`}),d]}):null,e.actions?.[`doctor.run`]?(0,H.jsxs)(C,{type:`button`,variant:`secondary`,disabled:c.busy,onClick:()=>void u(`doctor.run`),children:[(0,H.jsx)(_,{className:`size-4`}),f]}):null]})]}),p?(0,H.jsx)(`p`,{className:`mt-3 text-sm text-fg-muted`,children:p}):null,c.error?(0,H.jsx)(`p`,{className:`mt-3 text-sm text-red-600 dark:text-red-400`,children:c.error}):null,g?(0,H.jsxs)(`div`,{className:s(`flex h-80 items-center justify-center gap-4 overflow-hidden rounded-lg bg-surface-base p-3 shadow-surface`,i?`mt-1 flex-col text-center sm:h-64 sm:flex-row sm:text-left`:`mt-4 flex-col sm:h-64 sm:flex-row`),children:[(0,H.jsx)(`div`,{className:`flex size-56 shrink-0 items-center justify-center rounded-lg border border-edge bg-white p-3`,children:h?(0,H.jsx)(`img`,{src:h,alt:`${e.label} setup QR`,className:`size-52 object-contain`}):(0,H.jsx)(`div`,{className:`flex size-52 items-center justify-center rounded-md bg-surface-base`,children:(0,H.jsx)(w,{className:`size-48 rounded-md`})})}),(0,H.jsxs)(`div`,{className:s(`min-w-0 max-w-sm text-sm text-fg-muted`,i&&`w-full sm:w-auto`),children:[h?(0,H.jsx)(`p`,{className:`line-clamp-3`,children:n.waitingConfirmation}):(0,H.jsxs)(`div`,{className:`space-y-2`,"aria-busy":`true`,children:[(0,H.jsx)(w,{className:`h-4 w-48 max-w-full`}),(0,H.jsx)(w,{className:`h-4 w-36 max-w-full`})]}),m?(0,H.jsxs)(`a`,{className:`mt-2 inline-flex items-center gap-1 text-accent hover:underline`,href:m,target:`_blank`,rel:`noreferrer`,children:[n.openSetupLink,(0,H.jsx)(A,{className:`size-3.5`})]}):null]})]}):null,c.payload?.type===`poll`&&c.payload.phase===`done`?(0,H.jsxs)(`div`,{className:`mt-4 flex items-center gap-2 rounded-lg bg-surface-base px-3 py-2 text-sm shadow-surface`,children:[(0,H.jsx)(z,{className:c.payload.ok?`size-4 text-green-600`:`size-4 text-red-600`}),(0,H.jsx)(`span`,{className:c.payload.ok?`text-fg`:`text-red-600 dark:text-red-400`,children:c.payload.message??(c.payload.ok?n.complete:n.failed)})]}):null,v?(0,H.jsxs)(`div`,{className:`mt-4 space-y-3`,children:[(0,H.jsx)(ue,{schema:v.schema,values:c.formDraft,onChange:e=>l(t=>({...t,formDraft:e})),disabled:c.busy,labels:o}),(0,H.jsx)(C,{type:`button`,variant:`primary`,disabled:c.busy,onClick:()=>void u(v.submitAction,c.formDraft),children:n.saveSetup})]}):null,y?(0,H.jsx)(`div`,{className:`mt-4 space-y-2`,children:y.map((e,t)=>(0,H.jsxs)(`div`,{className:`rounded-lg bg-surface-base px-3 py-2 shadow-surface`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,H.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:e.label??e.id??n.diagnosticCheckFallback.replace(`{{index}}`,String(t+1))}),(0,H.jsx)(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-xs text-fg-muted`,children:e.status??`unknown`})]}),e.message?(0,H.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e.message}):null]},e.id??t))}):null]})}var ye=40;function q(e){return`ui:route:channel:${e.trim().toLowerCase()}`}function be(e,t){return e.find(e=>e.id===q(t))?.agentId?.trim().toLowerCase()??``}function xe(e,t,n){let r=q(t),i=e.filter(e=>e.id!==r),a=n.trim().toLowerCase();return a?[...i,{id:r,agentId:a,priority:ye,enabled:!0,match:{channel:t.trim().toLowerCase(),accountId:`*`}}]:i}function Se(e){let t=e.configured===!0,n=e.enabled===!0;return e.setupStatus??{enabled:n,ready:t,state:n&&!t?`needs_setup`:n?`ready`:`disabled`,issues:[]}}function Ce(e,t,n){let r=Se(e);return r.ready?r.enabled?n?t?.connected===!0?`running`:`stopped`:`checking`:`disabled`:`needs_setup`}function we(e,t=!1){return e===`drawer`?s(`xopc-drawer-right fixed right-0 top-0 flex size-full flex-col overflow-hidden border-l border-edge bg-surface-panel shadow-popover outline-none dark:border-edge`,t?`max-w-[36rem]`:`max-w-xl`,F):s(`fixed left-1/2 top-1/2 flex h-[min(calc(100dvh-2rem),52rem)] w-[min(calc(100%-2rem),32rem)] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden`,t&&`h-[min(calc(100dvh-2rem),48rem)] w-[min(calc(100%-2rem),36rem)]`,F,`rounded-2xl border border-edge bg-surface-panel shadow-popover outline-none dark:border-edge`)}function Te(e){let t=(0,V.c)(33),{presentation:n,open:r,onOpenChange:i,title:a,description:o,srTitle:c,srDescription:l,closeAriaLabel:u,children:d,footer:f,wide:p,headerExtra:m}=e,h=p===void 0?!1:p,g=n===`drawer`,[_,y]=(0,B.useState)(null),x;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,H.jsx)(b,{className:s(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,R)}),t[0]=x):x=t[0];let S;t[1]!==n||t[2]!==h?(S=we(n,h),t[1]=n,t[2]=h,t[3]=S):S=t[3];let w;t[4]===c?w=t[5]:(w=c?(0,H.jsx)(M,{className:`sr-only`,children:c}):null,t[4]=c,t[5]=w);let T;t[6]===l?T=t[7]:(T=l?(0,H.jsx)(j,{className:`sr-only`,children:l}):null,t[6]=l,t[7]=T);let E;t[8]!==u||t[9]!==o||t[10]!==m||t[11]!==g||t[12]!==a?(E=g?(0,H.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-3 border-b border-edge px-4 py-3`,children:[(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[a?(0,H.jsx)(`div`,{className:`text-base font-semibold text-fg`,children:a}):null,o?(0,H.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:o}):null]}),(0,H.jsx)(oe,{asChild:!0,children:(0,H.jsx)(C,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 p-0`,"aria-label":u,children:(0,H.jsx)(L,{className:`size-5`,strokeWidth:1.75})})})]}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(oe,{asChild:!0,children:(0,H.jsx)(`button`,{type:`button`,className:s(ie,`absolute right-3 top-3 z-20 p-1.5 hover:bg-surface-hover`),"aria-label":u,children:(0,H.jsx)(L,{className:`size-4`})})}),m]}),t[8]=u,t[9]=o,t[10]=m,t[11]=g,t[12]=a,t[13]=E):E=t[13];let k=g?`p-4`:`p-6`,A;t[14]===k?A=t[15]:(A=s(`min-h-0 flex-1 overflow-y-auto`,k),t[14]=k,t[15]=A);let N;t[16]!==d||t[17]!==A?(N=(0,H.jsx)(`div`,{className:A,children:d}),t[16]=d,t[17]=A,t[18]=N):N=t[18];let P;t[19]!==f||t[20]!==_||t[21]!==w||t[22]!==T||t[23]!==E||t[24]!==N?(P=(0,H.jsxs)(ne,{layer:`modal`,portalContainer:_,children:[w,T,E,N,f]}),t[19]=f,t[20]=_,t[21]=w,t[22]=T,t[23]=E,t[24]=N,t[25]=P):P=t[25];let F;t[26]!==P||t[27]!==S?(F=(0,H.jsxs)(O,{children:[x,(0,H.jsx)(v,{ref:y,className:S,onOpenAutoFocus:Ee,children:P})]}),t[26]=P,t[27]=S,t[28]=F):F=t[28];let I;return t[29]!==i||t[30]!==r||t[31]!==F?(I=(0,H.jsx)(D,{open:r,onOpenChange:i,children:F}),t[29]=i,t[30]=r,t[31]=F,t[32]=I):I=t[32],I}function Ee(e){return e.preventDefault()}var De=(0,B.memo)(function(e){let t=(0,V.c)(10),{ch:n,refreshing:r,saveOk:i,onRefresh:a}=e,o;t[0]!==n.saved||t[1]!==i?(o=i?(0,H.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,t[0]=n.saved,t[1]=i,t[2]=o):o=t[2];let s;t[3]!==n.refresh||t[4]!==a||t[5]!==r?(s=(0,H.jsx)(ee,{className:`size-9 shrink-0 p-0`,loading:r,label:n.refresh,onClick:a}),t[3]=n.refresh,t[4]=a,t[5]=r,t[6]=s):s=t[6];let c;return t[7]!==o||t[8]!==s?(c=(0,H.jsxs)(`div`,{className:`flex min-w-0 shrink-0 items-center justify-end gap-2`,children:[o,s]}),t[7]=o,t[8]=s,t[9]=c):c=t[9],c});function Oe(e){let t=(0,V.c)(24),{ch:n,dirty:r,saving:i,onCancel:a,onDiscard:o,onSave:s,showCancel:c}=e,l=c===void 0?!0:c,u;t[0]!==n.unsavedHint||t[1]!==r?(u=r?(0,H.jsx)(`p`,{className:`mb-3 text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,t[0]=n.unsavedHint,t[1]=r,t[2]=u):u=t[2];let d;t[3]!==n.modalCancel||t[4]!==a||t[5]!==l?(d=l?(0,H.jsx)(C,{type:`button`,variant:`secondary`,onClick:a,children:n.modalCancel}):null,t[3]=n.modalCancel,t[4]=a,t[5]=l,t[6]=d):d=t[6];let f=!r||i,p;t[7]!==n.discard||t[8]!==o||t[9]!==f?(p=(0,H.jsx)(C,{type:`button`,variant:`secondary`,disabled:f,onClick:o,children:n.discard}),t[7]=n.discard,t[8]=o,t[9]=f,t[10]=p):p=t[10];let m=!r||i,h;t[11]===s?h=t[12]:(h=()=>void s(),t[11]=s,t[12]=h);let g=i?n.saving:n.save,_;t[13]!==m||t[14]!==h||t[15]!==g?(_=(0,H.jsx)(C,{type:`button`,variant:`primary`,disabled:m,onClick:h,children:g}),t[13]=m,t[14]=h,t[15]=g,t[16]=_):_=t[16];let v;t[17]!==d||t[18]!==p||t[19]!==_?(v=(0,H.jsxs)(`div`,{className:`flex flex-wrap justify-end gap-2`,children:[d,p,_]}),t[17]=d,t[18]=p,t[19]=_,t[20]=v):v=t[20];let y;return t[21]!==v||t[22]!==u?(y=(0,H.jsxs)(`div`,{className:`sticky bottom-0 shrink-0 border-t border-edge-subtle bg-surface-panel px-6 py-4 dark:border-edge-subtle`,children:[u,v]}),t[21]=v,t[22]=u,t[23]=y):y=t[23],y}var J=`channels-status`;function ke(e){if(!e||typeof e!=`object`)return null;let t=e.channels;return Array.isArray(t)?t:null}function Ae(e){let t=t=>e(t.detail);return window.addEventListener(J,t),()=>window.removeEventListener(J,t)}function je(e,t){let n=(0,V.c)(4),r=t===void 0?!0:t,i,a;n[0]!==r||n[1]!==e?(i=()=>{if(r)return Ae(e)},a=[r,e],n[0]=r,n[1]=e,n[2]=i,n[3]=a):(i=n[2],a=n[3]),(0,B.useEffect)(i,a)}function Me(e){return e?f(`/api/channels/${encodeURIComponent(e)}/config`):null}async function Ne(e){return(await p(f(`/api/channels/${encodeURIComponent(e)}/config`))).payload?.config??{}}var Pe=[`enabled`];async function Fe(){let e=await p(f(`/api/config`));return{channels:e.payload?.config?.channels??{},bindings:e.payload?.config?.bindings??[]}}function Ie(e){return e.split(`/`).filter(Boolean).map(e=>encodeURIComponent(e)).join(`/`)}function Le(e){return e.configPath.startsWith(`channels.`)&&e.configPath.slice(9).split(`.`)[0]||e.id}function Y(e){let t=e.configured===!0,n=e.enabled===!0;return e.setupStatus??{enabled:n,ready:t,state:n&&!t?`needs_setup`:n?`ready`:`disabled`,issues:[]}}function Re(e,t){return e===`running`?t.connectionRunning:e===`stopped`?t.connectionStopped:e===`checking`?t.connectionChecking:e===`disabled`?t.connectionDisabled:t.connectionNeedsSetup}function ze(e,t){return e===`running`?t.connectionRunningHint:e===`stopped`?t.connectionStoppedHint:e===`disabled`?t.connectionDisabledHint:e===`needs_setup`?t.connectionNeedsSetupHint:t.connectionChecking}function Be(e){return e===`running`?`bg-emerald-500/12 text-emerald-700 dark:text-emerald-300`:e===`stopped`?`bg-red-500/10 text-red-700 dark:text-red-300`:e===`checking`?`bg-amber-500/10 text-amber-700 dark:text-amber-300`:e===`disabled`?`bg-surface-hover text-fg-muted`:`bg-amber-500/10 text-amber-700 dark:text-amber-300`}function Ve(e){if(!e)return[];let t=e.uiHints??{},n=X(e.configSchema)&&Array.isArray(e.configSchema.required)?e.configSchema.required.map(String):[],r=Y(e).issues.map(e=>e.fieldPath).filter(e=>!!e),i=Object.entries(t).filter(([,e])=>!X(e)||e.advanced===!0?!1:(Array.isArray(e.tags)?e.tags.map(String):[]).includes(`basic`)||e.advanced===!1).map(([e])=>e).filter(e=>!Pe.includes(e));return Array.from(new Set([...i,...n,...r])).filter(e=>!Pe.includes(e))}function X(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Z(e){return JSON.parse(JSON.stringify(e??{type:`object`,properties:{}}))}function He(e,t){let n={...Z(e),properties:{}};for(let r of t){let t=r.split(`.`),i=e,a=n;for(let[e,n]of t.entries()){let r=i.properties;if(!X(r)||!X(r[n]))break;let o=X(a.properties)?a.properties:{};if(a.properties=o,o[n]||(o[n]={...Z(r[n]),properties:{}}),e===t.length-1){o[n]=Z(r[n]);break}i=r[n],a=o[n]}}return n}function Ue(e){let t=e.properties;if(!X(t))return!1;for(let[e,n]of Object.entries(t))X(n)&&n.type===`object`&&Ue(n)&&delete t[e];return Object.keys(t).length===0}function We(e,t){let n=Z(e);for(let e of t){let t=e.split(`.`),r=n;for(let[e,n]of t.entries()){let i=r.properties;if(!X(i))break;if(e===t.length-1){delete i[n];break}if(!X(i[n]))break;r=i[n]}}return Ue(n),n}function Ge(e){return e.type===`object`&&X(e.properties)&&Object.keys(e.properties).length>0}function Ke(e,t){let n=e;for(let e of t.split(`.`)){if(!X(n))return;n=n[e]}return n}function qe(e){let t=e.accounts;return X(t)?Object.values(t).filter(e=>X(e)&&e.enabled!==!1).length:+(e.configured===!0)}function Je(e,t,n){return t==null||t===``?null:e.toLowerCase().includes(`dmpolicy`)&&typeof t==`string`?`${n.dmPolicy}: ${n.policy.dm[t]??t}`:(e.toLowerCase().includes(`stream`)||e.toLowerCase().includes(`streaming`))&&typeof t==`string`?`${n.cardStream}: ${n.policy.stream[t]??t}`:typeof t==`boolean`?t?n.enabledLabel:n.disabledLabel:String(t)}function Ye(e,t,n){let r=[],i=Y(e);if(i.issues.length>0&&r.push(Qe(i.issues[0],n)),t){let i=e.ui?.card?.summaryFields??[`dmPolicy`,`streamMode`,`streaming.mode`];for(let e of i){let i=Je(e,Ke(t,e),n);i&&r.push(i)}let a=qe(t);a>0&&r.push(n.cardAccounts.replace(`{{count}}`,String(a)))}return r.length>0?r.slice(0,2):i.ready?[n.hubStatusConfigured]:[]}function Q(e,t){let n=Y(e),r=he(e);return n.state===`needs_setup`?r?.[1].label??t.completeSetup:!n.enabled&&n.ready?t.enableChannel:n.state===`error`?t.diagnose:n.ready?t.manageChannel:r?.[1].label??t.startConfiguration}function Xe(e,t){let n=he(e);return n?.[1].result===`qr`?t.cardSetupQrHint:n?.[1].result===`form`?t.cardSetupConfigHint:t.cardSetupGenericHint}function Ze(e,t){let n=e.capabilities??{},r=[];return n.login===!0&&r.push(t.cardCapabilityLogin),n.pairing===!0&&r.push(t.cardCapabilityPairing),n.multiAccount===!0&&r.push(t.cardCapabilityMultiAccount),n.streaming===!0&&r.push(t.cardCapabilityStreaming),n.media===!0&&r.push(t.cardCapabilityMedia),n.doctor===!0&&r.push(t.cardCapabilityDoctor),r.slice(0,3)}function Qe(e,t){return e.code===`telegram.missing_credential`?t.setupIssueTelegramMissingCredential:e.code===`weixin.missing_account`?t.setupIssueWeixinMissingAccount:e.code===`feishu.missing_credentials`?t.setupIssueFeishuMissingCredentials:e.code===`config.missing_required`&&e.fieldPath?t.setupIssueMissingRequired.replace(`{{field}}`,e.fieldPath):e.message}function $e({entry:e}){let t=l(e=>e.token),[n,r]=(0,B.useState)(!1),i=(0,B.useMemo)(()=>{if(!e.ui?.icon||n)return null;let r=new URL(f(`/api/extensions/${encodeURIComponent(e.extensionId)}/assets/${Ie(e.ui.icon)}`));return t?.trim()&&r.searchParams.set(`token`,t.trim()),r.toString()},[n,e.extensionId,e.ui?.icon,t]);return(0,H.jsx)(`span`,{className:`flex size-12 shrink-0 items-center justify-center rounded-2xl bg-surface-base text-fg`,children:i?(0,H.jsx)(`img`,{src:i,alt:``,draggable:!1,className:`size-7`,"aria-hidden":!0,onError:()=>r(!0)}):(0,H.jsx)(h,{sourceChannel:e.id,className:`size-7`})})}function et(e){let t=(0,V.c)(16),{checked:n,disabled:r,onToggle:i,label:a}=e,o;t[0]===i?o=t[1]:(o=e=>{e.stopPropagation(),i()},t[0]=i,t[1]=o);let c=n?`border-accent bg-accent`:`border-edge bg-surface-hover`,l=r&&`cursor-not-allowed opacity-60`,u;t[2]!==c||t[3]!==l?(u=s(`relative inline-flex h-6 w-11 shrink-0 items-center rounded-full border transition-colors`,c,l),t[2]=c,t[3]=l,t[4]=u):u=t[4];let d=n?`translate-x-5`:`translate-x-0.5`,f;t[5]===d?f=t[6]:(f=s(`size-5 rounded-full bg-white shadow-surface transition-transform`,d),t[5]=d,t[6]=f);let p;t[7]===f?p=t[8]:(p=(0,H.jsx)(`span`,{className:f}),t[7]=f,t[8]=p);let m;return t[9]!==n||t[10]!==r||t[11]!==a||t[12]!==o||t[13]!==u||t[14]!==p?(m=(0,H.jsx)(`button`,{type:`button`,role:`switch`,"aria-checked":n,"aria-label":a,disabled:r,onClick:o,className:u,children:p}),t[9]=n,t[10]=r,t[11]=a,t[12]=o,t[13]=u,t[14]=p,t[15]=m):m=t[15],m}function tt(e){let t=(0,V.c)(71),{entry:n,config:r,runtime:i,busy:a,restarting:o,ch:c,onOpen:l,onToggle:u,onRestart:d}=e,f;t[0]===n?f=t[1]:(f=Y(n),t[0]=n,t[1]=f);let p=f,m,h,g,_,v,y,b;if(t[2]!==a||t[3]!==c||t[4]!==r||t[5]!==n||t[6]!==l||t[7]!==d||t[8]!==u||t[9]!==i||t[10]!==p.enabled||t[11]!==p.ready){let e=Ye(n,r,c),o=Ze(n,c);m=!p.enabled&&p.ready?u:i===`stopped`?d:l,y=`flex min-h-[15.5rem] flex-col rounded-xl bg-surface-panel p-4 shadow-surface transition-colors hover:bg-surface-hover/45`;let f;t[19]===n?f=t[20]:(f=(0,H.jsx)($e,{entry:n}),t[19]=n,t[20]=f);let x;t[21]===n.label?x=t[22]:(x=(0,H.jsx)(`h2`,{className:`truncate text-base font-semibold text-fg`,children:n.label}),t[21]=n.label,t[22]=x);let S;t[23]===i?S=t[24]:(S=s(`mt-1 inline-flex rounded-full px-2 py-0.5 text-xs font-medium`,Be(i)),t[23]=i,t[24]=S);let C;t[25]!==c||t[26]!==i?(C=Re(i,c),t[25]=c,t[26]=i,t[27]=C):C=t[27];let w;t[28]!==S||t[29]!==C?(w=(0,H.jsx)(`span`,{className:S,children:C}),t[28]=S,t[29]=C,t[30]=w):w=t[30];let T;t[31]!==w||t[32]!==x?(T=(0,H.jsxs)(`div`,{className:`min-w-0`,children:[x,w]}),t[31]=w,t[32]=x,t[33]=T):T=t[33];let E;t[34]!==T||t[35]!==f?(E=(0,H.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[f,T]}),t[34]=T,t[35]=f,t[36]=E):E=t[36];let D=p.enabled,O;t[37]!==c.toggleChannel||t[38]!==n.label?(O=c.toggleChannel.replace(`{{channel}}`,n.label),t[37]=c.toggleChannel,t[38]=n.label,t[39]=O):O=t[39];let k;t[40]!==a||t[41]!==u||t[42]!==p.enabled||t[43]!==O?(k=(0,H.jsx)(et,{checked:D,disabled:a,label:O,onToggle:u}),t[40]=a,t[41]=u,t[42]=p.enabled,t[43]=O,t[44]=k):k=t[44],t[45]!==E||t[46]!==k?(b=(0,H.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[E,k]}),t[45]=E,t[46]=k,t[47]=b):b=t[47],h=`button`,g=l,_=`mt-5 min-h-[6.25rem] text-left`,v=p.ready?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`p`,{className:`line-clamp-2 text-sm leading-6 text-fg-muted`,children:n.description??n.id}),e.length>0?(0,H.jsx)(`div`,{className:`mt-3 space-y-0.5 text-sm leading-5 text-fg-muted`,children:e.map(rt)}):null]}):(0,H.jsxs)(`div`,{className:`rounded-lg bg-surface-base p-3`,children:[(0,H.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:c.cardSetupTitle}),(0,H.jsx)(`p`,{className:`mt-1 line-clamp-2 text-sm leading-5 text-fg-muted`,children:e[0]??Xe(n,c)}),o.length>0?(0,H.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-1.5`,children:o.map(nt)}):null]}),t[2]=a,t[3]=c,t[4]=r,t[5]=n,t[6]=l,t[7]=d,t[8]=u,t[9]=i,t[10]=p.enabled,t[11]=p.ready,t[12]=m,t[13]=h,t[14]=g,t[15]=_,t[16]=v,t[17]=y,t[18]=b}else m=t[12],h=t[13],g=t[14],_=t[15],v=t[16],y=t[17],b=t[18];let x;t[48]!==h||t[49]!==g||t[50]!==_||t[51]!==v?(x=(0,H.jsx)(`button`,{type:h,onClick:g,className:_,children:v}),t[48]=h,t[49]=g,t[50]=_,t[51]=v,t[52]=x):x=t[52];let S=a||o,w;t[53]!==a||t[54]!==o?(w=a||o?(0,H.jsx)(T,{className:`size-4 animate-spin`}):null,t[53]=a,t[54]=o,t[55]=w):w=t[55];let E;t[56]!==c||t[57]!==n||t[58]!==o||t[59]!==i?(E=o?c.restartingChannel:i===`stopped`?c.restartChannel:Q(n,c),t[56]=c,t[57]=n,t[58]=o,t[59]=i,t[60]=E):E=t[60];let D;t[61]!==m||t[62]!==w||t[63]!==E||t[64]!==S?(D=(0,H.jsx)(`div`,{className:`mt-auto pt-4`,children:(0,H.jsxs)(C,{type:`button`,variant:`secondary`,className:`w-full rounded-2xl py-2.5`,onClick:m,disabled:S,children:[w,E]})}),t[61]=m,t[62]=w,t[63]=E,t[64]=S,t[65]=D):D=t[65];let O;return t[66]!==D||t[67]!==y||t[68]!==b||t[69]!==x?(O=(0,H.jsxs)(`article`,{className:y,children:[b,x,D]}),t[66]=D,t[67]=y,t[68]=b,t[69]=x,t[70]=O):O=t[70],O}function nt(e){return(0,H.jsx)(`span`,{className:`rounded-full bg-surface-hover px-2 py-0.5 text-xs text-fg-muted`,children:e},e)}function rt(e){return(0,H.jsx)(`p`,{className:`truncate`,title:e,children:e},e)}function it(e){let t=(0,V.c)(51),{runtime:n,restarting:r,checking:i,showConnectionOptions:a,canManageConnection:c,ch:l,onRestart:u,onCheck:d,onManageConnection:f}=e,p=n===`running`?z:n===`stopped`||n===`needs_setup`?o:T,m=n===`running`&&`text-emerald-600 dark:text-emerald-400`,h=n===`stopped`&&`text-red-600 dark:text-red-400`,g=n===`checking`&&`animate-spin text-amber-600 dark:text-amber-400`,_=n===`disabled`&&`text-fg-muted`,v=n===`needs_setup`&&`text-amber-600 dark:text-amber-400`,y;t[0]!==m||t[1]!==h||t[2]!==g||t[3]!==_||t[4]!==v?(y=s(`mt-0.5 size-5 shrink-0`,m,h,g,_,v),t[0]=m,t[1]=h,t[2]=g,t[3]=_,t[4]=v,t[5]=y):y=t[5];let b;t[6]!==p||t[7]!==y?(b=(0,H.jsx)(p,{className:y}),t[6]=p,t[7]=y,t[8]=b):b=t[8];let x;t[9]===l.connectionStatus?x=t[10]:(x=(0,H.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:l.connectionStatus}),t[9]=l.connectionStatus,t[10]=x);let S;t[11]!==l||t[12]!==n?(S=ze(n,l),t[11]=l,t[12]=n,t[13]=S):S=t[13];let w;t[14]===S?w=t[15]:(w=(0,H.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:S}),t[14]=S,t[15]=w);let E;t[16]!==w||t[17]!==x?(E=(0,H.jsxs)(`div`,{children:[x,w]}),t[16]=w,t[17]=x,t[18]=E):E=t[18];let D;t[19]!==E||t[20]!==b?(D=(0,H.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[b,E]}),t[19]=E,t[20]=b,t[21]=D):D=t[21];let O=i||r,k;t[22]===i?k=t[23]:(k=i?(0,H.jsx)(T,{className:`size-4 animate-spin`}):null,t[22]=i,t[23]=k);let A=i?l.checkingConnection:l.checkConnection,j;t[24]!==d||t[25]!==O||t[26]!==k||t[27]!==A?(j=(0,H.jsxs)(C,{type:`button`,variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:O,onClick:d,children:[k,A]}),t[24]=d,t[25]=O,t[26]=k,t[27]=A,t[28]=j):j=t[28];let M;t[29]!==l.restartChannel||t[30]!==l.restartingChannel||t[31]!==i||t[32]!==u||t[33]!==r||t[34]!==n?(M=n===`stopped`?(0,H.jsxs)(C,{type:`button`,variant:`primary`,className:`px-2.5 py-1.5 text-xs`,disabled:r||i,onClick:u,children:[r?(0,H.jsx)(T,{className:`size-4 animate-spin`}):(0,H.jsx)(ae,{className:`size-4`}),r?l.restartingChannel:l.restartChannel]}):null,t[29]=l.restartChannel,t[30]=l.restartingChannel,t[31]=i,t[32]=u,t[33]=r,t[34]=n,t[35]=M):M=t[35];let N;t[36]!==c||t[37]!==l.connectionOptions||t[38]!==l.hideConnectionOptions||t[39]!==i||t[40]!==f||t[41]!==r||t[42]!==a?(N=c?(0,H.jsx)(C,{type:`button`,variant:`ghost`,className:`px-2.5 py-1.5 text-xs`,disabled:i||r,onClick:f,children:a?l.hideConnectionOptions:l.connectionOptions}):null,t[36]=c,t[37]=l.connectionOptions,t[38]=l.hideConnectionOptions,t[39]=i,t[40]=f,t[41]=r,t[42]=a,t[43]=N):N=t[43];let P;t[44]!==j||t[45]!==M||t[46]!==N?(P=(0,H.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[j,M,N]}),t[44]=j,t[45]=M,t[46]=N,t[47]=P):P=t[47];let F;return t[48]!==D||t[49]!==P?(F=(0,H.jsx)(`section`,{className:`rounded-xl bg-surface-panel/80 p-4 shadow-surface`,children:(0,H.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[D,P]})}),t[48]=D,t[49]=P,t[50]=F):F=t[50],F}function at(e){let t=(0,V.c)(33),{entry:n,ch:r}=e,i,a,o,s,c,l,u,d,f;if(t[0]!==r||t[1]!==n){f=Symbol.for(`react.early_return_sentinel`);bb0:{let e=Y(n);if(e.ready||e.issues.length===0){f=null;break bb0}d=`rounded-xl border border-amber-200 bg-amber-50 px-4 py-3 text-amber-950 dark:border-amber-900/50 dark:bg-amber-950/30 dark:text-amber-100`,l=`flex items-start gap-3`,t[11]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,H.jsx)(k,{className:`mt-0.5 size-4 shrink-0`}),t[11]=u):u=t[11],o=`min-w-0`,t[12]===r.setupReadinessTitle?s=t[13]:(s=(0,H.jsx)(`h3`,{className:`text-sm font-semibold`,children:r.setupReadinessTitle}),t[12]=r.setupReadinessTitle,t[13]=s);let p=e.enabled?r.setupReadinessEnabledBody:r.setupReadinessDisabledBody;t[14]===p?c=t[15]:(c=(0,H.jsx)(`p`,{className:`mt-1 text-sm leading-5 text-amber-900 dark:text-amber-200`,children:p}),t[14]=p,t[15]=c),i=`mt-2 list-disc space-y-1 pl-5 text-sm text-amber-900 dark:text-amber-200`;let m;t[16]===r?m=t[17]:(m=e=>(0,H.jsx)(`li`,{children:Qe(e,r)},`${e.code}:${e.fieldPath??``}`),t[16]=r,t[17]=m),a=e.issues.map(m)}t[0]=r,t[1]=n,t[2]=i,t[3]=a,t[4]=o,t[5]=s,t[6]=c,t[7]=l,t[8]=u,t[9]=d,t[10]=f}else i=t[2],a=t[3],o=t[4],s=t[5],c=t[6],l=t[7],u=t[8],d=t[9],f=t[10];if(f!==Symbol.for(`react.early_return_sentinel`))return f;let p;t[18]!==i||t[19]!==a?(p=(0,H.jsx)(`ul`,{className:i,children:a}),t[18]=i,t[19]=a,t[20]=p):p=t[20];let m;t[21]!==p||t[22]!==o||t[23]!==s||t[24]!==c?(m=(0,H.jsxs)(`div`,{className:o,children:[s,c,p]}),t[21]=p,t[22]=o,t[23]=s,t[24]=c,t[25]=m):m=t[25];let h;t[26]!==m||t[27]!==l||t[28]!==u?(h=(0,H.jsxs)(`div`,{className:l,children:[u,m]}),t[26]=m,t[27]=l,t[28]=u,t[29]=h):h=t[29];let g;return t[30]!==h||t[31]!==d?(g=(0,H.jsx)(`section`,{className:d,children:h}),t[30]=h,t[31]=d,t[32]=g):g=t[32],g}function ot(){let e=u(e=>e.language),t=c(e),n=l(e=>!!e.token),r=i(),{channelId:o}=a(),p=g(o),h=me(n,e),_=h.entries,{data:v,mutate:b,isValidating:C}=m(n?pe():null,fe,{revalidateOnFocus:!0}),{data:w,mutate:T}=m(n?`channels-config-map`:null,Fe,{revalidateOnFocus:!1}),D=w?.channels??{},O=w?.bindings??[],{data:k}=m(n?`channel-routing-agents`:null,x,{revalidateOnFocus:!1}),j=P(e=>e.setPageHeader),M=P(e=>e.clearPageHeader),F=(0,B.useMemo)(()=>_.find(e=>e.id===p),[p,_]),ee=F?Le(F):null,{data:ne,mutate:L}=m(n&&ee?Me(ee):null,()=>Ne(ee)),[R,z]=(0,B.useState)(null),[re,ie]=(0,B.useState)(!1),[ae,oe]=(0,B.useState)(null),[de,V]=(0,B.useState)(null),[ge,_e]=(0,B.useState)(!1),[U,W]=(0,B.useState)(null),[G,K]=(0,B.useState)(null),ye=R??ne??{},q=t.channelsSettings,Se=(0,B.useMemo)(()=>F?.configSchema??{type:`object`,properties:{}},[F?.configSchema]),we=(0,B.useMemo)(()=>We(Se,Pe),[Se]),Ee=(0,B.useMemo)(()=>Ve(F),[F]),J=(0,B.useMemo)(()=>He(we,Ee),[Ee,we]),Ae=(0,B.useMemo)(()=>We(we,Ee),[Ee,we]),Ie=(0,B.useMemo)(()=>Ge(J),[J]),ze=F?G??be(O,F.id):``,X=(0,B.useMemo)(()=>(k?.items??[]).map(e=>{let n=S(e,t.agentsSettings);return{value:e.id,label:n===e.id?n:`${n} · ${e.id}`}}),[k?.items,t.agentsSettings]),Z=k?.items.find(e=>e.id===k.defaultId),Ue=Z?S(Z,t.agentsSettings):k?.defaultId??``,Ke=(0,B.useMemo)(()=>({defaultBooleanLabel:q.schemaBooleanDefault,unsupportedArrayType:q.schemaUnsupportedArrayType,arrayAddPlaceholder:q.schemaArrayAddPlaceholder,unsupportedFieldType:(e,t)=>q.schemaUnsupportedFieldType.replace(`{{title}}`,e).replace(`{{type}}`,t?` (${t})`:``)}),[q]),qe=(0,B.useMemo)(()=>new Map((v??[]).map(e=>[e.name,e])),[v]),Je=v!==void 0,Ye=(0,B.useCallback)(e=>Ce(e,qe.get(e.id),Je),[qe,Je]),Q=(0,B.useCallback)(async()=>{await Promise.all([h.mutate(),b()])},[h,b]);je((0,B.useCallback)(e=>{let t=ke(e);t&&b(t,!1)},[b]),n);let Xe=(0,B.useMemo)(()=>n?(0,H.jsx)(De,{ch:q,refreshing:h.isValidating||C,saveOk:!1,onRefresh:()=>void Q()}):null,[h.isValidating,q,n,C,Q]);(0,B.useLayoutEffect)(()=>(j({startExtra:null,main:(0,H.jsx)(`div`,{className:`min-w-0`,children:(0,H.jsx)(`h1`,{className:`truncate text-base font-semibold tracking-tight text-fg`,children:t.settingsSections.channels})}),end:Xe}),()=>M()),[M,Xe,t.settingsSections.channels,j]);let Ze=(0,B.useCallback)(e=>{r(E(e)),z(null),K(null),W(null)},[r]),Qe=(0,B.useCallback)(()=>{r(N),z(null),K(null),W(null)},[r]),nt=(0,B.useCallback)(async e=>{V(e.id),W(null);try{let t=await d(f(`/api/channels/${encodeURIComponent(e.id)}/restart`),{method:`POST`});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error?.message??t.statusText)}await Q()}catch(e){W(e instanceof Error?e.message:String(e))}finally{V(null)}},[Q]);(0,B.useEffect)(()=>{K(null),_e(!1)},[F?.id]);let rt=(0,B.useCallback)(async()=>{if(!F||!R&&G===null)return!1;let e=Le(F);ie(!0),W(null);try{let t=await d(f(`/api/config`),{method:`PATCH`,body:JSON.stringify({...R?{channels:{[e]:R}}:{},...G===null?{}:{bindings:xe(O,F.id,G)}})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error?.message??t.statusText)}return R&&await L(R,!1),await T(),await h.mutate(),z(null),K(null),!0}catch(e){return W(e instanceof Error?e.message:String(e)),!1}finally{ie(!1)}},[F,G,O,h,R,T,L]),ot=(0,B.useCallback)(async e=>{let t=Y(e),n=Le(e),r=F?.id===e.id?R:null;if(!t.enabled&&!t.ready&&!r){Ze(e.id);return}oe(e.id),W(null);try{let i=t.enabled?{enabled:!1}:r?{...r,enabled:!0}:{enabled:!0},a=await d(f(`/api/config`),{method:`PATCH`,body:JSON.stringify({channels:{[n]:i}})});if(!a.ok){let e=await a.json().catch(()=>({}));throw Error(e.error?.message??a.statusText)}await h.mutate(),await T(),await b(),F?.id===e.id&&(await L(),z(null))}catch(e){W(e instanceof Error?e.message:String(e))}finally{oe(null)}},[F?.id,h,R,T,L,b,Ze]),$=F?.ui?.modal,st=$?.placement!==`replace-config`,ct=F?Ye(F):`checking`,lt=F?!Y(F).ready||ge:!1;return n?(0,H.jsxs)(ce,{gap:`gap-4`,children:[h.isLoading?(0,H.jsx)(le,{sections:2}):h.error?(0,H.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:String(h.error)}):(0,H.jsx)(`div`,{className:`grid gap-4 md:grid-cols-2 xl:grid-cols-3`,children:_.map(e=>(0,H.jsx)(tt,{entry:e,config:D[Le(e)]?.config,runtime:Ye(e),busy:ae===e.id,restarting:de===e.id,ch:q,onOpen:()=>Ze(e.id),onToggle:()=>void ot(e),onRestart:()=>void nt(e)},e.id))}),U?(0,H.jsx)(`p`,{className:`mt-4 text-sm text-red-600 dark:text-red-400`,children:U}):null,(0,H.jsx)(Te,{presentation:`modal`,open:!!F,onOpenChange:e=>{e||Qe()},closeAriaLabel:q.close,srTitle:F?.label??q.selectChannel,srDescription:F?.description,wide:!0,footer:F?(0,H.jsx)(Oe,{ch:q,dirty:!!R||G!==null,saving:re,onCancel:Qe,onDiscard:()=>{z(null),K(null)},onSave:rt}):null,children:F?(0,H.jsxs)(`div`,{className:`space-y-4`,children:[(0,H.jsx)(`div`,{className:`rounded-xl bg-surface-panel/80 p-3 shadow-surface`,children:(0,H.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,H.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[(0,H.jsx)($e,{entry:F}),(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,H.jsx)(`h2`,{className:`truncate text-base font-semibold text-fg`,children:F.label}),(0,H.jsx)(`span`,{className:s(`shrink-0 rounded-full px-2 py-0.5 text-xs font-medium`,Be(ct)),children:Re(ct,q)})]}),(0,H.jsxs)(`div`,{className:`mt-1 flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1 text-sm text-fg-muted`,children:[(0,H.jsx)(`span`,{className:`min-w-0 truncate`,children:!Y(F).ready&&he(F)?.[1].result===`qr`?q.scanLoginHint.replace(`{{channel}}`,F.label):F.description}),F.docsPath?(0,H.jsxs)(`a`,{href:F.docsPath,target:`_blank`,rel:`noreferrer`,className:`inline-flex shrink-0 items-center gap-1 text-accent hover:underline`,children:[q.docs,(0,H.jsx)(A,{className:`size-3.5`})]}):null]})]})]}),(0,H.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2 pr-8`,children:[(0,H.jsx)(`span`,{className:`hidden text-xs text-fg-muted sm:inline`,children:Y(F).enabled?q.enabledLabel:q.disabledLabel}),(0,H.jsx)(et,{checked:Y(F).enabled,disabled:ae===F.id,label:q.toggleChannel.replace(`{{channel}}`,F.label),onToggle:()=>void ot(F)})]})]})}),(0,H.jsx)(it,{runtime:ct,restarting:de===F.id,checking:C,showConnectionOptions:ge,canManageConnection:Y(F).ready&&$?.placement!==`replace-config`,ch:q,onRestart:()=>void nt(F),onCheck:()=>void Q(),onManageConnection:()=>_e(e=>!e)}),(0,H.jsx)(at,{entry:F,ch:q}),lt&&$?.placement!==`replace-config`?(0,H.jsx)(ve,{entry:F,locale:e,messages:q,compact:!0,onChanged:async()=>{await L(),await Q(),await T()}},F.id):null,$?.entrypoint&&$.placement===`before-config`?(0,H.jsx)(y,{extensionId:F.extensionId,extensionName:F.label,entrypoint:$.entrypoint,permissions:$.permissions,minHeight:$.minHeight,maxHeight:$.maxHeight,initialData:{channelId:F.id,entry:F,config:ye}}):null,$?.entrypoint&&$.placement!==`before-config`?(0,H.jsx)(y,{extensionId:F.extensionId,extensionName:F.label,entrypoint:$.entrypoint,permissions:$.permissions,minHeight:$.minHeight,maxHeight:$.maxHeight,initialData:{channelId:F.id,entry:F,config:ye}}):null,st&&Ie?(0,H.jsxs)(`section`,{className:`rounded-xl bg-surface-panel/80 p-4 shadow-surface`,children:[(0,H.jsxs)(`div`,{className:`mb-4`,children:[(0,H.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:q.basicConfiguration}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:q.basicConfigurationHint})]}),(0,H.jsx)(ue,{schema:J,values:ye,onChange:e=>z(e),disabled:re,labels:Ke})]}):null,(0,H.jsxs)(`details`,{className:`group rounded-xl bg-surface-panel/80 shadow-surface`,children:[(0,H.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 px-4 py-3 text-sm font-medium text-fg marker:hidden [&::-webkit-details-marker]:hidden`,children:[(0,H.jsx)(I,{className:`size-4 text-fg-muted`}),q.messageHandling]}),(0,H.jsxs)(`div`,{className:`bg-surface-base/50 p-4`,children:[(0,H.jsxs)(`div`,{className:`mb-3`,children:[(0,H.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:q.agentRouting}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:q.messageHandlingHint})]}),(0,H.jsx)(te,{value:ze,options:X,placeholder:q.agentRoutingSelect,emptyLabel:q.agentRoutingDefault.replace(`{{agent}}`,Ue||q.agentRoutingSelect),ariaLabel:q.agentRouting,disabled:re||!k,onChange:e=>K(e)})]})]}),st&&Ge(Ae)?(0,H.jsxs)(`details`,{className:`group rounded-xl bg-surface-panel/80 shadow-surface`,children:[(0,H.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 px-4 py-3 text-sm font-medium text-fg marker:hidden [&::-webkit-details-marker]:hidden`,children:[(0,H.jsx)(I,{className:`size-4 text-fg-muted`}),q.advancedConfiguration]}),(0,H.jsx)(`div`,{className:`bg-surface-base/50 p-4`,children:(0,H.jsx)(ue,{schema:Ae,values:ye,onChange:e=>z(e),disabled:re,labels:Ke})})]}):null,U?(0,H.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:U}):null]}):null})]}):(0,H.jsxs)(ce,{gap:`gap-3`,padding:`px-3 py-8 sm:px-5 xl:px-6`,children:[(0,H.jsx)(se,{title:t.settingsSections.channels}),(0,H.jsx)(`p`,{className:`text-sm text-fg-muted`,children:q.tokenRequired})]})}export{ot as ChannelsSettingsPanel};
@@ -0,0 +1 @@
1
+ import{r as e}from"./locale-store-Ys6RP7Be.js";import{n as t}from"./channel-recipient-api-r7tdbnJE.js";function n(){return e(`/api/channels/status`)}var r=t;export{r as n,n as t};
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{t as i}from"./cn-JdwAhgNB.js";import{Ic as a}from"./index-C8JkTS6d.js";var o=n(),s=e(t(),1),c=r(),l={sm:{frame:`size-9 rounded-lg`,image:`size-6`,fallback:`size-4`},md:{frame:`size-10 rounded-xl`,image:`size-7`,fallback:`size-5`},lg:{frame:`size-12 rounded-xl`,image:`size-8`,fallback:`size-5`}};function u(e){let t=(0,o.c)(18),{connector:n,size:r,className:u}=e,d=r===void 0?`md`:r,f=n?.branding?.logoUrl,[p,m]=(0,s.useState)(!1),h=l[d],g;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(g=()=>{m(!1)},t[0]=g):g=t[0];let _;t[1]===f?_=t[2]:(_=[f],t[1]=f,t[2]=_),(0,s.useEffect)(g,_);let v;t[3]!==u||t[4]!==h.frame?(v=i(`flex shrink-0 items-center justify-center overflow-hidden border border-edge bg-surface-base`,h.frame,u),t[3]=u,t[4]=h.frame,t[5]=v):v=t[5];let y;t[6]===n?y=t[7]:(y=n?.branding?.backgroundColor?{backgroundColor:n.branding.backgroundColor}:void 0,t[6]=n,t[7]=y);let b=n?.displayName,x;t[8]!==h.fallback||t[9]!==h.image||t[10]!==p||t[11]!==f?(x=f&&!p?(0,c.jsx)(`img`,{src:f,alt:``,loading:`lazy`,draggable:!1,className:i(`object-contain`,h.image),onError:()=>m(!0)}):(0,c.jsx)(a,{className:i(`text-fg-muted`,h.fallback),"aria-hidden":!0}),t[8]=h.fallback,t[9]=h.image,t[10]=p,t[11]=f,t[12]=x):x=t[12];let S;return t[13]!==v||t[14]!==y||t[15]!==b||t[16]!==x?(S=(0,c.jsx)(`span`,{className:v,style:y,title:b,children:x}),t[13]=v,t[14]=y,t[15]=b,t[16]=x,t[17]=S):S=t[17],S}export{u as t};
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{t as i}from"./cn-JdwAhgNB.js";import{Bc as a}from"./index-HZdBKfk_.js";var o=n(),s=e(t(),1),c=r(),l={sm:{frame:`size-9 rounded-lg`,image:`size-6`,fallback:`size-4`},md:{frame:`size-10 rounded-xl`,image:`size-7`,fallback:`size-5`},lg:{frame:`size-12 rounded-xl`,image:`size-8`,fallback:`size-5`}};function u(e){let t=(0,o.c)(18),{connector:n,size:r,className:u}=e,d=r===void 0?`md`:r,f=n?.branding?.logoUrl,[p,m]=(0,s.useState)(!1),h=l[d],g;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(g=()=>{m(!1)},t[0]=g):g=t[0];let _;t[1]===f?_=t[2]:(_=[f],t[1]=f,t[2]=_),(0,s.useEffect)(g,_);let v;t[3]!==u||t[4]!==h.frame?(v=i(`flex shrink-0 items-center justify-center overflow-hidden border border-edge bg-surface-base`,h.frame,u),t[3]=u,t[4]=h.frame,t[5]=v):v=t[5];let y;t[6]===n?y=t[7]:(y=n?.branding?.backgroundColor?{backgroundColor:n.branding.backgroundColor}:void 0,t[6]=n,t[7]=y);let b=n?.displayName,x;t[8]!==h.fallback||t[9]!==h.image||t[10]!==p||t[11]!==f?(x=f&&!p?(0,c.jsx)(`img`,{src:f,alt:``,loading:`lazy`,draggable:!1,className:i(`object-contain`,h.image),onError:()=>m(!0)}):(0,c.jsx)(a,{className:i(`text-fg-muted`,h.fallback),"aria-hidden":!0}),t[8]=h.fallback,t[9]=h.image,t[10]=p,t[11]=f,t[12]=x):x=t[12];let S;return t[13]!==v||t[14]!==y||t[15]!==b||t[16]!==x?(S=(0,c.jsx)(`span`,{className:v,style:y,title:b,children:x}),t[13]=v,t[14]=y,t[15]=b,t[16]=x,t[17]=S):S=t[17],S}export{u as t};