@xopcai/xopc 0.0.165 → 0.0.166

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 (134) 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/{agent-avatar-dicebear-CKVX2TyD.js → agent-avatar-dicebear-Tr2hgn4j.js} +1 -1
  4. package/dist/gateway/static/root/assets/{agents-F8749KZ_.js → agents-DZ69tC4K.js} +1 -1
  5. package/dist/gateway/static/root/assets/{app-management-settings-panel-ClToHdDF.js → app-management-settings-panel-D7Nrbhez.js} +1 -1
  6. package/dist/gateway/static/root/assets/{appearance-settings-Ci2jWAkQ.js → appearance-settings-DNNbABFj.js} +1 -1
  7. package/dist/gateway/static/root/assets/{apps-page-DCow0nte.js → apps-page-0zXIeywq.js} +1 -1
  8. package/dist/gateway/static/root/assets/{archive-plugin-CKv5A1_M.js → archive-plugin-CizqFy4G.js} +1 -1
  9. package/dist/gateway/static/root/assets/{attachment-load-LgoN-Vwo.js → attachment-load-DU8KjTua.js} +1 -1
  10. package/dist/gateway/static/root/assets/{automation-suggestion-card-BwnZqDQE.js → automation-suggestion-card-3pqyIveW.js} +1 -1
  11. package/dist/gateway/static/root/assets/{automations-page-DWWHMqCZ.js → automations-page-DSz3xDsi.js} +1 -1
  12. package/dist/gateway/static/root/assets/{binary-plugins-WwMRnBdP.js → binary-plugins-CipUnsOr.js} +1 -1
  13. package/dist/gateway/static/root/assets/{block-editor-CThEfJSn.js → block-editor-XoEq6qiv.js} +3 -3
  14. package/dist/gateway/static/root/assets/{browser-settings-page-7x8rKLOl.js → browser-settings-page-COYvq3y5.js} +1 -1
  15. package/dist/gateway/static/root/assets/{browser-workflow-inputs-DCj9DG0A.js → browser-workflow-inputs-DRH995XI.js} +1 -1
  16. package/dist/gateway/static/root/assets/{browser-workflows-page-C1k2vHLV.js → browser-workflows-page-65edjhpz.js} +1 -1
  17. package/dist/gateway/static/root/assets/{capabilities-settings-panel-DIwGIpuS.js → capabilities-settings-panel-LOQyfdsM.js} +1 -1
  18. package/dist/gateway/static/root/assets/{capability-presets-api-C_NVbV7o.js → capability-presets-api-XL4h7dCK.js} +1 -1
  19. package/dist/gateway/static/root/assets/{capability-presets-settings-panel-DBdvIcV0.js → capability-presets-settings-panel-KPJFkt1h.js} +1 -1
  20. package/dist/gateway/static/root/assets/{channels-settings-DU93p9RZ.js → channels-settings-D8nH0mve.js} +1 -1
  21. package/dist/gateway/static/root/assets/{connector-logo-au5xzRMl.js → connector-logo-n4Hg41iD.js} +1 -1
  22. package/dist/gateway/static/root/assets/{connectors-page-B9sD56hT.js → connectors-page-jvRWZn3Y.js} +1 -1
  23. package/dist/gateway/static/root/assets/{desktop-pet-CaTO9bAV.js → desktop-pet-D4OzBOwm.js} +1 -1
  24. package/dist/gateway/static/root/assets/{desktop-pet-settings-CORq2BIE.js → desktop-pet-settings-CDGezbaf.js} +1 -1
  25. package/dist/gateway/static/root/assets/{directory-picker-path-field-Daf0tqrN.js → directory-picker-path-field-DmL4AUXQ.js} +1 -1
  26. package/dist/gateway/static/root/assets/{dreaming-settings-CJqJpvgc.js → dreaming-settings-ClUcBKnd.js} +1 -1
  27. package/dist/gateway/static/root/assets/{extension-debug-page-0XmiUqsm.js → extension-debug-page-DsV_KUDM.js} +1 -1
  28. package/dist/gateway/static/root/assets/{extension-page-C_9HSvyu.js → extension-page-DJv_G1jY.js} +1 -1
  29. package/dist/gateway/static/root/assets/{extension-settings-page-DcmUCmOu.js → extension-settings-page-DUAlJ4CU.js} +1 -1
  30. package/dist/gateway/static/root/assets/{gateway-config-api-CZqfsxJf.js → gateway-config-api-SVYgzqv7.js} +1 -1
  31. package/dist/gateway/static/root/assets/{gateway-settings-CzX8TVmO.js → gateway-settings-YL6f2C_F.js} +1 -1
  32. package/dist/gateway/static/root/assets/{goal-create-dialog-Dbj_sgV-.js → goal-create-dialog-CJJe-4Co.js} +1 -1
  33. package/dist/gateway/static/root/assets/{goal-detail-page-BdkiZwW-.js → goal-detail-page-Da9VMWRd.js} +1 -1
  34. package/dist/gateway/static/root/assets/{goals-config-api-Cvlq3jyf.js → goals-config-api-st_Itxa9.js} +1 -1
  35. package/dist/gateway/static/root/assets/{goals-page-BD9ztXNA.js → goals-page-B6pC7PYZ.js} +1 -1
  36. package/dist/gateway/static/root/assets/{goals-settings-CSGvHJDi.js → goals-settings-BEZePZ5m.js} +1 -1
  37. package/dist/gateway/static/root/assets/{heartbeat-settings-BvXA7oNN.js → heartbeat-settings-DpeD9GQ9.js} +1 -1
  38. package/dist/gateway/static/root/assets/{index-CfOzvGDb.js → index-BhQMnKH1.js} +6 -6
  39. package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-xb6mna1C.js → keyboard-shortcuts-settings-fhssr2-J.js} +1 -1
  40. package/dist/gateway/static/root/assets/{local-app-workbench-page-DH4nglP_.js → local-app-workbench-page-Ctia6lSG.js} +1 -1
  41. package/dist/gateway/static/root/assets/{local-apps-page-BScdXqMo.js → local-apps-page-DWF9rpWQ.js} +1 -1
  42. package/dist/gateway/static/root/assets/{logs-page-BBpAWjyF.js → logs-page-D3gL6vHX.js} +1 -1
  43. package/dist/gateway/static/root/assets/{markdown-split-8hnAS25m.js → markdown-split-BuduJ0Ev.js} +1 -1
  44. package/dist/gateway/static/root/assets/{media-plugins-DzlHseMD.js → media-plugins-CLASZjhT.js} +1 -1
  45. package/dist/gateway/static/root/assets/{notes-page-DbDHFPiI.js → notes-page-ve3XiBDF.js} +1 -1
  46. package/dist/gateway/static/root/assets/{notes-workbench-B-A9whbg.js → notes-workbench-oHU532lp.js} +2 -2
  47. package/dist/gateway/static/root/assets/{page-tabs-CXJiygUJ.js → page-tabs-DU85jn98.js} +1 -1
  48. package/dist/gateway/static/root/assets/{preview-open-alternatives-Cq6aue5a.js → preview-open-alternatives-CtchTuRQ.js} +1 -1
  49. package/dist/gateway/static/root/assets/{product-open-page-nP8vuNlJ.js → product-open-page-DFT6Fx6y.js} +1 -1
  50. package/dist/gateway/static/root/assets/{project-detail-page-BXrscUbq.js → project-detail-page-Ceu0NoC1.js} +1 -1
  51. package/dist/gateway/static/root/assets/{projects-page-m0EKUeaY.js → projects-page-CdpqOmO8.js} +1 -1
  52. package/dist/gateway/static/root/assets/{remote-access-hub-B16uQSY5.js → remote-access-hub-D1NKLyiR.js} +1 -1
  53. package/dist/gateway/static/root/assets/{save-bar-controls-BPgnLY1p.js → save-bar-controls-CmcrHpMc.js} +1 -1
  54. package/dist/gateway/static/root/assets/{schedule-field-rHWpueWl.js → schedule-field-DmIkP6JV.js} +1 -1
  55. package/dist/gateway/static/root/assets/{schema-form-CHKIUrzk.js → schema-form-Dkk9blN0.js} +1 -1
  56. package/dist/gateway/static/root/assets/{sessions-page-C5_qtznc.js → sessions-page-CMj_JaOk.js} +1 -1
  57. package/dist/gateway/static/root/assets/settings-advanced-gate-DR9Q2ZyF.js +1 -0
  58. package/dist/gateway/static/root/assets/{settings-form-section-CR4J0N4X.js → settings-form-section-CuQzWvg5.js} +1 -1
  59. package/dist/gateway/static/root/assets/{settings-loading-skeleton-B8v-lHKT.js → settings-loading-skeleton-C5FNbyej.js} +1 -1
  60. package/dist/gateway/static/root/assets/{settings-page-BcLf8Rd5.js → settings-page-a-A2yTGE.js} +1 -1
  61. package/dist/gateway/static/root/assets/{settings-page-layout-Co31Becn.js → settings-page-layout-MuXpamWD.js} +1 -1
  62. package/dist/gateway/static/root/assets/{setup-status-panel-BFLA1Fsj.js → setup-status-panel-BUdh8FKY.js} +1 -1
  63. package/dist/gateway/static/root/assets/{share-preview-page-B5vMe8DY.js → share-preview-page-BfzzmTgg.js} +1 -1
  64. package/dist/gateway/static/root/assets/{shares-settings-DL2tKPq6.js → shares-settings-8a9qnLF8.js} +1 -1
  65. package/dist/gateway/static/root/assets/{skill-reload-api-C8jkuLob.js → skill-reload-api-da5gLCer.js} +1 -1
  66. package/dist/gateway/static/root/assets/{skills-page-DAOZXlp5.js → skills-page-CmHj-CKY.js} +1 -1
  67. package/dist/gateway/static/root/assets/{system-settings-panel-CHt3FXI8.js → system-settings-panel-CyhRkWMi.js} +1 -1
  68. package/dist/gateway/static/root/assets/{time-picker-C9Rr1IUV.js → time-picker-WEPp3HrB.js} +1 -1
  69. package/dist/gateway/static/root/assets/{typed-models-lib-QMF30Yvh.js → typed-models-lib-Bi1uoxFR.js} +1 -1
  70. package/dist/gateway/static/root/assets/{user-context-page-D6EEhj-e.js → user-context-page-BObEyiim.js} +1 -1
  71. package/dist/gateway/static/root/assets/{voice-api-key-field-Gjjs3qih.js → voice-api-key-field-Gvgodhec.js} +1 -1
  72. package/dist/gateway/static/root/assets/{work-discovery-page-CDnL9daG.js → work-discovery-page-BHnjvGH1.js} +1 -1
  73. package/dist/gateway/static/root/assets/{work-item-detail-page-BCoT4p1E.js → work-item-detail-page-CQ8ybkxx.js} +1 -1
  74. package/dist/gateway/static/root/assets/{work-page-l8h2Y50w.js → work-page-D_U_En23.js} +1 -1
  75. package/dist/gateway/static/root/assets/{workflow-run-setup-panel-DnOfronD.js → workflow-run-setup-panel-B-Sk6gFn.js} +1 -1
  76. package/dist/gateway/static/root/assets/{workflows-page-IVbQ83CW.js → workflows-page-DT0pzfkz.js} +1 -1
  77. package/dist/gateway/static/root/index.html +1 -1
  78. package/dist/package.js +1 -1
  79. package/dist/src/agent/agent-manager.js +3 -3
  80. package/dist/src/agent/bootstrap/filter-bootstrap-files.js +1 -1
  81. package/dist/src/agent/embedded/model-runtime.js +1 -1
  82. package/dist/src/agent/goals/post-turn.js +1 -1
  83. package/dist/src/agent/image/tool-model-config.js +1 -1
  84. package/dist/src/agent/ipc/inbox.js +1 -1
  85. package/dist/src/agent/memory/dreaming/config.js +1 -1
  86. package/dist/src/agent/service.js +2 -2
  87. package/dist/src/agent/skills/hub-lock.js +1 -1
  88. package/dist/src/agent-runtime/index.js +1 -1
  89. package/dist/src/agent-runtime/runtime-profile.js +1 -1
  90. package/dist/src/auth/credentials.js +2 -2
  91. package/dist/src/auth/profiles/store.js +1 -1
  92. package/dist/src/auth/sync-provider-auth.js +2 -2
  93. package/dist/src/browser/providers/browser-ext-install.js +1 -1
  94. package/dist/src/cli/commands/connectors.js +1 -1
  95. package/dist/src/cli/commands/doctor/checks/provider-auth.js +1 -1
  96. package/dist/src/cli/commands/extension-marketplace.js +1 -1
  97. package/dist/src/cli/commands/gateway/lifecycle.js +1 -1
  98. package/dist/src/cli/commands/models.js +1 -1
  99. package/dist/src/cli/commands/update.js +1 -1
  100. package/dist/src/config/agent-profile.js +1 -1
  101. package/dist/src/config/index.js +4 -4
  102. package/dist/src/config/loader.js +1 -1
  103. package/dist/src/config/models-json.js +1 -1
  104. package/dist/src/connectors/connector-memory-sync.js +1 -1
  105. package/dist/src/connectors/health.js +1 -1
  106. package/dist/src/extensions/lockfile.js +1 -1
  107. package/dist/src/gateway/agents-admin.js +2 -2
  108. package/dist/src/gateway/file-path-classifier.js +1 -1
  109. package/dist/src/gateway/hono/lib/config-payload.js +1 -1
  110. package/dist/src/gateway/hono/routes/mcp.js +1 -1
  111. package/dist/src/gateway/hono/routes/models.js +1 -1
  112. package/dist/src/gateway/hono/routes/update.js +2 -2
  113. package/dist/src/gateway/hono/routes/workflows.js +1 -1
  114. package/dist/src/gateway/index.js +1 -1
  115. package/dist/src/gateway/run-loop.js +1 -1
  116. package/dist/src/gateway/service/config-coordinator.js +1 -1
  117. package/dist/src/gateway/service.js +4 -4
  118. package/dist/src/goals/goal-workflow-judge.js +1 -1
  119. package/dist/src/infra/gateway-processes.js +1 -1
  120. package/dist/src/infra/update-restart.js +1 -1
  121. package/dist/src/infra/update-runner.js +2 -2
  122. package/dist/src/infra/update-startup.js +1 -1
  123. package/dist/src/mcp/channel-bridge.js +1 -1
  124. package/dist/src/notes/service.js +1 -1
  125. package/dist/src/providers/auth-runtime/resolve-auth.js +1 -1
  126. package/dist/src/providers/index.js +7 -4
  127. package/dist/src/providers/model-ref.d.ts +6 -0
  128. package/dist/src/providers/model-ref.js +15 -0
  129. package/dist/src/providers/model-registry.js +6 -3
  130. package/dist/src/tui/tui-startup-resources.js +2 -2
  131. package/dist/src/tui/tui.js +1 -1
  132. package/dist/src/workflows/service/workflow-run-service.js +1 -1
  133. package/package.json +1 -1
  134. package/dist/gateway/static/root/assets/settings-advanced-gate-DQlbm1mA.js +0 -1
