@xopcai/xopc 0.0.247 → 0.0.248
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.
- package/dist/browser-ext/manifest.json +1 -1
- package/dist/extensions/telegram/src/update-offset-store.js +17 -54
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/extensions/weixin/src/auth/accounts.js +3 -5
- package/dist/extensions/weixin/src/monitor/monitor.js +3 -5
- package/dist/extensions/weixin/src/storage/sync-buf.d.ts +3 -6
- package/dist/extensions/weixin/src/storage/sync-buf.js +9 -22
- package/dist/gateway/static/root/assets/{activity-store-BlxqErph.js → activity-store-etpmyV7S.js} +1 -1
- package/dist/gateway/static/root/assets/{agent-avatar-dicebear-DmaFeojS.js → agent-avatar-dicebear-BmKxSM1k.js} +1 -1
- package/dist/gateway/static/root/assets/agent-defaults-settings-panel-CUXApfcE.js +1 -0
- package/dist/gateway/static/root/assets/{agents-CZwf1mgZ.js → agents-DNq_GKuc.js} +1 -1
- package/dist/gateway/static/root/assets/{api-BbXzyQMj.js → api-B0-hLuZ1.js} +1 -1
- package/dist/gateway/static/root/assets/{app-management-settings-panel-BODskFTb.js → app-management-settings-panel-qfwAgyhQ.js} +1 -1
- package/dist/gateway/static/root/assets/{appearance-settings-DeaVvaYZ.js → appearance-settings-DqQVUpCC.js} +1 -1
- package/dist/gateway/static/root/assets/apps-page-dwIqYmXk.js +1 -0
- package/dist/gateway/static/root/assets/{archive-plugin-DD2SweEH.js → archive-plugin-BnMSgZvR.js} +1 -1
- package/dist/gateway/static/root/assets/{attachment-load-BG82bNBQ.js → attachment-load-CejsQMev.js} +1 -1
- package/dist/gateway/static/root/assets/{automations-page-CqBZ89He.js → automations-page-RC8EyoAf.js} +1 -1
- package/dist/gateway/static/root/assets/automations-workspace-SkdcSZ0i.js +6 -0
- package/dist/gateway/static/root/assets/{binary-plugins-B6LKm5Zv.js → binary-plugins-DGjppLSG.js} +1 -1
- package/dist/gateway/static/root/assets/{block-editor-BJKvGVXd.js → block-editor-CWdP4bUc.js} +44 -44
- package/dist/gateway/static/root/assets/browser-settings-page-CKCa6TvG.js +8 -0
- package/dist/gateway/static/root/assets/{browser-workflow-inputs-BAAc151l.js → browser-workflow-inputs-BQ1Ilw_o.js} +1 -1
- package/dist/gateway/static/root/assets/{browser-workflows-page-DoE4Uuns.js → browser-workflows-page-CJh4NyxT.js} +2 -2
- package/dist/gateway/static/root/assets/{capabilities-settings-panel-Cg7zCxEH.js → capabilities-settings-panel-DSp--zIZ.js} +5 -5
- package/dist/gateway/static/root/assets/channels-settings-CMd2dDrI.js +1 -0
- package/dist/gateway/static/root/assets/{channels-status-swr-CCBCtLDg.js → channels-status-swr-Ohhee4vm.js} +1 -1
- package/dist/gateway/static/root/assets/{chat-terminal-dock-BsRWnz7M.js → chat-terminal-dock-BOtoKTK3.js} +2 -2
- package/dist/gateway/static/root/assets/connectors-page-udWs5Kdm.js +2 -0
- package/dist/gateway/static/root/assets/{cron-expression-DdCgsH2c.js → cron-expression-DTj1V3Sw.js} +1 -1
- package/dist/gateway/static/root/assets/{date-picker-dt37Lt8e.js → date-picker-Yr6OCvGL.js} +1 -1
- package/dist/gateway/static/root/assets/{dependency-picker-oi7cdv2C.js → dependency-picker-DpN3XZg9.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-Nw_Pgkk3.js → desktop-pet-DbGzggPF.js} +1 -1
- package/dist/gateway/static/root/assets/{desktop-pet-settings-D9OO-exo.js → desktop-pet-settings-DinCToZh.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-debug-page-BHSst0WN.js → extension-debug-page-DgTtk4KC.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-DXbL4cQZ.js → extension-page-DtQeiP6f.js} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-FTD7nE8v.js → extension-settings-page-DcguCgsH.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-config-api-c-8ENciH.js → gateway-config-api-Br7lSf6H.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-config-swr-826dipyU.js → gateway-config-swr-DXuXtU1w.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-settings-BxvyTRl0.js → gateway-settings-CdPoDMuj.js} +1 -1
- package/dist/gateway/static/root/assets/{gateway-startup-retry-DyvcAIMm.js → gateway-startup-retry-CzBzglzQ.js} +1 -1
- package/dist/gateway/static/root/assets/{heartbeat-settings-C1S2Ccui.js → heartbeat-settings-DHk1hawP.js} +1 -1
- package/dist/gateway/static/root/assets/home-page-YGipe_W6.js +1 -0
- package/dist/gateway/static/root/assets/{image-generation-api-D7cyfks6.js → image-generation-api-TIgsn04n.js} +1 -1
- package/dist/gateway/static/root/assets/{index-Cif1_3Jx.js → index-D5TQQpeb.js} +44 -44
- package/dist/gateway/static/root/assets/index-DReBaaTX.css +2 -0
- package/dist/gateway/static/root/assets/{keyboard-shortcuts-settings-EY4cu-6W.js → keyboard-shortcuts-settings-wsWuoa8p.js} +1 -1
- package/dist/gateway/static/root/assets/local-app-workbench-page-CpyvYyrb.js +2 -0
- package/dist/gateway/static/root/assets/{local-apps-page-Dh7OxX0S.js → local-apps-page-CXrbrGo8.js} +1 -1
- package/dist/gateway/static/root/assets/local-context-graph-BjUf7fQ9.js +1 -0
- package/dist/gateway/static/root/assets/{locale-store-CBoCuIMx.js → locale-store-BJFLQY8O.js} +1 -1
- package/dist/gateway/static/root/assets/{logs-page-DUsxXdDp.js → logs-page-CXKy6E_l.js} +2 -2
- package/dist/gateway/static/root/assets/{management-settings-ZjiL3A-S.js → management-settings-BdJZFR7U.js} +1 -1
- package/dist/gateway/static/root/assets/{markdown-split-B4BxkTpU.js → markdown-split-NK3ACVG2.js} +1 -1
- package/dist/gateway/static/root/assets/{markdown-view-BXsHghJd.js → markdown-view-DTF9v1gg.js} +1 -1
- package/dist/gateway/static/root/assets/{media-plugins-D15XBiEo.js → media-plugins-F0jcUxyl.js} +1 -1
- package/dist/gateway/static/root/assets/messages-CHNYp8EQ.js +3 -0
- package/dist/gateway/static/root/assets/{mobile-pairing-wizard-Dv87XewB.js → mobile-pairing-wizard-3NKCniSp.js} +1 -1
- package/dist/gateway/static/root/assets/models-hub-cache-nCfkBN8M.js +1 -0
- package/dist/gateway/static/root/assets/{notes-page-DOe0lOcQ.js → notes-page-DuqLahi6.js} +1 -1
- package/dist/gateway/static/root/assets/notes-workbench-C7j9EdQk.js +5 -0
- package/dist/gateway/static/root/assets/{oauth-api-BjSUDIgq.js → oauth-api-8lP_qJpq.js} +1 -1
- package/dist/gateway/static/root/assets/{product-open-page-CAJeUXeU.js → product-open-page-CxGGlWA8.js} +1 -1
- package/dist/gateway/static/root/assets/project-detail-page-CfebYVX0.js +1 -0
- package/dist/gateway/static/root/assets/projects-page-48GvzSVa.js +1 -0
- package/dist/gateway/static/root/assets/{registry-api-BhGKnvLP.js → registry-api-CIsNlSBi.js} +1 -1
- package/dist/gateway/static/root/assets/remote-access-hub-64xj_s2m.js +1 -0
- package/dist/gateway/static/root/assets/{runtime-tools-settings-panel-BhKcyEId.js → runtime-tools-settings-panel-YkjhiQfA.js} +2 -2
- package/dist/gateway/static/root/assets/{schema-form-L0s7RWCi.js → schema-form-oFGf3G3s.js} +1 -1
- package/dist/gateway/static/root/assets/sessions-page-CcwcdRN8.js +1 -0
- package/dist/gateway/static/root/assets/settings-advanced-gate-BaN84CyW.js +1 -0
- package/dist/gateway/static/root/assets/{settings-page-CTKoztlF.js → settings-page-C7VWs0IT.js} +1 -1
- package/dist/gateway/static/root/assets/setup-status-panel-DVVOCNbr.js +1 -0
- package/dist/gateway/static/root/assets/{share-preview-page-CiiLLz5A.js → share-preview-page-t5oz18rh.js} +1 -1
- package/dist/gateway/static/root/assets/shares-settings-DUYbYLi7.js +1 -0
- package/dist/gateway/static/root/assets/skill-reload-api-BGyD0gB9.js +1 -0
- package/dist/gateway/static/root/assets/{skills-page-cBT9jCof.js → skills-page-CjF8DTsN.js} +1 -1
- package/dist/gateway/static/root/assets/{skills-page.utils-CwRekJSJ.js → skills-page.utils-DEDTYs2W.js} +1 -1
- package/dist/gateway/static/root/assets/{system-settings-panel-Byrk4DQy.js → system-settings-panel-BSYuRgFI.js} +1 -1
- package/dist/gateway/static/root/assets/task-detail-page-YZYSTJH7.js +1 -0
- package/dist/gateway/static/root/assets/{theme-store-hybK3oC9.js → theme-store-O597U8q_.js} +1 -1
- package/dist/gateway/static/root/assets/{tunnel-api-jKzujxFU.js → tunnel-api-FKUi9wDL.js} +1 -1
- package/dist/gateway/static/root/assets/{use-autosave-DX5YZ3Nn.js → use-autosave-B5eUJ6Zq.js} +1 -1
- package/dist/gateway/static/root/assets/user-context-page-BCyiduKd.js +2 -0
- package/dist/gateway/static/root/assets/{voice-api-key-field-ocnZbAyi.js → voice-api-key-field-CMKSwz4C.js} +1 -1
- package/dist/gateway/static/root/assets/{voice-config-api-CBbiF1T3.js → voice-config-api-q7B6fOFB.js} +1 -1
- package/dist/gateway/static/root/assets/{work-discovery-overlay-DE4_YpDn.js → work-discovery-overlay-jhT2EzeH.js} +1 -1
- package/dist/gateway/static/root/assets/{workflow-run-setup-panel-DaErGvxO.js → workflow-run-setup-panel-DZmvLZjb.js} +2 -2
- package/dist/gateway/static/root/assets/workflows-page-DQC0TpMa.js +5 -0
- package/dist/gateway/static/root/index.html +12 -12
- package/dist/package.js +1 -1
- package/dist/src/agent/commands/command-registry.d.ts +1 -0
- package/dist/src/agent/commands/command-registry.js +12 -22
- package/dist/src/agent/ipc/inbox.d.ts +8 -31
- package/dist/src/agent/ipc/inbox.js +64 -133
- package/dist/src/agent/service/process-direct-one-shot.js +15 -10
- package/dist/src/agent/workflow/catalog.d.ts +1 -8
- package/dist/src/agent/workflow/catalog.js +44 -102
- package/dist/src/agent/workflow/index.d.ts +1 -1
- package/dist/src/agent/workflow/index.js +2 -2
- package/dist/src/automations/domain/types.d.ts +1 -0
- package/dist/src/automations/service/action-executor.js +2 -2
- package/dist/src/automations/service/automation-service.js +2 -2
- package/dist/src/channels/manager.d.ts +1 -1
- package/dist/src/channels/manager.js +2 -2
- package/dist/src/channels/outbound/persist-store.d.ts +2 -8
- package/dist/src/channels/outbound/persist-store.js +11 -38
- package/dist/src/channels/outbound-sender.d.ts +1 -1
- package/dist/src/channels/outbound-sender.js +2 -2
- package/dist/src/cli/commands/connectors.js +1 -1
- package/dist/src/cli/commands/doctor/checks/database-schema.js +1 -1
- package/dist/src/config/schema.js +2 -2
- package/dist/src/connectors/auth-provider-registry.js +1 -1
- package/dist/src/connectors/composio-triggers.d.ts +2 -2
- package/dist/src/connectors/composio-triggers.js +8 -15
- package/dist/src/connectors/connected-source-ingestion.js +1 -1
- package/dist/src/connectors/health.js +1 -1
- package/dist/src/gateway/automation-agent-session.js +3 -0
- package/dist/src/gateway/hono/lib/extension-store.js +8 -25
- package/dist/src/gateway/hono/routes/capabilities.js +1 -1
- package/dist/src/gateway/hono/routes/connectors.js +3 -3
- package/dist/src/gateway/hono/routes/mcp.js +1 -1
- package/dist/src/gateway/hono/routes/projects.js +1 -1
- package/dist/src/gateway/hono/routes/workflows.js +2 -2
- package/dist/src/gateway/hono/routes/you.js +16 -2
- package/dist/src/gateway/service.js +4 -5
- package/dist/src/notes/index.d.ts +1 -1
- package/dist/src/notes/index.js +2 -2
- package/dist/src/notes/paths.d.ts +0 -3
- package/dist/src/notes/paths.js +1 -10
- package/dist/src/notes/service.d.ts +0 -1
- package/dist/src/notes/service.js +0 -3
- package/dist/src/notes/store.d.ts +0 -2
- package/dist/src/notes/store.js +33 -80
- package/dist/src/share/hosted-session-share.d.ts +1 -4
- package/dist/src/share/hosted-session-share.js +14 -47
- package/dist/src/share/share-auto.d.ts +1 -1
- package/dist/src/share/share-auto.js +2 -2
- package/dist/src/share/share-store.d.ts +2 -7
- package/dist/src/share/share-store.js +153 -195
- package/dist/src/share/share-types.d.ts +0 -4
- package/dist/src/share/site-share-store.d.ts +3 -8
- package/dist/src/share/site-share-store.js +94 -153
- package/dist/src/share/site-share-types.d.ts +0 -4
- package/dist/src/storage/sqlite/connection.d.ts +1 -2
- package/dist/src/storage/sqlite/connection.js +50 -47
- package/dist/src/storage/sqlite/durable-queue.d.ts +16 -0
- package/dist/src/storage/sqlite/durable-queue.js +52 -0
- package/dist/src/storage/sqlite/durable-state.d.ts +16 -0
- package/dist/src/storage/sqlite/durable-state.js +43 -0
- package/dist/src/storage/sqlite/migrations/146_understanding_focus_exclusions.sql +9 -0
- package/dist/src/storage/sqlite/migrations/147_durable_application_state.sql +39 -0
- package/dist/src/storage/sqlite/migrations/runner.d.ts +1 -1
- package/dist/src/storage/sqlite/migrations/runner.js +3 -3
- package/dist/src/storage/sqlite/migrations/runner.ts +1 -1
- package/dist/src/storage/sqlite/schema.js +1 -1
- package/dist/src/storage/sqlite/understanding-focus-exclusions.d.ts +2 -0
- package/dist/src/storage/sqlite/understanding-focus-exclusions.js +24 -0
- package/dist/src/tui/tui-scoped-models.js +9 -6
- package/dist/src/tui/tui-startup-resources.js +1 -1
- package/dist/src/voice/realtime/agentEngine.js +63 -18
- package/dist/src/voice/realtime/conversationTurn.d.ts +20 -0
- package/dist/src/voice/realtime/conversationTurn.js +83 -0
- package/dist/src/voice/realtime/omniEngine.js +72 -18
- package/dist/src/workflows/authoring/workflow-draft-store.d.ts +1 -5
- package/dist/src/workflows/authoring/workflow-draft-store.js +23 -43
- package/dist/src/workflows/index.js +2 -2
- package/dist/src/workflows/store/event-store.d.ts +1 -2
- package/dist/src/workflows/store/event-store.js +19 -64
- package/dist/src/workflows/store/paths.d.ts +0 -2
- package/dist/src/workflows/store/paths.js +1 -7
- package/dist/src/workflows/store/run-store.d.ts +0 -1
- package/dist/src/workflows/store/run-store.js +1 -24
- package/package.json +3 -3
- package/dist/gateway/static/root/assets/agent-defaults-settings-panel-eG49pM-z.js +0 -1
- package/dist/gateway/static/root/assets/apps-page-BZG3BK7f.js +0 -1
- package/dist/gateway/static/root/assets/automations-workspace-CB7Yl2_B.js +0 -6
- package/dist/gateway/static/root/assets/browser-settings-page-Bu42Ljfw.js +0 -8
- package/dist/gateway/static/root/assets/channels-settings-EDTZ8P3y.js +0 -1
- package/dist/gateway/static/root/assets/connectors-page-kh7PEkSS.js +0 -2
- package/dist/gateway/static/root/assets/home-page-Bqx-SMWV.js +0 -1
- package/dist/gateway/static/root/assets/index-Dbh5SXyV.css +0 -2
- package/dist/gateway/static/root/assets/local-app-workbench-page-sDdw7Y3Q.js +0 -2
- package/dist/gateway/static/root/assets/messages-BbdwoxVo.js +0 -3
- package/dist/gateway/static/root/assets/models-hub-cache-88f4fzYS.js +0 -1
- package/dist/gateway/static/root/assets/notes-workbench-Cy0oYbWP.js +0 -4
- package/dist/gateway/static/root/assets/project-detail-page-fgD1xc4O.js +0 -1
- package/dist/gateway/static/root/assets/projects-page-CiTiEcOc.js +0 -1
- package/dist/gateway/static/root/assets/remote-access-hub-Dc0GrNSp.js +0 -1
- package/dist/gateway/static/root/assets/sessions-page-BPOW3yaM.js +0 -1
- package/dist/gateway/static/root/assets/settings-advanced-gate-Bz4s9BBY.js +0 -1
- package/dist/gateway/static/root/assets/setup-status-panel-rllj-j7k.js +0 -1
- package/dist/gateway/static/root/assets/shares-settings-DMj7onCX.js +0 -1
- package/dist/gateway/static/root/assets/skill-reload-api-DRB366nS.js +0 -1
- package/dist/gateway/static/root/assets/task-detail-page-CheX3zmK.js +0 -1
- package/dist/gateway/static/root/assets/user-context-page-CWy3Pqtk.js +0 -1
- package/dist/gateway/static/root/assets/workflows-page-y4O9-BTf.js +0 -5
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{d as i,l as a,p as o,r as s,t as c}from"./chunk-KS7C4IRE-BaASWQor.js";import{a as l,i as u,n as d,o as f,r as p,s as m,t as h}from"./dist-CpzYSoz7.js";import{n as g,r as _,t as v}from"./popover-select-C-Hj-nXR.js";import{t as y}from"./circle-check-C23XjkUj.js";import{t as b}from"./cloud-C4-yfnnk.js";import{t as x}from"./external-link-DjqjBmc3.js";import{t as S}from"./eye-CABVeTq0.js";import{t as C}from"./globe-DSSGFWFn.js";import{t as w}from"./loader-circle-CifKLtgG.js";import{t as T}from"./pencil-DmIY3Oa-.js";import{t as E}from"./plus-Q2yW6OE7.js";import{t as D}from"./search-DA7gz22f.js";import{t as O}from"./x-B_N4OPjy.js";import{t as k}from"./messages-
|
|
1
|
+
import{i as e}from"./rolldown-runtime-aKtaBQYM.js";import{a as t,n,t as r}from"./vendor-react-BOUWij0V.js";import{d as i,l as a,p as o,r as s,t as c}from"./chunk-KS7C4IRE-BaASWQor.js";import{a as l,i as u,n as d,o as f,r as p,s as m,t as h}from"./dist-CpzYSoz7.js";import{n as g,r as _,t as v}from"./popover-select-C-Hj-nXR.js";import{t as y}from"./circle-check-C23XjkUj.js";import{t as b}from"./cloud-C4-yfnnk.js";import{t as x}from"./external-link-DjqjBmc3.js";import{t as S}from"./eye-CABVeTq0.js";import{t as C}from"./globe-DSSGFWFn.js";import{t as w}from"./loader-circle-CifKLtgG.js";import{t as T}from"./pencil-DmIY3Oa-.js";import{t as E}from"./plus-Q2yW6OE7.js";import{t as D}from"./search-DA7gz22f.js";import{t as O}from"./x-B_N4OPjy.js";import{t as k}from"./messages-CHNYp8EQ.js";import{a as A,i as j,n as M,r as N,s as P}from"./locale-store-BJFLQY8O.js";import{t as F}from"./cn-JdwAhgNB.js";import{i as I}from"./vendor-swr-BIWyz7Rc.js";import{t as L}from"./button-CtTvuElV.js";import{n as R,t as ee}from"./interaction-BmQogeqz.js";import{n as z,r as B}from"./gateway-config-swr-DXuXtU1w.js";import{a as V,o as H,s as U}from"./form-field-width-DJw_jULe.js";import{n as W}from"./is-masked-secret-DOkL5b_X.js";import{t as G}from"./skeleton-BwbyijEw.js";import{i as K,o as te}from"./settings-shell-dialog-layer-BU3UuiJr.js";import{n as q,t as ne}from"./registry-api-CIsNlSBi.js";import{i as J,n as Y,r as X,t as re}from"./models-hub-cache-nCfkBN8M.js";import{a as ie,i as ae,n as oe,o as se,r as ce,t as le}from"./oauth-api-8lP_qJpq.js";import{$ as ue,$a as de,Cc as fe,Ds as pe,Ii as me,Li as he,Ll as ge,Oc as _e,Os as ve,Q as ye,Ql as be,Rs as xe,Uc as Se,Ws as Ce,Wt as we,X as Te,Xa as Ee,Y as De,Ya as Oe,Z as ke,Zs as Ae,_t as je,ao as Me,at as Ne,co as Pe,ct as Fe,dt as Ie,eo as Le,et as Re,eu as ze,fo as Be,ft as Ve,gt as He,ht as Ue,ii as We,it as Ge,lc as Ke,lo as qe,lt as Je,nc as Ye,no as Xe,nt as Ze,ot as Qe,po as $e,pt as et,qa as tt,qc as nt,qt as rt,rt as it,so as at,st as ot,tt as st,tu as ct,uc as lt,uo as ut,ut as dt,vs as ft,vt as pt,ys as mt,yt as ht}from"./index-D5TQQpeb.js";import{n as gt,r as _t}from"./settings-page-layout-BRQNel6r.js";import{t as vt}from"./settings-loading-skeleton-CAmWMaOT.js";import{n as yt,t as bt}from"./settings-form-section-DjWzRk4z.js";import{n as xt,r as St,t as Ct}from"./oauth-authorization-window-Cdolr2wE.js";import{n as wt,t as Tt}from"./use-autosave-B5eUJ6Zq.js";import{a as Et,c as Dt,d as Ot,f as kt,h as At,i as jt,l as Mt,n as Nt,o as Pt,p as Ft,r as It,t as Lt,u as Rt}from"./voice-config-api-q7B6fOFB.js";import{t as zt}from"./voice-api-key-field-CMKSwz4C.js";import{t as Bt}from"./page-tabs-BaEQMYm_.js";import{t as Vt}from"./settings-advanced-gate-BaN84CyW.js";import{a as Ht,i as Ut,n as Wt,o as Gt,r as Kt,t as qt}from"./image-generation-api-TIgsn04n.js";var Z=n(),Q=e(t(),1),$=r(),Jt={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 必须使用“名称: 值”格式,每行一个。`}},Yt=`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 Xt(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 Zt(e){let t=e.split(`
|
|
2
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 Qt({open:e,onOpenChange:t,provider:n,configured:r,language:i,onSaved:a}){let o=Jt[i],[s,c]=(0,Q.useState)(``),[g,_]=(0,Q.useState)(``),[y,b]=(0,Q.useState)(``),[x,C]=(0,Q.useState)(`bearer`),[T,D]=(0,Q.useState)(`x-api-key`),[k,A]=(0,Q.useState)(``),[j,M]=(0,Q.useState)(``),[N,P]=(0,Q.useState)(``),[I,R]=(0,Q.useState)(`/images/generations`),[ee,z]=(0,Q.useState)(`/images/edits`),[B,V]=(0,Q.useState)(``),[H,U]=(0,Q.useState)(``),[G,q]=(0,Q.useState)([Xt()]),[ne,J]=(0,Q.useState)(``),[Y,X]=(0,Q.useState)(),[re,ie]=(0,Q.useState)(!1),[ae,oe]=(0,Q.useState)(),[se,ce]=(0,Q.useState)(),[le,ue]=(0,Q.useState)();(0,Q.useEffect)(()=>{if(!e)return;let t=n?.imageGeneration;c(n?.providerId??``),_(t?.name??``),b(n?.baseUrl??``),C(t?.auth.type??`bearer`),D(t?.auth.type===`header`?t.auth.headerName:`x-api-key`),A(r?`••••••••••••`:``),M(t?.apiKeyUrl??``),P(t?.documentationUrl??``),R(t?.paths?.generations??`/images/generations`),z(t?.paths?.edits??`/images/edits`),V(t?.network?.allowedHosts.join(`
|
|
3
3
|
`)??``),U(Object.entries(n?.headers??{}).map(([e,t])=>`${e}: ${t}`).join(`
|
|
4
|
-
`)),q(t?.models.map(Xt)??[Xt()]),J(t?.defaultModel??``),ce(void 0),X(void 0),ie(!1),oe(void 0),ue(void 0)},[r,e,n]);let de=(0,Q.useMemo)(()=>G.filter(e=>e.id.trim()).map(e=>({value:e.id.trim(),label:e.name.trim()||e.id.trim()})),[G]),fe=(e,t)=>{q(n=>n.map((n,r)=>r===e?{...n,...t}:n))},
|
|
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}}}))}}}},
|
|
6
|
-
image-server.lan`,className:`mt-1.5 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 font-mono text-xs text-fg outline-none focus:border-accent focus:ring-2 focus:ring-accent/20`}),(0,$.jsx)(`span`,{className:`mt-1 block font-normal text-fg-subtle`,children:o.allowedHostsHint})]}),(0,$.jsxs)(`label`,{className:`mt-4 block text-xs font-medium text-fg-muted`,children:[o.staticHeaders,(0,$.jsx)(`textarea`,{value:H,onChange:e=>U(e.target.value),rows:3,className:`mt-1.5 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 font-mono text-xs text-fg outline-none focus:border-accent focus:ring-2 focus:ring-accent/20`}),(0,$.jsx)(`span`,{className:`mt-1 block font-normal text-fg-subtle`,children:o.staticHeadersHint})]})]})]}),(0,$.jsxs)(`section`,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wide text-fg-subtle`,children:o.models}),(0,$.jsxs)(L,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,onClick:()=>q(e=>[...e,Xt()]),children:[(0,$.jsx)(E,{className:`size-4`}),o.addModel]})]}),(0,$.jsxs)(`label`,{className:`block text-xs font-medium text-fg-muted`,children:[o.defaultModel,(0,$.jsx)(v,{value:ne||de[0]?.value||``,options:de,placeholder:o.defaultModel,allowEmpty:!1,onChange:J,triggerClassName:`mt-1.5 max-w-sm`})]}),G.map((e,t)=>(0,$.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface-base p-3`,children:[(0,$.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.modelId,(0,$.jsx)(`input`,{value:e.id,onChange:e=>fe(t,{id:e.target.value}),placeholder:`image-1`,className:Yt})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.modelName,(0,$.jsx)(`input`,{value:e.name,onChange:e=>fe(t,{name:e.target.value}),className:Yt})]})]}),(0,$.jsxs)(`div`,{className:`mt-3 grid gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.maxCount,(0,$.jsx)(`input`,{type:`number`,min:1,value:e.maxCount,onChange:e=>fe(t,{maxCount:e.target.value}),className:Yt})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.defaultCount,(0,$.jsx)(`input`,{type:`number`,min:1,value:e.defaultCount,onChange:e=>fe(t,{defaultCount:e.target.value}),className:Yt})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.defaultSize,(0,$.jsx)(`input`,{value:e.defaultSize,onChange:e=>fe(t,{defaultSize:e.target.value}),placeholder:`1024x1024`,className:Yt})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.format,(0,$.jsx)(v,{value:e.outputFormat,options:[{value:`png`,label:`PNG`},{value:`jpeg`,label:`JPEG`},{value:`webp`,label:`WebP`}],placeholder:o.format,allowEmpty:!0,onChange:e=>fe(t,{outputFormat:e}),triggerClassName:`mt-1.5`})]})]}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-4`,children:[(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:e.supportsSize,onChange:e=>fe(t,{supportsSize:e.target.checked})}),o.supportsSize]}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:e.editEnabled,onChange:e=>fe(t,{editEnabled:e.target.checked})}),o.edit]}),(0,$.jsxs)(`button`,{type:`button`,disabled:G.length===1,onClick:()=>q(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)(pe,{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)(S,{className:`size-4`}),o.testReady]}),(0,$.jsx)(`img`,{src:le,alt:`Generated provider test`,className:`max-h-72 rounded-lg object-contain`})]}):null,se?(0,$.jsx)(`p`,{className:`rounded-lg bg-emerald-500/10 px-3 py-2 text-sm text-emerald-700 dark:text-emerald-300`,role:`status`,children:se}):null,ae?(0,$.jsx)(`p`,{className:`rounded-lg bg-red-500/10 px-3 py-2 text-sm text-red-600 dark:text-red-400`,children:ae}):null]}),(0,$.jsxs)(`footer`,{className:`flex shrink-0 flex-wrap items-center gap-2 border-t border-edge px-5 py-3`,children:[n?(0,$.jsxs)(L,{variant:`secondary`,className:`border-red-500/30 text-red-600 hover:bg-red-500/10 dark:text-red-400`,disabled:!!Y,onClick:()=>void ve(),children:[Y===`delete`?(0,$.jsx)(w,{className:`size-4 animate-spin`}):(0,$.jsx)(pe,{className:`size-4`}),re?o.confirmDelete:o.delete]}):null,(0,$.jsxs)(`div`,{className:`ml-auto flex gap-2`,children:[(0,$.jsx)(d,{asChild:!0,children:(0,$.jsx)(L,{variant:`secondary`,children:o.cancel})}),(0,$.jsxs)(L,{variant:`secondary`,disabled:!!Y,onClick:()=>void _e(),children:[Y===`test`?(0,$.jsx)(w,{className:`size-4 animate-spin`}):null,Y===`test`?o.testing:o.test]}),(0,$.jsxs)(L,{variant:`primary`,disabled:!!Y,onClick:()=>void ge(),children:[Y===`save`?(0,$.jsx)(w,{className:`size-4 animate-spin`}):null,Y===`save`?o.saving:o.save]})]})]})]})]})})}var $t=`••••••••••••`,en={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 tn(e){let t=await A(N(`/api/agents/${encodeURIComponent(e)}/image-generation`));if(!t.payload)throw Error(`Invalid agent image generation response`);return t.payload}function nn(e){let t=e?.indexOf(`/`)??-1;return t>0?e.slice(0,t):void 0}function rn(e){let t=e?.indexOf(`/`)??-1;return t>0?e.slice(t+1):void 0}function an(e){return Object.fromEntries(e.configFields.map(t=>[t.key,e.config[t.key]??(t.required?t.options?.[0]?.value??``:``)]))}function on(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)(v,{value:r,options:(n.options??[]).map(sn),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 sn(e){return{value:e.value,label:e.label}}function cn(){let e=(0,Z.c)(2),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(G,{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(ln)}),(0,$.jsx)(G,{className:`h-64 rounded-xl`})]}),e[1]=n):n=e[1],n}function ln(e,t){return(0,$.jsx)(G,{className:`h-24 rounded-xl`},t)}function un(){let e=M(e=>e.language),t=en[e],n=k(e),r=!!P(e=>e.token),[i,a]=(0,Q.useState)(``),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(``),[u,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)({}),[m,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(),[b,x]=(0,Q.useState)(!1),[S,C]=(0,Q.useState)(!1),[T,D]=(0,Q.useState)(),{data:O,isLoading:j,error:F}=I(r?`image-generation-agents`:null,rt,{revalidateOnFocus:!1}),{data:R,isLoading:ee,error:z,mutate:B}=I(r?N(`/api/image-generation/catalog`):null,Kt,{revalidateOnFocus:!1}),{data:V,isLoading:H,error:U,mutate:G}=I(r?N(`/api/image-generation/custom-providers`):null,Wt,{revalidateOnFocus:!1});(0,Q.useEffect)(()=>{!O||i||a(O.defaultId||O.agents[0]?.id||``)},[i,O]);let{data:K,isLoading:te,error:q,mutate:ne}=I(r&&i?[`agent-image-generation`,i]:null,()=>tn(i),{revalidateOnFocus:!1});(0,Q.useEffect)(()=>{if(!R||!K)return;let e=nn(K.model?.primary),t=R.find(t=>t.id===e)??R.find(e=>e.configured)??R[0];t&&(s(t.id),l(t.id===e&&rn(K.model?.primary)||t.defaultModel),d(t.configured?$t:``),p(an(t)))},[K,R]),(0,Q.useEffect)(()=>{_(void 0)},[i]);let J=R?.find(e=>e.id===o),Y=J?J.apiKeyUrl??Oe(J.id,e)[0]?.href:void 0,X=(0,Q.useMemo)(()=>(O?.agents??[]).map(e=>({value:e.id,label:De(e,n.agentsSettings)})),[O?.agents,n.agentsSettings]),re=(0,Q.useMemo)(()=>(J?.models??[]).map(e=>({value:e,label:e})),[J?.models]),ie=K?.model?.primary,ae=!!(i&&J&&c&&(J.credentialMode!==`api-key`||J.configured||u.trim())&&J.configFields.every(e=>!e.required||f[e.key]?.trim()));if(!r)return(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.connect});if(j||ee||H||te)return(0,$.jsx)(cn,{});if(F||z||U||q||!R||!O||!V)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),d(e.configured?$t:``),p(an(e)),_(void 0)},se=()=>{D(void 0),C(!0)},ce=()=>{let e=V.find(e=>e.providerId===J?.id);e&&(D(e),C(!0))},le=async e=>{let[t,n]=await Promise.all([G(),B()]);if(e&&n?.some(t=>t.id===e)){let r=n.find(t=>t.id===e);s(r.id),l(r.defaultModel),d(r.configured?$t:``),p(an(r)),D(t?.find(t=>t.providerId===e))}},ue=async()=>{if(!(!J||!ae)){h(!0),_(void 0),x(!1);try{let e=await A(N(`/api/agents/${encodeURIComponent(i)}/image-generation/setup`),{method:`POST`,body:JSON.stringify({providerId:J.id,modelId:c,...u.trim()&&!W(u)?{apiKey:u.trim()}:{},providerConfig:Object.fromEntries(Object.entries(f).filter(([,e])=>e.trim()))})});if(!e.payload)throw Error(`Invalid setup response`);await Promise.all([ne(e.payload.agent,{revalidate:!1}),B(e.payload.providers,{revalidate:!1})]),d($t),x(!0)}catch(e){_(e instanceof Error?e.message:String(e))}finally{h(!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)(_e,{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)(v,{value:i,options:X,placeholder:t.selectAgent,allowEmpty:!1,onChange:a,triggerClassName:`mt-1.5 max-w-md`})]})]}),(0,$.jsxs)(`section`,{children:[(0,$.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-3`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wide text-fg-subtle`,children:t.provider}),(0,$.jsxs)(L,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,onClick:se,children:[(0,$.jsx)(E,{className:`size-4`}),t.addService]})]}),(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 xl:grid-cols-3`,children:R.map(e=>{let n=e.id===o,r=e.id===nn(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)(y,{className:`size-3.5`}):(0,$.jsx)(Ee,{className:`size-3.5`}),e.configured||e.credentialMode!==`api-key`?t.configured:t.needsKey]})]},e.id)})})]}),J?(0,$.jsxs)(`section`,{className:`rounded-xl border border-edge bg-surface-base p-4`,children:[(0,$.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:`block text-xs font-medium text-fg-muted`,children:[t.model,(0,$.jsx)(v,{value:c,options:re,placeholder:t.selectModel,allowEmpty:!1,onChange:l,triggerClassName:`mt-1.5`})]}),J.configFields.filter(e=>e.required).map(e=>(0,$.jsx)(on,{field:e,value:f[e.key]??``,onChange:t=>p(n=>({...n,[e.key]:t}))},e.key))]}),J.source===`custom`?(0,$.jsx)(`div`,{className:`mt-4 flex justify-end`,children:(0,$.jsxs)(L,{variant:`secondary`,onClick:ce,children:[(0,$.jsx)(je,{className:`size-4`}),t.manageService]})}):null,J.credentialMode===`api-key`?(0,$.jsxs)(`div`,{className:`mt-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(`label`,{htmlFor:`image-generation-api-key`,className:`text-xs font-medium text-fg-muted`,children:t.apiKey}),Y?(0,$.jsxs)(`a`,{href:Y,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs font-medium text-accent hover:underline`,children:[t.getApiKey,(0,$.jsx)(we,{className:`size-3.5`,"aria-hidden":`true`})]}):null]}),(0,$.jsx)(We,{id:`image-generation-api-key`,value:u,onChange:e=>d(W(u)?e.replace(/^•+/,``):e),placeholder:J.configured?t.existingKey:t.needsKey,labels:{show:t.show,hide:t.hide,copy:t.copy,copied:t.copied},reveal:()=>ht(J.id).then(e=>e.apiKey),loadFailedLabel:t.revealFailed,notInConfigFile:t.keyNotRevealable,className:`mt-1.5`,autoComplete:`new-password`},J.id),(0,$.jsx)(`span`,{className:`mt-1.5 block font-normal leading-relaxed text-fg-subtle`,children:J.configured?t.savedKey:t.apiKeyHint})]}):null,J.configFields.some(e=>!e.required)?(0,$.jsxs)(`details`,{className:`mt-4 rounded-lg border border-edge bg-surface-subtle px-3 py-2.5`,children:[(0,$.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 text-sm font-medium text-fg-muted`,children:[(0,$.jsx)(ve,{className:`size-4`}),t.advanced]}),(0,$.jsx)(`div`,{className:`mt-3 grid gap-3 md:grid-cols-2`,children:J.configFields.filter(e=>!e.required).map(e=>(0,$.jsx)(on,{field:e,value:f[e.key]??``,onChange:t=>p(n=>({...n,[e.key]:t}))},e.key))})]}):null,b?(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,g?(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:g}):null,(0,$.jsx)(`div`,{className:`mt-4 flex justify-end`,children:(0,$.jsxs)(L,{variant:`primary`,disabled:!ae||m,onClick:()=>void ue(),children:[m?(0,$.jsx)(w,{className:`size-4 animate-spin`}):(0,$.jsx)(y,{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:m?t.enabling:t.enable})]})]})})]}):null,(0,$.jsx)(Qt,{open:S,onOpenChange:C,provider:T,configured:!!(T&&R.find(e=>e.id===T.providerId)?.configured),language:e,onSaved:le})]})}function dn({v:e}){let t=dt(e=>e.microphoneId),n=dt(e=>e.setMicrophoneId),[r,i]=(0,Q.useState)([]),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(!1),l=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{l.current=!0;let e=()=>{navigator.mediaDevices?.enumerateDevices().then(e=>{l.current&&i(e.filter(e=>e.kind===`audioinput`))}).catch(()=>{})};return e(),navigator.mediaDevices?.addEventListener(`devicechange`,e),()=>{l.current=!1,navigator.mediaDevices?.removeEventListener(`devicechange`,e)}},[]);let u=async()=>{c(!0),o(``);try{(await navigator.mediaDevices.getUserMedia({audio:!0})).getTracks().forEach(e=>e.stop());let e=await navigator.mediaDevices.enumerateDevices();l.current&&i(e.filter(e=>e.kind===`audioinput`))}catch(e){l.current&&o(e instanceof Error?e.message:String(e))}finally{l.current&&c(!1)}};return(0,$.jsxs)(`section`,{className:`space-y-4 rounded-xl border border-edge p-4`,children:[(0,$.jsxs)(`label`,{className:`block space-y-2 text-sm`,children:[(0,$.jsx)(`span`,{children:e.experience.microphone}),(0,$.jsxs)(g,{value:t,onChange:e=>n(e.target.value),children:[(0,$.jsx)(_,{value:``,children:e.experience.systemDevice}),t&&!r.some(e=>e.deviceId===t)?(0,$.jsx)(_,{value:t,children:e.experience.unavailable}):null,r.filter(e=>e.deviceId&&e.deviceId!=="default").map((t,n)=>(0,$.jsx)(_,{value:t.deviceId,children:t.label||`${e.experience.microphone} ${n+1}`},t.deviceId))]})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.experience.deviceHint}),(0,$.jsx)(L,{variant:`secondary`,disabled:s,onClick:()=>void u(),children:e.experience.refreshDevices}),a?(0,$.jsx)(`p`,{role:`alert`,className:`text-sm text-red-600`,children:a}):null]})}function fn({v:e,canListen:t,canSpeak:n,disabled:r,onVerified:i}){let a=e.setup,o=(0,Q.useContext)(at)?.active??!1,[s,c]=(0,Q.useState)(`idle`),[l,u]=(0,Q.useState)(``),[d,f]=(0,Q.useState)(``),p=(0,Q.useRef)(`idle`),m=(0,Q.useRef)(null),h=(0,Q.useRef)(!1),g=e=>{p.current=e,c(e)},_=()=>{m.current?.(),m.current=null};(0,Q.useEffect)(()=>()=>m.current?.(),[]);async function v(e){_(),i?.({input:!1,output:!1}),h.current=!1,u(``),f(``),g(e?`connecting`:`playing`);let t=new AbortController,r,o,s,c,l=()=>{o?.cancel(),r?.getTracks().forEach(e=>e.stop()),s?.stop(`surface_closed`)},d=window.setTimeout(()=>v(a.timeout),6e4);m.current=()=>{t.abort(),window.clearTimeout(d),l(),c?.close()};function v(e){t.signal.aborted||(g(`error`),f(e),_())}async function y(){g(`playing`),l();try{let e=await kt(t.signal);if(t.signal.aborted)return;c?.enqueue(e,()=>{t.signal.aborted||(window.clearTimeout(d),g(`confirm`))})}catch(e){v(e instanceof Error?e.message:a.testFailed)}}try{if(n&&(c=new ct,await c.start(),t.signal.throwIfAborted()),!e){await y();return}let d=window.electronAPI?.system;if(d){let e=await d.requestMicrophone();if(t.signal.throwIfAborted(),e.status===`denied`)throw Error(a.microphoneDenied)}if(r=await navigator.mediaDevices.getUserMedia({audio:Ve()}),t.signal.aborted){l();return}if(s=await ze.connect({purpose:`dictation`,signal:t.signal,onEvent:e=>{t.signal.aborted||(e.type===`session.error`&&v(a.testFailed),p.current===`listening`&&(e.type===`input.transcript.delta`&&u(e.payload.text),e.type===`input.transcript.final`&&e.payload.text.trim()&&(u(e.payload.text.trim()),h.current=!0,n?y():(g(`passed`),i?.({input:!0,output:!1}),_()))))},onClose:()=>{(p.current===`listening`||p.current===`connecting`)&&v(a.testFailed)}}),t.signal.aborted){l();return}let f;if(o=await Ie.start(r,{onSamples:e=>{f&&!t.signal.aborted&&s?.sendAudio(f.push(e))}}),t.signal.aborted){l();return}f=new $e(o.sampleRate,s.session.inputFormat.sampleRate),g(`listening`)}catch(e){if(t.signal.aborted){l();return}v(e instanceof Error?e.message:a.testFailed)}}let y=s===`connecting`||s===`listening`||s===`playing`;return(0,$.jsxs)(`div`,{className:`space-y-3 border-t border-edge pt-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsxs)(L,{type:`button`,variant:`primary`,disabled:o||r||!t||y,onClick:()=>void v(!0),children:[y?(0,$.jsx)(w,{className:`size-4 animate-spin`}):(0,$.jsx)(mt,{className:`size-4`}),n?a.test:a.testInput]}),(0,$.jsxs)(L,{type:`button`,variant:`secondary`,disabled:o||r||!n||y,onClick:()=>void v(!1),children:[(0,$.jsx)(Re,{className:`size-4`}),e.tts.test.play]}),y?(0,$.jsxs)(L,{type:`button`,variant:`ghost`,onClick:()=>{_(),g(`idle`)},children:[(0,$.jsx)(be,{className:`size-4`}),e.tts.test.stop]}):null]}),(0,$.jsxs)(`div`,{role:`status`,"aria-live":`polite`,className:`space-y-2 text-xs text-fg-muted`,children:[s===`idle`?(0,$.jsx)(`p`,{children:o?e.experience.endCallBeforeTest:r?a.saveBeforeTest:a.microphoneHint}):null,s===`connecting`?(0,$.jsx)(`p`,{children:a.connecting}):null,s===`listening`?(0,$.jsx)(`p`,{children:a.speakNow}):null,l?(0,$.jsx)(`p`,{className:`rounded-lg bg-surface-base p-3 text-sm text-fg`,children:l}):null,s===`playing`?(0,$.jsx)(`p`,{children:a.playing}):null,s===`confirm`?(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`span`,{children:a.heardQuestion}),(0,$.jsx)(L,{type:`button`,variant:`secondary`,onClick:()=>{_(),i?.({input:h.current,output:!0}),g(`passed`)},children:a.heard}),(0,$.jsx)(L,{type:`button`,variant:`ghost`,onClick:()=>{_(),g(`error`),f(a.notHeard)},children:a.notHeardButton})]}):null,s===`passed`?(0,$.jsx)(`p`,{children:h.current?n?a.passed:a.inputPassed:a.outputPassed}):null,s===`error`?(0,$.jsx)(`p`,{role:`alert`,className:`text-red-600 dark:text-red-400`,children:d}):null]})]})}function pn(e,t){return{...e,stt:{...e.stt,enabled:!0,provider:t},voice:{...e.voice,realtime:{...e.voice.realtime,enabled:!0,tts:e.voice.realtime.tts?.provider===t?e.voice.realtime.tts:{provider:t,...t===`alibaba`?{voice:`Cherry`}:{}},omni:e.voice.realtime.omni?.provider===t?e.voice.realtime.omni:{provider:t,model:`qwen3-omni-flash-realtime`,voice:e.voice.realtime.omni?.voice??`Cherry`,instructions:e.voice.realtime.omni?.instructions??`Keep replies conversational and concise.`}}}}}function mn(e){let t=(0,Z.c)(112),{section:n,v:r,form:i,pending:a,apiKeyLabels:o,sttProviders:s,onChange:l}=e,u=r.setup,[d,f]=(0,Q.useState)(!1),p;t[0]===i?p=t[1]:(p=JSON.stringify(i),t[0]=i,t[1]=p);let m=p,h;t[2]===m?h=t[3]:(h={signature:m,input:!1,output:!1},t[2]=m,t[3]=h);let[v,y]=(0,Q.useState)(h);v.signature!==m&&y({signature:m,input:!1,output:!1});let b;t[4]!==a||t[5]!==m?(b=a?null:[`voice-realtime-status`,m],t[4]=a,t[5]=m,t[6]=b):b=t[6];let x;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(x={revalidateOnFocus:!0},t[7]=x):x=t[7];let{data:S,error:C,isLoading:w}=I(b,It,x),T=i.voice.realtime,E=i.stt.provider,D=T.tts,O=D?.provider??S?.tts?.provider,k=S?.tts?.model,A;t[8]!==k||t[9]!==O?(A=O&&k?[`realtime-voices`,O,k]:null,t[8]=k,t[9]=O,t[10]=A):A=t[10];let j;t[11]!==k||t[12]!==O?(j=()=>jt(O,k,`realtime`),t[11]=k,t[12]=O,t[13]=j):j=t[13];let M;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(M={revalidateOnFocus:!1},t[14]=M):M=t[14];let{data:N}=I(A,j,M),P;t[15]===N?P=t[16]:(P=N===void 0?[]:N,t[15]=N,t[16]=P);let F=P,R;t[17]!==O||t[18]!==F?(R=O===`alibaba`?F.filter(vn):F,t[17]=O,t[18]=F,t[19]=R):R=t[19];let ee=R,z=typeof i.stt.providers?.alibaba?.apiKey==`string`?i.stt.providers.alibaba.apiKey:``,B;t[20]!==z||t[21]!==s?(B=!!z||s.some(_n),t[20]=z,t[21]=s,t[22]=B):B=t[22];let V=B,U=T.defaultEngine===`omni`,W=U?T.omni?.voice??`Cherry`:D?.voice??S?.tts?.voice??``,K;t[23]!==U||t[24]!==ee?(K=U?[`Cherry`,`Ethan`,`Serena`,`Chelsie`].map(gn):ee,t[23]=U,t[24]=ee,t[25]=K):K=t[25];let te=K,q=!!(S?.enabled&&S.stt),ne=!!(S?.enabled&&S.tts),J;t[26]!==i||t[27]!==l||t[28]!==T?(J=e=>l({...i,voice:{...i.voice,realtime:{...T,...e}}}),t[26]=i,t[27]=l,t[28]=T,t[29]=J):J=t[29];let Y=J,X;t[30]!==i||t[31]!==l?(X=e=>l(pn(i,e)),t[30]=i,t[31]=l,t[32]=X):X=t[32];let re=X,ie;t[33]!==a||t[34]!==T.enabled||t[35]!==u.disabled||t[36]!==u.needsSetup||t[37]!==u.pending||t[38]!==u.unverified||t[39]!==u.verified||t[40]!==m||t[41]!==v.signature?(ie=(e,t)=>T.enabled?a?u.pending:e?t&&v.signature===m?u.verified:u.unverified:u.needsSetup:u.disabled,t[33]=a,t[34]=T.enabled,t[35]=u.disabled,t[36]=u.needsSetup,t[37]=u.pending,t[38]=u.unverified,t[39]=u.verified,t[40]=m,t[41]=v.signature,t[42]=ie):ie=t[42];let ae=ie,oe;t[43]!==o||t[44]!==re||t[45]!==d||t[46]!==C||t[47]!==i||t[48]!==z||t[49]!==V||t[50]!==l||t[51]!==a||t[52]!==E||t[53]!==T.defaultEngine||t[54]!==T.enabled||t[55]!==u.changeKey||t[56]!==u.configureConversation||t[57]!==u.customProvider||t[58]!==u.edgeHint||t[59]!==u.enable||t[60]!==u.finishSetup||t[61]!==u.hosted||t[62]!==u.hostedAccountHint||t[63]!==u.hostedHint||t[64]!==u.keyConfigured||t[65]!==u.keyHint||t[66]!==u.manageAccount||t[67]!==u.outputHint||t[68]!==u.ownKey||t[69]!==u.ownKeyHint||t[70]!==u.service||t[71]!==u.statusError||t[72]!==n||t[73]!==D||t[74]!==S?.tts||t[75]!==Y||t[76]!==r.experience||t[77]!==r.stt?(oe=n===`service`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 border-b border-edge pb-4`,children:(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-fg-muted`,children:[(0,$.jsx)(`input`,{type:`checkbox`,role:`switch`,"aria-checked":T.enabled,className:`size-4 accent-accent`,checked:T.enabled,onChange:e=>{e.target.checked?re(E===`alibaba`?`alibaba`:`xopc-cloud`):Y({enabled:!1})}}),u.enable]})}),C?(0,$.jsx)(`p`,{role:`alert`,className:`text-xs text-red-600 dark:text-red-400`,children:u.statusError}):null,(0,$.jsxs)(`fieldset`,{className:`space-y-3`,children:[(0,$.jsx)(`legend`,{className:`text-sm font-medium text-fg`,children:u.service}),(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[`xopc-cloud`,`alibaba`].map(e=>(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-3 rounded-lg border border-edge px-3 py-3 text-sm text-fg has-checked:border-accent/60`,children:[(0,$.jsx)(`input`,{type:`radio`,name:`realtime-service`,value:e,checked:E===e,onChange:()=>re(e),className:`mt-1 accent-accent`}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`block font-medium`,children:e===`xopc-cloud`?u.hosted:u.ownKey}),(0,$.jsx)(`span`,{className:`mt-1 block text-xs text-fg-muted`,children:e===`xopc-cloud`?u.hostedHint:u.ownKeyHint})]})]},e))})]}),E!==`alibaba`&&E!==`xopc-cloud`?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:u.customProvider.replace(`{provider}`,E)}):null,E===`alibaba`?(0,$.jsx)(`div`,{className:`space-y-2 text-xs`,children:V&&!d?(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-fg-muted`,children:u.keyConfigured}),(0,$.jsx)(L,{type:`button`,variant:`ghost`,onClick:()=>f(!0),children:u.changeKey})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`label`,{htmlFor:`realtime-api-key`,className:`font-medium text-fg`,children:r.stt.apiKey}),(0,$.jsx)(zt,{kind:`stt`,providerId:`alibaba`,fieldId:`realtime-api-key`,value:z,labels:{...o,maskedHelp:``},onChange:e=>l({...i,stt:{...i.stt,providers:{...i.stt.providers,alibaba:{...i.stt.providers?.alibaba,apiKey:e}}}})}),(0,$.jsx)(`p`,{className:`text-fg-muted`,children:u.keyHint})]})}):null,E===`xopc-cloud`?(0,$.jsxs)(`p`,{className:`text-xs text-fg-muted`,children:[u.hostedAccountHint,` `,(0,$.jsx)(c,{className:`text-accent hover:underline`,to:`/settings/capabilities/models`,children:u.manageAccount})]}):null,!D&&!a&&!S?.tts&&(E===`alibaba`||E===`xopc-cloud`)?(0,$.jsxs)(`div`,{className:`rounded-lg bg-surface-base p-3 text-xs`,children:[(0,$.jsx)(`p`,{className:`font-medium text-fg`,children:u.finishSetup}),(0,$.jsx)(`p`,{className:`mt-1 text-fg-muted`,children:i.tts.provider===`edge`?u.edgeHint:u.outputHint}),(0,$.jsx)(L,{className:`mt-2`,type:`button`,variant:`secondary`,onClick:()=>re(E),children:u.configureConversation})]}):null,(0,$.jsxs)(`label`,{className:`block space-y-2 text-sm`,children:[(0,$.jsx)(`span`,{children:r.experience.defaultEngine}),(0,$.jsxs)(g,{value:T.defaultEngine,className:H,onChange:e=>Y({defaultEngine:e.target.value}),children:[(0,$.jsx)(_,{value:`agent`,children:r.experience.agent}),(0,$.jsx)(_,{value:`omni`,children:r.experience.omni})]})]}),(0,$.jsxs)(`p`,{className:`text-xs text-fg-muted`,children:[T.defaultEngine===`agent`?r.experience.agentHint:r.experience.omniHint,` `,r.experience.nextCall]})]}):null,t[43]=o,t[44]=re,t[45]=d,t[46]=C,t[47]=i,t[48]=z,t[49]=V,t[50]=l,t[51]=a,t[52]=E,t[53]=T.defaultEngine,t[54]=T.enabled,t[55]=u.changeKey,t[56]=u.configureConversation,t[57]=u.customProvider,t[58]=u.edgeHint,t[59]=u.enable,t[60]=u.finishSetup,t[61]=u.hosted,t[62]=u.hostedAccountHint,t[63]=u.hostedHint,t[64]=u.keyConfigured,t[65]=u.keyHint,t[66]=u.manageAccount,t[67]=u.outputHint,t[68]=u.ownKey,t[69]=u.ownKeyHint,t[70]=u.service,t[71]=u.statusError,t[72]=n,t[73]=D,t[74]=S?.tts,t[75]=Y,t[76]=r.experience,t[77]=r.stt,t[78]=oe):oe=t[78];let se;t[79]!==W||t[80]!==U||t[81]!==O||t[82]!==T.bargeIn||t[83]!==T.omni||t[84]!==u.bargeIn||t[85]!==u.defaultVoice||t[86]!==u.voice||t[87]!==n||t[88]!==D||t[89]!==S?.tts||t[90]!==Y||t[91]!==r.realtime||t[92]!==te?(se=n===`listening`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,$.jsx)(`label`,{htmlFor:`realtime-voice`,className:`text-sm font-medium text-fg`,children:u.voice}),(0,$.jsxs)(g,{id:`realtime-voice`,className:`${H} w-full sm:w-56`,value:W,disabled:U?!T.omni:!D&&!S?.tts,onChange:e=>{if(U&&T.omni){Y({omni:{...T.omni,voice:e.target.value}});return}(O===`alibaba`||O===`xopc-cloud`)&&Y({tts:{provider:O,...e.target.value?{voice:e.target.value}:{}},...T.omni&&[`Cherry`,`Ethan`,`Serena`,`Chelsie`].includes(e.target.value)?{omni:{...T.omni,voice:e.target.value}}:{}})},children:[U?null:(0,$.jsx)(_,{value:``,children:u.defaultVoice}),W&&!te.some(e=>e.id===W)?(0,$.jsx)(_,{value:W,children:W}):null,te.map(hn)]})]}),(0,$.jsxs)(`label`,{className:`flex items-center justify-between gap-4 text-sm text-fg`,children:[(0,$.jsxs)(`span`,{children:[u.bargeIn,(0,$.jsx)(`span`,{className:`mt-1 block text-xs text-fg-muted`,children:r.realtime.bargeInDescription})]}),(0,$.jsx)(`input`,{type:`checkbox`,role:`switch`,"aria-checked":T.bargeIn,checked:T.bargeIn,className:`size-4 accent-accent`,onChange:e=>Y({bargeIn:e.target.checked})})]})]}):null,t[79]=W,t[80]=U,t[81]=O,t[82]=T.bargeIn,t[83]=T.omni,t[84]=u.bargeIn,t[85]=u.defaultVoice,t[86]=u.voice,t[87]=n,t[88]=D,t[89]=S?.tts,t[90]=Y,t[91]=r.realtime,t[92]=te,t[93]=se):se=t[93];let ce;t[94]!==q||t[95]!==ne||t[96]!==C||t[97]!==w||t[98]!==a||t[99]!==n||t[100]!==m||t[101]!==S||t[102]!==ae||t[103]!==r||t[104]!==v.input||t[105]!==v.output?(ce=n===`diagnostics`?(0,$.jsxs)($.Fragment,{children:[w?(0,$.jsx)(G,{className:`h-16 w-full`}):(0,$.jsxs)(`div`,{className:`space-y-2 text-sm`,role:`status`,children:[(0,$.jsxs)(`p`,{children:[r.experience.dictationReady,` · `,ae(q,v.input)]}),(0,$.jsxs)(`p`,{children:[r.experience.agentReady,` · `,ae(q&&ne,v.input&&v.output)]}),(0,$.jsxs)(`p`,{children:[r.experience.omniReady,` · `,ae(!!(S?.enabled&&S.omni),!1)]})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:r.experience.configurationOnly}),(0,$.jsx)(fn,{v:r,canListen:q,canSpeak:ne,disabled:a||w||!!C,onVerified:e=>y({signature:m,...e})},`${m}:${JSON.stringify(S)}`)]}):null,t[94]=q,t[95]=ne,t[96]=C,t[97]=w,t[98]=a,t[99]=n,t[100]=m,t[101]=S,t[102]=ae,t[103]=r,t[104]=v.input,t[105]=v.output,t[106]=ce):ce=t[106];let le;return t[107]!==u.service||t[108]!==oe||t[109]!==se||t[110]!==ce?(le=(0,$.jsxs)(`section`,{className:`space-y-5 rounded-xl border border-edge bg-surface-panel p-4 sm:p-5`,"aria-label":u.service,children:[oe,se,ce]}),t[107]=u.service,t[108]=oe,t[109]=se,t[110]=ce,t[111]=le):le=t[111],le}function hn(e){return(0,$.jsx)(_,{value:e.id,children:e.name},e.id)}function gn(e){return{id:e,name:e}}function _n(e){return e.id===`alibaba`&&e.configured}function vn(e){return[`Cherry`,`Ethan`,`Serena`,`Chelsie`].includes(e.id)}function yn(e){let t=(0,Z.c)(22),{value:n,onChange:r}=e,i=M(xn)===`zh`,a;t[0]===i?a=t[1]:(a=(e,t)=>i?t:e,t[0]=i,t[1]=a);let o=a,s;t[2]!==r||t[3]!==n?(s=e=>{n&&r({...n,...e})},t[2]=r,t[3]=n,t[4]=s):s=t[4];let c=s,l;t[5]===o?l=t[6]:(l=o(`Natural conversation · advanced`,`自然对话 · 高级设置`),t[5]=o,t[6]=l);let u;t[7]===l?u=t[8]:(u=(0,$.jsx)(`summary`,{className:`cursor-pointer text-sm font-medium text-fg`,children:l}),t[7]=l,t[8]=u);let d;t[9]===o?d=t[10]:(d=o(`Calls continue the same session using recent history. Service and credentials are shared with voice setup; override them here only when needed.`,`通话会接续同一会话的近期历史。默认共用语音服务与凭据,仅在需要独立配置时修改。`),t[9]=o,t[10]=d);let f;t[11]===d?f=t[12]:(f=(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:d}),t[11]=d,t[12]=f);let p;t[13]!==o||t[14]!==r||t[15]!==c||t[16]!==n?(p=n?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`label`,{className:`block space-y-1 text-sm`,children:[(0,$.jsx)(`span`,{children:o(`Connection`,`连接方式`)}),(0,$.jsxs)(g,{value:n.provider,onChange:e=>r({model:n.model,voice:n.voice,instructions:n.instructions,provider:e.target.value}),children:[(0,$.jsx)(_,{value:`xopc-cloud`,children:`XOPC Platform`}),(0,$.jsxs)(_,{value:`alibaba`,children:[`DashScope · `,o(`Your API key`,`自有 API Key`)]})]})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.provider===`xopc-cloud`?o(`Uses your XOPC sign-in and the platform’s published Omni route and credits.`,`使用 XOPC 登录授权、平台发布的 Omni 路由和额度。`):o(`Leave empty to use the shared voice service credential.`,`留空使用语音服务中已配置的凭据。`)}),(0,$.jsx)(`p`,{className:`font-mono text-xs text-fg-muted`,children:n.model}),n.provider===`alibaba`?(0,$.jsxs)(`label`,{className:`block space-y-1 text-sm`,children:[(0,$.jsx)(`span`,{children:`API Key`}),(0,$.jsx)(`input`,{className:`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,type:`password`,autoComplete:`new-password`,value:n.apiKey??``,onChange:e=>c({apiKey:e.target.value})})]}):null,(0,$.jsxs)(`label`,{className:`block space-y-1 text-sm`,children:[(0,$.jsx)(`span`,{children:o(`Endpoint override (optional)`,`自定义服务地址(可选)`)}),(0,$.jsx)(`input`,{className:`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,value:n.baseUrl??``,placeholder:n.provider===`alibaba`?`wss://dashscope.aliyuncs.com/api-ws/v1/realtime`:`https://router.xopc.ai/v1`,onChange:e=>c({baseUrl:e.target.value.trim()||void 0})})]}),(0,$.jsxs)(`label`,{className:`block space-y-1 text-sm`,children:[(0,$.jsx)(`span`,{children:o(`Voice`,`音色`)}),(0,$.jsx)(g,{value:n.voice,onChange:e=>c({voice:e.target.value}),children:[`Cherry`,`Ethan`,`Serena`,`Chelsie`].map(bn)})]}),(0,$.jsxs)(`label`,{className:`block space-y-1 text-sm`,children:[(0,$.jsx)(`span`,{children:o(`Conversation instructions`,`聊天指令`)}),(0,$.jsx)(`textarea`,{className:`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,rows:3,maxLength:8e3,value:n.instructions,onChange:e=>c({instructions:e.target.value})})]})]}):(0,$.jsx)(L,{variant:`secondary`,onClick:()=>r({provider:`xopc-cloud`,model:`qwen3-omni-flash-realtime`,voice:`Cherry`,instructions:`You are a friendly voice companion. You cannot execute tools.`}),children:o(`Configure natural conversation`,`配置自然聊天`)}),t[13]=o,t[14]=r,t[15]=c,t[16]=n,t[17]=p):p=t[17];let m;return t[18]!==u||t[19]!==f||t[20]!==p?(m=(0,$.jsxs)(`details`,{className:`space-y-3 rounded-xl border border-edge p-4`,children:[u,f,p]}),t[18]=u,t[19]=f,t[20]=p,t[21]=m):m=t[21],m}function bn(e){return(0,$.jsx)(_,{value:e,children:e},e)}function xn(e){return e.language}var Sn=V;function Cn(){return F(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,U,`dark:border-edge`)}function wn(){return F(H,V)}function Tn(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 Dn(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 On(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 kn(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 jn(e){return{maskedHelp:e.apiKeyMaskedHelp,copy:e.apiKeyCopy,copied:e.apiKeyCopied,show:e.apiKeyShow,hide:e.apiKeyHide,notInConfigFile:e.apiKeyNotInConfigFile,loadFailed:e.apiKeyRevealFailed}}function Mn(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 Nn(e,t){if(e.type===`boolean`)return!!t;if(e.type!==`number`)return t;let n=String(t).trim();if(!n)return;let r=Number(n);return Number.isFinite(r)?r:void 0}function Pn(e,t){switch(t.type){case`reset`:return{form:null,baseline:null};case`sync`:{let e=structuredClone(t.value);return{form:e,baseline:structuredClone(e)}}case`update`:return{...e,form:t.updater(e.form)};case`saved`:{let n=structuredClone(t.value);return{form:e.form!==null&&JSON.stringify(e.form)!==JSON.stringify(t.value)?e.form:n,baseline:structuredClone(n)}}}}function Fn(){let e=M(e=>e.language),t=k(e).voiceSettings,[n,r]=(0,Q.useState)(`listening`),i=dt(e=>e.captions),a=dt(e=>e.setCaptions),o=!!P(e=>e.token),[s,c]=(0,Q.useReducer)(Pn,{form:null,baseline:null}),l=s.form,u=s.baseline,[d,f]=(0,Q.useState)(null),p=(0,Q.useRef)(!1),m=(0,Q.useRef)(l);m.current=l;let h=(0,Q.useRef)({parsed:null,models:void 0}),{data:v,error:y,isLoading:b,mutate:x}=B(o),{data:S,error:C,isLoading:w,mutate:T}=I(o?N(`/api/voice/models`):null,Et,{revalidateOnFocus:!1}),{data:E,error:D,isLoading:O}=I(o?N(`/api/voice/providers`):null,Pt,{revalidateOnFocus:!1}),{data:A,error:j,isLoading:F}=I(o?N(`/api/voice/stt-providers`):null,Dt,{revalidateOnFocus:!1}),R=(0,Q.useMemo)(()=>E?.providers??[],[E]),ee=(0,Q.useMemo)(()=>A?.providers??[],[A]),z=(0,Q.useMemo)(()=>v?.payload?.config===void 0?null:Rt(v.payload.config),[v]),V=(0,Q.useMemo)(()=>!l||!u?!1:JSON.stringify(l)!==JSON.stringify(u),[l,u]);o?z!==null&&S!==void 0&&!p.current&&(h.current.parsed!==z||h.current.models!==S)&&(h.current={parsed:z,models:S},c({type:`sync`,value:z}),f(S)):(h.current.parsed!==null||h.current.models!==void 0)&&(h.current={parsed:null,models:void 0},c({type:`reset`}),f(null),p.current=!1);let H=!!(o&&(z===null||S===void 0||E===void 0||A===void 0)&&(b||w||O||F)),U=y instanceof Error?y.message:y?String(y):C instanceof Error?C.message:C?String(C):D instanceof Error?D.message:D?String(D):j instanceof Error?j.message:j?String(j):null,W=(0,Q.useCallback)(e=>{p.current=!0,c({type:`update`,updater:t=>t?{...t,stt:{...t.stt,...e}}:null})},[]),G=(0,Q.useCallback)(e=>{p.current=!0,c({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}}}}})},[]),K=(0,Q.useCallback)(e=>{p.current=!0,c({type:`update`,updater:t=>t?{...t,voice:{...t.voice,input:{...t.voice.input,refinement:{...t.voice.input.refinement,...e}}}}:null})},[]),te=(0,Q.useCallback)(t=>{p.current=!0,c({type:`update`,updater:n=>n?{...n,voice:{...n.voice,languageMode:t,...t===`auto`?{language:e}:{}}}:null})},[e]),q=(0,Q.useCallback)(e=>{p.current=!0,c({type:`update`,updater:t=>t?{...t,voice:{...t.voice,realtime:{...t.voice.realtime,...e}}}:null})},[]),ne=(0,Q.useCallback)(e=>{p.current=!0,c({type:`update`,updater:t=>t?{...t,tts:{...t.tts,...e}}:null})},[]),J=Tt({value:l,dirty:V,onSave:(0,Q.useCallback)(async e=>{let n=u?.stt.provider!==`xopc-local`&&e.stt.provider===`xopc-local`;try{await Ot(e),n&&window.dispatchEvent(new Event(Lt)),c({type:`saved`,value:e}),p.current=!!(m.current&&JSON.stringify(m.current)!==JSON.stringify(e))}catch(e){throw Error(e instanceof Error?e.message:t.saveError)}},[u?.stt.provider,t.saveError])}),Y=(0,Q.useCallback)(e=>{p.current=!0,c({type:`update`,updater:()=>e})},[]);if(!o)return(0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.needToken})});if(H)return(0,$.jsx)(vt,{rows:4});if(!l||d===null)return(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:U??t.loadError}),(0,$.jsx)(L,{type:`button`,variant:`secondary`,onClick:()=>{x(),T()},children:t.retry})]});let X=l.stt,re=l.tts,ie=l.voice.input.refinement,ae=jn(t);return(0,$.jsxs)(`div`,{className:`flex w-full flex-col gap-4`,onBlurCapture:J.onBlurCapture,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,$.jsx)(`p`,{className:`text-sm leading-relaxed text-fg-muted`,children:t.setup.subtitle}),(0,$.jsx)(wt,{status:J.status,error:J.error})]}),J.error?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:J.error}):null,(0,$.jsx)(`nav`,{"aria-label":t.setup.advanced,className:`flex flex-wrap gap-2`,children:[`listening`,`input`,`devices`,`service`,`diagnostics`].map(e=>(0,$.jsx)(L,{variant:n===e?`secondary`:`ghost`,"aria-pressed":n===e,onClick:()=>r(e),children:t.experience[e]},e))}),n===`listening`||n===`service`||n===`diagnostics`?(0,$.jsx)(mn,{section:n,v:t,form:l,pending:V||J.status===`saving`||!!J.error,apiKeyLabels:ae,sttProviders:ee,onChange:Y}):null,n===`listening`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(In,{v:t,voice:l.voice,updateLanguageMode:te}),(0,$.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-sm text-fg`,children:[t.experience.pace,(0,$.jsxs)(g,{className:wn(),value:String(l.voice.realtime.silenceDurationMs),onChange:e=>q({silenceDurationMs:Number(e.target.value)}),children:[(0,$.jsx)(_,{value:`400`,children:t.experience.fast}),(0,$.jsx)(_,{value:`700`,children:t.experience.standard}),(0,$.jsx)(_,{value:`1200`,children:t.experience.relaxed}),[400,700,1200].includes(l.voice.realtime.silenceDurationMs)?null:(0,$.jsxs)(_,{value:String(l.voice.realtime.silenceDurationMs),children:[l.voice.realtime.silenceDurationMs,` ms`]})]})]})]}):null,n===`input`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`label`,{className:`flex items-center justify-between text-sm`,children:[t.experience.captions,(0,$.jsx)(`input`,{type:`checkbox`,role:`switch`,"aria-checked":i,className:`ui-checkbox`,checked:i,onChange:e=>a(e.target.checked)})]}),(0,$.jsxs)(`label`,{className:`space-y-2 text-sm`,children:[(0,$.jsx)(`span`,{children:t.stt.refinement}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.stt.refinementDesc}),(0,$.jsxs)(g,{className:wn(),value:ie.mode,onChange:e=>K({mode:e.target.value}),children:[(0,$.jsx)(_,{value:`off`,children:t.stt.refinementOff}),(0,$.jsx)(_,{value:`punctuation`,children:t.stt.refinementPunctuation}),(0,$.jsx)(_,{value:`light`,children:t.stt.refinementLight}),ie.mode===`custom`?(0,$.jsx)(_,{value:`custom`,children:t.setup.advanced}):null]})]}),(0,$.jsxs)(`details`,{className:`rounded-xl border border-edge bg-surface-panel px-4 py-3`,children:[(0,$.jsxs)(`summary`,{className:`cursor-pointer text-sm font-medium text-fg`,children:[t.setup.readout,` · `,re.enabled?kn(re.trigger,t):t.overview.off]}),(0,$.jsx)(`p`,{className:`mt-3 text-xs text-fg-muted`,children:t.setup.readoutHint}),(0,$.jsx)(Vn,{v:t,apiKeyLabels:ae,tts:re,models:d,ttsProviders:R,updateTts:ne})]})]}):null,n===`devices`?(0,$.jsx)(dn,{v:t}):null,n===`service`?(0,$.jsxs)($.Fragment,{children:[l.voice.realtime.enabled?(0,$.jsx)(yn,{value:l.voice.realtime.omni,onChange:e=>q({omni:e})}):null,(0,$.jsxs)(`details`,{className:`rounded-xl border border-edge bg-surface-panel px-4 py-3`,children:[(0,$.jsx)(`summary`,{className:`cursor-pointer text-sm font-medium text-fg`,children:t.experience.technical}),(0,$.jsx)(Ln,{v:t,apiKeyLabels:ae,stt:X,models:d,sttProviders:ee,updateStt:W,updateSttFallback:G}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.notes.envVars})]})]}):null]})}function In(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=wn(),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)(_,{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)(_,{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)(g,{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 Ln(e){let t=(0,Z.c)(58),{v:n,apiKeyLabels:r,stt:i,models:a,sttProviders:o,updateStt:s,updateSttFallback:c}=e,l;if(t[0]!==o){let e=new Set;l=[];for(let t of o)e.has(t.id)||(e.add(t.id),l.push(t));t[0]=o,t[1]=l}else l=t[1];let u=l,d,f,p,m;if(t[2]!==a||t[3]!==u||t[4]!==i.provider||t[5]!==i.providers){d=u.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],p=e,f=a?.stt?.[i.provider]?.length?a.stt[i.provider]:d?.models??[],m=d?.fields.find(Rn),t[2]=a,t[3]=u,t[4]=i.provider,t[5]=i.providers,t[6]=d,t[7]=f,t[8]=p,t[9]=m}else d=t[6],f=t[7],p=t[8],m=t[9];let h=m,v=typeof p.model==`string`?p.model:void 0,y=v??(typeof h?.defaultValue==`string`?h.defaultValue:f[0]?.id),b;t[13]!==i.provider||t[14]!==i.providers||t[15]!==s?(b=e=>{s({providers:{...i.providers??{},[i.provider]:{...i.providers?.[i.provider]??{},...e}}})},t[13]=i.provider,t[14]=i.providers,t[15]=s,t[16]=b):b=t[16];let x=b,S,C;t[17]!==v||t[18]!==y||t[19]!==h||t[20]!==x?(S=()=>{h&&y&&v!==y&&x({model:y})},C=[v,y,h,x],t[17]=v,t[18]=y,t[19]=h,t[20]=x,t[21]=S,t[22]=C):(S=t[21],C=t[22]),(0,Q.useEffect)(S,C);let w;t[23]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,$.jsx)(mt,{className:`size-4 text-accent`,strokeWidth:1.75}),t[23]=w):w=t[23];let T;t[24]===n.stt.title?T=t[25]:(T=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[w,n.stt.title]}),t[24]=n.stt.title,t[25]=T);let E;t[26]===n.stt.description?E=t[27]:(E=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:n.stt.description}),t[26]=n.stt.description,t[27]=E);let D;t[28]!==T||t[29]!==E?(D=(0,$.jsxs)(`div`,{className:`mb-4`,children:[T,E]}),t[28]=T,t[29]=E,t[30]=D):D=t[30];let O;t[31]===s?O=t[32]:(O=e=>s({enabled:e}),t[31]=s,t[32]=O);let k;t[33]!==i.enabled||t[34]!==O||t[35]!==n.stt.enable||t[36]!==n.stt.enableDesc?(k=(0,$.jsx)(Un,{checked:i.enabled,title:n.stt.enable,description:n.stt.enableDesc,onChange:O}),t[33]=i.enabled,t[34]=O,t[35]=n.stt.enable,t[36]=n.stt.enableDesc,t[37]=k):k=t[37];let A;t[38]!==d?.fields||t[39]!==r||t[40]!==y||t[41]!==f||t[42]!==u||t[43]!==p||t[44]!==i.enabled||t[45]!==i.fallback?.enabled||t[46]!==i.provider||t[47]!==x||t[48]!==s||t[49]!==c||t[50]!==n?(A=i.enabled?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:F(`flex flex-col gap-1.5`,Sn),children:[(0,$.jsx)(Kn,{children:n.stt.provider}),(0,$.jsx)(g,{className:wn(),value:i.provider,onChange:e=>s({provider:e.target.value}),children:u.map(e=>(0,$.jsxs)(_,{value:e.id,children:[Dn(e.id,n),e.configured?``:` *`]},e.id))})]}),(0,$.jsx)(Hn,{kind:`stt`,providerId:i.provider,fields:d?.fields??[],providerSlice:p,models:f,currentModel:y,apiKeyLabels:r,onPatch:x})]}),i.provider===`xopc-local`?(0,$.jsx)(Bn,{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=>c({enabled:e.target.checked})})]})]}):null,t[38]=d?.fields,t[39]=r,t[40]=y,t[41]=f,t[42]=u,t[43]=p,t[44]=i.enabled,t[45]=i.fallback?.enabled,t[46]=i.provider,t[47]=x,t[48]=s,t[49]=c,t[50]=n,t[51]=A):A=t[51];let j;t[52]!==k||t[53]!==A?(j=(0,$.jsxs)(`div`,{className:`space-y-4`,children:[k,A]}),t[52]=k,t[53]=A,t[54]=j):j=t[54];let M;return t[55]!==j||t[56]!==D?(M=(0,$.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[D,j]}),t[55]=j,t[56]=D,t[57]=M):M=t[57],M}function Rn(e){return e.key===`model`}function zn(e){return`${Math.round(e/1024/1024)} MB`}function Bn({v:e}){let{data:t,error:n,mutate:r}=I(N(`/api/voice/local/status`),Nt,{revalidateOnFocus:!1,refreshInterval:e=>e?.models.some(e=>e.state===`downloading`)?1e3:0}),[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{let e=()=>void r();return window.addEventListener(Lt,e),()=>window.removeEventListener(Lt,e)},[r]);let c=(0,Q.useCallback)(async(e,t)=>{a(e.id),s(null);try{t===`install`?await Mt(e.id):await Ft(e.id),await r()}catch(e){s(e instanceof Error?e.message:String(e))}finally{a(null)}},[r]);return(0,$.jsxs)(`div`,{className:`rounded-xl border border-edge bg-surface-panel/60 p-3`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.stt.localModels}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:e.stt.localModelsDesc}),n?(0,$.jsx)(`p`,{className:`mt-3 text-xs text-red-600 dark:text-red-400`,children:String(n)}):null,t?.runtime.ready===!1?(0,$.jsx)(`p`,{className:`mt-3 text-xs text-red-600 dark:text-red-400`,children:t.runtime.error??`Local voice runtime is unavailable`}):null,t?.decoder?.available===!1?(0,$.jsx)(`p`,{className:`mt-3 text-xs text-amber-700 dark:text-amber-300`,children:t.decoder.error??`Compressed audio decoding is unavailable`}):null,o?(0,$.jsx)(`p`,{className:`mt-3 text-xs text-red-600 dark:text-red-400`,children:o}):null,(0,$.jsx)(`div`,{className:`mt-3 grid gap-2`,children:(t?.models??[]).map(t=>{let n=i===t.id||t.state===`downloading`;return(0,$.jsxs)(`div`,{className:F(`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:[zn(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)(L,{type:`button`,variant:`secondary`,disabled:n,onClick:()=>void c(t,t.state===`ready`?`remove`:`install`),children:n?(0,$.jsx)(w,{className:`size-4 animate-spin`}):t.state===`ready`?e.stt.localRemove:e.stt.localInstall})]},t.id)})})]})}function Vn({v:e,apiKeyLabels:t,tts:n,models:r,ttsProviders:i,updateTts:a}){let[o,s]=(0,Q.useState)(e.tts.test.sampleText),[c,l]=(0,Q.useState)({status:`idle`}),u=(0,Q.useRef)(null),d=(0,Q.useRef)(null),f=(0,Q.useRef)(null),p=(0,Q.useCallback)(()=>{f.current?.abort(),f.current=null,u.current?.pause(),u.current=null,d.current&&=(URL.revokeObjectURL(d.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),v=n.providers?.[n.provider]??{},y=r?.tts?.[n.provider]?.length?r.tts[n.provider]:h?.models??[],b=h?.fields.find(e=>e.key===`model`),x=h?.fields.find(e=>e.key===`voice`),S=typeof v.model==`string`?v.model:void 0,C=S??(typeof b?.defaultValue==`string`?b.defaultValue:y[0]?.id),T=y.find(e=>e.id===C),E=r?.ttsVoices?.[n.provider]?.length?r.ttsVoices[n.provider]:h?.voices??[],{data:D=[]}=I(C?`voice:tts:${n.provider}:${C}`:null,()=>jt(n.provider,C??``),{revalidateOnFocus:!1}),O=D.length>0?D:E,k=typeof v.voice==`string`?v.voice:void 0,A=k??O.find(e=>e.id===T?.tts?.defaultVoice)?.id??(typeof x?.defaultValue==`string`?x.defaultValue:O[0]?.id),j=(h?.fields??[]).filter(e=>(e.key!==`speed`||T?.tts?.speed!==!1)&&(e.key!==`instructions`||T?.tts?.instructions!==!1)),M=!!h?.diagnostics.requiresApiKey,N=!!h?.configured||!M,P=(0,Q.useCallback)(e=>{a({providers:{...n.providers??{},[n.provider]:{...n.providers?.[n.provider]??{},...e}}})},[n.provider,n.providers,a]);(0,Q.useEffect)(()=>{let e={};b&&C&&S!==C&&(e.model=C),x&&A&&k!==A&&(e.voice=A),Object.keys(e).length>0&&P(e)},[S,k,C,A,b,P,x]),(0,Q.useEffect)(()=>()=>p(),[p]);let R=(0,Q.useCallback)(e=>{a({provider:e}),l({status:`idle`})},[a]),ee=(0,Q.useCallback)(async()=>{let t=o.trim();if(!t){l({status:`error`,message:e.tts.test.emptyText});return}p();let r=new AbortController;f.current=r,l({status:`loading`});try{let i=await At({text:t,provider:n.provider,providerConfig:v,...C?{model:C}:{},...A?{voice:A}:{}},r.signal);if(r.signal.aborted)return;let a=En(i.audio,i.mimeType);d.current=a;let o=new Audio(a);u.current=o;let s=[i.provider,i.format,i.latencyMs===void 0?void 0:`${i.latencyMs}ms`,Tn(i.audioSize)].filter(Boolean).join(` · `);o.addEventListener(`ended`,()=>l({status:`done`,summary:s}),{once:!0}),o.addEventListener(`error`,()=>l({status:`error`,message:e.tts.test.playFailed}),{once:!0}),await o.play(),l({status:`playing`,summary:s})}catch(e){if(r.signal.aborted)return;p(),l({status:`error`,message:e instanceof Error?e.message:String(e)})}},[C,A,v,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)(qe,{className:`size-4 text-accent`,strokeWidth:1.75}),e.tts.title]}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:e.tts.description})]}),(0,$.jsxs)(`div`,{className:`space-y-4`,children:[(0,$.jsx)(Un,{checked:n.enabled,title:e.tts.enable,description:e.tts.enableDesc,onChange:e=>a({enabled:e})}),n.enabled?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:F(`flex flex-col gap-1.5`,Sn),children:[(0,$.jsx)(Kn,{children:e.tts.trigger}),(0,$.jsxs)(g,{className:wn(),value:n.trigger,onChange:e=>a({trigger:e.target.value}),children:[(0,$.jsx)(_,{value:`off`,children:e.tts.triggerOff}),(0,$.jsx)(_,{value:`inbound`,children:e.tts.triggerInbound}),(0,$.jsx)(_,{value:`tagged`,children:e.tts.triggerTagged}),(0,$.jsx)(_,{value:`always`,children:e.tts.triggerAlways})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.triggerHelp})]}),(0,$.jsxs)(`div`,{className:F(`flex flex-col gap-1.5`,Sn),children:[(0,$.jsx)(Kn,{children:e.tts.provider}),(0,$.jsx)(g,{className:wn(),value:n.provider,onChange:e=>R(e.target.value),children:m.map(t=>(0,$.jsx)(_,{value:t.id,children:On(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:!N||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)(Hn,{kind:`tts`,providerId:n.provider,fields:j,providerSlice:v,models:y,voices:O,currentModel:C,currentVoice:A,apiKeyLabels:t,onPatch:P,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)(L,{type:`button`,variant:`primary`,onClick:()=>void ee(),disabled:c.status===`loading`,className:`h-9`,children:[c.status===`loading`?(0,$.jsx)(w,{className:`size-4 animate-spin`}):(0,$.jsx)(Re,{className:`size-4`}),c.status===`loading`?e.tts.test.generating:e.tts.test.play]}),(0,$.jsxs)(L,{type:`button`,variant:`secondary`,onClick:()=>{p(),l(e=>e.status===`playing`?{status:`done`,summary:e.summary}:{status:`idle`})},disabled:c.status!==`playing`,className:`h-9`,children:[(0,$.jsx)(be,{className:`size-4`}),e.tts.test.stop]})]})]}),(0,$.jsxs)(`details`,{className:`mt-3`,children:[(0,$.jsx)(`summary`,{className:`cursor-pointer text-xs text-fg-muted`,children:e.setup.sampleText}),(0,$.jsx)(`textarea`,{className:F(Cn(),`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 Hn({kind:e,providerId:t,fields:n,providerSlice:r,models:i,voices:a=[],currentModel:o,currentVoice:s,apiKeyLabels:c,onPatch:l,resetVoiceOnModelChange:u=!1}){return n.map(n=>n.key===`apiKey`?(0,$.jsxs)(`div`,{className:F(`flex flex-col gap-1.5`,Sn),children:[(0,$.jsx)(Kn,{children:n.label}),(0,$.jsx)(zt,{kind:e,providerId:t,fieldId:`voice-${e}-${t}-api-key`,value:typeof r.apiKey==`string`?r.apiKey:``,onChange:e=>l({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:F(`flex flex-col gap-1.5`,Sn),children:[(0,$.jsx)(Kn,{children:n.label}),(0,$.jsx)(g,{className:wn(),value:o??``,onChange:e=>l({model:e.target.value,...u?{voice:void 0}:{}}),children:i.map(e=>(0,$.jsx)(_,{value:e.id,children:e.name},e.id))})]},n.key):n.key===`voice`&&a.length>0?(0,$.jsxs)(`div`,{className:F(`flex flex-col gap-1.5`,Sn),children:[(0,$.jsx)(Kn,{children:n.label}),(0,$.jsx)(g,{className:wn(),value:s??``,onChange:e=>l({voice:e.target.value}),children:a.map(e=>(0,$.jsx)(_,{value:e.id,children:e.name},e.id))})]},n.key):(0,$.jsx)(Wn,{field:n,value:Mn(r,n),onChange:e=>l({[n.key]:e}),className:n.type===`textarea`?`sm:col-span-2`:Sn},n.key))}function Un(e){let t=(0,Z.c)(27),{checked:n,title:r,description:i,onChange:a}=e,o;t[0]!==n||t[1]!==a?(o=()=>a(!n),t[0]=n,t[1]=a,t[2]=o):o=t[2];let s=n?`bg-surface-panel text-fg`:`bg-surface-panel/80 text-fg hover:bg-surface-hover`,c;t[3]===s?c=t[4]:(c=F(`group flex w-full items-center justify-between gap-4 rounded-lg border border-edge px-3 py-3 text-left transition-colors`,U,s),t[3]=s,t[4]=c);let l;t[5]===r?l=t[6]:(l=(0,$.jsx)(`span`,{className:`flex flex-wrap items-center gap-2 text-sm font-semibold text-fg`,children:r}),t[5]=r,t[6]=l);let u;t[7]===i?u=t[8]:(u=(0,$.jsx)(`span`,{className:`mt-1 block text-xs leading-relaxed text-fg-muted`,children:i}),t[7]=i,t[8]=u);let d;t[9]!==l||t[10]!==u?(d=(0,$.jsxs)(`span`,{className:`min-w-0`,children:[l,u]}),t[9]=l,t[10]=u,t[11]=d):d=t[11];let f=n?`border-accent bg-accent`:`border-edge bg-surface-hover group-hover:border-accent/40`,p;t[12]===f?p=t[13]:(p=F(`relative inline-flex h-6 w-11 shrink-0 items-center rounded-full border transition-colors`,f),t[12]=f,t[13]=p);let m=n?`translate-x-5`:`translate-x-0.5`,h;t[14]===m?h=t[15]:(h=F(`size-5 rounded-full bg-white shadow-surface transition-transform`,m),t[14]=m,t[15]=h);let g;t[16]===h?g=t[17]:(g=(0,$.jsx)(`span`,{className:h}),t[16]=h,t[17]=g);let _;t[18]!==g||t[19]!==p?(_=(0,$.jsx)(`span`,{className:p,"aria-hidden":!0,children:g}),t[18]=g,t[19]=p,t[20]=_):_=t[20];let v;return t[21]!==n||t[22]!==o||t[23]!==_||t[24]!==c||t[25]!==d?(v=(0,$.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":n,onClick:o,className:c,children:[d,_]}),t[21]=n,t[22]=o,t[23]=_,t[24]=c,t[25]=d,t[26]=v):v=t[26],v}function Wn(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=F(`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,a),t[0]=a,t[1]=e);let o;t[2]===n.label?o=t[3]:(o=(0,$.jsx)(`span`,{className:`block text-sm font-medium text-fg`,children:n.label}),t[2]=n.label,t[3]=o);let c;t[4]===s?c=t[5]:(c=s?(0,$.jsx)(`span`,{className:`mt-1 block text-xs text-fg-subtle`,children:s}):null,t[4]=s,t[5]=c);let l;t[6]!==o||t[7]!==c?(l=(0,$.jsxs)(`span`,{children:[o,c]}),t[6]=o,t[7]=c,t[8]=l):l=t[8];let u=!!r,d;t[9]!==n||t[10]!==i?(d=e=>i(Nn(n,e.target.checked)),t[9]=n,t[10]=i,t[11]=d):d=t[11];let f;t[12]!==u||t[13]!==d?(f=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:u,onChange:d}),t[12]=u,t[13]=d,t[14]=f):f=t[14];let p;return t[15]!==e||t[16]!==l||t[17]!==f?(p=(0,$.jsxs)(`label`,{className:e,children:[l,f]}),t[15]=e,t[16]=l,t[17]=f,t[18]=p):p=t[18],p}let c=typeof r==`boolean`?``:String(r),l;t[19]===a?l=t[20]:(l=F(`flex flex-col gap-1.5`,a),t[19]=a,t[20]=l);let u;t[21]===n.label?u=t[22]:(u=(0,$.jsx)(Kn,{children:n.label}),t[21]=n.label,t[22]=u);let d;t[23]!==a||t[24]!==n||t[25]!==c||t[26]!==o||t[27]!==i?(d=n.type===`select`?(0,$.jsx)(g,{id:o,className:wn(),value:c,required:n.required,onChange:e=>i(Nn(n,e.target.value)),children:(n.options??[]).map(Gn)}):n.type===`textarea`?(0,$.jsx)(`textarea`,{id:o,className:F(Cn(),`min-h-24 resize-y`),value:c,required:n.required,placeholder:n.placeholder,onChange:e=>i(Nn(n,e.target.value))}):n.type===`password`?(0,$.jsx)(We,{id:o,className:a,value:c,onChange:e=>i(Nn(n,e)),placeholder:n.placeholder,labels:Ne}):(0,$.jsx)(`input`,{id:o,className:Cn(),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(Nn(n,e.target.value))}),t[23]=a,t[24]=n,t[25]=c,t[26]=o,t[27]=i,t[28]=d):d=t[28];let f;t[29]===s?f=t[30]:(f=s?(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:s}):null,t[29]=s,t[30]=f);let p;return t[31]!==l||t[32]!==u||t[33]!==d||t[34]!==f?(p=(0,$.jsxs)(`div`,{className:l,children:[u,d,f]}),t[31]=l,t[32]=u,t[33]=d,t[34]=f,t[35]=p):p=t[35],p}function Gn(e){return(0,$.jsx)(_,{value:e.id,children:e.name},e.id)}function Kn(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 qn(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 Jn(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 A(N(`/api/config`),{method:`PATCH`,body:JSON.stringify({tools:{web:{region:t,search:n,blocklist:{enabled:e.blocklistEnabled,domains:e.blocklistDomains}}}})}),z()}async function Yn(e){let t=await A(N(`/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 Xn(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 Zn(){return F(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,U,`dark:border-edge`)}function Qn(){return F(H,V)}var $n=[`brave`,`tavily`,`bing`,`searxng`];function er(){return{type:`brave`,apiKey:``,url:``,disabled:!1}}var tr=me();function nr(){let e=k(M(e=>e.language)),t=e.webSearchSettings,n=e.logs,r=!!P(e=>e.token),[i,a]=(0,Q.useReducer)(tr,{form:null,baseline:null}),o=i.form,s=i.baseline,c=(0,Q.useRef)(!1),l=(0,Q.useRef)(o);l.current=o;let u=(0,Q.useRef)(null),{data:d,error:f,isLoading:p,mutate:m}=B(r);ye({enabled:r,parsed:(0,Q.useMemo)(()=>d?.payload?.config===void 0?null:qn(d.payload.config),[d]),dirty:c.current,trackedParsedRef:u,dispatch:a,onResetDirty:()=>{c.current=!1}});let h=!!(r&&p&&d===void 0&&!f),v=f instanceof Error?f.message:f?String(f):null,y=(0,Q.useMemo)(()=>!o||!s?!1:JSON.stringify(o)!==JSON.stringify(s),[o,s]),b=(0,Q.useCallback)(e=>{c.current=!0,a({type:`patch`,patch:e})},[]),x=Tt({value:o,dirty:y,onSave:(0,Q.useCallback)(async e=>{try{await Jn(e),a({type:`saved`,value:e}),c.current=!!(l.current&&JSON.stringify(l.current)!==JSON.stringify(e))}catch(e){throw Error(e instanceof Error?e.message:t.saveError)}},[t.saveError])});return r?h?(0,$.jsx)(vt,{rows:3}):o?(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,onBlurCapture:x.onBlurCapture,children:[x.error?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:x.error}):null,(0,$.jsxs)(bt,{children:[(0,$.jsx)(yt,{icon:D,title:t.sectionRegion,subtitle:t.sectionRegionHint,trailing:(0,$.jsx)(wt,{status:x.status,error:x.error})}),(0,$.jsx)(`div`,{className:`flex max-w-md flex-col gap-4`,children:(0,$.jsx)(Xn,{label:t.regionLabel,description:t.regionDesc,children:(0,$.jsxs)(g,{className:Qn(),value:o.regionMode,onChange:e=>b({regionMode:e.target.value}),children:[(0,$.jsx)(_,{value:`auto`,children:t.regionAuto}),(0,$.jsx)(_,{value:`cn`,children:t.regionCn}),(0,$.jsx)(_,{value:`global`,children:t.regionGlobal})]})})})]}),(0,$.jsx)(Vt,{children:(0,$.jsxs)(bt,{children:[(0,$.jsx)(yt,{icon:ke,title:t.sectionBlocklist,subtitle:t.sectionBlocklistHint}),(0,$.jsxs)(`div`,{className:`flex max-w-xl flex-col gap-4`,children:[(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:o.blocklistEnabled,onChange:e=>b({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)(Xn,{label:t.blocklistDomains,description:t.blocklistDomainsDesc,children:(0,$.jsx)(`textarea`,{className:F(Zn(),`min-h-[6rem] font-mono text-xs`),value:o.blocklistDomains.join(`
|
|
7
|
-
`),placeholder:t.blocklistDomainsPlaceholder,disabled:!o.blocklistEnabled,onChange:e=>{b({blocklistDomains:e.target.value.split(/\r?\n/).flatMap(e=>{let t=e.trim().toLowerCase();return t?[t]:[]})})}})})]})]})}),(0,$.jsxs)(bt,{children:[(0,$.jsx)(yt,{icon:D,title:t.sectionSearch,subtitle:t.sectionSearchHint}),(0,$.jsxs)(`div`,{className:`flex max-w-xl flex-col gap-6`,children:[(0,$.jsx)(Xn,{label:t.maxResultsLabel,description:t.maxResultsDesc,children:(0,$.jsx)(`input`,{type:`number`,min:1,max:50,className:Zn(),value:o.maxResults,onChange:e=>b({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)(rr,{row:n,providerIndex:r,labels:t,secretLabels:Ce(e.providersSettings),onChange:e=>{let t=[...o.providers];t[r]=e,b({providers:t})},onRemove:()=>{b({providers:o.providers.filter((e,t)=>t!==r)})}},`${n.type}:${n.url}:${n.apiKey}:${n.disabled}`)),(0,$.jsxs)(L,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5 text-sm`,onClick:()=>b({providers:[...o.providers,er()]}),children:[(0,$.jsx)(E,{className:`size-4`}),t.addProvider]})]})]})]}),(0,$.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:t.footerHint})]}):(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:v??t.loadError}),(0,$.jsx)(L,{type:`button`,variant:`secondary`,onClick:()=>void m(),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 rr(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=()=>Yn(r).then(ir),t[0]=r,t[1]=c);let l=c,u;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(u=F(Qn(),`min-w-[8rem]`),t[2]=u):u=t[2];let d=n.type,f;t[3]!==o||t[4]!==n?(f=e=>o({...n,type:e.target.value,url:e.target.value===`searxng`?n.url:``}),t[3]=o,t[4]=n,t[5]=f):f=t[5];let p;t[6]===i.providerTypes?p=t[7]:(p=$n.map(e=>(0,$.jsx)(_,{value:e,children:i.providerTypes[e]},e)),t[6]=i.providerTypes,t[7]=p);let m;t[8]!==n.type||t[9]!==f||t[10]!==p?(m=(0,$.jsx)(g,{className:u,value:d,onChange:f,children:p}),t[8]=n.type,t[9]=f,t[10]=p,t[11]=m):m=t[11];let h;t[12]!==o||t[13]!==n?(h=e=>o({...n,disabled:e.target.checked}),t[12]=o,t[13]=n,t[14]=h):h=t[14];let v;t[15]!==n.disabled||t[16]!==h?(v=(0,$.jsx)(`input`,{type:`checkbox`,className:`size-3.5 rounded border-edge`,checked:n.disabled,onChange:h}),t[15]=n.disabled,t[16]=h,t[17]=v):v=t[17];let y;t[18]!==i.disabled||t[19]!==v?(y=(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1.5 text-xs text-fg-muted`,children:[v,i.disabled]}),t[18]=i.disabled,t[19]=v,t[20]=y):y=t[20];let b;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,$.jsx)(pe,{className:`size-4`}),t[21]=b):b=t[21];let x;t[22]===s?x=t[23]:(x=(0,$.jsx)(L,{type:`button`,variant:`ghost`,className:`h-8 px-2 text-fg-muted`,onClick:s,children:b}),t[22]=s,t[23]=x);let S;t[24]!==x||t[25]!==y?(S=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[y,x]}),t[24]=x,t[25]=y,t[26]=S):S=t[26];let C;t[27]!==S||t[28]!==m?(C=(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[m,S]}),t[27]=S,t[28]=m,t[29]=C):C=t[29];let w;t[30]!==i.urlDesc||t[31]!==i.urlLabel||t[32]!==o||t[33]!==n?(w=n.type===`searxng`?(0,$.jsx)(Xn,{label:i.urlLabel,description:i.urlDesc,children:(0,$.jsx)(`input`,{type:`url`,className:Zn(),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]=w):w=t[34];let T;t[35]!==o||t[36]!==n?(T=e=>o({...n,apiKey:e}),t[35]=o,t[36]=n,t[37]=T):T=t[37];let E;t[38]!==i.keyPlaceholder||t[39]!==i.keyPlaceholderMasked||t[40]!==i.saveError||t[41]!==l||t[42]!==n.apiKey||t[43]!==a||t[44]!==T?(E=(0,$.jsx)(We,{value:n.apiKey,onChange:T,placeholder:i.keyPlaceholder,labels:a,reveal:l,loadFailedLabel:i.saveError,notInConfigFile:i.keyPlaceholderMasked}),t[38]=i.keyPlaceholder,t[39]=i.keyPlaceholderMasked,t[40]=i.saveError,t[41]=l,t[42]=n.apiKey,t[43]=a,t[44]=T,t[45]=E):E=t[45];let D;t[46]!==i.apiKeyDesc||t[47]!==i.apiKeyLabel||t[48]!==E?(D=(0,$.jsx)(Xn,{label:i.apiKeyLabel,description:i.apiKeyDesc,children:E}),t[46]=i.apiKeyDesc,t[47]=i.apiKeyLabel,t[48]=E,t[49]=D):D=t[49];let O;return t[50]!==C||t[51]!==w||t[52]!==D?(O=(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-xl bg-surface-panel/70 p-4 shadow-surface`,children:[C,w,D]}),t[50]=C,t[51]=w,t[52]=D,t[53]=O):O=t[53],O}function ir(e){return e.apiKey??null}var ar=[`common`,`domestic`,`specialty`,`enterprise`,`oauth`,`extension`];function or(e){let t=new Map;for(let e of ar)t.set(e,[]);for(let n of e){let e=n.category||`specialty`,r=t.get(e)??[];r.push(n),t.set(e,r)}return t}var sr=`xopc-cloud`;function cr(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,m]=(0,Q.useState)(u),[g,_]=(0,Q.useState)(``),v;t[1]===r?v=t[2]:(v=e=>{e||window.setTimeout(()=>{m({type:`pick`}),_(``)},200),r(e)},t[1]=r,t[2]=v);let y=v,b;t[3]!==y||t[4]!==c?(b=()=>{c(),y(!1)},t[3]=y,t[4]=c,t[5]=b):b=t[5];let x=b,S;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,$.jsx)(l,{className:F(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,te)}),t[6]=S):S=t[6];let C;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(C=F(`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`,K),t[7]=C):C=t[7];let w;t[8]!==i||t[9]!==a||t[10]!==x||t[11]!==o||t[12]!==s||t[13]!==g||t[14]!==d.presetKey||t[15]!==d.providerId||t[16]!==d.type?(w=(0,$.jsxs)(f,{children:[S,(0,$.jsx)(p,{className:C,children:d.type===`pick`?(0,$.jsx)(ur,{builtinRows:i,searchQuery:g,onSearchChange:_,labels:o,onPickBuiltin:e=>{let t=Ze(e);m(t?{type:`custom`,presetKey:t}:{type:`builtin`,providerId:e})},onPickCustom:()=>m({type:`custom`})}):d.type===`builtin`?(0,$.jsx)(mr,{providerId:d.providerId,builtinRows:i,labels:o,language:s,onBack:()=>m({type:`pick`}),onSaved:x}):(0,$.jsx)(_r,{initialPresetKey:d.presetKey,customConfig:a,labels:o,language:s,onBack:()=>m({type:`pick`}),onSaved:x})})]}),t[8]=i,t[9]=a,t[10]=x,t[11]=o,t[12]=s,t[13]=g,t[14]=d.presetKey,t[15]=d.providerId,t[16]=d.type,t[17]=w):w=t[17];let T;return t[18]!==y||t[19]!==n||t[20]!==w?(T=(0,$.jsx)(h,{open:n,onOpenChange:y,children:w}),t[18]=y,t[19]=n,t[20]=w,t[21]=T):T=t[21],T}function lr(e){let t=(0,Z.c)(4),{label:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=F(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,R.press),t[0]=r):r=t[0];let i;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(O,{className:`size-4`,"aria-hidden":!0}),t[1]=i):i=t[1];let a;return t[2]===n?a=t[3]:(a=(0,$.jsx)(d,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:r,"aria-label":n,children:i})}),t[2]=n,t[3]=a),a}function ur(e){let t=(0,Z.c)(49),{builtinRows:n,searchQuery:r,onSearchChange:i,labels:a,onPickBuiltin:o,onPickCustom:s}=e,c;t[0]===r?c=t[1]:(c=r.trim().toLowerCase(),t[0]=r,t[1]=c);let l=c,u;bb0:{if(!l){u=n;break bb0}let e;if(t[2]!==n||t[3]!==l){let r;t[5]===l?r=t[6]:(r=e=>{let t=Ae[e.id]?.aliases??[];return e.id.toLowerCase().includes(l)||e.name.toLowerCase().includes(l)||t.some(e=>e.toLowerCase().includes(l))},t[5]=l,t[6]=r),e=n.filter(r),t[2]=n,t[3]=l,t[4]=e}else e=t[4];u=e}let d=u,f;t[7]===d?f=t[8]:(f=d.find(fr),t[7]=d,t[8]=f);let p=f,h;t[9]===d?h=t[10]:(h=or(d.filter(dr)),t[9]=d,t[10]=h);let g=h,_;t[11]===a.step1Title?_=t[12]:(_=(0,$.jsx)(m,{className:`min-w-0 flex-1 text-base font-semibold text-fg`,children:a.step1Title}),t[11]=a.step1Title,t[12]=_);let v;t[13]===a.close?v=t[14]:(v=(0,$.jsx)(lr,{label:a.close}),t[13]=a.close,t[14]=v);let y;t[15]!==_||t[16]!==v?(y=(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b border-edge-subtle px-5 py-4`,children:[_,v]}),t[15]=_,t[16]=v,t[17]=y):y=t[17];let b;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,$.jsx)(D,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-fg-subtle`,strokeWidth:1.75,"aria-hidden":!0}),t[18]=b):b=t[18];let x;t[19]===i?x=t[20]:(x=e=>i(e.target.value),t[19]=i,t[20]=x);let S=a.searchPlaceholder,w;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(w=F(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-10 pr-3 text-sm text-fg placeholder:text-fg-subtle`,U),t[21]=w):w=t[21];let T;t[22]!==a.searchPlaceholder||t[23]!==r||t[24]!==x?(T=(0,$.jsx)(`div`,{className:`px-5 pt-3`,children:(0,$.jsxs)(`div`,{className:`relative`,children:[b,(0,$.jsx)(`input`,{type:`search`,value:r,onChange:x,placeholder:S,autoComplete:`off`,className:w})]})}),t[22]=a.searchPlaceholder,t[23]=r,t[24]=x,t[25]=T):T=t[25];let E;t[26]!==a.recommended||t[27]!==o||t[28]!==p?(E=p?(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`p`,{className:`mb-1 px-1 text-[11px] font-semibold uppercase tracking-wide text-fg-subtle`,children:a.recommended}),(0,$.jsx)(pr,{row:p,onPick:o})]}):null,t[26]=a.recommended,t[27]=o,t[28]=p,t[29]=E):E=t[29];let O;t[30]!==a.addCustom||t[31]!==a.customDescription||t[32]!==s||t[33]!==l?(O=l?null:(0,$.jsxs)(`button`,{type:`button`,onClick:s,className:F(`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`,R.press),children:[(0,$.jsx)(C,{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)(he,{className:`size-4 shrink-0 text-fg-subtle`,"aria-hidden":!0})]}),t[30]=a.addCustom,t[31]=a.customDescription,t[32]=s,t[33]=l,t[34]=O):O=t[34];let k;t[35]!==d.length||t[36]!==g||t[37]!==a.categories||t[38]!==a.noResults||t[39]!==o?(k=d.length===0?(0,$.jsx)(`p`,{className:`py-6 text-center text-sm text-fg-muted`,children:a.noResults}):(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:ar.map(e=>{let t=g.get(e)??[];return t.length===0?null:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`mb-1 px-1 text-[11px] font-semibold uppercase tracking-wide text-fg-subtle`,children:a.categories[e]??e}),(0,$.jsx)(`div`,{className:`flex flex-col gap-0.5`,children:t.map(e=>(0,$.jsx)(pr,{row:e,onPick:o},e.id))})]},e)})}),t[35]=d.length,t[36]=g,t[37]=a.categories,t[38]=a.noResults,t[39]=o,t[40]=k):k=t[40];let A;t[41]!==E||t[42]!==O||t[43]!==k?(A=(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto px-5 py-3`,children:[E,O,k]}),t[41]=E,t[42]=O,t[43]=k,t[44]=A):A=t[44];let j;return t[45]!==T||t[46]!==A||t[47]!==y?(j=(0,$.jsxs)($.Fragment,{children:[y,T,A]}),t[45]=T,t[46]=A,t[47]=y,t[48]=j):j=t[48],j}function dr(e){return e.id!==sr}function fr(e){return e.id===sr}function pr(e){let t=(0,Z.c)(12),{row:n,onPick:r}=e,i;t[0]!==r||t[1]!==n.id?(i=()=>r(n.id),t[0]=r,t[1]=n.id,t[2]=i):i=t[2];let a;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(a=F(`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`,R.press),t[3]=a):a=t[3];let o;t[4]===n.name?o=t[5]:(o=(0,$.jsx)(`span`,{className:`truncate text-sm text-fg`,children:n.name}),t[4]=n.name,t[5]=o);let s;t[6]===n.configured?s=t[7]:(s=n.configured?(0,$.jsx)(y,{className:`size-3.5 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):null,t[6]=n.configured,t[7]=s);let c;return t[8]!==i||t[9]!==o||t[10]!==s?(c=(0,$.jsxs)(`button`,{type:`button`,onClick:i,className:a,children:[o,s]}),t[8]=i,t[9]=o,t[10]=s,t[11]=c):c=t[11],c}function mr({providerId:e,builtinRows:t,labels:n,language:r,onBack:i,onSaved:a}){let o=t.find(t=>t.id===e),s=Ae[e],[c,l]=(0,Q.useState)(``),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(null),[h,g]=(0,Q.useState)(!1),_=(0,Q.useRef)(null),v=k(r).providersSettings,b=Ce(v),x=(0,Q.useMemo)(()=>Oe(e,r),[e,r]),S=o?.supportsApiKey!==!1,C=o?.supportsOAuth===!0,[T,E]=(0,Q.useState)(null),[D,O]=(0,Q.useState)(null),[A,j]=(0,Q.useState)(`idle`),[M,N]=(0,Q.useState)(null),[P,I]=(0,Q.useState)(null),[ee,z]=(0,Q.useState)(null),[B,V]=(0,Q.useState)(``),H=(0,Q.useRef)(null),W=(0,Q.useRef)(null),G=A===`waiting`||A===`waiting_code`;(0,Q.useEffect)(()=>{if(!T||!G)return;let t=window.setInterval(()=>{(async()=>{try{let n=await ce(T);n.status===`waiting_auth`||n.status===`waiting_code`?(j(n.status===`waiting_code`?`waiting_code`:`waiting`),O(n.message??null),N(n.authUrl??null),I(n.instructions??null),z(n.deviceCode??null),n.authUrl&&n.authUrl!==W.current&&(W.current=n.authUrl,xt(n.authUrl,H.current).catch(()=>{}))):n.status===`completed`?(window.clearInterval(t),Ct(H.current),H.current=null,e===`xopc-cloud`&&await J(),j(`success`),O(n.message??v.saved),window.setTimeout(a,600)):(n.status===`failed`||n.status===`cancelled`)&&(window.clearInterval(t),Ct(H.current),H.current=null,j(`error`),O(n.error??n.message??v.revokeFailed))}catch{}})()},1e3);return()=>window.clearInterval(t)},[T,G,a,e,v.revokeFailed,v.saved]),(0,Q.useEffect)(()=>()=>{T&&oe(T).catch(()=>{})},[T]),(0,Q.useEffect)(()=>()=>{Ct(H.current),H.current=null},[]);let K=async()=>{Ct(H.current),H.current=St(),W.current=null,j(`waiting`),O(v.oauthStarting),N(null),I(null),z(null),p(null);try{E((await ie(e)).sessionId)}catch(e){Ct(H.current),H.current=null,j(`error`),O(e instanceof Error?e.message:v.revokeFailed)}},te=async()=>{if(T){try{await le(T)}catch{}Ct(H.current),H.current=null,W.current=null,j(`idle`),O(null),E(null),N(null),I(null),z(null)}},q=async()=>{if(!(!T||!B.trim()))try{await se(T,B.trim()),V(``),O(v.oauthProcessingCode)}catch(e){j(`error`),O(e instanceof Error?e.message:v.revokeFailed)}},ne=async()=>{let t=c.trim();if(!(!t||!S)){d(!0),p(null);try{await Fe({[e]:t}),g(!0),window.setTimeout(a,600)}catch(e){p(e instanceof Error?e.message:n.saveError)}finally{d(!1)}}};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-edge-subtle px-5 py-4`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:i,className:F(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,R.press),"aria-label":n.back,children:(0,$.jsx)(he,{className:`size-4 rotate-180`,"aria-hidden":!0})}),(0,$.jsx)(m,{className:`min-w-0 flex-1 text-base font-semibold text-fg`,children:o?.name??e}),(0,$.jsx)(lr,{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)(We,{id:`builtin-api-key`,value:c,onChange:l,placeholder:n.apiKeyPlaceholder,labels:b,inputRef:_,onKeyDown:e=>{e.key===`Enter`&&ne()}})]}):null,C?(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:v.oauth}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:v.oauthHint})]}),(0,$.jsxs)(L,{type:`button`,variant:`primary`,className:`gap-1.5`,disabled:G,onClick:()=>void K(),children:[G?(0,$.jsx)(w,{className:`size-3.5 animate-spin`,"aria-hidden":!0}):null,v.oauth]})]}),D?(0,$.jsx)(`p`,{className:F(`text-xs`,A===`error`?`text-red-600 dark:text-red-400`:`text-fg-muted`),children:D}):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:[v.openAuthPage,(0,$.jsx)(`span`,{className:`size-3`,"aria-hidden":!0,children:`↗`})]}):null,(0,$.jsx)(L,{type:`button`,variant:`secondary`,onClick:()=>void te(),children:v.cancelOAuth})]}):null,P?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:P}):null,ee?(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:v.deviceCodeLabel}),(0,$.jsx)(`code`,{className:`mt-1 block select-all font-mono text-lg font-semibold tracking-widest text-fg`,children:ee}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:v.deviceCodeHint})]}):null,A===`waiting_code`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,$.jsx)(`input`,{type:`text`,value:B,onChange:e=>V(e.target.value),onKeyDown:e=>e.key===`Enter`&&void q(),placeholder:v.pasteRedirectUrl,className:F(`min-w-0 flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,U)}),(0,$.jsx)(L,{type:`button`,variant:`primary`,onClick:()=>void q(),children:v.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:[Me(e,n),(0,$.jsx)(`span`,{className:`size-3`,"aria-hidden":!0,children:`↗`})]},e))}):null,f?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:f}):null,(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,$.jsx)(L,{type:`button`,variant:`secondary`,onClick:i,children:n.cancel}),S?(0,$.jsx)(L,{type:`button`,variant:`primary`,disabled:!c.trim()||u||h,onClick:()=>void ne(),children:h?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(y,{className:`size-3.5`,"aria-hidden":!0}),n.saved]}):u?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(w,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),n.saving]}):n.save}):null]})]})]})}function hr(e=`custom`){if(e!==`custom`&&Le[e]){let t=Le[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 gr(e,t){switch(t.type){case`applyPreset`:return t.key===`custom`?{...e,preset:`custom`,error:null}:Le[t.key]?hr(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 _r({initialPresetKey:e,customConfig:t,labels:n,language:r,onBack:i,onSaved:a}){let[o,s]=(0,Q.useReducer)(gr,void 0,()=>hr(e)),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(!1),f=Ce(k(r).providersSettings),{preset:p,providerId:h,baseUrl:v,api:y,apiKey:b,modelIds:x,error:S}=o,C=async()=>{let e=h.trim(),r=v.trim();if(!e){s({type:`setError`,value:n.providerIdRequired});return}if(!r){s({type:`setError`,value:n.baseUrlRequired});return}let i=x.map(e=>e.trim()).filter(Boolean);l(!0),s({type:`setError`,value:null});try{let n=t?.providers??{},o=p===`custom`?void 0:Le[p]?.config,s={...o??{},baseUrl:r,api:y,apiKey:b.trim()||void 0,models:i.map(e=>o?.models?.find(t=>t.id===e)??{id:e})};await ot({providers:{...n,[e]:s}}),a()}catch(e){s({type:`setError`,value:e instanceof Error?e.message:n.saveError})}finally{l(!1)}},T=async()=>{let e=h.trim()||He(p)||`custom`,t=v.trim();if(!t){s({type:`setError`,value:n.baseUrlRequired});return}d(!0),s({type:`setError`,value:null});try{let r=p===`custom`?void 0:Le[p]?.config,i=(await Ge({providerId:e,baseUrl:t,apiKey:b.trim()||void 0,api:y,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{d(!1)}},A=h.trim()&&v.trim(),j=(y===`openai-completions`||y===`openai-responses`)&&v.trim();return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-edge-subtle px-5 py-4`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:i,className:F(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,R.press),"aria-label":n.back,children:(0,$.jsx)(he,{className:`size-4 rotate-180`,"aria-hidden":!0})}),(0,$.jsx)(m,{className:`min-w-0 flex-1 text-base font-semibold text-fg`,children:n.step2CustomTitle}),(0,$.jsx)(lr,{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)(g,{id:`custom-preset`,value:p,onChange:e=>s({type:`applyPreset`,key:e.target.value}),className:Ke(),children:[(0,$.jsx)(_,{value:`custom`,children:n.presetCustom}),et.map(e=>(0,$.jsx)(_,{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:h,onChange:e=>s({type:`setProviderId`,value:e.target.value}),placeholder:n.providerIdPlaceholder,className:F(`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,U)})]}),(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`custom-base-url`,className:`text-sm font-medium text-fg`,children:n.baseUrlLabel}),(0,$.jsx)(`input`,{id:`custom-base-url`,type:`url`,autoComplete:`off`,value:v,onChange:e=>s({type:`setBaseUrl`,value:e.target.value}),placeholder:n.baseUrlPlaceholder,className:F(`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,U)})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`custom-api-type`,className:`text-sm font-medium text-fg`,children:n.apiTypeLabel}),(0,$.jsx)(g,{id:`custom-api-type`,value:y,onChange:e=>s({type:`setApi`,value:e.target.value}),className:Ke(),children:Se.map(e=>(0,$.jsx)(_,{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)(We,{id:`custom-api-key`,value:b,onChange:e=>s({type:`setApiKey`,value:e}),placeholder:n.apiKeyPlaceholder,labels:f})]}),(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)(L,{type:`button`,variant:`secondary`,className:`gap-1.5`,disabled:!j||u,onClick:()=>void T(),children:[u?(0,$.jsx)(w,{className:`size-3.5 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(D,{className:`size-3.5`,"aria-hidden":!0}),u?n.discoveringModels:n.discoverModels]})]}),x.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:F(`flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,U)}),x.length>1?(0,$.jsx)(`button`,{type:`button`,onClick:()=>s({type:`removeModelSlot`,index:t}),className:F(`rounded-lg p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,R.press),children:(0,$.jsx)(O,{className:`size-3.5`,"aria-hidden":!0})}):null]},e||`model-slot-${t}`)),(0,$.jsxs)(L,{type:`button`,variant:`ghost`,className:`w-fit gap-1.5 text-fg-muted`,onClick:()=>s({type:`addModelSlot`}),children:[(0,$.jsx)(E,{className:`size-3.5`,"aria-hidden":!0}),n.addModel]})]}),S?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:S}):null]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t border-edge-subtle px-5 py-3`,children:[(0,$.jsx)(L,{type:`button`,variant:`secondary`,onClick:i,children:n.cancel}),(0,$.jsx)(L,{type:`button`,variant:`primary`,disabled:!A||c,onClick:()=>void C(),children:c?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(w,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),n.saving]}):n.save})]})]})}function vr(){let e=(0,Z.c)(31),t=P(Cr),n=!!t,{data:r,isLoading:i}=B(n),a;e[0]===n?a=e[1]:(a=n?N(`/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}=I(a,o,s),u;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(u={revalidateOnFocus:!1},e[5]=u):u=e[5];let{data:d,isLoading:f}=I(n?ne:null,Sr,u),p;e[6]===d?p=e[7]:(p=d===void 0?[]:d,e[6]=d,e[7]=p);let m=p,h;e[8]===Symbol.for(`react.memo_cache_sentinel`)?(h={revalidateOnFocus:!1},e[8]=h):h=e[8];let{data:g}=I(n?Y:null,xr,h),_;bb0:{if(!c||r===void 0){let t;e[9]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[9]=t):t=e[9],_=t;break bb0}let t;e[10]!==r?.payload?.config||e[11]!==c||e[12]!==m?(t=Je(c,pt(r?.payload?.config),m),e[10]=r?.payload?.config,e[11]=c,e[12]=m,e[13]=t):t=e[13],_=t}let v=_,y;bb1:{if(!g){y=null;break bb1}let t;e[14]===g.config?t=e[15]:(t=Qe(g.config),e[14]=g.config,e[15]=t),y=t}let b=y,x;if(e[16]!==v||e[17]!==b||e[18]!==c||e[19]!==m){x=[];let t=new Set((c??[]).filter(br).map(yr)),n;e[21]===b?n=e[22]:(n=new Set(b?Object.keys(b.providers):[]),e[21]=b,e[22]=n);let r=n;for(let e of v){if(!t.has(e.id))continue;let n=r.has(e.id),i=n?b.providers[e.id]?.models?.length??0:m.filter(t=>t.provider===e.id).length;x.push({id:e.id,name:e.name,configured:!0,isCustom:n,modelCount:i})}if(b){let t;e[23]===b.providers?t=e[24]:(t=Object.entries(b.providers),e[23]=b.providers,e[24]=t);for(let[e,n]of t)x.some(t=>t.id===e)||x.push({id:e,name:e,configured:!0,isCustom:!0,modelCount:n.models?.length??0})}e[16]=v,e[17]=b,e[18]=c,e[19]=m,e[20]=x}else x=e[20];let S=x,C=i||l||f,w;return e[25]!==v||e[26]!==S||e[27]!==b||e[28]!==C||e[29]!==m?(w={cards:S,loading:C,builtinRows:v,customConfig:b,allModels:m},e[25]=v,e[26]=S,e[27]=b,e[28]=C,e[29]=m,e[30]=w):w=e[30],w}function yr(e){return e.id}function br(e){return e.configured}function xr(){return ut()}function Sr(){return q()}function Cr(e){return e.token}function wr(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)(G,{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(Er)})]}),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)(E,{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)(L,{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)(L,{type:`button`,variant:`primary`,className:`mt-4 gap-1.5`,onClick:i,children:[(0,$.jsx)(E,{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)(Dr,{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 Er(e){return(0,$.jsx)(G,{className:`h-32 rounded-2xl`},e)}function Dr(e){let t=(0,Z.c)(28),{card:n,labels:r,onManage:i}=e,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=F(`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`,R.pressCard),t[0]=a):a=t[0];let o;t[1]===n.name?o=t[2]:(o=(0,$.jsx)(`span`,{className:`truncate text-sm font-semibold text-fg`,children:n.name}),t[1]=n.name,t[2]=o);let s;t[3]!==n.isCustom||t[4]!==r.custom?(s=n.isCustom?(0,$.jsx)(`span`,{className:`shrink-0 rounded bg-surface-hover px-1.5 py-0.5 text-[10px] font-medium text-fg-subtle`,children:r.custom}):null,t[3]=n.isCustom,t[4]=r.custom,t[5]=s):s=t[5];let c;t[6]!==o||t[7]!==s?(c=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[o,s]}),t[6]=o,t[7]=s,t[8]=c):c=t[8];let l;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(y,{className:`size-4 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}),t[9]=l):l=t[9];let u;t[10]===c?u=t[11]:(u=(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[c,l]}),t[10]=c,t[11]=u);let d;t[12]!==n.modelCount||t[13]!==r.modelsCount||t[14]!==r.noModels?(d=n.modelCount>0?r.modelsCount.replace(`{{count}}`,String(n.modelCount)):r.noModels,t[12]=n.modelCount,t[13]=r.modelsCount,t[14]=r.noModels,t[15]=d):d=t[15];let f;t[16]===d?f=t[17]:(f=(0,$.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:d}),t[16]=d,t[17]=f);let p;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(je,{className:`size-3`,"aria-hidden":!0}),t[18]=p):p=t[18];let m;t[19]===r.manage?m=t[20]:(m=(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-xs font-medium text-accent-fg opacity-0 transition-opacity group-hover:opacity-100`,children:[p,r.manage]}),t[19]=r.manage,t[20]=m);let h;t[21]!==m||t[22]!==f?(h=(0,$.jsxs)(`div`,{className:`mt-2.5 flex items-center justify-between`,children:[f,m]}),t[21]=m,t[22]=f,t[23]=h):h=t[23];let g;return t[24]!==i||t[25]!==h||t[26]!==u?(g=(0,$.jsxs)(`button`,{type:`button`,onClick:i,className:a,children:[u,h]}),t[24]=i,t[25]=h,t[26]=u,t[27]=g):g=t[27],g}function Or(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}:ue(``),t[0]=n,t[1]=c);let[l,u]=(0,Q.useState)(c),[f,p]=(0,Q.useState)(kr),h;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(h=(e,t)=>{u(n=>({...n,[e]:t})),p(t=>{let n=new Map(t);return n.delete(e),n})},t[2]=h):h=t[2];let v=h,y;t[3]!==l.contextWindow||t[4]!==l.id||t[5]!==l.maxTokens||t[6]!==s.modelIdRequired||t[7]!==s.mustBePositive?(y=()=>{let e=new Map;return(l.id||``).trim()||e.set(`id`,s.modelIdRequired),l.contextWindow!==void 0&&l.contextWindow<=0&&e.set(`contextWindow`,s.mustBePositive),l.maxTokens!==void 0&&l.maxTokens<=0&&e.set(`maxTokens`,s.mustBePositive),p(e),e.size===0},t[3]=l.contextWindow,t[4]=l.id,t[5]=l.maxTokens,t[6]=s.modelIdRequired,t[7]=s.mustBePositive,t[8]=y):y=t[8];let b=y,x;t[9]!==l||t[10]!==o||t[11]!==a||t[12]!==b?(x=()=>{if(!b())return;let e=(l.id||``).trim();a({...l,id:e,name:l.name?.trim()||e,reasoning:l.reasoning||!1,input:l.input||[`text`],contextWindow:l.contextWindow??128e3,maxTokens:l.maxTokens??16384,cost:{input:l.cost?.input??0,output:l.cost?.output??0,cacheRead:l.cost?.cacheRead??0,cacheWrite:l.cost?.cacheWrite??0}}),o()},t[9]=l,t[10]=o,t[11]=a,t[12]=b,t[13]=x):x=t[13];let S=x,C=l,w;t[14]===C?w=t[15]:(w=ft(C),t[14]=C,t[15]=w);let T=w,E=r?s.addModelTitle:s.editModelTitle,D;t[16]===E?D=t[17]:(D=(0,$.jsx)(m,{className:`text-base font-semibold text-fg`,children:E}),t[16]=E,t[17]=D);let k;t[18]!==s.modelProviderLabel||t[19]!==i?(k=i?(0,$.jsxs)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:[s.modelProviderLabel,`: `,i]}):null,t[18]=s.modelProviderLabel,t[19]=i,t[20]=k):k=t[20];let A;t[21]!==D||t[22]!==k?(A=(0,$.jsxs)(`div`,{children:[D,k]}),t[21]=D,t[22]=k,t[23]=A):A=t[23];let j;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(j=F(ee,`p-1.5 hover:bg-surface-base`),t[24]=j):j=t[24];let M;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(M=(0,$.jsx)(O,{className:`size-4`}),t[25]=M):M=t[25];let N;t[26]===s.close?N=t[27]:(N=(0,$.jsx)(d,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:j,"aria-label":s.close,children:M})}),t[26]=s.close,t[27]=N);let P;t[28]!==A||t[29]!==N?(P=(0,$.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[A,N]}),t[28]=A,t[29]=N,t[30]=P):P=t[30];let I;t[31]===Symbol.for(`react.memo_cache_sentinel`)?(I=(0,$.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`}),t[31]=I):I=t[31];let R;t[32]===s.modelId?R=t[33]:(R=(0,$.jsxs)(`label`,{className:`mb-1 block text-xs font-medium text-fg`,children:[s.modelId,I]}),t[32]=s.modelId,t[33]=R);let z;t[34]===f?z=t[35]:(z=F(lt(),f.has(`id`)&&`border-red-500`),t[34]=f,t[35]=z);let B=l.id||``,V;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(V=e=>v(`id`,e.target.value),t[36]=V):V=t[36];let H=!r,U;t[37]!==z||t[38]!==B||t[39]!==H?(U=(0,$.jsx)(`input`,{className:z,value:B,onChange:V,placeholder:`e.g. llama3.1:8b`,disabled:H}),t[37]=z,t[38]=B,t[39]=H,t[40]=U):U=t[40];let W;t[41]===f?W=t[42]:(W=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]=W);let G;t[43]!==R||t[44]!==U||t[45]!==W?(G=(0,$.jsxs)(`div`,{children:[R,U,W]}),t[43]=R,t[44]=U,t[45]=W,t[46]=G):G=t[46];let K;t[47]===s.displayName?K=t[48]:(K=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.displayName}),t[47]=s.displayName,t[48]=K);let te;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(te=lt(),t[49]=te):te=t[49];let q=l.name||``,ne;t[50]===Symbol.for(`react.memo_cache_sentinel`)?(ne=e=>v(`name`,e.target.value),t[50]=ne):ne=t[50];let J;t[51]===q?J=t[52]:(J=(0,$.jsx)(`input`,{className:te,value:q,onChange:ne}),t[51]=q,t[52]=J);let Y;t[53]!==K||t[54]!==J?(Y=(0,$.jsxs)(`div`,{children:[K,J]}),t[53]=K,t[54]=J,t[55]=Y):Y=t[55];let X;t[56]===s.inputTypes?X=t[57]:(X=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.inputTypes}),t[56]=s.inputTypes,t[57]=X);let re;t[58]===Symbol.for(`react.memo_cache_sentinel`)?(re=Ke(),t[58]=re):re=t[58];let ie;t[59]===Symbol.for(`react.memo_cache_sentinel`)?(ie=e=>v(`input`,Be(e.target.value)),t[59]=ie):ie=t[59];let ae;t[60]===s?ae=t[61]:(ae=Xe.map(e=>(0,$.jsx)(_,{value:e.value,children:s[e.labelKey]},e.value)),t[60]=s,t[61]=ae);let oe;t[62]!==T||t[63]!==ae?(oe=(0,$.jsx)(g,{className:re,value:T,onChange:ie,children:ae}),t[62]=T,t[63]=ae,t[64]=oe):oe=t[64];let se;t[65]!==X||t[66]!==oe?(se=(0,$.jsxs)(`div`,{children:[X,oe]}),t[65]=X,t[66]=oe,t[67]=se):se=t[67];let ce=l.reasoning||!1,le;t[68]===Symbol.for(`react.memo_cache_sentinel`)?(le=e=>v(`reasoning`,e.target.checked),t[68]=le):le=t[68];let de;t[69]===ce?de=t[70]:(de=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:ce,onChange:le}),t[69]=ce,t[70]=de);let fe;t[71]!==s.reasoning||t[72]!==de?(fe=(0,$.jsxs)(`label`,{className:`mt-6 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[de,s.reasoning]}),t[71]=s.reasoning,t[72]=de,t[73]=fe):fe=t[73];let pe;t[74]!==se||t[75]!==fe?(pe=(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[se,fe]}),t[74]=se,t[75]=fe,t[76]=pe):pe=t[76];let me;t[77]===s.contextWindow?me=t[78]:(me=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.contextWindow}),t[77]=s.contextWindow,t[78]=me);let he;t[79]===f?he=t[80]:(he=F(lt(),f.has(`contextWindow`)&&`border-red-500`),t[79]=f,t[80]=he);let ge=l.contextWindow??128e3,_e;t[81]===Symbol.for(`react.memo_cache_sentinel`)?(_e=e=>v(`contextWindow`,parseInt(e.target.value,10)||0),t[81]=_e):_e=t[81];let ve;t[82]!==he||t[83]!==ge?(ve=(0,$.jsx)(`input`,{type:`number`,min:1,className:he,value:ge,onChange:_e}),t[82]=he,t[83]=ge,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]!==me||t[88]!==ve||t[89]!==ye?(be=(0,$.jsxs)(`div`,{children:[me,ve,ye]}),t[87]=me,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=F(lt(),f.has(`maxTokens`)&&`border-red-500`),t[93]=f,t[94]=Se);let Ce=l.maxTokens??16384,we;t[95]===Symbol.for(`react.memo_cache_sentinel`)?(we=e=>v(`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 je;t[112]===Symbol.for(`react.memo_cache_sentinel`)?(je=lt(),t[112]=je):je=t[112];let Me=l.cost?.input??0,Ne;t[113]===l.cost?Ne=t[114]:(Ne=e=>v(`cost`,{...l.cost,input:parseFloat(e.target.value)||0,output:l.cost?.output??0,cacheRead:l.cost?.cacheRead??0,cacheWrite:l.cost?.cacheWrite??0}),t[113]=l.cost,t[114]=Ne);let Pe;t[115]!==Me||t[116]!==Ne?(Pe=(0,$.jsx)(`input`,{type:`number`,step:`any`,min:0,className:je,value:Me,onChange:Ne}),t[115]=Me,t[116]=Ne,t[117]=Pe):Pe=t[117];let Fe;t[118]!==Ae||t[119]!==Pe?(Fe=(0,$.jsxs)(`div`,{children:[Ae,Pe]}),t[118]=Ae,t[119]=Pe,t[120]=Fe):Fe=t[120];let Ie;t[121]===s.costOutput?Ie=t[122]:(Ie=(0,$.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:s.costOutput}),t[121]=s.costOutput,t[122]=Ie);let Le;t[123]===Symbol.for(`react.memo_cache_sentinel`)?(Le=lt(),t[123]=Le):Le=t[123];let Re=l.cost?.output??0,ze;t[124]===l.cost?ze=t[125]:(ze=e=>v(`cost`,{...l.cost,input:l.cost?.input??0,output:parseFloat(e.target.value)||0,cacheRead:l.cost?.cacheRead??0,cacheWrite:l.cost?.cacheWrite??0}),t[124]=l.cost,t[125]=ze);let Ve;t[126]!==Re||t[127]!==ze?(Ve=(0,$.jsx)(`input`,{type:`number`,step:`any`,min:0,className:Le,value:Re,onChange:ze}),t[126]=Re,t[127]=ze,t[128]=Ve):Ve=t[128];let He;t[129]!==Ie||t[130]!==Ve?(He=(0,$.jsxs)(`div`,{children:[Ie,Ve]}),t[129]=Ie,t[130]=Ve,t[131]=He):He=t[131];let Ue;t[132]!==Fe||t[133]!==He?(Ue=(0,$.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[Fe,He]}),t[132]=Fe,t[133]=He,t[134]=Ue):Ue=t[134];let We;t[135]!==ke||t[136]!==Ue?(We=(0,$.jsxs)(`div`,{className:`border-t border-edge-subtle pt-2 dark:border-edge`,children:[ke,Ue]}),t[135]=ke,t[136]=Ue,t[137]=We):We=t[137];let Ge;t[138]!==G||t[139]!==Y||t[140]!==pe||t[141]!==Oe||t[142]!==We?(Ge=(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[G,Y,pe,Oe,We]}),t[138]=G,t[139]=Y,t[140]=pe,t[141]=Oe,t[142]=We,t[143]=Ge):Ge=t[143];let qe;t[144]===s.cancel?qe=t[145]:(qe=(0,$.jsx)(d,{asChild:!0,children:(0,$.jsx)(L,{type:`button`,variant:`secondary`,children:s.cancel})}),t[144]=s.cancel,t[145]=qe);let Je=r?s.addModelConfirm:s.saveModelConfirm,Ye;t[146]!==S||t[147]!==Je?(Ye=(0,$.jsx)(L,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:S,children:Je}),t[146]=S,t[147]=Je,t[148]=Ye):Ye=t[148];let Ze;t[149]!==qe||t[150]!==Ye?(Ze=(0,$.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2 border-t border-edge-subtle pt-3 dark:border-edge`,children:[qe,Ye]}),t[149]=qe,t[150]=Ye,t[151]=Ze):Ze=t[151];let Qe;return t[152]!==P||t[153]!==Ge||t[154]!==Ze?(Qe=(0,$.jsxs)($.Fragment,{children:[P,Ge,Ze]}),t[152]=P,t[153]=Ge,t[154]=Ze,t[155]=Qe):Qe=t[155],Qe}function kr(){return new Map}function Ar(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)(l,{className:F(`xopc-dialog-overlay fixed inset-0 bg-scrim`,te)}),t[0]=u):u=t[0];let d;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(d=F(`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`,K,`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 m;t[2]!==o||t[3]!==c||t[4]!==a||t[5]!==r||t[6]!==s||t[7]!==n||t[8]!==i?(m=n?(0,$.jsx)(Or,{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]=m):m=t[9];let g;t[10]===m?g=t[11]:(g=(0,$.jsxs)(f,{children:[u,(0,$.jsx)(p,{className:d,onOpenAutoFocus:jr,children:m})]}),t[10]=m,t[11]=g);let _;return t[12]!==r||t[13]!==n||t[14]!==g?(_=(0,$.jsx)(h,{open:n,onOpenChange:r,children:g}),t[12]=r,t[13]=n,t[14]=g,t[15]=_):_=t[15],_}function jr(e){return e.preventDefault()}function Mr(e){let t=(0,Z.c)(14),{providerId:n,inputId:r,value:i,onChange:a,labels:o}=e,s;t[0]===n?s=t[1]:(s=()=>ht(n).then(Nr),t[0]=n,t[1]=s);let c=s,l;t[2]!==r||t[3]!==o.apiKeyLabel?(l=(0,$.jsx)(`label`,{htmlFor:r,className:`text-sm font-medium text-fg`,children:o.apiKeyLabel}),t[2]=r,t[3]=o.apiKeyLabel,t[4]=l):l=t[4];let u;t[5]!==r||t[6]!==o||t[7]!==a||t[8]!==c||t[9]!==i?(u=(0,$.jsx)(We,{id:r,value:i,onChange:a,placeholder:o.apiKeyPlaceholder,labels:o,reveal:c,loadFailedLabel:o.loadFailed,maskedHelp:o.maskedHelp,notInConfigFile:o.notInConfigFile}),t[5]=r,t[6]=o,t[7]=a,t[8]=c,t[9]=i,t[10]=u):u=t[10];let d;return t[11]!==l||t[12]!==u?(d=(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[l,u]}),t[11]=l,t[12]=u,t[13]=d):d=t[13],d}function Nr(e){return e.apiKey??null}function Pr(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:m}=e,g;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,$.jsx)(l,{className:F(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,te)}),t[0]=g):g=t[0];let _;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(_=F(`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`,K),t[1]=_):_=t[1];let v;t[2]!==c||t[3]!==o||t[4]!==s||t[5]!==a||t[6]!==u||t[7]!==d||t[8]!==r||t[9]!==m||t[10]!==i?(v=(0,$.jsxs)(f,{children:[g,(0,$.jsx)(p,{className:_,children:a?(0,$.jsx)(Ir,{providerId:i,customConfig:s,labels:u,language:d,onClose:()=>r(!1),onSaved:m}):(0,$.jsx)(Fr,{providerId:i,builtinRows:o,allModels:c,labels:u,language:d,onClose:()=>r(!1),onSaved:m})})]}),t[2]=c,t[3]=o,t[4]=s,t[5]=a,t[6]=u,t[7]=d,t[8]=r,t[9]=m,t[10]=i,t[11]=v):v=t[11];let y;return t[12]!==r||t[13]!==n||t[14]!==v?(y=(0,$.jsx)(h,{open:n,onOpenChange:r,children:v}),t[12]=r,t[13]=n,t[14]=v,t[15]=y):y=t[15],y}function Fr({providerId:e,builtinRows:t,allModels:n,labels:r,language:i,onClose:a,onSaved:o}){let s=t.find(t=>t.id===e),l=Ae[e],u=n.filter(t=>t.provider===e),[f,p]=(0,Q.useState)(s?.apiKey??``),[h,g]=(0,Q.useState)(!1),[_,v]=(0,Q.useState)(!1),[b,S]=(0,Q.useState)(null),[C,T]=(0,Q.useState)(!1),E=k(i).providersSettings,D=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`,[N,P]=(0,Q.useState)(null),[I,ee]=(0,Q.useState)(null),[z,B]=(0,Q.useState)(`idle`),[V,H]=(0,Q.useState)(null),[W,G]=(0,Q.useState)(null),[K,te]=(0,Q.useState)(null),[q,ne]=(0,Q.useState)(``),J=(0,Q.useRef)(null),Y=(0,Q.useRef)(null),X=z===`waiting`||z===`waiting_code`,re=(0,Q.useMemo)(()=>Oe(e,i),[e,i]),ue=f!==(s?.apiKey??``),de=async()=>{let t=f.trim();if(!(!t||!D||Ye(t))){g(!0),S(null);try{await Fe({[e]:t}),v(!0),window.setTimeout(()=>{o(),a()},600)}catch(e){S(e instanceof Error?e.message:r.saveError)}finally{g(!1)}}};(0,Q.useEffect)(()=>{if(!N||!X)return;let e=window.setInterval(()=>{(async()=>{try{let t=await ce(N);t.status===`waiting_auth`||t.status===`waiting_code`?(B(t.status===`waiting_code`?`waiting_code`:`waiting`),ee(t.message??null),H(t.authUrl??null),G(t.instructions??null),te(t.deviceCode??null),t.authUrl&&t.authUrl!==Y.current&&(Y.current=t.authUrl,xt(t.authUrl,J.current).catch(()=>{}))):t.status===`completed`?(window.clearInterval(e),Ct(J.current),J.current=null,B(`success`),ee(t.message??E.saved),window.setTimeout(()=>{o(),a()},600)):(t.status===`failed`||t.status===`cancelled`)&&(window.clearInterval(e),Ct(J.current),J.current=null,B(`error`),ee(t.error??t.message??E.revokeFailed))}catch{}})()},1e3);return()=>window.clearInterval(e)},[N,X,a,o,E.revokeFailed,E.saved]),(0,Q.useEffect)(()=>()=>{N&&oe(N).catch(()=>{})},[N]),(0,Q.useEffect)(()=>()=>{Ct(J.current),J.current=null},[]);let me=async()=>{try{await tt(e),o(),a()}catch{}},he=async()=>{Ct(J.current),J.current=St(),Y.current=null,B(`waiting`),ee(E.oauthStarting),H(null),G(null),te(null),S(null);try{P((await ie(e)).sessionId)}catch(e){Ct(J.current),J.current=null,B(`error`),ee(e instanceof Error?e.message:E.revokeFailed)}},ge=async()=>{if(N){try{await le(N)}catch{}Ct(J.current),J.current=null,Y.current=null,B(`idle`),ee(null),P(null),H(null),G(null),te(null)}},_e=async()=>{if(!(!N||!q.trim()))try{await se(N,q.trim()),ne(``),ee(E.oauthProcessingCode)}catch(e){B(`error`),ee(e instanceof Error?e.message:E.revokeFailed)}},ve=async()=>{try{await ae(e),o(),a()}catch(e){S(e instanceof Error?e.message:E.revokeFailed)}};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-edge-subtle px-5 py-4`,children:[(0,$.jsx)(m,{className:`text-base font-semibold text-fg`,children:s?.name??e}),(0,$.jsx)(d,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:F(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,R.press),children:(0,$.jsx)(O,{className:`size-4`,"aria-hidden":!0})})})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 overflow-y-auto px-5 py-4`,children:[l?.description?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:l.description}):null,s?.baseUrl?(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:r.apiUrlLabel}),(0,$.jsx)(`code`,{className:`break-all rounded-lg border border-edge-subtle bg-surface-panel/60 px-3 py-2 font-mono text-xs text-fg-muted`,children:s.baseUrl})]}):s?.category===`extension`?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:r.apiUrlExtensionHint}):null,D?(0,$.jsx)(Mr,{providerId:e,inputId:`manage-api-key`,value:f,onChange:e=>{p(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)(x,{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:E.oauth}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:j?E.sourceOauth:E.oauthHint})]}),j?(0,$.jsx)(L,{type:`button`,variant:`secondary`,className:`gap-1.5 text-red-600 dark:text-red-400`,onClick:()=>void ve(),children:E.revoke}):(0,$.jsxs)(L,{type:`button`,variant:`primary`,className:`gap-1.5`,disabled:X,onClick:()=>void he(),children:[X?(0,$.jsx)(w,{className:`size-3.5 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(fe,{className:`size-3.5`,"aria-hidden":!0}),E.oauth]})]}),I?(0,$.jsx)(`p`,{className:F(`text-xs`,z===`error`?`text-red-600 dark:text-red-400`:`text-fg-muted`),children:I}):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)(x,{className:`size-4`,"aria-hidden":!0}),E.openAuthPage]}):null,(0,$.jsx)(L,{type:`button`,variant:`secondary`,onClick:()=>void ge(),children:E.cancelOAuth})]}):null,W?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:W}):null,K?(0,$.jsxs)(`div`,{className:`rounded-lg border border-edge-subtle bg-surface-panel px-3 py-2`,children:[(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:E.deviceCodeLabel}),(0,$.jsx)(`code`,{className:`mt-1 block select-all font-mono text-lg font-semibold tracking-widest text-fg`,children:K}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:E.deviceCodeHint})]}):null,z===`waiting_code`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,$.jsx)(`input`,{type:`text`,value:q,onChange:e=>ne(e.target.value),onKeyDown:e=>e.key===`Enter`&&void _e(),placeholder:E.pasteRedirectUrl,className:F(`min-w-0 flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,U)}),(0,$.jsx)(L,{type:`button`,variant:`primary`,onClick:()=>void _e(),children:E.submitCode})]}):null]}):null,re.length>0&&D?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:re.map(({kind:e,href:t})=>(0,$.jsxs)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent hover:underline`,children:[Me(e,r),(0,$.jsx)(x,{className:`size-3`,"aria-hidden":!0})]},e))}):null,u.length>0?(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsxs)(`span`,{className:`text-sm font-medium text-fg`,children:[r.modelsLabel,` (`,u.length,`)`]}),(0,$.jsx)(`div`,{className:`max-h-40 overflow-y-auto rounded-lg border border-edge-subtle bg-surface-panel/40 p-2`,children:(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:u.map(e=>(0,$.jsx)(`span`,{className:`inline-block rounded-md bg-surface-hover px-2 py-1 text-xs text-fg-muted`,children:e.id.includes(`/`)?e.id.split(`/`).pop():e.id},e.id))})})]}):(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:r.noModels}),b?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:b}):null]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-t border-edge-subtle px-5 py-3`,children:[M?(0,$.jsxs)(L,{type:`button`,variant:`ghost`,className:`gap-1.5 text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300`,onClick:()=>T(!0),children:[(0,$.jsx)(pe,{className:`size-3.5`,"aria-hidden":!0}),r.remove]}):(0,$.jsx)(`span`,{}),(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:D&&ue&&!Ye(f.trim())?(0,$.jsx)(L,{type:`button`,variant:`primary`,disabled:!f.trim()||h||_,onClick:()=>void de(),children:_?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(y,{className:`size-3.5`,"aria-hidden":!0}),r.saved]}):h?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(w,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),r.saving]}):r.save}):null})]}),(0,$.jsx)(it,{open:C,title:r.removeConfirmTitle,description:r.removeConfirmDescription.replace(`{{provider}}`,s?.name??e),confirmLabel:r.removeConfirmAction,cancelLabel:r.cancel,destructive:!0,onConfirm:()=>void me(),onCancel:()=>T(!1)})]})}function Ir({providerId:e,customConfig:t,labels:n,language:r,onClose:i,onSaved:a}){let o=k(r).modelsSettings,s=t?.providers[e],[c,l]=(0,Q.useState)(s?.baseUrl??``),[u,f]=(0,Q.useState)(s?.apiKey??``),[p,h]=(0,Q.useState)(s?.models??[]),[g,_]=(0,Q.useState)(s?.modelDiscovery?.enabled===!0),[v,y]=(0,Q.useState)(!1),[b,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(!1),[D,A]=(0,Q.useState)(null),[j,M]=(0,Q.useState)(!1),[N,P]=(0,Q.useState)(null),I=n=>{if(!t)return null;let r=u.trim(),i={...s,baseUrl:c.trim()||void 0,apiKey:Ye(r)?s?.apiKey:r||void 0,...n};return{providers:{...t.providers,[e]:i}}},ee=async()=>{let e=I({models:p,modelDiscovery:{enabled:g}});if(e){y(!0),x(null);try{await ot(e),a(),i()}catch(e){x(e instanceof Error?e.message:n.saveError)}finally{y(!1)}}},z=async()=>{if(t)try{let{[e]:n,...r}=t.providers;await ot({providers:r}),a(),i()}catch{}},B=(e,t)=>{P({model:e,isNew:t}),M(!0)},V=async e=>{if(!N)return;let t=N.isNew?[...p,e]:p.map(t=>t.id===e.id?e:t);h(t);let r=I({models:t});if(r)try{await ot(r),a()}catch(e){x(e instanceof Error?e.message:n.saveError)}},H=async e=>{let t=p.filter(t=>t.id!==e);h(t),A(null);let r=I({models:t});if(r)try{await ot(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)(m,{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)(d,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:F(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,R.press),children:(0,$.jsx)(O,{className:`size-4`,"aria-hidden":!0})})})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 overflow-y-auto px-5 py-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`manage-base-url`,className:`text-sm font-medium text-fg`,children:n.baseUrlLabel}),(0,$.jsx)(`input`,{id:`manage-base-url`,type:`url`,autoComplete:`off`,value:c,onChange:e=>l(e.target.value),className:F(`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,U)})]}),(0,$.jsx)(Mr,{providerId:e,inputId:`manage-custom-api-key`,value:u,onChange:f,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,p.length>0?` (${p.length})`:``]}),(0,$.jsxs)(L,{type:`button`,variant:`primary`,className:`gap-1.5 px-2 py-1 text-xs`,onClick:()=>B(null,!0),children:[(0,$.jsx)(E,{className:`size-3.5`,"aria-hidden":!0}),o.addModel]})]}),p.length===0?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:o.modelsEmpty}):(0,$.jsx)(`ul`,{className:`space-y-2`,children:p.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:F(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,R.press),onClick:()=>B(e,!1),"aria-label":o.editModel,children:(0,$.jsx)(T,{className:`size-3.5`,"aria-hidden":!0})}),(0,$.jsx)(`button`,{type:`button`,className:F(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-red-600 dark:hover:text-red-400`,R.press),onClick:()=>A(e.id),"aria-label":o.removeModel,children:(0,$.jsx)(pe,{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)(L,{type:`button`,variant:`ghost`,className:`gap-1.5 text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300`,onClick:()=>C(!0),children:[(0,$.jsx)(pe,{className:`size-3.5`,"aria-hidden":!0}),n.remove]}),(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsx)(L,{type:`button`,variant:`primary`,disabled:v,onClick:()=>void ee(),children:v?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(w,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),n.saving]}):n.save})})]}),(0,$.jsx)(it,{open:S,title:n.removeConfirmTitle,description:n.removeConfirmDescription.replace(`{{provider}}`,e),confirmLabel:n.removeConfirmAction,cancelLabel:n.cancel,destructive:!0,onConfirm:()=>void z(),onCancel:()=>C(!1)}),(0,$.jsx)(it,{open:D!==null,title:o.removeModel,description:o.removeModelConfirm.replace(`{{id}}`,D??``),confirmLabel:n.removeConfirmAction,cancelLabel:n.cancel,destructive:!0,onConfirm:()=>{D&&H(D)},onCancel:()=>A(null)}),(0,$.jsx)(Ar,{open:j,onOpenChange:e=>{M(e),e||P(null)},providerId:e,model:N?.model??null,isNew:N?.isNew??!1,onSave:e=>void V(e),m:o})]})}function Lr(e,t){switch(e){case`vision`:return{href:`${nt(`models`)}?add=1`,guidance:t?`接入支持图片理解的模型服务`:`Connect a model service that supports vision`,action:t?`去接入模型`:`Connect model`};case`image-generation`:return{href:nt(`image`),guidance:t?`选择图片模型并配置所需凭据`:`Choose an image model and configure its credentials`,action:t?`去配置图片生成`:`Configure image generation`};case`stt`:return{href:nt(`voice`),guidance:t?`选择语音识别服务,或安装本地语音模型`:`Choose a speech-to-text service or install a local voice model`,action:t?`去配置语音识别`:`Configure speech-to-text`};case`tts`:return{href:nt(`voice`),guidance:t?`选择语音合成服务并完成凭据配置`:`Choose a text-to-speech service and configure its credentials`,action:t?`去配置语音合成`:`Configure text-to-speech`}}}async function Rr(){let e=await j(N(`/api/models/catalog`)),t=await e.json().catch(()=>null);if(!e.ok||!t?.ok||!t.payload)throw Error(t?.error?.message??`HTTP ${e.status}`);return t.payload}async function zr(){let e=await j(N(`/api/capabilities/readiness`)),t=await e.json().catch(()=>null);if(!e.ok||!t?.ok||!t.payload)throw Error(t?.error?.message??`HTTP ${e.status}`);return t.payload}function Br(){let e=M(e=>e.language)===`zh`,{data:t,error:n,isLoading:r}=I(X,Rr,{revalidateOnFocus:!1}),{data:i}=I(re,zr,{revalidateOnFocus:!1}),[a,o]=(0,Q.useState)(!1),[s,l]=(0,Q.useState)(null);if(r)return(0,$.jsx)(G,{className:`h-24 w-full rounded-2xl`});let u=Object.values(t?.sources??{}),d=u.reduce((e,t)=>e+t.models.filter(e=>e.availability===`available`).length,0),f=(t?.references??[]).filter(e=>e.availability===`unavailable`),p=t?.sync.lastSuccessAt??Math.max(0,...u.map(e=>e.lastSuccessAt)),m=s??(n instanceof Error?n.message:t?.sync.lastError??Object.values(t?.sync.sourceErrors??{})[0]),h=Object.values(i?.capabilities??{}).some(e=>e.status===`degraded`||e.status===`unavailable`),g=async()=>{o(!0),l(null);try{let e=await j(N(`/api/models/catalog/refresh`),{method:`POST`});if(!e.ok)throw Error(`HTTP ${e.status}`);await J()}catch(t){l(t instanceof Error?t.message:e?`模型目录刷新失败`:`Model catalog refresh failed`)}finally{o(!1)}};return(0,$.jsxs)(`div`,{className:`rounded-2xl border border-edge-subtle bg-surface-panel/40 p-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[m||f.length>0||h?(0,$.jsx)(Te,{className:`size-4 text-amber-500`,"aria-hidden":!0}):(0,$.jsx)(y,{className:`size-4 text-emerald-500`,"aria-hidden":!0}),(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:e?`模型目录同步`:`Model catalog sync`})]}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e?`${u.length} 个来源,${d} 个可用模型${p?` · 最近同步 ${new Date(p).toLocaleString()}`:``}`:`${u.length} sources, ${d} available models${p?` · Last synced ${new Date(p).toLocaleString()}`:``}`})]}),(0,$.jsxs)(L,{className:`shrink-0`,type:`button`,variant:`secondary`,disabled:a,onClick:()=>void g(),children:[a?(0,$.jsx)(w,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Ue,{className:`size-4`,"aria-hidden":!0}),a?e?`刷新中…`:`Refreshing…`:e?`立即刷新`:`Refresh now`]})]}),i?(0,$.jsx)(`div`,{className:`mt-3 grid gap-2 sm:grid-cols-2 xl:grid-cols-4`,children:Object.entries(i.capabilities).map(([t,n])=>{let r=t===`vision`?e?`图片理解`:`Vision`:t===`image-generation`?e?`图片生成`:`Image generation`:t.toUpperCase(),i=n.selectionSource!==`explicit-config`,a=n.status===`degraded`||n.status===`unavailable`,o=Lr(t,e),s=(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`min-w-0 text-xs font-medium text-fg`,children:r}),(0,$.jsx)(`span`,{className:n.status===`ready`?`shrink-0 text-xs text-emerald-600 dark:text-emerald-400`:n.status===`disabled`?`shrink-0 text-xs text-fg-muted`:`shrink-0 text-xs text-amber-600 dark:text-amber-400`,children:n.status===`ready`?e?`可用`:`Ready`:n.status===`disabled`?e?`已关闭`:`Off`:e?`需处理`:`Needs attention`})]}),(0,$.jsx)(`p`,{className:`mt-1 truncate text-xs text-fg-muted`,title:n.primary?`${n.primary.provider}/${n.primary.model}`:void 0,children:n.primary?`${i?e?`自动`:`Auto`:e?`显式`:`Explicit`} · ${n.primary.provider}/${n.primary.model}`:e?`无可用实现`:`No available implementation`}),a?(0,$.jsxs)(`div`,{className:`mt-2 border-t border-edge-subtle pt-2`,children:[(0,$.jsx)(`p`,{className:`text-xs leading-5 text-amber-700 dark:text-amber-300`,children:n.status===`degraded`?e?`当前配置不可用,正在使用备用方案。${o.guidance}`:`The current configuration is unavailable, so a fallback is in use. ${o.guidance}.`:o.guidance}),(0,$.jsxs)(`span`,{className:`mt-1 inline-flex items-center gap-1 text-xs font-medium text-accent`,children:[o.action,(0,$.jsx)(de,{className:`size-3.5`,"aria-hidden":!0})]})]}):null]});return a?(0,$.jsx)(c,{to:o.href,"aria-label":`${r}:${o.action}`,className:F(`rounded-xl border border-amber-400/40 bg-amber-500/5 px-3 py-2`,`transition-colors hover:border-amber-400/70 hover:bg-amber-500/10`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`),children:s},t):(0,$.jsx)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel px-3 py-2`,children:s},t)})}):null,f.length>0?(0,$.jsx)(`div`,{className:`mt-2 space-y-1 text-sm text-amber-700 dark:text-amber-300`,children:f.slice(0,3).map(t=>(0,$.jsxs)(`p`,{children:[t.ref,` `,e?`不可用`:`is unavailable`,t.suggestedRef?` · ${e?`建议`:`Suggested`} ${t.suggestedRef}`:``,` · ${t.locations.length} ${e?`处引用`:`references`}`]},t.ref))}):null,m?(0,$.jsx)(`p`,{className:`mt-2 text-sm text-danger`,children:m}):null]})}async function Vr(){return(await A(N(`/api/models/xopc-cloud/account-summary`))).payload}function Hr(e){let t=(0,Z.c)(93),{labels:n}=e,r=M(Ur)===`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}=I(`/api/models/xopc-cloud/account-summary`,Vr,i);if(s){let e;return t[1]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(G,{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)(Te,{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)(Ue,{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)(L,{type:`button`,variant:`secondary`,disabled:c,onClick:o,children:[u,n.retry]}),t[14]=c,t[15]=n.retry,t[16]=o,t[17]=u,t[18]=d):d=t[18];let f;return t[19]!==a||t[20]!==d?(f=(0,$.jsx)(`section`,{className:`rounded-2xl border border-edge-subtle bg-surface-panel/40 p-4`,children:(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[a,d]})}),t[19]=a,t[20]=d,t[21]=f):f=t[21],f}let u,d,f,p,m,h,g,_;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);_=n.usageSummary.replace(`{{tokens}}`,e.format(a.usage.totalTokens)).replace(`{{credits}}`,e.format(a.usage.chargedCredits)).replace(`{{requests}}`,e.format(a.usage.requests)),g=`rounded-2xl border border-edge-subtle bg-surface-panel/40 p-5`,h=`flex flex-col gap-5 sm:flex-row sm:items-start sm:justify-between`,f=`min-w-0 flex-1`;let i;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(b,{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?(p=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[i,o,s]}),t[44]=o,t[45]=s,t[46]=p):p=t[46],t[47]===n.availableCredits?m=t[48]:(m=(0,$.jsx)(`p`,{className:`mt-5 text-xs font-medium text-fg-subtle`,children:n.availableCredits}),t[47]=n.availableCredits,t[48]=m),u=`mt-1 text-3xl font-semibold tracking-tight text-fg`,d=e.format(a.balance.credits),t[22]=a.balance.credits,t[23]=a.usage.chargedCredits,t[24]=a.usage.requests,t[25]=a.usage.totalTokens,t[26]=n.availableCredits,t[27]=n.connected,t[28]=n.title,t[29]=n.usageSummary,t[30]=r,t[31]=u,t[32]=d,t[33]=f,t[34]=p,t[35]=m,t[36]=h,t[37]=g,t[38]=_}else u=t[31],d=t[32],f=t[33],p=t[34],m=t[35],h=t[36],g=t[37],_=t[38];let v;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(`span`,{className:`ml-2 text-sm font-medium text-fg-muted`,children:`credits`}),t[49]=v):v=t[49];let y;t[50]!==u||t[51]!==d?(y=(0,$.jsxs)(`p`,{className:u,children:[d,v]}),t[50]=u,t[51]=d,t[52]=y):y=t[52];let S;t[53]!==a.balance.credits||t[54]!==n.zeroBalance?(S=a.balance.credits===0?(0,$.jsx)(`p`,{className:`mt-2 text-sm font-medium text-danger`,children:n.zeroBalance}):null,t[53]=a.balance.credits,t[54]=n.zeroBalance,t[55]=S):S=t[55];let C;t[56]===n.recentUsage?C=t[57]:(C=(0,$.jsx)(`p`,{className:`mt-5 text-xs font-medium text-fg-subtle`,children:n.recentUsage}),t[56]=n.recentUsage,t[57]=C);let w;t[58]===_?w=t[59]:(w=(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:_}),t[58]=_,t[59]=w);let T;t[60]!==a.balance.updatedAt||t[61]!==n.updatedAt||t[62]!==r?(T=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]=T):T=t[63];let E;t[64]===T?E=t[65]:(E=(0,$.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:T}),t[64]=T,t[65]=E);let D;t[66]!==y||t[67]!==S||t[68]!==C||t[69]!==w||t[70]!==E||t[71]!==f||t[72]!==p||t[73]!==m?(D=(0,$.jsxs)(`div`,{className:f,children:[p,m,y,S,C,w,E]}),t[66]=y,t[67]=S,t[68]=C,t[69]=w,t[70]=E,t[71]=f,t[72]=p,t[73]=m,t[74]=D):D=t[74];let O;t[75]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,$.jsx)(x,{className:`size-3.5`,"aria-hidden":!0}),t[75]=O):O=t[75];let k;t[76]!==a.links.purchase||t[77]!==n.purchase?(k=(0,$.jsx)(L,{asChild:!0,variant:`primary`,children:(0,$.jsxs)(`a`,{href:a.links.purchase,target:`_blank`,rel:`noreferrer`,children:[n.purchase,O]})}),t[76]=a.links.purchase,t[77]=n.purchase,t[78]=k):k=t[78];let A;t[79]===Symbol.for(`react.memo_cache_sentinel`)?(A=(0,$.jsx)(x,{className:`size-3.5`,"aria-hidden":!0}),t[79]=A):A=t[79];let j;t[80]!==a.links.details||t[81]!==n.details?(j=(0,$.jsx)(L,{asChild:!0,variant:`secondary`,children:(0,$.jsxs)(`a`,{href:a.links.details,target:`_blank`,rel:`noreferrer`,children:[n.details,A]})}),t[80]=a.links.details,t[81]=n.details,t[82]=j):j=t[82];let N;t[83]!==k||t[84]!==j?(N=(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap gap-2`,children:[k,j]}),t[83]=k,t[84]=j,t[85]=N):N=t[85];let P;t[86]!==D||t[87]!==N||t[88]!==h?(P=(0,$.jsxs)(`div`,{className:h,children:[D,N]}),t[86]=D,t[87]=N,t[88]=h,t[89]=P):P=t[89];let F;return t[90]!==P||t[91]!==g?(F=(0,$.jsx)(`section`,{className:g,children:P}),t[90]=P,t[91]=g,t[92]=F):F=t[92],F}function Ur(e){return e.language}function Wr(e){return ge.includes(e)}function Gr(){let e=(0,Z.c)(78),t=M(Jr),n;e[0]===t?n=e[1]:(n=k(t),e[0]=t,e[1]=n);let r=n,l=r.capabilitiesSettings,u=a(),[d,f]=o(),p;if(e[2]!==d){let t=d.get(`returnTo`);p=t?.startsWith(`/chat/`)?t:null,e[2]=d,e[3]=p}else p=e[3];let m=p,{capability:h}=i(),[g,_]=(0,Q.useState)(!1),[v,y]=(0,Q.useState)(null),b=vr(),x;e[4]===b.cards?x=e[5]:(x=b.cards.some(qr),e[4]=b.cards,e[5]=x);let S=x,C,w;e[6]!==h||e[7]!==d||e[8]!==f?(C=()=>{if(h!==`models`||d.get(`add`)!==`1`)return;_(!0);let e=new URLSearchParams(d);e.delete(`add`),f(e,{replace:!0})},w=[h,d,f],e[6]=h,e[7]=d,e[8]=f,e[9]=C,e[10]=w):(C=e[9],w=e[10]),(0,Q.useEffect)(C,w);let T;e[11]!==l.modelsHint||e[12]!==l.tabs.models?(T={id:`models`,icon:st,label:l.tabs.models,hint:l.modelsHint},e[11]=l.modelsHint,e[12]=l.tabs.models,e[13]=T):T=e[13];let E;e[14]!==l.imageHint||e[15]!==l.tabs.image?(E={id:`image`,icon:_e,label:l.tabs.image,hint:l.imageHint},e[14]=l.imageHint,e[15]=l.tabs.image,e[16]=E):E=e[16];let O;e[17]!==l.tabs.voice||e[18]!==l.voiceHint?(O={id:`voice`,icon:mt,label:l.tabs.voice,hint:l.voiceHint},e[17]=l.tabs.voice,e[18]=l.voiceHint,e[19]=O):O=e[19];let A;e[20]!==l.searchHint||e[21]!==l.tabs.search?(A={id:`search`,icon:D,label:l.tabs.search,hint:l.searchHint},e[20]=l.searchHint,e[21]=l.tabs.search,e[22]=A):A=e[22];let j;e[23]!==T||e[24]!==E||e[25]!==O||e[26]!==A?(j=[T,E,O,A],e[23]=T,e[24]=E,e[25]=O,e[26]=A,e[27]=j):j=e[27];let N=j,P;e[28]===u?P=e[29]:(P=e=>u(nt(e)),e[28]=u,e[29]=P);let F=P,I=Kr;if(!Wr(h)){let t;return e[30]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(s,{to:nt(`models`),replace:!0}),e[30]=t):t=e[30],t}let R=r.nav.settingsCapabilities,ee=l.subtitle,z;e[31]===t?z=e[32]:(z=xe(t,`configuration`),e[31]=t,e[32]=z);let B;e[33]===Symbol.for(`react.memo_cache_sentinel`)?(B=(0,$.jsx)(Pe,{className:`size-4`,"aria-hidden":!0}),e[33]=B):B=e[33];let V;e[34]===l.agentSettingsLink?V=e[35]:(V=(0,$.jsx)(L,{asChild:!0,variant:`secondary`,children:(0,$.jsxs)(c,{to:`/agents`,children:[B,l.agentSettingsLink]})}),e[34]=l.agentSettingsLink,e[35]=V);let H;e[36]!==l.docsLink||e[37]!==l.subtitle||e[38]!==r.nav.settingsCapabilities||e[39]!==z||e[40]!==V?(H=(0,$.jsx)(gt,{title:R,subtitle:ee,docsLink:z,docsLabel:l.docsLink,actions:V}),e[36]=l.docsLink,e[37]=l.subtitle,e[38]=r.nav.settingsCapabilities,e[39]=z,e[40]=V,e[41]=H):H=e[41];let U;e[42]!==h||e[43]!==m||e[44]!==t?(U=h===`voice`&&m?(0,$.jsx)(c,{to:m,className:`text-sm text-accent-fg hover:underline`,children:t===`zh`?`返回对话`:`Return to conversation`}):null,e[42]=h,e[43]=m,e[44]=t,e[45]=U):U=e[45];let W;e[46]!==l.tabsAria||e[47]!==h||e[48]!==N||e[49]!==F?(W=(0,$.jsx)(Bt,{items:N,activeTab:h,onChange:F,ariaLabel:l.tabsAria,tabIdPrefix:`capability-tab`,panelIdPrefix:`capability-panel`}),e[46]=l.tabsAria,e[47]=h,e[48]=N,e[49]=F,e[50]=W):W=e[50];let G;e[51]!==l.connectedProviders||e[52]!==l.xopcCloudAccount||e[53]!==h||e[54]!==b||e[55]!==N||e[56]!==S?(G=N.map(e=>(0,$.jsx)(Xr,{id:e.id,activeSection:h,hint:e.hint,children:e.id===`models`?(0,$.jsxs)($.Fragment,{children:[S?(0,$.jsx)(Hr,{labels:l.xopcCloudAccount}):null,(0,$.jsx)(Br,{}),(0,$.jsx)(wr,{labels:l.connectedProviders,data:b,onAdd:()=>_(!0),onManage:(e,t)=>y({providerId:e,isCustom:t})})]}):(0,$.jsx)(Yr,{section:e.id})},e.id)),e[51]=l.connectedProviders,e[52]=l.xopcCloudAccount,e[53]=h,e[54]=b,e[55]=N,e[56]=S,e[57]=G):G=e[57];let K;e[58]!==g||e[59]!==l.addProviderDialog||e[60]!==t||e[61]!==b.builtinRows||e[62]!==b.customConfig?(K=(0,$.jsx)(cr,{open:g,onOpenChange:_,builtinRows:b.builtinRows,customConfig:b.customConfig,labels:l.addProviderDialog,language:t,onSaved:I}),e[58]=g,e[59]=l.addProviderDialog,e[60]=t,e[61]=b.builtinRows,e[62]=b.customConfig,e[63]=K):K=e[63];let te;e[64]!==l.manageProviderDialog||e[65]!==t||e[66]!==v||e[67]!==b.allModels||e[68]!==b.builtinRows||e[69]!==b.customConfig?(te=v?(0,$.jsx)(Pr,{open:!0,onOpenChange:e=>{e||y(null)},providerId:v.providerId,isCustom:v.isCustom,builtinRows:b.builtinRows,customConfig:b.customConfig,allModels:b.allModels,labels:l.manageProviderDialog,language:t,onSaved:I}):null,e[64]=l.manageProviderDialog,e[65]=t,e[66]=v,e[67]=b.allModels,e[68]=b.builtinRows,e[69]=b.customConfig,e[70]=te):te=e[70];let q;return e[71]!==H||e[72]!==U||e[73]!==W||e[74]!==G||e[75]!==K||e[76]!==te?(q=(0,$.jsxs)(_t,{children:[H,U,W,G,K,te]}),e[71]=H,e[72]=U,e[73]=W,e[74]=G,e[75]=K,e[76]=te,e[77]=q):q=e[77],q}function Kr(){J()}function qr(e){return e.id===`xopc-cloud`&&!e.isCustom}function Jr(e){return e.language}function Yr(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)(un,{}),t[0]=e):e=t[0],e}case`voice`:{let e;return t[1]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Fn,{}),t[1]=e):e=t[1],e}case`search`:{let e;return t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(nr,{}),t[2]=e):e=t[2],e}}}function Xr({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:F(`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&&e!==`voice`?(0,$.jsx)(`p`,{className:`text-sm leading-relaxed text-fg-muted`,children:n}):null,e===`voice`&&!i?null:r]}):null}export{Gr as CapabilitiesSettingsPanel};
|
|
4
|
+
`)),q(t?.models.map(Xt)??[Xt()]),J(t?.defaultModel??``),ce(void 0),X(void 0),ie(!1),oe(void 0),ue(void 0)},[r,e,n]);let de=(0,Q.useMemo)(()=>G.filter(e=>e.id.trim()).map(e=>({value:e.id.trim(),label:e.name.trim()||e.id.trim()})),[G]),fe=(e,t)=>{q(n=>n.map((n,r)=>r===e?{...n,...t}:n))},pe=()=>{let e=s.trim(),t=G.map(e=>({...e,id:e.id.trim(),name:e.name.trim()}));if(!e||!g.trim()||!y.trim()||t.some(e=>!e.id))throw Error(o.required);if(new Set(t.map(e=>e.id)).size!==t.length)throw Error(o.duplicateModels);let n=ne||t[0]?.id;if(!n||!t.some(e=>e.id===n))throw Error(o.required);let r;try{r=Zt(H)}catch{throw Error(o.invalidHeaders)}return{providerId:e,input:{baseUrl:y.trim(),...r?{headers:r}:{},imageGeneration:{api:`openai-images`,name:g.trim(),...N.trim()?{documentationUrl:N.trim()}:{},...j.trim()?{apiKeyUrl:j.trim()}:{},defaultModel:n,auth:x===`header`?{type:`header`,headerName:T.trim()}:{type:x},paths:{...I.trim()?{generations:I.trim()}:{},...ee.trim()?{edits:ee.trim()}:{}},...B.trim()?{network:{allowedHosts:B.split(`
|
|
5
|
+
`).map(e=>e.trim()).filter(Boolean)}}:{},models:t.map(e=>({...e.original,id:e.id,...e.name?{name:e.name}:{name:void 0},capabilities:{...e.original.capabilities,generate:{...e.original.capabilities.generate,maxCount:Math.max(1,Number.parseInt(e.maxCount,10)||1),supportsSize:e.supportsSize},edit:{...e.original.capabilities.edit,enabled:e.editEnabled}},defaults:{...e.original.defaults,...e.defaultCount?{count:Math.max(1,Number.parseInt(e.defaultCount,10)||1)}:{count:void 0},...e.defaultSize.trim()?{size:e.defaultSize.trim()}:{size:void 0},...e.outputFormat?{outputFormat:e.outputFormat}:{outputFormat:void 0}}}))}}}},me=async()=>{let e=pe();return await Ut(e.providerId,e.input),x!==`none`&&k.trim()&&!W(k)&&await Ht(e.providerId,k.trim()),await a(e.providerId),e},he=async()=>{X(`save`),oe(void 0),ce(void 0);try{await me(),A(x===`none`?``:`••••••••••••`),ce(o.saved)}catch(e){oe(e instanceof Error?e.message:String(e))}finally{X(void 0)}},ge=async()=>{X(`test`),oe(void 0),ce(void 0),ue(void 0);try{let e=await me();ue((await Gt(e.providerId,e.input.imageGeneration.defaultModel)).images[0]?.dataUrl),ce(o.testReady)}catch(e){oe(e instanceof Error?e.message:String(e))}finally{X(void 0)}},_e=async()=>{if(n){if(!re){ie(!0);return}X(`delete`),oe(void 0);try{await qt(n.providerId),await a(),t(!1)}catch(e){oe(e instanceof Error?e.message:String(e))}finally{X(void 0)}}};return(0,$.jsx)(h,{open:e,onOpenChange:t,children:(0,$.jsxs)(f,{children:[(0,$.jsx)(l,{className:F(`xopc-dialog-overlay fixed inset-0 bg-scrim`,te)}),(0,$.jsxs)(p,{className:F(`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`,K),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)(m,{className:`font-semibold text-fg`,children:n?o.editTitle:o.addTitle}),(0,$.jsx)(u,{className:`mt-1 text-sm text-fg-muted`,children:o.intro})]}),(0,$.jsx)(d,{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)(O,{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:Yt}),(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:g,onChange:e=>_(e.target.value),placeholder:`My Image Service`,className:Yt})]})]}),(0,$.jsxs)(`label`,{className:`block text-xs font-medium text-fg-muted`,children:[o.baseUrl,(0,$.jsx)(`input`,{value:y,onChange:e=>b(e.target.value),placeholder:`https://api.example.com/v1`,className:Yt})]}),(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)(v,{value:x,options:[{value:`bearer`,label:o.bearer},{value:`header`,label:o.header},{value:`none`,label:o.none}],placeholder:o.auth,allowEmpty:!1,onChange:e=>C(e),triggerClassName:`mt-1.5`})]}),x===`header`?(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.headerName,(0,$.jsx)(`input`,{value:T,onChange:e=>D(e.target.value),className:Yt})]}):null]}),x===`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}),j.trim()?(0,$.jsxs)(`a`,{href:j.trim(),target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent hover:underline`,children:[o.openKeyPage,(0,$.jsx)(ze,{className:`size-3.5`})]}):null]}),(0,$.jsx)(Xe,{id:`custom-image-api-key`,value:k,onChange:e=>A(W(k)?e.replace(/^•+/,``):e),labels:{show:o.show,hide:o.hide,copy:o.copy,copied:o.copied},reveal:()=>ht(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:j,onChange:e=>M(e.target.value),placeholder:`https://…`,className:Yt})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.docsUrl,(0,$.jsx)(`input`,{value:N,onChange:e=>P(e.target.value),placeholder:`https://…`,className:Yt})]})]}),(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:I,onChange:e=>R(e.target.value),className:Yt})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.editsPath,(0,$.jsx)(`input`,{value:ee,onChange:e=>z(e.target.value),className:Yt})]})]}),(0,$.jsxs)(`label`,{className:`mt-4 block text-xs font-medium text-fg-muted`,children:[o.allowedHosts,(0,$.jsx)(`textarea`,{value:B,onChange:e=>V(e.target.value),rows:2,placeholder:`127.0.0.1
|
|
6
|
+
image-server.lan`,className:`mt-1.5 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 font-mono text-xs text-fg outline-none focus:border-accent focus:ring-2 focus:ring-accent/20`}),(0,$.jsx)(`span`,{className:`mt-1 block font-normal text-fg-subtle`,children:o.allowedHostsHint})]}),(0,$.jsxs)(`label`,{className:`mt-4 block text-xs font-medium text-fg-muted`,children:[o.staticHeaders,(0,$.jsx)(`textarea`,{value:H,onChange:e=>U(e.target.value),rows:3,className:`mt-1.5 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 font-mono text-xs text-fg outline-none focus:border-accent focus:ring-2 focus:ring-accent/20`}),(0,$.jsx)(`span`,{className:`mt-1 block font-normal text-fg-subtle`,children:o.staticHeadersHint})]})]})]}),(0,$.jsxs)(`section`,{className:`space-y-3`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wide text-fg-subtle`,children:o.models}),(0,$.jsxs)(L,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,onClick:()=>q(e=>[...e,Xt()]),children:[(0,$.jsx)(E,{className:`size-4`}),o.addModel]})]}),(0,$.jsxs)(`label`,{className:`block text-xs font-medium text-fg-muted`,children:[o.defaultModel,(0,$.jsx)(v,{value:ne||de[0]?.value||``,options:de,placeholder:o.defaultModel,allowEmpty:!1,onChange:J,triggerClassName:`mt-1.5 max-w-sm`})]}),G.map((e,t)=>(0,$.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface-base p-3`,children:[(0,$.jsxs)(`div`,{className:`grid gap-3 md:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.modelId,(0,$.jsx)(`input`,{value:e.id,onChange:e=>fe(t,{id:e.target.value}),placeholder:`image-1`,className:Yt})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.modelName,(0,$.jsx)(`input`,{value:e.name,onChange:e=>fe(t,{name:e.target.value}),className:Yt})]})]}),(0,$.jsxs)(`div`,{className:`mt-3 grid gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.maxCount,(0,$.jsx)(`input`,{type:`number`,min:1,value:e.maxCount,onChange:e=>fe(t,{maxCount:e.target.value}),className:Yt})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.defaultCount,(0,$.jsx)(`input`,{type:`number`,min:1,value:e.defaultCount,onChange:e=>fe(t,{defaultCount:e.target.value}),className:Yt})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.defaultSize,(0,$.jsx)(`input`,{value:e.defaultSize,onChange:e=>fe(t,{defaultSize:e.target.value}),placeholder:`1024x1024`,className:Yt})]}),(0,$.jsxs)(`label`,{className:`text-xs font-medium text-fg-muted`,children:[o.format,(0,$.jsx)(v,{value:e.outputFormat,options:[{value:`png`,label:`PNG`},{value:`jpeg`,label:`JPEG`},{value:`webp`,label:`WebP`}],placeholder:o.format,allowEmpty:!0,onChange:e=>fe(t,{outputFormat:e}),triggerClassName:`mt-1.5`})]})]}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-4`,children:[(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:e.supportsSize,onChange:e=>fe(t,{supportsSize:e.target.checked})}),o.supportsSize]}),(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,$.jsx)(`input`,{type:`checkbox`,checked:e.editEnabled,onChange:e=>fe(t,{editEnabled:e.target.checked})}),o.edit]}),(0,$.jsxs)(`button`,{type:`button`,disabled:G.length===1,onClick:()=>q(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)(ve,{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)(S,{className:`size-4`}),o.testReady]}),(0,$.jsx)(`img`,{src:le,alt:`Generated provider test`,className:`max-h-72 rounded-lg object-contain`})]}):null,se?(0,$.jsx)(`p`,{className:`rounded-lg bg-emerald-500/10 px-3 py-2 text-sm text-emerald-700 dark:text-emerald-300`,role:`status`,children:se}):null,ae?(0,$.jsx)(`p`,{className:`rounded-lg bg-red-500/10 px-3 py-2 text-sm text-red-600 dark:text-red-400`,children:ae}):null]}),(0,$.jsxs)(`footer`,{className:`flex shrink-0 flex-wrap items-center gap-2 border-t border-edge px-5 py-3`,children:[n?(0,$.jsxs)(L,{variant:`secondary`,className:`border-red-500/30 text-red-600 hover:bg-red-500/10 dark:text-red-400`,disabled:!!Y,onClick:()=>void _e(),children:[Y===`delete`?(0,$.jsx)(w,{className:`size-4 animate-spin`}):(0,$.jsx)(ve,{className:`size-4`}),re?o.confirmDelete:o.delete]}):null,(0,$.jsxs)(`div`,{className:`ml-auto flex gap-2`,children:[(0,$.jsx)(d,{asChild:!0,children:(0,$.jsx)(L,{variant:`secondary`,children:o.cancel})}),(0,$.jsxs)(L,{variant:`secondary`,disabled:!!Y,onClick:()=>void ge(),children:[Y===`test`?(0,$.jsx)(w,{className:`size-4 animate-spin`}):null,Y===`test`?o.testing:o.test]}),(0,$.jsxs)(L,{variant:`primary`,disabled:!!Y,onClick:()=>void he(),children:[Y===`save`?(0,$.jsx)(w,{className:`size-4 animate-spin`}):null,Y===`save`?o.saving:o.save]})]})]})]})]})})}var $t=`••••••••••••`,en={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 tn(e){let t=await A(N(`/api/agents/${encodeURIComponent(e)}/image-generation`));if(!t.payload)throw Error(`Invalid agent image generation response`);return t.payload}function nn(e){let t=e?.indexOf(`/`)??-1;return t>0?e.slice(0,t):void 0}function rn(e){let t=e?.indexOf(`/`)??-1;return t>0?e.slice(t+1):void 0}function an(e){return Object.fromEntries(e.configFields.map(t=>[t.key,e.config[t.key]??(t.required?t.options?.[0]?.value??``:``)]))}function on(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)(v,{value:r,options:(n.options??[]).map(sn),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 sn(e){return{value:e.value,label:e.label}}function cn(){let e=(0,Z.c)(2),t;e[0]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(G,{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(ln)}),(0,$.jsx)(G,{className:`h-64 rounded-xl`})]}),e[1]=n):n=e[1],n}function ln(e,t){return(0,$.jsx)(G,{className:`h-24 rounded-xl`},t)}function un(){let e=M(e=>e.language),t=en[e],n=k(e),r=!!P(e=>e.token),[i,a]=(0,Q.useState)(``),[o,s]=(0,Q.useState)(``),[c,l]=(0,Q.useState)(``),[u,d]=(0,Q.useState)(``),[f,p]=(0,Q.useState)({}),[m,h]=(0,Q.useState)(!1),[g,_]=(0,Q.useState)(),[b,x]=(0,Q.useState)(!1),[S,C]=(0,Q.useState)(!1),[T,D]=(0,Q.useState)(),{data:O,isLoading:j,error:F}=I(r?`image-generation-agents`:null,rt,{revalidateOnFocus:!1}),{data:R,isLoading:ee,error:z,mutate:B}=I(r?N(`/api/image-generation/catalog`):null,Kt,{revalidateOnFocus:!1}),{data:V,isLoading:H,error:U,mutate:G}=I(r?N(`/api/image-generation/custom-providers`):null,Wt,{revalidateOnFocus:!1});(0,Q.useEffect)(()=>{!O||i||a(O.defaultId||O.agents[0]?.id||``)},[i,O]);let{data:K,isLoading:te,error:q,mutate:ne}=I(r&&i?[`agent-image-generation`,i]:null,()=>tn(i),{revalidateOnFocus:!1});(0,Q.useEffect)(()=>{if(!R||!K)return;let e=nn(K.model?.primary),t=R.find(t=>t.id===e)??R.find(e=>e.configured)??R[0];t&&(s(t.id),l(t.id===e&&rn(K.model?.primary)||t.defaultModel),d(t.configured?$t:``),p(an(t)))},[K,R]),(0,Q.useEffect)(()=>{_(void 0)},[i]);let J=R?.find(e=>e.id===o),Y=J?J.apiKeyUrl??Te(J.id,e)[0]?.href:void 0,X=(0,Q.useMemo)(()=>(O?.agents??[]).map(e=>({value:e.id,label:we(e,n.agentsSettings)})),[O?.agents,n.agentsSettings]),re=(0,Q.useMemo)(()=>(J?.models??[]).map(e=>({value:e,label:e})),[J?.models]),ie=K?.model?.primary,ae=!!(i&&J&&c&&(J.credentialMode!==`api-key`||J.configured||u.trim())&&J.configFields.every(e=>!e.required||f[e.key]?.trim()));if(!r)return(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.connect});if(j||ee||H||te)return(0,$.jsx)(cn,{});if(F||z||U||q||!R||!O||!V)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),d(e.configured?$t:``),p(an(e)),_(void 0)},se=()=>{D(void 0),C(!0)},ce=()=>{let e=V.find(e=>e.providerId===J?.id);e&&(D(e),C(!0))},le=async e=>{let[t,n]=await Promise.all([G(),B()]);if(e&&n?.some(t=>t.id===e)){let r=n.find(t=>t.id===e);s(r.id),l(r.defaultModel),d(r.configured?$t:``),p(an(r)),D(t?.find(t=>t.providerId===e))}},ue=async()=>{if(!(!J||!ae)){h(!0),_(void 0),x(!1);try{let e=await A(N(`/api/agents/${encodeURIComponent(i)}/image-generation/setup`),{method:`POST`,body:JSON.stringify({providerId:J.id,modelId:c,...u.trim()&&!W(u)?{apiKey:u.trim()}:{},providerConfig:Object.fromEntries(Object.entries(f).filter(([,e])=>e.trim()))})});if(!e.payload)throw Error(`Invalid setup response`);await Promise.all([ne(e.payload.agent,{revalidate:!1}),B(e.payload.providers,{revalidate:!1})]),d($t),x(!0)}catch(e){_(e instanceof Error?e.message:String(e))}finally{h(!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)(nt,{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)(v,{value:i,options:X,placeholder:t.selectAgent,allowEmpty:!1,onChange:a,triggerClassName:`mt-1.5 max-w-md`})]})]}),(0,$.jsxs)(`section`,{children:[(0,$.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-3`,children:[(0,$.jsx)(`h3`,{className:`text-xs font-semibold uppercase tracking-wide text-fg-subtle`,children:t.provider}),(0,$.jsxs)(L,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,onClick:se,children:[(0,$.jsx)(E,{className:`size-4`}),t.addService]})]}),(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2 xl:grid-cols-3`,children:R.map(e=>{let n=e.id===o,r=e.id===nn(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)(y,{className:`size-3.5`}):(0,$.jsx)(Se,{className:`size-3.5`}),e.configured||e.credentialMode!==`api-key`?t.configured:t.needsKey]})]},e.id)})})]}),J?(0,$.jsxs)(`section`,{className:`rounded-xl border border-edge bg-surface-base p-4`,children:[(0,$.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,$.jsxs)(`label`,{className:`block text-xs font-medium text-fg-muted`,children:[t.model,(0,$.jsx)(v,{value:c,options:re,placeholder:t.selectModel,allowEmpty:!1,onChange:l,triggerClassName:`mt-1.5`})]}),J.configFields.filter(e=>e.required).map(e=>(0,$.jsx)(on,{field:e,value:f[e.key]??``,onChange:t=>p(n=>({...n,[e.key]:t}))},e.key))]}),J.source===`custom`?(0,$.jsx)(`div`,{className:`mt-4 flex justify-end`,children:(0,$.jsxs)(L,{variant:`secondary`,onClick:ce,children:[(0,$.jsx)(Ae,{className:`size-4`}),t.manageService]})}):null,J.credentialMode===`api-key`?(0,$.jsxs)(`div`,{className:`mt-4`,children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,$.jsx)(`label`,{htmlFor:`image-generation-api-key`,className:`text-xs font-medium text-fg-muted`,children:t.apiKey}),Y?(0,$.jsxs)(`a`,{href:Y,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs font-medium text-accent hover:underline`,children:[t.getApiKey,(0,$.jsx)(ze,{className:`size-3.5`,"aria-hidden":`true`})]}):null]}),(0,$.jsx)(Xe,{id:`image-generation-api-key`,value:u,onChange:e=>d(W(u)?e.replace(/^•+/,``):e),placeholder:J.configured?t.existingKey:t.needsKey,labels:{show:t.show,hide:t.hide,copy:t.copy,copied:t.copied},reveal:()=>ht(J.id).then(e=>e.apiKey),loadFailedLabel:t.revealFailed,notInConfigFile:t.keyNotRevealable,className:`mt-1.5`,autoComplete:`new-password`},J.id),(0,$.jsx)(`span`,{className:`mt-1.5 block font-normal leading-relaxed text-fg-subtle`,children:J.configured?t.savedKey:t.apiKeyHint})]}):null,J.configFields.some(e=>!e.required)?(0,$.jsxs)(`details`,{className:`mt-4 rounded-lg border border-edge bg-surface-subtle px-3 py-2.5`,children:[(0,$.jsxs)(`summary`,{className:`flex cursor-pointer list-none items-center gap-2 text-sm font-medium text-fg-muted`,children:[(0,$.jsx)(Ce,{className:`size-4`}),t.advanced]}),(0,$.jsx)(`div`,{className:`mt-3 grid gap-3 md:grid-cols-2`,children:J.configFields.filter(e=>!e.required).map(e=>(0,$.jsx)(on,{field:e,value:f[e.key]??``,onChange:t=>p(n=>({...n,[e.key]:t}))},e.key))})]}):null,b?(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,g?(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:g}):null,(0,$.jsx)(`div`,{className:`mt-4 flex justify-end`,children:(0,$.jsxs)(L,{variant:`primary`,disabled:!ae||m,onClick:()=>void ue(),children:[m?(0,$.jsx)(w,{className:`size-4 animate-spin`}):(0,$.jsx)(y,{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:m?t.enabling:t.enable})]})]})})]}):null,(0,$.jsx)(Qt,{open:S,onOpenChange:C,provider:T,configured:!!(T&&R.find(e=>e.id===T.providerId)?.configured),language:e,onSaved:le})]})}function dn({v:e}){let t=Be(e=>e.microphoneId),n=Be(e=>e.setMicrophoneId),[r,i]=(0,Q.useState)([]),[a,o]=(0,Q.useState)(``),[s,c]=(0,Q.useState)(!1),l=(0,Q.useRef)(!1);(0,Q.useEffect)(()=>{l.current=!0;let e=()=>{navigator.mediaDevices?.enumerateDevices().then(e=>{l.current&&i(e.filter(e=>e.kind===`audioinput`))}).catch(()=>{})};return e(),navigator.mediaDevices?.addEventListener(`devicechange`,e),()=>{l.current=!1,navigator.mediaDevices?.removeEventListener(`devicechange`,e)}},[]);let u=async()=>{c(!0),o(``);try{(await navigator.mediaDevices.getUserMedia({audio:!0})).getTracks().forEach(e=>e.stop());let e=await navigator.mediaDevices.enumerateDevices();l.current&&i(e.filter(e=>e.kind===`audioinput`))}catch(e){l.current&&o(e instanceof Error?e.message:String(e))}finally{l.current&&c(!1)}};return(0,$.jsxs)(`section`,{className:`space-y-4 rounded-xl border border-edge p-4`,children:[(0,$.jsxs)(`label`,{className:`block space-y-2 text-sm`,children:[(0,$.jsx)(`span`,{children:e.experience.microphone}),(0,$.jsxs)(g,{value:t,onChange:e=>n(e.target.value),children:[(0,$.jsx)(_,{value:``,children:e.experience.systemDevice}),t&&!r.some(e=>e.deviceId===t)?(0,$.jsx)(_,{value:t,children:e.experience.unavailable}):null,r.filter(e=>e.deviceId&&e.deviceId!=="default").map((t,n)=>(0,$.jsx)(_,{value:t.deviceId,children:t.label||`${e.experience.microphone} ${n+1}`},t.deviceId))]})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.experience.deviceHint}),(0,$.jsx)(L,{variant:`secondary`,disabled:s,onClick:()=>void u(),children:e.experience.refreshDevices}),a?(0,$.jsx)(`p`,{role:`alert`,className:`text-sm text-red-600`,children:a}):null]})}function fn({v:e,canListen:t,canSpeak:n,disabled:r,onVerified:i}){let a=e.setup,o=(0,Q.useContext)(Me)?.active??!1,[s,c]=(0,Q.useState)(`idle`),[l,u]=(0,Q.useState)(``),[d,f]=(0,Q.useState)(``),p=(0,Q.useRef)(`idle`),m=(0,Q.useRef)(null),h=(0,Q.useRef)(!1),g=e=>{p.current=e,c(e)},_=()=>{m.current?.(),m.current=null};(0,Q.useEffect)(()=>()=>m.current?.(),[]);async function v(e){_(),i?.({input:!1,output:!1}),h.current=!1,u(``),f(``),g(e?`connecting`:`playing`);let t=new AbortController,r,o,s,c,l=()=>{o?.cancel(),r?.getTracks().forEach(e=>e.stop()),s?.stop(`surface_closed`)},d=window.setTimeout(()=>v(a.timeout),6e4);m.current=()=>{t.abort(),window.clearTimeout(d),l(),c?.close()};function v(e){t.signal.aborted||(g(`error`),f(e),_())}async function y(){g(`playing`),l();try{let e=await kt(t.signal);if(t.signal.aborted)return;c?.enqueue(e,()=>{t.signal.aborted||(window.clearTimeout(d),g(`confirm`))})}catch(e){v(e instanceof Error?e.message:a.testFailed)}}try{if(n&&(c=new qe,await c.start(),t.signal.throwIfAborted()),!e){await y();return}let d=window.electronAPI?.system;if(d){let e=await d.requestMicrophone();if(t.signal.throwIfAborted(),e.status===`denied`)throw Error(a.microphoneDenied)}if(r=await navigator.mediaDevices.getUserMedia({audio:$e()}),t.signal.aborted){l();return}if(s=await ut.connect({purpose:`dictation`,signal:t.signal,onEvent:e=>{t.signal.aborted||(e.type===`session.error`&&v(a.testFailed),p.current===`listening`&&(e.type===`input.transcript.delta`&&u(e.payload.text),e.type===`input.transcript.final`&&e.payload.text.trim()&&(u(e.payload.text.trim()),h.current=!0,n?y():(g(`passed`),i?.({input:!0,output:!1}),_()))))},onClose:()=>{(p.current===`listening`||p.current===`connecting`)&&v(a.testFailed)}}),t.signal.aborted){l();return}let f;if(o=await at.start(r,{onSamples:e=>{f&&!t.signal.aborted&&s?.sendAudio(f.push(e))}}),t.signal.aborted){l();return}f=new Pe(o.sampleRate,s.session.inputFormat.sampleRate),g(`listening`)}catch(e){if(t.signal.aborted){l();return}v(e instanceof Error?e.message:a.testFailed)}}let y=s===`connecting`||s===`listening`||s===`playing`;return(0,$.jsxs)(`div`,{className:`space-y-3 border-t border-edge pt-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsxs)(L,{type:`button`,variant:`primary`,disabled:o||r||!t||y,onClick:()=>void v(!0),children:[y?(0,$.jsx)(w,{className:`size-4 animate-spin`}):(0,$.jsx)(fe,{className:`size-4`}),n?a.test:a.testInput]}),(0,$.jsxs)(L,{type:`button`,variant:`secondary`,disabled:o||r||!n||y,onClick:()=>void v(!1),children:[(0,$.jsx)(lt,{className:`size-4`}),e.tts.test.play]}),y?(0,$.jsxs)(L,{type:`button`,variant:`ghost`,onClick:()=>{_(),g(`idle`)},children:[(0,$.jsx)(xe,{className:`size-4`}),e.tts.test.stop]}):null]}),(0,$.jsxs)(`div`,{role:`status`,"aria-live":`polite`,className:`space-y-2 text-xs text-fg-muted`,children:[s===`idle`?(0,$.jsx)(`p`,{children:o?e.experience.endCallBeforeTest:r?a.saveBeforeTest:a.microphoneHint}):null,s===`connecting`?(0,$.jsx)(`p`,{children:a.connecting}):null,s===`listening`?(0,$.jsx)(`p`,{children:a.speakNow}):null,l?(0,$.jsx)(`p`,{className:`rounded-lg bg-surface-base p-3 text-sm text-fg`,children:l}):null,s===`playing`?(0,$.jsx)(`p`,{children:a.playing}):null,s===`confirm`?(0,$.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,$.jsx)(`span`,{children:a.heardQuestion}),(0,$.jsx)(L,{type:`button`,variant:`secondary`,onClick:()=>{_(),i?.({input:h.current,output:!0}),g(`passed`)},children:a.heard}),(0,$.jsx)(L,{type:`button`,variant:`ghost`,onClick:()=>{_(),g(`error`),f(a.notHeard)},children:a.notHeardButton})]}):null,s===`passed`?(0,$.jsx)(`p`,{children:h.current?n?a.passed:a.inputPassed:a.outputPassed}):null,s===`error`?(0,$.jsx)(`p`,{role:`alert`,className:`text-red-600 dark:text-red-400`,children:d}):null]})]})}function pn(e,t){return{...e,stt:{...e.stt,enabled:!0,provider:t},voice:{...e.voice,realtime:{...e.voice.realtime,enabled:!0,tts:e.voice.realtime.tts?.provider===t?e.voice.realtime.tts:{provider:t,...t===`alibaba`?{voice:`Cherry`}:{}},omni:e.voice.realtime.omni?.provider===t?e.voice.realtime.omni:{provider:t,model:`qwen3-omni-flash-realtime`,voice:e.voice.realtime.omni?.voice??`Cherry`,instructions:e.voice.realtime.omni?.instructions??`Keep replies conversational and concise.`}}}}}function mn(e){let t=(0,Z.c)(112),{section:n,v:r,form:i,pending:a,apiKeyLabels:o,sttProviders:s,onChange:l}=e,u=r.setup,[d,f]=(0,Q.useState)(!1),p;t[0]===i?p=t[1]:(p=JSON.stringify(i),t[0]=i,t[1]=p);let m=p,h;t[2]===m?h=t[3]:(h={signature:m,input:!1,output:!1},t[2]=m,t[3]=h);let[v,y]=(0,Q.useState)(h);v.signature!==m&&y({signature:m,input:!1,output:!1});let b;t[4]!==a||t[5]!==m?(b=a?null:[`voice-realtime-status`,m],t[4]=a,t[5]=m,t[6]=b):b=t[6];let x;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(x={revalidateOnFocus:!0},t[7]=x):x=t[7];let{data:S,error:C,isLoading:w}=I(b,It,x),T=i.voice.realtime,E=i.stt.provider,D=T.tts,O=D?.provider??S?.tts?.provider,k=S?.tts?.model,A;t[8]!==k||t[9]!==O?(A=O&&k?[`realtime-voices`,O,k]:null,t[8]=k,t[9]=O,t[10]=A):A=t[10];let j;t[11]!==k||t[12]!==O?(j=()=>jt(O,k,`realtime`),t[11]=k,t[12]=O,t[13]=j):j=t[13];let M;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(M={revalidateOnFocus:!1},t[14]=M):M=t[14];let{data:N}=I(A,j,M),P;t[15]===N?P=t[16]:(P=N===void 0?[]:N,t[15]=N,t[16]=P);let F=P,R;t[17]!==O||t[18]!==F?(R=O===`alibaba`?F.filter(vn):F,t[17]=O,t[18]=F,t[19]=R):R=t[19];let ee=R,z=typeof i.stt.providers?.alibaba?.apiKey==`string`?i.stt.providers.alibaba.apiKey:``,B;t[20]!==z||t[21]!==s?(B=!!z||s.some(_n),t[20]=z,t[21]=s,t[22]=B):B=t[22];let V=B,U=T.defaultEngine===`omni`,W=U?T.omni?.voice??`Cherry`:D?.voice??S?.tts?.voice??``,K;t[23]!==U||t[24]!==ee?(K=U?[`Cherry`,`Ethan`,`Serena`,`Chelsie`].map(gn):ee,t[23]=U,t[24]=ee,t[25]=K):K=t[25];let te=K,q=!!(S?.enabled&&S.stt),ne=!!(S?.enabled&&S.tts),J;t[26]!==i||t[27]!==l||t[28]!==T?(J=e=>l({...i,voice:{...i.voice,realtime:{...T,...e}}}),t[26]=i,t[27]=l,t[28]=T,t[29]=J):J=t[29];let Y=J,X;t[30]!==i||t[31]!==l?(X=e=>l(pn(i,e)),t[30]=i,t[31]=l,t[32]=X):X=t[32];let re=X,ie;t[33]!==a||t[34]!==T.enabled||t[35]!==u.disabled||t[36]!==u.needsSetup||t[37]!==u.pending||t[38]!==u.unverified||t[39]!==u.verified||t[40]!==m||t[41]!==v.signature?(ie=(e,t)=>T.enabled?a?u.pending:e?t&&v.signature===m?u.verified:u.unverified:u.needsSetup:u.disabled,t[33]=a,t[34]=T.enabled,t[35]=u.disabled,t[36]=u.needsSetup,t[37]=u.pending,t[38]=u.unverified,t[39]=u.verified,t[40]=m,t[41]=v.signature,t[42]=ie):ie=t[42];let ae=ie,oe;t[43]!==o||t[44]!==re||t[45]!==d||t[46]!==C||t[47]!==i||t[48]!==z||t[49]!==V||t[50]!==l||t[51]!==a||t[52]!==E||t[53]!==T.defaultEngine||t[54]!==T.enabled||t[55]!==u.changeKey||t[56]!==u.configureConversation||t[57]!==u.customProvider||t[58]!==u.edgeHint||t[59]!==u.enable||t[60]!==u.finishSetup||t[61]!==u.hosted||t[62]!==u.hostedAccountHint||t[63]!==u.hostedHint||t[64]!==u.keyConfigured||t[65]!==u.keyHint||t[66]!==u.manageAccount||t[67]!==u.outputHint||t[68]!==u.ownKey||t[69]!==u.ownKeyHint||t[70]!==u.service||t[71]!==u.statusError||t[72]!==n||t[73]!==D||t[74]!==S?.tts||t[75]!==Y||t[76]!==r.experience||t[77]!==r.stt?(oe=n===`service`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`div`,{className:`flex flex-wrap items-center justify-between gap-3 border-b border-edge pb-4`,children:(0,$.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-fg-muted`,children:[(0,$.jsx)(`input`,{type:`checkbox`,role:`switch`,"aria-checked":T.enabled,className:`size-4 accent-accent`,checked:T.enabled,onChange:e=>{e.target.checked?re(E===`alibaba`?`alibaba`:`xopc-cloud`):Y({enabled:!1})}}),u.enable]})}),C?(0,$.jsx)(`p`,{role:`alert`,className:`text-xs text-red-600 dark:text-red-400`,children:u.statusError}):null,(0,$.jsxs)(`fieldset`,{className:`space-y-3`,children:[(0,$.jsx)(`legend`,{className:`text-sm font-medium text-fg`,children:u.service}),(0,$.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[`xopc-cloud`,`alibaba`].map(e=>(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-3 rounded-lg border border-edge px-3 py-3 text-sm text-fg has-checked:border-accent/60`,children:[(0,$.jsx)(`input`,{type:`radio`,name:`realtime-service`,value:e,checked:E===e,onChange:()=>re(e),className:`mt-1 accent-accent`}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`block font-medium`,children:e===`xopc-cloud`?u.hosted:u.ownKey}),(0,$.jsx)(`span`,{className:`mt-1 block text-xs text-fg-muted`,children:e===`xopc-cloud`?u.hostedHint:u.ownKeyHint})]})]},e))})]}),E!==`alibaba`&&E!==`xopc-cloud`?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:u.customProvider.replace(`{provider}`,E)}):null,E===`alibaba`?(0,$.jsx)(`div`,{className:`space-y-2 text-xs`,children:V&&!d?(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`text-fg-muted`,children:u.keyConfigured}),(0,$.jsx)(L,{type:`button`,variant:`ghost`,onClick:()=>f(!0),children:u.changeKey})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`label`,{htmlFor:`realtime-api-key`,className:`font-medium text-fg`,children:r.stt.apiKey}),(0,$.jsx)(zt,{kind:`stt`,providerId:`alibaba`,fieldId:`realtime-api-key`,value:z,labels:{...o,maskedHelp:``},onChange:e=>l({...i,stt:{...i.stt,providers:{...i.stt.providers,alibaba:{...i.stt.providers?.alibaba,apiKey:e}}}})}),(0,$.jsx)(`p`,{className:`text-fg-muted`,children:u.keyHint})]})}):null,E===`xopc-cloud`?(0,$.jsxs)(`p`,{className:`text-xs text-fg-muted`,children:[u.hostedAccountHint,` `,(0,$.jsx)(c,{className:`text-accent hover:underline`,to:`/settings/capabilities/models`,children:u.manageAccount})]}):null,!D&&!a&&!S?.tts&&(E===`alibaba`||E===`xopc-cloud`)?(0,$.jsxs)(`div`,{className:`rounded-lg bg-surface-base p-3 text-xs`,children:[(0,$.jsx)(`p`,{className:`font-medium text-fg`,children:u.finishSetup}),(0,$.jsx)(`p`,{className:`mt-1 text-fg-muted`,children:i.tts.provider===`edge`?u.edgeHint:u.outputHint}),(0,$.jsx)(L,{className:`mt-2`,type:`button`,variant:`secondary`,onClick:()=>re(E),children:u.configureConversation})]}):null,(0,$.jsxs)(`label`,{className:`block space-y-2 text-sm`,children:[(0,$.jsx)(`span`,{children:r.experience.defaultEngine}),(0,$.jsxs)(g,{value:T.defaultEngine,className:H,onChange:e=>Y({defaultEngine:e.target.value}),children:[(0,$.jsx)(_,{value:`agent`,children:r.experience.agent}),(0,$.jsx)(_,{value:`omni`,children:r.experience.omni})]})]}),(0,$.jsxs)(`p`,{className:`text-xs text-fg-muted`,children:[T.defaultEngine===`agent`?r.experience.agentHint:r.experience.omniHint,` `,r.experience.nextCall]})]}):null,t[43]=o,t[44]=re,t[45]=d,t[46]=C,t[47]=i,t[48]=z,t[49]=V,t[50]=l,t[51]=a,t[52]=E,t[53]=T.defaultEngine,t[54]=T.enabled,t[55]=u.changeKey,t[56]=u.configureConversation,t[57]=u.customProvider,t[58]=u.edgeHint,t[59]=u.enable,t[60]=u.finishSetup,t[61]=u.hosted,t[62]=u.hostedAccountHint,t[63]=u.hostedHint,t[64]=u.keyConfigured,t[65]=u.keyHint,t[66]=u.manageAccount,t[67]=u.outputHint,t[68]=u.ownKey,t[69]=u.ownKeyHint,t[70]=u.service,t[71]=u.statusError,t[72]=n,t[73]=D,t[74]=S?.tts,t[75]=Y,t[76]=r.experience,t[77]=r.stt,t[78]=oe):oe=t[78];let se;t[79]!==W||t[80]!==U||t[81]!==O||t[82]!==T.bargeIn||t[83]!==T.omni||t[84]!==u.bargeIn||t[85]!==u.defaultVoice||t[86]!==u.voice||t[87]!==n||t[88]!==D||t[89]!==S?.tts||t[90]!==Y||t[91]!==r.realtime||t[92]!==te?(se=n===`listening`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,$.jsx)(`label`,{htmlFor:`realtime-voice`,className:`text-sm font-medium text-fg`,children:u.voice}),(0,$.jsxs)(g,{id:`realtime-voice`,className:`${H} w-full sm:w-56`,value:W,disabled:U?!T.omni:!D&&!S?.tts,onChange:e=>{if(U&&T.omni){Y({omni:{...T.omni,voice:e.target.value}});return}(O===`alibaba`||O===`xopc-cloud`)&&Y({tts:{provider:O,...e.target.value?{voice:e.target.value}:{}},...T.omni&&[`Cherry`,`Ethan`,`Serena`,`Chelsie`].includes(e.target.value)?{omni:{...T.omni,voice:e.target.value}}:{}})},children:[U?null:(0,$.jsx)(_,{value:``,children:u.defaultVoice}),W&&!te.some(e=>e.id===W)?(0,$.jsx)(_,{value:W,children:W}):null,te.map(hn)]})]}),(0,$.jsxs)(`label`,{className:`flex items-center justify-between gap-4 text-sm text-fg`,children:[(0,$.jsxs)(`span`,{children:[u.bargeIn,(0,$.jsx)(`span`,{className:`mt-1 block text-xs text-fg-muted`,children:r.realtime.bargeInDescription})]}),(0,$.jsx)(`input`,{type:`checkbox`,role:`switch`,"aria-checked":T.bargeIn,checked:T.bargeIn,className:`size-4 accent-accent`,onChange:e=>Y({bargeIn:e.target.checked})})]})]}):null,t[79]=W,t[80]=U,t[81]=O,t[82]=T.bargeIn,t[83]=T.omni,t[84]=u.bargeIn,t[85]=u.defaultVoice,t[86]=u.voice,t[87]=n,t[88]=D,t[89]=S?.tts,t[90]=Y,t[91]=r.realtime,t[92]=te,t[93]=se):se=t[93];let ce;t[94]!==q||t[95]!==ne||t[96]!==C||t[97]!==w||t[98]!==a||t[99]!==n||t[100]!==m||t[101]!==S||t[102]!==ae||t[103]!==r||t[104]!==v.input||t[105]!==v.output?(ce=n===`diagnostics`?(0,$.jsxs)($.Fragment,{children:[w?(0,$.jsx)(G,{className:`h-16 w-full`}):(0,$.jsxs)(`div`,{className:`space-y-2 text-sm`,role:`status`,children:[(0,$.jsxs)(`p`,{children:[r.experience.dictationReady,` · `,ae(q,v.input)]}),(0,$.jsxs)(`p`,{children:[r.experience.agentReady,` · `,ae(q&&ne,v.input&&v.output)]}),(0,$.jsxs)(`p`,{children:[r.experience.omniReady,` · `,ae(!!(S?.enabled&&S.omni),!1)]})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:r.experience.configurationOnly}),(0,$.jsx)(fn,{v:r,canListen:q,canSpeak:ne,disabled:a||w||!!C,onVerified:e=>y({signature:m,...e})},`${m}:${JSON.stringify(S)}`)]}):null,t[94]=q,t[95]=ne,t[96]=C,t[97]=w,t[98]=a,t[99]=n,t[100]=m,t[101]=S,t[102]=ae,t[103]=r,t[104]=v.input,t[105]=v.output,t[106]=ce):ce=t[106];let le;return t[107]!==u.service||t[108]!==oe||t[109]!==se||t[110]!==ce?(le=(0,$.jsxs)(`section`,{className:`space-y-5 rounded-xl border border-edge bg-surface-panel p-4 sm:p-5`,"aria-label":u.service,children:[oe,se,ce]}),t[107]=u.service,t[108]=oe,t[109]=se,t[110]=ce,t[111]=le):le=t[111],le}function hn(e){return(0,$.jsx)(_,{value:e.id,children:e.name},e.id)}function gn(e){return{id:e,name:e}}function _n(e){return e.id===`alibaba`&&e.configured}function vn(e){return[`Cherry`,`Ethan`,`Serena`,`Chelsie`].includes(e.id)}function yn(e){let t=(0,Z.c)(22),{value:n,onChange:r}=e,i=M(xn)===`zh`,a;t[0]===i?a=t[1]:(a=(e,t)=>i?t:e,t[0]=i,t[1]=a);let o=a,s;t[2]!==r||t[3]!==n?(s=e=>{n&&r({...n,...e})},t[2]=r,t[3]=n,t[4]=s):s=t[4];let c=s,l;t[5]===o?l=t[6]:(l=o(`Natural conversation · advanced`,`自然对话 · 高级设置`),t[5]=o,t[6]=l);let u;t[7]===l?u=t[8]:(u=(0,$.jsx)(`summary`,{className:`cursor-pointer text-sm font-medium text-fg`,children:l}),t[7]=l,t[8]=u);let d;t[9]===o?d=t[10]:(d=o(`Calls continue the same session using recent history. Service and credentials are shared with voice setup; override them here only when needed.`,`通话会接续同一会话的近期历史。默认共用语音服务与凭据,仅在需要独立配置时修改。`),t[9]=o,t[10]=d);let f;t[11]===d?f=t[12]:(f=(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:d}),t[11]=d,t[12]=f);let p;t[13]!==o||t[14]!==r||t[15]!==c||t[16]!==n?(p=n?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`label`,{className:`block space-y-1 text-sm`,children:[(0,$.jsx)(`span`,{children:o(`Connection`,`连接方式`)}),(0,$.jsxs)(g,{value:n.provider,onChange:e=>r({model:n.model,voice:n.voice,instructions:n.instructions,provider:e.target.value}),children:[(0,$.jsx)(_,{value:`xopc-cloud`,children:`XOPC Platform`}),(0,$.jsxs)(_,{value:`alibaba`,children:[`DashScope · `,o(`Your API key`,`自有 API Key`)]})]})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.provider===`xopc-cloud`?o(`Uses your XOPC sign-in and the platform’s published Omni route and credits.`,`使用 XOPC 登录授权、平台发布的 Omni 路由和额度。`):o(`Leave empty to use the shared voice service credential.`,`留空使用语音服务中已配置的凭据。`)}),(0,$.jsx)(`p`,{className:`font-mono text-xs text-fg-muted`,children:n.model}),n.provider===`alibaba`?(0,$.jsxs)(`label`,{className:`block space-y-1 text-sm`,children:[(0,$.jsx)(`span`,{children:`API Key`}),(0,$.jsx)(`input`,{className:`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,type:`password`,autoComplete:`new-password`,value:n.apiKey??``,onChange:e=>c({apiKey:e.target.value})})]}):null,(0,$.jsxs)(`label`,{className:`block space-y-1 text-sm`,children:[(0,$.jsx)(`span`,{children:o(`Endpoint override (optional)`,`自定义服务地址(可选)`)}),(0,$.jsx)(`input`,{className:`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,value:n.baseUrl??``,placeholder:n.provider===`alibaba`?`wss://dashscope.aliyuncs.com/api-ws/v1/realtime`:`https://router.xopc.ai/v1`,onChange:e=>c({baseUrl:e.target.value.trim()||void 0})})]}),(0,$.jsxs)(`label`,{className:`block space-y-1 text-sm`,children:[(0,$.jsx)(`span`,{children:o(`Voice`,`音色`)}),(0,$.jsx)(g,{value:n.voice,onChange:e=>c({voice:e.target.value}),children:[`Cherry`,`Ethan`,`Serena`,`Chelsie`].map(bn)})]}),(0,$.jsxs)(`label`,{className:`block space-y-1 text-sm`,children:[(0,$.jsx)(`span`,{children:o(`Conversation instructions`,`聊天指令`)}),(0,$.jsx)(`textarea`,{className:`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,rows:3,maxLength:8e3,value:n.instructions,onChange:e=>c({instructions:e.target.value})})]})]}):(0,$.jsx)(L,{variant:`secondary`,onClick:()=>r({provider:`xopc-cloud`,model:`qwen3-omni-flash-realtime`,voice:`Cherry`,instructions:`You are a friendly voice companion. You cannot execute tools.`}),children:o(`Configure natural conversation`,`配置自然聊天`)}),t[13]=o,t[14]=r,t[15]=c,t[16]=n,t[17]=p):p=t[17];let m;return t[18]!==u||t[19]!==f||t[20]!==p?(m=(0,$.jsxs)(`details`,{className:`space-y-3 rounded-xl border border-edge p-4`,children:[u,f,p]}),t[18]=u,t[19]=f,t[20]=p,t[21]=m):m=t[21],m}function bn(e){return(0,$.jsx)(_,{value:e,children:e},e)}function xn(e){return e.language}var Sn=V;function Cn(){return F(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,U,`dark:border-edge`)}function wn(){return F(H,V)}function Tn(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 Dn(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 On(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 kn(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 jn(e){return{maskedHelp:e.apiKeyMaskedHelp,copy:e.apiKeyCopy,copied:e.apiKeyCopied,show:e.apiKeyShow,hide:e.apiKeyHide,notInConfigFile:e.apiKeyNotInConfigFile,loadFailed:e.apiKeyRevealFailed}}function Mn(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 Nn(e,t){if(e.type===`boolean`)return!!t;if(e.type!==`number`)return t;let n=String(t).trim();if(!n)return;let r=Number(n);return Number.isFinite(r)?r:void 0}function Pn(e,t){switch(t.type){case`reset`:return{form:null,baseline:null};case`sync`:{let e=structuredClone(t.value);return{form:e,baseline:structuredClone(e)}}case`update`:return{...e,form:t.updater(e.form)};case`saved`:{let n=structuredClone(t.value);return{form:e.form!==null&&JSON.stringify(e.form)!==JSON.stringify(t.value)?e.form:n,baseline:structuredClone(n)}}}}function Fn(){let e=M(e=>e.language),t=k(e).voiceSettings,[n,r]=(0,Q.useState)(`listening`),i=Be(e=>e.captions),a=Be(e=>e.setCaptions),o=!!P(e=>e.token),[s,c]=(0,Q.useReducer)(Pn,{form:null,baseline:null}),l=s.form,u=s.baseline,[d,f]=(0,Q.useState)(null),p=(0,Q.useRef)(!1),m=(0,Q.useRef)(l);m.current=l;let h=(0,Q.useRef)({parsed:null,models:void 0}),{data:v,error:y,isLoading:b,mutate:x}=B(o),{data:S,error:C,isLoading:w,mutate:T}=I(o?N(`/api/voice/models`):null,Et,{revalidateOnFocus:!1}),{data:E,error:D,isLoading:O}=I(o?N(`/api/voice/providers`):null,Pt,{revalidateOnFocus:!1}),{data:A,error:j,isLoading:F}=I(o?N(`/api/voice/stt-providers`):null,Dt,{revalidateOnFocus:!1}),R=(0,Q.useMemo)(()=>E?.providers??[],[E]),ee=(0,Q.useMemo)(()=>A?.providers??[],[A]),z=(0,Q.useMemo)(()=>v?.payload?.config===void 0?null:Rt(v.payload.config),[v]),V=(0,Q.useMemo)(()=>!l||!u?!1:JSON.stringify(l)!==JSON.stringify(u),[l,u]);o?z!==null&&S!==void 0&&!p.current&&(h.current.parsed!==z||h.current.models!==S)&&(h.current={parsed:z,models:S},c({type:`sync`,value:z}),f(S)):(h.current.parsed!==null||h.current.models!==void 0)&&(h.current={parsed:null,models:void 0},c({type:`reset`}),f(null),p.current=!1);let H=!!(o&&(z===null||S===void 0||E===void 0||A===void 0)&&(b||w||O||F)),U=y instanceof Error?y.message:y?String(y):C instanceof Error?C.message:C?String(C):D instanceof Error?D.message:D?String(D):j instanceof Error?j.message:j?String(j):null,W=(0,Q.useCallback)(e=>{p.current=!0,c({type:`update`,updater:t=>t?{...t,stt:{...t.stt,...e}}:null})},[]),G=(0,Q.useCallback)(e=>{p.current=!0,c({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}}}}})},[]),K=(0,Q.useCallback)(e=>{p.current=!0,c({type:`update`,updater:t=>t?{...t,voice:{...t.voice,input:{...t.voice.input,refinement:{...t.voice.input.refinement,...e}}}}:null})},[]),te=(0,Q.useCallback)(t=>{p.current=!0,c({type:`update`,updater:n=>n?{...n,voice:{...n.voice,languageMode:t,...t===`auto`?{language:e}:{}}}:null})},[e]),q=(0,Q.useCallback)(e=>{p.current=!0,c({type:`update`,updater:t=>t?{...t,voice:{...t.voice,realtime:{...t.voice.realtime,...e}}}:null})},[]),ne=(0,Q.useCallback)(e=>{p.current=!0,c({type:`update`,updater:t=>t?{...t,tts:{...t.tts,...e}}:null})},[]),J=Tt({value:l,dirty:V,onSave:(0,Q.useCallback)(async e=>{let n=u?.stt.provider!==`xopc-local`&&e.stt.provider===`xopc-local`;try{await Ot(e),n&&window.dispatchEvent(new Event(Lt)),c({type:`saved`,value:e}),p.current=!!(m.current&&JSON.stringify(m.current)!==JSON.stringify(e))}catch(e){throw Error(e instanceof Error?e.message:t.saveError)}},[u?.stt.provider,t.saveError])}),Y=(0,Q.useCallback)(e=>{p.current=!0,c({type:`update`,updater:()=>e})},[]);if(!o)return(0,$.jsx)(`div`,{className:`flex flex-col gap-3`,children:(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.needToken})});if(H)return(0,$.jsx)(vt,{rows:4});if(!l||d===null)return(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:U??t.loadError}),(0,$.jsx)(L,{type:`button`,variant:`secondary`,onClick:()=>{x(),T()},children:t.retry})]});let X=l.stt,re=l.tts,ie=l.voice.input.refinement,ae=jn(t);return(0,$.jsxs)(`div`,{className:`flex w-full flex-col gap-4`,onBlurCapture:J.onBlurCapture,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-3`,children:[(0,$.jsx)(`p`,{className:`text-sm leading-relaxed text-fg-muted`,children:t.setup.subtitle}),(0,$.jsx)(wt,{status:J.status,error:J.error})]}),J.error?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:J.error}):null,(0,$.jsx)(`nav`,{"aria-label":t.setup.advanced,className:`flex flex-wrap gap-2`,children:[`listening`,`input`,`devices`,`service`,`diagnostics`].map(e=>(0,$.jsx)(L,{variant:n===e?`secondary`:`ghost`,"aria-pressed":n===e,onClick:()=>r(e),children:t.experience[e]},e))}),n===`listening`||n===`service`||n===`diagnostics`?(0,$.jsx)(mn,{section:n,v:t,form:l,pending:V||J.status===`saving`||!!J.error,apiKeyLabels:ae,sttProviders:ee,onChange:Y}):null,n===`listening`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(In,{v:t,voice:l.voice,updateLanguageMode:te}),(0,$.jsxs)(`label`,{className:`flex items-center justify-between gap-3 text-sm text-fg`,children:[t.experience.pace,(0,$.jsxs)(g,{className:wn(),value:String(l.voice.realtime.silenceDurationMs),onChange:e=>q({silenceDurationMs:Number(e.target.value)}),children:[(0,$.jsx)(_,{value:`800`,children:t.experience.fast}),(0,$.jsx)(_,{value:`1200`,children:t.experience.standard}),(0,$.jsx)(_,{value:`2000`,children:t.experience.relaxed}),[800,1200,2e3].includes(l.voice.realtime.silenceDurationMs)?null:(0,$.jsxs)(_,{value:String(l.voice.realtime.silenceDurationMs),children:[l.voice.realtime.silenceDurationMs,` ms`]})]})]})]}):null,n===`input`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`label`,{className:`flex items-center justify-between text-sm`,children:[t.experience.captions,(0,$.jsx)(`input`,{type:`checkbox`,role:`switch`,"aria-checked":i,className:`ui-checkbox`,checked:i,onChange:e=>a(e.target.checked)})]}),(0,$.jsxs)(`label`,{className:`space-y-2 text-sm`,children:[(0,$.jsx)(`span`,{children:t.stt.refinement}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.stt.refinementDesc}),(0,$.jsxs)(g,{className:wn(),value:ie.mode,onChange:e=>K({mode:e.target.value}),children:[(0,$.jsx)(_,{value:`off`,children:t.stt.refinementOff}),(0,$.jsx)(_,{value:`punctuation`,children:t.stt.refinementPunctuation}),(0,$.jsx)(_,{value:`light`,children:t.stt.refinementLight}),ie.mode===`custom`?(0,$.jsx)(_,{value:`custom`,children:t.setup.advanced}):null]})]}),(0,$.jsxs)(`details`,{className:`rounded-xl border border-edge bg-surface-panel px-4 py-3`,children:[(0,$.jsxs)(`summary`,{className:`cursor-pointer text-sm font-medium text-fg`,children:[t.setup.readout,` · `,re.enabled?kn(re.trigger,t):t.overview.off]}),(0,$.jsx)(`p`,{className:`mt-3 text-xs text-fg-muted`,children:t.setup.readoutHint}),(0,$.jsx)(Vn,{v:t,apiKeyLabels:ae,tts:re,models:d,ttsProviders:R,updateTts:ne})]})]}):null,n===`devices`?(0,$.jsx)(dn,{v:t}):null,n===`service`?(0,$.jsxs)($.Fragment,{children:[l.voice.realtime.enabled?(0,$.jsx)(yn,{value:l.voice.realtime.omni,onChange:e=>q({omni:e})}):null,(0,$.jsxs)(`details`,{className:`rounded-xl border border-edge bg-surface-panel px-4 py-3`,children:[(0,$.jsx)(`summary`,{className:`cursor-pointer text-sm font-medium text-fg`,children:t.experience.technical}),(0,$.jsx)(Ln,{v:t,apiKeyLabels:ae,stt:X,models:d,sttProviders:ee,updateStt:W,updateSttFallback:G}),(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.notes.envVars})]})]}):null]})}function In(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=wn(),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)(_,{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)(_,{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)(g,{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 Ln(e){let t=(0,Z.c)(58),{v:n,apiKeyLabels:r,stt:i,models:a,sttProviders:o,updateStt:s,updateSttFallback:c}=e,l;if(t[0]!==o){let e=new Set;l=[];for(let t of o)e.has(t.id)||(e.add(t.id),l.push(t));t[0]=o,t[1]=l}else l=t[1];let u=l,d,f,p,m;if(t[2]!==a||t[3]!==u||t[4]!==i.provider||t[5]!==i.providers){d=u.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],p=e,f=a?.stt?.[i.provider]?.length?a.stt[i.provider]:d?.models??[],m=d?.fields.find(Rn),t[2]=a,t[3]=u,t[4]=i.provider,t[5]=i.providers,t[6]=d,t[7]=f,t[8]=p,t[9]=m}else d=t[6],f=t[7],p=t[8],m=t[9];let h=m,v=typeof p.model==`string`?p.model:void 0,y=v??(typeof h?.defaultValue==`string`?h.defaultValue:f[0]?.id),b;t[13]!==i.provider||t[14]!==i.providers||t[15]!==s?(b=e=>{s({providers:{...i.providers??{},[i.provider]:{...i.providers?.[i.provider]??{},...e}}})},t[13]=i.provider,t[14]=i.providers,t[15]=s,t[16]=b):b=t[16];let x=b,S,C;t[17]!==v||t[18]!==y||t[19]!==h||t[20]!==x?(S=()=>{h&&y&&v!==y&&x({model:y})},C=[v,y,h,x],t[17]=v,t[18]=y,t[19]=h,t[20]=x,t[21]=S,t[22]=C):(S=t[21],C=t[22]),(0,Q.useEffect)(S,C);let w;t[23]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,$.jsx)(fe,{className:`size-4 text-accent`,strokeWidth:1.75}),t[23]=w):w=t[23];let T;t[24]===n.stt.title?T=t[25]:(T=(0,$.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[w,n.stt.title]}),t[24]=n.stt.title,t[25]=T);let E;t[26]===n.stt.description?E=t[27]:(E=(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:n.stt.description}),t[26]=n.stt.description,t[27]=E);let D;t[28]!==T||t[29]!==E?(D=(0,$.jsxs)(`div`,{className:`mb-4`,children:[T,E]}),t[28]=T,t[29]=E,t[30]=D):D=t[30];let O;t[31]===s?O=t[32]:(O=e=>s({enabled:e}),t[31]=s,t[32]=O);let k;t[33]!==i.enabled||t[34]!==O||t[35]!==n.stt.enable||t[36]!==n.stt.enableDesc?(k=(0,$.jsx)(Un,{checked:i.enabled,title:n.stt.enable,description:n.stt.enableDesc,onChange:O}),t[33]=i.enabled,t[34]=O,t[35]=n.stt.enable,t[36]=n.stt.enableDesc,t[37]=k):k=t[37];let A;t[38]!==d?.fields||t[39]!==r||t[40]!==y||t[41]!==f||t[42]!==u||t[43]!==p||t[44]!==i.enabled||t[45]!==i.fallback?.enabled||t[46]!==i.provider||t[47]!==x||t[48]!==s||t[49]!==c||t[50]!==n?(A=i.enabled?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:F(`flex flex-col gap-1.5`,Sn),children:[(0,$.jsx)(Kn,{children:n.stt.provider}),(0,$.jsx)(g,{className:wn(),value:i.provider,onChange:e=>s({provider:e.target.value}),children:u.map(e=>(0,$.jsxs)(_,{value:e.id,children:[Dn(e.id,n),e.configured?``:` *`]},e.id))})]}),(0,$.jsx)(Hn,{kind:`stt`,providerId:i.provider,fields:d?.fields??[],providerSlice:p,models:f,currentModel:y,apiKeyLabels:r,onPatch:x})]}),i.provider===`xopc-local`?(0,$.jsx)(Bn,{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=>c({enabled:e.target.checked})})]})]}):null,t[38]=d?.fields,t[39]=r,t[40]=y,t[41]=f,t[42]=u,t[43]=p,t[44]=i.enabled,t[45]=i.fallback?.enabled,t[46]=i.provider,t[47]=x,t[48]=s,t[49]=c,t[50]=n,t[51]=A):A=t[51];let j;t[52]!==k||t[53]!==A?(j=(0,$.jsxs)(`div`,{className:`space-y-4`,children:[k,A]}),t[52]=k,t[53]=A,t[54]=j):j=t[54];let M;return t[55]!==j||t[56]!==D?(M=(0,$.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[D,j]}),t[55]=j,t[56]=D,t[57]=M):M=t[57],M}function Rn(e){return e.key===`model`}function zn(e){return`${Math.round(e/1024/1024)} MB`}function Bn({v:e}){let{data:t,error:n,mutate:r}=I(N(`/api/voice/local/status`),Nt,{revalidateOnFocus:!1,refreshInterval:e=>e?.models.some(e=>e.state===`downloading`)?1e3:0}),[i,a]=(0,Q.useState)(null),[o,s]=(0,Q.useState)(null);(0,Q.useEffect)(()=>{let e=()=>void r();return window.addEventListener(Lt,e),()=>window.removeEventListener(Lt,e)},[r]);let c=(0,Q.useCallback)(async(e,t)=>{a(e.id),s(null);try{t===`install`?await Mt(e.id):await Ft(e.id),await r()}catch(e){s(e instanceof Error?e.message:String(e))}finally{a(null)}},[r]);return(0,$.jsxs)(`div`,{className:`rounded-xl border border-edge bg-surface-panel/60 p-3`,children:[(0,$.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.stt.localModels}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:e.stt.localModelsDesc}),n?(0,$.jsx)(`p`,{className:`mt-3 text-xs text-red-600 dark:text-red-400`,children:String(n)}):null,t?.runtime.ready===!1?(0,$.jsx)(`p`,{className:`mt-3 text-xs text-red-600 dark:text-red-400`,children:t.runtime.error??`Local voice runtime is unavailable`}):null,t?.decoder?.available===!1?(0,$.jsx)(`p`,{className:`mt-3 text-xs text-amber-700 dark:text-amber-300`,children:t.decoder.error??`Compressed audio decoding is unavailable`}):null,o?(0,$.jsx)(`p`,{className:`mt-3 text-xs text-red-600 dark:text-red-400`,children:o}):null,(0,$.jsx)(`div`,{className:`mt-3 grid gap-2`,children:(t?.models??[]).map(t=>{let n=i===t.id||t.state===`downloading`;return(0,$.jsxs)(`div`,{className:F(`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:[zn(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)(L,{type:`button`,variant:`secondary`,disabled:n,onClick:()=>void c(t,t.state===`ready`?`remove`:`install`),children:n?(0,$.jsx)(w,{className:`size-4 animate-spin`}):t.state===`ready`?e.stt.localRemove:e.stt.localInstall})]},t.id)})})]})}function Vn({v:e,apiKeyLabels:t,tts:n,models:r,ttsProviders:i,updateTts:a}){let[o,s]=(0,Q.useState)(e.tts.test.sampleText),[c,l]=(0,Q.useState)({status:`idle`}),u=(0,Q.useRef)(null),d=(0,Q.useRef)(null),f=(0,Q.useRef)(null),p=(0,Q.useCallback)(()=>{f.current?.abort(),f.current=null,u.current?.pause(),u.current=null,d.current&&=(URL.revokeObjectURL(d.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),v=n.providers?.[n.provider]??{},y=r?.tts?.[n.provider]?.length?r.tts[n.provider]:h?.models??[],b=h?.fields.find(e=>e.key===`model`),x=h?.fields.find(e=>e.key===`voice`),S=typeof v.model==`string`?v.model:void 0,C=S??(typeof b?.defaultValue==`string`?b.defaultValue:y[0]?.id),T=y.find(e=>e.id===C),E=r?.ttsVoices?.[n.provider]?.length?r.ttsVoices[n.provider]:h?.voices??[],{data:D=[]}=I(C?`voice:tts:${n.provider}:${C}`:null,()=>jt(n.provider,C??``),{revalidateOnFocus:!1}),O=D.length>0?D:E,k=typeof v.voice==`string`?v.voice:void 0,A=k??O.find(e=>e.id===T?.tts?.defaultVoice)?.id??(typeof x?.defaultValue==`string`?x.defaultValue:O[0]?.id),j=(h?.fields??[]).filter(e=>(e.key!==`speed`||T?.tts?.speed!==!1)&&(e.key!==`instructions`||T?.tts?.instructions!==!1)),M=!!h?.diagnostics.requiresApiKey,N=!!h?.configured||!M,P=(0,Q.useCallback)(e=>{a({providers:{...n.providers??{},[n.provider]:{...n.providers?.[n.provider]??{},...e}}})},[n.provider,n.providers,a]);(0,Q.useEffect)(()=>{let e={};b&&C&&S!==C&&(e.model=C),x&&A&&k!==A&&(e.voice=A),Object.keys(e).length>0&&P(e)},[S,k,C,A,b,P,x]),(0,Q.useEffect)(()=>()=>p(),[p]);let R=(0,Q.useCallback)(e=>{a({provider:e}),l({status:`idle`})},[a]),ee=(0,Q.useCallback)(async()=>{let t=o.trim();if(!t){l({status:`error`,message:e.tts.test.emptyText});return}p();let r=new AbortController;f.current=r,l({status:`loading`});try{let i=await At({text:t,provider:n.provider,providerConfig:v,...C?{model:C}:{},...A?{voice:A}:{}},r.signal);if(r.signal.aborted)return;let a=En(i.audio,i.mimeType);d.current=a;let o=new Audio(a);u.current=o;let s=[i.provider,i.format,i.latencyMs===void 0?void 0:`${i.latencyMs}ms`,Tn(i.audioSize)].filter(Boolean).join(` · `);o.addEventListener(`ended`,()=>l({status:`done`,summary:s}),{once:!0}),o.addEventListener(`error`,()=>l({status:`error`,message:e.tts.test.playFailed}),{once:!0}),await o.play(),l({status:`playing`,summary:s})}catch(e){if(r.signal.aborted)return;p(),l({status:`error`,message:e instanceof Error?e.message:String(e)})}},[C,A,v,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)(ft,{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)(Un,{checked:n.enabled,title:e.tts.enable,description:e.tts.enableDesc,onChange:e=>a({enabled:e})}),n.enabled?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:F(`flex flex-col gap-1.5`,Sn),children:[(0,$.jsx)(Kn,{children:e.tts.trigger}),(0,$.jsxs)(g,{className:wn(),value:n.trigger,onChange:e=>a({trigger:e.target.value}),children:[(0,$.jsx)(_,{value:`off`,children:e.tts.triggerOff}),(0,$.jsx)(_,{value:`inbound`,children:e.tts.triggerInbound}),(0,$.jsx)(_,{value:`tagged`,children:e.tts.triggerTagged}),(0,$.jsx)(_,{value:`always`,children:e.tts.triggerAlways})]}),(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.triggerHelp})]}),(0,$.jsxs)(`div`,{className:F(`flex flex-col gap-1.5`,Sn),children:[(0,$.jsx)(Kn,{children:e.tts.provider}),(0,$.jsx)(g,{className:wn(),value:n.provider,onChange:e=>R(e.target.value),children:m.map(t=>(0,$.jsx)(_,{value:t.id,children:On(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:!N||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)(Hn,{kind:`tts`,providerId:n.provider,fields:j,providerSlice:v,models:y,voices:O,currentModel:C,currentVoice:A,apiKeyLabels:t,onPatch:P,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)(L,{type:`button`,variant:`primary`,onClick:()=>void ee(),disabled:c.status===`loading`,className:`h-9`,children:[c.status===`loading`?(0,$.jsx)(w,{className:`size-4 animate-spin`}):(0,$.jsx)(lt,{className:`size-4`}),c.status===`loading`?e.tts.test.generating:e.tts.test.play]}),(0,$.jsxs)(L,{type:`button`,variant:`secondary`,onClick:()=>{p(),l(e=>e.status===`playing`?{status:`done`,summary:e.summary}:{status:`idle`})},disabled:c.status!==`playing`,className:`h-9`,children:[(0,$.jsx)(xe,{className:`size-4`}),e.tts.test.stop]})]})]}),(0,$.jsxs)(`details`,{className:`mt-3`,children:[(0,$.jsx)(`summary`,{className:`cursor-pointer text-xs text-fg-muted`,children:e.setup.sampleText}),(0,$.jsx)(`textarea`,{className:F(Cn(),`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 Hn({kind:e,providerId:t,fields:n,providerSlice:r,models:i,voices:a=[],currentModel:o,currentVoice:s,apiKeyLabels:c,onPatch:l,resetVoiceOnModelChange:u=!1}){return n.map(n=>n.key===`apiKey`?(0,$.jsxs)(`div`,{className:F(`flex flex-col gap-1.5`,Sn),children:[(0,$.jsx)(Kn,{children:n.label}),(0,$.jsx)(zt,{kind:e,providerId:t,fieldId:`voice-${e}-${t}-api-key`,value:typeof r.apiKey==`string`?r.apiKey:``,onChange:e=>l({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:F(`flex flex-col gap-1.5`,Sn),children:[(0,$.jsx)(Kn,{children:n.label}),(0,$.jsx)(g,{className:wn(),value:o??``,onChange:e=>l({model:e.target.value,...u?{voice:void 0}:{}}),children:i.map(e=>(0,$.jsx)(_,{value:e.id,children:e.name},e.id))})]},n.key):n.key===`voice`&&a.length>0?(0,$.jsxs)(`div`,{className:F(`flex flex-col gap-1.5`,Sn),children:[(0,$.jsx)(Kn,{children:n.label}),(0,$.jsx)(g,{className:wn(),value:s??``,onChange:e=>l({voice:e.target.value}),children:a.map(e=>(0,$.jsx)(_,{value:e.id,children:e.name},e.id))})]},n.key):(0,$.jsx)(Wn,{field:n,value:Mn(r,n),onChange:e=>l({[n.key]:e}),className:n.type===`textarea`?`sm:col-span-2`:Sn},n.key))}function Un(e){let t=(0,Z.c)(27),{checked:n,title:r,description:i,onChange:a}=e,o;t[0]!==n||t[1]!==a?(o=()=>a(!n),t[0]=n,t[1]=a,t[2]=o):o=t[2];let s=n?`bg-surface-panel text-fg`:`bg-surface-panel/80 text-fg hover:bg-surface-hover`,c;t[3]===s?c=t[4]:(c=F(`group flex w-full items-center justify-between gap-4 rounded-lg border border-edge px-3 py-3 text-left transition-colors`,U,s),t[3]=s,t[4]=c);let l;t[5]===r?l=t[6]:(l=(0,$.jsx)(`span`,{className:`flex flex-wrap items-center gap-2 text-sm font-semibold text-fg`,children:r}),t[5]=r,t[6]=l);let u;t[7]===i?u=t[8]:(u=(0,$.jsx)(`span`,{className:`mt-1 block text-xs leading-relaxed text-fg-muted`,children:i}),t[7]=i,t[8]=u);let d;t[9]!==l||t[10]!==u?(d=(0,$.jsxs)(`span`,{className:`min-w-0`,children:[l,u]}),t[9]=l,t[10]=u,t[11]=d):d=t[11];let f=n?`border-accent bg-accent`:`border-edge bg-surface-hover group-hover:border-accent/40`,p;t[12]===f?p=t[13]:(p=F(`relative inline-flex h-6 w-11 shrink-0 items-center rounded-full border transition-colors`,f),t[12]=f,t[13]=p);let m=n?`translate-x-5`:`translate-x-0.5`,h;t[14]===m?h=t[15]:(h=F(`size-5 rounded-full bg-white shadow-surface transition-transform`,m),t[14]=m,t[15]=h);let g;t[16]===h?g=t[17]:(g=(0,$.jsx)(`span`,{className:h}),t[16]=h,t[17]=g);let _;t[18]!==g||t[19]!==p?(_=(0,$.jsx)(`span`,{className:p,"aria-hidden":!0,children:g}),t[18]=g,t[19]=p,t[20]=_):_=t[20];let v;return t[21]!==n||t[22]!==o||t[23]!==_||t[24]!==c||t[25]!==d?(v=(0,$.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":n,onClick:o,className:c,children:[d,_]}),t[21]=n,t[22]=o,t[23]=_,t[24]=c,t[25]=d,t[26]=v):v=t[26],v}function Wn(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=F(`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,a),t[0]=a,t[1]=e);let o;t[2]===n.label?o=t[3]:(o=(0,$.jsx)(`span`,{className:`block text-sm font-medium text-fg`,children:n.label}),t[2]=n.label,t[3]=o);let c;t[4]===s?c=t[5]:(c=s?(0,$.jsx)(`span`,{className:`mt-1 block text-xs text-fg-subtle`,children:s}):null,t[4]=s,t[5]=c);let l;t[6]!==o||t[7]!==c?(l=(0,$.jsxs)(`span`,{children:[o,c]}),t[6]=o,t[7]=c,t[8]=l):l=t[8];let u=!!r,d;t[9]!==n||t[10]!==i?(d=e=>i(Nn(n,e.target.checked)),t[9]=n,t[10]=i,t[11]=d):d=t[11];let f;t[12]!==u||t[13]!==d?(f=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:u,onChange:d}),t[12]=u,t[13]=d,t[14]=f):f=t[14];let p;return t[15]!==e||t[16]!==l||t[17]!==f?(p=(0,$.jsxs)(`label`,{className:e,children:[l,f]}),t[15]=e,t[16]=l,t[17]=f,t[18]=p):p=t[18],p}let c=typeof r==`boolean`?``:String(r),l;t[19]===a?l=t[20]:(l=F(`flex flex-col gap-1.5`,a),t[19]=a,t[20]=l);let u;t[21]===n.label?u=t[22]:(u=(0,$.jsx)(Kn,{children:n.label}),t[21]=n.label,t[22]=u);let d;t[23]!==a||t[24]!==n||t[25]!==c||t[26]!==o||t[27]!==i?(d=n.type===`select`?(0,$.jsx)(g,{id:o,className:wn(),value:c,required:n.required,onChange:e=>i(Nn(n,e.target.value)),children:(n.options??[]).map(Gn)}):n.type===`textarea`?(0,$.jsx)(`textarea`,{id:o,className:F(Cn(),`min-h-24 resize-y`),value:c,required:n.required,placeholder:n.placeholder,onChange:e=>i(Nn(n,e.target.value))}):n.type===`password`?(0,$.jsx)(Xe,{id:o,className:a,value:c,onChange:e=>i(Nn(n,e)),placeholder:n.placeholder,labels:de}):(0,$.jsx)(`input`,{id:o,className:Cn(),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(Nn(n,e.target.value))}),t[23]=a,t[24]=n,t[25]=c,t[26]=o,t[27]=i,t[28]=d):d=t[28];let f;t[29]===s?f=t[30]:(f=s?(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:s}):null,t[29]=s,t[30]=f);let p;return t[31]!==l||t[32]!==u||t[33]!==d||t[34]!==f?(p=(0,$.jsxs)(`div`,{className:l,children:[u,d,f]}),t[31]=l,t[32]=u,t[33]=d,t[34]=f,t[35]=p):p=t[35],p}function Gn(e){return(0,$.jsx)(_,{value:e.id,children:e.name},e.id)}function Kn(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 qn(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 Jn(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 A(N(`/api/config`),{method:`PATCH`,body:JSON.stringify({tools:{web:{region:t,search:n,blocklist:{enabled:e.blocklistEnabled,domains:e.blocklistDomains}}}})}),z()}async function Yn(e){let t=await A(N(`/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 Xn(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 Zn(){return F(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,U,`dark:border-edge`)}function Qn(){return F(H,V)}var $n=[`brave`,`tavily`,`bing`,`searxng`];function er(){return{type:`brave`,apiKey:``,url:``,disabled:!1}}var tr=me();function nr(){let e=k(M(e=>e.language)),t=e.webSearchSettings,n=e.logs,r=!!P(e=>e.token),[i,a]=(0,Q.useReducer)(tr,{form:null,baseline:null}),o=i.form,s=i.baseline,c=(0,Q.useRef)(!1),l=(0,Q.useRef)(o);l.current=o;let u=(0,Q.useRef)(null),{data:d,error:f,isLoading:p,mutate:m}=B(r);he({enabled:r,parsed:(0,Q.useMemo)(()=>d?.payload?.config===void 0?null:qn(d.payload.config),[d]),dirty:c.current,trackedParsedRef:u,dispatch:a,onResetDirty:()=>{c.current=!1}});let h=!!(r&&p&&d===void 0&&!f),v=f instanceof Error?f.message:f?String(f):null,y=(0,Q.useMemo)(()=>!o||!s?!1:JSON.stringify(o)!==JSON.stringify(s),[o,s]),b=(0,Q.useCallback)(e=>{c.current=!0,a({type:`patch`,patch:e})},[]),x=Tt({value:o,dirty:y,onSave:(0,Q.useCallback)(async e=>{try{await Jn(e),a({type:`saved`,value:e}),c.current=!!(l.current&&JSON.stringify(l.current)!==JSON.stringify(e))}catch(e){throw Error(e instanceof Error?e.message:t.saveError)}},[t.saveError])});return r?h?(0,$.jsx)(vt,{rows:3}):o?(0,$.jsxs)(`div`,{className:`flex flex-col gap-4`,onBlurCapture:x.onBlurCapture,children:[x.error?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:x.error}):null,(0,$.jsxs)(bt,{children:[(0,$.jsx)(yt,{icon:D,title:t.sectionRegion,subtitle:t.sectionRegionHint,trailing:(0,$.jsx)(wt,{status:x.status,error:x.error})}),(0,$.jsx)(`div`,{className:`flex max-w-md flex-col gap-4`,children:(0,$.jsx)(Xn,{label:t.regionLabel,description:t.regionDesc,children:(0,$.jsxs)(g,{className:Qn(),value:o.regionMode,onChange:e=>b({regionMode:e.target.value}),children:[(0,$.jsx)(_,{value:`auto`,children:t.regionAuto}),(0,$.jsx)(_,{value:`cn`,children:t.regionCn}),(0,$.jsx)(_,{value:`global`,children:t.regionGlobal})]})})})]}),(0,$.jsx)(Vt,{children:(0,$.jsxs)(bt,{children:[(0,$.jsx)(yt,{icon:be,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=>b({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)(Xn,{label:t.blocklistDomains,description:t.blocklistDomainsDesc,children:(0,$.jsx)(`textarea`,{className:F(Zn(),`min-h-[6rem] font-mono text-xs`),value:o.blocklistDomains.join(`
|
|
7
|
+
`),placeholder:t.blocklistDomainsPlaceholder,disabled:!o.blocklistEnabled,onChange:e=>{b({blocklistDomains:e.target.value.split(/\r?\n/).flatMap(e=>{let t=e.trim().toLowerCase();return t?[t]:[]})})}})})]})]})}),(0,$.jsxs)(bt,{children:[(0,$.jsx)(yt,{icon:D,title:t.sectionSearch,subtitle:t.sectionSearchHint}),(0,$.jsxs)(`div`,{className:`flex max-w-xl flex-col gap-6`,children:[(0,$.jsx)(Xn,{label:t.maxResultsLabel,description:t.maxResultsDesc,children:(0,$.jsx)(`input`,{type:`number`,min:1,max:50,className:Zn(),value:o.maxResults,onChange:e=>b({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)(rr,{row:n,providerIndex:r,labels:t,secretLabels:Le(e.providersSettings),onChange:e=>{let t=[...o.providers];t[r]=e,b({providers:t})},onRemove:()=>{b({providers:o.providers.filter((e,t)=>t!==r)})}},`${n.type}:${n.url}:${n.apiKey}:${n.disabled}`)),(0,$.jsxs)(L,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5 text-sm`,onClick:()=>b({providers:[...o.providers,er()]}),children:[(0,$.jsx)(E,{className:`size-4`}),t.addProvider]})]})]})]}),(0,$.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:t.footerHint})]}):(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:v??t.loadError}),(0,$.jsx)(L,{type:`button`,variant:`secondary`,onClick:()=>void m(),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 rr(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=()=>Yn(r).then(ir),t[0]=r,t[1]=c);let l=c,u;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(u=F(Qn(),`min-w-[8rem]`),t[2]=u):u=t[2];let d=n.type,f;t[3]!==o||t[4]!==n?(f=e=>o({...n,type:e.target.value,url:e.target.value===`searxng`?n.url:``}),t[3]=o,t[4]=n,t[5]=f):f=t[5];let p;t[6]===i.providerTypes?p=t[7]:(p=$n.map(e=>(0,$.jsx)(_,{value:e,children:i.providerTypes[e]},e)),t[6]=i.providerTypes,t[7]=p);let m;t[8]!==n.type||t[9]!==f||t[10]!==p?(m=(0,$.jsx)(g,{className:u,value:d,onChange:f,children:p}),t[8]=n.type,t[9]=f,t[10]=p,t[11]=m):m=t[11];let h;t[12]!==o||t[13]!==n?(h=e=>o({...n,disabled:e.target.checked}),t[12]=o,t[13]=n,t[14]=h):h=t[14];let v;t[15]!==n.disabled||t[16]!==h?(v=(0,$.jsx)(`input`,{type:`checkbox`,className:`size-3.5 rounded border-edge`,checked:n.disabled,onChange:h}),t[15]=n.disabled,t[16]=h,t[17]=v):v=t[17];let y;t[18]!==i.disabled||t[19]!==v?(y=(0,$.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1.5 text-xs text-fg-muted`,children:[v,i.disabled]}),t[18]=i.disabled,t[19]=v,t[20]=y):y=t[20];let b;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,$.jsx)(ve,{className:`size-4`}),t[21]=b):b=t[21];let x;t[22]===s?x=t[23]:(x=(0,$.jsx)(L,{type:`button`,variant:`ghost`,className:`h-8 px-2 text-fg-muted`,onClick:s,children:b}),t[22]=s,t[23]=x);let S;t[24]!==x||t[25]!==y?(S=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[y,x]}),t[24]=x,t[25]=y,t[26]=S):S=t[26];let C;t[27]!==S||t[28]!==m?(C=(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[m,S]}),t[27]=S,t[28]=m,t[29]=C):C=t[29];let w;t[30]!==i.urlDesc||t[31]!==i.urlLabel||t[32]!==o||t[33]!==n?(w=n.type===`searxng`?(0,$.jsx)(Xn,{label:i.urlLabel,description:i.urlDesc,children:(0,$.jsx)(`input`,{type:`url`,className:Zn(),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]=w):w=t[34];let T;t[35]!==o||t[36]!==n?(T=e=>o({...n,apiKey:e}),t[35]=o,t[36]=n,t[37]=T):T=t[37];let E;t[38]!==i.keyPlaceholder||t[39]!==i.keyPlaceholderMasked||t[40]!==i.saveError||t[41]!==l||t[42]!==n.apiKey||t[43]!==a||t[44]!==T?(E=(0,$.jsx)(Xe,{value:n.apiKey,onChange:T,placeholder:i.keyPlaceholder,labels:a,reveal:l,loadFailedLabel:i.saveError,notInConfigFile:i.keyPlaceholderMasked}),t[38]=i.keyPlaceholder,t[39]=i.keyPlaceholderMasked,t[40]=i.saveError,t[41]=l,t[42]=n.apiKey,t[43]=a,t[44]=T,t[45]=E):E=t[45];let D;t[46]!==i.apiKeyDesc||t[47]!==i.apiKeyLabel||t[48]!==E?(D=(0,$.jsx)(Xn,{label:i.apiKeyLabel,description:i.apiKeyDesc,children:E}),t[46]=i.apiKeyDesc,t[47]=i.apiKeyLabel,t[48]=E,t[49]=D):D=t[49];let O;return t[50]!==C||t[51]!==w||t[52]!==D?(O=(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-xl bg-surface-panel/70 p-4 shadow-surface`,children:[C,w,D]}),t[50]=C,t[51]=w,t[52]=D,t[53]=O):O=t[53],O}function ir(e){return e.apiKey??null}var ar=[`common`,`domestic`,`specialty`,`enterprise`,`oauth`,`extension`];function or(e){let t=new Map;for(let e of ar)t.set(e,[]);for(let n of e){let e=n.category||`specialty`,r=t.get(e)??[];r.push(n),t.set(e,r)}return t}var sr=`xopc-cloud`;function cr(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,m]=(0,Q.useState)(u),[g,_]=(0,Q.useState)(``),v;t[1]===r?v=t[2]:(v=e=>{e||window.setTimeout(()=>{m({type:`pick`}),_(``)},200),r(e)},t[1]=r,t[2]=v);let y=v,b;t[3]!==y||t[4]!==c?(b=()=>{c(),y(!1)},t[3]=y,t[4]=c,t[5]=b):b=t[5];let x=b,S;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,$.jsx)(l,{className:F(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,te)}),t[6]=S):S=t[6];let C;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(C=F(`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`,K),t[7]=C):C=t[7];let w;t[8]!==i||t[9]!==a||t[10]!==x||t[11]!==o||t[12]!==s||t[13]!==g||t[14]!==d.presetKey||t[15]!==d.providerId||t[16]!==d.type?(w=(0,$.jsxs)(f,{children:[S,(0,$.jsx)(p,{className:C,children:d.type===`pick`?(0,$.jsx)(ur,{builtinRows:i,searchQuery:g,onSearchChange:_,labels:o,onPickBuiltin:e=>{let t=Je(e);m(t?{type:`custom`,presetKey:t}:{type:`builtin`,providerId:e})},onPickCustom:()=>m({type:`custom`})}):d.type===`builtin`?(0,$.jsx)(mr,{providerId:d.providerId,builtinRows:i,labels:o,language:s,onBack:()=>m({type:`pick`}),onSaved:x}):(0,$.jsx)(_r,{initialPresetKey:d.presetKey,customConfig:a,labels:o,language:s,onBack:()=>m({type:`pick`}),onSaved:x})})]}),t[8]=i,t[9]=a,t[10]=x,t[11]=o,t[12]=s,t[13]=g,t[14]=d.presetKey,t[15]=d.providerId,t[16]=d.type,t[17]=w):w=t[17];let T;return t[18]!==y||t[19]!==n||t[20]!==w?(T=(0,$.jsx)(h,{open:n,onOpenChange:y,children:w}),t[18]=y,t[19]=n,t[20]=w,t[21]=T):T=t[21],T}function lr(e){let t=(0,Z.c)(4),{label:n}=e,r;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(r=F(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,R.press),t[0]=r):r=t[0];let i;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(O,{className:`size-4`,"aria-hidden":!0}),t[1]=i):i=t[1];let a;return t[2]===n?a=t[3]:(a=(0,$.jsx)(d,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:r,"aria-label":n,children:i})}),t[2]=n,t[3]=a),a}function ur(e){let t=(0,Z.c)(49),{builtinRows:n,searchQuery:r,onSearchChange:i,labels:a,onPickBuiltin:o,onPickCustom:s}=e,c;t[0]===r?c=t[1]:(c=r.trim().toLowerCase(),t[0]=r,t[1]=c);let l=c,u;bb0:{if(!l){u=n;break bb0}let e;if(t[2]!==n||t[3]!==l){let r;t[5]===l?r=t[6]:(r=e=>{let t=De[e.id]?.aliases??[];return e.id.toLowerCase().includes(l)||e.name.toLowerCase().includes(l)||t.some(e=>e.toLowerCase().includes(l))},t[5]=l,t[6]=r),e=n.filter(r),t[2]=n,t[3]=l,t[4]=e}else e=t[4];u=e}let d=u,f;t[7]===d?f=t[8]:(f=d.find(fr),t[7]=d,t[8]=f);let p=f,h;t[9]===d?h=t[10]:(h=or(d.filter(dr)),t[9]=d,t[10]=h);let g=h,_;t[11]===a.step1Title?_=t[12]:(_=(0,$.jsx)(m,{className:`min-w-0 flex-1 text-base font-semibold text-fg`,children:a.step1Title}),t[11]=a.step1Title,t[12]=_);let v;t[13]===a.close?v=t[14]:(v=(0,$.jsx)(lr,{label:a.close}),t[13]=a.close,t[14]=v);let y;t[15]!==_||t[16]!==v?(y=(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b border-edge-subtle px-5 py-4`,children:[_,v]}),t[15]=_,t[16]=v,t[17]=y):y=t[17];let b;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,$.jsx)(D,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-fg-subtle`,strokeWidth:1.75,"aria-hidden":!0}),t[18]=b):b=t[18];let x;t[19]===i?x=t[20]:(x=e=>i(e.target.value),t[19]=i,t[20]=x);let S=a.searchPlaceholder,w;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(w=F(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-10 pr-3 text-sm text-fg placeholder:text-fg-subtle`,U),t[21]=w):w=t[21];let T;t[22]!==a.searchPlaceholder||t[23]!==r||t[24]!==x?(T=(0,$.jsx)(`div`,{className:`px-5 pt-3`,children:(0,$.jsxs)(`div`,{className:`relative`,children:[b,(0,$.jsx)(`input`,{type:`search`,value:r,onChange:x,placeholder:S,autoComplete:`off`,className:w})]})}),t[22]=a.searchPlaceholder,t[23]=r,t[24]=x,t[25]=T):T=t[25];let E;t[26]!==a.recommended||t[27]!==o||t[28]!==p?(E=p?(0,$.jsxs)(`div`,{className:`mb-2`,children:[(0,$.jsx)(`p`,{className:`mb-1 px-1 text-[11px] font-semibold uppercase tracking-wide text-fg-subtle`,children:a.recommended}),(0,$.jsx)(pr,{row:p,onPick:o})]}):null,t[26]=a.recommended,t[27]=o,t[28]=p,t[29]=E):E=t[29];let O;t[30]!==a.addCustom||t[31]!==a.customDescription||t[32]!==s||t[33]!==l?(O=l?null:(0,$.jsxs)(`button`,{type:`button`,onClick:s,className:F(`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`,R.press),children:[(0,$.jsx)(C,{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)(ge,{className:`size-4 shrink-0 text-fg-subtle`,"aria-hidden":!0})]}),t[30]=a.addCustom,t[31]=a.customDescription,t[32]=s,t[33]=l,t[34]=O):O=t[34];let k;t[35]!==d.length||t[36]!==g||t[37]!==a.categories||t[38]!==a.noResults||t[39]!==o?(k=d.length===0?(0,$.jsx)(`p`,{className:`py-6 text-center text-sm text-fg-muted`,children:a.noResults}):(0,$.jsx)(`div`,{className:`flex flex-col gap-2`,children:ar.map(e=>{let t=g.get(e)??[];return t.length===0?null:(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`mb-1 px-1 text-[11px] font-semibold uppercase tracking-wide text-fg-subtle`,children:a.categories[e]??e}),(0,$.jsx)(`div`,{className:`flex flex-col gap-0.5`,children:t.map(e=>(0,$.jsx)(pr,{row:e,onPick:o},e.id))})]},e)})}),t[35]=d.length,t[36]=g,t[37]=a.categories,t[38]=a.noResults,t[39]=o,t[40]=k):k=t[40];let A;t[41]!==E||t[42]!==O||t[43]!==k?(A=(0,$.jsxs)(`div`,{className:`flex-1 overflow-y-auto px-5 py-3`,children:[E,O,k]}),t[41]=E,t[42]=O,t[43]=k,t[44]=A):A=t[44];let j;return t[45]!==T||t[46]!==A||t[47]!==y?(j=(0,$.jsxs)($.Fragment,{children:[y,T,A]}),t[45]=T,t[46]=A,t[47]=y,t[48]=j):j=t[48],j}function dr(e){return e.id!==sr}function fr(e){return e.id===sr}function pr(e){let t=(0,Z.c)(12),{row:n,onPick:r}=e,i;t[0]!==r||t[1]!==n.id?(i=()=>r(n.id),t[0]=r,t[1]=n.id,t[2]=i):i=t[2];let a;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(a=F(`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`,R.press),t[3]=a):a=t[3];let o;t[4]===n.name?o=t[5]:(o=(0,$.jsx)(`span`,{className:`truncate text-sm text-fg`,children:n.name}),t[4]=n.name,t[5]=o);let s;t[6]===n.configured?s=t[7]:(s=n.configured?(0,$.jsx)(y,{className:`size-3.5 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):null,t[6]=n.configured,t[7]=s);let c;return t[8]!==i||t[9]!==o||t[10]!==s?(c=(0,$.jsxs)(`button`,{type:`button`,onClick:i,className:a,children:[o,s]}),t[8]=i,t[9]=o,t[10]=s,t[11]=c):c=t[11],c}function mr({providerId:e,builtinRows:t,labels:n,language:r,onBack:i,onSaved:a}){let o=t.find(t=>t.id===e),s=De[e],[c,l]=(0,Q.useState)(``),[u,d]=(0,Q.useState)(!1),[f,p]=(0,Q.useState)(null),[h,g]=(0,Q.useState)(!1),_=(0,Q.useRef)(null),v=k(r).providersSettings,b=Le(v),x=(0,Q.useMemo)(()=>Te(e,r),[e,r]),S=o?.supportsApiKey!==!1,C=o?.supportsOAuth===!0,[T,E]=(0,Q.useState)(null),[D,O]=(0,Q.useState)(null),[A,j]=(0,Q.useState)(`idle`),[M,N]=(0,Q.useState)(null),[P,I]=(0,Q.useState)(null),[ee,z]=(0,Q.useState)(null),[B,V]=(0,Q.useState)(``),H=(0,Q.useRef)(null),W=(0,Q.useRef)(null),G=A===`waiting`||A===`waiting_code`;(0,Q.useEffect)(()=>{if(!T||!G)return;let t=window.setInterval(()=>{(async()=>{try{let n=await ce(T);n.status===`waiting_auth`||n.status===`waiting_code`?(j(n.status===`waiting_code`?`waiting_code`:`waiting`),O(n.message??null),N(n.authUrl??null),I(n.instructions??null),z(n.deviceCode??null),n.authUrl&&n.authUrl!==W.current&&(W.current=n.authUrl,xt(n.authUrl,H.current).catch(()=>{}))):n.status===`completed`?(window.clearInterval(t),Ct(H.current),H.current=null,e===`xopc-cloud`&&await J(),j(`success`),O(n.message??v.saved),window.setTimeout(a,600)):(n.status===`failed`||n.status===`cancelled`)&&(window.clearInterval(t),Ct(H.current),H.current=null,j(`error`),O(n.error??n.message??v.revokeFailed))}catch{}})()},1e3);return()=>window.clearInterval(t)},[T,G,a,e,v.revokeFailed,v.saved]),(0,Q.useEffect)(()=>()=>{T&&oe(T).catch(()=>{})},[T]),(0,Q.useEffect)(()=>()=>{Ct(H.current),H.current=null},[]);let K=async()=>{Ct(H.current),H.current=St(),W.current=null,j(`waiting`),O(v.oauthStarting),N(null),I(null),z(null),p(null);try{E((await ie(e)).sessionId)}catch(e){Ct(H.current),H.current=null,j(`error`),O(e instanceof Error?e.message:v.revokeFailed)}},te=async()=>{if(T){try{await le(T)}catch{}Ct(H.current),H.current=null,W.current=null,j(`idle`),O(null),E(null),N(null),I(null),z(null)}},q=async()=>{if(!(!T||!B.trim()))try{await se(T,B.trim()),V(``),O(v.oauthProcessingCode)}catch(e){j(`error`),O(e instanceof Error?e.message:v.revokeFailed)}},ne=async()=>{let t=c.trim();if(!(!t||!S)){d(!0),p(null);try{await je({[e]:t}),g(!0),window.setTimeout(a,600)}catch(e){p(e instanceof Error?e.message:n.saveError)}finally{d(!1)}}};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-edge-subtle px-5 py-4`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:i,className:F(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,R.press),"aria-label":n.back,children:(0,$.jsx)(ge,{className:`size-4 rotate-180`,"aria-hidden":!0})}),(0,$.jsx)(m,{className:`min-w-0 flex-1 text-base font-semibold text-fg`,children:o?.name??e}),(0,$.jsx)(lr,{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)(Xe,{id:`builtin-api-key`,value:c,onChange:l,placeholder:n.apiKeyPlaceholder,labels:b,inputRef:_,onKeyDown:e=>{e.key===`Enter`&&ne()}})]}):null,C?(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:v.oauth}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:v.oauthHint})]}),(0,$.jsxs)(L,{type:`button`,variant:`primary`,className:`gap-1.5`,disabled:G,onClick:()=>void K(),children:[G?(0,$.jsx)(w,{className:`size-3.5 animate-spin`,"aria-hidden":!0}):null,v.oauth]})]}),D?(0,$.jsx)(`p`,{className:F(`text-xs`,A===`error`?`text-red-600 dark:text-red-400`:`text-fg-muted`),children:D}):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:[v.openAuthPage,(0,$.jsx)(`span`,{className:`size-3`,"aria-hidden":!0,children:`↗`})]}):null,(0,$.jsx)(L,{type:`button`,variant:`secondary`,onClick:()=>void te(),children:v.cancelOAuth})]}):null,P?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:P}):null,ee?(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:v.deviceCodeLabel}),(0,$.jsx)(`code`,{className:`mt-1 block select-all font-mono text-lg font-semibold tracking-widest text-fg`,children:ee}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:v.deviceCodeHint})]}):null,A===`waiting_code`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,$.jsx)(`input`,{type:`text`,value:B,onChange:e=>V(e.target.value),onKeyDown:e=>e.key===`Enter`&&void q(),placeholder:v.pasteRedirectUrl,className:F(`min-w-0 flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,U)}),(0,$.jsx)(L,{type:`button`,variant:`primary`,onClick:()=>void q(),children:v.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:[ke(e,n),(0,$.jsx)(`span`,{className:`size-3`,"aria-hidden":!0,children:`↗`})]},e))}):null,f?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:f}):null,(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2`,children:[(0,$.jsx)(L,{type:`button`,variant:`secondary`,onClick:i,children:n.cancel}),S?(0,$.jsx)(L,{type:`button`,variant:`primary`,disabled:!c.trim()||u||h,onClick:()=>void ne(),children:h?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(y,{className:`size-3.5`,"aria-hidden":!0}),n.saved]}):u?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(w,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),n.saving]}):n.save}):null]})]})]})}function hr(e=`custom`){if(e!==`custom`&&Ne[e]){let t=Ne[e].config;return{preset:e,providerId:Ie(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 gr(e,t){switch(t.type){case`applyPreset`:return t.key===`custom`?{...e,preset:`custom`,error:null}:Ne[t.key]?hr(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 _r({initialPresetKey:e,customConfig:t,labels:n,language:r,onBack:i,onSaved:a}){let[o,s]=(0,Q.useReducer)(gr,void 0,()=>hr(e)),[c,l]=(0,Q.useState)(!1),[u,d]=(0,Q.useState)(!1),f=Le(k(r).providersSettings),{preset:p,providerId:h,baseUrl:v,api:y,apiKey:b,modelIds:x,error:S}=o,C=async()=>{let e=h.trim(),r=v.trim();if(!e){s({type:`setError`,value:n.providerIdRequired});return}if(!r){s({type:`setError`,value:n.baseUrlRequired});return}let i=x.map(e=>e.trim()).filter(Boolean);l(!0),s({type:`setError`,value:null});try{let n=t?.providers??{},o=p===`custom`?void 0:Ne[p]?.config,s={...o??{},baseUrl:r,api:y,apiKey:b.trim()||void 0,models:i.map(e=>o?.models?.find(t=>t.id===e)??{id:e})};await it({providers:{...n,[e]:s}}),a()}catch(e){s({type:`setError`,value:e instanceof Error?e.message:n.saveError})}finally{l(!1)}},T=async()=>{let e=h.trim()||Ie(p)||`custom`,t=v.trim();if(!t){s({type:`setError`,value:n.baseUrlRequired});return}d(!0),s({type:`setError`,value:null});try{let r=p===`custom`?void 0:Ne[p]?.config,i=(await Re({providerId:e,baseUrl:t,apiKey:b.trim()||void 0,api:y,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{d(!1)}},A=h.trim()&&v.trim(),j=(y===`openai-completions`||y===`openai-responses`)&&v.trim();return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-b border-edge-subtle px-5 py-4`,children:[(0,$.jsx)(`button`,{type:`button`,onClick:i,className:F(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,R.press),"aria-label":n.back,children:(0,$.jsx)(ge,{className:`size-4 rotate-180`,"aria-hidden":!0})}),(0,$.jsx)(m,{className:`min-w-0 flex-1 text-base font-semibold text-fg`,children:n.step2CustomTitle}),(0,$.jsx)(lr,{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)(g,{id:`custom-preset`,value:p,onChange:e=>s({type:`applyPreset`,key:e.target.value}),className:Ve(),children:[(0,$.jsx)(_,{value:`custom`,children:n.presetCustom}),Qe.map(e=>(0,$.jsx)(_,{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:h,onChange:e=>s({type:`setProviderId`,value:e.target.value}),placeholder:n.providerIdPlaceholder,className:F(`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,U)})]}),(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`custom-base-url`,className:`text-sm font-medium text-fg`,children:n.baseUrlLabel}),(0,$.jsx)(`input`,{id:`custom-base-url`,type:`url`,autoComplete:`off`,value:v,onChange:e=>s({type:`setBaseUrl`,value:e.target.value}),placeholder:n.baseUrlPlaceholder,className:F(`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,U)})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`custom-api-type`,className:`text-sm font-medium text-fg`,children:n.apiTypeLabel}),(0,$.jsx)(g,{id:`custom-api-type`,value:y,onChange:e=>s({type:`setApi`,value:e.target.value}),className:Ve(),children:ye.map(e=>(0,$.jsx)(_,{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)(Xe,{id:`custom-api-key`,value:b,onChange:e=>s({type:`setApiKey`,value:e}),placeholder:n.apiKeyPlaceholder,labels:f})]}),(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)(L,{type:`button`,variant:`secondary`,className:`gap-1.5`,disabled:!j||u,onClick:()=>void T(),children:[u?(0,$.jsx)(w,{className:`size-3.5 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(D,{className:`size-3.5`,"aria-hidden":!0}),u?n.discoveringModels:n.discoverModels]})]}),x.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:F(`flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,U)}),x.length>1?(0,$.jsx)(`button`,{type:`button`,onClick:()=>s({type:`removeModelSlot`,index:t}),className:F(`rounded-lg p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,R.press),children:(0,$.jsx)(O,{className:`size-3.5`,"aria-hidden":!0})}):null]},e||`model-slot-${t}`)),(0,$.jsxs)(L,{type:`button`,variant:`ghost`,className:`w-fit gap-1.5 text-fg-muted`,onClick:()=>s({type:`addModelSlot`}),children:[(0,$.jsx)(E,{className:`size-3.5`,"aria-hidden":!0}),n.addModel]})]}),S?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:S}):null]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-end gap-2 border-t border-edge-subtle px-5 py-3`,children:[(0,$.jsx)(L,{type:`button`,variant:`secondary`,onClick:i,children:n.cancel}),(0,$.jsx)(L,{type:`button`,variant:`primary`,disabled:!A||c,onClick:()=>void C(),children:c?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(w,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),n.saving]}):n.save})]})]})}function vr(){let e=(0,Z.c)(31),t=P(Cr),n=!!t,{data:r,isLoading:i}=B(n),a;e[0]===n?a=e[1]:(a=n?N(`/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}=I(a,o,s),u;e[5]===Symbol.for(`react.memo_cache_sentinel`)?(u={revalidateOnFocus:!1},e[5]=u):u=e[5];let{data:d,isLoading:f}=I(n?ne:null,Sr,u),p;e[6]===d?p=e[7]:(p=d===void 0?[]:d,e[6]=d,e[7]=p);let m=p,h;e[8]===Symbol.for(`react.memo_cache_sentinel`)?(h={revalidateOnFocus:!1},e[8]=h):h=e[8];let{data:g}=I(n?Y:null,xr,h),_;bb0:{if(!c||r===void 0){let t;e[9]===Symbol.for(`react.memo_cache_sentinel`)?(t=[],e[9]=t):t=e[9],_=t;break bb0}let t;e[10]!==r?.payload?.config||e[11]!==c||e[12]!==m?(t=He(c,pt(r?.payload?.config),m),e[10]=r?.payload?.config,e[11]=c,e[12]=m,e[13]=t):t=e[13],_=t}let v=_,y;bb1:{if(!g){y=null;break bb1}let t;e[14]===g.config?t=e[15]:(t=Ze(g.config),e[14]=g.config,e[15]=t),y=t}let b=y,x;if(e[16]!==v||e[17]!==b||e[18]!==c||e[19]!==m){x=[];let t=new Set((c??[]).filter(br).map(yr)),n;e[21]===b?n=e[22]:(n=new Set(b?Object.keys(b.providers):[]),e[21]=b,e[22]=n);let r=n;for(let e of v){if(!t.has(e.id))continue;let n=r.has(e.id),i=n?b.providers[e.id]?.models?.length??0:m.filter(t=>t.provider===e.id).length;x.push({id:e.id,name:e.name,configured:!0,isCustom:n,modelCount:i})}if(b){let t;e[23]===b.providers?t=e[24]:(t=Object.entries(b.providers),e[23]=b.providers,e[24]=t);for(let[e,n]of t)x.some(t=>t.id===e)||x.push({id:e,name:e,configured:!0,isCustom:!0,modelCount:n.models?.length??0})}e[16]=v,e[17]=b,e[18]=c,e[19]=m,e[20]=x}else x=e[20];let S=x,C=i||l||f,w;return e[25]!==v||e[26]!==S||e[27]!==b||e[28]!==C||e[29]!==m?(w={cards:S,loading:C,builtinRows:v,customConfig:b,allModels:m},e[25]=v,e[26]=S,e[27]=b,e[28]=C,e[29]=m,e[30]=w):w=e[30],w}function yr(e){return e.id}function br(e){return e.configured}function xr(){return st()}function Sr(){return q()}function Cr(e){return e.token}function wr(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)(G,{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(Er)})]}),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)(E,{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)(L,{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)(L,{type:`button`,variant:`primary`,className:`mt-4 gap-1.5`,onClick:i,children:[(0,$.jsx)(E,{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)(Dr,{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 Er(e){return(0,$.jsx)(G,{className:`h-32 rounded-2xl`},e)}function Dr(e){let t=(0,Z.c)(28),{card:n,labels:r,onManage:i}=e,a;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(a=F(`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`,R.pressCard),t[0]=a):a=t[0];let o;t[1]===n.name?o=t[2]:(o=(0,$.jsx)(`span`,{className:`truncate text-sm font-semibold text-fg`,children:n.name}),t[1]=n.name,t[2]=o);let s;t[3]!==n.isCustom||t[4]!==r.custom?(s=n.isCustom?(0,$.jsx)(`span`,{className:`shrink-0 rounded bg-surface-hover px-1.5 py-0.5 text-[10px] font-medium text-fg-subtle`,children:r.custom}):null,t[3]=n.isCustom,t[4]=r.custom,t[5]=s):s=t[5];let c;t[6]!==o||t[7]!==s?(c=(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[o,s]}),t[6]=o,t[7]=s,t[8]=c):c=t[8];let l;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,$.jsx)(y,{className:`size-4 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}),t[9]=l):l=t[9];let u;t[10]===c?u=t[11]:(u=(0,$.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[c,l]}),t[10]=c,t[11]=u);let d;t[12]!==n.modelCount||t[13]!==r.modelsCount||t[14]!==r.noModels?(d=n.modelCount>0?r.modelsCount.replace(`{{count}}`,String(n.modelCount)):r.noModels,t[12]=n.modelCount,t[13]=r.modelsCount,t[14]=r.noModels,t[15]=d):d=t[15];let f;t[16]===d?f=t[17]:(f=(0,$.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:d}),t[16]=d,t[17]=f);let p;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,$.jsx)(Ae,{className:`size-3`,"aria-hidden":!0}),t[18]=p):p=t[18];let m;t[19]===r.manage?m=t[20]:(m=(0,$.jsxs)(`span`,{className:`flex items-center gap-1 text-xs font-medium text-accent-fg opacity-0 transition-opacity group-hover:opacity-100`,children:[p,r.manage]}),t[19]=r.manage,t[20]=m);let h;t[21]!==m||t[22]!==f?(h=(0,$.jsxs)(`div`,{className:`mt-2.5 flex items-center justify-between`,children:[f,m]}),t[21]=m,t[22]=f,t[23]=h):h=t[23];let g;return t[24]!==i||t[25]!==h||t[26]!==u?(g=(0,$.jsxs)(`button`,{type:`button`,onClick:i,className:a,children:[u,h]}),t[24]=i,t[25]=h,t[26]=u,t[27]=g):g=t[27],g}function Or(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}:ue(``),t[0]=n,t[1]=c);let[l,u]=(0,Q.useState)(c),[f,p]=(0,Q.useState)(kr),h;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(h=(e,t)=>{u(n=>({...n,[e]:t})),p(t=>{let n=new Map(t);return n.delete(e),n})},t[2]=h):h=t[2];let v=h,y;t[3]!==l.contextWindow||t[4]!==l.id||t[5]!==l.maxTokens||t[6]!==s.modelIdRequired||t[7]!==s.mustBePositive?(y=()=>{let e=new Map;return(l.id||``).trim()||e.set(`id`,s.modelIdRequired),l.contextWindow!==void 0&&l.contextWindow<=0&&e.set(`contextWindow`,s.mustBePositive),l.maxTokens!==void 0&&l.maxTokens<=0&&e.set(`maxTokens`,s.mustBePositive),p(e),e.size===0},t[3]=l.contextWindow,t[4]=l.id,t[5]=l.maxTokens,t[6]=s.modelIdRequired,t[7]=s.mustBePositive,t[8]=y):y=t[8];let b=y,x;t[9]!==l||t[10]!==o||t[11]!==a||t[12]!==b?(x=()=>{if(!b())return;let e=(l.id||``).trim();a({...l,id:e,name:l.name?.trim()||e,reasoning:l.reasoning||!1,input:l.input||[`text`],contextWindow:l.contextWindow??128e3,maxTokens:l.maxTokens??16384,cost:{input:l.cost?.input??0,output:l.cost?.output??0,cacheRead:l.cost?.cacheRead??0,cacheWrite:l.cost?.cacheWrite??0}}),o()},t[9]=l,t[10]=o,t[11]=a,t[12]=b,t[13]=x):x=t[13];let S=x,C=l,w;t[14]===C?w=t[15]:(w=dt(C),t[14]=C,t[15]=w);let T=w,E=r?s.addModelTitle:s.editModelTitle,D;t[16]===E?D=t[17]:(D=(0,$.jsx)(m,{className:`text-base font-semibold text-fg`,children:E}),t[16]=E,t[17]=D);let k;t[18]!==s.modelProviderLabel||t[19]!==i?(k=i?(0,$.jsxs)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:[s.modelProviderLabel,`: `,i]}):null,t[18]=s.modelProviderLabel,t[19]=i,t[20]=k):k=t[20];let A;t[21]!==D||t[22]!==k?(A=(0,$.jsxs)(`div`,{children:[D,k]}),t[21]=D,t[22]=k,t[23]=A):A=t[23];let j;t[24]===Symbol.for(`react.memo_cache_sentinel`)?(j=F(ee,`p-1.5 hover:bg-surface-base`),t[24]=j):j=t[24];let M;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(M=(0,$.jsx)(O,{className:`size-4`}),t[25]=M):M=t[25];let N;t[26]===s.close?N=t[27]:(N=(0,$.jsx)(d,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:j,"aria-label":s.close,children:M})}),t[26]=s.close,t[27]=N);let P;t[28]!==A||t[29]!==N?(P=(0,$.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[A,N]}),t[28]=A,t[29]=N,t[30]=P):P=t[30];let I;t[31]===Symbol.for(`react.memo_cache_sentinel`)?(I=(0,$.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`}),t[31]=I):I=t[31];let R;t[32]===s.modelId?R=t[33]:(R=(0,$.jsxs)(`label`,{className:`mb-1 block text-xs font-medium text-fg`,children:[s.modelId,I]}),t[32]=s.modelId,t[33]=R);let z;t[34]===f?z=t[35]:(z=F(ot(),f.has(`id`)&&`border-red-500`),t[34]=f,t[35]=z);let B=l.id||``,V;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(V=e=>v(`id`,e.target.value),t[36]=V):V=t[36];let H=!r,U;t[37]!==z||t[38]!==B||t[39]!==H?(U=(0,$.jsx)(`input`,{className:z,value:B,onChange:V,placeholder:`e.g. llama3.1:8b`,disabled:H}),t[37]=z,t[38]=B,t[39]=H,t[40]=U):U=t[40];let W;t[41]===f?W=t[42]:(W=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]=W);let G;t[43]!==R||t[44]!==U||t[45]!==W?(G=(0,$.jsxs)(`div`,{children:[R,U,W]}),t[43]=R,t[44]=U,t[45]=W,t[46]=G):G=t[46];let K;t[47]===s.displayName?K=t[48]:(K=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.displayName}),t[47]=s.displayName,t[48]=K);let te;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(te=ot(),t[49]=te):te=t[49];let q=l.name||``,ne;t[50]===Symbol.for(`react.memo_cache_sentinel`)?(ne=e=>v(`name`,e.target.value),t[50]=ne):ne=t[50];let J;t[51]===q?J=t[52]:(J=(0,$.jsx)(`input`,{className:te,value:q,onChange:ne}),t[51]=q,t[52]=J);let Y;t[53]!==K||t[54]!==J?(Y=(0,$.jsxs)(`div`,{children:[K,J]}),t[53]=K,t[54]=J,t[55]=Y):Y=t[55];let X;t[56]===s.inputTypes?X=t[57]:(X=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.inputTypes}),t[56]=s.inputTypes,t[57]=X);let re;t[58]===Symbol.for(`react.memo_cache_sentinel`)?(re=Ve(),t[58]=re):re=t[58];let ie;t[59]===Symbol.for(`react.memo_cache_sentinel`)?(ie=e=>v(`input`,Fe(e.target.value)),t[59]=ie):ie=t[59];let ae;t[60]===s?ae=t[61]:(ae=Ge.map(e=>(0,$.jsx)(_,{value:e.value,children:s[e.labelKey]},e.value)),t[60]=s,t[61]=ae);let oe;t[62]!==T||t[63]!==ae?(oe=(0,$.jsx)(g,{className:re,value:T,onChange:ie,children:ae}),t[62]=T,t[63]=ae,t[64]=oe):oe=t[64];let se;t[65]!==X||t[66]!==oe?(se=(0,$.jsxs)(`div`,{children:[X,oe]}),t[65]=X,t[66]=oe,t[67]=se):se=t[67];let ce=l.reasoning||!1,le;t[68]===Symbol.for(`react.memo_cache_sentinel`)?(le=e=>v(`reasoning`,e.target.checked),t[68]=le):le=t[68];let de;t[69]===ce?de=t[70]:(de=(0,$.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:ce,onChange:le}),t[69]=ce,t[70]=de);let fe;t[71]!==s.reasoning||t[72]!==de?(fe=(0,$.jsxs)(`label`,{className:`mt-6 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[de,s.reasoning]}),t[71]=s.reasoning,t[72]=de,t[73]=fe):fe=t[73];let pe;t[74]!==se||t[75]!==fe?(pe=(0,$.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[se,fe]}),t[74]=se,t[75]=fe,t[76]=pe):pe=t[76];let me;t[77]===s.contextWindow?me=t[78]:(me=(0,$.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.contextWindow}),t[77]=s.contextWindow,t[78]=me);let he;t[79]===f?he=t[80]:(he=F(ot(),f.has(`contextWindow`)&&`border-red-500`),t[79]=f,t[80]=he);let ge=l.contextWindow??128e3,_e;t[81]===Symbol.for(`react.memo_cache_sentinel`)?(_e=e=>v(`contextWindow`,parseInt(e.target.value,10)||0),t[81]=_e):_e=t[81];let ve;t[82]!==he||t[83]!==ge?(ve=(0,$.jsx)(`input`,{type:`number`,min:1,className:he,value:ge,onChange:_e}),t[82]=he,t[83]=ge,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]!==me||t[88]!==ve||t[89]!==ye?(be=(0,$.jsxs)(`div`,{children:[me,ve,ye]}),t[87]=me,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=F(ot(),f.has(`maxTokens`)&&`border-red-500`),t[93]=f,t[94]=Se);let Ce=l.maxTokens??16384,we;t[95]===Symbol.for(`react.memo_cache_sentinel`)?(we=e=>v(`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 je;t[112]===Symbol.for(`react.memo_cache_sentinel`)?(je=ot(),t[112]=je):je=t[112];let Me=l.cost?.input??0,Ne;t[113]===l.cost?Ne=t[114]:(Ne=e=>v(`cost`,{...l.cost,input:parseFloat(e.target.value)||0,output:l.cost?.output??0,cacheRead:l.cost?.cacheRead??0,cacheWrite:l.cost?.cacheWrite??0}),t[113]=l.cost,t[114]=Ne);let Pe;t[115]!==Me||t[116]!==Ne?(Pe=(0,$.jsx)(`input`,{type:`number`,step:`any`,min:0,className:je,value:Me,onChange:Ne}),t[115]=Me,t[116]=Ne,t[117]=Pe):Pe=t[117];let Ie;t[118]!==Ae||t[119]!==Pe?(Ie=(0,$.jsxs)(`div`,{children:[Ae,Pe]}),t[118]=Ae,t[119]=Pe,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=ot(),t[123]=Re):Re=t[123];let ze=l.cost?.output??0,Be;t[124]===l.cost?Be=t[125]:(Be=e=>v(`cost`,{...l.cost,input:l.cost?.input??0,output:parseFloat(e.target.value)||0,cacheRead:l.cost?.cacheRead??0,cacheWrite:l.cost?.cacheWrite??0}),t[124]=l.cost,t[125]=Be);let He;t[126]!==ze||t[127]!==Be?(He=(0,$.jsx)(`input`,{type:`number`,step:`any`,min:0,className:Re,value:ze,onChange:Be}),t[126]=ze,t[127]=Be,t[128]=He):He=t[128];let Ue;t[129]!==Le||t[130]!==He?(Ue=(0,$.jsxs)(`div`,{children:[Le,He]}),t[129]=Le,t[130]=He,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 Ke;t[135]!==ke||t[136]!==We?(Ke=(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]=Ke):Ke=t[137];let qe;t[138]!==G||t[139]!==Y||t[140]!==pe||t[141]!==Oe||t[142]!==Ke?(qe=(0,$.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[G,Y,pe,Oe,Ke]}),t[138]=G,t[139]=Y,t[140]=pe,t[141]=Oe,t[142]=Ke,t[143]=qe):qe=t[143];let Je;t[144]===s.cancel?Je=t[145]:(Je=(0,$.jsx)(d,{asChild:!0,children:(0,$.jsx)(L,{type:`button`,variant:`secondary`,children:s.cancel})}),t[144]=s.cancel,t[145]=Je);let Ye=r?s.addModelConfirm:s.saveModelConfirm,Xe;t[146]!==S||t[147]!==Ye?(Xe=(0,$.jsx)(L,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:S,children:Ye}),t[146]=S,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]!==P||t[153]!==qe||t[154]!==Ze?(Qe=(0,$.jsxs)($.Fragment,{children:[P,qe,Ze]}),t[152]=P,t[153]=qe,t[154]=Ze,t[155]=Qe):Qe=t[155],Qe}function kr(){return new Map}function Ar(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)(l,{className:F(`xopc-dialog-overlay fixed inset-0 bg-scrim`,te)}),t[0]=u):u=t[0];let d;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(d=F(`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`,K,`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 m;t[2]!==o||t[3]!==c||t[4]!==a||t[5]!==r||t[6]!==s||t[7]!==n||t[8]!==i?(m=n?(0,$.jsx)(Or,{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]=m):m=t[9];let g;t[10]===m?g=t[11]:(g=(0,$.jsxs)(f,{children:[u,(0,$.jsx)(p,{className:d,onOpenAutoFocus:jr,children:m})]}),t[10]=m,t[11]=g);let _;return t[12]!==r||t[13]!==n||t[14]!==g?(_=(0,$.jsx)(h,{open:n,onOpenChange:r,children:g}),t[12]=r,t[13]=n,t[14]=g,t[15]=_):_=t[15],_}function jr(e){return e.preventDefault()}function Mr(e){let t=(0,Z.c)(14),{providerId:n,inputId:r,value:i,onChange:a,labels:o}=e,s;t[0]===n?s=t[1]:(s=()=>ht(n).then(Nr),t[0]=n,t[1]=s);let c=s,l;t[2]!==r||t[3]!==o.apiKeyLabel?(l=(0,$.jsx)(`label`,{htmlFor:r,className:`text-sm font-medium text-fg`,children:o.apiKeyLabel}),t[2]=r,t[3]=o.apiKeyLabel,t[4]=l):l=t[4];let u;t[5]!==r||t[6]!==o||t[7]!==a||t[8]!==c||t[9]!==i?(u=(0,$.jsx)(Xe,{id:r,value:i,onChange:a,placeholder:o.apiKeyPlaceholder,labels:o,reveal:c,loadFailedLabel:o.loadFailed,maskedHelp:o.maskedHelp,notInConfigFile:o.notInConfigFile}),t[5]=r,t[6]=o,t[7]=a,t[8]=c,t[9]=i,t[10]=u):u=t[10];let d;return t[11]!==l||t[12]!==u?(d=(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[l,u]}),t[11]=l,t[12]=u,t[13]=d):d=t[13],d}function Nr(e){return e.apiKey??null}function Pr(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:m}=e,g;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,$.jsx)(l,{className:F(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,te)}),t[0]=g):g=t[0];let _;t[1]===Symbol.for(`react.memo_cache_sentinel`)?(_=F(`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`,K),t[1]=_):_=t[1];let v;t[2]!==c||t[3]!==o||t[4]!==s||t[5]!==a||t[6]!==u||t[7]!==d||t[8]!==r||t[9]!==m||t[10]!==i?(v=(0,$.jsxs)(f,{children:[g,(0,$.jsx)(p,{className:_,children:a?(0,$.jsx)(Ir,{providerId:i,customConfig:s,labels:u,language:d,onClose:()=>r(!1),onSaved:m}):(0,$.jsx)(Fr,{providerId:i,builtinRows:o,allModels:c,labels:u,language:d,onClose:()=>r(!1),onSaved:m})})]}),t[2]=c,t[3]=o,t[4]=s,t[5]=a,t[6]=u,t[7]=d,t[8]=r,t[9]=m,t[10]=i,t[11]=v):v=t[11];let y;return t[12]!==r||t[13]!==n||t[14]!==v?(y=(0,$.jsx)(h,{open:n,onOpenChange:r,children:v}),t[12]=r,t[13]=n,t[14]=v,t[15]=y):y=t[15],y}function Fr({providerId:e,builtinRows:t,allModels:n,labels:r,language:i,onClose:a,onSaved:o}){let s=t.find(t=>t.id===e),l=De[e],u=n.filter(t=>t.provider===e),[f,p]=(0,Q.useState)(s?.apiKey??``),[h,g]=(0,Q.useState)(!1),[_,v]=(0,Q.useState)(!1),[b,S]=(0,Q.useState)(null),[C,T]=(0,Q.useState)(!1),E=k(i).providersSettings,D=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`,[N,P]=(0,Q.useState)(null),[I,ee]=(0,Q.useState)(null),[z,B]=(0,Q.useState)(`idle`),[V,H]=(0,Q.useState)(null),[W,G]=(0,Q.useState)(null),[K,te]=(0,Q.useState)(null),[q,ne]=(0,Q.useState)(``),J=(0,Q.useRef)(null),Y=(0,Q.useRef)(null),X=z===`waiting`||z===`waiting_code`,re=(0,Q.useMemo)(()=>Te(e,i),[e,i]),ue=f!==(s?.apiKey??``),de=async()=>{let t=f.trim();if(!(!t||!D||Ue(t))){g(!0),S(null);try{await je({[e]:t}),v(!0),window.setTimeout(()=>{o(),a()},600)}catch(e){S(e instanceof Error?e.message:r.saveError)}finally{g(!1)}}};(0,Q.useEffect)(()=>{if(!N||!X)return;let e=window.setInterval(()=>{(async()=>{try{let t=await ce(N);t.status===`waiting_auth`||t.status===`waiting_code`?(B(t.status===`waiting_code`?`waiting_code`:`waiting`),ee(t.message??null),H(t.authUrl??null),G(t.instructions??null),te(t.deviceCode??null),t.authUrl&&t.authUrl!==Y.current&&(Y.current=t.authUrl,xt(t.authUrl,J.current).catch(()=>{}))):t.status===`completed`?(window.clearInterval(e),Ct(J.current),J.current=null,B(`success`),ee(t.message??E.saved),window.setTimeout(()=>{o(),a()},600)):(t.status===`failed`||t.status===`cancelled`)&&(window.clearInterval(e),Ct(J.current),J.current=null,B(`error`),ee(t.error??t.message??E.revokeFailed))}catch{}})()},1e3);return()=>window.clearInterval(e)},[N,X,a,o,E.revokeFailed,E.saved]),(0,Q.useEffect)(()=>()=>{N&&oe(N).catch(()=>{})},[N]),(0,Q.useEffect)(()=>()=>{Ct(J.current),J.current=null},[]);let fe=async()=>{try{await et(e),o(),a()}catch{}},pe=async()=>{Ct(J.current),J.current=St(),Y.current=null,B(`waiting`),ee(E.oauthStarting),H(null),G(null),te(null),S(null);try{P((await ie(e)).sessionId)}catch(e){Ct(J.current),J.current=null,B(`error`),ee(e instanceof Error?e.message:E.revokeFailed)}},me=async()=>{if(N){try{await le(N)}catch{}Ct(J.current),J.current=null,Y.current=null,B(`idle`),ee(null),P(null),H(null),G(null),te(null)}},he=async()=>{if(!(!N||!q.trim()))try{await se(N,q.trim()),ne(``),ee(E.oauthProcessingCode)}catch(e){B(`error`),ee(e instanceof Error?e.message:E.revokeFailed)}},ge=async()=>{try{await ae(e),o(),a()}catch(e){S(e instanceof Error?e.message:E.revokeFailed)}};return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-b border-edge-subtle px-5 py-4`,children:[(0,$.jsx)(m,{className:`text-base font-semibold text-fg`,children:s?.name??e}),(0,$.jsx)(d,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:F(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,R.press),children:(0,$.jsx)(O,{className:`size-4`,"aria-hidden":!0})})})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 overflow-y-auto px-5 py-4`,children:[l?.description?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:l.description}):null,s?.baseUrl?(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:r.apiUrlLabel}),(0,$.jsx)(`code`,{className:`break-all rounded-lg border border-edge-subtle bg-surface-panel/60 px-3 py-2 font-mono text-xs text-fg-muted`,children:s.baseUrl})]}):s?.category===`extension`?(0,$.jsx)(`p`,{className:`text-sm text-fg-muted`,children:r.apiUrlExtensionHint}):null,D?(0,$.jsx)(Mr,{providerId:e,inputId:`manage-api-key`,value:f,onChange:e=>{p(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)(x,{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:E.oauth}),(0,$.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:j?E.sourceOauth:E.oauthHint})]}),j?(0,$.jsx)(L,{type:`button`,variant:`secondary`,className:`gap-1.5 text-red-600 dark:text-red-400`,onClick:()=>void ge(),children:E.revoke}):(0,$.jsxs)(L,{type:`button`,variant:`primary`,className:`gap-1.5`,disabled:X,onClick:()=>void pe(),children:[X?(0,$.jsx)(w,{className:`size-3.5 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(_e,{className:`size-3.5`,"aria-hidden":!0}),E.oauth]})]}),I?(0,$.jsx)(`p`,{className:F(`text-xs`,z===`error`?`text-red-600 dark:text-red-400`:`text-fg-muted`),children:I}):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)(x,{className:`size-4`,"aria-hidden":!0}),E.openAuthPage]}):null,(0,$.jsx)(L,{type:`button`,variant:`secondary`,onClick:()=>void me(),children:E.cancelOAuth})]}):null,W?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:W}):null,K?(0,$.jsxs)(`div`,{className:`rounded-lg border border-edge-subtle bg-surface-panel px-3 py-2`,children:[(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:E.deviceCodeLabel}),(0,$.jsx)(`code`,{className:`mt-1 block select-all font-mono text-lg font-semibold tracking-widest text-fg`,children:K}),(0,$.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:E.deviceCodeHint})]}):null,z===`waiting_code`?(0,$.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,$.jsx)(`input`,{type:`text`,value:q,onChange:e=>ne(e.target.value),onKeyDown:e=>e.key===`Enter`&&void he(),placeholder:E.pasteRedirectUrl,className:F(`min-w-0 flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,U)}),(0,$.jsx)(L,{type:`button`,variant:`primary`,onClick:()=>void he(),children:E.submitCode})]}):null]}):null,re.length>0&&D?(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:re.map(({kind:e,href:t})=>(0,$.jsxs)(`a`,{href:t,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-xs text-accent hover:underline`,children:[ke(e,r),(0,$.jsx)(x,{className:`size-3`,"aria-hidden":!0})]},e))}):null,u.length>0?(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsxs)(`span`,{className:`text-sm font-medium text-fg`,children:[r.modelsLabel,` (`,u.length,`)`]}),(0,$.jsx)(`div`,{className:`max-h-40 overflow-y-auto rounded-lg border border-edge-subtle bg-surface-panel/40 p-2`,children:(0,$.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:u.map(e=>(0,$.jsx)(`span`,{className:`inline-block rounded-md bg-surface-hover px-2 py-1 text-xs text-fg-muted`,children:e.id.includes(`/`)?e.id.split(`/`).pop():e.id},e.id))})})]}):(0,$.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:r.noModels}),b?(0,$.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:b}):null]}),(0,$.jsxs)(`div`,{className:`flex items-center justify-between border-t border-edge-subtle px-5 py-3`,children:[M?(0,$.jsxs)(L,{type:`button`,variant:`ghost`,className:`gap-1.5 text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300`,onClick:()=>T(!0),children:[(0,$.jsx)(ve,{className:`size-3.5`,"aria-hidden":!0}),r.remove]}):(0,$.jsx)(`span`,{}),(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:D&&ue&&!Ue(f.trim())?(0,$.jsx)(L,{type:`button`,variant:`primary`,disabled:!f.trim()||h||_,onClick:()=>void de(),children:_?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(y,{className:`size-3.5`,"aria-hidden":!0}),r.saved]}):h?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(w,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),r.saving]}):r.save}):null})]}),(0,$.jsx)(We,{open:C,title:r.removeConfirmTitle,description:r.removeConfirmDescription.replace(`{{provider}}`,s?.name??e),confirmLabel:r.removeConfirmAction,cancelLabel:r.cancel,destructive:!0,onConfirm:()=>void fe(),onCancel:()=>T(!1)})]})}function Ir({providerId:e,customConfig:t,labels:n,language:r,onClose:i,onSaved:a}){let o=k(r).modelsSettings,s=t?.providers[e],[c,l]=(0,Q.useState)(s?.baseUrl??``),[u,f]=(0,Q.useState)(s?.apiKey??``),[p,h]=(0,Q.useState)(s?.models??[]),[g,_]=(0,Q.useState)(s?.modelDiscovery?.enabled===!0),[v,y]=(0,Q.useState)(!1),[b,x]=(0,Q.useState)(null),[S,C]=(0,Q.useState)(!1),[D,A]=(0,Q.useState)(null),[j,M]=(0,Q.useState)(!1),[N,P]=(0,Q.useState)(null),I=n=>{if(!t)return null;let r=u.trim(),i={...s,baseUrl:c.trim()||void 0,apiKey:Ue(r)?s?.apiKey:r||void 0,...n};return{providers:{...t.providers,[e]:i}}},ee=async()=>{let e=I({models:p,modelDiscovery:{enabled:g}});if(e){y(!0),x(null);try{await it(e),a(),i()}catch(e){x(e instanceof Error?e.message:n.saveError)}finally{y(!1)}}},z=async()=>{if(t)try{let{[e]:n,...r}=t.providers;await it({providers:r}),a(),i()}catch{}},B=(e,t)=>{P({model:e,isNew:t}),M(!0)},V=async e=>{if(!N)return;let t=N.isNew?[...p,e]:p.map(t=>t.id===e.id?e:t);h(t);let r=I({models:t});if(r)try{await it(r),a()}catch(e){x(e instanceof Error?e.message:n.saveError)}},H=async e=>{let t=p.filter(t=>t.id!==e);h(t),A(null);let r=I({models:t});if(r)try{await it(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)(m,{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)(d,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,className:F(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,R.press),children:(0,$.jsx)(O,{className:`size-4`,"aria-hidden":!0})})})]}),(0,$.jsxs)(`div`,{className:`flex flex-col gap-4 overflow-y-auto px-5 py-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,$.jsx)(`label`,{htmlFor:`manage-base-url`,className:`text-sm font-medium text-fg`,children:n.baseUrlLabel}),(0,$.jsx)(`input`,{id:`manage-base-url`,type:`url`,autoComplete:`off`,value:c,onChange:e=>l(e.target.value),className:F(`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle`,U)})]}),(0,$.jsx)(Mr,{providerId:e,inputId:`manage-custom-api-key`,value:u,onChange:f,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,p.length>0?` (${p.length})`:``]}),(0,$.jsxs)(L,{type:`button`,variant:`primary`,className:`gap-1.5 px-2 py-1 text-xs`,onClick:()=>B(null,!0),children:[(0,$.jsx)(E,{className:`size-3.5`,"aria-hidden":!0}),o.addModel]})]}),p.length===0?(0,$.jsx)(`p`,{className:`text-xs text-fg-muted`,children:o.modelsEmpty}):(0,$.jsx)(`ul`,{className:`space-y-2`,children:p.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:F(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-fg`,R.press),onClick:()=>B(e,!1),"aria-label":o.editModel,children:(0,$.jsx)(T,{className:`size-3.5`,"aria-hidden":!0})}),(0,$.jsx)(`button`,{type:`button`,className:F(`rounded-lg p-1.5 text-fg-muted hover:bg-surface-hover hover:text-red-600 dark:hover:text-red-400`,R.press),onClick:()=>A(e.id),"aria-label":o.removeModel,children:(0,$.jsx)(ve,{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)(L,{type:`button`,variant:`ghost`,className:`gap-1.5 text-red-600 hover:text-red-700 dark:text-red-400 dark:hover:text-red-300`,onClick:()=>C(!0),children:[(0,$.jsx)(ve,{className:`size-3.5`,"aria-hidden":!0}),n.remove]}),(0,$.jsx)(`div`,{className:`flex items-center gap-2`,children:(0,$.jsx)(L,{type:`button`,variant:`primary`,disabled:v,onClick:()=>void ee(),children:v?(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsx)(w,{className:`size-3.5 animate-spin`,"aria-hidden":!0}),n.saving]}):n.save})})]}),(0,$.jsx)(We,{open:S,title:n.removeConfirmTitle,description:n.removeConfirmDescription.replace(`{{provider}}`,e),confirmLabel:n.removeConfirmAction,cancelLabel:n.cancel,destructive:!0,onConfirm:()=>void z(),onCancel:()=>C(!1)}),(0,$.jsx)(We,{open:D!==null,title:o.removeModel,description:o.removeModelConfirm.replace(`{{id}}`,D??``),confirmLabel:n.removeConfirmAction,cancelLabel:n.cancel,destructive:!0,onConfirm:()=>{D&&H(D)},onCancel:()=>A(null)}),(0,$.jsx)(Ar,{open:j,onOpenChange:e=>{M(e),e||P(null)},providerId:e,model:N?.model??null,isNew:N?.isNew??!1,onSave:e=>void V(e),m:o})]})}function Lr(e,t){switch(e){case`vision`:return{href:`${Oe(`models`)}?add=1`,guidance:t?`接入支持图片理解的模型服务`:`Connect a model service that supports vision`,action:t?`去接入模型`:`Connect model`};case`image-generation`:return{href:Oe(`image`),guidance:t?`选择图片模型并配置所需凭据`:`Choose an image model and configure its credentials`,action:t?`去配置图片生成`:`Configure image generation`};case`stt`:return{href:Oe(`voice`),guidance:t?`选择语音识别服务,或安装本地语音模型`:`Choose a speech-to-text service or install a local voice model`,action:t?`去配置语音识别`:`Configure speech-to-text`};case`tts`:return{href:Oe(`voice`),guidance:t?`选择语音合成服务并完成凭据配置`:`Choose a text-to-speech service and configure its credentials`,action:t?`去配置语音合成`:`Configure text-to-speech`}}}async function Rr(){let e=await j(N(`/api/models/catalog`)),t=await e.json().catch(()=>null);if(!e.ok||!t?.ok||!t.payload)throw Error(t?.error?.message??`HTTP ${e.status}`);return t.payload}async function zr(){let e=await j(N(`/api/capabilities/readiness`)),t=await e.json().catch(()=>null);if(!e.ok||!t?.ok||!t.payload)throw Error(t?.error?.message??`HTTP ${e.status}`);return t.payload}function Br(){let e=M(e=>e.language)===`zh`,{data:t,error:n,isLoading:r}=I(X,Rr,{revalidateOnFocus:!1}),{data:i}=I(re,zr,{revalidateOnFocus:!1}),[a,o]=(0,Q.useState)(!1),[s,l]=(0,Q.useState)(null);if(r)return(0,$.jsx)(G,{className:`h-24 w-full rounded-2xl`});let u=Object.values(t?.sources??{}),d=u.reduce((e,t)=>e+t.models.filter(e=>e.availability===`available`).length,0),f=(t?.references??[]).filter(e=>e.availability===`unavailable`),p=t?.sync.lastSuccessAt??Math.max(0,...u.map(e=>e.lastSuccessAt)),m=s??(n instanceof Error?n.message:t?.sync.lastError??Object.values(t?.sync.sourceErrors??{})[0]),h=Object.values(i?.capabilities??{}).some(e=>e.status===`degraded`||e.status===`unavailable`),g=async()=>{o(!0),l(null);try{let e=await j(N(`/api/models/catalog/refresh`),{method:`POST`});if(!e.ok)throw Error(`HTTP ${e.status}`);await J()}catch(t){l(t instanceof Error?t.message:e?`模型目录刷新失败`:`Model catalog refresh failed`)}finally{o(!1)}};return(0,$.jsxs)(`div`,{className:`rounded-2xl border border-edge-subtle bg-surface-panel/40 p-4`,children:[(0,$.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[m||f.length>0||h?(0,$.jsx)(pe,{className:`size-4 text-amber-500`,"aria-hidden":!0}):(0,$.jsx)(y,{className:`size-4 text-emerald-500`,"aria-hidden":!0}),(0,$.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:e?`模型目录同步`:`Model catalog sync`})]}),(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e?`${u.length} 个来源,${d} 个可用模型${p?` · 最近同步 ${new Date(p).toLocaleString()}`:``}`:`${u.length} sources, ${d} available models${p?` · Last synced ${new Date(p).toLocaleString()}`:``}`})]}),(0,$.jsxs)(L,{className:`shrink-0`,type:`button`,variant:`secondary`,disabled:a,onClick:()=>void g(),children:[a?(0,$.jsx)(w,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,$.jsx)(Ye,{className:`size-4`,"aria-hidden":!0}),a?e?`刷新中…`:`Refreshing…`:e?`立即刷新`:`Refresh now`]})]}),i?(0,$.jsx)(`div`,{className:`mt-3 grid gap-2 sm:grid-cols-2 xl:grid-cols-4`,children:Object.entries(i.capabilities).map(([t,n])=>{let r=t===`vision`?e?`图片理解`:`Vision`:t===`image-generation`?e?`图片生成`:`Image generation`:t.toUpperCase(),i=n.selectionSource!==`explicit-config`,a=n.status===`degraded`||n.status===`unavailable`,o=Lr(t,e),s=(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,$.jsx)(`span`,{className:`min-w-0 text-xs font-medium text-fg`,children:r}),(0,$.jsx)(`span`,{className:n.status===`ready`?`shrink-0 text-xs text-emerald-600 dark:text-emerald-400`:n.status===`disabled`?`shrink-0 text-xs text-fg-muted`:`shrink-0 text-xs text-amber-600 dark:text-amber-400`,children:n.status===`ready`?e?`可用`:`Ready`:n.status===`disabled`?e?`已关闭`:`Off`:e?`需处理`:`Needs attention`})]}),(0,$.jsx)(`p`,{className:`mt-1 truncate text-xs text-fg-muted`,title:n.primary?`${n.primary.provider}/${n.primary.model}`:void 0,children:n.primary?`${i?e?`自动`:`Auto`:e?`显式`:`Explicit`} · ${n.primary.provider}/${n.primary.model}`:e?`无可用实现`:`No available implementation`}),a?(0,$.jsxs)(`div`,{className:`mt-2 border-t border-edge-subtle pt-2`,children:[(0,$.jsx)(`p`,{className:`text-xs leading-5 text-amber-700 dark:text-amber-300`,children:n.status===`degraded`?e?`当前配置不可用,正在使用备用方案。${o.guidance}`:`The current configuration is unavailable, so a fallback is in use. ${o.guidance}.`:o.guidance}),(0,$.jsxs)(`span`,{className:`mt-1 inline-flex items-center gap-1 text-xs font-medium text-accent`,children:[o.action,(0,$.jsx)(ct,{className:`size-3.5`,"aria-hidden":!0})]})]}):null]});return a?(0,$.jsx)(c,{to:o.href,"aria-label":`${r}:${o.action}`,className:F(`rounded-xl border border-amber-400/40 bg-amber-500/5 px-3 py-2`,`transition-colors hover:border-amber-400/70 hover:bg-amber-500/10`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`),children:s},t):(0,$.jsx)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel px-3 py-2`,children:s},t)})}):null,f.length>0?(0,$.jsx)(`div`,{className:`mt-2 space-y-1 text-sm text-amber-700 dark:text-amber-300`,children:f.slice(0,3).map(t=>(0,$.jsxs)(`p`,{children:[t.ref,` `,e?`不可用`:`is unavailable`,t.suggestedRef?` · ${e?`建议`:`Suggested`} ${t.suggestedRef}`:``,` · ${t.locations.length} ${e?`处引用`:`references`}`]},t.ref))}):null,m?(0,$.jsx)(`p`,{className:`mt-2 text-sm text-danger`,children:m}):null]})}async function Vr(){return(await A(N(`/api/models/xopc-cloud/account-summary`))).payload}function Hr(e){let t=(0,Z.c)(93),{labels:n}=e,r=M(Ur)===`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}=I(`/api/models/xopc-cloud/account-summary`,Vr,i);if(s){let e;return t[1]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(G,{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)(pe,{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)(Ye,{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)(L,{type:`button`,variant:`secondary`,disabled:c,onClick:o,children:[u,n.retry]}),t[14]=c,t[15]=n.retry,t[16]=o,t[17]=u,t[18]=d):d=t[18];let f;return t[19]!==a||t[20]!==d?(f=(0,$.jsx)(`section`,{className:`rounded-2xl border border-edge-subtle bg-surface-panel/40 p-4`,children:(0,$.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[a,d]})}),t[19]=a,t[20]=d,t[21]=f):f=t[21],f}let u,d,f,p,m,h,g,_;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);_=n.usageSummary.replace(`{{tokens}}`,e.format(a.usage.totalTokens)).replace(`{{credits}}`,e.format(a.usage.chargedCredits)).replace(`{{requests}}`,e.format(a.usage.requests)),g=`rounded-2xl border border-edge-subtle bg-surface-panel/40 p-5`,h=`flex flex-col gap-5 sm:flex-row sm:items-start sm:justify-between`,f=`min-w-0 flex-1`;let i;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,$.jsx)(b,{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?(p=(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[i,o,s]}),t[44]=o,t[45]=s,t[46]=p):p=t[46],t[47]===n.availableCredits?m=t[48]:(m=(0,$.jsx)(`p`,{className:`mt-5 text-xs font-medium text-fg-subtle`,children:n.availableCredits}),t[47]=n.availableCredits,t[48]=m),u=`mt-1 text-3xl font-semibold tracking-tight text-fg`,d=e.format(a.balance.credits),t[22]=a.balance.credits,t[23]=a.usage.chargedCredits,t[24]=a.usage.requests,t[25]=a.usage.totalTokens,t[26]=n.availableCredits,t[27]=n.connected,t[28]=n.title,t[29]=n.usageSummary,t[30]=r,t[31]=u,t[32]=d,t[33]=f,t[34]=p,t[35]=m,t[36]=h,t[37]=g,t[38]=_}else u=t[31],d=t[32],f=t[33],p=t[34],m=t[35],h=t[36],g=t[37],_=t[38];let v;t[49]===Symbol.for(`react.memo_cache_sentinel`)?(v=(0,$.jsx)(`span`,{className:`ml-2 text-sm font-medium text-fg-muted`,children:`credits`}),t[49]=v):v=t[49];let y;t[50]!==u||t[51]!==d?(y=(0,$.jsxs)(`p`,{className:u,children:[d,v]}),t[50]=u,t[51]=d,t[52]=y):y=t[52];let S;t[53]!==a.balance.credits||t[54]!==n.zeroBalance?(S=a.balance.credits===0?(0,$.jsx)(`p`,{className:`mt-2 text-sm font-medium text-danger`,children:n.zeroBalance}):null,t[53]=a.balance.credits,t[54]=n.zeroBalance,t[55]=S):S=t[55];let C;t[56]===n.recentUsage?C=t[57]:(C=(0,$.jsx)(`p`,{className:`mt-5 text-xs font-medium text-fg-subtle`,children:n.recentUsage}),t[56]=n.recentUsage,t[57]=C);let w;t[58]===_?w=t[59]:(w=(0,$.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:_}),t[58]=_,t[59]=w);let T;t[60]!==a.balance.updatedAt||t[61]!==n.updatedAt||t[62]!==r?(T=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]=T):T=t[63];let E;t[64]===T?E=t[65]:(E=(0,$.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:T}),t[64]=T,t[65]=E);let D;t[66]!==y||t[67]!==S||t[68]!==C||t[69]!==w||t[70]!==E||t[71]!==f||t[72]!==p||t[73]!==m?(D=(0,$.jsxs)(`div`,{className:f,children:[p,m,y,S,C,w,E]}),t[66]=y,t[67]=S,t[68]=C,t[69]=w,t[70]=E,t[71]=f,t[72]=p,t[73]=m,t[74]=D):D=t[74];let O;t[75]===Symbol.for(`react.memo_cache_sentinel`)?(O=(0,$.jsx)(x,{className:`size-3.5`,"aria-hidden":!0}),t[75]=O):O=t[75];let k;t[76]!==a.links.purchase||t[77]!==n.purchase?(k=(0,$.jsx)(L,{asChild:!0,variant:`primary`,children:(0,$.jsxs)(`a`,{href:a.links.purchase,target:`_blank`,rel:`noreferrer`,children:[n.purchase,O]})}),t[76]=a.links.purchase,t[77]=n.purchase,t[78]=k):k=t[78];let A;t[79]===Symbol.for(`react.memo_cache_sentinel`)?(A=(0,$.jsx)(x,{className:`size-3.5`,"aria-hidden":!0}),t[79]=A):A=t[79];let j;t[80]!==a.links.details||t[81]!==n.details?(j=(0,$.jsx)(L,{asChild:!0,variant:`secondary`,children:(0,$.jsxs)(`a`,{href:a.links.details,target:`_blank`,rel:`noreferrer`,children:[n.details,A]})}),t[80]=a.links.details,t[81]=n.details,t[82]=j):j=t[82];let N;t[83]!==k||t[84]!==j?(N=(0,$.jsxs)(`div`,{className:`flex shrink-0 flex-wrap gap-2`,children:[k,j]}),t[83]=k,t[84]=j,t[85]=N):N=t[85];let P;t[86]!==D||t[87]!==N||t[88]!==h?(P=(0,$.jsxs)(`div`,{className:h,children:[D,N]}),t[86]=D,t[87]=N,t[88]=h,t[89]=P):P=t[89];let F;return t[90]!==P||t[91]!==g?(F=(0,$.jsx)(`section`,{className:g,children:P}),t[90]=P,t[91]=g,t[92]=F):F=t[92],F}function Ur(e){return e.language}function Wr(e){return tt.includes(e)}function Gr(){let e=(0,Z.c)(78),t=M(Jr),n;e[0]===t?n=e[1]:(n=k(t),e[0]=t,e[1]=n);let r=n,l=r.capabilitiesSettings,u=a(),[d,f]=o(),p;if(e[2]!==d){let t=d.get(`returnTo`);p=t?.startsWith(`/chat/`)?t:null,e[2]=d,e[3]=p}else p=e[3];let m=p,{capability:h}=i(),[g,_]=(0,Q.useState)(!1),[v,y]=(0,Q.useState)(null),b=vr(),x;e[4]===b.cards?x=e[5]:(x=b.cards.some(qr),e[4]=b.cards,e[5]=x);let S=x,C,w;e[6]!==h||e[7]!==d||e[8]!==f?(C=()=>{if(h!==`models`||d.get(`add`)!==`1`)return;_(!0);let e=new URLSearchParams(d);e.delete(`add`),f(e,{replace:!0})},w=[h,d,f],e[6]=h,e[7]=d,e[8]=f,e[9]=C,e[10]=w):(C=e[9],w=e[10]),(0,Q.useEffect)(C,w);let T;e[11]!==l.modelsHint||e[12]!==l.tabs.models?(T={id:`models`,icon:Ke,label:l.tabs.models,hint:l.modelsHint},e[11]=l.modelsHint,e[12]=l.tabs.models,e[13]=T):T=e[13];let E;e[14]!==l.imageHint||e[15]!==l.tabs.image?(E={id:`image`,icon:nt,label:l.tabs.image,hint:l.imageHint},e[14]=l.imageHint,e[15]=l.tabs.image,e[16]=E):E=e[16];let O;e[17]!==l.tabs.voice||e[18]!==l.voiceHint?(O={id:`voice`,icon:fe,label:l.tabs.voice,hint:l.voiceHint},e[17]=l.tabs.voice,e[18]=l.voiceHint,e[19]=O):O=e[19];let A;e[20]!==l.searchHint||e[21]!==l.tabs.search?(A={id:`search`,icon:D,label:l.tabs.search,hint:l.searchHint},e[20]=l.searchHint,e[21]=l.tabs.search,e[22]=A):A=e[22];let j;e[23]!==T||e[24]!==E||e[25]!==O||e[26]!==A?(j=[T,E,O,A],e[23]=T,e[24]=E,e[25]=O,e[26]=A,e[27]=j):j=e[27];let N=j,P;e[28]===u?P=e[29]:(P=e=>u(Oe(e)),e[28]=u,e[29]=P);let F=P,I=Kr;if(!Wr(h)){let t;return e[30]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,$.jsx)(s,{to:Oe(`models`),replace:!0}),e[30]=t):t=e[30],t}let R=r.nav.settingsCapabilities,ee=l.subtitle,z;e[31]===t?z=e[32]:(z=Ee(t,`configuration`),e[31]=t,e[32]=z);let B;e[33]===Symbol.for(`react.memo_cache_sentinel`)?(B=(0,$.jsx)(mt,{className:`size-4`,"aria-hidden":!0}),e[33]=B):B=e[33];let V;e[34]===l.agentSettingsLink?V=e[35]:(V=(0,$.jsx)(L,{asChild:!0,variant:`secondary`,children:(0,$.jsxs)(c,{to:`/agents`,children:[B,l.agentSettingsLink]})}),e[34]=l.agentSettingsLink,e[35]=V);let H;e[36]!==l.docsLink||e[37]!==l.subtitle||e[38]!==r.nav.settingsCapabilities||e[39]!==z||e[40]!==V?(H=(0,$.jsx)(gt,{title:R,subtitle:ee,docsLink:z,docsLabel:l.docsLink,actions:V}),e[36]=l.docsLink,e[37]=l.subtitle,e[38]=r.nav.settingsCapabilities,e[39]=z,e[40]=V,e[41]=H):H=e[41];let U;e[42]!==h||e[43]!==m||e[44]!==t?(U=h===`voice`&&m?(0,$.jsx)(c,{to:m,className:`text-sm text-accent-fg hover:underline`,children:t===`zh`?`返回对话`:`Return to conversation`}):null,e[42]=h,e[43]=m,e[44]=t,e[45]=U):U=e[45];let W;e[46]!==l.tabsAria||e[47]!==h||e[48]!==N||e[49]!==F?(W=(0,$.jsx)(Bt,{items:N,activeTab:h,onChange:F,ariaLabel:l.tabsAria,tabIdPrefix:`capability-tab`,panelIdPrefix:`capability-panel`}),e[46]=l.tabsAria,e[47]=h,e[48]=N,e[49]=F,e[50]=W):W=e[50];let G;e[51]!==l.connectedProviders||e[52]!==l.xopcCloudAccount||e[53]!==h||e[54]!==b||e[55]!==N||e[56]!==S?(G=N.map(e=>(0,$.jsx)(Xr,{id:e.id,activeSection:h,hint:e.hint,children:e.id===`models`?(0,$.jsxs)($.Fragment,{children:[S?(0,$.jsx)(Hr,{labels:l.xopcCloudAccount}):null,(0,$.jsx)(Br,{}),(0,$.jsx)(wr,{labels:l.connectedProviders,data:b,onAdd:()=>_(!0),onManage:(e,t)=>y({providerId:e,isCustom:t})})]}):(0,$.jsx)(Yr,{section:e.id})},e.id)),e[51]=l.connectedProviders,e[52]=l.xopcCloudAccount,e[53]=h,e[54]=b,e[55]=N,e[56]=S,e[57]=G):G=e[57];let K;e[58]!==g||e[59]!==l.addProviderDialog||e[60]!==t||e[61]!==b.builtinRows||e[62]!==b.customConfig?(K=(0,$.jsx)(cr,{open:g,onOpenChange:_,builtinRows:b.builtinRows,customConfig:b.customConfig,labels:l.addProviderDialog,language:t,onSaved:I}),e[58]=g,e[59]=l.addProviderDialog,e[60]=t,e[61]=b.builtinRows,e[62]=b.customConfig,e[63]=K):K=e[63];let te;e[64]!==l.manageProviderDialog||e[65]!==t||e[66]!==v||e[67]!==b.allModels||e[68]!==b.builtinRows||e[69]!==b.customConfig?(te=v?(0,$.jsx)(Pr,{open:!0,onOpenChange:e=>{e||y(null)},providerId:v.providerId,isCustom:v.isCustom,builtinRows:b.builtinRows,customConfig:b.customConfig,allModels:b.allModels,labels:l.manageProviderDialog,language:t,onSaved:I}):null,e[64]=l.manageProviderDialog,e[65]=t,e[66]=v,e[67]=b.allModels,e[68]=b.builtinRows,e[69]=b.customConfig,e[70]=te):te=e[70];let q;return e[71]!==H||e[72]!==U||e[73]!==W||e[74]!==G||e[75]!==K||e[76]!==te?(q=(0,$.jsxs)(_t,{children:[H,U,W,G,K,te]}),e[71]=H,e[72]=U,e[73]=W,e[74]=G,e[75]=K,e[76]=te,e[77]=q):q=e[77],q}function Kr(){J()}function qr(e){return e.id===`xopc-cloud`&&!e.isCustom}function Jr(e){return e.language}function Yr(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)(un,{}),t[0]=e):e=t[0],e}case`voice`:{let e;return t[1]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(Fn,{}),t[1]=e):e=t[1],e}case`search`:{let e;return t[2]===Symbol.for(`react.memo_cache_sentinel`)?(e=(0,$.jsx)(nr,{}),t[2]=e):e=t[2],e}}}function Xr({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:F(`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&&e!==`voice`?(0,$.jsx)(`p`,{className:`text-sm leading-relaxed text-fg-muted`,children:n}):null,e===`voice`&&!i?null:r]}):null}export{Gr as CapabilitiesSettingsPanel};
|