@xopcai/xopc 0.0.199 → 0.0.201

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 (152) hide show
  1. package/dist/browser-ext/manifest.json +1 -1
  2. package/dist/extensions/telegram/xopc.extension.json +1 -1
  3. package/dist/gateway/static/root/assets/{activity-store-DYVN1hRp.js → activity-store-DOhnAQOQ.js} +1 -1
  4. package/dist/gateway/static/root/assets/{agent-avatar-dicebear-Bt70bZjv.js → agent-avatar-dicebear-D8Cw0Mve.js} +1 -1
  5. package/dist/gateway/static/root/assets/agents-ANavi648.js +68 -0
  6. package/dist/gateway/static/root/assets/{api-B8mzbAle.js → api-E9Bk-Idp.js} +1 -1
  7. package/dist/gateway/static/root/assets/{app-management-settings-panel-B4x7JfL8.js → app-management-settings-panel-BubrReXg.js} +1 -1
  8. package/dist/gateway/static/root/assets/{appearance-settings-Dwdagf-Q.js → appearance-settings-BY5Az2p4.js} +1 -1
  9. package/dist/gateway/static/root/assets/{apps-page-DkTiesxe.js → apps-page-CFh9MBxc.js} +1 -1
  10. package/dist/gateway/static/root/assets/{archive-plugin-Cv0VXKLm.js → archive-plugin-BY8843mB.js} +1 -1
  11. package/dist/gateway/static/root/assets/{attachment-load-CgidKrXn.js → attachment-load-DG45KScf.js} +1 -1
  12. package/dist/gateway/static/root/assets/automations-page-751CeNI3.js +6 -0
  13. package/dist/gateway/static/root/assets/{binary-plugins-DN3CQgIq.js → binary-plugins-DGIF2ZAv.js} +1 -1
  14. package/dist/gateway/static/root/assets/{block-editor-BwkSl1F_.js → block-editor-C1Qktr1g.js} +5 -5
  15. package/dist/gateway/static/root/assets/browser-settings-page-CGAWs-TT.js +8 -0
  16. package/dist/gateway/static/root/assets/{browser-workflow-inputs-_ndaecsf.js → browser-workflow-inputs-D_jnndyz.js} +1 -1
  17. package/dist/gateway/static/root/assets/{browser-workflows-page-C_I31wLm.js → browser-workflows-page-DyIRvPaq.js} +2 -2
  18. package/dist/gateway/static/root/assets/capabilities-settings-panel-CghUK68J.js +7 -0
  19. package/dist/gateway/static/root/assets/{capability-presets-api-Dy1jZJKs.js → capability-presets-api--tz0mGLY.js} +1 -1
  20. package/dist/gateway/static/root/assets/capability-presets-settings-panel-XsTfkvUn.js +3 -0
  21. package/dist/gateway/static/root/assets/{channel-recipient-api-D-9qiuio.js → channel-recipient-api-CkOKF9nc.js} +1 -1
  22. package/dist/gateway/static/root/assets/{channels-settings-DV5BhAeu.js → channels-settings-DkoAZZMe.js} +1 -1
  23. package/dist/gateway/static/root/assets/channels-status-swr-DNDvMWpl.js +1 -0
  24. package/dist/gateway/static/root/assets/{connectors-api-5FEBYguL.js → connectors-api-FBOe9SWC.js} +1 -1
  25. package/dist/gateway/static/root/assets/connectors-page-e4vekkAu.js +2 -0
  26. package/dist/gateway/static/root/assets/{cron-expression-SEFx5rnr.js → cron-expression-Q4QaYjpI.js} +1 -1
  27. package/dist/gateway/static/root/assets/{date-picker-D4zCUQJL.js → date-picker-Dtn7e6TW.js} +1 -1
  28. package/dist/gateway/static/root/assets/{dependency-picker-DpQAxS2k.js → dependency-picker-Br6nPaM6.js} +1 -1
  29. package/dist/gateway/static/root/assets/{desktop-pet-B_5G3lQl.js → desktop-pet-DzTM6aH8.js} +1 -1
  30. package/dist/gateway/static/root/assets/{desktop-pet-settings-ClEyoUJe.js → desktop-pet-settings-FDmaty3P.js} +1 -1
  31. package/dist/gateway/static/root/assets/{directory-picker-path-field-AsFWmOjG.js → directory-picker-path-field-X2e8xn8j.js} +1 -1
  32. package/dist/gateway/static/root/assets/{extension-debug-page-C22Y2o5l.js → extension-debug-page-Dx4MBfga.js} +1 -1
  33. package/dist/gateway/static/root/assets/{extension-page-C61Ikawk.js → extension-page-Bf_FEDhM.js} +1 -1
  34. package/dist/gateway/static/root/assets/{extension-settings-page-WlWWcDFr.js → extension-settings-page-CrOgZxkf.js} +1 -1
  35. package/dist/gateway/static/root/assets/{gateway-config-api-ByIOMQdc.js → gateway-config-api-CZ4r-7qT.js} +1 -1
  36. package/dist/gateway/static/root/assets/{gateway-config-swr-jB0hAhWO.js → gateway-config-swr-Cv2ywpdb.js} +1 -1
  37. package/dist/gateway/static/root/assets/{gateway-settings-CzzS9A17.js → gateway-settings-DpWmVi0w.js} +1 -1
  38. package/dist/gateway/static/root/assets/{gateway-startup-retry-C-fRlHCL.js → gateway-startup-retry-undf-k5g.js} +1 -1
  39. package/dist/gateway/static/root/assets/heartbeat-settings-DSQZhSvT.js +1 -0
  40. package/dist/gateway/static/root/assets/home-page-L0uHiu0T.js +3 -0
  41. package/dist/gateway/static/root/assets/{index-CR233S0Q.css → index-Bp8I_eX4.css} +1 -1
  42. package/dist/gateway/static/root/assets/index-DRrjYYzZ.js +152 -0
  43. package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-BD_TFz0_.js → keyboard-shortcuts-settings-Bc3Quw42.js} +1 -1
  44. package/dist/gateway/static/root/assets/local-app-workbench-page-Copi3sdP.js +2 -0
  45. package/dist/gateway/static/root/assets/{local-apps-page-BwbUeLfm.js → local-apps-page-CP9X_vtz.js} +1 -1
  46. package/dist/gateway/static/root/assets/{locale-store-xULEcFVs.js → locale-store-CnamlR07.js} +1 -1
  47. package/dist/gateway/static/root/assets/logs-page-DMKq6e29.js +2 -0
  48. package/dist/gateway/static/root/assets/{management-settings-CW2VpqtT.js → management-settings-CJmcaVje.js} +1 -1
  49. package/dist/gateway/static/root/assets/{markdown-split-B1M9KO16.js → markdown-split-AcuFp0TH.js} +1 -1
  50. package/dist/gateway/static/root/assets/{media-plugins-B_QlNdqZ.js → media-plugins-BvFgsiJL.js} +1 -1
  51. package/dist/gateway/static/root/assets/messages-D7kOD_o_.js +3 -0
  52. package/dist/gateway/static/root/assets/{notes-page-BTbD4GmH.js → notes-page-IW7IQ9nJ.js} +1 -1
  53. package/dist/gateway/static/root/assets/notes-workbench-Zb8U0anO.js +4 -0
  54. package/dist/gateway/static/root/assets/{preview-open-alternatives-CeqtArlZ.js → preview-open-alternatives-C-b34dgQ.js} +1 -1
  55. package/dist/gateway/static/root/assets/{product-open-page-DnalBZZs.js → product-open-page-CWEzLykF.js} +1 -1
  56. package/dist/gateway/static/root/assets/project-detail-page-BuIbLnan.js +1 -0
  57. package/dist/gateway/static/root/assets/projects-page-BwUfRqNV.js +1 -0
  58. package/dist/gateway/static/root/assets/remote-access-hub-BTaXxcEi.js +1 -0
  59. package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-cGkBEfg4.js → runtime-tools-settings-panel-DAohEZrX.js} +2 -2
  60. package/dist/gateway/static/root/assets/{schema-form-CmsrLlxu.js → schema-form-C_OBW8A5.js} +1 -1
  61. package/dist/gateway/static/root/assets/sessions-page-BnHoTCD3.js +1 -0
  62. package/dist/gateway/static/root/assets/settings-advanced-gate-BTB_fxjt.js +1 -0
  63. package/dist/gateway/static/root/assets/{settings-form-section-DUWCbaMJ.js → settings-form-section-C7w2WS-A.js} +1 -1
  64. package/dist/gateway/static/root/assets/{settings-loading-skeleton-Bvy5rdMY.js → settings-loading-skeleton-zwibve4m.js} +1 -1
  65. package/dist/gateway/static/root/assets/{settings-page-cZSAwsRR.js → settings-page-B9W03dSW.js} +1 -1
  66. package/dist/gateway/static/root/assets/setup-status-panel-C8Hec2Af.js +1 -0
  67. package/dist/gateway/static/root/assets/{share-preview-page-BzA2NCAH.js → share-preview-page-6e3ks2be.js} +1 -1
  68. package/dist/gateway/static/root/assets/shares-settings-Bwc5HfLI.js +1 -0
  69. package/dist/gateway/static/root/assets/skill-reload-api-D7kunhqy.js +1 -0
  70. package/dist/gateway/static/root/assets/{skills-page-Bvde7_i5.js → skills-page-WgkaNzpc.js} +1 -1
  71. package/dist/gateway/static/root/assets/{skills-page.utils-vXSqHR7g.js → skills-page.utils-D9QT5cxj.js} +1 -1
  72. package/dist/gateway/static/root/assets/{system-settings-panel-9cQGOGCK.js → system-settings-panel-c1HVtv1Y.js} +1 -1
  73. package/dist/gateway/static/root/assets/task-detail-page-CjP-6WVU.js +1 -0
  74. package/dist/gateway/static/root/assets/{theme-store-CHQRiuCF.js → theme-store-BDyUTObE.js} +1 -1
  75. package/dist/gateway/static/root/assets/{use-autosave-7XfKULPI.js → use-autosave-D6UkH_Ga.js} +1 -1
  76. package/dist/gateway/static/root/assets/{user-context-page-CZ9m9aC_.js → user-context-page-D8ZhPDNF.js} +1 -1
  77. package/dist/gateway/static/root/assets/{voice-api-key-field-DXr21v-3.js → voice-api-key-field-BOxkKbGh.js} +1 -1
  78. package/dist/gateway/static/root/assets/{work-discovery-overlay-CeG7g_DZ.js → work-discovery-overlay-Dd19yK9t.js} +1 -1
  79. package/dist/gateway/static/root/assets/work-discovery-page-DUkdJl1e.js +1 -0
  80. package/dist/gateway/static/root/assets/{workflow-run-setup-panel-DSQQZP9T.js → workflow-run-setup-panel-ZA3bP65I.js} +2 -2
  81. package/dist/gateway/static/root/assets/workflows-page-C2b5W5bw.js +5 -0
  82. package/dist/gateway/static/root/assets/{working-directory-picker-modal-D-IgcHPp.js → working-directory-picker-modal-BcyiDXU3.js} +1 -1
  83. package/dist/gateway/static/root/index.html +9 -9
  84. package/dist/package.js +1 -1
  85. package/dist/packages/gateway-contract/src/tasks.js +51 -9
  86. package/dist/src/agent/context/execution-scope.js +3 -1
  87. package/dist/src/agent/tasks/task-judge-service.d.ts +1 -1
  88. package/dist/src/agent/tasks/task-judge-service.js +3 -2
  89. package/dist/src/agent/tools/xopc-use-tool.js +13 -3
  90. package/dist/src/auth/oauth/types.d.ts +2 -0
  91. package/dist/src/auth/oauth/xopc-cloud.js +24 -2
  92. package/dist/src/automations/domain/validation.d.ts +0 -12
  93. package/dist/src/automations/draft/automation-draft-validator.d.ts +0 -3
  94. package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
  95. package/dist/src/gateway/hono/app.js +1 -1
  96. package/dist/src/gateway/hono/oauth-async.js +2 -0
  97. package/dist/src/gateway/hono/routes/agent-stream.js +2 -74
  98. package/dist/src/gateway/hono/routes/session-input-handler.d.ts +62 -0
  99. package/dist/src/gateway/hono/routes/session-input-handler.js +82 -0
  100. package/dist/src/gateway/hono/routes/tasks.js +161 -2
  101. package/dist/src/gateway/service/task-conversation-query-service.d.ts +58 -0
  102. package/dist/src/gateway/service/task-conversation-query-service.js +84 -0
  103. package/dist/src/gateway/service.d.ts +10 -0
  104. package/dist/src/gateway/service.js +75 -42
  105. package/dist/src/projects/project-agent.js +1 -1
  106. package/dist/src/storage/sqlite/migrations/120_task_conversation.sql +112 -0
  107. package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
  108. package/dist/src/storage/sqlite/migrations/runner.js +3 -3
  109. package/dist/src/storage/sqlite/migrations/runner.ts +1 -1
  110. package/dist/src/storage/sqlite/schema.js +1 -1
  111. package/dist/src/tasks/execution-context.js +8 -4
  112. package/dist/src/tasks/index.d.ts +2 -0
  113. package/dist/src/tasks/index.js +3 -1
  114. package/dist/src/tasks/task-application-service.js +10 -17
  115. package/dist/src/tasks/task-context-assembler.js +9 -4
  116. package/dist/src/tasks/task-context-repository.d.ts +0 -6
  117. package/dist/src/tasks/task-context-repository.js +0 -4
  118. package/dist/src/tasks/task-conversation-repository.d.ts +71 -0
  119. package/dist/src/tasks/task-conversation-repository.js +194 -0
  120. package/dist/src/tasks/task-handoff-service.d.ts +31 -0
  121. package/dist/src/tasks/task-handoff-service.js +143 -0
  122. package/dist/src/tasks/task-read-model-projector.js +1 -5
  123. package/dist/src/tasks/task-repository.d.ts +0 -2
  124. package/dist/src/tasks/task-repository.js +2 -9
  125. package/dist/src/tasks/task-run-coordinator.js +3 -1
  126. package/dist/src/workflows/service/workflow-run-service.js +4 -2
  127. package/package.json +2 -2
  128. package/dist/gateway/static/root/assets/agents-D19uNmJf.js +0 -68
  129. package/dist/gateway/static/root/assets/automations-page-BR6qMOVr.js +0 -6
  130. package/dist/gateway/static/root/assets/browser-settings-page-CDFQWAxI.js +0 -8
  131. package/dist/gateway/static/root/assets/capabilities-settings-panel-D41mssOq.js +0 -7
  132. package/dist/gateway/static/root/assets/capability-presets-settings-panel-BXgCyuu2.js +0 -3
  133. package/dist/gateway/static/root/assets/channels-status-swr-B4Rbh3bM.js +0 -1
  134. package/dist/gateway/static/root/assets/connectors-page-C_qkEN0T.js +0 -2
  135. package/dist/gateway/static/root/assets/heartbeat-settings-B4A_CXUL.js +0 -1
  136. package/dist/gateway/static/root/assets/home-page-FVGYYPWo.js +0 -3
  137. package/dist/gateway/static/root/assets/index-CGbKTCST.js +0 -152
  138. package/dist/gateway/static/root/assets/local-app-workbench-page-BNpkigNb.js +0 -2
  139. package/dist/gateway/static/root/assets/logs-page-DXP9OQQt.js +0 -2
  140. package/dist/gateway/static/root/assets/messages-3qRsLZuX.js +0 -3
  141. package/dist/gateway/static/root/assets/notes-workbench-JRiq7QDW.js +0 -4
  142. package/dist/gateway/static/root/assets/project-detail-page-CjWA13aE.js +0 -1
  143. package/dist/gateway/static/root/assets/projects-page-jsCkScbG.js +0 -1
  144. package/dist/gateway/static/root/assets/remote-access-hub-CGPJTEkM.js +0 -1
  145. package/dist/gateway/static/root/assets/sessions-page-BBHzziMd.js +0 -1
  146. package/dist/gateway/static/root/assets/settings-advanced-gate-2cGg8-9h.js +0 -1
  147. package/dist/gateway/static/root/assets/setup-status-panel-Cf06b66-.js +0 -1
  148. package/dist/gateway/static/root/assets/shares-settings-xlNKydYY.js +0 -1
  149. package/dist/gateway/static/root/assets/skill-reload-api-C5Xu93c_.js +0 -1
  150. package/dist/gateway/static/root/assets/task-detail-page-Bkno4tTe.js +0 -1
  151. package/dist/gateway/static/root/assets/work-discovery-page-CQWZD03N.js +0 -1
  152. package/dist/gateway/static/root/assets/workflows-page-Cs-MXFJ1.js +0 -5
