@xopcai/xopc 0.0.196 → 0.0.197

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 (140) 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-B1oxPli_.js → agent-avatar-dicebear-C5st7lt5.js} +1 -1
  4. package/dist/gateway/static/root/assets/agents-Baxfj44y.js +68 -0
  5. package/dist/gateway/static/root/assets/{app-management-settings-panel-vmuJ_Z6i.js → app-management-settings-panel-S8LhoD6G.js} +1 -1
  6. package/dist/gateway/static/root/assets/{appearance-settings-BMlEoe-G.js → appearance-settings-D8Cd5vDP.js} +1 -1
  7. package/dist/gateway/static/root/assets/apps-page-0uCxKyE5.js +1 -0
  8. package/dist/gateway/static/root/assets/{archive-plugin-BdE4Mati.js → archive-plugin-qL07mwnY.js} +1 -1
  9. package/dist/gateway/static/root/assets/{attachment-load-CTzaQcLV.js → attachment-load-CqSobpdi.js} +1 -1
  10. package/dist/gateway/static/root/assets/automations-page-XyDat125.js +6 -0
  11. package/dist/gateway/static/root/assets/{binary-plugins-B25zTNxl.js → binary-plugins-DBRPyLYE.js} +1 -1
  12. package/dist/gateway/static/root/assets/{block-editor-Cdrf2awF.js → block-editor-6wG1LU7t.js} +46 -46
  13. package/dist/gateway/static/root/assets/{browser-settings-page-BMTmGMM6.js → browser-settings-page-CrYNMR4w.js} +4 -4
  14. package/dist/gateway/static/root/assets/{browser-workflow-inputs-BsmHy0ks.js → browser-workflow-inputs-Abil4puY.js} +1 -1
  15. package/dist/gateway/static/root/assets/{browser-workflows-page-Wx9FrbK-.js → browser-workflows-page-BEu3E0et.js} +1 -1
  16. package/dist/gateway/static/root/assets/capabilities-settings-panel-CvMcDhGf.js +7 -0
  17. package/dist/gateway/static/root/assets/{capability-presets-settings-panel-9T2KXAs1.js → capability-presets-settings-panel-CHJDY-Ih.js} +2 -2
  18. package/dist/gateway/static/root/assets/{channels-settings-DquD4BPQ.js → channels-settings-Ds9BJbcY.js} +1 -1
  19. package/dist/gateway/static/root/assets/{connectors-api-BC-4ftOM.js → connectors-api-CgWjgPSI.js} +1 -1
  20. package/dist/gateway/static/root/assets/connectors-page-NUs-Zf7F.js +2 -0
  21. package/dist/gateway/static/root/assets/{cron-expression-BycQlU8Q.js → cron-expression-ZdDBAoqA.js} +1 -1
  22. package/dist/gateway/static/root/assets/{dependency-picker-BvYqHRz0.js → dependency-picker-BGeB1jpn.js} +1 -1
  23. package/dist/gateway/static/root/assets/{desktop-pet-BOb8sEhN.js → desktop-pet-CsLR4pWB.js} +1 -1
  24. package/dist/gateway/static/root/assets/{desktop-pet-settings-DStgPb82.js → desktop-pet-settings-CCjT1bdo.js} +1 -1
  25. package/dist/gateway/static/root/assets/directory-picker-path-field-C-Te1QN3.js +1 -0
  26. package/dist/gateway/static/root/assets/{extension-debug-page-p83TmZFd.js → extension-debug-page-CD73euAM.js} +1 -1
  27. package/dist/gateway/static/root/assets/{extension-page-DMQ3ovxA.js → extension-page-DAKjpNwd.js} +1 -1
  28. package/dist/gateway/static/root/assets/{extension-settings-page-BcSKEU8s.js → extension-settings-page-BLSNdlgd.js} +1 -1
  29. package/dist/gateway/static/root/assets/{gateway-config-api-C-MmtCc7.js → gateway-config-api-CQrf0k3D.js} +1 -1
  30. package/dist/gateway/static/root/assets/{gateway-settings-CuaRDWbg.js → gateway-settings-CvgH8IJI.js} +1 -1
  31. package/dist/gateway/static/root/assets/{heartbeat-settings-Dm8TrfGa.js → heartbeat-settings-SPpnqbjl.js} +1 -1
  32. package/dist/gateway/static/root/assets/home-page-BFoD6047.js +3 -0
  33. package/dist/gateway/static/root/assets/index-84ys9u-K.js +152 -0
  34. package/dist/gateway/static/root/assets/index-D-srnucP.css +1 -0
  35. package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-BQb06_jl.js → keyboard-shortcuts-settings-HMhxgOuD.js} +1 -1
  36. package/dist/gateway/static/root/assets/local-app-workbench-page-D5uL2_Fd.js +2 -0
  37. package/dist/gateway/static/root/assets/{local-apps-page-DQtsxjGs.js → local-apps-page-DIWkFa3g.js} +1 -1
  38. package/dist/gateway/static/root/assets/{logs-page-CDqIY72S.js → logs-page--6v8qq6y.js} +2 -2
  39. package/dist/gateway/static/root/assets/{management-settings-D7itDEHl.js → management-settings-DtEuS-kR.js} +1 -1
  40. package/dist/gateway/static/root/assets/{markdown-split-Db-KrpOQ.js → markdown-split-DvVBewS4.js} +1 -1
  41. package/dist/gateway/static/root/assets/{media-plugins-CHN66qs0.js → media-plugins-YVj7NVzD.js} +1 -1
  42. package/dist/gateway/static/root/assets/{notes-page-CJtKZM0P.js → notes-page-BDzuL2I9.js} +1 -1
  43. package/dist/gateway/static/root/assets/notes-workbench-IdjuNXvH.js +4 -0
  44. package/dist/gateway/static/root/assets/{page-tabs-HXweXqYE.js → page-tabs-7bSEWfSX.js} +1 -1
  45. package/dist/gateway/static/root/assets/{preview-open-alternatives-Dob6Oe2l.js → preview-open-alternatives-tgLbHgcV.js} +1 -1
  46. package/dist/gateway/static/root/assets/{product-open-page--RnCc9bb.js → product-open-page-Bwx_CQht.js} +1 -1
  47. package/dist/gateway/static/root/assets/project-detail-page-DnJXSuM4.js +1 -0
  48. package/dist/gateway/static/root/assets/projects-page-DckZKlBI.js +1 -0
  49. package/dist/gateway/static/root/assets/remote-access-hub-CfbUHBUH.js +1 -0
  50. package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-Bg1W2__k.js → runtime-tools-settings-panel-Fe05Nus6.js} +1 -1
  51. package/dist/gateway/static/root/assets/{schema-form-BI4rVt3u.js → schema-form-CFfyC4CB.js} +1 -1
  52. package/dist/gateway/static/root/assets/sessions-page-BCfCh4My.js +1 -0
  53. package/dist/gateway/static/root/assets/settings-advanced-gate-Cbi4FvzO.js +1 -0
  54. package/dist/gateway/static/root/assets/{settings-form-section-C7rzhi7x.js → settings-form-section-gEnEYT_3.js} +1 -1
  55. package/dist/gateway/static/root/assets/{settings-loading-skeleton-BS36Mjzz.js → settings-loading-skeleton-BRE_-7Da.js} +1 -1
  56. package/dist/gateway/static/root/assets/{settings-page-BDSd7F9Y.js → settings-page-C1zxCpqB.js} +1 -1
  57. package/dist/gateway/static/root/assets/{settings-page-layout-CTMmZcwj.js → settings-page-layout-CRpXF_05.js} +1 -1
  58. package/dist/gateway/static/root/assets/setup-status-panel-BcHdpmFf.js +1 -0
  59. package/dist/gateway/static/root/assets/{share-preview-page-BeCxg6eb.js → share-preview-page-DU8L68A5.js} +1 -1
  60. package/dist/gateway/static/root/assets/{shares-settings-CXL1EldF.js → shares-settings-kjTqH9yY.js} +1 -1
  61. package/dist/gateway/static/root/assets/skill-reload-api-QAGpwzIM.js +1 -0
  62. package/dist/gateway/static/root/assets/{skills-page-CyfjEM4D.js → skills-page-lE1-YRdK.js} +1 -1
  63. package/dist/gateway/static/root/assets/{skills-page.utils-CnbJncdL.js → skills-page.utils-CYwFWTso.js} +1 -1
  64. package/dist/gateway/static/root/assets/{system-settings-panel-CAv0Yk0Y.js → system-settings-panel-CVDsiPKn.js} +1 -1
  65. package/dist/gateway/static/root/assets/task-detail-page-DsM13-cy.js +1 -0
  66. package/dist/gateway/static/root/assets/{typed-models-lib-DomX3Szl.js → typed-models-lib-DelyYgoc.js} +1 -1
  67. package/dist/gateway/static/root/assets/{use-autosave-BLc4gfG0.js → use-autosave-C50Mq5yQ.js} +1 -1
  68. package/dist/gateway/static/root/assets/{user-context-page-C2kQENTK.js → user-context-page-D-VEOt2A.js} +1 -1
  69. package/dist/gateway/static/root/assets/{voice-api-key-field-BijmpPjb.js → voice-api-key-field-DYfgTe3Y.js} +1 -1
  70. package/dist/gateway/static/root/assets/{work-discovery-overlay-D7w2JFFq.js → work-discovery-overlay-DPbujsp3.js} +1 -1
  71. package/dist/gateway/static/root/assets/work-discovery-page-D77opady.js +1 -0
  72. package/dist/gateway/static/root/assets/{workflow-run-setup-panel-BEmugHfL.js → workflow-run-setup-panel-DqIb1oBB.js} +2 -2
  73. package/dist/gateway/static/root/assets/workflows-page-B9-PLmlX.js +5 -0
  74. package/dist/gateway/static/root/index.html +2 -2
  75. package/dist/package.js +1 -1
  76. package/dist/src/agent/embedded/execution-context.d.ts +2 -0
  77. package/dist/src/agent/embedded/execution-context.js +11 -0
  78. package/dist/src/agent/embedded/index.d.ts +3 -1
  79. package/dist/src/agent/embedded/index.js +5 -3
  80. package/dist/src/agent/embedded/run-turn.js +15 -9
  81. package/dist/src/agent/embedded/session-runner.d.ts +6 -11
  82. package/dist/src/agent/embedded/session-runner.js +25 -36
  83. package/dist/src/agent/embedded/transcript-runtime.d.ts +35 -0
  84. package/dist/src/agent/embedded/transcript-runtime.js +66 -0
  85. package/dist/src/agent/embedded/types.d.ts +3 -1
  86. package/dist/src/agent/service.d.ts +15 -0
  87. package/dist/src/agent/service.js +30 -0
  88. package/dist/src/config/agent-profile.js +1 -1
  89. package/dist/src/gateway/agents-admin.js +1 -1
  90. package/dist/src/gateway/hono/routes/home.d.ts +1 -1
  91. package/dist/src/gateway/hono/routes/home.js +2 -2
  92. package/dist/src/gateway/hono/routes/index.js +2 -0
  93. package/dist/src/gateway/hono/routes/projects.js +12 -1
  94. package/dist/src/gateway/hono/routes/side-chats.d.ts +3 -0
  95. package/dist/src/gateway/hono/routes/side-chats.js +173 -0
  96. package/dist/src/gateway/service/agent-runner.d.ts +4 -0
  97. package/dist/src/gateway/service/agent-runner.js +15 -1
  98. package/dist/src/gateway/service/run-gateway-agent.js +1 -1
  99. package/dist/src/gateway/service.d.ts +4 -0
  100. package/dist/src/gateway/service.js +33 -7
  101. package/dist/src/gateway/side-chat/context-snapshot.d.ts +11 -0
  102. package/dist/src/gateway/side-chat/context-snapshot.js +108 -0
  103. package/dist/src/gateway/side-chat/index.d.ts +5 -0
  104. package/dist/src/gateway/side-chat/index.js +4 -0
  105. package/dist/src/gateway/side-chat/manager.d.ts +45 -0
  106. package/dist/src/gateway/side-chat/manager.js +198 -0
  107. package/dist/src/gateway/side-chat/run-service.d.ts +22 -0
  108. package/dist/src/gateway/side-chat/run-service.js +110 -0
  109. package/dist/src/gateway/side-chat/types.d.ts +61 -0
  110. package/dist/src/gateway/side-chat/types.js +1 -0
  111. package/dist/src/routing/session-key-utils.d.ts +0 -1
  112. package/dist/src/routing/session-key-utils.js +1 -6
  113. package/dist/src/routing/session-key.js +2 -2
  114. package/dist/src/tasks/home-query-service.d.ts +24 -0
  115. package/dist/src/tasks/home-query-service.js +284 -5
  116. package/dist/src/tasks/index.js +3 -3
  117. package/dist/src/tasks/project-operating-view-service.d.ts +2 -1
  118. package/dist/src/tasks/project-operating-view-service.js +27 -4
  119. package/package.json +2 -2
  120. package/dist/gateway/static/root/assets/agents-VoFNMGL3.js +0 -68
  121. package/dist/gateway/static/root/assets/apps-page-CsNB6mv_.js +0 -1
  122. package/dist/gateway/static/root/assets/automations-page-CW1YWgiX.js +0 -6
  123. package/dist/gateway/static/root/assets/capabilities-settings-panel-C5l85__e.js +0 -7
  124. package/dist/gateway/static/root/assets/connectors-page-7zUxVHQg.js +0 -2
  125. package/dist/gateway/static/root/assets/directory-picker-path-field-DUUr9sq0.js +0 -1
  126. package/dist/gateway/static/root/assets/home-page-BYhDbUvI.js +0 -3
  127. package/dist/gateway/static/root/assets/index-BzPwnXho.js +0 -150
  128. package/dist/gateway/static/root/assets/index-CFFYvilx.css +0 -1
  129. package/dist/gateway/static/root/assets/local-app-workbench-page-CHk4x0kR.js +0 -2
  130. package/dist/gateway/static/root/assets/notes-workbench-epHGeKd5.js +0 -4
  131. package/dist/gateway/static/root/assets/project-detail-page-BxOD5-zj.js +0 -1
  132. package/dist/gateway/static/root/assets/projects-page-D-9AhrH5.js +0 -1
  133. package/dist/gateway/static/root/assets/remote-access-hub-CSUNXLKM.js +0 -1
  134. package/dist/gateway/static/root/assets/sessions-page-BxOUBMca.js +0 -1
  135. package/dist/gateway/static/root/assets/settings-advanced-gate-DAvTIbgw.js +0 -1
  136. package/dist/gateway/static/root/assets/setup-status-panel-D1v-2Ci-.js +0 -1
  137. package/dist/gateway/static/root/assets/skill-reload-api-BxwkKgVw.js +0 -1
  138. package/dist/gateway/static/root/assets/task-detail-page-DGTVJs_N.js +0 -1
  139. package/dist/gateway/static/root/assets/work-discovery-page-XtoPgPUS.js +0 -1
  140. package/dist/gateway/static/root/assets/workflows-page-D_K2xOWq.js +0 -5
