@xopcai/xopc 0.0.241 → 0.0.242

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 (116) 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-CLnbVm9G.js → activity-store-MU5XrVv8.js} +1 -1
  4. package/dist/gateway/static/root/assets/{agent-avatar-dicebear-DuBewmbW.js → agent-avatar-dicebear-B_Wc0wuL.js} +1 -1
  5. package/dist/gateway/static/root/assets/{agent-defaults-settings-panel-DbdgX6AA.js → agent-defaults-settings-panel-Cf7U2aUi.js} +1 -1
  6. package/dist/gateway/static/root/assets/{agents-BX3uRVm4.js → agents-Ce9oOnwE.js} +1 -1
  7. package/dist/gateway/static/root/assets/{api-DjBZe303.js → api-DLyc8BQp.js} +1 -1
  8. package/dist/gateway/static/root/assets/{app-management-settings-panel-D8evZyFQ.js → app-management-settings-panel-CACOOS-a.js} +1 -1
  9. package/dist/gateway/static/root/assets/{appearance-settings-B-iul0RG.js → appearance-settings-DB5gEQhN.js} +1 -1
  10. package/dist/gateway/static/root/assets/{apps-page-CoZd_cZu.js → apps-page-BaTFOCmR.js} +1 -1
  11. package/dist/gateway/static/root/assets/{attachment-load-Cfk1lwBo.js → attachment-load-CYnYIyLr.js} +1 -1
  12. package/dist/gateway/static/root/assets/{automations-page-BTSGvaeS.js → automations-page-ChTflpmA.js} +1 -1
  13. package/dist/gateway/static/root/assets/{automations-workspace-C8RRKT-a.js → automations-workspace-DK6EreCr.js} +1 -1
  14. package/dist/gateway/static/root/assets/{binary-plugins-ChZyZK45.js → binary-plugins-BjbLfNwG.js} +1 -1
  15. package/dist/gateway/static/root/assets/{block-editor-DCH9b2Ht.js → block-editor-DgAs5aJc.js} +1 -1
  16. package/dist/gateway/static/root/assets/{browser-settings-page-D1GPwIfx.js → browser-settings-page-CHStw5UW.js} +1 -1
  17. package/dist/gateway/static/root/assets/{browser-workflow-inputs-jvfcgFG-.js → browser-workflow-inputs-DGQxD0vD.js} +1 -1
  18. package/dist/gateway/static/root/assets/{browser-workflows-page-DrHW7XNi.js → browser-workflows-page-B9gfdd7L.js} +1 -1
  19. package/dist/gateway/static/root/assets/{capabilities-settings-panel-CrXB1Q-l.js → capabilities-settings-panel-JGH6Kfkr.js} +6 -6
  20. package/dist/gateway/static/root/assets/{channels-settings-DWMSYaNZ.js → channels-settings-YkUaaWkY.js} +1 -1
  21. package/dist/gateway/static/root/assets/{channels-status-swr-CC9MFway.js → channels-status-swr-TkU42f-W.js} +1 -1
  22. package/dist/gateway/static/root/assets/{chat-terminal-dock-DeeZrVbV.js → chat-terminal-dock-CWMPcnoN.js} +1 -1
  23. package/dist/gateway/static/root/assets/{connectors-page-DXTl1fNB.js → connectors-page-BI0FG3gA.js} +1 -1
  24. package/dist/gateway/static/root/assets/{cron-expression-CiqQOeQ3.js → cron-expression-3h3rR0cf.js} +1 -1
  25. package/dist/gateway/static/root/assets/{date-picker-CGAMGPfU.js → date-picker-Bz1sLBEx.js} +1 -1
  26. package/dist/gateway/static/root/assets/{dependency-picker-CxWeUTsc.js → dependency-picker-p9DWR8uU.js} +1 -1
  27. package/dist/gateway/static/root/assets/{desktop-pet-C3QmYO75.js → desktop-pet-D1TDB_gR.js} +1 -1
  28. package/dist/gateway/static/root/assets/{desktop-pet-settings-CAADkWYy.js → desktop-pet-settings-DWPZpoB7.js} +1 -1
  29. package/dist/gateway/static/root/assets/{extension-debug-page-FQXjDJ8P.js → extension-debug-page-BrRbK2rJ.js} +1 -1
  30. package/dist/gateway/static/root/assets/{extension-page-BJE1D5Ji.js → extension-page-CD65czfS.js} +1 -1
  31. package/dist/gateway/static/root/assets/{extension-settings-page-5Ik2tNry.js → extension-settings-page-BRDDKhpi.js} +1 -1
  32. package/dist/gateway/static/root/assets/{gateway-config-api-cTj71t2a.js → gateway-config-api-CjbBsr5M.js} +1 -1
  33. package/dist/gateway/static/root/assets/{gateway-config-swr-Bxe_R-JH.js → gateway-config-swr-HT7sLeO9.js} +1 -1
  34. package/dist/gateway/static/root/assets/{gateway-settings-KXBUjNcx.js → gateway-settings-BQjmfYD4.js} +1 -1
  35. package/dist/gateway/static/root/assets/{gateway-startup-retry-DJG-I0wW.js → gateway-startup-retry-iBCtaAuT.js} +1 -1
  36. package/dist/gateway/static/root/assets/{heartbeat-settings-C8cVzIcs.js → heartbeat-settings-BzZxLgrw.js} +1 -1
  37. package/dist/gateway/static/root/assets/{home-page-NdWtBda5.js → home-page--9fKq0mL.js} +1 -1
  38. package/dist/gateway/static/root/assets/{image-generation-api-Dc_ojQuj.js → image-generation-api-dj9TNEn2.js} +1 -1
  39. package/dist/gateway/static/root/assets/index-D499B1qS.css +2 -0
  40. package/dist/gateway/static/root/assets/{index-7i2P3312.js → index-J3FsIvTs.js} +8 -8
  41. package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-pOKl7blR.js → keyboard-shortcuts-settings-BEnuEPD3.js} +1 -1
  42. package/dist/gateway/static/root/assets/{local-app-workbench-page-C_j_od5f.js → local-app-workbench-page-FqG00zS1.js} +1 -1
  43. package/dist/gateway/static/root/assets/{local-apps-page-Bi6wwKgm.js → local-apps-page-DXQtppWq.js} +1 -1
  44. package/dist/gateway/static/root/assets/{locale-store-C5wr3_pc.js → locale-store-DVzTJSj2.js} +1 -1
  45. package/dist/gateway/static/root/assets/{logs-page-D6PDZEVP.js → logs-page-c6CfZ8PA.js} +1 -1
  46. package/dist/gateway/static/root/assets/{management-settings-DGlVizWi.js → management-settings-DIpBMWrA.js} +1 -1
  47. package/dist/gateway/static/root/assets/{markdown-split-CXP5zBx_.js → markdown-split-BFHyGwNF.js} +1 -1
  48. package/dist/gateway/static/root/assets/{markdown-view-D6LxlDxr.js → markdown-view-DR3yVwtV.js} +1 -1
  49. package/dist/gateway/static/root/assets/{media-plugins-BsENGLr2.js → media-plugins-BjjMxC5_.js} +1 -1
  50. package/dist/gateway/static/root/assets/{mobile-pairing-wizard-DcEz7qcX.js → mobile-pairing-wizard-CHnXZTwb.js} +1 -1
  51. package/dist/gateway/static/root/assets/models-hub-cache-DiXjKuuY.js +1 -0
  52. package/dist/gateway/static/root/assets/{notes-page-D2EqpDyo.js → notes-page-BbvtelJa.js} +1 -1
  53. package/dist/gateway/static/root/assets/notes-workbench-DIR37b-K.js +4 -0
  54. package/dist/gateway/static/root/assets/{oauth-api-C5NVcsKE.js → oauth-api-BB-VYJ5j.js} +1 -1
  55. package/dist/gateway/static/root/assets/{product-open-page-DMhf1rdz.js → product-open-page-CRm9Q66h.js} +1 -1
  56. package/dist/gateway/static/root/assets/{project-detail-page-DDHi0Y4Q.js → project-detail-page-DHiLTiRW.js} +1 -1
  57. package/dist/gateway/static/root/assets/{projects-page-CVMFKpmu.js → projects-page-God7NCcI.js} +1 -1
  58. package/dist/gateway/static/root/assets/{registry-api-FXdFaoWM.js → registry-api-DXsR8oGN.js} +1 -1
  59. package/dist/gateway/static/root/assets/{remote-access-hub-B74aErBY.js → remote-access-hub-YpF0-mx2.js} +1 -1
  60. package/dist/gateway/static/root/assets/runtime-tools-settings-panel-DoEfLjPB.js +5 -0
  61. package/dist/gateway/static/root/assets/{schema-form-BUzdHWx6.js → schema-form-BsqpbBDv.js} +1 -1
  62. package/dist/gateway/static/root/assets/{sessions-page-D2wmGNZE.js → sessions-page-CP8O1TxR.js} +1 -1
  63. package/dist/gateway/static/root/assets/settings-advanced-gate-DzdbK3j9.js +1 -0
  64. package/dist/gateway/static/root/assets/{settings-page-C0OBLqpu.js → settings-page-CE7ZcCTK.js} +1 -1
  65. package/dist/gateway/static/root/assets/{setup-status-panel-NpLQkFCh.js → setup-status-panel-CGlne9i0.js} +1 -1
  66. package/dist/gateway/static/root/assets/{share-preview-page-BtbPYaYC.js → share-preview-page-Bn0qMX8V.js} +1 -1
  67. package/dist/gateway/static/root/assets/{shares-settings-rf8f1OGq.js → shares-settings-B7NeVl4g.js} +1 -1
  68. package/dist/gateway/static/root/assets/skill-reload-api-DDTmi4a7.js +1 -0
  69. package/dist/gateway/static/root/assets/{skills-page-CYk8pN97.js → skills-page-dRkeYh5P.js} +1 -1
  70. package/dist/gateway/static/root/assets/{skills-page.utils-DGjnz-NG.js → skills-page.utils--q8p7MAn.js} +1 -1
  71. package/dist/gateway/static/root/assets/{system-settings-panel-DmCRSvtd.js → system-settings-panel-C0ZCuCM4.js} +1 -1
  72. package/dist/gateway/static/root/assets/{task-detail-page-6a2RdDl2.js → task-detail-page-yiMzii2b.js} +1 -1
  73. package/dist/gateway/static/root/assets/{theme-store-DUko1ZnE.js → theme-store-Cth-eChE.js} +1 -1
  74. package/dist/gateway/static/root/assets/{tunnel-api-Chfiba_x.js → tunnel-api-CC3jOB4n.js} +1 -1
  75. package/dist/gateway/static/root/assets/{use-autosave-W_P8Kiv4.js → use-autosave-PSV89QuQ.js} +1 -1
  76. package/dist/gateway/static/root/assets/user-context-page-Vtwg7fQc.js +1 -0
  77. package/dist/gateway/static/root/assets/{voice-api-key-field-BZD0j1jc.js → voice-api-key-field-DXWdJ8cR.js} +1 -1
  78. package/dist/gateway/static/root/assets/{voice-config-api-BO6A8V3Z.js → voice-config-api-BDoeXgww.js} +1 -1
  79. package/dist/gateway/static/root/assets/{work-discovery-overlay-BfwEoOGL.js → work-discovery-overlay-BV_Jj5iD.js} +1 -1
  80. package/dist/gateway/static/root/assets/{workflow-run-setup-panel-X7Z5_lRX.js → workflow-run-setup-panel-DNHbWGPq.js} +1 -1
  81. package/dist/gateway/static/root/assets/{workflows-page-BklMzkg8.js → workflows-page-BkFIbMrz.js} +2 -2
  82. package/dist/gateway/static/root/index.html +11 -11
  83. package/dist/package.js +1 -1
  84. package/dist/src/agent/agent-manager.js +1 -0
  85. package/dist/src/agent/skills/installer.d.ts +1 -0
  86. package/dist/src/agent/skills/installer.js +9 -6
  87. package/dist/src/agent/tools/factory.d.ts +2 -0
  88. package/dist/src/agent/tools/factory.js +5 -1
  89. package/dist/src/config/schema.js +5 -3
  90. package/dist/src/extensions/install.js +1 -1
  91. package/dist/src/gateway/hono/routes/runtime-tools.js +7 -1
  92. package/dist/src/gateway/hono/routes/voice.js +1 -1
  93. package/dist/src/runtime-tools/archive.js +17 -3
  94. package/dist/src/runtime-tools/command.d.ts +1 -0
  95. package/dist/src/runtime-tools/command.js +29 -8
  96. package/dist/src/runtime-tools/environment.d.ts +1 -0
  97. package/dist/src/runtime-tools/environment.js +11 -16
  98. package/dist/src/runtime-tools/install-lock.d.ts +1 -1
  99. package/dist/src/runtime-tools/install-lock.js +34 -21
  100. package/dist/src/runtime-tools/manager.d.ts +1 -1
  101. package/dist/src/runtime-tools/manager.js +99 -64
  102. package/dist/src/runtime-tools/manifest-store.d.ts +2 -0
  103. package/dist/src/runtime-tools/manifest-store.js +29 -8
  104. package/dist/src/runtime-tools/paths.d.ts +2 -1
  105. package/dist/src/runtime-tools/paths.js +19 -8
  106. package/dist/src/runtime-tools/probe.d.ts +2 -0
  107. package/dist/src/runtime-tools/probe.js +13 -1
  108. package/dist/src/runtime-tools/prune.js +21 -7
  109. package/package.json +2 -2
  110. package/dist/gateway/static/root/assets/index-DTo3IcbW.css +0 -2
  111. package/dist/gateway/static/root/assets/models-hub-cache-Y7GUjxHx.js +0 -1
  112. package/dist/gateway/static/root/assets/notes-workbench-Bu0a83Oj.js +0 -4
  113. package/dist/gateway/static/root/assets/runtime-tools-settings-panel-Bv-akndY.js +0 -5
  114. package/dist/gateway/static/root/assets/settings-advanced-gate-CYCCUMEt.js +0 -1
  115. package/dist/gateway/static/root/assets/skill-reload-api-BkvclZ_o.js +0 -1
  116. package/dist/gateway/static/root/assets/user-context-page-SeOHP6XO.js +0 -1