@@ -0,0 +1,7 @@
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,f as a,l as o,r as s,t as c}from"./chunk-KS7C4IRE-BMhrPKJC.js";import{n as l,r as u,t as d}from"./popover-select-BzdnTy3h.js";import{t as f}from"./external-link-DjqjBmc3.js";import{t as p}from"./globe-DSSGFWFn.js";import{t as m}from"./loader-circle-CifKLtgG.js";import{t as h}from"./cn-JdwAhgNB.js";import{t as g}from"./button-CSEbl4zT.js";import{a as _,o as v,s as y}from"./form-field-width-DJw_jULe.js";import{n as b,t as x}from"./interaction-BmQogeqz.js";import{t as S}from"./messages-D7kOD_o_.js";import{l as C,n as w,o as T,r as E,s as D}from"./locale-store-CnamlR07.js";import{i as O,o as k}from"./settings-shell-dialog-layer-BU3UuiJr.js";import{a as A,i as j,n as M,o as N,r as P,s as F,t as I}from"./dist-BPoKqzeH.js";import{i as L}from"./vendor-swr-BIWyz7Rc.js";import{n as R,r as z}from"./gateway-config-swr-Cv2ywpdb.js";import{n as B,t as V}from"./settings-form-draft-Dy10ldo8.js";import{$ as H,$o as U,An as W,As as G,Cr as K,Ct as ee,Dt as te,Et as ne,Fo as q,Ft as re,Gl as ie,Go as ae,Gs as J,Hl as oe,Ho as Y,Ht as se,It as ce,Ko as le,Ks as ue,Ln as de,Lo as fe,Ls as X,Lt as pe,Mc as me,Mt as he,Na as ge,Ns as _e,Nt as ve,Oc as ye,Ol as be,Ot as xe,Po as Se,Pt as Ce,Ro as we,Rt as Te,St as Ee,Tl as De,Tt as Oe,Uo as ke,Ut as Ae,Ws as je,Xs as Me,Yo as Ne,_t as Pe,at as Fe,bt as Ie,cc as Le,cs as Re,ct as ze,dt as Be,es as Ve,et as He,fl as Ue,ft as We,gt as Ge,ht as Ke,it as qe,jt as Je,kt as Ye,ls as Xe,lt as Ze,mt as Qe,nt as $e,ot as et,pc as tt,pt as nt,rt,st as it,tl as at,tt as ot,ut as st,vt as ct,ws as lt,wt as ut,xt as dt,ys as ft,yt as pt}from"./index-DRrjYYzZ.js";import{n as mt,r as ht}from"./settings-page-layout-BRQNel6r.js";import{t as gt}from"./settings-loading-skeleton-zwibve4m.js";import{n as _t,t as vt}from"./use-autosave-D6UkH_Ga.js";import{a as yt,c as bt,d as xt,f as St,i as Ct,l as wt,n as Tt,r as Et,s as Dt,t as Ot,u as kt}from"./voice-api-key-field-BOxkKbGh.js";import{t as At}from"./settings-advanced-gate-BTB_fxjt.js";import{n as jt,t as Mt}from"./settings-form-section-C7w2WS-A.js";import{t as Nt}from"./page-tabs-BaEQMYm_.js";var Z=n(),Q=e(t(),1),$=r(),Pt={en:{addTitle:`Add image service`,editTitle:`Manage image service`,intro:`Connect an endpoint that implements the OpenAI Images protocol.`,connection:`Connection`,providerId:`Provider ID`,providerIdHint:`Lowercase letters, numbers, hyphens, or underscores.`,name:`Display name`,baseUrl:`Base URL`,auth:`Authentication`,bearer:`Bearer token`,header:`Custom API key header`,none:`No authentication`,headerName:`Header name`,apiKey:`API key`,apiKeyHint:`Stored in the local credential store, separate from models.json.`,apiKeyUrl:`API key page (optional)`,docsUrl:`Documentation page (optional)`,openKeyPage:`Create API key`,paths:`Protocol and network`,generationsPath:`Generations path`,editsPath:`Edits path`,allowedHosts:`Allowed private hosts (optional)`,allowedHostsHint:`One exact hostname or IP per line. Private endpoints stay blocked unless listed here.`,staticHeaders:`Static headers (optional)`,staticHeadersHint:`One per line: X-Tenant: value. Credential headers are rejected.`,models:`Image models`,addModel:`Add model`,modelId:`Model ID`,modelName:`Name (optional)`,defaultModel:`Default model`,maxCount:`Max images`,defaultCount:`Default count`,defaultSize:`Default size`,format:`Output format`,supportsSize:`Supports size`,edit:`Supports edits`,remove:`Remove`,cancel:`Cancel`,save:`Save service`,saving:`Saving…`,test:`Test generation`,testing:`Generating…`,delete:`Delete service`,confirmDelete:`Delete permanently`,saved:`Image service saved.`,deleted:`Image service deleted.`,testReady:`Test image generated.`,show:`Show key`,hide:`Hide key`,copy:`Copy key`,copied:`Copied`,revealFailed:`Unable to reveal the saved key.`,notRevealable:`No revealable key is stored locally.`,required:`Complete the required connection and model fields.`,duplicateModels:`Model IDs must be unique.`,invalidHeaders:`Static headers must use “Name: value”, one per line.`},zh:{addTitle:`添加图片服务`,editTitle:`管理图片服务`,intro:`连接一个严格实现 OpenAI Images 协议的服务端点。`,connection:`连接信息`,providerId:`Provider ID`,providerIdHint:`仅支持小写字母、数字、连字符和下划线。`,name:`显示名称`,baseUrl:`Base URL`,auth:`认证方式`,bearer:`Bearer Token`,header:`自定义 API Key Header`,none:`无需认证`,headerName:`Header 名称`,apiKey:`API Key`,apiKeyHint:`密钥单独保存在本机凭据存储,不写入 models.json。`,apiKeyUrl:`API Key 创建页面(可选)`,docsUrl:`协议文档页面(可选)`,openKeyPage:`去创建 API Key`,paths:`协议与网络`,generationsPath:`生成路径`,editsPath:`编辑路径`,allowedHosts:`允许访问的私有主机(可选)`,allowedHostsHint:`每行一个精确主机名或 IP;未列出的私网端点保持阻止。`,staticHeaders:`静态 Headers(可选)`,staticHeadersHint:`每行一个:X-Tenant: value。认证 Header 会被拒绝。`,models:`图片模型`,addModel:`添加模型`,modelId:`模型 ID`,modelName:`名称(可选)`,defaultModel:`默认模型`,maxCount:`单次最大张数`,defaultCount:`默认张数`,defaultSize:`默认尺寸`,format:`输出格式`,supportsSize:`支持尺寸参数`,edit:`支持图片编辑`,remove:`移除`,cancel:`取消`,save:`保存服务`,saving:`保存中…`,test:`测试生成`,testing:`生成中…`,delete:`删除服务`,confirmDelete:`确认永久删除`,saved:`图片服务已保存。`,deleted:`图片服务已删除。`,testReady:`测试图片生成成功。`,show:`显示密钥`,hide:`隐藏密钥`,copy:`复制密钥`,copied:`已复制`,revealFailed:`无法查看已保存的密钥。`,notRevealable:`本机没有可查看的密钥。`,required:`请补全必填的连接和模型信息。`,duplicateModels:`模型 ID 不能重复。`,invalidHeaders:`静态 Header 必须使用“名称: 值”格式,每行一个。`}},Ft=`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`;function It(e){let t=e??{id:``,capabilities:{generate:{maxCount:1,supportsSize:!0},edit:{enabled:!1}}};return{original:t,id:t.id,name:t.name??``,maxCount:String(t.capabilities.generate?.maxCount??1),defaultCount:t.defaults?.count?String(t.defaults.count):``,defaultSize:t.defaults?.size??``,outputFormat:t.defaults?.outputFormat??``,supportsSize:t.capabilities.generate?.supportsSize??!1,editEnabled:t.capabilities.edit?.enabled??!1}}function Lt(e){let t=e.split(`
2
+ `).map(e=>e.trim()).filter(Boolean);if(t.length===0)return;let n=t.map(e=>{let t=e.indexOf(`:`);if(t<=0||!e.slice(t+1).trim())throw Error(`invalid_headers`);return[e.slice(0,t).trim(),e.slice(t+1).trim()]});return Object.fromEntries(n)}function Rt({open:e,onOpenChange:t,provider:n,configured:r,language:i,onSaved:a}){let o=Pt[i],[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(``),[_,v]=(0,Q.useState)(`bearer`),[y,b]=(0,Q.useState)(`x-api-key`),[x,S]=(0,Q.useState)(``),[C,w]=(0,Q.useState)(``),[T,E]=(0,Q.useState)(``),[D,L]=(0,Q.useState)(`/images/generations`),[R,z]=(0,Q.useState)(`/images/edits`),[B,V]=(0,Q.useState)(``),[H,U]=(0,Q.useState)(``),[W,G]=(0,Q.useState)([It()]),[K,ee]=(0,Q.useState)(``),[te,ne]=(0,Q.useState)(),[q,J]=(0,Q.useState)(!1),[oe,Y]=(0,Q.useState)(),[se,ce]=(0,Q.useState)(),[ue,de]=(0,Q.useState)();(0,Q.useEffect)(()=>{if(!e)return;let t=n?.imageGeneration;c(n?.providerId??``),u(t?.name??``),p(n?.baseUrl??``),v(t?.auth.type??`bearer`),b(t?.auth.type===`header`?t.auth.headerName:`x-api-key`),S(r?`••••••••••••`:``),w(t?.apiKeyUrl??``),E(t?.documentationUrl??``),L(t?.paths?.generations??`/images/generations`),z(t?.paths?.edits??`/images/edits`),V(t?.network?.allowedHosts.join(`
3
+ `)??``),U(Object.entries(n?.headers??{}).map(([e,t])=>`${e}: ${t}`).join(`
4
+ `)),G(t?.models.map(It)??[It()]),ee(t?.defaultModel??``),ce(void 0),ne(void 0),J(!1),Y(void 0),de(void 0)},[r,e,n]);let fe=(0,Q.useMemo)(()=>W.filter(e=>e.id.trim()).map(e=>({value:e.id.trim(),label:e.name.trim()||e.id.trim()})),[W]),X=(e,t)=>{G(n=>n.map((n,r)=>r===e?{...n,...t}:n))},pe=()=>{let e=s.trim(),t=W.map(e=>({...e,id:e.id.trim(),name:e.name.trim()}));if(!e||!l.trim()||!f.trim()||t.some(e=>!e.id))throw Error(o.required);if(new Set(t.map(e=>e.id)).size!==t.length)throw Error(o.duplicateModels);let n=K||t[0]?.id;if(!n||!t.some(e=>e.id===n))throw Error(o.required);let r;try{r=Lt(H)}catch{throw Error(o.invalidHeaders)}return{providerId:e,input:{baseUrl:f.trim(),...r?{headers:r}:{},imageGeneration:{api:`openai-images`,name:l.trim(),...T.trim()?{documentationUrl:T.trim()}:{},...C.trim()?{apiKeyUrl:C.trim()}:{},defaultModel:n,auth:_===`header`?{type:`header`,headerName:y.trim()}:{type:_},paths:{...D.trim()?{generations:D.trim()}:{},...R.trim()?{edits:R.trim()}:{}},...B.trim()?{network:{allowedHosts:B.split(`
5
+ `).map(e=>e.trim()).filter(Boolean)}}:{},models:t.map(e=>({...e.original,id:e.id,...e.name?{name:e.name}:{name:void 0},capabilities:{...e.original.capabilities,generate:{...e.original.capabilities.generate,maxCount:Math.max(1,Number.parseInt(e.maxCount,10)||1),supportsSize:e.supportsSize},edit:{...e.original.capabilities.edit,enabled:e.editEnabled}},defaults:{...e.original.defaults,...e.defaultCount?{count:Math.max(1,Number.parseInt(e.defaultCount,10)||1)}:{count:void 0},...e.defaultSize.trim()?{size:e.defaultSize.trim()}:{size:void 0},...e.outputFormat?{outputFormat:e.outputFormat}:{outputFormat:void 0}}}))}}}},me=async()=>{let e=pe();return await Fe(e.providerId,e.input),_!==`none`&&x.trim()&&!le(x)&&await et(e.providerId,x.trim()),await a(e.providerId),e},he=async()=>{ne(`save`),Y(void 0),ce(void 0);try{await me(),S(_===`none`?``:`••••••••••••`),ce(o.saved)}catch(e){Y(e instanceof Error?e.message:String(e))}finally{ne(void 0)}},ge=async()=>{ne(`test`),Y(void 0),ce(void 0),de(void 0);try{let e=await me();de((await it(e.providerId,e.input.imageGeneration.defaultModel)).images[0]?.dataUrl),ce(o.testReady)}catch(e){Y(e instanceof Error?e.message:String(e))}finally{ne(void 0)}},_e=async()=>{if(n){if(!q){J(!0);return}ne(`delete`),Y(void 0);try{await $e(n.providerId),await a(),t(!1)}catch(e){Y(e instanceof Error?e.message:String(e))}finally{ne(void 0)}}};return(0,$.jsx)(I,{open:e,onOpenChange:t,children:(0,$.jsxs)(N,{children:[(0,$.jsx)(A,{className:h(`xopc-dialog-overlay fixed inset-0 bg-scrim`,k)}),(0,$.jsxs)(P,{className:h(`xopc-dialog-content fixed left-1/2 top-1/2 flex h-[min(88vh,760px)] w-[min(calc(100%-2rem),52rem)] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-edge bg-surface-panel shadow-popover`,O),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,$.jsxs)(`header`,{className:`flex shrink-0 items-start justify-between gap-4 border-b border-edge px-5 py-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(F,{className:`font-semibold text-fg`,children:n?o.editTitle:o.addTitle}),(0,$.jsx)(j,{className:`mt-1 text-sm text-fg-muted`,children:o.intro})]}),(0,$.jsx)(M,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:`rounded-md p-1 text-fg-muted hover:bg-surface-subtle hover:text-fg`,"aria-label":o.cancel,children:(0,$.jsx)(Ne,{className:`size-5`})})})]}),(0,$.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-6 overflow-y-auto px-5 py-4`,children:[(0,$.jsxs)(`section`,{className:`space-y-4`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wide text-fg-subtle`,children:o.connection}),(0,$.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.providerId,(0,$.jsx)(`input`,{value:s,disabled:!!n,onChange:e=>c(e.target.value),placeholder:`my-image-service`,className:Ft}),(0,$.jsx)(`span`,{className:`mt-1 block font-normal text-fg-subtle`,children:o.providerIdHint})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.name,(0,$.jsx)(`input`,{value:l,onChange:e=>u(e.target.value),placeholder:`My Image Service`,className:Ft})]})]}),(0,$.jsxs)(`label`,{className:`block text-xs font-medium text-fg-muted`,children:[o.baseUrl,(0,$.jsx)(`input`,{value:f,onChange:e=>p(e.target.value),placeholder:`https://api.example.com/v1`,className:Ft})]}),(0,$.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.auth,(0,$.jsx)(d,{value:_,options:[{value:`bearer`,label:o.bearer},{value:`header`,label:o.header},{value:`none`,label:o.none}],placeholder:o.auth,allowEmpty:!1,onChange:e=>v(e),triggerClassName:`mt-1.5`})]}),_===`header`?(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.headerName,(0,$.jsx)(`input`,{value:y,onChange:e=>b(e.target.value),className:Ft})]}):null]}),_===`none`?null:(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`mb-1.5 flex items-center justify-between`,children:[(0,$.jsx)(`label`,{htmlFor:`custom-image-api-key`,className:`text-xs font-medium text-fg-muted`,children:o.apiKey}),C.trim()?(0,$.jsxs)(`a`,{href:C.trim(),target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent hover:underline`,children:[o.openKeyPage,(0,$.jsx)(ie,{className:`size-3.5`})]}):null]}),(0,$.jsx)(ae,{id:`custom-image-api-key`,value:x,onChange:e=>S(le(x)?e.replace(/^•+/,``):e),labels:{show:o.show,hide:o.hide,copy:o.copy,copied:o.copied},reveal:()=>re(s).then(e=>e.apiKey),loadFailedLabel:o.revealFailed,notInConfigFile:o.notRevealable}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:o.apiKeyHint})]}),(0,$.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.apiKeyUrl,(0,$.jsx)(`input`,{value:C,onChange:e=>w(e.target.value),placeholder:`https://…`,className:Ft})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.docsUrl,(0,$.jsx)(`input`,{value:T,onChange:e=>E(e.target.value),placeholder:`https://…`,className:Ft})]})]}),(0,$.jsxs)(`details`,{className:`rounded-lg border border-edge bg-surface-subtle px-3 py-2.5`,children:[(0,$.jsx)(`summary`,{className:`cursor-pointer text-sm font-medium text-fg-muted`,children:o.paths}),(0,$.jsxs)(`div`,{className:`mt-3 grid gap-4 md:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.generationsPath,(0,$.jsx)(`input`,{value:D,onChange:e=>L(e.target.value),className:Ft})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.editsPath,(0,$.jsx)(`input`,{value:R,onChange:e=>z(e.target.value),className:Ft})]})]}),(0,$.jsxs)(`label`,{className:`mt-4 block text-xs font-medium text-fg-muted`,children:[o.allowedHosts,(0,$.jsx)(`textarea`,{value:B,onChange:e=>V(e.target.value),rows:2,placeholder:`127.0.0.1
6
+ image-server.lan`,className:`mt-1.5 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 font-mono text-xs text-fg outline-none focus:border-accent focus:ring-2 focus:ring-accent/20`}),(0,$.jsx)(`span`,{className:`mt-1 block font-normal text-fg-subtle`,children:o.allowedHostsHint})]}),(0,$.jsxs)(`label`,{className:`mt-4 block text-xs font-medium text-fg-muted`,children:[o.staticHeaders,(0,$.jsx)(`textarea`,{value:H,onChange:e=>U(e.target.value),rows:3,className:`mt-1.5 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 font-mono text-xs text-fg outline-none focus:border-accent focus:ring-2 focus:ring-accent/20`}),(0,$.jsx)(`span`,{className:`mt-1 block font-normal text-fg-subtle`,children:o.staticHeadersHint})]})]})]}),(0,$.jsxs)(`section`,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wide text-fg-subtle`,children:o.models}),(0,$.jsxs)(g,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,onClick:()=>G(e=>[...e,It()]),children:[(0,$.jsx)(je,{className:`size-4`}),o.addModel]})]}),(0,$.jsxs)(`label`,{className:`block text-xs font-medium text-fg-muted`,children:[o.defaultModel,(0,$.jsx)(d,{value:K||fe[0]?.value||``,options:fe,placeholder:o.defaultModel,allowEmpty:!1,onChange:ee,triggerClassName:`mt-1.5 max-w-sm`})]}),W.map((e,t)=>(0,$.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface-base p-3`,children:[(0,$.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.modelId,(0,$.jsx)(`input`,{value:e.id,onChange:e=>X(t,{id:e.target.value}),placeholder:`image-1`,className:Ft})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.modelName,(0,$.jsx)(`input`,{value:e.name,onChange:e=>X(t,{name:e.target.value}),className:Ft})]})]}),(0,$.jsxs)(`div`,{className:`mt-3 grid gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.maxCount,(0,$.jsx)(`input`,{type:`number`,min:1,value:e.maxCount,onChange:e=>X(t,{maxCount:e.target.value}),className:Ft})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.defaultCount,(0,$.jsx)(`input`,{type:`number`,min:1,value:e.defaultCount,onChange:e=>X(t,{defaultCount:e.target.value}),className:Ft})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.defaultSize,(0,$.jsx)(`input`,{value:e.defaultSize,onChange:e=>X(t,{defaultSize:e.target.value}),placeholder:`1024x1024`,className:Ft})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.format,(0,$.jsx)(d,{value:e.outputFormat,options:[{value:`png`,label:`PNG`},{value:`jpeg`,label:`JPEG`},{value:`webp`,label:`WebP`}],placeholder:o.format,allowEmpty:!0,onChange:e=>X(t,{outputFormat:e}),triggerClassName:`mt-1.5`})]})]}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-4`,children:[(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:e.supportsSize,onChange:e=>X(t,{supportsSize:e.target.checked})}),o.supportsSize]}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:e.editEnabled,onChange:e=>X(t,{editEnabled:e.target.checked})}),o.edit]}),(0,$.jsxs)(`button`,{type:`button`,disabled:W.length===1,onClick:()=>G(e=>e.filter((e,n)=>n!==t)),className:`ml-auto inline-flex items-center gap-1 text-xs text-red-600 disabled:opacity-40 dark:text-red-400`,children:[(0,$.jsx)(Xe,{className:`size-3.5`}),o.remove]})]})]},t))]}),ue?(0,$.jsxs)(`section`,{className:`rounded-lg border border-edge bg-surface-base p-3`,children:[(0,$.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 text-sm font-medium text-fg`,children:[(0,$.jsx)(at,{className:`size-4`}),o.testReady]}),(0,$.jsx)(`img`,{src:ue,alt:`Generated provider test`,className:`max-h-72 rounded-lg object-contain`})]}):null,se?(0,$.jsx)(`p`,{className:`rounded-lg bg-emerald-500/10 px-3 py-2 text-sm text-emerald-700 dark:text-emerald-300`,role:`status`,children:se}):null,oe?(0,$.jsx)(`p`,{className:`rounded-lg bg-red-500/10 px-3 py-2 text-sm text-red-600 dark:text-red-400`,children:oe}):null]}),(0,$.jsxs)(`footer`,{className:`flex shrink-0 flex-wrap items-center gap-2 border-t border-edge px-5 py-3`,children:[n?(0,$.jsxs)(g,{variant:`secondary`,className:`border-red-500/30 text-red-600 hover:bg-red-500/10 dark:text-red-400`,disabled:!!te,onClick:()=>void _e(),children:[te===`delete`?(0,$.jsx)(m,{className:`size-4 animate-spin`}):(0,$.jsx)(Xe,{className:`size-4`}),q?o.confirmDelete:o.delete]}):null,(0,$.jsxs)(`div`,{className:`ml-auto flex gap-2`,children:[(0,$.jsx)(M,{asChild:!0,children:(0,$.jsx)(g,{variant:`secondary`,children:o.cancel})}),(0,$.jsxs)(g,{variant:`secondary`,disabled:!!te,onClick:()=>void ge(),children:[te===`test`?(0,$.jsx)(m,{className:`size-4 animate-spin`}):null,te===`test`?o.testing:o.test]}),(0,$.jsxs)(g,{variant:`primary`,disabled:!!te,onClick:()=>void he(),children:[te===`save`?(0,$.jsx)(m,{className:`size-4 animate-spin`}):null,te===`save`?o.saving:o.save]})]})]})]})]})})}var zt=`••••••••••••`,Bt={en:{title:`Image generation`,intro:`Choose an agent and image model, or connect an OpenAI Images service of your own.`,agent:`Agent`,provider:`Provider`,model:`Model`,apiKey:`API key`,getApiKey:`Get 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.`,savedKey:`A credential is saved. Use the eye button to view it, or type a new key to replace it.`,revealFailed:`Unable to load the saved API key.`,keyNotRevealable:`This credential comes from an environment variable or another non-revealable source.`,advanced:`Provider settings`,enable:`Enable image generation`,enabling:`Verifying and enabling…`,enabled:`Image generation is ready.`,addService:`Add image service`,manageService:`Manage service`,custom:`Custom`,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 选择图片模型,也可以连接你自己的 OpenAI Images 服务。`,agent:`Agent`,provider:`Provider`,model:`模型`,apiKey:`API Key`,getApiKey:`获取 API Key`,apiKeyHint:`密钥只保存在本机凭据存储中,不会写入 xopc.json。`,existingKey:`已有凭据或环境变量;留空即可继续使用。`,savedKey:`凭据已保存。点击眼睛可查看,直接输入新密钥可替换。`,revealFailed:`无法读取已保存的 API Key。`,keyNotRevealable:`当前凭据来自环境变量或其他不可查看的来源。`,advanced:`服务商设置`,enable:`启用图片生成`,enabling:`正在验证并启用…`,enabled:`图片生成已可用。`,addService:`添加图片服务`,manageService:`管理服务`,custom:`自定义`,current:`当前使用`,configured:`凭据已就绪`,needsKey:`需要 API Key`,connect:`请先连接网关。`,loadError:`无法加载图片生成设置。`,selectAgent:`选择 Agent`,selectModel:`选择模型`,show:`显示密钥`,hide:`隐藏密钥`,copy:`复制密钥`,copied:`已复制`}};async function Vt(e){let t=await D(E(`/api/agents/${encodeURIComponent(e)}/image-generation`));if(!t.payload)throw Error(`Invalid agent image generation response`);return t.payload}function Ht(e){let t=e?.indexOf(`/`)??-1;return t>0?e.slice(0,t):void 0}function Ut(e){let t=e?.indexOf(`/`)??-1;return t>0?e.slice(t+1):void 0}function Wt(e){return Object.fromEntries(e.configFields.map(t=>[t.key,e.config[t.key]??(t.required?t.options?.[0]?.value??``:``)]))}function Gt(e){let t=(0,Z.c)(11),{field:n,value:r,onChange:i}=e,a;t[0]!==n.label||t[1]!==n.options||t[2]!==n.placeholder||t[3]!==n.required||t[4]!==n.type||t[5]!==i||t[6]!==r?(a=n.type===`select`?(0,$.jsx)(d,{value:r,options:(n.options??[]).map(Kt),placeholder:n.placeholder??n.label,allowEmpty:!n.required,onChange:i,triggerClassName:`mt-1.5`}):(0,$.jsx)(`input`,{type:`url`,value:r,required:n.required,onChange:e=>i(e.target.value),placeholder:n.placeholder,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`}),t[0]=n.label,t[1]=n.options,t[2]=n.placeholder,t[3]=n.required,t[4]=n.type,t[5]=i,t[6]=r,t[7]=a):a=t[7];let o;return t[8]!==n.label||t[9]!==a?(o=(0,$.jsxs)(`label`,{className:`block text-xs font-medium text-fg-muted`,children:[n.label,a]}),t[8]=n.label,t[9]=a,t[10]=o):o=t[10],o}function Kt(e){return{value:e.value,label:e.label}}function qt(){let e=(0,Z.c)(2),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(ge,{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(Jt)}),(0,$.jsx)(ge,{className:`h-64 rounded-xl`})]}),e[1]=n):n=e[1],n}function Jt(e,t){return(0,$.jsx)(ge,{className:`h-24 rounded-xl`},t)}function Yt(){let e=w(e=>e.language),t=Bt[e],n=S(e),r=!!C(e=>e.token),[i,a]=(0,Q.useState)(``),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(``),[u,f]=(0,Q.useState)(``),[p,h]=(0,Q.useState)({}),[_,v]=(0,Q.useState)(!1),[y,b]=(0,Q.useState)(),[x,T]=(0,Q.useState)(!1),[O,k]=(0,Q.useState)(!1),[A,j]=(0,Q.useState)(),{data:M,isLoading:N,error:P}=L(r?`image-generation-agents`:null,de,{revalidateOnFocus:!1}),{data:F,isLoading:I,error:R,mutate:z}=L(r?E(`/api/image-generation/catalog`):null,qe,{revalidateOnFocus:!1}),{data:B,isLoading:V,error:H,mutate:U}=L(r?E(`/api/image-generation/custom-providers`):null,rt,{revalidateOnFocus:!1});(0,Q.useEffect)(()=>{!M||i||a(M.defaultId||M.agents[0]?.id||``)},[i,M]);let{data:K,isLoading:ee,error:te,mutate:ne}=L(r&&i?[`agent-image-generation`,i]:null,()=>Vt(i),{revalidateOnFocus:!1});(0,Q.useEffect)(()=>{if(!F||!K)return;let e=Ht(K.model?.primary),t=F.find(t=>t.id===e)??F.find(e=>e.configured)??F[0];t&&(s(t.id),l(t.id===e&&Ut(K.model?.primary)||t.defaultModel),f(t.configured?zt:``),h(Wt(t)))},[K,F]),(0,Q.useEffect)(()=>{b(void 0)},[i]);let q=F?.find(e=>e.id===o),J=q?q.apiKeyUrl??He(q.id,e)[0]?.href:void 0,oe=(0,Q.useMemo)(()=>(M?.agents??[]).map(e=>({value:e.id,label:W(e,n.agentsSettings)})),[M?.agents,n.agentsSettings]),Y=(0,Q.useMemo)(()=>(q?.models??[]).map(e=>({value:e,label:e})),[q?.models]),se=K?.model?.primary,ce=!!(i&&q&&c&&(q.credentialMode!==`api-key`||q.configured||u.trim())&&q.configFields.every(e=>!e.required||p[e.key]?.trim()));if(!r)return(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.connect});if(N||I||V||ee)return(0,$.jsx)(qt,{});if(P||R||H||te||!F||!M||!B)return(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:t.loadError});let ue=e=>{s(e.id),l(e.defaultModel),f(e.configured?zt:``),h(Wt(e)),b(void 0)},fe=()=>{j(void 0),k(!0)},X=()=>{let e=B.find(e=>e.providerId===q?.id);e&&(j(e),k(!0))},pe=async e=>{let[t,n]=await Promise.all([U(),z()]);if(e&&n?.some(t=>t.id===e)){let r=n.find(t=>t.id===e);s(r.id),l(r.defaultModel),f(r.configured?zt:``),h(Wt(r)),j(t?.find(t=>t.providerId===e))}},he=async()=>{if(!(!q||!ce)){v(!0),b(void 0),T(!1);try{let e=await D(E(`/api/agents/${encodeURIComponent(i)}/image-generation/setup`),{method:`POST`,body:JSON.stringify({providerId:q.id,modelId:c,...u.trim()&&!le(u)?{apiKey:u.trim()}:{},providerConfig:Object.fromEntries(Object.entries(p).filter(([,e])=>e.trim()))})});if(!e.payload)throw Error(`Invalid setup response`);await Promise.all([ne(e.payload.agent,{revalidate:!1}),z(e.payload.providers,{revalidate:!1})]),f(zt),T(!0)}catch(e){b(e instanceof Error?e.message:String(e))}finally{v(!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)(me,{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)(d,{value:i,options:oe,placeholder:t.selectAgent,allowEmpty:!1,onChange:a,triggerClassName:`mt-1.5 max-w-md`})]})]}),(0,$.jsxs)(`section`,{children:[(0,$.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-3`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wide text-fg-subtle`,children:t.provider}),(0,$.jsxs)(g,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,onClick:fe,children:[(0,$.jsx)(je,{className:`size-4`}),t.addService]})]}),(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 xl:grid-cols-3`,children:F.map(e=>{let n=e.id===o,r=e.id===Ht(se);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>ue(e),className:`min-h-24 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,$.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`truncate font-medium text-fg`,children:e.label}),e.source===`custom`?(0,$.jsx)(`span`,{className:`rounded-full bg-surface-subtle px-2 py-0.5 text-[10px] text-fg-subtle`,children:t.custom}):null]}),(0,$.jsx)(`span`,{"aria-hidden":!r,className:`shrink-0 rounded-full bg-accent/10 px-2 py-0.5 text-[11px] font-medium text-accent ${r?``:`invisible`}`,children:t.current})]}),(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||e.credentialMode!==`api-key`?(0,$.jsx)(De,{className:`size-3.5`}):(0,$.jsx)(ye,{className:`size-3.5`}),e.configured||e.credentialMode!==`api-key`?t.configured:t.needsKey]})]},e.id)})})]}),q?(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)(d,{value:c,options:Y,placeholder:t.selectModel,allowEmpty:!1,onChange:l,triggerClassName:`mt-1.5`})]}),q.configFields.filter(e=>e.required).map(e=>(0,$.jsx)(Gt,{field:e,value:p[e.key]??``,onChange:t=>h(n=>({...n,[e.key]:t}))},e.key))]}),q.source===`custom`?(0,$.jsx)(`div`,{className:`mt-4 flex justify-end`,children:(0,$.jsxs)(g,{variant:`secondary`,onClick:X,children:[(0,$.jsx)(G,{className:`size-4`}),t.manageService]})}):null,q.credentialMode===`api-key`?(0,$.jsxs)(`div`,{className:`mt-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(`label`,{htmlFor:`image-generation-api-key`,className:`text-xs font-medium text-fg-muted`,children:t.apiKey}),J?(0,$.jsxs)(`a`,{href:J,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs font-medium text-accent hover:underline`,children:[t.getApiKey,(0,$.jsx)(ie,{className:`size-3.5`,"aria-hidden":`true`})]}):null]}),(0,$.jsx)(ae,{id:`image-generation-api-key`,value:u,onChange:e=>f(le(u)?e.replace(/^•+/,``):e),placeholder:q.configured?t.existingKey:t.needsKey,labels:{show:t.show,hide:t.hide,copy:t.copy,copied:t.copied},reveal:()=>re(q.id).then(e=>e.apiKey),loadFailedLabel:t.revealFailed,notInConfigFile:t.keyNotRevealable,className:`mt-1.5`,autoComplete:`new-password`},q.id),(0,$.jsx)(`span`,{className:`mt-1.5 block font-normal leading-relaxed text-fg-subtle`,children:q.configured?t.savedKey:t.apiKeyHint})]}):null,q.configFields.some(e=>!e.required)?(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)(lt,{className:`size-4`}),t.advanced]}),(0,$.jsx)(`div`,{className:`mt-3 grid gap-3 md:grid-cols-2`,children:q.configFields.filter(e=>!e.required).map(e=>(0,$.jsx)(Gt,{field:e,value:p[e.key]??``,onChange:t=>h(n=>({...n,[e.key]:t}))},e.key))})]}):null,x?(0,$.jsx)(`p`,{className:`mt-4 rounded-lg bg-emerald-500/10 px-3 py-2 text-sm text-emerald-700 dark:text-emerald-300`,role:`status`,children:t.enabled}):null,y?(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:y}):null,(0,$.jsx)(`div`,{className:`mt-4 flex justify-end`,children:(0,$.jsxs)(g,{variant:`primary`,disabled:!ce||_,onClick:()=>void he(),children:[_?(0,$.jsx)(m,{className:`size-4 animate-spin`}):(0,$.jsx)(De,{className:`size-4`}),(0,$.jsxs)(`span`,{className:`grid`,children:[(0,$.jsx)(`span`,{"aria-hidden":!0,className:`invisible col-start-1 row-start-1`,children:t.enable}),(0,$.jsx)(`span`,{"aria-hidden":!0,className:`invisible col-start-1 row-start-1`,children:t.enabling}),(0,$.jsx)(`span`,{className:`col-start-1 row-start-1`,children:_?t.enabling:t.enable})]})]})})]}):null,(0,$.jsx)(Rt,{open:O,onOpenChange:k,provider:A,configured:!!(A&&F.find(e=>e.id===A.providerId)?.configured),language:e,onSaved:pe})]})}var Xt=_;function Zt(){return h(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,y,`dark:border-edge`)}function Qt(){return h(v,_)}function $t(e){return!e||e<=0?``:e<1024*1024?`${Math.round(e/1024)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function en(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}))}function tn(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 nn(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 rn(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 an(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 on(e){return{maskedHelp:e.apiKeyMaskedHelp,copy:e.apiKeyCopy,copied:e.apiKeyCopied,show:e.apiKeyShow,hide:e.apiKeyHide,notInConfigFile:e.apiKeyNotInConfigFile,loadFailed:e.apiKeyRevealFailed}}function sn(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 cn(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 ln(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`saved`:{let n=structuredClone(t.value);return{form:e.form!==null&&JSON.stringify(e.form)!==JSON.stringify(t.value)?e.form:n,baseline:structuredClone(n)}}}}function un(){let e=w(e=>e.language),t=S(e).voiceSettings,n=!!C(e=>e.token),[r,i]=(0,Q.useReducer)(ln,{form:null,baseline:null}),a=r.form,o=r.baseline,[s,c]=(0,Q.useState)(null),l=(0,Q.useRef)(!1),u=(0,Q.useRef)(a);u.current=a;let d=(0,Q.useRef)({parsed:null,models:void 0}),{data:f,error:p,isLoading:m,mutate:h}=z(n),{data:_,error:v,isLoading:y,mutate:b}=L(n?E(`/api/voice/models`):null,Ct,{revalidateOnFocus:!1}),{data:x,error:T,isLoading:D}=L(n?E(`/api/voice/providers`):null,yt,{revalidateOnFocus:!1}),{data:O,error:k,isLoading:A}=L(n?E(`/api/voice/stt-providers`):null,Dt,{revalidateOnFocus:!1}),j=(0,Q.useMemo)(()=>x?.providers??[],[x]),M=(0,Q.useMemo)(()=>O?.providers??[],[O]),N=(0,Q.useMemo)(()=>f?.payload?.config===void 0?null:wt(f.payload.config),[f]),P=(0,Q.useMemo)(()=>!a||!o?!1:JSON.stringify(a)!==JSON.stringify(o),[a,o]);n?N!==null&&_!==void 0&&!l.current&&(d.current.parsed!==N||d.current.models!==_)&&(d.current={parsed:N,models:_},i({type:`sync`,value:N}),c(_)):(d.current.parsed!==null||d.current.models!==void 0)&&(d.current={parsed:null,models:void 0},i({type:`reset`}),c(null),l.current=!1);let F=!!(n&&(N===null||_===void 0||x===void 0||O===void 0)&&(m||y||D||A)),I=p instanceof Error?p.message:p?String(p):v instanceof Error?v.message:v?String(v):T instanceof Error?T.message:T?String(T):k instanceof Error?k.message:k?String(k):null,R=(0,Q.useCallback)(e=>{l.current=!0,i({type:`update`,updater:t=>t?{...t,stt:{...t.stt,...e}}:null})},[]),B=(0,Q.useCallback)(e=>{l.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}}}}})},[]),V=(0,Q.useCallback)(e=>{l.current=!0,i({type:`update`,updater:t=>t?{...t,voice:{...t.voice,input:{...t.voice.input,refinement:{...t.voice.input.refinement,...e}}}}:null})},[]),H=(0,Q.useCallback)(t=>{l.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=>{l.current=!0,i({type:`update`,updater:t=>t?{...t,tts:{...t.tts,...e}}:null})},[]),W=vt({value:a,dirty:P,onSave:(0,Q.useCallback)(async e=>{try{await kt(e),i({type:`saved`,value:e}),l.current=!!(u.current&&JSON.stringify(u.current)!==JSON.stringify(e))}catch(e){throw Error(e instanceof Error?e.message:t.saveError)}},[t.saveError])});if(!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(F)return(0,$.jsx)(gt,{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:I??t.loadError}),(0,$.jsx)(g,{type:`button`,variant:`secondary`,onClick:()=>{h(),b()},children:t.retry})]});let G=a.stt,K=a.tts,ee=a.voice.input.refinement,te=on(t);return(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,onBlurCapture:W.onBlurCapture,children:[(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(_t,{status:W.status,error:W.error})}),W.error?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:W.error}):null,(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsx)(dn,{v:t,voice:a.voice,updateLanguageMode:H}),(0,$.jsx)(fn,{v:t,stt:G,tts:K}),(0,$.jsx)(mn,{v:t,apiKeyLabels:te,stt:G,models:s,sttProviders:M,refinement:ee,updateStt:R,updateSttFallback:B,updateRefinement:V}),(0,$.jsx)(vn,{v:t,apiKeyLabels:te,tts:K,models:s,ttsProviders:j,updateTts:U})]}),(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 dn(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 d;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(d=Qt(),t[7]=d):d=t[7];let f;t[8]===i?f=t[9]:(f=e=>i(e.target.value),t[8]=i,t[9]=f);let p;t[10]===n.language.auto?p=t[11]:(p=(0,$.jsx)(u,{value:`auto`,children:n.language.auto}),t[10]=n.language.auto,t[11]=p);let m;t[12]===n.language.manual?m=t[13]:(m=(0,$.jsx)(u,{value:`manual`,children:n.language.manual}),t[12]=n.language.manual,t[13]=m);let h;t[14]!==f||t[15]!==p||t[16]!==m||t[17]!==r.languageMode?(h=(0,$.jsxs)(l,{className:d,value:r.languageMode,onChange:f,children:[p,m]}),t[14]=f,t[15]=p,t[16]=m,t[17]=r.languageMode,t[18]=h):h=t[18];let g;return t[19]!==c||t[20]!==h?(g=(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,h]})}),t[19]=c,t[20]=h,t[21]=g):g=t[21],g}function fn(e){let t=(0,Z.c)(39),{v:n,stt:r,tts:i}=e,a=i.providers?.[i.provider]?.voice,o=typeof a==`string`?a:void 0,s;t[0]===n.overview.title?s=t[1]:(s=(0,$.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:n.overview.title}),t[0]=n.overview.title,t[1]=s);let c;t[2]===n.overview.description?c=t[3]:(c=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:n.overview.description}),t[2]=n.overview.description,t[3]=c);let l;t[4]!==s||t[5]!==c?(l=(0,$.jsxs)(`div`,{className:`mb-4`,children:[s,c]}),t[4]=s,t[5]=c,t[6]=l):l=t[6];let u;t[7]!==r.enabled||t[8]!==r.provider||t[9]!==n?(u=r.enabled?`${n.overview.ready} · ${tn(r.provider,n)}`:n.overview.off,t[7]=r.enabled,t[8]=r.provider,t[9]=n,t[10]=u):u=t[10];let d;t[11]!==r.enabled||t[12]!==u||t[13]!==n.overview.input?(d=(0,$.jsx)(pn,{label:n.overview.input,value:u,ready:r.enabled}),t[11]=r.enabled,t[12]=u,t[13]=n.overview.input,t[14]=d):d=t[14];let f;t[15]!==i.enabled||t[16]!==i.trigger||t[17]!==n?(f=i.enabled?rn(i.trigger,n):n.overview.off,t[15]=i.enabled,t[16]=i.trigger,t[17]=n,t[18]=f):f=t[18];let p=i.enabled&&i.trigger!==`off`,m;t[19]!==f||t[20]!==p||t[21]!==n.overview.replies?(m=(0,$.jsx)(pn,{label:n.overview.replies,value:f,ready:p}),t[19]=f,t[20]=p,t[21]=n.overview.replies,t[22]=m):m=t[22];let h;t[23]!==o||t[24]!==i.enabled||t[25]!==i.provider||t[26]!==n?(h=i.enabled?`${nn(i.provider,n)}${o?` · ${o}`:``}`:n.overview.off,t[23]=o,t[24]=i.enabled,t[25]=i.provider,t[26]=n,t[27]=h):h=t[27];let g;t[28]!==h||t[29]!==i.enabled||t[30]!==n.overview.voice?(g=(0,$.jsx)(pn,{label:n.overview.voice,value:h,ready:i.enabled}),t[28]=h,t[29]=i.enabled,t[30]=n.overview.voice,t[31]=g):g=t[31];let _;t[32]!==g||t[33]!==d||t[34]!==m?(_=(0,$.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-3`,children:[d,m,g]}),t[32]=g,t[33]=d,t[34]=m,t[35]=_):_=t[35];let v;return t[36]!==_||t[37]!==l?(v=(0,$.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[l,_]}),t[36]=_,t[37]=l,t[38]=v):v=t[38],v}function pn(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=h(`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 l;return t[7]!==a||t[8]!==c?(l=(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]=l):l=t[9],l}function mn(e){let t=(0,Z.c)(62),{v:n,apiKeyLabels:r,stt:i,models:a,sttProviders:o,refinement:s,updateStt:c,updateSttFallback:d,updateRefinement:f}=e,p;if(t[0]!==o){let e=new Set;p=[];for(let t of o)e.has(t.id)||(e.add(t.id),p.push(t));t[0]=o,t[1]=p}else p=t[1];let m=p,g,_,v,y;if(t[2]!==a||t[3]!==m||t[4]!==i.provider||t[5]!==i.providers){g=m.find(e=>e.id===i.provider);let e;t[10]!==i.provider||t[11]!==i.providers?(e=i.providers?.[i.provider]??{},t[10]=i.provider,t[11]=i.providers,t[12]=e):e=t[12],v=e,_=a?.stt?.[i.provider]?.length?a.stt[i.provider]:g?.models??[],y=g?.fields.find(hn),t[2]=a,t[3]=m,t[4]=i.provider,t[5]=i.providers,t[6]=g,t[7]=_,t[8]=v,t[9]=y}else g=t[6],_=t[7],v=t[8],y=t[9];let b=y,x=typeof v.model==`string`?v.model:void 0,S=x??(typeof b?.defaultValue==`string`?b.defaultValue:_[0]?.id),C;t[13]!==i.provider||t[14]!==i.providers||t[15]!==c?(C=e=>{c({providers:{...i.providers??{},[i.provider]:{...i.providers?.[i.provider]??{},...e}}})},t[13]=i.provider,t[14]=i.providers,t[15]=c,t[16]=C):C=t[16];let w=C,T,E;t[17]!==x||t[18]!==S||t[19]!==b||t[20]!==w?(T=()=>{b&&S&&x!==S&&w({model:S})},E=[x,S,b,w],t[17]=x,t[18]=S,t[19]=b,t[20]=w,t[21]=T,t[22]=E):(T=t[21],E=t[22]),(0,Q.useEffect)(T,E);let D;t[23]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,$.jsx)(Le,{className:`size-4 text-accent`,strokeWidth:1.75}),t[23]=D):D=t[23];let O;t[24]===n.stt.title?O=t[25]:(O=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[D,n.stt.title]}),t[24]=n.stt.title,t[25]=O);let k;t[26]===n.stt.description?k=t[27]:(k=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:n.stt.description}),t[26]=n.stt.description,t[27]=k);let A;t[28]!==O||t[29]!==k?(A=(0,$.jsxs)(`div`,{className:`mb-4`,children:[O,k]}),t[28]=O,t[29]=k,t[30]=A):A=t[30];let j;t[31]===c?j=t[32]:(j=e=>c({enabled:e}),t[31]=c,t[32]=j);let M;t[33]!==i.enabled||t[34]!==j||t[35]!==n.overview.off||t[36]!==n.overview.ready||t[37]!==n.stt.enable||t[38]!==n.stt.enableDesc?(M=(0,$.jsx)(bn,{checked:i.enabled,title:n.stt.enable,description:n.stt.enableDesc,onLabel:n.overview.ready,offLabel:n.overview.off,onChange:j}),t[33]=i.enabled,t[34]=j,t[35]=n.overview.off,t[36]=n.overview.ready,t[37]=n.stt.enable,t[38]=n.stt.enableDesc,t[39]=M):M=t[39];let N;t[40]!==g?.fields||t[41]!==r||t[42]!==S||t[43]!==_||t[44]!==m||t[45]!==v||t[46]!==s||t[47]!==i.enabled||t[48]!==i.fallback?.enabled||t[49]!==i.provider||t[50]!==w||t[51]!==f||t[52]!==c||t[53]!==d||t[54]!==n?(N=i.enabled?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:h(`flex flex-col gap-1.5`,Xt),children:[(0,$.jsx)(Cn,{children:n.stt.provider}),(0,$.jsx)(l,{className:Qt(),value:i.provider,onChange:e=>c({provider:e.target.value}),children:m.map(e=>(0,$.jsxs)(u,{value:e.id,children:[tn(e.id,n),e.configured?``:` *`]},e.id))})]}),(0,$.jsx)(yn,{kind:`stt`,providerId:i.provider,fields:g?.fields??[],providerSlice:v,models:_,currentModel:S,apiKeyLabels:r,onPatch:w})]}),i.provider===`xopc-local`?(0,$.jsx)(_n,{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=>d({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)(l,{className:Qt(),value:s.mode,onChange:e=>f({mode:e.target.value}),children:[(0,$.jsx)(u,{value:`off`,children:n.stt.refinementOff}),(0,$.jsx)(u,{value:`punctuation`,children:n.stt.refinementPunctuation}),(0,$.jsx)(u,{value:`light`,children:n.stt.refinementLight})]})]})]}):null,t[40]=g?.fields,t[41]=r,t[42]=S,t[43]=_,t[44]=m,t[45]=v,t[46]=s,t[47]=i.enabled,t[48]=i.fallback?.enabled,t[49]=i.provider,t[50]=w,t[51]=f,t[52]=c,t[53]=d,t[54]=n,t[55]=N):N=t[55];let P;t[56]!==M||t[57]!==N?(P=(0,$.jsxs)(`div`,{className:`space-y-4`,children:[M,N]}),t[56]=M,t[57]=N,t[58]=P):P=t[58];let F;return t[59]!==P||t[60]!==A?(F=(0,$.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[A,P]}),t[59]=P,t[60]=A,t[61]=F):F=t[61],F}function hn(e){return e.key===`model`}function gn(e){return`${Math.round(e/1024/1024)} MB`}function _n({v:e}){let{data:t,error:n,mutate:r}=L(E(`/api/voice/local/status`),Tt,{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 bt(e.id):await xt(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:h(`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:[gn(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)(g,{type:`button`,variant:`secondary`,disabled:n,onClick:()=>void c(t,t.state===`ready`?`remove`:`install`),children:n?(0,$.jsx)(m,{className:`size-4 animate-spin`}):t.state===`ready`?e.stt.localRemove:e.stt.localInstall})]},t.id)})})]})}function vn({v:e,apiKeyLabels:t,tts:n,models:r,ttsProviders:i,updateTts:a}){let[o,s]=(0,Q.useState)(e.tts.test.sampleText),[c,d]=(0,Q.useState)({status:`idle`}),f=(0,Q.useRef)(null),p=(0,Q.useRef)(null),_=(0,Q.useCallback)(()=>{f.current?.pause(),f.current=null,p.current&&=(URL.revokeObjectURL(p.current),null)},[]),v=(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]),y=v.find(e=>e.id===n.provider),b=n.providers?.[n.provider]??{},x=r?.tts?.[n.provider]?.length?r.tts[n.provider]:y?.models??[],S=y?.fields.find(e=>e.key===`model`),C=y?.fields.find(e=>e.key===`voice`),w=typeof b.model==`string`?b.model:void 0,T=w??(typeof S?.defaultValue==`string`?S.defaultValue:x[0]?.id),E=x.find(e=>e.id===T),D=r?.ttsVoices?.[n.provider]?.length?r.ttsVoices[n.provider]:y?.voices??[],{data:O=[]}=L(T?`voice:tts:${n.provider}:${T}`:null,()=>Et(n.provider,T??``),{revalidateOnFocus:!1}),k=O.length>0?O:D,A=typeof b.voice==`string`?b.voice:void 0,j=A??k.find(e=>e.id===E?.tts?.defaultVoice)?.id??(typeof C?.defaultValue==`string`?C.defaultValue:k[0]?.id),M=(y?.fields??[]).filter(e=>(e.key!==`speed`||E?.tts?.speed!==!1)&&(e.key!==`instructions`||E?.tts?.instructions!==!1)),N=!!y?.diagnostics.requiresApiKey,P=!!y?.configured||!N,F=n.enabled?P?`ready`:`action`:`muted`,I=(0,Q.useCallback)(e=>{a({providers:{...n.providers??{},[n.provider]:{...n.providers?.[n.provider]??{},...e}}})},[n.provider,n.providers,a]);(0,Q.useEffect)(()=>{let e={};S&&T&&w!==T&&(e.model=T),C&&j&&A!==j&&(e.voice=j),Object.keys(e).length>0&&I(e)},[w,A,T,j,S,I,C]),(0,Q.useEffect)(()=>()=>_(),[_]);let R=(0,Q.useCallback)(e=>{a({provider:e}),d({status:`idle`})},[a]),z=(0,Q.useCallback)(async()=>{let t=o.trim();if(!t){d({status:`error`,message:e.tts.test.emptyText});return}_(),d({status:`loading`});try{let r=await St({text:t,provider:n.provider,providerConfig:b,...T?{model:T}:{},...j?{voice:j}:{}}),i=en(r.audio,r.mimeType);p.current=i;let a=new Audio(i);f.current=a;let o=[r.provider,r.format,r.latencyMs===void 0?void 0:`${r.latencyMs}ms`,$t(r.audioSize)].filter(Boolean).join(` · `);a.addEventListener(`ended`,()=>d({status:`done`,summary:o}),{once:!0}),a.addEventListener(`error`,()=>d({status:`error`,message:e.tts.test.playFailed}),{once:!0}),await a.play(),d({status:`playing`,summary:o})}catch(e){_(),d({status:`error`,message:e instanceof Error?e.message:String(e)})}},[T,j,b,_,o,n.provider,e.tts.test.emptyText,e.tts.test.playFailed]);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)(U,{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)(bn,{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:h(`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} ${nn(n.provider,e)}${j?` · ${j}`:``}`:`${e.tts.statusNeedsSetup} ${nn(n.provider,e)} · ${y?.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:h(`flex flex-col gap-1.5`,Xt),children:[(0,$.jsx)(Cn,{children:e.tts.trigger}),(0,$.jsxs)(l,{className:Qt(),value:n.trigger,onChange:e=>a({trigger:e.target.value}),children:[(0,$.jsx)(u,{value:`off`,children:e.tts.triggerOff}),(0,$.jsx)(u,{value:`inbound`,children:e.tts.triggerInbound}),(0,$.jsx)(u,{value:`tagged`,children:e.tts.triggerTagged}),(0,$.jsx)(u,{value:`always`,children:e.tts.triggerAlways})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.triggerHelp})]}),(0,$.jsxs)(`div`,{className:h(`flex flex-col gap-1.5`,Xt),children:[(0,$.jsx)(Cn,{children:e.tts.provider}),(0,$.jsx)(l,{className:Qt(),value:n.provider,onChange:e=>R(e.target.value),children:v.map(t=>(0,$.jsx)(u,{value:t.id,children:nn(t.id,e)},t.id))}),(0,$.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[y?.configured?e.tts.configured:y?.diagnostics.requiresApiKey?`${e.tts.needsKey} · ${y.diagnostics.envKeys?.join(`, `)??e.stt.apiKey}`:e.tts.noKeyNeeded,` · `,y?.description??an(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,$.jsx)(`div`,{className:`mt-3`,children:(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:(0,$.jsx)(yn,{kind:`tts`,providerId:n.provider,fields:M,providerSlice:b,models:x,voices:k,currentModel:T,currentVoice:j,apiKeyLabels:t,onPatch:I,resetVoiceOnModelChange:!0})})})]}),(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)(g,{type:`button`,variant:`primary`,onClick:()=>void z(),disabled:c.status===`loading`,className:`h-9`,children:[c.status===`loading`?(0,$.jsx)(m,{className:`size-4 animate-spin`}):(0,$.jsx)(ue,{className:`size-4`}),c.status===`loading`?e.tts.test.generating:e.tts.test.play]}),(0,$.jsxs)(g,{type:`button`,variant:`secondary`,onClick:()=>{_(),d(e=>e.status===`playing`?{status:`done`,summary:e.summary}:{status:`idle`})},disabled:c.status!==`playing`,className:`h-9`,children:[(0,$.jsx)(ft,{className:`size-4`}),e.tts.test.stop]})]})]}),(0,$.jsx)(`textarea`,{className:h(Zt(),`mt-3 min-h-20 resize-y`),value:o,onChange:e=>s(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:[o.length,`/1000`]}),c.status===`playing`||c.status===`done`?(0,$.jsxs)(`span`,{className:`text-emerald-700 dark:text-emerald-200`,children:[c.status===`playing`?e.tts.test.playing:e.tts.test.ready,` · `,c.summary]}):null,c.status===`error`?(0,$.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:c.message}):null]})]})]}):null]})]})}function yn({kind:e,providerId:t,fields:n,providerSlice:r,models:i,voices:a=[],currentModel:o,currentVoice:s,apiKeyLabels:c,onPatch:d,resetVoiceOnModelChange:f=!1}){return n.map(n=>n.key===`apiKey`?(0,$.jsxs)(`div`,{className:h(`flex flex-col gap-1.5`,Xt),children:[(0,$.jsx)(Cn,{children:n.label}),(0,$.jsx)(Ot,{kind:e,providerId:t,fieldId:`voice-${e}-${t}-api-key`,value:typeof r.apiKey==`string`?r.apiKey:``,onChange:e=>d({apiKey:e}),labels:c,placeholder:n.placeholder}),n.description?(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.description}):null]},n.key):n.key===`model`&&i.length>0?(0,$.jsxs)(`div`,{className:h(`flex flex-col gap-1.5`,Xt),children:[(0,$.jsx)(Cn,{children:n.label}),(0,$.jsx)(l,{className:Qt(),value:o??``,onChange:e=>d({model:e.target.value,...f?{voice:void 0}:{}}),children:i.map(e=>(0,$.jsx)(u,{value:e.id,children:e.name},e.id))})]},n.key):n.key===`voice`&&a.length>0?(0,$.jsxs)(`div`,{className:h(`flex flex-col gap-1.5`,Xt),children:[(0,$.jsx)(Cn,{children:n.label}),(0,$.jsx)(l,{className:Qt(),value:s??``,onChange:e=>d({voice:e.target.value}),children:a.map(e=>(0,$.jsx)(u,{value:e.id,children:e.name},e.id))})]},n.key):(0,$.jsx)(xn,{field:n,value:sn(r,n),onChange:e=>d({[n.key]:e}),className:n.type===`textarea`?`sm:col-span-2`:Xt},n.key))}function bn(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 l=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`,u;t[3]===l?u=t[4]:(u=h(`group flex w-full items-center justify-between gap-4 rounded-2xl px-4 py-3 text-left shadow-surface transition-colors`,y,l),t[3]=l,t[4]=u);let d=n?`bg-accent text-white`:`bg-surface-hover text-fg-muted`,f;t[5]===d?f=t[6]:(f=h(`rounded-full px-2 py-0.5 text-[11px] font-medium`,d),t[5]=d,t[6]=f);let p=n?a:o,m;t[7]!==f||t[8]!==p?(m=(0,$.jsx)(`span`,{className:f,children:p}),t[7]=f,t[8]=p,t[9]=m):m=t[9];let g;t[10]!==m||t[11]!==r?(g=(0,$.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-sm font-semibold text-fg`,children:[r,m]}),t[10]=m,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 b=n?`border-accent bg-accent`:`border-edge bg-surface-hover group-hover:border-accent/40`,x;t[18]===b?x=t[19]:(x=h(`relative inline-flex h-6 w-11 shrink-0 items-center rounded-full border transition-colors`,b),t[18]=b,t[19]=x);let S=n?`translate-x-5`:`translate-x-0.5`,C;t[20]===S?C=t[21]:(C=h(`size-5 rounded-full bg-white shadow-surface transition-transform`,S),t[20]=S,t[21]=C);let w;t[22]===C?w=t[23]:(w=(0,$.jsx)(`span`,{className:C}),t[22]=C,t[23]=w);let T;t[24]!==x||t[25]!==w?(T=(0,$.jsx)(`span`,{className:x,"aria-hidden":!0,children:w}),t[24]=x,t[25]=w,t[26]=T):T=t[26];let E;return t[27]!==n||t[28]!==c||t[29]!==v||t[30]!==T||t[31]!==u?(E=(0,$.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":n,onClick:c,className:u,children:[v,T]}),t[27]=n,t[28]=c,t[29]=v,t[30]=T,t[31]=u,t[32]=E):E=t[32],E}function xn(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=h(`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 l;t[6]!==o||t[7]!==c?(l=(0,$.jsxs)(`span`,{children:[o,c]}),t[6]=o,t[7]=c,t[8]=l):l=t[8];let u=!!r,d;t[9]!==n||t[10]!==i?(d=e=>i(cn(n,e.target.checked)),t[9]=n,t[10]=i,t[11]=d):d=t[11];let f;t[12]!==u||t[13]!==d?(f=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:u,onChange:d}),t[12]=u,t[13]=d,t[14]=f):f=t[14];let p;return t[15]!==e||t[16]!==l||t[17]!==f?(p=(0,$.jsxs)(`label`,{className:e,children:[l,f]}),t[15]=e,t[16]=l,t[17]=f,t[18]=p):p=t[18],p}let c=typeof r==`boolean`?``:String(r),u;t[19]===a?u=t[20]:(u=h(`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)(Cn,{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)(l,{id:o,className:Qt(),value:c,required:n.required,onChange:e=>i(cn(n,e.target.value)),children:(n.options??[]).map(Sn)}):n.type===`textarea`?(0,$.jsx)(`textarea`,{id:o,className:h(Zt(),`min-h-24 resize-y`),value:c,required:n.required,placeholder:n.placeholder,onChange:e=>i(cn(n,e.target.value))}):n.type===`password`?(0,$.jsx)(ae,{id:o,className:a,value:c,onChange:e=>i(cn(n,e)),placeholder:n.placeholder,labels:Y}):(0,$.jsx)(`input`,{id:o,className:Zt(),type:n.type===`number`?`number`:`text`,autoComplete:n.secret?`new-password`:`off`,spellCheck:!1,value:c,required:n.required,placeholder:n.placeholder,min:n.min,max:n.max,step:n.step,onChange:e=>i(cn(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 Sn(e){return(0,$.jsx)(u,{value:e.id,children:e.name},e.id)}function Cn(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 wn(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 Tn(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 D(E(`/api/config`),{method:`PATCH`,body:JSON.stringify({tools:{web:{region:t,search:n,blocklist:{enabled:e.blocklistEnabled,domains:e.blocklistDomains}}}})}),R()}async function En(e){let t=await D(E(`/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 Dn(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 On(){return h(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,y,`dark:border-edge`)}function kn(){return h(v,_)}var An=[`brave`,`tavily`,`bing`,`searxng`];function jn(){return{type:`brave`,apiKey:``,url:``,disabled:!1}}var Mn=V();function Nn(){let e=S(w(e=>e.language)),t=e.webSearchSettings,n=e.logs,r=!!C(e=>e.token),[i,a]=(0,Q.useReducer)(Mn,{form:null,baseline:null}),o=i.form,s=i.baseline,c=(0,Q.useRef)(!1),d=(0,Q.useRef)(o);d.current=o;let f=(0,Q.useRef)(null),{data:p,error:m,isLoading:_,mutate:v}=z(r);B({enabled:r,parsed:(0,Q.useMemo)(()=>p?.payload?.config===void 0?null:wn(p.payload.config),[p]),dirty:c.current,trackedParsedRef:f,dispatch:a,onResetDirty:()=>{c.current=!1}});let y=!!(r&&_&&p===void 0&&!m),b=m instanceof Error?m.message:m?String(m):null,x=(0,Q.useMemo)(()=>!o||!s?!1:JSON.stringify(o)!==JSON.stringify(s),[o,s]),T=(0,Q.useCallback)(e=>{c.current=!0,a({type:`patch`,patch:e})},[]),E=vt({value:o,dirty:x,onSave:(0,Q.useCallback)(async e=>{try{await Tn(e),a({type:`saved`,value:e}),c.current=!!(d.current&&JSON.stringify(d.current)!==JSON.stringify(e))}catch(e){throw Error(e instanceof Error?e.message:t.saveError)}},[t.saveError])});return r?y?(0,$.jsx)(gt,{rows:3}):o?(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,onBlurCapture:E.onBlurCapture,children:[E.error?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:E.error}):null,(0,$.jsxs)(Mt,{children:[(0,$.jsx)(jt,{icon:_e,title:t.sectionRegion,subtitle:t.sectionRegionHint,trailing:(0,$.jsx)(_t,{status:E.status,error:E.error})}),(0,$.jsx)(`div`,{className:`flex max-w-md flex-col gap-4`,children:(0,$.jsx)(Dn,{label:t.regionLabel,description:t.regionDesc,children:(0,$.jsxs)(l,{className:kn(),value:o.regionMode,onChange:e=>T({regionMode:e.target.value}),children:[(0,$.jsx)(u,{value:`auto`,children:t.regionAuto}),(0,$.jsx)(u,{value:`cn`,children:t.regionCn}),(0,$.jsx)(u,{value:`global`,children:t.regionGlobal})]})})})]}),(0,$.jsx)(At,{children:(0,$.jsxs)(Mt,{children:[(0,$.jsx)(jt,{icon:oe,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)(Dn,{label:t.blocklistDomains,description:t.blocklistDomainsDesc,children:(0,$.jsx)(`textarea`,{className:h(On(),`min-h-[6rem] font-mono text-xs`),value:o.blocklistDomains.join(`
7
+ `),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)(Mt,{children:[(0,$.jsx)(jt,{icon:_e,title:t.sectionSearch,subtitle:t.sectionSearchHint}),(0,$.jsxs)(`div`,{className:`flex max-w-xl flex-col gap-6`,children:[(0,$.jsx)(Dn,{label:t.maxResultsLabel,description:t.maxResultsDesc,children:(0,$.jsx)(`input`,{type:`number`,min:1,max:50,className:On(),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)(Pn,{row:n,providerIndex:r,labels:t,secretLabels:ke(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)(g,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5 text-sm`,onClick:()=>T({providers:[...o.providers,jn()]}),children:[(0,$.jsx)(je,{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:b??t.loadError}),(0,$.jsx)(g,{type:`button`,variant:`secondary`,onClick:()=>void v(),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 Pn(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=()=>En(r).then(Fn),t[0]=r,t[1]=c);let d=c,f;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(f=h(kn(),`min-w-[8rem]`),t[2]=f):f=t[2];let p=n.type,m;t[3]!==o||t[4]!==n?(m=e=>o({...n,type:e.target.value,url:e.target.value===`searxng`?n.url:``}),t[3]=o,t[4]=n,t[5]=m):m=t[5];let _;t[6]===i.providerTypes?_=t[7]:(_=An.map(e=>(0,$.jsx)(u,{value:e,children:i.providerTypes[e]},e)),t[6]=i.providerTypes,t[7]=_);let v;t[8]!==n.type||t[9]!==m||t[10]!==_?(v=(0,$.jsx)(l,{className:f,value:p,onChange:m,children:_}),t[8]=n.type,t[9]=m,t[10]=_,t[11]=v):v=t[11];let y;t[12]!==o||t[13]!==n?(y=e=>o({...n,disabled:e.target.checked}),t[12]=o,t[13]=n,t[14]=y):y=t[14];let b;t[15]!==n.disabled||t[16]!==y?(b=(0,$.jsx)(`input`,{type:`checkbox`,className:`size-3.5 rounded border-edge`,checked:n.disabled,onChange:y}),t[15]=n.disabled,t[16]=y,t[17]=b):b=t[17];let x;t[18]!==i.disabled||t[19]!==b?(x=(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1.5 text-xs text-fg-muted`,children:[b,i.disabled]}),t[18]=i.disabled,t[19]=b,t[20]=x):x=t[20];let S;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,$.jsx)(Xe,{className:`size-4`}),t[21]=S):S=t[21];let C;t[22]===s?C=t[23]:(C=(0,$.jsx)(g,{type:`button`,variant:`ghost`,className:`h-8 px-2 text-fg-muted`,onClick:s,children:S}),t[22]=s,t[23]=C);let w;t[24]!==C||t[25]!==x?(w=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[x,C]}),t[24]=C,t[25]=x,t[26]=w):w=t[26];let T;t[27]!==w||t[28]!==v?(T=(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[v,w]}),t[27]=w,t[28]=v,t[29]=T):T=t[29];let E;t[30]!==i.urlDesc||t[31]!==i.urlLabel||t[32]!==o||t[33]!==n?(E=n.type===`searxng`?(0,$.jsx)(Dn,{label:i.urlLabel,description:i.urlDesc,children:(0,$.jsx)(`input`,{type:`url`,className:On(),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]=E):E=t[34];let D;t[35]!==o||t[36]!==n?(D=e=>o({...n,apiKey:e}),t[35]=o,t[36]=n,t[37]=D):D=t[37];let O;t[38]!==i.keyPlaceholder||t[39]!==i.keyPlaceholderMasked||t[40]!==i.saveError||t[41]!==d||t[42]!==n.apiKey||t[43]!==a||t[44]!==D?(O=(0,$.jsx)(ae,{value:n.apiKey,onChange:D,placeholder:i.keyPlaceholder,labels:a,reveal:d,loadFailedLabel:i.saveError,notInConfigFile:i.keyPlaceholderMasked}),t[38]=i.keyPlaceholder,t[39]=i.keyPlaceholderMasked,t[40]=i.saveError,t[41]=d,t[42]=n.apiKey,t[43]=a,t[44]=D,t[45]=O):O=t[45];let k;t[46]!==i.apiKeyDesc||t[47]!==i.apiKeyLabel||t[48]!==O?(k=(0,$.jsx)(Dn,{label:i.apiKeyLabel,description:i.apiKeyDesc,children:O}),t[46]=i.apiKeyDesc,t[47]=i.apiKeyLabel,t[48]=O,t[49]=k):k=t[49];let A;return t[50]!==T||t[51]!==E||t[52]!==k?(A=(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-xl bg-surface-panel/70 p-4 shadow-surface`,children:[T,E,k]}),t[50]=T,t[51]=E,t[52]=k,t[53]=A):A=t[53],A}function Fn(e){return e.apiKey??null}function In(){if(Se())return null;let e=window.open(`about:blank`,`xopc-oauth`);return e&&(e.opener=null),e}async function Ln(e,t){return Se()?(await window.electronAPI?.shell?.openExternalUrl(e))?.ok===!0:!t||t.closed?!1:(t.location.replace(e),!0)}function Rn(e){e&&!e.closed&&e.close()}var zn=[`common`,`domestic`,`specialty`,`enterprise`,`oauth`,`extension`];function Bn(e){let t=new Map;for(let e of zn)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 Vn(e){let t=(0,Z.c)(22),{open:n,onOpenChange:r,builtinRows:i,customConfig:a,labels:o,language:s,onSaved:c}=e,l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l={type:`pick`},t[0]=l):l=t[0];let[u,d]=(0,Q.useState)(l),[f,p]=(0,Q.useState)(``),m;t[1]===r?m=t[2]:(m=e=>{e||window.setTimeout(()=>{d({type:`pick`}),p(``)},200),r(e)},t[1]=r,t[2]=m);let g=m,_;t[3]!==g||t[4]!==c?(_=()=>{c(),g(!1)},t[3]=g,t[4]=c,t[5]=_):_=t[5];let v=_,y;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,$.jsx)(A,{className:h(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,k)}),t[6]=y):y=t[6];let b;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(b=h(`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`,O),t[7]=b):b=t[7];let x;t[8]!==i||t[9]!==a||t[10]!==v||t[11]!==o||t[12]!==s||t[13]!==f||t[14]!==u.presetKey||t[15]!==u.providerId||t[16]!==u.type?(x=(0,$.jsxs)(N,{children:[y,(0,$.jsx)(P,{className:b,children:u.type===`pick`?(0,$.jsx)(Un,{builtinRows:i,searchQuery:f,onSearchChange:p,labels:o,onPickBuiltin:e=>{let t=pt(e);d(t?{type:`custom`,presetKey:t}:{type:`builtin`,providerId:e})},onPickCustom:()=>d({type:`custom`})}):u.type===`builtin`?(0,$.jsx)(Wn,{providerId:u.providerId,builtinRows:i,labels:o,language:s,onBack:()=>d({type:`pick`}),onSaved:v}):(0,$.jsx)(qn,{initialPresetKey:u.presetKey,customConfig:a,labels:o,language:s,onBack:()=>d({type:`pick`}),onSaved:v})})]}),t[8]=i,t[9]=a,t[10]=v,t[11]=o,t[12]=s,t[13]=f,t[14]=u.presetKey,t[15]=u.providerId,t[16]=u.type,t[17]=x):x=t[17];let S;return t[18]!==g||t[19]!==n||t[20]!==x?(S=(0,$.jsx)(I,{open:n,onOpenChange:g,children:x}),t[18]=g,t[19]=n,t[20]=x,t[21]=S):S=t[21],S}function Hn(e){let t=(0,Z.c)(4),{label:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=h(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,b.press),t[0]=r):r=t[0];let i;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(Ne,{className:`size-4`,"aria-hidden":!0}),t[1]=i):i=t[1];let a;return t[2]===n?a=t[3]:(a=(0,$.jsx)(M,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:r,"aria-label":n,children:i})}),t[2]=n,t[3]=a),a}function Un(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 l=c,u;bb0:{if(!l){u=n;break bb0}let e;if(t[2]!==n||t[3]!==l){let r;t[5]===l?r=t[6]:(r=e=>{let t=H[e.id]?.aliases??[];return e.id.toLowerCase().includes(l)||e.name.toLowerCase().includes(l)||t.some(e=>e.toLowerCase().includes(l))},t[5]=l,t[6]=r),e=n.filter(r),t[2]=n,t[3]=l,t[4]=e}else e=t[4];u=e}let d=u,f;t[7]===d?f=t[8]:(f=Bn(d),t[7]=d,t[8]=f);let m=f,g;t[9]===a.step1Title?g=t[10]:(g=(0,$.jsx)(F,{className:`min-w-0 flex-1 text-base font-semibold text-fg`,children:a.step1Title}),t[9]=a.step1Title,t[10]=g);let _;t[11]===a.close?_=t[12]:(_=(0,$.jsx)(Hn,{label:a.close}),t[11]=a.close,t[12]=_);let v;t[13]!==g||t[14]!==_?(v=(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b border-edge-subtle px-5 py-4`,children:[g,_]}),t[13]=g,t[14]=_,t[15]=v):v=t[15];let x;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,$.jsx)(_e,{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]=x):x=t[16];let S;t[17]===i?S=t[18]:(S=e=>i(e.target.value),t[17]=i,t[18]=S);let C=a.searchPlaceholder,w;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(w=h(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-10 pr-3 text-sm text-fg placeholder:text-fg-subtle`,y),t[19]=w):w=t[19];let T;t[20]!==a.searchPlaceholder||t[21]!==r||t[22]!==S?(T=(0,$.jsx)(`div`,{className:`px-5 pt-3`,children:(0,$.jsxs)(`div`,{className:`relative`,children:[x,(0,$.jsx)(`input`,{type:`search`,value:r,onChange:S,placeholder:C,autoComplete:`off`,className:w})]})}),t[20]=a.searchPlaceholder,t[21]=r,t[22]=S,t[23]=T):T=t[23];let E;t[24]!==a.addCustom||t[25]!==a.customDescription||t[26]!==s||t[27]!==l?(E=l?null:(0,$.jsxs)(`button`,{type:`button`,onClick:s,className:h(`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`,b.press),children:[(0,$.jsx)(p,{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)(be,{className:`size-4 shrink-0 text-fg-subtle`,"aria-hidden":!0})]}),t[24]=a.addCustom,t[25]=a.customDescription,t[26]=s,t[27]=l,t[28]=E):E=t[28];let D;t[29]!==d.length||t[30]!==m||t[31]!==a.categories||t[32]!==a.noResults||t[33]!==o?(D=d.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:zn.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:h(`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`,b.press),children:[(0,$.jsx)(`span`,{className:`truncate text-sm text-fg`,children:e.name}),e.configured?(0,$.jsx)(De,{className:`size-3.5 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):null]},e.id))})]},e)})}),t[29]=d.length,t[30]=m,t[31]=a.categories,t[32]=a.noResults,t[33]=o,t[34]=D):D=t[34];let O;t[35]!==E||t[36]!==D?(O=(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto px-5 py-3`,children:[E,D]}),t[35]=E,t[36]=D,t[37]=O):O=t[37];let k;return t[38]!==T||t[39]!==O||t[40]!==v?(k=(0,$.jsxs)($.Fragment,{children:[v,T,O]}),t[38]=T,t[39]=O,t[40]=v,t[41]=k):k=t[41],k}function Wn({providerId:e,builtinRows:t,labels:n,language:r,onBack:i,onSaved:a}){let o=t.find(t=>t.id===e),s=H[e],[c,l]=(0,Q.useState)(``),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(null),[_,v]=(0,Q.useState)(!1),x=(0,Q.useRef)(null),C=S(r).providersSettings,w=ke(C),T=(0,Q.useMemo)(()=>He(e,r),[e,r]),E=o?.supportsApiKey!==!1,D=o?.supportsOAuth===!0,[O,k]=(0,Q.useState)(null),[A,j]=(0,Q.useState)(null),[M,N]=(0,Q.useState)(`idle`),[P,I]=(0,Q.useState)(null),[L,R]=(0,Q.useState)(null),[z,B]=(0,Q.useState)(null),[V,U]=(0,Q.useState)(``),W=(0,Q.useRef)(null),G=(0,Q.useRef)(null),K=M===`waiting`||M===`waiting_code`;(0,Q.useEffect)(()=>{if(!O||!K)return;let t=window.setInterval(()=>{(async()=>{try{let n=await Oe(O);n.status===`waiting_auth`||n.status===`waiting_code`?(N(n.status===`waiting_code`?`waiting_code`:`waiting`),j(n.message??null),I(n.authUrl??null),R(n.instructions??null),B(n.deviceCode??null),n.authUrl&&n.authUrl!==G.current&&(G.current=n.authUrl,Ln(n.authUrl,W.current).catch(()=>{}))):n.status===`completed`?(window.clearInterval(t),Rn(W.current),W.current=null,e===`xopc-cloud`&&await Te(),N(`success`),j(n.message??C.saved),window.setTimeout(a,600)):(n.status===`failed`||n.status===`cancelled`)&&(window.clearInterval(t),Rn(W.current),W.current=null,N(`error`),j(n.error??n.message??C.revokeFailed))}catch{}})()},1e3);return()=>window.clearInterval(t)},[O,K,a,e,C.revokeFailed,C.saved]),(0,Q.useEffect)(()=>()=>{O&&ut(O).catch(()=>{})},[O]),(0,Q.useEffect)(()=>()=>{Rn(W.current),W.current=null},[]);let ne=async()=>{Rn(W.current),W.current=In(),G.current=null,N(`waiting`),j(C.oauthStarting),I(null),R(null),B(null),p(null);try{k((await te(e)).sessionId)}catch(e){Rn(W.current),W.current=null,N(`error`),j(e instanceof Error?e.message:C.revokeFailed)}},q=async()=>{if(O){try{await ee(O)}catch{}Rn(W.current),W.current=null,G.current=null,N(`idle`),j(null),k(null),I(null),R(null),B(null)}},re=async()=>{if(!(!O||!V.trim()))try{await xe(O,V.trim()),U(``),j(C.oauthProcessingCode)}catch(e){N(`error`),j(e instanceof Error?e.message:C.revokeFailed)}},ie=async()=>{let t=c.trim();if(!(!t||!E)){d(!0),p(null);try{await ve({[e]:t}),v(!0),window.setTimeout(a,600)}catch(e){p(e instanceof Error?e.message:n.saveError)}finally{d(!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:h(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,b.press),"aria-label":n.back,children:(0,$.jsx)(be,{className:`size-4 rotate-180`,"aria-hidden":!0})}),(0,$.jsx)(F,{className:`min-w-0 flex-1 text-base font-semibold text-fg`,children:o?.name??e}),(0,$.jsx)(Hn,{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,E?(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)(ae,{id:`builtin-api-key`,value:c,onChange:l,placeholder:n.apiKeyPlaceholder,labels:w,inputRef:x,onKeyDown:e=>{e.key===`Enter`&&ie()}})]}):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:C.oauth}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:C.oauthHint})]}),(0,$.jsxs)(g,{type:`button`,variant:`primary`,className:`gap-1.5`,disabled:K,onClick:()=>void ne(),children:[K?(0,$.jsx)(m,{className:`size-3.5 animate-spin`,"aria-hidden":!0}):null,C.oauth]})]}),A?(0,$.jsx)(`p`,{className:h(`text-xs`,M===`error`?`text-red-600 dark:text-red-400`:`text-fg-muted`),children:A}):null,M===`waiting`||M===`waiting_code`?(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[P?(0,$.jsxs)(`a`,{href:P,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:[C.openAuthPage,(0,$.jsx)(`span`,{className:`size-3`,"aria-hidden":!0,children:`↗`})]}):null,(0,$.jsx)(g,{type:`button`,variant:`secondary`,onClick:()=>void q(),children:C.cancelOAuth})]}):null,L?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:L}):null,z?(0,$.jsxs)(`div`,{className:`rounded-lg border border-edge-subtle bg-surface-panel px-3 py-2`,children:[(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:C.deviceCodeLabel}),(0,$.jsx)(`code`,{className:`mt-1 block select-all font-mono text-lg font-semibold tracking-widest text-fg`,children:z}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:C.deviceCodeHint})]}):null,M===`waiting_code`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,$.jsx)(`input`,{type:`text`,value:V,onChange:e=>U(e.target.value),onKeyDown:e=>e.key===`Enter`&&void re(),placeholder:C.pasteRedirectUrl,className:h(`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`,y)}),(0,$.jsx)(g,{type:`button`,variant:`primary`,onClick:()=>void re(),children:C.submitCode})]}):null]}):null,T.length>0&&E?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:T.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:[ot(e,n),(0,$.jsx)(`span`,{className:`size-3`,"aria-hidden":!0,children:`↗`})]},e))}):null,f?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:f}):null,(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,$.jsx)(g,{type:`button`,variant:`secondary`,onClick:i,children:n.cancel}),E?(0,$.jsx)(g,{type:`button`,variant:`primary`,disabled:!c.trim()||u||_,onClick:()=>void ie(),children:_?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(De,{className:`size-3.5`,"aria-hidden":!0}),n.saved]}):u?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(m,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),n.saving]}):n.save}):null]})]})]})}function Gn(e=`custom`){if(e!==`custom`&&Ke[e]){let t=Ke[e].config;return{preset:e,providerId:dt(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 Kn(e,t){switch(t.type){case`applyPreset`:return t.key===`custom`?{...e,preset:`custom`,error:null}:Ke[t.key]?Gn(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 qn({initialPresetKey:e,customConfig:t,labels:n,language:r,onBack:i,onSaved:a}){let[o,s]=(0,Q.useReducer)(Kn,void 0,()=>Gn(e)),[c,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(!1),_=ke(S(r).providersSettings),{preset:v,providerId:x,baseUrl:C,api:w,apiKey:T,modelIds:E,error:D}=o,O=async()=>{let e=x.trim(),r=C.trim();if(!e){s({type:`setError`,value:n.providerIdRequired});return}if(!r){s({type:`setError`,value:n.baseUrlRequired});return}let i=E.map(e=>e.trim()).filter(Boolean);d(!0),s({type:`setError`,value:null});try{let n=t?.providers??{},o=v===`custom`?void 0:Ke[v]?.config,s={...o??{},baseUrl:r,api:w,apiKey:T.trim()||void 0,models:i.map(e=>o?.models?.find(t=>t.id===e)??{id:e})};await nt({providers:{...n,[e]:s}}),a()}catch(e){s({type:`setError`,value:e instanceof Error?e.message:n.saveError})}finally{d(!1)}},k=async()=>{let e=x.trim()||dt(v)||`custom`,t=C.trim();if(!t){s({type:`setError`,value:n.baseUrlRequired});return}p(!0),s({type:`setError`,value:null});try{let r=v===`custom`?void 0:Ke[v]?.config,i=(await st({providerId:e,baseUrl:t,apiKey:T.trim()||void 0,api:w,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)}},A=x.trim()&&C.trim(),j=(w===`openai-completions`||w===`openai-responses`)&&C.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:h(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,b.press),"aria-label":n.back,children:(0,$.jsx)(be,{className:`size-4 rotate-180`,"aria-hidden":!0})}),(0,$.jsx)(F,{className:`min-w-0 flex-1 text-base font-semibold text-fg`,children:n.step2CustomTitle}),(0,$.jsx)(Hn,{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)(l,{id:`custom-preset`,value:v,onChange:e=>s({type:`applyPreset`,key:e.target.value}),className:Ee(),children:[(0,$.jsx)(u,{value:`custom`,children:n.presetCustom}),Ge.map(e=>(0,$.jsx)(u,{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:x,onChange:e=>s({type:`setProviderId`,value:e.target.value}),placeholder:n.providerIdPlaceholder,className:h(`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,y)})]}),(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:C,onChange:e=>s({type:`setBaseUrl`,value:e.target.value}),placeholder:n.baseUrlPlaceholder,className:h(`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,y)})]}),(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)(l,{id:`custom-api-type`,value:w,onChange:e=>s({type:`setApi`,value:e.target.value}),className:Ee(),children:ze.map(e=>(0,$.jsx)(u,{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)(ae,{id:`custom-api-key`,value:T,onChange:e=>s({type:`setApiKey`,value:e}),placeholder:n.apiKeyPlaceholder,labels:_})]}),(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)(g,{type:`button`,variant:`secondary`,className:`gap-1.5`,disabled:!j||f,onClick:()=>void k(),children:[f?(0,$.jsx)(m,{className:`size-3.5 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(_e,{className:`size-3.5`,"aria-hidden":!0}),f?n.discoveringModels:n.discoverModels]})]}),E.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:h(`flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,y)}),E.length>1?(0,$.jsx)(`button`,{type:`button`,onClick:()=>s({type:`removeModelSlot`,index:t}),className:h(`rounded-lg p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,b.press),children:(0,$.jsx)(Ne,{className:`size-3.5`,"aria-hidden":!0})}):null]},e||`model-slot-${t}`)),(0,$.jsxs)(g,{type:`button`,variant:`ghost`,className:`w-fit gap-1.5 text-fg-muted`,onClick:()=>s({type:`addModelSlot`}),children:[(0,$.jsx)(je,{className:`size-3.5`,"aria-hidden":!0}),n.addModel]})]}),D?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:D}):null]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t border-edge-subtle px-5 py-3`,children:[(0,$.jsx)(g,{type:`button`,variant:`secondary`,onClick:i,children:n.cancel}),(0,$.jsx)(g,{type:`button`,variant:`primary`,disabled:!A||c,onClick:()=>void O(),children:c?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(m,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),n.saving]}):n.save})]})]})}function Jn(){let e=(0,Z.c)(31),t=C($n),n=!!t,{data:r,isLoading:i}=z(n),a;e[0]===n?a=e[1]:(a=n?E(`/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}=L(a,o,s),u;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(u={revalidateOnFocus:!1},e[5]=u):u=e[5];let{data:d,isLoading:f}=L(n?se:null,Qn,u),p;e[6]===d?p=e[7]:(p=d===void 0?[]:d,e[6]=d,e[7]=p);let m=p,h;e[8]===Symbol.for(`react.memo_cache_sentinel`)?(h={revalidateOnFocus:!1},e[8]=h):h=e[8];let{data:g}=L(n?ce:null,Zn,h),_;bb0:{if(!c||r===void 0){let t;e[9]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[9]=t):t=e[9],_=t;break bb0}let t;e[10]!==r?.payload?.config||e[11]!==c||e[12]!==m?(t=he(c,Ce(r?.payload?.config),m),e[10]=r?.payload?.config,e[11]=c,e[12]=m,e[13]=t):t=e[13],_=t}let v=_,y;bb1:{if(!g){y=null;break bb1}let t;e[14]===g.config?t=e[15]:(t=We(g.config),e[14]=g.config,e[15]=t),y=t}let b=y,x;if(e[16]!==v||e[17]!==b||e[18]!==c||e[19]!==m){x=[];let t=new Set((c??[]).filter(Xn).map(Yn)),n;e[21]===b?n=e[22]:(n=new Set(b?Object.keys(b.providers):[]),e[21]=b,e[22]=n);let r=n;for(let e of v){if(!t.has(e.id))continue;let n=r.has(e.id),i=n?b.providers[e.id]?.models?.length??0:m.filter(t=>t.provider===e.id).length;x.push({id:e.id,name:e.name,configured:!0,isCustom:n,modelCount:i})}if(b){let t;e[23]===b.providers?t=e[24]:(t=Object.entries(b.providers),e[23]=b.providers,e[24]=t);for(let[e,n]of t)x.some(t=>t.id===e)||x.push({id:e,name:e,configured:!0,isCustom:!0,modelCount:n.models?.length??0})}e[16]=v,e[17]=b,e[18]=c,e[19]=m,e[20]=x}else x=e[20];let S=x,w=i||l||f,T;return e[25]!==v||e[26]!==S||e[27]!==b||e[28]!==w||e[29]!==m?(T={cards:S,loading:w,builtinRows:v,customConfig:b,allModels:m},e[25]=v,e[26]=S,e[27]=b,e[28]=w,e[29]=m,e[30]=T):T=e[30],T}function Yn(e){return e.id}function Xn(e){return e.configured}function Zn(){return Be()}function Qn(){return Ae()}function $n(e){return e.token}function er(e){let t=(0,Z.c)(16),{labels:n,data:r,onAdd:i,onManage:a}=e,{cards:o,loading:s}=r;if(s){let e;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(ge,{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(nr)})]}),t[1]=n):n=t[1],n}let c;if(t[2]!==o||t[3]!==n||t[4]!==i||t[5]!==a){let e=o.filter(tr),r=e.length>0?n.titleCount.replace(`{{count}}`,String(e.length)):n.title,s;t[7]===r?s=t[8]:(s=(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:r}),t[7]=r,t[8]=s);let l;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(je,{className:`size-3.5`,strokeWidth:2,"aria-hidden":!0}),t[9]=l):l=t[9];let u;t[10]!==n.addProvider||t[11]!==i?(u=(0,$.jsxs)(g,{type:`button`,variant:`primary`,className:`gap-1.5`,onClick:i,children:[l,n.addProvider]}),t[10]=n.addProvider,t[11]=i,t[12]=u):u=t[12];let d;t[13]!==s||t[14]!==u?(d=(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[s,u]}),t[13]=s,t[14]=u,t[15]=d):d=t[15],c=(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)(g,{type:`button`,variant:`primary`,className:`mt-4 gap-1.5`,onClick:i,children:[(0,$.jsx)(je,{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)(rr,{card:e,labels:n,onManage:()=>a(e.id,e.isCustom)},e.id))})]}),t[2]=o,t[3]=n,t[4]=i,t[5]=a,t[6]=c}else c=t[6];return c}function tr(e){return e.configured}function nr(e){return(0,$.jsx)(ge,{className:`h-32 rounded-2xl`},e)}function rr(e){let t=(0,Z.c)(28),{card:n,labels:r,onManage:i}=e,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=h(`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`,b.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 l;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(De,{className:`size-4 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}),t[9]=l):l=t[9];let u;t[10]===c?u=t[11]:(u=(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[c,l]}),t[10]=c,t[11]=u);let d;t[12]!==n.modelCount||t[13]!==r.modelsCount||t[14]!==r.noModels?(d=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]=d):d=t[15];let f;t[16]===d?f=t[17]:(f=(0,$.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:d}),t[16]=d,t[17]=f);let p;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(G,{className:`size-3`,"aria-hidden":!0}),t[18]=p):p=t[18];let m;t[19]===r.manage?m=t[20]:(m=(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:[p,r.manage]}),t[19]=r.manage,t[20]=m);let g;t[21]!==m||t[22]!==f?(g=(0,$.jsxs)(`div`,{className:`mt-2.5 flex items-center justify-between`,children:[f,m]}),t[21]=m,t[22]=f,t[23]=g):g=t[23];let _;return t[24]!==i||t[25]!==g||t[26]!==u?(_=(0,$.jsxs)(`button`,{type:`button`,onClick:i,className:a,children:[u,g]}),t[24]=i,t[25]=g,t[26]=u,t[27]=_):_=t[27],_}function ir(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}:Ze(``),t[0]=n,t[1]=c);let[d,f]=(0,Q.useState)(c),[p,m]=(0,Q.useState)(ar),_;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(_=(e,t)=>{f(n=>({...n,[e]:t})),m(t=>{let n=new Map(t);return n.delete(e),n})},t[2]=_):_=t[2];let v=_,y;t[3]!==d.contextWindow||t[4]!==d.id||t[5]!==d.maxTokens||t[6]!==s.modelIdRequired||t[7]!==s.mustBePositive?(y=()=>{let e=new Map;return(d.id||``).trim()||e.set(`id`,s.modelIdRequired),d.contextWindow!==void 0&&d.contextWindow<=0&&e.set(`contextWindow`,s.mustBePositive),d.maxTokens!==void 0&&d.maxTokens<=0&&e.set(`maxTokens`,s.mustBePositive),m(e),e.size===0},t[3]=d.contextWindow,t[4]=d.id,t[5]=d.maxTokens,t[6]=s.modelIdRequired,t[7]=s.mustBePositive,t[8]=y):y=t[8];let b=y,S;t[9]!==d||t[10]!==o||t[11]!==a||t[12]!==b?(S=()=>{if(!b())return;let e=(d.id||``).trim();a({...d,id:e,name:d.name?.trim()||e,reasoning:d.reasoning||!1,input:d.input||[`text`],contextWindow:d.contextWindow??128e3,maxTokens:d.maxTokens??16384,cost:{input:d.cost?.input??0,output:d.cost?.output??0,cacheRead:d.cost?.cacheRead??0,cacheWrite:d.cost?.cacheWrite??0}}),o()},t[9]=d,t[10]=o,t[11]=a,t[12]=b,t[13]=S):S=t[13];let C=S,w=d,T;t[14]===w?T=t[15]:(T=Ie(w),t[14]=w,t[15]=T);let E=T,D=r?s.addModelTitle:s.editModelTitle,O;t[16]===D?O=t[17]:(O=(0,$.jsx)(F,{className:`text-base font-semibold text-fg`,children:D}),t[16]=D,t[17]=O);let k;t[18]!==s.modelProviderLabel||t[19]!==i?(k=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]=k):k=t[20];let A;t[21]!==O||t[22]!==k?(A=(0,$.jsxs)(`div`,{children:[O,k]}),t[21]=O,t[22]=k,t[23]=A):A=t[23];let j;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(j=h(x,`p-1.5 hover:bg-surface-base`),t[24]=j):j=t[24];let N;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(N=(0,$.jsx)(Ne,{className:`size-4`}),t[25]=N):N=t[25];let P;t[26]===s.close?P=t[27]:(P=(0,$.jsx)(M,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:j,"aria-label":s.close,children:N})}),t[26]=s.close,t[27]=P);let I;t[28]!==A||t[29]!==P?(I=(0,$.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[A,P]}),t[28]=A,t[29]=P,t[30]=I):I=t[30];let L;t[31]===Symbol.for(`react.memo_cache_sentinel`)?(L=(0,$.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`}),t[31]=L):L=t[31];let R;t[32]===s.modelId?R=t[33]:(R=(0,$.jsxs)(`label`,{className:`mb-1 block text-xs font-medium text-fg`,children:[s.modelId,L]}),t[32]=s.modelId,t[33]=R);let z;t[34]===p?z=t[35]:(z=h(Pe(),p.has(`id`)&&`border-red-500`),t[34]=p,t[35]=z);let B=d.id||``,V;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(V=e=>v(`id`,e.target.value),t[36]=V):V=t[36];let H=!r,U;t[37]!==z||t[38]!==B||t[39]!==H?(U=(0,$.jsx)(`input`,{className:z,value:B,onChange:V,placeholder:`e.g. llama3.1:8b`,disabled:H}),t[37]=z,t[38]=B,t[39]=H,t[40]=U):U=t[40];let W;t[41]===p?W=t[42]:(W=p.has(`id`)?(0,$.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:p.get(`id`)}):null,t[41]=p,t[42]=W);let G;t[43]!==R||t[44]!==U||t[45]!==W?(G=(0,$.jsxs)(`div`,{children:[R,U,W]}),t[43]=R,t[44]=U,t[45]=W,t[46]=G):G=t[46];let K;t[47]===s.displayName?K=t[48]:(K=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.displayName}),t[47]=s.displayName,t[48]=K);let ee;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(ee=Pe(),t[49]=ee):ee=t[49];let te=d.name||``,ne;t[50]===Symbol.for(`react.memo_cache_sentinel`)?(ne=e=>v(`name`,e.target.value),t[50]=ne):ne=t[50];let q;t[51]===te?q=t[52]:(q=(0,$.jsx)(`input`,{className:ee,value:te,onChange:ne}),t[51]=te,t[52]=q);let re;t[53]!==K||t[54]!==q?(re=(0,$.jsxs)(`div`,{children:[K,q]}),t[53]=K,t[54]=q,t[55]=re):re=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 ae;t[58]===Symbol.for(`react.memo_cache_sentinel`)?(ae=Ee(),t[58]=ae):ae=t[58];let J;t[59]===Symbol.for(`react.memo_cache_sentinel`)?(J=e=>v(`input`,ct(e.target.value)),t[59]=J):J=t[59];let oe;t[60]===s?oe=t[61]:(oe=Qe.map(e=>(0,$.jsx)(u,{value:e.value,children:s[e.labelKey]},e.value)),t[60]=s,t[61]=oe);let Y;t[62]!==E||t[63]!==oe?(Y=(0,$.jsx)(l,{className:ae,value:E,onChange:J,children:oe}),t[62]=E,t[63]=oe,t[64]=Y):Y=t[64];let se;t[65]!==ie||t[66]!==Y?(se=(0,$.jsxs)(`div`,{children:[ie,Y]}),t[65]=ie,t[66]=Y,t[67]=se):se=t[67];let ce=d.reasoning||!1,le;t[68]===Symbol.for(`react.memo_cache_sentinel`)?(le=e=>v(`reasoning`,e.target.checked),t[68]=le):le=t[68];let ue;t[69]===ce?ue=t[70]:(ue=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:ce,onChange:le}),t[69]=ce,t[70]=ue);let de;t[71]!==s.reasoning||t[72]!==ue?(de=(0,$.jsxs)(`label`,{className:`mt-6 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[ue,s.reasoning]}),t[71]=s.reasoning,t[72]=ue,t[73]=de):de=t[73];let fe;t[74]!==se||t[75]!==de?(fe=(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[se,de]}),t[74]=se,t[75]=de,t[76]=fe):fe=t[76];let X;t[77]===s.contextWindow?X=t[78]:(X=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.contextWindow}),t[77]=s.contextWindow,t[78]=X);let pe;t[79]===p?pe=t[80]:(pe=h(Pe(),p.has(`contextWindow`)&&`border-red-500`),t[79]=p,t[80]=pe);let me=d.contextWindow??128e3,he;t[81]===Symbol.for(`react.memo_cache_sentinel`)?(he=e=>v(`contextWindow`,parseInt(e.target.value,10)||0),t[81]=he):he=t[81];let ge;t[82]!==pe||t[83]!==me?(ge=(0,$.jsx)(`input`,{type:`number`,min:1,className:pe,value:me,onChange:he}),t[82]=pe,t[83]=me,t[84]=ge):ge=t[84];let _e;t[85]===p?_e=t[86]:(_e=p.has(`contextWindow`)?(0,$.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:p.get(`contextWindow`)}):null,t[85]=p,t[86]=_e);let ve;t[87]!==X||t[88]!==ge||t[89]!==_e?(ve=(0,$.jsxs)(`div`,{children:[X,ge,_e]}),t[87]=X,t[88]=ge,t[89]=_e,t[90]=ve):ve=t[90];let ye;t[91]===s.maxOutputTokens?ye=t[92]:(ye=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.maxOutputTokens}),t[91]=s.maxOutputTokens,t[92]=ye);let be;t[93]===p?be=t[94]:(be=h(Pe(),p.has(`maxTokens`)&&`border-red-500`),t[93]=p,t[94]=be);let xe=d.maxTokens??16384,Se;t[95]===Symbol.for(`react.memo_cache_sentinel`)?(Se=e=>v(`maxTokens`,parseInt(e.target.value,10)||0),t[95]=Se):Se=t[95];let Ce;t[96]!==be||t[97]!==xe?(Ce=(0,$.jsx)(`input`,{type:`number`,min:1,className:be,value:xe,onChange:Se}),t[96]=be,t[97]=xe,t[98]=Ce):Ce=t[98];let we;t[99]===p?we=t[100]:(we=p.has(`maxTokens`)?(0,$.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:p.get(`maxTokens`)}):null,t[99]=p,t[100]=we);let Te;t[101]!==ye||t[102]!==Ce||t[103]!==we?(Te=(0,$.jsxs)(`div`,{children:[ye,Ce,we]}),t[101]=ye,t[102]=Ce,t[103]=we,t[104]=Te):Te=t[104];let De;t[105]!==ve||t[106]!==Te?(De=(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[ve,Te]}),t[105]=ve,t[106]=Te,t[107]=De):De=t[107];let Oe;t[108]===s.costSection?Oe=t[109]:(Oe=(0,$.jsx)(`p`,{className:`mb-2 text-xs font-semibold text-fg`,children:s.costSection}),t[108]=s.costSection,t[109]=Oe);let ke;t[110]===s.costInput?ke=t[111]:(ke=(0,$.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:s.costInput}),t[110]=s.costInput,t[111]=ke);let Ae;t[112]===Symbol.for(`react.memo_cache_sentinel`)?(Ae=Pe(),t[112]=Ae):Ae=t[112];let je=d.cost?.input??0,Me;t[113]===d.cost?Me=t[114]:(Me=e=>v(`cost`,{...d.cost,input:parseFloat(e.target.value)||0,output:d.cost?.output??0,cacheRead:d.cost?.cacheRead??0,cacheWrite:d.cost?.cacheWrite??0}),t[113]=d.cost,t[114]=Me);let Fe;t[115]!==je||t[116]!==Me?(Fe=(0,$.jsx)(`input`,{type:`number`,step:`any`,min:0,className:Ae,value:je,onChange:Me}),t[115]=je,t[116]=Me,t[117]=Fe):Fe=t[117];let Le;t[118]!==ke||t[119]!==Fe?(Le=(0,$.jsxs)(`div`,{children:[ke,Fe]}),t[118]=ke,t[119]=Fe,t[120]=Le):Le=t[120];let Re;t[121]===s.costOutput?Re=t[122]:(Re=(0,$.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:s.costOutput}),t[121]=s.costOutput,t[122]=Re);let ze;t[123]===Symbol.for(`react.memo_cache_sentinel`)?(ze=Pe(),t[123]=ze):ze=t[123];let Be=d.cost?.output??0,Ve;t[124]===d.cost?Ve=t[125]:(Ve=e=>v(`cost`,{...d.cost,input:d.cost?.input??0,output:parseFloat(e.target.value)||0,cacheRead:d.cost?.cacheRead??0,cacheWrite:d.cost?.cacheWrite??0}),t[124]=d.cost,t[125]=Ve);let He;t[126]!==Be||t[127]!==Ve?(He=(0,$.jsx)(`input`,{type:`number`,step:`any`,min:0,className:ze,value:Be,onChange:Ve}),t[126]=Be,t[127]=Ve,t[128]=He):He=t[128];let Ue;t[129]!==Re||t[130]!==He?(Ue=(0,$.jsxs)(`div`,{children:[Re,He]}),t[129]=Re,t[130]=He,t[131]=Ue):Ue=t[131];let We;t[132]!==Le||t[133]!==Ue?(We=(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[Le,Ue]}),t[132]=Le,t[133]=Ue,t[134]=We):We=t[134];let Ge;t[135]!==Oe||t[136]!==We?(Ge=(0,$.jsxs)(`div`,{className:`border-t border-edge-subtle pt-2 dark:border-edge`,children:[Oe,We]}),t[135]=Oe,t[136]=We,t[137]=Ge):Ge=t[137];let Ke;t[138]!==G||t[139]!==re||t[140]!==fe||t[141]!==De||t[142]!==Ge?(Ke=(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[G,re,fe,De,Ge]}),t[138]=G,t[139]=re,t[140]=fe,t[141]=De,t[142]=Ge,t[143]=Ke):Ke=t[143];let qe;t[144]===s.cancel?qe=t[145]:(qe=(0,$.jsx)(M,{asChild:!0,children:(0,$.jsx)(g,{type:`button`,variant:`secondary`,children:s.cancel})}),t[144]=s.cancel,t[145]=qe);let Je=r?s.addModelConfirm:s.saveModelConfirm,Ye;t[146]!==C||t[147]!==Je?(Ye=(0,$.jsx)(g,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:C,children:Je}),t[146]=C,t[147]=Je,t[148]=Ye):Ye=t[148];let Xe;t[149]!==qe||t[150]!==Ye?(Xe=(0,$.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2 border-t border-edge-subtle pt-3 dark:border-edge`,children:[qe,Ye]}),t[149]=qe,t[150]=Ye,t[151]=Xe):Xe=t[151];let $e;return t[152]!==I||t[153]!==Ke||t[154]!==Xe?($e=(0,$.jsxs)($.Fragment,{children:[I,Ke,Xe]}),t[152]=I,t[153]=Ke,t[154]=Xe,t[155]=$e):$e=t[155],$e}function ar(){return new Map}function or(e){let t=(0,Z.c)(16),{open:n,onOpenChange:r,providerId:i,model:a,isNew:o,onSave:s,m:c}=e,l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(A,{className:h(`xopc-dialog-overlay fixed inset-0 bg-scrim`,k)}),t[0]=l):l=t[0];let u;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(u=h(`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`,O,`overflow-y-auto rounded-xl border border-edge bg-surface-panel p-4 shadow-popover dark:border-edge`),t[1]=u):u=t[1];let d;t[2]!==o||t[3]!==c||t[4]!==a||t[5]!==r||t[6]!==s||t[7]!==n||t[8]!==i?(d=n?(0,$.jsx)(ir,{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]=d):d=t[9];let f;t[10]===d?f=t[11]:(f=(0,$.jsxs)(N,{children:[l,(0,$.jsx)(P,{className:u,onOpenAutoFocus:sr,children:d})]}),t[10]=d,t[11]=f);let p;return t[12]!==r||t[13]!==n||t[14]!==f?(p=(0,$.jsx)(I,{open:n,onOpenChange:r,children:f}),t[12]=r,t[13]=n,t[14]=f,t[15]=p):p=t[15],p}function sr(e){return e.preventDefault()}function cr(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=()=>re(n).then(lr),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)(ae,{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 lr(e){return e.apiKey??null}function ur(e){let t=(0,Z.c)(16),{open:n,onOpenChange:r,providerId:i,isCustom:a,builtinRows:o,customConfig:s,allModels:c,labels:l,language:u,onSaved:d}=e,f;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,$.jsx)(A,{className:h(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,k)}),t[0]=f):f=t[0];let p;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(p=h(`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`,O),t[1]=p):p=t[1];let m;t[2]!==c||t[3]!==o||t[4]!==s||t[5]!==a||t[6]!==l||t[7]!==u||t[8]!==r||t[9]!==d||t[10]!==i?(m=(0,$.jsxs)(N,{children:[f,(0,$.jsx)(P,{className:p,children:a?(0,$.jsx)(fr,{providerId:i,customConfig:s,labels:l,language:u,onClose:()=>r(!1),onSaved:d}):(0,$.jsx)(dr,{providerId:i,builtinRows:o,allModels:c,labels:l,language:u,onClose:()=>r(!1),onSaved:d})})]}),t[2]=c,t[3]=o,t[4]=s,t[5]=a,t[6]=l,t[7]=u,t[8]=r,t[9]=d,t[10]=i,t[11]=m):m=t[11];let g;return t[12]!==r||t[13]!==n||t[14]!==m?(g=(0,$.jsx)(I,{open:n,onOpenChange:r,children:m}),t[12]=r,t[13]=n,t[14]=m,t[15]=g):g=t[15],g}function dr({providerId:e,builtinRows:t,allModels:n,labels:r,language:i,onClose:a,onSaved:o}){let s=t.find(t=>t.id===e),l=H[e],u=n.filter(t=>t.provider===e),[d,p]=(0,Q.useState)(s?.apiKey??``),[_,v]=(0,Q.useState)(!1),[x,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(null),[E,D]=(0,Q.useState)(!1),O=S(i).providersSettings,k=s?.supportsApiKey!==!1,A=s?.supportsOAuth===!0,j=s?.authMode===`oauth`&&s.authStatus===`connected`,N=s?.configured===!0&&s.activeKeySource!==`env`&&s.activeKeySource!==`extension`&&s.activeKeySource!==`models_json`,[P,I]=(0,Q.useState)(null),[L,R]=(0,Q.useState)(null),[z,B]=(0,Q.useState)(`idle`),[V,U]=(0,Q.useState)(null),[W,G]=(0,Q.useState)(null),[q,re]=(0,Q.useState)(null),[ie,ae]=(0,Q.useState)(``),J=(0,Q.useRef)(null),oe=(0,Q.useRef)(null),Y=z===`waiting`||z===`waiting_code`,se=(0,Q.useMemo)(()=>He(e,i),[e,i]),ce=d!==(s?.apiKey??``),le=async()=>{let t=d.trim();if(!(!t||!k||Je(t))){v(!0),T(null);try{await ve({[e]:t}),C(!0),window.setTimeout(()=>{o(),a()},600)}catch(e){T(e instanceof Error?e.message:r.saveError)}finally{v(!1)}}};(0,Q.useEffect)(()=>{if(!P||!Y)return;let e=window.setInterval(()=>{(async()=>{try{let t=await Oe(P);t.status===`waiting_auth`||t.status===`waiting_code`?(B(t.status===`waiting_code`?`waiting_code`:`waiting`),R(t.message??null),U(t.authUrl??null),G(t.instructions??null),re(t.deviceCode??null),t.authUrl&&t.authUrl!==oe.current&&(oe.current=t.authUrl,Ln(t.authUrl,J.current).catch(()=>{}))):t.status===`completed`?(window.clearInterval(e),Rn(J.current),J.current=null,B(`success`),R(t.message??O.saved),window.setTimeout(()=>{o(),a()},600)):(t.status===`failed`||t.status===`cancelled`)&&(window.clearInterval(e),Rn(J.current),J.current=null,B(`error`),R(t.error??t.message??O.revokeFailed))}catch{}})()},1e3);return()=>window.clearInterval(e)},[P,Y,a,o,O.revokeFailed,O.saved]),(0,Q.useEffect)(()=>()=>{P&&ut(P).catch(()=>{})},[P]),(0,Q.useEffect)(()=>()=>{Rn(J.current),J.current=null},[]);let ue=async()=>{try{await Ye(e),o(),a()}catch{}},de=async()=>{Rn(J.current),J.current=In(),oe.current=null,B(`waiting`),R(O.oauthStarting),U(null),G(null),re(null),T(null);try{I((await te(e)).sessionId)}catch(e){Rn(J.current),J.current=null,B(`error`),R(e instanceof Error?e.message:O.revokeFailed)}},fe=async()=>{if(P){try{await ee(P)}catch{}Rn(J.current),J.current=null,oe.current=null,B(`idle`),R(null),I(null),U(null),G(null),re(null)}},X=async()=>{if(!(!P||!ie.trim()))try{await xe(P,ie.trim()),ae(``),R(O.oauthProcessingCode)}catch(e){B(`error`),R(e instanceof Error?e.message:O.revokeFailed)}},pe=async()=>{try{await ne(e),o(),a()}catch(e){T(e instanceof Error?e.message:O.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)(F,{className:`text-base font-semibold text-fg`,children:s?.name??e}),(0,$.jsx)(M,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:h(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,b.press),children:(0,$.jsx)(Ne,{className:`size-4`,"aria-hidden":!0})})})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 overflow-y-auto px-5 py-4`,children:[l?.description?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:l.description}):null,s?.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:s.baseUrl})]}):s?.category===`extension`?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:r.apiUrlExtensionHint}):null,k?(0,$.jsx)(cr,{providerId:e,inputId:`manage-api-key`,value:d,onChange:e=>{p(e),C(!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}}):s?.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}),s?.extensionId?(0,$.jsxs)(c,{to:`/settings/ext/${encodeURIComponent(s.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)(f,{className:`size-3`,"aria-hidden":!0})]}):null]}):null,A?(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:O.oauth}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:j?O.sourceOauth:O.oauthHint})]}),j?(0,$.jsx)(g,{type:`button`,variant:`secondary`,className:`gap-1.5 text-red-600 dark:text-red-400`,onClick:()=>void pe(),children:O.revoke}):(0,$.jsxs)(g,{type:`button`,variant:`primary`,className:`gap-1.5`,disabled:Y,onClick:()=>void de(),children:[Y?(0,$.jsx)(m,{className:`size-3.5 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(tt,{className:`size-3.5`,"aria-hidden":!0}),O.oauth]})]}),L?(0,$.jsx)(`p`,{className:h(`text-xs`,z===`error`?`text-red-600 dark:text-red-400`:`text-fg-muted`),children:L}):null,z===`waiting`||z===`waiting_code`?(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[V?(0,$.jsxs)(`a`,{href:V,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)(f,{className:`size-4`,"aria-hidden":!0}),O.openAuthPage]}):null,(0,$.jsx)(g,{type:`button`,variant:`secondary`,onClick:()=>void fe(),children:O.cancelOAuth})]}):null,W?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:W}):null,q?(0,$.jsxs)(`div`,{className:`rounded-lg border border-edge-subtle bg-surface-panel px-3 py-2`,children:[(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:O.deviceCodeLabel}),(0,$.jsx)(`code`,{className:`mt-1 block select-all font-mono text-lg font-semibold tracking-widest text-fg`,children:q}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:O.deviceCodeHint})]}):null,z===`waiting_code`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,$.jsx)(`input`,{type:`text`,value:ie,onChange:e=>ae(e.target.value),onKeyDown:e=>e.key===`Enter`&&void X(),placeholder:O.pasteRedirectUrl,className:h(`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`,y)}),(0,$.jsx)(g,{type:`button`,variant:`primary`,onClick:()=>void X(),children:O.submitCode})]}):null]}):null,se.length>0&&k?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:se.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:[ot(e,r),(0,$.jsx)(f,{className:`size-3`,"aria-hidden":!0})]},e))}):null,u.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,` (`,u.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:u.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}),w?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:w}):null]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-t border-edge-subtle px-5 py-3`,children:[N?(0,$.jsxs)(g,{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:()=>D(!0),children:[(0,$.jsx)(Xe,{className:`size-3.5`,"aria-hidden":!0}),r.remove]}):(0,$.jsx)(`span`,{}),(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:k&&ce&&!Je(d.trim())?(0,$.jsx)(g,{type:`button`,variant:`primary`,disabled:!d.trim()||_||x,onClick:()=>void le(),children:x?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(De,{className:`size-3.5`,"aria-hidden":!0}),r.saved]}):_?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(m,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),r.saving]}):r.save}):null})]}),(0,$.jsx)(K,{open:E,title:r.removeConfirmTitle,description:r.removeConfirmDescription.replace(`{{provider}}`,s?.name??e),confirmLabel:r.removeConfirmAction,cancelLabel:r.cancel,destructive:!0,onConfirm:()=>void ue(),onCancel:()=>D(!1)})]})}function fr({providerId:e,customConfig:t,labels:n,language:r,onClose:i,onSaved:a}){let o=S(r).modelsSettings,s=t?.providers[e],[c,l]=(0,Q.useState)(s?.baseUrl??``),[u,d]=(0,Q.useState)(s?.apiKey??``),[f,p]=(0,Q.useState)(s?.models??[]),[_,v]=(0,Q.useState)(s?.modelDiscovery?.enabled===!0),[x,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(null),[E,D]=(0,Q.useState)(!1),[O,k]=(0,Q.useState)(null),[A,j]=(0,Q.useState)(!1),[N,P]=(0,Q.useState)(null),I=n=>{if(!t)return null;let r=u.trim(),i={...s,baseUrl:c.trim()||void 0,apiKey:Je(r)?s?.apiKey:r||void 0,...n};return{providers:{...t.providers,[e]:i}}},L=async()=>{let e=I({models:f,modelDiscovery:{enabled:_}});if(e){C(!0),T(null);try{await nt(e),a(),i()}catch(e){T(e instanceof Error?e.message:n.saveError)}finally{C(!1)}}},R=async()=>{if(t)try{let{[e]:n,...r}=t.providers;await nt({providers:r}),a(),i()}catch{}},z=(e,t)=>{P({model:e,isNew:t}),j(!0)},B=async e=>{if(!N)return;let t=N.isNew?[...f,e]:f.map(t=>t.id===e.id?e:t);p(t);let r=I({models:t});if(r)try{await nt(r),a()}catch(e){T(e instanceof Error?e.message:n.saveError)}},V=async e=>{let t=f.filter(t=>t.id!==e);p(t),k(null);let r=I({models:t});if(r)try{await nt(r),a()}catch(e){T(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)(F,{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)(M,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:h(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,b.press),children:(0,$.jsx)(Ne,{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=>l(e.target.value),className:h(`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,y)})]}),(0,$.jsx)(cr,{providerId:e,inputId:`manage-custom-api-key`,value:u,onChange:d,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:_,onChange:e=>v(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,f.length>0?` (${f.length})`:``]}),(0,$.jsxs)(g,{type:`button`,variant:`primary`,className:`gap-1.5 px-2 py-1 text-xs`,onClick:()=>z(null,!0),children:[(0,$.jsx)(je,{className:`size-3.5`,"aria-hidden":!0}),o.addModel]})]}),f.length===0?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:o.modelsEmpty}):(0,$.jsx)(`ul`,{className:`space-y-2`,children:f.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:h(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,b.press),onClick:()=>z(e,!1),"aria-label":o.editModel,children:(0,$.jsx)(Me,{className:`size-3.5`,"aria-hidden":!0})}),(0,$.jsx)(`button`,{type:`button`,className:h(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-red-600 dark:hover:text-red-400`,b.press),onClick:()=>k(e.id),"aria-label":o.removeModel,children:(0,$.jsx)(Xe,{className:`size-3.5`,"aria-hidden":!0})})]})]},e.id))})]}),w?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:w}):null]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-t border-edge-subtle px-5 py-3`,children:[(0,$.jsxs)(g,{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:()=>D(!0),children:[(0,$.jsx)(Xe,{className:`size-3.5`,"aria-hidden":!0}),n.remove]}),(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsx)(g,{type:`button`,variant:`primary`,disabled:x,onClick:()=>void L(),children:x?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(m,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),n.saving]}):n.save})})]}),(0,$.jsx)(K,{open:E,title:n.removeConfirmTitle,description:n.removeConfirmDescription.replace(`{{provider}}`,e),confirmLabel:n.removeConfirmAction,cancelLabel:n.cancel,destructive:!0,onConfirm:()=>void R(),onCancel:()=>D(!1)}),(0,$.jsx)(K,{open:O!==null,title:o.removeModel,description:o.removeModelConfirm.replace(`{{id}}`,O??``),confirmLabel:n.removeConfirmAction,cancelLabel:n.cancel,destructive:!0,onConfirm:()=>{O&&V(O)},onCancel:()=>k(null)}),(0,$.jsx)(or,{open:A,onOpenChange:e=>{j(e),e||P(null)},providerId:e,model:N?.model??null,isNew:N?.isNew??!1,onSave:e=>void B(e),m:o})]})}async function pr(){let e=await T(E(`/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=w(e=>e.language)===`zh`,{data:t,error:n,isLoading:r}=L(pe,pr,{revalidateOnFocus:!1}),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(null);if(r)return(0,$.jsx)(ge,{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)),f=o??(n instanceof Error?n.message:t?.sync.lastError??Object.values(t?.sync.sourceErrors??{})[0]),p=async()=>{a(!0),s(null);try{let e=await T(E(`/api/models/catalog/refresh`),{method:`POST`});if(!e.ok)throw Error(`HTTP ${e.status}`);await Te()}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:[f||u.length>0?(0,$.jsx)(Re,{className:`size-4 text-amber-500`,"aria-hidden":!0}):(0,$.jsx)(De,{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,f?(0,$.jsx)(`p`,{className:`mt-2 text-sm text-danger`,children:f}):null]}),(0,$.jsxs)(g,{type:`button`,variant:`secondary`,disabled:i,onClick:()=>void p(),children:[i?(0,$.jsx)(m,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(X,{className:`size-4`,"aria-hidden":!0}),i?e?`刷新中…`:`Refreshing…`:e?`立即刷新`:`Refresh now`]})]})})}async function hr(){return(await D(E(`/api/models/xopc-cloud/account-summary`))).payload}function gr(e){let t=(0,Z.c)(93),{labels:n}=e,r=w(_r)===`zh`?`zh-CN`:`en-US`,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i={refreshInterval:6e4,revalidateOnFocus:!0},t[0]=i):i=t[0];let{data:a,error:o,isLoading:s,isValidating:c,mutate:l}=L(`/api/models/xopc-cloud/account-summary`,hr,i);if(s){let e;return t[1]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(ge,{className:`h-48 w-full rounded-2xl`}),t[1]=e):e=t[1],e}if(o||!a){let e;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Re,{className:`mt-0.5 size-4 shrink-0 text-amber-500`,"aria-hidden":!0}),t[2]=e):e=t[2];let r;t[3]===n.title?r=t[4]:(r=(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:n.title}),t[3]=n.title,t[4]=r);let i;t[5]===n.unavailable?i=t[6]:(i=(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.unavailable}),t[5]=n.unavailable,t[6]=i);let a;t[7]!==r||t[8]!==i?(a=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[e,(0,$.jsxs)(`div`,{children:[r,i]})]}),t[7]=r,t[8]=i,t[9]=a):a=t[9];let o;t[10]===l?o=t[11]:(o=()=>void l(),t[10]=l,t[11]=o);let s=c?`size-4 animate-spin`:`size-4`,u;t[12]===s?u=t[13]:(u=(0,$.jsx)(X,{className:s,"aria-hidden":!0}),t[12]=s,t[13]=u);let d;t[14]!==c||t[15]!==n.retry||t[16]!==o||t[17]!==u?(d=(0,$.jsxs)(g,{type:`button`,variant:`secondary`,disabled:c,onClick:o,children:[u,n.retry]}),t[14]=c,t[15]=n.retry,t[16]=o,t[17]=u,t[18]=d):d=t[18];let f;return t[19]!==a||t[20]!==d?(f=(0,$.jsx)(`section`,{className:`rounded-2xl border border-edge-subtle bg-surface-panel/40 p-4`,children:(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[a,d]})}),t[19]=a,t[20]=d,t[21]=f):f=t[21],f}let u,d,p,m,h,_,v,y;if(t[22]!==a.balance.credits||t[23]!==a.usage.chargedCredits||t[24]!==a.usage.requests||t[25]!==a.usage.totalTokens||t[26]!==n.availableCredits||t[27]!==n.connected||t[28]!==n.title||t[29]!==n.usageSummary||t[30]!==r){let e=new Intl.NumberFormat(r);y=n.usageSummary.replace(`{{tokens}}`,e.format(a.usage.totalTokens)).replace(`{{credits}}`,e.format(a.usage.chargedCredits)).replace(`{{requests}}`,e.format(a.usage.requests)),v=`rounded-2xl border border-edge-subtle bg-surface-panel/40 p-5`,_=`flex flex-col gap-5 sm:flex-row sm:items-start sm:justify-between`,p=`min-w-0 flex-1`;let i;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(Ue,{className:`size-4 text-accent-fg`,"aria-hidden":!0}),t[39]=i):i=t[39];let o;t[40]===n.title?o=t[41]:(o=(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:n.title}),t[40]=n.title,t[41]=o);let s;t[42]===n.connected?s=t[43]:(s=(0,$.jsx)(`span`,{className:`rounded-full bg-emerald-500/10 px-2 py-0.5 text-xs font-medium text-emerald-700 dark:text-emerald-300`,children:n.connected}),t[42]=n.connected,t[43]=s),t[44]!==o||t[45]!==s?(m=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[i,o,s]}),t[44]=o,t[45]=s,t[46]=m):m=t[46],t[47]===n.availableCredits?h=t[48]:(h=(0,$.jsx)(`p`,{className:`mt-5 text-xs font-medium text-fg-subtle`,children:n.availableCredits}),t[47]=n.availableCredits,t[48]=h),u=`mt-1 text-3xl font-semibold tracking-tight text-fg`,d=e.format(a.balance.credits),t[22]=a.balance.credits,t[23]=a.usage.chargedCredits,t[24]=a.usage.requests,t[25]=a.usage.totalTokens,t[26]=n.availableCredits,t[27]=n.connected,t[28]=n.title,t[29]=n.usageSummary,t[30]=r,t[31]=u,t[32]=d,t[33]=p,t[34]=m,t[35]=h,t[36]=_,t[37]=v,t[38]=y}else u=t[31],d=t[32],p=t[33],m=t[34],h=t[35],_=t[36],v=t[37],y=t[38];let b;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,$.jsx)(`span`,{className:`ml-2 text-sm font-medium text-fg-muted`,children:`credits`}),t[49]=b):b=t[49];let x;t[50]!==u||t[51]!==d?(x=(0,$.jsxs)(`p`,{className:u,children:[d,b]}),t[50]=u,t[51]=d,t[52]=x):x=t[52];let S;t[53]!==a.balance.credits||t[54]!==n.zeroBalance?(S=a.balance.credits===0?(0,$.jsx)(`p`,{className:`mt-2 text-sm font-medium text-danger`,children:n.zeroBalance}):null,t[53]=a.balance.credits,t[54]=n.zeroBalance,t[55]=S):S=t[55];let C;t[56]===n.recentUsage?C=t[57]:(C=(0,$.jsx)(`p`,{className:`mt-5 text-xs font-medium text-fg-subtle`,children:n.recentUsage}),t[56]=n.recentUsage,t[57]=C);let T;t[58]===y?T=t[59]:(T=(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:y}),t[58]=y,t[59]=T);let E;t[60]!==a.balance.updatedAt||t[61]!==n.updatedAt||t[62]!==r?(E=n.updatedAt.replace(`{{time}}`,new Date(a.balance.updatedAt).toLocaleString(r)),t[60]=a.balance.updatedAt,t[61]=n.updatedAt,t[62]=r,t[63]=E):E=t[63];let D;t[64]===E?D=t[65]:(D=(0,$.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:E}),t[64]=E,t[65]=D);let O;t[66]!==x||t[67]!==S||t[68]!==C||t[69]!==T||t[70]!==D||t[71]!==p||t[72]!==m||t[73]!==h?(O=(0,$.jsxs)(`div`,{className:p,children:[m,h,x,S,C,T,D]}),t[66]=x,t[67]=S,t[68]=C,t[69]=T,t[70]=D,t[71]=p,t[72]=m,t[73]=h,t[74]=O):O=t[74];let k;t[75]===Symbol.for(`react.memo_cache_sentinel`)?(k=(0,$.jsx)(f,{className:`size-3.5`,"aria-hidden":!0}),t[75]=k):k=t[75];let A;t[76]!==a.links.purchase||t[77]!==n.purchase?(A=(0,$.jsx)(g,{asChild:!0,variant:`primary`,children:(0,$.jsxs)(`a`,{href:a.links.purchase,target:`_blank`,rel:`noreferrer`,children:[n.purchase,k]})}),t[76]=a.links.purchase,t[77]=n.purchase,t[78]=A):A=t[78];let j;t[79]===Symbol.for(`react.memo_cache_sentinel`)?(j=(0,$.jsx)(f,{className:`size-3.5`,"aria-hidden":!0}),t[79]=j):j=t[79];let M;t[80]!==a.links.details||t[81]!==n.details?(M=(0,$.jsx)(g,{asChild:!0,variant:`secondary`,children:(0,$.jsxs)(`a`,{href:a.links.details,target:`_blank`,rel:`noreferrer`,children:[n.details,j]})}),t[80]=a.links.details,t[81]=n.details,t[82]=M):M=t[82];let N;t[83]!==A||t[84]!==M?(N=(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap gap-2`,children:[A,M]}),t[83]=A,t[84]=M,t[85]=N):N=t[85];let P;t[86]!==O||t[87]!==N||t[88]!==_?(P=(0,$.jsxs)(`div`,{className:_,children:[O,N]}),t[86]=O,t[87]=N,t[88]=_,t[89]=P):P=t[89];let F;return t[90]!==P||t[91]!==v?(F=(0,$.jsx)(`section`,{className:v,children:P}),t[90]=P,t[91]=v,t[92]=F):F=t[92],F}function _r(e){return e.language}function vr(e){return q.includes(e)}function yr(){let e=(0,Z.c)(71),t=w(Sr),n;e[0]===t?n=e[1]:(n=S(t),e[0]=t,e[1]=n);let r=n,l=r.capabilitiesSettings,u=o(),[d,f]=a(),{capability:p}=i(),[m,h]=(0,Q.useState)(!1),[_,v]=(0,Q.useState)(null),y=Jn(),b;e[2]===y.cards?b=e[3]:(b=y.cards.some(xr),e[2]=y.cards,e[3]=b);let x=b,C,T;e[4]!==p||e[5]!==d||e[6]!==f?(C=()=>{if(p!==`models`||d.get(`add`)!==`1`)return;h(!0);let e=new URLSearchParams(d);e.delete(`add`),f(e,{replace:!0})},T=[p,d,f],e[4]=p,e[5]=d,e[6]=f,e[7]=C,e[8]=T):(C=e[7],T=e[8]),(0,Q.useEffect)(C,T);let E;e[9]!==l.modelsHint||e[10]!==l.tabs.models?(E={id:`models`,icon:J,label:l.tabs.models,hint:l.modelsHint},e[9]=l.modelsHint,e[10]=l.tabs.models,e[11]=E):E=e[11];let D;e[12]!==l.imageHint||e[13]!==l.tabs.image?(D={id:`image`,icon:me,label:l.tabs.image,hint:l.imageHint},e[12]=l.imageHint,e[13]=l.tabs.image,e[14]=D):D=e[14];let O;e[15]!==l.tabs.voice||e[16]!==l.voiceHint?(O={id:`voice`,icon:Le,label:l.tabs.voice,hint:l.voiceHint},e[15]=l.tabs.voice,e[16]=l.voiceHint,e[17]=O):O=e[17];let k;e[18]!==l.searchHint||e[19]!==l.tabs.search?(k={id:`search`,icon:_e,label:l.tabs.search,hint:l.searchHint},e[18]=l.searchHint,e[19]=l.tabs.search,e[20]=k):k=e[20];let A;e[21]!==E||e[22]!==D||e[23]!==O||e[24]!==k?(A=[E,D,O,k],e[21]=E,e[22]=D,e[23]=O,e[24]=k,e[25]=A):A=e[25];let j=A,M;e[26]===u?M=e[27]:(M=e=>u(fe(e)),e[26]=u,e[27]=M);let N=M,P=br;if(!vr(p)){let t;return e[28]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(s,{to:fe(`models`),replace:!0}),e[28]=t):t=e[28],t}let F=r.nav.settingsCapabilities,I=l.subtitle,L;e[29]===t?L=e[30]:(L=we(t,`configuration`),e[29]=t,e[30]=L);let R;e[31]===Symbol.for(`react.memo_cache_sentinel`)?(R=(0,$.jsx)(Ve,{className:`size-4`,"aria-hidden":!0}),e[31]=R):R=e[31];let z;e[32]===l.agentSettingsLink?z=e[33]:(z=(0,$.jsx)(g,{asChild:!0,variant:`secondary`,children:(0,$.jsxs)(c,{to:`/agents`,children:[R,l.agentSettingsLink]})}),e[32]=l.agentSettingsLink,e[33]=z);let B;e[34]!==l.docsLink||e[35]!==l.subtitle||e[36]!==r.nav.settingsCapabilities||e[37]!==L||e[38]!==z?(B=(0,$.jsx)(mt,{title:F,subtitle:I,docsLink:L,docsLabel:l.docsLink,actions:z}),e[34]=l.docsLink,e[35]=l.subtitle,e[36]=r.nav.settingsCapabilities,e[37]=L,e[38]=z,e[39]=B):B=e[39];let V;e[40]!==l.tabsAria||e[41]!==p||e[42]!==j||e[43]!==N?(V=(0,$.jsx)(Nt,{items:j,activeTab:p,onChange:N,ariaLabel:l.tabsAria,tabIdPrefix:`capability-tab`,panelIdPrefix:`capability-panel`}),e[40]=l.tabsAria,e[41]=p,e[42]=j,e[43]=N,e[44]=V):V=e[44];let H;e[45]!==l.connectedProviders||e[46]!==l.xopcCloudAccount||e[47]!==p||e[48]!==y||e[49]!==j||e[50]!==x?(H=j.map(e=>(0,$.jsx)(wr,{id:e.id,activeSection:p,hint:e.hint,children:e.id===`models`?(0,$.jsxs)($.Fragment,{children:[x?(0,$.jsx)(gr,{labels:l.xopcCloudAccount}):null,(0,$.jsx)(mr,{}),(0,$.jsx)(er,{labels:l.connectedProviders,data:y,onAdd:()=>h(!0),onManage:(e,t)=>v({providerId:e,isCustom:t})})]}):(0,$.jsx)(Cr,{section:e.id})},e.id)),e[45]=l.connectedProviders,e[46]=l.xopcCloudAccount,e[47]=p,e[48]=y,e[49]=j,e[50]=x,e[51]=H):H=e[51];let U;e[52]!==m||e[53]!==l.addProviderDialog||e[54]!==t||e[55]!==y.builtinRows||e[56]!==y.customConfig?(U=(0,$.jsx)(Vn,{open:m,onOpenChange:h,builtinRows:y.builtinRows,customConfig:y.customConfig,labels:l.addProviderDialog,language:t,onSaved:P}),e[52]=m,e[53]=l.addProviderDialog,e[54]=t,e[55]=y.builtinRows,e[56]=y.customConfig,e[57]=U):U=e[57];let W;e[58]!==l.manageProviderDialog||e[59]!==t||e[60]!==_||e[61]!==y.allModels||e[62]!==y.builtinRows||e[63]!==y.customConfig?(W=_?(0,$.jsx)(ur,{open:!0,onOpenChange:e=>{e||v(null)},providerId:_.providerId,isCustom:_.isCustom,builtinRows:y.builtinRows,customConfig:y.customConfig,allModels:y.allModels,labels:l.manageProviderDialog,language:t,onSaved:P}):null,e[58]=l.manageProviderDialog,e[59]=t,e[60]=_,e[61]=y.allModels,e[62]=y.builtinRows,e[63]=y.customConfig,e[64]=W):W=e[64];let G;return e[65]!==B||e[66]!==V||e[67]!==H||e[68]!==U||e[69]!==W?(G=(0,$.jsxs)(ht,{children:[B,V,H,U,W]}),e[65]=B,e[66]=V,e[67]=H,e[68]=U,e[69]=W,e[70]=G):G=e[70],G}function br(){Te()}function xr(e){return e.id===`xopc-cloud`&&!e.isCustom}function Sr(e){return e.language}function Cr(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)(Yt,{}),t[0]=e):e=t[0],e}case`voice`:{let e;return t[1]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(un,{}),t[1]=e):e=t[1],e}case`search`:{let e;return t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Nn,{}),t[2]=e):e=t[2],e}}}function wr({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:h(`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{yr as CapabilitiesSettingsPanel};
@@ -1 +1 @@
1
- import{r as e,s as t}from"./locale-store-xULEcFVs.js";var n=[{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`,`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`]}],r=new Set(n.flatMap(e=>[...e.toolIds].map(e=>String(e))));function i(e){return e.filter(e=>e&&!r.has(e)).sort((e,t)=>e.localeCompare(t))}async function a(){let n=await t(e(`/api/capability-presets`));if(!Array.isArray(n.payload?.presets)||typeof n.payload.defaultPresetId!=`string`||!Array.isArray(n.payload.agents)||!Array.isArray(n.payload.builtinToolIds)||!Array.isArray(n.payload.mcpServerIds)||!Array.isArray(n.payload.workflows))throw Error(`Invalid /api/capability-presets response`);return n.payload}async function o(n){return(await Promise.all(n.map(async n=>{try{return((await t(e(`/api/mcp/servers/${encodeURIComponent(n)}/tools`))).payload?.tools??[]).map(e=>({id:e.name,serverId:n,name:e.shortName,description:e.description,readOnly:e.readOnly}))}catch{return[]}}))).flat().sort((e,t)=>e.id.localeCompare(t.id))}async function s(n){let r=await t(e(`/api/capability-presets`),{method:`POST`,body:JSON.stringify(n)}),i=r.payload?.presetId,a=r.payload?.presets;if(!i||!a||typeof a.defaultPresetId!=`string`||!Array.isArray(a.presets)||!Array.isArray(a.agents)||!Array.isArray(a.builtinToolIds)||!Array.isArray(a.mcpServerIds)||!Array.isArray(a.workflows))throw Error(`Invalid create capability preset response`);return{presetId:i,presets:a}}async function c(n,r){let i=await t(e(`/api/capability-presets/${encodeURIComponent(n)}`),{method:`PATCH`,body:JSON.stringify(r)});if(!Array.isArray(i.payload?.presets)||typeof i.payload.defaultPresetId!=`string`||!Array.isArray(i.payload.agents)||!Array.isArray(i.payload.builtinToolIds)||!Array.isArray(i.payload.mcpServerIds)||!Array.isArray(i.payload.workflows))throw Error(`Invalid update capability preset response`);return i.payload}async function l(n,r){let i=await t(e(`/api/capability-presets/${encodeURIComponent(n)}/preview`),{method:`POST`,body:JSON.stringify(r)});if(!Array.isArray(i.payload?.agents))throw Error(`Invalid capability preset preview response`);return i.payload}async function u(n){let r=await t(e(`/api/capability-presets/${encodeURIComponent(n)}`),{method:`DELETE`});if(!Array.isArray(r.payload?.presets)||typeof r.payload.defaultPresetId!=`string`||!Array.isArray(r.payload.agents)||!Array.isArray(r.payload.builtinToolIds)||!Array.isArray(r.payload.mcpServerIds)||!Array.isArray(r.payload.workflows))throw Error(`Invalid delete capability preset response`);return r.payload}export{l as a,i as c,a as i,u as n,c as o,o as r,n as s,s as t};
1
+ import{r as e,s as t}from"./locale-store-CnamlR07.js";var n=[{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`,`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`]}],r=new Set(n.flatMap(e=>[...e.toolIds].map(e=>String(e))));function i(e){return e.filter(e=>e&&!r.has(e)).sort((e,t)=>e.localeCompare(t))}async function a(){let n=await t(e(`/api/capability-presets`));if(!Array.isArray(n.payload?.presets)||typeof n.payload.defaultPresetId!=`string`||!Array.isArray(n.payload.agents)||!Array.isArray(n.payload.builtinToolIds)||!Array.isArray(n.payload.mcpServerIds)||!Array.isArray(n.payload.workflows))throw Error(`Invalid /api/capability-presets response`);return n.payload}async function o(n){return(await Promise.all(n.map(async n=>{try{return((await t(e(`/api/mcp/servers/${encodeURIComponent(n)}/tools`))).payload?.tools??[]).map(e=>({id:e.name,serverId:n,name:e.shortName,description:e.description,readOnly:e.readOnly}))}catch{return[]}}))).flat().sort((e,t)=>e.id.localeCompare(t.id))}async function s(n){let r=await t(e(`/api/capability-presets`),{method:`POST`,body:JSON.stringify(n)}),i=r.payload?.presetId,a=r.payload?.presets;if(!i||!a||typeof a.defaultPresetId!=`string`||!Array.isArray(a.presets)||!Array.isArray(a.agents)||!Array.isArray(a.builtinToolIds)||!Array.isArray(a.mcpServerIds)||!Array.isArray(a.workflows))throw Error(`Invalid create capability preset response`);return{presetId:i,presets:a}}async function c(n,r){let i=await t(e(`/api/capability-presets/${encodeURIComponent(n)}`),{method:`PATCH`,body:JSON.stringify(r)});if(!Array.isArray(i.payload?.presets)||typeof i.payload.defaultPresetId!=`string`||!Array.isArray(i.payload.agents)||!Array.isArray(i.payload.builtinToolIds)||!Array.isArray(i.payload.mcpServerIds)||!Array.isArray(i.payload.workflows))throw Error(`Invalid update capability preset response`);return i.payload}async function l(n,r){let i=await t(e(`/api/capability-presets/${encodeURIComponent(n)}/preview`),{method:`POST`,body:JSON.stringify(r)});if(!Array.isArray(i.payload?.agents))throw Error(`Invalid capability preset preview response`);return i.payload}async function u(n){let r=await t(e(`/api/capability-presets/${encodeURIComponent(n)}`),{method:`DELETE`});if(!Array.isArray(r.payload?.presets)||typeof r.payload.defaultPresetId!=`string`||!Array.isArray(r.payload.agents)||!Array.isArray(r.payload.builtinToolIds)||!Array.isArray(r.payload.mcpServerIds)||!Array.isArray(r.payload.workflows))throw Error(`Invalid delete capability preset response`);return r.payload}export{l as a,i as c,a as i,u as n,c as o,o as r,n as s,s as t};
@@ -0,0 +1,3 @@
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{f as i,t as a}from"./chunk-KS7C4IRE-BMhrPKJC.js";import{i as o,n as s,r as c,t as l}from"./popover-select-BzdnTy3h.js";import{t as u}from"./copy-Dv6d4Dvw.js";import{t as d}from"./loader-circle-CifKLtgG.js";import{t as f}from"./cn-JdwAhgNB.js";import{t as p}from"./button-CSEbl4zT.js";import{t as m}from"./interaction-BmQogeqz.js";import{t as h}from"./messages-D7kOD_o_.js";import{l as g,n as _}from"./locale-store-CnamlR07.js";import{i as v,o as y}from"./settings-shell-dialog-layer-BU3UuiJr.js";import{a as b,i as x,n as S,o as C,r as w,s as T,t as E}from"./dist-BPoKqzeH.js";import{i as D}from"./vendor-swr-BIWyz7Rc.js";import{Al as O,Dc as k,Gl as A,Jl as j,Ps as M,Rn as N,Vs as P,Wl as F,Ws as I,X as L,Xo as R,Yo as ee,it as te,ls as z,ql as B,tl as ne,ws as re,zl as V}from"./index-DRrjYYzZ.js";import{l as H}from"./vendor-codemirror-DRr7hFaD.js";import{t as U}from"./code-editor-dFzqyDXS.js";import{n as W,r as G}from"./settings-page-layout-BRQNel6r.js";import{n as ie,r as ae}from"./settings-loading-skeleton-zwibve4m.js";import{n as K,t as oe}from"./settings-form-section-C7w2WS-A.js";import{a as se,c as ce,i as le,n as ue,o as de,r as fe,s as pe,t as me}from"./capability-presets-api--tz0mGLY.js";import{a as he,i as ge,o as q,s as J,t as _e}from"./typed-models-lib-q5-Vfqd8.js";var Y=n(),X=e(t(),1),Z=r(),Q=[`deep`,`fast`,`cheap`,`code`,`review`];function ve(e){return Q.includes(e)}function ye(e){let{rows:t,onChange:n,disabled:r,defaultRole:i,chat:a,labels:o}=e,s=(0,X.useRef)([]),c=(0,X.useRef)(0);for(;s.current.length<t.length;)s.current.push(`preset-model-row-${c.current++}`);s.current.length>t.length&&(s.current.length=t.length);let u=i??(t.some(e=>e.id===`deep`)?`deep`:t[0]?.id)??`deep`,d=t.findIndex(e=>e.id===u),f=d>=0?t[d]:void 0,m=t.map((e,t)=>({row:e,index:t})).filter(({index:e})=>e!==d),h=(e,r)=>{n(t.map((t,n)=>n===e?{...t,...r}:t))},g=e=>{if(d>=0){h(d,{model:e});return}s.current.unshift(`preset-model-row-${c.current++}`),n([{id:u,model:e,fallbacks:[],description:ve(u)?o.roleDescriptions[u]:``},...t])},_=e=>{let n=t[e];n&&h(e,{fallbacks:[...n.fallbacks??[],``]})},v=(e,n,r)=>{let i=t[e];if(!i)return;let a=[...i.fallbacks??[]];a[n]=r,h(e,{fallbacks:a})},y=(e,n)=>{let r=t[e];r&&h(e,{fallbacks:(r.fallbacks??[]).filter((e,t)=>t!==n)})},b=e=>{s.current.splice(e,1),n(t.filter((t,n)=>n!==e))},x=e=>{if(!e)return;let r=e===`__custom__`?``:e;s.current.push(`preset-model-row-${c.current++}`),n([...t,{id:r,model:``,fallbacks:[],description:ve(r)?o.roleDescriptions[r]:``}])},S=[...Q.filter(e=>e!==u&&!t.some(t=>t.id===e)).map(e=>({value:e,label:o.roleNames[e]})),{value:`__custom__`,label:o.customRole}],C=(e,t)=>(0,Z.jsxs)(`div`,{className:`grid gap-3 border-t border-edge-subtle pt-3 dark:border-edge`,children:[(0,Z.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:o.fallbackModels}),(0,Z.jsxs)(p,{type:`button`,variant:`secondary`,className:`h-7 gap-1 px-2 text-xs`,disabled:r,onClick:()=>_(t),children:[(0,Z.jsx)(I,{className:`size-3.5`,"aria-hidden":!0}),o.addFallback]})]}),(e.fallbacks??[]).length>0?(0,Z.jsx)(`div`,{className:`grid gap-1.5`,children:(e.fallbacks??[]).map((e,n)=>(0,Z.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] gap-2`,children:[(0,Z.jsx)(L,{value:e,disabled:r,placeholder:o.fallbackPlaceholder,searchPlaceholder:a.modelSearchPlaceholder,noMatches:a.modelNoMatches,className:`w-full max-w-none`,contentAlign:`start`,onChange:e=>v(t,n,e)}),(0,Z.jsx)(p,{type:`button`,variant:`secondary`,className:`shrink-0 px-2`,disabled:r,"aria-label":o.removeFallback,onClick:()=>y(t,n),children:(0,Z.jsx)(z,{className:`size-4`,"aria-hidden":!0})})]},`${s.current[t]}-fallback-${n}`))}):(0,Z.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:o.fallbackEmptyHint})]}),(0,Z.jsxs)(`label`,{className:`grid gap-1.5 text-xs font-medium text-fg-muted`,children:[o.description,(0,Z.jsx)(`input`,{type:`text`,className:J(),value:e.description,disabled:r,placeholder:o.descriptionPlaceholder,onChange:e=>h(t,{description:e.target.value})})]})]});return(0,Z.jsxs)(`div`,{className:`grid gap-5`,children:[(0,Z.jsxs)(`div`,{className:`rounded-xl border border-edge bg-surface-base p-4`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Z.jsx)(`h4`,{className:`text-sm font-semibold text-fg`,children:o.defaultTitle}),(0,Z.jsx)(`span`,{className:`rounded-full bg-accent/10 px-2 py-0.5 text-[11px] font-medium text-accent`,children:o.defaultBadge})]}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-fg-muted`,children:o.defaultHint})]}),(0,Z.jsxs)(`span`,{className:`rounded-md bg-surface-panel px-2 py-1 font-mono text-[11px] text-fg-subtle`,children:[o.roleId,`: `,u]})]}),(0,Z.jsxs)(`div`,{className:`mt-4 grid gap-1.5`,children:[(0,Z.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:o.primaryModel}),(0,Z.jsx)(L,{value:f?.model??``,disabled:r,placeholder:a.modelPlaceholder,searchPlaceholder:a.modelSearchPlaceholder,noMatches:a.modelNoMatches,className:`w-full max-w-none`,contentAlign:`start`,onChange:g})]}),f?(0,Z.jsxs)(`details`,{className:`group mt-3`,children:[(0,Z.jsxs)(`summary`,{className:`flex w-fit cursor-pointer list-none items-center gap-1.5 rounded-md text-xs font-medium text-fg-muted hover:text-fg`,children:[o.moreSettings,(0,Z.jsx)(O,{className:`size-3.5 transition-transform group-open:rotate-180`,"aria-hidden":!0})]}),(0,Z.jsx)(`div`,{className:`mt-3`,children:C(f,d)})]}):null]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h4`,{className:`text-sm font-semibold text-fg`,children:o.otherRolesTitle}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-fg-muted`,children:o.otherRolesHint})]}),m.length>0?(0,Z.jsx)(`div`,{className:`mt-3 grid gap-2`,children:m.map(({row:e,index:t})=>{let n=ve(e.id)?e.id:void 0;return(0,Z.jsxs)(`div`,{className:`rounded-lg border border-edge-subtle bg-surface-panel/60 p-3 dark:border-edge`,children:[(0,Z.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-[minmax(8rem,12rem)_minmax(0,1fr)] md:items-end`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n?o.roleNames[n]:o.customRole}),n?(0,Z.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-fg-subtle`,children:e.id}):(0,Z.jsxs)(`label`,{className:`mt-1 grid gap-1 text-[11px] text-fg-muted`,children:[o.roleId,(0,Z.jsx)(`input`,{type:`text`,className:J(),value:e.id,disabled:r,placeholder:o.roleIdPlaceholder,onChange:e=>h(t,{id:e.target.value.toLowerCase()})})]})]}),(0,Z.jsxs)(`label`,{className:`grid min-w-0 gap-1.5 text-xs font-medium text-fg-muted`,children:[o.primaryModel,(0,Z.jsx)(L,{value:e.model,disabled:r,placeholder:a.modelPlaceholder,searchPlaceholder:a.modelSearchPlaceholder,noMatches:a.modelNoMatches,className:`w-full max-w-none`,contentAlign:`start`,onChange:e=>h(t,{model:e})})]})]}),(0,Z.jsxs)(`details`,{className:`group mt-3`,children:[(0,Z.jsxs)(`summary`,{className:`flex w-fit cursor-pointer list-none items-center gap-1.5 text-xs font-medium text-fg-muted hover:text-fg`,children:[o.moreSettings,(0,Z.jsx)(O,{className:`size-3.5 transition-transform group-open:rotate-180`,"aria-hidden":!0})]}),(0,Z.jsxs)(`div`,{className:`mt-3`,children:[C(e,t),(0,Z.jsx)(`div`,{className:`mt-3 flex justify-end`,children:(0,Z.jsxs)(p,{type:`button`,variant:`secondary`,disabled:r,onClick:()=>b(t),children:[(0,Z.jsx)(z,{className:`size-4`,"aria-hidden":!0}),o.removeRole]})})]})]})]},s.current[t])})}):(0,Z.jsx)(`p`,{className:`mt-3 rounded-lg bg-surface-panel/60 px-3 py-2 text-sm text-fg-muted shadow-surface`,children:o.otherRolesEmpty}),(0,Z.jsx)(l,{value:``,options:S,placeholder:o.addTaskModel,allowEmpty:!1,disabled:r,triggerClassName:`mt-3 w-fit`,onChange:x})]})]})}var be=H();function xe(e){let t=e.split(`
2
+ `).map(e=>e.trim()).filter(Boolean);return t.length?t:void 0}function Se(e){return e?.join(`
3
+ `)??``}function Ce(e,t,n){return Object.entries(e).find(([e])=>e===t||e.startsWith(`${t}.`))?.[1]??n}function we(e){return!!(e&&typeof e==`object`&&!Array.isArray(e))}function Te(e){if(!we(e)||[`models`,`tools`,`skills`,`workflows`,`boundaries`,`runtime`].some(t=>e[t]!==void 0&&!we(e[t]))||e.extends!==void 0&&!Array.isArray(e.extends)||e.locks!==void 0&&!Array.isArray(e.locks))return!1;let t=e.skills;if(t&&[`allow`,`deny`].some(e=>t[e]!==void 0&&!Array.isArray(t[e])))return!1;let n=e.workflows;if(n&&[`allowed`,`suggested`].some(e=>n[e]!==void 0&&!Array.isArray(n[e])))return!1;let r=e.boundaries;return!(r&&[`requiresConfirmation`,`forbidden`,`escalation`].some(e=>r[e]!==void 0&&!Array.isArray(r[e])))}function Ee(e){let{extendsIds:t,onExtendsChange:n,presetOptions:r,inherited:i,inheritedSources:a={},mcpServerIds:o,mcpTools:l,workflows:u,policy:d,onPolicyChange:f,rawPolicy:m,onRawPolicyChange:h,disabled:g,labels:_}=e,[v,y]=(0,X.useState)(t.length>1),[b,x]=(0,X.useState)(!1),[S,C]=(0,X.useState)(``),[w,T]=(0,X.useState)(``),E=d.mcp??{},D=d.workflows??{},O=d.boundaries??{},k=d.runtime??{},A=d.locks??[],M=[...new Set([...o,...Object.keys(E.servers??{})])].sort(),N=new Map(r.map(e=>[e.id,e])),P=r.filter(e=>!t.includes(e.id)),I=(e,t)=>{f({...d,[e]:t})},L=(e,t)=>{let n={...E.servers??{}};t?n[e]={...n[e],mode:t}:delete n[e],I(`mcp`,De({...E,servers:Object.keys(n).length?n:void 0,tools:Object.keys(E.tools??{}).length?E.tools:void 0}))},R=(e,t)=>{let n={...E.tools??{}};t?n[e]=t:delete n[e],I(`mcp`,De({...E,servers:Object.keys(E.servers??{}).length?E.servers:void 0,tools:Object.keys(n).length?n:void 0}))};return(0,Z.jsxs)(`div`,{className:`flex flex-col gap-7`,children:[(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(`h4`,{className:`text-sm font-semibold text-fg`,children:_.inheritanceTitle}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-fg-muted`,children:_.inheritanceHint}),v?(0,Z.jsxs)(`div`,{className:`mt-3 grid gap-2`,children:[t.map((e,r)=>(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg bg-surface-panel/70 px-3 py-2.5 shadow-surface`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Z.jsx)(`div`,{className:`truncate text-sm font-medium text-fg`,children:N.get(e)?.name??e}),(0,Z.jsx)(`div`,{className:`font-mono text-[11px] text-fg-subtle`,children:e})]}),(0,Z.jsx)(p,{type:`button`,variant:`secondary`,className:`size-8 p-0`,disabled:g||r===0,"aria-label":_.inheritanceMoveUp,onClick:()=>{let e=[...t];[e[r-1],e[r]]=[e[r],e[r-1]],n(e)},children:(0,Z.jsx)(F,{className:`size-3.5`})}),(0,Z.jsx)(p,{type:`button`,variant:`secondary`,className:`size-8 p-0`,disabled:g||r===t.length-1,"aria-label":_.inheritanceMoveDown,onClick:()=>{let e=[...t];[e[r],e[r+1]]=[e[r+1],e[r]],n(e)},children:(0,Z.jsx)(j,{className:`size-3.5`})}),(0,Z.jsx)(p,{type:`button`,variant:`secondary`,className:`size-8 p-0`,disabled:g,"aria-label":_.inheritanceRemove,onClick:()=>n(t.filter(t=>t!==e)),children:(0,Z.jsx)(z,{className:`size-3.5`})})]},e)),P.length?(0,Z.jsxs)(`label`,{className:`text-xs text-fg-muted`,children:[_.inheritanceAdd,(0,Z.jsxs)(s,{value:``,disabled:g,onChange:e=>e.target.value&&n([...t,e.target.value]),children:[(0,Z.jsx)(c,{value:``,children:_.inheritanceAvailable}),P.map(e=>(0,Z.jsx)(c,{value:e.id,children:e.name},e.id))]})]}):null]}):(0,Z.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-end gap-2`,children:[(0,Z.jsxs)(`label`,{className:`min-w-64 flex-1 text-xs text-fg-muted`,children:[_.inheritanceAvailable,(0,Z.jsxs)(s,{value:t[0]??``,disabled:g,onChange:e=>n(e.target.value?[e.target.value]:[]),children:[(0,Z.jsx)(c,{value:``,children:_.inherit}),r.map(e=>(0,Z.jsx)(c,{value:e.id,children:e.name},e.id))]})]}),(0,Z.jsx)(p,{type:`button`,variant:`secondary`,disabled:g,onClick:()=>y(!0),children:_.compose})]}),r.length?null:(0,Z.jsx)(`p`,{className:`mt-3 text-sm text-fg-muted`,children:_.inheritanceEmpty})]}),(0,Z.jsx)(Oe,{title:_.mcpTitle,hint:_.mcpHint,source:Ce(a,`tools.mcp`,_.inherit),children:M.length?(0,Z.jsx)(`div`,{className:`grid gap-2`,children:M.map(e=>(0,Z.jsxs)(`details`,{className:`rounded-lg bg-surface-panel/70 px-3 py-2 shadow-surface`,children:[(0,Z.jsxs)(`summary`,{className:`grid cursor-pointer items-center gap-2 sm:grid-cols-[minmax(0,1fr)_12rem]`,children:[(0,Z.jsx)(`span`,{className:`truncate font-mono text-xs text-fg`,children:e}),(0,Z.jsxs)(s,{value:E.servers?.[e]?.mode??``,disabled:g,onClick:e=>e.stopPropagation(),onChange:t=>L(e,t.target.value),children:[(0,Z.jsx)(c,{value:``,children:i?.tools?.mcp?.servers?.[e]?.mode?`${_.inherit} · ${i.tools.mcp.servers[e].mode}`:_.inherit}),(0,Z.jsx)(c,{value:`allow`,children:_.modeAllow}),(0,Z.jsx)(c,{value:`confirm`,children:_.modeConfirm}),(0,Z.jsx)(c,{value:`deny`,children:_.modeDeny})]})]}),(0,Z.jsxs)(`div`,{className:`mt-3 grid gap-2 border-t border-edge-subtle pt-3`,children:[E.servers?.[e]?(0,Z.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-fg-muted`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:E.servers[e].scope===`readonly`,disabled:g,onChange:t=>{let n=E.servers?.[e];if(!n)return;let r={...E.servers??{},[e]:{...n,scope:t.target.checked?`readonly`:void 0}};I(`mcp`,De({...E,servers:r}))}}),_.readonlyOnly]}):null,l.filter(t=>t.serverId===e).map(e=>{let t=E.tools?.[e.id];return(0,Z.jsxs)(`div`,{className:`grid gap-2 rounded-lg bg-surface-base px-3 py-2 lg:grid-cols-[minmax(0,1fr)_11rem_8rem_8rem] lg:items-end`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`truncate font-mono text-xs text-fg`,children:e.name}),(0,Z.jsx)(`div`,{className:`truncate text-xs text-fg-muted`,children:e.description})]}),(0,Z.jsxs)(s,{value:t?.mode??``,disabled:g,onChange:n=>{let r=n.target.value;R(e.id,r?{...t??{},mode:r}:void 0)},children:[(0,Z.jsx)(c,{value:``,children:_.inherit}),(0,Z.jsx)(c,{value:`allow`,children:_.modeAllow}),(0,Z.jsx)(c,{value:`confirm`,children:_.modeConfirm}),(0,Z.jsx)(c,{value:`deny`,children:_.modeDeny})]}),(0,Z.jsx)(ke,{label:_.maxCalls,value:t?.limits?.maxCallsPerTurn,disabled:!t||g,onChange:n=>R(e.id,t?{...t,limits:De({...t.limits,maxCallsPerTurn:n})}:void 0)}),(0,Z.jsx)(ke,{label:_.timeoutMinutes,value:t?.limits?.timeoutMs?t.limits.timeoutMs/6e4:void 0,disabled:!t||g,onChange:n=>R(e.id,t?{...t,limits:De({...t.limits,timeoutMs:n?n*6e4:void 0})}:void 0)})]},e.id)})]})]},e))}):(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:_.noMcp})}),(0,Z.jsxs)(Oe,{title:_.workflowsTitle,hint:_.workflowsHint,source:Ce(a,`workflows`,_.inherit),children:[(0,Z.jsxs)(`label`,{className:`text-xs text-fg-muted`,children:[_.defaultWorkflow,(0,Z.jsxs)(s,{value:D.default??``,disabled:g,onChange:e=>I(`workflows`,De({...D,default:e.target.value||void 0})),children:[(0,Z.jsx)(c,{value:``,children:i?.workflows?.default?`${_.inherit} · ${i.workflows.default}`:_.inherit}),u.map(e=>(0,Z.jsx)(c,{value:e.id,children:e.title},e.id))]})]}),(0,Z.jsxs)(`div`,{className:`mt-3`,children:[(0,Z.jsx)(`div`,{className:`mb-2 text-xs text-fg-muted`,children:_.allowedWorkflows}),(0,Z.jsx)(`div`,{className:`grid gap-2 sm:grid-cols-2`,children:u.map(e=>{let t=D.allowed?.includes(e.id)??!1;return(0,Z.jsxs)(`label`,{className:`flex gap-2 rounded-lg bg-surface-panel/70 px-3 py-2 text-sm text-fg`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,checked:t,disabled:g,onChange:()=>{let n=new Set(D.allowed??[]);t?n.delete(e.id):n.add(e.id),I(`workflows`,De({...D,allowed:n.size?[...n].sort():void 0}))}}),(0,Z.jsxs)(`span`,{children:[(0,Z.jsx)(`span`,{className:`block font-medium`,children:e.title}),(0,Z.jsx)(`span`,{className:`text-xs text-fg-muted`,children:e.description})]})]},e.id)})})]})]}),(0,Z.jsx)(Oe,{title:_.runtimeTitle,hint:_.runtimeHint,source:Ce(a,`runtime`,_.inherit),children:(0,Z.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[(0,Z.jsx)(ke,{label:_.timeoutMinutes,value:k.timeoutMs?k.timeoutMs/6e4:void 0,placeholder:i?.runtime?.timeoutMs?String(i.runtime.timeoutMs/6e4):void 0,disabled:g,onChange:e=>I(`runtime`,De({...k,timeoutMs:e?e*6e4:void 0}))}),(0,Z.jsx)(ke,{label:_.maxTurns,value:k.maxTurns,placeholder:i?.runtime?.maxTurns?String(i.runtime.maxTurns):void 0,disabled:g,onChange:e=>I(`runtime`,De({...k,maxTurns:e}))}),(0,Z.jsx)(ke,{label:_.maxFailures,value:k.maxToolFailuresPerTurn,placeholder:i?.runtime?.maxToolFailuresPerTurn?String(i.runtime.maxToolFailuresPerTurn):void 0,disabled:g,onChange:e=>I(`runtime`,De({...k,maxToolFailuresPerTurn:e}))})]})}),(0,Z.jsx)(Oe,{title:_.boundariesTitle,hint:_.boundariesHint,source:Ce(a,`boundaries`,_.inherit),children:(0,Z.jsx)(`div`,{className:`grid gap-3 lg:grid-cols-3`,children:[[`requiresConfirmation`,_.confirmRules],[`forbidden`,_.forbiddenRules],[`escalation`,_.escalationRules]].map(([e,t])=>(0,Z.jsxs)(`label`,{className:`text-xs text-fg-muted`,children:[t,(0,Z.jsx)(`textarea`,{className:`mt-1 min-h-28 w-full resize-y rounded-lg border border-edge bg-surface-base px-3 py-2 text-sm text-fg`,placeholder:_.onePerLine,value:Se(O[e]),disabled:g,onChange:t=>I(`boundaries`,De({...O,[e]:xe(t.target.value)}))})]},e))})}),(0,Z.jsxs)(`details`,{className:`rounded-xl border border-edge-subtle bg-surface-panel/40 p-4`,children:[(0,Z.jsx)(`summary`,{className:`cursor-pointer text-sm font-semibold text-fg`,children:_.governanceTitle}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:_.governanceHint}),(0,Z.jsxs)(`label`,{className:`mt-3 block text-xs text-fg-muted`,children:[_.locksLabel,(0,Z.jsx)(`textarea`,{className:`mt-1 min-h-28 w-full resize-y rounded-lg border border-edge bg-surface-base px-3 py-2 font-mono text-xs text-fg`,placeholder:_.onePerLine,value:Se(A),disabled:g,onChange:e=>I(`locks`,xe(e.target.value))})]})]}),(0,Z.jsxs)(`section`,{children:[(0,Z.jsx)(`h4`,{className:`text-sm font-semibold text-fg`,children:_.rawTitle}),(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:_.rawHint}),b?(0,Z.jsxs)(`div`,{className:`mt-3`,children:[(0,Z.jsx)(`div`,{className:`h-72 overflow-hidden rounded-lg border border-edge bg-surface-base`,children:(0,Z.jsx)(U,{initialContent:S,onChange:C,language:be,lineWrap:!0})}),w?(0,Z.jsx)(`p`,{className:`mt-2 text-sm text-red-600 dark:text-red-400`,children:w}):null,(0,Z.jsxs)(`div`,{className:`mt-2 flex gap-2`,children:[(0,Z.jsx)(p,{type:`button`,onClick:()=>{try{let e=JSON.parse(S);if(!Te(e))throw Error(`invalid policy`);h(e),T(``),x(!1)}catch{T(_.rawInvalid)}},children:_.rawApply}),(0,Z.jsx)(p,{type:`button`,variant:`secondary`,onClick:()=>x(!1),children:_.cancel})]})]}):(0,Z.jsx)(p,{className:`mt-3`,type:`button`,variant:`secondary`,onClick:()=>{C(JSON.stringify(m,null,2)),T(``),x(!0)},children:_.rawOpen})]})]})}function De(e){let t=Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0));return Object.keys(t).length?t:void 0}function Oe(e){let t=(0,Y.c)(17),n;t[0]===e.title?n=t[1]:(n=(0,Z.jsx)(`h4`,{className:`text-sm font-semibold text-fg`,children:e.title}),t[0]=e.title,t[1]=n);let r;t[2]===e.hint?r=t[3]:(r=(0,Z.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:e.hint}),t[2]=e.hint,t[3]=r);let i;t[4]!==n||t[5]!==r?(i=(0,Z.jsxs)(`div`,{children:[n,r]}),t[4]=n,t[5]=r,t[6]=i):i=t[6];let a;t[7]===e.source?a=t[8]:(a=(0,Z.jsx)(`span`,{className:`rounded-full bg-surface-panel px-2 py-0.5 text-[11px] text-fg-muted`,children:e.source}),t[7]=e.source,t[8]=a);let o;t[9]!==i||t[10]!==a?(o=(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-2`,children:[i,a]}),t[9]=i,t[10]=a,t[11]=o):o=t[11];let s;t[12]===e.children?s=t[13]:(s=(0,Z.jsx)(`div`,{className:`mt-3`,children:e.children}),t[12]=e.children,t[13]=s);let c;return t[14]!==o||t[15]!==s?(c=(0,Z.jsxs)(`section`,{children:[o,s]}),t[14]=o,t[15]=s,t[16]=c):c=t[16],c}function ke(e){let t=(0,Y.c)(10),n=e.value??``,r;t[0]===e?r=t[1]:(r=t=>e.onChange(t.target.value?Number(t.target.value):void 0),t[0]=e,t[1]=r);let i;t[2]!==e.disabled||t[3]!==e.placeholder||t[4]!==n||t[5]!==r?(i=(0,Z.jsx)(`input`,{type:`number`,min:1,step:1,className:`mt-1 w-full rounded-lg border border-edge bg-surface-base px-3 py-2 text-sm text-fg`,value:n,placeholder:e.placeholder,disabled:e.disabled,onChange:r}),t[2]=e.disabled,t[3]=e.placeholder,t[4]=n,t[5]=r,t[6]=i):i=t[6];let a;return t[7]!==e.label||t[8]!==i?(a=(0,Z.jsxs)(`label`,{className:`text-xs text-fg-muted`,children:[e.label,i]}),t[7]=e.label,t[8]=i,t[9]=a):a=t[9],a}function Ae(e){return e.name||e.directoryId}function je(e){let t=(0,Y.c)(56),{mode:n,selected:r,catalog:i,loading:a,disabled:o,onModeChange:s,onSelectedChange:c,labels:l}=e,u=n===`allowlist`||n===`denylist`,d;t[0]===i?d=t[1]:(d=i.map(Ae).filter(Boolean),t[0]=i,t[1]=d);let m=d,h;bb0:{if(n===`inherit`){h=l.inheritSummary;break bb0}if(n===`all`){h=l.allSummary;break bb0}if(n===`off`){h=l.offSummary;break bb0}let e=n===`allowlist`?l.allowSummary:l.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],h=i}let g=h,_;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(_=(0,Z.jsx)(V,{className:`size-3.5`,"aria-hidden":!0}),t[5]=_):_=t[5];let v;t[6]===l.overrideSummaryTitle?v=t[7]:(v=(0,Z.jsxs)(`div`,{className:`flex items-center gap-2 text-xs font-medium text-fg-muted`,children:[_,l.overrideSummaryTitle]}),t[6]=l.overrideSummaryTitle,t[7]=v);let y;t[8]===g?y=t[9]:(y=(0,Z.jsx)(`p`,{className:`mt-1 text-sm text-fg`,children:g}),t[8]=g,t[9]=y);let b;t[10]!==v||t[11]!==y?(b=(0,Z.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]=b):b=t[12];let x;t[13]===l.modeLabel?x=t[14]:(x=(0,Z.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:l.modeLabel}),t[13]=l.modeLabel,t[14]=x);let S;t[15]===l.modeInherit?S=t[16]:(S=[`inherit`,l.modeInherit],t[15]=l.modeInherit,t[16]=S);let C;t[17]===l.modeAll?C=t[18]:(C=[`all`,l.modeAll],t[17]=l.modeAll,t[18]=C);let w;t[19]===l.modeAllowlist?w=t[20]:(w=[`allowlist`,l.modeAllowlist],t[19]=l.modeAllowlist,t[20]=w);let T;t[21]===l.modeDenylist?T=t[22]:(T=[`denylist`,l.modeDenylist],t[21]=l.modeDenylist,t[22]=T);let E;t[23]===l.modeOff?E=t[24]:(E=[`off`,l.modeOff],t[23]=l.modeOff,t[24]=E);let D;t[25]!==T||t[26]!==E||t[27]!==S||t[28]!==C||t[29]!==w?(D=[S,C,w,T,E],t[25]=T,t[26]=E,t[27]=S,t[28]=C,t[29]=w,t[30]=D):D=t[30];let O=D,k;t[31]!==o||t[32]!==n||t[33]!==s||t[34]!==O?(k=(0,Z.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:O.map(e=>{let[t,r]=e;return(0,Z.jsx)(`button`,{type:`button`,className:f(`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:o,onClick:()=>s(t),children:r},t)})}),t[31]=o,t[32]=n,t[33]=s,t[34]=O,t[35]=k):k=t[35];let A;t[36]!==k||t[37]!==x?(A=(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[x,k]}),t[36]=k,t[37]=x,t[38]=A):A=t[38];let j;t[39]!==i||t[40]!==m||t[41]!==o||t[42]!==l.emptyCatalog||t[43]!==l.noDescription||t[44]!==l.quickActionsLabel||t[45]!==l.quickClear||t[46]!==l.quickSelectAll||t[47]!==a||t[48]!==c||t[49]!==u||t[50]!==r?(j=u?(0,Z.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Z.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:l.quickActionsLabel}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Z.jsx)(p,{type:`button`,variant:`secondary`,className:q,disabled:o||a||m.length===0,onClick:()=>c(new Set(m)),children:l.quickSelectAll}),(0,Z.jsx)(p,{type:`button`,variant:`secondary`,className:q,disabled:o||a||r.size===0,onClick:()=>c(new Set),children:l.quickClear})]})]}),a?(0,Z.jsx)(ae,{rows:3}):i.length===0?(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:l.emptyCatalog}):(0,Z.jsx)(`ul`,{className:`flex flex-col gap-2.5 text-sm`,children:i.map(e=>{let t=Ae(e),n=r.has(t),i=typeof e.description==`string`?e.description.trim():``,a=i||l.noDescription;return(0,Z.jsx)(`li`,{className:`h-16 shrink-0 overflow-hidden rounded-xl bg-surface-panel/70 px-3 shadow-surface`,children:(0,Z.jsxs)(`label`,{className:`flex h-full cursor-pointer items-center gap-3 text-sm`,children:[(0,Z.jsx)(`input`,{type:`checkbox`,className:`shrink-0 rounded border-edge`,checked:n,disabled:o,onChange:()=>{let e=new Set(r);n?e.delete(t):e.add(t),c(e)},"aria-label":t}),(0,Z.jsxs)(`div`,{className:`min-w-0 flex-1 overflow-hidden`,children:[(0,Z.jsx)(`div`,{className:`truncate font-mono text-xs font-medium text-fg`,title:t,children:t}),(0,Z.jsx)(`p`,{className:f(`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]=m,t[41]=o,t[42]=l.emptyCatalog,t[43]=l.noDescription,t[44]=l.quickActionsLabel,t[45]=l.quickClear,t[46]=l.quickSelectAll,t[47]=a,t[48]=c,t[49]=u,t[50]=r,t[51]=j):j=t[51];let M;return t[52]!==A||t[53]!==j||t[54]!==b?(M=(0,Z.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[b,A,j]}),t[52]=A,t[53]=j,t[54]=b,t[55]=M):M=t[55],M}var Me=[`write_file`,`apply_patch`,`exec_command`,`execute_code`],Ne=[`exec_command`,`execute_code`,`automation`,`extensions`,`bundle-mcp`,`skill_manage`],$=[`send_message`,`send_media`,`text_to_speech`,`create_share`],Pe=[`read_file`,`list_dir`,`grep`,`find`,`web_search`,`web_fetch`,`web_extract`],Fe=[...Me,...$],Ie=[`read_file`,`write_file`,`apply_patch`,`list_dir`,`grep`,`find`,`web_search`,`web_fetch`],Le=[`send_message`,`send_media`];function Re(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 ze(e){let t=(0,Y.c)(100),{builtinToolIds:n,toolPolicies:r,onChange:i,disabled:a,getToolDescription:o,getGroupTitle:s,labels:c}=e,l;t[0]===n?l=t[1]:(l=new Set(n),t[0]=n,t[1]=l);let u=l,d;t[2]!==u||t[3]!==r?(d=Object.entries(r).filter(e=>{let[t]=e;return u.has(t)}).toSorted(Be),t[2]=u,t[3]=r,t[4]=d):d=t[4];let m=d,h;if(t[5]!==u||t[6]!==n){h=[];for(let e of pe){let t=e.toolIds.filter(e=>u.has(e));t.length>0&&h.push({key:e.key,ids:[...t]})}let e;t[8]===n?e=t[9]:(e=ce(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),h.push(e)}t[5]=u,t[6]=n,t[7]=h}else h=t[7];let g=h,_;t[12]!==i||t[13]!==r?(_=(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]=_):_=t[14];let v=_,y;t[15]!==i||t[16]!==r?(y=(e,t)=>{let n=r[e];n&&i({...r,[e]:t(n)})},t[15]=i,t[16]=r,t[17]=y):y=t[17];let b=y,x;t[18]!==u||t[19]!==i?(x=e=>{i(Re(u,e))},t[18]=u,t[19]=i,t[20]=x):x=t[20];let S=x;if(n.length===0){let e;return t[21]===c.emptyBuiltin?e=t[22]:(e=(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:c.emptyBuiltin}),t[21]=c.emptyBuiltin,t[22]=e),e}let C;t[23]===c.quickActionsLabel?C=t[24]:(C=(0,Z.jsx)(`p`,{className:`text-xs font-medium text-fg-muted`,children:c.quickActionsLabel}),t[23]=c.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]!==c.quickClearOverrides||t[29]!==w?(T=(0,Z.jsx)(p,{type:`button`,variant:`secondary`,className:q,disabled:a,onClick:w,children:c.quickClearOverrides}),t[27]=a,t[28]=c.quickClearOverrides,t[29]=w,t[30]=T):T=t[30];let E;t[31]===S?E=t[32]:(E=()=>S([[Me,`deny`]]),t[31]=S,t[32]=E);let D;t[33]!==a||t[34]!==c.quickReadOnlyWorkspace||t[35]!==E?(D=(0,Z.jsx)(p,{type:`button`,variant:`secondary`,className:q,disabled:a,onClick:E,children:c.quickReadOnlyWorkspace}),t[33]=a,t[34]=c.quickReadOnlyWorkspace,t[35]=E,t[36]=D):D=t[36];let O;t[37]===S?O=t[38]:(O=()=>S([[Ne,`deny`]]),t[37]=S,t[38]=O);let k;t[39]!==a||t[40]!==c.quickHighRiskOff||t[41]!==O?(k=(0,Z.jsx)(p,{type:`button`,variant:`secondary`,className:q,disabled:a,onClick:O,children:c.quickHighRiskOff}),t[39]=a,t[40]=c.quickHighRiskOff,t[41]=O,t[42]=k):k=t[42];let A;t[43]===S?A=t[44]:(A=()=>S([[$,`deny`]]),t[43]=S,t[44]=A);let j;t[45]!==a||t[46]!==c.quickNoOutbound||t[47]!==A?(j=(0,Z.jsx)(p,{type:`button`,variant:`secondary`,className:q,disabled:a,onClick:A,children:c.quickNoOutbound}),t[45]=a,t[46]=c.quickNoOutbound,t[47]=A,t[48]=j):j=t[48];let M;t[49]===S?M=t[50]:(M=()=>S([[Pe,`allow`],[Fe,`deny`]]),t[49]=S,t[50]=M);let N;t[51]!==a||t[52]!==c.quickResearchMode||t[53]!==M?(N=(0,Z.jsx)(p,{type:`button`,variant:`secondary`,className:q,disabled:a,onClick:M,children:c.quickResearchMode}),t[51]=a,t[52]=c.quickResearchMode,t[53]=M,t[54]=N):N=t[54];let P;t[55]===S?P=t[56]:(P=()=>S([[Ie,`allow`],[Le,`deny`]]),t[55]=S,t[56]=P);let F;t[57]!==a||t[58]!==c.quickCodingMode||t[59]!==P?(F=(0,Z.jsx)(p,{type:`button`,variant:`secondary`,className:q,disabled:a,onClick:P,children:c.quickCodingMode}),t[57]=a,t[58]=c.quickCodingMode,t[59]=P,t[60]=F):F=t[60];let I;t[61]!==k||t[62]!==j||t[63]!==N||t[64]!==F||t[65]!==T||t[66]!==D?(I=(0,Z.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]=I):I=t[67];let L;t[68]!==I||t[69]!==C?(L=(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[C,I]}),t[68]=I,t[69]=C,t[70]=L):L=t[70];let R;t[71]===c.overrideSummaryTitle?R=t[72]:(R=(0,Z.jsx)(`div`,{className:`text-xs font-medium text-fg-muted`,children:c.overrideSummaryTitle}),t[71]=c.overrideSummaryTitle,t[72]=R);let ee;t[73]!==c.modeAllow||t[74]!==c.modeConfirm||t[75]!==c.modeDeny||t[76]!==c.noOverrides||t[77]!==m?(ee=m.length>0?(0,Z.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-1.5`,children:m.map(e=>{let[t,n]=e;return(0,Z.jsxs)(`span`,{className:f(`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,Z.jsx)(`span`,{className:`font-sans opacity-80`,children:n.mode===`allow`?c.modeAllow:n.mode===`confirm`?c.modeConfirm:c.modeDeny})]},t)})}):(0,Z.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:c.noOverrides}),t[73]=c.modeAllow,t[74]=c.modeConfirm,t[75]=c.modeDeny,t[76]=c.noOverrides,t[77]=m,t[78]=ee):ee=t[78];let te;t[79]!==R||t[80]!==ee?(te=(0,Z.jsxs)(`div`,{className:`rounded-lg bg-surface-panel/70 px-3 py-2 shadow-surface`,children:[R,ee]}),t[79]=R,t[80]=ee,t[81]=te):te=t[81];let z;t[82]!==a||t[83]!==s||t[84]!==o||t[85]!==g||t[86]!==c.inheritedMode||t[87]!==c.maxCallsLabel||t[88]!==c.modeAllow||t[89]!==c.modeConfirm||t[90]!==c.modeDeny||t[91]!==c.timeoutLabel||t[92]!==v||t[93]!==r||t[94]!==b?(z=(0,Z.jsx)(`div`,{className:`flex flex-col gap-5`,children:g.map(e=>{let{key:t,ids:n}=e;return(0,Z.jsxs)(`div`,{children:[(0,Z.jsx)(`h4`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-fg-muted`,children:s(t)}),(0,Z.jsx)(`ul`,{className:`flex flex-col gap-2.5`,children:n.map(e=>{let t=o(e),n=r[e],i=n?n.mode:`inherit`;return(0,Z.jsxs)(`li`,{className:f(`rounded-xl px-3 py-2.5 shadow-surface transition-colors`,i===`inherit`?`bg-surface-panel/50`:`bg-surface-panel`),children:[(0,Z.jsxs)(`div`,{className:`grid gap-2 md:grid-cols-[minmax(0,1fr)_auto] md:items-center`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`font-mono text-xs font-medium text-fg`,children:e}),t?(0,Z.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-fg-muted`,children:t}):null]}),(0,Z.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,Z.jsx)(`button`,{type:`button`,className:f(`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:()=>v(e,t),children:t===`inherit`?c.inheritedMode:t===`allow`?c.modeAllow:t===`confirm`?c.modeConfirm:c.modeDeny},t))})]}),n?(0,Z.jsxs)(`div`,{className:`mt-3 grid gap-2 border-t border-edge-subtle pt-3 sm:grid-cols-2 dark:border-edge`,children:[(0,Z.jsx)(He,{label:c.maxCallsLabel,value:n.limits?.maxCallsPerTurn,disabled:a,onChange:t=>b(e,e=>Ve(e,`maxCallsPerTurn`,t))}),(0,Z.jsx)(He,{label:c.timeoutLabel,value:n.limits?.timeoutMs,disabled:a,onChange:t=>b(e,e=>Ve(e,`timeoutMs`,t))})]}):null]},e)})})]},t)})}),t[82]=a,t[83]=s,t[84]=o,t[85]=g,t[86]=c.inheritedMode,t[87]=c.maxCallsLabel,t[88]=c.modeAllow,t[89]=c.modeConfirm,t[90]=c.modeDeny,t[91]=c.timeoutLabel,t[92]=v,t[93]=r,t[94]=b,t[95]=z):z=t[95];let B;return t[96]!==L||t[97]!==te||t[98]!==z?(B=(0,Z.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[L,te,z]}),t[96]=L,t[97]=te,t[98]=z,t[99]=B):B=t[99],B}function Be(e,t){let[n]=e,[r]=t;return n.localeCompare(r)}function Ve(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 He(e){let t=(0,Y.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,Z.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,Z.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 Ue=[`blank`,`safe-coder`,`read-only`,`low-cost`],We=[{id:`overview`,icon:u},{id:`models`,icon:k},{id:`tools`,icon:R},{id:`skills`,icon:P},{id:`advanced`,icon:re},{id:`impact`,icon:ne}];function Ge(e){return ge(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 qe(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 Ye(e){return{primary:e?.primary??``,fallbacks:[...e?.fallbacks??[]],timeoutMs:e?.timeoutMs?String(e.timeoutMs):``,autoProviderFallback:e?.autoProviderFallback===void 0?``:e.autoProviderFallback?`true`:`false`}}function Xe(){return{imageModel:Je(),imageGenerationModel:Je(),allowFallbacks:``,maxCostTier:``}}function Ze(e){return{imageModel:Ye(e?.models?.imageModel),imageGenerationModel:Ye(e?.models?.imageGenerationModel),allowFallbacks:e?.models?.policy?.allowFallbacks===void 0?``:e.models.policy.allowFallbacks?`true`:`false`,maxCostTier:e?.models?.policy?.maxCostTier??``}}function Qe(e){return{mcp:structuredClone(e?.tools?.mcp),workflows:structuredClone(e?.workflows),boundaries:structuredClone(e?.boundaries),runtime:structuredClone(e?.runtime),locks:structuredClone(e?.locks)}}function $e(e){return{id:e?.id??``,name:e?.name??``,description:e?.description??``,modelRows:Ge(e),modelAdvanced:Ze(e),toolPolicies:Ke(e),skillMode:e?.skills?.mode??`inherit`,skillPick:qe(e),extendsIds:[...e?.extends??[]],advancedPolicy:Qe(e)}}function et(e,t){let n={id:e.id,name:e.name,version:1,usage:[],inherited:{},inheritedSources:{},...t};return{...e,modelRows:Ge(n),modelAdvanced:Ze(n),toolPolicies:Ke(n),skillMode:n.skills?.mode??`inherit`,skillPick:qe(n),extendsIds:[...n.extends??[]],advancedPolicy:Qe(n)}}function tt(e){let t=e.primary.trim();if(!t)return;let n=e.fallbacks.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 nt(e,t){let n=_e(e.modelRows),r=tt(e.modelAdvanced.imageModel),i=tt(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 rt(e){let t=Object.fromEntries(Object.entries(e.toolPolicies).toSorted(([e],[t])=>e.localeCompare(t))),n=e.advancedPolicy.mcp;return Object.keys(t).length>0||n?{builtin:t,...n?{mcp:n}:{}}:null}function it(e){return Object.fromEntries(Object.entries(e??{}).toSorted(([e],[t])=>e.localeCompare(t)))}function at(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 ot(e,t){return{id:e.id.trim(),name:e.name.trim(),description:e.description.trim(),models:nt(e,t),tools:{builtin:it(e.toolPolicies),mcp:e.advancedPolicy.mcp},skills:at(e),extends:[...e.extendsIds].toSorted(),workflows:e.advancedPolicy.workflows,boundaries:e.advancedPolicy.boundaries,runtime:e.advancedPolicy.runtime,locks:e.advancedPolicy.locks}}function st(e){return e?{id:e.id,name:e.name,description:e.description??``,models:e.models??null,tools:{builtin:it(e.tools?.builtin),mcp:e.tools?.mcp},skills:e.skills??null,extends:[...e.extends??[]].toSorted(),workflows:e.workflows,boundaries:e.boundaries,runtime:e.runtime,locks:e.locks}:null}function ct(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 lt(e){return e===void 0?`—`:typeof e==`string`?e:JSON.stringify(e)}function ut(){return{modelAdvanced:Xe(),extendsIds:[],advancedPolicy:{}}}function dt(e,t){return{extends:[...e.extendsIds],models:nt(e,t)??void 0,tools:rt(e)??void 0,skills:at(e)??void 0,workflows:e.advancedPolicy.workflows,boundaries:e.advancedPolicy.boundaries,runtime:e.advancedPolicy.runtime,locks:e.advancedPolicy.locks}}function ft(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`]),...ut()}: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,...ut()}: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,...ut()}:{id:``,name:``,description:``,modelRows:[],toolPolicies:{},skillMode:`inherit`,skillPick:new Set,...ut()}}function pt(){let e=h(_(e=>e.language)),t=e.capabilityPresetsSettings,n=(0,Z.jsx)(p,{asChild:!0,type:`button`,variant:`secondary`,children:(0,Z.jsxs)(a,{to:`/agents`,children:[t.manageAgents,(0,Z.jsx)(A,{className:`size-4`,"aria-hidden":!0})]})}),r=!!g(e=>e.token),{data:s,error:c,isLoading:l,mutate:O}=D(r?`settings-capability-presets`:null,le,{revalidateOnFocus:!1}),{data:j=[],isLoading:F}=D(r?`settings-capability-presets-skills-catalog`:null,N,{revalidateOnFocus:!1}),L=s?.mcpServerIds??[],{data:te=[]}=D(r&&L.length?[`capability-preset-mcp-tools`,...L]:null,()=>fe(L),{revalidateOnFocus:!1}),[V,H]=i(),[U,ce]=(0,X.useState)(``),[pe,ge]=(0,X.useState)(`overview`),[q,J]=(0,X.useState)(()=>ft(`blank`,t)),[_e,Y]=(0,X.useState)(null),[Q,ve]=(0,X.useState)(!1),[be,xe]=(0,X.useState)(null),[Se,Ce]=(0,X.useState)(!1),[we,Te]=(0,X.useState)(null),[De,Oe]=(0,X.useState)(null),ke=s?.presets??[],Ae=s?.defaultPresetId??`default`,Me=ke.find(e=>e.id===Ae)??null,Ne=ke.filter(e=>e.id!==Ae),$=(0,X.useMemo)(()=>ke.find(e=>e.id===U)??ke[0]??null,[ke,U]),Pe=!$||q.id.trim()!==$.id,Fe=!!($&&$.id===Ae),Ie=JSON.stringify(ot(q,$))!==JSON.stringify(st($)),Le=ot(q,$),Re=st($),Be=[Le.id!==Re?.id||Le.name!==Re?.name||Le.description!==Re?.description?t.tabs.overview:``,JSON.stringify(Le.models)===JSON.stringify(Re?.models)?``:t.tabs.models,JSON.stringify(Le.tools)===JSON.stringify(Re?.tools)?``:t.tabs.tools,JSON.stringify(Le.skills)===JSON.stringify(Re?.skills)?``:t.tabs.skills,JSON.stringify({extends:Le.extends,workflows:Le.workflows,boundaries:Le.boundaries,runtime:Le.runtime,locks:Le.locks})===JSON.stringify({extends:Re?.extends,workflows:Re?.workflows,boundaries:Re?.boundaries,runtime:Re?.runtime,locks:Re?.locks})?``:t.tabs.advanced].filter(Boolean),Ve=(0,X.useMemo)(()=>{if(!$||Pe)return null;let e=dt(q,$);return{name:q.name.trim(),description:q.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}},[q,Pe,$]),{data:He,error:Ge,isLoading:Ke}=D(pe===`impact`&&$&&Ve?[`capability-preset-impact-preview`,$.id,JSON.stringify(Ve)]:null,()=>se($.id,Ve),{revalidateOnFocus:!1}),qe=be??(c instanceof Error?c.message:null),Je=V.get(`action`)===`new`||!!V.get(`preset`),Ye=V.get(`action`)===`new`&&_e===null,Xe=Pe?t.newPreset:$?.name??t.editorTitle,Ze=t=>e.agentsSettings.toolsDisableGroups[t],Qe=t=>t in e.agentsSettings.toolDescriptions?e.agentsSettings.toolDescriptions[t]:``;(0,X.useEffect)(()=>{if(!s||Q)return;if(V.get(`action`)===`new`){ce(``),J(ft(`blank`,t)),ge(`overview`);return}let e=V.get(`preset`)?.trim(),n=e?s.presets.find(t=>t.id===e):null;if(n){ce(n.id),J($e(n)),ge(V.get(`tab`)??`overview`);return}$&&(ce($.id),J(e=>e.id===$.id?e:$e($)))},[Q,s,V,$]);function tt(e){Y(null),ce(e.id),J($e(e)),H({preset:e.id},{replace:!0}),ge(`overview`)}function nt(){Y(null),ce(``),J(ft(`blank`,t)),xe(null),H({action:`new`},{replace:!0}),ge(`overview`)}function rt(e){Y(e),J(ft(e,t)),xe(null),ge(`overview`)}function it(){if(_e){let e=ft(_e,t);if(JSON.stringify(ot(q,null))!==JSON.stringify(ot(e,null))&&!window.confirm(t.changeTemplateConfirm))return}Y(null),xe(null)}function at(){!Ye&&Ie&&!window.confirm(t.discardConfirm)||(Ce(!1),Te(null),H({},{replace:!0}),Y(null),xe(null),J($e($)),ge(`overview`))}async function ut(){let e=he(q.modelRows,{invalidId:t.invalidModelRoleId,duplicateId:t.duplicateModelRoleId,invalidModel:t.invalidModelRef});if(e){xe(e),ge(`models`);return}for(let e of[q.modelAdvanced.imageModel,q.modelAdvanced.imageGenerationModel]){if([e.primary,...e.fallbacks].map(e=>e.trim()).filter(Boolean).some(e=>!/^[^/\s]+\/.+/.test(e))){xe(t.invalidModelRef),ge(`models`);return}if(e.timeoutMs.trim()&&(!Number.isInteger(Number(e.timeoutMs))||Number(e.timeoutMs)<=0)){xe(t.advancedPositiveIntegerError),ge(`models`);return}}for(let e of Object.values(q.toolPolicies))if([e.limits?.maxCallsPerTurn,e.limits?.timeoutMs].filter(e=>e!==void 0).some(e=>!Number.isInteger(e)||e<=0)){xe(t.advancedPositiveIntegerError),ge(`tools`);return}ve(!0),xe(null);try{let e=dt(q,$);if(Pe){let t=await me({id:q.id.trim(),name:q.name.trim(),...q.description.trim()?{description:q.description.trim()}:{},...e});await O(t.presets,{revalidate:!1}),ce(t.presetId),Y(null),H({preset:t.presetId},{replace:!0})}else $&&await O(await de($.id,{name:q.name.trim(),description:q.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){xe(e instanceof Error?e.message:t.saveError)}finally{ve(!1)}}async function pt(){if($){ve(!0),xe(null),Te(null);try{await O(await ue($.id),{revalidate:!1}),Ce(!1),ce(``),Y(null),J(ft(`blank`,t)),ge(`overview`),H({},{replace:!0})}catch(e){Te(e instanceof Error?e.message:t.deleteError)}finally{ve(!1)}}}return r?(0,Z.jsxs)(G,{gap:`gap-5`,className:`pb-24`,children:[(0,Z.jsx)(W,{title:t.title,subtitle:t.subtitle,actions:(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center justify-end gap-2`,children:[n,(0,Z.jsxs)(p,{type:`button`,onClick:nt,disabled:Q,children:[(0,Z.jsx)(I,{className:`size-4`,"aria-hidden":!0}),t.newPreset]})]})}),qe?(0,Z.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:qe}):null,l?(0,Z.jsx)(ie,{sections:2}):(0,Z.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[Me?(0,Z.jsxs)(oe,{children:[(0,Z.jsx)(K,{icon:k,title:t.globalDefaultsTitle,subtitle:t.globalDefaultsHint}),(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>tt(Me),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,Z.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-3`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Z.jsx)(`span`,{className:`text-sm font-semibold text-fg`,children:Me.name}),(0,Z.jsx)(`span`,{className:`rounded-full bg-surface-panel px-2 py-0.5 text-[11px] font-medium text-accent`,children:t.globalDefaultsBadge})]}),(0,Z.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-fg-subtle`,children:Me.id})]}),(0,Z.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})]}),Me.description?(0,Z.jsx)(`p`,{className:`mt-3 line-clamp-2 text-xs leading-relaxed text-fg-muted`,children:Me.description}):null,(0,Z.jsx)(`div`,{className:`mt-3 text-xs text-fg-subtle`,children:ct(Me,t)})]})]}):null,(0,Z.jsxs)(oe,{children:[(0,Z.jsx)(K,{icon:k,title:t.listTitle,subtitle:t.listHint}),Ne.length===0?(0,Z.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,Z.jsx)(`p`,{children:t.empty}),(0,Z.jsxs)(p,{type:`button`,variant:`secondary`,onClick:nt,disabled:Q,children:[(0,Z.jsx)(I,{className:`size-4`,"aria-hidden":!0}),t.newPreset]})]}):(0,Z.jsx)(`div`,{className:`grid gap-3 md:grid-cols-2 xl:grid-cols-3`,children:Ne.map(e=>(0,Z.jsxs)(`button`,{type:`button`,onClick:()=>tt(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,Z.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(`div`,{className:`truncate text-sm font-semibold text-fg`,children:e.name}),(0,Z.jsx)(`div`,{className:`mt-1 truncate font-mono text-[11px] text-fg-subtle`,children:e.id})]}),(0,Z.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,Z.jsx)(`p`,{className:`mt-3 line-clamp-2 text-xs leading-relaxed text-fg-muted`,children:e.description}):null,(0,Z.jsx)(`div`,{className:`mt-3 truncate text-xs text-fg-subtle`,children:ct(e,t)})]},e.id))})]})]}),(0,Z.jsx)(E,{open:Je,onOpenChange:e=>{e||at()},children:(0,Z.jsxs)(C,{children:[(0,Z.jsx)(b,{className:f(`xopc-dialog-overlay fixed inset-0 bg-scrim`,y)}),(0,Z.jsx)(w,{ref:Oe,className:f(`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`,v),onOpenAutoFocus:e=>e.preventDefault(),children:(0,Z.jsxs)(o,{layer:`modal`,portalContainer:De,children:[(0,Z.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,Z.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2`,children:[!Ye&&Pe&&_e?(0,Z.jsx)(`button`,{type:`button`,className:f(m,`shrink-0 p-1.5 hover:bg-surface-base`),onClick:it,"aria-label":t.changeTemplate,title:t.changeTemplate,children:(0,Z.jsx)(B,{className:`size-4`,"aria-hidden":!0})}):null,(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[(0,Z.jsx)(T,{className:`truncate text-base font-semibold text-fg`,children:Xe}),(0,Z.jsx)(x,{className:`mt-0.5 truncate text-xs text-fg-muted`,children:Ye?t.templatePickerSubtitle:Pe&&_e?`${t.editorHint} · ${t.basedOnTemplate.replace(`{{template}}`,t.starters[_e].title)}`:Pe?t.editorHint:q.id})]})]}),(0,Z.jsx)(S,{asChild:!0,children:(0,Z.jsx)(`button`,{type:`button`,className:f(m,`shrink-0 p-1.5 hover:bg-surface-base`),"aria-label":t.closeDialog,children:(0,Z.jsx)(ee,{className:`size-4`,"aria-hidden":!0})})})]}),Ye?(0,Z.jsxs)(Z.Fragment,{children:[(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-4 sm:p-5`,children:(0,Z.jsx)(`div`,{className:`mx-auto grid max-w-3xl gap-3 sm:grid-cols-2`,children:Ue.map(e=>(0,Z.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:()=>rt(e),children:[(0,Z.jsxs)(`span`,{className:`flex items-center justify-between gap-3`,children:[(0,Z.jsx)(`span`,{className:`font-medium`,children:t.starters[e].title}),e===`blank`?(0,Z.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,Z.jsx)(`span`,{className:`mt-2 block text-xs leading-relaxed text-fg-muted`,children:t.starters[e].description})]},e))})}),(0,Z.jsx)(`div`,{className:`flex shrink-0 justify-end border-t border-edge-subtle px-4 py-3 dark:border-edge`,children:(0,Z.jsx)(p,{type:`button`,variant:`secondary`,onClick:at,children:t.cancel})})]}):(0,Z.jsxs)(Z.Fragment,{children:[qe?(0,Z.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:qe}):null,(0,Z.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:We.map(({id:e,icon:n})=>(0,Z.jsxs)(`button`,{type:`button`,className:f(`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`,pe===e?`bg-surface-panel text-fg shadow-surface`:`text-fg-muted hover:bg-surface-hover hover:text-fg`),onClick:()=>ge(e),children:[(0,Z.jsx)(n,{className:`size-4`,"aria-hidden":!0}),t.tabs[e]]},e))}),(0,Z.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto p-4`,children:(0,Z.jsxs)(`div`,{className:`w-full`,children:[pe===`overview`?(0,Z.jsxs)(oe,{children:[(0,Z.jsx)(K,{icon:u,title:t.overviewTitle,subtitle:t.overviewHint}),(0,Z.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:t.idLabel}),(0,Z.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:q.id,disabled:Q||!Pe,onChange:e=>J(t=>({...t,id:e.target.value.toLowerCase()})),placeholder:`safe-coder`})]}),!Pe&&$?(0,Z.jsxs)(`div`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:t.versionLabel}),(0,Z.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($.version))})]}):null,(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm sm:col-span-2`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:t.nameLabel}),(0,Z.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:q.name,disabled:Q,onChange:e=>J(t=>({...t,name:e.target.value})),placeholder:t.namePlaceholder})]}),(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm sm:col-span-2`,children:[(0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:t.descriptionLabel}),(0,Z.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:q.description,disabled:Q,onChange:e=>J(t=>({...t,description:e.target.value})),placeholder:t.descriptionPlaceholder})]})]}),(0,Z.jsxs)(`div`,{className:`mt-5 grid gap-2 sm:grid-cols-3`,children:[(0,Z.jsx)(mt,{icon:k,label:t.modelsTitle,value:String(q.modelRows.length)}),(0,Z.jsx)(mt,{icon:R,label:t.toolsTitle,value:String(Object.keys(q.toolPolicies).length)}),(0,Z.jsx)(mt,{icon:P,label:t.skillsTitle,value:t.skillModeLabels[q.skillMode]})]})]}):null,pe===`models`?(0,Z.jsxs)(oe,{children:[(0,Z.jsx)(K,{icon:k,title:t.modelsTitle,subtitle:t.modelsHint}),(0,Z.jsx)(ye,{rows:q.modelRows,onChange:e=>J(t=>({...t,modelRows:e})),disabled:Q,defaultRole:$?.models?.defaultRole,chat:e.chat,labels:{defaultTitle:t.modelDefaultTitle,defaultHint:t.modelDefaultHint,defaultBadge:t.modelDefaultBadge,roleId:t.modelRoleIdLabel,description:t.modelRoleDescriptionLabel,descriptionPlaceholder:t.modelRoleDescriptionPlaceholder,primaryModel:t.modelPrimaryModelLabel,fallbackModels:t.modelFallbackModelsLabel,addFallback:t.modelAddFallback,removeFallback:t.modelRemoveFallback,fallbackPlaceholder:t.modelFallbackPlaceholder,fallbackEmptyHint:t.modelFallbackEmptyHint,moreSettings:t.modelMoreSettings,otherRolesTitle:t.modelOtherRolesTitle,otherRolesHint:t.modelOtherRolesHint,otherRolesEmpty:t.modelOtherRolesEmpty,addTaskModel:t.modelAddTaskModel,customRole:t.modelCustomRole,removeRole:t.removeModelRole,roleIdPlaceholder:`custom-role`,roleNames:t.modelRoleNames,roleDescriptions:t.modelRoleDescriptions}}),(0,Z.jsx)(ht,{value:q.modelAdvanced,onChange:e=>J(t=>({...t,modelAdvanced:e})),disabled:Q,cp:t,chat:e.chat})]}):null,pe===`tools`?(0,Z.jsxs)(oe,{children:[(0,Z.jsx)(K,{icon:R,title:t.toolsTitle,subtitle:t.toolsHint}),(0,Z.jsx)(ze,{builtinToolIds:s?.builtinToolIds??[],toolPolicies:q.toolPolicies,onChange:e=>J(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,maxCallsLabel:t.toolMaxCallsLabel,timeoutLabel:t.toolTimeoutLabel}})]}):null,pe===`skills`?(0,Z.jsxs)(oe,{children:[(0,Z.jsx)(K,{icon:P,title:t.skillsTitle,subtitle:t.skillsHint}),(0,Z.jsx)(je,{mode:q.skillMode,selected:q.skillPick,catalog:j,loading:F,disabled:Q,onModeChange:e=>J(t=>({...t,skillMode:e})),onSelectedChange:e=>J(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,pe===`advanced`?(0,Z.jsxs)(oe,{children:[(0,Z.jsx)(K,{icon:re,title:t.advancedTitle,subtitle:t.advancedHint}),(0,Z.jsx)(Ee,{extendsIds:q.extendsIds,onExtendsChange:e=>J(t=>({...t,extendsIds:e})),presetOptions:ke.filter(e=>e.id!==$?.id&&e.id!==Ae),inherited:JSON.stringify(q.extendsIds)===JSON.stringify($?.extends??[])?$?.inherited:void 0,inheritedSources:JSON.stringify(q.extendsIds)===JSON.stringify($?.extends??[])?$?.inheritedSources:void 0,mcpServerIds:s?.mcpServerIds??[],mcpTools:te,workflows:s?.workflows??[],policy:q.advancedPolicy,onPolicyChange:e=>J(t=>({...t,advancedPolicy:e})),rawPolicy:dt(q,$),onRawPolicyChange:e=>J(t=>et(t,e)),disabled:Q,labels:{inheritanceTitle:t.advancedInheritanceTitle,inheritanceHint:t.advancedInheritanceHint,inheritanceEmpty:t.advancedInheritanceEmpty,inheritanceAvailable:t.advancedInheritanceAvailable,inheritanceAdd:t.advancedInheritanceAdd,inheritanceRemove:t.advancedInheritanceRemove,inheritanceMoveUp:t.advancedInheritanceMoveUp,inheritanceMoveDown:t.advancedInheritanceMoveDown,compose:t.advancedCompose,inherit:t.advancedInherit,cancel:t.cancel,mcpTitle:t.advancedMcpTitle,mcpHint:t.advancedMcpHint,noMcp:t.advancedNoMcp,workflowsTitle:t.advancedWorkflowsTitle,workflowsHint:t.advancedWorkflowsHint,defaultWorkflow:t.advancedDefaultWorkflow,allowedWorkflows:t.advancedAllowedWorkflows,runtimeTitle:t.advancedRuntimeTitle,runtimeHint:t.advancedRuntimeHint,timeoutMinutes:t.advancedTimeoutMinutes,maxTurns:t.advancedMaxTurns,maxFailures:t.advancedMaxFailures,maxCalls:t.toolMaxCallsLabel,boundariesTitle:t.advancedBoundariesTitle,boundariesHint:t.advancedBoundariesHint,confirmRules:t.advancedConfirmRules,forbiddenRules:t.advancedForbiddenRules,escalationRules:t.advancedEscalationRules,onePerLine:t.advancedOnePerLine,governanceTitle:t.advancedGovernanceTitle,governanceHint:t.advancedGovernanceHint,locksLabel:t.advancedLocksLabel,rawTitle:t.advancedRawTitle,rawHint:t.advancedRawHint,rawOpen:t.advancedRawOpen,rawApply:t.advancedRawApply,rawInvalid:t.advancedRawInvalid,modeAllow:t.toolModes.allow,modeConfirm:t.toolModes.confirm,modeDeny:t.toolModes.deny,readonlyOnly:t.toolScopeReadonly}})]}):null,pe===`impact`?(0,Z.jsxs)(oe,{children:[(0,Z.jsx)(K,{icon:ne,title:t.usageTitle,subtitle:t.usageHint}),(0,Z.jsxs)(`div`,{className:`mb-4 rounded-lg bg-surface-panel/70 px-3 py-2 shadow-surface`,children:[(0,Z.jsx)(`div`,{className:`text-xs font-medium text-fg-muted`,children:t.changePreviewTitle}),(0,Z.jsx)(`p`,{className:`mt-1 text-sm text-fg`,children:Be.length>0?t.changePreviewSections.replace(`{{sections}}`,Be.join(`、`)):t.changePreviewEmpty})]}),Pe?null:(0,Z.jsxs)(`div`,{className:`mb-4`,children:[(0,Z.jsx)(`div`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-fg-muted`,children:t.effectiveChangePreviewTitle}),Ke?(0,Z.jsx)(ae,{rows:2}):Ge?(0,Z.jsx)(`p`,{className:`rounded-lg bg-surface-panel/60 px-3 py-2 text-sm text-red-600 shadow-surface dark:text-red-400`,children:t.effectiveChangePreviewError}):He?.agents.length?(0,Z.jsx)(`div`,{className:`grid gap-3`,children:He.agents.map(e=>(0,Z.jsxs)(`div`,{className:`rounded-lg bg-surface-panel/80 px-3 py-2 shadow-surface`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.agentName||e.agentId}),(0,Z.jsx)(`div`,{className:`mt-2 grid gap-2`,children:e.diffs.map(e=>(0,Z.jsxs)(`div`,{className:`grid gap-1 text-xs sm:grid-cols-[minmax(0,12rem)_minmax(0,1fr)]`,children:[(0,Z.jsx)(`div`,{className:`truncate font-mono text-fg-muted`,children:e.path}),(0,Z.jsxs)(`div`,{className:`min-w-0 text-fg`,children:[(0,Z.jsx)(`span`,{className:`break-all text-fg-muted`,children:lt(e.before)}),(0,Z.jsx)(`span`,{className:`px-1.5 text-fg-subtle`,"aria-hidden":!0,children:`→`}),(0,Z.jsx)(`span`,{className:`break-all`,children:lt(e.after)})]})]},e.path))})]},e.agentId))}):(0,Z.jsx)(`p`,{className:`rounded-lg bg-surface-panel/60 px-3 py-2 text-sm text-fg-muted shadow-surface`,children:t.effectiveChangePreviewEmpty})]}),$?.usage.length?(0,Z.jsx)(`div`,{className:`grid gap-2`,children:$.usage.map(e=>(0,Z.jsxs)(`div`,{className:`rounded-lg bg-surface-panel/80 px-3 py-2 shadow-surface`,children:[(0,Z.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.agentName||e.agentId}),(0,Z.jsx)(`div`,{className:`mt-1 font-mono text-[11px] text-fg-muted`,children:e.agentId}),(0,Z.jsx)(`div`,{className:`mt-1 text-[11px] text-fg-subtle`,children:e.direct?t.usageDirect:t.usageIndirect})]},e.agentId))}):(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.noUsage})]}):null]})}),(0,Z.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,Z.jsxs)(`div`,{className:`min-w-0 text-sm`,children:[(0,Z.jsx)(`div`,{className:`font-medium text-fg`,children:Ie?t.unsavedTitle:t.noUnsavedTitle}),(0,Z.jsx)(`div`,{className:`text-xs text-fg-muted`,children:Ie?($?.usage.length??0)>0?t.unsavedImpact.replace(`{{count}}`,String($?.usage.length??0)):t.unsavedNoImpact:t.noUnsavedHint})]}),(0,Z.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[Ie?(0,Z.jsx)(p,{type:`button`,variant:`secondary`,disabled:Q,onClick:()=>J($e($)),children:t.discard}):null,$&&!Fe?(0,Z.jsxs)(p,{type:`button`,variant:`secondary`,disabled:Q,onClick:()=>{Te(null),Ce(!0)},children:[(0,Z.jsx)(z,{className:`size-4`,"aria-hidden":!0}),t.delete]}):null,(0,Z.jsxs)(p,{type:`button`,disabled:Q||!q.id.trim()||!q.name.trim()||!Ie,onClick:()=>void ut(),children:[(0,Z.jsx)(M,{className:`size-4`,"aria-hidden":!0}),t.savePreset]})]})]})]})]})})]})}),(0,Z.jsx)(E,{open:Se,onOpenChange:e=>{Q||(Ce(e),e||Te(null))},children:(0,Z.jsxs)(C,{children:[(0,Z.jsx)(b,{className:f(`xopc-dialog-overlay fixed inset-0 bg-scrim`,y)}),(0,Z.jsxs)(w,{className:f(`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`,v),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,Z.jsxs)(`div`,{className:`border-b border-edge-subtle px-4 py-3 dark:border-edge`,children:[(0,Z.jsx)(T,{className:`text-base font-semibold text-fg`,children:t.deleteDialogTitle}),(0,Z.jsx)(x,{className:`mt-1 text-sm leading-relaxed text-fg-muted`,children:$?t.deleteConfirm.replace(`{{name}}`,$.name):t.deleteConfirmFallback})]}),we?(0,Z.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:we}):null,(0,Z.jsxs)(`div`,{className:`flex justify-end gap-2 px-4 py-3`,children:[(0,Z.jsx)(p,{type:`button`,variant:`secondary`,disabled:Q,onClick:()=>Ce(!1),children:t.cancel}),(0,Z.jsxs)(p,{type:`button`,disabled:Q||!$,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 pt(),children:[Q?(0,Z.jsx)(d,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Z.jsx)(z,{className:`size-4`,"aria-hidden":!0}),Q?t.deleting:t.delete]})]})]})]})})]}):(0,Z.jsxs)(G,{gap:`gap-3`,children:[(0,Z.jsx)(W,{title:t.title,actions:n}),(0,Z.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.needToken})]})}function mt(e){let t=(0,Y.c)(10),{icon:n,label:r,value:i}=e,a;t[0]===n?a=t[1]:(a=(0,Z.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,Z.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,Z.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,Z.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 ht(e){let t=(0,Y.c)(121),{value:n,onChange:r,disabled:i,cp:a,chat:o}=e,l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l={revalidateOnFocus:!1},t[0]=l):l=t[0];let{data:u,isLoading:d,error:f}=D(`capability-preset-image-generation-models`,te,l),p;t[1]===u?p=t[2]:(p=(u??[]).filter(vt).flatMap(_t),t[1]=u,t[2]=p);let m=p,h;t[3]===m?h=t[4]:(h=new Set(m.map(gt)),t[3]=m,t[4]=h);let g=h,_,v;t[5]!==g||t[6]!==u||t[7]!==r||t[8]!==n?(_=()=>{if(!u)return;let e=n.imageGenerationModel,t=g.has(e.primary)?e.primary:``,i=e.fallbacks.filter(e=>g.has(e));t===e.primary&&i.length===e.fallbacks.length||r({...n,imageGenerationModel:{...e,primary:t,fallbacks:i}})},v=[g,u,r,n],t[5]=g,t[6]=u,t[7]=r,t[8]=n,t[9]=_,t[10]=v):(_=t[9],v=t[10]),(0,X.useEffect)(_,v);let y;t[11]!==r||t[12]!==n?(y=(e,t)=>{r({...n,[e]:t})},t[11]=r,t[12]=n,t[13]=y):y=t[13];let b=y,x;t[14]===a.modelSpecializedTitle?x=t[15]:(x=(0,Z.jsx)(`h4`,{className:`text-sm font-semibold text-fg`,children:a.modelSpecializedTitle}),t[14]=a.modelSpecializedTitle,t[15]=x);let S;t[16]!==a.modelNotSet||t[17]!==a.modelSpecializedSummary||t[18]!==n.imageGenerationModel.primary||t[19]!==n.imageModel.primary?(S=a.modelSpecializedSummary.replace(`{{image}}`,n.imageModel.primary||a.modelNotSet).replace(`{{generation}}`,n.imageGenerationModel.primary||a.modelNotSet),t[16]=a.modelNotSet,t[17]=a.modelSpecializedSummary,t[18]=n.imageGenerationModel.primary,t[19]=n.imageModel.primary,t[20]=S):S=t[20];let C;t[21]===S?C=t[22]:(C=(0,Z.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-fg-muted`,children:S}),t[21]=S,t[22]=C);let w;t[23]!==x||t[24]!==C?(w=(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[x,C]}),t[23]=x,t[24]=C,t[25]=w):w=t[25];let T;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(T=(0,Z.jsx)(O,{className:`size-4 shrink-0 text-fg-subtle transition-transform group-open:rotate-180`,"aria-hidden":!0}),t[26]=T):T=t[26];let E;t[27]===w?E=t[28]:(E=(0,Z.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center justify-between gap-3 p-4`,children:[w,T]}),t[27]=w,t[28]=E);let k;t[29]===b?k=t[30]:(k=e=>b(`imageModel`,e),t[29]=b,t[30]=k);let A;t[31]!==o||t[32]!==a||t[33]!==i||t[34]!==k||t[35]!==n.imageModel?(A=(0,Z.jsx)(yt,{title:a.imageUnderstandingTitle,value:n.imageModel,onChange:k,disabled:i,cp:a,chat:o,capabilitiesFilter:`vision`}),t[31]=o,t[32]=a,t[33]=i,t[34]=k,t[35]=n.imageModel,t[36]=A):A=t[36];let j;t[37]===b?j=t[38]:(j=e=>b(`imageGenerationModel`,e),t[37]=b,t[38]=j);let M;t[39]===a.modelImageSettingsLink?M=t[40]:(M={label:a.modelImageSettingsLink,path:`/settings/capabilities/image`},t[39]=a.modelImageSettingsLink,t[40]=M);let N;t[41]!==o||t[42]!==a||t[43]!==i||t[44]!==m||t[45]!==f||t[46]!==d||t[47]!==j||t[48]!==M||t[49]!==n.imageGenerationModel?(N=(0,Z.jsx)(yt,{title:a.imageGenerationTitle,value:n.imageGenerationModel,onChange:j,disabled:i,cp:a,chat:o,models:m,modelsLoading:d,modelsError:f,noMatches:a.modelNoConfiguredImageModels,settingsFooterLink:M}),t[41]=o,t[42]=a,t[43]=i,t[44]=m,t[45]=f,t[46]=d,t[47]=j,t[48]=M,t[49]=n.imageGenerationModel,t[50]=N):N=t[50];let P;t[51]!==A||t[52]!==N?(P=(0,Z.jsxs)(`div`,{className:`grid gap-3 border-t border-edge-subtle p-4 dark:border-edge lg:grid-cols-2`,children:[A,N]}),t[51]=A,t[52]=N,t[53]=P):P=t[53];let F;t[54]!==E||t[55]!==P?(F=(0,Z.jsxs)(`details`,{className:`group rounded-xl border border-edge bg-surface-base`,children:[E,P]}),t[54]=E,t[55]=P,t[56]=F):F=t[56];let I;t[57]===a.modelAdvancedTitle?I=t[58]:(I=(0,Z.jsx)(`h4`,{className:`text-sm font-semibold text-fg`,children:a.modelAdvancedTitle}),t[57]=a.modelAdvancedTitle,t[58]=I);let L;t[59]===a.modelAdvancedHint?L=t[60]:(L=(0,Z.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-fg-muted`,children:a.modelAdvancedHint}),t[59]=a.modelAdvancedHint,t[60]=L);let R;t[61]!==I||t[62]!==L?(R=(0,Z.jsxs)(`div`,{className:`min-w-0`,children:[I,L]}),t[61]=I,t[62]=L,t[63]=R):R=t[63];let ee;t[64]===Symbol.for(`react.memo_cache_sentinel`)?(ee=(0,Z.jsx)(O,{className:`size-4 shrink-0 text-fg-subtle transition-transform group-open:rotate-180`,"aria-hidden":!0}),t[64]=ee):ee=t[64];let z;t[65]===R?z=t[66]:(z=(0,Z.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center justify-between gap-3 p-4`,children:[R,ee]}),t[65]=R,t[66]=z);let B;t[67]===a.modelAllowFallbacksLabel?B=t[68]:(B=(0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:a.modelAllowFallbacksLabel}),t[67]=a.modelAllowFallbacksLabel,t[68]=B);let ne;t[69]!==r||t[70]!==n?(ne=e=>r({...n,allowFallbacks:e.target.value}),t[69]=r,t[70]=n,t[71]=ne):ne=t[71];let re;t[72]===a.policyInherit?re=t[73]:(re=(0,Z.jsx)(c,{value:``,children:a.policyInherit}),t[72]=a.policyInherit,t[73]=re);let V;t[74]===a.policyEnabled?V=t[75]:(V=(0,Z.jsx)(c,{value:`true`,children:a.policyEnabled}),t[74]=a.policyEnabled,t[75]=V);let H;t[76]===a.policyDisabled?H=t[77]:(H=(0,Z.jsx)(c,{value:`false`,children:a.policyDisabled}),t[76]=a.policyDisabled,t[77]=H);let U;t[78]!==i||t[79]!==ne||t[80]!==re||t[81]!==V||t[82]!==H||t[83]!==n.allowFallbacks?(U=(0,Z.jsxs)(s,{value:n.allowFallbacks,disabled:i,side:`top`,onChange:ne,children:[re,V,H]}),t[78]=i,t[79]=ne,t[80]=re,t[81]=V,t[82]=H,t[83]=n.allowFallbacks,t[84]=U):U=t[84];let W;t[85]!==B||t[86]!==U?(W=(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[B,U]}),t[85]=B,t[86]=U,t[87]=W):W=t[87];let G;t[88]===a.modelMaxCostTierLabel?G=t[89]:(G=(0,Z.jsx)(`span`,{className:`font-medium text-fg`,children:a.modelMaxCostTierLabel}),t[88]=a.modelMaxCostTierLabel,t[89]=G);let ie;t[90]!==r||t[91]!==n?(ie=e=>r({...n,maxCostTier:e.target.value}),t[90]=r,t[91]=n,t[92]=ie):ie=t[92];let ae;t[93]===a.policyInherit?ae=t[94]:(ae=(0,Z.jsx)(c,{value:``,children:a.policyInherit}),t[93]=a.policyInherit,t[94]=ae);let K;t[95]===a.costTierLow?K=t[96]:(K=(0,Z.jsx)(c,{value:`low`,children:a.costTierLow}),t[95]=a.costTierLow,t[96]=K);let oe;t[97]===a.costTierMedium?oe=t[98]:(oe=(0,Z.jsx)(c,{value:`medium`,children:a.costTierMedium}),t[97]=a.costTierMedium,t[98]=oe);let se;t[99]===a.costTierHigh?se=t[100]:(se=(0,Z.jsx)(c,{value:`high`,children:a.costTierHigh}),t[99]=a.costTierHigh,t[100]=se);let ce;t[101]!==i||t[102]!==ie||t[103]!==ae||t[104]!==K||t[105]!==oe||t[106]!==se||t[107]!==n.maxCostTier?(ce=(0,Z.jsxs)(s,{value:n.maxCostTier,disabled:i,side:`top`,onChange:ie,children:[ae,K,oe,se]}),t[101]=i,t[102]=ie,t[103]=ae,t[104]=K,t[105]=oe,t[106]=se,t[107]=n.maxCostTier,t[108]=ce):ce=t[108];let le;t[109]!==G||t[110]!==ce?(le=(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[G,ce]}),t[109]=G,t[110]=ce,t[111]=le):le=t[111];let ue;t[112]!==W||t[113]!==le?(ue=(0,Z.jsxs)(`div`,{className:`grid gap-3 border-t border-edge-subtle p-4 dark:border-edge sm:grid-cols-2`,children:[W,le]}),t[112]=W,t[113]=le,t[114]=ue):ue=t[114];let de;t[115]!==z||t[116]!==ue?(de=(0,Z.jsxs)(`details`,{className:`group rounded-xl border border-edge bg-surface-base`,children:[z,ue]}),t[115]=z,t[116]=ue,t[117]=de):de=t[117];let fe;return t[118]!==F||t[119]!==de?(fe=(0,Z.jsxs)(`div`,{className:`mt-5 grid gap-3 border-t border-edge-subtle pt-5 dark:border-edge`,children:[F,de]}),t[118]=F,t[119]=de,t[120]=fe):fe=t[120],fe}function gt(e){return e.id}function _t(e){return e.models.map(t=>({id:`${e.id}/${t}`,name:t,provider:e.label}))}function vt(e){return e.configured||e.credentialMode!==`api-key`}function yt(e){let t=(0,Y.c)(109),{title:n,value:r,onChange:i,disabled:a,cp:o,chat:l,capabilitiesFilter:u,models:d,modelsLoading:f,modelsError:m,noMatches:h,settingsFooterLink:g}=e,_;t[0]!==i||t[1]!==r?(_=(e,t)=>{i({...r,fallbacks:r.fallbacks.map((n,r)=>r===e?t:n)})},t[0]=i,t[1]=r,t[2]=_):_=t[2];let v=_,y;t[3]===n?y=t[4]:(y=(0,Z.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:n}),t[3]=n,t[4]=y);let b=r.primary||o.modelNotSet,x;t[5]===b?x=t[6]:(x=(0,Z.jsx)(`span`,{className:`max-w-48 truncate font-mono text-xs text-fg-muted`,children:b}),t[5]=b,t[6]=x);let S;t[7]!==y||t[8]!==x?(S=(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2 px-3 py-2.5`,children:[y,x]}),t[7]=y,t[8]=x,t[9]=S):S=t[9];let C;t[10]===o.modelToolPrimaryLabel?C=t[11]:(C=(0,Z.jsx)(`div`,{className:`text-xs text-fg-muted`,children:o.modelToolPrimaryLabel}),t[10]=o.modelToolPrimaryLabel,t[11]=C);let w=h??l.modelNoMatches,T;t[12]!==i||t[13]!==r?(T=e=>i({...r,primary:e}),t[12]=i,t[13]=r,t[14]=T):T=t[14];let E;t[15]!==u||t[16]!==l.modelPlaceholder||t[17]!==l.modelSearchPlaceholder||t[18]!==a||t[19]!==d||t[20]!==m||t[21]!==f||t[22]!==g||t[23]!==w||t[24]!==T||t[25]!==r.primary?(E=(0,Z.jsx)(L,{value:r.primary,disabled:a,placeholder:l.modelPlaceholder,searchPlaceholder:l.modelSearchPlaceholder,noMatches:w,models:d,modelsLoading:f,modelsError:m,settingsFooterLink:g,capabilitiesFilter:u,className:`w-full max-w-none`,contentAlign:`start`,onChange:T}),t[15]=u,t[16]=l.modelPlaceholder,t[17]=l.modelSearchPlaceholder,t[18]=a,t[19]=d,t[20]=m,t[21]=f,t[22]=g,t[23]=w,t[24]=T,t[25]=r.primary,t[26]=E):E=t[26];let D;t[27]!==o.modelClearSelection||t[28]!==a||t[29]!==i||t[30]!==r?(D=r.primary?(0,Z.jsx)(p,{type:`button`,variant:`secondary`,className:`shrink-0 px-2`,disabled:a,"aria-label":o.modelClearSelection,onClick:()=>i({...r,primary:``}),children:(0,Z.jsx)(ee,{className:`size-4`,strokeWidth:1.75})}):null,t[27]=o.modelClearSelection,t[28]=a,t[29]=i,t[30]=r,t[31]=D):D=t[31];let O;t[32]!==E||t[33]!==D?(O=(0,Z.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] gap-2`,children:[E,D]}),t[32]=E,t[33]=D,t[34]=O):O=t[34];let k;t[35]!==O||t[36]!==C?(k=(0,Z.jsxs)(`div`,{className:`grid gap-1`,children:[C,O]}),t[35]=O,t[36]=C,t[37]=k):k=t[37];let A;t[38]===o.modelToolFallbacksLabel?A=t[39]:(A=(0,Z.jsx)(`div`,{className:`text-xs text-fg-muted`,children:o.modelToolFallbacksLabel}),t[38]=o.modelToolFallbacksLabel,t[39]=A);let j;t[40]!==i||t[41]!==r?(j=()=>i({...r,fallbacks:[...r.fallbacks,``]}),t[40]=i,t[41]=r,t[42]=j):j=t[42];let M;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(M=(0,Z.jsx)(I,{className:`size-3.5`,strokeWidth:1.75}),t[43]=M):M=t[43];let N;t[44]!==o.modelAddFallback||t[45]!==a||t[46]!==j?(N=(0,Z.jsxs)(p,{type:`button`,variant:`secondary`,className:`h-7 gap-1 px-2 text-xs`,disabled:a,onClick:j,children:[M,o.modelAddFallback]}),t[44]=o.modelAddFallback,t[45]=a,t[46]=j,t[47]=N):N=t[47];let P;t[48]!==A||t[49]!==N?(P=(0,Z.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[A,N]}),t[48]=A,t[49]=N,t[50]=P):P=t[50];let F;t[51]!==u||t[52]!==l.modelNoMatches||t[53]!==l.modelSearchPlaceholder||t[54]!==o.modelFallbackEmptyHint||t[55]!==o.modelFallbackPlaceholder||t[56]!==o.modelRemoveFallback||t[57]!==a||t[58]!==d||t[59]!==m||t[60]!==f||t[61]!==h||t[62]!==i||t[63]!==g||t[64]!==v||t[65]!==r?(F=r.fallbacks.length>0?(0,Z.jsx)(`div`,{className:`grid gap-1.5`,children:r.fallbacks.map((e,t)=>(0,Z.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] gap-2`,children:[(0,Z.jsx)(L,{value:e,disabled:a,placeholder:o.modelFallbackPlaceholder,searchPlaceholder:l.modelSearchPlaceholder,noMatches:h??l.modelNoMatches,models:d,modelsLoading:f,modelsError:m,settingsFooterLink:g,capabilitiesFilter:u,className:`w-full max-w-none`,contentAlign:`start`,onChange:e=>v(t,e)}),(0,Z.jsx)(p,{type:`button`,variant:`secondary`,className:`shrink-0 px-2`,disabled:a,"aria-label":o.modelRemoveFallback,onClick:()=>i({...r,fallbacks:r.fallbacks.filter((e,n)=>n!==t)}),children:(0,Z.jsx)(z,{className:`size-4`,strokeWidth:1.75})})]},`fallback-${t}`))}):(0,Z.jsx)(`div`,{className:`rounded-lg bg-surface-base px-3 py-2 text-xs text-fg-muted`,children:o.modelFallbackEmptyHint}),t[51]=u,t[52]=l.modelNoMatches,t[53]=l.modelSearchPlaceholder,t[54]=o.modelFallbackEmptyHint,t[55]=o.modelFallbackPlaceholder,t[56]=o.modelRemoveFallback,t[57]=a,t[58]=d,t[59]=m,t[60]=f,t[61]=h,t[62]=i,t[63]=g,t[64]=v,t[65]=r,t[66]=F):F=t[66];let R;t[67]!==P||t[68]!==F?(R=(0,Z.jsxs)(`div`,{className:`grid gap-1.5`,children:[P,F]}),t[67]=P,t[68]=F,t[69]=R):R=t[69];let te;t[70]!==i||t[71]!==r?(te=e=>i({...r,timeoutMs:e.target.value}),t[70]=i,t[71]=r,t[72]=te):te=t[72];let B;t[73]!==a||t[74]!==te||t[75]!==r.timeoutMs?(B=(0,Z.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:te}),t[73]=a,t[74]=te,t[75]=r.timeoutMs,t[76]=B):B=t[76];let ne;t[77]!==o.toolTimeoutLabel||t[78]!==B?(ne=(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1 text-xs text-fg-muted`,children:[o.toolTimeoutLabel,B]}),t[77]=o.toolTimeoutLabel,t[78]=B,t[79]=ne):ne=t[79];let re;t[80]!==i||t[81]!==r?(re=e=>i({...r,autoProviderFallback:e.target.value}),t[80]=i,t[81]=r,t[82]=re):re=t[82];let V;t[83]===o.policyInherit?V=t[84]:(V=(0,Z.jsx)(c,{value:``,children:o.policyInherit}),t[83]=o.policyInherit,t[84]=V);let H;t[85]===o.policyEnabled?H=t[86]:(H=(0,Z.jsx)(c,{value:`true`,children:o.policyEnabled}),t[85]=o.policyEnabled,t[86]=H);let U;t[87]===o.policyDisabled?U=t[88]:(U=(0,Z.jsx)(c,{value:`false`,children:o.policyDisabled}),t[87]=o.policyDisabled,t[88]=U);let W;t[89]!==a||t[90]!==re||t[91]!==V||t[92]!==H||t[93]!==U||t[94]!==r.autoProviderFallback?(W=(0,Z.jsxs)(s,{value:r.autoProviderFallback,disabled:a,side:`top`,onChange:re,children:[V,H,U]}),t[89]=a,t[90]=re,t[91]=V,t[92]=H,t[93]=U,t[94]=r.autoProviderFallback,t[95]=W):W=t[95];let G;t[96]!==o.modelAutoProviderFallbackLabel||t[97]!==W?(G=(0,Z.jsxs)(`label`,{className:`flex flex-col gap-1 text-xs text-fg-muted`,children:[o.modelAutoProviderFallbackLabel,W]}),t[96]=o.modelAutoProviderFallbackLabel,t[97]=W,t[98]=G):G=t[98];let ie;t[99]!==ne||t[100]!==G?(ie=(0,Z.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[ne,G]}),t[99]=ne,t[100]=G,t[101]=ie):ie=t[101];let ae;t[102]!==k||t[103]!==R||t[104]!==ie?(ae=(0,Z.jsxs)(`div`,{className:`grid gap-3 border-t border-edge-subtle p-3 dark:border-edge`,children:[k,R,ie]}),t[102]=k,t[103]=R,t[104]=ie,t[105]=ae):ae=t[105];let K;return t[106]!==ae||t[107]!==S?(K=(0,Z.jsxs)(`div`,{className:`rounded-lg bg-surface-panel/70 shadow-surface`,children:[S,ae]}),t[106]=ae,t[107]=S,t[108]=K):K=t[108],K}export{pt as CapabilityPresetsSettingsPanel};
@@ -1 +1 @@
1
- import{r as e,s as t}from"./locale-store-xULEcFVs.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-CnamlR07.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};