@@ -0,0 +1,7 @@
1
+ import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{d as i,f as a,l as o,r as s,t as c}from"./chunk-KS7C4IRE-BMhrPKJC.js";import{t as l}from"./cn-JdwAhgNB.js";import{t as u}from"./messages-DQ5X6cXp.js";import{l as d,n as f,o as p,r as m,s as h}from"./locale-store-Bjvw7jtg.js";import{i as g}from"./vendor-swr-BIWyz7Rc.js";import{$ as _,At as v,Bc as y,Bo as b,Bs as x,Cc as S,Cs as C,Ct as w,Ds as T,Dt as E,Du as D,Fo as O,Gc as k,Go as A,Ho as j,Il as M,Io as N,Kc as P,Ko as F,Ll as I,Lo as L,Ms as ee,Mt as R,Na as z,Nt as B,Oc as V,Ot as H,Pt as U,Q as te,Qo as W,Ro as G,Rt as K,Sc as q,Ss as J,St as ne,Tt as re,Uo as ie,Vo as ae,Vs as oe,X as se,Xo as ce,Y as le,Yl as ue,Z as de,Zo as Y,Zs as fe,_r as pe,_s as me,_t as he,at as ge,bo as _e,bt as ve,cc as ye,ct as be,cu as xe,dc as Se,dl as Ce,dt as we,du as Te,ei as Ee,et as De,fs as Oe,ft as ke,gs as Ae,gt as je,hc as Me,hs as Ne,ht as Pe,is as Fe,it as Ie,jn as Le,js as Re,jt as ze,kt as Be,lt as Ve,mt as He,nc as Ue,nt as We,ot as Ge,ps as Ke,pt as qe,rs as Je,rt as Ye,sl as Xe,st as Ze,ti as Qe,tt as $e,ut as et,vs as tt,vt as nt,wc as rt,wn as it,ws as X,wt as at,wu as ot,xl as st,xo as ct,xs as lt,xt as ut,yt as dt,zo as ft,zt as pt}from"./index-84ys9u-K.js";import{n as mt,r as ht}from"./settings-page-layout-CRpXF_05.js";import{t as gt}from"./settings-loading-skeleton-BRE_-7Da.js";import{n as _t,t as vt}from"./use-autosave-C50Mq5yQ.js";import{a as yt,c as bt,d as xt,f as St,i as Ct,l as wt,n as Tt,r as Et,s as Dt,t as Ot,u as kt}from"./voice-api-key-field-DYfgTe3Y.js";import{t as At}from"./settings-advanced-gate-Cbi4FvzO.js";import{n as jt,t as Mt}from"./settings-form-section-gEnEYT_3.js";import{t as Nt}from"./page-tabs-7bSEWfSX.js";var Z=n(),Q=e(t(),1),$=r(),Pt={en:{addTitle:`Add image service`,editTitle:`Manage image service`,intro:`Connect an endpoint that implements the OpenAI Images protocol.`,connection:`Connection`,providerId:`Provider ID`,providerIdHint:`Lowercase letters, numbers, hyphens, or underscores.`,name:`Display name`,baseUrl:`Base URL`,auth:`Authentication`,bearer:`Bearer token`,header:`Custom API key header`,none:`No authentication`,headerName:`Header name`,apiKey:`API key`,apiKeyHint:`Stored in the local credential store, separate from models.json.`,apiKeyUrl:`API key page (optional)`,docsUrl:`Documentation page (optional)`,openKeyPage:`Create API key`,paths:`Protocol and network`,generationsPath:`Generations path`,editsPath:`Edits path`,allowedHosts:`Allowed private hosts (optional)`,allowedHostsHint:`One exact hostname or IP per line. Private endpoints stay blocked unless listed here.`,staticHeaders:`Static headers (optional)`,staticHeadersHint:`One per line: X-Tenant: value. Credential headers are rejected.`,models:`Image models`,addModel:`Add model`,modelId:`Model ID`,modelName:`Name (optional)`,defaultModel:`Default model`,maxCount:`Max images`,defaultCount:`Default count`,defaultSize:`Default size`,format:`Output format`,supportsSize:`Supports size`,edit:`Supports edits`,remove:`Remove`,cancel:`Cancel`,save:`Save service`,saving:`Saving…`,test:`Test generation`,testing:`Generating…`,delete:`Delete service`,confirmDelete:`Delete permanently`,saved:`Image service saved.`,deleted:`Image service deleted.`,testReady:`Test image generated.`,show:`Show key`,hide:`Hide key`,copy:`Copy key`,copied:`Copied`,revealFailed:`Unable to reveal the saved key.`,notRevealable:`No revealable key is stored locally.`,required:`Complete the required connection and model fields.`,duplicateModels:`Model IDs must be unique.`,invalidHeaders:`Static headers must use “Name: value”, one per line.`},zh:{addTitle:`添加图片服务`,editTitle:`管理图片服务`,intro:`连接一个严格实现 OpenAI Images 协议的服务端点。`,connection:`连接信息`,providerId:`Provider ID`,providerIdHint:`仅支持小写字母、数字、连字符和下划线。`,name:`显示名称`,baseUrl:`Base URL`,auth:`认证方式`,bearer:`Bearer Token`,header:`自定义 API Key Header`,none:`无需认证`,headerName:`Header 名称`,apiKey:`API Key`,apiKeyHint:`密钥单独保存在本机凭据存储,不写入 models.json。`,apiKeyUrl:`API Key 创建页面(可选)`,docsUrl:`协议文档页面(可选)`,openKeyPage:`去创建 API Key`,paths:`协议与网络`,generationsPath:`生成路径`,editsPath:`编辑路径`,allowedHosts:`允许访问的私有主机(可选)`,allowedHostsHint:`每行一个精确主机名或 IP;未列出的私网端点保持阻止。`,staticHeaders:`静态 Headers(可选)`,staticHeadersHint:`每行一个:X-Tenant: value。认证 Header 会被拒绝。`,models:`图片模型`,addModel:`添加模型`,modelId:`模型 ID`,modelName:`名称(可选)`,defaultModel:`默认模型`,maxCount:`单次最大张数`,defaultCount:`默认张数`,defaultSize:`默认尺寸`,format:`输出格式`,supportsSize:`支持尺寸参数`,edit:`支持图片编辑`,remove:`移除`,cancel:`取消`,save:`保存服务`,saving:`保存中…`,test:`测试生成`,testing:`生成中…`,delete:`删除服务`,confirmDelete:`确认永久删除`,saved:`图片服务已保存。`,deleted:`图片服务已删除。`,testReady:`测试图片生成成功。`,show:`显示密钥`,hide:`隐藏密钥`,copy:`复制密钥`,copied:`已复制`,revealFailed:`无法查看已保存的密钥。`,notRevealable:`本机没有可查看的密钥。`,required:`请补全必填的连接和模型信息。`,duplicateModels:`模型 ID 不能重复。`,invalidHeaders:`静态 Header 必须使用“名称: 值”格式,每行一个。`}},Ft=`mt-1.5 h-10 w-full rounded-lg border border-edge bg-surface-panel px-3 text-sm text-fg outline-none focus:border-accent focus:ring-2 focus:ring-accent/20`;function It(e){let t=e??{id:``,capabilities:{generate:{maxCount:1,supportsSize:!0},edit:{enabled:!1}}};return{original:t,id:t.id,name:t.name??``,maxCount:String(t.capabilities.generate?.maxCount??1),defaultCount:t.defaults?.count?String(t.defaults.count):``,defaultSize:t.defaults?.size??``,outputFormat:t.defaults?.outputFormat??``,supportsSize:t.capabilities.generate?.supportsSize??!1,editEnabled:t.capabilities.edit?.enabled??!1}}function Lt(e){let t=e.split(`
2
+ `).map(e=>e.trim()).filter(Boolean);if(t.length===0)return;let n=t.map(e=>{let t=e.indexOf(`:`);if(t<=0||!e.slice(t+1).trim())throw Error(`invalid_headers`);return[e.slice(0,t).trim(),e.slice(t+1).trim()]});return Object.fromEntries(n)}function Rt({open:e,onOpenChange:t,provider:n,configured:r,language:i,onSaved:a}){let o=Pt[i],[s,c]=(0,Q.useState)(``),[u,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(``),[m,h]=(0,Q.useState)(`bearer`),[g,_]=(0,Q.useState)(`x-api-key`),[v,y]=(0,Q.useState)(``),[x,S]=(0,Q.useState)(``),[C,w]=(0,Q.useState)(``),[E,k]=(0,Q.useState)(`/images/generations`),[A,j]=(0,Q.useState)(`/images/edits`),[F,I]=(0,Q.useState)(``),[ee,R]=(0,Q.useState)(``),[z,B]=(0,Q.useState)([It()]),[V,H]=(0,Q.useState)(``),[U,W]=(0,Q.useState)(),[K,J]=(0,Q.useState)(!1),[ne,re]=(0,Q.useState)(),[ie,se]=(0,Q.useState)(),[le,ue]=(0,Q.useState)();(0,Q.useEffect)(()=>{if(!e)return;let t=n?.imageGeneration;c(n?.providerId??``),d(t?.name??``),p(n?.baseUrl??``),h(t?.auth.type??`bearer`),_(t?.auth.type===`header`?t.auth.headerName:`x-api-key`),y(r?`••••••••••••`:``),S(t?.apiKeyUrl??``),w(t?.documentationUrl??``),k(t?.paths?.generations??`/images/generations`),j(t?.paths?.edits??`/images/edits`),I(t?.network?.allowedHosts.join(`
3
+ `)??``),R(Object.entries(n?.headers??{}).map(([e,t])=>`${e}: ${t}`).join(`
4
+ `)),B(t?.models.map(It)??[It()]),H(t?.defaultModel??``),se(void 0),W(void 0),J(!1),re(void 0),ue(void 0)},[r,e,n]);let de=(0,Q.useMemo)(()=>z.filter(e=>e.id.trim()).map(e=>({value:e.id.trim(),label:e.name.trim()||e.id.trim()})),[z]),Y=(e,t)=>{B(n=>n.map((n,r)=>r===e?{...n,...t}:n))},fe=()=>{let e=s.trim(),t=z.map(e=>({...e,id:e.id.trim(),name:e.name.trim()}));if(!e||!u.trim()||!f.trim()||t.some(e=>!e.id))throw Error(o.required);if(new Set(t.map(e=>e.id)).size!==t.length)throw Error(o.duplicateModels);let n=V||t[0]?.id;if(!n||!t.some(e=>e.id===n))throw Error(o.required);let r;try{r=Lt(ee)}catch{throw Error(o.invalidHeaders)}return{providerId:e,input:{baseUrl:f.trim(),...r?{headers:r}:{},imageGeneration:{api:`openai-images`,name:u.trim(),...C.trim()?{documentationUrl:C.trim()}:{},...x.trim()?{apiKeyUrl:x.trim()}:{},defaultModel:n,auth:m===`header`?{type:`header`,headerName:g.trim()}:{type:m},paths:{...E.trim()?{generations:E.trim()}:{},...A.trim()?{edits:A.trim()}:{}},...F.trim()?{network:{allowedHosts:F.split(`
5
+ `).map(e=>e.trim()).filter(Boolean)}}:{},models:t.map(e=>({...e.original,id:e.id,...e.name?{name:e.name}:{name:void 0},capabilities:{...e.original.capabilities,generate:{...e.original.capabilities.generate,maxCount:Math.max(1,Number.parseInt(e.maxCount,10)||1),supportsSize:e.supportsSize},edit:{...e.original.capabilities.edit,enabled:e.editEnabled}},defaults:{...e.original.defaults,...e.defaultCount?{count:Math.max(1,Number.parseInt(e.defaultCount,10)||1)}:{count:void 0},...e.defaultSize.trim()?{size:e.defaultSize.trim()}:{size:void 0},...e.outputFormat?{outputFormat:e.outputFormat}:{outputFormat:void 0}}}))}}}},pe=async()=>{let e=fe();return await $e(e.providerId,e.input),m!==`none`&&v.trim()&&!Ae(v)&&await We(e.providerId,v.trim()),await a(e.providerId),e},me=async()=>{W(`save`),re(void 0),se(void 0);try{await pe(),y(m===`none`?``:`••••••••••••`),se(o.saved)}catch(e){re(e instanceof Error?e.message:String(e))}finally{W(void 0)}},he=async()=>{W(`test`),re(void 0),se(void 0),ue(void 0);try{let e=await pe();ue((await Ye(e.providerId,e.input.imageGeneration.defaultModel)).images[0]?.dataUrl),se(o.testReady)}catch(e){re(e instanceof Error?e.message:String(e))}finally{W(void 0)}},ge=async()=>{if(n){if(!K){J(!0);return}W(`delete`),re(void 0);try{await te(n.providerId),await a(),t(!1)}catch(e){re(e instanceof Error?e.message:String(e))}finally{W(void 0)}}};return(0,$.jsx)(O,{open:e,onOpenChange:t,children:(0,$.jsxs)(b,{children:[(0,$.jsx)(ft,{className:l(`xopc-dialog-overlay fixed inset-0 bg-scrim`,Fe)}),(0,$.jsxs)(L,{className:l(`xopc-dialog-content fixed left-1/2 top-1/2 flex h-[min(88vh,760px)] w-[min(calc(100%-2rem),52rem)] -translate-x-1/2 -translate-y-1/2 flex-col overflow-hidden rounded-xl border border-edge bg-surface-panel shadow-popover`,Je),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,$.jsxs)(`header`,{className:`flex shrink-0 items-start justify-between gap-4 border-b border-edge px-5 py-4`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(ae,{className:`font-semibold text-fg`,children:n?o.editTitle:o.addTitle}),(0,$.jsx)(G,{className:`mt-1 text-sm text-fg-muted`,children:o.intro})]}),(0,$.jsx)(N,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:`rounded-md p-1 text-fg-muted hover:bg-surface-subtle hover:text-fg`,"aria-label":o.cancel,children:(0,$.jsx)(T,{className:`size-5`})})})]}),(0,$.jsxs)(`div`,{className:`min-h-0 flex-1 space-y-6 overflow-y-auto px-5 py-4`,children:[(0,$.jsxs)(`section`,{className:`space-y-4`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wide text-fg-subtle`,children:o.connection}),(0,$.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.providerId,(0,$.jsx)(`input`,{value:s,disabled:!!n,onChange:e=>c(e.target.value),placeholder:`my-image-service`,className:Ft}),(0,$.jsx)(`span`,{className:`mt-1 block font-normal text-fg-subtle`,children:o.providerIdHint})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.name,(0,$.jsx)(`input`,{value:u,onChange:e=>d(e.target.value),placeholder:`My Image Service`,className:Ft})]})]}),(0,$.jsxs)(`label`,{className:`block text-xs font-medium text-fg-muted`,children:[o.baseUrl,(0,$.jsx)(`input`,{value:f,onChange:e=>p(e.target.value),placeholder:`https://api.example.com/v1`,className:Ft})]}),(0,$.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.auth,(0,$.jsx)(ce,{value:m,options:[{value:`bearer`,label:o.bearer},{value:`header`,label:o.header},{value:`none`,label:o.none}],placeholder:o.auth,allowEmpty:!1,onChange:e=>h(e),triggerClassName:`mt-1.5`})]}),m===`header`?(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.headerName,(0,$.jsx)(`input`,{value:g,onChange:e=>_(e.target.value),className:Ft})]}):null]}),m===`none`?null:(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`mb-1.5 flex items-center justify-between`,children:[(0,$.jsx)(`label`,{htmlFor:`custom-image-api-key`,className:`text-xs font-medium text-fg-muted`,children:o.apiKey}),x.trim()?(0,$.jsxs)(`a`,{href:x.trim(),target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent hover:underline`,children:[o.openKeyPage,(0,$.jsx)(D,{className:`size-3.5`})]}):null]}),(0,$.jsx)(Ne,{id:`custom-image-api-key`,value:v,onChange:e=>y(Ae(v)?e.replace(/^•+/,``):e),labels:{show:o.show,hide:o.hide,copy:o.copy,copied:o.copied},reveal:()=>ze(s).then(e=>e.apiKey),loadFailedLabel:o.revealFailed,notInConfigFile:o.notRevealable}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:o.apiKeyHint})]}),(0,$.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.apiKeyUrl,(0,$.jsx)(`input`,{value:x,onChange:e=>S(e.target.value),placeholder:`https://…`,className:Ft})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.docsUrl,(0,$.jsx)(`input`,{value:C,onChange:e=>w(e.target.value),placeholder:`https://…`,className:Ft})]})]}),(0,$.jsxs)(`details`,{className:`rounded-lg border border-edge bg-surface-subtle px-3 py-2.5`,children:[(0,$.jsx)(`summary`,{className:`cursor-pointer text-sm font-medium text-fg-muted`,children:o.paths}),(0,$.jsxs)(`div`,{className:`mt-3 grid gap-4 md:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.generationsPath,(0,$.jsx)(`input`,{value:E,onChange:e=>k(e.target.value),className:Ft})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.editsPath,(0,$.jsx)(`input`,{value:A,onChange:e=>j(e.target.value),className:Ft})]})]}),(0,$.jsxs)(`label`,{className:`mt-4 block text-xs font-medium text-fg-muted`,children:[o.allowedHosts,(0,$.jsx)(`textarea`,{value:F,onChange:e=>I(e.target.value),rows:2,placeholder:`127.0.0.1
6
+ image-server.lan`,className:`mt-1.5 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 font-mono text-xs text-fg outline-none focus:border-accent focus:ring-2 focus:ring-accent/20`}),(0,$.jsx)(`span`,{className:`mt-1 block font-normal text-fg-subtle`,children:o.allowedHostsHint})]}),(0,$.jsxs)(`label`,{className:`mt-4 block text-xs font-medium text-fg-muted`,children:[o.staticHeaders,(0,$.jsx)(`textarea`,{value:ee,onChange:e=>R(e.target.value),rows:3,className:`mt-1.5 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 font-mono text-xs text-fg outline-none focus:border-accent focus:ring-2 focus:ring-accent/20`}),(0,$.jsx)(`span`,{className:`mt-1 block font-normal text-fg-subtle`,children:o.staticHeadersHint})]})]})]}),(0,$.jsxs)(`section`,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wide text-fg-subtle`,children:o.models}),(0,$.jsxs)(X,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,onClick:()=>B(e=>[...e,It()]),children:[(0,$.jsx)(q,{className:`size-4`}),o.addModel]})]}),(0,$.jsxs)(`label`,{className:`block text-xs font-medium text-fg-muted`,children:[o.defaultModel,(0,$.jsx)(ce,{value:V||de[0]?.value||``,options:de,placeholder:o.defaultModel,allowEmpty:!1,onChange:H,triggerClassName:`mt-1.5 max-w-sm`})]}),z.map((e,t)=>(0,$.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface-base p-3`,children:[(0,$.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.modelId,(0,$.jsx)(`input`,{value:e.id,onChange:e=>Y(t,{id:e.target.value}),placeholder:`image-1`,className:Ft})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.modelName,(0,$.jsx)(`input`,{value:e.name,onChange:e=>Y(t,{name:e.target.value}),className:Ft})]})]}),(0,$.jsxs)(`div`,{className:`mt-3 grid gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.maxCount,(0,$.jsx)(`input`,{type:`number`,min:1,value:e.maxCount,onChange:e=>Y(t,{maxCount:e.target.value}),className:Ft})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.defaultCount,(0,$.jsx)(`input`,{type:`number`,min:1,value:e.defaultCount,onChange:e=>Y(t,{defaultCount:e.target.value}),className:Ft})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.defaultSize,(0,$.jsx)(`input`,{value:e.defaultSize,onChange:e=>Y(t,{defaultSize:e.target.value}),placeholder:`1024x1024`,className:Ft})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.format,(0,$.jsx)(ce,{value:e.outputFormat,options:[{value:`png`,label:`PNG`},{value:`jpeg`,label:`JPEG`},{value:`webp`,label:`WebP`}],placeholder:o.format,allowEmpty:!0,onChange:e=>Y(t,{outputFormat:e}),triggerClassName:`mt-1.5`})]})]}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-4`,children:[(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:e.supportsSize,onChange:e=>Y(t,{supportsSize:e.target.checked})}),o.supportsSize]}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:e.editEnabled,onChange:e=>Y(t,{editEnabled:e.target.checked})}),o.edit]}),(0,$.jsxs)(`button`,{type:`button`,disabled:z.length===1,onClick:()=>B(e=>e.filter((e,n)=>n!==t)),className:`ml-auto inline-flex items-center gap-1 text-xs text-red-600 disabled:opacity-40 dark:text-red-400`,children:[(0,$.jsx)(oe,{className:`size-3.5`}),o.remove]})]})]},t))]}),le?(0,$.jsxs)(`section`,{className:`rounded-lg border border-edge bg-surface-base p-3`,children:[(0,$.jsxs)(`div`,{className:`mb-2 flex items-center gap-2 text-sm font-medium text-fg`,children:[(0,$.jsx)(M,{className:`size-4`}),o.testReady]}),(0,$.jsx)(`img`,{src:le,alt:`Generated provider test`,className:`max-h-72 rounded-lg object-contain`})]}):null,ie?(0,$.jsx)(`p`,{className:`rounded-lg bg-emerald-500/10 px-3 py-2 text-sm text-emerald-700 dark:text-emerald-300`,role:`status`,children:ie}):null,ne?(0,$.jsx)(`p`,{className:`rounded-lg bg-red-500/10 px-3 py-2 text-sm text-red-600 dark:text-red-400`,children:ne}):null]}),(0,$.jsxs)(`footer`,{className:`flex shrink-0 flex-wrap items-center gap-2 border-t border-edge px-5 py-3`,children:[n?(0,$.jsxs)(X,{variant:`secondary`,className:`border-red-500/30 text-red-600 hover:bg-red-500/10 dark:text-red-400`,disabled:!!U,onClick:()=>void ge(),children:[U===`delete`?(0,$.jsx)(P,{className:`size-4 animate-spin`}):(0,$.jsx)(oe,{className:`size-4`}),K?o.confirmDelete:o.delete]}):null,(0,$.jsxs)(`div`,{className:`ml-auto flex gap-2`,children:[(0,$.jsx)(N,{asChild:!0,children:(0,$.jsx)(X,{variant:`secondary`,children:o.cancel})}),(0,$.jsxs)(X,{variant:`secondary`,disabled:!!U,onClick:()=>void he(),children:[U===`test`?(0,$.jsx)(P,{className:`size-4 animate-spin`}):null,U===`test`?o.testing:o.test]}),(0,$.jsxs)(X,{variant:`primary`,disabled:!!U,onClick:()=>void me(),children:[U===`save`?(0,$.jsx)(P,{className:`size-4 animate-spin`}):null,U===`save`?o.saving:o.save]})]})]})]})]})})}var zt=`••••••••••••`,Bt={en:{title:`Image generation`,intro:`Choose an agent and image model, or connect an OpenAI Images service of your own.`,agent:`Agent`,provider:`Provider`,model:`Model`,apiKey:`API key`,getApiKey:`Get API key`,apiKeyHint:`Stored in the local credential store, never in xopc.json.`,existingKey:`A credential or environment variable is already available. Leave this blank to reuse it.`,savedKey:`A credential is saved. Use the eye button to view it, or type a new key to replace it.`,revealFailed:`Unable to load the saved API key.`,keyNotRevealable:`This credential comes from an environment variable or another non-revealable source.`,advanced:`Provider settings`,enable:`Enable image generation`,enabling:`Verifying and enabling…`,enabled:`Image generation is ready.`,addService:`Add image service`,manageService:`Manage service`,custom:`Custom`,current:`Current`,configured:`Credential ready`,needsKey:`API key required`,connect:`Connect to a gateway to continue.`,loadError:`Unable to load image generation settings.`,selectAgent:`Select an agent`,selectModel:`Select a model`,show:`Show key`,hide:`Hide key`,copy:`Copy key`,copied:`Copied`},zh:{title:`图片生成`,intro:`为 Agent 选择图片模型,也可以连接你自己的 OpenAI Images 服务。`,agent:`Agent`,provider:`Provider`,model:`模型`,apiKey:`API Key`,getApiKey:`获取 API Key`,apiKeyHint:`密钥只保存在本机凭据存储中,不会写入 xopc.json。`,existingKey:`已有凭据或环境变量;留空即可继续使用。`,savedKey:`凭据已保存。点击眼睛可查看,直接输入新密钥可替换。`,revealFailed:`无法读取已保存的 API Key。`,keyNotRevealable:`当前凭据来自环境变量或其他不可查看的来源。`,advanced:`服务商设置`,enable:`启用图片生成`,enabling:`正在验证并启用…`,enabled:`图片生成已可用。`,addService:`添加图片服务`,manageService:`管理服务`,custom:`自定义`,current:`当前使用`,configured:`凭据已就绪`,needsKey:`需要 API Key`,connect:`请先连接网关。`,loadError:`无法加载图片生成设置。`,selectAgent:`选择 Agent`,selectModel:`选择模型`,show:`显示密钥`,hide:`隐藏密钥`,copy:`复制密钥`,copied:`已复制`}};async function Vt(e){let t=await h(m(`/api/agents/${encodeURIComponent(e)}/image-generation`));if(!t.payload)throw Error(`Invalid agent image generation response`);return t.payload}function Ht(e){let t=e?.indexOf(`/`)??-1;return t>0?e.slice(0,t):void 0}function Ut(e){let t=e?.indexOf(`/`)??-1;return t>0?e.slice(t+1):void 0}function Wt(e){return Object.fromEntries(e.configFields.map(t=>[t.key,e.config[t.key]??(t.required?t.options?.[0]?.value??``:``)]))}function Gt(e){let t=(0,Z.c)(11),{field:n,value:r,onChange:i}=e,a;t[0]!==n.label||t[1]!==n.options||t[2]!==n.placeholder||t[3]!==n.required||t[4]!==n.type||t[5]!==i||t[6]!==r?(a=n.type===`select`?(0,$.jsx)(ce,{value:r,options:(n.options??[]).map(Kt),placeholder:n.placeholder??n.label,allowEmpty:!n.required,onChange:i,triggerClassName:`mt-1.5`}):(0,$.jsx)(`input`,{type:`url`,value:r,required:n.required,onChange:e=>i(e.target.value),placeholder:n.placeholder,className:`mt-1.5 h-10 w-full rounded-lg border border-edge bg-surface-panel px-3 text-sm text-fg outline-none focus:border-accent focus:ring-2 focus:ring-accent/20`}),t[0]=n.label,t[1]=n.options,t[2]=n.placeholder,t[3]=n.required,t[4]=n.type,t[5]=i,t[6]=r,t[7]=a):a=t[7];let o;return t[8]!==n.label||t[9]!==a?(o=(0,$.jsxs)(`label`,{className:`block text-xs font-medium text-fg-muted`,children:[n.label,a]}),t[8]=n.label,t[9]=a,t[10]=o):o=t[10],o}function Kt(e){return{value:e.value,label:e.label}}function qt(){let e=(0,Z.c)(2),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(z,{className:`h-24 rounded-xl`}),e[0]=t):t=e[0];let n;return e[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsxs)(`div`,{className:`grid gap-4`,"aria-hidden":`true`,children:[t,(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 xl:grid-cols-3`,children:Array.from({length:5}).map(Jt)}),(0,$.jsx)(z,{className:`h-64 rounded-xl`})]}),e[1]=n):n=e[1],n}function Jt(e,t){return(0,$.jsx)(z,{className:`h-24 rounded-xl`},t)}function Yt(){let e=f(e=>e.language),t=Bt[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,v]=(0,Q.useState)(``),[y,b]=(0,Q.useState)({}),[x,S]=(0,Q.useState)(!1),[C,w]=(0,Q.useState)(),[T,E]=(0,Q.useState)(!1),[O,k]=(0,Q.useState)(!1),[A,j]=(0,Q.useState)(),{data:M,isLoading:N,error:F}=g(r?`image-generation-agents`:null,Le,{revalidateOnFocus:!1}),{data:I,isLoading:L,error:ee,mutate:R}=g(r?m(`/api/image-generation/catalog`):null,De,{revalidateOnFocus:!1}),{data:z,isLoading:B,error:V,mutate:H}=g(r?m(`/api/image-generation/custom-providers`):null,_,{revalidateOnFocus:!1});(0,Q.useEffect)(()=>{!M||i||a(M.defaultId||M.agents[0]?.id||``)},[i,M]);let{data:U,isLoading:te,error:W,mutate:G}=g(r&&i?[`agent-image-generation`,i]:null,()=>Vt(i),{revalidateOnFocus:!1});(0,Q.useEffect)(()=>{if(!I||!U)return;let e=Ht(U.model?.primary),t=I.find(t=>t.id===e)??I.find(e=>e.configured)??I[0];t&&(s(t.id),l(t.id===e&&Ut(U.model?.primary)||t.defaultModel),v(t.configured?zt:``),b(Wt(t)))},[U,I]),(0,Q.useEffect)(()=>{w(void 0)},[i]);let K=I?.find(e=>e.id===o),J=K?K.apiKeyUrl??se(K.id,e)[0]?.href:void 0,ne=(0,Q.useMemo)(()=>(M?.agents??[]).map(e=>({value:e.id,label:it(e,n.agentsSettings)})),[M?.agents,n.agentsSettings]),re=(0,Q.useMemo)(()=>(K?.models??[]).map(e=>({value:e,label:e})),[K?.models]),ie=U?.model?.primary,ae=!!(i&&K&&c&&(K.credentialMode!==`api-key`||K.configured||p.trim())&&K.configFields.every(e=>!e.required||y[e.key]?.trim()));if(!r)return(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.connect});if(N||L||B||te)return(0,$.jsx)(qt,{});if(F||ee||V||W||!I||!M||!z)return(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:t.loadError});let oe=e=>{s(e.id),l(e.defaultModel),v(e.configured?zt:``),b(Wt(e)),w(void 0)},le=()=>{j(void 0),k(!0)},ue=()=>{let e=z.find(e=>e.providerId===K?.id);e&&(j(e),k(!0))},de=async e=>{let[t,n]=await Promise.all([H(),R()]);if(e&&n?.some(t=>t.id===e)){let r=n.find(t=>t.id===e);s(r.id),l(r.defaultModel),v(r.configured?zt:``),b(Wt(r)),j(t?.find(t=>t.providerId===e))}},Y=async()=>{if(!(!K||!ae)){S(!0),w(void 0),E(!1);try{let e=await h(m(`/api/agents/${encodeURIComponent(i)}/image-generation/setup`),{method:`POST`,body:JSON.stringify({providerId:K.id,modelId:c,...p.trim()&&!Ae(p)?{apiKey:p.trim()}:{},providerConfig:Object.fromEntries(Object.entries(y).filter(([,e])=>e.trim()))})});if(!e.payload)throw Error(`Invalid setup response`);await Promise.all([G(e.payload.agent,{revalidate:!1}),R(e.payload.providers,{revalidate:!1})]),v(zt),E(!0)}catch(e){w(e instanceof Error?e.message:String(e))}finally{S(!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)(Ce,{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:ne,placeholder:t.selectAgent,allowEmpty:!1,onChange:a,triggerClassName:`mt-1.5 max-w-md`})]})]}),(0,$.jsxs)(`section`,{children:[(0,$.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-3`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wide text-fg-subtle`,children:t.provider}),(0,$.jsxs)(X,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,onClick:le,children:[(0,$.jsx)(q,{className:`size-4`}),t.addService]})]}),(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 xl:grid-cols-3`,children:I.map(e=>{let n=e.id===o,r=e.id===Ht(ie);return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>oe(e),className:`min-h-24 rounded-xl border p-4 text-left transition-colors ${n?`border-accent bg-accent/5 ring-1 ring-accent/20`:`border-edge bg-surface-base hover:border-edge-strong`}`,children:[(0,$.jsxs)(`span`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`truncate font-medium text-fg`,children:e.label}),e.source===`custom`?(0,$.jsx)(`span`,{className:`rounded-full bg-surface-subtle px-2 py-0.5 text-[10px] text-fg-subtle`,children:t.custom}):null]}),(0,$.jsx)(`span`,{"aria-hidden":!r,className:`shrink-0 rounded-full bg-accent/10 px-2 py-0.5 text-[11px] font-medium text-accent ${r?``:`invisible`}`,children:t.current})]}),(0,$.jsxs)(`span`,{className:`mt-2 flex items-center gap-1.5 text-xs ${e.configured?`text-emerald-600 dark:text-emerald-400`:`text-fg-muted`}`,children:[e.configured||e.credentialMode!==`api-key`?(0,$.jsx)(xe,{className:`size-3.5`}):(0,$.jsx)(Xe,{className:`size-3.5`}),e.configured||e.credentialMode!==`api-key`?t.configured:t.needsKey]})]},e.id)})})]}),K?(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:re,placeholder:t.selectModel,allowEmpty:!1,onChange:l,triggerClassName:`mt-1.5`})]}),K.configFields.filter(e=>e.required).map(e=>(0,$.jsx)(Gt,{field:e,value:y[e.key]??``,onChange:t=>b(n=>({...n,[e.key]:t}))},e.key))]}),K.source===`custom`?(0,$.jsx)(`div`,{className:`mt-4 flex justify-end`,children:(0,$.jsxs)(X,{variant:`secondary`,onClick:ue,children:[(0,$.jsx)(ye,{className:`size-4`}),t.manageService]})}):null,K.credentialMode===`api-key`?(0,$.jsxs)(`div`,{className:`mt-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(`label`,{htmlFor:`image-generation-api-key`,className:`text-xs font-medium text-fg-muted`,children:t.apiKey}),J?(0,$.jsxs)(`a`,{href:J,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs font-medium text-accent hover:underline`,children:[t.getApiKey,(0,$.jsx)(D,{className:`size-3.5`,"aria-hidden":`true`})]}):null]}),(0,$.jsx)(Ne,{id:`image-generation-api-key`,value:p,onChange:e=>v(Ae(p)?e.replace(/^•+/,``):e),placeholder:K.configured?t.existingKey:t.needsKey,labels:{show:t.show,hide:t.hide,copy:t.copy,copied:t.copied},reveal:()=>ze(K.id).then(e=>e.apiKey),loadFailedLabel:t.revealFailed,notInConfigFile:t.keyNotRevealable,className:`mt-1.5`,autoComplete:`new-password`},K.id),(0,$.jsx)(`span`,{className:`mt-1.5 block font-normal leading-relaxed text-fg-subtle`,children:K.configured?t.savedKey:t.apiKeyHint})]}):null,K.configFields.some(e=>!e.required)?(0,$.jsxs)(`details`,{className:`mt-4 rounded-lg border border-edge bg-surface-subtle px-3 py-2.5`,children:[(0,$.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 text-sm font-medium text-fg-muted`,children:[(0,$.jsx)(Ue,{className:`size-4`}),t.advanced]}),(0,$.jsx)(`div`,{className:`mt-3 grid gap-3 md:grid-cols-2`,children:K.configFields.filter(e=>!e.required).map(e=>(0,$.jsx)(Gt,{field:e,value:y[e.key]??``,onChange:t=>b(n=>({...n,[e.key]:t}))},e.key))})]}):null,T?(0,$.jsx)(`p`,{className:`mt-4 rounded-lg bg-emerald-500/10 px-3 py-2 text-sm text-emerald-700 dark:text-emerald-300`,role:`status`,children:t.enabled}):null,C?(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:C}):null,(0,$.jsx)(`div`,{className:`mt-4 flex justify-end`,children:(0,$.jsxs)(X,{variant:`primary`,disabled:!ae||x,onClick:()=>void Y(),children:[x?(0,$.jsx)(P,{className:`size-4 animate-spin`}):(0,$.jsx)(xe,{className:`size-4`}),(0,$.jsxs)(`span`,{className:`grid`,children:[(0,$.jsx)(`span`,{"aria-hidden":!0,className:`invisible col-start-1 row-start-1`,children:t.enable}),(0,$.jsx)(`span`,{"aria-hidden":!0,className:`invisible col-start-1 row-start-1`,children:t.enabling}),(0,$.jsx)(`span`,{className:`col-start-1 row-start-1`,children:x?t.enabling:t.enable})]})]})})]}):null,(0,$.jsx)(Rt,{open:O,onOpenChange:k,provider:A,configured:!!(A&&I.find(e=>e.id===A.providerId)?.configured),language:e,onSaved:de})]})}var Xt=lt;function Zt(){return l(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,C,`dark:border-edge`)}function Qt(){return l(J,lt)}function $t(e){return!e||e<=0?``:e<1024*1024?`${Math.round(e/1024)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function en(e,t){let n=window.atob(e),r=new Uint8Array(n.length);for(let e=0;e<n.length;e++)r[e]=n.charCodeAt(e);return URL.createObjectURL(new Blob([r],{type:t}))}function tn(e,t){switch(e){case`xopc-local`:return t.stt.localProvider;case`openai`:return t.stt.openai;case`alibaba`:return t.stt.alibaba;case`groq`:return`Groq`;default:return e}}function nn(e,t){switch(e){case`openai`:return t.tts.providerOpenai;case`alibaba`:return t.stt.alibaba;case`edge`:return t.tts.providerEdge;case`tts-local-cli`:return t.tts.providerLocalCli;case`minimax`:return`MiniMax`;default:return e}}function rn(e,t){switch(e){case`off`:return t.tts.triggerOff;case`always`:return t.tts.triggerAlways;case`inbound`:return t.tts.triggerInbound;case`tagged`:return t.tts.triggerTagged}}function an(e,t){switch(e){case`edge`:return t.tts.providerHints.edge;case`openai`:return t.tts.providerHints.openai;case`alibaba`:return t.tts.providerHints.alibaba;case`minimax`:return t.tts.providerHints.minimax;case`tts-local-cli`:return t.tts.providerHints.localCli;default:return t.tts.providerHints.generic}}function on(e){return{maskedHelp:e.apiKeyMaskedHelp,copy:e.apiKeyCopy,copied:e.apiKeyCopied,show:e.apiKeyShow,hide:e.apiKeyHide,notInConfigFile:e.apiKeyNotInConfigFile,loadFailed:e.apiKeyRevealFailed}}function sn(e,t){let n=e[t.key];return typeof n==`string`||typeof n==`number`||typeof n==`boolean`?n:t.defaultValue===void 0?t.type===`boolean`?!1:``:t.defaultValue}function cn(e,t){if(e.type===`boolean`)return!!t;if(e.type!==`number`)return t;let n=String(t).trim();if(!n)return;let r=Number(n);return Number.isFinite(r)?r:void 0}function ln(e,t){switch(t.type){case`reset`:return{form:null,baseline:null};case`sync`:{let e=structuredClone(t.value);return{form:e,baseline:structuredClone(e)}}case`update`:return{...e,form:t.updater(e.form)};case`saved`:{let n=structuredClone(t.value);return{form:e.form!==null&&JSON.stringify(e.form)!==JSON.stringify(t.value)?e.form:n,baseline:structuredClone(n)}}}}function un(){let e=f(e=>e.language),t=u(e).voiceSettings,n=!!d(e=>e.token),[r,i]=(0,Q.useReducer)(ln,{form:null,baseline:null}),a=r.form,o=r.baseline,[s,c]=(0,Q.useState)(null),l=(0,Q.useRef)(!1),p=(0,Q.useRef)(a);p.current=a;let h=(0,Q.useRef)({parsed:null,models:void 0}),{data:_,error:v,isLoading:y,mutate:b}=ct(n),{data:x,error:S,isLoading:C,mutate:w}=g(n?m(`/api/voice/models`):null,Ct,{revalidateOnFocus:!1}),{data:T,error:E,isLoading:D}=g(n?m(`/api/voice/providers`):null,yt,{revalidateOnFocus:!1}),{data:O,error:k,isLoading:A}=g(n?m(`/api/voice/stt-providers`):null,Dt,{revalidateOnFocus:!1}),j=(0,Q.useMemo)(()=>T?.providers??[],[T]),M=(0,Q.useMemo)(()=>O?.providers??[],[O]),N=(0,Q.useMemo)(()=>_?.payload?.config===void 0?null:wt(_.payload.config),[_]),P=(0,Q.useMemo)(()=>!a||!o?!1:JSON.stringify(a)!==JSON.stringify(o),[a,o]);n?N!==null&&x!==void 0&&!l.current&&(h.current.parsed!==N||h.current.models!==x)&&(h.current={parsed:N,models:x},i({type:`sync`,value:N}),c(x)):(h.current.parsed!==null||h.current.models!==void 0)&&(h.current={parsed:null,models:void 0},i({type:`reset`}),c(null),l.current=!1);let F=!!(n&&(N===null||x===void 0||T===void 0||O===void 0)&&(y||C||D||A)),I=v instanceof Error?v.message:v?String(v):S instanceof Error?S.message:S?String(S):E instanceof Error?E.message:E?String(E):k instanceof Error?k.message:k?String(k):null,L=(0,Q.useCallback)(e=>{l.current=!0,i({type:`update`,updater:t=>t?{...t,stt:{...t.stt,...e}}:null})},[]),ee=(0,Q.useCallback)(e=>{l.current=!0,i({type:`update`,updater:t=>{if(!t)return null;let n=t.stt.fallback??{enabled:!1,order:[`xopc-local`]};return{...t,stt:{...t.stt,fallback:{...n,...e}}}}})},[]),R=(0,Q.useCallback)(e=>{l.current=!0,i({type:`update`,updater:t=>t?{...t,voice:{...t.voice,input:{...t.voice.input,refinement:{...t.voice.input.refinement,...e}}}}:null})},[]),z=(0,Q.useCallback)(t=>{l.current=!0,i({type:`update`,updater:n=>n?{...n,voice:{...n.voice,languageMode:t,...t===`auto`?{language:e}:{}}}:null})},[e]),B=(0,Q.useCallback)(e=>{l.current=!0,i({type:`update`,updater:t=>t?{...t,tts:{...t.tts,...e}}:null})},[]),V=vt({value:a,dirty:P,onSave:(0,Q.useCallback)(async e=>{try{await kt(e),i({type:`saved`,value:e}),l.current=!!(p.current&&JSON.stringify(p.current)!==JSON.stringify(e))}catch(e){throw Error(e instanceof Error?e.message:t.saveError)}},[t.saveError])});if(!n)return(0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.needToken})});if(F)return(0,$.jsx)(gt,{rows:4});if(!a||s===null)return(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:I??t.loadError}),(0,$.jsx)(X,{type:`button`,variant:`secondary`,onClick:()=>{b(),w()},children:t.retry})]});let H=a.stt,U=a.tts,te=a.voice.input.refinement,W=on(t);return(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,onBlurCapture:V.onBlurCapture,children:[(0,$.jsx)(`div`,{className:`flex justify-end`,children:(0,$.jsx)(_t,{status:V.status,error:V.error})}),V.error?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:V.error}):null,(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,$.jsx)(dn,{v:t,voice:a.voice,updateLanguageMode:z}),(0,$.jsx)(fn,{v:t,stt:H,tts:U}),(0,$.jsx)(mn,{v:t,apiKeyLabels:W,stt:H,models:s,sttProviders:M,refinement:te,updateStt:L,updateSttFallback:ee,updateRefinement:R}),(0,$.jsx)(vn,{v:t,apiKeyLabels:W,tts:U,models:s,ttsProviders:j,updateTts:B})]}),(0,$.jsxs)(`div`,{className:`rounded-xl border border-accent/25 bg-accent/5 px-4 py-3 dark:border-accent/30 dark:bg-accent/10`,children:[(0,$.jsxs)(`p`,{className:`text-sm text-fg`,children:[(0,$.jsx)(`strong`,{className:`text-accent`,children:t.notes.title}),` `,t.notes.duration]}),(0,$.jsx)(`p`,{className:`mt-2 text-xs text-fg-muted`,children:t.notes.envVars})]})]})}function dn(e){let t=(0,Z.c)(22),{v:n,voice:r,updateLanguageMode:i}=e,a;t[0]===n.language.title?a=t[1]:(a=(0,$.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:n.language.title}),t[0]=n.language.title,t[1]=a);let o=r.languageMode===`auto`?n.language.autoDescription:n.language.manualDescription,s;t[2]===o?s=t[3]:(s=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:o}),t[2]=o,t[3]=s);let c;t[4]!==a||t[5]!==s?(c=(0,$.jsxs)(`div`,{children:[a,s]}),t[4]=a,t[5]=s,t[6]=c):c=t[6];let l;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(l=Qt(),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)(W,{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)(W,{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 fn(e){let t=(0,Z.c)(39),{v:n,stt:r,tts:i}=e,a=i.providers?.[i.provider]?.voice,o=typeof a==`string`?a:void 0,s;t[0]===n.overview.title?s=t[1]:(s=(0,$.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:n.overview.title}),t[0]=n.overview.title,t[1]=s);let c;t[2]===n.overview.description?c=t[3]:(c=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:n.overview.description}),t[2]=n.overview.description,t[3]=c);let l;t[4]!==s||t[5]!==c?(l=(0,$.jsxs)(`div`,{className:`mb-4`,children:[s,c]}),t[4]=s,t[5]=c,t[6]=l):l=t[6];let u;t[7]!==r.enabled||t[8]!==r.provider||t[9]!==n?(u=r.enabled?`${n.overview.ready} · ${tn(r.provider,n)}`:n.overview.off,t[7]=r.enabled,t[8]=r.provider,t[9]=n,t[10]=u):u=t[10];let d;t[11]!==r.enabled||t[12]!==u||t[13]!==n.overview.input?(d=(0,$.jsx)(pn,{label:n.overview.input,value:u,ready:r.enabled}),t[11]=r.enabled,t[12]=u,t[13]=n.overview.input,t[14]=d):d=t[14];let f;t[15]!==i.enabled||t[16]!==i.trigger||t[17]!==n?(f=i.enabled?rn(i.trigger,n):n.overview.off,t[15]=i.enabled,t[16]=i.trigger,t[17]=n,t[18]=f):f=t[18];let p=i.enabled&&i.trigger!==`off`,m;t[19]!==f||t[20]!==p||t[21]!==n.overview.replies?(m=(0,$.jsx)(pn,{label:n.overview.replies,value:f,ready:p}),t[19]=f,t[20]=p,t[21]=n.overview.replies,t[22]=m):m=t[22];let h;t[23]!==o||t[24]!==i.enabled||t[25]!==i.provider||t[26]!==n?(h=i.enabled?`${nn(i.provider,n)}${o?` · ${o}`:``}`:n.overview.off,t[23]=o,t[24]=i.enabled,t[25]=i.provider,t[26]=n,t[27]=h):h=t[27];let g;t[28]!==h||t[29]!==i.enabled||t[30]!==n.overview.voice?(g=(0,$.jsx)(pn,{label:n.overview.voice,value:h,ready:i.enabled}),t[28]=h,t[29]=i.enabled,t[30]=n.overview.voice,t[31]=g):g=t[31];let _;t[32]!==g||t[33]!==d||t[34]!==m?(_=(0,$.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-3`,children:[d,m,g]}),t[32]=g,t[33]=d,t[34]=m,t[35]=_):_=t[35];let v;return t[36]!==_||t[37]!==l?(v=(0,$.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[l,_]}),t[36]=_,t[37]=l,t[38]=v):v=t[38],v}function pn(e){let t=(0,Z.c)(10),{label:n,value:r,ready:i}=e,a;t[0]===n?a=t[1]:(a=(0,$.jsx)(`div`,{className:`text-xs text-fg-muted`,children:n}),t[0]=n,t[1]=a);let o=i?`text-fg`:`text-fg-muted`,s;t[2]===o?s=t[3]:(s=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 mn(e){let t=(0,Z.c)(62),{v:n,apiKeyLabels:r,stt:i,models:a,sttProviders:o,refinement:s,updateStt:c,updateSttFallback:u,updateRefinement:d}=e,f;if(t[0]!==o){let e=new Set;f=[];for(let t of o)e.has(t.id)||(e.add(t.id),f.push(t));t[0]=o,t[1]=f}else f=t[1];let p=f,m,h,g,_;if(t[2]!==a||t[3]!==p||t[4]!==i.provider||t[5]!==i.providers){m=p.find(e=>e.id===i.provider);let e;t[10]!==i.provider||t[11]!==i.providers?(e=i.providers?.[i.provider]??{},t[10]=i.provider,t[11]=i.providers,t[12]=e):e=t[12],g=e,h=a?.stt?.[i.provider]?.length?a.stt[i.provider]:m?.models??[],_=m?.fields.find(hn),t[2]=a,t[3]=p,t[4]=i.provider,t[5]=i.providers,t[6]=m,t[7]=h,t[8]=g,t[9]=_}else m=t[6],h=t[7],g=t[8],_=t[9];let v=_,b=typeof g.model==`string`?g.model:void 0,x=b??(typeof v?.defaultValue==`string`?v.defaultValue:h[0]?.id),S;t[13]!==i.provider||t[14]!==i.providers||t[15]!==c?(S=e=>{c({providers:{...i.providers??{},[i.provider]:{...i.providers?.[i.provider]??{},...e}}})},t[13]=i.provider,t[14]=i.providers,t[15]=c,t[16]=S):S=t[16];let C=S,w,T;t[17]!==b||t[18]!==x||t[19]!==v||t[20]!==C?(w=()=>{v&&x&&b!==x&&C({model:x})},T=[b,x,v,C],t[17]=b,t[18]=x,t[19]=v,t[20]=C,t[21]=w,t[22]=T):(w=t[21],T=t[22]),(0,Q.useEffect)(w,T);let E;t[23]===Symbol.for(`react.memo_cache_sentinel`)?(E=(0,$.jsx)(y,{className:`size-4 text-accent`,strokeWidth:1.75}),t[23]=E):E=t[23];let D;t[24]===n.stt.title?D=t[25]:(D=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[E,n.stt.title]}),t[24]=n.stt.title,t[25]=D);let O;t[26]===n.stt.description?O=t[27]:(O=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:n.stt.description}),t[26]=n.stt.description,t[27]=O);let k;t[28]!==D||t[29]!==O?(k=(0,$.jsxs)(`div`,{className:`mb-4`,children:[D,O]}),t[28]=D,t[29]=O,t[30]=k):k=t[30];let A;t[31]===c?A=t[32]:(A=e=>c({enabled:e}),t[31]=c,t[32]=A);let j;t[33]!==i.enabled||t[34]!==A||t[35]!==n.overview.off||t[36]!==n.overview.ready||t[37]!==n.stt.enable||t[38]!==n.stt.enableDesc?(j=(0,$.jsx)(bn,{checked:i.enabled,title:n.stt.enable,description:n.stt.enableDesc,onLabel:n.overview.ready,offLabel:n.overview.off,onChange:A}),t[33]=i.enabled,t[34]=A,t[35]=n.overview.off,t[36]=n.overview.ready,t[37]=n.stt.enable,t[38]=n.stt.enableDesc,t[39]=j):j=t[39];let M;t[40]!==m?.fields||t[41]!==r||t[42]!==x||t[43]!==h||t[44]!==p||t[45]!==g||t[46]!==s||t[47]!==i.enabled||t[48]!==i.fallback?.enabled||t[49]!==i.provider||t[50]!==C||t[51]!==d||t[52]!==c||t[53]!==u||t[54]!==n?(M=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`,Xt),children:[(0,$.jsx)(Cn,{children:n.stt.provider}),(0,$.jsx)(Y,{className:Qt(),value:i.provider,onChange:e=>c({provider:e.target.value}),children:p.map(e=>(0,$.jsxs)(W,{value:e.id,children:[tn(e.id,n),e.configured?``:` *`]},e.id))})]}),(0,$.jsx)(yn,{kind:`stt`,providerId:i.provider,fields:m?.fields??[],providerSlice:g,models:h,currentModel:x,apiKeyLabels:r,onPatch:C})]}),i.provider===`xopc-local`?(0,$.jsx)(_n,{v:n}):null,(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.stt.fallback}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.stt.fallbackDesc})]}),(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:i.fallback?.enabled??!1,onChange:e=>u({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:Qt(),value:s.mode,onChange:e=>d({mode:e.target.value}),children:[(0,$.jsx)(W,{value:`off`,children:n.stt.refinementOff}),(0,$.jsx)(W,{value:`punctuation`,children:n.stt.refinementPunctuation}),(0,$.jsx)(W,{value:`light`,children:n.stt.refinementLight})]})]})]}):null,t[40]=m?.fields,t[41]=r,t[42]=x,t[43]=h,t[44]=p,t[45]=g,t[46]=s,t[47]=i.enabled,t[48]=i.fallback?.enabled,t[49]=i.provider,t[50]=C,t[51]=d,t[52]=c,t[53]=u,t[54]=n,t[55]=M):M=t[55];let N;t[56]!==j||t[57]!==M?(N=(0,$.jsxs)(`div`,{className:`space-y-4`,children:[j,M]}),t[56]=j,t[57]=M,t[58]=N):N=t[58];let P;return t[59]!==N||t[60]!==k?(P=(0,$.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[k,N]}),t[59]=N,t[60]=k,t[61]=P):P=t[61],P}function hn(e){return e.key===`model`}function gn(e){return`${Math.round(e/1024/1024)} MB`}function _n({v:e}){let{data:t,error:n,mutate:r}=g(m(`/api/voice/local/status`),Tt,{revalidateOnFocus:!1,refreshInterval:e=>e?.models.some(e=>e.state===`downloading`)?1e3:0}),[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(null),c=(0,Q.useCallback)(async(e,t)=>{a(e.id),s(null);try{t===`install`?await bt(e.id):await xt(e.id),await r()}catch(e){s(e instanceof Error?e.message:String(e))}finally{a(null)}},[r]);return(0,$.jsxs)(`div`,{className:`rounded-xl border border-edge bg-surface-panel/60 p-3`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.stt.localModels}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:e.stt.localModelsDesc}),n?(0,$.jsx)(`p`,{className:`mt-3 text-xs text-red-600 dark:text-red-400`,children:String(n)}):null,o?(0,$.jsx)(`p`,{className:`mt-3 text-xs text-red-600 dark:text-red-400`,children:o}):null,(0,$.jsx)(`div`,{className:`mt-3 grid gap-2`,children:(t?.models??[]).map(t=>{let n=i===t.id||t.state===`downloading`;return(0,$.jsxs)(`div`,{className: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:[gn(t.approximateBytes),` · `,t.description]}),(0,$.jsxs)(`div`,{className:`mt-0.5 text-[11px] text-fg-subtle`,children:[t.engine,` · `,t.languages.join(` / `)]}),t.state===`downloading`?(0,$.jsxs)(`div`,{className:`mt-1 text-xs text-accent`,children:[e.stt.localDownloading,` `,Math.round((t.progress??0)*100),`%`]}):t.state===`error`?(0,$.jsx)(`div`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:t.error}):null]}),(0,$.jsx)(X,{type:`button`,variant:`secondary`,disabled:n,onClick:()=>void c(t,t.state===`ready`?`remove`:`install`),children:n?(0,$.jsx)(P,{className:`size-4 animate-spin`}):t.state===`ready`?e.stt.localRemove:e.stt.localInstall})]},t.id)})})]})}function vn({v:e,apiKeyLabels:t,tts:n,models:r,ttsProviders:i,updateTts:a}){let[o,s]=(0,Q.useState)(e.tts.test.sampleText),[c,u]=(0,Q.useState)({status:`idle`}),d=(0,Q.useRef)(null),f=(0,Q.useRef)(null),p=(0,Q.useCallback)(()=>{d.current?.pause(),d.current=null,f.current&&=(URL.revokeObjectURL(f.current),null)},[]),m=(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]),h=m.find(e=>e.id===n.provider),_=n.providers?.[n.provider]??{},v=r?.tts?.[n.provider]?.length?r.tts[n.provider]:h?.models??[],y=h?.fields.find(e=>e.key===`model`),b=h?.fields.find(e=>e.key===`voice`),x=typeof _.model==`string`?_.model:void 0,S=x??(typeof y?.defaultValue==`string`?y.defaultValue:v[0]?.id),C=v.find(e=>e.id===S),w=r?.ttsVoices?.[n.provider]?.length?r.ttsVoices[n.provider]:h?.voices??[],{data:T=[]}=g(S?`voice:tts:${n.provider}:${S}`:null,()=>Et(n.provider,S??``),{revalidateOnFocus:!1}),E=T.length>0?T:w,D=typeof _.voice==`string`?_.voice:void 0,O=D??E.find(e=>e.id===C?.tts?.defaultVoice)?.id??(typeof b?.defaultValue==`string`?b.defaultValue:E[0]?.id),k=(h?.fields??[]).filter(e=>(e.key!==`speed`||C?.tts?.speed!==!1)&&(e.key!==`instructions`||C?.tts?.instructions!==!1)),A=!!h?.diagnostics.requiresApiKey,j=!!h?.configured||!A,M=n.enabled?j?`ready`:`action`:`muted`,N=(0,Q.useCallback)(e=>{a({providers:{...n.providers??{},[n.provider]:{...n.providers?.[n.provider]??{},...e}}})},[n.provider,n.providers,a]);(0,Q.useEffect)(()=>{let e={};y&&S&&x!==S&&(e.model=S),b&&O&&D!==O&&(e.voice=O),Object.keys(e).length>0&&N(e)},[x,D,S,O,y,N,b]),(0,Q.useEffect)(()=>()=>p(),[p]);let F=(0,Q.useCallback)(e=>{a({provider:e}),u({status:`idle`})},[a]),I=(0,Q.useCallback)(async()=>{let t=o.trim();if(!t){u({status:`error`,message:e.tts.test.emptyText});return}p(),u({status:`loading`});try{let r=await St({text:t,provider:n.provider,providerConfig:_,...S?{model:S}:{},...O?{voice:O}:{}}),i=en(r.audio,r.mimeType);f.current=i;let a=new Audio(i);d.current=a;let o=[r.provider,r.format,r.latencyMs===void 0?void 0:`${r.latencyMs}ms`,$t(r.audioSize)].filter(Boolean).join(` · `);a.addEventListener(`ended`,()=>u({status:`done`,summary:o}),{once:!0}),a.addEventListener(`error`,()=>u({status:`error`,message:e.tts.test.playFailed}),{once:!0}),await a.play(),u({status:`playing`,summary:o})}catch(e){p(),u({status:`error`,message:e instanceof Error?e.message:String(e)})}},[S,O,_,p,o,n.provider,e.tts.test.emptyText,e.tts.test.playFailed]);return(0,$.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[(0,$.jsxs)(`div`,{className:`mb-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,$.jsx)(Re,{className:`size-4 text-accent`,strokeWidth:1.75}),e.tts.title]}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:e.tts.description})]}),(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(bn,{checked:n.enabled,title:e.tts.enable,description:e.tts.enableDesc,onLabel:e.overview.ready,offLabel:e.overview.off,onChange:e=>a({enabled:e})}),(0,$.jsxs)(`div`,{className:l(`rounded-xl border px-3 py-2.5 text-sm`,M===`ready`?`border-emerald-500/25 bg-emerald-500/10 text-emerald-800 dark:text-emerald-100`:M===`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?j?`${e.tts.statusReady} ${nn(n.provider,e)}${O?` · ${O}`:``}`:`${e.tts.statusNeedsSetup} ${nn(n.provider,e)} · ${h?.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`,Xt),children:[(0,$.jsx)(Cn,{children:e.tts.trigger}),(0,$.jsxs)(Y,{className:Qt(),value:n.trigger,onChange:e=>a({trigger:e.target.value}),children:[(0,$.jsx)(W,{value:`off`,children:e.tts.triggerOff}),(0,$.jsx)(W,{value:`inbound`,children:e.tts.triggerInbound}),(0,$.jsx)(W,{value:`tagged`,children:e.tts.triggerTagged}),(0,$.jsx)(W,{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`,Xt),children:[(0,$.jsx)(Cn,{children:e.tts.provider}),(0,$.jsx)(Y,{className:Qt(),value:n.provider,onChange:e=>F(e.target.value),children:m.map(t=>(0,$.jsx)(W,{value:t.id,children:nn(t.id,e)},t.id))}),(0,$.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[h?.configured?e.tts.configured:h?.diagnostics.requiresApiKey?`${e.tts.needsKey} · ${h.diagnostics.envKeys?.join(`, `)??e.stt.apiKey}`:e.tts.noKeyNeeded,` · `,h?.description??an(n.provider,e)]})]})]}),(0,$.jsxs)(`details`,{className:`rounded-xl bg-surface-panel/80 p-3 shadow-surface`,open:!j||n.provider===`tts-local-cli`,children:[(0,$.jsxs)(`summary`,{className:`cursor-pointer text-sm font-medium text-fg marker:text-fg-muted`,children:[e.tts.advanced.title,(0,$.jsx)(`span`,{className:`ml-2 text-xs font-normal text-fg-muted`,children:e.tts.advanced.description})]}),(0,$.jsx)(`div`,{className:`mt-3`,children:(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:(0,$.jsx)(yn,{kind:`tts`,providerId:n.provider,fields:k,providerSlice:_,models:v,voices:E,currentModel:S,currentVoice:O,apiKeyLabels:t,onPatch:N,resetVoiceOnModelChange:!0})})})]}),(0,$.jsxs)(`div`,{className:`rounded-xl bg-surface-panel/80 p-3 shadow-surface`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.tts.test.title}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:e.tts.test.description})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 gap-2`,children:[(0,$.jsxs)(X,{type:`button`,variant:`primary`,onClick:()=>void I(),disabled:c.status===`loading`,className:`h-9`,children:[c.status===`loading`?(0,$.jsx)(P,{className:`size-4 animate-spin`}):(0,$.jsx)(rt,{className:`size-4`}),c.status===`loading`?e.tts.test.generating:e.tts.test.play]}),(0,$.jsxs)(X,{type:`button`,variant:`secondary`,onClick:()=>{p(),u(e=>e.status===`playing`?{status:`done`,summary:e.summary}:{status:`idle`})},disabled:c.status!==`playing`,className:`h-9`,children:[(0,$.jsx)(fe,{className:`size-4`}),e.tts.test.stop]})]})]}),(0,$.jsx)(`textarea`,{className:l(Zt(),`mt-3 min-h-20 resize-y`),value:o,onChange:e=>s(e.target.value),maxLength:1e3}),(0,$.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center justify-between gap-2 text-xs`,children:[(0,$.jsxs)(`span`,{className:`text-fg-subtle`,children:[o.length,`/1000`]}),c.status===`playing`||c.status===`done`?(0,$.jsxs)(`span`,{className:`text-emerald-700 dark:text-emerald-200`,children:[c.status===`playing`?e.tts.test.playing:e.tts.test.ready,` · `,c.summary]}):null,c.status===`error`?(0,$.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:c.message}):null]})]})]}):null]})]})}function yn({kind:e,providerId:t,fields:n,providerSlice:r,models:i,voices:a=[],currentModel:o,currentVoice:s,apiKeyLabels:c,onPatch:u,resetVoiceOnModelChange:d=!1}){return n.map(n=>n.key===`apiKey`?(0,$.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,Xt),children:[(0,$.jsx)(Cn,{children:n.label}),(0,$.jsx)(Ot,{kind:e,providerId:t,fieldId:`voice-${e}-${t}-api-key`,value:typeof r.apiKey==`string`?r.apiKey:``,onChange:e=>u({apiKey:e}),labels:c,placeholder:n.placeholder}),n.description?(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.description}):null]},n.key):n.key===`model`&&i.length>0?(0,$.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,Xt),children:[(0,$.jsx)(Cn,{children:n.label}),(0,$.jsx)(Y,{className:Qt(),value:o??``,onChange:e=>u({model:e.target.value,...d?{voice:void 0}:{}}),children:i.map(e=>(0,$.jsx)(W,{value:e.id,children:e.name},e.id))})]},n.key):n.key===`voice`&&a.length>0?(0,$.jsxs)(`div`,{className:l(`flex flex-col gap-1.5`,Xt),children:[(0,$.jsx)(Cn,{children:n.label}),(0,$.jsx)(Y,{className:Qt(),value:s??``,onChange:e=>u({voice:e.target.value}),children:a.map(e=>(0,$.jsx)(W,{value:e.id,children:e.name},e.id))})]},n.key):(0,$.jsx)(xn,{field:n,value:sn(r,n),onChange:e=>u({[n.key]:e}),className:n.type===`textarea`?`sm:col-span-2`:Xt},n.key))}function bn(e){let t=(0,Z.c)(33),{checked:n,title:r,description:i,onLabel:a,offLabel:o,onChange:s}=e,c;t[0]!==n||t[1]!==s?(c=()=>s(!n),t[0]=n,t[1]=s,t[2]=c):c=t[2];let 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`,C,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 w;t[22]===S?w=t[23]:(w=(0,$.jsx)(`span`,{className:S}),t[22]=S,t[23]=w);let T;t[24]!==b||t[25]!==w?(T=(0,$.jsx)(`span`,{className:b,"aria-hidden":!0,children:w}),t[24]=b,t[25]=w,t[26]=T):T=t[26];let E;return t[27]!==n||t[28]!==c||t[29]!==v||t[30]!==T||t[31]!==d?(E=(0,$.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":n,onClick:c,className:d,children:[v,T]}),t[27]=n,t[28]=c,t[29]=v,t[30]=T,t[31]=d,t[32]=E):E=t[32],E}function xn(e){let t=(0,Z.c)(36),{field:n,value:r,onChange:i,className:a}=e,o=`voice-schema-field-${n.key}`,s=n.description;if(n.type===`boolean`){let e;t[0]===a?e=t[1]:(e=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(cn(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)(Cn,{children:n.label}),t[21]=n.label,t[22]=d);let f;t[23]!==a||t[24]!==n||t[25]!==c||t[26]!==o||t[27]!==i?(f=n.type===`select`?(0,$.jsx)(Y,{id:o,className:Qt(),value:c,required:n.required,onChange:e=>i(cn(n,e.target.value)),children:(n.options??[]).map(Sn)}):n.type===`textarea`?(0,$.jsx)(`textarea`,{id:o,className:l(Zt(),`min-h-24 resize-y`),value:c,required:n.required,placeholder:n.placeholder,onChange:e=>i(cn(n,e.target.value))}):n.type===`password`?(0,$.jsx)(Ne,{id:o,className:a,value:c,onChange:e=>i(cn(n,e)),placeholder:n.placeholder,labels:Oe}):(0,$.jsx)(`input`,{id:o,className:Zt(),type:n.type===`number`?`number`:`text`,autoComplete:n.secret?`new-password`:`off`,spellCheck:!1,value:c,required:n.required,placeholder:n.placeholder,min:n.min,max:n.max,step:n.step,onChange:e=>i(cn(n,e.target.value))}),t[23]=a,t[24]=n,t[25]=c,t[26]=o,t[27]=i,t[28]=f):f=t[28];let p;t[29]===s?p=t[30]:(p=s?(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:s}):null,t[29]=s,t[30]=p);let m;return t[31]!==u||t[32]!==d||t[33]!==f||t[34]!==p?(m=(0,$.jsxs)(`div`,{className:u,children:[d,f,p]}),t[31]=u,t[32]=d,t[33]=f,t[34]=p,t[35]=m):m=t[35],m}function Sn(e){return(0,$.jsx)(W,{value:e.id,children:e.name},e.id)}function Cn(e){let t=(0,Z.c)(2),{children:n}=e,r;return t[0]===n?r=t[1]:(r=(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n}),t[0]=n,t[1]=r),r}function wn(e){let t=e&&typeof e==`object`&&`tools`in e?e.tools:void 0,n=t&&typeof t==`object`&&`web`in t?t.web:void 0,r=n&&typeof n==`object`&&`region`in n?n.region:void 0,i=r===`cn`||r===`global`?r:`auto`,a=n&&typeof n==`object`&&`search`in n?n.search:void 0,o=a&&typeof a==`object`?a:{},s=typeof o.maxResults==`number`&&Number.isFinite(o.maxResults)?Math.floor(o.maxResults):5,c=n&&typeof n==`object`&&`blocklist`in n?n.blocklist:void 0,l=c&&typeof c==`object`?c:{},u=Array.isArray(l.domains)?l.domains.filter(e=>typeof e==`string`&&e.trim().length>0):[],d=o.providers;return{regionMode:i,maxResults:s,providers:Array.isArray(d)?d.map(e=>{let t=e&&typeof e==`object`?e:{},n=t.type;return{type:n===`brave`||n===`tavily`||n===`bing`||n===`searxng`?n:`brave`,apiKey:typeof t.apiKey==`string`?t.apiKey:``,url:typeof t.url==`string`?t.url:``,disabled:t.disabled===!0}}):[],blocklistEnabled:l.enabled===!0,blocklistDomains:u}}async function Tn(e){let t=e.regionMode===`auto`?`auto`:e.regionMode===`cn`?`cn`:`global`,n={maxResults:e.maxResults,providers:e.providers.map(e=>{let t={type:e.type,apiKey:e.apiKey};return e.type===`searxng`&&e.url.trim()&&(t.url=e.url.trim().replace(/\/+$/,``)),e.disabled&&(t.disabled=!0),t})};await h(m(`/api/config`),{method:`PATCH`,body:JSON.stringify({tools:{web:{region:t,search:n,blocklist:{enabled:e.blocklistEnabled,domains:e.blocklistDomains}}}})}),_e()}async function En(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 Dn(e){let t=(0,Z.c)(8),{label:n,description:r,children:i}=e,a;t[0]===n?a=t[1]:(a=(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n}),t[0]=n,t[1]=a);let o;t[2]===r?o=t[3]:(o=(0,$.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:r}),t[2]=r,t[3]=o);let s;return t[4]!==i||t[5]!==a||t[6]!==o?(s=(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[a,i,o]}),t[4]=i,t[5]=a,t[6]=o,t[7]=s):s=t[7],s}function On(){return l(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,C,`dark:border-edge`)}function kn(){return l(J,lt)}var An=[`brave`,`tavily`,`bing`,`searxng`];function jn(){return{type:`brave`,apiKey:``,url:``,disabled:!1}}var Mn=Ee();function Nn(){let e=u(f(e=>e.language)),t=e.webSearchSettings,n=e.logs,r=!!d(e=>e.token),[i,a]=(0,Q.useReducer)(Mn,{form:null,baseline:null}),o=i.form,s=i.baseline,c=(0,Q.useRef)(!1),p=(0,Q.useRef)(o);p.current=o;let m=(0,Q.useRef)(null),{data:h,error:g,isLoading:_,mutate:v}=ct(r);Qe({enabled:r,parsed:(0,Q.useMemo)(()=>h?.payload?.config===void 0?null:wn(h.payload.config),[h]),dirty:c.current,trackedParsedRef:m,dispatch:a,onResetDirty:()=>{c.current=!1}});let y=!!(r&&_&&h===void 0&&!g),b=g instanceof Error?g.message:g?String(g):null,x=(0,Q.useMemo)(()=>!o||!s?!1:JSON.stringify(o)!==JSON.stringify(s),[o,s]),S=(0,Q.useCallback)(e=>{c.current=!0,a({type:`patch`,patch:e})},[]),C=vt({value:o,dirty:x,onSave:(0,Q.useCallback)(async e=>{try{await Tn(e),a({type:`saved`,value:e}),c.current=!!(p.current&&JSON.stringify(p.current)!==JSON.stringify(e))}catch(e){throw Error(e instanceof Error?e.message:t.saveError)}},[t.saveError])});return r?y?(0,$.jsx)(gt,{rows:3}):o?(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,onBlurCapture:C.onBlurCapture,children:[C.error?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:C.error}):null,(0,$.jsxs)(Mt,{children:[(0,$.jsx)(jt,{icon:Se,title:t.sectionRegion,subtitle:t.sectionRegionHint,trailing:(0,$.jsx)(_t,{status:C.status,error:C.error})}),(0,$.jsx)(`div`,{className:`flex max-w-md flex-col gap-4`,children:(0,$.jsx)(Dn,{label:t.regionLabel,description:t.regionDesc,children:(0,$.jsxs)(Y,{className:kn(),value:o.regionMode,onChange:e=>S({regionMode:e.target.value}),children:[(0,$.jsx)(W,{value:`auto`,children:t.regionAuto}),(0,$.jsx)(W,{value:`cn`,children:t.regionCn}),(0,$.jsx)(W,{value:`global`,children:t.regionGlobal})]})})})]}),(0,$.jsx)(At,{children:(0,$.jsxs)(Mt,{children:[(0,$.jsx)(jt,{icon:ot,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=>S({blocklistEnabled:e.target.checked})}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`font-medium`,children:t.blocklistEnabled}),(0,$.jsx)(`span`,{className:`mt-0.5 block text-xs text-fg-subtle`,children:t.blocklistEnabledDesc})]})]}),(0,$.jsx)(Dn,{label:t.blocklistDomains,description:t.blocklistDomainsDesc,children:(0,$.jsx)(`textarea`,{className:l(On(),`min-h-[6rem] font-mono text-xs`),value:o.blocklistDomains.join(`
7
+ `),placeholder:t.blocklistDomainsPlaceholder,disabled:!o.blocklistEnabled,onChange:e=>{S({blocklistDomains:e.target.value.split(/\r?\n/).flatMap(e=>{let t=e.trim().toLowerCase();return t?[t]:[]})})}})})]})]})}),(0,$.jsxs)(Mt,{children:[(0,$.jsx)(jt,{icon:Se,title:t.sectionSearch,subtitle:t.sectionSearchHint}),(0,$.jsxs)(`div`,{className:`flex max-w-xl flex-col gap-6`,children:[(0,$.jsx)(Dn,{label:t.maxResultsLabel,description:t.maxResultsDesc,children:(0,$.jsx)(`input`,{type:`number`,min:1,max:50,className:On(),value:o.maxResults,onChange:e=>S({maxResults:Math.max(1,Math.min(50,Number(e.target.value)||5))})})}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.providersTitle}),o.providers.map((n,r)=>(0,$.jsx)(Pn,{row:n,providerIndex:r,labels:t,secretLabels:Ke(e.providersSettings),onChange:e=>{let t=[...o.providers];t[r]=e,S({providers:t})},onRemove:()=>{S({providers:o.providers.filter((e,t)=>t!==r)})}},`${n.type}:${n.url}:${n.apiKey}:${n.disabled}`)),(0,$.jsxs)(X,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5 text-sm`,onClick:()=>S({providers:[...o.providers,jn()]}),children:[(0,$.jsx)(q,{className:`size-4`}),t.addProvider]})]})]})]}),(0,$.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:t.footerHint})]}):(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:b??t.loadError}),(0,$.jsx)(X,{type:`button`,variant:`secondary`,onClick:()=>void v(),children:n.refresh})]}):(0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.needToken})})}function Pn(e){let t=(0,Z.c)(54),{row:n,providerIndex:r,labels:i,secretLabels:a,onChange:o,onRemove:s}=e,c;t[0]===r?c=t[1]:(c=()=>En(r).then(Fn),t[0]=r,t[1]=c);let u=c,d;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(d=l(kn(),`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=An.map(e=>(0,$.jsx)(W,{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)(oe,{className:`size-4`}),t[21]=y):y=t[21];let b;t[22]===s?b=t[23]:(b=(0,$.jsx)(X,{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)(Dn,{label:i.urlLabel,description:i.urlDesc,children:(0,$.jsx)(`input`,{type:`url`,className:On(),value:n.url,placeholder:`http://localhost:8080`,onChange:e=>o({...n,url:e.target.value})})}):null,t[30]=i.urlDesc,t[31]=i.urlLabel,t[32]=o,t[33]=n,t[34]=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)(Ne,{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)(Dn,{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 Fn(e){return e.apiKey??null}function In(){if(j())return null;let e=window.open(`about:blank`,`xopc-oauth`);return e&&(e.opener=null),e}async function Ln(e,t){return j()?(await window.electronAPI?.shell?.openExternalUrl(e))?.ok===!0:!t||t.closed?!1:(t.location.replace(e),!0)}function Rn(e){e&&!e.closed&&e.close()}var zn=[`common`,`domestic`,`specialty`,`enterprise`,`oauth`,`extension`];function Bn(e){let t=new Map;for(let e of zn)t.set(e,[]);for(let n of e){let e=n.category||`specialty`,r=t.get(e)??[];r.push(n),t.set(e,r)}return t}function Vn(e){let t=(0,Z.c)(22),{open:n,onOpenChange:r,builtinRows:i,customConfig:a,labels:o,language:s,onSaved:c}=e,u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u={type:`pick`},t[0]=u):u=t[0];let[d,f]=(0,Q.useState)(u),[p,m]=(0,Q.useState)(``),h;t[1]===r?h=t[2]:(h=e=>{e||window.setTimeout(()=>{f({type:`pick`}),m(``)},200),r(e)},t[1]=r,t[2]=h);let g=h,_;t[3]!==g||t[4]!==c?(_=()=>{c(),g(!1)},t[3]=g,t[4]=c,t[5]=_):_=t[5];let v=_,y;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(y=(0,$.jsx)(ft,{className:l(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,Fe)}),t[6]=y):y=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`,Je),t[7]=x):x=t[7];let S;t[8]!==i||t[9]!==a||t[10]!==v||t[11]!==o||t[12]!==s||t[13]!==p||t[14]!==d.presetKey||t[15]!==d.providerId||t[16]!==d.type?(S=(0,$.jsxs)(b,{children:[y,(0,$.jsx)(L,{className:x,children:d.type===`pick`?(0,$.jsx)(Un,{builtinRows:i,searchQuery:p,onSearchChange:m,labels:o,onPickBuiltin:e=>{let t=Pe(e);f(t?{type:`custom`,presetKey:t}:{type:`builtin`,providerId:e})},onPickCustom:()=>f({type:`custom`})}):d.type===`builtin`?(0,$.jsx)(Wn,{providerId:d.providerId,builtinRows:i,labels:o,language:s,onBack:()=>f({type:`pick`}),onSaved:v}):(0,$.jsx)(qn,{initialPresetKey:d.presetKey,customConfig:a,labels:o,language:s,onBack:()=>f({type:`pick`}),onSaved:v})})]}),t[8]=i,t[9]=a,t[10]=v,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)(O,{open:n,onOpenChange:g,children:S}),t[18]=g,t[19]=n,t[20]=S,t[21]=C):C=t[21],C}function Hn(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`,tt.press),t[0]=r):r=t[0];let i;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(T,{className:`size-4`,"aria-hidden":!0}),t[1]=i):i=t[1];let a;return t[2]===n?a=t[3]:(a=(0,$.jsx)(N,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:r,"aria-label":n,children:i})}),t[2]=n,t[3]=a),a}function Un(e){let t=(0,Z.c)(42),{builtinRows:n,searchQuery:r,onSearchChange:i,labels:a,onPickBuiltin:o,onPickCustom:s}=e,c;t[0]===r?c=t[1]:(c=r.trim().toLowerCase(),t[0]=r,t[1]=c);let 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=le[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=Bn(f),t[7]=f,t[8]=p);let m=p,h;t[9]===a.step1Title?h=t[10]:(h=(0,$.jsx)(ae,{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)(Hn,{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)(Se,{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`,C),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 w;t[24]!==a.addCustom||t[25]!==a.customDescription||t[26]!==s||t[27]!==u?(w=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`,tt.press),children:[(0,$.jsx)(st,{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)(Te,{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]=w):w=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:zn.map(e=>{let t=m.get(e)??[];return t.length===0?null:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`mb-1 px-1 text-[11px] font-semibold uppercase tracking-wide text-fg-subtle`,children:a.categories[e]??e}),(0,$.jsx)(`div`,{className:`flex flex-col gap-0.5`,children:t.map(e=>(0,$.jsxs)(`button`,{type:`button`,onClick:()=>o(e.id),className: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`,tt.press),children:[(0,$.jsx)(`span`,{className:`truncate text-sm text-fg`,children:e.name}),e.configured?(0,$.jsx)(xe,{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]!==w||t[36]!==T?(E=(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto px-5 py-3`,children:[w,T]}),t[35]=w,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 Wn({providerId:e,builtinRows:t,labels:n,language:r,onBack:i,onSaved:a}){let o=t.find(t=>t.id===e),s=le[e],[c,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)(!1),[m,h]=(0,Q.useState)(null),[g,_]=(0,Q.useState)(!1),v=(0,Q.useRef)(null),y=u(r).providersSettings,b=Ke(y),x=(0,Q.useMemo)(()=>se(e,r),[e,r]),S=o?.supportsApiKey!==!1,T=o?.supportsOAuth===!0,[E,D]=(0,Q.useState)(null),[O,k]=(0,Q.useState)(null),[A,j]=(0,Q.useState)(`idle`),[M,N]=(0,Q.useState)(null),[F,I]=(0,Q.useState)(null),[L,ee]=(0,Q.useState)(null),[R,z]=(0,Q.useState)(``),B=(0,Q.useRef)(null),V=(0,Q.useRef)(null),H=A===`waiting`||A===`waiting_code`;(0,Q.useEffect)(()=>{if(!E||!H)return;let t=window.setInterval(()=>{(async()=>{try{let n=await ut(E);n.status===`waiting_auth`||n.status===`waiting_code`?(j(n.status===`waiting_code`?`waiting_code`:`waiting`),k(n.message??null),N(n.authUrl??null),I(n.instructions??null),ee(n.deviceCode??null),n.authUrl&&n.authUrl!==V.current&&(V.current=n.authUrl,Ln(n.authUrl,B.current).catch(()=>{}))):n.status===`completed`?(window.clearInterval(t),Rn(B.current),B.current=null,e===`xopc-cloud`&&await U(),j(`success`),k(n.message??y.saved),window.setTimeout(a,600)):(n.status===`failed`||n.status===`cancelled`)&&(window.clearInterval(t),Rn(B.current),B.current=null,j(`error`),k(n.error??n.message??y.revokeFailed))}catch{}})()},1e3);return()=>window.clearInterval(t)},[E,H,a,e,y.revokeFailed,y.saved]),(0,Q.useEffect)(()=>()=>{E&&ve(E).catch(()=>{})},[E]),(0,Q.useEffect)(()=>()=>{Rn(B.current),B.current=null},[]);let te=async()=>{Rn(B.current),B.current=In(),V.current=null,j(`waiting`),k(y.oauthStarting),N(null),I(null),ee(null),h(null);try{D((await w(e)).sessionId)}catch(e){Rn(B.current),B.current=null,j(`error`),k(e instanceof Error?e.message:y.revokeFailed)}},W=async()=>{if(E){try{await dt(E)}catch{}Rn(B.current),B.current=null,V.current=null,j(`idle`),k(null),D(null),N(null),I(null),ee(null)}},G=async()=>{if(!(!E||!R.trim()))try{await at(E,R.trim()),z(``),k(y.oauthProcessingCode)}catch(e){j(`error`),k(e instanceof Error?e.message:y.revokeFailed)}},K=async()=>{let t=c.trim();if(!(!t||!S)){p(!0),h(null);try{await Be({[e]:t}),_(!0),window.setTimeout(a,600)}catch(e){h(e instanceof Error?e.message:n.saveError)}finally{p(!1)}}};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-edge-subtle px-5 py-4`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:i,className:l(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,tt.press),"aria-label":n.back,children:(0,$.jsx)(Te,{className:`size-4 rotate-180`,"aria-hidden":!0})}),(0,$.jsx)(ae,{className:`min-w-0 flex-1 text-base font-semibold text-fg`,children:o?.name??e}),(0,$.jsx)(Hn,{label:n.close})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 px-5 py-4`,children:[s?.description?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:s.description}):null,S?(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)(Ne,{id:`builtin-api-key`,value:c,onChange:d,placeholder:n.apiKeyPlaceholder,labels:b,inputRef:v,onKeyDown:e=>{e.key===`Enter`&&K()}})]}):null,T?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-lg border border-edge-subtle bg-surface-panel/60 p-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:y.oauth}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:y.oauthHint})]}),(0,$.jsxs)(X,{type:`button`,variant:`primary`,className:`gap-1.5`,disabled:H,onClick:()=>void te(),children:[H?(0,$.jsx)(P,{className:`size-3.5 animate-spin`,"aria-hidden":!0}):null,y.oauth]})]}),O?(0,$.jsx)(`p`,{className:l(`text-xs`,A===`error`?`text-red-600 dark:text-red-400`:`text-fg-muted`),children:O}):null,A===`waiting`||A===`waiting_code`?(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[M?(0,$.jsxs)(`a`,{href:M,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1.5 rounded-md bg-accent px-3 py-2 text-sm font-medium text-white hover:bg-accent-hover`,children:[y.openAuthPage,(0,$.jsx)(`span`,{className:`size-3`,"aria-hidden":!0,children:`↗`})]}):null,(0,$.jsx)(X,{type:`button`,variant:`secondary`,onClick:()=>void W(),children:y.cancelOAuth})]}):null,F?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:F}):null,L?(0,$.jsxs)(`div`,{className:`rounded-lg border border-edge-subtle bg-surface-panel px-3 py-2`,children:[(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:y.deviceCodeLabel}),(0,$.jsx)(`code`,{className:`mt-1 block select-all font-mono text-lg font-semibold tracking-widest text-fg`,children:L}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:y.deviceCodeHint})]}):null,A===`waiting_code`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,$.jsx)(`input`,{type:`text`,value:R,onChange:e=>z(e.target.value),onKeyDown:e=>e.key===`Enter`&&void G(),placeholder:y.pasteRedirectUrl,className:l(`min-w-0 flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,C)}),(0,$.jsx)(X,{type:`button`,variant:`primary`,onClick:()=>void G(),children:y.submitCode})]}):null]}):null,x.length>0&&S?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:x.map(({kind:e,href:t})=>(0,$.jsxs)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent hover:underline`,children:[de(e,n),(0,$.jsx)(`span`,{className:`size-3`,"aria-hidden":!0,children:`↗`})]},e))}):null,m?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:m}):null,(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,$.jsx)(X,{type:`button`,variant:`secondary`,onClick:i,children:n.cancel}),S?(0,$.jsx)(X,{type:`button`,variant:`primary`,disabled:!c.trim()||f||g,onClick:()=>void K(),children:g?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(xe,{className:`size-3.5`,"aria-hidden":!0}),n.saved]}):f?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(P,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),n.saving]}):n.save}):null]})]})]})}function Gn(e=`custom`){if(e!==`custom`&&we[e]){let t=we[e].config;return{preset:e,providerId:he(e),baseUrl:t.baseUrl??``,api:t.api??`openai-completions`,apiKey:t.apiKey??``,modelIds:t.models?.map(e=>e.id)??[``],error:null}}return{preset:`custom`,providerId:``,baseUrl:``,api:`openai-completions`,apiKey:``,modelIds:[``],error:null}}function Kn(e,t){switch(t.type){case`applyPreset`:return t.key===`custom`?{...e,preset:`custom`,error:null}:we[t.key]?Gn(t.key):e;case`setProviderId`:return{...e,providerId:t.value};case`setBaseUrl`:return{...e,baseUrl:t.value};case`setApi`:return{...e,api:t.value};case`setApiKey`:return{...e,apiKey:t.value};case`addModelSlot`:return{...e,modelIds:[...e.modelIds,``]};case`updateModelId`:return{...e,modelIds:e.modelIds.map((e,n)=>n===t.index?t.value:e)};case`setModelIds`:return{...e,modelIds:t.values.length>0?t.values:[``]};case`removeModelSlot`:return{...e,modelIds:e.modelIds.filter((e,n)=>n!==t.index)};case`setError`:return{...e,error:t.value}}}function qn({initialPresetKey:e,customConfig:t,labels:n,language:r,onBack:i,onSaved:a}){let[o,s]=(0,Q.useReducer)(Kn,void 0,()=>Gn(e)),[c,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(!1),m=Ke(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:we[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 Ve({providers:{...n,[e]:s}}),a()}catch(e){s({type:`setError`,value:e instanceof Error?e.message:n.saveError})}finally{d(!1)}},w=async()=>{let e=g.trim()||he(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:we[h]?.config,i=(await Ge({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)}},E=g.trim()&&_.trim(),D=(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`,tt.press),"aria-label":n.back,children:(0,$.jsx)(Te,{className:`size-4 rotate-180`,"aria-hidden":!0})}),(0,$.jsx)(ae,{className:`min-w-0 flex-1 text-base font-semibold text-fg`,children:n.step2CustomTitle}),(0,$.jsx)(Hn,{label:n.close})]}),(0,$.jsxs)(`div`,{className:`flex max-h-[60vh] flex-col gap-4 overflow-y-auto px-5 py-4`,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.customDescription}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`custom-preset`,className:`text-sm font-medium text-fg`,children:n.presetLabel}),(0,$.jsxs)(Y,{id:`custom-preset`,value:h,onChange:e=>s({type:`applyPreset`,key:e.target.value}),className:nt(),children:[(0,$.jsx)(W,{value:`custom`,children:n.presetCustom}),ke.map(e=>(0,$.jsx)(W,{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`,C)})]}),(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`,C)})]}),(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:nt(),children:Ie.map(e=>(0,$.jsx)(W,{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)(Ne,{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)(X,{type:`button`,variant:`secondary`,className:`gap-1.5`,disabled:!D||f,onClick:()=>void w(),children:[f?(0,$.jsx)(P,{className:`size-3.5 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Se,{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`,C)}),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`,tt.press),children:(0,$.jsx)(T,{className:`size-3.5`,"aria-hidden":!0})}):null]},e||`model-slot-${t}`)),(0,$.jsxs)(X,{type:`button`,variant:`ghost`,className:`w-fit gap-1.5 text-fg-muted`,onClick:()=>s({type:`addModelSlot`}),children:[(0,$.jsx)(q,{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)(X,{type:`button`,variant:`secondary`,onClick:i,children:n.cancel}),(0,$.jsx)(X,{type:`button`,variant:`primary`,disabled:!E||c,onClick:()=>void S(),children:c?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(P,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),n.saving]}):n.save})]})]})}function Jn(){let e=(0,Z.c)(31),t=d($n),n=!!t,{data:r,isLoading:i}=ct(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?K:null,Qn,u),h;e[6]===f?h=e[7]:(h=f===void 0?[]:f,e[6]=f,e[7]=h);let _=h,y;e[8]===Symbol.for(`react.memo_cache_sentinel`)?(y={revalidateOnFocus:!1},e[8]=y):y=e[8];let{data:b}=g(n?R:null,Zn,y),x;bb0:{if(!c||r===void 0){let t;e[9]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[9]=t):t=e[9],x=t;break bb0}let t;e[10]!==r?.payload?.config||e[11]!==c||e[12]!==_?(t=H(c,v(r?.payload?.config),_),e[10]=r?.payload?.config,e[11]=c,e[12]=_,e[13]=t):t=e[13],x=t}let S=x,C;bb1:{if(!b){C=null;break bb1}let t;e[14]===b.config?t=e[15]:(t=be(b.config),e[14]=b.config,e[15]=t),C=t}let w=C,T;if(e[16]!==S||e[17]!==w||e[18]!==c||e[19]!==_){T=[];let t=new Set((c??[]).filter(Xn).map(Yn)),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 S){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]=S,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]!==S||e[26]!==E||e[27]!==w||e[28]!==D||e[29]!==_?(O={cards:E,loading:D,builtinRows:S,customConfig:w,allModels:_},e[25]=S,e[26]=E,e[27]=w,e[28]=D,e[29]=_,e[30]=O):O=e[30],O}function Yn(e){return e.id}function Xn(e){return e.configured}function Zn(){return Ze()}function Qn(){return pt()}function $n(e){return e.token}function er(e){let t=(0,Z.c)(16),{labels:n,data:r,onAdd:i,onManage:a}=e,{cards:o,loading:s}=r;if(s){let e;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(z,{className:`h-6 w-48 max-w-full`}),t[0]=e):e=t[0];let n;return t[1]===Symbol.for(`react.memo_cache_sentinel`)?(n=(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,"aria-busy":`true`,children:[e,(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:[1,2,3].map(nr)})]}),t[1]=n):n=t[1],n}let c;if(t[2]!==o||t[3]!==n||t[4]!==i||t[5]!==a){let e=o.filter(tr),r=e.length>0?n.titleCount.replace(`{{count}}`,String(e.length)):n.title,s;t[7]===r?s=t[8]:(s=(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:r}),t[7]=r,t[8]=s);let l;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(q,{className:`size-3.5`,strokeWidth:2,"aria-hidden":!0}),t[9]=l):l=t[9];let u;t[10]!==n.addProvider||t[11]!==i?(u=(0,$.jsxs)(X,{type:`button`,variant:`primary`,className:`gap-1.5`,onClick:i,children:[l,n.addProvider]}),t[10]=n.addProvider,t[11]=i,t[12]=u):u=t[12];let d;t[13]!==s||t[14]!==u?(d=(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[s,u]}),t[13]=s,t[14]=u,t[15]=d):d=t[15],c=(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[d,e.length===0?(0,$.jsxs)(`div`,{className:`rounded-2xl bg-surface-panel/60 px-6 py-10 text-center shadow-surface`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:n.empty}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.emptyHint}),(0,$.jsxs)(X,{type:`button`,variant:`primary`,className:`mt-4 gap-1.5`,onClick:i,children:[(0,$.jsx)(q,{className:`size-3.5`,strokeWidth:2,"aria-hidden":!0}),n.addProvider]})]}):(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:e.map(e=>(0,$.jsx)(rr,{card:e,labels:n,onManage:()=>a(e.id,e.isCustom)},e.id))})]}),t[2]=o,t[3]=n,t[4]=i,t[5]=a,t[6]=c}else c=t[6];return c}function tr(e){return e.configured}function nr(e){return(0,$.jsx)(z,{className:`h-32 rounded-2xl`},e)}function rr(e){let t=(0,Z.c)(28),{card:n,labels:r,onManage:i}=e,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=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`,tt.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)(xe,{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)(ye,{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 ir(e){let t=(0,Z.c)(156),{model:n,isNew:r,providerId:i,onSave:a,onClose:o,m:s}=e,c;t[0]===n?c=t[1]:(c=()=>n?{...n}:ge(``),t[0]=n,t[1]=c);let[u,d]=(0,Q.useState)(c),[f,p]=(0,Q.useState)(ar),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=je(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)(ae,{className:`text-base font-semibold text-fg`,children:C}),t[16]=C,t[17]=w);let E;t[18]!==s.modelProviderLabel||t[19]!==i?(E=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]=E):E=t[20];let D;t[21]!==w||t[22]!==E?(D=(0,$.jsxs)(`div`,{children:[w,E]}),t[21]=w,t[22]=E,t[23]=D):D=t[23];let O;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(O=l(me,`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)(T,{className:`size-4`}),t[25]=k):k=t[25];let A;t[26]===s.close?A=t[27]:(A=(0,$.jsx)(N,{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]!==D||t[29]!==A?(j=(0,$.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[D,A]}),t[28]=D,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 P;t[32]===s.modelId?P=t[33]:(P=(0,$.jsxs)(`label`,{className:`mb-1 block text-xs font-medium text-fg`,children:[s.modelId,M]}),t[32]=s.modelId,t[33]=P);let F;t[34]===f?F=t[35]:(F=l(qe(),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 ee=!r,R;t[37]!==F||t[38]!==I||t[39]!==ee?(R=(0,$.jsx)(`input`,{className:F,value:I,onChange:L,placeholder:`e.g. llama3.1:8b`,disabled:ee}),t[37]=F,t[38]=I,t[39]=ee,t[40]=R):R=t[40];let z;t[41]===f?z=t[42]:(z=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]=z);let B;t[43]!==P||t[44]!==R||t[45]!==z?(B=(0,$.jsxs)(`div`,{children:[P,R,z]}),t[43]=P,t[44]=R,t[45]=z,t[46]=B):B=t[46];let V;t[47]===s.displayName?V=t[48]:(V=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.displayName}),t[47]=s.displayName,t[48]=V);let H;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(H=qe(),t[49]=H):H=t[49];let U=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 G;t[51]===U?G=t[52]:(G=(0,$.jsx)(`input`,{className:H,value:U,onChange:te}),t[51]=U,t[52]=G);let K;t[53]!==V||t[54]!==G?(K=(0,$.jsxs)(`div`,{children:[V,G]}),t[53]=V,t[54]=G,t[55]=K):K=t[55];let q;t[56]===s.inputTypes?q=t[57]:(q=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.inputTypes}),t[56]=s.inputTypes,t[57]=q);let J;t[58]===Symbol.for(`react.memo_cache_sentinel`)?(J=nt(),t[58]=J):J=t[58];let ne;t[59]===Symbol.for(`react.memo_cache_sentinel`)?(ne=e=>h(`input`,He(e.target.value)),t[59]=ne):ne=t[59];let re;t[60]===s?re=t[61]:(re=et.map(e=>(0,$.jsx)(W,{value:e.value,children:s[e.labelKey]},e.value)),t[60]=s,t[61]=re);let ie;t[62]!==S||t[63]!==re?(ie=(0,$.jsx)(Y,{className:J,value:S,onChange:ne,children:re}),t[62]=S,t[63]=re,t[64]=ie):ie=t[64];let oe;t[65]!==q||t[66]!==ie?(oe=(0,$.jsxs)(`div`,{children:[q,ie]}),t[65]=q,t[66]=ie,t[67]=oe):oe=t[67];let se=u.reasoning||!1,ce;t[68]===Symbol.for(`react.memo_cache_sentinel`)?(ce=e=>h(`reasoning`,e.target.checked),t[68]=ce):ce=t[68];let le;t[69]===se?le=t[70]:(le=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:se,onChange:ce}),t[69]=se,t[70]=le);let ue;t[71]!==s.reasoning||t[72]!==le?(ue=(0,$.jsxs)(`label`,{className:`mt-6 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[le,s.reasoning]}),t[71]=s.reasoning,t[72]=le,t[73]=ue):ue=t[73];let de;t[74]!==oe||t[75]!==ue?(de=(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[oe,ue]}),t[74]=oe,t[75]=ue,t[76]=de):de=t[76];let fe;t[77]===s.contextWindow?fe=t[78]:(fe=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.contextWindow}),t[77]=s.contextWindow,t[78]=fe);let pe;t[79]===f?pe=t[80]:(pe=l(qe(),f.has(`contextWindow`)&&`border-red-500`),t[79]=f,t[80]=pe);let he=u.contextWindow??128e3,_e;t[81]===Symbol.for(`react.memo_cache_sentinel`)?(_e=e=>h(`contextWindow`,parseInt(e.target.value,10)||0),t[81]=_e):_e=t[81];let ve;t[82]!==pe||t[83]!==he?(ve=(0,$.jsx)(`input`,{type:`number`,min:1,className:pe,value:he,onChange:_e}),t[82]=pe,t[83]=he,t[84]=ve):ve=t[84];let ye;t[85]===f?ye=t[86]:(ye=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]=ye);let be;t[87]!==fe||t[88]!==ve||t[89]!==ye?(be=(0,$.jsxs)(`div`,{children:[fe,ve,ye]}),t[87]=fe,t[88]=ve,t[89]=ye,t[90]=be):be=t[90];let xe;t[91]===s.maxOutputTokens?xe=t[92]:(xe=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.maxOutputTokens}),t[91]=s.maxOutputTokens,t[92]=xe);let Se;t[93]===f?Se=t[94]:(Se=l(qe(),f.has(`maxTokens`)&&`border-red-500`),t[93]=f,t[94]=Se);let Ce=u.maxTokens??16384,we;t[95]===Symbol.for(`react.memo_cache_sentinel`)?(we=e=>h(`maxTokens`,parseInt(e.target.value,10)||0),t[95]=we):we=t[95];let Te;t[96]!==Se||t[97]!==Ce?(Te=(0,$.jsx)(`input`,{type:`number`,min:1,className:Se,value:Ce,onChange:we}),t[96]=Se,t[97]=Ce,t[98]=Te):Te=t[98];let Ee;t[99]===f?Ee=t[100]:(Ee=f.has(`maxTokens`)?(0,$.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:f.get(`maxTokens`)}):null,t[99]=f,t[100]=Ee);let De;t[101]!==xe||t[102]!==Te||t[103]!==Ee?(De=(0,$.jsxs)(`div`,{children:[xe,Te,Ee]}),t[101]=xe,t[102]=Te,t[103]=Ee,t[104]=De):De=t[104];let Oe;t[105]!==be||t[106]!==De?(Oe=(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[be,De]}),t[105]=be,t[106]=De,t[107]=Oe):Oe=t[107];let ke;t[108]===s.costSection?ke=t[109]:(ke=(0,$.jsx)(`p`,{className:`mb-2 text-xs font-semibold text-fg`,children:s.costSection}),t[108]=s.costSection,t[109]=ke);let Ae;t[110]===s.costInput?Ae=t[111]:(Ae=(0,$.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:s.costInput}),t[110]=s.costInput,t[111]=Ae);let Me;t[112]===Symbol.for(`react.memo_cache_sentinel`)?(Me=qe(),t[112]=Me):Me=t[112];let Ne=u.cost?.input??0,Pe;t[113]===u.cost?Pe=t[114]:(Pe=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]=Pe);let Fe;t[115]!==Ne||t[116]!==Pe?(Fe=(0,$.jsx)(`input`,{type:`number`,step:`any`,min:0,className:Me,value:Ne,onChange:Pe}),t[115]=Ne,t[116]=Pe,t[117]=Fe):Fe=t[117];let Ie;t[118]!==Ae||t[119]!==Fe?(Ie=(0,$.jsxs)(`div`,{children:[Ae,Fe]}),t[118]=Ae,t[119]=Fe,t[120]=Ie):Ie=t[120];let Le;t[121]===s.costOutput?Le=t[122]:(Le=(0,$.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:s.costOutput}),t[121]=s.costOutput,t[122]=Le);let Re;t[123]===Symbol.for(`react.memo_cache_sentinel`)?(Re=qe(),t[123]=Re):Re=t[123];let ze=u.cost?.output??0,Be;t[124]===u.cost?Be=t[125]:(Be=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]=Be);let Ve;t[126]!==ze||t[127]!==Be?(Ve=(0,$.jsx)(`input`,{type:`number`,step:`any`,min:0,className:Re,value:ze,onChange:Be}),t[126]=ze,t[127]=Be,t[128]=Ve):Ve=t[128];let Ue;t[129]!==Le||t[130]!==Ve?(Ue=(0,$.jsxs)(`div`,{children:[Le,Ve]}),t[129]=Le,t[130]=Ve,t[131]=Ue):Ue=t[131];let We;t[132]!==Ie||t[133]!==Ue?(We=(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[Ie,Ue]}),t[132]=Ie,t[133]=Ue,t[134]=We):We=t[134];let Ge;t[135]!==ke||t[136]!==We?(Ge=(0,$.jsxs)(`div`,{className:`border-t border-edge-subtle pt-2 dark:border-edge`,children:[ke,We]}),t[135]=ke,t[136]=We,t[137]=Ge):Ge=t[137];let Ke;t[138]!==B||t[139]!==K||t[140]!==de||t[141]!==Oe||t[142]!==Ge?(Ke=(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[B,K,de,Oe,Ge]}),t[138]=B,t[139]=K,t[140]=de,t[141]=Oe,t[142]=Ge,t[143]=Ke):Ke=t[143];let Je;t[144]===s.cancel?Je=t[145]:(Je=(0,$.jsx)(N,{asChild:!0,children:(0,$.jsx)(X,{type:`button`,variant:`secondary`,children:s.cancel})}),t[144]=s.cancel,t[145]=Je);let Ye=r?s.addModelConfirm:s.saveModelConfirm,Xe;t[146]!==y||t[147]!==Ye?(Xe=(0,$.jsx)(X,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:y,children:Ye}),t[146]=y,t[147]=Ye,t[148]=Xe):Xe=t[148];let Ze;t[149]!==Je||t[150]!==Xe?(Ze=(0,$.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2 border-t border-edge-subtle pt-3 dark:border-edge`,children:[Je,Xe]}),t[149]=Je,t[150]=Xe,t[151]=Ze):Ze=t[151];let Qe;return t[152]!==j||t[153]!==Ke||t[154]!==Ze?(Qe=(0,$.jsxs)($.Fragment,{children:[j,Ke,Ze]}),t[152]=j,t[153]=Ke,t[154]=Ze,t[155]=Qe):Qe=t[155],Qe}function ar(){return new Map}function or(e){let t=(0,Z.c)(16),{open:n,onOpenChange:r,providerId:i,model:a,isNew:o,onSave:s,m:c}=e,u;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(u=(0,$.jsx)(ft,{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`,Je,`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)(ir,{model:a,isNew:o,providerId:i,onSave:s,onClose:()=>r(!1),m:c},`${i??`none`}-${a?.id??`new`}`):null,t[2]=o,t[3]=c,t[4]=a,t[5]=r,t[6]=s,t[7]=n,t[8]=i,t[9]=f):f=t[9];let p;t[10]===f?p=t[11]:(p=(0,$.jsxs)(b,{children:[u,(0,$.jsx)(L,{className:d,onOpenAutoFocus:sr,children:f})]}),t[10]=f,t[11]=p);let m;return t[12]!==r||t[13]!==n||t[14]!==p?(m=(0,$.jsx)(O,{open:n,onOpenChange:r,children:p}),t[12]=r,t[13]=n,t[14]=p,t[15]=m):m=t[15],m}function sr(e){return e.preventDefault()}function cr(e){let t=(0,Z.c)(14),{providerId:n,inputId:r,value:i,onChange:a,labels:o}=e,s;t[0]===n?s=t[1]:(s=()=>ze(n).then(lr),t[0]=n,t[1]=s);let c=s,l;t[2]!==r||t[3]!==o.apiKeyLabel?(l=(0,$.jsx)(`label`,{htmlFor:r,className:`text-sm font-medium text-fg`,children:o.apiKeyLabel}),t[2]=r,t[3]=o.apiKeyLabel,t[4]=l):l=t[4];let u;t[5]!==r||t[6]!==o||t[7]!==a||t[8]!==c||t[9]!==i?(u=(0,$.jsx)(Ne,{id:r,value:i,onChange:a,placeholder:o.apiKeyPlaceholder,labels:o,reveal:c,loadFailedLabel:o.loadFailed,maskedHelp:o.maskedHelp,notInConfigFile:o.notInConfigFile}),t[5]=r,t[6]=o,t[7]=a,t[8]=c,t[9]=i,t[10]=u):u=t[10];let d;return t[11]!==l||t[12]!==u?(d=(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[l,u]}),t[11]=l,t[12]=u,t[13]=d):d=t[13],d}function lr(e){return e.apiKey??null}function ur(e){let t=(0,Z.c)(16),{open:n,onOpenChange:r,providerId:i,isCustom:a,builtinRows:o,customConfig:s,allModels:c,labels:u,language:d,onSaved:f}=e,p;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(ft,{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`,Je),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)(b,{children:[p,(0,$.jsx)(L,{className:m,children:a?(0,$.jsx)(fr,{providerId:i,customConfig:s,labels:u,language:d,onClose:()=>r(!1),onSaved:f}):(0,$.jsx)(dr,{providerId:i,builtinRows:o,allModels:c,labels:u,language:d,onClose:()=>r(!1),onSaved:f})})]}),t[2]=c,t[3]=o,t[4]=s,t[5]=a,t[6]=u,t[7]=d,t[8]=r,t[9]=f,t[10]=i,t[11]=h):h=t[11];let g;return t[12]!==r||t[13]!==n||t[14]!==h?(g=(0,$.jsx)(O,{open:n,onOpenChange:r,children:h}),t[12]=r,t[13]=n,t[14]=h,t[15]=g):g=t[15],g}function dr({providerId:e,builtinRows:t,allModels:n,labels:r,language:i,onClose:a,onSaved:o}){let s=t.find(t=>t.id===e),d=le[e],f=n.filter(t=>t.provider===e),[p,m]=(0,Q.useState)(s?.apiKey??``),[h,g]=(0,Q.useState)(!1),[_,v]=(0,Q.useState)(!1),[y,b]=(0,Q.useState)(null),[x,S]=(0,Q.useState)(!1),D=u(i).providersSettings,O=s?.supportsApiKey!==!1,A=s?.supportsOAuth===!0,j=s?.authMode===`oauth`&&s.authStatus===`connected`,M=s?.configured===!0&&s.activeKeySource!==`env`&&s.activeKeySource!==`extension`&&s.activeKeySource!==`models_json`,[F,L]=(0,Q.useState)(null),[ee,R]=(0,Q.useState)(null),[z,B]=(0,Q.useState)(`idle`),[V,H]=(0,Q.useState)(null),[U,te]=(0,Q.useState)(null),[W,G]=(0,Q.useState)(null),[K,q]=(0,Q.useState)(``),J=(0,Q.useRef)(null),ie=(0,Q.useRef)(null),ce=z===`waiting`||z===`waiting_code`,ue=(0,Q.useMemo)(()=>se(e,i),[e,i]),Y=p!==(s?.apiKey??``),fe=async()=>{let t=p.trim();if(!(!t||!O||E(t))){g(!0),b(null);try{await Be({[e]:t}),v(!0),window.setTimeout(()=>{o(),a()},600)}catch(e){b(e instanceof Error?e.message:r.saveError)}finally{g(!1)}}};(0,Q.useEffect)(()=>{if(!F||!ce)return;let e=window.setInterval(()=>{(async()=>{try{let t=await ut(F);t.status===`waiting_auth`||t.status===`waiting_code`?(B(t.status===`waiting_code`?`waiting_code`:`waiting`),R(t.message??null),H(t.authUrl??null),te(t.instructions??null),G(t.deviceCode??null),t.authUrl&&t.authUrl!==ie.current&&(ie.current=t.authUrl,Ln(t.authUrl,J.current).catch(()=>{}))):t.status===`completed`?(window.clearInterval(e),Rn(J.current),J.current=null,B(`success`),R(t.message??D.saved),window.setTimeout(()=>{o(),a()},600)):(t.status===`failed`||t.status===`cancelled`)&&(window.clearInterval(e),Rn(J.current),J.current=null,B(`error`),R(t.error??t.message??D.revokeFailed))}catch{}})()},1e3);return()=>window.clearInterval(e)},[F,ce,a,o,D.revokeFailed,D.saved]),(0,Q.useEffect)(()=>()=>{F&&ve(F).catch(()=>{})},[F]),(0,Q.useEffect)(()=>()=>{Rn(J.current),J.current=null},[]);let me=async()=>{try{await re(e),o(),a()}catch{}},he=async()=>{Rn(J.current),J.current=In(),ie.current=null,B(`waiting`),R(D.oauthStarting),H(null),te(null),G(null),b(null);try{L((await w(e)).sessionId)}catch(e){Rn(J.current),J.current=null,B(`error`),R(e instanceof Error?e.message:D.revokeFailed)}},ge=async()=>{if(F){try{await dt(F)}catch{}Rn(J.current),J.current=null,ie.current=null,B(`idle`),R(null),L(null),H(null),te(null),G(null)}},_e=async()=>{if(!(!F||!K.trim()))try{await at(F,K.trim()),q(``),R(D.oauthProcessingCode)}catch(e){B(`error`),R(e instanceof Error?e.message:D.revokeFailed)}},ye=async()=>{try{await ne(e),o(),a()}catch(e){b(e instanceof Error?e.message:D.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)(ae,{className:`text-base font-semibold text-fg`,children:s?.name??e}),(0,$.jsx)(N,{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`,tt.press),children:(0,$.jsx)(T,{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,s?.baseUrl?(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:r.apiUrlLabel}),(0,$.jsx)(`code`,{className:`break-all rounded-lg border border-edge-subtle bg-surface-panel/60 px-3 py-2 font-mono text-xs text-fg-muted`,children:s.baseUrl})]}):s?.category===`extension`?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:r.apiUrlExtensionHint}):null,O?(0,$.jsx)(cr,{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}}):s?.category===`extension`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-lg border border-edge-subtle bg-surface-panel/60 px-3 py-2 text-sm text-fg-muted`,children:[(0,$.jsx)(`p`,{children:r.extensionKeyHint}),s?.extensionId?(0,$.jsxs)(c,{to:`/settings/ext/${encodeURIComponent(s.extensionId)}`,className:`inline-flex w-fit items-center gap-1 font-medium text-accent hover:underline`,title:r.extensionSettingsLinkTitle,onClick:a,children:[r.openExtensionSettings,(0,$.jsx)(I,{className:`size-3`,"aria-hidden":!0})]}):null]}):null,A?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-lg border border-edge-subtle bg-surface-panel/60 p-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:D.oauth}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:j?D.sourceOauth:D.oauthHint})]}),j?(0,$.jsx)(X,{type:`button`,variant:`secondary`,className:`gap-1.5 text-red-600 dark:text-red-400`,onClick:()=>void ye(),children:D.revoke}):(0,$.jsxs)(X,{type:`button`,variant:`primary`,className:`gap-1.5`,disabled:ce,onClick:()=>void he(),children:[ce?(0,$.jsx)(P,{className:`size-3.5 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(k,{className:`size-3.5`,"aria-hidden":!0}),D.oauth]})]}),ee?(0,$.jsx)(`p`,{className:l(`text-xs`,z===`error`?`text-red-600 dark:text-red-400`:`text-fg-muted`),children:ee}):null,z===`waiting`||z===`waiting_code`?(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[V?(0,$.jsxs)(`a`,{href:V,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1.5 rounded-md bg-accent px-3 py-2 text-sm font-medium text-white hover:bg-accent-hover`,children:[(0,$.jsx)(I,{className:`size-4`,"aria-hidden":!0}),D.openAuthPage]}):null,(0,$.jsx)(X,{type:`button`,variant:`secondary`,onClick:()=>void ge(),children:D.cancelOAuth})]}):null,U?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:U}):null,W?(0,$.jsxs)(`div`,{className:`rounded-lg border border-edge-subtle bg-surface-panel px-3 py-2`,children:[(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:D.deviceCodeLabel}),(0,$.jsx)(`code`,{className:`mt-1 block select-all font-mono text-lg font-semibold tracking-widest text-fg`,children:W}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:D.deviceCodeHint})]}):null,z===`waiting_code`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,$.jsx)(`input`,{type:`text`,value:K,onChange:e=>q(e.target.value),onKeyDown:e=>e.key===`Enter`&&void _e(),placeholder:D.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`,C)}),(0,$.jsx)(X,{type:`button`,variant:`primary`,onClick:()=>void _e(),children:D.submitCode})]}):null]}):null,ue.length>0&&O?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:ue.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:[de(e,r),(0,$.jsx)(I,{className:`size-3`,"aria-hidden":!0})]},e))}):null,f.length>0?(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsxs)(`span`,{className:`text-sm font-medium text-fg`,children:[r.modelsLabel,` (`,f.length,`)`]}),(0,$.jsx)(`div`,{className:`max-h-40 overflow-y-auto rounded-lg border border-edge-subtle bg-surface-panel/40 p-2`,children:(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:f.map(e=>(0,$.jsx)(`span`,{className:`inline-block rounded-md bg-surface-hover px-2 py-1 text-xs text-fg-muted`,children:e.id.includes(`/`)?e.id.split(`/`).pop():e.id},e.id))})})]}):(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:r.noModels}),y?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:y}):null]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-t border-edge-subtle px-5 py-3`,children:[M?(0,$.jsxs)(X,{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:()=>S(!0),children:[(0,$.jsx)(oe,{className:`size-3.5`,"aria-hidden":!0}),r.remove]}):(0,$.jsx)(`span`,{}),(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:O&&Y&&!E(p.trim())?(0,$.jsx)(X,{type:`button`,variant:`primary`,disabled:!p.trim()||h||_,onClick:()=>void fe(),children:_?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(xe,{className:`size-3.5`,"aria-hidden":!0}),r.saved]}):h?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(P,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),r.saving]}):r.save}):null})]}),(0,$.jsx)(pe,{open:x,title:r.removeConfirmTitle,description:r.removeConfirmDescription.replace(`{{provider}}`,s?.name??e),confirmLabel:r.removeConfirmAction,cancelLabel:r.cancel,destructive:!0,onConfirm:()=>void me(),onCancel:()=>S(!1)})]})}function fr({providerId:e,customConfig:t,labels:n,language:r,onClose:i,onSaved:a}){let o=u(r).modelsSettings,s=t?.providers[e],[c,d]=(0,Q.useState)(s?.baseUrl??``),[f,p]=(0,Q.useState)(s?.apiKey??``),[m,h]=(0,Q.useState)(s?.models??[]),[g,_]=(0,Q.useState)(s?.modelDiscovery?.enabled===!0),[v,y]=(0,Q.useState)(!1),[b,x]=(0,Q.useState)(null),[S,w]=(0,Q.useState)(!1),[D,O]=(0,Q.useState)(null),[k,A]=(0,Q.useState)(!1),[j,M]=(0,Q.useState)(null),F=n=>{if(!t)return null;let r=f.trim(),i={...s,baseUrl:c.trim()||void 0,apiKey:E(r)?s?.apiKey:r||void 0,...n};return{providers:{...t.providers,[e]:i}}},I=async()=>{let e=F({models:m,modelDiscovery:{enabled:g}});if(e){y(!0),x(null);try{await Ve(e),a(),i()}catch(e){x(e instanceof Error?e.message:n.saveError)}finally{y(!1)}}},L=async()=>{if(t)try{let{[e]:n,...r}=t.providers;await Ve({providers:r}),a(),i()}catch{}},ee=(e,t)=>{M({model:e,isNew:t}),A(!0)},R=async e=>{if(!j)return;let t=j.isNew?[...m,e]:m.map(t=>t.id===e.id?e:t);h(t);let r=F({models:t});if(r)try{await Ve(r),a()}catch(e){x(e instanceof Error?e.message:n.saveError)}},z=async e=>{let t=m.filter(t=>t.id!==e);h(t),O(null);let r=F({models:t});if(r)try{await Ve(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)(ae,{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)(N,{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`,tt.press),children:(0,$.jsx)(T,{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`,C)})]}),(0,$.jsx)(cr,{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)(X,{type:`button`,variant:`primary`,className:`gap-1.5 px-2 py-1 text-xs`,onClick:()=>ee(null,!0),children:[(0,$.jsx)(q,{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`,tt.press),onClick:()=>ee(e,!1),"aria-label":o.editModel,children:(0,$.jsx)(V,{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`,tt.press),onClick:()=>O(e.id),"aria-label":o.removeModel,children:(0,$.jsx)(oe,{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)(X,{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:()=>w(!0),children:[(0,$.jsx)(oe,{className:`size-3.5`,"aria-hidden":!0}),n.remove]}),(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsx)(X,{type:`button`,variant:`primary`,disabled:v,onClick:()=>void I(),children:v?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(P,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),n.saving]}):n.save})})]}),(0,$.jsx)(pe,{open:S,title:n.removeConfirmTitle,description:n.removeConfirmDescription.replace(`{{provider}}`,e),confirmLabel:n.removeConfirmAction,cancelLabel:n.cancel,destructive:!0,onConfirm:()=>void L(),onCancel:()=>w(!1)}),(0,$.jsx)(pe,{open:D!==null,title:o.removeModel,description:o.removeModelConfirm.replace(`{{id}}`,D??``),confirmLabel:n.removeConfirmAction,cancelLabel:n.cancel,destructive:!0,onConfirm:()=>{D&&z(D)},onCancel:()=>O(null)}),(0,$.jsx)(or,{open:k,onOpenChange:e=>{A(e),e||M(null)},providerId:e,model:j?.model??null,isNew:j?.isNew??!1,onSave:e=>void R(e),m:o})]})}async function pr(){let e=await p(m(`/api/models/catalog`)),t=await e.json().catch(()=>null);if(!e.ok||!t?.ok||!t.payload)throw Error(t?.error?.message??`HTTP ${e.status}`);return t.payload}function mr(){let e=f(e=>e.language)===`zh`,{data:t,error:n,isLoading:r}=g(B,pr,{revalidateOnFocus:!1}),[i,a]=(0,Q.useState)(!1),[o,s]=(0,Q.useState)(null);if(r)return(0,$.jsx)(z,{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 U()}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)(x,{className:`size-4 text-amber-500`,"aria-hidden":!0}):(0,$.jsx)(xe,{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)(X,{type:`button`,variant:`secondary`,disabled:i,onClick:()=>void _(),children:[i?(0,$.jsx)(P,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Me,{className:`size-4`,"aria-hidden":!0}),i?e?`刷新中…`:`Refreshing…`:e?`立即刷新`:`Refresh now`]})]})})}async function hr(){return(await h(m(`/api/models/xopc-cloud/account-summary`))).payload}function gr(e){let t=(0,Z.c)(93),{labels:n}=e,r=f(_r)===`zh`?`zh-CN`:`en-US`,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i={refreshInterval:6e4,revalidateOnFocus:!0},t[0]=i):i=t[0];let{data:a,error:o,isLoading:s,isValidating:c,mutate:l}=g(`/api/models/xopc-cloud/account-summary`,hr,i);if(s){let e;return t[1]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(z,{className:`h-48 w-full rounded-2xl`}),t[1]=e):e=t[1],e}if(o||!a){let e;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(x,{className:`mt-0.5 size-4 shrink-0 text-amber-500`,"aria-hidden":!0}),t[2]=e):e=t[2];let r;t[3]===n.title?r=t[4]:(r=(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:n.title}),t[3]=n.title,t[4]=r);let i;t[5]===n.unavailable?i=t[6]:(i=(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.unavailable}),t[5]=n.unavailable,t[6]=i);let a;t[7]!==r||t[8]!==i?(a=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-start gap-3`,children:[e,(0,$.jsxs)(`div`,{children:[r,i]})]}),t[7]=r,t[8]=i,t[9]=a):a=t[9];let o;t[10]===l?o=t[11]:(o=()=>void l(),t[10]=l,t[11]=o);let s=c?`size-4 animate-spin`:`size-4`,u;t[12]===s?u=t[13]:(u=(0,$.jsx)(Me,{className:s,"aria-hidden":!0}),t[12]=s,t[13]=u);let d;t[14]!==c||t[15]!==n.retry||t[16]!==o||t[17]!==u?(d=(0,$.jsxs)(X,{type:`button`,variant:`secondary`,disabled:c,onClick:o,children:[u,n.retry]}),t[14]=c,t[15]=n.retry,t[16]=o,t[17]=u,t[18]=d):d=t[18];let f;return t[19]!==a||t[20]!==d?(f=(0,$.jsx)(`section`,{className:`rounded-2xl border border-edge-subtle bg-surface-panel/40 p-4`,children:(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[a,d]})}),t[19]=a,t[20]=d,t[21]=f):f=t[21],f}let u,d,p,m,h,_,v,y;if(t[22]!==a.balance.credits||t[23]!==a.usage.chargedCredits||t[24]!==a.usage.requests||t[25]!==a.usage.totalTokens||t[26]!==n.availableCredits||t[27]!==n.connected||t[28]!==n.title||t[29]!==n.usageSummary||t[30]!==r){let e=new Intl.NumberFormat(r);y=n.usageSummary.replace(`{{tokens}}`,e.format(a.usage.totalTokens)).replace(`{{credits}}`,e.format(a.usage.chargedCredits)).replace(`{{requests}}`,e.format(a.usage.requests)),v=`rounded-2xl border border-edge-subtle bg-surface-panel/40 p-5`,_=`flex flex-col gap-5 sm:flex-row sm:items-start sm:justify-between`,p=`min-w-0 flex-1`;let i;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(ue,{className:`size-4 text-accent-fg`,"aria-hidden":!0}),t[39]=i):i=t[39];let o;t[40]===n.title?o=t[41]:(o=(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:n.title}),t[40]=n.title,t[41]=o);let s;t[42]===n.connected?s=t[43]:(s=(0,$.jsx)(`span`,{className:`rounded-full bg-emerald-500/10 px-2 py-0.5 text-xs font-medium text-emerald-700 dark:text-emerald-300`,children:n.connected}),t[42]=n.connected,t[43]=s),t[44]!==o||t[45]!==s?(m=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[i,o,s]}),t[44]=o,t[45]=s,t[46]=m):m=t[46],t[47]===n.availableCredits?h=t[48]:(h=(0,$.jsx)(`p`,{className:`mt-5 text-xs font-medium text-fg-subtle`,children:n.availableCredits}),t[47]=n.availableCredits,t[48]=h),u=`mt-1 text-3xl font-semibold tracking-tight text-fg`,d=e.format(a.balance.credits),t[22]=a.balance.credits,t[23]=a.usage.chargedCredits,t[24]=a.usage.requests,t[25]=a.usage.totalTokens,t[26]=n.availableCredits,t[27]=n.connected,t[28]=n.title,t[29]=n.usageSummary,t[30]=r,t[31]=u,t[32]=d,t[33]=p,t[34]=m,t[35]=h,t[36]=_,t[37]=v,t[38]=y}else u=t[31],d=t[32],p=t[33],m=t[34],h=t[35],_=t[36],v=t[37],y=t[38];let b;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,$.jsx)(`span`,{className:`ml-2 text-sm font-medium text-fg-muted`,children:`credits`}),t[49]=b):b=t[49];let S;t[50]!==u||t[51]!==d?(S=(0,$.jsxs)(`p`,{className:u,children:[d,b]}),t[50]=u,t[51]=d,t[52]=S):S=t[52];let C;t[53]!==a.balance.credits||t[54]!==n.zeroBalance?(C=a.balance.credits===0?(0,$.jsx)(`p`,{className:`mt-2 text-sm font-medium text-danger`,children:n.zeroBalance}):null,t[53]=a.balance.credits,t[54]=n.zeroBalance,t[55]=C):C=t[55];let w;t[56]===n.recentUsage?w=t[57]:(w=(0,$.jsx)(`p`,{className:`mt-5 text-xs font-medium text-fg-subtle`,children:n.recentUsage}),t[56]=n.recentUsage,t[57]=w);let T;t[58]===y?T=t[59]:(T=(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:y}),t[58]=y,t[59]=T);let E;t[60]!==a.balance.updatedAt||t[61]!==n.updatedAt||t[62]!==r?(E=n.updatedAt.replace(`{{time}}`,new Date(a.balance.updatedAt).toLocaleString(r)),t[60]=a.balance.updatedAt,t[61]=n.updatedAt,t[62]=r,t[63]=E):E=t[63];let D;t[64]===E?D=t[65]:(D=(0,$.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:E}),t[64]=E,t[65]=D);let O;t[66]!==S||t[67]!==C||t[68]!==w||t[69]!==T||t[70]!==D||t[71]!==p||t[72]!==m||t[73]!==h?(O=(0,$.jsxs)(`div`,{className:p,children:[m,h,S,C,w,T,D]}),t[66]=S,t[67]=C,t[68]=w,t[69]=T,t[70]=D,t[71]=p,t[72]=m,t[73]=h,t[74]=O):O=t[74];let k;t[75]===Symbol.for(`react.memo_cache_sentinel`)?(k=(0,$.jsx)(I,{className:`size-3.5`,"aria-hidden":!0}),t[75]=k):k=t[75];let A;t[76]!==a.links.purchase||t[77]!==n.purchase?(A=(0,$.jsx)(X,{asChild:!0,variant:`primary`,children:(0,$.jsxs)(`a`,{href:a.links.purchase,target:`_blank`,rel:`noreferrer`,children:[n.purchase,k]})}),t[76]=a.links.purchase,t[77]=n.purchase,t[78]=A):A=t[78];let j;t[79]===Symbol.for(`react.memo_cache_sentinel`)?(j=(0,$.jsx)(I,{className:`size-3.5`,"aria-hidden":!0}),t[79]=j):j=t[79];let M;t[80]!==a.links.details||t[81]!==n.details?(M=(0,$.jsx)(X,{asChild:!0,variant:`secondary`,children:(0,$.jsxs)(`a`,{href:a.links.details,target:`_blank`,rel:`noreferrer`,children:[n.details,j]})}),t[80]=a.links.details,t[81]=n.details,t[82]=M):M=t[82];let N;t[83]!==A||t[84]!==M?(N=(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap gap-2`,children:[A,M]}),t[83]=A,t[84]=M,t[85]=N):N=t[85];let P;t[86]!==O||t[87]!==N||t[88]!==_?(P=(0,$.jsxs)(`div`,{className:_,children:[O,N]}),t[86]=O,t[87]=N,t[88]=_,t[89]=P):P=t[89];let F;return t[90]!==P||t[91]!==v?(F=(0,$.jsx)(`section`,{className:v,children:P}),t[90]=P,t[91]=v,t[92]=F):F=t[92],F}function _r(e){return e.language}function vr(e){return ie.includes(e)}function yr(){let e=(0,Z.c)(71),t=f(Sr),n;e[0]===t?n=e[1]:(n=u(t),e[0]=t,e[1]=n);let r=n,l=r.capabilitiesSettings,d=o(),[p,m]=a(),{capability:h}=i(),[g,_]=(0,Q.useState)(!1),[v,b]=(0,Q.useState)(null),x=Jn(),C;e[2]===x.cards?C=e[3]:(C=x.cards.some(xr),e[2]=x.cards,e[3]=C);let w=C,T,E;e[4]!==h||e[5]!==p||e[6]!==m?(T=()=>{if(h!==`models`||p.get(`add`)!==`1`)return;_(!0);let e=new URLSearchParams(p);e.delete(`add`),m(e,{replace:!0})},E=[h,p,m],e[4]=h,e[5]=p,e[6]=m,e[7]=T,e[8]=E):(T=e[7],E=e[8]),(0,Q.useEffect)(T,E);let D;e[9]!==l.modelsHint||e[10]!==l.tabs.models?(D={id:`models`,icon:S,label:l.tabs.models,hint:l.modelsHint},e[9]=l.modelsHint,e[10]=l.tabs.models,e[11]=D):D=e[11];let O;e[12]!==l.imageHint||e[13]!==l.tabs.image?(O={id:`image`,icon:Ce,label:l.tabs.image,hint:l.imageHint},e[12]=l.imageHint,e[13]=l.tabs.image,e[14]=O):O=e[14];let k;e[15]!==l.tabs.voice||e[16]!==l.voiceHint?(k={id:`voice`,icon:y,label:l.tabs.voice,hint:l.voiceHint},e[15]=l.tabs.voice,e[16]=l.voiceHint,e[17]=k):k=e[17];let j;e[18]!==l.searchHint||e[19]!==l.tabs.search?(j={id:`search`,icon:Se,label:l.tabs.search,hint:l.searchHint},e[18]=l.searchHint,e[19]=l.tabs.search,e[20]=j):j=e[20];let M;e[21]!==D||e[22]!==O||e[23]!==k||e[24]!==j?(M=[D,O,k,j],e[21]=D,e[22]=O,e[23]=k,e[24]=j,e[25]=M):M=e[25];let N=M,P;e[26]===d?P=e[27]:(P=e=>d(A(e)),e[26]=d,e[27]=P);let I=P,L=br;if(!vr(h)){let t;return e[28]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(s,{to:A(`models`),replace:!0}),e[28]=t):t=e[28],t}let R=r.nav.settingsCapabilities,z=l.subtitle,B;e[29]===t?B=e[30]:(B=F(t,`configuration`),e[29]=t,e[30]=B);let V;e[31]===Symbol.for(`react.memo_cache_sentinel`)?(V=(0,$.jsx)(ee,{className:`size-4`,"aria-hidden":!0}),e[31]=V):V=e[31];let H;e[32]===l.agentSettingsLink?H=e[33]:(H=(0,$.jsx)(X,{asChild:!0,variant:`secondary`,children:(0,$.jsxs)(c,{to:`/agents`,children:[V,l.agentSettingsLink]})}),e[32]=l.agentSettingsLink,e[33]=H);let U;e[34]!==l.docsLink||e[35]!==l.subtitle||e[36]!==r.nav.settingsCapabilities||e[37]!==B||e[38]!==H?(U=(0,$.jsx)(mt,{title:R,subtitle:z,docsLink:B,docsLabel:l.docsLink,actions:H}),e[34]=l.docsLink,e[35]=l.subtitle,e[36]=r.nav.settingsCapabilities,e[37]=B,e[38]=H,e[39]=U):U=e[39];let te;e[40]!==l.tabsAria||e[41]!==h||e[42]!==N||e[43]!==I?(te=(0,$.jsx)(Nt,{items:N,activeTab:h,onChange:I,ariaLabel:l.tabsAria,tabIdPrefix:`capability-tab`,panelIdPrefix:`capability-panel`}),e[40]=l.tabsAria,e[41]=h,e[42]=N,e[43]=I,e[44]=te):te=e[44];let W;e[45]!==l.connectedProviders||e[46]!==l.xopcCloudAccount||e[47]!==h||e[48]!==x||e[49]!==N||e[50]!==w?(W=N.map(e=>(0,$.jsx)(wr,{id:e.id,activeSection:h,hint:e.hint,children:e.id===`models`?(0,$.jsxs)($.Fragment,{children:[w?(0,$.jsx)(gr,{labels:l.xopcCloudAccount}):null,(0,$.jsx)(mr,{}),(0,$.jsx)(er,{labels:l.connectedProviders,data:x,onAdd:()=>_(!0),onManage:(e,t)=>b({providerId:e,isCustom:t})})]}):(0,$.jsx)(Cr,{section:e.id})},e.id)),e[45]=l.connectedProviders,e[46]=l.xopcCloudAccount,e[47]=h,e[48]=x,e[49]=N,e[50]=w,e[51]=W):W=e[51];let G;e[52]!==g||e[53]!==l.addProviderDialog||e[54]!==t||e[55]!==x.builtinRows||e[56]!==x.customConfig?(G=(0,$.jsx)(Vn,{open:g,onOpenChange:_,builtinRows:x.builtinRows,customConfig:x.customConfig,labels:l.addProviderDialog,language:t,onSaved:L}),e[52]=g,e[53]=l.addProviderDialog,e[54]=t,e[55]=x.builtinRows,e[56]=x.customConfig,e[57]=G):G=e[57];let K;e[58]!==l.manageProviderDialog||e[59]!==t||e[60]!==v||e[61]!==x.allModels||e[62]!==x.builtinRows||e[63]!==x.customConfig?(K=v?(0,$.jsx)(ur,{open:!0,onOpenChange:e=>{e||b(null)},providerId:v.providerId,isCustom:v.isCustom,builtinRows:x.builtinRows,customConfig:x.customConfig,allModels:x.allModels,labels:l.manageProviderDialog,language:t,onSaved:L}):null,e[58]=l.manageProviderDialog,e[59]=t,e[60]=v,e[61]=x.allModels,e[62]=x.builtinRows,e[63]=x.customConfig,e[64]=K):K=e[64];let q;return e[65]!==U||e[66]!==te||e[67]!==W||e[68]!==G||e[69]!==K?(q=(0,$.jsxs)(ht,{children:[U,te,W,G,K]}),e[65]=U,e[66]=te,e[67]=W,e[68]=G,e[69]=K,e[70]=q):q=e[70],q}function br(){U()}function xr(e){return e.id===`xopc-cloud`&&!e.isCustom}function Sr(e){return e.language}function Cr(e){let t=(0,Z.c)(3),{section:n}=e;switch(n){case`models`:return null;case`image`:{let e;return t[0]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Yt,{}),t[0]=e):e=t[0],e}case`voice`:{let e;return t[1]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(un,{}),t[1]=e):e=t[1],e}case`search`:{let e;return t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Nn,{}),t[2]=e):e=t[2],e}}}function wr({id:e,activeSection:t,hint:n,children:r}){let i=e===t,a=(0,Q.useRef)(i);return i&&(a.current=!0),a.current?(0,$.jsxs)(`div`,{role:`tabpanel`,id:`capability-panel-${e}`,"aria-labelledby":`capability-tab-${e}`,hidden:!i,className: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{yr as CapabilitiesSettingsPanel};