@xopcai/xopc 0.0.43 → 0.0.45
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/README.md +138 -102
- package/README.zh-CN.md +155 -67
- package/dist/extensions/dingtalk/src/plugin.js +1 -1
- package/dist/extensions/feishu/src/outbound/media-load.js +1 -1
- package/dist/extensions/telegram/src/plugin.js +1 -1
- package/dist/extensions/telegram/src/routing-integration.js +2 -2
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/extensions/weixin/src/api/api.js +2 -2
- package/dist/extensions/weixin/src/auth/accounts.js +1 -1
- package/dist/extensions/weixin/src/cdn/upload.js +1 -1
- package/dist/extensions/weixin/src/media/data-url.js +1 -1
- package/dist/extensions/weixin/src/messaging/debug-mode.js +1 -1
- package/dist/extensions/weixin/src/messaging/inbound.js +1 -1
- package/dist/extensions/weixin/src/messaging/process-message.js +1 -1
- package/dist/extensions/weixin/src/plugin.js +1 -1
- package/dist/extensions/weixin/src/storage/sync-buf.js +1 -1
- package/dist/gateway/static/root/assets/agents-Bk2uuFvC.js +216 -0
- package/dist/gateway/static/root/assets/agents-Bk2uuFvC.js.map +1 -0
- package/dist/gateway/static/root/assets/{apps-page-Bco3oZzd.js → apps-page-CbSr8cvX.js} +2 -2
- package/dist/gateway/static/root/assets/{apps-page-Bco3oZzd.js.map → apps-page-CbSr8cvX.js.map} +1 -1
- package/dist/gateway/static/root/assets/channels-settings-Dn-hIRl1.js +2 -0
- package/dist/gateway/static/root/assets/{channels-settings-CpTZxCKG.js.map → channels-settings-Dn-hIRl1.js.map} +1 -1
- package/dist/gateway/static/root/assets/{cron-api-YLqLzMDN.js → cron-dreaming-jobs-D460WnXB.js} +3 -3
- package/dist/gateway/static/root/assets/cron-dreaming-jobs-D460WnXB.js.map +1 -0
- package/dist/gateway/static/root/assets/cron-page-Df6AyXfn.js +2 -0
- package/dist/gateway/static/root/assets/cron-page-Df6AyXfn.js.map +1 -0
- package/dist/gateway/static/root/assets/dist-DN37Fw0E.js +2 -0
- package/dist/gateway/static/root/assets/{dist-4ClCuR-G.js.map → dist-DN37Fw0E.js.map} +1 -1
- package/dist/gateway/static/root/assets/{extension-debug-page-yNO3rwBQ.js → extension-debug-page-CqdKfBv_.js} +2 -2
- package/dist/gateway/static/root/assets/{extension-debug-page-yNO3rwBQ.js.map → extension-debug-page-CqdKfBv_.js.map} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-D0vOu9eC.js → extension-page-DhxjnfDf.js} +2 -2
- package/dist/gateway/static/root/assets/{extension-page-D0vOu9eC.js.map → extension-page-DhxjnfDf.js.map} +1 -1
- package/dist/gateway/static/root/assets/extension-settings-page-B3uhrA_f.js +2 -0
- package/dist/gateway/static/root/assets/{extension-settings-page-DqaNWoo7.js.map → extension-settings-page-B3uhrA_f.js.map} +1 -1
- package/dist/gateway/static/root/assets/heartbeat-config-api-z1kl5_rE.js +2 -0
- package/dist/gateway/static/root/assets/heartbeat-config-api-z1kl5_rE.js.map +1 -0
- package/dist/gateway/static/root/assets/{index-K0ZDwzeJ.css → index-B8G4Y9YY.css} +1 -1
- package/dist/gateway/static/root/assets/{index-KxjI2fjF.js → index-BUYGk2UT.js} +93 -93
- package/dist/gateway/static/root/assets/{index-KxjI2fjF.js.map → index-BUYGk2UT.js.map} +1 -1
- package/dist/gateway/static/root/assets/logs-page-Z9KRHWeO.js +2 -0
- package/dist/gateway/static/root/assets/{logs-page-DSdKuyeD.js.map → logs-page-Z9KRHWeO.js.map} +1 -1
- package/dist/gateway/static/root/assets/sessions-page-TlMYZxuv.js +2 -0
- package/dist/gateway/static/root/assets/{sessions-page-Bfb-hZJb.js.map → sessions-page-TlMYZxuv.js.map} +1 -1
- package/dist/gateway/static/root/assets/settings-page-X8vVcB8e.js +2 -0
- package/dist/gateway/static/root/assets/settings-page-X8vVcB8e.js.map +1 -0
- package/dist/gateway/static/root/assets/skills-page-B-tO9-I7.js +3 -0
- package/dist/gateway/static/root/assets/skills-page-B-tO9-I7.js.map +1 -0
- package/dist/gateway/static/root/assets/{use-image-provider-credentials-Cu5zeVdn.js → use-image-provider-credentials-DsYECmye.js} +2 -2
- package/dist/gateway/static/root/assets/{use-image-provider-credentials-Cu5zeVdn.js.map → use-image-provider-credentials-DsYECmye.js.map} +1 -1
- package/dist/gateway/static/root/index.html +2 -2
- package/dist/package.js +1 -1
- package/dist/src/agent/agent-manager.js +6 -6
- package/dist/src/agent/context/workspace-seed.js +2 -2
- package/dist/src/agent/goals/post-turn.js +1 -1
- package/dist/src/agent/image/load-image-media.js +1 -1
- package/dist/src/agent/ipc/bus.js +1 -1
- package/dist/src/agent/ipc/inbox.js +2 -2
- package/dist/src/agent/ipc/socket.js +1 -1
- package/dist/src/agent/memory/builtin-memory-store.js +1 -1
- package/dist/src/agent/memory/dreaming/deep-promotion.js +1 -1
- package/dist/src/agent/memory/dreaming/events.js +1 -1
- package/dist/src/agent/memory/dreaming/last-run.js +1 -1
- package/dist/src/agent/memory/dreaming/light-sweep.js +1 -1
- package/dist/src/agent/memory/dreaming/preview.js +1 -1
- package/dist/src/agent/memory/dreaming/rem-patterns.js +1 -1
- package/dist/src/agent/memory/dreaming/short-term-store.js +1 -1
- package/dist/src/agent/memory/dreaming/utils.js +1 -1
- package/dist/src/agent/memory/plugin-discovery.js +1 -1
- package/dist/src/agent/models/manager.js +1 -1
- package/dist/src/agent/prompt/service-prompt-builder.js +2 -2
- package/dist/src/agent/service.js +5 -5
- package/dist/src/agent/skills/config.js +1 -1
- package/dist/src/agent/skills/hub-hash.js +2 -2
- package/dist/src/agent/skills/hub-lock.js +1 -1
- package/dist/src/agent/skills/hub-pull.js +1 -1
- package/dist/src/agent/skills/index.js +1 -1
- package/dist/src/agent/skills/managed-store.js +1 -1
- package/dist/src/agent/skills/scanner.js +1 -1
- package/dist/src/agent/skills/skill-manage-ops.js +1 -1
- package/dist/src/agent/skills/skill-manager.js +1 -1
- package/dist/src/agent/tools/dreaming-tool.js +1 -1
- package/dist/src/agent/tools/factory.js +1 -1
- package/dist/src/agent/tools/image-generate-tool.js +1 -1
- package/dist/src/agent/tools/send-media.js +1 -1
- package/dist/src/agent/tools/skill-manage-tool.js +1 -1
- package/dist/src/agent/tools/write.js +1 -1
- package/dist/src/auth/credentials.js +3 -3
- package/dist/src/auth/profiles/store.js +1 -1
- package/dist/src/auth/sync-provider-auth.js +1 -1
- package/dist/src/channels/attachments/inbound-persist.js +1 -1
- package/dist/src/channels/attachments/outbound-tts-persist.js +1 -1
- package/dist/src/channels/outbound/persist-store.js +1 -1
- package/dist/src/channels/pairing/allow-from-file.js +1 -1
- package/dist/src/channels/pairing/pairing-store.js +2 -2
- package/dist/src/chat-commands/builtins/config.js +2 -2
- package/dist/src/chat-commands/context.js +1 -1
- package/dist/src/cli/commands/agent.js +1 -1
- package/dist/src/cli/commands/agents.js +1 -1
- package/dist/src/cli/commands/config.js +1 -1
- package/dist/src/cli/commands/doctor/checks/config-health.js +1 -1
- package/dist/src/cli/commands/doctor/checks/provider-auth.js +1 -1
- package/dist/src/cli/commands/doctor/checks/session-integrity.js +1 -1
- package/dist/src/cli/commands/doctor/checks/state-integrity.js +1 -1
- package/dist/src/cli/commands/doctor/checks/workspace-status.js +1 -1
- package/dist/src/cli/commands/extension-dev.js +1 -1
- package/dist/src/cli/commands/extension-marketplace.js +1 -1
- package/dist/src/cli/commands/extension-pack.js +1 -1
- package/dist/src/cli/commands/image.js +1 -1
- package/dist/src/cli/commands/init.js +4 -4
- package/dist/src/cli/utils/init-workspace.js +2 -2
- package/dist/src/config/index.js +2 -2
- package/dist/src/config/loader.js +2 -2
- package/dist/src/config/models-json.js +2 -2
- package/dist/src/config/profile.js +2 -2
- package/dist/src/cron/executor.js +2 -2
- package/dist/src/cron/persistence.js +1 -1
- package/dist/src/cron/run-log-store.js +1 -1
- package/dist/src/daemon/launchd.js +2 -2
- package/dist/src/daemon/systemd.js +2 -2
- package/dist/src/extensions/health.js +1 -1
- package/dist/src/extensions/loader.js +1 -1
- package/dist/src/extensions/lockfile.js +2 -2
- package/dist/src/gateway/agents-admin.js +2 -2
- package/dist/src/gateway/hono/lib/extension-store.js +1 -1
- package/dist/src/gateway/hono/lib/static-ui.js +1 -1
- package/dist/src/gateway/hono/oauth.js +1 -1
- package/dist/src/gateway/hono/routes/auth-registry-extensions.js +1 -1
- package/dist/src/gateway/hono/routes/config.js +1 -1
- package/dist/src/gateway/hono/routes/dreaming.js +1 -1
- package/dist/src/gateway/hono/routes/host-fs.js +1 -1
- package/dist/src/gateway/hono/routes/models.js +1 -1
- package/dist/src/gateway/hono/routes/workspace.js +3 -3
- package/dist/src/gateway/hono/sse.js +2 -2
- package/dist/src/gateway/lock.js +2 -2
- package/dist/src/gateway/service/run-gateway-agent.js +2 -2
- package/dist/src/gateway/service.js +5 -5
- package/dist/src/gateway/workspace-fs-file-list.js +1 -1
- package/dist/src/gateway/workspace-heartbeat-path.js +1 -1
- package/dist/src/infra/update-check.js +1 -1
- package/dist/src/infra/update-lock.js +3 -3
- package/dist/src/infra/update-runner.js +1 -1
- package/dist/src/infra/update-startup.js +2 -2
- package/dist/src/infra/write-file-atomic.js +2 -2
- package/dist/src/providers/auth-runtime/auth-profile-store.js +1 -1
- package/dist/src/providers/index.js +2 -2
- package/dist/src/providers/model-registry.js +1 -1
- package/dist/src/session/config-store.js +2 -2
- package/dist/src/session/search-index-cache.js +1 -1
- package/dist/src/session/search-index.js +1 -1
- package/dist/src/session/session-title.js +1 -1
- package/dist/src/session/store.js +5 -5
- package/dist/src/tui/backends/embedded-backend.js +1 -1
- package/dist/src/tui/tui.js +1 -1
- package/dist/src/utils/logger/audit.js +1 -1
- package/dist/src/utils/logger/log-store.js +1 -1
- package/dist/src/utils/logger/rotation.js +1 -1
- package/dist/src/voice/tts/audio.js +1 -1
- package/dist/src/voice/tts/providers/edge-speech.js +1 -1
- package/package.json +2 -2
- package/dist/gateway/static/root/assets/agents-BDhkkT2o.js +0 -216
- package/dist/gateway/static/root/assets/agents-BDhkkT2o.js.map +0 -1
- package/dist/gateway/static/root/assets/channels-settings-CpTZxCKG.js +0 -2
- package/dist/gateway/static/root/assets/cron-api-YLqLzMDN.js.map +0 -1
- package/dist/gateway/static/root/assets/cron-page-aiDeJtJ-.js +0 -2
- package/dist/gateway/static/root/assets/cron-page-aiDeJtJ-.js.map +0 -1
- package/dist/gateway/static/root/assets/dist-4ClCuR-G.js +0 -2
- package/dist/gateway/static/root/assets/extension-settings-page-DqaNWoo7.js +0 -2
- package/dist/gateway/static/root/assets/logs-page-DSdKuyeD.js +0 -2
- package/dist/gateway/static/root/assets/sessions-page-Bfb-hZJb.js +0 -2
- package/dist/gateway/static/root/assets/settings-page-B7NZPSpO.js +0 -2
- package/dist/gateway/static/root/assets/settings-page-B7NZPSpO.js.map +0 -1
- package/dist/gateway/static/root/assets/skills-page-D-AJTEVx.js +0 -3
- package/dist/gateway/static/root/assets/skills-page-D-AJTEVx.js.map +0 -1
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{i as t,t as n}from"./vendor-react-DbimaAId.js";import{i as r,o as i}from"./vendor-swr-B5fPo7KK.js";import{$r as a,An as o,At as s,Ci as c,Di as l,Dn as u,Dr as d,Dt as f,En as p,Er as m,Et as h,Fn as g,Ft as _,In as v,Ir as y,It as b,Jr as x,Ln as S,Lr as C,Lt as w,Mt as T,Nt as E,On as D,Pn as O,Pt as k,Rn as ee,Rr as A,Rt as j,Si as M,Sn as N,Tn as P,Tr as F,Wn as te,Xn as I,Y as L,Yr as ne,Zn as R,_ as re,_n as z,_r as ie,a as ae,ar as oe,bn as B,br as V,bt as H,c as U,cr as se,di as ce,dn as le,ei as W,er as ue,fn as de,fr as fe,g as pe,gi as me,h as he,hn as ge,i as _e,jn as G,jt as ve,kn as K,kt as ye,l as be,li as xe,lr as Se,m as Ce,mi as we,mn as Te,mr as Ee,n as De,o as Oe,pi as ke,pn as Ae,qn as je,qr as Me,r as Ne,rr as Pe,s as Fe,si as Ie,sn as Le,t as Re,tr as ze,u as Be,ui as Ve,un as q,ur as He,v as Ue,vn as We,wi as Ge,wn as Ke,wr as qe,xn as Je,xt as Ye,y as Xe,yr as Ze,zn as Qe,zr as $e}from"./index-KxjI2fjF.js";import{i as et,n as tt,r as nt,t as rt}from"./use-image-provider-credentials-Cu5zeVdn.js";import{i as it,l as at,y as ot}from"./cron-api-YLqLzMDN.js";import{_ as st,a as ct,b as J,c as lt,d as ut,f as dt,g as ft,h as pt,i as mt,l as ht,m as gt,n as _t,o as vt,p as yt,r as bt,s as xt,t as St,u as Ct,v as wt,y as Tt}from"./agents-BDhkkT2o.js";import{t as Et}from"./browser-DNXWYwzc.js";var Y=n();function Dt(){return g(`rounded-xl border border-edge-subtle bg-surface-base px-4 py-1 sm:px-5`)}var Ot={default:{light:{canvas:`#f5f5f7`,panel:`#ffffff`,accent:`#2563eb`,fg:`#1d1d1f`,muted:`#d2d2d7`},dark:{canvas:`#1c1c1e`,panel:`#2c2c2e`,accent:`#3b82f6`,fg:`#f5f5f7`,muted:`#48484a`}},emerald:{light:{canvas:`#f0fdf4`,panel:`#ffffff`,accent:`#059669`,fg:`#052e16`,muted:`#86efac`},dark:{canvas:`#000000`,panel:`#0a0a0a`,accent:`#10b981`,fg:`#d1fae5`,muted:`#134e2a`}},mono:{light:{canvas:`#ffffff`,panel:`#f5f5f5`,accent:`#111111`,fg:`#111111`,muted:`#e5e7eb`},dark:{canvas:`#101010`,panel:`#1a1a1a`,accent:`#737373`,fg:`#fafafa`,muted:`#333333`}}};function kt({canvas:e,panel:t,accent:n,fg:r,muted:i}){return(0,Y.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col justify-center gap-1 p-1.5`,style:{backgroundColor:e},children:(0,Y.jsxs)(`div`,{className:`flex flex-col gap-0.5 rounded-sm border p-1`,style:{backgroundColor:t,borderColor:i},children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`div`,{className:`h-1 w-1 shrink-0 rounded-full`,style:{backgroundColor:n}}),(0,Y.jsx)(`div`,{className:`h-1 min-w-0 flex-1 rounded-full`,style:{backgroundColor:r,opacity:.85}})]}),(0,Y.jsx)(`div`,{className:`h-1 w-2/3 max-w-[70%] rounded-full`,style:{backgroundColor:i}}),(0,Y.jsx)(`div`,{className:`h-1 w-1/2 max-w-[55%] rounded-full`,style:{backgroundColor:i}})]})})}function At({scheme:e}){let{light:t,dark:n}=Ot[e];return(0,Y.jsxs)(`div`,{className:`flex h-11 w-full overflow-hidden rounded-md border border-edge-subtle`,children:[(0,Y.jsx)(kt,{...t}),(0,Y.jsx)(`div`,{className:`w-px shrink-0 bg-black/12 dark:bg-white/12`,"aria-hidden":!0}),(0,Y.jsx)(kt,{...n})]})}var jt=[{value:`default`,labelKey:`colorSchemeDefault`},{value:`emerald`,labelKey:`colorSchemeLightGreen`},{value:`mono`,labelKey:`colorSchemeModernMono`}];function Mt(){let e=o(N(e=>e.language)).appearanceSettings,t=Je(e=>e.colorScheme),n=Je(e=>e.setColorScheme);return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2 border-b border-edge-subtle py-3.5 last:border-b-0 sm:py-4`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:e.colorSchemeTitle}),(0,Y.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:e.colorSchemeDescription})]}),(0,Y.jsx)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-3`,children:jt.map(({value:r,labelKey:i})=>{let a=t===r;return(0,Y.jsxs)(`button`,{type:`button`,"aria-pressed":a,onClick:()=>n(r),className:g(`flex flex-col gap-2 rounded-xl border-2 p-2.5 text-left transition-[border-color,box-shadow] duration-150`,a?`border-accent shadow-[0_0_0_1px_var(--color-accent)]`:`border-edge-subtle hover:border-edge`),children:[(0,Y.jsx)(At,{scheme:r}),(0,Y.jsx)(`span`,{className:g(`text-xs font-medium leading-none`,a?`text-accent-fg`:`text-fg-muted`),children:e[i]})]},r)})})]})}function Nt(){let e=o(N(e=>e.language)).appearanceSettings;return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col gap-1`,children:[(0,Y.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight text-fg`,children:e.pageTitle}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.subtitle})]}),(0,Y.jsxs)(`section`,{className:Dt(),"aria-labelledby":`pref-language-heading`,children:[(0,Y.jsx)(`h2`,{id:`pref-language-heading`,className:`sr-only`,children:e.languageTitle}),(0,Y.jsx)(B,{variant:`page`,sections:[`language`]})]}),(0,Y.jsxs)(`section`,{className:Dt(),"aria-labelledby":`pref-appearance-heading`,children:[(0,Y.jsx)(`h2`,{id:`pref-appearance-heading`,className:`sr-only`,children:e.themeTitle}),(0,Y.jsx)(B,{variant:`page`,sections:[`theme`,`font`]}),(0,Y.jsx)(Mt,{})]})]})}var X=e(t(),1);function Pt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var Ft={enabled:!0,cron:`0 */6 * * *`,lookbackDays:1,limit:50,dedupeSimilarity:.85},It={enabled:!0,cron:`0 3 * * *`,minScore:.8,minRecallCount:3,limit:10,recencyHalfLifeDays:14,maxAgeDays:30},Lt={enabled:!0,cron:`0 5 * * 0`,lookbackDays:7,limit:20,minPatternStrength:.6},Rt={enabled:!1,frequency:`0 3 * * *`,timezone:``,deepEnabled:!0,minScore:.8,minRecallCount:3,limit:10,light:Ft,deep:It,rem:Lt};function zt(e,t){return Number.isFinite(e)?Math.max(0,Math.min(1,e)):t}function Bt(e,t){let n=typeof e==`string`?Number(e):e;return Number.isFinite(n)?Math.max(0,Math.floor(n)):t}function Vt(e,t){let n=typeof e==`string`?Number(e):e;return Number.isFinite(n)?n:t}function Ht(e){let t=Pt(e)?e:{},n=Pt(t.agents)?t.agents:{},r=Pt(n.defaults)?n.defaults:{},i=Pt(r.memory)?r.memory:{},a=Pt(i.dreaming)?i.dreaming:{},o=Pt(a.phases)?a.phases:{},s=Pt(o.light)?o.light:{},c=Pt(o.deep)?o.deep:{},l=Pt(o.rem)?o.rem:{};return{enabled:a.enabled===!0,frequency:typeof a.frequency==`string`&&a.frequency.trim()?a.frequency.trim():Rt.frequency,timezone:typeof a.timezone==`string`?a.timezone:``,deepEnabled:c.enabled!==!1,minScore:zt(typeof c.minScore==`number`?c.minScore:Number(c.minScore),Rt.minScore),minRecallCount:Math.max(1,Bt(c.minRecallCount,Rt.minRecallCount)),limit:Bt(c.limit,Rt.limit),light:{enabled:s.enabled!==!1,cron:typeof s.cron==`string`&&s.cron.trim()?s.cron.trim():Ft.cron,lookbackDays:Math.max(1,Bt(s.lookbackDays,Ft.lookbackDays)),limit:Bt(s.limit,Ft.limit),dedupeSimilarity:zt(Vt(s.dedupeSimilarity,Ft.dedupeSimilarity),Ft.dedupeSimilarity)},deep:{enabled:c.enabled!==!1,cron:typeof c.cron==`string`&&c.cron.trim()?c.cron.trim():It.cron,minScore:zt(Vt(c.minScore,It.minScore),It.minScore),minRecallCount:Math.max(1,Bt(c.minRecallCount,It.minRecallCount)),limit:Bt(c.limit,It.limit),recencyHalfLifeDays:Math.max(1,Vt(c.recencyHalfLifeDays,It.recencyHalfLifeDays)),maxAgeDays:Math.max(1,Vt(c.maxAgeDays,It.maxAgeDays))},rem:{enabled:l.enabled!==!1,cron:typeof l.cron==`string`&&l.cron.trim()?l.cron.trim():Lt.cron,lookbackDays:Math.max(1,Bt(l.lookbackDays,Lt.lookbackDays)),limit:Bt(l.limit,Lt.limit),minPatternStrength:zt(Vt(l.minPatternStrength,Lt.minPatternStrength),Lt.minPatternStrength)}}}async function Ut(e){let t=e.frequency.trim(),n=e.timezone.trim();await ge(q(`/api/config`),{method:`PATCH`,body:JSON.stringify({agents:{defaults:{memory:{dreaming:{enabled:!!e.enabled,frequency:t||null,timezone:n||null,phases:{light:{enabled:!!e.light.enabled,cron:e.light.cron.trim()||null,lookbackDays:Math.max(1,Math.floor(e.light.lookbackDays)),limit:Math.max(0,Math.floor(e.light.limit)),dedupeSimilarity:zt(e.light.dedupeSimilarity,Ft.dedupeSimilarity)},deep:{enabled:!!e.deep.enabled,cron:e.deep.cron.trim()||null,minScore:zt(e.deep.minScore,It.minScore),minRecallCount:Math.max(1,Math.floor(e.deep.minRecallCount)),limit:Math.max(0,Math.floor(e.deep.limit)),recencyHalfLifeDays:Math.max(1,e.deep.recencyHalfLifeDays),maxAgeDays:Math.max(1,e.deep.maxAgeDays)},rem:{enabled:!!e.rem.enabled,cron:e.rem.cron.trim()||null,lookbackDays:Math.max(1,Math.floor(e.rem.lookbackDays)),limit:Math.max(0,Math.floor(e.rem.limit)),minPatternStrength:zt(e.rem.minPatternStrength,Lt.minPatternStrength)}}}}}}})}),H()}function Z(){return`text-xs font-medium text-fg-muted`}function Q(){return`text-sm font-medium text-fg`}function Wt(e){return e?e.replace(`T`,` `).replace(`Z`,``):`—`}function Gt(e){return e===void 0||!Number.isFinite(e)||e<0?`—`:e<1e3?`${Math.round(e)} ms`:`${(e/1e3).toFixed(2)} s`}function Kt({label:e,children:t,className:n}){return(0,Y.jsxs)(`div`,{className:g(`space-y-2`,n),children:[(0,Y.jsx)(`h3`,{className:`text-[0.7rem] font-semibold uppercase tracking-wider text-fg-muted`,children:e}),t]})}function qt({icon:e,label:t,enabled:n,cron:r,details:i,t:a}){return(0,Y.jsxs)(`div`,{className:g(J(),`space-y-1.5`),children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e,(0,Y.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:t}),(0,Y.jsx)(`span`,{className:g(`ml-auto text-xs font-medium`,n?`text-emerald-600 dark:text-emerald-400`:`text-fg-muted`),children:n?a.on:a.off})]}),(0,Y.jsx)(`div`,{className:`font-mono text-xs text-fg-muted`,children:r}),(0,Y.jsx)(`div`,{className:`text-xs text-fg-muted`,children:i})]})}function Jt({label:e,lastRun:t,t:n}){return(0,Y.jsx)(Kt,{label:e,children:t?.exists?(0,Y.jsxs)(`details`,{className:`group rounded-lg border border-edge-subtle`,children:[(0,Y.jsx)(`summary`,{className:`cursor-pointer list-none px-3 py-2 text-xs font-medium text-fg-muted marker:hidden [&::-webkit-details-marker]:hidden`,children:(0,Y.jsx)(`span`,{className:`underline decoration-edge underline-offset-2 group-open:text-fg`,children:n.lastRunRaw})}),(0,Y.jsx)(`pre`,{className:`max-h-[12rem] overflow-auto border-t border-edge-subtle p-3 text-xs text-fg-muted`,children:JSON.stringify(t.raw,null,2)})]}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.phaseLastRunEmpty})})}function Yt({t:e,r:t}){let n=t.deep?.skipped;return(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.lastRunStatus}),(0,Y.jsx)(`div`,{className:g(Q(),t.ok?`text-emerald-600 dark:text-emerald-400`:`text-amber-600 dark:text-amber-400`),children:t.ok?e.lastRunSuccess:e.lastRunFailure})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.lastRunDuration}),(0,Y.jsx)(`div`,{className:Q(),children:Gt(t.durationMs)})]}),(0,Y.jsxs)(`div`,{className:g(J(),`sm:col-span-2`),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.lastRunReason}),(0,Y.jsx)(`div`,{className:Q(),children:t.reason}),t.errorMessage?(0,Y.jsx)(`div`,{className:`mt-1 text-xs text-amber-600 dark:text-amber-400`,children:`${e.lastRunError}: ${t.errorMessage}`}):null]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.lastRunRanked}),(0,Y.jsx)(`div`,{className:Q(),children:String(t.deep?.candidatesRanked??`—`)})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.lastRunApplied}),(0,Y.jsx)(`div`,{className:Q(),children:String(t.deep?.applied??`—`)})]}),n?(0,Y.jsxs)(`div`,{className:`sm:col-span-2`,children:[(0,Y.jsx)(`div`,{className:`mb-2 text-xs font-medium text-fg`,children:e.lastRunSkipped}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.lastRunSkipKey}),(0,Y.jsx)(`div`,{className:Q(),children:String(n.alreadyPromotedKey)})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.lastRunSkipRehydrate}),(0,Y.jsx)(`div`,{className:Q(),children:String(n.rehydrateFailed)})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.lastRunSkipContaminated}),(0,Y.jsx)(`div`,{className:Q(),children:String(n.contaminated)})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.lastRunSkipHash}),(0,Y.jsx)(`div`,{className:Q(),children:String(n.hashDuplicate)})]})]})]}):null]})}function Xt(e,t){return e.locked?{text:t.lockValueLocked,className:`text-amber-600 dark:text-amber-400`}:{text:t.lockValueUnlocked,className:`text-emerald-600 dark:text-emerald-400`}}function Zt(){let e=o(N(e=>e.language)).dreamingSettings,t=!!z(e=>e.token),{data:n}=Ye(t),[i,a]=(0,X.useState)(null),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(!1),[f,p]=(0,X.useState)(!1),[h,_]=(0,X.useState)(!1),[v,y]=(0,X.useState)(null),[b,x]=(0,X.useState)(`deep`),[S,C]=(0,X.useState)(null),[w,T]=(0,X.useState)(null),[E,D]=(0,X.useState)(!1),[O,k]=(0,X.useState)(!1),[A,j]=(0,X.useState)(null),[P,F]=(0,X.useState)(!1),[L,ne]=(0,X.useState)(null),[R,re]=(0,X.useState)(null),[ie,ae]=(0,X.useState)(!1),[oe,B]=(0,X.useState)(null),[V,H]=(0,X.useState)(null),{data:U,error:ce,isLoading:le,mutate:W}=r(t?dt():null,pt,{revalidateOnFocus:!1}),ue=(0,X.useMemo)(()=>U?Xt(U.lock,e):null,[U,e]),de=(0,X.useMemo)(()=>{let e=[];return ce&&e.push(ce instanceof Error?ce.message:String(ce)),s&&e.push(s),v&&e.push(v),L&&e.push(L),oe&&e.push(oe),A&&e.push(A),e},[ce,s,v,L,oe,A]),fe=(0,X.useMemo)(()=>{let t=[];return O&&t.push(e.configSaved),h&&t.push(e.runQueued),l&&t.push(e.actionOk),t},[O,h,l,e]),pe=(0,X.useCallback)(async()=>{u(!1),c(null),_(!1),y(null),k(!1),j(null),ne(null),await W()},[W]),me=(0,X.useCallback)(async()=>{F(!0),ne(null);try{re((await gt(20)).items??[])}catch(e){ne(e instanceof Error?e.message:String(e))}finally{F(!1)}},[]),he=(0,X.useCallback)(async()=>{ae(!0),B(null);try{H(await yt(50))}catch(e){B(e instanceof Error?e.message:String(e))}finally{ae(!1)}},[]),ge=(0,X.useCallback)(async(e=`deep`)=>{p(!0),_(!1),y(null);try{await st(e),_(!0),await W()}catch(e){y(e instanceof Error?e.message:String(e))}finally{p(!1)}},[W]),_e=(0,X.useCallback)(async e=>{a(e),c(null),u(!1);try{await ft(e),u(!0),await W()}catch(e){c(e instanceof Error?e.message:String(e))}finally{a(null)}},[W]),ve=!t||le||!!i,K=(0,X.useMemo)(()=>{let e=n?.payload?.config;return Ht(e??{})},[n]);(0,X.useEffect)(()=>{if(t){if(!w){T(K),C(K);return}JSON.stringify(K)!==JSON.stringify(w)&&(T(K),C(K))}},[w,K,t]);let ye=(0,X.useMemo)(()=>!S||!w?!1:JSON.stringify(S)!==JSON.stringify(w),[S,w]),be=(0,X.useCallback)(async()=>{if(S){D(!0),k(!1),j(null);try{await Ut(S),T(S),k(!0),await W()}catch(e){j(e instanceof Error?e.message:String(e))}finally{D(!1)}}},[S,W]);return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:e.title}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e.subtitle})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 items-center justify-end gap-2`,children:[K.enabled?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`select`,{className:`rounded-lg border border-edge bg-surface-panel px-2 py-1.5 text-xs text-fg`,value:b,onChange:e=>x(e.target.value),disabled:!t||f,children:[(0,Y.jsx)(`option`,{value:`light`,children:`Light`}),(0,Y.jsx)(`option`,{value:`deep`,children:`Deep`}),(0,Y.jsx)(`option`,{value:`rem`,children:`REM`})]}),(0,Y.jsxs)(G,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||f,onClick:()=>void ge(b),title:e.runNowHint,children:[f?(0,Y.jsx)(d,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(Ee,{className:`mr-2 size-4`,"aria-hidden":!0}),e.runNow]})]}):null,(0,Y.jsxs)(G,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t,onClick:()=>void pe(),children:[(0,Y.jsx)(He,{className:`mr-2 size-4`,"aria-hidden":!0}),e.refresh]})]})]}),de.length>0?(0,Y.jsx)(`div`,{className:`space-y-1.5 rounded-2xl border border-amber-500/20 bg-amber-500/5 px-4 py-3`,role:`alert`,children:de.map((e,t)=>(0,Y.jsx)(`p`,{className:`text-sm text-amber-800 dark:text-amber-200/90`,children:e},t))}):null,fe.length>0?(0,Y.jsx)(`div`,{className:`space-y-1.5 rounded-2xl border border-emerald-500/20 bg-emerald-500/5 px-4 py-3`,role:`status`,children:fe.map((e,t)=>(0,Y.jsx)(`p`,{className:`text-sm text-emerald-800 dark:text-emerald-200/90`,children:e},t))}):null,(0,Y.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,Y.jsxs)(wt,{className:`min-w-0`,children:[(0,Y.jsx)(Tt,{icon:ze,title:e.configTitle,subtitle:e.configHint,trailing:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(G,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||!S||E||!ye,onClick:()=>void be(),children:[E?(0,Y.jsx)(d,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,e.saveConfig]}),(0,Y.jsx)(G,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||!S||E||!ye,onClick:()=>{k(!1),j(null),C(w)},children:e.resetConfig})]})}),S?(0,Y.jsxs)(`div`,{className:`space-y-5`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-3`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configEnabled}),(0,Y.jsxs)(`label`,{className:`mt-2 inline-flex items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:S.enabled,onChange:e=>C({...S,enabled:e.target.checked})}),(0,Y.jsx)(`span`,{children:S.enabled?e.on:e.off})]})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configFrequency}),(0,Y.jsx)(`input`,{className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle dark:border-edge`,value:S.frequency,onChange:e=>C({...S,frequency:e.target.value}),placeholder:`0 3 * * *`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configTimezone}),(0,Y.jsx)(`input`,{className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle dark:border-edge`,value:S.timezone,onChange:e=>C({...S,timezone:e.target.value}),placeholder:`Asia/Shanghai`})]})]}),(0,Y.jsxs)(Kt,{label:e.configPhaseLight,children:[(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.configPhaseLightHint}),(0,Y.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configPhaseEnabled}),(0,Y.jsxs)(`label`,{className:`mt-2 inline-flex items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:S.light.enabled,onChange:e=>C({...S,light:{...S.light,enabled:e.target.checked}})}),(0,Y.jsx)(`span`,{children:S.light.enabled?e.on:e.off})]})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configPhaseCron}),(0,Y.jsx)(`input`,{className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.light.cron,onChange:e=>C({...S,light:{...S.light,cron:e.target.value}}),placeholder:`0 */6 * * *`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configLightLookbackDays}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.light.lookbackDays,onChange:e=>C({...S,light:{...S.light,lookbackDays:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configLightLimit}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:0,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.light.limit,onChange:e=>C({...S,light:{...S.light,limit:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configLightDedupe}),(0,Y.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.light.dedupeSimilarity,onChange:e=>C({...S,light:{...S.light,dedupeSimilarity:Number(e.target.value)}})})]})]})]}),(0,Y.jsxs)(Kt,{label:e.configPhaseDeep,children:[(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.configPhaseDeepHint}),(0,Y.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configPhaseEnabled}),(0,Y.jsxs)(`label`,{className:`mt-2 inline-flex items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:S.deep.enabled,onChange:e=>C({...S,deep:{...S.deep,enabled:e.target.checked}})}),(0,Y.jsx)(`span`,{children:S.deep.enabled?e.on:e.off})]})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configPhaseCron}),(0,Y.jsx)(`input`,{className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.deep.cron,onChange:e=>C({...S,deep:{...S.deep,cron:e.target.value}}),placeholder:`0 3 * * *`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configDeepMinScore}),(0,Y.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.deep.minScore,onChange:e=>C({...S,deep:{...S.deep,minScore:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configDeepMinRecallCount}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.deep.minRecallCount,onChange:e=>C({...S,deep:{...S.deep,minRecallCount:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configDeepLimit}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:0,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.deep.limit,onChange:e=>C({...S,deep:{...S.deep,limit:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configDeepHalfLife}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.deep.recencyHalfLifeDays,onChange:e=>C({...S,deep:{...S.deep,recencyHalfLifeDays:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configDeepMaxAge}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.deep.maxAgeDays,onChange:e=>C({...S,deep:{...S.deep,maxAgeDays:Number(e.target.value)}})})]})]})]}),(0,Y.jsxs)(Kt,{label:e.configPhaseRem,children:[(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.configPhaseRemHint}),(0,Y.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configPhaseEnabled}),(0,Y.jsxs)(`label`,{className:`mt-2 inline-flex items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:S.rem.enabled,onChange:e=>C({...S,rem:{...S.rem,enabled:e.target.checked}})}),(0,Y.jsx)(`span`,{children:S.rem.enabled?e.on:e.off})]})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configPhaseCron}),(0,Y.jsx)(`input`,{className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.rem.cron,onChange:e=>C({...S,rem:{...S.rem,cron:e.target.value}}),placeholder:`0 5 * * 0`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configRemLookbackDays}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.rem.lookbackDays,onChange:e=>C({...S,rem:{...S.rem,lookbackDays:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configRemLimit}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:0,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.rem.limit,onChange:e=>C({...S,rem:{...S.rem,limit:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configRemMinStrength}),(0,Y.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.rem.minPatternStrength,onChange:e=>C({...S,rem:{...S.rem,minPatternStrength:Number(e.target.value)}})})]})]})]})]}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.configLoading})]}),(0,Y.jsxs)(wt,{className:`min-w-0`,children:[(0,Y.jsx)(Tt,{icon:M,title:e.runtimeTitle,subtitle:e.runtimeHint,trailing:le?(0,Y.jsx)(d,{className:`size-4 shrink-0 animate-spin text-fg-muted`,"aria-hidden":!0}):null}),(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsx)(Kt,{label:e.subsectionSchedule,children:(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.enabled}),(0,Y.jsx)(`div`,{className:Q(),children:U?U.config.enabled?e.on:e.off:`—`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.lock}),(0,Y.jsx)(`div`,{className:g(Q(),ue?.className),children:ue?ue.text:`—`})]}),(0,Y.jsxs)(`div`,{className:g(J(),`sm:col-span-2`),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.schedule}),(0,Y.jsx)(`div`,{className:`mt-1 break-all font-mono text-sm text-fg`,children:U?U.config.frequency:`—`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.timezone}),(0,Y.jsx)(`div`,{className:Q(),children:U?U.config.timezone:`—`})]})]})}),(0,Y.jsx)(Kt,{label:e.subsectionStore,children:(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.storeEntries}),(0,Y.jsx)(`div`,{className:Q(),children:U?String(U.store.entryCount):`—`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.storePromoted}),(0,Y.jsx)(`div`,{className:Q(),children:U?String(U.store.promotedCount):`—`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.storeUpdatedAt}),(0,Y.jsx)(`div`,{className:Q(),children:U?Wt(U.store.updatedAt):`—`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.storeLastPromotedAt}),(0,Y.jsx)(`div`,{className:Q(),children:U?Wt(U.store.lastPromotedAt):`—`})]})]})}),U?.config?.phases?(0,Y.jsx)(Kt,{label:e.subsectionPhases,children:(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-3`,children:[(0,Y.jsx)(qt,{icon:(0,Y.jsx)(je,{className:`size-4 text-amber-500`}),label:`Light`,enabled:U.config.phases.light.enabled,cron:U.config.phases.light.cron,details:`lookback=${U.config.phases.light.lookbackDays}d, limit=${U.config.phases.light.limit}, dedupe=${U.config.phases.light.dedupeSimilarity}`,t:e}),(0,Y.jsx)(qt,{icon:(0,Y.jsx)(Ze,{className:`size-4 text-indigo-500`}),label:`Deep`,enabled:U.config.phases.deep.enabled,cron:U.config.phases.deep.cron,details:`minScore=${U.config.phases.deep.minScore}, recalls≥${U.config.phases.deep.minRecallCount}, limit=${U.config.phases.deep.limit}, halfLife=${U.config.phases.deep.recencyHalfLifeDays}d`,t:e}),(0,Y.jsx)(qt,{icon:(0,Y.jsx)(I,{className:`size-4 text-purple-500`}),label:`REM`,enabled:U.config.phases.rem.enabled,cron:U.config.phases.rem.cron,details:`lookback=${U.config.phases.rem.lookbackDays}d, limit=${U.config.phases.rem.limit}, strength≥${U.config.phases.rem.minPatternStrength}`,t:e})]})}):null,(0,Y.jsxs)(Kt,{label:e.subsectionLastRun,children:[(0,Y.jsx)(`p`,{className:`mb-2 text-xs text-fg-muted`,children:e.lastRunBlockHint}),U?.lastRun?.exists?(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[U.lastRun.parseError?(0,Y.jsxs)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:[e.lastRunParseError,`: `,U.lastRun.parseError]}):null,U.lastRun.record?(0,Y.jsx)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel/40 p-2 sm:p-3`,children:(0,Y.jsx)(Yt,{t:e,r:U.lastRun.record})}):null,U.lastRun.raw!==void 0&&U.lastRun.raw!==null?(0,Y.jsxs)(`details`,{className:`group rounded-lg border border-edge-subtle`,children:[(0,Y.jsx)(`summary`,{className:`cursor-pointer list-none px-3 py-2 text-xs font-medium text-fg-muted marker:hidden [&::-webkit-details-marker]:hidden`,children:(0,Y.jsx)(`span`,{className:`underline decoration-edge underline-offset-2 group-open:text-fg`,children:e.lastRunRaw})}),(0,Y.jsx)(`pre`,{className:`max-h-[12rem] overflow-auto border-t border-edge-subtle p-3 text-xs text-fg-muted`,children:JSON.stringify(U.lastRun.raw,null,2)})]}):null]}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.lastRunEmpty})]}),(0,Y.jsx)(Jt,{label:e.subsectionLightLastRun,lastRun:U?.lightLastRun,t:e}),(0,Y.jsx)(Jt,{label:e.subsectionRemLastRun,lastRun:U?.remLastRun,t:e})]})]})]}),(0,Y.jsxs)(wt,{children:[(0,Y.jsx)(Tt,{icon:se,title:e.previewTitle,subtitle:e.previewHint,trailing:(0,Y.jsxs)(G,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||P,onClick:()=>void me(),children:[P?(0,Y.jsx)(d,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,e.previewLoad]})}),R?R.length>0?(0,Y.jsx)(`div`,{className:`space-y-2`,children:R.map(t=>{let n=`${t.path}:${t.startLine}-${t.endLine}`,r=t.skippedReason;return(0,Y.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel/60 px-3 py-3`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-fg-muted`,children:[(0,Y.jsx)(`span`,{className:`font-medium text-fg`,children:n}),(0,Y.jsxs)(`span`,{children:[`score=`,t.score.toFixed(3)]}),(0,Y.jsxs)(`span`,{children:[`recalls=`,t.recallCount]}),(0,Y.jsxs)(`span`,{children:[`avg=`,t.avgScore.toFixed(3)]}),(0,Y.jsxs)(`span`,{children:[`decay=`,t.recencyDecay?.toFixed(3)??`—`]}),r?(0,Y.jsx)(`span`,{className:`text-amber-600 dark:text-amber-400`,children:r}):(0,Y.jsx)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:e.previewEligible})]}),t.snippet?(0,Y.jsx)(`div`,{className:`mt-2 text-sm text-fg`,children:t.snippet}):null]},`${t.key}:${t.hash}:${n}`)})}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.previewEmpty}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.previewNotLoaded})]}),(0,Y.jsxs)(wt,{children:[(0,Y.jsx)(Tt,{icon:M,title:e.eventsTitle,subtitle:e.eventsHint,trailing:(0,Y.jsxs)(G,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||ie,onClick:()=>void he(),children:[ie?(0,Y.jsx)(d,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,e.eventsLoad]})}),V?V.length>0?(0,Y.jsx)(`div`,{className:`space-y-1.5`,children:V.map((e,t)=>{let n=e.phase===`light`?`☀️`:e.phase===`rem`?`✨`:`🌙`,r=e.phase===`light`?`scanned=${e.scannedEntries??0} new=${e.newSignals??0} deduped=${e.deduped??0}`:e.phase===`rem`?`patterns=${e.patternsDiscovered??0} analyzed=${e.entriesAnalyzed??0}`:`candidates=${e.candidates??0} applied=${e.applied??0}`;return(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 rounded-lg border border-edge-subtle bg-surface-panel/60 px-3 py-2 text-xs`,children:[(0,Y.jsx)(`span`,{children:n}),(0,Y.jsx)(`span`,{className:`font-medium text-fg`,children:e.phase}),(0,Y.jsx)(`span`,{className:g(`font-medium`,e.ok?`text-emerald-600 dark:text-emerald-400`:`text-amber-600 dark:text-amber-400`),children:e.ok?`OK`:`FAIL`}),(0,Y.jsx)(`span`,{className:`text-fg-muted`,children:r}),(0,Y.jsx)(`span`,{className:`text-fg-muted`,children:Gt(e.durationMs)}),(0,Y.jsx)(`span`,{className:`ml-auto text-fg-subtle`,children:Wt(e.timestamp)})]},`${e.timestamp}:${e.phase}:${t}`)})}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.eventsEmpty}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.eventsNotLoaded})]}),(0,Y.jsxs)(wt,{className:`max-w-2xl`,children:[(0,Y.jsx)(Tt,{icon:ee,title:e.maintenanceTitle,subtitle:e.maintenanceHint}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,Y.jsxs)(G,{variant:`secondary`,disabled:ve,onClick:()=>{confirm(e.confirmResetStore)&&_e(`reset_store`)},children:[i===`reset_store`?(0,Y.jsx)(d,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(te,{className:`mr-2 size-4`,"aria-hidden":!0}),e.resetStore]}),(0,Y.jsxs)(G,{variant:`secondary`,disabled:ve,onClick:()=>{confirm(e.confirmClearLock)&&_e(`clear_lock`)},children:[i===`clear_lock`?(0,Y.jsx)(d,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(m,{className:`mr-2 size-4`,"aria-hidden":!0}),e.clearLock]})]})]})]})}var Qt=e(Et(),1);function $t(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function en(e){let t=$t(e)?e:{},n=$t(t.gateway)?t.gateway:{},r=$t(n.auth)?n.auth:{},i=r.mode===`none`||r.mode===`token`?r.mode:`token`,a=($t(t.update)?t.update:{}).channel,o=a===`beta`||a===`dev`||a===`stable`?a:`stable`;return{host:typeof n.host==`string`?n.host:``,port:typeof n.port==`number`?n.port:void 0,auth:{mode:i,token:typeof r.token==`string`?r.token:``},updateChannel:o}}async function tn(e){let t=e.auth.token.trim().length>0?{mode:e.auth.mode,token:e.auth.token}:{mode:e.auth.mode};await ge(q(`/api/config`),{method:`PATCH`,body:JSON.stringify({gateway:{auth:t},update:{channel:e.updateChannel}})}),H()}function nn(){return g(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,K,`dark:border-edge`)}function rn(){let e=N(e=>e.language),t=o(e),n=t.gatewaySettings,r=z(e=>e.token),i=z(e=>e.tokenExpired),a=z(e=>e.openTokenDialog),s=!!r,[c,l]=(0,X.useState)(null),[u,f]=(0,X.useState)(null),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(null),[_,v]=(0,X.useState)(!1),[y,b]=(0,X.useState)(!1),[x,S]=(0,X.useState)(!1),C=(0,X.useRef)(!1),{data:w,error:T,isLoading:E,mutate:D}=Ye(s),O=(0,X.useMemo)(()=>w?.payload?.config===void 0?null:structuredClone(en(w.payload.config)),[w]);(0,X.useEffect)(()=>{if(!s){l(null),f(null),C.current=!1;return}O!==null&&(C.current||(l(O),f(structuredClone(O)),v(!1)))},[s,O]);let k=!!(s&&E&&w===void 0&&!T),ee=T instanceof Error?T.message:T?String(T):null,A=(0,X.useMemo)(()=>!c||!u?!1:JSON.stringify(c)!==JSON.stringify(u),[c,u]),j=(0,X.useCallback)(e=>{C.current=!0,l(t=>t?{...t,auth:{...t.auth,...e}}:null)},[]),M=(0,X.useCallback)(e=>{C.current=!0,l(t=>t?{...t,updateChannel:e}:null)},[]),P=(0,X.useCallback)(async()=>{if(!(!c||p)){m(!0),g(null),v(!1);try{await tn(c),C.current=!1,f(structuredClone(c)),v(!0),window.setTimeout(()=>v(!1),2500)}catch(e){g(e instanceof Error?e.message:n.saveError)}finally{m(!1)}}},[c,p,n.saveError]),F=(0,X.useCallback)(()=>{u&&(C.current=!1,l(structuredClone(u)),g(null),v(!1))},[u]),te=(0,X.useCallback)(async()=>{let e=c?.auth.token;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),S(!0),window.setTimeout(()=>S(!1),2e3))},[c?.auth.token]);return s?k?(0,Y.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,Y.jsx)(d,{className:`size-4 animate-spin`}),n.loading]})}):c?(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.gateway}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,Y.jsxs)(`a`,{href:We(e,`gateway`),target:`_blank`,rel:`noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-sm text-accent hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,children:[n.docsLink,(0,Y.jsx)(ne,{className:`size-3.5`})]})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[_?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,Y.jsx)(G,{type:`button`,variant:`secondary`,disabled:!A||p,onClick:F,children:n.discard}),(0,Y.jsx)(G,{type:`button`,variant:`primary`,disabled:!A||p,onClick:()=>void P(),children:p?n.saving:n.save})]})]}),i?(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-lg border border-red-200 bg-red-50 px-4 py-3 dark:border-red-900/50 dark:bg-red-950/40`,role:`alert`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(xe,{className:`mt-0.5 size-4 shrink-0 text-red-600 dark:text-red-400`}),(0,Y.jsx)(`p`,{className:`text-sm text-red-900 dark:text-red-100`,children:n.tokenExpired})]}),(0,Y.jsx)(`div`,{children:(0,Y.jsx)(G,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:()=>a(),children:n.updateToken})})]}):null,A?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,h?(0,Y.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:h}):null,c.auth.mode===`none`?(0,Y.jsx)(`p`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-950 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-100`,children:n.authModeNone}):null,(0,Y.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[(0,Y.jsxs)(`div`,{className:`mb-5 flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)(Pe,{className:`size-4 text-accent`,strokeWidth:1.75}),t.settingsSections.gateway]}),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(c.host||c.port!=null)&&(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:n.listenHost}),(0,Y.jsx)(`div`,{className:`rounded-lg bg-surface-hover/80 px-3 py-2 font-mono text-xs text-fg-muted dark:bg-surface-hover/50`,children:c.host||`—`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:n.listenPort}),(0,Y.jsx)(`div`,{className:`rounded-lg bg-surface-hover/80 px-3 py-2 font-mono text-xs text-fg-muted dark:bg-surface-hover/50`,children:c.port==null?`—`:String(c.port)})]}),(0,Y.jsx)(`p`,{className:`sm:col-span-2 text-xs text-fg-subtle`,children:n.listenHint})]}),(0,Y.jsx)(on,{g:n,value:c.auth.token,show:y,copied:x,onToggleShow:()=>b(e=>!e),onCopy:()=>void te(),onChange:e=>j({token:e})}),(0,Y.jsx)(G,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,onClick:()=>a(),children:n.changeToken}),r?(0,Y.jsx)(an,{g:n,gatewayToken:r}):null,(0,Y.jsxs)(`div`,{className:`space-y-2 border-t border-edge pt-4`,children:[(0,Y.jsx)(`label`,{className:`text-sm font-medium text-fg`,htmlFor:`gateway-update-channel`,children:n.updateChannel}),(0,Y.jsxs)(`select`,{id:`gateway-update-channel`,value:c.updateChannel,onChange:e=>M(e.target.value),className:nn(),children:[(0,Y.jsx)(`option`,{value:`stable`,children:n.channelStable}),(0,Y.jsx)(`option`,{value:`beta`,children:n.channelBeta}),(0,Y.jsx)(`option`,{value:`dev`,children:n.channelDev})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.updateChannelHint})]})]})]})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:h??ee??n.loadError}),(0,Y.jsx)(G,{type:`button`,variant:`secondary`,onClick:()=>void D(),children:n.retry})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.gateway}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}function an({g:e,gatewayToken:t}){let[n,r]=(0,X.useState)(de),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(!1),[c,l]=(0,X.useState)(!1),u=n.trim(),d=(0,X.useMemo)(()=>{try{let e=new URL(u);return e.protocol===`http:`||e.protocol===`https:`}catch{return!1}},[u]),f=(0,X.useMemo)(()=>!t||!d?``:le({baseUrl:u,gatewayToken:t}),[d,t,u]);(0,X.useEffect)(()=>{if(!f){a(null),s(!1);return}let e=!1;return s(!1),Qt.toDataURL(f,{width:216,margin:2,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}}).then(t=>{e||a(t)}).catch(()=>{e||(s(!0),a(null))}),()=>{e=!0}},[f]);let p=d&&Ae(u),m=(0,X.useCallback)(async()=>{f&&(await navigator.clipboard.writeText(f).catch(()=>{}),l(!0),window.setTimeout(()=>l(!1),2e3))},[f]);return(0,Y.jsxs)(`div`,{className:`space-y-3 border-t border-edge pt-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)(R,{className:`size-4 text-accent`,strokeWidth:1.75}),e.mobilePairTitle]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.mobilePairSubtitle}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{className:`text-sm font-medium text-fg`,htmlFor:`gateway-mobile-pair-base`,children:e.mobilePairBaseUrlLabel}),(0,Y.jsx)(`input`,{id:`gateway-mobile-pair-base`,className:g(nn(),`font-mono text-xs`),type:`text`,autoComplete:`off`,spellCheck:!1,value:n,onChange:e=>r(e.target.value)}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.mobilePairBaseUrlHint}),d?null:(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:e.mobilePairInvalidBaseUrl}),p?(0,Y.jsx)(`p`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-950 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-100`,children:e.mobilePairLocalhostWarning}):null,(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.mobilePairSecurityNote})]}),f?(0,Y.jsxs)(`div`,{className:`flex flex-col items-center gap-3 sm:items-start`,children:[i&&!o?(0,Y.jsx)(`img`,{src:i,alt:``,className:`h-56 w-56 rounded-lg border border-edge-subtle bg-white object-contain p-3 dark:border-edge`}):null,!i&&!o?(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.mobilePairEncoding}):null,o?(0,Y.jsx)(`p`,{className:`text-center text-sm text-fg-muted sm:text-left`,children:e.mobilePairImageError}):null,(0,Y.jsxs)(G,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,disabled:!f,onClick:()=>void m(),children:[c?(0,Y.jsx)(we,{className:`size-3.5`}):(0,Y.jsx)(W,{className:`size-3.5`}),c?e.mobilePairCopied:e.mobilePairCopyLink]})]}):null,(0,Y.jsx)(`p`,{className:`break-all font-mono text-[10px] leading-relaxed text-fg-subtle`,children:e.mobilePairSchemeHint})]})}function on({g:e,value:t,show:n,copied:r,onToggleShow:i,onCopy:a,onChange:o}){return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.accessToken}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Y.jsx)(`input`,{className:g(nn(),`min-w-0 flex-1 font-mono text-xs`),type:n?`text`:`password`,autoComplete:`off`,value:t,onChange:e=>o(e.target.value),placeholder:e.tokenPlaceholder}),t?(0,Y.jsxs)(G,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:a,children:[r?(0,Y.jsx)(we,{className:`size-3.5`}):(0,Y.jsx)(W,{className:`size-3.5`}),r?e.copied:e.copy]}):null,(0,Y.jsxs)(G,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:i,children:[n?(0,Y.jsx)(x,{className:`size-3.5`}):(0,Y.jsx)(Me,{className:`size-3.5`}),n?e.hide:e.show]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tokenHelp})]})}function sn(){return q(`/api/channels/status`)}var cn=it;function ln(){return q(`/api/workspace/heartbeat-md`)}async function un(){let e=await ge(ln());return typeof e.payload?.content==`string`?e.payload.content:``}function dn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function fn(e){let t=dn(e)?e:{},n=dn(t.gateway)?t.gateway:{},r=dn(n.heartbeat)?n.heartbeat:{},i=r.activeHours,a=dn(i)?i:null,o=a&&typeof a.start==`string`&&typeof a.end==`string`&&a.start&&a.end?{start:a.start,end:a.end,timezone:typeof a.timezone==`string`?a.timezone:``}:null;return{enabled:!!(r.enabled??!0),intervalMs:typeof r.intervalMs==`number`&&Number.isFinite(r.intervalMs)?r.intervalMs:18e5,target:typeof r.target==`string`?r.target:``,targetChatId:typeof r.targetChatId==`string`?r.targetChatId:``,prompt:typeof r.prompt==`string`?r.prompt:``,ackMaxChars:typeof r.ackMaxChars==`number`&&Number.isFinite(r.ackMaxChars)?r.ackMaxChars:``,isolatedSession:!!r.isolatedSession,activeHours:o}}function pn(e){let t={enabled:e.enabled,intervalMs:e.intervalMs};return e.target.trim()?t.target=e.target.trim():t.target=null,e.targetChatId.trim()?t.targetChatId=e.targetChatId.trim():t.targetChatId=null,e.prompt.trim()?t.prompt=e.prompt.trim():t.prompt=null,e.ackMaxChars===``||e.ackMaxChars===void 0?t.ackMaxChars=null:t.ackMaxChars=e.ackMaxChars,e.isolatedSession?t.isolatedSession=!0:t.isolatedSession=null,e.activeHours?.start?.trim()&&e.activeHours?.end?.trim()?t.activeHours={start:e.activeHours.start.trim(),end:e.activeHours.end.trim(),...e.activeHours.timezone.trim()?{timezone:e.activeHours.timezone.trim()}:{}}:t.activeHours=null,t}async function mn(e){await ge(q(`/api/config`),{method:`PATCH`,body:JSON.stringify({gateway:{heartbeat:pn(e)}})}),H()}async function hn(e){await ge(q(`/api/workspace/heartbeat-md`),{method:`PUT`,body:JSON.stringify({content:e})}),i(ln())}async function gn(e){await ge(q(`/api/heartbeat/trigger`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e?{reason:e}:{})})}var _n=[3e4,6e4,3e5,6e5,9e5,18e5,36e5,72e5],vn=new Set(_n);function yn(){return g(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,K,`dark:border-edge`)}function bn(){return g(D,p)}function xn(e){if(!e||typeof e!=`object`||Array.isArray(e))return``;let t=e.agents;if(!t||typeof t!=`object`||Array.isArray(t))return``;let n=t.defaults;if(!n||typeof n!=`object`||Array.isArray(n))return``;let r=n.workspace;return typeof r==`string`?r:``}function Sn(e,t){switch(e){case 3e4:return t.every30s;case 6e4:return t.every1min;case 3e5:return t.every5min;case 6e5:return t.every10min;case 9e5:return t.every15min;case 18e5:return t.every30min;case 36e5:return t.every1h;case 72e5:return t.every2h;default:return String(e)}}function Cn(){let e=N(e=>e.language),t=o(e),n=t.heartbeatSettings,i=!!z(e=>e.token),[a,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),[u,f]=(0,X.useState)(``),[p,m]=(0,X.useState)(``),[h,_]=(0,X.useState)(!1),[v,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(null),[S,C]=(0,X.useState)(!1),[w,T]=(0,X.useState)(!1),[E,D]=(0,X.useState)(!1),[O,k]=(0,X.useState)(!1),[ee,A]=(0,X.useState)(null),[j,M]=(0,X.useState)([]),{data:P,error:F,isLoading:te,mutate:I}=Ye(i),{data:L,error:R,isLoading:re,mutate:ie}=r(i?ln():null,un,{revalidateOnFocus:!1}),{data:ae=[]}=r(i?sn():null,cn,{revalidateOnFocus:!1}),oe=(0,X.useMemo)(()=>xn(P?.payload?.config),[P]),B=(0,X.useMemo)(()=>fn(P?.payload?.config??{}),[P]),V=(0,X.useMemo)(()=>!a||!c?!1:JSON.stringify(a)!==JSON.stringify(c),[a,c]),H=(0,X.useMemo)(()=>u!==p,[u,p]);(0,X.useEffect)(()=>{if(!i){s(null),l(null);return}if(P!==void 0&&!V){let e=structuredClone(B);s(e),l(e),C(!1)}},[i,P,B,V]),(0,X.useEffect)(()=>{!i||L===void 0||H||(f(L),m(L),T(!1))},[i,L,H]);let U=F instanceof Error?F.message:F?String(F):R instanceof Error?R.message:R?String(R):null,se=!!(i&&(P===void 0||L===void 0)&&!U&&(te||re));(0,X.useEffect)(()=>{if(!i||!a){M([]);return}let e=a.target.trim();if(!e){M([]);return}let t=!1;return at(e).then(e=>{t||M(e)}),()=>{t=!0}},[i,a?.target]);let ce=(0,X.useCallback)(()=>{let e=a?.target?.trim();e&&at(e).then(M)},[a?.target]),le=(0,X.useCallback)(async()=>{D(!0),k(!1),A(null);try{await gn(),k(!0),window.setTimeout(()=>k(!1),3e3)}catch(e){A(e instanceof Error?e.message:n.triggerError)}finally{D(!1)}},[n.triggerError]),W=(0,X.useCallback)(e=>{s(t=>t?{...t,...e}:null)},[]),ue=(0,X.useCallback)(()=>{c&&(s(structuredClone(c)),C(!1),x(null))},[c]),de=(0,X.useCallback)(()=>{f(p),T(!1),x(null)},[p]),fe=(0,X.useCallback)(async()=>{if(!(!a||h)){_(!0),x(null),C(!1);try{await mn(a),l(structuredClone(a)),C(!0),window.setTimeout(()=>C(!1),2500)}catch(e){x(e instanceof Error?e.message:n.saveConfigError)}finally{_(!1)}}},[a,h,n.saveConfigError]),pe=(0,X.useCallback)(async()=>{if(!v){y(!0),x(null),T(!1);try{await hn(u),m(u),T(!0),window.setTimeout(()=>T(!1),2500)}catch(e){x(e instanceof Error?e.message:n.saveDocError)}finally{y(!1)}}},[u,v,n.saveDocError]);return i?se?(0,Y.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,Y.jsx)(d,{className:`size-4 animate-spin`}),n.loading]})}):a?(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Y.jsx)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.heartbeat}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,Y.jsxs)(`a`,{href:We(e,`heartbeat`),target:`_blank`,rel:`noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-sm text-accent hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,children:[n.docsLink,(0,Y.jsx)(ne,{className:`size-3.5`})]})]})}),oe?(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.workspaceLabel,`: `,(0,Y.jsx)(`span`,{className:`font-mono text-fg-muted`,children:oe})]}):null,b?(0,Y.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:b}):null,(0,Y.jsxs)(wt,{children:[(0,Y.jsxs)(`div`,{className:`mb-2 flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)($e,{className:`size-4 text-accent`,strokeWidth:1.75}),n.configSection]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsxs)(G,{type:`button`,variant:`secondary`,className:`inline-flex items-center gap-2`,disabled:E,onClick:()=>void le(),children:[E?(0,Y.jsx)(d,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(Ee,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),E?n.triggering:n.triggerNow]}),O?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.triggered}):null]})]}),(0,Y.jsx)(`p`,{className:`mb-4 text-xs text-fg-subtle`,children:n.triggerHint}),ee?(0,Y.jsx)(`p`,{className:`mb-3 text-sm text-red-600 dark:text-red-400`,children:ee}):null,(0,Y.jsx)(wn,{h:n,cron:t.cron,form:a,channels:ae,sessionChatIds:j,onRefreshChatIds:ce,update:W,inputClassName:yn,selectClassName:bn}),(0,Y.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-2`,children:[S?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.savedConfig}):null,(0,Y.jsx)(G,{type:`button`,variant:`secondary`,disabled:!V||h,onClick:ue,children:n.discard}),(0,Y.jsx)(G,{type:`button`,variant:`primary`,disabled:!V||h,onClick:()=>void fe(),children:h?n.savingConfig:n.saveConfig}),V?(0,Y.jsx)(`span`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedConfig}):null]})]}),(0,Y.jsxs)(wt,{children:[(0,Y.jsx)(`div`,{className:`mb-2 text-sm font-semibold text-fg`,children:n.docSection}),(0,Y.jsx)(`p`,{className:`mb-3 text-xs text-fg-subtle`,children:n.docHint}),(0,Y.jsx)(`textarea`,{className:g(yn(),`min-h-[12rem] resize-y font-mono text-xs leading-relaxed`),value:u,onChange:e=>f(e.target.value),spellCheck:!1,"aria-label":n.docSection}),(0,Y.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-2`,children:[w?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.savedDoc}):null,(0,Y.jsx)(G,{type:`button`,variant:`secondary`,disabled:!H||v,onClick:de,children:n.discard}),(0,Y.jsx)(G,{type:`button`,variant:`primary`,disabled:!H||v,onClick:()=>void pe(),children:v?n.savingDoc:n.saveDoc}),H?(0,Y.jsx)(`span`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedDoc}):null]})]})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:b??U??n.loadError}),(0,Y.jsx)(G,{type:`button`,variant:`secondary`,onClick:()=>{I(),ie()},children:n.retry})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.heartbeat}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}function wn({h:e,cron:t,form:n,channels:r,sessionChatIds:i,onRefreshChatIds:a,update:o,inputClassName:s,selectClassName:c}){let l=(0,X.useMemo)(()=>new Set(r.map(e=>e.name)),[r]),u=n.target.trim(),d=!!(u&&!l.has(u)),f=(0,X.useMemo)(()=>vn.has(n.intervalMs)?String(n.intervalMs):``,[n.intervalMs]),[p,m]=(0,X.useState)(null),h=Math.max(1,Math.round(n.intervalMs/1e3)),_=p===null?String(h):p;return(0,X.useEffect)(()=>{m(null)},[n.intervalMs]),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:n.enabled,onChange:e=>o({enabled:e.target.checked})}),e.enable]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.interval}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:e.intervalSecondsLabel}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`input`,{type:`number`,min:1,step:1,className:g(s(),`min-w-0 flex-1`),value:_,onChange:e=>{let t=e.target.value;m(t);let n=parseInt(t,10);Number.isFinite(n)&&n>=1&&o({intervalMs:n*1e3})},onBlur:()=>{if(p===null)return;let e=parseInt(p,10);o(!Number.isFinite(e)||e<1?{intervalMs:1e3}:{intervalMs:e*1e3}),m(null)}}),(0,Y.jsxs)(`select`,{className:g(c(),`max-w-[11rem] shrink-0 text-xs`),value:f,onChange:e=>{let t=e.target.value;t&&(o({intervalMs:parseInt(t,10)}),m(null))},children:[(0,Y.jsx)(`option`,{value:``,children:e.intervalPresets.custom}),_n.map(t=>(0,Y.jsx)(`option`,{value:String(t),children:Sn(t,e.intervalPresets)},t))]})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.intervalHintPreset}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.intervalHint})]}),(0,Y.jsxs)(`div`,{className:`border-t border-edge-subtle pt-4`,children:[(0,Y.jsx)(`div`,{className:`mb-2 text-sm font-medium text-fg`,children:e.deliveryTitle}),(0,Y.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:t.channel}),(0,Y.jsxs)(`select`,{className:c(),value:u,onChange:e=>{o({target:e.target.value.trim(),targetChatId:``})},children:[(0,Y.jsx)(`option`,{value:``,children:e.channelNone}),d?(0,Y.jsxs)(`option`,{value:u,children:[u,` (`,e.customChannelSuffix,`)`]}):null,r.map(e=>(0,Y.jsxs)(`option`,{value:e.name,disabled:!e.enabled,children:[e.name,` `,e.enabled?``:`(disabled)`]},e.name))]})]}),u?(0,Y.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:t.recipient}),(0,Y.jsxs)(G,{type:`button`,variant:`ghost`,className:`h-7 gap-1 px-2 text-xs`,title:t.refreshRecipientHint,onClick:a,children:[(0,Y.jsx)(He,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0}),t.refreshList]})]}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`input`,{type:`text`,className:g(s(),`min-w-0 flex-1`),value:n.targetChatId,onChange:e=>o({targetChatId:e.target.value}),placeholder:t.recipientPlaceholder,autoComplete:`off`}),(0,Y.jsxs)(`select`,{className:g(c(),`max-w-[10rem] shrink-0 text-xs`),value:n.targetChatId,onChange:e=>{let t=e.target.value;t&&o({targetChatId:t})},children:[(0,Y.jsx)(`option`,{value:``,children:t.selectRecipient}),i.length>0?i.map(e=>(0,Y.jsx)(`option`,{value:e.chatId,children:ot(e,t.lastActiveLabels)},`${e.channel}-${e.chatId}`)):(0,Y.jsx)(`option`,{value:``,disabled:!0,children:t.noRecentChatsOption})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:i.length>0?t.enterManuallyOrSelect:t.noRecentChats})]}):null,(0,Y.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:e.deliveryHint})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:e.prompt}),(0,Y.jsx)(`textarea`,{className:g(s(),`min-h-[4.5rem] resize-y font-mono text-xs`),value:n.prompt,onChange:e=>o({prompt:e.target.value}),placeholder:e.promptPlaceholder}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:e.promptHint})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:e.ackMaxChars}),(0,Y.jsx)(`input`,{type:`number`,min:1,className:s(),value:n.ackMaxChars===``?``:n.ackMaxChars,onChange:e=>{let t=e.target.value;if(t===``)o({ackMaxChars:``});else{let e=parseInt(t,10);o({ackMaxChars:Number.isFinite(e)?e:``})}},placeholder:e.ackDefaultPlaceholder}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:e.ackMaxCharsHint})]}),(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:n.isolatedSession,onChange:e=>o({isolatedSession:e.target.checked})}),(0,Y.jsxs)(`span`,{children:[e.isolatedSession,(0,Y.jsx)(`span`,{className:`mt-1 block text-xs text-fg-subtle`,children:e.isolatedSessionHint})]})]}),(0,Y.jsxs)(`div`,{className:`border-t border-edge-subtle pt-4`,children:[(0,Y.jsx)(`div`,{className:`mb-2 text-sm font-medium text-fg`,children:e.activeHoursTitle}),n.activeHours?(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-xs text-fg`,children:e.activeStart}),(0,Y.jsx)(`input`,{className:s(),value:n.activeHours.start,onChange:e=>o({activeHours:{...n.activeHours,start:e.target.value}}),placeholder:`09:00`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-xs text-fg`,children:e.activeEnd}),(0,Y.jsx)(`input`,{className:s(),value:n.activeHours.end,onChange:e=>o({activeHours:{...n.activeHours,end:e.target.value}}),placeholder:`22:00`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-xs text-fg`,children:e.activeTimezone}),(0,Y.jsx)(`input`,{className:s(),value:n.activeHours.timezone,onChange:e=>o({activeHours:{...n.activeHours,timezone:e.target.value}}),placeholder:`Asia/Shanghai`})]})]}):(0,Y.jsx)(G,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:()=>o({activeHours:{start:`09:00`,end:`22:00`,timezone:``}}),children:e.addActiveHours}),n.activeHours?(0,Y.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:(0,Y.jsx)(G,{type:`button`,variant:`secondary`,className:`text-xs`,onClick:()=>o({activeHours:null}),children:e.clearActiveHours})}):null,(0,Y.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:e.activeHoursHint})]})]})}async function Tn(){let e=await Te(q(`/api/image/providers`));if(!e.ok)throw Error(`Image providers: HTTP ${e.status}`);return(await e.json()).payload?.providers??[]}function En(e){let t=new Set,n=[];for(let r of e){let e=r.models.length>0?r.models:r.defaultModel?[r.defaultModel]:[];for(let i of e){let e=`${r.id}/${i}`;t.has(e)||(t.add(e),n.push(e))}}return n}function Dn(e,t){let n=En(e.filter(e=>e.configured===!0));return!t||n.includes(t)?n:[t,...n]}function On(e,t){let n=t.trim().toLowerCase();if(!n)return e;let r=n.split(/[/\s]+/).filter(Boolean);return e.filter(e=>{let t=e.toLowerCase();return r.every(e=>t.includes(e))})}var kn=`image-generation-providers`;function An({value:e,disabled:t,placeholder:n,searchPlaceholder:i,noMatches:a,registryEmptyHint:o,outOfFilterNote:s,className:c,onChange:l}){let[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(``),{data:h,isLoading:v,error:y}=r(kn,Tn,{revalidateOnFocus:!1}),x=e.trim(),S=(0,X.useMemo)(()=>En((h??[]).filter(e=>e.configured===!0)),[h]),C=(0,X.useMemo)(()=>Dn(h??[],x),[h,x]),T=(0,X.useMemo)(()=>On(C,p),[C,p]),E=!!s&&!!x&&!S.includes(x),D=e.trim()?e:n,O=e.trim()||n,k=(0,X.useCallback)(e=>{f(e),e||m(``)},[]);return(0,Y.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,Y.jsxs)(w,{open:d,onOpenChange:k,modal:!1,children:[(0,Y.jsx)(j,{asChild:!0,children:(0,Y.jsxs)(`button`,{type:`button`,disabled:t||v,title:v?`…`:O,className:g(Ke,`items-center gap-2 rounded-lg border border-edge-subtle bg-surface-panel px-3 py-2 text-left text-sm font-normal text-fg`,L.transition,`hover:border-edge hover:bg-surface-hover/45`,u,`disabled:cursor-not-allowed disabled:opacity-50`,`dark:border-edge-subtle dark:hover:bg-surface-hover/55`,c),"aria-haspopup":`listbox`,"aria-expanded":d,children:[(0,Y.jsx)(`span`,{className:`min-w-0 truncate`,children:v?`…`:D}),(0,Y.jsx)(Ve,{className:`h-4 w-4 shrink-0 text-fg-subtle opacity-70`,"aria-hidden":!0})]})}),(0,Y.jsx)(b,{children:(0,Y.jsxs)(_,{className:g(`w-[min(22rem,calc(100vw-2rem))] rounded-xl border border-edge-subtle bg-surface-panel p-1 shadow-elevated dark:border-edge-subtle`,Xe),side:`bottom`,sideOffset:4,align:`end`,onOpenAutoFocus:e=>e.preventDefault(),children:[(0,Y.jsx)(`input`,{type:`search`,className:g(`mb-1 w-full rounded-lg border border-edge-subtle bg-surface-base px-2.5 py-1.5 text-sm text-fg placeholder:text-fg-disabled dark:bg-surface-hover/40`,P),placeholder:i,value:p,onChange:e=>m(e.target.value),onKeyDown:e=>e.stopPropagation()}),(0,Y.jsxs)(`div`,{className:`max-h-60 overflow-auto`,role:`listbox`,"aria-label":i,children:[y?(0,Y.jsx)(`div`,{className:`px-2 py-2 text-xs text-red-600 dark:text-red-400`,children:y instanceof Error?y.message:`Failed to load image providers`}):null,!y&&C.length===0&&!v?(0,Y.jsx)(`div`,{className:`px-2 py-3 text-center text-xs text-fg-muted`,children:o??a}):null,!y&&C.length>0&&T.length===0?(0,Y.jsx)(`div`,{className:`px-2 py-3 text-center text-xs text-fg-muted`,children:a}):null,T.map(t=>(0,Y.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t===e,className:g(`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-fg hover:bg-surface-hover`,t===e&&`bg-surface-hover/90 font-medium dark:bg-surface-hover/70`),onClick:()=>{l(t),f(!1),m(``)},children:[(0,Y.jsx)(we,{className:g(`h-4 w-4 shrink-0`,t!==e&&`invisible`),"aria-hidden":!0}),(0,Y.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm font-medium`,children:t})]},t))]})]})})]}),E?(0,Y.jsx)(`p`,{className:`text-xs text-amber-700 dark:text-amber-400/90`,children:s}):null]})}function jn(e){let{a:t,chat:n,form:r,update:i}=e;return(0,Y.jsxs)(wt,{children:[(0,Y.jsx)(Tt,{icon:A,title:t.cardModelsTitle,subtitle:t.cardModelsSubtitle}),(0,Y.jsxs)(`div`,{className:`mt-4 flex flex-col gap-5`,children:[(0,Y.jsx)(ut,{label:t.label.imageModel,description:t.desc.imageModel,children:(0,Y.jsx)(Ce,{value:r.imageModel,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,capabilitiesFilter:`vision`,registryEmptyHint:t.visionRegistryEmpty,outOfFilterNote:t.visionOutOfFilterNote,onChange:e=>i({imageModel:e})})}),(0,Y.jsx)(ut,{label:t.label.imageModelFallbacks,description:t.desc.imageModelFallbacks,children:(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[r.imageModelFallbacks.map((e,a)=>(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Y.jsx)(Ce,{value:e,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,capabilitiesFilter:`vision`,registryEmptyHint:t.visionRegistryEmpty,outOfFilterNote:t.visionOutOfFilterNote,onChange:e=>{let t=[...r.imageModelFallbacks];t[a]=e,i({imageModelFallbacks:t})}})}),(0,Y.jsx)(G,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":t.removeModelFallback,onClick:()=>i({imageModelFallbacks:r.imageModelFallbacks.filter((e,t)=>t!==a)}),children:(0,Y.jsx)(te,{className:`size-4`,strokeWidth:1.75})})]},a)),(0,Y.jsxs)(G,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:()=>i({imageModelFallbacks:[...r.imageModelFallbacks,``]}),children:[(0,Y.jsx)(fe,{className:`size-4 shrink-0`,strokeWidth:1.75}),t.addModelFallback]})]})}),(0,Y.jsx)(ut,{label:t.label.imageGenerationModel,description:t.desc.imageGenerationModel,children:(0,Y.jsx)(An,{value:r.imageGenerationModel,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,registryEmptyHint:t.imageGenRegistryEmpty,outOfFilterNote:t.imageGenOutOfFilterNote,onChange:e=>i({imageGenerationModel:e})})}),(0,Y.jsx)(ut,{label:t.label.imageGenerationModelFallbacks,description:t.desc.imageGenerationModelFallbacks,children:(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[r.imageGenerationModelFallbacks.map((e,a)=>(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Y.jsx)(An,{value:e,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,registryEmptyHint:t.imageGenRegistryEmpty,outOfFilterNote:t.imageGenOutOfFilterNote,onChange:e=>{let t=[...r.imageGenerationModelFallbacks];t[a]=e,i({imageGenerationModelFallbacks:t})}})}),(0,Y.jsx)(G,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":t.removeModelFallback,onClick:()=>i({imageGenerationModelFallbacks:r.imageGenerationModelFallbacks.filter((e,t)=>t!==a)}),children:(0,Y.jsx)(te,{className:`size-4`,strokeWidth:1.75})})]},a)),(0,Y.jsxs)(G,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:()=>i({imageGenerationModelFallbacks:[...r.imageGenerationModelFallbacks,``]}),children:[(0,Y.jsx)(fe,{className:`size-4 shrink-0`,strokeWidth:1.75}),t.addModelFallback]})]})})]})]})}function Mn(){return g(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,K)}var Nn=()=>q(et);function Pn(e){return{imageModel:e.imageModel,imageModelFallbacks:e.imageModelFallbacks,imageGenerationModel:e.imageGenerationModel,imageGenerationModelFallbacks:e.imageGenerationModelFallbacks,imageGenerationModelTimeoutMs:e.imageGenerationModelTimeoutMs,imageGenerationModelAutoProviderFallback:e.imageGenerationModelAutoProviderFallback}}function Fn(e){return{credentialsIntro:e.credentialsIntro,regionHint:e.regionHint,endpointPresetsHint:e.endpointPresetsHint,apiKeyLabel:e.apiKeyLabel,optionalPlaceholder:e.optionalPlaceholder,regionLabel:e.regionLabel,baseUrlLabel:e.baseUrlLabel,imageBaseUrlLabel:e.imageBaseUrlLabel,saveCredentials:e.saveCredentials,savingCredentials:e.savingCredentials,credentialsSaved:e.credentialsSaved,discardCredentials:e.discardCredentials,credentialsNothingToSave:e.credentialsNothingToSave,credentialsSaveError:e.credentialsSaveError,regionPresetDefault:e.regionPresetDefault,regionPresetCustom:e.regionPresetCustom,baseUrlPresetDefault:e.baseUrlPresetDefault,baseUrlPresetCustom:e.baseUrlPresetCustom,openExtensionSettings:e.openExtensionSettings,openImageModelsPage:e.openImageModelsPage,extensionSettingsLinkTitle:e.extensionSettingsLinkTitle,imageModelsLinkTitle:e.imageModelsLinkTitle,configured:e.configured,missingKey:e.missingKey,defaultModel:e.defaultModel,modelsLabel:e.modelsLabel,imageBaseUrlPresetHint:e.imageBaseUrlPresetHint,dashscopeRegion_beijing:e.dashscopeRegion_beijing,dashscopeRegion_singapore:e.dashscopeRegion_singapore,dashscopeRegion_us:e.dashscopeRegion_us,apiKeyMaskedHelp:e.apiKeyMaskedHelp,apiKeyCopy:e.apiKeyCopy,apiKeyCopied:e.apiKeyCopied,apiKeyShow:e.apiKeyShow,apiKeyHide:e.apiKeyHide,apiKeyNotInConfigFile:e.apiKeyNotInConfigFile,apiKeyRevealFailed:e.apiKeyRevealFailed,minimaxClusterLabel:e.minimaxClusterLabel,minimaxClusterHint:e.minimaxClusterHint,falQueueBaseLabel:e.falQueueBaseLabel,falQueueBaseHint:e.falQueueBaseHint}}function In(){let e=N(e=>e.language),t=o(e),n=t.imageModelsSettings,i=!!z(e=>e.token),[a,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),[u,f]=(0,X.useState)(!0),[p,m]=(0,X.useState)(!1),[h,_]=(0,X.useState)(!1),[v,y]=(0,X.useState)(void 0),b=Le(),x=(0,X.useMemo)(()=>new Set(b.map(e=>e.id)),[b]),S=(0,X.useCallback)(async()=>{if(i){f(!0),y(void 0);try{let e=await lt(),t=structuredClone(e);s(t),l(structuredClone(t))}catch(e){y(e instanceof Error?e.message:String(e))}finally{f(!1)}}},[i]);(0,X.useEffect)(()=>{S()},[S]);let C=(0,X.useCallback)(e=>{s(t=>t?{...t,...e}:null)},[]),{data:w=[],mutate:T}=r(i?Nn():null,nt,{revalidateOnFocus:!1}),E=Ye(i),D=rt(w),O=(0,X.useMemo)(()=>!a||!c?!1:JSON.stringify(Pn(a))!==JSON.stringify(Pn(c)),[a,c]),k=O||D.credDirty;(0,X.useEffect)(()=>{if(!k)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[k]);let ee=(0,X.useCallback)(async()=>{if(a){m(!0),y(void 0);try{try{ht(a.paramsJson)}catch(e){y(e instanceof SyntaxError?t.agentSettings.advanced.paramsInvalidJson:e instanceof Error?e.message:t.agentSettings.advanced.paramsInvalidJson);return}await Ct(a),l(structuredClone(a)),_(!0),window.setTimeout(()=>_(!1),1500),E.mutate?.()}catch(e){y(e instanceof Error?e.message:String(e))}finally{m(!1)}}},[a,E,t.agentSettings]),j=(0,X.useCallback)(()=>{c&&(s(structuredClone(c)),y(void 0),_(!1))},[c]),M=(0,X.useMemo)(()=>Fn(n),[n]),P=(0,X.useMemo)(()=>({getApiKey:t.providersSettings.getApiKey,getApiKeyIntl:t.providersSettings.getApiKeyIntl,getApiKeyCn:t.providersSettings.getApiKeyCn}),[t.providersSettings]);return i?u||!a?(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main items-center gap-2 px-4 py-8 text-sm text-fg-muted`,children:[(0,Y.jsx)(d,{className:`size-4 animate-spin`}),` Loading…`]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.title}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[(0,Y.jsxs)(G,{type:`button`,variant:`ghost`,onClick:()=>{S(),T(),E.mutate?.()},children:[(0,Y.jsx)(He,{className:`size-3.5`}),(0,Y.jsx)(`span`,{className:`ml-1.5`,children:n.refresh})]}),h?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,Y.jsx)(G,{type:`button`,variant:`secondary`,onClick:j,disabled:!O||p,children:n.discard}),(0,Y.jsxs)(G,{type:`button`,variant:`primary`,onClick:()=>void ee(),disabled:!O||p,children:[p?(0,Y.jsx)(d,{className:`size-3.5 animate-spin`}):(0,Y.jsx)(Se,{className:`size-3.5`}),(0,Y.jsx)(`span`,{className:`ml-1.5`,children:p?n.saving:n.save})]})]})]}),v?(0,Y.jsx)(`div`,{className:`rounded-lg border border-red-500/30 bg-red-500/10 px-3 py-2 text-sm text-red-700 dark:text-red-300`,children:v}):null,(0,Y.jsx)(jn,{form:a,update:C,a:t.agentSettings,chat:t.chat}),(0,Y.jsxs)(wt,{children:[(0,Y.jsx)(Tt,{icon:A,title:n.title,subtitle:n.subtitle}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Y.jsx)(`div`,{className:`rounded-lg border border-edge-subtle bg-surface-base px-3 py-2.5 text-xs leading-relaxed text-fg-muted`,children:n.crossLinkHint}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(`label`,{className:`text-sm font-medium text-fg`,children:n.timeoutLabel}),(0,Y.jsx)(`input`,{type:`number`,min:0,step:1e3,className:g(Mn(),`max-w-[12rem]`),value:a.imageGenerationModelTimeoutMs??``,placeholder:`120000`,onChange:e=>{let t=e.target.value.trim(),n=t===``?null:Math.max(0,Math.floor(Number(t)));s(e=>e?{...e,imageGenerationModelTimeoutMs:n&&n>0?n:null}:null)}}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.timeoutHint})]}),(0,Y.jsxs)(`label`,{className:`flex items-start gap-3 text-sm`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`mt-0.5`,checked:a.imageGenerationModelAutoProviderFallback,onChange:e=>s(t=>t?{...t,imageGenerationModelAutoProviderFallback:e.target.checked}:null)}),(0,Y.jsxs)(`span`,{className:`flex flex-col gap-0.5`,children:[(0,Y.jsx)(`span`,{className:`font-medium text-fg`,children:n.autoFallbackLabel}),(0,Y.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:n.autoFallbackHint})]})]})]})]}),(0,Y.jsxs)(wt,{children:[(0,Y.jsx)(Tt,{icon:Pe,title:n.providersTitle,subtitle:``}),w.length===0?(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.providersEmpty}):(0,Y.jsx)(tt,{summaries:w,credDraft:D.credDraft,credDirty:D.credDirty,credSaving:D.credSaving,credError:D.credError,credSavedFlash:D.credSavedFlash,credNoopFlash:D.credNoopFlash,updateCredRow:D.updateCredRow,onDiscardCredentials:D.onDiscardCredentials,onSaveCredentials:()=>void D.saveCredentials(n.credentialsSaveError),extensionIds:x,showExtensionLinks:!0,showImageModelsLink:!1,language:e,apiKeyLinkLabels:P,messages:M})]})]}):(0,Y.jsx)(`div`,{className:`mx-auto w-full max-w-app-main px-4 py-8 text-sm text-fg-muted`,children:e===`zh`?`请先登录网关。`:`Connect to a gateway to continue.`})}var Ln=[{value:`openai-completions`,label:`OpenAI Completions`},{value:`openai-responses`,label:`OpenAI Responses`},{value:`anthropic-messages`,label:`Anthropic Messages`},{value:`google-generative-ai`,label:`Google Generative AI`},{value:`azure-openai-responses`,label:`Azure OpenAI`},{value:`bedrock-converse-stream`,label:`AWS Bedrock`},{value:`openai-codex-responses`,label:`OpenAI Codex`},{value:`google-gemini-cli`,label:`Google Gemini CLI`},{value:`google-vertex`,label:`Google Vertex AI`}];function Rn(e){if(!e||typeof e!=`object`)return;let t=e;if(typeof t.error==`string`)return t.error;if(t.error&&typeof t.error==`object`&&`message`in t.error){let e=t.error.message;return typeof e==`string`?e:void 0}}function zn(e){if(!e||typeof e!=`object`)return{providers:{}};let t=e,n=t.providers;return n&&typeof n==`object`&&!Array.isArray(n)?e:{...t,providers:{}}}async function Bn(){let e=await Te(q(`/api/models-json`)),t=await e.json().catch(()=>({}));if(!e.ok||!t.ok||!t.payload)throw Error(Rn(t)||`HTTP ${e.status}`);return{...t.payload,config:zn(t.payload.config)}}async function Vn(e){let t=await Te(q(`/api/models-json/validate`),{method:`POST`,body:JSON.stringify({config:e})}),n=await t.json().catch(()=>({}));if(!t.ok||!n.ok||!n.payload)throw Error(Rn(n)||`HTTP ${t.status}`);return n.payload}async function Hn(e){let t=await Te(q(`/api/models-json`),{method:`PATCH`,body:JSON.stringify({config:e})}),n=await t.json().catch(()=>({}));if(!t.ok||!n.ok||!n.payload)throw Error(Rn(n)||`HTTP ${t.status}`);return n.payload}async function Un(){let e=await Te(q(`/api/models-json/reload`),{method:`POST`}),t=await e.json().catch(()=>({}));if(!e.ok||!t.ok||!t.payload)throw Error(Rn(t)||`HTTP ${e.status}`);return t.payload}async function Wn(e){let t=await Te(q(`/api/models-json/test-api-key`),{method:`POST`,body:JSON.stringify({value:e})}),n=await t.json().catch(()=>({}));if(!t.ok||!n.ok||!n.payload)throw Error(Rn(n)||`HTTP ${t.status}`);return n.payload}function Gn(e,t,n){return{id:e,name:t||e,input:[`text`],contextWindow:128e3,maxTokens:16384,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},...n}}function Kn(e){return e.startsWith(`!`)}function qn(e){return/^[A-Z][A-Z0-9_]*$/.test(e)}function Jn(e){return Kn(e)?`shell`:qn(e)?`env`:`literal`}function Yn(e){return e?e.length<=8?`••••`:`${e.slice(0,4)}••••${e.slice(-4)}`:``}function Xn(e){let{a:t,chat:n,form:r,update:i}=e;return(0,Y.jsxs)(wt,{children:[(0,Y.jsx)(Tt,{icon:a,title:t.label.modelFallbacks,subtitle:t.desc.modelFallbacks}),(0,Y.jsxs)(`div`,{className:`mt-4 flex flex-col gap-2`,children:[r.modelFallbacks.map((e,a)=>(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Y.jsx)(Ce,{value:e,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,onChange:e=>{let t=[...r.modelFallbacks];t[a]=e,i({modelFallbacks:t})}})}),(0,Y.jsx)(G,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":t.removeModelFallback,onClick:()=>i({modelFallbacks:r.modelFallbacks.filter((e,t)=>t!==a)}),children:(0,Y.jsx)(te,{className:`size-4`,strokeWidth:1.75})})]},a)),(0,Y.jsxs)(G,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:()=>i({modelFallbacks:[...r.modelFallbacks,``]}),children:[(0,Y.jsx)(fe,{className:`size-4 shrink-0`,strokeWidth:1.75}),t.addModelFallback]})]})]})}var Zn={ollama:{baseUrl:`http://localhost:11434/v1`,api:`openai-completions`,apiKey:`ollama`},lmstudio:{baseUrl:`http://localhost:1234/v1`,api:`openai-completions`,apiKey:`lmstudio`},openrouter:{baseUrl:`https://openrouter.ai/api/v1`,api:`openai-completions`,apiKey:``},zhipuCn:{baseUrl:`https://open.bigmodel.cn/api/coding/paas/v4`,api:`openai-completions`,apiKey:`ZHIPU_API_KEY`},zaiGeneral:{baseUrl:`https://api.z.ai/api/paas/v4`,api:`openai-completions`,apiKey:`ZAI_API_KEY`}};function Qn(e){return e===`openrouter`?`openrouter`:e===`zhipuCn`?`zhipu-cn`:e===`zaiGeneral`?`zai`:e}var $n=[{value:`text`,labelKey:`inputTextOnly`},{value:`text,image`,labelKey:`inputTextVision`}];function er(){return g(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,K,`dark:border-edge`)}function tr(){return g(D,p)}function nr(e){return(e.input||[`text`]).includes(`image`)?`text,image`:`text`}function rr(e){return e===`text,image`?[`text`,`image`]:[`text`]}function ir(e,t,n){return{...e,providers:{...e.providers,[t]:{...e.providers[t],...n}}}}function ar(e,t){let n={...e.providers};return delete n[t],{...e,providers:n}}function or(e,t,n){return{...e,providers:{...e.providers,[t]:n}}}function sr({open:e,onOpenChange:t,providerId:n,model:r,isNew:i,onSave:a,m:o}){let[c,l]=(0,X.useState)(()=>Gn(``)),[u,d]=(0,X.useState)(()=>new Map);(0,X.useEffect)(()=>{e&&(d(new Map),l(r?{...r}:Gn(``)))},[e,r]);let p=(e,t)=>{l(n=>({...n,[e]:t})),d(t=>{let n=new Map(t);return n.delete(e),n})},m=()=>{let e=new Map;return(c.id||``).trim()||e.set(`id`,o.modelIdRequired),c.contextWindow!==void 0&&c.contextWindow<=0&&e.set(`contextWindow`,o.mustBePositive),c.maxTokens!==void 0&&c.maxTokens<=0&&e.set(`maxTokens`,o.mustBePositive),d(e),e.size===0},_=()=>{if(!m())return;let e=(c.id||``).trim();a({...c,id:e,name:c.name?.trim()||e,reasoning:c.reasoning||!1,input:c.input||[`text`],contextWindow:c.contextWindow??128e3,maxTokens:c.maxTokens??16384,cost:{input:c.cost?.input??0,output:c.cost?.output??0,cacheRead:c.cost?.cacheRead??0,cacheWrite:c.cost?.cacheWrite??0}}),t(!1)},v=nr(c);return(0,Y.jsx)(ve,{open:e,onOpenChange:t,children:(0,Y.jsxs)(s,{children:[(0,Y.jsx)(ye,{className:g(`xopc-dialog-overlay fixed inset-0 bg-scrim`,Ue)}),(0,Y.jsxs)(f,{className:g(`xopc-dialog-content fixed left-1/2 top-1/2 max-h-[min(90vh,720px)] w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2`,re,`overflow-y-auto rounded-xl border border-edge bg-surface-panel p-4 shadow-popover dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,Y.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(T,{className:`text-base font-semibold text-fg`,children:i?o.addModelTitle:o.editModelTitle}),n?(0,Y.jsxs)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:[o.modelProviderLabel,`: `,n]}):null]}),(0,Y.jsx)(h,{asChild:!0,children:(0,Y.jsx)(`button`,{type:`button`,className:`rounded-lg p-1.5 text-fg-muted hover:bg-surface-base hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,"aria-label":o.close,children:(0,Y.jsx)(S,{className:`size-4`})})})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`mb-1 block text-xs font-medium text-fg`,children:[o.modelId,(0,Y.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,Y.jsx)(`input`,{className:g(er(),u.has(`id`)&&`border-red-500`),value:c.id||``,onChange:e=>p(`id`,e.target.value),placeholder:`e.g. llama3.1:8b`,disabled:!i}),u.has(`id`)?(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:u.get(`id`)}):null]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:o.displayName}),(0,Y.jsx)(`input`,{className:er(),value:c.name||``,onChange:e=>p(`name`,e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:o.inputTypes}),(0,Y.jsx)(`select`,{className:tr(),value:v,onChange:e=>p(`input`,rr(e.target.value)),children:$n.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:o[e.labelKey]},e.value))})]}),(0,Y.jsxs)(`label`,{className:`mt-6 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:c.reasoning||!1,onChange:e=>p(`reasoning`,e.target.checked)}),o.reasoning]})]}),(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:o.contextWindow}),(0,Y.jsx)(`input`,{type:`number`,min:1,className:g(er(),u.has(`contextWindow`)&&`border-red-500`),value:c.contextWindow??128e3,onChange:e=>p(`contextWindow`,parseInt(e.target.value,10)||0)}),u.has(`contextWindow`)?(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:u.get(`contextWindow`)}):null]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:o.maxOutputTokens}),(0,Y.jsx)(`input`,{type:`number`,min:1,className:g(er(),u.has(`maxTokens`)&&`border-red-500`),value:c.maxTokens??16384,onChange:e=>p(`maxTokens`,parseInt(e.target.value,10)||0)}),u.has(`maxTokens`)?(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:u.get(`maxTokens`)}):null]})]}),(0,Y.jsxs)(`div`,{className:`border-t border-edge-subtle pt-2 dark:border-edge`,children:[(0,Y.jsx)(`p`,{className:`mb-2 text-xs font-semibold text-fg`,children:o.costSection}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:o.costInput}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,min:0,className:er(),value:c.cost?.input??0,onChange:e=>p(`cost`,{...c.cost,input:parseFloat(e.target.value)||0,output:c.cost?.output??0,cacheRead:c.cost?.cacheRead??0,cacheWrite:c.cost?.cacheWrite??0})})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:o.costOutput}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,min:0,className:er(),value:c.cost?.output??0,onChange:e=>p(`cost`,{...c.cost,input:c.cost?.input??0,output:parseFloat(e.target.value)||0,cacheRead:c.cost?.cacheRead??0,cacheWrite:c.cost?.cacheWrite??0})})]})]})]})]}),(0,Y.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2 border-t border-edge-subtle pt-3 dark:border-edge`,children:[(0,Y.jsx)(h,{asChild:!0,children:(0,Y.jsx)(G,{type:`button`,variant:`secondary`,children:o.cancel})}),(0,Y.jsx)(G,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:_,children:i?o.addModelConfirm:o.saveModelConfirm})]})]})]})})}function cr({open:e,onOpenChange:t,presetKey:n,onConfirm:r,m:i}){let[a,o]=(0,X.useState)(``),[c,l]=(0,X.useState)(`custom`),[u,d]=(0,X.useState)(``),[p,m]=(0,X.useState)(`openai-completions`),[_,v]=(0,X.useState)(``),[y,b]=(0,X.useState)(null);(0,X.useEffect)(()=>{if(!e)return;b(null);let t=n||null;if(t&&Zn[t]){let e=Zn[t];l(t),d(e.baseUrl||``),m(e.api||`openai-completions`),v(e.apiKey??``),o(Qn(t))}else l(`custom`),o(``),d(``),m(`openai-completions`),v(``)},[e,n]);let x=e=>{if(l(e),e===`custom`)return;let t=Zn[e];t&&(d(t.baseUrl||``),m(t.api||`openai-completions`),v(t.apiKey??``),o(Qn(e)))};return(0,Y.jsx)(ve,{open:e,onOpenChange:t,children:(0,Y.jsxs)(s,{children:[(0,Y.jsx)(ye,{className:g(`xopc-dialog-overlay fixed inset-0 bg-scrim`,Ue)}),(0,Y.jsxs)(f,{className:g(`xopc-dialog-content fixed left-1/2 top-1/2 max-h-[min(90vh,640px)] w-[min(100%-2rem,32rem)] -translate-x-1/2 -translate-y-1/2`,re,`overflow-y-auto rounded-xl border border-edge bg-surface-panel p-4 shadow-popover dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,Y.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(T,{className:`text-base font-semibold text-fg`,children:i.addProviderTitle}),(0,Y.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:i.addProviderSubtitle})]}),(0,Y.jsx)(h,{asChild:!0,children:(0,Y.jsx)(`button`,{type:`button`,className:`rounded-lg p-1.5 text-fg-muted hover:bg-surface-base hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,"aria-label":i.close,children:(0,Y.jsx)(S,{className:`size-4`})})})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:i.presetLabel}),(0,Y.jsxs)(`select`,{className:tr(),value:c,onChange:e=>x(e.target.value),children:[(0,Y.jsx)(`option`,{value:`custom`,children:i.presetCustom}),(0,Y.jsx)(`option`,{value:`ollama`,children:i.presetOllama}),(0,Y.jsx)(`option`,{value:`lmstudio`,children:i.presetLmStudio}),(0,Y.jsx)(`option`,{value:`openrouter`,children:i.presetOpenRouter}),(0,Y.jsx)(`option`,{value:`zhipuCn`,children:i.presetZhipuCn}),(0,Y.jsx)(`option`,{value:`zaiGeneral`,children:i.presetZaiGeneral})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`mb-1 block text-xs font-medium text-fg`,children:[i.providerIdLabel,(0,Y.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,Y.jsx)(`input`,{className:er(),value:a,onChange:e=>o(e.target.value),placeholder:i.providerIdPlaceholder})]}),(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:i.baseUrl}),(0,Y.jsx)(`input`,{className:er(),value:u,onChange:e=>d(e.target.value),placeholder:`https://…`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:i.apiType}),(0,Y.jsx)(`select`,{className:tr(),value:p,onChange:e=>m(e.target.value),children:Ln.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:i.apiKey}),(0,Y.jsx)(`input`,{className:er(),value:_,onChange:e=>v(e.target.value),placeholder:i.apiKeyPlaceholder})]}),y?(0,Y.jsxs)(`p`,{className:`flex items-center gap-1 text-xs text-red-600 dark:text-red-400`,children:[(0,Y.jsx)(xe,{className:`size-3.5 shrink-0`}),y]}):null]}),(0,Y.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2 border-t border-edge-subtle pt-3 dark:border-edge`,children:[(0,Y.jsx)(h,{asChild:!0,children:(0,Y.jsx)(G,{type:`button`,variant:`secondary`,children:i.cancel})}),(0,Y.jsx)(G,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:()=>{let e=a.trim();if(!e){b(i.providerIdRequired);return}b(null),r(e,{baseUrl:u.trim()||void 0,api:p,apiKey:_.trim()||void 0,models:[]}),t(!1)},children:i.addProviderConfirm})]})]})]})})}function lr({config:e,setConfig:t,expanded:n,toggleExpand:r,showPw:i,toggleShowPw:a,testResults:o,runTestKey:s,ms:c,removeProv:l,openModelDialog:u,setTestResults:d}){return(0,Y.jsx)(`div`,{className:`flex flex-col gap-3`,children:Object.entries(e.providers).sort(([e],[t])=>e.localeCompare(t)).map(([e,f])=>{let p=n.has(e),m=f.models?.length??0,h=f.apiKey?Jn(f.apiKey):null,_=o.get(e),v=i.has(e);return(0,Y.jsxs)(`section`,{className:`overflow-hidden rounded-2xl bg-surface-base`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b border-edge-subtle bg-surface-hover/35 px-3 py-2 dark:border-edge-subtle`,children:[(0,Y.jsxs)(`button`,{type:`button`,className:`flex min-w-0 flex-1 items-center gap-2 text-left text-sm font-semibold text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,onClick:()=>r(e),children:[p?(0,Y.jsx)(ke,{className:`size-4 shrink-0 text-fg-muted`}):(0,Y.jsx)(ce,{className:`size-4 shrink-0 text-fg-muted`}),(0,Y.jsx)(`span`,{className:`truncate`,children:e}),m>0?(0,Y.jsx)(`span`,{className:`shrink-0 rounded-full bg-accent px-2 py-0.5 text-[10px] font-medium text-white`,children:m}):null,h?(0,Y.jsx)(`span`,{className:g(`shrink-0 rounded-full px-2 py-0.5 text-[10px] font-medium`,h===`shell`&&`bg-blue-100 text-blue-800 dark:bg-blue-950 dark:text-blue-200`,h===`env`&&`bg-emerald-100 text-emerald-800 dark:bg-emerald-950 dark:text-emerald-200`,h===`literal`&&`bg-surface-hover text-fg-muted dark:bg-surface-active`),children:h===`shell`?c.badgeShell:h===`env`?c.badgeEnv:c.badgeLiteral}):null]}),(0,Y.jsx)(`button`,{type:`button`,className:`rounded-lg p-1.5 text-fg-muted hover:bg-surface-base hover:text-red-600 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 dark:hover:text-red-400`,onClick:()=>l(e),"aria-label":c.removeProvider,children:(0,Y.jsx)(te,{className:`size-4`})})]}),p?(0,Y.jsxs)(`div`,{className:`space-y-4 px-3 py-3`,children:[(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:c.baseUrl}),(0,Y.jsx)(`input`,{className:er(),value:f.baseUrl||``,onChange:n=>t(t=>ir(t,e,{baseUrl:n.target.value}))})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:c.apiType}),(0,Y.jsx)(`select`,{className:tr(),value:f.api||`openai-completions`,onChange:n=>t(t=>ir(t,e,{api:n.target.value})),children:Ln.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:c.apiKey}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Y.jsx)(`input`,{className:g(er(),`min-w-0 flex-1`),type:v?`text`:`password`,autoComplete:`off`,value:f.apiKey||``,onChange:n=>{let r=n.target.value;t(t=>ir(t,e,{apiKey:r})),d(t=>{let n=new Map(t);return n.delete(e),n})},placeholder:c.apiKeyPlaceholder}),(0,Y.jsx)(G,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>a(e),children:v?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(x,{className:`mr-1 size-3.5`}),c.hide]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Me,{className:`mr-1 size-3.5`}),c.show]})}),(0,Y.jsx)(G,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>s(e,f.apiKey||``),children:c.testKey})]}),_?(0,Y.jsx)(`p`,{className:g(`mt-1 text-xs`,_.error?`text-red-600 dark:text-red-400`:`text-emerald-700 dark:text-emerald-400`),children:_.error?`${c.testError}: ${_.error}`:`${c.testOk} (${_.type}): ${Yn(_.resolved||``)}`}):null,(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:c.apiKeyHint})]}),(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:f.authHeader||!1,onChange:n=>t(t=>ir(t,e,{authHeader:n.target.checked}))}),c.authHeader]}),(0,Y.jsxs)(`div`,{className:`border-t border-edge-subtle pt-3 dark:border-edge`,children:[(0,Y.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-semibold text-fg`,children:c.modelsSection}),(0,Y.jsxs)(G,{type:`button`,variant:`primary`,className:`px-2 py-1 text-xs`,onClick:()=>u(e,null,!0),children:[(0,Y.jsx)(fe,{className:`mr-1 size-3.5`}),c.addModel]})]}),(f.models||[]).length===0?(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:c.modelsEmpty}):(0,Y.jsx)(`ul`,{className:`space-y-2`,children:(f.models||[]).map(n=>(0,Y.jsxs)(`li`,{className:`flex items-center justify-between gap-2 rounded-lg border border-edge-subtle bg-surface-base px-3 py-2 dark:border-edge`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`div`,{className:`truncate text-sm font-medium text-fg`,children:n.id}),n.name&&n.name!==n.id?(0,Y.jsx)(`div`,{className:`truncate text-xs text-fg-muted`,children:n.name}):null]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(0,Y.jsx)(`button`,{type:`button`,className:`rounded-lg p-1.5 text-fg-muted hover:bg-surface-panel hover:text-fg`,onClick:()=>u(e,n,!1),"aria-label":c.editModel,children:(0,Y.jsx)(ie,{className:`size-4`})}),(0,Y.jsx)(`button`,{type:`button`,className:`rounded-lg p-1.5 text-fg-muted hover:bg-surface-panel hover:text-red-600 dark:hover:text-red-400`,onClick:()=>{window.confirm(c.removeModelConfirm.replace(`{{id}}`,n.id))&&t(t=>{let r=t.providers[e];return r?ir(t,e,{models:(r.models||[]).filter(e=>e.id!==n.id)}):t})},"aria-label":c.removeModel,children:(0,Y.jsx)(te,{className:`size-4`})})]})]},n.id))})]})]}):null]},e)})})}function ur({ms:e,openAddProvider:t}){return(0,Y.jsxs)(`div`,{className:`flex flex-col items-center rounded-xl border-2 border-dashed border-edge-subtle bg-surface-panel px-6 py-12 text-center dark:border-edge`,children:[(0,Y.jsx)(`div`,{className:`mb-4 flex size-14 items-center justify-center rounded-full border border-edge bg-surface-base dark:border-edge`,children:(0,Y.jsx)(a,{className:`size-7 text-accent`,strokeWidth:1.5})}),(0,Y.jsx)(`h2`,{className:`mb-1 text-base font-semibold text-fg`,children:e.emptyTitle}),(0,Y.jsx)(`p`,{className:`mb-6 max-w-md text-sm text-fg-muted`,children:e.emptyDesc}),(0,Y.jsxs)(G,{type:`button`,className:`mb-6 bg-accent text-white hover:bg-accent/90`,onClick:()=>t(null),children:[(0,Y.jsx)(fe,{className:`mr-1 size-4`}),e.emptyCta]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap justify-center gap-2`,children:[(0,Y.jsxs)(`button`,{type:`button`,className:g(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,L.transition,L.focusRingBase),onClick:()=>t(`ollama`),children:[(0,Y.jsx)(v,{className:`size-3.5`,"aria-hidden":!0}),e.presetOllama]}),(0,Y.jsxs)(`button`,{type:`button`,className:g(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,L.transition,L.focusRingBase),onClick:()=>t(`openrouter`),children:[(0,Y.jsx)(me,{className:`size-3.5`,"aria-hidden":!0}),e.presetOpenRouter]}),(0,Y.jsxs)(`button`,{type:`button`,className:g(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,L.transition,L.focusRingBase),onClick:()=>t(`lmstudio`),children:[(0,Y.jsx)(a,{className:`size-3.5`,"aria-hidden":!0}),e.presetLmStudio]}),(0,Y.jsxs)(`button`,{type:`button`,className:g(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,L.transition,L.focusRingBase),onClick:()=>t(`zhipuCn`),children:[(0,Y.jsx)(v,{className:`size-3.5`,"aria-hidden":!0}),e.presetZhipuCn]}),(0,Y.jsxs)(`button`,{type:`button`,className:g(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,L.transition,L.focusRingBase),onClick:()=>t(`zaiGeneral`),children:[(0,Y.jsx)(me,{className:`size-3.5`,"aria-hidden":!0}),e.presetZaiGeneral]})]})]})}function dr(){let e=N(e=>e.language),t=o(e),n=t.modelsSettings,r=xt(t.agentSettings),i=!!z(e=>e.token),[a,s]=(0,X.useState)({providers:{}}),[c,l]=(0,X.useState)({providers:{}}),[u,f]=(0,X.useState)(``),[p,m]=(0,X.useState)(),[h,_]=(0,X.useState)(!0),[v,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(!1),[S,C]=(0,X.useState)(!1),[w,T]=(0,X.useState)(null),[E,D]=(0,X.useState)(!1),[O,k]=(0,X.useState)(null),[ee,A]=(0,X.useState)(()=>new Set),[j,M]=(0,X.useState)(!1),[P,F]=(0,X.useState)(``),[te,I]=(0,X.useState)(null),[L,R]=(0,X.useState)(()=>new Set),[re,ie]=(0,X.useState)(()=>new Map),[ae,oe]=(0,X.useState)(!1),[B,V]=(0,X.useState)(null),[H,U]=(0,X.useState)(!1),[se,ce]=(0,X.useState)(null),le=(0,X.useCallback)(async e=>{let t=!e?.skipFullPageLoading;t&&_(!0),T(null);try{let e=await Bn(),t=zn(e.config);s(t),l(structuredClone(t)),f(e.path),m(e.loadError),k(null),D(!1)}catch(e){T(e instanceof Error?e.message:n.loadError),s({providers:{}}),l({providers:{}})}finally{t&&_(!1)}},[n.loadError]);(0,X.useEffect)(()=>{if(!i){_(!1);return}le()},[i,le]);let W=(0,X.useMemo)(()=>JSON.stringify(a)!==JSON.stringify(c),[a,c]),ue=(0,X.useMemo)(()=>r.form?{form:r.form,update:r.update,a:t.agentSettings,chat:t.chat}:null,[r.form,r.update,t.agentSettings,t.chat]),de=W||r.dirty,pe=(0,X.useMemo)(()=>{let e=Object.keys(a.providers),t=0;for(let e of Object.values(a.providers))t+=e.models?.length??0;return{providers:e.length,models:t}},[a.providers]),me=e=>{A(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},he=e=>{R(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},ge=(0,X.useCallback)(()=>{F(JSON.stringify(a,null,2)),I(null)},[a]);(0,X.useEffect)(()=>{j&&ge()},[j,ge]);let _e=()=>{try{s(zn(JSON.parse(P))),I(null)}catch{I(n.jsonParseError)}},ve=async()=>{x(!0),T(null);try{k(await Vn(a))}catch(e){T(e instanceof Error?e.message:n.validateError)}finally{x(!1)}},K=async()=>{if(v||r.saving)return;let e=W,i=r.dirty;if(!(!e&&!i)){T(null),D(!1);try{if(e){y(!0);try{await Hn(a),l(structuredClone(a)),k(null)}finally{y(!1)}}if(i&&r.form&&!await r.save())throw Error(t.agentSettings.saveError);D(!0)}catch(e){T(e instanceof Error?e.message:n.saveError)}}},ye=(0,X.useCallback)(()=>{s(structuredClone(c)),k(null),D(!1),T(null),j&&(F(JSON.stringify(c,null,2)),I(null)),r.discard()},[c,j,r.discard]),be=async()=>{C(!0),T(null);try{await Un(),await le({skipFullPageLoading:!0})}catch(e){T(e instanceof Error?e.message:n.reloadError)}finally{C(!1)}},Se=async(e,t)=>{try{let n=await Wn(t);ie(t=>{let r=new Map(t);return r.set(e,n),r})}catch(t){ie(n=>{let r=new Map(n);return r.set(e,{type:`error`,error:t instanceof Error?t.message:`Error`}),r})}},Ce=(e=null)=>{V(e),oe(!0)},we=(e,t)=>{s(n=>or(n,e,t)),A(t=>new Set(t).add(e))},Te=e=>{window.confirm(n.removeProviderConfirm.replace(`{{id}}`,e))&&(s(t=>ar(t,e)),ie(t=>{let n=new Map(t);return n.delete(e),n}))},Ee=(e,t,n)=>{ce({providerId:e,model:t,isNew:n}),U(!0)},De=e=>{if(!se)return;let{providerId:t,isNew:n}=se;s(r=>{let i=r.providers[t];if(!i)return r;let a=i.models||[];return n?ir(r,t,{models:[...a,e]}):ir(r,t,{models:a.map(t=>t.id===e.id?e:t)})})};return i?(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-4 px-4 py-8`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.models}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.subtitle}),(0,Y.jsxs)(`a`,{href:We(e,`models`),target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-sm text-accent hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,children:[n.docsLink,(0,Y.jsx)(ne,{className:`size-3.5`})]})]}),p?(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-100`,role:`status`,children:[(0,Y.jsx)(xe,{className:`mt-0.5 size-4 shrink-0`}),(0,Y.jsxs)(`span`,{children:[n.loadFileWarning,`: `,p]})]}):null,u?(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.filePath,`: `,(0,Y.jsx)(`code`,{className:`rounded bg-surface-base px-1 py-0.5 font-mono text-fg-muted`,children:u})]}):null,(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsxs)(G,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:()=>Ce(null),disabled:h,children:[(0,Y.jsx)(fe,{className:`mr-1 size-4`}),n.addProvider]}),(0,Y.jsx)(G,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:ve,disabled:h||b,children:b?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(d,{className:`mr-1 size-4 animate-spin`}),n.validating]}):n.validate}),(0,Y.jsx)(G,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:ye,disabled:h||v||r.saving||!de,children:n.discard}),(0,Y.jsx)(G,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:()=>void K(),disabled:h||v||r.saving||!de,children:v||r.saving?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(d,{className:`mr-1 size-4 animate-spin`}),n.saving]}):n.save}),(0,Y.jsx)(G,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[8.5rem] justify-center`,onClick:be,disabled:h||S,children:S?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(d,{className:`mr-1 size-4 animate-spin`}),n.reloading]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(He,{className:`mr-1 size-4`}),n.reload]})}),(0,Y.jsx)(G,{type:`button`,variant:`ghost`,className:`text-fg-muted`,onClick:()=>{M(e=>!e),I(null)},children:j?n.hideJson:n.showJson}),(0,Y.jsxs)(`div`,{className:`ml-auto flex items-center gap-2 rounded-lg border border-edge-subtle bg-surface-panel px-3 py-1.5 text-sm dark:border-edge`,children:[(0,Y.jsx)(`span`,{className:`text-fg-muted`,children:n.statsProviders.replace(`{{count}}`,String(pe.providers))}),(0,Y.jsx)(`span`,{className:`text-fg-subtle`,children:`|`}),(0,Y.jsx)(`span`,{className:`text-fg-muted`,children:n.statsModels.replace(`{{count}}`,String(pe.models))})]})]}),de?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,E||r.saveOk?(0,Y.jsx)(`p`,{className:`text-xs text-emerald-700 dark:text-emerald-400`,role:`status`,children:n.saved}):null,w?(0,Y.jsxs)(`p`,{className:`flex items-center gap-1 text-sm text-red-600 dark:text-red-400`,role:`alert`,children:[(0,Y.jsx)(xe,{className:`size-4 shrink-0`}),w]}):null,r.error?(0,Y.jsxs)(`p`,{className:`flex items-center gap-1 text-sm text-red-600 dark:text-red-400`,role:`alert`,children:[(0,Y.jsx)(xe,{className:`size-4 shrink-0`}),r.error]}):null,O&&O.errors.length>0?(0,Y.jsxs)(`div`,{className:`rounded-lg border border-amber-200 bg-amber-50/80 px-3 py-2 dark:border-amber-800 dark:bg-amber-950/30`,role:`status`,children:[(0,Y.jsx)(`p`,{className:`mb-1 text-sm font-medium text-amber-950 dark:text-amber-100`,children:O.valid?n.validationWarnings:n.validationErrors}),(0,Y.jsx)(`ul`,{className:`list-inside list-disc space-y-0.5 text-xs text-amber-900 dark:text-amber-200`,children:O.errors.map((e,t)=>(0,Y.jsxs)(`li`,{children:[e.path,`: `,e.message,` (`,e.severity,`)`]},`${e.path}-${t}`))})]}):null,h?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,Y.jsx)(d,{className:`size-4 animate-spin`}),n.loading]}):j?(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(`textarea`,{className:g(er(),`min-h-[320px] resize-y font-mono text-xs leading-relaxed`),value:P,onChange:e=>F(e.target.value),spellCheck:!1}),te?(0,Y.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:te}):null,(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(G,{type:`button`,variant:`secondary`,onClick:ge,children:n.jsonReset}),(0,Y.jsx)(G,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:_e,children:n.jsonApply})]})]}):Object.keys(a.providers).length===0?(0,Y.jsx)(ur,{ms:n,openAddProvider:Ce}):(0,Y.jsx)(lr,{config:a,setConfig:s,expanded:ee,toggleExpand:me,showPw:L,toggleShowPw:he,testResults:re,runTestKey:Se,ms:n,removeProv:Te,openModelDialog:Ee,setTestResults:ie}),ue?(0,Y.jsx)(`div`,{className:`mt-10 border-t border-edge-subtle pt-8 dark:border-edge`,children:(0,Y.jsx)(Xn,{...ue})}):null,(0,Y.jsx)(cr,{open:ae,onOpenChange:oe,presetKey:B,onConfirm:we,m:n}),(0,Y.jsx)(sr,{open:H,onOpenChange:e=>{U(e),e||ce(null)},providerId:se?.providerId??null,model:se?.model??null,isNew:se?.isNew??!1,onSave:De,m:n})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.models}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}async function fr(e){let t=await Te(q(`/api/auth/oauth-async/start`),{method:`POST`,body:JSON.stringify({provider:e})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error||`OAuth start failed: ${t.status}`)}return(await t.json()).payload}async function pr(e){let t=await Te(q(`/api/auth/oauth-async/${encodeURIComponent(e)}/status`));if(!t.ok)throw Error(`OAuth status: ${t.status}`);return(await t.json()).payload}async function mr(e,t){let n=await Te(q(`/api/auth/oauth-async/${encodeURIComponent(e)}/code`),{method:`POST`,body:JSON.stringify({code:t})});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error||`Submit code failed: ${n.status}`)}}async function hr(e){let t=await Te(q(`/api/auth/oauth-async/${encodeURIComponent(e)}/cancel`),{method:`POST`});if(!t.ok)throw Error(`Cancel OAuth failed: ${t.status}`)}async function gr(e){let t=await Te(q(`/api/auth/oauth-async/${encodeURIComponent(e)}`),{method:`DELETE`});if(!t.ok)throw Error(`Cleanup session failed: ${t.status}`)}async function _r(e){let t=await Te(q(`/api/auth/oauth/${encodeURIComponent(e)}`),{method:`DELETE`});if(!t.ok)throw Error(`Revoke OAuth failed: ${t.status}`)}function vr({providerId:e,language:t}){let n=Fe[e];if(!n)return null;let r=t===`zh`,i=r&&n.descriptionZh?n.descriptionZh:n.description;return i?(0,Y.jsxs)(w,{children:[(0,Y.jsx)(j,{asChild:!0,children:(0,Y.jsx)(`button`,{type:`button`,className:`rounded p-0.5 text-fg-subtle hover:bg-surface-hover hover:text-fg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,"aria-label":r?`${e} 详情`:`${e} info`,children:(0,Y.jsx)(C,{className:`size-3.5`,"aria-hidden":!0})})}),(0,Y.jsx)(b,{children:(0,Y.jsxs)(_,{side:`right`,align:`start`,sideOffset:6,className:g(`w-64 rounded-xl border border-edge bg-surface-panel p-3 shadow-md`,Xe,`data-[state=open]:animate-in data-[state=closed]:animate-out`,`data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,`data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95`),children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs font-semibold text-fg`,children:e}),(0,Y.jsx)(k,{asChild:!0,children:(0,Y.jsx)(`button`,{type:`button`,className:`shrink-0 rounded p-0.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,"aria-label":r?`关闭`:`Close`,children:(0,Y.jsx)(S,{className:`size-3.5`,"aria-hidden":!0})})})]}),(0,Y.jsx)(`p`,{className:`mt-1.5 text-xs leading-relaxed text-fg-muted`,children:i}),n.bestFor&&n.bestFor.length>0?(0,Y.jsxs)(`div`,{className:`mt-2`,children:[(0,Y.jsx)(`p`,{className:`text-[10px] font-medium uppercase tracking-wide text-fg-subtle`,children:r?`适合场景`:`Best for`}),(0,Y.jsx)(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:n.bestFor.map(e=>(0,Y.jsx)(`span`,{className:`rounded bg-surface-hover px-1.5 py-0.5 text-[10px] font-medium text-fg-muted`,children:e},e))})]}):null,n.freeTier===void 0?null:(0,Y.jsxs)(`div`,{className:`mt-2`,children:[(0,Y.jsx)(`p`,{className:`text-[10px] font-medium uppercase tracking-wide text-fg-subtle`,children:r?`免费额度`:`Free tier`}),(0,Y.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:n.freeTier?n.freeTierNote??(r?`有免费额度`:`Available`):r?`无免费额度(按量付费)`:`None (pay-as-you-go)`})]}),n.pricingUrl||n.docsUrl?(0,Y.jsxs)(`div`,{className:`mt-2.5 flex gap-3`,children:[n.pricingUrl?(0,Y.jsxs)(`a`,{href:n.pricingUrl,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-0.5 text-xs text-accent-fg hover:underline`,children:[r?`定价`:`Pricing`,(0,Y.jsx)(ne,{className:`size-3`,"aria-hidden":!0})]}):null,n.docsUrl?(0,Y.jsxs)(`a`,{href:n.docsUrl,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-0.5 text-xs text-accent-fg hover:underline`,children:[r?`文档`:`Docs`,(0,Y.jsx)(ne,{className:`size-3`,"aria-hidden":!0})]}):null]}):null,(0,Y.jsx)(E,{className:`fill-edge`})]})})]}):null}var yr=[`common`,`specialty`,`enterprise`,`oauth`,`extension`];function br(e){let t=new Map;for(let e of yr)t.set(e,[]);for(let n of e){let e=n.category||`specialty`,r=t.get(e)??[];r.push(n),t.set(e,r)}return t}function xr(e,t){return e.replace(/\{\{(\w+)\}\}/g,(e,n)=>String(t[n]??``))}function Sr(e,t){switch(t){case`agent`:return e.sourceAgent;case`gateway`:return e.sourceGateway;case`oauth`:return e.sourceOauth;case`env`:return e.sourceEnv;case`models_json`:return e.sourceModelsJson;case`extension`:return e.sourceExtension;default:return e.sourceNone}}function Cr({envVar:e,labels:t}){let[n,r]=(0,X.useState)(!1),i=async()=>{try{await navigator.clipboard.writeText(e),r(!0),window.setTimeout(()=>r(!1),2e3)}catch{}};return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`code`,{className:`rounded bg-surface-hover px-1.5 py-0.5 font-mono text-[11px] text-fg-muted`,children:e}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>void i(),className:`rounded p-0.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,title:n?t.copied:t.copy,"aria-label":n?t.copied:t.copy,children:n?(0,Y.jsx)(Ie,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):(0,Y.jsx)(W,{className:`size-3.5`,"aria-hidden":!0})})]})}function wr({row:e,value:t,rowDirty:n,labels:r,language:i,onChange:a,onReload:o,justSaved:s,availableModels:c}){let[l,u]=(0,X.useState)(!1),[f,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)(!1),[_,v]=(0,X.useState)(null),[b,w]=(0,X.useState)(!1),[T,E]=(0,X.useState)(null),[D,O]=(0,X.useState)(!1),k=De(t),ee=k&&!f?``:t,A=e.configured&&!k&&!!t,[j,M]=(0,X.useState)(!1),[N,P]=(0,X.useState)(),[I,R]=(0,X.useState)(),[re,z]=(0,X.useState)(),[ie,ae]=(0,X.useState)(),[oe,B]=(0,X.useState)(),[V,H]=(0,X.useState)(``),[se,ce]=(0,X.useState)(!1),[le,ue]=(0,X.useState)(null),[de,fe]=(0,X.useState)(null),pe=e.activeKeySource??`none`,me=(0,X.useMemo)(()=>U(e.id,i),[e.id,i]);(0,X.useEffect)(()=>()=>{N&&gr(N).catch(()=>{})},[N]),(0,X.useEffect)(()=>{if(!N||!j)return;let e=window.setInterval(()=>{(async()=>{try{let t=await pr(N);z(t.message),ae(t.authUrl),B(t.instructions),t.status===`waiting_auth`||t.status===`waiting_code`?R(t.status===`waiting_code`?`waiting_code`:`waiting`):t.status===`completed`?(window.clearInterval(e),M(!1),R(`success`),z(t.message),window.setTimeout(()=>o(),800)):(t.status===`failed`||t.status===`cancelled`)&&(window.clearInterval(e),M(!1),R(`error`),z(t.error||t.message||`OAuth failed`))}catch{}})()},1e3);return()=>window.clearInterval(e)},[N,j,o]);let he=async()=>{M(!0),R(`waiting`),z(r.oauthStarting),P(void 0),ae(void 0),B(void 0);try{P((await fr(e.id)).sessionId)}catch(e){R(`error`),z(e instanceof Error?e.message:`OAuth failed`),M(!1)}},ge=async()=>{if(N){try{await hr(N)}catch{}P(void 0),M(!1),R(`idle`),z(void 0)}},_e=async()=>{if(!(!N||!V.trim()))try{await mr(N,V.trim()),H(``),z(r.oauthProcessingCode)}catch(e){R(`error`),z(e instanceof Error?e.message:`Failed`)}},ve=()=>{window.confirm(xr(r.revokeConfirm,{name:e.name}))&&(v(null),_r(e.id).then(()=>o()).catch(e=>v(e instanceof Error?e.message:r.revokeFailed)))},ye=async()=>{O(!1),w(!0),E(null);try{await Re(e.id),E(r.removeKeySuccess),a(e.id,``),window.setTimeout(()=>o(),600)}catch(e){E(e instanceof Error?e.message:r.removeKeyFailed)}finally{w(!1)}},Se=e.configured&&k&&pe!==`env`&&pe!==`extension`&&pe!==`models_json`,Ce=async()=>{if(!(!t||k))try{await navigator.clipboard.writeText(t),h(!0),window.setTimeout(()=>h(!1),2e3)}catch{}},we=async()=>{let e=t.trim();if(!(!e||De(e))){ce(!0),ue(null),fe(null);try{let t=await Oe(e);if(t.error){fe(!1),ue(`${r.testFailed} ${t.error}`);return}fe(!0),t.type===`env`?ue(r.testOkEnv):t.type===`command`?ue(r.testOkCommand):ue(r.testOkLiteral)}catch(e){fe(!1),ue(e instanceof Error?e.message:r.testFailed)}finally{ce(!1)}}},Te=n?r.metaWillSave:e.configured?k?`${r.metaMasked} · ${r.runtimeLabelPrefix} ${Sr(r,pe)}`:`${r.runtimeLabelPrefix} ${Sr(r,pe)}`:r.metaNotConfigured,Ee=`provider-details-${e.id}`;return(0,Y.jsxs)(`div`,{className:`bg-surface-panel`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-3 sm:px-4`,children:[(0,Y.jsx)(`div`,{className:`flex size-8 shrink-0 items-center justify-center rounded-md bg-surface-hover/80 dark:bg-surface-hover/50`,"aria-hidden":!0,children:e.configured?(0,Y.jsx)(Ie,{className:`size-4 text-emerald-600 dark:text-emerald-400`}):(0,Y.jsx)(y,{className:`size-4 text-fg-subtle`,strokeWidth:1.75})}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-semibold text-fg`,children:e.name}),(0,Y.jsx)(vr,{providerId:e.id,language:i}),(0,Y.jsx)(`span`,{className:`rounded bg-surface-hover px-1.5 py-0.5 font-mono text-[10px] font-medium uppercase tracking-wide text-fg-subtle`,children:e.id}),(0,Y.jsx)(`span`,{className:`rounded bg-surface-hover px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-fg-subtle`,children:e.category})]}),(0,Y.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:Te})]}),(0,Y.jsx)(G,{type:`button`,variant:`ghost`,className:`h-9 w-9 shrink-0 p-0`,"aria-expanded":l,"aria-controls":Ee,"aria-label":r.expandRowDetails,onClick:()=>u(e=>!e),children:(0,Y.jsx)(ke,{className:g(`size-4 transition-transform`,l&&`rotate-180`),"aria-hidden":!0})})]}),l?(0,Y.jsxs)(`div`,{id:Ee,role:`region`,className:`space-y-3 border-t border-edge-subtle bg-surface-base/40 px-3 py-3 dark:bg-surface-base/20 sm:px-4`,children:[e.supportsApiKey===!1?null:(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsxs)(`div`,{className:`relative flex flex-col gap-2 sm:flex-row sm:gap-2`,children:[(0,Y.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,Y.jsx)(`input`,{type:f||!k?`text`:`password`,className:g(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-3 pr-20 font-mono text-sm text-fg`,`placeholder:text-fg-subtle`,K,`dark:border-edge`),value:ee,placeholder:k?r.placeholderOverride:e.configured?r.placeholderKeep:r.placeholderKey,disabled:j,onChange:t=>a(e.id,t.target.value),autoComplete:`off`,spellCheck:!1}),(0,Y.jsxs)(`div`,{className:`absolute right-1 top-1/2 flex -translate-y-1/2 gap-0.5`,children:[t&&!k?(0,Y.jsx)(`button`,{type:`button`,className:g(`rounded p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,L.transition,L.press,L.focusRingPanel),title:m?r.copied:r.copy,"aria-label":m?r.copied:r.copy,onClick:()=>void Ce(),children:m?(0,Y.jsx)(Ie,{className:`size-4`}):(0,Y.jsx)(W,{className:`size-4`})}):null,(0,Y.jsx)(`button`,{type:`button`,className:g(`rounded p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg disabled:opacity-40`,L.transition,L.press,L.focusRingPanel),title:f?r.hide:r.show,"aria-label":f?r.hide:r.show,disabled:k,onClick:()=>p(e=>!e),children:f?(0,Y.jsx)(x,{className:`size-4`}):(0,Y.jsx)(Me,{className:`size-4`})})]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2 sm:shrink-0`,children:[(0,Y.jsxs)(G,{type:`button`,variant:`secondary`,className:`gap-1`,disabled:j||se||!t.trim()||De(t),onClick:()=>void we(),children:[se?(0,Y.jsx)(d,{className:`size-4 animate-spin`,"aria-hidden":!0}):null,se?r.testingKey:r.testKey]}),e.supportsOAuth?A?(0,Y.jsxs)(G,{type:`button`,variant:`secondary`,className:`gap-1 text-red-600 dark:text-red-400`,onClick:ve,children:[(0,Y.jsx)(qe,{className:`size-4`,"aria-hidden":!0}),r.revoke]}):(0,Y.jsxs)(G,{type:`button`,variant:`secondary`,className:`gap-1`,disabled:j,onClick:()=>void he(),children:[j?(0,Y.jsx)(d,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(F,{className:`size-4`,"aria-hidden":!0}),r.oauth]}):null,Se?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(G,{type:`button`,variant:`secondary`,className:`gap-1 text-red-600 dark:text-red-400`,disabled:b,onClick:()=>O(!0),children:[b?(0,Y.jsx)(d,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(te,{className:`size-4`,"aria-hidden":!0}),r.removeKey]}),(0,Y.jsx)(Be,{open:D,title:r.removeKey,description:xr(r.removeKeyConfirm,{name:e.name}),confirmLabel:r.removeKey,cancelLabel:r.cancelOAuth,destructive:!0,onConfirm:()=>void ye(),onCancel:()=>O(!1)})]}):null]})]}),le?(0,Y.jsx)(`p`,{className:g(`text-xs`,de===!1?`text-red-600 dark:text-red-400`:`text-fg-muted`),role:`status`,children:le}):null,me.length>0?(0,Y.jsx)(`div`,{className:`flex flex-col gap-1`,children:me.map(e=>(0,Y.jsxs)(`a`,{href:e.href,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex w-fit items-center gap-1 text-xs font-medium text-accent-fg hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:[be(e.kind,r),(0,Y.jsx)(ne,{className:`size-3`,"aria-hidden":!0})]},`${e.kind}-${e.href}`))}):null]}),re?(0,Y.jsxs)(`div`,{className:g(`flex gap-2 rounded-md px-3 py-2 text-xs`,I===`error`?`border border-red-200 bg-red-50 text-red-700 dark:border-red-900/50 dark:bg-red-950/50 dark:text-red-400`:`bg-surface-base text-fg-muted`),children:[I===`error`?(0,Y.jsx)(xe,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}):I===`success`?(0,Y.jsx)(Ie,{className:`mt-0.5 size-4 shrink-0 text-emerald-600`,"aria-hidden":!0}):(0,Y.jsx)(C,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:re})]}):null,_?(0,Y.jsxs)(`div`,{className:`flex gap-2 rounded-md border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700 dark:border-red-900/50 dark:bg-red-950/50 dark:text-red-400`,role:`alert`,children:[(0,Y.jsx)(xe,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:_})]}):null,T?(0,Y.jsxs)(`div`,{className:g(`flex gap-2 rounded-md px-3 py-2 text-xs`,T===r.removeKeySuccess?`bg-surface-hover/60 text-fg-muted dark:bg-surface-hover/40`:`border border-red-200 bg-red-50 text-red-700 dark:border-red-900/50 dark:bg-red-950/50 dark:text-red-400`),role:`status`,children:[T===r.removeKeySuccess?(0,Y.jsx)(Ie,{className:`mt-0.5 size-4 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):(0,Y.jsx)(xe,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:T})]}):null,(I===`waiting`||I===`waiting_code`)&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[ie?(0,Y.jsxs)(`a`,{href:ie,target:`_blank`,rel:`noopener 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,Y.jsx)(ne,{className:`size-4`,"aria-hidden":!0}),r.openAuthPage]}):null,(0,Y.jsxs)(G,{type:`button`,variant:`secondary`,className:`gap-1`,onClick:()=>void ge(),children:[(0,Y.jsx)(S,{className:`size-4`,"aria-hidden":!0}),r.cancelOAuth]})]}),oe?(0,Y.jsxs)(`div`,{className:`flex gap-2 rounded-md bg-surface-hover/60 px-3 py-2 text-xs text-fg-muted dark:bg-surface-hover/40`,children:[(0,Y.jsx)(C,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:oe})]}):null,I===`waiting_code`?(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,Y.jsx)(`input`,{type:`text`,className:g(`min-w-0 flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,K,`dark:border-edge`),value:V,placeholder:r.pasteRedirectUrl,onChange:e=>H(e.target.value),onKeyDown:e=>e.key===`Enter`&&void _e()}),(0,Y.jsx)(G,{type:`button`,variant:`primary`,className:`shrink-0`,onClick:()=>void _e(),children:r.submitCode})]}):null,k?(0,Y.jsxs)(`div`,{className:`flex gap-2 rounded-md bg-surface-hover/60 px-3 py-2 text-xs text-fg-muted dark:bg-surface-hover/40`,children:[(0,Y.jsx)(C,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:pe===`env`?r.envHint:r.maskedStoredHint})]}):null,e.supportsOAuth&&!k&&!A?(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:r.oauthHint}):null,s?(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md bg-surface-hover/60 px-3 py-2 text-xs text-fg-muted dark:bg-surface-hover/40`,children:[(0,Y.jsx)(Ie,{className:`mt-0.5 size-3.5 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:(()=>{let t=c.filter(t=>t.provider===e.id);if(t.length===0)return r.savedNoModels;let n=t.slice(0,3).map(e=>e.name||e.id).join(`, `),i=t.length>3?`… (+${t.length-3})`:``;return`${t.length} ${r.savedModelsAvailable}: ${n}${i}`})()})]}):null,(Fe[e.id]?.envVars??[]).length>0?(0,Y.jsxs)(`details`,{children:[(0,Y.jsx)(`summary`,{className:`cursor-pointer select-none list-none text-xs text-fg-subtle hover:text-fg-muted`,children:r.envVarAlt}),(0,Y.jsx)(`div`,{className:`mt-1.5 flex flex-col gap-1`,children:(Fe[e.id]?.envVars??[]).map(e=>(0,Y.jsx)(Cr,{envVar:e,labels:r},e))})]}):null]}):null]})}function Tr(){let e=N(e=>e.language),t=o(e),n=t.providersSettings,i=!!z(e=>e.token),[a,s]=(0,X.useState)({}),[l,u]=(0,X.useState)({}),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(null),[h,_]=(0,X.useState)(null),[v,b]=(0,X.useState)(()=>new Set([`common`])),[x,S]=(0,X.useState)(``),[C,w]=(0,X.useState)(!1),[T,E]=(0,X.useState)(()=>new Set),D=(0,X.useRef)(``),O=q(`/api/providers/meta`),k=(0,X.useCallback)(async e=>(await ge(e)).payload?.providers??[],[]),{data:ee,error:A,isLoading:j,mutate:M}=Ye(i),{data:P,error:F,isLoading:te,mutate:I}=r(i?O:null,k,{revalidateOnFocus:!1}),{data:L,mutate:ne}=r(i?he:null,()=>pe(),{revalidateOnFocus:!1}),R=(0,X.useMemo)(()=>!P||ee===void 0?null:Ne(P,ae(ee.payload?.config),L??[]),[P,ee,L]),re=A instanceof Error?A.message:A?String(A):F instanceof Error?F.message:F?String(F):null,ie=!!(i&&R===null&&(j||te)&&!re),B=(0,X.useMemo)(()=>JSON.stringify(a)!==JSON.stringify(l),[a,l]);(0,X.useEffect)(()=>{if(!B)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[B]),(0,X.useEffect)(()=>{if(!(!i||R===null)&&!B){let e={};for(let t of R)e[t.id]=t.apiKey;s(e),u({...e})}},[i,R,B]);let V=R??[],H=(0,X.useMemo)(()=>{let e=V,t=x.trim().toLowerCase();return t&&(e=e.filter(e=>{let n=Fe[e.id]?.aliases??[];return e.id.toLowerCase().includes(t)||e.name.toLowerCase().includes(t)||n.some(e=>e.toLowerCase().includes(t))})),C&&(e=e.filter(e=>!e.configured)),e},[V,x,C]),U=(0,X.useMemo)(()=>br(H),[H]);(0,X.useEffect)(()=>{let e=D.current;if(D.current=x,x.trim()){let e=new Set;for(let t of yr)(U.get(t)??[]).length>0&&e.add(t);b(e);return}e.trim()&&b(new Set([`common`]))},[x,U]);let se=(0,X.useCallback)(async()=>{if(d)return;let e={};for(let t of Object.keys(a)){let n=a[t]?.trim()??``;!n||De(n)||(e[t]=n)}if(Object.keys(e).length===0){u({...a}),_(`noChanges`),window.setTimeout(()=>_(null),2500);return}f(!0),m(null),_(null);try{await _e(e),E(new Set(Object.keys(e)));let t=await ne(pe(!0))??L??[],[n,r]=await Promise.all([M(),I()]),i=Array.isArray(r)?r:P??[],a=n??ee;if(a?.payload){let e=Ne(i,ae(a.payload.config),t),n={};for(let t of e)n[t.id]=t.apiKey;s(n),u({...n})}_(`saved`),window.setTimeout(()=>_(null),2500)}catch(e){m(e instanceof Error?e.message:n.saveError)}finally{f(!1)}},[ee,a,P,L,M,I,ne,n.saveError,d]),ce=(0,X.useCallback)(()=>{s({...l}),m(null),_(null),E(new Set)},[l]),le=e=>{b(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},W=(0,X.useCallback)(()=>{M(),I()},[M,I]),ue=!!(x.trim()||C);return i?ie?(0,Y.jsxs)(`div`,{className:`mx-auto w-full max-w-app-main px-4 py-8`,children:[(0,Y.jsx)(`div`,{className:`h-8 w-48 animate-pulse rounded bg-surface-hover`}),(0,Y.jsx)(`div`,{className:`mt-6 h-32 animate-pulse rounded-xl bg-surface-hover`}),(0,Y.jsx)(`p`,{className:`mt-4 text-sm text-fg-muted`,children:t.logs.loading})]}):V.length===0?(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-10`,children:[(0,Y.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-base px-4 py-3`,children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:n.loadError}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:p??re??n.empty})]}),(0,Y.jsx)(G,{type:`button`,variant:`secondary`,onClick:()=>{M(),I()},children:t.logs.refresh})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.providers}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,Y.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:n.rotateHint})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[h===`saved`?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,h===`noChanges`?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.noChangesSaved}):null,(0,Y.jsx)(G,{type:`button`,variant:`secondary`,disabled:!B||d,onClick:ce,children:n.discard}),(0,Y.jsx)(G,{type:`button`,variant:`primary`,disabled:!B||d,onClick:()=>void se(),children:d?n.saving:n.save})]})]}),B?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,(0,Y.jsxs)(`p`,{className:`text-sm leading-relaxed text-fg-muted`,children:[n.intro,` `,(0,Y.jsx)(`a`,{href:We(e,`models`),target:`_blank`,rel:`noopener noreferrer`,className:`font-medium text-accent-fg hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:n.docsLink}),` · `,(0,Y.jsx)(c,{to:`/settings/models`,className:`font-medium text-accent-fg hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:n.modelsLink})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-center`,children:[(0,Y.jsxs)(`div`,{className:`relative min-w-0 flex-1 sm:max-w-md`,children:[(0,Y.jsx)(oe,{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}),(0,Y.jsx)(`input`,{type:`search`,value:x,onChange:e=>S(e.target.value),placeholder:n.searchPlaceholder,autoComplete:`off`,className:g(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-10 pr-3 text-sm text-fg placeholder:text-fg-subtle`,K,`dark:border-edge`),"aria-label":n.searchPlaceholder})]}),(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg-muted`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:C,onChange:e=>w(e.target.checked),className:`size-4 rounded border-edge text-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`}),n.unconfiguredOnly]}),ue?(0,Y.jsx)(G,{type:`button`,variant:`ghost`,className:`h-9 w-fit self-start text-fg-muted`,onClick:()=>{S(``),w(!1)},children:n.clearFilters}):null]}),p?(0,Y.jsx)(`div`,{className:`rounded-md border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-red-900/50 dark:bg-red-950/50 dark:text-red-400`,role:`alert`,children:p}):null,H.length===0?(0,Y.jsxs)(`div`,{className:`rounded-xl border border-dashed border-edge-subtle bg-surface-base px-4 py-8 text-center text-sm text-fg-muted`,children:[(0,Y.jsx)(`p`,{children:n.noMatches}),(0,Y.jsx)(G,{type:`button`,variant:`secondary`,className:`mt-4`,onClick:()=>{S(``),w(!1)},children:n.clearFilters})]}):(0,Y.jsx)(`div`,{className:`flex flex-col gap-3`,children:yr.map(t=>{let r=U.get(t)??[];if(r.length===0)return null;let i=v.has(t),o=r.filter(e=>e.configured).length,c=`providers-cat-${t}`;return(0,Y.jsxs)(`section`,{className:`overflow-hidden rounded-2xl bg-surface-base`,children:[(0,Y.jsxs)(`button`,{type:`button`,id:`${c}-trigger`,"aria-expanded":i,"aria-controls":c,className:`flex w-full items-center justify-between gap-2 border-b border-edge-subtle px-4 py-3 text-left transition-colors hover:bg-surface-hover/60 dark:border-edge-subtle`,onClick:()=>le(t),children:[(0,Y.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)(`span`,{className:`truncate`,children:n.categories[t]}),(0,Y.jsx)(`span`,{className:`shrink-0 rounded bg-surface-hover px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-fg-subtle`,children:r.length})]}),(0,Y.jsxs)(`span`,{className:`flex shrink-0 items-center gap-2`,children:[o>0?(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-fg-subtle`,children:[(0,Y.jsx)(Ie,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}),xr(n.configuredCount,{count:String(o)})]}):null,(0,Y.jsx)(ke,{className:g(`size-4 text-fg-subtle transition-transform`,i&&`rotate-180`),"aria-hidden":!0})]})]}),i?(0,Y.jsx)(`div`,{id:c,role:`region`,"aria-labelledby":`${c}-trigger`,className:`divide-y divide-edge-subtle`,children:r.map(t=>(0,Y.jsx)(`div`,{id:`provider-row-${t.id}`,children:(0,Y.jsx)(wr,{row:t,value:a[t.id]??``,rowDirty:(a[t.id]??``)!==(l[t.id]??``),labels:n,language:e,onChange:(e,t)=>s(n=>({...n,[e]:t})),onReload:W,justSaved:T.has(t.id),availableModels:L??[]})},t.id))}):null]},t)})})]}):(0,Y.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-10`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-3 rounded-2xl bg-surface-base p-6`,children:[(0,Y.jsx)(y,{className:`mt-0.5 size-5 shrink-0 text-fg-subtle`,strokeWidth:1.75}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-base font-semibold text-fg`,children:t.settingsSections.providers}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.needToken})]})]})})}var Er=[{key:`fullDisk`,pane:`fullDisk`},{key:`screen`,pane:`screen`},{key:`microphone`,pane:`microphone`},{key:`accessibility`,pane:`accessibility`},{key:`automation`,pane:`automation`},{key:`notifications`,pane:`notifications`},{key:`location`,pane:`location`}];function Dr(e,t){let n=o(e).systemSettings.status;return t===`granted`?{label:n.granted,className:`text-emerald-600 dark:text-emerald-400`}:t===`denied`?{label:n.denied,className:`text-amber-600 dark:text-amber-400`}:{label:n.unknown,className:`text-fg-muted`}}function Or(){let e=N(e=>e.language),t=o(e).systemSettings,[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(null),[s,c]=(0,X.useState)(null),l=typeof window<`u`?window.electronAPI?.system:void 0,u=(0,X.useCallback)(async()=>{if(l){c(null);try{r(await l.getBehavior()),a(await l.getPermissions())}catch(e){c(e instanceof Error?e.message:String(e))}}},[l]);if((0,X.useEffect)(()=>{O()&&l&&u()},[l,u]),!O()||!l)return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.title}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:t.desktopOnlyTitle}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:t.desktopOnlyBody})]})]});let d=async e=>{try{let{behavior:t}=await l.setBehavior(e);r(t)}catch(e){c(e instanceof Error?e.message:String(e))}},f=async e=>{try{(await l.openPrivacy(e)).ok||c(`open_privacy failed`)}catch(e){c(e instanceof Error?e.message:String(e))}},p=n?n.platform===`win32`?t.permissionsHintWin:n.platform===`linux`?t.permissionsHintLinux:n.platform===`darwin`?t.permissionsHintDarwin:t.permissionsHint:t.permissionsHint;return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[(0,Y.jsx)(`div`,{children:(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.title})}),s?(0,Y.jsx)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:s}):null,(0,Y.jsxs)(wt,{children:[(0,Y.jsxs)(`div`,{className:`mb-4 flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)(ue,{className:`size-4 text-accent`,strokeWidth:1.75}),t.behaviorGroup]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.openAtLogin}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.openAtLoginDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!n,checked:!!n?.openAtLogin,onChange:e=>{d({openAtLogin:e.target.checked})}})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.keepAwake}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.keepAwakeDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!n,checked:!!n?.keepAwakePreferred,onChange:e=>{d({keepAwakePreferred:e.target.checked})}})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.notifyDesktop}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.notifyDesktopDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!n,checked:!!n?.notifyEnabled,onChange:e=>{d({notifyEnabled:e.target.checked})}})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.notifySound}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.notifySoundDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!n,checked:!!n?.notifySoundEnabled,onChange:e=>{d({notifySoundEnabled:e.target.checked})}})]})]})]}),n&&i?(0,Y.jsxs)(`section`,{className:J(),children:[(0,Y.jsxs)(`div`,{className:`mb-4 flex flex-col gap-1 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:t.permissionsTitle}),(0,Y.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:p})]}),(0,Y.jsx)(`button`,{type:`button`,className:`mt-2 inline-flex max-w-full items-center justify-center rounded-lg border border-edge bg-surface-panel px-3 py-1.5 text-sm font-medium text-fg transition-colors hover:bg-surface-hover sm:mt-0`,onClick:()=>void u(),children:t.refresh})]}),(0,Y.jsx)(`ul`,{className:`space-y-3`,children:Er.map(({key:r,pane:o})=>{let s=Dr(e,i[r]),u=t.perm[r];return u?(0,Y.jsxs)(`li`,{className:`flex flex-col gap-2 rounded-xl border border-edge-subtle bg-surface-panel/60 px-3 py-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:u.title}),(0,Y.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:u.desc}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs font-medium ${s.className}`,children:s.label})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[r===`microphone`&&n?.platform===`darwin`?(0,Y.jsx)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover`,onClick:()=>{(async()=>{try{await l.requestMicrophone(),a(await l.getPermissions())}catch(e){c(e instanceof Error?e.message:String(e))}})()},children:e===`zh`?`请求访问`:`Request`}):null,(0,Y.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover`,onClick:()=>void f(o),children:[t.openSettings,(0,Y.jsx)(ne,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0})]})]})]},r):null})})]}):null]})}function kr(){return{enabled:!1,provider:`alibaba`,alibaba:{model:`paraformer-v2`},openai:{model:`whisper-1`},fallback:{enabled:!0,order:[`alibaba`,`openai`]}}}function Ar(){return{enabled:!1,provider:`openai`,trigger:`always`,maxTextLength:512,timeoutMs:6e4,alibaba:{model:`qwen-tts`,voice:`Cherry`},openai:{model:`tts-1`,voice:`alloy`},edge:{voice:`en-US-MichelleNeural`},minimax:{model:`speech-2.8-hd`,voice:`male-qn-qingse`},"tts-local-cli":{command:``,outputFormat:`wav`}}}function jr(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Mr(e){let t=kr();if(!jr(e))return t;let n=e.provider===`openai`?`openai`:`alibaba`,r=jr(e.alibaba)?{...t.alibaba,...e.alibaba}:t.alibaba,i=jr(e.openai)?{...t.openai,...e.openai}:t.openai,a=t.fallback??{enabled:!0,order:[`alibaba`,`openai`]};if(jr(e.fallback)){let t=Array.isArray(e.fallback.order)?e.fallback.order.filter(e=>e===`alibaba`||e===`openai`):a.order;a={enabled:typeof e.fallback.enabled==`boolean`?e.fallback.enabled:a.enabled,order:t.length?t:a.order}}return{enabled:!!e.enabled,provider:n,alibaba:r,openai:i,fallback:a}}function Nr(e){return typeof e==`string`&&e.trim().length>0?e.trim():`openai`}function Pr(e){let t=Ar();if(!jr(e))return t;let n=Nr(e.provider),r=e.trigger===`off`||e.trigger===`always`||e.trigger===`inbound`||e.trigger===`tagged`?e.trigger:`always`,i=e[`tts-local-cli`];return{enabled:!!e.enabled,provider:n,trigger:r,maxTextLength:typeof e.maxTextLength==`number`&&Number.isFinite(e.maxTextLength)?e.maxTextLength:t.maxTextLength,timeoutMs:typeof e.timeoutMs==`number`&&Number.isFinite(e.timeoutMs)?e.timeoutMs:t.timeoutMs,alibaba:jr(e.alibaba)?{...t.alibaba,...e.alibaba}:t.alibaba,openai:jr(e.openai)?{...t.openai,...e.openai}:t.openai,edge:jr(e.edge)?{...t.edge,...e.edge}:t.edge,minimax:jr(e.minimax)?{...t.minimax,...e.minimax}:t.minimax,"tts-local-cli":jr(i)?{...t[`tts-local-cli`],...i}:t[`tts-local-cli`]}}function Fr(e){let t=jr(e)?e:{};return{stt:Mr(t.stt),tts:Pr(t.tts)}}async function Ir(e){await ge(q(`/api/config`),{method:`PATCH`,body:JSON.stringify({stt:e.stt,tts:e.tts})}),H()}async function Lr(){let e=await ge(q(`/api/voice/models`));if(!e.payload?.models)throw Error(`Missing voice models payload`);return e.payload.models}function Rr(){return g(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,K,`dark:border-edge`)}function zr(){return g(D,p)}var Br=[{id:`paraformer-v2`,name:`Paraformer v2`},{id:`paraformer-v1`,name:`Paraformer v1`}],Vr=[{id:`whisper-1`,name:`Whisper-1`}],Hr=[{id:`tts-1`,name:`TTS-1`},{id:`tts-1-hd`,name:`TTS-1 HD`}],Ur=[{id:`alloy`,name:`Alloy`},{id:`echo`,name:`Echo`}],Wr=[{id:`qwen-tts`,name:`Qwen TTS`},{id:`qwen3-tts-flash`,name:`Qwen3 TTS Flash`}],Gr=[{id:`Cherry`,name:`Cherry`},{id:`longxiaochun`,name:`Long Xiao Chun`}],Kr=[{id:`en-US-MichelleNeural`,name:`Michelle (US English)`},{id:`zh-CN-XiaoxiaoNeural`,name:`Xiaoxiao (Chinese)`}],qr=[{id:`speech-2.8-hd`,name:`Speech 2.8 HD (Recommended)`},{id:`speech-2.8-turbo`,name:`Speech 2.8 Turbo (Fast)`}],Jr=[{id:`male-qn-qingse`,name:`Male Qingse (青涩男声)`},{id:`female-shaonv`,name:`Female Shaonv (少女音)`}];function Yr(){let e=N(e=>e.language),t=o(e),n=t.voiceSettings,i=!!z(e=>e.token),[a,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),[u,f]=(0,X.useState)(null),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(null),[_,v]=(0,X.useState)(!1),{data:y,error:b,isLoading:x,mutate:S}=Ye(i),{data:C,error:w,isLoading:T,mutate:E}=r(i?q(`/api/voice/models`):null,Lr,{revalidateOnFocus:!1}),D=(0,X.useMemo)(()=>y?.payload?.config===void 0?null:Fr(y.payload.config),[y]),O=(0,X.useMemo)(()=>!a||!c?!1:JSON.stringify(a)!==JSON.stringify(c),[a,c]);(0,X.useEffect)(()=>{if(!i){s(null),l(null),f(null);return}D===null||C===void 0||O||(s(structuredClone(D)),l(structuredClone(D)),f(C),v(!1))},[i,D,C,O]);let k=!!(i&&(D===null||C===void 0)&&(x||T)),ee=b instanceof Error?b.message:b?String(b):w instanceof Error?w.message:w?String(w):null,A=(0,X.useCallback)(e=>{s(t=>t?{...t,stt:{...t.stt,...e}}:null)},[]),j=(0,X.useCallback)(e=>{s(t=>t?{...t,stt:{...t.stt,alibaba:{...t.stt.alibaba,...e}}}:null)},[]),M=(0,X.useCallback)(e=>{s(t=>t?{...t,stt:{...t.stt,openai:{...t.stt.openai,...e}}}:null)},[]),P=(0,X.useCallback)(e=>{s(t=>{if(!t)return null;let n=t.stt.fallback??{enabled:!0,order:[`alibaba`,`openai`]};return{...t,stt:{...t.stt,fallback:{...n,...e}}}})},[]),F=(0,X.useCallback)(e=>{s(t=>t?{...t,tts:{...t.tts,...e}}:null)},[]),te=(0,X.useCallback)(e=>{s(t=>t?{...t,tts:{...t.tts,alibaba:{...t.tts.alibaba,...e}}}:null)},[]),I=(0,X.useCallback)(e=>{s(t=>t?{...t,tts:{...t.tts,openai:{...t.tts.openai,...e}}}:null)},[]),L=(0,X.useCallback)(e=>{s(t=>t?{...t,tts:{...t.tts,edge:{...t.tts.edge,...e}}}:null)},[]),R=(0,X.useCallback)(e=>{s(t=>t?{...t,tts:{...t.tts,minimax:{...t.tts.minimax,...e}}}:null)},[]),re=(0,X.useCallback)(e=>{s(t=>t?{...t,tts:{...t.tts,"tts-local-cli":{...t.tts[`tts-local-cli`],...e}}}:null)},[]),ie=(0,X.useCallback)(async()=>{if(!(!a||p)){m(!0),g(null),v(!1);try{await Ir(a);let e=structuredClone(a);l(e),s(e),v(!0),window.setTimeout(()=>v(!1),2500)}catch(e){g(e instanceof Error?e.message:n.saveError)}finally{m(!1)}}},[a,p,n.saveError]),ae=(0,X.useCallback)(()=>{c&&(s(structuredClone(c)),g(null),v(!1))},[c]);if(!i)return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.voice}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]});if(k)return(0,Y.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,Y.jsx)(d,{className:`size-4 animate-spin`}),n.loading]})});if(!a||u===null)return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:h??ee??n.loadError}),(0,Y.jsx)(G,{type:`button`,variant:`secondary`,onClick:()=>{S(),E()},children:n.retry})]});let oe=a.stt,B=a.tts;return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.voice}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,Y.jsxs)(`a`,{href:We(e,`voice`),target:`_blank`,rel:`noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-sm text-accent hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,children:[n.docsLink,(0,Y.jsx)(ne,{className:`size-3.5`})]})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[_?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,Y.jsx)(G,{type:`button`,variant:`secondary`,disabled:!O||p,onClick:ae,children:n.discard}),(0,Y.jsx)(G,{type:`button`,variant:`primary`,disabled:!O||p,onClick:()=>void ie(),children:p?n.saving:n.save})]})]}),O?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,h?(0,Y.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:h}):null,(0,Y.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Y.jsx)(Xr,{v:n,stt:oe,models:u,updateStt:A,updateSttAlibaba:j,updateSttOpenai:M,updateSttFallback:P}),(0,Y.jsx)(Zr,{v:n,tts:B,models:u,updateTts:F,updateTtsAlibaba:te,updateTtsOpenai:I,updateTtsEdge:L,updateTtsMinimax:R,updateTtsLocalCli:re})]}),(0,Y.jsxs)(`div`,{className:`rounded-xl border border-accent/25 bg-accent/5 px-4 py-3 dark:border-accent/30 dark:bg-accent/10`,children:[(0,Y.jsxs)(`p`,{className:`text-sm text-fg`,children:[(0,Y.jsx)(`strong`,{className:`text-accent`,children:n.notes.title}),` `,n.notes.duration]}),(0,Y.jsx)(`p`,{className:`mt-2 text-xs text-fg-muted`,children:n.notes.envVars})]})]})}function Xr({v:e,stt:t,models:n,updateStt:r,updateSttAlibaba:i,updateSttOpenai:a,updateSttFallback:o}){let s=n?.stt?.alibaba?.length?n.stt.alibaba:Br,c=n?.stt?.openai?.length?n.stt.openai:Vr;return(0,Y.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[(0,Y.jsxs)(`div`,{className:`mb-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)(V,{className:`size-4 text-accent`,strokeWidth:1.75}),e.stt.title]}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:e.stt.description})]}),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.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,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.stt.enable}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.stt.enableDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:t.enabled,onChange:e=>r({enabled:e.target.checked})})]}),t.enabled?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.provider}),(0,Y.jsxs)(`select`,{className:zr(),value:t.provider,onChange:e=>r({provider:e.target.value}),children:[(0,Y.jsx)(`option`,{value:`alibaba`,children:e.stt.alibaba}),(0,Y.jsx)(`option`,{value:`openai`,children:e.stt.openai})]})]})}),t.provider===`alibaba`?(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.apiKey}),(0,Y.jsx)(`input`,{className:g(Rr(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.alibaba?.apiKey??``,onChange:e=>i({apiKey:e.target.value}),placeholder:`sk-...`}),(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (DASHSCOPE_API_KEY)`]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:zr(),value:t.alibaba?.model??``,onChange:e=>i({model:e.target.value}),children:s.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}):(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.apiKey}),(0,Y.jsx)(`input`,{className:g(Rr(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.openai?.apiKey??``,onChange:e=>a({apiKey:e.target.value}),placeholder:`sk-...`}),(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (OPENAI_API_KEY)`]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:zr(),value:t.openai?.model??``,onChange:e=>a({model:e.target.value}),children:c.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}),(0,Y.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,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.stt.fallback}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.stt.fallbackDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:t.fallback?.enabled??!0,onChange:e=>o({enabled:e.target.checked})})]})]}):null]})]})}function Zr({v:e,tts:t,models:n,updateTts:r,updateTtsAlibaba:i,updateTtsOpenai:a,updateTtsEdge:o,updateTtsMinimax:s,updateTtsLocalCli:c}){let l=t=>t===`off`?e.tts.triggerDescOff:t===`always`?e.tts.triggerDescAlways:t===`inbound`?e.tts.triggerDescInbound:t===`tagged`?e.tts.triggerDescTagged:``,u=n?.tts?.openai?.length?n.tts.openai:Hr,d=n?.ttsVoices?.openai?.length?n.ttsVoices.openai:Ur,f=n?.tts?.alibaba?.length?n.tts.alibaba:Wr,p=n?.ttsVoices?.alibaba?.length?n.ttsVoices.alibaba:Gr,m=n?.ttsVoices?.edge?.length?n.ttsVoices.edge:Kr,h=n?.tts?.minimax?.length?n.tts.minimax:qr,_=n?.ttsVoices?.minimax?.length?n.ttsVoices.minimax:Jr;return(0,Y.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[(0,Y.jsxs)(`div`,{className:`mb-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)(Qe,{className:`size-4 text-accent`,strokeWidth:1.75}),e.tts.title]}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:e.tts.description})]}),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.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,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.tts.enable}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.tts.enableDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:t.enabled,onChange:e=>r({enabled:e.target.checked})})]}),t.enabled?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.tts.trigger}),(0,Y.jsxs)(`select`,{className:zr(),value:t.trigger,onChange:e=>r({trigger:e.target.value}),children:[(0,Y.jsx)(`option`,{value:`off`,children:e.tts.triggerOff}),(0,Y.jsx)(`option`,{value:`always`,children:e.tts.triggerAlways}),(0,Y.jsx)(`option`,{value:`inbound`,children:e.tts.triggerInbound}),(0,Y.jsx)(`option`,{value:`tagged`,children:e.tts.triggerTagged})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:l(t.trigger)})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.tts.provider}),(0,Y.jsxs)(`select`,{className:zr(),value:t.provider,onChange:e=>r({provider:e.target.value}),children:[(0,Y.jsx)(`option`,{value:`openai`,children:e.tts.providerOpenai}),(0,Y.jsx)(`option`,{value:`alibaba`,children:e.stt.alibaba}),(0,Y.jsx)(`option`,{value:`minimax`,children:`MiniMax`}),(0,Y.jsx)(`option`,{value:`edge`,children:e.tts.providerEdge}),(0,Y.jsx)(`option`,{value:`tts-local-cli`,children:e.tts.providerLocalCli})]})]})]}),t.provider===`openai`?(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,Y.jsx)($,{children:e.stt.apiKey}),(0,Y.jsx)(`input`,{className:g(Rr(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.openai?.apiKey??``,onChange:e=>a({apiKey:e.target.value}),placeholder:`sk-...`}),(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (OPENAI_API_KEY)`]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:zr(),value:t.openai?.model??``,onChange:e=>a({model:e.target.value}),children:u.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.tts.voice}),(0,Y.jsx)(`select`,{className:zr(),value:t.openai?.voice??``,onChange:e=>a({voice:e.target.value}),children:d.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}):null,t.provider===`alibaba`?(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,Y.jsx)($,{children:e.stt.apiKey}),(0,Y.jsx)(`input`,{className:g(Rr(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.alibaba?.apiKey??``,onChange:e=>i({apiKey:e.target.value}),placeholder:`sk-...`}),(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (DASHSCOPE_API_KEY)`]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:zr(),value:t.alibaba?.model??``,onChange:e=>i({model:e.target.value}),children:f.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.tts.voice}),(0,Y.jsx)(`select`,{className:zr(),value:t.alibaba?.voice??``,onChange:e=>i({voice:e.target.value}),children:p.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}):null,t.provider===`minimax`?(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,Y.jsx)($,{children:e.stt.apiKey}),(0,Y.jsx)(`input`,{className:g(Rr(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.minimax?.apiKey??``,onChange:e=>s({apiKey:e.target.value}),placeholder:`eyJ...`}),(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (MINIMAX_API_KEY)`]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:zr(),value:t.minimax?.model??``,onChange:e=>s({model:e.target.value}),children:h.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.tts.voice}),(0,Y.jsx)(`select`,{className:zr(),value:t.minimax?.voice??``,onChange:e=>s({voice:e.target.value}),children:_.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}):null,t.provider===`edge`?(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.tts.voice}),(0,Y.jsx)(`select`,{className:zr(),value:t.edge?.voice??``,onChange:e=>o({voice:e.target.value}),children:m.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.edgeHint})]}):null,t.provider===`tts-local-cli`?(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,Y.jsx)($,{children:e.tts.localCli.command}),(0,Y.jsx)(`input`,{className:g(Rr(),`font-mono text-xs`),type:`text`,autoComplete:`off`,spellCheck:!1,value:t[`tts-local-cli`]?.command??``,onChange:e=>c({command:e.target.value}),placeholder:e.tts.localCli.commandPlaceholder}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.commandDesc})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.tts.localCli.cwd}),(0,Y.jsx)(`input`,{className:g(Rr(),`font-mono text-xs`),type:`text`,autoComplete:`off`,spellCheck:!1,value:t[`tts-local-cli`]?.cwd??``,onChange:e=>c({cwd:e.target.value}),placeholder:`/path/to/cwd`}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.cwdDesc})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.tts.localCli.outputFormat}),(0,Y.jsxs)(`select`,{className:zr(),value:t[`tts-local-cli`]?.outputFormat??`wav`,onChange:e=>c({outputFormat:e.target.value}),children:[(0,Y.jsx)(`option`,{value:`wav`,children:`wav`}),(0,Y.jsx)(`option`,{value:`mp3`,children:`mp3`}),(0,Y.jsx)(`option`,{value:`opus`,children:`opus`})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.outputFormatDesc})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,Y.jsx)($,{children:e.tts.localCli.timeoutMs}),(0,Y.jsx)(`input`,{className:Rr(),type:`number`,min:0,step:1e3,value:typeof t[`tts-local-cli`]?.timeoutMs==`number`?String(t[`tts-local-cli`].timeoutMs):``,onChange:e=>{let t=e.target.value.trim();if(t===``){c({timeoutMs:void 0});return}let n=Number(t);Number.isFinite(n)&&n>=0&&c({timeoutMs:n})},placeholder:`30000`}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.timeoutMsDesc})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle sm:col-span-2`,children:e.tts.localCli.hint})]}):null]}):null]})]})}function $({children:e}){return(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e})}function Qr(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=o.providers;return{regionMode:i,maxResults:s,providers:Array.isArray(c)?c.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}}):[]}}async function $r(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 ge(q(`/api/config`),{method:`PATCH`,body:JSON.stringify({tools:{web:{region:t,search:n}}})}),H()}function ei({label:e,description:t,children:n}){return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e}),n,(0,Y.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:t})]})}function ti(){return g(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,K,`dark:border-edge`)}function ni(){return g(D,p)}var ri=[`brave`,`tavily`,`bing`,`searxng`];function ii(){return{type:`brave`,apiKey:``,url:``,disabled:!1}}function ai(){let e=N(e=>e.language),t=o(e),n=t.webSearchSettings,r=t.logs,i=!!z(e=>e.token),[a,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),[u,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(null),[h,g]=(0,X.useState)(!1),_=(0,X.useRef)(!1),{data:v,error:y,isLoading:b,mutate:x}=Ye(i),S=(0,X.useMemo)(()=>v?.payload?.config===void 0?null:Qr(v.payload.config),[v]);(0,X.useEffect)(()=>{if(!i){s(null),l(null),_.current=!1;return}S!==null&&(_.current||(s(S),l(S)))},[i,S]);let C=!!(i&&b&&v===void 0&&!y),w=y instanceof Error?y.message:y?String(y):null,T=(0,X.useMemo)(()=>!a||!c?!1:JSON.stringify(a)!==JSON.stringify(c),[a,c]),E=(0,X.useCallback)(e=>{_.current=!0,s(t=>t?{...t,...e}:null)},[]),D=(0,X.useCallback)(async()=>{if(!(!a||u)){f(!0),m(null),g(!1);try{await $r(a);let e=structuredClone(a);l(e),s(e),_.current=!1,g(!0),window.setTimeout(()=>g(!1),2500)}catch(e){m(e instanceof Error?e.message:n.saveError)}finally{f(!1)}}},[a,u,n.saveError]),O=(0,X.useCallback)(()=>{c&&(_.current=!1,s(structuredClone(c)),m(null),g(!1))},[c]);return i?C?(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col items-center gap-3 px-4 py-8`,children:[(0,Y.jsx)(d,{className:`size-8 animate-spin text-fg-muted`,"aria-hidden":!0}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.loading})]}):a?(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.title}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,Y.jsxs)(`a`,{href:We(e,`gateway`),target:`_blank`,rel:`noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-sm text-accent hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,children:[n.docsLink,(0,Y.jsx)(ne,{className:`size-3.5`})]})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[h?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,Y.jsx)(G,{type:`button`,variant:`secondary`,disabled:!T||u,onClick:O,children:n.discard}),(0,Y.jsx)(G,{type:`button`,variant:`primary`,disabled:!T||u,onClick:()=>void D(),children:u?n.saving:n.save})]})]}),T?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,p?(0,Y.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:p}):null,(0,Y.jsxs)(wt,{children:[(0,Y.jsx)(Tt,{icon:oe,title:n.sectionRegion,subtitle:n.sectionRegionHint}),(0,Y.jsx)(`div`,{className:`flex max-w-md flex-col gap-4`,children:(0,Y.jsx)(ei,{label:n.regionLabel,description:n.regionDesc,children:(0,Y.jsxs)(`select`,{className:ni(),value:a.regionMode,onChange:e=>E({regionMode:e.target.value}),children:[(0,Y.jsx)(`option`,{value:`auto`,children:n.regionAuto}),(0,Y.jsx)(`option`,{value:`cn`,children:n.regionCn}),(0,Y.jsx)(`option`,{value:`global`,children:n.regionGlobal})]})})})]}),(0,Y.jsxs)(wt,{children:[(0,Y.jsx)(Tt,{icon:oe,title:n.sectionSearch,subtitle:n.sectionSearchHint}),(0,Y.jsxs)(`div`,{className:`flex max-w-xl flex-col gap-6`,children:[(0,Y.jsx)(ei,{label:n.maxResultsLabel,description:n.maxResultsDesc,children:(0,Y.jsx)(`input`,{type:`number`,min:1,max:50,className:ti(),value:a.maxResults,onChange:e=>E({maxResults:Math.max(1,Math.min(50,Number(e.target.value)||5))})})}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.providersTitle}),a.providers.map((e,t)=>(0,Y.jsx)(oi,{row:e,labels:n,onChange:e=>{let n=[...a.providers];n[t]=e,E({providers:n})},onRemove:()=>{E({providers:a.providers.filter((e,n)=>n!==t)})}},t)),(0,Y.jsxs)(G,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5 text-sm`,onClick:()=>E({providers:[...a.providers,ii()]}),children:[(0,Y.jsx)(fe,{className:`size-4`}),n.addProvider]})]})]})]}),(0,Y.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:n.footerHint})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:p??w??n.loadError}),(0,Y.jsx)(G,{type:`button`,variant:`secondary`,onClick:()=>void x(),children:r.refresh})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-4 px-4 py-6`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:n.title}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}function oi({row:e,labels:t,onChange:n,onRemove:r}){return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-xl border border-edge-subtle bg-surface-panel/60 p-4 dark:border-edge-subtle`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,Y.jsx)(`select`,{className:g(ni(),`min-w-[8rem]`),value:e.type,onChange:t=>n({...e,type:t.target.value,url:t.target.value===`searxng`?e.url:``}),children:ri.map(e=>(0,Y.jsx)(`option`,{value:e,children:t.providerTypes[e]},e))}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1.5 text-xs text-fg-muted`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`size-3.5 rounded border-edge`,checked:e.disabled,onChange:t=>n({...e,disabled:t.target.checked})}),t.disabled]}),(0,Y.jsx)(G,{type:`button`,variant:`ghost`,className:`h-8 px-2 text-fg-muted`,onClick:r,children:(0,Y.jsx)(te,{className:`size-4`})})]})]}),e.type===`searxng`?(0,Y.jsx)(ei,{label:t.urlLabel,description:t.urlDesc,children:(0,Y.jsx)(`input`,{type:`url`,className:ti(),value:e.url,placeholder:`http://localhost:8080`,onChange:t=>n({...e,url:t.target.value})})}):null,(0,Y.jsx)(ei,{label:t.apiKeyLabel,description:t.apiKeyDesc,children:(0,Y.jsx)(`input`,{type:`password`,autoComplete:`off`,className:ti(),value:De(e.apiKey)?``:e.apiKey,placeholder:De(e.apiKey)?t.keyPlaceholderMasked:t.keyPlaceholder,onChange:t=>n({...e,apiKey:t.target.value})})})]})}var si=[`appearance`,`system`,`agent-chat`,`agent-workspace`,`agent-browser`,`agent-runtime`,`agent-tools`,`agent-system-prompt`,`providers`,`models`,`image-models`,`voice`,`gateway`,`heartbeat`,`search`,`dreams`];function ci(){let{section:e}=l(),t=N(e=>e.language),n=o(t);if(e===`agent`||e===`agents`)return(0,Y.jsx)(Ge,{to:`/agents`,replace:!0});if(!e||!si.includes(e))return(0,Y.jsx)(Ge,{to:`/settings/appearance`,replace:!0});let r=e,i=n.settingsSections[r];return r===`appearance`?(0,Y.jsx)(Nt,{}):r===`system`?(0,Y.jsx)(Or,{}):r===`agent-chat`?(0,Y.jsx)(_t,{}):r===`agent-workspace`?(0,Y.jsx)(vt,{}):r===`agent-browser`?(0,Y.jsx)(St,{}):r===`agent-runtime`?(0,Y.jsx)(bt,{}):r===`agent-tools`?(0,Y.jsx)(ct,{}):r===`agent-system-prompt`?(0,Y.jsx)(mt,{}):r===`providers`?(0,Y.jsx)(Tr,{}):r===`models`?(0,Y.jsx)(dr,{}):r===`image-models`?(0,Y.jsx)(In,{}):r===`voice`?(0,Y.jsx)(Yr,{}):r===`gateway`?(0,Y.jsx)(rn,{}):r===`heartbeat`?(0,Y.jsx)(Cn,{}):r===`search`?(0,Y.jsx)(ai,{}):r===`dreams`?(0,Y.jsx)(Zt,{}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:i}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t===`zh`?`设置 · ${i}(即将推出)。`:`Settings · ${i} (coming soon).`})]})}export{ci as SettingsPage};
|
|
2
|
-
//# sourceMappingURL=settings-page-B7NZPSpO.js.map
|