@@ -1,2 +1,2 @@
1
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{d as i,l as a,r as o,t as s,u as c}from"./chunk-KS7C4IRE-uQ0fehio.js";import{t as l}from"./cn-JdwAhgNB.js";import{t as u}from"./messages-C96Zjb0V.js";import{l as d,n as f,o as p,r as m,s as h}from"./locale-store-C_ax27uc.js";import{i as g}from"./vendor-swr-BIWyz7Rc.js";import{An as _,As as v,Bn as y,Bs as b,Bt as x,Cn as S,Dn as C,Ds as w,Ec as T,En as E,Es as D,Fc as O,Fn as k,Gn as A,Go as j,Hn as M,In as N,Is as P,Jn as F,Jo as I,Js as L,Kl as R,Kn as z,Ln as B,Lr as V,Mn as H,Ms as U,Mt as ee,Nc as te,Nn as ne,Ns as W,On as re,Pc as ie,Pn as ae,Qo as G,Rn as oe,Sl as se,Sn as K,Ss as q,Tn as ce,Un as le,Uo as ue,Vs as de,Vt as fe,Wn as pe,Wo as me,Wr as he,Xc as ge,Xn as _e,Yn as ve,Yo as ye,Ys as be,Zn as xe,_u as Se,as as Ce,bn as we,cs as J,dc as Te,es as Ee,gc as De,hu as Oe,jl as ke,jn as Ae,js as je,jt as Me,ju as Ne,kn as Pe,ms as Fe,no as Ie,oc as Le,os as Y,ps as Re,qn as ze,qo as Be,rl as X,ro as Ve,tl as He,to as Ue,tr as We,ts as Ge,vl as Ke,wn as qe,ws as Je,xn as Ye,xs as Xe,yc as Ze,yn as Qe,zc as $e,zn as et,zt as tt}from"./index-CfOzvGDb.js";import{n as nt,r as rt}from"./settings-page-layout-Co31Becn.js";import{t as it}from"./settings-loading-skeleton-B8v-lHKT.js";import{c as at,d as ot,i as st,l as ct,n as lt,o as ut,r as dt,s as ft,t as pt,u as mt}from"./voice-api-key-field-Gjjs3qih.js";import{t as ht}from"./settings-advanced-gate-DQlbm1mA.js";import{n as gt,t as _t}from"./settings-form-section-CR4J0N4X.js";import{t as vt}from"./page-tabs-CXJiygUJ.js";import{n as yt,r as bt,t as xt}from"./save-bar-controls-BPgnLY1p.js";var Z=n(),Q=e(t(),1),$=r(),St={en:{title:`Image generation`,intro:`Choose an agent and a built-in provider. One action stores the credential and enables the model.`,agent:`Agent`,provider:`Provider`,model:`Model`,apiKey:`API key`,apiKeyHint:`Stored in the local credential store, never in xopc.json.`,existingKey:`A credential or environment variable is already available. Leave this blank to reuse it.`,region:`Service region`,cn:`China`,intl:`International`,advanced:`Custom endpoint`,baseUrl:`Base URL (optional)`,enable:`Enable image generation`,enabling:`Verifying and enabling…`,enabled:`Image generation is ready.`,enabledWithoutVerify:`Image generation is enabled. This provider does not expose a lightweight credential check.`,current:`Current`,configured:`Credential ready`,needsKey:`API key required`,connect:`Connect to a gateway to continue.`,loadError:`Unable to load image generation settings.`,selectAgent:`Select an agent`,selectModel:`Select a model`,show:`Show key`,hide:`Hide key`,copy:`Copy key`,copied:`Copied`},zh:{title:`图片生成`,intro:`选择 Agent 和内置 Provider,一次操作完成凭据保存与模型启用。`,agent:`Agent`,provider:`Provider`,model:`模型`,apiKey:`API Key`,apiKeyHint:`密钥只保存在本机凭据存储中,不会写入 xopc.json。`,existingKey:`已有凭据或环境变量;留空即可继续使用。`,region:`服务地域`,cn:`中国站`,intl:`国际站`,advanced:`自定义服务地址`,baseUrl:`Base URL(可选)`,enable:`启用图片生成`,enabling:`正在验证并启用…`,enabled:`图片生成已可用。`,enabledWithoutVerify:`图片生成已启用;该 Provider 暂无轻量凭据验证接口。`,current:`当前使用`,configured:`凭据已就绪`,needsKey:`需要 API Key`,connect:`请先连接网关。`,loadError:`无法加载图片生成设置。`,selectAgent:`选择 Agent`,selectModel:`选择模型`,show:`显示密钥`,hide:`隐藏密钥`,copy:`复制密钥`,copied:`已复制`}};async function Ct(){let e=await h(m(`/api/image-generation/catalog`));if(!Array.isArray(e.payload?.providers))throw Error(`Invalid image provider catalog`);return e.payload.providers}async function wt(e){let t=await h(m(`/api/agents/${encodeURIComponent(e)}/image-generation`));if(!t.payload)throw Error(`Invalid agent image generation response`);return t.payload}function Tt(e){let t=e?.indexOf(`/`)??-1;return t>0?e.slice(0,t):void 0}function Et(e){let t=e?.indexOf(`/`)??-1;return t>0?e.slice(t+1):void 0}function Dt(){let e=(0,Z.c)(2),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(Ve,{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(Ot)}),(0,$.jsx)(Ve,{className:`h-64 rounded-xl`})]}),e[1]=n):n=e[1],n}function Ot(e,t){return(0,$.jsx)(Ve,{className:`h-24 rounded-xl`},t)}function kt(){let e=f(e=>e.language),t=St[e],n=u(e),r=!!d(e=>e.token),[i,a]=(0,Q.useState)(``),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(``),[p,_]=(0,Q.useState)(``),[v,y]=(0,Q.useState)(e===`zh`?`cn`:`intl`),[b,x]=(0,Q.useState)(``),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(),[E,D]=(0,Q.useState)(),{data:O,isLoading:k,error:A}=g(r?`image-generation-agents`:null,he,{revalidateOnFocus:!1}),{data:j,isLoading:M,error:N,mutate:P}=g(r?m(`/api/image-generation/catalog`):null,Ct,{revalidateOnFocus:!1});(0,Q.useEffect)(()=>{!O||i||a(O.defaultId||O.agents[0]?.id||``)},[i,O]);let{data:F,isLoading:I,error:L,mutate:R}=g(r&&i?[`agent-image-generation`,i]:null,()=>wt(i),{revalidateOnFocus:!1});(0,Q.useEffect)(()=>{if(!j||!F)return;let e=Tt(F.model?.primary),t=j.find(t=>t.id===e)??j.find(e=>e.configured)??j[0];t&&(s(t.id),l(t.id===e&&Et(F.model?.primary)||t.defaultModel),_(``))},[F,j]),(0,Q.useEffect)(()=>{T(void 0),D(void 0)},[i]);let z=j?.find(e=>e.id===o),B=(0,Q.useMemo)(()=>(O?.agents??[]).map(e=>({value:e.id,label:V(e,n.agentsSettings)})),[O?.agents,n.agentsSettings]),H=(0,Q.useMemo)(()=>(z?.models??[]).map(e=>({value:e,label:e})),[z?.models]),U=F?.model?.primary,ee=!!(i&&z&&c&&(z.configured||p.trim()));if(!r)return(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.connect});if(k||M||I)return(0,$.jsx)(Dt,{});if(A||N||L||!j||!O)return(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:t.loadError});let te=e=>{s(e.id),l(e.defaultModel),_(``),x(``),T(void 0),D(void 0)},ne=async()=>{if(!(!z||!ee)){C(!0),T(void 0),D(void 0);try{let e=await h(m(`/api/agents/${encodeURIComponent(i)}/image-generation/setup`),{method:`POST`,body:JSON.stringify({providerId:z.id,modelId:c,...p.trim()?{apiKey:p.trim()}:{},...z.requiresRegion?{region:v}:{},...b.trim()?{baseUrl:b.trim()}:{}})});if(!e.payload)throw Error(`Invalid setup response`);await Promise.all([R(e.payload.agent,{revalidate:!1}),P(e.payload.providers,{revalidate:!1})]),_(``),D(e.payload.verification.supported?t.enabled:t.enabledWithoutVerify)}catch(e){T(e instanceof Error?e.message:String(e))}finally{C(!1)}}};return(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`section`,{className:`rounded-xl border border-edge bg-surface-base p-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,$.jsx)(`div`,{className:`rounded-lg bg-accent/10 p-2 text-accent`,children:(0,$.jsx)(se,{className:`size-5`})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:t.title}),(0,$.jsx)(`p`,{className:`mt-1 text-sm leading-relaxed text-fg-muted`,children:t.intro})]})]}),(0,$.jsxs)(`label`,{className:`mt-4 block text-xs font-medium text-fg-muted`,children:[t.agent,(0,$.jsx)(Ce,{value:i,options:B,placeholder:t.selectAgent,allowEmpty:!1,onChange:a,triggerClassName:`mt-1.5 max-w-md`})]})]}),(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h3`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-fg-subtle`,children:t.provider}),(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 xl:grid-cols-3`,children:j.map(e=>{let n=e.id===o,r=e.id===Tt(U);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>te(e),className:`rounded-xl border p-4 text-left transition-colors ${n?`border-accent bg-accent/5 ring-1 ring-accent/20`:`border-edge bg-surface-base hover:border-edge-strong`}`,children:[(0,$.jsxs)(`span`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`font-medium text-fg`,children:e.label}),r?(0,$.jsx)(`span`,{className:`rounded-full bg-accent/10 px-2 py-0.5 text-[11px] font-medium text-accent`,children:t.current}):null]}),(0,$.jsxs)(`span`,{className:`mt-2 flex items-center gap-1.5 text-xs ${e.configured?`text-emerald-600 dark:text-emerald-400`:`text-fg-muted`}`,children:[e.configured?(0,$.jsx)(Oe,{className:`size-3.5`}):(0,$.jsx)(Ke,{className:`size-3.5`}),e.configured?t.configured:t.needsKey]})]},e.id)})})]}),z?(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)(Ce,{value:c,options:H,placeholder:t.selectModel,allowEmpty:!1,onChange:l,triggerClassName:`mt-1.5`})]}),z.requiresRegion?(0,$.jsxs)(`label`,{className:`block text-xs font-medium text-fg-muted`,children:[t.region,(0,$.jsx)(Ce,{value:v,options:[{value:`cn`,label:t.cn},{value:`intl`,label:t.intl}],placeholder:t.region,allowEmpty:!1,onChange:e=>y(e),triggerClassName:`mt-1.5`})]}):null]}),(0,$.jsxs)(`label`,{className:`mt-4 block text-xs font-medium text-fg-muted`,children:[t.apiKey,(0,$.jsx)(Je,{value:p,onChange:_,placeholder:z.configured?t.existingKey:t.needsKey,labels:{show:t.show,hide:t.hide,copy:t.copy,copied:t.copied},className:`mt-1.5`,autoComplete:`new-password`}),(0,$.jsx)(`span`,{className:`mt-1.5 block font-normal leading-relaxed text-fg-subtle`,children:z.configured?t.existingKey:t.apiKeyHint})]}),(0,$.jsxs)(`details`,{className:`mt-4 rounded-lg border border-edge bg-surface-subtle px-3 py-2.5`,children:[(0,$.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 text-sm font-medium text-fg-muted`,children:[(0,$.jsx)(Te,{className:`size-4`}),t.advanced]}),(0,$.jsxs)(`label`,{className:`mt-3 block text-xs font-medium text-fg-muted`,children:[t.baseUrl,(0,$.jsx)(`input`,{value:b,onChange:e=>x(e.target.value),placeholder:`https://…`,className:`mt-1.5 h-10 w-full rounded-lg border border-edge bg-surface-panel px-3 text-sm text-fg outline-none focus:border-accent focus:ring-2 focus:ring-accent/20`})]})]}),w?(0,$.jsx)(`p`,{className:`mt-4 rounded-lg bg-red-500/10 px-3 py-2 text-sm text-red-600 dark:text-red-400`,children:w}):null,E?(0,$.jsx)(`p`,{className:`mt-4 rounded-lg bg-emerald-500/10 px-3 py-2 text-sm text-emerald-700 dark:text-emerald-400`,children:E}):null,(0,$.jsx)(`div`,{className:`mt-4 flex justify-end`,children:(0,$.jsxs)(W,{variant:`primary`,disabled:!ee||S,onClick:()=>void ne(),children:[S?(0,$.jsx)(X,{className:`size-4 animate-spin`}):(0,$.jsx)(Oe,{className:`size-4`}),S?t.enabling:t.enable]})})]}):null]})}var At=v;function jt(e){switch(e){case`alibaba`:return`(DASHSCOPE_API_KEY)`;case`openai`:return`(OPENAI_API_KEY)`;case`groq`:return`(GROQ_API_KEY)`;default:return``}}function Mt(e){switch(e){case`alibaba`:return`(DASHSCOPE_API_KEY)`;case`openai`:return`(OPENAI_API_KEY)`;case`minimax`:return`(MINIMAX_API_KEY)`;default:return``}}function Nt(){return l(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,U,`dark:border-edge`)}function Pt(){return l(je,v)}function Ft(e){return!e||e<=0?``:e<1024*1024?`${Math.round(e/1024)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function It(e,t){let n=window.atob(e),r=new Uint8Array(n.length);for(let e=0;e<n.length;e++)r[e]=n.charCodeAt(e);return URL.createObjectURL(new Blob([r],{type:t}))}var Lt=[{id:`paraformer-v2`,name:`Paraformer v2`},{id:`paraformer-v1`,name:`Paraformer v1`}],Rt=[{id:`whisper-1`,name:`Whisper-1`}],zt=[{id:`whisper-large-v3-turbo`,name:`Whisper Large v3 Turbo`},{id:`whisper-large-v3`,name:`Whisper Large v3`}],Bt=[{id:`tts-1`,name:`TTS-1`},{id:`tts-1-hd`,name:`TTS-1 HD`}],Vt=[{id:`alloy`,name:`Alloy`},{id:`echo`,name:`Echo`}],Ht=[{id:`qwen-tts`,name:`Qwen TTS`},{id:`qwen3-tts-flash`,name:`Qwen3 TTS Flash`}],Ut=[{id:`Cherry`,name:`Cherry`},{id:`longxiaochun`,name:`Long Xiao Chun`}],Wt=[{id:`en-US-MichelleNeural`,name:`Michelle (US English)`},{id:`zh-CN-XiaoxiaoNeural`,name:`Xiaoxiao (Chinese)`}],Gt=[{id:`speech-2.8-hd`,name:`Speech 2.8 HD (Recommended)`},{id:`speech-2.8-turbo`,name:`Speech 2.8 Turbo (Fast)`}],Kt=[{id:`male-qn-qingse`,name:`Male Qingse (青涩男声)`},{id:`female-shaonv`,name:`Female Shaonv (少女音)`}],qt=[{id:`piper`,command:`piper --model /path/to/voice.onnx --output_file "{{OutputPath}}"`,outputFormat:`wav`},{id:`sherpa-onnx`,command:`sherpa-onnx-offline-tts --text "{{Text}}" --output-filename "{{OutputPath}}"`,outputFormat:`wav`},{id:`mlx-audio`,command:`python -m mlx_audio.tts.generate --text "{{Text}}" --file_prefix "{{OutputBase}}"`,outputFormat:`wav`}];function Jt(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 Yt(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 Xt(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 Zt(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 Qt(e){return{maskedHelp:e.apiKeyMaskedHelp,copy:e.apiKeyCopy,copied:e.apiKeyCopied,show:e.apiKeyShow,hide:e.apiKeyHide,notInConfigFile:e.apiKeyNotInConfigFile,loadFailed:e.apiKeyRevealFailed}}function $t(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 en(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 tn(e,t){switch(t.type){case`reset`:return{form:null,baseline:null};case`sync`:{let e=structuredClone(t.value);return{form:e,baseline:structuredClone(e)}}case`update`:return{...e,form:t.updater(e.form)};case`discard`:return e.baseline?{form:structuredClone(e.baseline),baseline:e.baseline}:e;case`saved`:{let e=structuredClone(t.value);return{form:e,baseline:structuredClone(e)}}}}function nn(){let e=f(e=>e.language),t=u(e).voiceSettings,n=!!d(e=>e.token),[r,i]=(0,Q.useReducer)(tn,{form:null,baseline:null}),a=r.form,o=r.baseline,[s,c]=(0,Q.useState)(null),[l,p]=(0,Q.useState)(!1),[h,_]=(0,Q.useState)(null),v=(0,Q.useRef)(!1),y=(0,Q.useRef)({parsed:null,models:void 0}),{data:b,error:x,isLoading:S,mutate:C}=Ie(n),{data:w,error:T,isLoading:E,mutate:D}=g(n?m(`/api/voice/models`):null,dt,{revalidateOnFocus:!1}),{data:O,error:k,isLoading:A}=g(n?m(`/api/voice/providers`):null,st,{revalidateOnFocus:!1}),{data:j,error:M,isLoading:N}=g(n?m(`/api/voice/stt-providers`):null,ut,{revalidateOnFocus:!1}),P=(0,Q.useMemo)(()=>O?.providers??[],[O]),F=(0,Q.useMemo)(()=>j?.providers??[],[j]),I=(0,Q.useMemo)(()=>b?.payload?.config===void 0?null:at(b.payload.config),[b]),L=(0,Q.useMemo)(()=>!a||!o?!1:JSON.stringify(a)!==JSON.stringify(o),[a,o]);n?I!==null&&w!==void 0&&!v.current&&(y.current.parsed!==I||y.current.models!==w)&&(y.current={parsed:I,models:w},i({type:`sync`,value:I}),c(w)):(y.current.parsed!==null||y.current.models!==void 0)&&(y.current={parsed:null,models:void 0},i({type:`reset`}),c(null),v.current=!1);let R=!!(n&&(I===null||w===void 0||O===void 0||j===void 0)&&(S||E||A||N)),z=x instanceof Error?x.message:x?String(x):T instanceof Error?T.message:T?String(T):k instanceof Error?k.message:k?String(k):M instanceof Error?M.message:M?String(M):null,B=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>t?{...t,stt:{...t.stt,...e}}:null})},[]),V=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>t?{...t,stt:{...t.stt,alibaba:{...t.stt.alibaba,...e}}}:null})},[]),H=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>t?{...t,stt:{...t.stt,openai:{...t.stt.openai,...e}}}:null})},[]),U=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>{if(!t)return null;let n=t.stt.fallback??{enabled:!1,order:[`xopc-local`]};return{...t,stt:{...t.stt,fallback:{...n,...e}}}}})},[]),ee=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>t?{...t,voice:{...t.voice,input:{...t.voice.input,refinement:{...t.voice.input.refinement,...e}}}}:null})},[]),te=(0,Q.useCallback)(t=>{v.current=!0,i({type:`update`,updater:n=>n?{...n,voice:{...n.voice,languageMode:t,...t===`auto`?{language:e}:{}}}:null})},[e]),ne=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>t?{...t,tts:{...t.tts,...e}}:null})},[]),re=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>t?{...t,tts:{...t.tts,alibaba:{...t.tts.alibaba,...e}}}:null})},[]),ie=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>t?{...t,tts:{...t.tts,openai:{...t.tts.openai,...e}}}:null})},[]),ae=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>t?{...t,voice:e.voice!==void 0||e.lang!==void 0?{...t.voice,languageMode:`manual`}:t.voice,tts:{...t.tts,edge:{...t.tts.edge,...e}}}:null})},[]),G=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>t?{...t,tts:{...t.tts,minimax:{...t.tts.minimax,...e}}}:null})},[]),oe=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>t?{...t,tts:{...t.tts,"tts-local-cli":{...t.tts[`tts-local-cli`],...e}}}:null})},[]);if(yt({id:`voice`,dirty:L,saving:l,save:(0,Q.useCallback)(async()=>{if(!(!a||l)){p(!0),_(null);try{await ct(a),i({type:`saved`,value:a}),v.current=!1}catch(e){_(e instanceof Error?e.message:t.saveError)}finally{p(!1)}}},[a,l,t.saveError]),discard:(0,Q.useCallback)(()=>{o&&(v.current=!1,i({type:`discard`}),_(null))},[o])}),!n)return(0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.needToken})});if(R)return(0,$.jsx)(it,{rows:4});if(!a||s===null)return(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:h??z??t.loadError}),(0,$.jsx)(W,{type:`button`,variant:`secondary`,onClick:()=>{C(),D()},children:t.retry})]});let se=a.stt,K=a.tts,q=a.voice.input.refinement,ce=Qt(t);return(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[h?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:h}):null,(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsx)(rn,{v:t,voice:a.voice,updateLanguageMode:te}),(0,$.jsx)(an,{v:t,stt:se,tts:K}),(0,$.jsx)(sn,{v:t,apiKeyLabels:ce,stt:se,models:s,sttProviders:F,refinement:q,updateStt:B,updateSttAlibaba:V,updateSttOpenai:H,updateSttFallback:U,updateRefinement:ee}),(0,$.jsx)(hn,{v:t,apiKeyLabels:ce,tts:K,models:s,ttsProviders:P,updateTts:ne,updateTtsAlibaba:re,updateTtsOpenai:ie,updateTtsEdge:ae,updateTtsMinimax:G,updateTtsLocalCli:oe})]}),(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 rn(e){let t=(0,Z.c)(22),{v:n,voice:r,updateLanguageMode:i}=e,a;t[0]===n.language.title?a=t[1]:(a=(0,$.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:n.language.title}),t[0]=n.language.title,t[1]=a);let o=r.languageMode===`auto`?n.language.autoDescription:n.language.manualDescription,s;t[2]===o?s=t[3]:(s=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:o}),t[2]=o,t[3]=s);let c;t[4]!==a||t[5]!==s?(c=(0,$.jsxs)(`div`,{children:[a,s]}),t[4]=a,t[5]=s,t[6]=c):c=t[6];let l;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(l=Pt(),t[7]=l):l=t[7];let u;t[8]===i?u=t[9]:(u=e=>i(e.target.value),t[8]=i,t[9]=u);let d;t[10]===n.language.auto?d=t[11]:(d=(0,$.jsx)(J,{value:`auto`,children:n.language.auto}),t[10]=n.language.auto,t[11]=d);let f;t[12]===n.language.manual?f=t[13]:(f=(0,$.jsx)(J,{value:`manual`,children:n.language.manual}),t[12]=n.language.manual,t[13]=f);let p;t[14]!==u||t[15]!==d||t[16]!==f||t[17]!==r.languageMode?(p=(0,$.jsxs)(Y,{className:l,value:r.languageMode,onChange:u,children:[d,f]}),t[14]=u,t[15]=d,t[16]=f,t[17]=r.languageMode,t[18]=p):p=t[18];let m;return t[19]!==c||t[20]!==p?(m=(0,$.jsx)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-[minmax(0,1fr)_minmax(12rem,18rem)] sm:items-center`,children:[c,p]})}),t[19]=c,t[20]=p,t[21]=m):m=t[21],m}function an(e){let t=(0,Z.c)(39),{v:n,stt:r,tts:i}=e,a=i.provider===`openai`?i.openai?.voice:i.provider===`alibaba`?i.alibaba?.voice:i.provider===`minimax`?i.minimax?.voice:i.provider===`edge`?i.edge?.voice:void 0,o;t[0]===n.overview.title?o=t[1]:(o=(0,$.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:n.overview.title}),t[0]=n.overview.title,t[1]=o);let s;t[2]===n.overview.description?s=t[3]:(s=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:n.overview.description}),t[2]=n.overview.description,t[3]=s);let c;t[4]!==o||t[5]!==s?(c=(0,$.jsxs)(`div`,{className:`mb-4`,children:[o,s]}),t[4]=o,t[5]=s,t[6]=c):c=t[6];let l;t[7]!==r.enabled||t[8]!==r.provider||t[9]!==n?(l=r.enabled?`${n.overview.ready} · ${Jt(r.provider,n)}`:n.overview.off,t[7]=r.enabled,t[8]=r.provider,t[9]=n,t[10]=l):l=t[10];let u;t[11]!==r.enabled||t[12]!==l||t[13]!==n.overview.input?(u=(0,$.jsx)(on,{label:n.overview.input,value:l,ready:r.enabled}),t[11]=r.enabled,t[12]=l,t[13]=n.overview.input,t[14]=u):u=t[14];let d;t[15]!==i.enabled||t[16]!==i.trigger||t[17]!==n?(d=i.enabled?Xt(i.trigger,n):n.overview.off,t[15]=i.enabled,t[16]=i.trigger,t[17]=n,t[18]=d):d=t[18];let f=i.enabled&&i.trigger!==`off`,p;t[19]!==d||t[20]!==f||t[21]!==n.overview.replies?(p=(0,$.jsx)(on,{label:n.overview.replies,value:d,ready:f}),t[19]=d,t[20]=f,t[21]=n.overview.replies,t[22]=p):p=t[22];let m;t[23]!==a||t[24]!==i.enabled||t[25]!==i.provider||t[26]!==n?(m=i.enabled?`${Yt(i.provider,n)}${a?` · ${a}`:``}`:n.overview.off,t[23]=a,t[24]=i.enabled,t[25]=i.provider,t[26]=n,t[27]=m):m=t[27];let h;t[28]!==m||t[29]!==i.enabled||t[30]!==n.overview.voice?(h=(0,$.jsx)(on,{label:n.overview.voice,value:m,ready:i.enabled}),t[28]=m,t[29]=i.enabled,t[30]=n.overview.voice,t[31]=h):h=t[31];let g;t[32]!==h||t[33]!==u||t[34]!==p?(g=(0,$.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-3`,children:[u,p,h]}),t[32]=h,t[33]=u,t[34]=p,t[35]=g):g=t[35];let _;return t[36]!==g||t[37]!==c?(_=(0,$.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[c,g]}),t[36]=g,t[37]=c,t[38]=_):_=t[38],_}function on(e){let t=(0,Z.c)(10),{label:n,value:r,ready:i}=e,a;t[0]===n?a=t[1]:(a=(0,$.jsx)(`div`,{className:`text-xs text-fg-muted`,children:n}),t[0]=n,t[1]=a);let o=i?`text-fg`:`text-fg-muted`,s;t[2]===o?s=t[3]:(s=l(`mt-1 text-sm font-medium`,o),t[2]=o,t[3]=s);let c;t[4]!==s||t[5]!==r?(c=(0,$.jsx)(`div`,{className:s,children:r}),t[4]=s,t[5]=r,t[6]=c):c=t[6];let u;return t[7]!==a||t[8]!==c?(u=(0,$.jsxs)(`div`,{className:`rounded-xl bg-surface-panel/80 px-3 py-2.5 shadow-surface`,children:[a,c]}),t[7]=a,t[8]=c,t[9]=u):u=t[9],u}function sn(e){let t=(0,Z.c)(49),{v:n,apiKeyLabels:r,stt:i,models:a,sttProviders:o,refinement:s,updateStt:c,updateSttAlibaba:u,updateSttOpenai:d,updateSttFallback:f,updateRefinement:p}=e,m=a?.stt?.alibaba?.length?a.stt.alibaba:Lt,h=a?.stt?.openai?.length?a.stt.openai:Rt,g;if(t[0]!==o){let e=new Set;g=[];for(let t of o)e.has(t.id)||(e.add(t.id),g.push(t));t[0]=o,t[1]=g}else g=t[1];let _=g,v,y,b,x,S;if(t[2]!==m||t[3]!==r||t[4]!==a?.stt||t[5]!==h||t[6]!==_||t[7]!==s||t[8]!==i||t[9]!==p||t[10]!==c||t[11]!==u||t[12]!==f||t[13]!==d||t[14]!==n){let e=_.find(e=>e.id===i.provider),o=i.providers?.[i.provider],g=typeof o?.apiKey==`string`?o.apiKey:``,C=typeof o?.model==`string`?o.model:``,w={...i.provider===`alibaba`?i.alibaba??{}:{},...i.provider===`openai`?i.openai??{}:{},...o??{}},T=(e?.fields??[]).filter(fn),E;t[20]!==i.provider||t[21]!==i.providers||t[22]!==c?(E=e=>{c({providers:{...i.providers??{},[i.provider]:{...i.providers?.[i.provider]??{},...e}}})},t[20]=i.provider,t[21]=i.providers,t[22]=c,t[23]=E):E=t[23];let D=E;x=`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`;let O;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,$.jsx)(ge,{className:`size-4 text-accent`,strokeWidth:1.75}),t[24]=O):O=t[24];let k;t[25]===n.stt.title?k=t[26]:(k=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[O,n.stt.title]}),t[25]=n.stt.title,t[26]=k);let A;t[27]===n.stt.description?A=t[28]:(A=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:n.stt.description}),t[27]=n.stt.description,t[28]=A),t[29]!==k||t[30]!==A?(S=(0,$.jsxs)(`div`,{className:`mb-4`,children:[k,A]}),t[29]=k,t[30]=A,t[31]=S):S=t[31],v=`space-y-4`;let j;t[32]===c?j=t[33]:(j=e=>c({enabled:e}),t[32]=c,t[33]=j),t[34]!==i.enabled||t[35]!==j||t[36]!==n.overview.off||t[37]!==n.overview.ready||t[38]!==n.stt.enable||t[39]!==n.stt.enableDesc?(y=(0,$.jsx)(gn,{checked:i.enabled,title:n.stt.enable,description:n.stt.enableDesc,onLabel:n.overview.ready,offLabel:n.overview.off,onChange:j}),t[34]=i.enabled,t[35]=j,t[36]=n.overview.off,t[37]=n.overview.ready,t[38]=n.stt.enable,t[39]=n.stt.enableDesc,t[40]=y):y=t[40],b=i.enabled?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,At),children:[(0,$.jsx)(yn,{children:n.stt.provider}),(0,$.jsx)(Y,{className:Pt(),value:i.provider,onChange:e=>c({provider:e.target.value}),children:_.map(e=>(0,$.jsxs)(J,{value:e.id,children:[Jt(e.id,n),e.configured?``:` *`]},e.id))})]}),(0,$.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,At),children:[(0,$.jsx)(yn,{children:n.stt.model}),i.provider===`xopc-local`?(0,$.jsx)(Y,{className:Pt(),value:C||`sensevoice-small`,onChange:e=>D({model:e.target.value}),children:(a?.stt?.[`xopc-local`]??[]).map(dn)}):i.provider===`alibaba`?(0,$.jsx)(Y,{className:Pt(),value:i.alibaba?.model??``,onChange:e=>u({model:e.target.value}),children:m.map(un)}):i.provider===`openai`?(0,$.jsx)(Y,{className:Pt(),value:i.openai?.model??``,onChange:e=>d({model:e.target.value}),children:h.map(ln)}):i.provider===`groq`?(0,$.jsx)(Y,{className:Pt(),value:C||zt[0].id,onChange:e=>D({model:e.target.value}),children:zt.map(cn)}):(0,$.jsx)(`input`,{className:Nt(),value:C,onChange:e=>D({model:e.target.value}),placeholder:i.provider})]}),e?.diagnostics.requiresApiKey===!1?null:(0,$.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,At),children:[(0,$.jsx)(yn,{children:n.stt.apiKey}),(0,$.jsx)(pt,{kind:`stt`,providerId:i.provider,fieldId:`voice-stt-${i.provider}-api-key`,value:i.provider===`alibaba`?i.alibaba?.apiKey??``:i.provider===`openai`?i.openai?.apiKey??``:g,onChange:e=>{i.provider===`alibaba`?u({apiKey:e}):i.provider===`openai`?d({apiKey:e}):D({apiKey:e})},labels:r,placeholder:i.provider===`groq`?`gsk_...`:`sk-...`}),(0,$.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.stt.apiKeyDesc,jt(i.provider)?` ${jt(i.provider)}`:``]})]})]}),T.length>0?(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:T.map(e=>(0,$.jsx)(_n,{field:e,value:$t(w,e),onChange:t=>D({[e.key]:t}),className:e.type===`textarea`?`sm:col-span-2`:At},e.key))}):null,i.provider===`xopc-local`?(0,$.jsx)(mn,{v:n}):null,(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.stt.fallback}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.stt.fallbackDesc})]}),(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:i.fallback?.enabled??!1,onChange:e=>f({enabled:e.target.checked})})]}),(0,$.jsxs)(`div`,{className:`grid gap-3 rounded-xl bg-surface-hover/50 p-3 dark:bg-surface-hover/35 sm:grid-cols-[minmax(0,1fr)_minmax(12rem,18rem)] sm:items-center`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.stt.refinement}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.stt.refinementDesc})]}),(0,$.jsxs)(Y,{className:Pt(),value:s.mode,onChange:e=>p({mode:e.target.value}),children:[(0,$.jsx)(J,{value:`off`,children:n.stt.refinementOff}),(0,$.jsx)(J,{value:`punctuation`,children:n.stt.refinementPunctuation}),(0,$.jsx)(J,{value:`light`,children:n.stt.refinementLight})]})]})]}):null,t[2]=m,t[3]=r,t[4]=a?.stt,t[5]=h,t[6]=_,t[7]=s,t[8]=i,t[9]=p,t[10]=c,t[11]=u,t[12]=f,t[13]=d,t[14]=n,t[15]=v,t[16]=y,t[17]=b,t[18]=x,t[19]=S}else v=t[15],y=t[16],b=t[17],x=t[18],S=t[19];let C;t[41]!==v||t[42]!==y||t[43]!==b?(C=(0,$.jsxs)(`div`,{className:v,children:[y,b]}),t[41]=v,t[42]=y,t[43]=b,t[44]=C):C=t[44];let w;return t[45]!==x||t[46]!==S||t[47]!==C?(w=(0,$.jsxs)(`section`,{className:x,children:[S,C]}),t[45]=x,t[46]=S,t[47]=C,t[48]=w):w=t[48],w}function cn(e){return(0,$.jsx)(J,{value:e.id,children:e.name},e.id)}function ln(e){return(0,$.jsx)(J,{value:e.id,children:e.name},e.id)}function un(e){return(0,$.jsx)(J,{value:e.id,children:e.name},e.id)}function dn(e){return(0,$.jsx)(J,{value:e.id,children:e.name},e.id)}function fn(e){return e.key!==`apiKey`&&e.key!==`model`}function pn(e){return`${Math.round(e/1024/1024)} MB`}function mn({v:e}){let{data:t,error:n,mutate:r}=g(m(`/api/voice/local/status`),lt,{revalidateOnFocus:!1,refreshInterval:e=>e?.models.some(e=>e.state===`downloading`)?1e3:0}),[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(null),c=(0,Q.useCallback)(async(e,t)=>{a(e.id),s(null);try{t===`install`?await ft(e.id):await mt(e.id),await r()}catch(e){s(e instanceof Error?e.message:String(e))}finally{a(null)}},[r]);return(0,$.jsxs)(`div`,{className:`rounded-xl border border-edge bg-surface-panel/60 p-3`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.stt.localModels}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:e.stt.localModelsDesc}),n?(0,$.jsx)(`p`,{className:`mt-3 text-xs text-red-600 dark:text-red-400`,children:String(n)}):null,o?(0,$.jsx)(`p`,{className:`mt-3 text-xs text-red-600 dark:text-red-400`,children:o}):null,(0,$.jsx)(`div`,{className:`mt-3 grid gap-2`,children:(t?.models??[]).map(t=>{let n=i===t.id||t.state===`downloading`;return(0,$.jsxs)(`div`,{className:l(`flex items-center justify-between gap-3 rounded-lg bg-surface-base px-3 py-2.5`,t.recommended?`ring-1 ring-accent/40`:``),children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-sm font-medium text-fg`,children:[t.name,t.recommended?(0,$.jsx)(`span`,{className:`rounded-full bg-accent/10 px-2 py-0.5 text-[10px] font-medium text-accent`,children:e.stt.localRecommended}):null]}),(0,$.jsxs)(`div`,{className:`text-xs text-fg-muted`,children:[pn(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)(W,{type:`button`,variant:`secondary`,disabled:n,onClick:()=>void c(t,t.state===`ready`?`remove`:`install`),children:n?(0,$.jsx)(X,{className:`size-4 animate-spin`}):t.state===`ready`?e.stt.localRemove:e.stt.localInstall})]},t.id)})})]})}function hn({v:e,apiKeyLabels:t,tts:n,models:r,ttsProviders:i,updateTts:a,updateTtsAlibaba:o,updateTtsOpenai:s,updateTtsEdge:c,updateTtsMinimax:u,updateTtsLocalCli:d}){let f=r?.tts?.openai?.length?r.tts.openai:Bt,p=r?.ttsVoices?.openai?.length?r.ttsVoices.openai:Vt,m=r?.tts?.alibaba?.length?r.tts.alibaba:Ht,h=r?.ttsVoices?.alibaba?.length?r.ttsVoices.alibaba:Ut,g=r?.ttsVoices?.edge?.length?r.ttsVoices.edge:Wt,_=r?.tts?.minimax?.length?r.tts.minimax:Gt,v=r?.ttsVoices?.minimax?.length?r.ttsVoices.minimax:Kt,[y,x]=(0,Q.useState)(e.tts.test.sampleText),[S,C]=(0,Q.useState)({status:`idle`}),w=(0,Q.useRef)(null),T=(0,Q.useRef)(null),E=(0,Q.useCallback)(()=>{w.current?.pause(),w.current=null,T.current&&=(URL.revokeObjectURL(T.current),null)},[]),D=(0,Q.useMemo)(()=>{let e=new Set,t=[];for(let n of i)e.has(n.id)||(e.add(n.id),t.push(n));return t},[i]),k=D.find(e=>e.id===n.provider),A=n.providers?.[n.provider],j={...n.provider===`openai`?n.openai??{}:{},...n.provider===`alibaba`?n.alibaba??{}:{},...n.provider===`edge`?n.edge??{}:{},...n.provider===`minimax`?n.minimax??{}:{},...n.provider===`tts-local-cli`?n[`tts-local-cli`]??{}:{},...A??{}},M=(k?.fields??[]).filter(e=>![`apiKey`,`model`,`voice`].includes(e.key)),N=!!k?.diagnostics.requiresApiKey,P=!!k?.configured||!N,F=n.enabled?P?`ready`:`action`:`muted`,I=n.provider===`openai`?n.openai?.model:n.provider===`alibaba`?n.alibaba?.model:n.provider===`minimax`?n.minimax?.model:void 0,L=n.provider===`openai`?n.openai?.voice:n.provider===`alibaba`?n.alibaba?.voice:n.provider===`minimax`?n.minimax?.voice:n.provider===`edge`?n.edge?.voice:void 0;(0,Q.useEffect)(()=>()=>E(),[E]);let R=(0,Q.useCallback)(e=>{a({provider:e}),C({status:`idle`})},[a]),z=(0,Q.useCallback)(async()=>{let t=y.trim();if(!t){C({status:`error`,message:e.tts.test.emptyText});return}E(),C({status:`loading`});try{let r=await ot({text:t,provider:n.provider,providerConfig:j,...I?{model:I}:{},...L?{voice:L}:{}}),i=It(r.audio,r.mimeType);T.current=i;let a=new Audio(i);w.current=a;let o=[r.provider,r.format,r.latencyMs===void 0?void 0:`${r.latencyMs}ms`,Ft(r.audioSize)].filter(Boolean).join(` · `);a.addEventListener(`ended`,()=>C({status:`done`,summary:o}),{once:!0}),a.addEventListener(`error`,()=>C({status:`error`,message:e.tts.test.playFailed}),{once:!0}),await a.play(),C({status:`playing`,summary:o})}catch(e){E(),C({status:`error`,message:e instanceof Error?e.message:String(e)})}},[I,L,j,E,y,n.provider,e.tts.test.emptyText,e.tts.test.playFailed]),B=(0,Q.useCallback)(e=>{a({providers:{...n.providers??{},[n.provider]:{...n.providers?.[n.provider]??{},...e}}})},[n.provider,n.providers,a]),V=(0,Q.useCallback)((e,t)=>{let r={[e.key]:t};B(r),n.provider===`openai`&&e.key===`baseUrl`?s(r):n.provider===`minimax`&&(e.key===`baseUrl`||e.key===`groupId`)?u(r):n.provider===`edge`&&e.key===`lang`&&c(r)},[n.provider,B,c,u,s]);return(0,$.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[(0,$.jsxs)(`div`,{className:`mb-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,$.jsx)(b,{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)(gn,{checked:n.enabled,title:e.tts.enable,description:e.tts.enableDesc,onLabel:e.overview.ready,offLabel:e.overview.off,onChange:e=>a({enabled:e})}),(0,$.jsxs)(`div`,{className:l(`rounded-xl border px-3 py-2.5 text-sm`,F===`ready`?`border-emerald-500/25 bg-emerald-500/10 text-emerald-800 dark:text-emerald-100`:F===`action`?`border-amber-300/50 bg-amber-50 text-amber-900 dark:border-amber-300/30 dark:bg-amber-400/10 dark:text-amber-100`:`border-edge bg-surface-panel text-fg-muted`),children:[(0,$.jsx)(`div`,{className:`font-medium text-fg`,children:e.tts.statusTitle}),(0,$.jsx)(`p`,{className:`mt-1 text-xs`,children:n.enabled?P?`${e.tts.statusReady} ${Yt(n.provider,e)}${L?` · ${L}`:``}`:`${e.tts.statusNeedsSetup} ${Yt(n.provider,e)} · ${k?.diagnostics.envKeys?.join(`, `)??e.stt.apiKey}`:e.tts.statusOff})]}),n.enabled?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,At),children:[(0,$.jsx)(yn,{children:e.tts.trigger}),(0,$.jsxs)(Y,{className:Pt(),value:n.trigger,onChange:e=>a({trigger:e.target.value}),children:[(0,$.jsx)(J,{value:`off`,children:e.tts.triggerOff}),(0,$.jsx)(J,{value:`inbound`,children:e.tts.triggerInbound}),(0,$.jsx)(J,{value:`tagged`,children:e.tts.triggerTagged}),(0,$.jsx)(J,{value:`always`,children:e.tts.triggerAlways})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.triggerHelp})]}),(0,$.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,At),children:[(0,$.jsx)(yn,{children:e.tts.provider}),(0,$.jsx)(Y,{className:Pt(),value:n.provider,onChange:e=>R(e.target.value),children:D.map(t=>(0,$.jsx)(J,{value:t.id,children:Yt(t.id,e)},t.id))}),(0,$.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[k?.configured?e.tts.configured:k?.diagnostics.requiresApiKey?`${e.tts.needsKey} · ${k.diagnostics.envKeys?.join(`, `)??e.stt.apiKey}`:e.tts.noKeyNeeded,` · `,k?.description??Zt(n.provider,e)]})]})]}),(0,$.jsxs)(`details`,{className:`rounded-xl bg-surface-panel/80 p-3 shadow-surface`,open:!P||n.provider===`tts-local-cli`,children:[(0,$.jsxs)(`summary`,{className:`cursor-pointer text-sm font-medium text-fg marker:text-fg-muted`,children:[e.tts.advanced.title,(0,$.jsx)(`span`,{className:`ml-2 text-xs font-normal text-fg-muted`,children:e.tts.advanced.description})]}),(0,$.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[n.provider===`openai`||n.provider===`alibaba`||n.provider===`minimax`?(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,At),children:[(0,$.jsx)(yn,{children:e.stt.apiKey}),(0,$.jsx)(pt,{kind:`tts`,providerId:n.provider,fieldId:`voice-tts-${n.provider}-api-key`,value:n.provider===`openai`?n.openai?.apiKey??``:n.provider===`alibaba`?n.alibaba?.apiKey??``:n.minimax?.apiKey??``,onChange:e=>{n.provider===`openai`?s({apiKey:e}):n.provider===`alibaba`?o({apiKey:e}):u({apiKey:e})},labels:t,placeholder:n.provider===`minimax`?`eyJ...`:`sk-...`}),(0,$.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,Mt(n.provider)?` ${Mt(n.provider)}`:``]})]}),(0,$.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,At),children:[(0,$.jsx)(yn,{children:e.stt.model}),(0,$.jsx)(Y,{className:Pt(),value:n.provider===`openai`?n.openai?.model??``:n.provider===`alibaba`?n.alibaba?.model??``:n.minimax?.model??``,onChange:e=>{n.provider===`openai`?s({model:e.target.value}):n.provider===`alibaba`?o({model:e.target.value}):u({model:e.target.value})},children:(n.provider===`openai`?f:n.provider===`alibaba`?m:_).map(e=>(0,$.jsx)(J,{value:e.id,children:e.name},e.id))})]}),(0,$.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,At),children:[(0,$.jsx)(yn,{children:e.tts.voice}),(0,$.jsx)(Y,{className:Pt(),value:n.provider===`openai`?n.openai?.voice??``:n.provider===`alibaba`?n.alibaba?.voice??``:n.minimax?.voice??``,onChange:e=>{n.provider===`openai`?s({voice:e.target.value}):n.provider===`alibaba`?o({voice:e.target.value}):u({voice:e.target.value})},children:(n.provider===`openai`?p:n.provider===`alibaba`?h:v).map(e=>(0,$.jsx)(J,{value:e.id,children:e.name},e.id))})]})]}):null,n.provider===`edge`?(0,$.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,At),children:[(0,$.jsx)(yn,{children:e.tts.voice}),(0,$.jsx)(Y,{className:Pt(),value:n.edge?.voice??``,onChange:e=>c({voice:e.target.value}),children:g.map(e=>(0,$.jsx)(J,{value:e.id,children:e.name},e.id))}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.edgeHint})]}):null,n.provider===`tts-local-cli`?(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,$.jsx)(yn,{children:e.tts.localCli.preset}),(0,$.jsxs)(Y,{className:Pt(),value:``,onChange:e=>{let t=qt.find(t=>t.id===e.target.value);t&&d({command:t.command,outputFormat:t.outputFormat})},children:[(0,$.jsx)(J,{value:``,children:e.tts.localCli.presetPlaceholder}),qt.map(e=>(0,$.jsx)(J,{value:e.id,children:e.id},e.id))]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.presetDesc})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,$.jsx)(yn,{children:e.tts.localCli.command}),(0,$.jsx)(`input`,{className:l(Nt(),`font-mono text-xs`),type:`text`,autoComplete:`off`,spellCheck:!1,value:n[`tts-local-cli`]?.command??``,onChange:e=>d({command:e.target.value}),placeholder:e.tts.localCli.commandPlaceholder}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.commandDesc})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(yn,{children:e.tts.localCli.cwd}),(0,$.jsx)(`input`,{className:l(Nt(),`font-mono text-xs`),type:`text`,autoComplete:`off`,spellCheck:!1,value:n[`tts-local-cli`]?.cwd??``,onChange:e=>d({cwd:e.target.value}),placeholder:`/path/to/cwd`}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.cwdDesc})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(yn,{children:e.tts.localCli.outputFormat}),(0,$.jsxs)(Y,{className:Pt(),value:n[`tts-local-cli`]?.outputFormat??`wav`,onChange:e=>d({outputFormat:e.target.value}),children:[(0,$.jsx)(J,{value:`wav`,children:`wav`}),(0,$.jsx)(J,{value:`mp3`,children:`mp3`}),(0,$.jsx)(J,{value:`opus`,children:`opus`})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.outputFormatDesc})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,$.jsx)(yn,{children:e.tts.localCli.timeoutMs}),(0,$.jsx)(`input`,{className:Nt(),type:`number`,min:0,step:1e3,value:typeof n[`tts-local-cli`]?.timeoutMs==`number`?String(n[`tts-local-cli`].timeoutMs):``,onChange:e=>{let t=e.target.value.trim();if(t===``){d({timeoutMs:void 0});return}let n=Number(t);Number.isFinite(n)&&n>=0&&d({timeoutMs:n})},placeholder:`30000`}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.timeoutMsDesc})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle sm:col-span-2`,children:e.tts.localCli.hint})]}):null,M.length>0?(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:M.map(e=>(0,$.jsx)(_n,{field:e,value:$t(j,e),onChange:t=>V(e,t),className:e.type===`textarea`?`sm:col-span-2`:At},e.key))}):null]})]}),(0,$.jsxs)(`div`,{className:`rounded-xl bg-surface-panel/80 p-3 shadow-surface`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.tts.test.title}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:e.tts.test.description})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[(0,$.jsxs)(W,{type:`button`,variant:`primary`,onClick:()=>void z(),disabled:S.status===`loading`,className:`h-9`,children:[S.status===`loading`?(0,$.jsx)(X,{className:`size-4 animate-spin`}):(0,$.jsx)(O,{className:`size-4`}),S.status===`loading`?e.tts.test.generating:e.tts.test.play]}),(0,$.jsxs)(W,{type:`button`,variant:`secondary`,onClick:()=>{E(),C(e=>e.status===`playing`?{status:`done`,summary:e.summary}:{status:`idle`})},disabled:S.status!==`playing`,className:`h-9`,children:[(0,$.jsx)(Le,{className:`size-4`}),e.tts.test.stop]})]})]}),(0,$.jsx)(`textarea`,{className:l(Nt(),`mt-3 min-h-20 resize-y`),value:y,onChange:e=>x(e.target.value),maxLength:1e3}),(0,$.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center justify-between gap-2 text-xs`,children:[(0,$.jsxs)(`span`,{className:`text-fg-subtle`,children:[y.length,`/1000`]}),S.status===`playing`||S.status===`done`?(0,$.jsxs)(`span`,{className:`text-emerald-700 dark:text-emerald-200`,children:[S.status===`playing`?e.tts.test.playing:e.tts.test.ready,` · `,S.summary]}):null,S.status===`error`?(0,$.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:S.message}):null]})]})]}):null]})]})}function gn(e){let t=(0,Z.c)(33),{checked:n,title:r,description:i,onLabel:a,offLabel:o,onChange:s}=e,c;t[0]!==n||t[1]!==s?(c=()=>s(!n),t[0]=n,t[1]=s,t[2]=c):c=t[2];let u=n?`bg-accent/10 text-fg ring-1 ring-accent/45 dark:bg-accent/15`:`bg-surface-panel/80 text-fg hover:bg-surface-hover`,d;t[3]===u?d=t[4]:(d=l(`group flex w-full items-center justify-between gap-4 rounded-2xl px-4 py-3 text-left shadow-surface transition-colors`,U,u),t[3]=u,t[4]=d);let f=n?`bg-accent text-white`:`bg-surface-hover text-fg-muted`,p;t[5]===f?p=t[6]:(p=l(`rounded-full px-2 py-0.5 text-[11px] font-medium`,f),t[5]=f,t[6]=p);let m=n?a:o,h;t[7]!==p||t[8]!==m?(h=(0,$.jsx)(`span`,{className:p,children:m}),t[7]=p,t[8]=m,t[9]=h):h=t[9];let g;t[10]!==h||t[11]!==r?(g=(0,$.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-sm font-semibold text-fg`,children:[r,h]}),t[10]=h,t[11]=r,t[12]=g):g=t[12];let _;t[13]===i?_=t[14]:(_=(0,$.jsx)(`span`,{className:`mt-1 block text-xs leading-relaxed text-fg-muted`,children:i}),t[13]=i,t[14]=_);let v;t[15]!==g||t[16]!==_?(v=(0,$.jsxs)(`span`,{className:`min-w-0`,children:[g,_]}),t[15]=g,t[16]=_,t[17]=v):v=t[17];let y=n?`border-accent bg-accent`:`border-edge bg-surface-hover group-hover:border-accent/40`,b;t[18]===y?b=t[19]:(b=l(`relative inline-flex h-6 w-11 shrink-0 items-center rounded-full border transition-colors`,y),t[18]=y,t[19]=b);let x=n?`translate-x-5`:`translate-x-0.5`,S;t[20]===x?S=t[21]:(S=l(`size-5 rounded-full bg-white shadow-surface transition-transform`,x),t[20]=x,t[21]=S);let C;t[22]===S?C=t[23]:(C=(0,$.jsx)(`span`,{className:S}),t[22]=S,t[23]=C);let w;t[24]!==b||t[25]!==C?(w=(0,$.jsx)(`span`,{className:b,"aria-hidden":!0,children:C}),t[24]=b,t[25]=C,t[26]=w):w=t[26];let T;return t[27]!==n||t[28]!==c||t[29]!==v||t[30]!==w||t[31]!==d?(T=(0,$.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":n,onClick:c,className:d,children:[v,w]}),t[27]=n,t[28]=c,t[29]=v,t[30]=w,t[31]=d,t[32]=T):T=t[32],T}function _n(e){let t=(0,Z.c)(36),{field:n,value:r,onChange:i,className:a}=e,o=`voice-schema-field-${n.key}`,s=n.description;if(n.type===`boolean`){let e;t[0]===a?e=t[1]:(e=l(`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,a),t[0]=a,t[1]=e);let o;t[2]===n.label?o=t[3]:(o=(0,$.jsx)(`span`,{className:`block text-sm font-medium text-fg`,children:n.label}),t[2]=n.label,t[3]=o);let c;t[4]===s?c=t[5]:(c=s?(0,$.jsx)(`span`,{className:`mt-1 block text-xs text-fg-subtle`,children:s}):null,t[4]=s,t[5]=c);let u;t[6]!==o||t[7]!==c?(u=(0,$.jsxs)(`span`,{children:[o,c]}),t[6]=o,t[7]=c,t[8]=u):u=t[8];let d=!!r,f;t[9]!==n||t[10]!==i?(f=e=>i(en(n,e.target.checked)),t[9]=n,t[10]=i,t[11]=f):f=t[11];let p;t[12]!==d||t[13]!==f?(p=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:d,onChange:f}),t[12]=d,t[13]=f,t[14]=p):p=t[14];let m;return t[15]!==e||t[16]!==u||t[17]!==p?(m=(0,$.jsxs)(`label`,{className:e,children:[u,p]}),t[15]=e,t[16]=u,t[17]=p,t[18]=m):m=t[18],m}let c=typeof r==`boolean`?``:String(r),u;t[19]===a?u=t[20]:(u=l(`flex flex-col gap-1.5`,a),t[19]=a,t[20]=u);let d;t[21]===n.label?d=t[22]:(d=(0,$.jsx)(yn,{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)(Y,{id:o,className:Pt(),value:c,required:n.required,onChange:e=>i(en(n,e.target.value)),children:(n.options??[]).map(vn)}):n.type===`textarea`?(0,$.jsx)(`textarea`,{id:o,className:l(Nt(),`min-h-24 resize-y`),value:c,required:n.required,placeholder:n.placeholder,onChange:e=>i(en(n,e.target.value))}):n.type===`password`?(0,$.jsx)(Je,{id:o,className:a,value:c,onChange:e=>i(en(n,e)),placeholder:n.placeholder,labels:Xe}):(0,$.jsx)(`input`,{id:o,className:Nt(),type:n.type===`number`?`number`:`text`,autoComplete:n.secret?`new-password`:`off`,spellCheck:!1,value:c,required:n.required,placeholder:n.placeholder,onChange:e=>i(en(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 vn(e){return(0,$.jsx)(J,{value:e.id,children:e.name},e.id)}function yn(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 bn(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 xn(e){let t=e.regionMode===`auto`?`auto`:e.regionMode===`cn`?`cn`:`global`,n={maxResults:e.maxResults,providers:e.providers.map(e=>{let t={type:e.type,apiKey:e.apiKey};return e.type===`searxng`&&e.url.trim()&&(t.url=e.url.trim().replace(/\/+$/,``)),e.disabled&&(t.disabled=!0),t})};await h(m(`/api/config`),{method:`PATCH`,body:JSON.stringify({tools:{web:{region:t,search:n,blocklist:{enabled:e.blocklistEnabled,domains:e.blocklistDomains}}}})}),Ue()}async function Sn(e){let t=await h(m(`/api/tools/web/reveal-search-api-key`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({index:e})});if(!t.ok||!t.payload)throw Error(t.error?.message??`Reveal failed`);return t.payload}function Cn(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 wn(){return l(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,U,`dark:border-edge`)}function Tn(){return l(je,v)}var En=[`brave`,`tavily`,`bing`,`searxng`];function Dn(){return{type:`brave`,apiKey:``,url:``,disabled:!1}}var On=Me();function kn(){let e=u(f(e=>e.language)),t=e.webSearchSettings,n=e.logs,r=!!d(e=>e.token),[i,a]=(0,Q.useReducer)(On,{form:null,baseline:null}),o=i.form,s=i.baseline,[c,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(null),g=(0,Q.useRef)(!1),_=(0,Q.useRef)(null),{data:v,error:y,isLoading:b,mutate:x}=Ie(r);ee({enabled:r,parsed:(0,Q.useMemo)(()=>v?.payload?.config===void 0?null:bn(v.payload.config),[v]),dirty:g.current,trackedParsedRef:_,dispatch:a,onResetDirty:()=>{g.current=!1}});let S=!!(r&&b&&v===void 0&&!y),C=y instanceof Error?y.message:y?String(y):null,w=(0,Q.useMemo)(()=>!o||!s?!1:JSON.stringify(o)!==JSON.stringify(s),[o,s]),T=(0,Q.useCallback)(e=>{g.current=!0,a({type:`patch`,patch:e})},[]);return yt({id:`search`,dirty:w,saving:c,save:(0,Q.useCallback)(async()=>{if(!(!o||c)){p(!0),h(null);try{await xn(o),g.current=!1,a({type:`saved`,value:o})}catch(e){h(e instanceof Error?e.message:t.saveError)}finally{p(!1)}}},[o,c,t.saveError]),discard:(0,Q.useCallback)(()=>{s&&(g.current=!1,a({type:`discard`}),h(null))},[s])}),r?S?(0,$.jsx)(it,{rows:3}):o?(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[m?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:m}):null,(0,$.jsxs)(_t,{children:[(0,$.jsx)(gt,{icon:Ze,title:t.sectionRegion,subtitle:t.sectionRegionHint}),(0,$.jsx)(`div`,{className:`flex max-w-md flex-col gap-4`,children:(0,$.jsx)(Cn,{label:t.regionLabel,description:t.regionDesc,children:(0,$.jsxs)(Y,{className:Tn(),value:o.regionMode,onChange:e=>T({regionMode:e.target.value}),children:[(0,$.jsx)(J,{value:`auto`,children:t.regionAuto}),(0,$.jsx)(J,{value:`cn`,children:t.regionCn}),(0,$.jsx)(J,{value:`global`,children:t.regionGlobal})]})})})]}),(0,$.jsx)(ht,{children:(0,$.jsxs)(_t,{children:[(0,$.jsx)(gt,{icon:Ne,title:t.sectionBlocklist,subtitle:t.sectionBlocklistHint}),(0,$.jsxs)(`div`,{className:`flex max-w-xl flex-col gap-4`,children:[(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:o.blocklistEnabled,onChange:e=>T({blocklistEnabled:e.target.checked})}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`font-medium`,children:t.blocklistEnabled}),(0,$.jsx)(`span`,{className:`mt-0.5 block text-xs text-fg-subtle`,children:t.blocklistEnabledDesc})]})]}),(0,$.jsx)(Cn,{label:t.blocklistDomains,description:t.blocklistDomainsDesc,children:(0,$.jsx)(`textarea`,{className:l(wn(),`min-h-[6rem] font-mono text-xs`),value:o.blocklistDomains.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,r as o,t as s,u as c}from"./chunk-KS7C4IRE-uQ0fehio.js";import{t as l}from"./cn-JdwAhgNB.js";import{t as u}from"./messages-C96Zjb0V.js";import{l as d,n as f,o as p,r as m,s as h}from"./locale-store-C_ax27uc.js";import{i as g}from"./vendor-swr-BIWyz7Rc.js";import{An as _,As as v,Bn as y,Bs as b,Bt as x,Cn as S,Dn as C,Ds as w,Ec as T,En as E,Es as D,Fc as O,Fn as k,Gn as A,Go as j,Hn as M,In as N,Is as P,Jn as F,Jo as I,Js as L,Kl as R,Kn as z,Ln as B,Lr as V,Mn as H,Ms as U,Mt as ee,Nc as te,Nn as ne,Ns as W,On as re,Pc as ie,Pn as ae,Qo as G,Rn as oe,Sl as se,Sn as K,Ss as q,Tn as ce,Un as le,Uo as ue,Vs as de,Vt as fe,Wn as pe,Wo as me,Wr as he,Xc as ge,Xn as _e,Yn as ve,Yo as ye,Ys as be,Zn as xe,_u as Se,as as Ce,bn as we,cs as J,dc as Te,es as Ee,gc as De,hu as Oe,jl as ke,jn as Ae,js as je,jt as Me,ju as Ne,kn as Pe,ms as Fe,no as Ie,oc as Le,os as Y,ps as Re,qn as ze,qo as Be,rl as X,ro as Ve,tl as He,to as Ue,tr as We,ts as Ge,vl as Ke,wn as qe,ws as Je,xn as Ye,xs as Xe,yc as Ze,yn as Qe,zc as $e,zn as et,zt as tt}from"./index-BhQMnKH1.js";import{n as nt,r as rt}from"./settings-page-layout-MuXpamWD.js";import{t as it}from"./settings-loading-skeleton-C5FNbyej.js";import{c as at,d as ot,i as st,l as ct,n as lt,o as ut,r as dt,s as ft,t as pt,u as mt}from"./voice-api-key-field-Gvgodhec.js";import{t as ht}from"./settings-advanced-gate-DR9Q2ZyF.js";import{n as gt,t as _t}from"./settings-form-section-CuQzWvg5.js";import{t as vt}from"./page-tabs-DU85jn98.js";import{n as yt,r as bt,t as xt}from"./save-bar-controls-CmcrHpMc.js";var Z=n(),Q=e(t(),1),$=r(),St={en:{title:`Image generation`,intro:`Choose an agent and a built-in provider. One action stores the credential and enables the model.`,agent:`Agent`,provider:`Provider`,model:`Model`,apiKey:`API key`,apiKeyHint:`Stored in the local credential store, never in xopc.json.`,existingKey:`A credential or environment variable is already available. Leave this blank to reuse it.`,region:`Service region`,cn:`China`,intl:`International`,advanced:`Custom endpoint`,baseUrl:`Base URL (optional)`,enable:`Enable image generation`,enabling:`Verifying and enabling…`,enabled:`Image generation is ready.`,enabledWithoutVerify:`Image generation is enabled. This provider does not expose a lightweight credential check.`,current:`Current`,configured:`Credential ready`,needsKey:`API key required`,connect:`Connect to a gateway to continue.`,loadError:`Unable to load image generation settings.`,selectAgent:`Select an agent`,selectModel:`Select a model`,show:`Show key`,hide:`Hide key`,copy:`Copy key`,copied:`Copied`},zh:{title:`图片生成`,intro:`选择 Agent 和内置 Provider,一次操作完成凭据保存与模型启用。`,agent:`Agent`,provider:`Provider`,model:`模型`,apiKey:`API Key`,apiKeyHint:`密钥只保存在本机凭据存储中,不会写入 xopc.json。`,existingKey:`已有凭据或环境变量;留空即可继续使用。`,region:`服务地域`,cn:`中国站`,intl:`国际站`,advanced:`自定义服务地址`,baseUrl:`Base URL(可选)`,enable:`启用图片生成`,enabling:`正在验证并启用…`,enabled:`图片生成已可用。`,enabledWithoutVerify:`图片生成已启用;该 Provider 暂无轻量凭据验证接口。`,current:`当前使用`,configured:`凭据已就绪`,needsKey:`需要 API Key`,connect:`请先连接网关。`,loadError:`无法加载图片生成设置。`,selectAgent:`选择 Agent`,selectModel:`选择模型`,show:`显示密钥`,hide:`隐藏密钥`,copy:`复制密钥`,copied:`已复制`}};async function Ct(){let e=await h(m(`/api/image-generation/catalog`));if(!Array.isArray(e.payload?.providers))throw Error(`Invalid image provider catalog`);return e.payload.providers}async function wt(e){let t=await h(m(`/api/agents/${encodeURIComponent(e)}/image-generation`));if(!t.payload)throw Error(`Invalid agent image generation response`);return t.payload}function Tt(e){let t=e?.indexOf(`/`)??-1;return t>0?e.slice(0,t):void 0}function Et(e){let t=e?.indexOf(`/`)??-1;return t>0?e.slice(t+1):void 0}function Dt(){let e=(0,Z.c)(2),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(Ve,{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(Ot)}),(0,$.jsx)(Ve,{className:`h-64 rounded-xl`})]}),e[1]=n):n=e[1],n}function Ot(e,t){return(0,$.jsx)(Ve,{className:`h-24 rounded-xl`},t)}function kt(){let e=f(e=>e.language),t=St[e],n=u(e),r=!!d(e=>e.token),[i,a]=(0,Q.useState)(``),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(``),[p,_]=(0,Q.useState)(``),[v,y]=(0,Q.useState)(e===`zh`?`cn`:`intl`),[b,x]=(0,Q.useState)(``),[S,C]=(0,Q.useState)(!1),[w,T]=(0,Q.useState)(),[E,D]=(0,Q.useState)(),{data:O,isLoading:k,error:A}=g(r?`image-generation-agents`:null,he,{revalidateOnFocus:!1}),{data:j,isLoading:M,error:N,mutate:P}=g(r?m(`/api/image-generation/catalog`):null,Ct,{revalidateOnFocus:!1});(0,Q.useEffect)(()=>{!O||i||a(O.defaultId||O.agents[0]?.id||``)},[i,O]);let{data:F,isLoading:I,error:L,mutate:R}=g(r&&i?[`agent-image-generation`,i]:null,()=>wt(i),{revalidateOnFocus:!1});(0,Q.useEffect)(()=>{if(!j||!F)return;let e=Tt(F.model?.primary),t=j.find(t=>t.id===e)??j.find(e=>e.configured)??j[0];t&&(s(t.id),l(t.id===e&&Et(F.model?.primary)||t.defaultModel),_(``))},[F,j]),(0,Q.useEffect)(()=>{T(void 0),D(void 0)},[i]);let z=j?.find(e=>e.id===o),B=(0,Q.useMemo)(()=>(O?.agents??[]).map(e=>({value:e.id,label:V(e,n.agentsSettings)})),[O?.agents,n.agentsSettings]),H=(0,Q.useMemo)(()=>(z?.models??[]).map(e=>({value:e,label:e})),[z?.models]),U=F?.model?.primary,ee=!!(i&&z&&c&&(z.configured||p.trim()));if(!r)return(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.connect});if(k||M||I)return(0,$.jsx)(Dt,{});if(A||N||L||!j||!O)return(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:t.loadError});let te=e=>{s(e.id),l(e.defaultModel),_(``),x(``),T(void 0),D(void 0)},ne=async()=>{if(!(!z||!ee)){C(!0),T(void 0),D(void 0);try{let e=await h(m(`/api/agents/${encodeURIComponent(i)}/image-generation/setup`),{method:`POST`,body:JSON.stringify({providerId:z.id,modelId:c,...p.trim()?{apiKey:p.trim()}:{},...z.requiresRegion?{region:v}:{},...b.trim()?{baseUrl:b.trim()}:{}})});if(!e.payload)throw Error(`Invalid setup response`);await Promise.all([R(e.payload.agent,{revalidate:!1}),P(e.payload.providers,{revalidate:!1})]),_(``),D(e.payload.verification.supported?t.enabled:t.enabledWithoutVerify)}catch(e){T(e instanceof Error?e.message:String(e))}finally{C(!1)}}};return(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsxs)(`section`,{className:`rounded-xl border border-edge bg-surface-base p-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,$.jsx)(`div`,{className:`rounded-lg bg-accent/10 p-2 text-accent`,children:(0,$.jsx)(se,{className:`size-5`})}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`h3`,{className:`text-sm font-semibold text-fg`,children:t.title}),(0,$.jsx)(`p`,{className:`mt-1 text-sm leading-relaxed text-fg-muted`,children:t.intro})]})]}),(0,$.jsxs)(`label`,{className:`mt-4 block text-xs font-medium text-fg-muted`,children:[t.agent,(0,$.jsx)(Ce,{value:i,options:B,placeholder:t.selectAgent,allowEmpty:!1,onChange:a,triggerClassName:`mt-1.5 max-w-md`})]})]}),(0,$.jsxs)(`section`,{children:[(0,$.jsx)(`h3`,{className:`mb-2 text-xs font-semibold uppercase tracking-wide text-fg-subtle`,children:t.provider}),(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 xl:grid-cols-3`,children:j.map(e=>{let n=e.id===o,r=e.id===Tt(U);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>te(e),className:`rounded-xl border p-4 text-left transition-colors ${n?`border-accent bg-accent/5 ring-1 ring-accent/20`:`border-edge bg-surface-base hover:border-edge-strong`}`,children:[(0,$.jsxs)(`span`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`font-medium text-fg`,children:e.label}),r?(0,$.jsx)(`span`,{className:`rounded-full bg-accent/10 px-2 py-0.5 text-[11px] font-medium text-accent`,children:t.current}):null]}),(0,$.jsxs)(`span`,{className:`mt-2 flex items-center gap-1.5 text-xs ${e.configured?`text-emerald-600 dark:text-emerald-400`:`text-fg-muted`}`,children:[e.configured?(0,$.jsx)(Oe,{className:`size-3.5`}):(0,$.jsx)(Ke,{className:`size-3.5`}),e.configured?t.configured:t.needsKey]})]},e.id)})})]}),z?(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)(Ce,{value:c,options:H,placeholder:t.selectModel,allowEmpty:!1,onChange:l,triggerClassName:`mt-1.5`})]}),z.requiresRegion?(0,$.jsxs)(`label`,{className:`block text-xs font-medium text-fg-muted`,children:[t.region,(0,$.jsx)(Ce,{value:v,options:[{value:`cn`,label:t.cn},{value:`intl`,label:t.intl}],placeholder:t.region,allowEmpty:!1,onChange:e=>y(e),triggerClassName:`mt-1.5`})]}):null]}),(0,$.jsxs)(`label`,{className:`mt-4 block text-xs font-medium text-fg-muted`,children:[t.apiKey,(0,$.jsx)(Je,{value:p,onChange:_,placeholder:z.configured?t.existingKey:t.needsKey,labels:{show:t.show,hide:t.hide,copy:t.copy,copied:t.copied},className:`mt-1.5`,autoComplete:`new-password`}),(0,$.jsx)(`span`,{className:`mt-1.5 block font-normal leading-relaxed text-fg-subtle`,children:z.configured?t.existingKey:t.apiKeyHint})]}),(0,$.jsxs)(`details`,{className:`mt-4 rounded-lg border border-edge bg-surface-subtle px-3 py-2.5`,children:[(0,$.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 text-sm font-medium text-fg-muted`,children:[(0,$.jsx)(Te,{className:`size-4`}),t.advanced]}),(0,$.jsxs)(`label`,{className:`mt-3 block text-xs font-medium text-fg-muted`,children:[t.baseUrl,(0,$.jsx)(`input`,{value:b,onChange:e=>x(e.target.value),placeholder:`https://…`,className:`mt-1.5 h-10 w-full rounded-lg border border-edge bg-surface-panel px-3 text-sm text-fg outline-none focus:border-accent focus:ring-2 focus:ring-accent/20`})]})]}),w?(0,$.jsx)(`p`,{className:`mt-4 rounded-lg bg-red-500/10 px-3 py-2 text-sm text-red-600 dark:text-red-400`,children:w}):null,E?(0,$.jsx)(`p`,{className:`mt-4 rounded-lg bg-emerald-500/10 px-3 py-2 text-sm text-emerald-700 dark:text-emerald-400`,children:E}):null,(0,$.jsx)(`div`,{className:`mt-4 flex justify-end`,children:(0,$.jsxs)(W,{variant:`primary`,disabled:!ee||S,onClick:()=>void ne(),children:[S?(0,$.jsx)(X,{className:`size-4 animate-spin`}):(0,$.jsx)(Oe,{className:`size-4`}),S?t.enabling:t.enable]})})]}):null]})}var At=v;function jt(e){switch(e){case`alibaba`:return`(DASHSCOPE_API_KEY)`;case`openai`:return`(OPENAI_API_KEY)`;case`groq`:return`(GROQ_API_KEY)`;default:return``}}function Mt(e){switch(e){case`alibaba`:return`(DASHSCOPE_API_KEY)`;case`openai`:return`(OPENAI_API_KEY)`;case`minimax`:return`(MINIMAX_API_KEY)`;default:return``}}function Nt(){return l(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,U,`dark:border-edge`)}function Pt(){return l(je,v)}function Ft(e){return!e||e<=0?``:e<1024*1024?`${Math.round(e/1024)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function It(e,t){let n=window.atob(e),r=new Uint8Array(n.length);for(let e=0;e<n.length;e++)r[e]=n.charCodeAt(e);return URL.createObjectURL(new Blob([r],{type:t}))}var Lt=[{id:`paraformer-v2`,name:`Paraformer v2`},{id:`paraformer-v1`,name:`Paraformer v1`}],Rt=[{id:`whisper-1`,name:`Whisper-1`}],zt=[{id:`whisper-large-v3-turbo`,name:`Whisper Large v3 Turbo`},{id:`whisper-large-v3`,name:`Whisper Large v3`}],Bt=[{id:`tts-1`,name:`TTS-1`},{id:`tts-1-hd`,name:`TTS-1 HD`}],Vt=[{id:`alloy`,name:`Alloy`},{id:`echo`,name:`Echo`}],Ht=[{id:`qwen-tts`,name:`Qwen TTS`},{id:`qwen3-tts-flash`,name:`Qwen3 TTS Flash`}],Ut=[{id:`Cherry`,name:`Cherry`},{id:`longxiaochun`,name:`Long Xiao Chun`}],Wt=[{id:`en-US-MichelleNeural`,name:`Michelle (US English)`},{id:`zh-CN-XiaoxiaoNeural`,name:`Xiaoxiao (Chinese)`}],Gt=[{id:`speech-2.8-hd`,name:`Speech 2.8 HD (Recommended)`},{id:`speech-2.8-turbo`,name:`Speech 2.8 Turbo (Fast)`}],Kt=[{id:`male-qn-qingse`,name:`Male Qingse (青涩男声)`},{id:`female-shaonv`,name:`Female Shaonv (少女音)`}],qt=[{id:`piper`,command:`piper --model /path/to/voice.onnx --output_file "{{OutputPath}}"`,outputFormat:`wav`},{id:`sherpa-onnx`,command:`sherpa-onnx-offline-tts --text "{{Text}}" --output-filename "{{OutputPath}}"`,outputFormat:`wav`},{id:`mlx-audio`,command:`python -m mlx_audio.tts.generate --text "{{Text}}" --file_prefix "{{OutputBase}}"`,outputFormat:`wav`}];function Jt(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 Yt(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 Xt(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 Zt(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 Qt(e){return{maskedHelp:e.apiKeyMaskedHelp,copy:e.apiKeyCopy,copied:e.apiKeyCopied,show:e.apiKeyShow,hide:e.apiKeyHide,notInConfigFile:e.apiKeyNotInConfigFile,loadFailed:e.apiKeyRevealFailed}}function $t(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 en(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 tn(e,t){switch(t.type){case`reset`:return{form:null,baseline:null};case`sync`:{let e=structuredClone(t.value);return{form:e,baseline:structuredClone(e)}}case`update`:return{...e,form:t.updater(e.form)};case`discard`:return e.baseline?{form:structuredClone(e.baseline),baseline:e.baseline}:e;case`saved`:{let e=structuredClone(t.value);return{form:e,baseline:structuredClone(e)}}}}function nn(){let e=f(e=>e.language),t=u(e).voiceSettings,n=!!d(e=>e.token),[r,i]=(0,Q.useReducer)(tn,{form:null,baseline:null}),a=r.form,o=r.baseline,[s,c]=(0,Q.useState)(null),[l,p]=(0,Q.useState)(!1),[h,_]=(0,Q.useState)(null),v=(0,Q.useRef)(!1),y=(0,Q.useRef)({parsed:null,models:void 0}),{data:b,error:x,isLoading:S,mutate:C}=Ie(n),{data:w,error:T,isLoading:E,mutate:D}=g(n?m(`/api/voice/models`):null,dt,{revalidateOnFocus:!1}),{data:O,error:k,isLoading:A}=g(n?m(`/api/voice/providers`):null,st,{revalidateOnFocus:!1}),{data:j,error:M,isLoading:N}=g(n?m(`/api/voice/stt-providers`):null,ut,{revalidateOnFocus:!1}),P=(0,Q.useMemo)(()=>O?.providers??[],[O]),F=(0,Q.useMemo)(()=>j?.providers??[],[j]),I=(0,Q.useMemo)(()=>b?.payload?.config===void 0?null:at(b.payload.config),[b]),L=(0,Q.useMemo)(()=>!a||!o?!1:JSON.stringify(a)!==JSON.stringify(o),[a,o]);n?I!==null&&w!==void 0&&!v.current&&(y.current.parsed!==I||y.current.models!==w)&&(y.current={parsed:I,models:w},i({type:`sync`,value:I}),c(w)):(y.current.parsed!==null||y.current.models!==void 0)&&(y.current={parsed:null,models:void 0},i({type:`reset`}),c(null),v.current=!1);let R=!!(n&&(I===null||w===void 0||O===void 0||j===void 0)&&(S||E||A||N)),z=x instanceof Error?x.message:x?String(x):T instanceof Error?T.message:T?String(T):k instanceof Error?k.message:k?String(k):M instanceof Error?M.message:M?String(M):null,B=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>t?{...t,stt:{...t.stt,...e}}:null})},[]),V=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>t?{...t,stt:{...t.stt,alibaba:{...t.stt.alibaba,...e}}}:null})},[]),H=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>t?{...t,stt:{...t.stt,openai:{...t.stt.openai,...e}}}:null})},[]),U=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>{if(!t)return null;let n=t.stt.fallback??{enabled:!1,order:[`xopc-local`]};return{...t,stt:{...t.stt,fallback:{...n,...e}}}}})},[]),ee=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>t?{...t,voice:{...t.voice,input:{...t.voice.input,refinement:{...t.voice.input.refinement,...e}}}}:null})},[]),te=(0,Q.useCallback)(t=>{v.current=!0,i({type:`update`,updater:n=>n?{...n,voice:{...n.voice,languageMode:t,...t===`auto`?{language:e}:{}}}:null})},[e]),ne=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>t?{...t,tts:{...t.tts,...e}}:null})},[]),re=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>t?{...t,tts:{...t.tts,alibaba:{...t.tts.alibaba,...e}}}:null})},[]),ie=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>t?{...t,tts:{...t.tts,openai:{...t.tts.openai,...e}}}:null})},[]),ae=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>t?{...t,voice:e.voice!==void 0||e.lang!==void 0?{...t.voice,languageMode:`manual`}:t.voice,tts:{...t.tts,edge:{...t.tts.edge,...e}}}:null})},[]),G=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>t?{...t,tts:{...t.tts,minimax:{...t.tts.minimax,...e}}}:null})},[]),oe=(0,Q.useCallback)(e=>{v.current=!0,i({type:`update`,updater:t=>t?{...t,tts:{...t.tts,"tts-local-cli":{...t.tts[`tts-local-cli`],...e}}}:null})},[]);if(yt({id:`voice`,dirty:L,saving:l,save:(0,Q.useCallback)(async()=>{if(!(!a||l)){p(!0),_(null);try{await ct(a),i({type:`saved`,value:a}),v.current=!1}catch(e){_(e instanceof Error?e.message:t.saveError)}finally{p(!1)}}},[a,l,t.saveError]),discard:(0,Q.useCallback)(()=>{o&&(v.current=!1,i({type:`discard`}),_(null))},[o])}),!n)return(0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.needToken})});if(R)return(0,$.jsx)(it,{rows:4});if(!a||s===null)return(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:h??z??t.loadError}),(0,$.jsx)(W,{type:`button`,variant:`secondary`,onClick:()=>{C(),D()},children:t.retry})]});let se=a.stt,K=a.tts,q=a.voice.input.refinement,ce=Qt(t);return(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[h?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:h}):null,(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsx)(rn,{v:t,voice:a.voice,updateLanguageMode:te}),(0,$.jsx)(an,{v:t,stt:se,tts:K}),(0,$.jsx)(sn,{v:t,apiKeyLabels:ce,stt:se,models:s,sttProviders:F,refinement:q,updateStt:B,updateSttAlibaba:V,updateSttOpenai:H,updateSttFallback:U,updateRefinement:ee}),(0,$.jsx)(hn,{v:t,apiKeyLabels:ce,tts:K,models:s,ttsProviders:P,updateTts:ne,updateTtsAlibaba:re,updateTtsOpenai:ie,updateTtsEdge:ae,updateTtsMinimax:G,updateTtsLocalCli:oe})]}),(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 rn(e){let t=(0,Z.c)(22),{v:n,voice:r,updateLanguageMode:i}=e,a;t[0]===n.language.title?a=t[1]:(a=(0,$.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:n.language.title}),t[0]=n.language.title,t[1]=a);let o=r.languageMode===`auto`?n.language.autoDescription:n.language.manualDescription,s;t[2]===o?s=t[3]:(s=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:o}),t[2]=o,t[3]=s);let c;t[4]!==a||t[5]!==s?(c=(0,$.jsxs)(`div`,{children:[a,s]}),t[4]=a,t[5]=s,t[6]=c):c=t[6];let l;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(l=Pt(),t[7]=l):l=t[7];let u;t[8]===i?u=t[9]:(u=e=>i(e.target.value),t[8]=i,t[9]=u);let d;t[10]===n.language.auto?d=t[11]:(d=(0,$.jsx)(J,{value:`auto`,children:n.language.auto}),t[10]=n.language.auto,t[11]=d);let f;t[12]===n.language.manual?f=t[13]:(f=(0,$.jsx)(J,{value:`manual`,children:n.language.manual}),t[12]=n.language.manual,t[13]=f);let p;t[14]!==u||t[15]!==d||t[16]!==f||t[17]!==r.languageMode?(p=(0,$.jsxs)(Y,{className:l,value:r.languageMode,onChange:u,children:[d,f]}),t[14]=u,t[15]=d,t[16]=f,t[17]=r.languageMode,t[18]=p):p=t[18];let m;return t[19]!==c||t[20]!==p?(m=(0,$.jsx)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-[minmax(0,1fr)_minmax(12rem,18rem)] sm:items-center`,children:[c,p]})}),t[19]=c,t[20]=p,t[21]=m):m=t[21],m}function an(e){let t=(0,Z.c)(39),{v:n,stt:r,tts:i}=e,a=i.provider===`openai`?i.openai?.voice:i.provider===`alibaba`?i.alibaba?.voice:i.provider===`minimax`?i.minimax?.voice:i.provider===`edge`?i.edge?.voice:void 0,o;t[0]===n.overview.title?o=t[1]:(o=(0,$.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:n.overview.title}),t[0]=n.overview.title,t[1]=o);let s;t[2]===n.overview.description?s=t[3]:(s=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:n.overview.description}),t[2]=n.overview.description,t[3]=s);let c;t[4]!==o||t[5]!==s?(c=(0,$.jsxs)(`div`,{className:`mb-4`,children:[o,s]}),t[4]=o,t[5]=s,t[6]=c):c=t[6];let l;t[7]!==r.enabled||t[8]!==r.provider||t[9]!==n?(l=r.enabled?`${n.overview.ready} · ${Jt(r.provider,n)}`:n.overview.off,t[7]=r.enabled,t[8]=r.provider,t[9]=n,t[10]=l):l=t[10];let u;t[11]!==r.enabled||t[12]!==l||t[13]!==n.overview.input?(u=(0,$.jsx)(on,{label:n.overview.input,value:l,ready:r.enabled}),t[11]=r.enabled,t[12]=l,t[13]=n.overview.input,t[14]=u):u=t[14];let d;t[15]!==i.enabled||t[16]!==i.trigger||t[17]!==n?(d=i.enabled?Xt(i.trigger,n):n.overview.off,t[15]=i.enabled,t[16]=i.trigger,t[17]=n,t[18]=d):d=t[18];let f=i.enabled&&i.trigger!==`off`,p;t[19]!==d||t[20]!==f||t[21]!==n.overview.replies?(p=(0,$.jsx)(on,{label:n.overview.replies,value:d,ready:f}),t[19]=d,t[20]=f,t[21]=n.overview.replies,t[22]=p):p=t[22];let m;t[23]!==a||t[24]!==i.enabled||t[25]!==i.provider||t[26]!==n?(m=i.enabled?`${Yt(i.provider,n)}${a?` · ${a}`:``}`:n.overview.off,t[23]=a,t[24]=i.enabled,t[25]=i.provider,t[26]=n,t[27]=m):m=t[27];let h;t[28]!==m||t[29]!==i.enabled||t[30]!==n.overview.voice?(h=(0,$.jsx)(on,{label:n.overview.voice,value:m,ready:i.enabled}),t[28]=m,t[29]=i.enabled,t[30]=n.overview.voice,t[31]=h):h=t[31];let g;t[32]!==h||t[33]!==u||t[34]!==p?(g=(0,$.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-3`,children:[u,p,h]}),t[32]=h,t[33]=u,t[34]=p,t[35]=g):g=t[35];let _;return t[36]!==g||t[37]!==c?(_=(0,$.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[c,g]}),t[36]=g,t[37]=c,t[38]=_):_=t[38],_}function on(e){let t=(0,Z.c)(10),{label:n,value:r,ready:i}=e,a;t[0]===n?a=t[1]:(a=(0,$.jsx)(`div`,{className:`text-xs text-fg-muted`,children:n}),t[0]=n,t[1]=a);let o=i?`text-fg`:`text-fg-muted`,s;t[2]===o?s=t[3]:(s=l(`mt-1 text-sm font-medium`,o),t[2]=o,t[3]=s);let c;t[4]!==s||t[5]!==r?(c=(0,$.jsx)(`div`,{className:s,children:r}),t[4]=s,t[5]=r,t[6]=c):c=t[6];let u;return t[7]!==a||t[8]!==c?(u=(0,$.jsxs)(`div`,{className:`rounded-xl bg-surface-panel/80 px-3 py-2.5 shadow-surface`,children:[a,c]}),t[7]=a,t[8]=c,t[9]=u):u=t[9],u}function sn(e){let t=(0,Z.c)(49),{v:n,apiKeyLabels:r,stt:i,models:a,sttProviders:o,refinement:s,updateStt:c,updateSttAlibaba:u,updateSttOpenai:d,updateSttFallback:f,updateRefinement:p}=e,m=a?.stt?.alibaba?.length?a.stt.alibaba:Lt,h=a?.stt?.openai?.length?a.stt.openai:Rt,g;if(t[0]!==o){let e=new Set;g=[];for(let t of o)e.has(t.id)||(e.add(t.id),g.push(t));t[0]=o,t[1]=g}else g=t[1];let _=g,v,y,b,x,S;if(t[2]!==m||t[3]!==r||t[4]!==a?.stt||t[5]!==h||t[6]!==_||t[7]!==s||t[8]!==i||t[9]!==p||t[10]!==c||t[11]!==u||t[12]!==f||t[13]!==d||t[14]!==n){let e=_.find(e=>e.id===i.provider),o=i.providers?.[i.provider],g=typeof o?.apiKey==`string`?o.apiKey:``,C=typeof o?.model==`string`?o.model:``,w={...i.provider===`alibaba`?i.alibaba??{}:{},...i.provider===`openai`?i.openai??{}:{},...o??{}},T=(e?.fields??[]).filter(fn),E;t[20]!==i.provider||t[21]!==i.providers||t[22]!==c?(E=e=>{c({providers:{...i.providers??{},[i.provider]:{...i.providers?.[i.provider]??{},...e}}})},t[20]=i.provider,t[21]=i.providers,t[22]=c,t[23]=E):E=t[23];let D=E;x=`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`;let O;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,$.jsx)(ge,{className:`size-4 text-accent`,strokeWidth:1.75}),t[24]=O):O=t[24];let k;t[25]===n.stt.title?k=t[26]:(k=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[O,n.stt.title]}),t[25]=n.stt.title,t[26]=k);let A;t[27]===n.stt.description?A=t[28]:(A=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:n.stt.description}),t[27]=n.stt.description,t[28]=A),t[29]!==k||t[30]!==A?(S=(0,$.jsxs)(`div`,{className:`mb-4`,children:[k,A]}),t[29]=k,t[30]=A,t[31]=S):S=t[31],v=`space-y-4`;let j;t[32]===c?j=t[33]:(j=e=>c({enabled:e}),t[32]=c,t[33]=j),t[34]!==i.enabled||t[35]!==j||t[36]!==n.overview.off||t[37]!==n.overview.ready||t[38]!==n.stt.enable||t[39]!==n.stt.enableDesc?(y=(0,$.jsx)(gn,{checked:i.enabled,title:n.stt.enable,description:n.stt.enableDesc,onLabel:n.overview.ready,offLabel:n.overview.off,onChange:j}),t[34]=i.enabled,t[35]=j,t[36]=n.overview.off,t[37]=n.overview.ready,t[38]=n.stt.enable,t[39]=n.stt.enableDesc,t[40]=y):y=t[40],b=i.enabled?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,At),children:[(0,$.jsx)(yn,{children:n.stt.provider}),(0,$.jsx)(Y,{className:Pt(),value:i.provider,onChange:e=>c({provider:e.target.value}),children:_.map(e=>(0,$.jsxs)(J,{value:e.id,children:[Jt(e.id,n),e.configured?``:` *`]},e.id))})]}),(0,$.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,At),children:[(0,$.jsx)(yn,{children:n.stt.model}),i.provider===`xopc-local`?(0,$.jsx)(Y,{className:Pt(),value:C||`sensevoice-small`,onChange:e=>D({model:e.target.value}),children:(a?.stt?.[`xopc-local`]??[]).map(dn)}):i.provider===`alibaba`?(0,$.jsx)(Y,{className:Pt(),value:i.alibaba?.model??``,onChange:e=>u({model:e.target.value}),children:m.map(un)}):i.provider===`openai`?(0,$.jsx)(Y,{className:Pt(),value:i.openai?.model??``,onChange:e=>d({model:e.target.value}),children:h.map(ln)}):i.provider===`groq`?(0,$.jsx)(Y,{className:Pt(),value:C||zt[0].id,onChange:e=>D({model:e.target.value}),children:zt.map(cn)}):(0,$.jsx)(`input`,{className:Nt(),value:C,onChange:e=>D({model:e.target.value}),placeholder:i.provider})]}),e?.diagnostics.requiresApiKey===!1?null:(0,$.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,At),children:[(0,$.jsx)(yn,{children:n.stt.apiKey}),(0,$.jsx)(pt,{kind:`stt`,providerId:i.provider,fieldId:`voice-stt-${i.provider}-api-key`,value:i.provider===`alibaba`?i.alibaba?.apiKey??``:i.provider===`openai`?i.openai?.apiKey??``:g,onChange:e=>{i.provider===`alibaba`?u({apiKey:e}):i.provider===`openai`?d({apiKey:e}):D({apiKey:e})},labels:r,placeholder:i.provider===`groq`?`gsk_...`:`sk-...`}),(0,$.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.stt.apiKeyDesc,jt(i.provider)?` ${jt(i.provider)}`:``]})]})]}),T.length>0?(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:T.map(e=>(0,$.jsx)(_n,{field:e,value:$t(w,e),onChange:t=>D({[e.key]:t}),className:e.type===`textarea`?`sm:col-span-2`:At},e.key))}):null,i.provider===`xopc-local`?(0,$.jsx)(mn,{v:n}):null,(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.stt.fallback}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.stt.fallbackDesc})]}),(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:i.fallback?.enabled??!1,onChange:e=>f({enabled:e.target.checked})})]}),(0,$.jsxs)(`div`,{className:`grid gap-3 rounded-xl bg-surface-hover/50 p-3 dark:bg-surface-hover/35 sm:grid-cols-[minmax(0,1fr)_minmax(12rem,18rem)] sm:items-center`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.stt.refinement}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.stt.refinementDesc})]}),(0,$.jsxs)(Y,{className:Pt(),value:s.mode,onChange:e=>p({mode:e.target.value}),children:[(0,$.jsx)(J,{value:`off`,children:n.stt.refinementOff}),(0,$.jsx)(J,{value:`punctuation`,children:n.stt.refinementPunctuation}),(0,$.jsx)(J,{value:`light`,children:n.stt.refinementLight})]})]})]}):null,t[2]=m,t[3]=r,t[4]=a?.stt,t[5]=h,t[6]=_,t[7]=s,t[8]=i,t[9]=p,t[10]=c,t[11]=u,t[12]=f,t[13]=d,t[14]=n,t[15]=v,t[16]=y,t[17]=b,t[18]=x,t[19]=S}else v=t[15],y=t[16],b=t[17],x=t[18],S=t[19];let C;t[41]!==v||t[42]!==y||t[43]!==b?(C=(0,$.jsxs)(`div`,{className:v,children:[y,b]}),t[41]=v,t[42]=y,t[43]=b,t[44]=C):C=t[44];let w;return t[45]!==x||t[46]!==S||t[47]!==C?(w=(0,$.jsxs)(`section`,{className:x,children:[S,C]}),t[45]=x,t[46]=S,t[47]=C,t[48]=w):w=t[48],w}function cn(e){return(0,$.jsx)(J,{value:e.id,children:e.name},e.id)}function ln(e){return(0,$.jsx)(J,{value:e.id,children:e.name},e.id)}function un(e){return(0,$.jsx)(J,{value:e.id,children:e.name},e.id)}function dn(e){return(0,$.jsx)(J,{value:e.id,children:e.name},e.id)}function fn(e){return e.key!==`apiKey`&&e.key!==`model`}function pn(e){return`${Math.round(e/1024/1024)} MB`}function mn({v:e}){let{data:t,error:n,mutate:r}=g(m(`/api/voice/local/status`),lt,{revalidateOnFocus:!1,refreshInterval:e=>e?.models.some(e=>e.state===`downloading`)?1e3:0}),[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(null),c=(0,Q.useCallback)(async(e,t)=>{a(e.id),s(null);try{t===`install`?await ft(e.id):await mt(e.id),await r()}catch(e){s(e instanceof Error?e.message:String(e))}finally{a(null)}},[r]);return(0,$.jsxs)(`div`,{className:`rounded-xl border border-edge bg-surface-panel/60 p-3`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.stt.localModels}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:e.stt.localModelsDesc}),n?(0,$.jsx)(`p`,{className:`mt-3 text-xs text-red-600 dark:text-red-400`,children:String(n)}):null,o?(0,$.jsx)(`p`,{className:`mt-3 text-xs text-red-600 dark:text-red-400`,children:o}):null,(0,$.jsx)(`div`,{className:`mt-3 grid gap-2`,children:(t?.models??[]).map(t=>{let n=i===t.id||t.state===`downloading`;return(0,$.jsxs)(`div`,{className:l(`flex items-center justify-between gap-3 rounded-lg bg-surface-base px-3 py-2.5`,t.recommended?`ring-1 ring-accent/40`:``),children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-sm font-medium text-fg`,children:[t.name,t.recommended?(0,$.jsx)(`span`,{className:`rounded-full bg-accent/10 px-2 py-0.5 text-[10px] font-medium text-accent`,children:e.stt.localRecommended}):null]}),(0,$.jsxs)(`div`,{className:`text-xs text-fg-muted`,children:[pn(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)(W,{type:`button`,variant:`secondary`,disabled:n,onClick:()=>void c(t,t.state===`ready`?`remove`:`install`),children:n?(0,$.jsx)(X,{className:`size-4 animate-spin`}):t.state===`ready`?e.stt.localRemove:e.stt.localInstall})]},t.id)})})]})}function hn({v:e,apiKeyLabels:t,tts:n,models:r,ttsProviders:i,updateTts:a,updateTtsAlibaba:o,updateTtsOpenai:s,updateTtsEdge:c,updateTtsMinimax:u,updateTtsLocalCli:d}){let f=r?.tts?.openai?.length?r.tts.openai:Bt,p=r?.ttsVoices?.openai?.length?r.ttsVoices.openai:Vt,m=r?.tts?.alibaba?.length?r.tts.alibaba:Ht,h=r?.ttsVoices?.alibaba?.length?r.ttsVoices.alibaba:Ut,g=r?.ttsVoices?.edge?.length?r.ttsVoices.edge:Wt,_=r?.tts?.minimax?.length?r.tts.minimax:Gt,v=r?.ttsVoices?.minimax?.length?r.ttsVoices.minimax:Kt,[y,x]=(0,Q.useState)(e.tts.test.sampleText),[S,C]=(0,Q.useState)({status:`idle`}),w=(0,Q.useRef)(null),T=(0,Q.useRef)(null),E=(0,Q.useCallback)(()=>{w.current?.pause(),w.current=null,T.current&&=(URL.revokeObjectURL(T.current),null)},[]),D=(0,Q.useMemo)(()=>{let e=new Set,t=[];for(let n of i)e.has(n.id)||(e.add(n.id),t.push(n));return t},[i]),k=D.find(e=>e.id===n.provider),A=n.providers?.[n.provider],j={...n.provider===`openai`?n.openai??{}:{},...n.provider===`alibaba`?n.alibaba??{}:{},...n.provider===`edge`?n.edge??{}:{},...n.provider===`minimax`?n.minimax??{}:{},...n.provider===`tts-local-cli`?n[`tts-local-cli`]??{}:{},...A??{}},M=(k?.fields??[]).filter(e=>![`apiKey`,`model`,`voice`].includes(e.key)),N=!!k?.diagnostics.requiresApiKey,P=!!k?.configured||!N,F=n.enabled?P?`ready`:`action`:`muted`,I=n.provider===`openai`?n.openai?.model:n.provider===`alibaba`?n.alibaba?.model:n.provider===`minimax`?n.minimax?.model:void 0,L=n.provider===`openai`?n.openai?.voice:n.provider===`alibaba`?n.alibaba?.voice:n.provider===`minimax`?n.minimax?.voice:n.provider===`edge`?n.edge?.voice:void 0;(0,Q.useEffect)(()=>()=>E(),[E]);let R=(0,Q.useCallback)(e=>{a({provider:e}),C({status:`idle`})},[a]),z=(0,Q.useCallback)(async()=>{let t=y.trim();if(!t){C({status:`error`,message:e.tts.test.emptyText});return}E(),C({status:`loading`});try{let r=await ot({text:t,provider:n.provider,providerConfig:j,...I?{model:I}:{},...L?{voice:L}:{}}),i=It(r.audio,r.mimeType);T.current=i;let a=new Audio(i);w.current=a;let o=[r.provider,r.format,r.latencyMs===void 0?void 0:`${r.latencyMs}ms`,Ft(r.audioSize)].filter(Boolean).join(` · `);a.addEventListener(`ended`,()=>C({status:`done`,summary:o}),{once:!0}),a.addEventListener(`error`,()=>C({status:`error`,message:e.tts.test.playFailed}),{once:!0}),await a.play(),C({status:`playing`,summary:o})}catch(e){E(),C({status:`error`,message:e instanceof Error?e.message:String(e)})}},[I,L,j,E,y,n.provider,e.tts.test.emptyText,e.tts.test.playFailed]),B=(0,Q.useCallback)(e=>{a({providers:{...n.providers??{},[n.provider]:{...n.providers?.[n.provider]??{},...e}}})},[n.provider,n.providers,a]),V=(0,Q.useCallback)((e,t)=>{let r={[e.key]:t};B(r),n.provider===`openai`&&e.key===`baseUrl`?s(r):n.provider===`minimax`&&(e.key===`baseUrl`||e.key===`groupId`)?u(r):n.provider===`edge`&&e.key===`lang`&&c(r)},[n.provider,B,c,u,s]);return(0,$.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[(0,$.jsxs)(`div`,{className:`mb-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,$.jsx)(b,{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)(gn,{checked:n.enabled,title:e.tts.enable,description:e.tts.enableDesc,onLabel:e.overview.ready,offLabel:e.overview.off,onChange:e=>a({enabled:e})}),(0,$.jsxs)(`div`,{className:l(`rounded-xl border px-3 py-2.5 text-sm`,F===`ready`?`border-emerald-500/25 bg-emerald-500/10 text-emerald-800 dark:text-emerald-100`:F===`action`?`border-amber-300/50 bg-amber-50 text-amber-900 dark:border-amber-300/30 dark:bg-amber-400/10 dark:text-amber-100`:`border-edge bg-surface-panel text-fg-muted`),children:[(0,$.jsx)(`div`,{className:`font-medium text-fg`,children:e.tts.statusTitle}),(0,$.jsx)(`p`,{className:`mt-1 text-xs`,children:n.enabled?P?`${e.tts.statusReady} ${Yt(n.provider,e)}${L?` · ${L}`:``}`:`${e.tts.statusNeedsSetup} ${Yt(n.provider,e)} · ${k?.diagnostics.envKeys?.join(`, `)??e.stt.apiKey}`:e.tts.statusOff})]}),n.enabled?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,At),children:[(0,$.jsx)(yn,{children:e.tts.trigger}),(0,$.jsxs)(Y,{className:Pt(),value:n.trigger,onChange:e=>a({trigger:e.target.value}),children:[(0,$.jsx)(J,{value:`off`,children:e.tts.triggerOff}),(0,$.jsx)(J,{value:`inbound`,children:e.tts.triggerInbound}),(0,$.jsx)(J,{value:`tagged`,children:e.tts.triggerTagged}),(0,$.jsx)(J,{value:`always`,children:e.tts.triggerAlways})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.triggerHelp})]}),(0,$.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,At),children:[(0,$.jsx)(yn,{children:e.tts.provider}),(0,$.jsx)(Y,{className:Pt(),value:n.provider,onChange:e=>R(e.target.value),children:D.map(t=>(0,$.jsx)(J,{value:t.id,children:Yt(t.id,e)},t.id))}),(0,$.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[k?.configured?e.tts.configured:k?.diagnostics.requiresApiKey?`${e.tts.needsKey} · ${k.diagnostics.envKeys?.join(`, `)??e.stt.apiKey}`:e.tts.noKeyNeeded,` · `,k?.description??Zt(n.provider,e)]})]})]}),(0,$.jsxs)(`details`,{className:`rounded-xl bg-surface-panel/80 p-3 shadow-surface`,open:!P||n.provider===`tts-local-cli`,children:[(0,$.jsxs)(`summary`,{className:`cursor-pointer text-sm font-medium text-fg marker:text-fg-muted`,children:[e.tts.advanced.title,(0,$.jsx)(`span`,{className:`ml-2 text-xs font-normal text-fg-muted`,children:e.tts.advanced.description})]}),(0,$.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[n.provider===`openai`||n.provider===`alibaba`||n.provider===`minimax`?(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,At),children:[(0,$.jsx)(yn,{children:e.stt.apiKey}),(0,$.jsx)(pt,{kind:`tts`,providerId:n.provider,fieldId:`voice-tts-${n.provider}-api-key`,value:n.provider===`openai`?n.openai?.apiKey??``:n.provider===`alibaba`?n.alibaba?.apiKey??``:n.minimax?.apiKey??``,onChange:e=>{n.provider===`openai`?s({apiKey:e}):n.provider===`alibaba`?o({apiKey:e}):u({apiKey:e})},labels:t,placeholder:n.provider===`minimax`?`eyJ...`:`sk-...`}),(0,$.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,Mt(n.provider)?` ${Mt(n.provider)}`:``]})]}),(0,$.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,At),children:[(0,$.jsx)(yn,{children:e.stt.model}),(0,$.jsx)(Y,{className:Pt(),value:n.provider===`openai`?n.openai?.model??``:n.provider===`alibaba`?n.alibaba?.model??``:n.minimax?.model??``,onChange:e=>{n.provider===`openai`?s({model:e.target.value}):n.provider===`alibaba`?o({model:e.target.value}):u({model:e.target.value})},children:(n.provider===`openai`?f:n.provider===`alibaba`?m:_).map(e=>(0,$.jsx)(J,{value:e.id,children:e.name},e.id))})]}),(0,$.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,At),children:[(0,$.jsx)(yn,{children:e.tts.voice}),(0,$.jsx)(Y,{className:Pt(),value:n.provider===`openai`?n.openai?.voice??``:n.provider===`alibaba`?n.alibaba?.voice??``:n.minimax?.voice??``,onChange:e=>{n.provider===`openai`?s({voice:e.target.value}):n.provider===`alibaba`?o({voice:e.target.value}):u({voice:e.target.value})},children:(n.provider===`openai`?p:n.provider===`alibaba`?h:v).map(e=>(0,$.jsx)(J,{value:e.id,children:e.name},e.id))})]})]}):null,n.provider===`edge`?(0,$.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,At),children:[(0,$.jsx)(yn,{children:e.tts.voice}),(0,$.jsx)(Y,{className:Pt(),value:n.edge?.voice??``,onChange:e=>c({voice:e.target.value}),children:g.map(e=>(0,$.jsx)(J,{value:e.id,children:e.name},e.id))}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.edgeHint})]}):null,n.provider===`tts-local-cli`?(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,$.jsx)(yn,{children:e.tts.localCli.preset}),(0,$.jsxs)(Y,{className:Pt(),value:``,onChange:e=>{let t=qt.find(t=>t.id===e.target.value);t&&d({command:t.command,outputFormat:t.outputFormat})},children:[(0,$.jsx)(J,{value:``,children:e.tts.localCli.presetPlaceholder}),qt.map(e=>(0,$.jsx)(J,{value:e.id,children:e.id},e.id))]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.presetDesc})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,$.jsx)(yn,{children:e.tts.localCli.command}),(0,$.jsx)(`input`,{className:l(Nt(),`font-mono text-xs`),type:`text`,autoComplete:`off`,spellCheck:!1,value:n[`tts-local-cli`]?.command??``,onChange:e=>d({command:e.target.value}),placeholder:e.tts.localCli.commandPlaceholder}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.commandDesc})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(yn,{children:e.tts.localCli.cwd}),(0,$.jsx)(`input`,{className:l(Nt(),`font-mono text-xs`),type:`text`,autoComplete:`off`,spellCheck:!1,value:n[`tts-local-cli`]?.cwd??``,onChange:e=>d({cwd:e.target.value}),placeholder:`/path/to/cwd`}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.cwdDesc})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(yn,{children:e.tts.localCli.outputFormat}),(0,$.jsxs)(Y,{className:Pt(),value:n[`tts-local-cli`]?.outputFormat??`wav`,onChange:e=>d({outputFormat:e.target.value}),children:[(0,$.jsx)(J,{value:`wav`,children:`wav`}),(0,$.jsx)(J,{value:`mp3`,children:`mp3`}),(0,$.jsx)(J,{value:`opus`,children:`opus`})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.outputFormatDesc})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,$.jsx)(yn,{children:e.tts.localCli.timeoutMs}),(0,$.jsx)(`input`,{className:Nt(),type:`number`,min:0,step:1e3,value:typeof n[`tts-local-cli`]?.timeoutMs==`number`?String(n[`tts-local-cli`].timeoutMs):``,onChange:e=>{let t=e.target.value.trim();if(t===``){d({timeoutMs:void 0});return}let n=Number(t);Number.isFinite(n)&&n>=0&&d({timeoutMs:n})},placeholder:`30000`}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.timeoutMsDesc})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle sm:col-span-2`,children:e.tts.localCli.hint})]}):null,M.length>0?(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:M.map(e=>(0,$.jsx)(_n,{field:e,value:$t(j,e),onChange:t=>V(e,t),className:e.type===`textarea`?`sm:col-span-2`:At},e.key))}):null]})]}),(0,$.jsxs)(`div`,{className:`rounded-xl bg-surface-panel/80 p-3 shadow-surface`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.tts.test.title}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:e.tts.test.description})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[(0,$.jsxs)(W,{type:`button`,variant:`primary`,onClick:()=>void z(),disabled:S.status===`loading`,className:`h-9`,children:[S.status===`loading`?(0,$.jsx)(X,{className:`size-4 animate-spin`}):(0,$.jsx)(O,{className:`size-4`}),S.status===`loading`?e.tts.test.generating:e.tts.test.play]}),(0,$.jsxs)(W,{type:`button`,variant:`secondary`,onClick:()=>{E(),C(e=>e.status===`playing`?{status:`done`,summary:e.summary}:{status:`idle`})},disabled:S.status!==`playing`,className:`h-9`,children:[(0,$.jsx)(Le,{className:`size-4`}),e.tts.test.stop]})]})]}),(0,$.jsx)(`textarea`,{className:l(Nt(),`mt-3 min-h-20 resize-y`),value:y,onChange:e=>x(e.target.value),maxLength:1e3}),(0,$.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center justify-between gap-2 text-xs`,children:[(0,$.jsxs)(`span`,{className:`text-fg-subtle`,children:[y.length,`/1000`]}),S.status===`playing`||S.status===`done`?(0,$.jsxs)(`span`,{className:`text-emerald-700 dark:text-emerald-200`,children:[S.status===`playing`?e.tts.test.playing:e.tts.test.ready,` · `,S.summary]}):null,S.status===`error`?(0,$.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:S.message}):null]})]})]}):null]})]})}function gn(e){let t=(0,Z.c)(33),{checked:n,title:r,description:i,onLabel:a,offLabel:o,onChange:s}=e,c;t[0]!==n||t[1]!==s?(c=()=>s(!n),t[0]=n,t[1]=s,t[2]=c):c=t[2];let u=n?`bg-accent/10 text-fg ring-1 ring-accent/45 dark:bg-accent/15`:`bg-surface-panel/80 text-fg hover:bg-surface-hover`,d;t[3]===u?d=t[4]:(d=l(`group flex w-full items-center justify-between gap-4 rounded-2xl px-4 py-3 text-left shadow-surface transition-colors`,U,u),t[3]=u,t[4]=d);let f=n?`bg-accent text-white`:`bg-surface-hover text-fg-muted`,p;t[5]===f?p=t[6]:(p=l(`rounded-full px-2 py-0.5 text-[11px] font-medium`,f),t[5]=f,t[6]=p);let m=n?a:o,h;t[7]!==p||t[8]!==m?(h=(0,$.jsx)(`span`,{className:p,children:m}),t[7]=p,t[8]=m,t[9]=h):h=t[9];let g;t[10]!==h||t[11]!==r?(g=(0,$.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-sm font-semibold text-fg`,children:[r,h]}),t[10]=h,t[11]=r,t[12]=g):g=t[12];let _;t[13]===i?_=t[14]:(_=(0,$.jsx)(`span`,{className:`mt-1 block text-xs leading-relaxed text-fg-muted`,children:i}),t[13]=i,t[14]=_);let v;t[15]!==g||t[16]!==_?(v=(0,$.jsxs)(`span`,{className:`min-w-0`,children:[g,_]}),t[15]=g,t[16]=_,t[17]=v):v=t[17];let y=n?`border-accent bg-accent`:`border-edge bg-surface-hover group-hover:border-accent/40`,b;t[18]===y?b=t[19]:(b=l(`relative inline-flex h-6 w-11 shrink-0 items-center rounded-full border transition-colors`,y),t[18]=y,t[19]=b);let x=n?`translate-x-5`:`translate-x-0.5`,S;t[20]===x?S=t[21]:(S=l(`size-5 rounded-full bg-white shadow-surface transition-transform`,x),t[20]=x,t[21]=S);let C;t[22]===S?C=t[23]:(C=(0,$.jsx)(`span`,{className:S}),t[22]=S,t[23]=C);let w;t[24]!==b||t[25]!==C?(w=(0,$.jsx)(`span`,{className:b,"aria-hidden":!0,children:C}),t[24]=b,t[25]=C,t[26]=w):w=t[26];let T;return t[27]!==n||t[28]!==c||t[29]!==v||t[30]!==w||t[31]!==d?(T=(0,$.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":n,onClick:c,className:d,children:[v,w]}),t[27]=n,t[28]=c,t[29]=v,t[30]=w,t[31]=d,t[32]=T):T=t[32],T}function _n(e){let t=(0,Z.c)(36),{field:n,value:r,onChange:i,className:a}=e,o=`voice-schema-field-${n.key}`,s=n.description;if(n.type===`boolean`){let e;t[0]===a?e=t[1]:(e=l(`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,a),t[0]=a,t[1]=e);let o;t[2]===n.label?o=t[3]:(o=(0,$.jsx)(`span`,{className:`block text-sm font-medium text-fg`,children:n.label}),t[2]=n.label,t[3]=o);let c;t[4]===s?c=t[5]:(c=s?(0,$.jsx)(`span`,{className:`mt-1 block text-xs text-fg-subtle`,children:s}):null,t[4]=s,t[5]=c);let u;t[6]!==o||t[7]!==c?(u=(0,$.jsxs)(`span`,{children:[o,c]}),t[6]=o,t[7]=c,t[8]=u):u=t[8];let d=!!r,f;t[9]!==n||t[10]!==i?(f=e=>i(en(n,e.target.checked)),t[9]=n,t[10]=i,t[11]=f):f=t[11];let p;t[12]!==d||t[13]!==f?(p=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:d,onChange:f}),t[12]=d,t[13]=f,t[14]=p):p=t[14];let m;return t[15]!==e||t[16]!==u||t[17]!==p?(m=(0,$.jsxs)(`label`,{className:e,children:[u,p]}),t[15]=e,t[16]=u,t[17]=p,t[18]=m):m=t[18],m}let c=typeof r==`boolean`?``:String(r),u;t[19]===a?u=t[20]:(u=l(`flex flex-col gap-1.5`,a),t[19]=a,t[20]=u);let d;t[21]===n.label?d=t[22]:(d=(0,$.jsx)(yn,{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)(Y,{id:o,className:Pt(),value:c,required:n.required,onChange:e=>i(en(n,e.target.value)),children:(n.options??[]).map(vn)}):n.type===`textarea`?(0,$.jsx)(`textarea`,{id:o,className:l(Nt(),`min-h-24 resize-y`),value:c,required:n.required,placeholder:n.placeholder,onChange:e=>i(en(n,e.target.value))}):n.type===`password`?(0,$.jsx)(Je,{id:o,className:a,value:c,onChange:e=>i(en(n,e)),placeholder:n.placeholder,labels:Xe}):(0,$.jsx)(`input`,{id:o,className:Nt(),type:n.type===`number`?`number`:`text`,autoComplete:n.secret?`new-password`:`off`,spellCheck:!1,value:c,required:n.required,placeholder:n.placeholder,onChange:e=>i(en(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 vn(e){return(0,$.jsx)(J,{value:e.id,children:e.name},e.id)}function yn(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 bn(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 xn(e){let t=e.regionMode===`auto`?`auto`:e.regionMode===`cn`?`cn`:`global`,n={maxResults:e.maxResults,providers:e.providers.map(e=>{let t={type:e.type,apiKey:e.apiKey};return e.type===`searxng`&&e.url.trim()&&(t.url=e.url.trim().replace(/\/+$/,``)),e.disabled&&(t.disabled=!0),t})};await h(m(`/api/config`),{method:`PATCH`,body:JSON.stringify({tools:{web:{region:t,search:n,blocklist:{enabled:e.blocklistEnabled,domains:e.blocklistDomains}}}})}),Ue()}async function Sn(e){let t=await h(m(`/api/tools/web/reveal-search-api-key`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({index:e})});if(!t.ok||!t.payload)throw Error(t.error?.message??`Reveal failed`);return t.payload}function Cn(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 wn(){return l(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,U,`dark:border-edge`)}function Tn(){return l(je,v)}var En=[`brave`,`tavily`,`bing`,`searxng`];function Dn(){return{type:`brave`,apiKey:``,url:``,disabled:!1}}var On=Me();function kn(){let e=u(f(e=>e.language)),t=e.webSearchSettings,n=e.logs,r=!!d(e=>e.token),[i,a]=(0,Q.useReducer)(On,{form:null,baseline:null}),o=i.form,s=i.baseline,[c,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(null),g=(0,Q.useRef)(!1),_=(0,Q.useRef)(null),{data:v,error:y,isLoading:b,mutate:x}=Ie(r);ee({enabled:r,parsed:(0,Q.useMemo)(()=>v?.payload?.config===void 0?null:bn(v.payload.config),[v]),dirty:g.current,trackedParsedRef:_,dispatch:a,onResetDirty:()=>{g.current=!1}});let S=!!(r&&b&&v===void 0&&!y),C=y instanceof Error?y.message:y?String(y):null,w=(0,Q.useMemo)(()=>!o||!s?!1:JSON.stringify(o)!==JSON.stringify(s),[o,s]),T=(0,Q.useCallback)(e=>{g.current=!0,a({type:`patch`,patch:e})},[]);return yt({id:`search`,dirty:w,saving:c,save:(0,Q.useCallback)(async()=>{if(!(!o||c)){p(!0),h(null);try{await xn(o),g.current=!1,a({type:`saved`,value:o})}catch(e){h(e instanceof Error?e.message:t.saveError)}finally{p(!1)}}},[o,c,t.saveError]),discard:(0,Q.useCallback)(()=>{s&&(g.current=!1,a({type:`discard`}),h(null))},[s])}),r?S?(0,$.jsx)(it,{rows:3}):o?(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[m?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:m}):null,(0,$.jsxs)(_t,{children:[(0,$.jsx)(gt,{icon:Ze,title:t.sectionRegion,subtitle:t.sectionRegionHint}),(0,$.jsx)(`div`,{className:`flex max-w-md flex-col gap-4`,children:(0,$.jsx)(Cn,{label:t.regionLabel,description:t.regionDesc,children:(0,$.jsxs)(Y,{className:Tn(),value:o.regionMode,onChange:e=>T({regionMode:e.target.value}),children:[(0,$.jsx)(J,{value:`auto`,children:t.regionAuto}),(0,$.jsx)(J,{value:`cn`,children:t.regionCn}),(0,$.jsx)(J,{value:`global`,children:t.regionGlobal})]})})})]}),(0,$.jsx)(ht,{children:(0,$.jsxs)(_t,{children:[(0,$.jsx)(gt,{icon:Ne,title:t.sectionBlocklist,subtitle:t.sectionBlocklistHint}),(0,$.jsxs)(`div`,{className:`flex max-w-xl flex-col gap-4`,children:[(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:o.blocklistEnabled,onChange:e=>T({blocklistEnabled:e.target.checked})}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`font-medium`,children:t.blocklistEnabled}),(0,$.jsx)(`span`,{className:`mt-0.5 block text-xs text-fg-subtle`,children:t.blocklistEnabledDesc})]})]}),(0,$.jsx)(Cn,{label:t.blocklistDomains,description:t.blocklistDomainsDesc,children:(0,$.jsx)(`textarea`,{className:l(wn(),`min-h-[6rem] font-mono text-xs`),value:o.blocklistDomains.join(`
2
2
  `),placeholder:t.blocklistDomainsPlaceholder,disabled:!o.blocklistEnabled,onChange:e=>{T({blocklistDomains:e.target.value.split(/\r?\n/).flatMap(e=>{let t=e.trim().toLowerCase();return t?[t]:[]})})}})})]})]})}),(0,$.jsxs)(_t,{children:[(0,$.jsx)(gt,{icon:Ze,title:t.sectionSearch,subtitle:t.sectionSearchHint}),(0,$.jsxs)(`div`,{className:`flex max-w-xl flex-col gap-6`,children:[(0,$.jsx)(Cn,{label:t.maxResultsLabel,description:t.maxResultsDesc,children:(0,$.jsx)(`input`,{type:`number`,min:1,max:50,className:wn(),value:o.maxResults,onChange:e=>T({maxResults:Math.max(1,Math.min(50,Number(e.target.value)||5))})})}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.providersTitle}),o.providers.map((n,r)=>(0,$.jsx)(An,{row:n,providerIndex:r,labels:t,secretLabels:q(e.providersSettings),onChange:e=>{let t=[...o.providers];t[r]=e,T({providers:t})},onRemove:()=>{T({providers:o.providers.filter((e,t)=>t!==r)})}},`${n.type}:${n.url}:${n.apiKey}:${n.disabled}`)),(0,$.jsxs)(W,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5 text-sm`,onClick:()=>T({providers:[...o.providers,Dn()]}),children:[(0,$.jsx)(te,{className:`size-4`}),t.addProvider]})]})]})]}),(0,$.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:t.footerHint})]}):(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:m??C??t.loadError}),(0,$.jsx)(W,{type:`button`,variant:`secondary`,onClick:()=>void x(),children:n.refresh})]}):(0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.needToken})})}function An(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=()=>Sn(r).then(jn),t[0]=r,t[1]=c);let u=c,d;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(d=l(Tn(),`min-w-[8rem]`),t[2]=d):d=t[2];let f=n.type,p;t[3]!==o||t[4]!==n?(p=e=>o({...n,type:e.target.value,url:e.target.value===`searxng`?n.url:``}),t[3]=o,t[4]=n,t[5]=p):p=t[5];let m;t[6]===i.providerTypes?m=t[7]:(m=En.map(e=>(0,$.jsx)(J,{value:e,children:i.providerTypes[e]},e)),t[6]=i.providerTypes,t[7]=m);let h;t[8]!==n.type||t[9]!==p||t[10]!==m?(h=(0,$.jsx)(Y,{className:d,value:f,onChange:p,children:m}),t[8]=n.type,t[9]=p,t[10]=m,t[11]=h):h=t[11];let g;t[12]!==o||t[13]!==n?(g=e=>o({...n,disabled:e.target.checked}),t[12]=o,t[13]=n,t[14]=g):g=t[14];let _;t[15]!==n.disabled||t[16]!==g?(_=(0,$.jsx)(`input`,{type:`checkbox`,className:`size-3.5 rounded border-edge`,checked:n.disabled,onChange:g}),t[15]=n.disabled,t[16]=g,t[17]=_):_=t[17];let v;t[18]!==i.disabled||t[19]!==_?(v=(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1.5 text-xs text-fg-muted`,children:[_,i.disabled]}),t[18]=i.disabled,t[19]=_,t[20]=v):v=t[20];let y;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,$.jsx)(be,{className:`size-4`}),t[21]=y):y=t[21];let b;t[22]===s?b=t[23]:(b=(0,$.jsx)(W,{type:`button`,variant:`ghost`,className:`h-8 px-2 text-fg-muted`,onClick:s,children:y}),t[22]=s,t[23]=b);let x;t[24]!==b||t[25]!==v?(x=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[v,b]}),t[24]=b,t[25]=v,t[26]=x):x=t[26];let S;t[27]!==x||t[28]!==h?(S=(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[h,x]}),t[27]=x,t[28]=h,t[29]=S):S=t[29];let C;t[30]!==i.urlDesc||t[31]!==i.urlLabel||t[32]!==o||t[33]!==n?(C=n.type===`searxng`?(0,$.jsx)(Cn,{label:i.urlLabel,description:i.urlDesc,children:(0,$.jsx)(`input`,{type:`url`,className:wn(),value:n.url,placeholder:`http://localhost:8080`,onChange:e=>o({...n,url:e.target.value})})}):null,t[30]=i.urlDesc,t[31]=i.urlLabel,t[32]=o,t[33]=n,t[34]=C):C=t[34];let w;t[35]!==o||t[36]!==n?(w=e=>o({...n,apiKey:e}),t[35]=o,t[36]=n,t[37]=w):w=t[37];let T;t[38]!==i.keyPlaceholder||t[39]!==i.keyPlaceholderMasked||t[40]!==i.saveError||t[41]!==u||t[42]!==n.apiKey||t[43]!==a||t[44]!==w?(T=(0,$.jsx)(Je,{value:n.apiKey,onChange:w,placeholder:i.keyPlaceholder,labels:a,reveal:u,loadFailedLabel:i.saveError,notInConfigFile:i.keyPlaceholderMasked}),t[38]=i.keyPlaceholder,t[39]=i.keyPlaceholderMasked,t[40]=i.saveError,t[41]=u,t[42]=n.apiKey,t[43]=a,t[44]=w,t[45]=T):T=t[45];let E;t[46]!==i.apiKeyDesc||t[47]!==i.apiKeyLabel||t[48]!==T?(E=(0,$.jsx)(Cn,{label:i.apiKeyLabel,description:i.apiKeyDesc,children:T}),t[46]=i.apiKeyDesc,t[47]=i.apiKeyLabel,t[48]=T,t[49]=E):E=t[49];let D;return t[50]!==S||t[51]!==C||t[52]!==E?(D=(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-xl bg-surface-panel/70 p-4 shadow-surface`,children:[S,C,E]}),t[50]=S,t[51]=C,t[52]=E,t[53]=D):D=t[53],D}function jn(e){return e.apiKey??null}var Mn=[`common`,`domestic`,`specialty`,`enterprise`,`oauth`,`extension`];function Nn(e){let t=new Map;for(let e of Mn)t.set(e,[]);for(let n of e){let e=n.category||`specialty`,r=t.get(e)??[];r.push(n),t.set(e,r)}return t}function Pn(e){let t=(0,Z.c)(22),{open:n,onOpenChange:r,builtinRows:i,customConfig:a,labels:o,language:s,onSaved:c}=e,u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u={type:`pick`},t[0]=u):u=t[0];let[d,f]=(0,Q.useState)(u),[p,m]=(0,Q.useState)(``),h;t[1]===r?h=t[2]:(h=e=>{e||window.setTimeout(()=>{f({type:`pick`}),m(``)},200),r(e)},t[1]=r,t[2]=h);let g=h,v;t[3]!==g||t[4]!==c?(v=()=>{c(),g(!1)},t[3]=g,t[4]=c,t[5]=v):v=t[5];let y=v,b;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,$.jsx)(Be,{className:l(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,Fe)}),t[6]=b):b=t[6];let x;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(x=l(`fixed left-1/2 top-1/2 flex max-h-[85vh] w-full max-w-lg -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-2xl border border-edge-subtle bg-surface-base shadow-xl`,Re),t[7]=x):x=t[7];let S;t[8]!==i||t[9]!==a||t[10]!==y||t[11]!==o||t[12]!==s||t[13]!==p||t[14]!==d.presetKey||t[15]!==d.providerId||t[16]!==d.type?(S=(0,$.jsxs)(I,{children:[b,(0,$.jsx)(j,{className:x,children:d.type===`pick`?(0,$.jsx)(In,{builtinRows:i,searchQuery:p,onSearchChange:m,labels:o,onPickBuiltin:e=>{let t=_(e);f(t?{type:`custom`,presetKey:t}:{type:`builtin`,providerId:e})},onPickCustom:()=>f({type:`custom`})}):d.type===`builtin`?(0,$.jsx)(Ln,{providerId:d.providerId,builtinRows:i,labels:o,language:s,onBack:()=>f({type:`pick`}),onSaved:y}):(0,$.jsx)(Bn,{initialPresetKey:d.presetKey,customConfig:a,labels:o,language:s,onBack:()=>f({type:`pick`}),onSaved:y})})]}),t[8]=i,t[9]=a,t[10]=y,t[11]=o,t[12]=s,t[13]=p,t[14]=d.presetKey,t[15]=d.providerId,t[16]=d.type,t[17]=S):S=t[17];let C;return t[18]!==g||t[19]!==n||t[20]!==S?(C=(0,$.jsx)(ue,{open:n,onOpenChange:g,children:S}),t[18]=g,t[19]=n,t[20]=S,t[21]=C):C=t[21],C}function Fn(e){let t=(0,Z.c)(4),{label:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=l(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,w.press),t[0]=r):r=t[0];let i;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(P,{className:`size-4`,"aria-hidden":!0}),t[1]=i):i=t[1];let a;return t[2]===n?a=t[3]:(a=(0,$.jsx)(me,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:r,"aria-label":n,children:i})}),t[2]=n,t[3]=a),a}function In(e){let t=(0,Z.c)(42),{builtinRows:n,searchQuery:r,onSearchChange:i,labels:a,onPickBuiltin:o,onPickCustom:s}=e,c;t[0]===r?c=t[1]:(c=r.trim().toLowerCase(),t[0]=r,t[1]=c);let u=c,d;bb0:{if(!u){d=n;break bb0}let e;if(t[2]!==n||t[3]!==u){let r;t[5]===u?r=t[6]:(r=e=>{let t=tt[e.id]?.aliases??[];return e.id.toLowerCase().includes(u)||e.name.toLowerCase().includes(u)||t.some(e=>e.toLowerCase().includes(u))},t[5]=u,t[6]=r),e=n.filter(r),t[2]=n,t[3]=u,t[4]=e}else e=t[4];d=e}let f=d,p;t[7]===f?p=t[8]:(p=Nn(f),t[7]=f,t[8]=p);let m=p,h;t[9]===a.step1Title?h=t[10]:(h=(0,$.jsx)(ye,{className:`min-w-0 flex-1 text-base font-semibold text-fg`,children:a.step1Title}),t[9]=a.step1Title,t[10]=h);let g;t[11]===a.close?g=t[12]:(g=(0,$.jsx)(Fn,{label:a.close}),t[11]=a.close,t[12]=g);let _;t[13]!==h||t[14]!==g?(_=(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b border-edge-subtle px-5 py-4`,children:[h,g]}),t[13]=h,t[14]=g,t[15]=_):_=t[15];let v;t[16]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(Ze,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-fg-subtle`,strokeWidth:1.75,"aria-hidden":!0}),t[16]=v):v=t[16];let y;t[17]===i?y=t[18]:(y=e=>i(e.target.value),t[17]=i,t[18]=y);let b=a.searchPlaceholder,x;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(x=l(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-10 pr-3 text-sm text-fg placeholder:text-fg-subtle`,U),t[19]=x):x=t[19];let S;t[20]!==a.searchPlaceholder||t[21]!==r||t[22]!==y?(S=(0,$.jsx)(`div`,{className:`px-5 pt-3`,children:(0,$.jsxs)(`div`,{className:`relative`,children:[v,(0,$.jsx)(`input`,{type:`search`,value:r,onChange:y,placeholder:b,autoComplete:`off`,className:x})]})}),t[20]=a.searchPlaceholder,t[21]=r,t[22]=y,t[23]=S):S=t[23];let C;t[24]!==a.addCustom||t[25]!==a.customDescription||t[26]!==s||t[27]!==u?(C=u?null:(0,$.jsxs)(`button`,{type:`button`,onClick:s,className:l(`mb-3 flex w-full items-center gap-3 rounded-xl border border-dashed border-edge-subtle bg-surface-panel/40 px-4 py-3 text-left transition-colors`,`hover:bg-surface-hover/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,w.press),children:[(0,$.jsx)(ke,{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)(Se,{className:`size-4 shrink-0 text-fg-subtle`,"aria-hidden":!0})]}),t[24]=a.addCustom,t[25]=a.customDescription,t[26]=s,t[27]=u,t[28]=C):C=t[28];let T;t[29]!==f.length||t[30]!==m||t[31]!==a.categories||t[32]!==a.noResults||t[33]!==o?(T=f.length===0?(0,$.jsx)(`p`,{className:`py-6 text-center text-sm text-fg-muted`,children:a.noResults}):(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:Mn.map(e=>{let t=m.get(e)??[];return t.length===0?null:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`mb-1 px-1 text-[11px] font-semibold uppercase tracking-wide text-fg-subtle`,children:a.categories[e]??e}),(0,$.jsx)(`div`,{className:`flex flex-col gap-0.5`,children:t.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>o(e.id),className:l(`flex w-full items-center justify-between gap-2 rounded-lg px-3 py-2.5 text-left transition-colors`,`hover:bg-surface-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,w.press),children:[(0,$.jsx)(`span`,{className:`truncate text-sm text-fg`,children:e.name}),e.configured?(0,$.jsx)(Oe,{className:`size-3.5 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):null]},e.id))})]},e)})}),t[29]=f.length,t[30]=m,t[31]=a.categories,t[32]=a.noResults,t[33]=o,t[34]=T):T=t[34];let E;t[35]!==C||t[36]!==T?(E=(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto px-5 py-3`,children:[C,T]}),t[35]=C,t[36]=T,t[37]=E):E=t[37];let D;return t[38]!==S||t[39]!==E||t[40]!==_?(D=(0,$.jsxs)($.Fragment,{children:[_,S,E]}),t[38]=S,t[39]=E,t[40]=_,t[41]=D):D=t[41],D}function Ln({providerId:e,builtinRows:t,labels:n,language:r,onBack:i,onSaved:a}){let o=t.find(t=>t.id===e),s=tt[e],[c,d]=(0,Q.useState)(``),[f,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(null),[v,y]=(0,Q.useState)(!1),b=(0,Q.useRef)(null),S=u(r).providersSettings,C=q(S),T=(0,Q.useMemo)(()=>x(e,r),[e,r]),E=o?.supportsApiKey!==!1,D=o?.supportsOAuth===!0,[O,A]=(0,Q.useState)(null),[j,M]=(0,Q.useState)(null),[P,F]=(0,Q.useState)(`idle`),[I,L]=(0,Q.useState)(null),[R,z]=(0,Q.useState)(null),[B,V]=(0,Q.useState)(``),H=P===`waiting`||P===`waiting_code`;(0,Q.useEffect)(()=>{if(!O||!H)return;let t=window.setInterval(()=>{(async()=>{try{let n=await N(O);if(n.status===`waiting_auth`||n.status===`waiting_code`)F(n.status===`waiting_code`?`waiting_code`:`waiting`),M(n.message??null),L(n.authUrl??null),z(n.instructions??null);else if(n.status===`completed`){window.clearInterval(t);try{if(e===`xopc-cloud`){let e=await p(m(`/api/models/catalog/refresh`),{method:`POST`});if(!e.ok)throw Error(`Model catalog refresh failed: ${e.status}`);await ve()}}catch(e){F(`error`),M(e instanceof Error?e.message:S.revokeFailed);return}F(`success`),M(n.message??S.saved),window.setTimeout(a,600)}else (n.status===`failed`||n.status===`cancelled`)&&(window.clearInterval(t),F(`error`),M(n.error??n.message??S.revokeFailed))}catch{}})()},1e3);return()=>window.clearInterval(t)},[O,H,a,e,S.revokeFailed,S.saved]),(0,Q.useEffect)(()=>()=>{O&&k(O).catch(()=>{})},[O]);let ee=async()=>{F(`waiting`),M(S.oauthStarting),_(null);try{A((await oe(e)).sessionId)}catch(e){F(`error`),M(e instanceof Error?e.message:S.revokeFailed)}},te=async()=>{if(O){try{await ae(O)}catch{}F(`idle`),M(null),A(null),L(null),z(null)}},ne=async()=>{if(!(!O||!B.trim()))try{await et(O,B.trim()),V(``),M(S.oauthProcessingCode)}catch(e){F(`error`),M(e instanceof Error?e.message:S.revokeFailed)}},re=async()=>{let t=c.trim();if(!(!t||!E)){h(!0),_(null);try{await pe({[e]:t}),y(!0),window.setTimeout(a,600)}catch(e){_(e instanceof Error?e.message:n.saveError)}finally{h(!1)}}};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-edge-subtle px-5 py-4`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:i,className:l(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,w.press),"aria-label":n.back,children:(0,$.jsx)(Se,{className:`size-4 rotate-180`,"aria-hidden":!0})}),(0,$.jsx)(ye,{className:`min-w-0 flex-1 text-base font-semibold text-fg`,children:o?.name??e}),(0,$.jsx)(Fn,{label:n.close})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 px-5 py-4`,children:[s?.description?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:s.description}):null,E?(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`builtin-api-key`,className:`text-sm font-medium text-fg`,children:n.apiKeyLabel}),(0,$.jsx)(Je,{id:`builtin-api-key`,value:c,onChange:d,placeholder:n.apiKeyPlaceholder,labels:C,inputRef:b,onKeyDown:e=>{e.key===`Enter`&&re()}})]}):null,D?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-lg border border-edge-subtle bg-surface-panel/60 p-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:S.oauth}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:S.oauthHint})]}),(0,$.jsxs)(W,{type:`button`,variant:`primary`,className:`gap-1.5`,disabled:H,onClick:()=>void ee(),children:[H?(0,$.jsx)(X,{className:`size-3.5 animate-spin`,"aria-hidden":!0}):null,S.oauth]})]}),j?(0,$.jsx)(`p`,{className:l(`text-xs`,P===`error`?`text-red-600 dark:text-red-400`:`text-fg-muted`),children:j}):null,P===`waiting`||P===`waiting_code`?(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[I?(0,$.jsxs)(`a`,{href:I,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:[S.openAuthPage,(0,$.jsx)(`span`,{className:`size-3`,"aria-hidden":!0,children:`↗`})]}):null,(0,$.jsx)(W,{type:`button`,variant:`secondary`,onClick:()=>void te(),children:S.cancelOAuth})]}):null,R?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:R}):null,P===`waiting_code`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,$.jsx)(`input`,{type:`text`,value:B,onChange:e=>V(e.target.value),onKeyDown:e=>e.key===`Enter`&&void ne(),placeholder:S.pasteRedirectUrl,className:l(`min-w-0 flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,U)}),(0,$.jsx)(W,{type:`button`,variant:`primary`,onClick:()=>void ne(),children:S.submitCode})]}):null]}):null,T.length>0&&E?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:T.map(({kind:e,href:t})=>(0,$.jsxs)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent hover:underline`,children:[fe(e,n),(0,$.jsx)(`span`,{className:`size-3`,"aria-hidden":!0,children:`↗`})]},e))}):null,g?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:g}):null,(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,$.jsx)(W,{type:`button`,variant:`secondary`,onClick:i,children:n.cancel}),E?(0,$.jsx)(W,{type:`button`,variant:`primary`,disabled:!c.trim()||f||v,onClick:()=>void re(),children:v?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(Oe,{className:`size-3.5`,"aria-hidden":!0}),n.saved]}):f?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(X,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),n.saving]}):n.save}):null]})]})]})}function Rn(e=`custom`){if(e!==`custom`&&E[e]){let t=E[e].config;return{preset:e,providerId:H(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}:E[t.key]?Rn(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 Bn({initialPresetKey:e,customConfig:t,labels:n,language:r,onBack:i,onSaved:a}){let[o,s]=(0,Q.useReducer)(zn,void 0,()=>Rn(e)),[c,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(!1),m=q(u(r).providersSettings),{preset:h,providerId:g,baseUrl:_,api:v,apiKey:y,modelIds:b,error:x}=o,S=async()=>{let e=g.trim(),r=_.trim();if(!e){s({type:`setError`,value:n.providerIdRequired});return}if(!r){s({type:`setError`,value:n.baseUrlRequired});return}let i=b.map(e=>e.trim()).filter(Boolean);d(!0),s({type:`setError`,value:null});try{let n=t?.providers??{},o=h===`custom`?void 0:E[h]?.config,s={...o??{},baseUrl:r,api:v,apiKey:y.trim()||void 0,models:i.map(e=>o?.models?.find(t=>t.id===e)??{id:e})};await qe({providers:{...n,[e]:s}}),a()}catch(e){s({type:`setError`,value:e instanceof Error?e.message:n.saveError})}finally{d(!1)}},T=async()=>{let e=g.trim()||H(h)||`custom`,t=_.trim();if(!t){s({type:`setError`,value:n.baseUrlRequired});return}p(!0),s({type:`setError`,value:null});try{let r=h===`custom`?void 0:E[h]?.config,i=(await Ye({providerId:e,baseUrl:t,apiKey:y.trim()||void 0,api:v,headers:r?.headers})).map(e=>e.id).filter(e=>e&&!e.includes(`/`));s({type:`setModelIds`,values:i}),i.length===0&&s({type:`setError`,value:n.discoverModelsHint})}catch(e){s({type:`setError`,value:e instanceof Error?e.message:n.discoverModelsHint})}finally{p(!1)}},D=g.trim()&&_.trim(),O=(v===`openai-completions`||v===`openai-responses`)&&_.trim();return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-edge-subtle px-5 py-4`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:i,className:l(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,w.press),"aria-label":n.back,children:(0,$.jsx)(Se,{className:`size-4 rotate-180`,"aria-hidden":!0})}),(0,$.jsx)(ye,{className:`min-w-0 flex-1 text-base font-semibold text-fg`,children:n.step2CustomTitle}),(0,$.jsx)(Fn,{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)(Y,{id:`custom-preset`,value:h,onChange:e=>s({type:`applyPreset`,key:e.target.value}),className:ne(),children:[(0,$.jsx)(J,{value:`custom`,children:n.presetCustom}),C.map(e=>(0,$.jsx)(J,{value:e.key,children:e.label},e.key))]})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`custom-provider-id`,className:`text-sm font-medium text-fg`,children:n.providerIdLabel}),(0,$.jsx)(`input`,{id:`custom-provider-id`,type:`text`,autoComplete:`off`,value:g,onChange:e=>s({type:`setProviderId`,value:e.target.value}),placeholder:n.providerIdPlaceholder,className:l(`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,U)})]}),(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`custom-base-url`,className:`text-sm font-medium text-fg`,children:n.baseUrlLabel}),(0,$.jsx)(`input`,{id:`custom-base-url`,type:`url`,autoComplete:`off`,value:_,onChange:e=>s({type:`setBaseUrl`,value:e.target.value}),placeholder:n.baseUrlPlaceholder,className:l(`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,U)})]}),(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)(Y,{id:`custom-api-type`,value:v,onChange:e=>s({type:`setApi`,value:e.target.value}),className:ne(),children:Qe.map(e=>(0,$.jsx)(J,{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)(Je,{id:`custom-api-key`,value:y,onChange:e=>s({type:`setApiKey`,value:e}),placeholder:n.apiKeyPlaceholder,labels:m})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:n.modelIdLabel}),(0,$.jsxs)(W,{type:`button`,variant:`secondary`,className:`gap-1.5`,disabled:!O||f,onClick:()=>void T(),children:[f?(0,$.jsx)(X,{className:`size-3.5 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Ze,{className:`size-3.5`,"aria-hidden":!0}),f?n.discoveringModels:n.discoverModels]})]}),b.map((e,t)=>(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`input`,{type:`text`,autoComplete:`off`,value:e,onChange:e=>s({type:`updateModelId`,index:t,value:e.target.value}),placeholder:n.modelIdPlaceholder,className:l(`flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,U)}),b.length>1?(0,$.jsx)(`button`,{type:`button`,onClick:()=>s({type:`removeModelSlot`,index:t}),className:l(`rounded-lg p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,w.press),children:(0,$.jsx)(P,{className:`size-3.5`,"aria-hidden":!0})}):null]},e||`model-slot-${t}`)),(0,$.jsxs)(W,{type:`button`,variant:`ghost`,className:`w-fit gap-1.5 text-fg-muted`,onClick:()=>s({type:`addModelSlot`}),children:[(0,$.jsx)(te,{className:`size-3.5`,"aria-hidden":!0}),n.addModel]})]}),x?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:x}):null]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t border-edge-subtle px-5 py-3`,children:[(0,$.jsx)(W,{type:`button`,variant:`secondary`,onClick:i,children:n.cancel}),(0,$.jsx)(W,{type:`button`,variant:`primary`,disabled:!D||c,onClick:()=>void S(),children:c?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(X,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),n.saving]}):n.save})]})]})}function Vn(){let e=(0,Z.c)(31),t=d(Kn),n=!!t,{data:r,isLoading:i}=Ie(n),a;e[0]===n?a=e[1]:(a=n?m(`/api/providers/meta`):null,e[0]=n,e[1]=a);let o;e[2]===t?o=e[3]:(o=async e=>{let{payload:n}=await(await fetch(e,{headers:{Authorization:`Bearer ${t}`}})).json();return n?.providers??[]},e[2]=t,e[3]=o);let s;e[4]===Symbol.for(`react.memo_cache_sentinel`)?(s={revalidateOnFocus:!1},e[4]=s):s=e[4];let{data:c,isLoading:l}=g(a,o,s),u;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(u={revalidateOnFocus:!1},e[5]=u):u=e[5];let{data:f,isLoading:p}=g(n?_e:null,Gn,u),h;e[6]===f?h=e[7]:(h=f===void 0?[]:f,e[6]=f,e[7]=h);let _=h,v;e[8]===Symbol.for(`react.memo_cache_sentinel`)?(v={revalidateOnFocus:!1},e[8]=v):v=e[8];let{data:y}=g(n?ze:null,Wn,v),b;bb0:{if(!c||r===void 0){let t;e[9]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[9]=t):t=e[9],b=t;break bb0}let t;e[10]!==r?.payload?.config||e[11]!==c||e[12]!==_?(t=le(c,A(r?.payload?.config),_),e[10]=r?.payload?.config,e[11]=c,e[12]=_,e[13]=t):t=e[13],b=t}let x=b,C;bb1:{if(!y){C=null;break bb1}let t;e[14]===y.config?t=e[15]:(t=S(y.config),e[14]=y.config,e[15]=t),C=t}let w=C,T;if(e[16]!==x||e[17]!==w||e[18]!==c||e[19]!==_){T=[];let t=new Set((c??[]).filter(Un).map(Hn)),n;e[21]===w?n=e[22]:(n=new Set(w?Object.keys(w.providers):[]),e[21]=w,e[22]=n);let r=n;for(let e of x){if(!t.has(e.id))continue;let n=r.has(e.id),i=n?w.providers[e.id]?.models?.length??0:_.filter(t=>t.provider===e.id).length;T.push({id:e.id,name:e.name,configured:!0,isCustom:n,modelCount:i})}if(w){let t;e[23]===w.providers?t=e[24]:(t=Object.entries(w.providers),e[23]=w.providers,e[24]=t);for(let[e,n]of t)T.some(t=>t.id===e)||T.push({id:e,name:e,configured:!0,isCustom:!0,modelCount:n.models?.length??0})}e[16]=x,e[17]=w,e[18]=c,e[19]=_,e[20]=T}else T=e[20];let E=T,D=i||l||p,O;return e[25]!==x||e[26]!==E||e[27]!==w||e[28]!==D||e[29]!==_?(O={cards:E,loading:D,builtinRows:x,customConfig:w,allModels:_},e[25]=x,e[26]=E,e[27]=w,e[28]=D,e[29]=_,e[30]=O):O=e[30],O}function Hn(e){return e.id}function Un(e){return e.configured}function Wn(){return K()}function Gn(){return xe()}function Kn(e){return e.token}function qn(e){let t=(0,Z.c)(16),{labels:n,onAdd:r,onManage:i}=e,{cards:a,loading:o}=Vn();if(o){let e;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Ve,{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(Yn)})]}),t[1]=n):n=t[1],n}let s;if(t[2]!==a||t[3]!==n||t[4]!==r||t[5]!==i){let e=a.filter(Jn),o=e.length>0?n.titleCount.replace(`{{count}}`,String(e.length)):n.title,c;t[7]===o?c=t[8]:(c=(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:o}),t[7]=o,t[8]=c);let l;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(te,{className:`size-3.5`,strokeWidth:2,"aria-hidden":!0}),t[9]=l):l=t[9];let u;t[10]!==n.addProvider||t[11]!==r?(u=(0,$.jsxs)(W,{type:`button`,variant:`primary`,className:`gap-1.5`,onClick:r,children:[l,n.addProvider]}),t[10]=n.addProvider,t[11]=r,t[12]=u):u=t[12];let d;t[13]!==c||t[14]!==u?(d=(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[c,u]}),t[13]=c,t[14]=u,t[15]=d):d=t[15],s=(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[d,e.length===0?(0,$.jsxs)(`div`,{className:`rounded-2xl bg-surface-panel/60 px-6 py-10 text-center shadow-surface`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:n.empty}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.emptyHint}),(0,$.jsxs)(W,{type:`button`,variant:`primary`,className:`mt-4 gap-1.5`,onClick:r,children:[(0,$.jsx)(te,{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)(Xn,{card:e,labels:n,onManage:()=>i(e.id,e.isCustom)},e.id))})]}),t[2]=a,t[3]=n,t[4]=r,t[5]=i,t[6]=s}else s=t[6];return s}function Jn(e){return e.configured}function Yn(e){return(0,$.jsx)(Ve,{className:`h-32 rounded-2xl`},e)}function Xn(e){let t=(0,Z.c)(28),{card:n,labels:r,onManage:i}=e,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=l(`group relative flex flex-col justify-between rounded-2xl bg-surface-base p-4 text-left shadow-surface transition-colors`,`hover:bg-surface-hover/60 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,w.pressCard),t[0]=a):a=t[0];let o;t[1]===n.name?o=t[2]:(o=(0,$.jsx)(`span`,{className:`truncate text-sm font-semibold text-fg`,children:n.name}),t[1]=n.name,t[2]=o);let s;t[3]!==n.isCustom||t[4]!==r.custom?(s=n.isCustom?(0,$.jsx)(`span`,{className:`shrink-0 rounded bg-surface-hover px-1.5 py-0.5 text-[10px] font-medium text-fg-subtle`,children:r.custom}):null,t[3]=n.isCustom,t[4]=r.custom,t[5]=s):s=t[5];let c;t[6]!==o||t[7]!==s?(c=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[o,s]}),t[6]=o,t[7]=s,t[8]=c):c=t[8];let u;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,$.jsx)(Oe,{className:`size-4 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}),t[9]=u):u=t[9];let d;t[10]===c?d=t[11]:(d=(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[c,u]}),t[10]=c,t[11]=d);let f;t[12]!==n.modelCount||t[13]!==r.modelsCount||t[14]!==r.noModels?(f=n.modelCount>0?r.modelsCount.replace(`{{count}}`,String(n.modelCount)):r.noModels,t[12]=n.modelCount,t[13]=r.modelsCount,t[14]=r.noModels,t[15]=f):f=t[15];let p;t[16]===f?p=t[17]:(p=(0,$.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:f}),t[16]=f,t[17]=p);let m;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,$.jsx)(De,{className:`size-3`,"aria-hidden":!0}),t[18]=m):m=t[18];let h;t[19]===r.manage?h=t[20]:(h=(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-xs font-medium text-accent-fg opacity-0 transition-opacity group-hover:opacity-100`,children:[m,r.manage]}),t[19]=r.manage,t[20]=h);let g;t[21]!==h||t[22]!==p?(g=(0,$.jsxs)(`div`,{className:`mt-2.5 flex items-center justify-between`,children:[p,h]}),t[21]=h,t[22]=p,t[23]=g):g=t[23];let _;return t[24]!==i||t[25]!==g||t[26]!==d?(_=(0,$.jsxs)(`button`,{type:`button`,onClick:i,className:a,children:[d,g]}),t[24]=i,t[25]=g,t[26]=d,t[27]=_):_=t[27],_}function Zn(e){let t=(0,Z.c)(156),{model:n,isNew:r,providerId:i,onSave:a,onClose:o,m:s}=e,c;t[0]===n?c=t[1]:(c=()=>n?{...n}:we(``),t[0]=n,t[1]=c);let[u,d]=(0,Q.useState)(c),[f,p]=(0,Q.useState)(Qn),m;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(m=(e,t)=>{d(n=>({...n,[e]:t})),p(t=>{let n=new Map(t);return n.delete(e),n})},t[2]=m):m=t[2];let h=m,g;t[3]!==u.contextWindow||t[4]!==u.id||t[5]!==u.maxTokens||t[6]!==s.modelIdRequired||t[7]!==s.mustBePositive?(g=()=>{let e=new Map;return(u.id||``).trim()||e.set(`id`,s.modelIdRequired),u.contextWindow!==void 0&&u.contextWindow<=0&&e.set(`contextWindow`,s.mustBePositive),u.maxTokens!==void 0&&u.maxTokens<=0&&e.set(`maxTokens`,s.mustBePositive),p(e),e.size===0},t[3]=u.contextWindow,t[4]=u.id,t[5]=u.maxTokens,t[6]=s.modelIdRequired,t[7]=s.mustBePositive,t[8]=g):g=t[8];let _=g,v;t[9]!==u||t[10]!==o||t[11]!==a||t[12]!==_?(v=()=>{if(!_())return;let e=(u.id||``).trim();a({...u,id:e,name:u.name?.trim()||e,reasoning:u.reasoning||!1,input:u.input||[`text`],contextWindow:u.contextWindow??128e3,maxTokens:u.maxTokens??16384,cost:{input:u.cost?.input??0,output:u.cost?.output??0,cacheRead:u.cost?.cacheRead??0,cacheWrite:u.cost?.cacheWrite??0}}),o()},t[9]=u,t[10]=o,t[11]=a,t[12]=_,t[13]=v):v=t[13];let y=v,b=u,x;t[14]===b?x=t[15]:(x=Ae(b),t[14]=b,t[15]=x);let S=x,C=r?s.addModelTitle:s.editModelTitle,w;t[16]===C?w=t[17]:(w=(0,$.jsx)(ye,{className:`text-base font-semibold text-fg`,children:C}),t[16]=C,t[17]=w);let T;t[18]!==s.modelProviderLabel||t[19]!==i?(T=i?(0,$.jsxs)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:[s.modelProviderLabel,`: `,i]}):null,t[18]=s.modelProviderLabel,t[19]=i,t[20]=T):T=t[20];let E;t[21]!==w||t[22]!==T?(E=(0,$.jsxs)(`div`,{children:[w,T]}),t[21]=w,t[22]=T,t[23]=E):E=t[23];let O;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(O=l(D,`p-1.5 hover:bg-surface-base`),t[24]=O):O=t[24];let k;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(k=(0,$.jsx)(P,{className:`size-4`}),t[25]=k):k=t[25];let A;t[26]===s.close?A=t[27]:(A=(0,$.jsx)(me,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:O,"aria-label":s.close,children:k})}),t[26]=s.close,t[27]=A);let j;t[28]!==E||t[29]!==A?(j=(0,$.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[E,A]}),t[28]=E,t[29]=A,t[30]=j):j=t[30];let M;t[31]===Symbol.for(`react.memo_cache_sentinel`)?(M=(0,$.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`}),t[31]=M):M=t[31];let N;t[32]===s.modelId?N=t[33]:(N=(0,$.jsxs)(`label`,{className:`mb-1 block text-xs font-medium text-fg`,children:[s.modelId,M]}),t[32]=s.modelId,t[33]=N);let F;t[34]===f?F=t[35]:(F=l(re(),f.has(`id`)&&`border-red-500`),t[34]=f,t[35]=F);let I=u.id||``,L;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(L=e=>h(`id`,e.target.value),t[36]=L):L=t[36];let R=!r,z;t[37]!==F||t[38]!==I||t[39]!==R?(z=(0,$.jsx)(`input`,{className:F,value:I,onChange:L,placeholder:`e.g. llama3.1:8b`,disabled:R}),t[37]=F,t[38]=I,t[39]=R,t[40]=z):z=t[40];let B;t[41]===f?B=t[42]:(B=f.has(`id`)?(0,$.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:f.get(`id`)}):null,t[41]=f,t[42]=B);let V;t[43]!==N||t[44]!==z||t[45]!==B?(V=(0,$.jsxs)(`div`,{children:[N,z,B]}),t[43]=N,t[44]=z,t[45]=B,t[46]=V):V=t[46];let H;t[47]===s.displayName?H=t[48]:(H=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.displayName}),t[47]=s.displayName,t[48]=H);let U;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(U=re(),t[49]=U):U=t[49];let ee=u.name||``,te;t[50]===Symbol.for(`react.memo_cache_sentinel`)?(te=e=>h(`name`,e.target.value),t[50]=te):te=t[50];let ie;t[51]===ee?ie=t[52]:(ie=(0,$.jsx)(`input`,{className:U,value:ee,onChange:te}),t[51]=ee,t[52]=ie);let ae;t[53]!==H||t[54]!==ie?(ae=(0,$.jsxs)(`div`,{children:[H,ie]}),t[53]=H,t[54]=ie,t[55]=ae):ae=t[55];let G;t[56]===s.inputTypes?G=t[57]:(G=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.inputTypes}),t[56]=s.inputTypes,t[57]=G);let oe;t[58]===Symbol.for(`react.memo_cache_sentinel`)?(oe=ne(),t[58]=oe):oe=t[58];let se;t[59]===Symbol.for(`react.memo_cache_sentinel`)?(se=e=>h(`input`,Pe(e.target.value)),t[59]=se):se=t[59];let K;t[60]===s?K=t[61]:(K=ce.map(e=>(0,$.jsx)(J,{value:e.value,children:s[e.labelKey]},e.value)),t[60]=s,t[61]=K);let q;t[62]!==S||t[63]!==K?(q=(0,$.jsx)(Y,{className:oe,value:S,onChange:se,children:K}),t[62]=S,t[63]=K,t[64]=q):q=t[64];let le;t[65]!==G||t[66]!==q?(le=(0,$.jsxs)(`div`,{children:[G,q]}),t[65]=G,t[66]=q,t[67]=le):le=t[67];let ue=u.reasoning||!1,de;t[68]===Symbol.for(`react.memo_cache_sentinel`)?(de=e=>h(`reasoning`,e.target.checked),t[68]=de):de=t[68];let fe;t[69]===ue?fe=t[70]:(fe=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:ue,onChange:de}),t[69]=ue,t[70]=fe);let pe;t[71]!==s.reasoning||t[72]!==fe?(pe=(0,$.jsxs)(`label`,{className:`mt-6 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[fe,s.reasoning]}),t[71]=s.reasoning,t[72]=fe,t[73]=pe):pe=t[73];let he;t[74]!==le||t[75]!==pe?(he=(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[le,pe]}),t[74]=le,t[75]=pe,t[76]=he):he=t[76];let ge;t[77]===s.contextWindow?ge=t[78]:(ge=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.contextWindow}),t[77]=s.contextWindow,t[78]=ge);let _e;t[79]===f?_e=t[80]:(_e=l(re(),f.has(`contextWindow`)&&`border-red-500`),t[79]=f,t[80]=_e);let ve=u.contextWindow??128e3,be;t[81]===Symbol.for(`react.memo_cache_sentinel`)?(be=e=>h(`contextWindow`,parseInt(e.target.value,10)||0),t[81]=be):be=t[81];let xe;t[82]!==_e||t[83]!==ve?(xe=(0,$.jsx)(`input`,{type:`number`,min:1,className:_e,value:ve,onChange:be}),t[82]=_e,t[83]=ve,t[84]=xe):xe=t[84];let Se;t[85]===f?Se=t[86]:(Se=f.has(`contextWindow`)?(0,$.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:f.get(`contextWindow`)}):null,t[85]=f,t[86]=Se);let Ce;t[87]!==ge||t[88]!==xe||t[89]!==Se?(Ce=(0,$.jsxs)(`div`,{children:[ge,xe,Se]}),t[87]=ge,t[88]=xe,t[89]=Se,t[90]=Ce):Ce=t[90];let Te;t[91]===s.maxOutputTokens?Te=t[92]:(Te=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.maxOutputTokens}),t[91]=s.maxOutputTokens,t[92]=Te);let Ee;t[93]===f?Ee=t[94]:(Ee=l(re(),f.has(`maxTokens`)&&`border-red-500`),t[93]=f,t[94]=Ee);let De=u.maxTokens??16384,Oe;t[95]===Symbol.for(`react.memo_cache_sentinel`)?(Oe=e=>h(`maxTokens`,parseInt(e.target.value,10)||0),t[95]=Oe):Oe=t[95];let ke;t[96]!==Ee||t[97]!==De?(ke=(0,$.jsx)(`input`,{type:`number`,min:1,className:Ee,value:De,onChange:Oe}),t[96]=Ee,t[97]=De,t[98]=ke):ke=t[98];let je;t[99]===f?je=t[100]:(je=f.has(`maxTokens`)?(0,$.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:f.get(`maxTokens`)}):null,t[99]=f,t[100]=je);let Me;t[101]!==Te||t[102]!==ke||t[103]!==je?(Me=(0,$.jsxs)(`div`,{children:[Te,ke,je]}),t[101]=Te,t[102]=ke,t[103]=je,t[104]=Me):Me=t[104];let Ne;t[105]!==Ce||t[106]!==Me?(Ne=(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[Ce,Me]}),t[105]=Ce,t[106]=Me,t[107]=Ne):Ne=t[107];let Fe;t[108]===s.costSection?Fe=t[109]:(Fe=(0,$.jsx)(`p`,{className:`mb-2 text-xs font-semibold text-fg`,children:s.costSection}),t[108]=s.costSection,t[109]=Fe);let Ie;t[110]===s.costInput?Ie=t[111]:(Ie=(0,$.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:s.costInput}),t[110]=s.costInput,t[111]=Ie);let Le;t[112]===Symbol.for(`react.memo_cache_sentinel`)?(Le=re(),t[112]=Le):Le=t[112];let Re=u.cost?.input??0,ze;t[113]===u.cost?ze=t[114]:(ze=e=>h(`cost`,{...u.cost,input:parseFloat(e.target.value)||0,output:u.cost?.output??0,cacheRead:u.cost?.cacheRead??0,cacheWrite:u.cost?.cacheWrite??0}),t[113]=u.cost,t[114]=ze);let Be;t[115]!==Re||t[116]!==ze?(Be=(0,$.jsx)(`input`,{type:`number`,step:`any`,min:0,className:Le,value:Re,onChange:ze}),t[115]=Re,t[116]=ze,t[117]=Be):Be=t[117];let X;t[118]!==Ie||t[119]!==Be?(X=(0,$.jsxs)(`div`,{children:[Ie,Be]}),t[118]=Ie,t[119]=Be,t[120]=X):X=t[120];let Ve;t[121]===s.costOutput?Ve=t[122]:(Ve=(0,$.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:s.costOutput}),t[121]=s.costOutput,t[122]=Ve);let He;t[123]===Symbol.for(`react.memo_cache_sentinel`)?(He=re(),t[123]=He):He=t[123];let Ue=u.cost?.output??0,We;t[124]===u.cost?We=t[125]:(We=e=>h(`cost`,{...u.cost,input:u.cost?.input??0,output:parseFloat(e.target.value)||0,cacheRead:u.cost?.cacheRead??0,cacheWrite:u.cost?.cacheWrite??0}),t[124]=u.cost,t[125]=We);let Ge;t[126]!==Ue||t[127]!==We?(Ge=(0,$.jsx)(`input`,{type:`number`,step:`any`,min:0,className:He,value:Ue,onChange:We}),t[126]=Ue,t[127]=We,t[128]=Ge):Ge=t[128];let Ke;t[129]!==Ve||t[130]!==Ge?(Ke=(0,$.jsxs)(`div`,{children:[Ve,Ge]}),t[129]=Ve,t[130]=Ge,t[131]=Ke):Ke=t[131];let qe;t[132]!==X||t[133]!==Ke?(qe=(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[X,Ke]}),t[132]=X,t[133]=Ke,t[134]=qe):qe=t[134];let Je;t[135]!==Fe||t[136]!==qe?(Je=(0,$.jsxs)(`div`,{className:`border-t border-edge-subtle pt-2 dark:border-edge`,children:[Fe,qe]}),t[135]=Fe,t[136]=qe,t[137]=Je):Je=t[137];let Ye;t[138]!==V||t[139]!==ae||t[140]!==he||t[141]!==Ne||t[142]!==Je?(Ye=(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[V,ae,he,Ne,Je]}),t[138]=V,t[139]=ae,t[140]=he,t[141]=Ne,t[142]=Je,t[143]=Ye):Ye=t[143];let Xe;t[144]===s.cancel?Xe=t[145]:(Xe=(0,$.jsx)(me,{asChild:!0,children:(0,$.jsx)(W,{type:`button`,variant:`secondary`,children:s.cancel})}),t[144]=s.cancel,t[145]=Xe);let Ze=r?s.addModelConfirm:s.saveModelConfirm,Qe;t[146]!==y||t[147]!==Ze?(Qe=(0,$.jsx)(W,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:y,children:Ze}),t[146]=y,t[147]=Ze,t[148]=Qe):Qe=t[148];let $e;t[149]!==Xe||t[150]!==Qe?($e=(0,$.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2 border-t border-edge-subtle pt-3 dark:border-edge`,children:[Xe,Qe]}),t[149]=Xe,t[150]=Qe,t[151]=$e):$e=t[151];let et;return t[152]!==j||t[153]!==Ye||t[154]!==$e?(et=(0,$.jsxs)($.Fragment,{children:[j,Ye,$e]}),t[152]=j,t[153]=Ye,t[154]=$e,t[155]=et):et=t[155],et}function Qn(){return new Map}function $n(e){let t=(0,Z.c)(16),{open:n,onOpenChange:r,providerId:i,model:a,isNew:o,onSave:s,m:c}=e,u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,$.jsx)(Be,{className:l(`xopc-dialog-overlay fixed inset-0 bg-scrim`,Fe)}),t[0]=u):u=t[0];let d;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(d=l(`xopc-dialog-content fixed left-1/2 top-1/2 max-h-[min(90vh,720px)] w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2`,Re,`overflow-y-auto rounded-xl border border-edge bg-surface-panel p-4 shadow-popover dark:border-edge`),t[1]=d):d=t[1];let f;t[2]!==o||t[3]!==c||t[4]!==a||t[5]!==r||t[6]!==s||t[7]!==n||t[8]!==i?(f=n?(0,$.jsx)(Zn,{model:a,isNew:o,providerId:i,onSave:s,onClose:()=>r(!1),m:c},`${i??`none`}-${a?.id??`new`}`):null,t[2]=o,t[3]=c,t[4]=a,t[5]=r,t[6]=s,t[7]=n,t[8]=i,t[9]=f):f=t[9];let p;t[10]===f?p=t[11]:(p=(0,$.jsxs)(I,{children:[u,(0,$.jsx)(j,{className:d,onOpenAutoFocus:er,children:f})]}),t[10]=f,t[11]=p);let m;return t[12]!==r||t[13]!==n||t[14]!==p?(m=(0,$.jsx)(ue,{open:n,onOpenChange:r,children:p}),t[12]=r,t[13]=n,t[14]=p,t[15]=m):m=t[15],m}function er(e){return e.preventDefault()}function tr(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=()=>z(n).then(nr),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)(Je,{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 nr(e){return e.apiKey??null}function rr(e){let t=(0,Z.c)(16),{open:n,onOpenChange:r,providerId:i,isCustom:a,builtinRows:o,customConfig:s,allModels:c,labels:u,language:d,onSaved:f}=e,p;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(Be,{className:l(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,Fe)}),t[0]=p):p=t[0];let m;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(m=l(`fixed left-1/2 top-1/2 flex max-h-[85vh] w-[calc(100%-2rem)] max-w-lg -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-2xl border border-edge-subtle bg-surface-base shadow-xl`,Re),t[1]=m):m=t[1];let h;t[2]!==c||t[3]!==o||t[4]!==s||t[5]!==a||t[6]!==u||t[7]!==d||t[8]!==r||t[9]!==f||t[10]!==i?(h=(0,$.jsxs)(I,{children:[p,(0,$.jsx)(j,{className:m,children:a?(0,$.jsx)(ar,{providerId:i,customConfig:s,labels:u,language:d,onClose:()=>r(!1),onSaved:f}):(0,$.jsx)(ir,{providerId:i,builtinRows:o,allModels:c,labels:u,language:d,onClose:()=>r(!1),onSaved:f})})]}),t[2]=c,t[3]=o,t[4]=s,t[5]=a,t[6]=u,t[7]=d,t[8]=r,t[9]=f,t[10]=i,t[11]=h):h=t[11];let g;return t[12]!==r||t[13]!==n||t[14]!==h?(g=(0,$.jsx)(ue,{open:n,onOpenChange:r,children:h}),t[12]=r,t[13]=n,t[14]=h,t[15]=g):g=t[15],g}function ir({providerId:e,builtinRows:t,allModels:n,labels:r,language:i,onClose:a,onSaved:o}){let c=t.find(t=>t.id===e),d=tt[e],f=n.filter(t=>t.provider===e),[p,m]=(0,Q.useState)(c?.apiKey??``),[h,g]=(0,Q.useState)(!1),[_,v]=(0,Q.useState)(!1),[b,S]=(0,Q.useState)(null),[C,T]=(0,Q.useState)(!1),E=u(i).providersSettings,D=c?.supportsApiKey!==!1,O=c?.supportsOAuth===!0,A=c?.authMode===`oauth`&&c.authStatus===`connected`,j=c?.configured===!0&&c.activeKeySource!==`env`&&c.activeKeySource!==`extension`&&c.activeKeySource!==`models_json`,[F,I]=(0,Q.useState)(null),[L,z]=(0,Q.useState)(null),[V,H]=(0,Q.useState)(`idle`),[ee,te]=(0,Q.useState)(null),[ne,re]=(0,Q.useState)(null),[ie,G]=(0,Q.useState)(``),se=V===`waiting`||V===`waiting_code`,K=(0,Q.useMemo)(()=>x(e,i),[e,i]),q=p!==(c?.apiKey??``),ce=async()=>{let t=p.trim();if(!(!t||!D||M(t))){g(!0),S(null);try{await pe({[e]:t}),v(!0),window.setTimeout(()=>{o(),a()},600)}catch(e){S(e instanceof Error?e.message:r.saveError)}finally{g(!1)}}};(0,Q.useEffect)(()=>{if(!F||!se)return;let e=window.setInterval(()=>{(async()=>{try{let t=await N(F);t.status===`waiting_auth`||t.status===`waiting_code`?(H(t.status===`waiting_code`?`waiting_code`:`waiting`),z(t.message??null),te(t.authUrl??null),re(t.instructions??null)):t.status===`completed`?(window.clearInterval(e),H(`success`),z(t.message??E.saved),window.setTimeout(()=>{o(),a()},600)):(t.status===`failed`||t.status===`cancelled`)&&(window.clearInterval(e),H(`error`),z(t.error??t.message??E.revokeFailed))}catch{}})()},1e3);return()=>window.clearInterval(e)},[F,se,a,o,E.revokeFailed,E.saved]),(0,Q.useEffect)(()=>()=>{F&&k(F).catch(()=>{})},[F]);let le=async()=>{try{await y(e),o(),a()}catch{}},ue=async()=>{H(`waiting`),z(E.oauthStarting),S(null);try{I((await oe(e)).sessionId)}catch(e){H(`error`),z(e instanceof Error?e.message:E.revokeFailed)}},de=async()=>{if(F){try{await ae(F)}catch{}H(`idle`),z(null),I(null),te(null),re(null)}},he=async()=>{if(!(!F||!ie.trim()))try{await et(F,ie.trim()),G(``),z(E.oauthProcessingCode)}catch(e){H(`error`),z(e instanceof Error?e.message:E.revokeFailed)}},ge=async()=>{try{await B(e),o(),a()}catch(e){S(e instanceof Error?e.message:E.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)(ye,{className:`text-base font-semibold text-fg`,children:c?.name??e}),(0,$.jsx)(me,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:l(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,w.press),children:(0,$.jsx)(P,{className:`size-4`,"aria-hidden":!0})})})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 overflow-y-auto px-5 py-4`,children:[d?.description?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:d.description}):null,c?.baseUrl?(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:r.apiUrlLabel}),(0,$.jsx)(`code`,{className:`break-all rounded-lg border border-edge-subtle bg-surface-panel/60 px-3 py-2 font-mono text-xs text-fg-muted`,children:c.baseUrl})]}):c?.category===`extension`?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:r.apiUrlExtensionHint}):null,D?(0,$.jsx)(tr,{providerId:e,inputId:`manage-api-key`,value:p,onChange:e=>{m(e),v(!1)},labels:{apiKeyLabel:r.apiKeyLabel,apiKeyPlaceholder:r.apiKeyPlaceholder,maskedHelp:r.maskedHelp,copy:r.copy,copied:r.copied,show:r.showKey,hide:r.hideKey,notInConfigFile:r.notInConfigFile,loadFailed:r.loadFailed}}):c?.category===`extension`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-lg border border-edge-subtle bg-surface-panel/60 px-3 py-2 text-sm text-fg-muted`,children:[(0,$.jsx)(`p`,{children:r.extensionKeyHint}),c?.extensionId?(0,$.jsxs)(s,{to:`/settings/ext/${encodeURIComponent(c.extensionId)}`,className:`inline-flex w-fit items-center gap-1 font-medium text-accent hover:underline`,title:r.extensionSettingsLinkTitle,onClick:a,children:[r.openExtensionSettings,(0,$.jsx)(R,{className:`size-3`,"aria-hidden":!0})]}):null]}):null,O?(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:E.oauth}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:A?E.sourceOauth:E.oauthHint})]}),A?(0,$.jsx)(W,{type:`button`,variant:`secondary`,className:`gap-1.5 text-red-600 dark:text-red-400`,onClick:()=>void ge(),children:E.revoke}):(0,$.jsxs)(W,{type:`button`,variant:`primary`,className:`gap-1.5`,disabled:se,onClick:()=>void ue(),children:[se?(0,$.jsx)(X,{className:`size-3.5 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(He,{className:`size-3.5`,"aria-hidden":!0}),E.oauth]})]}),L?(0,$.jsx)(`p`,{className:l(`text-xs`,V===`error`?`text-red-600 dark:text-red-400`:`text-fg-muted`),children:L}):null,V===`waiting`||V===`waiting_code`?(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[ee?(0,$.jsxs)(`a`,{href:ee,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)(R,{className:`size-4`,"aria-hidden":!0}),E.openAuthPage]}):null,(0,$.jsx)(W,{type:`button`,variant:`secondary`,onClick:()=>void de(),children:E.cancelOAuth})]}):null,ne?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:ne}):null,V===`waiting_code`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,$.jsx)(`input`,{type:`text`,value:ie,onChange:e=>G(e.target.value),onKeyDown:e=>e.key===`Enter`&&void he(),placeholder:E.pasteRedirectUrl,className:l(`min-w-0 flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,U)}),(0,$.jsx)(W,{type:`button`,variant:`primary`,onClick:()=>void he(),children:E.submitCode})]}):null]}):null,K.length>0&&D?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:K.map(({kind:e,href:t})=>(0,$.jsxs)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent hover:underline`,children:[fe(e,r),(0,$.jsx)(R,{className:`size-3`,"aria-hidden":!0})]},e))}):null,f.length>0?(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsxs)(`span`,{className:`text-sm font-medium text-fg`,children:[r.modelsLabel,` (`,f.length,`)`]}),(0,$.jsx)(`div`,{className:`max-h-40 overflow-y-auto rounded-lg border border-edge-subtle bg-surface-panel/40 p-2`,children:(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:f.map(e=>(0,$.jsx)(`span`,{className:`inline-block rounded-md bg-surface-hover px-2 py-1 text-xs text-fg-muted`,children:e.id.includes(`/`)?e.id.split(`/`).pop():e.id},e.id))})})]}):(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:r.noModels}),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:[j?(0,$.jsxs)(W,{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:()=>T(!0),children:[(0,$.jsx)(be,{className:`size-3.5`,"aria-hidden":!0}),r.remove]}):(0,$.jsx)(`span`,{}),(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:D&&q&&!M(p.trim())?(0,$.jsx)(W,{type:`button`,variant:`primary`,disabled:!p.trim()||h||_,onClick:()=>void ce(),children:_?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(Oe,{className:`size-3.5`,"aria-hidden":!0}),r.saved]}):h?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(X,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),r.saving]}):r.save}):null})]}),(0,$.jsx)(We,{open:C,title:r.removeConfirmTitle,description:r.removeConfirmDescription.replace(`{{provider}}`,c?.name??e),confirmLabel:r.removeConfirmAction,cancelLabel:r.cancel,destructive:!0,onConfirm:()=>void le(),onCancel:()=>T(!1)})]})}function ar({providerId:e,customConfig:t,labels:n,language:r,onClose:i,onSaved:a}){let o=u(r).modelsSettings,s=t?.providers[e],[c,d]=(0,Q.useState)(s?.baseUrl??``),[f,p]=(0,Q.useState)(s?.apiKey??``),[m,h]=(0,Q.useState)(s?.models??[]),[g,_]=(0,Q.useState)(s?.modelDiscovery?.enabled===!0),[v,y]=(0,Q.useState)(!1),[b,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(!1),[T,E]=(0,Q.useState)(null),[D,O]=(0,Q.useState)(!1),[k,A]=(0,Q.useState)(null),j=n=>{if(!t)return null;let r=f.trim(),i={...s,baseUrl:c.trim()||void 0,apiKey:M(r)?s?.apiKey:r||void 0,...n};return{providers:{...t.providers,[e]:i}}},N=async()=>{let e=j({models:m,modelDiscovery:{enabled:g}});if(e){y(!0),x(null);try{await qe(e),a(),i()}catch(e){x(e instanceof Error?e.message:n.saveError)}finally{y(!1)}}},F=async()=>{if(t)try{let{[e]:n,...r}=t.providers;await qe({providers:r}),a(),i()}catch{}},I=(e,t)=>{A({model:e,isNew:t}),O(!0)},L=async e=>{if(!k)return;let t=k.isNew?[...m,e]:m.map(t=>t.id===e.id?e:t);h(t);let r=j({models:t});if(r)try{await qe(r),a()}catch(e){x(e instanceof Error?e.message:n.saveError)}},R=async e=>{let t=m.filter(t=>t.id!==e);h(t),E(null);let r=j({models:t});if(r)try{await qe(r),a()}catch(e){x(e instanceof Error?e.message:n.saveError)}};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-edge-subtle px-5 py-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(ye,{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)(me,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:l(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,w.press),children:(0,$.jsx)(P,{className:`size-4`,"aria-hidden":!0})})})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 overflow-y-auto px-5 py-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`manage-base-url`,className:`text-sm font-medium text-fg`,children:n.baseUrlLabel}),(0,$.jsx)(`input`,{id:`manage-base-url`,type:`url`,autoComplete:`off`,value:c,onChange:e=>d(e.target.value),className:l(`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,U)})]}),(0,$.jsx)(tr,{providerId:e,inputId:`manage-custom-api-key`,value:f,onChange:p,labels:{apiKeyLabel:n.apiKeyLabel,apiKeyPlaceholder:n.apiKeyPlaceholder,maskedHelp:n.maskedHelp,copy:n.copy,copied:n.copied,show:n.showKey,hide:n.hideKey,notInConfigFile:n.notInConfigFile,loadFailed:n.loadFailed}}),(0,$.jsxs)(`label`,{className:`flex items-start gap-3 rounded-xl border border-edge-subtle bg-surface-panel/40 p-3`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:g,onChange:e=>_(e.target.checked),className:`mt-0.5 size-4 rounded border-edge accent-accent`}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`block text-sm font-medium text-fg`,children:r===`zh`?`自动同步模型目录`:`Automatically sync model catalog`}),(0,$.jsx)(`span`,{className:`mt-0.5 block text-xs text-fg-muted`,children:r===`zh`?`启动时及定时从此服务的 /models 接口更新模型。`:`Update models from this service’s /models endpoint at startup and on schedule.`})]})]}),(0,$.jsxs)(`div`,{className:`border-t border-edge-subtle pt-3`,children:[(0,$.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,$.jsxs)(`span`,{className:`text-sm font-semibold text-fg`,children:[o.modelsSection,m.length>0?` (${m.length})`:``]}),(0,$.jsxs)(W,{type:`button`,variant:`primary`,className:`gap-1.5 px-2 py-1 text-xs`,onClick:()=>I(null,!0),children:[(0,$.jsx)(te,{className:`size-3.5`,"aria-hidden":!0}),o.addModel]})]}),m.length===0?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:o.modelsEmpty}):(0,$.jsx)(`ul`,{className:`space-y-2`,children:m.map(e=>(0,$.jsxs)(`li`,{className:`flex items-center justify-between gap-2 rounded-lg border border-edge-subtle bg-surface-panel/40 px-3 py-2`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`truncate text-sm font-medium text-fg`,children:e.id}),e.name&&e.name!==e.id?(0,$.jsx)(`div`,{className:`truncate text-xs text-fg-muted`,children:e.name}):null]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(0,$.jsx)(`button`,{type:`button`,className:l(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,w.press),onClick:()=>I(e,!1),"aria-label":o.editModel,children:(0,$.jsx)($e,{className:`size-3.5`,"aria-hidden":!0})}),(0,$.jsx)(`button`,{type:`button`,className:l(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-red-600 dark:hover:text-red-400`,w.press),onClick:()=>E(e.id),"aria-label":o.removeModel,children:(0,$.jsx)(be,{className:`size-3.5`,"aria-hidden":!0})})]})]},e.id))})]}),b?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:b}):null]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-t border-edge-subtle px-5 py-3`,children:[(0,$.jsxs)(W,{type:`button`,variant:`ghost`,className:`gap-1.5 text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300`,onClick:()=>C(!0),children:[(0,$.jsx)(be,{className:`size-3.5`,"aria-hidden":!0}),n.remove]}),(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsx)(W,{type:`button`,variant:`primary`,disabled:v,onClick:()=>void N(),children:v?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(X,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),n.saving]}):n.save})})]}),(0,$.jsx)(We,{open:S,title:n.removeConfirmTitle,description:n.removeConfirmDescription.replace(`{{provider}}`,e),confirmLabel:n.removeConfirmAction,cancelLabel:n.cancel,destructive:!0,onConfirm:()=>void F(),onCancel:()=>C(!1)}),(0,$.jsx)(We,{open:T!==null,title:o.removeModel,description:o.removeModelConfirm.replace(`{{id}}`,T??``),confirmLabel:n.removeConfirmAction,cancelLabel:n.cancel,destructive:!0,onConfirm:()=>{T&&R(T)},onCancel:()=>E(null)}),(0,$.jsx)($n,{open:D,onOpenChange:e=>{O(e),e||A(null)},providerId:e,model:k?.model??null,isNew:k?.isNew??!1,onSave:e=>void L(e),m:o})]})}async function or(){let e=await p(m(`/api/models/catalog`)),t=await e.json().catch(()=>null);if(!e.ok||!t?.ok||!t.payload)throw Error(t?.error?.message??`HTTP ${e.status}`);return t.payload}function sr(){let e=f(e=>e.language)===`zh`,{data:t,error:n,isLoading:r}=g(F,or,{revalidateOnFocus:!1}),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(null);if(r)return(0,$.jsx)(Ve,{className:`h-24 w-full rounded-2xl`});let c=Object.values(t?.sources??{}),l=c.reduce((e,t)=>e+t.models.filter(e=>e.availability===`available`).length,0),u=(t?.references??[]).filter(e=>e.availability===`unavailable`),d=t?.sync.lastSuccessAt??Math.max(0,...c.map(e=>e.lastSuccessAt)),h=o??(n instanceof Error?n.message:t?.sync.lastError??Object.values(t?.sync.sourceErrors??{})[0]),_=async()=>{a(!0),s(null);try{let e=await p(m(`/api/models/catalog/refresh`),{method:`POST`});if(!e.ok)throw Error(`HTTP ${e.status}`);await ve()}catch(t){s(t instanceof Error?t.message:e?`模型目录刷新失败`:`Model catalog refresh failed`)}finally{a(!1)}};return(0,$.jsx)(`div`,{className:`rounded-2xl border border-edge-subtle bg-surface-panel/40 p-4`,children:(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[h||u.length>0?(0,$.jsx)(L,{className:`size-4 text-amber-500`,"aria-hidden":!0}):(0,$.jsx)(Oe,{className:`size-4 text-emerald-500`,"aria-hidden":!0}),(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:e?`模型目录同步`:`Model catalog sync`})]}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e?`${c.length} 个来源,${l} 个可用模型${d?` · 最近同步 ${new Date(d).toLocaleString()}`:``}`:`${c.length} sources, ${l} available models${d?` · Last synced ${new Date(d).toLocaleString()}`:``}`}),u.length>0?(0,$.jsx)(`div`,{className:`mt-2 space-y-1 text-sm text-amber-700 dark:text-amber-300`,children:u.slice(0,3).map(t=>(0,$.jsxs)(`p`,{children:[t.ref,` `,e?`不可用`:`is unavailable`,t.suggestedRef?` · ${e?`建议`:`Suggested`} ${t.suggestedRef}`:``,` · ${t.locations.length} ${e?`处引用`:`references`}`]},t.ref))}):null,h?(0,$.jsx)(`p`,{className:`mt-2 text-sm text-danger`,children:h}):null]}),(0,$.jsxs)(W,{type:`button`,variant:`secondary`,disabled:i,onClick:()=>void _(),children:[i?(0,$.jsx)(X,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(T,{className:`size-4`,"aria-hidden":!0}),i?e?`刷新中…`:`Refreshing…`:e?`立即刷新`:`Refresh now`]})]})})}function cr(e){return G.includes(e)}function lr(){let e=(0,Z.c)(79),t=f(fr),n;e[0]===t?n=e[1]:(n=u(t),e[0]=t,e[1]=n);let r=n,l=r.capabilitiesSettings,d=a(),[p,m]=i(),{capability:h}=c(),g=bt(dr),[_,v]=(0,Q.useState)(!1),[y,b]=(0,Q.useState)(null),x=Vn(),S,C;e[2]!==h||e[3]!==p||e[4]!==m?(S=()=>{if(h!==`models`||p.get(`add`)!==`1`)return;v(!0);let e=new URLSearchParams(p);e.delete(`add`),m(e,{replace:!0})},C=[h,p,m],e[2]=h,e[3]=p,e[4]=m,e[5]=S,e[6]=C):(S=e[5],C=e[6]),(0,Q.useEffect)(S,C);let w;e[7]!==l.unsavedChanges||e[8]!==g?(w=e=>g.get(e)?.dirty?(0,$.jsx)(`span`,{className:`size-1.5 rounded-full bg-amber-500`,"aria-label":l.unsavedChanges,title:l.unsavedChanges}):void 0,e[7]=l.unsavedChanges,e[8]=g,e[9]=w):w=e[9];let T=w,E;e[10]!==l.modelsHint||e[11]!==l.tabs.models?(E={id:`models`,icon:ie,label:l.tabs.models,hint:l.modelsHint},e[10]=l.modelsHint,e[11]=l.tabs.models,e[12]=E):E=e[12];let D=l.tabs.image,O=l.imageHint,k;e[13]===T?k=e[14]:(k=T(`image-models`),e[13]=T,e[14]=k);let A;e[15]!==l.imageHint||e[16]!==l.tabs.image||e[17]!==k?(A={id:`image`,icon:se,label:D,hint:O,suffix:k},e[15]=l.imageHint,e[16]=l.tabs.image,e[17]=k,e[18]=A):A=e[18];let j=l.tabs.voice,M=l.voiceHint,N;e[19]===T?N=e[20]:(N=T(`voice`),e[19]=T,e[20]=N);let P;e[21]!==l.tabs.voice||e[22]!==l.voiceHint||e[23]!==N?(P={id:`voice`,icon:ge,label:j,hint:M,suffix:N},e[21]=l.tabs.voice,e[22]=l.voiceHint,e[23]=N,e[24]=P):P=e[24];let F=l.tabs.search,I=l.searchHint,L;e[25]===T?L=e[26]:(L=T(`search`),e[25]=T,e[26]=L);let R;e[27]!==l.searchHint||e[28]!==l.tabs.search||e[29]!==L?(R={id:`search`,icon:Ze,label:F,hint:I,suffix:L},e[27]=l.searchHint,e[28]=l.tabs.search,e[29]=L,e[30]=R):R=e[30];let z;e[31]!==P||e[32]!==R||e[33]!==E||e[34]!==A?(z=[E,A,P,R],e[31]=P,e[32]=R,e[33]=E,e[34]=A,e[35]=z):z=e[35];let B=z,V;e[36]===d?V=e[37]:(V=e=>d(Ee(e)),e[36]=d,e[37]=V);let H=V,U=ur;if(!cr(h)){let t;return e[38]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(o,{to:Ee(`models`),replace:!0}),e[38]=t):t=e[38],t}let ee=r.nav.settingsCapabilities,te=l.subtitle,ne;e[39]===t?ne=e[40]:(ne=Ge(t,`configuration`),e[39]=t,e[40]=ne);let re;e[41]===Symbol.for(`react.memo_cache_sentinel`)?(re=(0,$.jsx)(de,{className:`size-4`,"aria-hidden":!0}),e[41]=re):re=e[41];let ae;e[42]===l.agentSettingsLink?ae=e[43]:(ae=(0,$.jsx)(W,{asChild:!0,variant:`secondary`,children:(0,$.jsxs)(s,{to:`/agents`,children:[re,l.agentSettingsLink]})}),e[42]=l.agentSettingsLink,e[43]=ae);let G;e[44]!==l.docsLink||e[45]!==l.subtitle||e[46]!==r.nav.settingsCapabilities||e[47]!==ne||e[48]!==ae?(G=(0,$.jsx)(nt,{title:ee,subtitle:te,docsLink:ne,docsLabel:l.docsLink,actions:ae}),e[44]=l.docsLink,e[45]=l.subtitle,e[46]=r.nav.settingsCapabilities,e[47]=ne,e[48]=ae,e[49]=G):G=e[49];let oe;e[50]===Symbol.for(`react.memo_cache_sentinel`)?(oe=(0,$.jsx)(xt,{}),e[50]=oe):oe=e[50];let K;e[51]!==l.tabsAria||e[52]!==h||e[53]!==B||e[54]!==H?(K=(0,$.jsx)(vt,{items:B,activeTab:h,onChange:H,ariaLabel:l.tabsAria,tabIdPrefix:`capability-tab`,panelIdPrefix:`capability-panel`}),e[51]=l.tabsAria,e[52]=h,e[53]=B,e[54]=H,e[55]=K):K=e[55];let q;e[56]!==l.connectedProviders||e[57]!==h||e[58]!==B?(q=B.map(e=>(0,$.jsx)(mr,{id:e.id,activeSection:h,hint:e.hint,children:e.id===`models`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(sr,{}),(0,$.jsx)(qn,{labels:l.connectedProviders,onAdd:()=>v(!0),onManage:(e,t)=>b({providerId:e,isCustom:t})})]}):(0,$.jsx)(pr,{section:e.id})},e.id)),e[56]=l.connectedProviders,e[57]=h,e[58]=B,e[59]=q):q=e[59];let ce;e[60]!==_||e[61]!==l.addProviderDialog||e[62]!==t||e[63]!==x.builtinRows||e[64]!==x.customConfig?(ce=(0,$.jsx)(Pn,{open:_,onOpenChange:v,builtinRows:x.builtinRows,customConfig:x.customConfig,labels:l.addProviderDialog,language:t,onSaved:U}),e[60]=_,e[61]=l.addProviderDialog,e[62]=t,e[63]=x.builtinRows,e[64]=x.customConfig,e[65]=ce):ce=e[65];let le;e[66]!==l.manageProviderDialog||e[67]!==t||e[68]!==y||e[69]!==x.allModels||e[70]!==x.builtinRows||e[71]!==x.customConfig?(le=y?(0,$.jsx)(rr,{open:!0,onOpenChange:e=>{e||b(null)},providerId:y.providerId,isCustom:y.isCustom,builtinRows:x.builtinRows,customConfig:x.customConfig,allModels:x.allModels,labels:l.manageProviderDialog,language:t,onSaved:U}):null,e[66]=l.manageProviderDialog,e[67]=t,e[68]=y,e[69]=x.allModels,e[70]=x.builtinRows,e[71]=x.customConfig,e[72]=le):le=e[72];let ue;return e[73]!==G||e[74]!==K||e[75]!==q||e[76]!==ce||e[77]!==le?(ue=(0,$.jsxs)(rt,{children:[G,oe,K,q,ce,le]}),e[73]=G,e[74]=K,e[75]=q,e[76]=ce,e[77]=le,e[78]=ue):ue=e[78],ue}function ur(){ve()}function dr(e){return e.sections}function fr(e){return e.language}function pr(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)(kt,{}),t[0]=e):e=t[0],e}case`voice`:{let e;return t[1]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(nn,{}),t[1]=e):e=t[1],e}case`search`:{let e;return t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(kn,{}),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:l(`min-w-0 rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,i?`flex flex-col gap-3`:void 0),children:[i?(0,$.jsx)(`p`,{className:`text-sm leading-relaxed text-fg-muted`,children:n}):null,r]}):null}export{lr as CapabilitiesSettingsPanel};
@@ -1 +1 @@
1
- import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,t as n}from"./vendor-react-BOUWij0V.js";import{r,s as i}from"./locale-store-C_ax27uc.js";import{i as a}from"./vendor-swr-BIWyz7Rc.js";import{It as o,Nc as s,Ns as c,Xn as l,Ys as u,Zn as d}from"./index-CfOzvGDb.js";import{s as f}from"./typed-models-lib-QMF30Yvh.js";var p=[{key:`code-intelligence`,toolIds:[`code_search`,`code_read_symbol`,`code_trace`,`code_impact`,`code_architecture`]},{key:`workspace`,toolIds:[`read_file`,`write_file`,`apply_patch`,`list_dir`,`grep`,`find`]},{key:`execution`,toolIds:[`exec_command`,`execute_code`]},{key:`messaging`,toolIds:[`send_message`,`send_media`,`text_to_speech`]},{key:`memory`,toolIds:[`memory_search`,`memory_get`,`curated_memory`,`session_search`]},{key:`media`,toolIds:[`image`,`image_generate`,`read_media`,`create_share`]},{key:`web`,toolIds:[`web_search`,`web_fetch`,`web_extract`,`browser_use`]},{key:`misc`,toolIds:[`session_status`,`dreaming`,`tool_manual`,`clarify`,`todo`,`update_plan`,`automation`,`workflow`,`delegate_task`]},{key:`unknown`,toolIds:[`skills_list`,`skill_view`,`skill_manage`]},{key:`extensions`,toolIds:[`extensions`]},{key:`mcp`,toolIds:[`bundle-mcp`]}],m=new Set(p.flatMap(e=>[...e.toolIds].map(e=>String(e))));function h(e){return e.filter(e=>e&&!m.has(e)).sort((e,t)=>e.localeCompare(t))}var g=e(t(),1),_=n(),v=[`deep`,`fast`,`cheap`,`code`,`review`];function y(e){return v.includes(e)}function b(e){let{rows:t,onChange:n,disabled:r,defaultRole:i,chat:p,labels:m}=e,{data:h=[]}=a(l,d,{revalidateOnFocus:!1}),b=(0,g.useMemo)(()=>new Set(h.filter(e=>e.vision===!0).map(e=>e.id)),[h]),x=(0,g.useRef)([]),S=(0,g.useRef)(0);for(;x.current.length<t.length;)x.current.push(`typed-model-row-${S.current++}`);x.current.length>t.length&&(x.current.length=t.length);let C=(e,r)=>{n(t.map((t,n)=>n===e?{...t,...r}:t))},w=(e,n,r)=>{let i=t[e];if(!i)return;let a=[...i.fallbacks??[]];a[n]=r,C(e,{fallbacks:a})},T=e=>{let n=t[e];n&&C(e,{fallbacks:[...n.fallbacks??[],``]})},E=(e,n)=>{let r=t[e];r&&C(e,{fallbacks:(r.fallbacks??[]).filter((e,t)=>t!==n)})},D=e=>{x.current.splice(e,1),n(t.filter((t,n)=>n!==e))},O=e=>{x.current.push(`typed-model-row-${S.current++}`),n([...t,e])},k=t.find(e=>e.model.trim())?.model??``,A=t.map((e,t)=>({row:e,index:t})),j=v.map(e=>A.find(t=>t.row.id===e)).filter(e=>!!e),M=A.filter(e=>!y(e.row.id)),N=v.filter(e=>!t.some(t=>t.id===e)),P=(e,t)=>{let{row:n,index:a}=e,l=n.id===i,d=[n.model,...n.fallbacks??[]].some(e=>b.has(e.trim())),h=y(n.id)?m.roleNames[n.id]:m.id,g=y(n.id)?m.roleDescriptions[n.id]:``;return(0,_.jsxs)(`div`,{className:`grid gap-3 rounded-lg bg-surface-panel/70 p-3 shadow-surface lg:grid-cols-[minmax(0,11rem)_minmax(0,1fr)_auto] lg:items-start`,children:[t.recommended?(0,_.jsxs)(`div`,{className:`min-w-0`,children:[(0,_.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,_.jsx)(`span`,{className:`truncate text-sm font-medium text-fg`,children:h}),l?(0,_.jsx)(`span`,{className:`shrink-0 rounded-full border border-accent/25 bg-accent/10 px-2 py-0.5 text-[11px] font-medium text-accent`,children:m.defaultBadge}):null,d?(0,_.jsx)(`span`,{className:`shrink-0 rounded-full border border-accent/25 bg-accent/10 px-2 py-0.5 text-[11px] font-medium text-accent`,children:m.visionBadge}):null]}),(0,_.jsx)(`div`,{className:`mt-1 truncate font-mono text-[11px] text-fg-subtle`,children:n.id}),g?(0,_.jsx)(`div`,{className:`mt-1 line-clamp-2 text-xs text-fg-muted`,children:g}):null]}):(0,_.jsxs)(`div`,{className:`min-w-0`,children:[(0,_.jsxs)(`div`,{className:`mb-1 flex items-center gap-2 text-xs font-medium text-fg-muted`,children:[(0,_.jsx)(`span`,{children:m.id}),d?(0,_.jsx)(`span`,{className:`shrink-0 rounded-full border border-accent/25 bg-accent/10 px-2 py-0.5 text-[11px] font-medium text-accent`,children:m.visionBadge}):null]}),(0,_.jsx)(`input`,{type:`text`,className:f(),value:n.id,disabled:r,placeholder:m.idPlaceholder,"aria-label":m.id,onChange:e=>C(a,{id:e.target.value.toLowerCase()})})]}),(0,_.jsxs)(`div`,{className:`grid min-w-0 gap-2`,children:[(0,_.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,_.jsx)(`div`,{className:`text-xs font-medium text-fg-muted`,children:m.primaryModel}),(0,_.jsx)(o,{value:n.model,disabled:r,placeholder:p.modelPlaceholder,searchPlaceholder:p.modelSearchPlaceholder,noMatches:p.modelNoMatches,className:`w-full max-w-none`,contentAlign:`start`,onChange:e=>C(a,{model:e})}),d?(0,_.jsx)(`div`,{className:`text-xs leading-relaxed text-fg-muted`,children:m.visionAutoHint}):null]}),(0,_.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,_.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,_.jsx)(`div`,{className:`text-xs font-medium text-fg-muted`,children:m.fallbackModels}),(0,_.jsxs)(c,{type:`button`,variant:`secondary`,className:`h-7 gap-1 px-2 text-xs`,disabled:r,onClick:()=>T(a),children:[(0,_.jsx)(s,{className:`size-3.5`,strokeWidth:1.75}),m.addFallback]})]}),(n.fallbacks??[]).length>0?(0,_.jsx)(`div`,{className:`grid gap-1.5`,children:(n.fallbacks??[]).map((e,t)=>(0,_.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] gap-2`,children:[(0,_.jsx)(o,{value:e,disabled:r,placeholder:m.fallbackPlaceholder,searchPlaceholder:p.modelSearchPlaceholder,noMatches:p.modelNoMatches,className:`w-full max-w-none`,contentAlign:`start`,onChange:e=>w(a,t,e)}),(0,_.jsx)(c,{type:`button`,variant:`secondary`,className:`shrink-0 px-2`,disabled:r,"aria-label":m.removeFallback,onClick:()=>E(a,t),children:(0,_.jsx)(u,{className:`size-4`,strokeWidth:1.75})})]},`${x.current[a]??a}-fallback-${t}`))}):(0,_.jsx)(`div`,{className:`rounded-lg bg-surface-panel/60 px-3 py-2 text-xs text-fg-muted shadow-surface`,children:m.fallbackEmptyHint})]}),(0,_.jsx)(`input`,{type:`text`,className:f(),value:n.description,disabled:r,placeholder:m.descriptionPlaceholder,"aria-label":m.description,onChange:e=>C(a,{description:e.target.value})})]}),(0,_.jsx)(c,{type:`button`,variant:`secondary`,className:`shrink-0 sm:mt-0`,disabled:r||l,"aria-label":m.remove,onClick:()=>D(a),children:(0,_.jsx)(u,{className:`size-4`,strokeWidth:1.75})})]},x.current[a]??`typed-model-row-${a}`)};return(0,_.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,_.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,_.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-fg-muted`,children:m.recommendedTitle}),j.map(e=>P(e,{recommended:!0})),N.length>0?(0,_.jsx)(`div`,{className:`flex flex-wrap gap-2 pt-1`,children:N.map(e=>(0,_.jsxs)(c,{type:`button`,variant:`secondary`,className:`h-8 gap-1.5 rounded-lg px-2.5 text-xs`,disabled:r,onClick:()=>O({id:e,description:m.roleDescriptions[e],model:k,fallbacks:[]}),children:[(0,_.jsx)(s,{className:`size-3.5 shrink-0`,strokeWidth:1.75}),m.addPurpose.replace(`{name}`,m.roleNames[e])]},e))}):null]}),(0,_.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,_.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-fg-muted`,children:m.customTitle}),M.length>0?M.map(e=>P(e,{recommended:!1})):(0,_.jsx)(`div`,{className:`rounded-lg bg-surface-panel/60 px-3 py-2 text-sm text-fg-muted shadow-surface`,children:m.noCustomRoles})]}),(0,_.jsxs)(c,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,disabled:r,onClick:()=>O({id:``,description:``,model:k,fallbacks:[]}),children:[(0,_.jsx)(s,{className:`size-4 shrink-0`,strokeWidth:1.75}),m.add]})]})}async function x(){let e=await i(r(`/api/capability-presets`));if(!Array.isArray(e.payload?.presets)||typeof e.payload.defaultPresetId!=`string`||!Array.isArray(e.payload.agents)||!Array.isArray(e.payload.builtinToolIds))throw Error(`Invalid /api/capability-presets response`);return e.payload}async function S(e){let t=await i(r(`/api/capability-presets`),{method:`POST`,body:JSON.stringify(e)}),n=t.payload?.presetId,a=t.payload?.presets;if(!n||!a||typeof a.defaultPresetId!=`string`||!Array.isArray(a.presets)||!Array.isArray(a.agents)||!Array.isArray(a.builtinToolIds))throw Error(`Invalid create capability preset response`);return{presetId:n,presets:a}}async function C(e,t){let n=await i(r(`/api/capability-presets/${encodeURIComponent(e)}`),{method:`PATCH`,body:JSON.stringify(t)});if(!Array.isArray(n.payload?.presets)||typeof n.payload.defaultPresetId!=`string`||!Array.isArray(n.payload.agents)||!Array.isArray(n.payload.builtinToolIds))throw Error(`Invalid update capability preset response`);return n.payload}async function w(e){let t=await i(r(`/api/capability-presets/${encodeURIComponent(e)}`),{method:`DELETE`});if(!Array.isArray(t.payload?.presets)||typeof t.payload.defaultPresetId!=`string`||!Array.isArray(t.payload.agents)||!Array.isArray(t.payload.builtinToolIds))throw Error(`Invalid delete capability preset response`);return t.payload}export{b as a,C as i,w as n,p as o,x as r,h as s,S as t};
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,t as n}from"./vendor-react-BOUWij0V.js";import{r,s as i}from"./locale-store-C_ax27uc.js";import{i as a}from"./vendor-swr-BIWyz7Rc.js";import{It as o,Nc as s,Ns as c,Xn as l,Ys as u,Zn as d}from"./index-BhQMnKH1.js";import{s as f}from"./typed-models-lib-Bi1uoxFR.js";var p=[{key:`code-intelligence`,toolIds:[`code_search`,`code_read_symbol`,`code_trace`,`code_impact`,`code_architecture`]},{key:`workspace`,toolIds:[`read_file`,`write_file`,`apply_patch`,`list_dir`,`grep`,`find`]},{key:`execution`,toolIds:[`exec_command`,`execute_code`]},{key:`messaging`,toolIds:[`send_message`,`send_media`,`text_to_speech`]},{key:`memory`,toolIds:[`memory_search`,`memory_get`,`curated_memory`,`session_search`]},{key:`media`,toolIds:[`image`,`image_generate`,`read_media`,`create_share`]},{key:`web`,toolIds:[`web_search`,`web_fetch`,`web_extract`,`browser_use`]},{key:`misc`,toolIds:[`session_status`,`dreaming`,`tool_manual`,`clarify`,`todo`,`update_plan`,`automation`,`workflow`,`delegate_task`]},{key:`unknown`,toolIds:[`skills_list`,`skill_view`,`skill_manage`]},{key:`extensions`,toolIds:[`extensions`]},{key:`mcp`,toolIds:[`bundle-mcp`]}],m=new Set(p.flatMap(e=>[...e.toolIds].map(e=>String(e))));function h(e){return e.filter(e=>e&&!m.has(e)).sort((e,t)=>e.localeCompare(t))}var g=e(t(),1),_=n(),v=[`deep`,`fast`,`cheap`,`code`,`review`];function y(e){return v.includes(e)}function b(e){let{rows:t,onChange:n,disabled:r,defaultRole:i,chat:p,labels:m}=e,{data:h=[]}=a(l,d,{revalidateOnFocus:!1}),b=(0,g.useMemo)(()=>new Set(h.filter(e=>e.vision===!0).map(e=>e.id)),[h]),x=(0,g.useRef)([]),S=(0,g.useRef)(0);for(;x.current.length<t.length;)x.current.push(`typed-model-row-${S.current++}`);x.current.length>t.length&&(x.current.length=t.length);let C=(e,r)=>{n(t.map((t,n)=>n===e?{...t,...r}:t))},w=(e,n,r)=>{let i=t[e];if(!i)return;let a=[...i.fallbacks??[]];a[n]=r,C(e,{fallbacks:a})},T=e=>{let n=t[e];n&&C(e,{fallbacks:[...n.fallbacks??[],``]})},E=(e,n)=>{let r=t[e];r&&C(e,{fallbacks:(r.fallbacks??[]).filter((e,t)=>t!==n)})},D=e=>{x.current.splice(e,1),n(t.filter((t,n)=>n!==e))},O=e=>{x.current.push(`typed-model-row-${S.current++}`),n([...t,e])},k=t.find(e=>e.model.trim())?.model??``,A=t.map((e,t)=>({row:e,index:t})),j=v.map(e=>A.find(t=>t.row.id===e)).filter(e=>!!e),M=A.filter(e=>!y(e.row.id)),N=v.filter(e=>!t.some(t=>t.id===e)),P=(e,t)=>{let{row:n,index:a}=e,l=n.id===i,d=[n.model,...n.fallbacks??[]].some(e=>b.has(e.trim())),h=y(n.id)?m.roleNames[n.id]:m.id,g=y(n.id)?m.roleDescriptions[n.id]:``;return(0,_.jsxs)(`div`,{className:`grid gap-3 rounded-lg bg-surface-panel/70 p-3 shadow-surface lg:grid-cols-[minmax(0,11rem)_minmax(0,1fr)_auto] lg:items-start`,children:[t.recommended?(0,_.jsxs)(`div`,{className:`min-w-0`,children:[(0,_.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,_.jsx)(`span`,{className:`truncate text-sm font-medium text-fg`,children:h}),l?(0,_.jsx)(`span`,{className:`shrink-0 rounded-full border border-accent/25 bg-accent/10 px-2 py-0.5 text-[11px] font-medium text-accent`,children:m.defaultBadge}):null,d?(0,_.jsx)(`span`,{className:`shrink-0 rounded-full border border-accent/25 bg-accent/10 px-2 py-0.5 text-[11px] font-medium text-accent`,children:m.visionBadge}):null]}),(0,_.jsx)(`div`,{className:`mt-1 truncate font-mono text-[11px] text-fg-subtle`,children:n.id}),g?(0,_.jsx)(`div`,{className:`mt-1 line-clamp-2 text-xs text-fg-muted`,children:g}):null]}):(0,_.jsxs)(`div`,{className:`min-w-0`,children:[(0,_.jsxs)(`div`,{className:`mb-1 flex items-center gap-2 text-xs font-medium text-fg-muted`,children:[(0,_.jsx)(`span`,{children:m.id}),d?(0,_.jsx)(`span`,{className:`shrink-0 rounded-full border border-accent/25 bg-accent/10 px-2 py-0.5 text-[11px] font-medium text-accent`,children:m.visionBadge}):null]}),(0,_.jsx)(`input`,{type:`text`,className:f(),value:n.id,disabled:r,placeholder:m.idPlaceholder,"aria-label":m.id,onChange:e=>C(a,{id:e.target.value.toLowerCase()})})]}),(0,_.jsxs)(`div`,{className:`grid min-w-0 gap-2`,children:[(0,_.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,_.jsx)(`div`,{className:`text-xs font-medium text-fg-muted`,children:m.primaryModel}),(0,_.jsx)(o,{value:n.model,disabled:r,placeholder:p.modelPlaceholder,searchPlaceholder:p.modelSearchPlaceholder,noMatches:p.modelNoMatches,className:`w-full max-w-none`,contentAlign:`start`,onChange:e=>C(a,{model:e})}),d?(0,_.jsx)(`div`,{className:`text-xs leading-relaxed text-fg-muted`,children:m.visionAutoHint}):null]}),(0,_.jsxs)(`div`,{className:`grid gap-1.5`,children:[(0,_.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,_.jsx)(`div`,{className:`text-xs font-medium text-fg-muted`,children:m.fallbackModels}),(0,_.jsxs)(c,{type:`button`,variant:`secondary`,className:`h-7 gap-1 px-2 text-xs`,disabled:r,onClick:()=>T(a),children:[(0,_.jsx)(s,{className:`size-3.5`,strokeWidth:1.75}),m.addFallback]})]}),(n.fallbacks??[]).length>0?(0,_.jsx)(`div`,{className:`grid gap-1.5`,children:(n.fallbacks??[]).map((e,t)=>(0,_.jsxs)(`div`,{className:`grid grid-cols-[minmax(0,1fr)_auto] gap-2`,children:[(0,_.jsx)(o,{value:e,disabled:r,placeholder:m.fallbackPlaceholder,searchPlaceholder:p.modelSearchPlaceholder,noMatches:p.modelNoMatches,className:`w-full max-w-none`,contentAlign:`start`,onChange:e=>w(a,t,e)}),(0,_.jsx)(c,{type:`button`,variant:`secondary`,className:`shrink-0 px-2`,disabled:r,"aria-label":m.removeFallback,onClick:()=>E(a,t),children:(0,_.jsx)(u,{className:`size-4`,strokeWidth:1.75})})]},`${x.current[a]??a}-fallback-${t}`))}):(0,_.jsx)(`div`,{className:`rounded-lg bg-surface-panel/60 px-3 py-2 text-xs text-fg-muted shadow-surface`,children:m.fallbackEmptyHint})]}),(0,_.jsx)(`input`,{type:`text`,className:f(),value:n.description,disabled:r,placeholder:m.descriptionPlaceholder,"aria-label":m.description,onChange:e=>C(a,{description:e.target.value})})]}),(0,_.jsx)(c,{type:`button`,variant:`secondary`,className:`shrink-0 sm:mt-0`,disabled:r||l,"aria-label":m.remove,onClick:()=>D(a),children:(0,_.jsx)(u,{className:`size-4`,strokeWidth:1.75})})]},x.current[a]??`typed-model-row-${a}`)};return(0,_.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,_.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,_.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-fg-muted`,children:m.recommendedTitle}),j.map(e=>P(e,{recommended:!0})),N.length>0?(0,_.jsx)(`div`,{className:`flex flex-wrap gap-2 pt-1`,children:N.map(e=>(0,_.jsxs)(c,{type:`button`,variant:`secondary`,className:`h-8 gap-1.5 rounded-lg px-2.5 text-xs`,disabled:r,onClick:()=>O({id:e,description:m.roleDescriptions[e],model:k,fallbacks:[]}),children:[(0,_.jsx)(s,{className:`size-3.5 shrink-0`,strokeWidth:1.75}),m.addPurpose.replace(`{name}`,m.roleNames[e])]},e))}):null]}),(0,_.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,_.jsx)(`div`,{className:`text-xs font-medium uppercase tracking-wide text-fg-muted`,children:m.customTitle}),M.length>0?M.map(e=>P(e,{recommended:!1})):(0,_.jsx)(`div`,{className:`rounded-lg bg-surface-panel/60 px-3 py-2 text-sm text-fg-muted shadow-surface`,children:m.noCustomRoles})]}),(0,_.jsxs)(c,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,disabled:r,onClick:()=>O({id:``,description:``,model:k,fallbacks:[]}),children:[(0,_.jsx)(s,{className:`size-4 shrink-0`,strokeWidth:1.75}),m.add]})]})}async function x(){let e=await i(r(`/api/capability-presets`));if(!Array.isArray(e.payload?.presets)||typeof e.payload.defaultPresetId!=`string`||!Array.isArray(e.payload.agents)||!Array.isArray(e.payload.builtinToolIds))throw Error(`Invalid /api/capability-presets response`);return e.payload}async function S(e){let t=await i(r(`/api/capability-presets`),{method:`POST`,body:JSON.stringify(e)}),n=t.payload?.presetId,a=t.payload?.presets;if(!n||!a||typeof a.defaultPresetId!=`string`||!Array.isArray(a.presets)||!Array.isArray(a.agents)||!Array.isArray(a.builtinToolIds))throw Error(`Invalid create capability preset response`);return{presetId:n,presets:a}}async function C(e,t){let n=await i(r(`/api/capability-presets/${encodeURIComponent(e)}`),{method:`PATCH`,body:JSON.stringify(t)});if(!Array.isArray(n.payload?.presets)||typeof n.payload.defaultPresetId!=`string`||!Array.isArray(n.payload.agents)||!Array.isArray(n.payload.builtinToolIds))throw Error(`Invalid update capability preset response`);return n.payload}async function w(e){let t=await i(r(`/api/capability-presets/${encodeURIComponent(e)}`),{method:`DELETE`});if(!Array.isArray(t.payload?.presets)||typeof t.payload.defaultPresetId!=`string`||!Array.isArray(t.payload.agents)||!Array.isArray(t.payload.builtinToolIds))throw Error(`Invalid delete capability preset response`);return t.payload}export{b as a,C as i,w as n,p as o,x as r,h as s,S as t};