@@ -1,7 +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,l as a,p as o,r as s,t as c}from"./chunk-KS7C4IRE-BaASWQor.js";import{n as l,r as u,t as d}from"./popover-select-DrILF6mR.js";import{t as f}from"./circle-check-C23XjkUj.js";import{t as p}from"./cloud-C4-yfnnk.js";import{t as m}from"./external-link-DjqjBmc3.js";import{t as h}from"./eye-CABVeTq0.js";import{t as g}from"./globe-DSSGFWFn.js";import{t as _}from"./loader-circle-CifKLtgG.js";import{t as v}from"./pencil-DmIY3Oa-.js";import{t as y}from"./plus-Q2yW6OE7.js";import{t as b}from"./search-DA7gz22f.js";import{t as x}from"./x-B_N4OPjy.js";import{t as S}from"./cn-JdwAhgNB.js";import{t as C}from"./button-CSEbl4zT.js";import{a as w,o as T,s as E}from"./form-field-width-DJw_jULe.js";import{n as D,t as O}from"./interaction-BmQogeqz.js";import{n as k}from"./is-masked-secret-DOkL5b_X.js";import{t as A}from"./messages-_tYhRAHD.js";import{a as j,i as M,n as N,r as P,s as F}from"./locale-store-C5wr3_pc.js";import{t as I}from"./skeleton-BwbyijEw.js";import{i as L,o as R}from"./settings-shell-dialog-layer-BU3UuiJr.js";import{a as z,i as B,n as V,o as H,r as U,s as ee,t as W}from"./dist-BPoKqzeH.js";import{i as G}from"./vendor-swr-BIWyz7Rc.js";import{n as K,r as q}from"./gateway-config-swr-Bxe_R-JH.js";import{n as te,t as ne}from"./registry-api-FXdFaoWM.js";import{i as J,n as Y,r as X,t as re}from"./models-hub-cache-Y7GUjxHx.js";import{a as ie,i as ae,n as oe,o as se,r as ce,t as le}from"./oauth-api-C5NVcsKE.js";import{$t as ue,El as de,Es as fe,Go as pe,Gt as me,Ic as he,Jo as ge,Jt as _e,Kn as ve,Kt as ye,Mc as be,Ms as xe,Na as Se,Pa as Ce,Qo as we,Qs as Te,Qt as Ee,Ul as De,Un as Oe,Vl as ke,Ws as Ae,Xt as je,Yt as Me,Zo as Ne,Zs as Pe,Zt as Fe,_c as Ie,an as Le,cn as Re,dn as ze,en as Be,es as Ve,fc as He,fn as Ue,gs as We,hn as Ge,hs as Ke,in as qe,ln as Je,mn as Ye,nn as Xe,on as Ze,os as Qe,pn as $e,qo as et,qt as tt,rn as nt,sn as rt,ss as it,ta as at,tn as ot,zs as st}from"./index-7i2P3312.js";import{n as ct,r as lt}from"./settings-page-layout-BRQNel6r.js";import{t as ut}from"./settings-loading-skeleton-CAmWMaOT.js";import{n as dt,t as ft}from"./settings-form-section-DjWzRk4z.js";import{n as pt,r as mt,t as ht}from"./oauth-authorization-window-Cdolr2wE.js";import{n as gt,t as _t}from"./use-autosave-W_P8Kiv4.js";import{a as vt,c as yt,d as bt,i as xt,l as St,n as Ct,p as wt,r as Tt,s as Et,t as Dt,u as Ot}from"./voice-config-api-BO6A8V3Z.js";import{t as kt}from"./voice-api-key-field-BZD0j1jc.js";import{t as At}from"./page-tabs-BaEQMYm_.js";import{t as jt}from"./settings-advanced-gate-CYCCUMEt.js";import{a as Mt,i as Nt,n as Pt,o as Ft,r as It,t as Lt}from"./image-generation-api-Dc_ojQuj.js";var Z=n(),Q=e(t(),1),$=r(),Rt={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 必须使用“名称: 值”格式,每行一个。`}},zt=`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 Bt(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 Vt(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 Ht({open:e,onOpenChange:t,provider:n,configured:r,language:i,onSaved:a}){let o=Rt[i],[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(``),[m,g]=(0,Q.useState)(`bearer`),[v,b]=(0,Q.useState)(`x-api-key`),[w,T]=(0,Q.useState)(``),[E,D]=(0,Q.useState)(``),[O,A]=(0,Q.useState)(``),[j,M]=(0,Q.useState)(`/images/generations`),[N,P]=(0,Q.useState)(`/images/edits`),[F,I]=(0,Q.useState)(``),[G,K]=(0,Q.useState)(``),[q,te]=(0,Q.useState)([Bt()]),[ne,J]=(0,Q.useState)(``),[Y,X]=(0,Q.useState)(),[re,ie]=(0,Q.useState)(!1),[ae,oe]=(0,Q.useState)(),[se,ce]=(0,Q.useState)(),[le,ue]=(0,Q.useState)();(0,Q.useEffect)(()=>{if(!e)return;let t=n?.imageGeneration;c(n?.providerId??``),u(t?.name??``),p(n?.baseUrl??``),g(t?.auth.type??`bearer`),b(t?.auth.type===`header`?t.auth.headerName:`x-api-key`),T(r?`••••••••••••`:``),D(t?.apiKeyUrl??``),A(t?.documentationUrl??``),M(t?.paths?.generations??`/images/generations`),P(t?.paths?.edits??`/images/edits`),I(t?.network?.allowedHosts.join(`
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{d as i,l as a,p as o,r as s,t as c}from"./chunk-KS7C4IRE-BaASWQor.js";import{n as l,r as u,t as d}from"./popover-select-DrILF6mR.js";import{t as f}from"./circle-check-C23XjkUj.js";import{t as p}from"./cloud-C4-yfnnk.js";import{t as m}from"./external-link-DjqjBmc3.js";import{t as h}from"./eye-CABVeTq0.js";import{t as g}from"./globe-DSSGFWFn.js";import{t as _}from"./loader-circle-CifKLtgG.js";import{t as v}from"./pencil-DmIY3Oa-.js";import{t as y}from"./plus-Q2yW6OE7.js";import{t as b}from"./search-DA7gz22f.js";import{t as x}from"./x-B_N4OPjy.js";import{t as S}from"./cn-JdwAhgNB.js";import{t as C}from"./button-CSEbl4zT.js";import{a as w,o as T,s as E}from"./form-field-width-DJw_jULe.js";import{n as D,t as O}from"./interaction-BmQogeqz.js";import{n as k}from"./is-masked-secret-DOkL5b_X.js";import{t as A}from"./messages-_tYhRAHD.js";import{a as j,i as M,n as N,r as P,s as F}from"./locale-store-DVzTJSj2.js";import{t as I}from"./skeleton-BwbyijEw.js";import{i as L,o as R}from"./settings-shell-dialog-layer-BU3UuiJr.js";import{a as z,i as B,n as V,o as H,r as U,s as ee,t as W}from"./dist-BPoKqzeH.js";import{i as G}from"./vendor-swr-BIWyz7Rc.js";import{n as K,r as q}from"./gateway-config-swr-HT7sLeO9.js";import{n as te,t as ne}from"./registry-api-DXsR8oGN.js";import{i as J,n as Y,r as X,t as re}from"./models-hub-cache-DiXjKuuY.js";import{a as ie,i as ae,n as oe,o as se,r as ce,t as le}from"./oauth-api-BB-VYJ5j.js";import{$t as ue,El as de,Es as fe,Go as pe,Gt as me,Ic as he,Jo as ge,Jt as _e,Kn as ve,Kt as ye,Mc as be,Ms as xe,Na as Se,Pa as Ce,Qo as we,Qs as Te,Qt as Ee,Ul as De,Un as Oe,Vl as ke,Wl as Ae,Ws as je,Xt as Me,Yt as Ne,Zo as Pe,Zs as Fe,Zt as Ie,_c as Le,an as Re,cn as ze,dn as Be,en as Ve,es as He,fc as Ue,fn as We,gs as Ge,hn as Ke,hs as qe,in as Je,ln as Ye,mn as Xe,nn as Ze,on as Qe,os as $e,pn as et,qo as tt,qt as nt,rn as rt,sn as it,ss as at,ta as ot,tn as st,zs as ct}from"./index-J3FsIvTs.js";import{n as lt,r as ut}from"./settings-page-layout-BRQNel6r.js";import{t as dt}from"./settings-loading-skeleton-CAmWMaOT.js";import{n as ft,t as pt}from"./settings-form-section-DjWzRk4z.js";import{n as mt,r as ht,t as gt}from"./oauth-authorization-window-Cdolr2wE.js";import{n as _t,t as vt}from"./use-autosave-PSV89QuQ.js";import{a as yt,c as bt,d as xt,i as St,l as Ct,n as wt,p as Tt,r as Et,s as Dt,t as Ot,u as kt}from"./voice-config-api-BDoeXgww.js";import{t as At}from"./voice-api-key-field-DXWdJ8cR.js";import{t as jt}from"./page-tabs-BaEQMYm_.js";import{t as Mt}from"./settings-advanced-gate-DzdbK3j9.js";import{a as Nt,i as Pt,n as Ft,o as It,r as Lt,t as Rt}from"./image-generation-api-dj9TNEn2.js";var Z=n(),Q=e(t(),1),$=r(),zt={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 必须使用“名称: 值”格式,每行一个。`}},Bt=`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 Vt(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 Ht(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 Ut({open:e,onOpenChange:t,provider:n,configured:r,language:i,onSaved:a}){let o=zt[i],[s,c]=(0,Q.useState)(``),[l,u]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(``),[m,g]=(0,Q.useState)(`bearer`),[v,b]=(0,Q.useState)(`x-api-key`),[w,T]=(0,Q.useState)(``),[E,D]=(0,Q.useState)(``),[O,A]=(0,Q.useState)(``),[j,M]=(0,Q.useState)(`/images/generations`),[N,P]=(0,Q.useState)(`/images/edits`),[F,I]=(0,Q.useState)(``),[G,K]=(0,Q.useState)(``),[q,te]=(0,Q.useState)([Vt()]),[ne,J]=(0,Q.useState)(``),[Y,X]=(0,Q.useState)(),[re,ie]=(0,Q.useState)(!1),[ae,oe]=(0,Q.useState)(),[se,ce]=(0,Q.useState)(),[le,ue]=(0,Q.useState)();(0,Q.useEffect)(()=>{if(!e)return;let t=n?.imageGeneration;c(n?.providerId??``),u(t?.name??``),p(n?.baseUrl??``),g(t?.auth.type??`bearer`),b(t?.auth.type===`header`?t.auth.headerName:`x-api-key`),T(r?`••••••••••••`:``),D(t?.apiKeyUrl??``),A(t?.documentationUrl??``),M(t?.paths?.generations??`/images/generations`),P(t?.paths?.edits??`/images/edits`),I(t?.network?.allowedHosts.join(`
3
3
  `)??``),K(Object.entries(n?.headers??{}).map(([e,t])=>`${e}: ${t}`).join(`
4
- `)),te(t?.models.map(Bt)??[Bt()]),J(t?.defaultModel??``),ce(void 0),X(void 0),ie(!1),oe(void 0),ue(void 0)},[r,e,n]);let de=(0,Q.useMemo)(()=>q.filter(e=>e.id.trim()).map(e=>({value:e.id.trim(),label:e.name.trim()||e.id.trim()})),[q]),fe=(e,t)=>{te(n=>n.map((n,r)=>r===e?{...n,...t}:n))},pe=()=>{let e=s.trim(),t=q.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=ne||t[0]?.id;if(!n||!t.some(e=>e.id===n))throw Error(o.required);let r;try{r=Vt(G)}catch{throw Error(o.invalidHeaders)}return{providerId:e,input:{baseUrl:f.trim(),...r?{headers:r}:{},imageGeneration:{api:`openai-images`,name:l.trim(),...O.trim()?{documentationUrl:O.trim()}:{},...E.trim()?{apiKeyUrl:E.trim()}:{},defaultModel:n,auth:m===`header`?{type:`header`,headerName:v.trim()}:{type:m},paths:{...j.trim()?{generations:j.trim()}:{},...N.trim()?{edits:N.trim()}:{}},...F.trim()?{network:{allowedHosts:F.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 Nt(e.providerId,e.input),m!==`none`&&w.trim()&&!k(w)&&await Mt(e.providerId,w.trim()),await a(e.providerId),e},he=async()=>{X(`save`),oe(void 0),ce(void 0);try{await me(),T(m===`none`?``:`••••••••••••`),ce(o.saved)}catch(e){oe(e instanceof Error?e.message:String(e))}finally{X(void 0)}},ge=async()=>{X(`test`),oe(void 0),ce(void 0),ue(void 0);try{let e=await me();ue((await Ft(e.providerId,e.input.imageGeneration.defaultModel)).images[0]?.dataUrl),ce(o.testReady)}catch(e){oe(e instanceof Error?e.message:String(e))}finally{X(void 0)}},_e=async()=>{if(n){if(!re){ie(!0);return}X(`delete`),oe(void 0);try{await Lt(n.providerId),await a(),t(!1)}catch(e){oe(e instanceof Error?e.message:String(e))}finally{X(void 0)}}};return(0,$.jsx)(W,{open:e,onOpenChange:t,children:(0,$.jsxs)(H,{children:[(0,$.jsx)(z,{className:S(`xopc-dialog-overlay fixed inset-0 bg-scrim`,R)}),(0,$.jsxs)(U,{className:S(`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`,L),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)(ee,{className:`font-semibold text-fg`,children:n?o.editTitle:o.addTitle}),(0,$.jsx)(B,{className:`mt-1 text-sm text-fg-muted`,children:o.intro})]}),(0,$.jsx)(V,{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)(x,{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:zt}),(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:zt})]})]}),(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:zt})]}),(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:m,options:[{value:`bearer`,label:o.bearer},{value:`header`,label:o.header},{value:`none`,label:o.none}],placeholder:o.auth,allowEmpty:!1,onChange:e=>g(e),triggerClassName:`mt-1.5`})]}),m===`header`?(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.headerName,(0,$.jsx)(`input`,{value:v,onChange:e=>b(e.target.value),className:zt})]}):null]}),m===`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}),E.trim()?(0,$.jsxs)(`a`,{href:E.trim(),target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent hover:underline`,children:[o.openKeyPage,(0,$.jsx)(De,{className:`size-3.5`})]}):null]}),(0,$.jsx)(Ve,{id:`custom-image-api-key`,value:w,onChange:e=>T(k(w)?e.replace(/^•+/,``):e),labels:{show:o.show,hide:o.hide,copy:o.copy,copied:o.copied},reveal:()=>Ge(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:E,onChange:e=>D(e.target.value),placeholder:`https://…`,className:zt})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.docsUrl,(0,$.jsx)(`input`,{value:O,onChange:e=>A(e.target.value),placeholder:`https://…`,className:zt})]})]}),(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:j,onChange:e=>M(e.target.value),className:zt})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.editsPath,(0,$.jsx)(`input`,{value:N,onChange:e=>P(e.target.value),className:zt})]})]}),(0,$.jsxs)(`label`,{className:`mt-4 block text-xs font-medium text-fg-muted`,children:[o.allowedHosts,(0,$.jsx)(`textarea`,{value:F,onChange:e=>I(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:G,onChange:e=>K(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)(C,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,onClick:()=>te(e=>[...e,Bt()]),children:[(0,$.jsx)(y,{className:`size-4`}),o.addModel]})]}),(0,$.jsxs)(`label`,{className:`block text-xs font-medium text-fg-muted`,children:[o.defaultModel,(0,$.jsx)(d,{value:ne||de[0]?.value||``,options:de,placeholder:o.defaultModel,allowEmpty:!1,onChange:J,triggerClassName:`mt-1.5 max-w-sm`})]}),q.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=>fe(t,{id:e.target.value}),placeholder:`image-1`,className:zt})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.modelName,(0,$.jsx)(`input`,{value:e.name,onChange:e=>fe(t,{name:e.target.value}),className:zt})]})]}),(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=>fe(t,{maxCount:e.target.value}),className:zt})]}),(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=>fe(t,{defaultCount:e.target.value}),className:zt})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.defaultSize,(0,$.jsx)(`input`,{value:e.defaultSize,onChange:e=>fe(t,{defaultSize:e.target.value}),placeholder:`1024x1024`,className:zt})]}),(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=>fe(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=>fe(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=>fe(t,{editEnabled:e.target.checked})}),o.edit]}),(0,$.jsxs)(`button`,{type:`button`,disabled:q.length===1,onClick:()=>te(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)(We,{className:`size-3.5`}),o.remove]})]})]},t))]}),le?(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)(h,{className:`size-4`}),o.testReady]}),(0,$.jsx)(`img`,{src:le,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,ae?(0,$.jsx)(`p`,{className:`rounded-lg bg-red-500/10 px-3 py-2 text-sm text-red-600 dark:text-red-400`,children:ae}):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)(C,{variant:`secondary`,className:`border-red-500/30 text-red-600 hover:bg-red-500/10 dark:text-red-400`,disabled:!!Y,onClick:()=>void _e(),children:[Y===`delete`?(0,$.jsx)(_,{className:`size-4 animate-spin`}):(0,$.jsx)(We,{className:`size-4`}),re?o.confirmDelete:o.delete]}):null,(0,$.jsxs)(`div`,{className:`ml-auto flex gap-2`,children:[(0,$.jsx)(V,{asChild:!0,children:(0,$.jsx)(C,{variant:`secondary`,children:o.cancel})}),(0,$.jsxs)(C,{variant:`secondary`,disabled:!!Y,onClick:()=>void ge(),children:[Y===`test`?(0,$.jsx)(_,{className:`size-4 animate-spin`}):null,Y===`test`?o.testing:o.test]}),(0,$.jsxs)(C,{variant:`primary`,disabled:!!Y,onClick:()=>void he(),children:[Y===`save`?(0,$.jsx)(_,{className:`size-4 animate-spin`}):null,Y===`save`?o.saving:o.save]})]})]})]})]})})}var Ut=`••••••••••••`,Wt={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 Gt(e){let t=await j(P(`/api/agents/${encodeURIComponent(e)}/image-generation`));if(!t.payload)throw Error(`Invalid agent image generation response`);return t.payload}function Kt(e){let t=e?.indexOf(`/`)??-1;return t>0?e.slice(0,t):void 0}function qt(e){let t=e?.indexOf(`/`)??-1;return t>0?e.slice(t+1):void 0}function Jt(e){return Object.fromEntries(e.configFields.map(t=>[t.key,e.config[t.key]??(t.required?t.options?.[0]?.value??``:``)]))}function Yt(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(Xt),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 Xt(e){return{value:e.value,label:e.label}}function Zt(){let e=(0,Z.c)(2),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(I,{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(Qt)}),(0,$.jsx)(I,{className:`h-64 rounded-xl`})]}),e[1]=n):n=e[1],n}function Qt(e,t){return(0,$.jsx)(I,{className:`h-24 rounded-xl`},t)}function $t(){let e=N(e=>e.language),t=Wt[e],n=A(e),r=!!F(e=>e.token),[i,a]=(0,Q.useState)(``),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(``),[u,p]=(0,Q.useState)(``),[m,h]=(0,Q.useState)({}),[g,v]=(0,Q.useState)(!1),[b,x]=(0,Q.useState)(),[S,w]=(0,Q.useState)(!1),[T,E]=(0,Q.useState)(!1),[D,O]=(0,Q.useState)(),{data:M,isLoading:I,error:L}=G(r?`image-generation-agents`:null,ve,{revalidateOnFocus:!1}),{data:R,isLoading:z,error:B,mutate:V}=G(r?P(`/api/image-generation/catalog`):null,It,{revalidateOnFocus:!1}),{data:H,isLoading:U,error:ee,mutate:W}=G(r?P(`/api/image-generation/custom-providers`):null,Pt,{revalidateOnFocus:!1});(0,Q.useEffect)(()=>{!M||i||a(M.defaultId||M.agents[0]?.id||``)},[i,M]);let{data:K,isLoading:q,error:te,mutate:ne}=G(r&&i?[`agent-image-generation`,i]:null,()=>Gt(i),{revalidateOnFocus:!1});(0,Q.useEffect)(()=>{if(!R||!K)return;let e=Kt(K.model?.primary),t=R.find(t=>t.id===e)??R.find(e=>e.configured)??R[0];t&&(s(t.id),l(t.id===e&&qt(K.model?.primary)||t.defaultModel),p(t.configured?Ut:``),h(Jt(t)))},[K,R]),(0,Q.useEffect)(()=>{x(void 0)},[i]);let J=R?.find(e=>e.id===o),Y=J?J.apiKeyUrl??ye(J.id,e)[0]?.href:void 0,X=(0,Q.useMemo)(()=>(M?.agents??[]).map(e=>({value:e.id,label:Oe(e,n.agentsSettings)})),[M?.agents,n.agentsSettings]),re=(0,Q.useMemo)(()=>(J?.models??[]).map(e=>({value:e,label:e})),[J?.models]),ie=K?.model?.primary,ae=!!(i&&J&&c&&(J.credentialMode!==`api-key`||J.configured||u.trim())&&J.configFields.every(e=>!e.required||m[e.key]?.trim()));if(!r)return(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.connect});if(I||z||U||q)return(0,$.jsx)(Zt,{});if(L||B||ee||te||!R||!M||!H)return(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:t.loadError});let oe=e=>{s(e.id),l(e.defaultModel),p(e.configured?Ut:``),h(Jt(e)),x(void 0)},se=()=>{O(void 0),E(!0)},ce=()=>{let e=H.find(e=>e.providerId===J?.id);e&&(O(e),E(!0))},le=async e=>{let[t,n]=await Promise.all([W(),V()]);if(e&&n?.some(t=>t.id===e)){let r=n.find(t=>t.id===e);s(r.id),l(r.defaultModel),p(r.configured?Ut:``),h(Jt(r)),O(t?.find(t=>t.providerId===e))}},ue=async()=>{if(!(!J||!ae)){v(!0),x(void 0),w(!1);try{let e=await j(P(`/api/agents/${encodeURIComponent(i)}/image-generation/setup`),{method:`POST`,body:JSON.stringify({providerId:J.id,modelId:c,...u.trim()&&!k(u)?{apiKey:u.trim()}:{},providerConfig:Object.fromEntries(Object.entries(m).filter(([,e])=>e.trim()))})});if(!e.payload)throw Error(`Invalid setup response`);await Promise.all([ne(e.payload.agent,{revalidate:!1}),V(e.payload.providers,{revalidate:!1})]),p(Ut),w(!0)}catch(e){x(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)(he,{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:X,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)(C,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,onClick:se,children:[(0,$.jsx)(y,{className:`size-4`}),t.addService]})]}),(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 xl:grid-cols-3`,children:R.map(e=>{let n=e.id===o,r=e.id===Kt(ie);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>oe(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)(f,{className:`size-3.5`}):(0,$.jsx)(be,{className:`size-3.5`}),e.configured||e.credentialMode!==`api-key`?t.configured:t.needsKey]})]},e.id)})})]}),J?(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:re,placeholder:t.selectModel,allowEmpty:!1,onChange:l,triggerClassName:`mt-1.5`})]}),J.configFields.filter(e=>e.required).map(e=>(0,$.jsx)(Yt,{field:e,value:m[e.key]??``,onChange:t=>h(n=>({...n,[e.key]:t}))},e.key))]}),J.source===`custom`?(0,$.jsx)(`div`,{className:`mt-4 flex justify-end`,children:(0,$.jsxs)(C,{variant:`secondary`,onClick:ce,children:[(0,$.jsx)(st,{className:`size-4`}),t.manageService]})}):null,J.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}),Y?(0,$.jsxs)(`a`,{href:Y,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs font-medium text-accent hover:underline`,children:[t.getApiKey,(0,$.jsx)(De,{className:`size-3.5`,"aria-hidden":`true`})]}):null]}),(0,$.jsx)(Ve,{id:`image-generation-api-key`,value:u,onChange:e=>p(k(u)?e.replace(/^•+/,``):e),placeholder:J.configured?t.existingKey:t.needsKey,labels:{show:t.show,hide:t.hide,copy:t.copy,copied:t.copied},reveal:()=>Ge(J.id).then(e=>e.apiKey),loadFailedLabel:t.revealFailed,notInConfigFile:t.keyNotRevealable,className:`mt-1.5`,autoComplete:`new-password`},J.id),(0,$.jsx)(`span`,{className:`mt-1.5 block font-normal leading-relaxed text-fg-subtle`,children:J.configured?t.savedKey:t.apiKeyHint})]}):null,J.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)(xe,{className:`size-4`}),t.advanced]}),(0,$.jsx)(`div`,{className:`mt-3 grid gap-3 md:grid-cols-2`,children:J.configFields.filter(e=>!e.required).map(e=>(0,$.jsx)(Yt,{field:e,value:m[e.key]??``,onChange:t=>h(n=>({...n,[e.key]:t}))},e.key))})]}):null,S?(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,b?(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:b}):null,(0,$.jsx)(`div`,{className:`mt-4 flex justify-end`,children:(0,$.jsxs)(C,{variant:`primary`,disabled:!ae||g,onClick:()=>void ue(),children:[g?(0,$.jsx)(_,{className:`size-4 animate-spin`}):(0,$.jsx)(f,{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:g?t.enabling:t.enable})]})]})})]}):null,(0,$.jsx)(Ht,{open:T,onOpenChange:E,provider:D,configured:!!(D&&R.find(e=>e.id===D.providerId)?.configured),language:e,onSaved:le})]})}var en=w;function tn(){return S(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,E,`dark:border-edge`)}function nn(){return S(T,w)}function rn(e){return!e||e<=0?``:e<1024*1024?`${Math.round(e/1024)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function an(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 on(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 sn(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 cn(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 ln(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 un(e){return{maskedHelp:e.apiKeyMaskedHelp,copy:e.apiKeyCopy,copied:e.apiKeyCopied,show:e.apiKeyShow,hide:e.apiKeyHide,notInConfigFile:e.apiKeyNotInConfigFile,loadFailed:e.apiKeyRevealFailed}}function dn(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 fn(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 pn(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 mn(){let e=N(e=>e.language),t=A(e).voiceSettings,n=!!F(e=>e.token),[r,i]=(0,Q.useReducer)(pn,{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}=q(n),{data:g,error:_,isLoading:v,mutate:y}=G(n?P(`/api/voice/models`):null,xt,{revalidateOnFocus:!1}),{data:b,error:x,isLoading:S}=G(n?P(`/api/voice/providers`):null,vt,{revalidateOnFocus:!1}),{data:w,error:T,isLoading:E}=G(n?P(`/api/voice/stt-providers`):null,Et,{revalidateOnFocus:!1}),D=(0,Q.useMemo)(()=>b?.providers??[],[b]),O=(0,Q.useMemo)(()=>w?.providers??[],[w]),k=(0,Q.useMemo)(()=>f?.payload?.config===void 0?null:St(f.payload.config),[f]),j=(0,Q.useMemo)(()=>!a||!o?!1:JSON.stringify(a)!==JSON.stringify(o),[a,o]);n?k!==null&&g!==void 0&&!l.current&&(d.current.parsed!==k||d.current.models!==g)&&(d.current={parsed:k,models:g},i({type:`sync`,value:k}),c(g)):(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 M=!!(n&&(k===null||g===void 0||b===void 0||w===void 0)&&(m||v||S||E)),I=p instanceof Error?p.message:p?String(p):_ instanceof Error?_.message:_?String(_):x instanceof Error?x.message:x?String(x):T instanceof Error?T.message:T?String(T):null,L=(0,Q.useCallback)(e=>{l.current=!0,i({type:`update`,updater:t=>t?{...t,stt:{...t.stt,...e}}:null})},[]),R=(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}}}}})},[]),z=(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})},[]),B=(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]),V=(0,Q.useCallback)(e=>{l.current=!0,i({type:`update`,updater:t=>t?{...t,tts:{...t.tts,...e}}:null})},[]),H=_t({value:a,dirty:j,onSave:(0,Q.useCallback)(async e=>{let n=o?.stt.provider!==`xopc-local`&&e.stt.provider===`xopc-local`;try{await Ot(e),n&&window.dispatchEvent(new Event(Dt)),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)}},[o?.stt.provider,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(M)return(0,$.jsx)(ut,{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)(C,{type:`button`,variant:`secondary`,onClick:()=>{h(),y()},children:t.retry})]});let U=a.stt,ee=a.tts,W=a.voice.input.refinement,K=un(t);return(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,onBlurCapture:H.onBlurCapture,children:[(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(gt,{status:H.status,error:H.error})}),H.error?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:H.error}):null,(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsx)(hn,{v:t,voice:a.voice,updateLanguageMode:B}),(0,$.jsx)(gn,{v:t,stt:U,tts:ee}),(0,$.jsx)(vn,{v:t,apiKeyLabels:K,stt:U,models:s,sttProviders:O,refinement:W,updateStt:L,updateSttFallback:R,updateRefinement:z}),(0,$.jsx)(Sn,{v:t,apiKeyLabels:K,tts:ee,models:s,ttsProviders:D,updateTts:V})]}),(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 hn(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=nn(),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 gn(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} · ${on(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)(_n,{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?cn(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)(_n,{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?`${sn(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)(_n,{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 _n(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=S(`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 vn(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,h,g,_,v;if(t[2]!==a||t[3]!==m||t[4]!==i.provider||t[5]!==i.providers){h=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],_=e,g=a?.stt?.[i.provider]?.length?a.stt[i.provider]:h?.models??[],v=h?.fields.find(yn),t[2]=a,t[3]=m,t[4]=i.provider,t[5]=i.providers,t[6]=h,t[7]=g,t[8]=_,t[9]=v}else h=t[6],g=t[7],_=t[8],v=t[9];let y=v,b=typeof _.model==`string`?_.model:void 0,x=b??(typeof y?.defaultValue==`string`?y.defaultValue:g[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]!==b||t[18]!==x||t[19]!==y||t[20]!==w?(T=()=>{y&&x&&b!==x&&w({model:x})},E=[b,x,y,w],t[17]=b,t[18]=x,t[19]=y,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)(He,{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)(wn,{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]!==h?.fields||t[41]!==r||t[42]!==x||t[43]!==g||t[44]!==m||t[45]!==_||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:S(`flex flex-col gap-1.5`,en),children:[(0,$.jsx)(Dn,{children:n.stt.provider}),(0,$.jsx)(l,{className:nn(),value:i.provider,onChange:e=>c({provider:e.target.value}),children:m.map(e=>(0,$.jsxs)(u,{value:e.id,children:[on(e.id,n),e.configured?``:` *`]},e.id))})]}),(0,$.jsx)(Cn,{kind:`stt`,providerId:i.provider,fields:h?.fields??[],providerSlice:_,models:g,currentModel:x,apiKeyLabels:r,onPatch:w})]}),i.provider===`xopc-local`?(0,$.jsx)(xn,{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:nn(),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]=h?.fields,t[41]=r,t[42]=x,t[43]=g,t[44]=m,t[45]=_,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 yn(e){return e.key===`model`}function bn(e){return`${Math.round(e/1024/1024)} MB`}function xn({v:e}){let{data:t,error:n,mutate:r}=G(P(`/api/voice/local/status`),Ct,{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);(0,Q.useEffect)(()=>{let e=()=>void r();return window.addEventListener(Dt,e),()=>window.removeEventListener(Dt,e)},[r]);let c=(0,Q.useCallback)(async(e,t)=>{a(e.id),s(null);try{t===`install`?await yt(e.id):await bt(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,t?.runtime.ready===!1?(0,$.jsx)(`p`,{className:`mt-3 text-xs text-red-600 dark:text-red-400`,children:t.runtime.error??`Local voice runtime is unavailable`}):null,t?.decoder?.available===!1?(0,$.jsx)(`p`,{className:`mt-3 text-xs text-amber-700 dark:text-amber-300`,children:t.decoder.error??`Compressed audio decoding is unavailable`}):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:S(`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:[bn(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)(C,{type:`button`,variant:`secondary`,disabled:n,onClick:()=>void c(t,t.state===`ready`?`remove`:`install`),children:n?(0,$.jsx)(_,{className:`size-4 animate-spin`}):t.state===`ready`?e.stt.localRemove:e.stt.localInstall})]},t.id)})})]})}function Sn({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),m=(0,Q.useCallback)(()=>{f.current?.pause(),f.current=null,p.current&&=(URL.revokeObjectURL(p.current),null)},[]),h=(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]),g=h.find(e=>e.id===n.provider),v=n.providers?.[n.provider]??{},y=r?.tts?.[n.provider]?.length?r.tts[n.provider]:g?.models??[],b=g?.fields.find(e=>e.key===`model`),x=g?.fields.find(e=>e.key===`voice`),w=typeof v.model==`string`?v.model:void 0,T=w??(typeof b?.defaultValue==`string`?b.defaultValue:y[0]?.id),E=y.find(e=>e.id===T),D=r?.ttsVoices?.[n.provider]?.length?r.ttsVoices[n.provider]:g?.voices??[],{data:O=[]}=G(T?`voice:tts:${n.provider}:${T}`:null,()=>Tt(n.provider,T??``),{revalidateOnFocus:!1}),k=O.length>0?O:D,A=typeof v.voice==`string`?v.voice:void 0,j=A??k.find(e=>e.id===E?.tts?.defaultVoice)?.id??(typeof x?.defaultValue==`string`?x.defaultValue:k[0]?.id),M=(g?.fields??[]).filter(e=>(e.key!==`speed`||E?.tts?.speed!==!1)&&(e.key!==`instructions`||E?.tts?.instructions!==!1)),N=!!g?.diagnostics.requiresApiKey,P=!!g?.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={};b&&T&&w!==T&&(e.model=T),x&&j&&A!==j&&(e.voice=j),Object.keys(e).length>0&&I(e)},[w,A,T,j,b,I,x]),(0,Q.useEffect)(()=>()=>m(),[m]);let L=(0,Q.useCallback)(e=>{a({provider:e}),d({status:`idle`})},[a]),R=(0,Q.useCallback)(async()=>{let t=o.trim();if(!t){d({status:`error`,message:e.tts.test.emptyText});return}m(),d({status:`loading`});try{let r=await wt({text:t,provider:n.provider,providerConfig:v,...T?{model:T}:{},...j?{voice:j}:{}}),i=an(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`,rn(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){m(),d({status:`error`,message:e instanceof Error?e.message:String(e)})}},[T,j,v,m,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)(Qe,{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)(wn,{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:S(`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} ${sn(n.provider,e)}${j?` · ${j}`:``}`:`${e.tts.statusNeedsSetup} ${sn(n.provider,e)} · ${g?.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:S(`flex flex-col gap-1.5`,en),children:[(0,$.jsx)(Dn,{children:e.tts.trigger}),(0,$.jsxs)(l,{className:nn(),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:S(`flex flex-col gap-1.5`,en),children:[(0,$.jsx)(Dn,{children:e.tts.provider}),(0,$.jsx)(l,{className:nn(),value:n.provider,onChange:e=>L(e.target.value),children:h.map(t=>(0,$.jsx)(u,{value:t.id,children:sn(t.id,e)},t.id))}),(0,$.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[g?.configured?e.tts.configured:g?.diagnostics.requiresApiKey?`${e.tts.needsKey} · ${g.diagnostics.envKeys?.join(`, `)??e.stt.apiKey}`:e.tts.noKeyNeeded,` · `,g?.description??ln(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)(Cn,{kind:`tts`,providerId:n.provider,fields:M,providerSlice:v,models:y,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)(C,{type:`button`,variant:`primary`,onClick:()=>void R(),disabled:c.status===`loading`,className:`h-9`,children:[c.status===`loading`?(0,$.jsx)(_,{className:`size-4 animate-spin`}):(0,$.jsx)(Te,{className:`size-4`}),c.status===`loading`?e.tts.test.generating:e.tts.test.play]}),(0,$.jsxs)(C,{type:`button`,variant:`secondary`,onClick:()=>{m(),d(e=>e.status===`playing`?{status:`done`,summary:e.summary}:{status:`idle`})},disabled:c.status!==`playing`,className:`h-9`,children:[(0,$.jsx)(fe,{className:`size-4`}),e.tts.test.stop]})]})]}),(0,$.jsx)(`textarea`,{className:S(tn(),`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 Cn({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:S(`flex flex-col gap-1.5`,en),children:[(0,$.jsx)(Dn,{children:n.label}),(0,$.jsx)(kt,{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:S(`flex flex-col gap-1.5`,en),children:[(0,$.jsx)(Dn,{children:n.label}),(0,$.jsx)(l,{className:nn(),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:S(`flex flex-col gap-1.5`,en),children:[(0,$.jsx)(Dn,{children:n.label}),(0,$.jsx)(l,{className:nn(),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)(Tn,{field:n,value:dn(r,n),onChange:e=>d({[n.key]:e}),className:n.type===`textarea`?`sm:col-span-2`:en},n.key))}function wn(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=S(`group flex w-full items-center justify-between gap-4 rounded-2xl px-4 py-3 text-left shadow-surface transition-colors`,E,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=S(`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 h;t[10]!==m||t[11]!==r?(h=(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]=h):h=t[12];let g;t[13]===i?g=t[14]:(g=(0,$.jsx)(`span`,{className:`mt-1 block text-xs leading-relaxed text-fg-muted`,children:i}),t[13]=i,t[14]=g);let _;t[15]!==h||t[16]!==g?(_=(0,$.jsxs)(`span`,{className:`min-w-0`,children:[h,g]}),t[15]=h,t[16]=g,t[17]=_):_=t[17];let v=n?`border-accent bg-accent`:`border-edge bg-surface-hover group-hover:border-accent/40`,y;t[18]===v?y=t[19]:(y=S(`relative inline-flex h-6 w-11 shrink-0 items-center rounded-full border transition-colors`,v),t[18]=v,t[19]=y);let b=n?`translate-x-5`:`translate-x-0.5`,x;t[20]===b?x=t[21]:(x=S(`size-5 rounded-full bg-white shadow-surface transition-transform`,b),t[20]=b,t[21]=x);let C;t[22]===x?C=t[23]:(C=(0,$.jsx)(`span`,{className:x}),t[22]=x,t[23]=C);let w;t[24]!==y||t[25]!==C?(w=(0,$.jsx)(`span`,{className:y,"aria-hidden":!0,children:C}),t[24]=y,t[25]=C,t[26]=w):w=t[26];let T;return t[27]!==n||t[28]!==c||t[29]!==_||t[30]!==w||t[31]!==u?(T=(0,$.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":n,onClick:c,className:u,children:[_,w]}),t[27]=n,t[28]=c,t[29]=_,t[30]=w,t[31]=u,t[32]=T):T=t[32],T}function Tn(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=S(`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(fn(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=S(`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)(Dn,{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:nn(),value:c,required:n.required,onChange:e=>i(fn(n,e.target.value)),children:(n.options??[]).map(En)}):n.type===`textarea`?(0,$.jsx)(`textarea`,{id:o,className:S(tn(),`min-h-24 resize-y`),value:c,required:n.required,placeholder:n.placeholder,onChange:e=>i(fn(n,e.target.value))}):n.type===`password`?(0,$.jsx)(Ve,{id:o,className:a,value:c,onChange:e=>i(fn(n,e)),placeholder:n.placeholder,labels:Ne}):(0,$.jsx)(`input`,{id:o,className:tn(),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(fn(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 En(e){return(0,$.jsx)(u,{value:e.id,children:e.name},e.id)}function Dn(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 On(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 kn(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 j(P(`/api/config`),{method:`PATCH`,body:JSON.stringify({tools:{web:{region:t,search:n,blocklist:{enabled:e.blocklistEnabled,domains:e.blocklistDomains}}}})}),K()}async function An(e){let t=await j(P(`/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 jn(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 Mn(){return S(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,E,`dark:border-edge`)}function Nn(){return S(T,w)}var Pn=[`brave`,`tavily`,`bing`,`searxng`];function Fn(){return{type:`brave`,apiKey:``,url:``,disabled:!1}}var In=Se();function Ln(){let e=A(N(e=>e.language)),t=e.webSearchSettings,n=e.logs,r=!!F(e=>e.token),[i,a]=(0,Q.useReducer)(In,{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:h,mutate:g}=q(r);Ce({enabled:r,parsed:(0,Q.useMemo)(()=>p?.payload?.config===void 0?null:On(p.payload.config),[p]),dirty:c.current,trackedParsedRef:f,dispatch:a,onResetDirty:()=>{c.current=!1}});let _=!!(r&&h&&p===void 0&&!m),v=m instanceof Error?m.message:m?String(m):null,x=(0,Q.useMemo)(()=>!o||!s?!1:JSON.stringify(o)!==JSON.stringify(s),[o,s]),w=(0,Q.useCallback)(e=>{c.current=!0,a({type:`patch`,patch:e})},[]),T=_t({value:o,dirty:x,onSave:(0,Q.useCallback)(async e=>{try{await kn(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?_?(0,$.jsx)(ut,{rows:3}):o?(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,onBlurCapture:T.onBlurCapture,children:[T.error?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:T.error}):null,(0,$.jsxs)(ft,{children:[(0,$.jsx)(dt,{icon:b,title:t.sectionRegion,subtitle:t.sectionRegionHint,trailing:(0,$.jsx)(gt,{status:T.status,error:T.error})}),(0,$.jsx)(`div`,{className:`flex max-w-md flex-col gap-4`,children:(0,$.jsx)(jn,{label:t.regionLabel,description:t.regionDesc,children:(0,$.jsxs)(l,{className:Nn(),value:o.regionMode,onChange:e=>w({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)(jt,{children:(0,$.jsxs)(ft,{children:[(0,$.jsx)(dt,{icon:ke,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=>w({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)(jn,{label:t.blocklistDomains,description:t.blocklistDomainsDesc,children:(0,$.jsx)(`textarea`,{className:S(Mn(),`min-h-[6rem] font-mono text-xs`),value:o.blocklistDomains.join(`
7
- `),placeholder:t.blocklistDomainsPlaceholder,disabled:!o.blocklistEnabled,onChange:e=>{w({blocklistDomains:e.target.value.split(/\r?\n/).flatMap(e=>{let t=e.trim().toLowerCase();return t?[t]:[]})})}})})]})]})}),(0,$.jsxs)(ft,{children:[(0,$.jsx)(dt,{icon:b,title:t.sectionSearch,subtitle:t.sectionSearchHint}),(0,$.jsxs)(`div`,{className:`flex max-w-xl flex-col gap-6`,children:[(0,$.jsx)(jn,{label:t.maxResultsLabel,description:t.maxResultsDesc,children:(0,$.jsx)(`input`,{type:`number`,min:1,max:50,className:Mn(),value:o.maxResults,onChange:e=>w({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)(Rn,{row:n,providerIndex:r,labels:t,secretLabels:we(e.providersSettings),onChange:e=>{let t=[...o.providers];t[r]=e,w({providers:t})},onRemove:()=>{w({providers:o.providers.filter((e,t)=>t!==r)})}},`${n.type}:${n.url}:${n.apiKey}:${n.disabled}`)),(0,$.jsxs)(C,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5 text-sm`,onClick:()=>w({providers:[...o.providers,Fn()]}),children:[(0,$.jsx)(y,{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:v??t.loadError}),(0,$.jsx)(C,{type:`button`,variant:`secondary`,onClick:()=>void g(),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 Rn(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=()=>An(r).then(zn),t[0]=r,t[1]=c);let d=c,f;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(f=S(Nn(),`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 h;t[6]===i.providerTypes?h=t[7]:(h=Pn.map(e=>(0,$.jsx)(u,{value:e,children:i.providerTypes[e]},e)),t[6]=i.providerTypes,t[7]=h);let g;t[8]!==n.type||t[9]!==m||t[10]!==h?(g=(0,$.jsx)(l,{className:f,value:p,onChange:m,children:h}),t[8]=n.type,t[9]=m,t[10]=h,t[11]=g):g=t[11];let _;t[12]!==o||t[13]!==n?(_=e=>o({...n,disabled:e.target.checked}),t[12]=o,t[13]=n,t[14]=_):_=t[14];let v;t[15]!==n.disabled||t[16]!==_?(v=(0,$.jsx)(`input`,{type:`checkbox`,className:`size-3.5 rounded border-edge`,checked:n.disabled,onChange:_}),t[15]=n.disabled,t[16]=_,t[17]=v):v=t[17];let y;t[18]!==i.disabled||t[19]!==v?(y=(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1.5 text-xs text-fg-muted`,children:[v,i.disabled]}),t[18]=i.disabled,t[19]=v,t[20]=y):y=t[20];let b;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,$.jsx)(We,{className:`size-4`}),t[21]=b):b=t[21];let x;t[22]===s?x=t[23]:(x=(0,$.jsx)(C,{type:`button`,variant:`ghost`,className:`h-8 px-2 text-fg-muted`,onClick:s,children:b}),t[22]=s,t[23]=x);let w;t[24]!==x||t[25]!==y?(w=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[y,x]}),t[24]=x,t[25]=y,t[26]=w):w=t[26];let T;t[27]!==w||t[28]!==g?(T=(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[g,w]}),t[27]=w,t[28]=g,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)(jn,{label:i.urlLabel,description:i.urlDesc,children:(0,$.jsx)(`input`,{type:`url`,className:Mn(),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)(Ve,{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)(jn,{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 zn(e){return e.apiKey??null}var Bn=[`common`,`domestic`,`specialty`,`enterprise`,`oauth`,`extension`];function Vn(e){let t=new Map;for(let e of Bn)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}var Hn=`xopc-cloud`;function Un(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 h=m,g;t[3]!==h||t[4]!==c?(g=()=>{c(),h(!1)},t[3]=h,t[4]=c,t[5]=g):g=t[5];let _=g,v;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(z,{className:S(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,R)}),t[6]=v):v=t[6];let y;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(y=S(`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`,L),t[7]=y):y=t[7];let b;t[8]!==i||t[9]!==a||t[10]!==_||t[11]!==o||t[12]!==s||t[13]!==f||t[14]!==u.presetKey||t[15]!==u.providerId||t[16]!==u.type?(b=(0,$.jsxs)(H,{children:[v,(0,$.jsx)(U,{className:y,children:u.type===`pick`?(0,$.jsx)(Gn,{builtinRows:i,searchQuery:f,onSearchChange:p,labels:o,onPickBuiltin:e=>{let t=Le(e);d(t?{type:`custom`,presetKey:t}:{type:`builtin`,providerId:e})},onPickCustom:()=>d({type:`custom`})}):u.type===`builtin`?(0,$.jsx)(Yn,{providerId:u.providerId,builtinRows:i,labels:o,language:s,onBack:()=>d({type:`pick`}),onSaved:_}):(0,$.jsx)(Qn,{initialPresetKey:u.presetKey,customConfig:a,labels:o,language:s,onBack:()=>d({type:`pick`}),onSaved:_})})]}),t[8]=i,t[9]=a,t[10]=_,t[11]=o,t[12]=s,t[13]=f,t[14]=u.presetKey,t[15]=u.providerId,t[16]=u.type,t[17]=b):b=t[17];let x;return t[18]!==h||t[19]!==n||t[20]!==b?(x=(0,$.jsx)(W,{open:n,onOpenChange:h,children:b}),t[18]=h,t[19]=n,t[20]=b,t[21]=x):x=t[21],x}function Wn(e){let t=(0,Z.c)(4),{label:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=S(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,D.press),t[0]=r):r=t[0];let i;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(x,{className:`size-4`,"aria-hidden":!0}),t[1]=i):i=t[1];let a;return t[2]===n?a=t[3]:(a=(0,$.jsx)(V,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:r,"aria-label":n,children:i})}),t[2]=n,t[3]=a),a}function Gn(e){let t=(0,Z.c)(49),{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=me[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=d.find(qn),t[7]=d,t[8]=f);let p=f,m;t[9]===d?m=t[10]:(m=Vn(d.filter(Kn)),t[9]=d,t[10]=m);let h=m,_;t[11]===a.step1Title?_=t[12]:(_=(0,$.jsx)(ee,{className:`min-w-0 flex-1 text-base font-semibold text-fg`,children:a.step1Title}),t[11]=a.step1Title,t[12]=_);let v;t[13]===a.close?v=t[14]:(v=(0,$.jsx)(Wn,{label:a.close}),t[13]=a.close,t[14]=v);let y;t[15]!==_||t[16]!==v?(y=(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b border-edge-subtle px-5 py-4`,children:[_,v]}),t[15]=_,t[16]=v,t[17]=y):y=t[17];let x;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,$.jsx)(b,{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[18]=x):x=t[18];let C;t[19]===i?C=t[20]:(C=e=>i(e.target.value),t[19]=i,t[20]=C);let w=a.searchPlaceholder,T;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(T=S(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-10 pr-3 text-sm text-fg placeholder:text-fg-subtle`,E),t[21]=T):T=t[21];let O;t[22]!==a.searchPlaceholder||t[23]!==r||t[24]!==C?(O=(0,$.jsx)(`div`,{className:`px-5 pt-3`,children:(0,$.jsxs)(`div`,{className:`relative`,children:[x,(0,$.jsx)(`input`,{type:`search`,value:r,onChange:C,placeholder:w,autoComplete:`off`,className:T})]})}),t[22]=a.searchPlaceholder,t[23]=r,t[24]=C,t[25]=O):O=t[25];let k;t[26]!==a.recommended||t[27]!==o||t[28]!==p?(k=p?(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`p`,{className:`mb-1 px-1 text-[11px] font-semibold uppercase tracking-wide text-fg-subtle`,children:a.recommended}),(0,$.jsx)(Jn,{row:p,onPick:o})]}):null,t[26]=a.recommended,t[27]=o,t[28]=p,t[29]=k):k=t[29];let A;t[30]!==a.addCustom||t[31]!==a.customDescription||t[32]!==s||t[33]!==l?(A=l?null:(0,$.jsxs)(`button`,{type:`button`,onClick:s,className:S(`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`,D.press),children:[(0,$.jsx)(g,{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)(de,{className:`size-4 shrink-0 text-fg-subtle`,"aria-hidden":!0})]}),t[30]=a.addCustom,t[31]=a.customDescription,t[32]=s,t[33]=l,t[34]=A):A=t[34];let j;t[35]!==d.length||t[36]!==h||t[37]!==a.categories||t[38]!==a.noResults||t[39]!==o?(j=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:Bn.map(e=>{let t=h.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,$.jsx)(Jn,{row:e,onPick:o},e.id))})]},e)})}),t[35]=d.length,t[36]=h,t[37]=a.categories,t[38]=a.noResults,t[39]=o,t[40]=j):j=t[40];let M;t[41]!==k||t[42]!==A||t[43]!==j?(M=(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto px-5 py-3`,children:[k,A,j]}),t[41]=k,t[42]=A,t[43]=j,t[44]=M):M=t[44];let N;return t[45]!==O||t[46]!==M||t[47]!==y?(N=(0,$.jsxs)($.Fragment,{children:[y,O,M]}),t[45]=O,t[46]=M,t[47]=y,t[48]=N):N=t[48],N}function Kn(e){return e.id!==Hn}function qn(e){return e.id===Hn}function Jn(e){let t=(0,Z.c)(12),{row:n,onPick:r}=e,i;t[0]!==r||t[1]!==n.id?(i=()=>r(n.id),t[0]=r,t[1]=n.id,t[2]=i):i=t[2];let a;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(a=S(`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`,D.press),t[3]=a):a=t[3];let o;t[4]===n.name?o=t[5]:(o=(0,$.jsx)(`span`,{className:`truncate text-sm text-fg`,children:n.name}),t[4]=n.name,t[5]=o);let s;t[6]===n.configured?s=t[7]:(s=n.configured?(0,$.jsx)(f,{className:`size-3.5 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):null,t[6]=n.configured,t[7]=s);let c;return t[8]!==i||t[9]!==o||t[10]!==s?(c=(0,$.jsxs)(`button`,{type:`button`,onClick:i,className:a,children:[o,s]}),t[8]=i,t[9]=o,t[10]=s,t[11]=c):c=t[11],c}function Yn({providerId:e,builtinRows:t,labels:n,language:r,onBack:i,onSaved:a}){let o=t.find(t=>t.id===e),s=me[e],[c,l]=(0,Q.useState)(``),[u,d]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)(!1),v=(0,Q.useRef)(null),y=A(r).providersSettings,b=we(y),x=(0,Q.useMemo)(()=>ye(e,r),[e,r]),w=o?.supportsApiKey!==!1,T=o?.supportsOAuth===!0,[O,k]=(0,Q.useState)(null),[j,M]=(0,Q.useState)(null),[N,P]=(0,Q.useState)(`idle`),[F,I]=(0,Q.useState)(null),[L,R]=(0,Q.useState)(null),[z,B]=(0,Q.useState)(null),[V,H]=(0,Q.useState)(``),U=(0,Q.useRef)(null),W=(0,Q.useRef)(null),G=N===`waiting`||N===`waiting_code`;(0,Q.useEffect)(()=>{if(!O||!G)return;let t=window.setInterval(()=>{(async()=>{try{let n=await ce(O);n.status===`waiting_auth`||n.status===`waiting_code`?(P(n.status===`waiting_code`?`waiting_code`:`waiting`),M(n.message??null),I(n.authUrl??null),R(n.instructions??null),B(n.deviceCode??null),n.authUrl&&n.authUrl!==W.current&&(W.current=n.authUrl,pt(n.authUrl,U.current).catch(()=>{}))):n.status===`completed`?(window.clearInterval(t),ht(U.current),U.current=null,e===`xopc-cloud`&&await J(),P(`success`),M(n.message??y.saved),window.setTimeout(a,600)):(n.status===`failed`||n.status===`cancelled`)&&(window.clearInterval(t),ht(U.current),U.current=null,P(`error`),M(n.error??n.message??y.revokeFailed))}catch{}})()},1e3);return()=>window.clearInterval(t)},[O,G,a,e,y.revokeFailed,y.saved]),(0,Q.useEffect)(()=>()=>{O&&oe(O).catch(()=>{})},[O]),(0,Q.useEffect)(()=>()=>{ht(U.current),U.current=null},[]);let K=async()=>{ht(U.current),U.current=mt(),W.current=null,P(`waiting`),M(y.oauthStarting),I(null),R(null),B(null),m(null);try{k((await ie(e)).sessionId)}catch(e){ht(U.current),U.current=null,P(`error`),M(e instanceof Error?e.message:y.revokeFailed)}},q=async()=>{if(O){try{await le(O)}catch{}ht(U.current),U.current=null,W.current=null,P(`idle`),M(null),k(null),I(null),R(null),B(null)}},te=async()=>{if(!(!O||!V.trim()))try{await se(O,V.trim()),H(``),M(y.oauthProcessingCode)}catch(e){P(`error`),M(e instanceof Error?e.message:y.revokeFailed)}},ne=async()=>{let t=c.trim();if(!(!t||!w)){d(!0),m(null);try{await $e({[e]:t}),g(!0),window.setTimeout(a,600)}catch(e){m(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:S(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,D.press),"aria-label":n.back,children:(0,$.jsx)(de,{className:`size-4 rotate-180`,"aria-hidden":!0})}),(0,$.jsx)(ee,{className:`min-w-0 flex-1 text-base font-semibold text-fg`,children:o?.name??e}),(0,$.jsx)(Wn,{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,w?(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)(Ve,{id:`builtin-api-key`,value:c,onChange:l,placeholder:n.apiKeyPlaceholder,labels:b,inputRef:v,onKeyDown:e=>{e.key===`Enter`&&ne()}})]}):null,T?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-lg border border-edge-subtle bg-surface-panel/60 p-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:y.oauth}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:y.oauthHint})]}),(0,$.jsxs)(C,{type:`button`,variant:`primary`,className:`gap-1.5`,disabled:G,onClick:()=>void K(),children:[G?(0,$.jsx)(_,{className:`size-3.5 animate-spin`,"aria-hidden":!0}):null,y.oauth]})]}),j?(0,$.jsx)(`p`,{className:S(`text-xs`,N===`error`?`text-red-600 dark:text-red-400`:`text-fg-muted`),children:j}):null,N===`waiting`||N===`waiting_code`?(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[F?(0,$.jsxs)(`a`,{href:F,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1.5 rounded-md bg-accent px-3 py-2 text-sm font-medium text-white hover:bg-accent-hover`,children:[y.openAuthPage,(0,$.jsx)(`span`,{className:`size-3`,"aria-hidden":!0,children:`↗`})]}):null,(0,$.jsx)(C,{type:`button`,variant:`secondary`,onClick:()=>void q(),children:y.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:y.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:y.deviceCodeHint})]}):null,N===`waiting_code`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,$.jsx)(`input`,{type:`text`,value:V,onChange:e=>H(e.target.value),onKeyDown:e=>e.key===`Enter`&&void te(),placeholder:y.pasteRedirectUrl,className:S(`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`,E)}),(0,$.jsx)(C,{type:`button`,variant:`primary`,onClick:()=>void te(),children:y.submitCode})]}):null]}):null,x.length>0&&w?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:x.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:[tt(e,n),(0,$.jsx)(`span`,{className:`size-3`,"aria-hidden":!0,children:`↗`})]},e))}):null,p?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:p}):null,(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,$.jsx)(C,{type:`button`,variant:`secondary`,onClick:i,children:n.cancel}),w?(0,$.jsx)(C,{type:`button`,variant:`primary`,disabled:!c.trim()||u||h,onClick:()=>void ne(),children:h?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(f,{className:`size-3.5`,"aria-hidden":!0}),n.saved]}):u?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(_,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),n.saving]}):n.save}):null]})]})]})}function Xn(e=`custom`){if(e!==`custom`&&ot[e]){let t=ot[e].config;return{preset:e,providerId:rt(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 Zn(e,t){switch(t.type){case`applyPreset`:return t.key===`custom`?{...e,preset:`custom`,error:null}:ot[t.key]?Xn(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)(Zn,void 0,()=>Xn(e)),[c,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(!1),m=we(A(r).providersSettings),{preset:h,providerId:g,baseUrl:v,api:w,apiKey:T,modelIds:O,error:k}=o,j=async()=>{let e=g.trim(),r=v.trim();if(!e){s({type:`setError`,value:n.providerIdRequired});return}if(!r){s({type:`setError`,value:n.baseUrlRequired});return}let i=O.map(e=>e.trim()).filter(Boolean);d(!0),s({type:`setError`,value:null});try{let n=t?.providers??{},o=h===`custom`?void 0:ot[h]?.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 ue({providers:{...n,[e]:s}}),a()}catch(e){s({type:`setError`,value:e instanceof Error?e.message:n.saveError})}finally{d(!1)}},M=async()=>{let e=g.trim()||rt(h)||`custom`,t=v.trim();if(!t){s({type:`setError`,value:n.baseUrlRequired});return}p(!0),s({type:`setError`,value:null});try{let r=h===`custom`?void 0:ot[h]?.config,i=(await je({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)}},N=g.trim()&&v.trim(),P=(w===`openai-completions`||w===`openai-responses`)&&v.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:S(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,D.press),"aria-label":n.back,children:(0,$.jsx)(de,{className:`size-4 rotate-180`,"aria-hidden":!0})}),(0,$.jsx)(ee,{className:`min-w-0 flex-1 text-base font-semibold text-fg`,children:n.step2CustomTitle}),(0,$.jsx)(Wn,{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:h,onChange:e=>s({type:`applyPreset`,key:e.target.value}),className:Re(),children:[(0,$.jsx)(u,{value:`custom`,children:n.presetCustom}),Xe.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:g,onChange:e=>s({type:`setProviderId`,value:e.target.value}),placeholder:n.providerIdPlaceholder,className:S(`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,E)})]}),(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:v,onChange:e=>s({type:`setBaseUrl`,value:e.target.value}),placeholder:n.baseUrlPlaceholder,className:S(`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,E)})]}),(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:Re(),children:_e.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)(Ve,{id:`custom-api-key`,value:T,onChange:e=>s({type:`setApiKey`,value:e}),placeholder:n.apiKeyPlaceholder,labels:m})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:n.modelIdLabel}),(0,$.jsxs)(C,{type:`button`,variant:`secondary`,className:`gap-1.5`,disabled:!P||f,onClick:()=>void M(),children:[f?(0,$.jsx)(_,{className:`size-3.5 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(b,{className:`size-3.5`,"aria-hidden":!0}),f?n.discoveringModels:n.discoverModels]})]}),O.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:S(`flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,E)}),O.length>1?(0,$.jsx)(`button`,{type:`button`,onClick:()=>s({type:`removeModelSlot`,index:t}),className:S(`rounded-lg p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,D.press),children:(0,$.jsx)(x,{className:`size-3.5`,"aria-hidden":!0})}):null]},e||`model-slot-${t}`)),(0,$.jsxs)(C,{type:`button`,variant:`ghost`,className:`w-fit gap-1.5 text-fg-muted`,onClick:()=>s({type:`addModelSlot`}),children:[(0,$.jsx)(y,{className:`size-3.5`,"aria-hidden":!0}),n.addModel]})]}),k?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:k}):null]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t border-edge-subtle px-5 py-3`,children:[(0,$.jsx)(C,{type:`button`,variant:`secondary`,onClick:i,children:n.cancel}),(0,$.jsx)(C,{type:`button`,variant:`primary`,disabled:!N||c,onClick:()=>void j(),children:c?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(_,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),n.saving]}):n.save})]})]})}function $n(){let e=(0,Z.c)(31),t=F(ir),n=!!t,{data:r,isLoading:i}=q(n),a;e[0]===n?a=e[1]:(a=n?P(`/api/providers/meta`):null,e[0]=n,e[1]=a);let o;e[2]===t?o=e[3]:(o=async e=>{let{payload:n}=await(await fetch(e,{headers:{Authorization:`Bearer ${t}`}})).json();return n?.providers??[]},e[2]=t,e[3]=o);let s;e[4]===Symbol.for(`react.memo_cache_sentinel`)?(s={revalidateOnFocus:!1},e[4]=s):s=e[4];let{data:c,isLoading:l}=G(a,o,s),u;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(u={revalidateOnFocus:!1},e[5]=u):u=e[5];let{data:d,isLoading:f}=G(n?ne:null,rr,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}=G(n?Y:null,nr,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=Ue(c,Ye(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=Ee(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(tr).map(er)),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,C=i||l||f,w;return e[25]!==v||e[26]!==S||e[27]!==b||e[28]!==C||e[29]!==m?(w={cards:S,loading:C,builtinRows:v,customConfig:b,allModels:m},e[25]=v,e[26]=S,e[27]=b,e[28]=C,e[29]=m,e[30]=w):w=e[30],w}function er(e){return e.id}function tr(e){return e.configured}function nr(){return Fe()}function rr(){return te()}function ir(e){return e.token}function ar(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)(I,{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(sr)})]}),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(or),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)(y,{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)(C,{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)(C,{type:`button`,variant:`primary`,className:`mt-4 gap-1.5`,onClick:i,children:[(0,$.jsx)(y,{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)(cr,{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 or(e){return e.configured}function sr(e){return(0,$.jsx)(I,{className:`h-32 rounded-2xl`},e)}function cr(e){let t=(0,Z.c)(28),{card:n,labels:r,onManage:i}=e,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=S(`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`,D.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)(f,{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 p;t[16]===d?p=t[17]:(p=(0,$.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:d}),t[16]=d,t[17]=p);let m;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)(st,{className:`size-3`,"aria-hidden":!0}),t[18]=m):m=t[18];let h;t[19]===r.manage?h=t[20]:(h=(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-xs font-medium text-accent-fg opacity-0 transition-opacity group-hover:opacity-100`,children:[m,r.manage]}),t[19]=r.manage,t[20]=h);let g;t[21]!==h||t[22]!==p?(g=(0,$.jsxs)(`div`,{className:`mt-2.5 flex items-center justify-between`,children:[p,h]}),t[21]=h,t[22]=p,t[23]=g):g=t[23];let _;return t[24]!==i||t[25]!==g||t[26]!==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 lr(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}:Me(``),t[0]=n,t[1]=c);let[d,f]=(0,Q.useState)(c),[p,m]=(0,Q.useState)(ur),h;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(h=(e,t)=>{f(n=>({...n,[e]:t})),m(t=>{let n=new Map(t);return n.delete(e),n})},t[2]=h):h=t[2];let g=h,_;t[3]!==d.contextWindow||t[4]!==d.id||t[5]!==d.maxTokens||t[6]!==s.modelIdRequired||t[7]!==s.mustBePositive?(_=()=>{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]=_):_=t[8];let v=_,y;t[9]!==d||t[10]!==o||t[11]!==a||t[12]!==v?(y=()=>{if(!v())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]=v,t[13]=y):y=t[13];let b=y,w=d,T;t[14]===w?T=t[15]:(T=Ze(w),t[14]=w,t[15]=T);let E=T,D=r?s.addModelTitle:s.editModelTitle,k;t[16]===D?k=t[17]:(k=(0,$.jsx)(ee,{className:`text-base font-semibold text-fg`,children:D}),t[16]=D,t[17]=k);let A;t[18]!==s.modelProviderLabel||t[19]!==i?(A=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]=A):A=t[20];let j;t[21]!==k||t[22]!==A?(j=(0,$.jsxs)(`div`,{children:[k,A]}),t[21]=k,t[22]=A,t[23]=j):j=t[23];let M;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(M=S(O,`p-1.5 hover:bg-surface-base`),t[24]=M):M=t[24];let N;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(N=(0,$.jsx)(x,{className:`size-4`}),t[25]=N):N=t[25];let P;t[26]===s.close?P=t[27]:(P=(0,$.jsx)(V,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:M,"aria-label":s.close,children:N})}),t[26]=s.close,t[27]=P);let F;t[28]!==j||t[29]!==P?(F=(0,$.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[j,P]}),t[28]=j,t[29]=P,t[30]=F):F=t[30];let I;t[31]===Symbol.for(`react.memo_cache_sentinel`)?(I=(0,$.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`}),t[31]=I):I=t[31];let L;t[32]===s.modelId?L=t[33]:(L=(0,$.jsxs)(`label`,{className:`mb-1 block text-xs font-medium text-fg`,children:[s.modelId,I]}),t[32]=s.modelId,t[33]=L);let R;t[34]===p?R=t[35]:(R=S(nt(),p.has(`id`)&&`border-red-500`),t[34]=p,t[35]=R);let z=d.id||``,B;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(B=e=>g(`id`,e.target.value),t[36]=B):B=t[36];let H=!r,U;t[37]!==R||t[38]!==z||t[39]!==H?(U=(0,$.jsx)(`input`,{className:R,value:z,onChange:B,placeholder:`e.g. llama3.1:8b`,disabled:H}),t[37]=R,t[38]=z,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]!==L||t[44]!==U||t[45]!==W?(G=(0,$.jsxs)(`div`,{children:[L,U,W]}),t[43]=L,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 q;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(q=nt(),t[49]=q):q=t[49];let te=d.name||``,ne;t[50]===Symbol.for(`react.memo_cache_sentinel`)?(ne=e=>g(`name`,e.target.value),t[50]=ne):ne=t[50];let J;t[51]===te?J=t[52]:(J=(0,$.jsx)(`input`,{className:q,value:te,onChange:ne}),t[51]=te,t[52]=J);let Y;t[53]!==K||t[54]!==J?(Y=(0,$.jsxs)(`div`,{children:[K,J]}),t[53]=K,t[54]=J,t[55]=Y):Y=t[55];let X;t[56]===s.inputTypes?X=t[57]:(X=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.inputTypes}),t[56]=s.inputTypes,t[57]=X);let re;t[58]===Symbol.for(`react.memo_cache_sentinel`)?(re=Re(),t[58]=re):re=t[58];let ie;t[59]===Symbol.for(`react.memo_cache_sentinel`)?(ie=e=>g(`input`,qe(e.target.value)),t[59]=ie):ie=t[59];let ae;t[60]===s?ae=t[61]:(ae=Be.map(e=>(0,$.jsx)(u,{value:e.value,children:s[e.labelKey]},e.value)),t[60]=s,t[61]=ae);let oe;t[62]!==E||t[63]!==ae?(oe=(0,$.jsx)(l,{className:re,value:E,onChange:ie,children:ae}),t[62]=E,t[63]=ae,t[64]=oe):oe=t[64];let se;t[65]!==X||t[66]!==oe?(se=(0,$.jsxs)(`div`,{children:[X,oe]}),t[65]=X,t[66]=oe,t[67]=se):se=t[67];let ce=d.reasoning||!1,le;t[68]===Symbol.for(`react.memo_cache_sentinel`)?(le=e=>g(`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 pe;t[77]===s.contextWindow?pe=t[78]:(pe=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.contextWindow}),t[77]=s.contextWindow,t[78]=pe);let me;t[79]===p?me=t[80]:(me=S(nt(),p.has(`contextWindow`)&&`border-red-500`),t[79]=p,t[80]=me);let he=d.contextWindow??128e3,ge;t[81]===Symbol.for(`react.memo_cache_sentinel`)?(ge=e=>g(`contextWindow`,parseInt(e.target.value,10)||0),t[81]=ge):ge=t[81];let _e;t[82]!==me||t[83]!==he?(_e=(0,$.jsx)(`input`,{type:`number`,min:1,className:me,value:he,onChange:ge}),t[82]=me,t[83]=he,t[84]=_e):_e=t[84];let ve;t[85]===p?ve=t[86]:(ve=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]=ve);let ye;t[87]!==pe||t[88]!==_e||t[89]!==ve?(ye=(0,$.jsxs)(`div`,{children:[pe,_e,ve]}),t[87]=pe,t[88]=_e,t[89]=ve,t[90]=ye):ye=t[90];let be;t[91]===s.maxOutputTokens?be=t[92]:(be=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.maxOutputTokens}),t[91]=s.maxOutputTokens,t[92]=be);let xe;t[93]===p?xe=t[94]:(xe=S(nt(),p.has(`maxTokens`)&&`border-red-500`),t[93]=p,t[94]=xe);let Se=d.maxTokens??16384,Ce;t[95]===Symbol.for(`react.memo_cache_sentinel`)?(Ce=e=>g(`maxTokens`,parseInt(e.target.value,10)||0),t[95]=Ce):Ce=t[95];let we;t[96]!==xe||t[97]!==Se?(we=(0,$.jsx)(`input`,{type:`number`,min:1,className:xe,value:Se,onChange:Ce}),t[96]=xe,t[97]=Se,t[98]=we):we=t[98];let Te;t[99]===p?Te=t[100]:(Te=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]=Te);let Ee;t[101]!==be||t[102]!==we||t[103]!==Te?(Ee=(0,$.jsxs)(`div`,{children:[be,we,Te]}),t[101]=be,t[102]=we,t[103]=Te,t[104]=Ee):Ee=t[104];let De;t[105]!==ye||t[106]!==Ee?(De=(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[ye,Ee]}),t[105]=ye,t[106]=Ee,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=nt(),t[112]=Ae):Ae=t[112];let je=d.cost?.input??0,Ne;t[113]===d.cost?Ne=t[114]:(Ne=e=>g(`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]=Ne);let Pe;t[115]!==je||t[116]!==Ne?(Pe=(0,$.jsx)(`input`,{type:`number`,step:`any`,min:0,className:Ae,value:je,onChange:Ne}),t[115]=je,t[116]=Ne,t[117]=Pe):Pe=t[117];let Fe;t[118]!==ke||t[119]!==Pe?(Fe=(0,$.jsxs)(`div`,{children:[ke,Pe]}),t[118]=ke,t[119]=Pe,t[120]=Fe):Fe=t[120];let Ie;t[121]===s.costOutput?Ie=t[122]:(Ie=(0,$.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:s.costOutput}),t[121]=s.costOutput,t[122]=Ie);let Le;t[123]===Symbol.for(`react.memo_cache_sentinel`)?(Le=nt(),t[123]=Le):Le=t[123];let ze=d.cost?.output??0,Ve;t[124]===d.cost?Ve=t[125]:(Ve=e=>g(`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]!==ze||t[127]!==Ve?(He=(0,$.jsx)(`input`,{type:`number`,step:`any`,min:0,className:Le,value:ze,onChange:Ve}),t[126]=ze,t[127]=Ve,t[128]=He):He=t[128];let Ue;t[129]!==Ie||t[130]!==He?(Ue=(0,$.jsxs)(`div`,{children:[Ie,He]}),t[129]=Ie,t[130]=He,t[131]=Ue):Ue=t[131];let We;t[132]!==Fe||t[133]!==Ue?(We=(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[Fe,Ue]}),t[132]=Fe,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]!==Y||t[140]!==fe||t[141]!==De||t[142]!==Ge?(Ke=(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[G,Y,fe,De,Ge]}),t[138]=G,t[139]=Y,t[140]=fe,t[141]=De,t[142]=Ge,t[143]=Ke):Ke=t[143];let Je;t[144]===s.cancel?Je=t[145]:(Je=(0,$.jsx)(V,{asChild:!0,children:(0,$.jsx)(C,{type:`button`,variant:`secondary`,children:s.cancel})}),t[144]=s.cancel,t[145]=Je);let Ye=r?s.addModelConfirm:s.saveModelConfirm,Xe;t[146]!==b||t[147]!==Ye?(Xe=(0,$.jsx)(C,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:b,children:Ye}),t[146]=b,t[147]=Ye,t[148]=Xe):Xe=t[148];let Qe;t[149]!==Je||t[150]!==Xe?(Qe=(0,$.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2 border-t border-edge-subtle pt-3 dark:border-edge`,children:[Je,Xe]}),t[149]=Je,t[150]=Xe,t[151]=Qe):Qe=t[151];let $e;return t[152]!==F||t[153]!==Ke||t[154]!==Qe?($e=(0,$.jsxs)($.Fragment,{children:[F,Ke,Qe]}),t[152]=F,t[153]=Ke,t[154]=Qe,t[155]=$e):$e=t[155],$e}function ur(){return new Map}function dr(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)(z,{className:S(`xopc-dialog-overlay fixed inset-0 bg-scrim`,R)}),t[0]=l):l=t[0];let u;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(u=S(`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`,L,`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)(lr,{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)(H,{children:[l,(0,$.jsx)(U,{className:u,onOpenAutoFocus:fr,children:d})]}),t[10]=d,t[11]=f);let p;return t[12]!==r||t[13]!==n||t[14]!==f?(p=(0,$.jsx)(W,{open:n,onOpenChange:r,children:f}),t[12]=r,t[13]=n,t[14]=f,t[15]=p):p=t[15],p}function fr(e){return e.preventDefault()}function pr(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=()=>Ge(n).then(mr),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)(Ve,{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 mr(e){return e.apiKey??null}function hr(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)(z,{className:S(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,R)}),t[0]=f):f=t[0];let p;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(p=S(`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`,L),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)(H,{children:[f,(0,$.jsx)(U,{className:p,children:a?(0,$.jsx)(_r,{providerId:i,customConfig:s,labels:l,language:u,onClose:()=>r(!1),onSaved:d}):(0,$.jsx)(gr,{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 h;return t[12]!==r||t[13]!==n||t[14]!==m?(h=(0,$.jsx)(W,{open:n,onOpenChange:r,children:m}),t[12]=r,t[13]=n,t[14]=m,t[15]=h):h=t[15],h}function gr({providerId:e,builtinRows:t,allModels:n,labels:r,language:i,onClose:a,onSaved:o}){let s=t.find(t=>t.id===e),l=me[e],u=n.filter(t=>t.provider===e),[d,p]=(0,Q.useState)(s?.apiKey??``),[h,g]=(0,Q.useState)(!1),[v,y]=(0,Q.useState)(!1),[b,w]=(0,Q.useState)(null),[T,O]=(0,Q.useState)(!1),k=A(i).providersSettings,j=s?.supportsApiKey!==!1,M=s?.supportsOAuth===!0,N=s?.authMode===`oauth`&&s.authStatus===`connected`,P=s?.configured===!0&&s.activeKeySource!==`env`&&s.activeKeySource!==`extension`&&s.activeKeySource!==`models_json`,[F,I]=(0,Q.useState)(null),[L,R]=(0,Q.useState)(null),[z,B]=(0,Q.useState)(`idle`),[H,U]=(0,Q.useState)(null),[W,G]=(0,Q.useState)(null),[K,q]=(0,Q.useState)(null),[te,ne]=(0,Q.useState)(``),J=(0,Q.useRef)(null),Y=(0,Q.useRef)(null),X=z===`waiting`||z===`waiting_code`,re=(0,Q.useMemo)(()=>ye(e,i),[e,i]),ue=d!==(s?.apiKey??``),de=async()=>{let t=d.trim();if(!(!t||!j||ze(t))){g(!0),w(null);try{await $e({[e]:t}),y(!0),window.setTimeout(()=>{o(),a()},600)}catch(e){w(e instanceof Error?e.message:r.saveError)}finally{g(!1)}}};(0,Q.useEffect)(()=>{if(!F||!X)return;let e=window.setInterval(()=>{(async()=>{try{let t=await ce(F);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),q(t.deviceCode??null),t.authUrl&&t.authUrl!==Y.current&&(Y.current=t.authUrl,pt(t.authUrl,J.current).catch(()=>{}))):t.status===`completed`?(window.clearInterval(e),ht(J.current),J.current=null,B(`success`),R(t.message??k.saved),window.setTimeout(()=>{o(),a()},600)):(t.status===`failed`||t.status===`cancelled`)&&(window.clearInterval(e),ht(J.current),J.current=null,B(`error`),R(t.error??t.message??k.revokeFailed))}catch{}})()},1e3);return()=>window.clearInterval(e)},[F,X,a,o,k.revokeFailed,k.saved]),(0,Q.useEffect)(()=>()=>{F&&oe(F).catch(()=>{})},[F]),(0,Q.useEffect)(()=>()=>{ht(J.current),J.current=null},[]);let fe=async()=>{try{await Je(e),o(),a()}catch{}},pe=async()=>{ht(J.current),J.current=mt(),Y.current=null,B(`waiting`),R(k.oauthStarting),U(null),G(null),q(null),w(null);try{I((await ie(e)).sessionId)}catch(e){ht(J.current),J.current=null,B(`error`),R(e instanceof Error?e.message:k.revokeFailed)}},he=async()=>{if(F){try{await le(F)}catch{}ht(J.current),J.current=null,Y.current=null,B(`idle`),R(null),I(null),U(null),G(null),q(null)}},ge=async()=>{if(!(!F||!te.trim()))try{await se(F,te.trim()),ne(``),R(k.oauthProcessingCode)}catch(e){B(`error`),R(e instanceof Error?e.message:k.revokeFailed)}},_e=async()=>{try{await ae(e),o(),a()}catch(e){w(e instanceof Error?e.message:k.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)(ee,{className:`text-base font-semibold text-fg`,children:s?.name??e}),(0,$.jsx)(V,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:S(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,D.press),children:(0,$.jsx)(x,{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,j?(0,$.jsx)(pr,{providerId:e,inputId:`manage-api-key`,value:d,onChange:e=>{p(e),y(!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)(m,{className:`size-3`,"aria-hidden":!0})]}):null]}):null,M?(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:k.oauth}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:N?k.sourceOauth:k.oauthHint})]}),N?(0,$.jsx)(C,{type:`button`,variant:`secondary`,className:`gap-1.5 text-red-600 dark:text-red-400`,onClick:()=>void _e(),children:k.revoke}):(0,$.jsxs)(C,{type:`button`,variant:`primary`,className:`gap-1.5`,disabled:X,onClick:()=>void pe(),children:[X?(0,$.jsx)(_,{className:`size-3.5 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Ie,{className:`size-3.5`,"aria-hidden":!0}),k.oauth]})]}),L?(0,$.jsx)(`p`,{className:S(`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:[H?(0,$.jsxs)(`a`,{href:H,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)(m,{className:`size-4`,"aria-hidden":!0}),k.openAuthPage]}):null,(0,$.jsx)(C,{type:`button`,variant:`secondary`,onClick:()=>void he(),children:k.cancelOAuth})]}):null,W?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:W}):null,K?(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:k.deviceCodeLabel}),(0,$.jsx)(`code`,{className:`mt-1 block select-all font-mono text-lg font-semibold tracking-widest text-fg`,children:K}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:k.deviceCodeHint})]}):null,z===`waiting_code`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,$.jsx)(`input`,{type:`text`,value:te,onChange:e=>ne(e.target.value),onKeyDown:e=>e.key===`Enter`&&void ge(),placeholder:k.pasteRedirectUrl,className:S(`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`,E)}),(0,$.jsx)(C,{type:`button`,variant:`primary`,onClick:()=>void ge(),children:k.submitCode})]}):null]}):null,re.length>0&&j?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:re.map(({kind:e,href:t})=>(0,$.jsxs)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent hover:underline`,children:[tt(e,r),(0,$.jsx)(m,{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}),b?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:b}):null]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-t border-edge-subtle px-5 py-3`,children:[P?(0,$.jsxs)(C,{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:()=>O(!0),children:[(0,$.jsx)(We,{className:`size-3.5`,"aria-hidden":!0}),r.remove]}):(0,$.jsx)(`span`,{}),(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:j&&ue&&!ze(d.trim())?(0,$.jsx)(C,{type:`button`,variant:`primary`,disabled:!d.trim()||h||v,onClick:()=>void de(),children:v?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(f,{className:`size-3.5`,"aria-hidden":!0}),r.saved]}):h?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(_,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),r.saving]}):r.save}):null})]}),(0,$.jsx)(at,{open:T,title:r.removeConfirmTitle,description:r.removeConfirmDescription.replace(`{{provider}}`,s?.name??e),confirmLabel:r.removeConfirmAction,cancelLabel:r.cancel,destructive:!0,onConfirm:()=>void fe(),onCancel:()=>O(!1)})]})}function _r({providerId:e,customConfig:t,labels:n,language:r,onClose:i,onSaved:a}){let o=A(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??[]),[m,h]=(0,Q.useState)(s?.modelDiscovery?.enabled===!0),[g,b]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(null),[O,k]=(0,Q.useState)(!1),[j,M]=(0,Q.useState)(null),[N,P]=(0,Q.useState)(!1),[F,I]=(0,Q.useState)(null),L=n=>{if(!t)return null;let r=u.trim(),i={...s,baseUrl:c.trim()||void 0,apiKey:ze(r)?s?.apiKey:r||void 0,...n};return{providers:{...t.providers,[e]:i}}},R=async()=>{let e=L({models:f,modelDiscovery:{enabled:m}});if(e){b(!0),T(null);try{await ue(e),a(),i()}catch(e){T(e instanceof Error?e.message:n.saveError)}finally{b(!1)}}},z=async()=>{if(t)try{let{[e]:n,...r}=t.providers;await ue({providers:r}),a(),i()}catch{}},B=(e,t)=>{I({model:e,isNew:t}),P(!0)},H=async e=>{if(!F)return;let t=F.isNew?[...f,e]:f.map(t=>t.id===e.id?e:t);p(t);let r=L({models:t});if(r)try{await ue(r),a()}catch(e){T(e instanceof Error?e.message:n.saveError)}},U=async e=>{let t=f.filter(t=>t.id!==e);p(t),M(null);let r=L({models:t});if(r)try{await ue(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)(ee,{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)(V,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:S(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,D.press),children:(0,$.jsx)(x,{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:S(`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,E)})]}),(0,$.jsx)(pr,{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:m,onChange:e=>h(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)(C,{type:`button`,variant:`primary`,className:`gap-1.5 px-2 py-1 text-xs`,onClick:()=>B(null,!0),children:[(0,$.jsx)(y,{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:S(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,D.press),onClick:()=>B(e,!1),"aria-label":o.editModel,children:(0,$.jsx)(v,{className:`size-3.5`,"aria-hidden":!0})}),(0,$.jsx)(`button`,{type:`button`,className:S(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-red-600 dark:hover:text-red-400`,D.press),onClick:()=>M(e.id),"aria-label":o.removeModel,children:(0,$.jsx)(We,{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)(C,{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:()=>k(!0),children:[(0,$.jsx)(We,{className:`size-3.5`,"aria-hidden":!0}),n.remove]}),(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsx)(C,{type:`button`,variant:`primary`,disabled:g,onClick:()=>void R(),children:g?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(_,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),n.saving]}):n.save})})]}),(0,$.jsx)(at,{open:O,title:n.removeConfirmTitle,description:n.removeConfirmDescription.replace(`{{provider}}`,e),confirmLabel:n.removeConfirmAction,cancelLabel:n.cancel,destructive:!0,onConfirm:()=>void z(),onCancel:()=>k(!1)}),(0,$.jsx)(at,{open:j!==null,title:o.removeModel,description:o.removeModelConfirm.replace(`{{id}}`,j??``),confirmLabel:n.removeConfirmAction,cancelLabel:n.cancel,destructive:!0,onConfirm:()=>{j&&U(j)},onCancel:()=>M(null)}),(0,$.jsx)(dr,{open:N,onOpenChange:e=>{P(e),e||I(null)},providerId:e,model:F?.model??null,isNew:F?.isNew??!1,onSave:e=>void H(e),m:o})]})}async function vr(){let e=await M(P(`/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}async function yr(){let e=await M(P(`/api/capabilities/readiness`)),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 br(){let e=N(e=>e.language)===`zh`,{data:t,error:n,isLoading:r}=G(X,vr,{revalidateOnFocus:!1}),{data:i}=G(re,yr,{revalidateOnFocus:!1}),[a,o]=(0,Q.useState)(!1),[s,c]=(0,Q.useState)(null);if(r)return(0,$.jsx)(I,{className:`h-24 w-full rounded-2xl`});let l=Object.values(t?.sources??{}),u=l.reduce((e,t)=>e+t.models.filter(e=>e.availability===`available`).length,0),d=(t?.references??[]).filter(e=>e.availability===`unavailable`),p=t?.sync.lastSuccessAt??Math.max(0,...l.map(e=>e.lastSuccessAt)),m=s??(n instanceof Error?n.message:t?.sync.lastError??Object.values(t?.sync.sourceErrors??{})[0]),h=async()=>{o(!0),c(null);try{let e=await M(P(`/api/models/catalog/refresh`),{method:`POST`});if(!e.ok)throw Error(`HTTP ${e.status}`);await J()}catch(t){c(t instanceof Error?t.message:e?`模型目录刷新失败`:`Model catalog refresh failed`)}finally{o(!1)}};return(0,$.jsxs)(`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:[m||d.length>0?(0,$.jsx)(Ke,{className:`size-4 text-amber-500`,"aria-hidden":!0}):(0,$.jsx)(f,{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?`${l.length} 个来源,${u} 个可用模型${p?` · 最近同步 ${new Date(p).toLocaleString()}`:``}`:`${l.length} sources, ${u} available models${p?` · Last synced ${new Date(p).toLocaleString()}`:``}`})]}),(0,$.jsxs)(C,{className:`shrink-0`,type:`button`,variant:`secondary`,disabled:a,onClick:()=>void h(),children:[a?(0,$.jsx)(_,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Ae,{className:`size-4`,"aria-hidden":!0}),a?e?`刷新中…`:`Refreshing…`:e?`立即刷新`:`Refresh now`]})]}),i?(0,$.jsx)(`div`,{className:`mt-3 grid gap-2 sm:grid-cols-2 xl:grid-cols-4`,children:Object.entries(i.capabilities).map(([t,n])=>{let r=t===`vision`?e?`图片理解`:`Vision`:t===`image-generation`?e?`图片生成`:`Image generation`:t.toUpperCase(),i=n.selectionSource!==`explicit-config`;return(0,$.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel px-3 py-2`,children:[(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`min-w-0 text-xs font-medium text-fg`,children:r}),(0,$.jsx)(`span`,{className:n.status===`ready`?`shrink-0 text-xs text-emerald-600 dark:text-emerald-400`:n.status===`disabled`?`shrink-0 text-xs text-fg-muted`:`shrink-0 text-xs text-amber-600 dark:text-amber-400`,children:n.status===`ready`?e?`可用`:`Ready`:n.status===`disabled`?e?`已关闭`:`Off`:e?`需处理`:`Needs attention`})]}),(0,$.jsx)(`p`,{className:`mt-1 truncate text-xs text-fg-muted`,title:n.primary?`${n.primary.provider}/${n.primary.model}`:void 0,children:n.primary?`${i?e?`自动`:`Auto`:e?`显式`:`Explicit`} · ${n.primary.provider}/${n.primary.model}`:e?`无可用实现`:`No available implementation`})]},t)})}):null,d.length>0?(0,$.jsx)(`div`,{className:`mt-2 space-y-1 text-sm text-amber-700 dark:text-amber-300`,children:d.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,m?(0,$.jsx)(`p`,{className:`mt-2 text-sm text-danger`,children:m}):null]})}async function xr(){return(await j(P(`/api/models/xopc-cloud/account-summary`))).payload}function Sr(e){let t=(0,Z.c)(93),{labels:n}=e,r=N(Cr)===`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}=G(`/api/models/xopc-cloud/account-summary`,xr,i);if(s){let e;return t[1]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(I,{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)(Ke,{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)(Ae,{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)(C,{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,f,h,g,_,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`,f=`min-w-0 flex-1`;let i;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(p,{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?(h=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[i,o,s]}),t[44]=o,t[45]=s,t[46]=h):h=t[46],t[47]===n.availableCredits?g=t[48]:(g=(0,$.jsx)(`p`,{className:`mt-5 text-xs font-medium text-fg-subtle`,children:n.availableCredits}),t[47]=n.availableCredits,t[48]=g),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]=f,t[34]=h,t[35]=g,t[36]=_,t[37]=v,t[38]=y}else u=t[31],d=t[32],f=t[33],h=t[34],g=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 w;t[56]===n.recentUsage?w=t[57]:(w=(0,$.jsx)(`p`,{className:`mt-5 text-xs font-medium text-fg-subtle`,children:n.recentUsage}),t[56]=n.recentUsage,t[57]=w);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]!==w||t[69]!==T||t[70]!==D||t[71]!==f||t[72]!==h||t[73]!==g?(O=(0,$.jsxs)(`div`,{className:f,children:[h,g,x,S,w,T,D]}),t[66]=x,t[67]=S,t[68]=w,t[69]=T,t[70]=D,t[71]=f,t[72]=h,t[73]=g,t[74]=O):O=t[74];let k;t[75]===Symbol.for(`react.memo_cache_sentinel`)?(k=(0,$.jsx)(m,{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)(C,{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)(m,{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)(C,{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 P;t[83]!==A||t[84]!==M?(P=(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap gap-2`,children:[A,M]}),t[83]=A,t[84]=M,t[85]=P):P=t[85];let F;t[86]!==O||t[87]!==P||t[88]!==_?(F=(0,$.jsxs)(`div`,{className:_,children:[O,P]}),t[86]=O,t[87]=P,t[88]=_,t[89]=F):F=t[89];let L;return t[90]!==F||t[91]!==v?(L=(0,$.jsx)(`section`,{className:v,children:F}),t[90]=F,t[91]=v,t[92]=L):L=t[92],L}function Cr(e){return e.language}function wr(e){return pe.includes(e)}function Tr(){let e=(0,Z.c)(71),t=N(Or),n;e[0]===t?n=e[1]:(n=A(t),e[0]=t,e[1]=n);let r=n,l=r.capabilitiesSettings,u=a(),[d,f]=o(),{capability:p}=i(),[m,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(null),v=$n(),y;e[2]===v.cards?y=e[3]:(y=v.cards.some(Dr),e[2]=v.cards,e[3]=y);let x=y,S,w;e[4]!==p||e[5]!==d||e[6]!==f?(S=()=>{if(p!==`models`||d.get(`add`)!==`1`)return;h(!0);let e=new URLSearchParams(d);e.delete(`add`),f(e,{replace:!0})},w=[p,d,f],e[4]=p,e[5]=d,e[6]=f,e[7]=S,e[8]=w):(S=e[7],w=e[8]),(0,Q.useEffect)(S,w);let T;e[9]!==l.modelsHint||e[10]!==l.tabs.models?(T={id:`models`,icon:Pe,label:l.tabs.models,hint:l.modelsHint},e[9]=l.modelsHint,e[10]=l.tabs.models,e[11]=T):T=e[11];let E;e[12]!==l.imageHint||e[13]!==l.tabs.image?(E={id:`image`,icon:he,label:l.tabs.image,hint:l.imageHint},e[12]=l.imageHint,e[13]=l.tabs.image,e[14]=E):E=e[14];let D;e[15]!==l.tabs.voice||e[16]!==l.voiceHint?(D={id:`voice`,icon:He,label:l.tabs.voice,hint:l.voiceHint},e[15]=l.tabs.voice,e[16]=l.voiceHint,e[17]=D):D=e[17];let O;e[18]!==l.searchHint||e[19]!==l.tabs.search?(O={id:`search`,icon:b,label:l.tabs.search,hint:l.searchHint},e[18]=l.searchHint,e[19]=l.tabs.search,e[20]=O):O=e[20];let k;e[21]!==T||e[22]!==E||e[23]!==D||e[24]!==O?(k=[T,E,D,O],e[21]=T,e[22]=E,e[23]=D,e[24]=O,e[25]=k):k=e[25];let j=k,M;e[26]===u?M=e[27]:(M=e=>u(et(e)),e[26]=u,e[27]=M);let P=M,F=Er;if(!wr(p)){let t;return e[28]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(s,{to:et(`models`),replace:!0}),e[28]=t):t=e[28],t}let I=r.nav.settingsCapabilities,L=l.subtitle,R;e[29]===t?R=e[30]:(R=ge(t,`configuration`),e[29]=t,e[30]=R);let z;e[31]===Symbol.for(`react.memo_cache_sentinel`)?(z=(0,$.jsx)(it,{className:`size-4`,"aria-hidden":!0}),e[31]=z):z=e[31];let B;e[32]===l.agentSettingsLink?B=e[33]:(B=(0,$.jsx)(C,{asChild:!0,variant:`secondary`,children:(0,$.jsxs)(c,{to:`/agents`,children:[z,l.agentSettingsLink]})}),e[32]=l.agentSettingsLink,e[33]=B);let V;e[34]!==l.docsLink||e[35]!==l.subtitle||e[36]!==r.nav.settingsCapabilities||e[37]!==R||e[38]!==B?(V=(0,$.jsx)(ct,{title:I,subtitle:L,docsLink:R,docsLabel:l.docsLink,actions:B}),e[34]=l.docsLink,e[35]=l.subtitle,e[36]=r.nav.settingsCapabilities,e[37]=R,e[38]=B,e[39]=V):V=e[39];let H;e[40]!==l.tabsAria||e[41]!==p||e[42]!==j||e[43]!==P?(H=(0,$.jsx)(At,{items:j,activeTab:p,onChange:P,ariaLabel:l.tabsAria,tabIdPrefix:`capability-tab`,panelIdPrefix:`capability-panel`}),e[40]=l.tabsAria,e[41]=p,e[42]=j,e[43]=P,e[44]=H):H=e[44];let U;e[45]!==l.connectedProviders||e[46]!==l.xopcCloudAccount||e[47]!==p||e[48]!==v||e[49]!==j||e[50]!==x?(U=j.map(e=>(0,$.jsx)(Ar,{id:e.id,activeSection:p,hint:e.hint,children:e.id===`models`?(0,$.jsxs)($.Fragment,{children:[x?(0,$.jsx)(Sr,{labels:l.xopcCloudAccount}):null,(0,$.jsx)(br,{}),(0,$.jsx)(ar,{labels:l.connectedProviders,data:v,onAdd:()=>h(!0),onManage:(e,t)=>_({providerId:e,isCustom:t})})]}):(0,$.jsx)(kr,{section:e.id})},e.id)),e[45]=l.connectedProviders,e[46]=l.xopcCloudAccount,e[47]=p,e[48]=v,e[49]=j,e[50]=x,e[51]=U):U=e[51];let ee;e[52]!==m||e[53]!==l.addProviderDialog||e[54]!==t||e[55]!==v.builtinRows||e[56]!==v.customConfig?(ee=(0,$.jsx)(Un,{open:m,onOpenChange:h,builtinRows:v.builtinRows,customConfig:v.customConfig,labels:l.addProviderDialog,language:t,onSaved:F}),e[52]=m,e[53]=l.addProviderDialog,e[54]=t,e[55]=v.builtinRows,e[56]=v.customConfig,e[57]=ee):ee=e[57];let W;e[58]!==l.manageProviderDialog||e[59]!==t||e[60]!==g||e[61]!==v.allModels||e[62]!==v.builtinRows||e[63]!==v.customConfig?(W=g?(0,$.jsx)(hr,{open:!0,onOpenChange:e=>{e||_(null)},providerId:g.providerId,isCustom:g.isCustom,builtinRows:v.builtinRows,customConfig:v.customConfig,allModels:v.allModels,labels:l.manageProviderDialog,language:t,onSaved:F}):null,e[58]=l.manageProviderDialog,e[59]=t,e[60]=g,e[61]=v.allModels,e[62]=v.builtinRows,e[63]=v.customConfig,e[64]=W):W=e[64];let G;return e[65]!==V||e[66]!==H||e[67]!==U||e[68]!==ee||e[69]!==W?(G=(0,$.jsxs)(lt,{children:[V,H,U,ee,W]}),e[65]=V,e[66]=H,e[67]=U,e[68]=ee,e[69]=W,e[70]=G):G=e[70],G}function Er(){J()}function Dr(e){return e.id===`xopc-cloud`&&!e.isCustom}function Or(e){return e.language}function kr(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)($t,{}),t[0]=e):e=t[0],e}case`voice`:{let e;return t[1]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(mn,{}),t[1]=e):e=t[1],e}case`search`:{let e;return t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Ln,{}),t[2]=e):e=t[2],e}}}function Ar({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:S(`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{Tr as CapabilitiesSettingsPanel};
4
+ `)),te(t?.models.map(Vt)??[Vt()]),J(t?.defaultModel??``),ce(void 0),X(void 0),ie(!1),oe(void 0),ue(void 0)},[r,e,n]);let de=(0,Q.useMemo)(()=>q.filter(e=>e.id.trim()).map(e=>({value:e.id.trim(),label:e.name.trim()||e.id.trim()})),[q]),fe=(e,t)=>{te(n=>n.map((n,r)=>r===e?{...n,...t}:n))},pe=()=>{let e=s.trim(),t=q.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=ne||t[0]?.id;if(!n||!t.some(e=>e.id===n))throw Error(o.required);let r;try{r=Ht(G)}catch{throw Error(o.invalidHeaders)}return{providerId:e,input:{baseUrl:f.trim(),...r?{headers:r}:{},imageGeneration:{api:`openai-images`,name:l.trim(),...O.trim()?{documentationUrl:O.trim()}:{},...E.trim()?{apiKeyUrl:E.trim()}:{},defaultModel:n,auth:m===`header`?{type:`header`,headerName:v.trim()}:{type:m},paths:{...j.trim()?{generations:j.trim()}:{},...N.trim()?{edits:N.trim()}:{}},...F.trim()?{network:{allowedHosts:F.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 Pt(e.providerId,e.input),m!==`none`&&w.trim()&&!k(w)&&await Nt(e.providerId,w.trim()),await a(e.providerId),e},he=async()=>{X(`save`),oe(void 0),ce(void 0);try{await me(),T(m===`none`?``:`••••••••••••`),ce(o.saved)}catch(e){oe(e instanceof Error?e.message:String(e))}finally{X(void 0)}},ge=async()=>{X(`test`),oe(void 0),ce(void 0),ue(void 0);try{let e=await me();ue((await It(e.providerId,e.input.imageGeneration.defaultModel)).images[0]?.dataUrl),ce(o.testReady)}catch(e){oe(e instanceof Error?e.message:String(e))}finally{X(void 0)}},_e=async()=>{if(n){if(!re){ie(!0);return}X(`delete`),oe(void 0);try{await Rt(n.providerId),await a(),t(!1)}catch(e){oe(e instanceof Error?e.message:String(e))}finally{X(void 0)}}};return(0,$.jsx)(W,{open:e,onOpenChange:t,children:(0,$.jsxs)(H,{children:[(0,$.jsx)(z,{className:S(`xopc-dialog-overlay fixed inset-0 bg-scrim`,R)}),(0,$.jsxs)(U,{className:S(`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`,L),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)(ee,{className:`font-semibold text-fg`,children:n?o.editTitle:o.addTitle}),(0,$.jsx)(B,{className:`mt-1 text-sm text-fg-muted`,children:o.intro})]}),(0,$.jsx)(V,{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)(x,{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:Bt}),(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:Bt})]})]}),(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:Bt})]}),(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:m,options:[{value:`bearer`,label:o.bearer},{value:`header`,label:o.header},{value:`none`,label:o.none}],placeholder:o.auth,allowEmpty:!1,onChange:e=>g(e),triggerClassName:`mt-1.5`})]}),m===`header`?(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.headerName,(0,$.jsx)(`input`,{value:v,onChange:e=>b(e.target.value),className:Bt})]}):null]}),m===`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}),E.trim()?(0,$.jsxs)(`a`,{href:E.trim(),target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent hover:underline`,children:[o.openKeyPage,(0,$.jsx)(De,{className:`size-3.5`})]}):null]}),(0,$.jsx)(He,{id:`custom-image-api-key`,value:w,onChange:e=>T(k(w)?e.replace(/^•+/,``):e),labels:{show:o.show,hide:o.hide,copy:o.copy,copied:o.copied},reveal:()=>Ke(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:E,onChange:e=>D(e.target.value),placeholder:`https://…`,className:Bt})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.docsUrl,(0,$.jsx)(`input`,{value:O,onChange:e=>A(e.target.value),placeholder:`https://…`,className:Bt})]})]}),(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:j,onChange:e=>M(e.target.value),className:Bt})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.editsPath,(0,$.jsx)(`input`,{value:N,onChange:e=>P(e.target.value),className:Bt})]})]}),(0,$.jsxs)(`label`,{className:`mt-4 block text-xs font-medium text-fg-muted`,children:[o.allowedHosts,(0,$.jsx)(`textarea`,{value:F,onChange:e=>I(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:G,onChange:e=>K(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)(C,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,onClick:()=>te(e=>[...e,Vt()]),children:[(0,$.jsx)(y,{className:`size-4`}),o.addModel]})]}),(0,$.jsxs)(`label`,{className:`block text-xs font-medium text-fg-muted`,children:[o.defaultModel,(0,$.jsx)(d,{value:ne||de[0]?.value||``,options:de,placeholder:o.defaultModel,allowEmpty:!1,onChange:J,triggerClassName:`mt-1.5 max-w-sm`})]}),q.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=>fe(t,{id:e.target.value}),placeholder:`image-1`,className:Bt})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.modelName,(0,$.jsx)(`input`,{value:e.name,onChange:e=>fe(t,{name:e.target.value}),className:Bt})]})]}),(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=>fe(t,{maxCount:e.target.value}),className:Bt})]}),(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=>fe(t,{defaultCount:e.target.value}),className:Bt})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.defaultSize,(0,$.jsx)(`input`,{value:e.defaultSize,onChange:e=>fe(t,{defaultSize:e.target.value}),placeholder:`1024x1024`,className:Bt})]}),(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=>fe(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=>fe(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=>fe(t,{editEnabled:e.target.checked})}),o.edit]}),(0,$.jsxs)(`button`,{type:`button`,disabled:q.length===1,onClick:()=>te(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)(Ge,{className:`size-3.5`}),o.remove]})]})]},t))]}),le?(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)(h,{className:`size-4`}),o.testReady]}),(0,$.jsx)(`img`,{src:le,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,ae?(0,$.jsx)(`p`,{className:`rounded-lg bg-red-500/10 px-3 py-2 text-sm text-red-600 dark:text-red-400`,children:ae}):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)(C,{variant:`secondary`,className:`border-red-500/30 text-red-600 hover:bg-red-500/10 dark:text-red-400`,disabled:!!Y,onClick:()=>void _e(),children:[Y===`delete`?(0,$.jsx)(_,{className:`size-4 animate-spin`}):(0,$.jsx)(Ge,{className:`size-4`}),re?o.confirmDelete:o.delete]}):null,(0,$.jsxs)(`div`,{className:`ml-auto flex gap-2`,children:[(0,$.jsx)(V,{asChild:!0,children:(0,$.jsx)(C,{variant:`secondary`,children:o.cancel})}),(0,$.jsxs)(C,{variant:`secondary`,disabled:!!Y,onClick:()=>void ge(),children:[Y===`test`?(0,$.jsx)(_,{className:`size-4 animate-spin`}):null,Y===`test`?o.testing:o.test]}),(0,$.jsxs)(C,{variant:`primary`,disabled:!!Y,onClick:()=>void he(),children:[Y===`save`?(0,$.jsx)(_,{className:`size-4 animate-spin`}):null,Y===`save`?o.saving:o.save]})]})]})]})]})})}var Wt=`••••••••••••`,Gt={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 Kt(e){let t=await j(P(`/api/agents/${encodeURIComponent(e)}/image-generation`));if(!t.payload)throw Error(`Invalid agent image generation response`);return t.payload}function qt(e){let t=e?.indexOf(`/`)??-1;return t>0?e.slice(0,t):void 0}function Jt(e){let t=e?.indexOf(`/`)??-1;return t>0?e.slice(t+1):void 0}function Yt(e){return Object.fromEntries(e.configFields.map(t=>[t.key,e.config[t.key]??(t.required?t.options?.[0]?.value??``:``)]))}function Xt(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(Zt),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 Zt(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)(I,{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($t)}),(0,$.jsx)(I,{className:`h-64 rounded-xl`})]}),e[1]=n):n=e[1],n}function $t(e,t){return(0,$.jsx)(I,{className:`h-24 rounded-xl`},t)}function en(){let e=N(e=>e.language),t=Gt[e],n=A(e),r=!!F(e=>e.token),[i,a]=(0,Q.useState)(``),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(``),[u,p]=(0,Q.useState)(``),[m,h]=(0,Q.useState)({}),[g,v]=(0,Q.useState)(!1),[b,x]=(0,Q.useState)(),[S,w]=(0,Q.useState)(!1),[T,E]=(0,Q.useState)(!1),[D,O]=(0,Q.useState)(),{data:M,isLoading:I,error:L}=G(r?`image-generation-agents`:null,ve,{revalidateOnFocus:!1}),{data:R,isLoading:z,error:B,mutate:V}=G(r?P(`/api/image-generation/catalog`):null,Lt,{revalidateOnFocus:!1}),{data:H,isLoading:U,error:ee,mutate:W}=G(r?P(`/api/image-generation/custom-providers`):null,Ft,{revalidateOnFocus:!1});(0,Q.useEffect)(()=>{!M||i||a(M.defaultId||M.agents[0]?.id||``)},[i,M]);let{data:K,isLoading:q,error:te,mutate:ne}=G(r&&i?[`agent-image-generation`,i]:null,()=>Kt(i),{revalidateOnFocus:!1});(0,Q.useEffect)(()=>{if(!R||!K)return;let e=qt(K.model?.primary),t=R.find(t=>t.id===e)??R.find(e=>e.configured)??R[0];t&&(s(t.id),l(t.id===e&&Jt(K.model?.primary)||t.defaultModel),p(t.configured?Wt:``),h(Yt(t)))},[K,R]),(0,Q.useEffect)(()=>{x(void 0)},[i]);let J=R?.find(e=>e.id===o),Y=J?J.apiKeyUrl??ye(J.id,e)[0]?.href:void 0,X=(0,Q.useMemo)(()=>(M?.agents??[]).map(e=>({value:e.id,label:Oe(e,n.agentsSettings)})),[M?.agents,n.agentsSettings]),re=(0,Q.useMemo)(()=>(J?.models??[]).map(e=>({value:e,label:e})),[J?.models]),ie=K?.model?.primary,ae=!!(i&&J&&c&&(J.credentialMode!==`api-key`||J.configured||u.trim())&&J.configFields.every(e=>!e.required||m[e.key]?.trim()));if(!r)return(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.connect});if(I||z||U||q)return(0,$.jsx)(Qt,{});if(L||B||ee||te||!R||!M||!H)return(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:t.loadError});let oe=e=>{s(e.id),l(e.defaultModel),p(e.configured?Wt:``),h(Yt(e)),x(void 0)},se=()=>{O(void 0),E(!0)},ce=()=>{let e=H.find(e=>e.providerId===J?.id);e&&(O(e),E(!0))},le=async e=>{let[t,n]=await Promise.all([W(),V()]);if(e&&n?.some(t=>t.id===e)){let r=n.find(t=>t.id===e);s(r.id),l(r.defaultModel),p(r.configured?Wt:``),h(Yt(r)),O(t?.find(t=>t.providerId===e))}},ue=async()=>{if(!(!J||!ae)){v(!0),x(void 0),w(!1);try{let e=await j(P(`/api/agents/${encodeURIComponent(i)}/image-generation/setup`),{method:`POST`,body:JSON.stringify({providerId:J.id,modelId:c,...u.trim()&&!k(u)?{apiKey:u.trim()}:{},providerConfig:Object.fromEntries(Object.entries(m).filter(([,e])=>e.trim()))})});if(!e.payload)throw Error(`Invalid setup response`);await Promise.all([ne(e.payload.agent,{revalidate:!1}),V(e.payload.providers,{revalidate:!1})]),p(Wt),w(!0)}catch(e){x(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)(he,{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:X,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)(C,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,onClick:se,children:[(0,$.jsx)(y,{className:`size-4`}),t.addService]})]}),(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 xl:grid-cols-3`,children:R.map(e=>{let n=e.id===o,r=e.id===qt(ie);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>oe(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)(f,{className:`size-3.5`}):(0,$.jsx)(be,{className:`size-3.5`}),e.configured||e.credentialMode!==`api-key`?t.configured:t.needsKey]})]},e.id)})})]}),J?(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:re,placeholder:t.selectModel,allowEmpty:!1,onChange:l,triggerClassName:`mt-1.5`})]}),J.configFields.filter(e=>e.required).map(e=>(0,$.jsx)(Xt,{field:e,value:m[e.key]??``,onChange:t=>h(n=>({...n,[e.key]:t}))},e.key))]}),J.source===`custom`?(0,$.jsx)(`div`,{className:`mt-4 flex justify-end`,children:(0,$.jsxs)(C,{variant:`secondary`,onClick:ce,children:[(0,$.jsx)(ct,{className:`size-4`}),t.manageService]})}):null,J.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}),Y?(0,$.jsxs)(`a`,{href:Y,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs font-medium text-accent hover:underline`,children:[t.getApiKey,(0,$.jsx)(De,{className:`size-3.5`,"aria-hidden":`true`})]}):null]}),(0,$.jsx)(He,{id:`image-generation-api-key`,value:u,onChange:e=>p(k(u)?e.replace(/^•+/,``):e),placeholder:J.configured?t.existingKey:t.needsKey,labels:{show:t.show,hide:t.hide,copy:t.copy,copied:t.copied},reveal:()=>Ke(J.id).then(e=>e.apiKey),loadFailedLabel:t.revealFailed,notInConfigFile:t.keyNotRevealable,className:`mt-1.5`,autoComplete:`new-password`},J.id),(0,$.jsx)(`span`,{className:`mt-1.5 block font-normal leading-relaxed text-fg-subtle`,children:J.configured?t.savedKey:t.apiKeyHint})]}):null,J.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)(xe,{className:`size-4`}),t.advanced]}),(0,$.jsx)(`div`,{className:`mt-3 grid gap-3 md:grid-cols-2`,children:J.configFields.filter(e=>!e.required).map(e=>(0,$.jsx)(Xt,{field:e,value:m[e.key]??``,onChange:t=>h(n=>({...n,[e.key]:t}))},e.key))})]}):null,S?(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,b?(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:b}):null,(0,$.jsx)(`div`,{className:`mt-4 flex justify-end`,children:(0,$.jsxs)(C,{variant:`primary`,disabled:!ae||g,onClick:()=>void ue(),children:[g?(0,$.jsx)(_,{className:`size-4 animate-spin`}):(0,$.jsx)(f,{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:g?t.enabling:t.enable})]})]})})]}):null,(0,$.jsx)(Ut,{open:T,onOpenChange:E,provider:D,configured:!!(D&&R.find(e=>e.id===D.providerId)?.configured),language:e,onSaved:le})]})}var tn=w;function nn(){return S(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,E,`dark:border-edge`)}function rn(){return S(T,w)}function an(e){return!e||e<=0?``:e<1024*1024?`${Math.round(e/1024)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function on(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 sn(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 cn(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 ln(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 un(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 dn(e){return{maskedHelp:e.apiKeyMaskedHelp,copy:e.apiKeyCopy,copied:e.apiKeyCopied,show:e.apiKeyShow,hide:e.apiKeyHide,notInConfigFile:e.apiKeyNotInConfigFile,loadFailed:e.apiKeyRevealFailed}}function fn(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 pn(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 mn(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 hn(){let e=N(e=>e.language),t=A(e).voiceSettings,n=!!F(e=>e.token),[r,i]=(0,Q.useReducer)(mn,{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}=q(n),{data:g,error:_,isLoading:v,mutate:y}=G(n?P(`/api/voice/models`):null,St,{revalidateOnFocus:!1}),{data:b,error:x,isLoading:S}=G(n?P(`/api/voice/providers`):null,yt,{revalidateOnFocus:!1}),{data:w,error:T,isLoading:E}=G(n?P(`/api/voice/stt-providers`):null,Dt,{revalidateOnFocus:!1}),D=(0,Q.useMemo)(()=>b?.providers??[],[b]),O=(0,Q.useMemo)(()=>w?.providers??[],[w]),k=(0,Q.useMemo)(()=>f?.payload?.config===void 0?null:Ct(f.payload.config),[f]),j=(0,Q.useMemo)(()=>!a||!o?!1:JSON.stringify(a)!==JSON.stringify(o),[a,o]);n?k!==null&&g!==void 0&&!l.current&&(d.current.parsed!==k||d.current.models!==g)&&(d.current={parsed:k,models:g},i({type:`sync`,value:k}),c(g)):(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 M=!!(n&&(k===null||g===void 0||b===void 0||w===void 0)&&(m||v||S||E)),I=p instanceof Error?p.message:p?String(p):_ instanceof Error?_.message:_?String(_):x instanceof Error?x.message:x?String(x):T instanceof Error?T.message:T?String(T):null,L=(0,Q.useCallback)(e=>{l.current=!0,i({type:`update`,updater:t=>t?{...t,stt:{...t.stt,...e}}:null})},[]),R=(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}}}}})},[]),z=(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})},[]),B=(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]),V=(0,Q.useCallback)(e=>{l.current=!0,i({type:`update`,updater:t=>t?{...t,tts:{...t.tts,...e}}:null})},[]),H=vt({value:a,dirty:j,onSave:(0,Q.useCallback)(async e=>{let n=o?.stt.provider!==`xopc-local`&&e.stt.provider===`xopc-local`;try{await kt(e),n&&window.dispatchEvent(new Event(Ot)),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)}},[o?.stt.provider,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(M)return(0,$.jsx)(dt,{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)(C,{type:`button`,variant:`secondary`,onClick:()=>{h(),y()},children:t.retry})]});let U=a.stt,ee=a.tts,W=a.voice.input.refinement,K=dn(t);return(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,onBlurCapture:H.onBlurCapture,children:[(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(_t,{status:H.status,error:H.error})}),H.error?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:H.error}):null,(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsx)(gn,{v:t,voice:a.voice,updateLanguageMode:B}),(0,$.jsx)(_n,{v:t,stt:U,tts:ee}),(0,$.jsx)(yn,{v:t,apiKeyLabels:K,stt:U,models:s,sttProviders:O,refinement:W,updateStt:L,updateSttFallback:R,updateRefinement:z}),(0,$.jsx)(Cn,{v:t,apiKeyLabels:K,tts:ee,models:s,ttsProviders:D,updateTts:V})]}),(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 gn(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=rn(),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 _n(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} · ${sn(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)(vn,{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?ln(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)(vn,{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?`${cn(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)(vn,{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 vn(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=S(`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 yn(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,h,g,_,v;if(t[2]!==a||t[3]!==m||t[4]!==i.provider||t[5]!==i.providers){h=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],_=e,g=a?.stt?.[i.provider]?.length?a.stt[i.provider]:h?.models??[],v=h?.fields.find(bn),t[2]=a,t[3]=m,t[4]=i.provider,t[5]=i.providers,t[6]=h,t[7]=g,t[8]=_,t[9]=v}else h=t[6],g=t[7],_=t[8],v=t[9];let y=v,b=typeof _.model==`string`?_.model:void 0,x=b??(typeof y?.defaultValue==`string`?y.defaultValue:g[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]!==b||t[18]!==x||t[19]!==y||t[20]!==w?(T=()=>{y&&x&&b!==x&&w({model:x})},E=[b,x,y,w],t[17]=b,t[18]=x,t[19]=y,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)(Ue,{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)(Tn,{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]!==h?.fields||t[41]!==r||t[42]!==x||t[43]!==g||t[44]!==m||t[45]!==_||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:S(`flex flex-col gap-1.5`,tn),children:[(0,$.jsx)(On,{children:n.stt.provider}),(0,$.jsx)(l,{className:rn(),value:i.provider,onChange:e=>c({provider:e.target.value}),children:m.map(e=>(0,$.jsxs)(u,{value:e.id,children:[sn(e.id,n),e.configured?``:` *`]},e.id))})]}),(0,$.jsx)(wn,{kind:`stt`,providerId:i.provider,fields:h?.fields??[],providerSlice:_,models:g,currentModel:x,apiKeyLabels:r,onPatch:w})]}),i.provider===`xopc-local`?(0,$.jsx)(Sn,{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:rn(),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]=h?.fields,t[41]=r,t[42]=x,t[43]=g,t[44]=m,t[45]=_,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 bn(e){return e.key===`model`}function xn(e){return`${Math.round(e/1024/1024)} MB`}function Sn({v:e}){let{data:t,error:n,mutate:r}=G(P(`/api/voice/local/status`),wt,{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);(0,Q.useEffect)(()=>{let e=()=>void r();return window.addEventListener(Ot,e),()=>window.removeEventListener(Ot,e)},[r]);let 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,t?.runtime.ready===!1?(0,$.jsx)(`p`,{className:`mt-3 text-xs text-red-600 dark:text-red-400`,children:t.runtime.error??`Local voice runtime is unavailable`}):null,t?.decoder?.available===!1?(0,$.jsx)(`p`,{className:`mt-3 text-xs text-amber-700 dark:text-amber-300`,children:t.decoder.error??`Compressed audio decoding is unavailable`}):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:S(`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:[xn(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)(C,{type:`button`,variant:`secondary`,disabled:n,onClick:()=>void c(t,t.state===`ready`?`remove`:`install`),children:n?(0,$.jsx)(_,{className:`size-4 animate-spin`}):t.state===`ready`?e.stt.localRemove:e.stt.localInstall})]},t.id)})})]})}function Cn({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),m=(0,Q.useCallback)(()=>{f.current?.pause(),f.current=null,p.current&&=(URL.revokeObjectURL(p.current),null)},[]),h=(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]),g=h.find(e=>e.id===n.provider),v=n.providers?.[n.provider]??{},y=r?.tts?.[n.provider]?.length?r.tts[n.provider]:g?.models??[],b=g?.fields.find(e=>e.key===`model`),x=g?.fields.find(e=>e.key===`voice`),w=typeof v.model==`string`?v.model:void 0,T=w??(typeof b?.defaultValue==`string`?b.defaultValue:y[0]?.id),E=y.find(e=>e.id===T),D=r?.ttsVoices?.[n.provider]?.length?r.ttsVoices[n.provider]:g?.voices??[],{data:O=[]}=G(T?`voice:tts:${n.provider}:${T}`:null,()=>Et(n.provider,T??``),{revalidateOnFocus:!1}),k=O.length>0?O:D,A=typeof v.voice==`string`?v.voice:void 0,j=A??k.find(e=>e.id===E?.tts?.defaultVoice)?.id??(typeof x?.defaultValue==`string`?x.defaultValue:k[0]?.id),M=(g?.fields??[]).filter(e=>(e.key!==`speed`||E?.tts?.speed!==!1)&&(e.key!==`instructions`||E?.tts?.instructions!==!1)),N=!!g?.diagnostics.requiresApiKey,P=!!g?.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={};b&&T&&w!==T&&(e.model=T),x&&j&&A!==j&&(e.voice=j),Object.keys(e).length>0&&I(e)},[w,A,T,j,b,I,x]),(0,Q.useEffect)(()=>()=>m(),[m]);let L=(0,Q.useCallback)(e=>{a({provider:e}),d({status:`idle`})},[a]),R=(0,Q.useCallback)(async()=>{let t=o.trim();if(!t){d({status:`error`,message:e.tts.test.emptyText});return}m(),d({status:`loading`});try{let r=await Tt({text:t,provider:n.provider,providerConfig:v,...T?{model:T}:{},...j?{voice:j}:{}}),i=on(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`,an(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){m(),d({status:`error`,message:e instanceof Error?e.message:String(e)})}},[T,j,v,m,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)($e,{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)(Tn,{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:S(`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} ${cn(n.provider,e)}${j?` · ${j}`:``}`:`${e.tts.statusNeedsSetup} ${cn(n.provider,e)} · ${g?.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:S(`flex flex-col gap-1.5`,tn),children:[(0,$.jsx)(On,{children:e.tts.trigger}),(0,$.jsxs)(l,{className:rn(),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:S(`flex flex-col gap-1.5`,tn),children:[(0,$.jsx)(On,{children:e.tts.provider}),(0,$.jsx)(l,{className:rn(),value:n.provider,onChange:e=>L(e.target.value),children:h.map(t=>(0,$.jsx)(u,{value:t.id,children:cn(t.id,e)},t.id))}),(0,$.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[g?.configured?e.tts.configured:g?.diagnostics.requiresApiKey?`${e.tts.needsKey} · ${g.diagnostics.envKeys?.join(`, `)??e.stt.apiKey}`:e.tts.noKeyNeeded,` · `,g?.description??un(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)(wn,{kind:`tts`,providerId:n.provider,fields:M,providerSlice:v,models:y,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)(C,{type:`button`,variant:`primary`,onClick:()=>void R(),disabled:c.status===`loading`,className:`h-9`,children:[c.status===`loading`?(0,$.jsx)(_,{className:`size-4 animate-spin`}):(0,$.jsx)(Te,{className:`size-4`}),c.status===`loading`?e.tts.test.generating:e.tts.test.play]}),(0,$.jsxs)(C,{type:`button`,variant:`secondary`,onClick:()=>{m(),d(e=>e.status===`playing`?{status:`done`,summary:e.summary}:{status:`idle`})},disabled:c.status!==`playing`,className:`h-9`,children:[(0,$.jsx)(fe,{className:`size-4`}),e.tts.test.stop]})]})]}),(0,$.jsx)(`textarea`,{className:S(nn(),`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 wn({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:S(`flex flex-col gap-1.5`,tn),children:[(0,$.jsx)(On,{children:n.label}),(0,$.jsx)(At,{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:S(`flex flex-col gap-1.5`,tn),children:[(0,$.jsx)(On,{children:n.label}),(0,$.jsx)(l,{className:rn(),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:S(`flex flex-col gap-1.5`,tn),children:[(0,$.jsx)(On,{children:n.label}),(0,$.jsx)(l,{className:rn(),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)(En,{field:n,value:fn(r,n),onChange:e=>d({[n.key]:e}),className:n.type===`textarea`?`sm:col-span-2`:tn},n.key))}function Tn(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=S(`group flex w-full items-center justify-between gap-4 rounded-2xl px-4 py-3 text-left shadow-surface transition-colors`,E,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=S(`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 h;t[10]!==m||t[11]!==r?(h=(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]=h):h=t[12];let g;t[13]===i?g=t[14]:(g=(0,$.jsx)(`span`,{className:`mt-1 block text-xs leading-relaxed text-fg-muted`,children:i}),t[13]=i,t[14]=g);let _;t[15]!==h||t[16]!==g?(_=(0,$.jsxs)(`span`,{className:`min-w-0`,children:[h,g]}),t[15]=h,t[16]=g,t[17]=_):_=t[17];let v=n?`border-accent bg-accent`:`border-edge bg-surface-hover group-hover:border-accent/40`,y;t[18]===v?y=t[19]:(y=S(`relative inline-flex h-6 w-11 shrink-0 items-center rounded-full border transition-colors`,v),t[18]=v,t[19]=y);let b=n?`translate-x-5`:`translate-x-0.5`,x;t[20]===b?x=t[21]:(x=S(`size-5 rounded-full bg-white shadow-surface transition-transform`,b),t[20]=b,t[21]=x);let C;t[22]===x?C=t[23]:(C=(0,$.jsx)(`span`,{className:x}),t[22]=x,t[23]=C);let w;t[24]!==y||t[25]!==C?(w=(0,$.jsx)(`span`,{className:y,"aria-hidden":!0,children:C}),t[24]=y,t[25]=C,t[26]=w):w=t[26];let T;return t[27]!==n||t[28]!==c||t[29]!==_||t[30]!==w||t[31]!==u?(T=(0,$.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":n,onClick:c,className:u,children:[_,w]}),t[27]=n,t[28]=c,t[29]=_,t[30]=w,t[31]=u,t[32]=T):T=t[32],T}function En(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=S(`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(pn(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=S(`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)(On,{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:rn(),value:c,required:n.required,onChange:e=>i(pn(n,e.target.value)),children:(n.options??[]).map(Dn)}):n.type===`textarea`?(0,$.jsx)(`textarea`,{id:o,className:S(nn(),`min-h-24 resize-y`),value:c,required:n.required,placeholder:n.placeholder,onChange:e=>i(pn(n,e.target.value))}):n.type===`password`?(0,$.jsx)(He,{id:o,className:a,value:c,onChange:e=>i(pn(n,e)),placeholder:n.placeholder,labels:Pe}):(0,$.jsx)(`input`,{id:o,className:nn(),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(pn(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 Dn(e){return(0,$.jsx)(u,{value:e.id,children:e.name},e.id)}function On(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 kn(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 An(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 j(P(`/api/config`),{method:`PATCH`,body:JSON.stringify({tools:{web:{region:t,search:n,blocklist:{enabled:e.blocklistEnabled,domains:e.blocklistDomains}}}})}),K()}async function jn(e){let t=await j(P(`/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 Mn(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 Nn(){return S(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,E,`dark:border-edge`)}function Pn(){return S(T,w)}var Fn=[`brave`,`tavily`,`bing`,`searxng`];function In(){return{type:`brave`,apiKey:``,url:``,disabled:!1}}var Ln=Se();function Rn(){let e=A(N(e=>e.language)),t=e.webSearchSettings,n=e.logs,r=!!F(e=>e.token),[i,a]=(0,Q.useReducer)(Ln,{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:h,mutate:g}=q(r);Ce({enabled:r,parsed:(0,Q.useMemo)(()=>p?.payload?.config===void 0?null:kn(p.payload.config),[p]),dirty:c.current,trackedParsedRef:f,dispatch:a,onResetDirty:()=>{c.current=!1}});let _=!!(r&&h&&p===void 0&&!m),v=m instanceof Error?m.message:m?String(m):null,x=(0,Q.useMemo)(()=>!o||!s?!1:JSON.stringify(o)!==JSON.stringify(s),[o,s]),w=(0,Q.useCallback)(e=>{c.current=!0,a({type:`patch`,patch:e})},[]),T=vt({value:o,dirty:x,onSave:(0,Q.useCallback)(async e=>{try{await An(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?_?(0,$.jsx)(dt,{rows:3}):o?(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,onBlurCapture:T.onBlurCapture,children:[T.error?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:T.error}):null,(0,$.jsxs)(pt,{children:[(0,$.jsx)(ft,{icon:b,title:t.sectionRegion,subtitle:t.sectionRegionHint,trailing:(0,$.jsx)(_t,{status:T.status,error:T.error})}),(0,$.jsx)(`div`,{className:`flex max-w-md flex-col gap-4`,children:(0,$.jsx)(Mn,{label:t.regionLabel,description:t.regionDesc,children:(0,$.jsxs)(l,{className:Pn(),value:o.regionMode,onChange:e=>w({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)(Mt,{children:(0,$.jsxs)(pt,{children:[(0,$.jsx)(ft,{icon:ke,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=>w({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)(Mn,{label:t.blocklistDomains,description:t.blocklistDomainsDesc,children:(0,$.jsx)(`textarea`,{className:S(Nn(),`min-h-[6rem] font-mono text-xs`),value:o.blocklistDomains.join(`
7
+ `),placeholder:t.blocklistDomainsPlaceholder,disabled:!o.blocklistEnabled,onChange:e=>{w({blocklistDomains:e.target.value.split(/\r?\n/).flatMap(e=>{let t=e.trim().toLowerCase();return t?[t]:[]})})}})})]})]})}),(0,$.jsxs)(pt,{children:[(0,$.jsx)(ft,{icon:b,title:t.sectionSearch,subtitle:t.sectionSearchHint}),(0,$.jsxs)(`div`,{className:`flex max-w-xl flex-col gap-6`,children:[(0,$.jsx)(Mn,{label:t.maxResultsLabel,description:t.maxResultsDesc,children:(0,$.jsx)(`input`,{type:`number`,min:1,max:50,className:Nn(),value:o.maxResults,onChange:e=>w({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)(zn,{row:n,providerIndex:r,labels:t,secretLabels:we(e.providersSettings),onChange:e=>{let t=[...o.providers];t[r]=e,w({providers:t})},onRemove:()=>{w({providers:o.providers.filter((e,t)=>t!==r)})}},`${n.type}:${n.url}:${n.apiKey}:${n.disabled}`)),(0,$.jsxs)(C,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5 text-sm`,onClick:()=>w({providers:[...o.providers,In()]}),children:[(0,$.jsx)(y,{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:v??t.loadError}),(0,$.jsx)(C,{type:`button`,variant:`secondary`,onClick:()=>void g(),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 zn(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=()=>jn(r).then(Bn),t[0]=r,t[1]=c);let d=c,f;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(f=S(Pn(),`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 h;t[6]===i.providerTypes?h=t[7]:(h=Fn.map(e=>(0,$.jsx)(u,{value:e,children:i.providerTypes[e]},e)),t[6]=i.providerTypes,t[7]=h);let g;t[8]!==n.type||t[9]!==m||t[10]!==h?(g=(0,$.jsx)(l,{className:f,value:p,onChange:m,children:h}),t[8]=n.type,t[9]=m,t[10]=h,t[11]=g):g=t[11];let _;t[12]!==o||t[13]!==n?(_=e=>o({...n,disabled:e.target.checked}),t[12]=o,t[13]=n,t[14]=_):_=t[14];let v;t[15]!==n.disabled||t[16]!==_?(v=(0,$.jsx)(`input`,{type:`checkbox`,className:`size-3.5 rounded border-edge`,checked:n.disabled,onChange:_}),t[15]=n.disabled,t[16]=_,t[17]=v):v=t[17];let y;t[18]!==i.disabled||t[19]!==v?(y=(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1.5 text-xs text-fg-muted`,children:[v,i.disabled]}),t[18]=i.disabled,t[19]=v,t[20]=y):y=t[20];let b;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,$.jsx)(Ge,{className:`size-4`}),t[21]=b):b=t[21];let x;t[22]===s?x=t[23]:(x=(0,$.jsx)(C,{type:`button`,variant:`ghost`,className:`h-8 px-2 text-fg-muted`,onClick:s,children:b}),t[22]=s,t[23]=x);let w;t[24]!==x||t[25]!==y?(w=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[y,x]}),t[24]=x,t[25]=y,t[26]=w):w=t[26];let T;t[27]!==w||t[28]!==g?(T=(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[g,w]}),t[27]=w,t[28]=g,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)(Mn,{label:i.urlLabel,description:i.urlDesc,children:(0,$.jsx)(`input`,{type:`url`,className:Nn(),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)(He,{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)(Mn,{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 Bn(e){return e.apiKey??null}var Vn=[`common`,`domestic`,`specialty`,`enterprise`,`oauth`,`extension`];function Hn(e){let t=new Map;for(let e of Vn)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}var Un=`xopc-cloud`;function Wn(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 h=m,g;t[3]!==h||t[4]!==c?(g=()=>{c(),h(!1)},t[3]=h,t[4]=c,t[5]=g):g=t[5];let _=g,v;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(z,{className:S(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,R)}),t[6]=v):v=t[6];let y;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(y=S(`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`,L),t[7]=y):y=t[7];let b;t[8]!==i||t[9]!==a||t[10]!==_||t[11]!==o||t[12]!==s||t[13]!==f||t[14]!==u.presetKey||t[15]!==u.providerId||t[16]!==u.type?(b=(0,$.jsxs)(H,{children:[v,(0,$.jsx)(U,{className:y,children:u.type===`pick`?(0,$.jsx)(Kn,{builtinRows:i,searchQuery:f,onSearchChange:p,labels:o,onPickBuiltin:e=>{let t=Re(e);d(t?{type:`custom`,presetKey:t}:{type:`builtin`,providerId:e})},onPickCustom:()=>d({type:`custom`})}):u.type===`builtin`?(0,$.jsx)(Xn,{providerId:u.providerId,builtinRows:i,labels:o,language:s,onBack:()=>d({type:`pick`}),onSaved:_}):(0,$.jsx)($n,{initialPresetKey:u.presetKey,customConfig:a,labels:o,language:s,onBack:()=>d({type:`pick`}),onSaved:_})})]}),t[8]=i,t[9]=a,t[10]=_,t[11]=o,t[12]=s,t[13]=f,t[14]=u.presetKey,t[15]=u.providerId,t[16]=u.type,t[17]=b):b=t[17];let x;return t[18]!==h||t[19]!==n||t[20]!==b?(x=(0,$.jsx)(W,{open:n,onOpenChange:h,children:b}),t[18]=h,t[19]=n,t[20]=b,t[21]=x):x=t[21],x}function Gn(e){let t=(0,Z.c)(4),{label:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=S(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,D.press),t[0]=r):r=t[0];let i;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(x,{className:`size-4`,"aria-hidden":!0}),t[1]=i):i=t[1];let a;return t[2]===n?a=t[3]:(a=(0,$.jsx)(V,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:r,"aria-label":n,children:i})}),t[2]=n,t[3]=a),a}function Kn(e){let t=(0,Z.c)(49),{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=me[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=d.find(Jn),t[7]=d,t[8]=f);let p=f,m;t[9]===d?m=t[10]:(m=Hn(d.filter(qn)),t[9]=d,t[10]=m);let h=m,_;t[11]===a.step1Title?_=t[12]:(_=(0,$.jsx)(ee,{className:`min-w-0 flex-1 text-base font-semibold text-fg`,children:a.step1Title}),t[11]=a.step1Title,t[12]=_);let v;t[13]===a.close?v=t[14]:(v=(0,$.jsx)(Gn,{label:a.close}),t[13]=a.close,t[14]=v);let y;t[15]!==_||t[16]!==v?(y=(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b border-edge-subtle px-5 py-4`,children:[_,v]}),t[15]=_,t[16]=v,t[17]=y):y=t[17];let x;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,$.jsx)(b,{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[18]=x):x=t[18];let C;t[19]===i?C=t[20]:(C=e=>i(e.target.value),t[19]=i,t[20]=C);let w=a.searchPlaceholder,T;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(T=S(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-10 pr-3 text-sm text-fg placeholder:text-fg-subtle`,E),t[21]=T):T=t[21];let O;t[22]!==a.searchPlaceholder||t[23]!==r||t[24]!==C?(O=(0,$.jsx)(`div`,{className:`px-5 pt-3`,children:(0,$.jsxs)(`div`,{className:`relative`,children:[x,(0,$.jsx)(`input`,{type:`search`,value:r,onChange:C,placeholder:w,autoComplete:`off`,className:T})]})}),t[22]=a.searchPlaceholder,t[23]=r,t[24]=C,t[25]=O):O=t[25];let k;t[26]!==a.recommended||t[27]!==o||t[28]!==p?(k=p?(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`p`,{className:`mb-1 px-1 text-[11px] font-semibold uppercase tracking-wide text-fg-subtle`,children:a.recommended}),(0,$.jsx)(Yn,{row:p,onPick:o})]}):null,t[26]=a.recommended,t[27]=o,t[28]=p,t[29]=k):k=t[29];let A;t[30]!==a.addCustom||t[31]!==a.customDescription||t[32]!==s||t[33]!==l?(A=l?null:(0,$.jsxs)(`button`,{type:`button`,onClick:s,className:S(`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`,D.press),children:[(0,$.jsx)(g,{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)(de,{className:`size-4 shrink-0 text-fg-subtle`,"aria-hidden":!0})]}),t[30]=a.addCustom,t[31]=a.customDescription,t[32]=s,t[33]=l,t[34]=A):A=t[34];let j;t[35]!==d.length||t[36]!==h||t[37]!==a.categories||t[38]!==a.noResults||t[39]!==o?(j=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:Vn.map(e=>{let t=h.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,$.jsx)(Yn,{row:e,onPick:o},e.id))})]},e)})}),t[35]=d.length,t[36]=h,t[37]=a.categories,t[38]=a.noResults,t[39]=o,t[40]=j):j=t[40];let M;t[41]!==k||t[42]!==A||t[43]!==j?(M=(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto px-5 py-3`,children:[k,A,j]}),t[41]=k,t[42]=A,t[43]=j,t[44]=M):M=t[44];let N;return t[45]!==O||t[46]!==M||t[47]!==y?(N=(0,$.jsxs)($.Fragment,{children:[y,O,M]}),t[45]=O,t[46]=M,t[47]=y,t[48]=N):N=t[48],N}function qn(e){return e.id!==Un}function Jn(e){return e.id===Un}function Yn(e){let t=(0,Z.c)(12),{row:n,onPick:r}=e,i;t[0]!==r||t[1]!==n.id?(i=()=>r(n.id),t[0]=r,t[1]=n.id,t[2]=i):i=t[2];let a;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(a=S(`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`,D.press),t[3]=a):a=t[3];let o;t[4]===n.name?o=t[5]:(o=(0,$.jsx)(`span`,{className:`truncate text-sm text-fg`,children:n.name}),t[4]=n.name,t[5]=o);let s;t[6]===n.configured?s=t[7]:(s=n.configured?(0,$.jsx)(f,{className:`size-3.5 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):null,t[6]=n.configured,t[7]=s);let c;return t[8]!==i||t[9]!==o||t[10]!==s?(c=(0,$.jsxs)(`button`,{type:`button`,onClick:i,className:a,children:[o,s]}),t[8]=i,t[9]=o,t[10]=s,t[11]=c):c=t[11],c}function Xn({providerId:e,builtinRows:t,labels:n,language:r,onBack:i,onSaved:a}){let o=t.find(t=>t.id===e),s=me[e],[c,l]=(0,Q.useState)(``),[u,d]=(0,Q.useState)(!1),[p,m]=(0,Q.useState)(null),[h,g]=(0,Q.useState)(!1),v=(0,Q.useRef)(null),y=A(r).providersSettings,b=we(y),x=(0,Q.useMemo)(()=>ye(e,r),[e,r]),w=o?.supportsApiKey!==!1,T=o?.supportsOAuth===!0,[O,k]=(0,Q.useState)(null),[j,M]=(0,Q.useState)(null),[N,P]=(0,Q.useState)(`idle`),[F,I]=(0,Q.useState)(null),[L,R]=(0,Q.useState)(null),[z,B]=(0,Q.useState)(null),[V,H]=(0,Q.useState)(``),U=(0,Q.useRef)(null),W=(0,Q.useRef)(null),G=N===`waiting`||N===`waiting_code`;(0,Q.useEffect)(()=>{if(!O||!G)return;let t=window.setInterval(()=>{(async()=>{try{let n=await ce(O);n.status===`waiting_auth`||n.status===`waiting_code`?(P(n.status===`waiting_code`?`waiting_code`:`waiting`),M(n.message??null),I(n.authUrl??null),R(n.instructions??null),B(n.deviceCode??null),n.authUrl&&n.authUrl!==W.current&&(W.current=n.authUrl,mt(n.authUrl,U.current).catch(()=>{}))):n.status===`completed`?(window.clearInterval(t),gt(U.current),U.current=null,e===`xopc-cloud`&&await J(),P(`success`),M(n.message??y.saved),window.setTimeout(a,600)):(n.status===`failed`||n.status===`cancelled`)&&(window.clearInterval(t),gt(U.current),U.current=null,P(`error`),M(n.error??n.message??y.revokeFailed))}catch{}})()},1e3);return()=>window.clearInterval(t)},[O,G,a,e,y.revokeFailed,y.saved]),(0,Q.useEffect)(()=>()=>{O&&oe(O).catch(()=>{})},[O]),(0,Q.useEffect)(()=>()=>{gt(U.current),U.current=null},[]);let K=async()=>{gt(U.current),U.current=ht(),W.current=null,P(`waiting`),M(y.oauthStarting),I(null),R(null),B(null),m(null);try{k((await ie(e)).sessionId)}catch(e){gt(U.current),U.current=null,P(`error`),M(e instanceof Error?e.message:y.revokeFailed)}},q=async()=>{if(O){try{await le(O)}catch{}gt(U.current),U.current=null,W.current=null,P(`idle`),M(null),k(null),I(null),R(null),B(null)}},te=async()=>{if(!(!O||!V.trim()))try{await se(O,V.trim()),H(``),M(y.oauthProcessingCode)}catch(e){P(`error`),M(e instanceof Error?e.message:y.revokeFailed)}},ne=async()=>{let t=c.trim();if(!(!t||!w)){d(!0),m(null);try{await et({[e]:t}),g(!0),window.setTimeout(a,600)}catch(e){m(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:S(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,D.press),"aria-label":n.back,children:(0,$.jsx)(de,{className:`size-4 rotate-180`,"aria-hidden":!0})}),(0,$.jsx)(ee,{className:`min-w-0 flex-1 text-base font-semibold text-fg`,children:o?.name??e}),(0,$.jsx)(Gn,{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,w?(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)(He,{id:`builtin-api-key`,value:c,onChange:l,placeholder:n.apiKeyPlaceholder,labels:b,inputRef:v,onKeyDown:e=>{e.key===`Enter`&&ne()}})]}):null,T?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-lg border border-edge-subtle bg-surface-panel/60 p-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:y.oauth}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:y.oauthHint})]}),(0,$.jsxs)(C,{type:`button`,variant:`primary`,className:`gap-1.5`,disabled:G,onClick:()=>void K(),children:[G?(0,$.jsx)(_,{className:`size-3.5 animate-spin`,"aria-hidden":!0}):null,y.oauth]})]}),j?(0,$.jsx)(`p`,{className:S(`text-xs`,N===`error`?`text-red-600 dark:text-red-400`:`text-fg-muted`),children:j}):null,N===`waiting`||N===`waiting_code`?(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[F?(0,$.jsxs)(`a`,{href:F,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1.5 rounded-md bg-accent px-3 py-2 text-sm font-medium text-white hover:bg-accent-hover`,children:[y.openAuthPage,(0,$.jsx)(`span`,{className:`size-3`,"aria-hidden":!0,children:`↗`})]}):null,(0,$.jsx)(C,{type:`button`,variant:`secondary`,onClick:()=>void q(),children:y.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:y.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:y.deviceCodeHint})]}):null,N===`waiting_code`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,$.jsx)(`input`,{type:`text`,value:V,onChange:e=>H(e.target.value),onKeyDown:e=>e.key===`Enter`&&void te(),placeholder:y.pasteRedirectUrl,className:S(`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`,E)}),(0,$.jsx)(C,{type:`button`,variant:`primary`,onClick:()=>void te(),children:y.submitCode})]}):null]}):null,x.length>0&&w?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:x.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:[nt(e,n),(0,$.jsx)(`span`,{className:`size-3`,"aria-hidden":!0,children:`↗`})]},e))}):null,p?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:p}):null,(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,$.jsx)(C,{type:`button`,variant:`secondary`,onClick:i,children:n.cancel}),w?(0,$.jsx)(C,{type:`button`,variant:`primary`,disabled:!c.trim()||u||h,onClick:()=>void ne(),children:h?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(f,{className:`size-3.5`,"aria-hidden":!0}),n.saved]}):u?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(_,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),n.saving]}):n.save}):null]})]})]})}function Zn(e=`custom`){if(e!==`custom`&&st[e]){let t=st[e].config;return{preset:e,providerId:it(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 Qn(e,t){switch(t.type){case`applyPreset`:return t.key===`custom`?{...e,preset:`custom`,error:null}:st[t.key]?Zn(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 $n({initialPresetKey:e,customConfig:t,labels:n,language:r,onBack:i,onSaved:a}){let[o,s]=(0,Q.useReducer)(Qn,void 0,()=>Zn(e)),[c,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(!1),m=we(A(r).providersSettings),{preset:h,providerId:g,baseUrl:v,api:w,apiKey:T,modelIds:O,error:k}=o,j=async()=>{let e=g.trim(),r=v.trim();if(!e){s({type:`setError`,value:n.providerIdRequired});return}if(!r){s({type:`setError`,value:n.baseUrlRequired});return}let i=O.map(e=>e.trim()).filter(Boolean);d(!0),s({type:`setError`,value:null});try{let n=t?.providers??{},o=h===`custom`?void 0:st[h]?.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 ue({providers:{...n,[e]:s}}),a()}catch(e){s({type:`setError`,value:e instanceof Error?e.message:n.saveError})}finally{d(!1)}},M=async()=>{let e=g.trim()||it(h)||`custom`,t=v.trim();if(!t){s({type:`setError`,value:n.baseUrlRequired});return}p(!0),s({type:`setError`,value:null});try{let r=h===`custom`?void 0:st[h]?.config,i=(await Me({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)}},N=g.trim()&&v.trim(),P=(w===`openai-completions`||w===`openai-responses`)&&v.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:S(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,D.press),"aria-label":n.back,children:(0,$.jsx)(de,{className:`size-4 rotate-180`,"aria-hidden":!0})}),(0,$.jsx)(ee,{className:`min-w-0 flex-1 text-base font-semibold text-fg`,children:n.step2CustomTitle}),(0,$.jsx)(Gn,{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:h,onChange:e=>s({type:`applyPreset`,key:e.target.value}),className:ze(),children:[(0,$.jsx)(u,{value:`custom`,children:n.presetCustom}),Ze.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:g,onChange:e=>s({type:`setProviderId`,value:e.target.value}),placeholder:n.providerIdPlaceholder,className:S(`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,E)})]}),(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:v,onChange:e=>s({type:`setBaseUrl`,value:e.target.value}),placeholder:n.baseUrlPlaceholder,className:S(`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,E)})]}),(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:ze(),children:_e.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)(He,{id:`custom-api-key`,value:T,onChange:e=>s({type:`setApiKey`,value:e}),placeholder:n.apiKeyPlaceholder,labels:m})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:n.modelIdLabel}),(0,$.jsxs)(C,{type:`button`,variant:`secondary`,className:`gap-1.5`,disabled:!P||f,onClick:()=>void M(),children:[f?(0,$.jsx)(_,{className:`size-3.5 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(b,{className:`size-3.5`,"aria-hidden":!0}),f?n.discoveringModels:n.discoverModels]})]}),O.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:S(`flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,E)}),O.length>1?(0,$.jsx)(`button`,{type:`button`,onClick:()=>s({type:`removeModelSlot`,index:t}),className:S(`rounded-lg p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,D.press),children:(0,$.jsx)(x,{className:`size-3.5`,"aria-hidden":!0})}):null]},e||`model-slot-${t}`)),(0,$.jsxs)(C,{type:`button`,variant:`ghost`,className:`w-fit gap-1.5 text-fg-muted`,onClick:()=>s({type:`addModelSlot`}),children:[(0,$.jsx)(y,{className:`size-3.5`,"aria-hidden":!0}),n.addModel]})]}),k?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:k}):null]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t border-edge-subtle px-5 py-3`,children:[(0,$.jsx)(C,{type:`button`,variant:`secondary`,onClick:i,children:n.cancel}),(0,$.jsx)(C,{type:`button`,variant:`primary`,disabled:!N||c,onClick:()=>void j(),children:c?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(_,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),n.saving]}):n.save})]})]})}function er(){let e=(0,Z.c)(31),t=F(ar),n=!!t,{data:r,isLoading:i}=q(n),a;e[0]===n?a=e[1]:(a=n?P(`/api/providers/meta`):null,e[0]=n,e[1]=a);let o;e[2]===t?o=e[3]:(o=async e=>{let{payload:n}=await(await fetch(e,{headers:{Authorization:`Bearer ${t}`}})).json();return n?.providers??[]},e[2]=t,e[3]=o);let s;e[4]===Symbol.for(`react.memo_cache_sentinel`)?(s={revalidateOnFocus:!1},e[4]=s):s=e[4];let{data:c,isLoading:l}=G(a,o,s),u;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(u={revalidateOnFocus:!1},e[5]=u):u=e[5];let{data:d,isLoading:f}=G(n?ne:null,ir,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}=G(n?Y:null,rr,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=We(c,Xe(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=Ee(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(nr).map(tr)),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,C=i||l||f,w;return e[25]!==v||e[26]!==S||e[27]!==b||e[28]!==C||e[29]!==m?(w={cards:S,loading:C,builtinRows:v,customConfig:b,allModels:m},e[25]=v,e[26]=S,e[27]=b,e[28]=C,e[29]=m,e[30]=w):w=e[30],w}function tr(e){return e.id}function nr(e){return e.configured}function rr(){return Ie()}function ir(){return te()}function ar(e){return e.token}function or(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)(I,{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(cr)})]}),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(sr),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)(y,{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)(C,{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)(C,{type:`button`,variant:`primary`,className:`mt-4 gap-1.5`,onClick:i,children:[(0,$.jsx)(y,{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)(lr,{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 sr(e){return e.configured}function cr(e){return(0,$.jsx)(I,{className:`h-32 rounded-2xl`},e)}function lr(e){let t=(0,Z.c)(28),{card:n,labels:r,onManage:i}=e,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=S(`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`,D.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)(f,{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 p;t[16]===d?p=t[17]:(p=(0,$.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:d}),t[16]=d,t[17]=p);let m;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)(ct,{className:`size-3`,"aria-hidden":!0}),t[18]=m):m=t[18];let h;t[19]===r.manage?h=t[20]:(h=(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-xs font-medium text-accent-fg opacity-0 transition-opacity group-hover:opacity-100`,children:[m,r.manage]}),t[19]=r.manage,t[20]=h);let g;t[21]!==h||t[22]!==p?(g=(0,$.jsxs)(`div`,{className:`mt-2.5 flex items-center justify-between`,children:[p,h]}),t[21]=h,t[22]=p,t[23]=g):g=t[23];let _;return t[24]!==i||t[25]!==g||t[26]!==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 ur(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}:Ne(``),t[0]=n,t[1]=c);let[d,f]=(0,Q.useState)(c),[p,m]=(0,Q.useState)(dr),h;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(h=(e,t)=>{f(n=>({...n,[e]:t})),m(t=>{let n=new Map(t);return n.delete(e),n})},t[2]=h):h=t[2];let g=h,_;t[3]!==d.contextWindow||t[4]!==d.id||t[5]!==d.maxTokens||t[6]!==s.modelIdRequired||t[7]!==s.mustBePositive?(_=()=>{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]=_):_=t[8];let v=_,y;t[9]!==d||t[10]!==o||t[11]!==a||t[12]!==v?(y=()=>{if(!v())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]=v,t[13]=y):y=t[13];let b=y,w=d,T;t[14]===w?T=t[15]:(T=Qe(w),t[14]=w,t[15]=T);let E=T,D=r?s.addModelTitle:s.editModelTitle,k;t[16]===D?k=t[17]:(k=(0,$.jsx)(ee,{className:`text-base font-semibold text-fg`,children:D}),t[16]=D,t[17]=k);let A;t[18]!==s.modelProviderLabel||t[19]!==i?(A=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]=A):A=t[20];let j;t[21]!==k||t[22]!==A?(j=(0,$.jsxs)(`div`,{children:[k,A]}),t[21]=k,t[22]=A,t[23]=j):j=t[23];let M;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(M=S(O,`p-1.5 hover:bg-surface-base`),t[24]=M):M=t[24];let N;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(N=(0,$.jsx)(x,{className:`size-4`}),t[25]=N):N=t[25];let P;t[26]===s.close?P=t[27]:(P=(0,$.jsx)(V,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:M,"aria-label":s.close,children:N})}),t[26]=s.close,t[27]=P);let F;t[28]!==j||t[29]!==P?(F=(0,$.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[j,P]}),t[28]=j,t[29]=P,t[30]=F):F=t[30];let I;t[31]===Symbol.for(`react.memo_cache_sentinel`)?(I=(0,$.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`}),t[31]=I):I=t[31];let L;t[32]===s.modelId?L=t[33]:(L=(0,$.jsxs)(`label`,{className:`mb-1 block text-xs font-medium text-fg`,children:[s.modelId,I]}),t[32]=s.modelId,t[33]=L);let R;t[34]===p?R=t[35]:(R=S(rt(),p.has(`id`)&&`border-red-500`),t[34]=p,t[35]=R);let z=d.id||``,B;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(B=e=>g(`id`,e.target.value),t[36]=B):B=t[36];let H=!r,U;t[37]!==R||t[38]!==z||t[39]!==H?(U=(0,$.jsx)(`input`,{className:R,value:z,onChange:B,placeholder:`e.g. llama3.1:8b`,disabled:H}),t[37]=R,t[38]=z,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]!==L||t[44]!==U||t[45]!==W?(G=(0,$.jsxs)(`div`,{children:[L,U,W]}),t[43]=L,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 q;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(q=rt(),t[49]=q):q=t[49];let te=d.name||``,ne;t[50]===Symbol.for(`react.memo_cache_sentinel`)?(ne=e=>g(`name`,e.target.value),t[50]=ne):ne=t[50];let J;t[51]===te?J=t[52]:(J=(0,$.jsx)(`input`,{className:q,value:te,onChange:ne}),t[51]=te,t[52]=J);let Y;t[53]!==K||t[54]!==J?(Y=(0,$.jsxs)(`div`,{children:[K,J]}),t[53]=K,t[54]=J,t[55]=Y):Y=t[55];let X;t[56]===s.inputTypes?X=t[57]:(X=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.inputTypes}),t[56]=s.inputTypes,t[57]=X);let re;t[58]===Symbol.for(`react.memo_cache_sentinel`)?(re=ze(),t[58]=re):re=t[58];let ie;t[59]===Symbol.for(`react.memo_cache_sentinel`)?(ie=e=>g(`input`,Je(e.target.value)),t[59]=ie):ie=t[59];let ae;t[60]===s?ae=t[61]:(ae=Ve.map(e=>(0,$.jsx)(u,{value:e.value,children:s[e.labelKey]},e.value)),t[60]=s,t[61]=ae);let oe;t[62]!==E||t[63]!==ae?(oe=(0,$.jsx)(l,{className:re,value:E,onChange:ie,children:ae}),t[62]=E,t[63]=ae,t[64]=oe):oe=t[64];let se;t[65]!==X||t[66]!==oe?(se=(0,$.jsxs)(`div`,{children:[X,oe]}),t[65]=X,t[66]=oe,t[67]=se):se=t[67];let ce=d.reasoning||!1,le;t[68]===Symbol.for(`react.memo_cache_sentinel`)?(le=e=>g(`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 pe;t[77]===s.contextWindow?pe=t[78]:(pe=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.contextWindow}),t[77]=s.contextWindow,t[78]=pe);let me;t[79]===p?me=t[80]:(me=S(rt(),p.has(`contextWindow`)&&`border-red-500`),t[79]=p,t[80]=me);let he=d.contextWindow??128e3,ge;t[81]===Symbol.for(`react.memo_cache_sentinel`)?(ge=e=>g(`contextWindow`,parseInt(e.target.value,10)||0),t[81]=ge):ge=t[81];let _e;t[82]!==me||t[83]!==he?(_e=(0,$.jsx)(`input`,{type:`number`,min:1,className:me,value:he,onChange:ge}),t[82]=me,t[83]=he,t[84]=_e):_e=t[84];let ve;t[85]===p?ve=t[86]:(ve=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]=ve);let ye;t[87]!==pe||t[88]!==_e||t[89]!==ve?(ye=(0,$.jsxs)(`div`,{children:[pe,_e,ve]}),t[87]=pe,t[88]=_e,t[89]=ve,t[90]=ye):ye=t[90];let be;t[91]===s.maxOutputTokens?be=t[92]:(be=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.maxOutputTokens}),t[91]=s.maxOutputTokens,t[92]=be);let xe;t[93]===p?xe=t[94]:(xe=S(rt(),p.has(`maxTokens`)&&`border-red-500`),t[93]=p,t[94]=xe);let Se=d.maxTokens??16384,Ce;t[95]===Symbol.for(`react.memo_cache_sentinel`)?(Ce=e=>g(`maxTokens`,parseInt(e.target.value,10)||0),t[95]=Ce):Ce=t[95];let we;t[96]!==xe||t[97]!==Se?(we=(0,$.jsx)(`input`,{type:`number`,min:1,className:xe,value:Se,onChange:Ce}),t[96]=xe,t[97]=Se,t[98]=we):we=t[98];let Te;t[99]===p?Te=t[100]:(Te=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]=Te);let Ee;t[101]!==be||t[102]!==we||t[103]!==Te?(Ee=(0,$.jsxs)(`div`,{children:[be,we,Te]}),t[101]=be,t[102]=we,t[103]=Te,t[104]=Ee):Ee=t[104];let De;t[105]!==ye||t[106]!==Ee?(De=(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[ye,Ee]}),t[105]=ye,t[106]=Ee,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=rt(),t[112]=Ae):Ae=t[112];let je=d.cost?.input??0,Me;t[113]===d.cost?Me=t[114]:(Me=e=>g(`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 Pe;t[115]!==je||t[116]!==Me?(Pe=(0,$.jsx)(`input`,{type:`number`,step:`any`,min:0,className:Ae,value:je,onChange:Me}),t[115]=je,t[116]=Me,t[117]=Pe):Pe=t[117];let Fe;t[118]!==ke||t[119]!==Pe?(Fe=(0,$.jsxs)(`div`,{children:[ke,Pe]}),t[118]=ke,t[119]=Pe,t[120]=Fe):Fe=t[120];let Ie;t[121]===s.costOutput?Ie=t[122]:(Ie=(0,$.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:s.costOutput}),t[121]=s.costOutput,t[122]=Ie);let Le;t[123]===Symbol.for(`react.memo_cache_sentinel`)?(Le=rt(),t[123]=Le):Le=t[123];let Re=d.cost?.output??0,Be;t[124]===d.cost?Be=t[125]:(Be=e=>g(`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]=Be);let He;t[126]!==Re||t[127]!==Be?(He=(0,$.jsx)(`input`,{type:`number`,step:`any`,min:0,className:Le,value:Re,onChange:Be}),t[126]=Re,t[127]=Be,t[128]=He):He=t[128];let Ue;t[129]!==Ie||t[130]!==He?(Ue=(0,$.jsxs)(`div`,{children:[Ie,He]}),t[129]=Ie,t[130]=He,t[131]=Ue):Ue=t[131];let We;t[132]!==Fe||t[133]!==Ue?(We=(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[Fe,Ue]}),t[132]=Fe,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]!==Y||t[140]!==fe||t[141]!==De||t[142]!==Ge?(Ke=(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[G,Y,fe,De,Ge]}),t[138]=G,t[139]=Y,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)(V,{asChild:!0,children:(0,$.jsx)(C,{type:`button`,variant:`secondary`,children:s.cancel})}),t[144]=s.cancel,t[145]=qe);let Ye=r?s.addModelConfirm:s.saveModelConfirm,Xe;t[146]!==b||t[147]!==Ye?(Xe=(0,$.jsx)(C,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:b,children:Ye}),t[146]=b,t[147]=Ye,t[148]=Xe):Xe=t[148];let Ze;t[149]!==qe||t[150]!==Xe?(Ze=(0,$.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2 border-t border-edge-subtle pt-3 dark:border-edge`,children:[qe,Xe]}),t[149]=qe,t[150]=Xe,t[151]=Ze):Ze=t[151];let $e;return t[152]!==F||t[153]!==Ke||t[154]!==Ze?($e=(0,$.jsxs)($.Fragment,{children:[F,Ke,Ze]}),t[152]=F,t[153]=Ke,t[154]=Ze,t[155]=$e):$e=t[155],$e}function dr(){return new Map}function fr(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)(z,{className:S(`xopc-dialog-overlay fixed inset-0 bg-scrim`,R)}),t[0]=l):l=t[0];let u;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(u=S(`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`,L,`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)(ur,{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)(H,{children:[l,(0,$.jsx)(U,{className:u,onOpenAutoFocus:pr,children:d})]}),t[10]=d,t[11]=f);let p;return t[12]!==r||t[13]!==n||t[14]!==f?(p=(0,$.jsx)(W,{open:n,onOpenChange:r,children:f}),t[12]=r,t[13]=n,t[14]=f,t[15]=p):p=t[15],p}function pr(e){return e.preventDefault()}function mr(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=()=>Ke(n).then(hr),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)(He,{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 hr(e){return e.apiKey??null}function gr(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)(z,{className:S(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,R)}),t[0]=f):f=t[0];let p;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(p=S(`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`,L),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)(H,{children:[f,(0,$.jsx)(U,{className:p,children:a?(0,$.jsx)(vr,{providerId:i,customConfig:s,labels:l,language:u,onClose:()=>r(!1),onSaved:d}):(0,$.jsx)(_r,{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 h;return t[12]!==r||t[13]!==n||t[14]!==m?(h=(0,$.jsx)(W,{open:n,onOpenChange:r,children:m}),t[12]=r,t[13]=n,t[14]=m,t[15]=h):h=t[15],h}function _r({providerId:e,builtinRows:t,allModels:n,labels:r,language:i,onClose:a,onSaved:o}){let s=t.find(t=>t.id===e),l=me[e],u=n.filter(t=>t.provider===e),[d,p]=(0,Q.useState)(s?.apiKey??``),[h,g]=(0,Q.useState)(!1),[v,y]=(0,Q.useState)(!1),[b,w]=(0,Q.useState)(null),[T,O]=(0,Q.useState)(!1),k=A(i).providersSettings,j=s?.supportsApiKey!==!1,M=s?.supportsOAuth===!0,N=s?.authMode===`oauth`&&s.authStatus===`connected`,P=s?.configured===!0&&s.activeKeySource!==`env`&&s.activeKeySource!==`extension`&&s.activeKeySource!==`models_json`,[F,I]=(0,Q.useState)(null),[L,R]=(0,Q.useState)(null),[z,B]=(0,Q.useState)(`idle`),[H,U]=(0,Q.useState)(null),[W,G]=(0,Q.useState)(null),[K,q]=(0,Q.useState)(null),[te,ne]=(0,Q.useState)(``),J=(0,Q.useRef)(null),Y=(0,Q.useRef)(null),X=z===`waiting`||z===`waiting_code`,re=(0,Q.useMemo)(()=>ye(e,i),[e,i]),ue=d!==(s?.apiKey??``),de=async()=>{let t=d.trim();if(!(!t||!j||Be(t))){g(!0),w(null);try{await et({[e]:t}),y(!0),window.setTimeout(()=>{o(),a()},600)}catch(e){w(e instanceof Error?e.message:r.saveError)}finally{g(!1)}}};(0,Q.useEffect)(()=>{if(!F||!X)return;let e=window.setInterval(()=>{(async()=>{try{let t=await ce(F);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),q(t.deviceCode??null),t.authUrl&&t.authUrl!==Y.current&&(Y.current=t.authUrl,mt(t.authUrl,J.current).catch(()=>{}))):t.status===`completed`?(window.clearInterval(e),gt(J.current),J.current=null,B(`success`),R(t.message??k.saved),window.setTimeout(()=>{o(),a()},600)):(t.status===`failed`||t.status===`cancelled`)&&(window.clearInterval(e),gt(J.current),J.current=null,B(`error`),R(t.error??t.message??k.revokeFailed))}catch{}})()},1e3);return()=>window.clearInterval(e)},[F,X,a,o,k.revokeFailed,k.saved]),(0,Q.useEffect)(()=>()=>{F&&oe(F).catch(()=>{})},[F]),(0,Q.useEffect)(()=>()=>{gt(J.current),J.current=null},[]);let fe=async()=>{try{await Ye(e),o(),a()}catch{}},pe=async()=>{gt(J.current),J.current=ht(),Y.current=null,B(`waiting`),R(k.oauthStarting),U(null),G(null),q(null),w(null);try{I((await ie(e)).sessionId)}catch(e){gt(J.current),J.current=null,B(`error`),R(e instanceof Error?e.message:k.revokeFailed)}},he=async()=>{if(F){try{await le(F)}catch{}gt(J.current),J.current=null,Y.current=null,B(`idle`),R(null),I(null),U(null),G(null),q(null)}},ge=async()=>{if(!(!F||!te.trim()))try{await se(F,te.trim()),ne(``),R(k.oauthProcessingCode)}catch(e){B(`error`),R(e instanceof Error?e.message:k.revokeFailed)}},_e=async()=>{try{await ae(e),o(),a()}catch(e){w(e instanceof Error?e.message:k.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)(ee,{className:`text-base font-semibold text-fg`,children:s?.name??e}),(0,$.jsx)(V,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:S(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,D.press),children:(0,$.jsx)(x,{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,j?(0,$.jsx)(mr,{providerId:e,inputId:`manage-api-key`,value:d,onChange:e=>{p(e),y(!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)(m,{className:`size-3`,"aria-hidden":!0})]}):null]}):null,M?(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:k.oauth}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:N?k.sourceOauth:k.oauthHint})]}),N?(0,$.jsx)(C,{type:`button`,variant:`secondary`,className:`gap-1.5 text-red-600 dark:text-red-400`,onClick:()=>void _e(),children:k.revoke}):(0,$.jsxs)(C,{type:`button`,variant:`primary`,className:`gap-1.5`,disabled:X,onClick:()=>void pe(),children:[X?(0,$.jsx)(_,{className:`size-3.5 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Le,{className:`size-3.5`,"aria-hidden":!0}),k.oauth]})]}),L?(0,$.jsx)(`p`,{className:S(`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:[H?(0,$.jsxs)(`a`,{href:H,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)(m,{className:`size-4`,"aria-hidden":!0}),k.openAuthPage]}):null,(0,$.jsx)(C,{type:`button`,variant:`secondary`,onClick:()=>void he(),children:k.cancelOAuth})]}):null,W?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:W}):null,K?(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:k.deviceCodeLabel}),(0,$.jsx)(`code`,{className:`mt-1 block select-all font-mono text-lg font-semibold tracking-widest text-fg`,children:K}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:k.deviceCodeHint})]}):null,z===`waiting_code`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,$.jsx)(`input`,{type:`text`,value:te,onChange:e=>ne(e.target.value),onKeyDown:e=>e.key===`Enter`&&void ge(),placeholder:k.pasteRedirectUrl,className:S(`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`,E)}),(0,$.jsx)(C,{type:`button`,variant:`primary`,onClick:()=>void ge(),children:k.submitCode})]}):null]}):null,re.length>0&&j?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:re.map(({kind:e,href:t})=>(0,$.jsxs)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent hover:underline`,children:[nt(e,r),(0,$.jsx)(m,{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}),b?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:b}):null]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-t border-edge-subtle px-5 py-3`,children:[P?(0,$.jsxs)(C,{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:()=>O(!0),children:[(0,$.jsx)(Ge,{className:`size-3.5`,"aria-hidden":!0}),r.remove]}):(0,$.jsx)(`span`,{}),(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:j&&ue&&!Be(d.trim())?(0,$.jsx)(C,{type:`button`,variant:`primary`,disabled:!d.trim()||h||v,onClick:()=>void de(),children:v?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(f,{className:`size-3.5`,"aria-hidden":!0}),r.saved]}):h?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(_,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),r.saving]}):r.save}):null})]}),(0,$.jsx)(ot,{open:T,title:r.removeConfirmTitle,description:r.removeConfirmDescription.replace(`{{provider}}`,s?.name??e),confirmLabel:r.removeConfirmAction,cancelLabel:r.cancel,destructive:!0,onConfirm:()=>void fe(),onCancel:()=>O(!1)})]})}function vr({providerId:e,customConfig:t,labels:n,language:r,onClose:i,onSaved:a}){let o=A(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??[]),[m,h]=(0,Q.useState)(s?.modelDiscovery?.enabled===!0),[g,b]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(null),[O,k]=(0,Q.useState)(!1),[j,M]=(0,Q.useState)(null),[N,P]=(0,Q.useState)(!1),[F,I]=(0,Q.useState)(null),L=n=>{if(!t)return null;let r=u.trim(),i={...s,baseUrl:c.trim()||void 0,apiKey:Be(r)?s?.apiKey:r||void 0,...n};return{providers:{...t.providers,[e]:i}}},R=async()=>{let e=L({models:f,modelDiscovery:{enabled:m}});if(e){b(!0),T(null);try{await ue(e),a(),i()}catch(e){T(e instanceof Error?e.message:n.saveError)}finally{b(!1)}}},z=async()=>{if(t)try{let{[e]:n,...r}=t.providers;await ue({providers:r}),a(),i()}catch{}},B=(e,t)=>{I({model:e,isNew:t}),P(!0)},H=async e=>{if(!F)return;let t=F.isNew?[...f,e]:f.map(t=>t.id===e.id?e:t);p(t);let r=L({models:t});if(r)try{await ue(r),a()}catch(e){T(e instanceof Error?e.message:n.saveError)}},U=async e=>{let t=f.filter(t=>t.id!==e);p(t),M(null);let r=L({models:t});if(r)try{await ue(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)(ee,{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)(V,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:S(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,D.press),children:(0,$.jsx)(x,{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:S(`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,E)})]}),(0,$.jsx)(mr,{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:m,onChange:e=>h(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)(C,{type:`button`,variant:`primary`,className:`gap-1.5 px-2 py-1 text-xs`,onClick:()=>B(null,!0),children:[(0,$.jsx)(y,{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:S(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,D.press),onClick:()=>B(e,!1),"aria-label":o.editModel,children:(0,$.jsx)(v,{className:`size-3.5`,"aria-hidden":!0})}),(0,$.jsx)(`button`,{type:`button`,className:S(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-red-600 dark:hover:text-red-400`,D.press),onClick:()=>M(e.id),"aria-label":o.removeModel,children:(0,$.jsx)(Ge,{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)(C,{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:()=>k(!0),children:[(0,$.jsx)(Ge,{className:`size-3.5`,"aria-hidden":!0}),n.remove]}),(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsx)(C,{type:`button`,variant:`primary`,disabled:g,onClick:()=>void R(),children:g?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(_,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),n.saving]}):n.save})})]}),(0,$.jsx)(ot,{open:O,title:n.removeConfirmTitle,description:n.removeConfirmDescription.replace(`{{provider}}`,e),confirmLabel:n.removeConfirmAction,cancelLabel:n.cancel,destructive:!0,onConfirm:()=>void z(),onCancel:()=>k(!1)}),(0,$.jsx)(ot,{open:j!==null,title:o.removeModel,description:o.removeModelConfirm.replace(`{{id}}`,j??``),confirmLabel:n.removeConfirmAction,cancelLabel:n.cancel,destructive:!0,onConfirm:()=>{j&&U(j)},onCancel:()=>M(null)}),(0,$.jsx)(fr,{open:N,onOpenChange:e=>{P(e),e||I(null)},providerId:e,model:F?.model??null,isNew:F?.isNew??!1,onSave:e=>void H(e),m:o})]})}function yr(e,t){switch(e){case`vision`:return{href:`${tt(`models`)}?add=1`,guidance:t?`接入支持图片理解的模型服务`:`Connect a model service that supports vision`,action:t?`去接入模型`:`Connect model`};case`image-generation`:return{href:tt(`image`),guidance:t?`选择图片模型并配置所需凭据`:`Choose an image model and configure its credentials`,action:t?`去配置图片生成`:`Configure image generation`};case`stt`:return{href:tt(`voice`),guidance:t?`选择语音识别服务,或安装本地语音模型`:`Choose a speech-to-text service or install a local voice model`,action:t?`去配置语音识别`:`Configure speech-to-text`};case`tts`:return{href:tt(`voice`),guidance:t?`选择语音合成服务并完成凭据配置`:`Choose a text-to-speech service and configure its credentials`,action:t?`去配置语音合成`:`Configure text-to-speech`}}}async function br(){let e=await M(P(`/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}async function xr(){let e=await M(P(`/api/capabilities/readiness`)),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 Sr(){let e=N(e=>e.language)===`zh`,{data:t,error:n,isLoading:r}=G(X,br,{revalidateOnFocus:!1}),{data:i}=G(re,xr,{revalidateOnFocus:!1}),[a,o]=(0,Q.useState)(!1),[s,l]=(0,Q.useState)(null);if(r)return(0,$.jsx)(I,{className:`h-24 w-full rounded-2xl`});let u=Object.values(t?.sources??{}),d=u.reduce((e,t)=>e+t.models.filter(e=>e.availability===`available`).length,0),p=(t?.references??[]).filter(e=>e.availability===`unavailable`),m=t?.sync.lastSuccessAt??Math.max(0,...u.map(e=>e.lastSuccessAt)),h=s??(n instanceof Error?n.message:t?.sync.lastError??Object.values(t?.sync.sourceErrors??{})[0]),g=Object.values(i?.capabilities??{}).some(e=>e.status===`degraded`||e.status===`unavailable`),v=async()=>{o(!0),l(null);try{let e=await M(P(`/api/models/catalog/refresh`),{method:`POST`});if(!e.ok)throw Error(`HTTP ${e.status}`);await J()}catch(t){l(t instanceof Error?t.message:e?`模型目录刷新失败`:`Model catalog refresh failed`)}finally{o(!1)}};return(0,$.jsxs)(`div`,{className:`rounded-2xl border border-edge-subtle bg-surface-panel/40 p-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[h||p.length>0||g?(0,$.jsx)(qe,{className:`size-4 text-amber-500`,"aria-hidden":!0}):(0,$.jsx)(f,{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?`${u.length} 个来源,${d} 个可用模型${m?` · 最近同步 ${new Date(m).toLocaleString()}`:``}`:`${u.length} sources, ${d} available models${m?` · Last synced ${new Date(m).toLocaleString()}`:``}`})]}),(0,$.jsxs)(C,{className:`shrink-0`,type:`button`,variant:`secondary`,disabled:a,onClick:()=>void v(),children:[a?(0,$.jsx)(_,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(je,{className:`size-4`,"aria-hidden":!0}),a?e?`刷新中…`:`Refreshing…`:e?`立即刷新`:`Refresh now`]})]}),i?(0,$.jsx)(`div`,{className:`mt-3 grid gap-2 sm:grid-cols-2 xl:grid-cols-4`,children:Object.entries(i.capabilities).map(([t,n])=>{let r=t===`vision`?e?`图片理解`:`Vision`:t===`image-generation`?e?`图片生成`:`Image generation`:t.toUpperCase(),i=n.selectionSource!==`explicit-config`,a=n.status===`degraded`||n.status===`unavailable`,o=yr(t,e),s=(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`min-w-0 text-xs font-medium text-fg`,children:r}),(0,$.jsx)(`span`,{className:n.status===`ready`?`shrink-0 text-xs text-emerald-600 dark:text-emerald-400`:n.status===`disabled`?`shrink-0 text-xs text-fg-muted`:`shrink-0 text-xs text-amber-600 dark:text-amber-400`,children:n.status===`ready`?e?`可用`:`Ready`:n.status===`disabled`?e?`已关闭`:`Off`:e?`需处理`:`Needs attention`})]}),(0,$.jsx)(`p`,{className:`mt-1 truncate text-xs text-fg-muted`,title:n.primary?`${n.primary.provider}/${n.primary.model}`:void 0,children:n.primary?`${i?e?`自动`:`Auto`:e?`显式`:`Explicit`} · ${n.primary.provider}/${n.primary.model}`:e?`无可用实现`:`No available implementation`}),a?(0,$.jsxs)(`div`,{className:`mt-2 border-t border-edge-subtle pt-2`,children:[(0,$.jsx)(`p`,{className:`text-xs leading-5 text-amber-700 dark:text-amber-300`,children:n.status===`degraded`?e?`当前配置不可用,正在使用备用方案。${o.guidance}`:`The current configuration is unavailable, so a fallback is in use. ${o.guidance}.`:o.guidance}),(0,$.jsxs)(`span`,{className:`mt-1 inline-flex items-center gap-1 text-xs font-medium text-accent`,children:[o.action,(0,$.jsx)(Ae,{className:`size-3.5`,"aria-hidden":!0})]})]}):null]});return a?(0,$.jsx)(c,{to:o.href,"aria-label":`${r}:${o.action}`,className:S(`rounded-xl border border-amber-400/40 bg-amber-500/5 px-3 py-2`,`transition-colors hover:border-amber-400/70 hover:bg-amber-500/10`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`),children:s},t):(0,$.jsx)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel px-3 py-2`,children:s},t)})}):null,p.length>0?(0,$.jsx)(`div`,{className:`mt-2 space-y-1 text-sm text-amber-700 dark:text-amber-300`,children:p.slice(0,3).map(t=>(0,$.jsxs)(`p`,{children:[t.ref,` `,e?`不可用`:`is unavailable`,t.suggestedRef?` · ${e?`建议`:`Suggested`} ${t.suggestedRef}`:``,` · ${t.locations.length} ${e?`处引用`:`references`}`]},t.ref))}):null,h?(0,$.jsx)(`p`,{className:`mt-2 text-sm text-danger`,children:h}):null]})}async function Cr(){return(await j(P(`/api/models/xopc-cloud/account-summary`))).payload}function wr(e){let t=(0,Z.c)(93),{labels:n}=e,r=N(Tr)===`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}=G(`/api/models/xopc-cloud/account-summary`,Cr,i);if(s){let e;return t[1]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(I,{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)(qe,{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)(je,{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)(C,{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,f,h,g,_,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`,f=`min-w-0 flex-1`;let i;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(p,{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?(h=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[i,o,s]}),t[44]=o,t[45]=s,t[46]=h):h=t[46],t[47]===n.availableCredits?g=t[48]:(g=(0,$.jsx)(`p`,{className:`mt-5 text-xs font-medium text-fg-subtle`,children:n.availableCredits}),t[47]=n.availableCredits,t[48]=g),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]=f,t[34]=h,t[35]=g,t[36]=_,t[37]=v,t[38]=y}else u=t[31],d=t[32],f=t[33],h=t[34],g=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 w;t[56]===n.recentUsage?w=t[57]:(w=(0,$.jsx)(`p`,{className:`mt-5 text-xs font-medium text-fg-subtle`,children:n.recentUsage}),t[56]=n.recentUsage,t[57]=w);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]!==w||t[69]!==T||t[70]!==D||t[71]!==f||t[72]!==h||t[73]!==g?(O=(0,$.jsxs)(`div`,{className:f,children:[h,g,x,S,w,T,D]}),t[66]=x,t[67]=S,t[68]=w,t[69]=T,t[70]=D,t[71]=f,t[72]=h,t[73]=g,t[74]=O):O=t[74];let k;t[75]===Symbol.for(`react.memo_cache_sentinel`)?(k=(0,$.jsx)(m,{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)(C,{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)(m,{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)(C,{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 P;t[83]!==A||t[84]!==M?(P=(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap gap-2`,children:[A,M]}),t[83]=A,t[84]=M,t[85]=P):P=t[85];let F;t[86]!==O||t[87]!==P||t[88]!==_?(F=(0,$.jsxs)(`div`,{className:_,children:[O,P]}),t[86]=O,t[87]=P,t[88]=_,t[89]=F):F=t[89];let L;return t[90]!==F||t[91]!==v?(L=(0,$.jsx)(`section`,{className:v,children:F}),t[90]=F,t[91]=v,t[92]=L):L=t[92],L}function Tr(e){return e.language}function Er(e){return pe.includes(e)}function Dr(){let e=(0,Z.c)(71),t=N(Ar),n;e[0]===t?n=e[1]:(n=A(t),e[0]=t,e[1]=n);let r=n,l=r.capabilitiesSettings,u=a(),[d,f]=o(),{capability:p}=i(),[m,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(null),v=er(),y;e[2]===v.cards?y=e[3]:(y=v.cards.some(kr),e[2]=v.cards,e[3]=y);let x=y,S,w;e[4]!==p||e[5]!==d||e[6]!==f?(S=()=>{if(p!==`models`||d.get(`add`)!==`1`)return;h(!0);let e=new URLSearchParams(d);e.delete(`add`),f(e,{replace:!0})},w=[p,d,f],e[4]=p,e[5]=d,e[6]=f,e[7]=S,e[8]=w):(S=e[7],w=e[8]),(0,Q.useEffect)(S,w);let T;e[9]!==l.modelsHint||e[10]!==l.tabs.models?(T={id:`models`,icon:Fe,label:l.tabs.models,hint:l.modelsHint},e[9]=l.modelsHint,e[10]=l.tabs.models,e[11]=T):T=e[11];let E;e[12]!==l.imageHint||e[13]!==l.tabs.image?(E={id:`image`,icon:he,label:l.tabs.image,hint:l.imageHint},e[12]=l.imageHint,e[13]=l.tabs.image,e[14]=E):E=e[14];let D;e[15]!==l.tabs.voice||e[16]!==l.voiceHint?(D={id:`voice`,icon:Ue,label:l.tabs.voice,hint:l.voiceHint},e[15]=l.tabs.voice,e[16]=l.voiceHint,e[17]=D):D=e[17];let O;e[18]!==l.searchHint||e[19]!==l.tabs.search?(O={id:`search`,icon:b,label:l.tabs.search,hint:l.searchHint},e[18]=l.searchHint,e[19]=l.tabs.search,e[20]=O):O=e[20];let k;e[21]!==T||e[22]!==E||e[23]!==D||e[24]!==O?(k=[T,E,D,O],e[21]=T,e[22]=E,e[23]=D,e[24]=O,e[25]=k):k=e[25];let j=k,M;e[26]===u?M=e[27]:(M=e=>u(tt(e)),e[26]=u,e[27]=M);let P=M,F=Or;if(!Er(p)){let t;return e[28]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(s,{to:tt(`models`),replace:!0}),e[28]=t):t=e[28],t}let I=r.nav.settingsCapabilities,L=l.subtitle,R;e[29]===t?R=e[30]:(R=ge(t,`configuration`),e[29]=t,e[30]=R);let z;e[31]===Symbol.for(`react.memo_cache_sentinel`)?(z=(0,$.jsx)(at,{className:`size-4`,"aria-hidden":!0}),e[31]=z):z=e[31];let B;e[32]===l.agentSettingsLink?B=e[33]:(B=(0,$.jsx)(C,{asChild:!0,variant:`secondary`,children:(0,$.jsxs)(c,{to:`/agents`,children:[z,l.agentSettingsLink]})}),e[32]=l.agentSettingsLink,e[33]=B);let V;e[34]!==l.docsLink||e[35]!==l.subtitle||e[36]!==r.nav.settingsCapabilities||e[37]!==R||e[38]!==B?(V=(0,$.jsx)(lt,{title:I,subtitle:L,docsLink:R,docsLabel:l.docsLink,actions:B}),e[34]=l.docsLink,e[35]=l.subtitle,e[36]=r.nav.settingsCapabilities,e[37]=R,e[38]=B,e[39]=V):V=e[39];let H;e[40]!==l.tabsAria||e[41]!==p||e[42]!==j||e[43]!==P?(H=(0,$.jsx)(jt,{items:j,activeTab:p,onChange:P,ariaLabel:l.tabsAria,tabIdPrefix:`capability-tab`,panelIdPrefix:`capability-panel`}),e[40]=l.tabsAria,e[41]=p,e[42]=j,e[43]=P,e[44]=H):H=e[44];let U;e[45]!==l.connectedProviders||e[46]!==l.xopcCloudAccount||e[47]!==p||e[48]!==v||e[49]!==j||e[50]!==x?(U=j.map(e=>(0,$.jsx)(Mr,{id:e.id,activeSection:p,hint:e.hint,children:e.id===`models`?(0,$.jsxs)($.Fragment,{children:[x?(0,$.jsx)(wr,{labels:l.xopcCloudAccount}):null,(0,$.jsx)(Sr,{}),(0,$.jsx)(or,{labels:l.connectedProviders,data:v,onAdd:()=>h(!0),onManage:(e,t)=>_({providerId:e,isCustom:t})})]}):(0,$.jsx)(jr,{section:e.id})},e.id)),e[45]=l.connectedProviders,e[46]=l.xopcCloudAccount,e[47]=p,e[48]=v,e[49]=j,e[50]=x,e[51]=U):U=e[51];let ee;e[52]!==m||e[53]!==l.addProviderDialog||e[54]!==t||e[55]!==v.builtinRows||e[56]!==v.customConfig?(ee=(0,$.jsx)(Wn,{open:m,onOpenChange:h,builtinRows:v.builtinRows,customConfig:v.customConfig,labels:l.addProviderDialog,language:t,onSaved:F}),e[52]=m,e[53]=l.addProviderDialog,e[54]=t,e[55]=v.builtinRows,e[56]=v.customConfig,e[57]=ee):ee=e[57];let W;e[58]!==l.manageProviderDialog||e[59]!==t||e[60]!==g||e[61]!==v.allModels||e[62]!==v.builtinRows||e[63]!==v.customConfig?(W=g?(0,$.jsx)(gr,{open:!0,onOpenChange:e=>{e||_(null)},providerId:g.providerId,isCustom:g.isCustom,builtinRows:v.builtinRows,customConfig:v.customConfig,allModels:v.allModels,labels:l.manageProviderDialog,language:t,onSaved:F}):null,e[58]=l.manageProviderDialog,e[59]=t,e[60]=g,e[61]=v.allModels,e[62]=v.builtinRows,e[63]=v.customConfig,e[64]=W):W=e[64];let G;return e[65]!==V||e[66]!==H||e[67]!==U||e[68]!==ee||e[69]!==W?(G=(0,$.jsxs)(ut,{children:[V,H,U,ee,W]}),e[65]=V,e[66]=H,e[67]=U,e[68]=ee,e[69]=W,e[70]=G):G=e[70],G}function Or(){J()}function kr(e){return e.id===`xopc-cloud`&&!e.isCustom}function Ar(e){return e.language}function jr(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)(en,{}),t[0]=e):e=t[0],e}case`voice`:{let e;return t[1]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(hn,{}),t[1]=e):e=t[1],e}case`search`:{let e;return t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Rn,{}),t[2]=e):e=t[2],e}}}function Mr({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:S(`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{Dr as CapabilitiesSettingsPanel};