@xopcai/xopc 0.0.52 → 0.0.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/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-CLNe-mJX.js → agents-Dk8idifM.js} +2 -2
- package/dist/gateway/static/root/assets/{agents-CLNe-mJX.js.map → agents-Dk8idifM.js.map} +1 -1
- package/dist/gateway/static/root/assets/{apps-page-c5XF02ek.js → apps-page-C4_ekFnF.js} +2 -2
- package/dist/gateway/static/root/assets/{apps-page-c5XF02ek.js.map → apps-page-C4_ekFnF.js.map} +1 -1
- package/dist/gateway/static/root/assets/{channels-settings-BTgdsBM4.js → channels-settings-BoRUNSby.js} +2 -2
- package/dist/gateway/static/root/assets/{channels-settings-BTgdsBM4.js.map → channels-settings-BoRUNSby.js.map} +1 -1
- package/dist/gateway/static/root/assets/{cron-dreaming-jobs-CiQJHx3s.js → cron-dreaming-jobs-DjK4YEV9.js} +2 -2
- package/dist/gateway/static/root/assets/{cron-dreaming-jobs-CiQJHx3s.js.map → cron-dreaming-jobs-DjK4YEV9.js.map} +1 -1
- package/dist/gateway/static/root/assets/{cron-page-DJOj7JWb.js → cron-page-wQAlt7WL.js} +2 -2
- package/dist/gateway/static/root/assets/{cron-page-DJOj7JWb.js.map → cron-page-wQAlt7WL.js.map} +1 -1
- package/dist/gateway/static/root/assets/{dist-BY3E71wk.js → dist-DfWs1l6V.js} +2 -2
- package/dist/gateway/static/root/assets/{dist-BY3E71wk.js.map → dist-DfWs1l6V.js.map} +1 -1
- package/dist/gateway/static/root/assets/{extension-debug-page-DzkYBiW-.js → extension-debug-page-DKpIM74M.js} +2 -2
- package/dist/gateway/static/root/assets/{extension-debug-page-DzkYBiW-.js.map → extension-debug-page-DKpIM74M.js.map} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-yF0LIy5D.js → extension-page-DR980mtQ.js} +2 -2
- package/dist/gateway/static/root/assets/{extension-page-yF0LIy5D.js.map → extension-page-DR980mtQ.js.map} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-CS_Y4y3w.js → extension-settings-page-CZWcC3OA.js} +2 -2
- package/dist/gateway/static/root/assets/{extension-settings-page-CS_Y4y3w.js.map → extension-settings-page-CZWcC3OA.js.map} +1 -1
- package/dist/gateway/static/root/assets/{heartbeat-config-api-DD2LdM_Q.js → heartbeat-config-api-D4vLbsOG.js} +2 -2
- package/dist/gateway/static/root/assets/{heartbeat-config-api-DD2LdM_Q.js.map → heartbeat-config-api-D4vLbsOG.js.map} +1 -1
- package/dist/gateway/static/root/assets/{index-V5ZnG6RE.js → index-DZLKmP08.js} +4 -4
- package/dist/gateway/static/root/assets/{index-V5ZnG6RE.js.map → index-DZLKmP08.js.map} +1 -1
- package/dist/gateway/static/root/assets/{logs-page-D79WclZL.js → logs-page-f_viqgaf.js} +2 -2
- package/dist/gateway/static/root/assets/{logs-page-D79WclZL.js.map → logs-page-f_viqgaf.js.map} +1 -1
- package/dist/gateway/static/root/assets/{sessions-page-R_QJy3OK.js → sessions-page-DW2-c8fv.js} +2 -2
- package/dist/gateway/static/root/assets/{sessions-page-R_QJy3OK.js.map → sessions-page-DW2-c8fv.js.map} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-CGaj_9Qb.js → settings-page-D7-piKSc.js} +2 -2
- package/dist/gateway/static/root/assets/{settings-page-CGaj_9Qb.js.map → settings-page-D7-piKSc.js.map} +1 -1
- package/dist/gateway/static/root/assets/{skills-page-UzbTgnVY.js → skills-page-ChpOJZM1.js} +2 -2
- package/dist/gateway/static/root/assets/{skills-page-UzbTgnVY.js.map → skills-page-ChpOJZM1.js.map} +1 -1
- package/dist/gateway/static/root/assets/{use-image-provider-credentials-DAx__u3a.js → use-image-provider-credentials-131rA-SV.js} +2 -2
- package/dist/gateway/static/root/assets/{use-image-provider-credentials-DAx__u3a.js.map → use-image-provider-credentials-131rA-SV.js.map} +1 -1
- package/dist/gateway/static/root/index.html +1 -1
- 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/browser/providers/extension.js +37 -3
- package/dist/src/browser/providers/extension.js.map +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/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 +3 -3
- 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 +18 -9
- package/dist/src/gateway/service.js.map +1 -1
- 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/parity/jsonl-transcript-io.js +2 -2
- package/dist/src/session/parity/sessions-json-file.js +1 -1
- package/dist/src/session/parity/transcript-file-lock.js +2 -2
- package/dist/src/session/parity/transcript-paths.js +1 -1
- 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 +4 -4
- 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 +1 -1
package/dist/gateway/static/root/assets/{settings-page-CGaj_9Qb.js → settings-page-D7-piKSc.js}
RENAMED
|
@@ -1,2 +1,2 @@
|
|
|
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}from"./vendor-swr-B5fPo7KK.js";import{$n as i,Ai as a,An as o,Ar as s,At as c,Bn as l,Br as u,Cr as d,Di as f,Dn as p,Dr as m,Dt as h,Ei as g,En as _,Ft as v,Hr as y,In as b,It as x,Kn as S,Ln as C,Lt as w,Mt as T,Nt as E,On as D,Or as O,Ot as k,Pn as A,Pt as j,Qn as M,Qr as N,Rn as ee,Rt as P,S as F,Sn as I,Sr as L,St as R,Ti as te,Tn as z,Vr as B,Xr as V,Y as H,Yn as ne,Zr as re,_ as ie,_i as ae,_n as oe,_r as se,a as U,ar as W,b as ce,bn as le,br as ue,c as G,cn as de,dn as fe,dr as pe,f as me,fi as he,fn as ge,fr as _e,g as ve,gi as ye,h as be,hn as xe,jn as K,jt as Se,kn as Ce,kr as we,m as Te,mi as Ee,mn as De,mr as Oe,ni as ke,nr as Ae,o as je,p as Me,pi as Ne,pn as Pe,ri as Fe,rr as Ie,s as Le,sr as Re,t as ze,ui as Be,un as q,ur as Ve,v as He,vn as Ue,wn as We,x as Ge,xn as Ke,xt as qe,y as Je,yi as Ye,zn as Xe,zr as Ze,zt as Qe}from"./index-V5ZnG6RE.js";import{i as $e,n as et,r as tt,t as nt}from"./use-image-provider-credentials-DAx__u3a.js";import{a as rt,b as it,u as at}from"./cron-dreaming-jobs-CiQJHx3s.js";import{_ as ot,a as st,b as J,c as ct,d as lt,f as ut,g as dt,h as ft,i as pt,l as mt,m as ht,n as gt,o as _t,p as vt,r as yt,s as bt,t as xt,u as St,v as Ct,y as wt}from"./agents-CLNe-mJX.js";import{t as Tt}from"./browser-DNXWYwzc.js";import{a as Et,i as Dt,n as Ot,o as kt,r as At,t as jt}from"./heartbeat-config-api-DD2LdM_Q.js";var Y=n();function Mt(){return b(`rounded-xl border border-edge-subtle bg-surface-base px-4 py-1 sm:px-5`)}var Nt={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 Pt({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 Ft({scheme:e}){let{light:t,dark:n}=Nt[e];return(0,Y.jsxs)(`div`,{className:`flex h-11 w-full overflow-hidden rounded-md border border-edge-subtle`,children:[(0,Y.jsx)(Pt,{...t}),(0,Y.jsx)(`div`,{className:`w-px shrink-0 bg-black/12 dark:bg-white/12`,"aria-hidden":!0}),(0,Y.jsx)(Pt,{...n})]})}var It=[{value:`default`,labelKey:`colorSchemeDefault`},{value:`emerald`,labelKey:`colorSchemeLightGreen`},{value:`mono`,labelKey:`colorSchemeModernMono`}];function Lt(){let e=o(I(e=>e.language)).appearanceSettings,t=Ke(e=>e.colorScheme),n=Ke(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:It.map(({value:r,labelKey:i})=>{let a=t===r;return(0,Y.jsxs)(`button`,{type:`button`,"aria-pressed":a,onClick:()=>n(r),className:b(`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)(Ft,{scheme:r}),(0,Y.jsx)(`span`,{className:b(`text-xs font-medium leading-none`,a?`text-accent-fg`:`text-fg-muted`),children:e[i]})]},r)})})]})}function Rt(){let e=o(I(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:Mt(),"aria-labelledby":`pref-language-heading`,children:[(0,Y.jsx)(`h2`,{id:`pref-language-heading`,className:`sr-only`,children:e.languageTitle}),(0,Y.jsx)(le,{variant:`page`,sections:[`language`]})]}),(0,Y.jsxs)(`section`,{className:Mt(),"aria-labelledby":`pref-appearance-heading`,children:[(0,Y.jsx)(`h2`,{id:`pref-appearance-heading`,className:`sr-only`,children:e.themeTitle}),(0,Y.jsx)(le,{variant:`page`,sections:[`theme`,`font`]}),(0,Y.jsx)(Lt,{})]})]})}var X=e(t(),1);function zt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var Bt={enabled:!0,cron:`0 */6 * * *`,lookbackDays:1,limit:50,dedupeSimilarity:.85},Vt={enabled:!0,cron:`0 3 * * *`,minScore:.8,minRecallCount:3,limit:10,recencyHalfLifeDays:14,maxAgeDays:30},Ht={enabled:!0,cron:`0 5 * * 0`,lookbackDays:7,limit:20,minPatternStrength:.6},Ut={enabled:!1,frequency:`0 3 * * *`,timezone:``,deepEnabled:!0,minScore:.8,minRecallCount:3,limit:10,light:Bt,deep:Vt,rem:Ht};function Wt(e,t){return Number.isFinite(e)?Math.max(0,Math.min(1,e)):t}function Gt(e,t){let n=typeof e==`string`?Number(e):e;return Number.isFinite(n)?Math.max(0,Math.floor(n)):t}function Kt(e,t){let n=typeof e==`string`?Number(e):e;return Number.isFinite(n)?n:t}function qt(e){let t=zt(e)?e:{},n=zt(t.agents)?t.agents:{},r=zt(n.defaults)?n.defaults:{},i=zt(r.memory)?r.memory:{},a=zt(i.dreaming)?i.dreaming:{},o=zt(a.phases)?a.phases:{},s=zt(o.light)?o.light:{},c=zt(o.deep)?o.deep:{},l=zt(o.rem)?o.rem:{};return{enabled:a.enabled===!0,frequency:typeof a.frequency==`string`&&a.frequency.trim()?a.frequency.trim():Ut.frequency,timezone:typeof a.timezone==`string`?a.timezone:``,deepEnabled:c.enabled!==!1,minScore:Wt(typeof c.minScore==`number`?c.minScore:Number(c.minScore),Ut.minScore),minRecallCount:Math.max(1,Gt(c.minRecallCount,Ut.minRecallCount)),limit:Gt(c.limit,Ut.limit),light:{enabled:s.enabled!==!1,cron:typeof s.cron==`string`&&s.cron.trim()?s.cron.trim():Bt.cron,lookbackDays:Math.max(1,Gt(s.lookbackDays,Bt.lookbackDays)),limit:Gt(s.limit,Bt.limit),dedupeSimilarity:Wt(Kt(s.dedupeSimilarity,Bt.dedupeSimilarity),Bt.dedupeSimilarity)},deep:{enabled:c.enabled!==!1,cron:typeof c.cron==`string`&&c.cron.trim()?c.cron.trim():Vt.cron,minScore:Wt(Kt(c.minScore,Vt.minScore),Vt.minScore),minRecallCount:Math.max(1,Gt(c.minRecallCount,Vt.minRecallCount)),limit:Gt(c.limit,Vt.limit),recencyHalfLifeDays:Math.max(1,Kt(c.recencyHalfLifeDays,Vt.recencyHalfLifeDays)),maxAgeDays:Math.max(1,Kt(c.maxAgeDays,Vt.maxAgeDays))},rem:{enabled:l.enabled!==!1,cron:typeof l.cron==`string`&&l.cron.trim()?l.cron.trim():Ht.cron,lookbackDays:Math.max(1,Gt(l.lookbackDays,Ht.lookbackDays)),limit:Gt(l.limit,Ht.limit),minPatternStrength:Wt(Kt(l.minPatternStrength,Ht.minPatternStrength),Ht.minPatternStrength)}}}async function Jt(e){let t=e.frequency.trim(),n=e.timezone.trim();await xe(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:Wt(e.light.dedupeSimilarity,Bt.dedupeSimilarity)},deep:{enabled:!!e.deep.enabled,cron:e.deep.cron.trim()||null,minScore:Wt(e.deep.minScore,Vt.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:Wt(e.rem.minPatternStrength,Ht.minPatternStrength)}}}}}}})}),qe()}function Z(){return`text-xs font-medium text-fg-muted`}function Q(){return`text-sm font-medium text-fg`}function Yt(e){return e?e.replace(`T`,` `).replace(`Z`,``):`—`}function Xt(e){return e===void 0||!Number.isFinite(e)||e<0?`—`:e<1e3?`${Math.round(e)} ms`:`${(e/1e3).toFixed(2)} s`}function Zt({label:e,children:t,className:n}){return(0,Y.jsxs)(`div`,{className:b(`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:b(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:b(`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 $t({label:e,lastRun:t,t:n}){return(0,Y.jsx)(Zt,{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 en({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:b(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:Xt(t.durationMs)})]}),(0,Y.jsxs)(`div`,{className:b(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 tn(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 nn(){let e=o(I(e=>e.language)).dreamingSettings,t=!!oe(e=>e.token),{data:n}=R(t),[i,a]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(null),[v,y]=(0,X.useState)(`deep`),[x,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),[N,ee]=(0,X.useState)(!1),[P,F]=(0,X.useState)(null),[z,B]=(0,X.useState)(null),[V,H]=(0,X.useState)(!1),[re,ie]=(0,X.useState)(null),[ae,U]=(0,X.useState)(null),{data:W,error:ce,isLoading:le,mutate:ue}=r(t?ut():null,ft,{revalidateOnFocus:!1}),G=(0,X.useMemo)(()=>W?tn(W.lock,e):null,[W,e]),de=(0,X.useMemo)(()=>{let e=[];return ce&&e.push(ce instanceof Error?ce.message:String(ce)),c&&e.push(c),g&&e.push(g),P&&e.push(P),re&&e.push(re),A&&e.push(A),e},[ce,c,g,P,re,A]),fe=(0,X.useMemo)(()=>{let t=[];return O&&t.push(e.configSaved),m&&t.push(e.runQueued),u&&t.push(e.actionOk),t},[O,m,u,e]),pe=(0,X.useCallback)(async()=>{d(!1),l(null),h(!1),_(null),k(!1),j(null),F(null),await ue()},[ue]),me=(0,X.useCallback)(async()=>{ee(!0),F(null);try{B((await ht(20)).items??[])}catch(e){F(e instanceof Error?e.message:String(e))}finally{ee(!1)}},[]),he=(0,X.useCallback)(async()=>{H(!0),ie(null);try{U(await vt(50))}catch(e){ie(e instanceof Error?e.message:String(e))}finally{H(!1)}},[]),ge=(0,X.useCallback)(async(e=`deep`)=>{p(!0),h(!1),_(null);try{await ot(e),h(!0),await ue()}catch(e){_(e instanceof Error?e.message:String(e))}finally{p(!1)}},[ue]),ve=(0,X.useCallback)(async e=>{a(e),l(null),d(!1);try{await dt(e),d(!0),await ue()}catch(e){l(e instanceof Error?e.message:String(e))}finally{a(null)}},[ue]),ye=!t||le||!!i,be=(0,X.useMemo)(()=>{let e=n?.payload?.config;return qt(e??{})},[n]);(0,X.useEffect)(()=>{if(t){if(!w){T(be),C(be);return}JSON.stringify(be)!==JSON.stringify(w)&&(T(be),C(be))}},[w,be,t]);let xe=(0,X.useMemo)(()=>!x||!w?!1:JSON.stringify(x)!==JSON.stringify(w),[x,w]),Se=(0,X.useCallback)(async()=>{if(x){D(!0),k(!1),j(null);try{await Jt(x),T(x),k(!0),await ue()}catch(e){j(e instanceof Error?e.message:String(e))}finally{D(!1)}}},[x,ue]);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:[be.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:v,onChange:e=>y(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)(K,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||f,onClick:()=>void ge(v),title:e.runNowHint,children:[f?(0,Y.jsx)(s,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(se,{className:`mr-2 size-4`,"aria-hidden":!0}),e.runNow]})]}):null,(0,Y.jsxs)(K,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t,onClick:()=>void pe(),children:[(0,Y.jsx)(_e,{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)(Ct,{className:`min-w-0`,children:[(0,Y.jsx)(wt,{icon:Ie,title:e.configTitle,subtitle:e.configHint,trailing:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(K,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||!x||E||!xe,onClick:()=>void Se(),children:[E?(0,Y.jsx)(s,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,e.saveConfig]}),(0,Y.jsx)(K,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||!x||E||!xe,onClick:()=>{k(!1),j(null),C(w)},children:e.resetConfig})]})}),x?(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:x.enabled,onChange:e=>C({...x,enabled:e.target.checked})}),(0,Y.jsx)(`span`,{children:x.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:x.frequency,onChange:e=>C({...x,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:x.timezone,onChange:e=>C({...x,timezone:e.target.value}),placeholder:`Asia/Shanghai`})]})]}),(0,Y.jsxs)(Zt,{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:x.light.enabled,onChange:e=>C({...x,light:{...x.light,enabled:e.target.checked}})}),(0,Y.jsx)(`span`,{children:x.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:x.light.cron,onChange:e=>C({...x,light:{...x.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:x.light.lookbackDays,onChange:e=>C({...x,light:{...x.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:x.light.limit,onChange:e=>C({...x,light:{...x.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:x.light.dedupeSimilarity,onChange:e=>C({...x,light:{...x.light,dedupeSimilarity:Number(e.target.value)}})})]})]})]}),(0,Y.jsxs)(Zt,{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:x.deep.enabled,onChange:e=>C({...x,deep:{...x.deep,enabled:e.target.checked}})}),(0,Y.jsx)(`span`,{children:x.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:x.deep.cron,onChange:e=>C({...x,deep:{...x.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:x.deep.minScore,onChange:e=>C({...x,deep:{...x.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:x.deep.minRecallCount,onChange:e=>C({...x,deep:{...x.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:x.deep.limit,onChange:e=>C({...x,deep:{...x.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:x.deep.recencyHalfLifeDays,onChange:e=>C({...x,deep:{...x.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:x.deep.maxAgeDays,onChange:e=>C({...x,deep:{...x.deep,maxAgeDays:Number(e.target.value)}})})]})]})]}),(0,Y.jsxs)(Zt,{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:x.rem.enabled,onChange:e=>C({...x,rem:{...x.rem,enabled:e.target.checked}})}),(0,Y.jsx)(`span`,{children:x.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:x.rem.cron,onChange:e=>C({...x,rem:{...x.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:x.rem.lookbackDays,onChange:e=>C({...x,rem:{...x.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:x.rem.limit,onChange:e=>C({...x,rem:{...x.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:x.rem.minPatternStrength,onChange:e=>C({...x,rem:{...x.rem,minPatternStrength:Number(e.target.value)}})})]})]})]})]}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.configLoading})]}),(0,Y.jsxs)(Ct,{className:`min-w-0`,children:[(0,Y.jsx)(wt,{icon:te,title:e.runtimeTitle,subtitle:e.runtimeHint,trailing:le?(0,Y.jsx)(s,{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)(Zt,{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:W?W.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:b(Q(),G?.className),children:G?G.text:`—`})]}),(0,Y.jsxs)(`div`,{className:b(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:W?W.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:W?W.config.timezone:`—`})]})]})}),(0,Y.jsx)(Zt,{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:W?String(W.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:W?String(W.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:W?Yt(W.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:W?Yt(W.store.lastPromotedAt):`—`})]})]})}),W?.config?.phases?(0,Y.jsx)(Zt,{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)(ne,{className:`size-4 text-amber-500`}),label:`Light`,enabled:W.config.phases.light.enabled,cron:W.config.phases.light.cron,details:`lookback=${W.config.phases.light.lookbackDays}d, limit=${W.config.phases.light.limit}, dedupe=${W.config.phases.light.dedupeSimilarity}`,t:e}),(0,Y.jsx)(Qt,{icon:(0,Y.jsx)(L,{className:`size-4 text-indigo-500`}),label:`Deep`,enabled:W.config.phases.deep.enabled,cron:W.config.phases.deep.cron,details:`minScore=${W.config.phases.deep.minScore}, recalls≥${W.config.phases.deep.minRecallCount}, limit=${W.config.phases.deep.limit}, halfLife=${W.config.phases.deep.recencyHalfLifeDays}d`,t:e}),(0,Y.jsx)(Qt,{icon:(0,Y.jsx)(M,{className:`size-4 text-purple-500`}),label:`REM`,enabled:W.config.phases.rem.enabled,cron:W.config.phases.rem.cron,details:`lookback=${W.config.phases.rem.lookbackDays}d, limit=${W.config.phases.rem.limit}, strength≥${W.config.phases.rem.minPatternStrength}`,t:e})]})}):null,(0,Y.jsxs)(Zt,{label:e.subsectionLastRun,children:[(0,Y.jsx)(`p`,{className:`mb-2 text-xs text-fg-muted`,children:e.lastRunBlockHint}),W?.lastRun?.exists?(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[W.lastRun.parseError?(0,Y.jsxs)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:[e.lastRunParseError,`: `,W.lastRun.parseError]}):null,W.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)(en,{t:e,r:W.lastRun.record})}):null,W.lastRun.raw!==void 0&&W.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(W.lastRun.raw,null,2)})]}):null]}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.lastRunEmpty})]}),(0,Y.jsx)($t,{label:e.subsectionLightLastRun,lastRun:W?.lightLastRun,t:e}),(0,Y.jsx)($t,{label:e.subsectionRemLastRun,lastRun:W?.remLastRun,t:e})]})]})]}),(0,Y.jsxs)(Ct,{children:[(0,Y.jsx)(wt,{icon:Ve,title:e.previewTitle,subtitle:e.previewHint,trailing:(0,Y.jsxs)(K,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||N,onClick:()=>void me(),children:[N?(0,Y.jsx)(s,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,e.previewLoad]})}),z?z.length>0?(0,Y.jsx)(`div`,{className:`space-y-2`,children:z.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)(Ct,{children:[(0,Y.jsx)(wt,{icon:te,title:e.eventsTitle,subtitle:e.eventsHint,trailing:(0,Y.jsxs)(K,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||V,onClick:()=>void he(),children:[V?(0,Y.jsx)(s,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,e.eventsLoad]})}),ae?ae.length>0?(0,Y.jsx)(`div`,{className:`space-y-1.5`,children:ae.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:b(`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:Xt(e.durationMs)}),(0,Y.jsx)(`span`,{className:`ml-auto text-fg-subtle`,children:Yt(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)(Ct,{className:`max-w-2xl`,children:[(0,Y.jsx)(wt,{icon:Xe,title:e.maintenanceTitle,subtitle:e.maintenanceHint}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,Y.jsxs)(K,{variant:`secondary`,disabled:ye,onClick:()=>{confirm(e.confirmResetStore)&&ve(`reset_store`)},children:[i===`reset_store`?(0,Y.jsx)(s,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(S,{className:`mr-2 size-4`,"aria-hidden":!0}),e.resetStore]}),(0,Y.jsxs)(K,{variant:`secondary`,disabled:ye,onClick:()=>{confirm(e.confirmClearLock)&&ve(`clear_lock`)},children:[i===`clear_lock`?(0,Y.jsx)(s,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(we,{className:`mr-2 size-4`,"aria-hidden":!0}),e.clearLock]})]})]})]})}var rn=e(Tt(),1);function an(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function on(e){let t=an(e)?e:{},n=an(t.gateway)?t.gateway:{},r=an(n.auth)?n.auth:{},i=r.mode===`none`||r.mode===`token`?r.mode:`token`,a=(an(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 sn(e){let t=e.auth.token.trim().length>0?{mode:e.auth.mode,token:e.auth.token}:{mode:e.auth.mode};await xe(q(`/api/config`),{method:`PATCH`,body:JSON.stringify({gateway:{auth:t},update:{channel:e.updateChannel}})}),qe()}function cn(){return b(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,Ce,`dark:border-edge`)}function ln(){let e=I(e=>e.language),t=o(e),n=t.gatewaySettings,r=oe(e=>e.token),i=oe(e=>e.tokenExpired),a=oe(e=>e.openTokenDialog),c=!!r,[l,u]=(0,X.useState)(null),[d,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}=R(c),O=(0,X.useMemo)(()=>w?.payload?.config===void 0?null:structuredClone(on(w.payload.config)),[w]);(0,X.useEffect)(()=>{if(!c){u(null),f(null),C.current=!1;return}O!==null&&(C.current||(u(O),f(structuredClone(O)),v(!1)))},[c,O]);let k=!!(c&&E&&w===void 0&&!T),A=T instanceof Error?T.message:T?String(T):null,j=(0,X.useMemo)(()=>!l||!d?!1:JSON.stringify(l)!==JSON.stringify(d),[l,d]),M=(0,X.useCallback)(e=>{C.current=!0,u(t=>t?{...t,auth:{...t.auth,...e}}:null)},[]),ee=(0,X.useCallback)(e=>{C.current=!0,u(t=>t?{...t,updateChannel:e}:null)},[]),P=(0,X.useCallback)(async()=>{if(!(!l||p)){m(!0),g(null),v(!1);try{await sn(l),C.current=!1,f(structuredClone(l)),v(!0),window.setTimeout(()=>v(!1),2500)}catch(e){g(e instanceof Error?e.message:n.saveError)}finally{m(!1)}}},[l,p,n.saveError]),F=(0,X.useCallback)(()=>{d&&(C.current=!1,u(structuredClone(d)),g(null),v(!1))},[d]),L=(0,X.useCallback)(async()=>{let e=l?.auth.token;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),S(!0),window.setTimeout(()=>S(!1),2e3))},[l?.auth.token]);return c?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)(s,{className:`size-4 animate-spin`}),n.loading]})}):l?(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:Ue(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)(N,{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)(K,{type:`button`,variant:`secondary`,disabled:!j||p,onClick:F,children:n.discard}),(0,Y.jsx)(K,{type:`button`,variant:`primary`,disabled:!j||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)(he,{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)(K,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:()=>a(),children:n.updateToken})})]}):null,j?(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,l.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)(W,{className:`size-4 text-accent`,strokeWidth:1.75}),t.settingsSections.gateway]}),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(l.host||l.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:l.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:l.port==null?`—`:String(l.port)})]}),(0,Y.jsx)(`p`,{className:`sm:col-span-2 text-xs text-fg-subtle`,children:n.listenHint})]}),(0,Y.jsx)(dn,{g:n,value:l.auth.token,show:y,copied:x,onToggleShow:()=>b(e=>!e),onCopy:()=>void L(),onChange:e=>M({token:e})}),(0,Y.jsx)(K,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,onClick:()=>a(),children:n.changeToken}),r?(0,Y.jsx)(un,{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:l.updateChannel,onChange:e=>ee(e.target.value),className:cn(),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??A??n.loadError}),(0,Y.jsx)(K,{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 un({g:e,gatewayToken:t}){let[n,r]=(0,X.useState)(ge),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(!1),[l,u]=(0,X.useState)(!1),d=n.trim(),f=(0,X.useMemo)(()=>{try{let e=new URL(d);return e.protocol===`http:`||e.protocol===`https:`}catch{return!1}},[d]),p=(0,X.useMemo)(()=>!t||!f?``:fe({baseUrl:d,gatewayToken:t}),[f,t,d]);(0,X.useEffect)(()=>{if(!p){o(null),c(!1);return}let e=!1;return c(!1),rn.toDataURL(p,{width:216,margin:2,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}}).then(t=>{e||o(t)}).catch(()=>{e||(c(!0),o(null))}),()=>{e=!0}},[p]);let m=f&&Pe(d),h=(0,X.useCallback)(async()=>{p&&(await navigator.clipboard.writeText(p).catch(()=>{}),u(!0),window.setTimeout(()=>u(!1),2e3))},[p]);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)(i,{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:b(cn(),`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}),f?null:(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:e.mobilePairInvalidBaseUrl}),m?(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})]}),p?(0,Y.jsxs)(`div`,{className:`flex flex-col items-center gap-3 sm:items-start`,children:[a&&!s?(0,Y.jsx)(`img`,{src:a,alt:``,className:`h-56 w-56 rounded-lg border border-edge-subtle bg-white object-contain p-3 dark:border-edge`}):null,!a&&!s?(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.mobilePairEncoding}):null,s?(0,Y.jsx)(`p`,{className:`text-center text-sm text-fg-muted sm:text-left`,children:e.mobilePairImageError}):null,(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,disabled:!p,onClick:()=>void h(),children:[l?(0,Y.jsx)(ae,{className:`size-3.5`}):(0,Y.jsx)(Fe,{className:`size-3.5`}),l?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 dn({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:b(cn(),`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)(K,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:a,children:[r?(0,Y.jsx)(ae,{className:`size-3.5`}):(0,Y.jsx)(Fe,{className:`size-3.5`}),r?e.copied:e.copy]}):null,(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:i,children:[n?(0,Y.jsx)(re,{className:`size-3.5`}):(0,Y.jsx)(V,{className:`size-3.5`}),n?e.hide:e.show]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tokenHelp})]})}function fn(){return q(`/api/channels/status`)}var pn=rt,mn=[3e4,6e4,3e5,6e5,9e5,18e5,36e5,72e5],hn=new Set(mn);function gn(){return b(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,Ce,`dark:border-edge`)}function _n(){return b(D,_)}function vn(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 yn(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 bn(){let e=I(e=>e.language),t=o(e),n=t.heartbeatSettings,i=!!oe(e=>e.token),[a,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(``),[p,m]=(0,X.useState)(``),[h,g]=(0,X.useState)(!1),[_,v]=(0,X.useState)(!1),[x,S]=(0,X.useState)(null),[C,w]=(0,X.useState)(!1),[T,E]=(0,X.useState)(!1),[D,O]=(0,X.useState)(!1),[k,A]=(0,X.useState)(!1),[j,M]=(0,X.useState)(null),[ee,P]=(0,X.useState)([]),{data:F,error:L,isLoading:te,mutate:z}=R(i),{data:B,error:V,isLoading:H,mutate:ne}=r(i?kt():null,Et,{revalidateOnFocus:!1}),{data:re=[]}=r(i?fn():null,pn,{revalidateOnFocus:!1}),ie=(0,X.useMemo)(()=>vn(F?.payload?.config),[F]),ae=(0,X.useMemo)(()=>jt(F?.payload?.config??{}),[F]),U=(0,X.useMemo)(()=>!a||!l?!1:JSON.stringify(a)!==JSON.stringify(l),[a,l]),W=(0,X.useMemo)(()=>d!==p,[d,p]);(0,X.useEffect)(()=>{if(!i){c(null),u(null);return}if(F!==void 0&&!U){let e=structuredClone(ae);c(e),u(e),w(!1)}},[i,F,ae,U]),(0,X.useEffect)(()=>{!i||B===void 0||W||(f(B),m(B),E(!1))},[i,B,W]);let ce=L instanceof Error?L.message:L?String(L):V instanceof Error?V.message:V?String(V):null,le=!!(i&&(F===void 0||B===void 0)&&!ce&&(te||H));(0,X.useEffect)(()=>{if(!i||!a){P([]);return}let e=a.target.trim();if(!e){P([]);return}let t=!1;return at(e).then(e=>{t||P(e)}),()=>{t=!0}},[i,a?.target]);let ue=(0,X.useCallback)(()=>{let e=a?.target?.trim();e&&at(e).then(P)},[a?.target]),G=(0,X.useCallback)(async()=>{O(!0),A(!1),M(null);try{await Dt(),A(!0),window.setTimeout(()=>A(!1),3e3)}catch(e){M(e instanceof Error?e.message:n.triggerError)}finally{O(!1)}},[n.triggerError]),de=(0,X.useCallback)(e=>{c(t=>t?{...t,...e}:null)},[]),fe=(0,X.useCallback)(()=>{l&&(c(structuredClone(l)),w(!1),S(null))},[l]),pe=(0,X.useCallback)(()=>{f(p),E(!1),S(null)},[p]),me=(0,X.useCallback)(async()=>{if(!(!a||h)){g(!0),S(null),w(!1);try{await Ot(a),u(structuredClone(a)),w(!0),window.setTimeout(()=>w(!1),2500)}catch(e){S(e instanceof Error?e.message:n.saveConfigError)}finally{g(!1)}}},[a,h,n.saveConfigError]),he=(0,X.useCallback)(async()=>{if(!_){v(!0),S(null),E(!1);try{await At(d),m(d),E(!0),window.setTimeout(()=>E(!1),2500)}catch(e){S(e instanceof Error?e.message:n.saveDocError)}finally{v(!1)}}},[d,_,n.saveDocError]);return i?le?(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)(s,{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:Ue(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)(N,{className:`size-3.5`})]})]})}),ie?(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.workspaceLabel,`: `,(0,Y.jsx)(`span`,{className:`font-mono text-fg-muted`,children:ie})]}):null,x?(0,Y.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:x}):null,(0,Y.jsxs)(Ct,{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)(y,{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)(K,{type:`button`,variant:`secondary`,className:`inline-flex items-center gap-2`,disabled:D,onClick:()=>void G(),children:[D?(0,Y.jsx)(s,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(se,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),D?n.triggering:n.triggerNow]}),k?(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}),j?(0,Y.jsx)(`p`,{className:`mb-3 text-sm text-red-600 dark:text-red-400`,children:j}):null,(0,Y.jsx)(xn,{h:n,cron:t.cron,form:a,channels:re,sessionChatIds:ee,onRefreshChatIds:ue,update:de,inputClassName:gn,selectClassName:_n}),(0,Y.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-2`,children:[C?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.savedConfig}):null,(0,Y.jsx)(K,{type:`button`,variant:`secondary`,disabled:!U||h,onClick:fe,children:n.discard}),(0,Y.jsx)(K,{type:`button`,variant:`primary`,disabled:!U||h,onClick:()=>void me(),children:h?n.savingConfig:n.saveConfig}),U?(0,Y.jsx)(`span`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedConfig}):null]})]}),(0,Y.jsxs)(Ct,{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:b(gn(),`min-h-[12rem] resize-y font-mono text-xs leading-relaxed`),value:d,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:[T?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.savedDoc}):null,(0,Y.jsx)(K,{type:`button`,variant:`secondary`,disabled:!W||_,onClick:pe,children:n.discard}),(0,Y.jsx)(K,{type:`button`,variant:`primary`,disabled:!W||_,onClick:()=>void he(),children:_?n.savingDoc:n.saveDoc}),W?(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:x??ce??n.loadError}),(0,Y.jsx)(K,{type:`button`,variant:`secondary`,onClick:()=>{z(),ne()},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 xn({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)(()=>hn.has(n.intervalMs)?String(n.intervalMs):``,[n.intervalMs]),[p,m]=(0,X.useState)(null),h=Math.max(1,Math.round(n.intervalMs/1e3)),g=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:b(s(),`min-w-0 flex-1`),value:g,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:b(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}),mn.map(t=>(0,Y.jsx)(`option`,{value:String(t),children:yn(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)(K,{type:`button`,variant:`ghost`,className:`h-7 gap-1 px-2 text-xs`,title:t.refreshRecipientHint,onClick:a,children:[(0,Y.jsx)(_e,{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:b(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:b(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:it(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:b(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)(K,{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)(K,{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 Sn(){let e=await De(q(`/api/image/providers`));if(!e.ok)throw Error(`Image providers: HTTP ${e.status}`);return(await e.json()).payload?.providers??[]}function Cn(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 wn(e,t){let n=Cn(e.filter(e=>e.configured===!0));return!t||n.includes(t)?n:[t,...n]}function Tn(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 En=`image-generation-providers`;function Dn({value:e,disabled:t,placeholder:n,searchPlaceholder:i,noMatches:a,registryEmptyHint:o,outOfFilterNote:s,className:c,onChange:l}){let[u,d]=(0,X.useState)(!1),[f,m]=(0,X.useState)(``),{data:h,isLoading:g,error:_}=r(En,Sn,{revalidateOnFocus:!1}),v=e.trim(),y=(0,X.useMemo)(()=>Cn((h??[]).filter(e=>e.configured===!0)),[h]),S=(0,X.useMemo)(()=>wn(h??[],v),[h,v]),C=(0,X.useMemo)(()=>Tn(S,f),[S,f]),T=!!s&&!!v&&!y.includes(v),E=e.trim()?e:n,D=e.trim()||n,O=(0,X.useCallback)(e=>{d(e),e||m(``)},[]);return(0,Y.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,Y.jsxs)(P,{open:u,onOpenChange:O,modal:!1,children:[(0,Y.jsx)(Qe,{asChild:!0,children:(0,Y.jsxs)(`button`,{type:`button`,disabled:t||g,title:g?`…`:D,className:b(We,`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`,H.transition,`hover:border-edge hover:bg-surface-hover/45`,p,`disabled:cursor-not-allowed disabled:opacity-50`,`dark:border-edge-subtle dark:hover:bg-surface-hover/55`,c),"aria-haspopup":`listbox`,"aria-expanded":u,children:[(0,Y.jsx)(`span`,{className:`min-w-0 truncate`,children:g?`…`:E}),(0,Y.jsx)(Ne,{className:`h-4 w-4 shrink-0 text-fg-subtle opacity-70`,"aria-hidden":!0})]})}),(0,Y.jsx)(w,{children:(0,Y.jsxs)(x,{className:b(`w-[min(22rem,calc(100vw-2rem))] rounded-xl border border-edge-subtle bg-surface-panel p-1 shadow-elevated dark:border-edge-subtle`,G),side:`bottom`,sideOffset:4,align:`end`,onOpenAutoFocus:e=>e.preventDefault(),children:[(0,Y.jsx)(`input`,{type:`search`,className:b(`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`,z),placeholder:i,value:f,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:[_?(0,Y.jsx)(`div`,{className:`px-2 py-2 text-xs text-red-600 dark:text-red-400`,children:_ instanceof Error?_.message:`Failed to load image providers`}):null,!_&&S.length===0&&!g?(0,Y.jsx)(`div`,{className:`px-2 py-3 text-center text-xs text-fg-muted`,children:o??a}):null,!_&&S.length>0&&C.length===0?(0,Y.jsx)(`div`,{className:`px-2 py-3 text-center text-xs text-fg-muted`,children:a}):null,C.map(t=>(0,Y.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t===e,className:b(`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),d(!1),m(``)},children:[(0,Y.jsx)(ae,{className:b(`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))]})]})})]}),T?(0,Y.jsx)(`p`,{className:`text-xs text-amber-700 dark:text-amber-400/90`,children:s}):null]})}function On(e){let{a:t,chat:n,form:r,update:i}=e;return(0,Y.jsxs)(Ct,{children:[(0,Y.jsx)(wt,{icon:B,title:t.cardModelsTitle,subtitle:t.cardModelsSubtitle}),(0,Y.jsxs)(`div`,{className:`mt-4 flex flex-col gap-5`,children:[(0,Y.jsx)(lt,{label:t.label.imageModel,description:t.desc.imageModel,children:(0,Y.jsx)(U,{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)(lt,{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)(U,{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)(K,{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)(S,{className:`size-4`,strokeWidth:1.75})})]},a)),(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:()=>i({imageModelFallbacks:[...r.imageModelFallbacks,``]}),children:[(0,Y.jsx)(Oe,{className:`size-4 shrink-0`,strokeWidth:1.75}),t.addModelFallback]})]})}),(0,Y.jsx)(lt,{label:t.label.imageGenerationModel,description:t.desc.imageGenerationModel,children:(0,Y.jsx)(Dn,{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)(lt,{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)(Dn,{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)(K,{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)(S,{className:`size-4`,strokeWidth:1.75})})]},a)),(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:()=>i({imageGenerationModelFallbacks:[...r.imageGenerationModelFallbacks,``]}),children:[(0,Y.jsx)(Oe,{className:`size-4 shrink-0`,strokeWidth:1.75}),t.addModelFallback]})]})})]})]})}function kn(){return b(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,Ce)}var An=()=>q($e);function jn(e){return{imageModel:e.imageModel,imageModelFallbacks:e.imageModelFallbacks,imageGenerationModel:e.imageGenerationModel,imageGenerationModelFallbacks:e.imageGenerationModelFallbacks,imageGenerationModelTimeoutMs:e.imageGenerationModelTimeoutMs,imageGenerationModelAutoProviderFallback:e.imageGenerationModelAutoProviderFallback}}function Mn(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 Nn(){let e=I(e=>e.language),t=o(e),n=t.imageModelsSettings,i=!!oe(e=>e.token),[a,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(!0),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(!1),[_,v]=(0,X.useState)(void 0),y=de(),x=(0,X.useMemo)(()=>new Set(y.map(e=>e.id)),[y]),S=(0,X.useCallback)(async()=>{if(i){f(!0),v(void 0);try{let e=await ct(),t=structuredClone(e);c(t),u(structuredClone(t))}catch(e){v(e instanceof Error?e.message:String(e))}finally{f(!1)}}},[i]);(0,X.useEffect)(()=>{S()},[S]);let C=(0,X.useCallback)(e=>{c(t=>t?{...t,...e}:null)},[]),{data:w=[],mutate:T}=r(i?An():null,tt,{revalidateOnFocus:!1}),E=R(i),D=nt(w),O=(0,X.useMemo)(()=>!a||!l?!1:JSON.stringify(jn(a))!==JSON.stringify(jn(l)),[a,l]),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 A=(0,X.useCallback)(async()=>{if(a){m(!0),v(void 0);try{try{mt(a.paramsJson)}catch(e){v(e instanceof SyntaxError?t.agentSettings.advanced.paramsInvalidJson:e instanceof Error?e.message:t.agentSettings.advanced.paramsInvalidJson);return}await St(a),u(structuredClone(a)),g(!0),window.setTimeout(()=>g(!1),1500),E.mutate?.()}catch(e){v(e instanceof Error?e.message:String(e))}finally{m(!1)}}},[a,E,t.agentSettings]),j=(0,X.useCallback)(()=>{l&&(c(structuredClone(l)),v(void 0),g(!1))},[l]),M=(0,X.useMemo)(()=>Mn(n),[n]),N=(0,X.useMemo)(()=>({getApiKey:t.providersSettings.getApiKey,getApiKeyIntl:t.providersSettings.getApiKeyIntl,getApiKeyCn:t.providersSettings.getApiKeyCn}),[t.providersSettings]);return i?d||!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)(s,{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)(K,{type:`button`,variant:`ghost`,onClick:()=>{S(),T(),E.mutate?.()},children:[(0,Y.jsx)(_e,{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)(K,{type:`button`,variant:`secondary`,onClick:j,disabled:!O||p,children:n.discard}),(0,Y.jsxs)(K,{type:`button`,variant:`primary`,onClick:()=>void A(),disabled:!O||p,children:[p?(0,Y.jsx)(s,{className:`size-3.5 animate-spin`}):(0,Y.jsx)(pe,{className:`size-3.5`}),(0,Y.jsx)(`span`,{className:`ml-1.5`,children:p?n.saving:n.save})]})]})]}),_?(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:_}):null,(0,Y.jsx)(On,{form:a,update:C,a:t.agentSettings,chat:t.chat}),(0,Y.jsxs)(Ct,{children:[(0,Y.jsx)(wt,{icon:B,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:b(kn(),`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)));c(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=>c(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)(Ct,{children:[(0,Y.jsx)(wt,{icon:W,title:n.providersTitle,subtitle:``}),w.length===0?(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.providersEmpty}):(0,Y.jsx)(et,{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:N,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 Pn=[{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 Fn(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 In(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 Ln(){let e=await De(q(`/api/models-json`)),t=await e.json().catch(()=>({}));if(!e.ok||!t.ok||!t.payload)throw Error(Fn(t)||`HTTP ${e.status}`);return{...t.payload,config:In(t.payload.config)}}async function Rn(e){let t=await De(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(Fn(n)||`HTTP ${t.status}`);return n.payload}async function zn(e){let t=await De(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(Fn(n)||`HTTP ${t.status}`);return n.payload}async function Bn(){let e=await De(q(`/api/models-json/reload`),{method:`POST`}),t=await e.json().catch(()=>({}));if(!e.ok||!t.ok||!t.payload)throw Error(Fn(t)||`HTTP ${e.status}`);return t.payload}async function Vn(e){let t=await De(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(Fn(n)||`HTTP ${t.status}`);return n.payload}function Hn(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 Un(e){return e.startsWith(`!`)}function Wn(e){return/^[A-Z][A-Z0-9_]*$/.test(e)}function Gn(e){return Un(e)?`shell`:Wn(e)?`env`:`literal`}function Kn(e){return e?e.length<=8?`••••`:`${e.slice(0,4)}••••${e.slice(-4)}`:``}function qn(e){let{a:t,chat:n,form:r,update:i}=e;return(0,Y.jsxs)(Ct,{children:[(0,Y.jsx)(wt,{icon:ke,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)(U,{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)(K,{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)(S,{className:`size-4`,strokeWidth:1.75})})]},a)),(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:()=>i({modelFallbacks:[...r.modelFallbacks,``]}),children:[(0,Y.jsx)(Oe,{className:`size-4 shrink-0`,strokeWidth:1.75}),t.addModelFallback]})]})]})}var Jn={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 Yn(e){return e===`openrouter`?`openrouter`:e===`zhipuCn`?`zhipu-cn`:e===`zaiGeneral`?`zai`:e}var Xn=[{value:`text`,labelKey:`inputTextOnly`},{value:`text,image`,labelKey:`inputTextVision`}];function Zn(){return b(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,Ce,`dark:border-edge`)}function Qn(){return b(D,_)}function $n(e){return(e.input||[`text`]).includes(`image`)?`text,image`:`text`}function er(e){return e===`text,image`?[`text`,`image`]:[`text`]}function tr(e,t,n){return{...e,providers:{...e.providers,[t]:{...e.providers[t],...n}}}}function nr(e,t){let n={...e.providers};return delete n[t],{...e,providers:n}}function rr(e,t,n){return{...e,providers:{...e.providers,[t]:n}}}function ir({open:e,onOpenChange:t,providerId:n,model:r,isNew:i,onSave:a,m:o}){let[s,l]=(0,X.useState)(()=>Hn(``)),[u,d]=(0,X.useState)(()=>new Map);(0,X.useEffect)(()=>{e&&(d(new Map),l(r?{...r}:Hn(``)))},[e,r]);let f=(e,t)=>{l(n=>({...n,[e]:t})),d(t=>{let n=new Map(t);return n.delete(e),n})},p=()=>{let e=new Map;return(s.id||``).trim()||e.set(`id`,o.modelIdRequired),s.contextWindow!==void 0&&s.contextWindow<=0&&e.set(`contextWindow`,o.mustBePositive),s.maxTokens!==void 0&&s.maxTokens<=0&&e.set(`maxTokens`,o.mustBePositive),d(e),e.size===0},m=()=>{if(!p())return;let e=(s.id||``).trim();a({...s,id:e,name:s.name?.trim()||e,reasoning:s.reasoning||!1,input:s.input||[`text`],contextWindow:s.contextWindow??128e3,maxTokens:s.maxTokens??16384,cost:{input:s.cost?.input??0,output:s.cost?.output??0,cacheRead:s.cost?.cacheRead??0,cacheWrite:s.cost?.cacheWrite??0}}),t(!1)},g=$n(s);return(0,Y.jsx)(T,{open:e,onOpenChange:t,children:(0,Y.jsxs)(Se,{children:[(0,Y.jsx)(c,{className:b(`xopc-dialog-overlay fixed inset-0 bg-scrim`,Le)}),(0,Y.jsxs)(k,{className:b(`xopc-dialog-content fixed left-1/2 top-1/2 max-h-[min(90vh,720px)] w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2`,je,`overflow-y-auto rounded-xl border border-edge bg-surface-panel p-4 shadow-popover dark:border-edge`),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)(E,{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)(ee,{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:b(Zn(),u.has(`id`)&&`border-red-500`),value:s.id||``,onChange:e=>f(`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:Zn(),value:s.name||``,onChange:e=>f(`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:Qn(),value:g,onChange:e=>f(`input`,er(e.target.value)),children:Xn.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:s.reasoning||!1,onChange:e=>f(`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:b(Zn(),u.has(`contextWindow`)&&`border-red-500`),value:s.contextWindow??128e3,onChange:e=>f(`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:b(Zn(),u.has(`maxTokens`)&&`border-red-500`),value:s.maxTokens??16384,onChange:e=>f(`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:Zn(),value:s.cost?.input??0,onChange:e=>f(`cost`,{...s.cost,input:parseFloat(e.target.value)||0,output:s.cost?.output??0,cacheRead:s.cost?.cacheRead??0,cacheWrite:s.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:Zn(),value:s.cost?.output??0,onChange:e=>f(`cost`,{...s.cost,input:s.cost?.input??0,output:parseFloat(e.target.value)||0,cacheRead:s.cost?.cacheRead??0,cacheWrite:s.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)(K,{type:`button`,variant:`secondary`,children:o.cancel})}),(0,Y.jsx)(K,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:m,children:i?o.addModelConfirm:o.saveModelConfirm})]})]})]})})}function ar({open:e,onOpenChange:t,presetKey:n,onConfirm:r,m:i}){let[a,o]=(0,X.useState)(``),[s,l]=(0,X.useState)(`custom`),[u,d]=(0,X.useState)(``),[f,p]=(0,X.useState)(`openai-completions`),[m,g]=(0,X.useState)(``),[_,v]=(0,X.useState)(null);(0,X.useEffect)(()=>{if(!e)return;v(null);let t=n||null;if(t&&Jn[t]){let e=Jn[t];l(t),d(e.baseUrl||``),p(e.api||`openai-completions`),g(e.apiKey??``),o(Yn(t))}else l(`custom`),o(``),d(``),p(`openai-completions`),g(``)},[e,n]);let y=e=>{if(l(e),e===`custom`)return;let t=Jn[e];t&&(d(t.baseUrl||``),p(t.api||`openai-completions`),g(t.apiKey??``),o(Yn(e)))};return(0,Y.jsx)(T,{open:e,onOpenChange:t,children:(0,Y.jsxs)(Se,{children:[(0,Y.jsx)(c,{className:b(`xopc-dialog-overlay fixed inset-0 bg-scrim`,Le)}),(0,Y.jsxs)(k,{className:b(`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`,je,`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)(E,{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)(ee,{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:Qn(),value:s,onChange:e=>y(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:Zn(),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:Zn(),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:Qn(),value:f,onChange:e=>p(e.target.value),children:Pn.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:Zn(),value:m,onChange:e=>g(e.target.value),placeholder:i.apiKeyPlaceholder})]}),_?(0,Y.jsxs)(`p`,{className:`flex items-center gap-1 text-xs text-red-600 dark:text-red-400`,children:[(0,Y.jsx)(he,{className:`size-3.5 shrink-0`}),_]}):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)(K,{type:`button`,variant:`secondary`,children:i.cancel})}),(0,Y.jsx)(K,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:()=>{let e=a.trim();if(!e){v(i.providerIdRequired);return}v(null),r(e,{baseUrl:u.trim()||void 0,api:f,apiKey:m.trim()||void 0,models:[]}),t(!1)},children:i.addProviderConfirm})]})]})]})})}function or({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?Gn(f.apiKey):null,g=o.get(e),_=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)(ye,{className:`size-4 shrink-0 text-fg-muted`}):(0,Y.jsx)(Ee,{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:b(`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)(S,{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:Zn(),value:f.baseUrl||``,onChange:n=>t(t=>tr(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:Qn(),value:f.api||`openai-completions`,onChange:n=>t(t=>tr(t,e,{api:n.target.value})),children:Pn.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:b(Zn(),`min-w-0 flex-1`),type:_?`text`:`password`,autoComplete:`off`,value:f.apiKey||``,onChange:n=>{let r=n.target.value;t(t=>tr(t,e,{apiKey:r})),d(t=>{let n=new Map(t);return n.delete(e),n})},placeholder:c.apiKeyPlaceholder}),(0,Y.jsx)(K,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>a(e),children:_?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(re,{className:`mr-1 size-3.5`}),c.hide]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(V,{className:`mr-1 size-3.5`}),c.show]})}),(0,Y.jsx)(K,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>s(e,f.apiKey||``),children:c.testKey})]}),g?(0,Y.jsx)(`p`,{className:b(`mt-1 text-xs`,g.error?`text-red-600 dark:text-red-400`:`text-emerald-700 dark:text-emerald-400`),children:g.error?`${c.testError}: ${g.error}`:`${c.testOk} (${g.type}): ${Kn(g.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=>tr(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)(K,{type:`button`,variant:`primary`,className:`px-2 py-1 text-xs`,onClick:()=>u(e,null,!0),children:[(0,Y.jsx)(Oe,{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)(ue,{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?tr(t,e,{models:(r.models||[]).filter(e=>e.id!==n.id)}):t})},"aria-label":c.removeModel,children:(0,Y.jsx)(S,{className:`size-4`})})]})]},n.id))})]})]}):null]},e)})})}function sr({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)(ke,{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)(K,{type:`button`,className:`mb-6 bg-accent text-white hover:bg-accent/90`,onClick:()=>t(null),children:[(0,Y.jsx)(Oe,{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:b(`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`,H.transition,H.focusRingBase),onClick:()=>t(`ollama`),children:[(0,Y.jsx)(C,{className:`size-3.5`,"aria-hidden":!0}),e.presetOllama]}),(0,Y.jsxs)(`button`,{type:`button`,className:b(`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`,H.transition,H.focusRingBase),onClick:()=>t(`openrouter`),children:[(0,Y.jsx)(Ye,{className:`size-3.5`,"aria-hidden":!0}),e.presetOpenRouter]}),(0,Y.jsxs)(`button`,{type:`button`,className:b(`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`,H.transition,H.focusRingBase),onClick:()=>t(`lmstudio`),children:[(0,Y.jsx)(ke,{className:`size-3.5`,"aria-hidden":!0}),e.presetLmStudio]}),(0,Y.jsxs)(`button`,{type:`button`,className:b(`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`,H.transition,H.focusRingBase),onClick:()=>t(`zhipuCn`),children:[(0,Y.jsx)(C,{className:`size-3.5`,"aria-hidden":!0}),e.presetZhipuCn]}),(0,Y.jsxs)(`button`,{type:`button`,className:b(`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`,H.transition,H.focusRingBase),onClick:()=>t(`zaiGeneral`),children:[(0,Y.jsx)(Ye,{className:`size-3.5`,"aria-hidden":!0}),e.presetZaiGeneral]})]})]})}function cr(){let e=I(e=>e.language),t=o(e),n=t.modelsSettings,r=bt(t.agentSettings),i=!!oe(e=>e.token),[a,c]=(0,X.useState)({providers:{}}),[l,u]=(0,X.useState)({providers:{}}),[d,f]=(0,X.useState)(``),[p,m]=(0,X.useState)(),[h,g]=(0,X.useState)(!0),[_,v]=(0,X.useState)(!1),[y,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),[A,j]=(0,X.useState)(()=>new Set),[M,ee]=(0,X.useState)(!1),[P,F]=(0,X.useState)(``),[L,R]=(0,X.useState)(null),[te,z]=(0,X.useState)(()=>new Set),[B,V]=(0,X.useState)(()=>new Map),[H,ne]=(0,X.useState)(!1),[re,ie]=(0,X.useState)(null),[ae,se]=(0,X.useState)(!1),[U,W]=(0,X.useState)(null),ce=(0,X.useCallback)(async e=>{let t=!e?.skipFullPageLoading;t&&g(!0),T(null);try{let e=await Ln(),t=In(e.config);c(t),u(structuredClone(t)),f(e.path),m(e.loadError),k(null),D(!1)}catch(e){T(e instanceof Error?e.message:n.loadError),c({providers:{}}),u({providers:{}})}finally{t&&g(!1)}},[n.loadError]);(0,X.useEffect)(()=>{if(!i){g(!1);return}ce()},[i,ce]);let le=(0,X.useMemo)(()=>JSON.stringify(a)!==JSON.stringify(l),[a,l]),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]),G=le||r.dirty,de=(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]),fe=e=>{j(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},pe=e=>{z(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},me=(0,X.useCallback)(()=>{F(JSON.stringify(a,null,2)),R(null)},[a]);(0,X.useEffect)(()=>{M&&me()},[M,me]);let ge=()=>{try{c(In(JSON.parse(P))),R(null)}catch{R(n.jsonParseError)}},ve=async()=>{x(!0),T(null);try{k(await Rn(a))}catch(e){T(e instanceof Error?e.message:n.validateError)}finally{x(!1)}},ye=async()=>{if(_||r.saving)return;let e=le,i=r.dirty;if(!(!e&&!i)){T(null),D(!1);try{if(e){v(!0);try{await zn(a),u(structuredClone(a)),k(null)}finally{v(!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)}}},be=(0,X.useCallback)(()=>{c(structuredClone(l)),k(null),D(!1),T(null),M&&(F(JSON.stringify(l,null,2)),R(null)),r.discard()},[l,M,r.discard]),xe=async()=>{C(!0),T(null);try{await Bn(),await ce({skipFullPageLoading:!0})}catch(e){T(e instanceof Error?e.message:n.reloadError)}finally{C(!1)}},Se=async(e,t)=>{try{let n=await Vn(t);V(t=>{let r=new Map(t);return r.set(e,n),r})}catch(t){V(n=>{let r=new Map(n);return r.set(e,{type:`error`,error:t instanceof Error?t.message:`Error`}),r})}},Ce=(e=null)=>{ie(e),ne(!0)},we=(e,t)=>{c(n=>rr(n,e,t)),j(t=>new Set(t).add(e))},Te=e=>{window.confirm(n.removeProviderConfirm.replace(`{{id}}`,e))&&(c(t=>nr(t,e)),V(t=>{let n=new Map(t);return n.delete(e),n}))},Ee=(e,t,n)=>{W({providerId:e,model:t,isNew:n}),se(!0)},De=e=>{if(!U)return;let{providerId:t,isNew:n}=U;c(r=>{let i=r.providers[t];if(!i)return r;let a=i.models||[];return n?tr(r,t,{models:[...a,e]}):tr(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:Ue(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)(N,{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)(he,{className:`mt-0.5 size-4 shrink-0`}),(0,Y.jsxs)(`span`,{children:[n.loadFileWarning,`: `,p]})]}):null,d?(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:d})]}):null,(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsxs)(K,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:()=>Ce(null),disabled:h,children:[(0,Y.jsx)(Oe,{className:`mr-1 size-4`}),n.addProvider]}),(0,Y.jsx)(K,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:ve,disabled:h||y,children:y?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(s,{className:`mr-1 size-4 animate-spin`}),n.validating]}):n.validate}),(0,Y.jsx)(K,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:be,disabled:h||_||r.saving||!G,children:n.discard}),(0,Y.jsx)(K,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:()=>void ye(),disabled:h||_||r.saving||!G,children:_||r.saving?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(s,{className:`mr-1 size-4 animate-spin`}),n.saving]}):n.save}),(0,Y.jsx)(K,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[8.5rem] justify-center`,onClick:xe,disabled:h||S,children:S?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(s,{className:`mr-1 size-4 animate-spin`}),n.reloading]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(_e,{className:`mr-1 size-4`}),n.reload]})}),(0,Y.jsx)(K,{type:`button`,variant:`ghost`,className:`text-fg-muted`,onClick:()=>{ee(e=>!e),R(null)},children:M?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(de.providers))}),(0,Y.jsx)(`span`,{className:`text-fg-subtle`,children:`|`}),(0,Y.jsx)(`span`,{className:`text-fg-muted`,children:n.statsModels.replace(`{{count}}`,String(de.models))})]})]}),G?(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)(he,{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)(he,{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)(s,{className:`size-4 animate-spin`}),n.loading]}):M?(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(`textarea`,{className:b(Zn(),`min-h-[320px] resize-y font-mono text-xs leading-relaxed`),value:P,onChange:e=>F(e.target.value),spellCheck:!1}),L?(0,Y.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:L}):null,(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(K,{type:`button`,variant:`secondary`,onClick:me,children:n.jsonReset}),(0,Y.jsx)(K,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:ge,children:n.jsonApply})]})]}):Object.keys(a.providers).length===0?(0,Y.jsx)(sr,{ms:n,openAddProvider:Ce}):(0,Y.jsx)(or,{config:a,setConfig:c,expanded:A,toggleExpand:fe,showPw:te,toggleShowPw:pe,testResults:B,runTestKey:Se,ms:n,removeProv:Te,openModelDialog:Ee,setTestResults:V}),ue?(0,Y.jsx)(`div`,{className:`mt-10 border-t border-edge-subtle pt-8 dark:border-edge`,children:(0,Y.jsx)(qn,{...ue})}):null,(0,Y.jsx)(ar,{open:H,onOpenChange:ne,presetKey:re,onConfirm:we,m:n}),(0,Y.jsx)(ir,{open:ae,onOpenChange:e=>{se(e),e||W(null)},providerId:U?.providerId??null,model:U?.model??null,isNew:U?.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 lr(e){let t=await De(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 ur(e){let t=await De(q(`/api/auth/oauth-async/${encodeURIComponent(e)}/status`));if(!t.ok)throw Error(`OAuth status: ${t.status}`);return(await t.json()).payload}async function dr(e,t){let n=await De(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 fr(e){let t=await De(q(`/api/auth/oauth-async/${encodeURIComponent(e)}/cancel`),{method:`POST`});if(!t.ok)throw Error(`Cancel OAuth failed: ${t.status}`)}async function pr(e){let t=await De(q(`/api/auth/oauth-async/${encodeURIComponent(e)}`),{method:`DELETE`});if(!t.ok)throw Error(`Cleanup session failed: ${t.status}`)}async function mr(e){let t=await De(q(`/api/auth/oauth/${encodeURIComponent(e)}`),{method:`DELETE`});if(!t.ok)throw Error(`Revoke OAuth failed: ${t.status}`)}function hr({providerId:e,language:t}){let n=He[e];if(!n)return null;let r=t===`zh`,i=r&&n.descriptionZh?n.descriptionZh:n.description;return i?(0,Y.jsxs)(P,{children:[(0,Y.jsx)(Qe,{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)(u,{className:`size-3.5`,"aria-hidden":!0})})}),(0,Y.jsx)(w,{children:(0,Y.jsxs)(x,{side:`right`,align:`start`,sideOffset:6,className:b(`w-64 rounded-xl border border-edge bg-surface-panel p-3 shadow-md`,G,`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)(v,{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)(ee,{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)(N,{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)(N,{className:`size-3`,"aria-hidden":!0})]}):null]}):null,(0,Y.jsx)(j,{className:`fill-edge`})]})})]}):null}var gr=[`common`,`specialty`,`enterprise`,`oauth`,`extension`];function _r(e){let t=new Map;for(let e of gr)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 vr(e,t){return e.replace(/\{\{(\w+)\}\}/g,(e,n)=>String(t[n]??``))}function yr(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 br({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)(Be,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):(0,Y.jsx)(Fe,{className:`size-3.5`,"aria-hidden":!0})})]})}function xr({row:e,value:t,rowDirty:n,labels:r,language:i,onChange:a,onReload:o,justSaved:c,availableModels:l}){let[d,f]=(0,X.useState)(!1),[p,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(!1),[v,y]=(0,X.useState)(null),[x,C]=(0,X.useState)(!1),[w,T]=(0,X.useState)(null),[E,D]=(0,X.useState)(!1),k=Me(t),A=k&&!p?``:t,j=e.configured&&!k&&!!t,[M,P]=(0,X.useState)(!1),[F,I]=(0,X.useState)(),[L,R]=(0,X.useState)(),[te,z]=(0,X.useState)(),[B,ne]=(0,X.useState)(),[ae,oe]=(0,X.useState)(),[se,U]=(0,X.useState)(``),[W,le]=(0,X.useState)(!1),[ue,G]=(0,X.useState)(null),[de,fe]=(0,X.useState)(null),pe=e.activeKeySource??`none`,ge=(0,X.useMemo)(()=>Je(e.id,i),[e.id,i]);(0,X.useEffect)(()=>()=>{F&&pr(F).catch(()=>{})},[F]),(0,X.useEffect)(()=>{if(!F||!M)return;let e=window.setInterval(()=>{(async()=>{try{let t=await ur(F);z(t.message),ne(t.authUrl),oe(t.instructions),t.status===`waiting_auth`||t.status===`waiting_code`?R(t.status===`waiting_code`?`waiting_code`:`waiting`):t.status===`completed`?(window.clearInterval(e),P(!1),R(`success`),z(t.message),window.setTimeout(()=>o(),800)):(t.status===`failed`||t.status===`cancelled`)&&(window.clearInterval(e),P(!1),R(`error`),z(t.error||t.message||`OAuth failed`))}catch{}})()},1e3);return()=>window.clearInterval(e)},[F,M,o]);let _e=async()=>{P(!0),R(`waiting`),z(r.oauthStarting),I(void 0),ne(void 0),oe(void 0);try{I((await lr(e.id)).sessionId)}catch(e){R(`error`),z(e instanceof Error?e.message:`OAuth failed`),P(!1)}},ve=async()=>{if(F){try{await fr(F)}catch{}I(void 0),P(!1),R(`idle`),z(void 0)}},be=async()=>{if(!(!F||!se.trim()))try{await dr(F,se.trim()),U(``),z(r.oauthProcessingCode)}catch(e){R(`error`),z(e instanceof Error?e.message:`Failed`)}},xe=()=>{window.confirm(vr(r.revokeConfirm,{name:e.name}))&&(y(null),mr(e.id).then(()=>o()).catch(e=>y(e instanceof Error?e.message:r.revokeFailed)))},Se=async()=>{D(!1),C(!0),T(null);try{await me(e.id),T(r.removeKeySuccess),a(e.id,``),window.setTimeout(()=>o(),600)}catch(e){T(e instanceof Error?e.message:r.removeKeyFailed)}finally{C(!1)}},we=e.configured&&k&&pe!==`env`&&pe!==`extension`&&pe!==`models_json`,Te=async()=>{if(!(!t||k))try{await navigator.clipboard.writeText(t),_(!0),window.setTimeout(()=>_(!1),2e3)}catch{}},Ee=async()=>{let e=t.trim();if(!(!e||Me(e))){le(!0),G(null),fe(null);try{let t=await ie(e);if(t.error){fe(!1),G(`${r.testFailed} ${t.error}`);return}fe(!0),t.type===`env`?G(r.testOkEnv):t.type===`command`?G(r.testOkCommand):G(r.testOkLiteral)}catch(e){fe(!1),G(e instanceof Error?e.message:r.testFailed)}finally{le(!1)}}},De=n?r.metaWillSave:e.configured?k?`${r.metaMasked} · ${r.runtimeLabelPrefix} ${yr(r,pe)}`:`${r.runtimeLabelPrefix} ${yr(r,pe)}`:r.metaNotConfigured,Oe=`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)(Be,{className:`size-4 text-emerald-600 dark:text-emerald-400`}):(0,Y.jsx)(Ze,{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)(hr,{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:De})]}),(0,Y.jsx)(K,{type:`button`,variant:`ghost`,className:`h-9 w-9 shrink-0 p-0`,"aria-expanded":d,"aria-controls":Oe,"aria-label":r.expandRowDetails,onClick:()=>f(e=>!e),children:(0,Y.jsx)(ye,{className:b(`size-4 transition-transform`,d&&`rotate-180`),"aria-hidden":!0})})]}),d?(0,Y.jsxs)(`div`,{id:Oe,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:p||!k?`text`:`password`,className:b(`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`,Ce,`dark:border-edge`),value:A,placeholder:k?r.placeholderOverride:e.configured?r.placeholderKeep:r.placeholderKey,disabled:M,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:b(`rounded p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,H.transition,H.press,H.focusRingPanel),title:g?r.copied:r.copy,"aria-label":g?r.copied:r.copy,onClick:()=>void Te(),children:g?(0,Y.jsx)(Be,{className:`size-4`}):(0,Y.jsx)(Fe,{className:`size-4`})}):null,(0,Y.jsx)(`button`,{type:`button`,className:b(`rounded p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg disabled:opacity-40`,H.transition,H.press,H.focusRingPanel),title:p?r.hide:r.show,"aria-label":p?r.hide:r.show,disabled:k,onClick:()=>h(e=>!e),children:p?(0,Y.jsx)(re,{className:`size-4`}):(0,Y.jsx)(V,{className:`size-4`})})]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2 sm:shrink-0`,children:[(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,className:`gap-1`,disabled:M||W||!t.trim()||Me(t),onClick:()=>void Ee(),children:[W?(0,Y.jsx)(s,{className:`size-4 animate-spin`,"aria-hidden":!0}):null,W?r.testingKey:r.testKey]}),e.supportsOAuth?j?(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,className:`gap-1 text-red-600 dark:text-red-400`,onClick:xe,children:[(0,Y.jsx)(m,{className:`size-4`,"aria-hidden":!0}),r.revoke]}):(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,className:`gap-1`,disabled:M,onClick:()=>void _e(),children:[M?(0,Y.jsx)(s,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(O,{className:`size-4`,"aria-hidden":!0}),r.oauth]}):null,we?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,className:`gap-1 text-red-600 dark:text-red-400`,disabled:x,onClick:()=>D(!0),children:[x?(0,Y.jsx)(s,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(S,{className:`size-4`,"aria-hidden":!0}),r.removeKey]}),(0,Y.jsx)(ze,{open:E,title:r.removeKey,description:vr(r.removeKeyConfirm,{name:e.name}),confirmLabel:r.removeKey,cancelLabel:r.cancelOAuth,destructive:!0,onConfirm:()=>void Se(),onCancel:()=>D(!1)})]}):null]})]}),ue?(0,Y.jsx)(`p`,{className:b(`text-xs`,de===!1?`text-red-600 dark:text-red-400`:`text-fg-muted`),role:`status`,children:ue}):null,ge.length>0?(0,Y.jsx)(`div`,{className:`flex flex-col gap-1`,children:ge.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:[ce(e.kind,r),(0,Y.jsx)(N,{className:`size-3`,"aria-hidden":!0})]},`${e.kind}-${e.href}`))}):null]}),te?(0,Y.jsxs)(`div`,{className:b(`flex gap-2 rounded-md px-3 py-2 text-xs`,L===`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:[L===`error`?(0,Y.jsx)(he,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}):L===`success`?(0,Y.jsx)(Be,{className:`mt-0.5 size-4 shrink-0 text-emerald-600`,"aria-hidden":!0}):(0,Y.jsx)(u,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:te})]}):null,v?(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)(he,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:v})]}):null,w?(0,Y.jsxs)(`div`,{className:b(`flex gap-2 rounded-md px-3 py-2 text-xs`,w===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:[w===r.removeKeySuccess?(0,Y.jsx)(Be,{className:`mt-0.5 size-4 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):(0,Y.jsx)(he,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:w})]}):null,(L===`waiting`||L===`waiting_code`)&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[B?(0,Y.jsxs)(`a`,{href:B,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)(N,{className:`size-4`,"aria-hidden":!0}),r.openAuthPage]}):null,(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,className:`gap-1`,onClick:()=>void ve(),children:[(0,Y.jsx)(ee,{className:`size-4`,"aria-hidden":!0}),r.cancelOAuth]})]}),ae?(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)(u,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:ae})]}):null,L===`waiting_code`?(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,Y.jsx)(`input`,{type:`text`,className:b(`min-w-0 flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,Ce,`dark:border-edge`),value:se,placeholder:r.pasteRedirectUrl,onChange:e=>U(e.target.value),onKeyDown:e=>e.key===`Enter`&&void be()}),(0,Y.jsx)(K,{type:`button`,variant:`primary`,className:`shrink-0`,onClick:()=>void be(),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)(u,{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&&!j?(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:r.oauthHint}):null,c?(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)(Be,{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=l.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,(He[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:(He[e.id]?.envVars??[]).map(e=>(0,Y.jsx)(br,{envVar:e,labels:r},e))})]}):null]}):null]})}function Sr(){let e=I(e=>e.language),t=o(e),n=t.providersSettings,i=!!oe(e=>e.token),[a,s]=(0,X.useState)({}),[c,l]=(0,X.useState)({}),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(null),[m,h]=(0,X.useState)(null),[_,v]=(0,X.useState)(()=>new Set([`common`])),[y,x]=(0,X.useState)(``),[S,C]=(0,X.useState)(!1),[w,T]=(0,X.useState)(()=>new Set),E=(0,X.useRef)(``),D=q(`/api/providers/meta`),O=(0,X.useCallback)(async e=>(await xe(e)).payload?.providers??[],[]),{data:k,error:A,isLoading:j,mutate:M}=R(i),{data:N,error:ee,isLoading:P,mutate:L}=r(i?D:null,O,{revalidateOnFocus:!1}),{data:te,mutate:z}=r(i?Ge:null,()=>F(),{revalidateOnFocus:!1}),B=(0,X.useMemo)(()=>!N||k===void 0?null:Te(N,ve(k.payload?.config),te??[]),[N,k,te]),V=A instanceof Error?A.message:A?String(A):ee instanceof Error?ee.message:ee?String(ee):null,H=!!(i&&B===null&&(j||P)&&!V),ne=(0,X.useMemo)(()=>JSON.stringify(a)!==JSON.stringify(c),[a,c]);(0,X.useEffect)(()=>{if(!ne)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[ne]),(0,X.useEffect)(()=>{if(!(!i||B===null)&&!ne){let e={};for(let t of B)e[t.id]=t.apiKey;s(e),l({...e})}},[i,B,ne]);let re=B??[],ie=(0,X.useMemo)(()=>{let e=re,t=y.trim().toLowerCase();return t&&(e=e.filter(e=>{let n=He[e.id]?.aliases??[];return e.id.toLowerCase().includes(t)||e.name.toLowerCase().includes(t)||n.some(e=>e.toLowerCase().includes(t))})),S&&(e=e.filter(e=>!e.configured)),e},[re,y,S]),ae=(0,X.useMemo)(()=>_r(ie),[ie]);(0,X.useEffect)(()=>{let e=E.current;if(E.current=y,y.trim()){let e=new Set;for(let t of gr)(ae.get(t)??[]).length>0&&e.add(t);v(e);return}e.trim()&&v(new Set([`common`]))},[y,ae]);let se=(0,X.useCallback)(async()=>{if(u)return;let e={};for(let t of Object.keys(a)){let n=a[t]?.trim()??``;!n||Me(n)||(e[t]=n)}if(Object.keys(e).length===0){l({...a}),h(`noChanges`),window.setTimeout(()=>h(null),2500);return}d(!0),p(null),h(null);try{await be(e),T(new Set(Object.keys(e)));let t=await z(F(!0))??te??[],[n,r]=await Promise.all([M(),L()]),i=Array.isArray(r)?r:N??[],a=n??k;if(a?.payload){let e=Te(i,ve(a.payload.config),t),n={};for(let t of e)n[t.id]=t.apiKey;s(n),l({...n})}h(`saved`),window.setTimeout(()=>h(null),2500)}catch(e){p(e instanceof Error?e.message:n.saveError)}finally{d(!1)}},[k,a,N,te,M,L,z,n.saveError,u]),U=(0,X.useCallback)(()=>{s({...c}),p(null),h(null),T(new Set)},[c]),W=e=>{v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},ce=(0,X.useCallback)(()=>{M(),L()},[M,L]),le=!!(y.trim()||S);return i?H?(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})]}):re.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:f??V??n.empty})]}),(0,Y.jsx)(K,{type:`button`,variant:`secondary`,onClick:()=>{M(),L()},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:[m===`saved`?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,m===`noChanges`?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.noChangesSaved}):null,(0,Y.jsx)(K,{type:`button`,variant:`secondary`,disabled:!ne||u,onClick:U,children:n.discard}),(0,Y.jsx)(K,{type:`button`,variant:`primary`,disabled:!ne||u,onClick:()=>void se(),children:u?n.saving:n.save})]})]}),ne?(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:Ue(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)(g,{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)(Re,{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:y,onChange:e=>x(e.target.value),placeholder:n.searchPlaceholder,autoComplete:`off`,className:b(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-10 pr-3 text-sm text-fg placeholder:text-fg-subtle`,Ce,`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:S,onChange:e=>C(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]}),le?(0,Y.jsx)(K,{type:`button`,variant:`ghost`,className:`h-9 w-fit self-start text-fg-muted`,onClick:()=>{x(``),C(!1)},children:n.clearFilters}):null]}),f?(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:f}):null,ie.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)(K,{type:`button`,variant:`secondary`,className:`mt-4`,onClick:()=>{x(``),C(!1)},children:n.clearFilters})]}):(0,Y.jsx)(`div`,{className:`flex flex-col gap-3`,children:gr.map(t=>{let r=ae.get(t)??[];if(r.length===0)return null;let i=_.has(t),o=r.filter(e=>e.configured).length,l=`providers-cat-${t}`;return(0,Y.jsxs)(`section`,{className:`overflow-hidden rounded-2xl bg-surface-base`,children:[(0,Y.jsxs)(`button`,{type:`button`,id:`${l}-trigger`,"aria-expanded":i,"aria-controls":l,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:()=>W(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)(Be,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}),vr(n.configuredCount,{count:String(o)})]}):null,(0,Y.jsx)(ye,{className:b(`size-4 text-fg-subtle transition-transform`,i&&`rotate-180`),"aria-hidden":!0})]})]}),i?(0,Y.jsx)(`div`,{id:l,role:`region`,"aria-labelledby":`${l}-trigger`,className:`divide-y divide-edge-subtle`,children:r.map(t=>(0,Y.jsx)(`div`,{id:`provider-row-${t.id}`,children:(0,Y.jsx)(xr,{row:t,value:a[t.id]??``,rowDirty:(a[t.id]??``)!==(c[t.id]??``),labels:n,language:e,onChange:(e,t)=>s(n=>({...n,[e]:t})),onReload:ce,justSaved:w.has(t.id),availableModels:te??[]})},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)(Ze,{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 Cr=[{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 wr(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 Tr(){let e=I(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)(()=>{A()&&l&&u()},[l,u]),!A()||!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)(Ct,{children:[(0,Y.jsxs)(`div`,{className:`mb-4 flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)(Ae,{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:Cr.map(({key:r,pane:o})=>{let s=wr(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)(N,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0})]})]})]},r):null})})]}):null]})}function Er(){return{enabled:!1,provider:`alibaba`,alibaba:{model:`paraformer-v2`},openai:{model:`whisper-1`},fallback:{enabled:!0,order:[`alibaba`,`openai`]}}}function Dr(){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 Or(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function kr(e){let t=Er();if(!Or(e))return t;let n=e.provider===`openai`?`openai`:`alibaba`,r=Or(e.alibaba)?{...t.alibaba,...e.alibaba}:t.alibaba,i=Or(e.openai)?{...t.openai,...e.openai}:t.openai,a=t.fallback??{enabled:!0,order:[`alibaba`,`openai`]};if(Or(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 Ar(e){return typeof e==`string`&&e.trim().length>0?e.trim():`openai`}function jr(e){let t=Dr();if(!Or(e))return t;let n=Ar(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:Or(e.alibaba)?{...t.alibaba,...e.alibaba}:t.alibaba,openai:Or(e.openai)?{...t.openai,...e.openai}:t.openai,edge:Or(e.edge)?{...t.edge,...e.edge}:t.edge,minimax:Or(e.minimax)?{...t.minimax,...e.minimax}:t.minimax,"tts-local-cli":Or(i)?{...t[`tts-local-cli`],...i}:t[`tts-local-cli`]}}function Mr(e){let t=Or(e)?e:{};return{stt:kr(t.stt),tts:jr(t.tts)}}async function Nr(e){await xe(q(`/api/config`),{method:`PATCH`,body:JSON.stringify({stt:e.stt,tts:e.tts})}),qe()}async function Pr(){let e=await xe(q(`/api/voice/models`));if(!e.payload?.models)throw Error(`Missing voice models payload`);return e.payload.models}function Fr(){return b(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,Ce,`dark:border-edge`)}function Ir(){return b(D,_)}var Lr=[{id:`paraformer-v2`,name:`Paraformer v2`},{id:`paraformer-v1`,name:`Paraformer v1`}],Rr=[{id:`whisper-1`,name:`Whisper-1`}],zr=[{id:`tts-1`,name:`TTS-1`},{id:`tts-1-hd`,name:`TTS-1 HD`}],Br=[{id:`alloy`,name:`Alloy`},{id:`echo`,name:`Echo`}],Vr=[{id:`qwen-tts`,name:`Qwen TTS`},{id:`qwen3-tts-flash`,name:`Qwen3 TTS Flash`}],Hr=[{id:`Cherry`,name:`Cherry`},{id:`longxiaochun`,name:`Long Xiao Chun`}],Ur=[{id:`en-US-MichelleNeural`,name:`Michelle (US English)`},{id:`zh-CN-XiaoxiaoNeural`,name:`Xiaoxiao (Chinese)`}],Wr=[{id:`speech-2.8-hd`,name:`Speech 2.8 HD (Recommended)`},{id:`speech-2.8-turbo`,name:`Speech 2.8 Turbo (Fast)`}],Gr=[{id:`male-qn-qingse`,name:`Male Qingse (青涩男声)`},{id:`female-shaonv`,name:`Female Shaonv (少女音)`}];function Kr(){let e=I(e=>e.language),t=o(e),n=t.voiceSettings,i=!!oe(e=>e.token),[a,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(null),[d,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}=R(i),{data:C,error:w,isLoading:T,mutate:E}=r(i?q(`/api/voice/models`):null,Pr,{revalidateOnFocus:!1}),D=(0,X.useMemo)(()=>y?.payload?.config===void 0?null:Mr(y.payload.config),[y]),O=(0,X.useMemo)(()=>!a||!l?!1:JSON.stringify(a)!==JSON.stringify(l),[a,l]);(0,X.useEffect)(()=>{if(!i){c(null),u(null),f(null);return}D===null||C===void 0||O||(c(structuredClone(D)),u(structuredClone(D)),f(C),v(!1))},[i,D,C,O]);let k=!!(i&&(D===null||C===void 0)&&(x||T)),A=b instanceof Error?b.message:b?String(b):w instanceof Error?w.message:w?String(w):null,j=(0,X.useCallback)(e=>{c(t=>t?{...t,stt:{...t.stt,...e}}:null)},[]),M=(0,X.useCallback)(e=>{c(t=>t?{...t,stt:{...t.stt,alibaba:{...t.stt.alibaba,...e}}}:null)},[]),ee=(0,X.useCallback)(e=>{c(t=>t?{...t,stt:{...t.stt,openai:{...t.stt.openai,...e}}}:null)},[]),P=(0,X.useCallback)(e=>{c(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=>{c(t=>t?{...t,tts:{...t.tts,...e}}:null)},[]),L=(0,X.useCallback)(e=>{c(t=>t?{...t,tts:{...t.tts,alibaba:{...t.tts.alibaba,...e}}}:null)},[]),te=(0,X.useCallback)(e=>{c(t=>t?{...t,tts:{...t.tts,openai:{...t.tts.openai,...e}}}:null)},[]),z=(0,X.useCallback)(e=>{c(t=>t?{...t,tts:{...t.tts,edge:{...t.tts.edge,...e}}}:null)},[]),B=(0,X.useCallback)(e=>{c(t=>t?{...t,tts:{...t.tts,minimax:{...t.tts.minimax,...e}}}:null)},[]),V=(0,X.useCallback)(e=>{c(t=>t?{...t,tts:{...t.tts,"tts-local-cli":{...t.tts[`tts-local-cli`],...e}}}:null)},[]),H=(0,X.useCallback)(async()=>{if(!(!a||p)){m(!0),g(null),v(!1);try{await Nr(a);let e=structuredClone(a);u(e),c(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]),ne=(0,X.useCallback)(()=>{l&&(c(structuredClone(l)),g(null),v(!1))},[l]);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)(s,{className:`size-4 animate-spin`}),n.loading]})});if(!a||d===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??A??n.loadError}),(0,Y.jsx)(K,{type:`button`,variant:`secondary`,onClick:()=>{S(),E()},children:n.retry})]});let re=a.stt,ie=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:Ue(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)(N,{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)(K,{type:`button`,variant:`secondary`,disabled:!O||p,onClick:ne,children:n.discard}),(0,Y.jsx)(K,{type:`button`,variant:`primary`,disabled:!O||p,onClick:()=>void H(),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)(qr,{v:n,stt:re,models:d,updateStt:j,updateSttAlibaba:M,updateSttOpenai:ee,updateSttFallback:P}),(0,Y.jsx)(Jr,{v:n,tts:ie,models:d,updateTts:F,updateTtsAlibaba:L,updateTtsOpenai:te,updateTtsEdge:z,updateTtsMinimax:B,updateTtsLocalCli:V})]}),(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 qr({v:e,stt:t,models:n,updateStt:r,updateSttAlibaba:i,updateSttOpenai:a,updateSttFallback:o}){let s=n?.stt?.alibaba?.length?n.stt.alibaba:Lr,c=n?.stt?.openai?.length?n.stt.openai:Rr;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)(d,{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:Ir(),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:b(Fr(),`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:Ir(),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:b(Fr(),`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:Ir(),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 Jr({v:e,tts:t,models:n,updateTts:r,updateTtsAlibaba:i,updateTtsOpenai:a,updateTtsEdge:o,updateTtsMinimax:s,updateTtsLocalCli:c}){let u=t=>t===`off`?e.tts.triggerDescOff:t===`always`?e.tts.triggerDescAlways:t===`inbound`?e.tts.triggerDescInbound:t===`tagged`?e.tts.triggerDescTagged:``,d=n?.tts?.openai?.length?n.tts.openai:zr,f=n?.ttsVoices?.openai?.length?n.ttsVoices.openai:Br,p=n?.tts?.alibaba?.length?n.tts.alibaba:Vr,m=n?.ttsVoices?.alibaba?.length?n.ttsVoices.alibaba:Hr,h=n?.ttsVoices?.edge?.length?n.ttsVoices.edge:Ur,g=n?.tts?.minimax?.length?n.tts.minimax:Wr,_=n?.ttsVoices?.minimax?.length?n.ttsVoices.minimax:Gr;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)(l,{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:Ir(),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:u(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:Ir(),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:b(Fr(),`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:Ir(),value:t.openai?.model??``,onChange:e=>a({model:e.target.value}),children:d.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:Ir(),value:t.openai?.voice??``,onChange:e=>a({voice:e.target.value}),children:f.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:b(Fr(),`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:Ir(),value:t.alibaba?.model??``,onChange:e=>i({model:e.target.value}),children:p.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:Ir(),value:t.alibaba?.voice??``,onChange:e=>i({voice:e.target.value}),children:m.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:b(Fr(),`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:Ir(),value:t.minimax?.model??``,onChange:e=>s({model:e.target.value}),children:g.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:Ir(),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:Ir(),value:t.edge?.voice??``,onChange:e=>o({voice:e.target.value}),children:h.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:b(Fr(),`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:b(Fr(),`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:Ir(),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:Fr(),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 Yr(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 Xr(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 xe(q(`/api/config`),{method:`PATCH`,body:JSON.stringify({tools:{web:{region:t,search:n}}})}),qe()}function Zr({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 Qr(){return b(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,Ce,`dark:border-edge`)}function $r(){return b(D,_)}var ei=[`brave`,`tavily`,`bing`,`searxng`];function ti(){return{type:`brave`,apiKey:``,url:``,disabled:!1}}function ni(){let e=I(e=>e.language),t=o(e),n=t.webSearchSettings,r=t.logs,i=!!oe(e=>e.token),[a,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(null),[d,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}=R(i),S=(0,X.useMemo)(()=>v?.payload?.config===void 0?null:Yr(v.payload.config),[v]);(0,X.useEffect)(()=>{if(!i){c(null),u(null),_.current=!1;return}S!==null&&(_.current||(c(S),u(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||!l?!1:JSON.stringify(a)!==JSON.stringify(l),[a,l]),E=(0,X.useCallback)(e=>{_.current=!0,c(t=>t?{...t,...e}:null)},[]),D=(0,X.useCallback)(async()=>{if(!(!a||d)){f(!0),m(null),g(!1);try{await Xr(a);let e=structuredClone(a);u(e),c(e),_.current=!1,g(!0),window.setTimeout(()=>g(!1),2500)}catch(e){m(e instanceof Error?e.message:n.saveError)}finally{f(!1)}}},[a,d,n.saveError]),O=(0,X.useCallback)(()=>{l&&(_.current=!1,c(structuredClone(l)),m(null),g(!1))},[l]);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)(s,{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:Ue(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)(N,{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)(K,{type:`button`,variant:`secondary`,disabled:!T||d,onClick:O,children:n.discard}),(0,Y.jsx)(K,{type:`button`,variant:`primary`,disabled:!T||d,onClick:()=>void D(),children:d?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)(Ct,{children:[(0,Y.jsx)(wt,{icon:Re,title:n.sectionRegion,subtitle:n.sectionRegionHint}),(0,Y.jsx)(`div`,{className:`flex max-w-md flex-col gap-4`,children:(0,Y.jsx)(Zr,{label:n.regionLabel,description:n.regionDesc,children:(0,Y.jsxs)(`select`,{className:$r(),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)(Ct,{children:[(0,Y.jsx)(wt,{icon:Re,title:n.sectionSearch,subtitle:n.sectionSearchHint}),(0,Y.jsxs)(`div`,{className:`flex max-w-xl flex-col gap-6`,children:[(0,Y.jsx)(Zr,{label:n.maxResultsLabel,description:n.maxResultsDesc,children:(0,Y.jsx)(`input`,{type:`number`,min:1,max:50,className:Qr(),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)(ri,{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)(K,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5 text-sm`,onClick:()=>E({providers:[...a.providers,ti()]}),children:[(0,Y.jsx)(Oe,{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)(K,{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 ri({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:b($r(),`min-w-[8rem]`),value:e.type,onChange:t=>n({...e,type:t.target.value,url:t.target.value===`searxng`?e.url:``}),children:ei.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)(K,{type:`button`,variant:`ghost`,className:`h-8 px-2 text-fg-muted`,onClick:r,children:(0,Y.jsx)(S,{className:`size-4`})})]})]}),e.type===`searxng`?(0,Y.jsx)(Zr,{label:t.urlLabel,description:t.urlDesc,children:(0,Y.jsx)(`input`,{type:`url`,className:Qr(),value:e.url,placeholder:`http://localhost:8080`,onChange:t=>n({...e,url:t.target.value})})}):null,(0,Y.jsx)(Zr,{label:t.apiKeyLabel,description:t.apiKeyDesc,children:(0,Y.jsx)(`input`,{type:`password`,autoComplete:`off`,className:Qr(),value:Me(e.apiKey)?``:e.apiKey,placeholder:Me(e.apiKey)?t.keyPlaceholderMasked:t.keyPlaceholder,onChange:t=>n({...e,apiKey:t.target.value})})})]})}var ii=[`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 ai(){let{section:e}=a(),t=I(e=>e.language),n=o(t);if(e===`agent`||e===`agents`)return(0,Y.jsx)(f,{to:`/agents`,replace:!0});if(!e||!ii.includes(e))return(0,Y.jsx)(f,{to:`/settings/appearance`,replace:!0});let r=e,i=n.settingsSections[r];return r===`appearance`?(0,Y.jsx)(Rt,{}):r===`system`?(0,Y.jsx)(Tr,{}):r===`agent-chat`?(0,Y.jsx)(gt,{}):r===`agent-workspace`?(0,Y.jsx)(_t,{}):r===`agent-browser`?(0,Y.jsx)(xt,{}):r===`agent-runtime`?(0,Y.jsx)(yt,{}):r===`agent-tools`?(0,Y.jsx)(st,{}):r===`agent-system-prompt`?(0,Y.jsx)(pt,{}):r===`providers`?(0,Y.jsx)(Sr,{}):r===`models`?(0,Y.jsx)(cr,{}):r===`image-models`?(0,Y.jsx)(Nn,{}):r===`voice`?(0,Y.jsx)(Kr,{}):r===`gateway`?(0,Y.jsx)(ln,{}):r===`heartbeat`?(0,Y.jsx)(bn,{}):r===`search`?(0,Y.jsx)(ni,{}):r===`dreams`?(0,Y.jsx)(nn,{}):(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{ai as SettingsPage};
|
|
2
|
-
//# sourceMappingURL=settings-page-
|
|
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}from"./vendor-swr-B5fPo7KK.js";import{$n as i,Ai as a,An as o,Ar as s,At as c,Bn as l,Br as u,Cr as d,Di as f,Dn as p,Dr as m,Dt as h,Ei as g,En as _,Ft as v,Hr as y,In as b,It as x,Kn as S,Ln as C,Lt as w,Mt as T,Nt as E,On as D,Or as O,Ot as k,Pn as A,Pt as j,Qn as M,Qr as N,Rn as ee,Rt as P,S as F,Sn as I,Sr as L,St as R,Ti as te,Tn as z,Vr as B,Xr as V,Y as H,Yn as ne,Zr as re,_ as ie,_i as ae,_n as oe,_r as se,a as U,ar as W,b as ce,bn as le,br as ue,c as G,cn as de,dn as fe,dr as pe,f as me,fi as he,fn as ge,fr as _e,g as ve,gi as ye,h as be,hn as xe,jn as K,jt as Se,kn as Ce,kr as we,m as Te,mi as Ee,mn as De,mr as Oe,ni as ke,nr as Ae,o as je,p as Me,pi as Ne,pn as Pe,ri as Fe,rr as Ie,s as Le,sr as Re,t as ze,ui as Be,un as q,ur as Ve,v as He,vn as Ue,wn as We,x as Ge,xn as Ke,xt as qe,y as Je,yi as Ye,zn as Xe,zr as Ze,zt as Qe}from"./index-DZLKmP08.js";import{i as $e,n as et,r as tt,t as nt}from"./use-image-provider-credentials-131rA-SV.js";import{a as rt,b as it,u as at}from"./cron-dreaming-jobs-DjK4YEV9.js";import{_ as ot,a as st,b as J,c as ct,d as lt,f as ut,g as dt,h as ft,i as pt,l as mt,m as ht,n as gt,o as _t,p as vt,r as yt,s as bt,t as xt,u as St,v as Ct,y as wt}from"./agents-Dk8idifM.js";import{t as Tt}from"./browser-DNXWYwzc.js";import{a as Et,i as Dt,n as Ot,o as kt,r as At,t as jt}from"./heartbeat-config-api-D4vLbsOG.js";var Y=n();function Mt(){return b(`rounded-xl border border-edge-subtle bg-surface-base px-4 py-1 sm:px-5`)}var Nt={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 Pt({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 Ft({scheme:e}){let{light:t,dark:n}=Nt[e];return(0,Y.jsxs)(`div`,{className:`flex h-11 w-full overflow-hidden rounded-md border border-edge-subtle`,children:[(0,Y.jsx)(Pt,{...t}),(0,Y.jsx)(`div`,{className:`w-px shrink-0 bg-black/12 dark:bg-white/12`,"aria-hidden":!0}),(0,Y.jsx)(Pt,{...n})]})}var It=[{value:`default`,labelKey:`colorSchemeDefault`},{value:`emerald`,labelKey:`colorSchemeLightGreen`},{value:`mono`,labelKey:`colorSchemeModernMono`}];function Lt(){let e=o(I(e=>e.language)).appearanceSettings,t=Ke(e=>e.colorScheme),n=Ke(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:It.map(({value:r,labelKey:i})=>{let a=t===r;return(0,Y.jsxs)(`button`,{type:`button`,"aria-pressed":a,onClick:()=>n(r),className:b(`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)(Ft,{scheme:r}),(0,Y.jsx)(`span`,{className:b(`text-xs font-medium leading-none`,a?`text-accent-fg`:`text-fg-muted`),children:e[i]})]},r)})})]})}function Rt(){let e=o(I(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:Mt(),"aria-labelledby":`pref-language-heading`,children:[(0,Y.jsx)(`h2`,{id:`pref-language-heading`,className:`sr-only`,children:e.languageTitle}),(0,Y.jsx)(le,{variant:`page`,sections:[`language`]})]}),(0,Y.jsxs)(`section`,{className:Mt(),"aria-labelledby":`pref-appearance-heading`,children:[(0,Y.jsx)(`h2`,{id:`pref-appearance-heading`,className:`sr-only`,children:e.themeTitle}),(0,Y.jsx)(le,{variant:`page`,sections:[`theme`,`font`]}),(0,Y.jsx)(Lt,{})]})]})}var X=e(t(),1);function zt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var Bt={enabled:!0,cron:`0 */6 * * *`,lookbackDays:1,limit:50,dedupeSimilarity:.85},Vt={enabled:!0,cron:`0 3 * * *`,minScore:.8,minRecallCount:3,limit:10,recencyHalfLifeDays:14,maxAgeDays:30},Ht={enabled:!0,cron:`0 5 * * 0`,lookbackDays:7,limit:20,minPatternStrength:.6},Ut={enabled:!1,frequency:`0 3 * * *`,timezone:``,deepEnabled:!0,minScore:.8,minRecallCount:3,limit:10,light:Bt,deep:Vt,rem:Ht};function Wt(e,t){return Number.isFinite(e)?Math.max(0,Math.min(1,e)):t}function Gt(e,t){let n=typeof e==`string`?Number(e):e;return Number.isFinite(n)?Math.max(0,Math.floor(n)):t}function Kt(e,t){let n=typeof e==`string`?Number(e):e;return Number.isFinite(n)?n:t}function qt(e){let t=zt(e)?e:{},n=zt(t.agents)?t.agents:{},r=zt(n.defaults)?n.defaults:{},i=zt(r.memory)?r.memory:{},a=zt(i.dreaming)?i.dreaming:{},o=zt(a.phases)?a.phases:{},s=zt(o.light)?o.light:{},c=zt(o.deep)?o.deep:{},l=zt(o.rem)?o.rem:{};return{enabled:a.enabled===!0,frequency:typeof a.frequency==`string`&&a.frequency.trim()?a.frequency.trim():Ut.frequency,timezone:typeof a.timezone==`string`?a.timezone:``,deepEnabled:c.enabled!==!1,minScore:Wt(typeof c.minScore==`number`?c.minScore:Number(c.minScore),Ut.minScore),minRecallCount:Math.max(1,Gt(c.minRecallCount,Ut.minRecallCount)),limit:Gt(c.limit,Ut.limit),light:{enabled:s.enabled!==!1,cron:typeof s.cron==`string`&&s.cron.trim()?s.cron.trim():Bt.cron,lookbackDays:Math.max(1,Gt(s.lookbackDays,Bt.lookbackDays)),limit:Gt(s.limit,Bt.limit),dedupeSimilarity:Wt(Kt(s.dedupeSimilarity,Bt.dedupeSimilarity),Bt.dedupeSimilarity)},deep:{enabled:c.enabled!==!1,cron:typeof c.cron==`string`&&c.cron.trim()?c.cron.trim():Vt.cron,minScore:Wt(Kt(c.minScore,Vt.minScore),Vt.minScore),minRecallCount:Math.max(1,Gt(c.minRecallCount,Vt.minRecallCount)),limit:Gt(c.limit,Vt.limit),recencyHalfLifeDays:Math.max(1,Kt(c.recencyHalfLifeDays,Vt.recencyHalfLifeDays)),maxAgeDays:Math.max(1,Kt(c.maxAgeDays,Vt.maxAgeDays))},rem:{enabled:l.enabled!==!1,cron:typeof l.cron==`string`&&l.cron.trim()?l.cron.trim():Ht.cron,lookbackDays:Math.max(1,Gt(l.lookbackDays,Ht.lookbackDays)),limit:Gt(l.limit,Ht.limit),minPatternStrength:Wt(Kt(l.minPatternStrength,Ht.minPatternStrength),Ht.minPatternStrength)}}}async function Jt(e){let t=e.frequency.trim(),n=e.timezone.trim();await xe(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:Wt(e.light.dedupeSimilarity,Bt.dedupeSimilarity)},deep:{enabled:!!e.deep.enabled,cron:e.deep.cron.trim()||null,minScore:Wt(e.deep.minScore,Vt.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:Wt(e.rem.minPatternStrength,Ht.minPatternStrength)}}}}}}})}),qe()}function Z(){return`text-xs font-medium text-fg-muted`}function Q(){return`text-sm font-medium text-fg`}function Yt(e){return e?e.replace(`T`,` `).replace(`Z`,``):`—`}function Xt(e){return e===void 0||!Number.isFinite(e)||e<0?`—`:e<1e3?`${Math.round(e)} ms`:`${(e/1e3).toFixed(2)} s`}function Zt({label:e,children:t,className:n}){return(0,Y.jsxs)(`div`,{className:b(`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:b(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:b(`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 $t({label:e,lastRun:t,t:n}){return(0,Y.jsx)(Zt,{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 en({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:b(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:Xt(t.durationMs)})]}),(0,Y.jsxs)(`div`,{className:b(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 tn(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 nn(){let e=o(I(e=>e.language)).dreamingSettings,t=!!oe(e=>e.token),{data:n}=R(t),[i,a]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(null),[v,y]=(0,X.useState)(`deep`),[x,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),[N,ee]=(0,X.useState)(!1),[P,F]=(0,X.useState)(null),[z,B]=(0,X.useState)(null),[V,H]=(0,X.useState)(!1),[re,ie]=(0,X.useState)(null),[ae,U]=(0,X.useState)(null),{data:W,error:ce,isLoading:le,mutate:ue}=r(t?ut():null,ft,{revalidateOnFocus:!1}),G=(0,X.useMemo)(()=>W?tn(W.lock,e):null,[W,e]),de=(0,X.useMemo)(()=>{let e=[];return ce&&e.push(ce instanceof Error?ce.message:String(ce)),c&&e.push(c),g&&e.push(g),P&&e.push(P),re&&e.push(re),A&&e.push(A),e},[ce,c,g,P,re,A]),fe=(0,X.useMemo)(()=>{let t=[];return O&&t.push(e.configSaved),m&&t.push(e.runQueued),u&&t.push(e.actionOk),t},[O,m,u,e]),pe=(0,X.useCallback)(async()=>{d(!1),l(null),h(!1),_(null),k(!1),j(null),F(null),await ue()},[ue]),me=(0,X.useCallback)(async()=>{ee(!0),F(null);try{B((await ht(20)).items??[])}catch(e){F(e instanceof Error?e.message:String(e))}finally{ee(!1)}},[]),he=(0,X.useCallback)(async()=>{H(!0),ie(null);try{U(await vt(50))}catch(e){ie(e instanceof Error?e.message:String(e))}finally{H(!1)}},[]),ge=(0,X.useCallback)(async(e=`deep`)=>{p(!0),h(!1),_(null);try{await ot(e),h(!0),await ue()}catch(e){_(e instanceof Error?e.message:String(e))}finally{p(!1)}},[ue]),ve=(0,X.useCallback)(async e=>{a(e),l(null),d(!1);try{await dt(e),d(!0),await ue()}catch(e){l(e instanceof Error?e.message:String(e))}finally{a(null)}},[ue]),ye=!t||le||!!i,be=(0,X.useMemo)(()=>{let e=n?.payload?.config;return qt(e??{})},[n]);(0,X.useEffect)(()=>{if(t){if(!w){T(be),C(be);return}JSON.stringify(be)!==JSON.stringify(w)&&(T(be),C(be))}},[w,be,t]);let xe=(0,X.useMemo)(()=>!x||!w?!1:JSON.stringify(x)!==JSON.stringify(w),[x,w]),Se=(0,X.useCallback)(async()=>{if(x){D(!0),k(!1),j(null);try{await Jt(x),T(x),k(!0),await ue()}catch(e){j(e instanceof Error?e.message:String(e))}finally{D(!1)}}},[x,ue]);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:[be.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:v,onChange:e=>y(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)(K,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||f,onClick:()=>void ge(v),title:e.runNowHint,children:[f?(0,Y.jsx)(s,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(se,{className:`mr-2 size-4`,"aria-hidden":!0}),e.runNow]})]}):null,(0,Y.jsxs)(K,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t,onClick:()=>void pe(),children:[(0,Y.jsx)(_e,{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)(Ct,{className:`min-w-0`,children:[(0,Y.jsx)(wt,{icon:Ie,title:e.configTitle,subtitle:e.configHint,trailing:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(K,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||!x||E||!xe,onClick:()=>void Se(),children:[E?(0,Y.jsx)(s,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,e.saveConfig]}),(0,Y.jsx)(K,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||!x||E||!xe,onClick:()=>{k(!1),j(null),C(w)},children:e.resetConfig})]})}),x?(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:x.enabled,onChange:e=>C({...x,enabled:e.target.checked})}),(0,Y.jsx)(`span`,{children:x.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:x.frequency,onChange:e=>C({...x,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:x.timezone,onChange:e=>C({...x,timezone:e.target.value}),placeholder:`Asia/Shanghai`})]})]}),(0,Y.jsxs)(Zt,{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:x.light.enabled,onChange:e=>C({...x,light:{...x.light,enabled:e.target.checked}})}),(0,Y.jsx)(`span`,{children:x.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:x.light.cron,onChange:e=>C({...x,light:{...x.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:x.light.lookbackDays,onChange:e=>C({...x,light:{...x.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:x.light.limit,onChange:e=>C({...x,light:{...x.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:x.light.dedupeSimilarity,onChange:e=>C({...x,light:{...x.light,dedupeSimilarity:Number(e.target.value)}})})]})]})]}),(0,Y.jsxs)(Zt,{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:x.deep.enabled,onChange:e=>C({...x,deep:{...x.deep,enabled:e.target.checked}})}),(0,Y.jsx)(`span`,{children:x.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:x.deep.cron,onChange:e=>C({...x,deep:{...x.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:x.deep.minScore,onChange:e=>C({...x,deep:{...x.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:x.deep.minRecallCount,onChange:e=>C({...x,deep:{...x.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:x.deep.limit,onChange:e=>C({...x,deep:{...x.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:x.deep.recencyHalfLifeDays,onChange:e=>C({...x,deep:{...x.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:x.deep.maxAgeDays,onChange:e=>C({...x,deep:{...x.deep,maxAgeDays:Number(e.target.value)}})})]})]})]}),(0,Y.jsxs)(Zt,{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:x.rem.enabled,onChange:e=>C({...x,rem:{...x.rem,enabled:e.target.checked}})}),(0,Y.jsx)(`span`,{children:x.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:x.rem.cron,onChange:e=>C({...x,rem:{...x.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:x.rem.lookbackDays,onChange:e=>C({...x,rem:{...x.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:x.rem.limit,onChange:e=>C({...x,rem:{...x.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:x.rem.minPatternStrength,onChange:e=>C({...x,rem:{...x.rem,minPatternStrength:Number(e.target.value)}})})]})]})]})]}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.configLoading})]}),(0,Y.jsxs)(Ct,{className:`min-w-0`,children:[(0,Y.jsx)(wt,{icon:te,title:e.runtimeTitle,subtitle:e.runtimeHint,trailing:le?(0,Y.jsx)(s,{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)(Zt,{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:W?W.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:b(Q(),G?.className),children:G?G.text:`—`})]}),(0,Y.jsxs)(`div`,{className:b(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:W?W.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:W?W.config.timezone:`—`})]})]})}),(0,Y.jsx)(Zt,{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:W?String(W.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:W?String(W.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:W?Yt(W.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:W?Yt(W.store.lastPromotedAt):`—`})]})]})}),W?.config?.phases?(0,Y.jsx)(Zt,{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)(ne,{className:`size-4 text-amber-500`}),label:`Light`,enabled:W.config.phases.light.enabled,cron:W.config.phases.light.cron,details:`lookback=${W.config.phases.light.lookbackDays}d, limit=${W.config.phases.light.limit}, dedupe=${W.config.phases.light.dedupeSimilarity}`,t:e}),(0,Y.jsx)(Qt,{icon:(0,Y.jsx)(L,{className:`size-4 text-indigo-500`}),label:`Deep`,enabled:W.config.phases.deep.enabled,cron:W.config.phases.deep.cron,details:`minScore=${W.config.phases.deep.minScore}, recalls≥${W.config.phases.deep.minRecallCount}, limit=${W.config.phases.deep.limit}, halfLife=${W.config.phases.deep.recencyHalfLifeDays}d`,t:e}),(0,Y.jsx)(Qt,{icon:(0,Y.jsx)(M,{className:`size-4 text-purple-500`}),label:`REM`,enabled:W.config.phases.rem.enabled,cron:W.config.phases.rem.cron,details:`lookback=${W.config.phases.rem.lookbackDays}d, limit=${W.config.phases.rem.limit}, strength≥${W.config.phases.rem.minPatternStrength}`,t:e})]})}):null,(0,Y.jsxs)(Zt,{label:e.subsectionLastRun,children:[(0,Y.jsx)(`p`,{className:`mb-2 text-xs text-fg-muted`,children:e.lastRunBlockHint}),W?.lastRun?.exists?(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[W.lastRun.parseError?(0,Y.jsxs)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:[e.lastRunParseError,`: `,W.lastRun.parseError]}):null,W.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)(en,{t:e,r:W.lastRun.record})}):null,W.lastRun.raw!==void 0&&W.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(W.lastRun.raw,null,2)})]}):null]}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.lastRunEmpty})]}),(0,Y.jsx)($t,{label:e.subsectionLightLastRun,lastRun:W?.lightLastRun,t:e}),(0,Y.jsx)($t,{label:e.subsectionRemLastRun,lastRun:W?.remLastRun,t:e})]})]})]}),(0,Y.jsxs)(Ct,{children:[(0,Y.jsx)(wt,{icon:Ve,title:e.previewTitle,subtitle:e.previewHint,trailing:(0,Y.jsxs)(K,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||N,onClick:()=>void me(),children:[N?(0,Y.jsx)(s,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,e.previewLoad]})}),z?z.length>0?(0,Y.jsx)(`div`,{className:`space-y-2`,children:z.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)(Ct,{children:[(0,Y.jsx)(wt,{icon:te,title:e.eventsTitle,subtitle:e.eventsHint,trailing:(0,Y.jsxs)(K,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||V,onClick:()=>void he(),children:[V?(0,Y.jsx)(s,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,e.eventsLoad]})}),ae?ae.length>0?(0,Y.jsx)(`div`,{className:`space-y-1.5`,children:ae.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:b(`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:Xt(e.durationMs)}),(0,Y.jsx)(`span`,{className:`ml-auto text-fg-subtle`,children:Yt(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)(Ct,{className:`max-w-2xl`,children:[(0,Y.jsx)(wt,{icon:Xe,title:e.maintenanceTitle,subtitle:e.maintenanceHint}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,Y.jsxs)(K,{variant:`secondary`,disabled:ye,onClick:()=>{confirm(e.confirmResetStore)&&ve(`reset_store`)},children:[i===`reset_store`?(0,Y.jsx)(s,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(S,{className:`mr-2 size-4`,"aria-hidden":!0}),e.resetStore]}),(0,Y.jsxs)(K,{variant:`secondary`,disabled:ye,onClick:()=>{confirm(e.confirmClearLock)&&ve(`clear_lock`)},children:[i===`clear_lock`?(0,Y.jsx)(s,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(we,{className:`mr-2 size-4`,"aria-hidden":!0}),e.clearLock]})]})]})]})}var rn=e(Tt(),1);function an(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function on(e){let t=an(e)?e:{},n=an(t.gateway)?t.gateway:{},r=an(n.auth)?n.auth:{},i=r.mode===`none`||r.mode===`token`?r.mode:`token`,a=(an(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 sn(e){let t=e.auth.token.trim().length>0?{mode:e.auth.mode,token:e.auth.token}:{mode:e.auth.mode};await xe(q(`/api/config`),{method:`PATCH`,body:JSON.stringify({gateway:{auth:t},update:{channel:e.updateChannel}})}),qe()}function cn(){return b(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,Ce,`dark:border-edge`)}function ln(){let e=I(e=>e.language),t=o(e),n=t.gatewaySettings,r=oe(e=>e.token),i=oe(e=>e.tokenExpired),a=oe(e=>e.openTokenDialog),c=!!r,[l,u]=(0,X.useState)(null),[d,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}=R(c),O=(0,X.useMemo)(()=>w?.payload?.config===void 0?null:structuredClone(on(w.payload.config)),[w]);(0,X.useEffect)(()=>{if(!c){u(null),f(null),C.current=!1;return}O!==null&&(C.current||(u(O),f(structuredClone(O)),v(!1)))},[c,O]);let k=!!(c&&E&&w===void 0&&!T),A=T instanceof Error?T.message:T?String(T):null,j=(0,X.useMemo)(()=>!l||!d?!1:JSON.stringify(l)!==JSON.stringify(d),[l,d]),M=(0,X.useCallback)(e=>{C.current=!0,u(t=>t?{...t,auth:{...t.auth,...e}}:null)},[]),ee=(0,X.useCallback)(e=>{C.current=!0,u(t=>t?{...t,updateChannel:e}:null)},[]),P=(0,X.useCallback)(async()=>{if(!(!l||p)){m(!0),g(null),v(!1);try{await sn(l),C.current=!1,f(structuredClone(l)),v(!0),window.setTimeout(()=>v(!1),2500)}catch(e){g(e instanceof Error?e.message:n.saveError)}finally{m(!1)}}},[l,p,n.saveError]),F=(0,X.useCallback)(()=>{d&&(C.current=!1,u(structuredClone(d)),g(null),v(!1))},[d]),L=(0,X.useCallback)(async()=>{let e=l?.auth.token;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),S(!0),window.setTimeout(()=>S(!1),2e3))},[l?.auth.token]);return c?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)(s,{className:`size-4 animate-spin`}),n.loading]})}):l?(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:Ue(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)(N,{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)(K,{type:`button`,variant:`secondary`,disabled:!j||p,onClick:F,children:n.discard}),(0,Y.jsx)(K,{type:`button`,variant:`primary`,disabled:!j||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)(he,{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)(K,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:()=>a(),children:n.updateToken})})]}):null,j?(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,l.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)(W,{className:`size-4 text-accent`,strokeWidth:1.75}),t.settingsSections.gateway]}),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(l.host||l.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:l.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:l.port==null?`—`:String(l.port)})]}),(0,Y.jsx)(`p`,{className:`sm:col-span-2 text-xs text-fg-subtle`,children:n.listenHint})]}),(0,Y.jsx)(dn,{g:n,value:l.auth.token,show:y,copied:x,onToggleShow:()=>b(e=>!e),onCopy:()=>void L(),onChange:e=>M({token:e})}),(0,Y.jsx)(K,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,onClick:()=>a(),children:n.changeToken}),r?(0,Y.jsx)(un,{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:l.updateChannel,onChange:e=>ee(e.target.value),className:cn(),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??A??n.loadError}),(0,Y.jsx)(K,{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 un({g:e,gatewayToken:t}){let[n,r]=(0,X.useState)(ge),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(!1),[l,u]=(0,X.useState)(!1),d=n.trim(),f=(0,X.useMemo)(()=>{try{let e=new URL(d);return e.protocol===`http:`||e.protocol===`https:`}catch{return!1}},[d]),p=(0,X.useMemo)(()=>!t||!f?``:fe({baseUrl:d,gatewayToken:t}),[f,t,d]);(0,X.useEffect)(()=>{if(!p){o(null),c(!1);return}let e=!1;return c(!1),rn.toDataURL(p,{width:216,margin:2,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}}).then(t=>{e||o(t)}).catch(()=>{e||(c(!0),o(null))}),()=>{e=!0}},[p]);let m=f&&Pe(d),h=(0,X.useCallback)(async()=>{p&&(await navigator.clipboard.writeText(p).catch(()=>{}),u(!0),window.setTimeout(()=>u(!1),2e3))},[p]);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)(i,{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:b(cn(),`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}),f?null:(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:e.mobilePairInvalidBaseUrl}),m?(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})]}),p?(0,Y.jsxs)(`div`,{className:`flex flex-col items-center gap-3 sm:items-start`,children:[a&&!s?(0,Y.jsx)(`img`,{src:a,alt:``,className:`h-56 w-56 rounded-lg border border-edge-subtle bg-white object-contain p-3 dark:border-edge`}):null,!a&&!s?(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.mobilePairEncoding}):null,s?(0,Y.jsx)(`p`,{className:`text-center text-sm text-fg-muted sm:text-left`,children:e.mobilePairImageError}):null,(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,disabled:!p,onClick:()=>void h(),children:[l?(0,Y.jsx)(ae,{className:`size-3.5`}):(0,Y.jsx)(Fe,{className:`size-3.5`}),l?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 dn({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:b(cn(),`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)(K,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:a,children:[r?(0,Y.jsx)(ae,{className:`size-3.5`}):(0,Y.jsx)(Fe,{className:`size-3.5`}),r?e.copied:e.copy]}):null,(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:i,children:[n?(0,Y.jsx)(re,{className:`size-3.5`}):(0,Y.jsx)(V,{className:`size-3.5`}),n?e.hide:e.show]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tokenHelp})]})}function fn(){return q(`/api/channels/status`)}var pn=rt,mn=[3e4,6e4,3e5,6e5,9e5,18e5,36e5,72e5],hn=new Set(mn);function gn(){return b(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,Ce,`dark:border-edge`)}function _n(){return b(D,_)}function vn(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 yn(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 bn(){let e=I(e=>e.language),t=o(e),n=t.heartbeatSettings,i=!!oe(e=>e.token),[a,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(``),[p,m]=(0,X.useState)(``),[h,g]=(0,X.useState)(!1),[_,v]=(0,X.useState)(!1),[x,S]=(0,X.useState)(null),[C,w]=(0,X.useState)(!1),[T,E]=(0,X.useState)(!1),[D,O]=(0,X.useState)(!1),[k,A]=(0,X.useState)(!1),[j,M]=(0,X.useState)(null),[ee,P]=(0,X.useState)([]),{data:F,error:L,isLoading:te,mutate:z}=R(i),{data:B,error:V,isLoading:H,mutate:ne}=r(i?kt():null,Et,{revalidateOnFocus:!1}),{data:re=[]}=r(i?fn():null,pn,{revalidateOnFocus:!1}),ie=(0,X.useMemo)(()=>vn(F?.payload?.config),[F]),ae=(0,X.useMemo)(()=>jt(F?.payload?.config??{}),[F]),U=(0,X.useMemo)(()=>!a||!l?!1:JSON.stringify(a)!==JSON.stringify(l),[a,l]),W=(0,X.useMemo)(()=>d!==p,[d,p]);(0,X.useEffect)(()=>{if(!i){c(null),u(null);return}if(F!==void 0&&!U){let e=structuredClone(ae);c(e),u(e),w(!1)}},[i,F,ae,U]),(0,X.useEffect)(()=>{!i||B===void 0||W||(f(B),m(B),E(!1))},[i,B,W]);let ce=L instanceof Error?L.message:L?String(L):V instanceof Error?V.message:V?String(V):null,le=!!(i&&(F===void 0||B===void 0)&&!ce&&(te||H));(0,X.useEffect)(()=>{if(!i||!a){P([]);return}let e=a.target.trim();if(!e){P([]);return}let t=!1;return at(e).then(e=>{t||P(e)}),()=>{t=!0}},[i,a?.target]);let ue=(0,X.useCallback)(()=>{let e=a?.target?.trim();e&&at(e).then(P)},[a?.target]),G=(0,X.useCallback)(async()=>{O(!0),A(!1),M(null);try{await Dt(),A(!0),window.setTimeout(()=>A(!1),3e3)}catch(e){M(e instanceof Error?e.message:n.triggerError)}finally{O(!1)}},[n.triggerError]),de=(0,X.useCallback)(e=>{c(t=>t?{...t,...e}:null)},[]),fe=(0,X.useCallback)(()=>{l&&(c(structuredClone(l)),w(!1),S(null))},[l]),pe=(0,X.useCallback)(()=>{f(p),E(!1),S(null)},[p]),me=(0,X.useCallback)(async()=>{if(!(!a||h)){g(!0),S(null),w(!1);try{await Ot(a),u(structuredClone(a)),w(!0),window.setTimeout(()=>w(!1),2500)}catch(e){S(e instanceof Error?e.message:n.saveConfigError)}finally{g(!1)}}},[a,h,n.saveConfigError]),he=(0,X.useCallback)(async()=>{if(!_){v(!0),S(null),E(!1);try{await At(d),m(d),E(!0),window.setTimeout(()=>E(!1),2500)}catch(e){S(e instanceof Error?e.message:n.saveDocError)}finally{v(!1)}}},[d,_,n.saveDocError]);return i?le?(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)(s,{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:Ue(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)(N,{className:`size-3.5`})]})]})}),ie?(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.workspaceLabel,`: `,(0,Y.jsx)(`span`,{className:`font-mono text-fg-muted`,children:ie})]}):null,x?(0,Y.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:x}):null,(0,Y.jsxs)(Ct,{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)(y,{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)(K,{type:`button`,variant:`secondary`,className:`inline-flex items-center gap-2`,disabled:D,onClick:()=>void G(),children:[D?(0,Y.jsx)(s,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(se,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),D?n.triggering:n.triggerNow]}),k?(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}),j?(0,Y.jsx)(`p`,{className:`mb-3 text-sm text-red-600 dark:text-red-400`,children:j}):null,(0,Y.jsx)(xn,{h:n,cron:t.cron,form:a,channels:re,sessionChatIds:ee,onRefreshChatIds:ue,update:de,inputClassName:gn,selectClassName:_n}),(0,Y.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-2`,children:[C?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.savedConfig}):null,(0,Y.jsx)(K,{type:`button`,variant:`secondary`,disabled:!U||h,onClick:fe,children:n.discard}),(0,Y.jsx)(K,{type:`button`,variant:`primary`,disabled:!U||h,onClick:()=>void me(),children:h?n.savingConfig:n.saveConfig}),U?(0,Y.jsx)(`span`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedConfig}):null]})]}),(0,Y.jsxs)(Ct,{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:b(gn(),`min-h-[12rem] resize-y font-mono text-xs leading-relaxed`),value:d,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:[T?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.savedDoc}):null,(0,Y.jsx)(K,{type:`button`,variant:`secondary`,disabled:!W||_,onClick:pe,children:n.discard}),(0,Y.jsx)(K,{type:`button`,variant:`primary`,disabled:!W||_,onClick:()=>void he(),children:_?n.savingDoc:n.saveDoc}),W?(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:x??ce??n.loadError}),(0,Y.jsx)(K,{type:`button`,variant:`secondary`,onClick:()=>{z(),ne()},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 xn({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)(()=>hn.has(n.intervalMs)?String(n.intervalMs):``,[n.intervalMs]),[p,m]=(0,X.useState)(null),h=Math.max(1,Math.round(n.intervalMs/1e3)),g=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:b(s(),`min-w-0 flex-1`),value:g,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:b(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}),mn.map(t=>(0,Y.jsx)(`option`,{value:String(t),children:yn(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)(K,{type:`button`,variant:`ghost`,className:`h-7 gap-1 px-2 text-xs`,title:t.refreshRecipientHint,onClick:a,children:[(0,Y.jsx)(_e,{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:b(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:b(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:it(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:b(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)(K,{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)(K,{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 Sn(){let e=await De(q(`/api/image/providers`));if(!e.ok)throw Error(`Image providers: HTTP ${e.status}`);return(await e.json()).payload?.providers??[]}function Cn(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 wn(e,t){let n=Cn(e.filter(e=>e.configured===!0));return!t||n.includes(t)?n:[t,...n]}function Tn(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 En=`image-generation-providers`;function Dn({value:e,disabled:t,placeholder:n,searchPlaceholder:i,noMatches:a,registryEmptyHint:o,outOfFilterNote:s,className:c,onChange:l}){let[u,d]=(0,X.useState)(!1),[f,m]=(0,X.useState)(``),{data:h,isLoading:g,error:_}=r(En,Sn,{revalidateOnFocus:!1}),v=e.trim(),y=(0,X.useMemo)(()=>Cn((h??[]).filter(e=>e.configured===!0)),[h]),S=(0,X.useMemo)(()=>wn(h??[],v),[h,v]),C=(0,X.useMemo)(()=>Tn(S,f),[S,f]),T=!!s&&!!v&&!y.includes(v),E=e.trim()?e:n,D=e.trim()||n,O=(0,X.useCallback)(e=>{d(e),e||m(``)},[]);return(0,Y.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,Y.jsxs)(P,{open:u,onOpenChange:O,modal:!1,children:[(0,Y.jsx)(Qe,{asChild:!0,children:(0,Y.jsxs)(`button`,{type:`button`,disabled:t||g,title:g?`…`:D,className:b(We,`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`,H.transition,`hover:border-edge hover:bg-surface-hover/45`,p,`disabled:cursor-not-allowed disabled:opacity-50`,`dark:border-edge-subtle dark:hover:bg-surface-hover/55`,c),"aria-haspopup":`listbox`,"aria-expanded":u,children:[(0,Y.jsx)(`span`,{className:`min-w-0 truncate`,children:g?`…`:E}),(0,Y.jsx)(Ne,{className:`h-4 w-4 shrink-0 text-fg-subtle opacity-70`,"aria-hidden":!0})]})}),(0,Y.jsx)(w,{children:(0,Y.jsxs)(x,{className:b(`w-[min(22rem,calc(100vw-2rem))] rounded-xl border border-edge-subtle bg-surface-panel p-1 shadow-elevated dark:border-edge-subtle`,G),side:`bottom`,sideOffset:4,align:`end`,onOpenAutoFocus:e=>e.preventDefault(),children:[(0,Y.jsx)(`input`,{type:`search`,className:b(`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`,z),placeholder:i,value:f,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:[_?(0,Y.jsx)(`div`,{className:`px-2 py-2 text-xs text-red-600 dark:text-red-400`,children:_ instanceof Error?_.message:`Failed to load image providers`}):null,!_&&S.length===0&&!g?(0,Y.jsx)(`div`,{className:`px-2 py-3 text-center text-xs text-fg-muted`,children:o??a}):null,!_&&S.length>0&&C.length===0?(0,Y.jsx)(`div`,{className:`px-2 py-3 text-center text-xs text-fg-muted`,children:a}):null,C.map(t=>(0,Y.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t===e,className:b(`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),d(!1),m(``)},children:[(0,Y.jsx)(ae,{className:b(`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))]})]})})]}),T?(0,Y.jsx)(`p`,{className:`text-xs text-amber-700 dark:text-amber-400/90`,children:s}):null]})}function On(e){let{a:t,chat:n,form:r,update:i}=e;return(0,Y.jsxs)(Ct,{children:[(0,Y.jsx)(wt,{icon:B,title:t.cardModelsTitle,subtitle:t.cardModelsSubtitle}),(0,Y.jsxs)(`div`,{className:`mt-4 flex flex-col gap-5`,children:[(0,Y.jsx)(lt,{label:t.label.imageModel,description:t.desc.imageModel,children:(0,Y.jsx)(U,{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)(lt,{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)(U,{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)(K,{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)(S,{className:`size-4`,strokeWidth:1.75})})]},a)),(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:()=>i({imageModelFallbacks:[...r.imageModelFallbacks,``]}),children:[(0,Y.jsx)(Oe,{className:`size-4 shrink-0`,strokeWidth:1.75}),t.addModelFallback]})]})}),(0,Y.jsx)(lt,{label:t.label.imageGenerationModel,description:t.desc.imageGenerationModel,children:(0,Y.jsx)(Dn,{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)(lt,{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)(Dn,{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)(K,{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)(S,{className:`size-4`,strokeWidth:1.75})})]},a)),(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:()=>i({imageGenerationModelFallbacks:[...r.imageGenerationModelFallbacks,``]}),children:[(0,Y.jsx)(Oe,{className:`size-4 shrink-0`,strokeWidth:1.75}),t.addModelFallback]})]})})]})]})}function kn(){return b(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,Ce)}var An=()=>q($e);function jn(e){return{imageModel:e.imageModel,imageModelFallbacks:e.imageModelFallbacks,imageGenerationModel:e.imageGenerationModel,imageGenerationModelFallbacks:e.imageGenerationModelFallbacks,imageGenerationModelTimeoutMs:e.imageGenerationModelTimeoutMs,imageGenerationModelAutoProviderFallback:e.imageGenerationModelAutoProviderFallback}}function Mn(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 Nn(){let e=I(e=>e.language),t=o(e),n=t.imageModelsSettings,i=!!oe(e=>e.token),[a,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(!0),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(!1),[_,v]=(0,X.useState)(void 0),y=de(),x=(0,X.useMemo)(()=>new Set(y.map(e=>e.id)),[y]),S=(0,X.useCallback)(async()=>{if(i){f(!0),v(void 0);try{let e=await ct(),t=structuredClone(e);c(t),u(structuredClone(t))}catch(e){v(e instanceof Error?e.message:String(e))}finally{f(!1)}}},[i]);(0,X.useEffect)(()=>{S()},[S]);let C=(0,X.useCallback)(e=>{c(t=>t?{...t,...e}:null)},[]),{data:w=[],mutate:T}=r(i?An():null,tt,{revalidateOnFocus:!1}),E=R(i),D=nt(w),O=(0,X.useMemo)(()=>!a||!l?!1:JSON.stringify(jn(a))!==JSON.stringify(jn(l)),[a,l]),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 A=(0,X.useCallback)(async()=>{if(a){m(!0),v(void 0);try{try{mt(a.paramsJson)}catch(e){v(e instanceof SyntaxError?t.agentSettings.advanced.paramsInvalidJson:e instanceof Error?e.message:t.agentSettings.advanced.paramsInvalidJson);return}await St(a),u(structuredClone(a)),g(!0),window.setTimeout(()=>g(!1),1500),E.mutate?.()}catch(e){v(e instanceof Error?e.message:String(e))}finally{m(!1)}}},[a,E,t.agentSettings]),j=(0,X.useCallback)(()=>{l&&(c(structuredClone(l)),v(void 0),g(!1))},[l]),M=(0,X.useMemo)(()=>Mn(n),[n]),N=(0,X.useMemo)(()=>({getApiKey:t.providersSettings.getApiKey,getApiKeyIntl:t.providersSettings.getApiKeyIntl,getApiKeyCn:t.providersSettings.getApiKeyCn}),[t.providersSettings]);return i?d||!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)(s,{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)(K,{type:`button`,variant:`ghost`,onClick:()=>{S(),T(),E.mutate?.()},children:[(0,Y.jsx)(_e,{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)(K,{type:`button`,variant:`secondary`,onClick:j,disabled:!O||p,children:n.discard}),(0,Y.jsxs)(K,{type:`button`,variant:`primary`,onClick:()=>void A(),disabled:!O||p,children:[p?(0,Y.jsx)(s,{className:`size-3.5 animate-spin`}):(0,Y.jsx)(pe,{className:`size-3.5`}),(0,Y.jsx)(`span`,{className:`ml-1.5`,children:p?n.saving:n.save})]})]})]}),_?(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:_}):null,(0,Y.jsx)(On,{form:a,update:C,a:t.agentSettings,chat:t.chat}),(0,Y.jsxs)(Ct,{children:[(0,Y.jsx)(wt,{icon:B,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:b(kn(),`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)));c(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=>c(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)(Ct,{children:[(0,Y.jsx)(wt,{icon:W,title:n.providersTitle,subtitle:``}),w.length===0?(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.providersEmpty}):(0,Y.jsx)(et,{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:N,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 Pn=[{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 Fn(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 In(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 Ln(){let e=await De(q(`/api/models-json`)),t=await e.json().catch(()=>({}));if(!e.ok||!t.ok||!t.payload)throw Error(Fn(t)||`HTTP ${e.status}`);return{...t.payload,config:In(t.payload.config)}}async function Rn(e){let t=await De(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(Fn(n)||`HTTP ${t.status}`);return n.payload}async function zn(e){let t=await De(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(Fn(n)||`HTTP ${t.status}`);return n.payload}async function Bn(){let e=await De(q(`/api/models-json/reload`),{method:`POST`}),t=await e.json().catch(()=>({}));if(!e.ok||!t.ok||!t.payload)throw Error(Fn(t)||`HTTP ${e.status}`);return t.payload}async function Vn(e){let t=await De(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(Fn(n)||`HTTP ${t.status}`);return n.payload}function Hn(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 Un(e){return e.startsWith(`!`)}function Wn(e){return/^[A-Z][A-Z0-9_]*$/.test(e)}function Gn(e){return Un(e)?`shell`:Wn(e)?`env`:`literal`}function Kn(e){return e?e.length<=8?`••••`:`${e.slice(0,4)}••••${e.slice(-4)}`:``}function qn(e){let{a:t,chat:n,form:r,update:i}=e;return(0,Y.jsxs)(Ct,{children:[(0,Y.jsx)(wt,{icon:ke,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)(U,{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)(K,{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)(S,{className:`size-4`,strokeWidth:1.75})})]},a)),(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:()=>i({modelFallbacks:[...r.modelFallbacks,``]}),children:[(0,Y.jsx)(Oe,{className:`size-4 shrink-0`,strokeWidth:1.75}),t.addModelFallback]})]})]})}var Jn={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 Yn(e){return e===`openrouter`?`openrouter`:e===`zhipuCn`?`zhipu-cn`:e===`zaiGeneral`?`zai`:e}var Xn=[{value:`text`,labelKey:`inputTextOnly`},{value:`text,image`,labelKey:`inputTextVision`}];function Zn(){return b(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,Ce,`dark:border-edge`)}function Qn(){return b(D,_)}function $n(e){return(e.input||[`text`]).includes(`image`)?`text,image`:`text`}function er(e){return e===`text,image`?[`text`,`image`]:[`text`]}function tr(e,t,n){return{...e,providers:{...e.providers,[t]:{...e.providers[t],...n}}}}function nr(e,t){let n={...e.providers};return delete n[t],{...e,providers:n}}function rr(e,t,n){return{...e,providers:{...e.providers,[t]:n}}}function ir({open:e,onOpenChange:t,providerId:n,model:r,isNew:i,onSave:a,m:o}){let[s,l]=(0,X.useState)(()=>Hn(``)),[u,d]=(0,X.useState)(()=>new Map);(0,X.useEffect)(()=>{e&&(d(new Map),l(r?{...r}:Hn(``)))},[e,r]);let f=(e,t)=>{l(n=>({...n,[e]:t})),d(t=>{let n=new Map(t);return n.delete(e),n})},p=()=>{let e=new Map;return(s.id||``).trim()||e.set(`id`,o.modelIdRequired),s.contextWindow!==void 0&&s.contextWindow<=0&&e.set(`contextWindow`,o.mustBePositive),s.maxTokens!==void 0&&s.maxTokens<=0&&e.set(`maxTokens`,o.mustBePositive),d(e),e.size===0},m=()=>{if(!p())return;let e=(s.id||``).trim();a({...s,id:e,name:s.name?.trim()||e,reasoning:s.reasoning||!1,input:s.input||[`text`],contextWindow:s.contextWindow??128e3,maxTokens:s.maxTokens??16384,cost:{input:s.cost?.input??0,output:s.cost?.output??0,cacheRead:s.cost?.cacheRead??0,cacheWrite:s.cost?.cacheWrite??0}}),t(!1)},g=$n(s);return(0,Y.jsx)(T,{open:e,onOpenChange:t,children:(0,Y.jsxs)(Se,{children:[(0,Y.jsx)(c,{className:b(`xopc-dialog-overlay fixed inset-0 bg-scrim`,Le)}),(0,Y.jsxs)(k,{className:b(`xopc-dialog-content fixed left-1/2 top-1/2 max-h-[min(90vh,720px)] w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2`,je,`overflow-y-auto rounded-xl border border-edge bg-surface-panel p-4 shadow-popover dark:border-edge`),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)(E,{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)(ee,{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:b(Zn(),u.has(`id`)&&`border-red-500`),value:s.id||``,onChange:e=>f(`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:Zn(),value:s.name||``,onChange:e=>f(`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:Qn(),value:g,onChange:e=>f(`input`,er(e.target.value)),children:Xn.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:s.reasoning||!1,onChange:e=>f(`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:b(Zn(),u.has(`contextWindow`)&&`border-red-500`),value:s.contextWindow??128e3,onChange:e=>f(`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:b(Zn(),u.has(`maxTokens`)&&`border-red-500`),value:s.maxTokens??16384,onChange:e=>f(`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:Zn(),value:s.cost?.input??0,onChange:e=>f(`cost`,{...s.cost,input:parseFloat(e.target.value)||0,output:s.cost?.output??0,cacheRead:s.cost?.cacheRead??0,cacheWrite:s.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:Zn(),value:s.cost?.output??0,onChange:e=>f(`cost`,{...s.cost,input:s.cost?.input??0,output:parseFloat(e.target.value)||0,cacheRead:s.cost?.cacheRead??0,cacheWrite:s.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)(K,{type:`button`,variant:`secondary`,children:o.cancel})}),(0,Y.jsx)(K,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:m,children:i?o.addModelConfirm:o.saveModelConfirm})]})]})]})})}function ar({open:e,onOpenChange:t,presetKey:n,onConfirm:r,m:i}){let[a,o]=(0,X.useState)(``),[s,l]=(0,X.useState)(`custom`),[u,d]=(0,X.useState)(``),[f,p]=(0,X.useState)(`openai-completions`),[m,g]=(0,X.useState)(``),[_,v]=(0,X.useState)(null);(0,X.useEffect)(()=>{if(!e)return;v(null);let t=n||null;if(t&&Jn[t]){let e=Jn[t];l(t),d(e.baseUrl||``),p(e.api||`openai-completions`),g(e.apiKey??``),o(Yn(t))}else l(`custom`),o(``),d(``),p(`openai-completions`),g(``)},[e,n]);let y=e=>{if(l(e),e===`custom`)return;let t=Jn[e];t&&(d(t.baseUrl||``),p(t.api||`openai-completions`),g(t.apiKey??``),o(Yn(e)))};return(0,Y.jsx)(T,{open:e,onOpenChange:t,children:(0,Y.jsxs)(Se,{children:[(0,Y.jsx)(c,{className:b(`xopc-dialog-overlay fixed inset-0 bg-scrim`,Le)}),(0,Y.jsxs)(k,{className:b(`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`,je,`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)(E,{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)(ee,{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:Qn(),value:s,onChange:e=>y(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:Zn(),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:Zn(),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:Qn(),value:f,onChange:e=>p(e.target.value),children:Pn.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:Zn(),value:m,onChange:e=>g(e.target.value),placeholder:i.apiKeyPlaceholder})]}),_?(0,Y.jsxs)(`p`,{className:`flex items-center gap-1 text-xs text-red-600 dark:text-red-400`,children:[(0,Y.jsx)(he,{className:`size-3.5 shrink-0`}),_]}):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)(K,{type:`button`,variant:`secondary`,children:i.cancel})}),(0,Y.jsx)(K,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:()=>{let e=a.trim();if(!e){v(i.providerIdRequired);return}v(null),r(e,{baseUrl:u.trim()||void 0,api:f,apiKey:m.trim()||void 0,models:[]}),t(!1)},children:i.addProviderConfirm})]})]})]})})}function or({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?Gn(f.apiKey):null,g=o.get(e),_=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)(ye,{className:`size-4 shrink-0 text-fg-muted`}):(0,Y.jsx)(Ee,{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:b(`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)(S,{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:Zn(),value:f.baseUrl||``,onChange:n=>t(t=>tr(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:Qn(),value:f.api||`openai-completions`,onChange:n=>t(t=>tr(t,e,{api:n.target.value})),children:Pn.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:b(Zn(),`min-w-0 flex-1`),type:_?`text`:`password`,autoComplete:`off`,value:f.apiKey||``,onChange:n=>{let r=n.target.value;t(t=>tr(t,e,{apiKey:r})),d(t=>{let n=new Map(t);return n.delete(e),n})},placeholder:c.apiKeyPlaceholder}),(0,Y.jsx)(K,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>a(e),children:_?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(re,{className:`mr-1 size-3.5`}),c.hide]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(V,{className:`mr-1 size-3.5`}),c.show]})}),(0,Y.jsx)(K,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>s(e,f.apiKey||``),children:c.testKey})]}),g?(0,Y.jsx)(`p`,{className:b(`mt-1 text-xs`,g.error?`text-red-600 dark:text-red-400`:`text-emerald-700 dark:text-emerald-400`),children:g.error?`${c.testError}: ${g.error}`:`${c.testOk} (${g.type}): ${Kn(g.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=>tr(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)(K,{type:`button`,variant:`primary`,className:`px-2 py-1 text-xs`,onClick:()=>u(e,null,!0),children:[(0,Y.jsx)(Oe,{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)(ue,{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?tr(t,e,{models:(r.models||[]).filter(e=>e.id!==n.id)}):t})},"aria-label":c.removeModel,children:(0,Y.jsx)(S,{className:`size-4`})})]})]},n.id))})]})]}):null]},e)})})}function sr({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)(ke,{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)(K,{type:`button`,className:`mb-6 bg-accent text-white hover:bg-accent/90`,onClick:()=>t(null),children:[(0,Y.jsx)(Oe,{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:b(`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`,H.transition,H.focusRingBase),onClick:()=>t(`ollama`),children:[(0,Y.jsx)(C,{className:`size-3.5`,"aria-hidden":!0}),e.presetOllama]}),(0,Y.jsxs)(`button`,{type:`button`,className:b(`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`,H.transition,H.focusRingBase),onClick:()=>t(`openrouter`),children:[(0,Y.jsx)(Ye,{className:`size-3.5`,"aria-hidden":!0}),e.presetOpenRouter]}),(0,Y.jsxs)(`button`,{type:`button`,className:b(`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`,H.transition,H.focusRingBase),onClick:()=>t(`lmstudio`),children:[(0,Y.jsx)(ke,{className:`size-3.5`,"aria-hidden":!0}),e.presetLmStudio]}),(0,Y.jsxs)(`button`,{type:`button`,className:b(`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`,H.transition,H.focusRingBase),onClick:()=>t(`zhipuCn`),children:[(0,Y.jsx)(C,{className:`size-3.5`,"aria-hidden":!0}),e.presetZhipuCn]}),(0,Y.jsxs)(`button`,{type:`button`,className:b(`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`,H.transition,H.focusRingBase),onClick:()=>t(`zaiGeneral`),children:[(0,Y.jsx)(Ye,{className:`size-3.5`,"aria-hidden":!0}),e.presetZaiGeneral]})]})]})}function cr(){let e=I(e=>e.language),t=o(e),n=t.modelsSettings,r=bt(t.agentSettings),i=!!oe(e=>e.token),[a,c]=(0,X.useState)({providers:{}}),[l,u]=(0,X.useState)({providers:{}}),[d,f]=(0,X.useState)(``),[p,m]=(0,X.useState)(),[h,g]=(0,X.useState)(!0),[_,v]=(0,X.useState)(!1),[y,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),[A,j]=(0,X.useState)(()=>new Set),[M,ee]=(0,X.useState)(!1),[P,F]=(0,X.useState)(``),[L,R]=(0,X.useState)(null),[te,z]=(0,X.useState)(()=>new Set),[B,V]=(0,X.useState)(()=>new Map),[H,ne]=(0,X.useState)(!1),[re,ie]=(0,X.useState)(null),[ae,se]=(0,X.useState)(!1),[U,W]=(0,X.useState)(null),ce=(0,X.useCallback)(async e=>{let t=!e?.skipFullPageLoading;t&&g(!0),T(null);try{let e=await Ln(),t=In(e.config);c(t),u(structuredClone(t)),f(e.path),m(e.loadError),k(null),D(!1)}catch(e){T(e instanceof Error?e.message:n.loadError),c({providers:{}}),u({providers:{}})}finally{t&&g(!1)}},[n.loadError]);(0,X.useEffect)(()=>{if(!i){g(!1);return}ce()},[i,ce]);let le=(0,X.useMemo)(()=>JSON.stringify(a)!==JSON.stringify(l),[a,l]),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]),G=le||r.dirty,de=(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]),fe=e=>{j(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},pe=e=>{z(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},me=(0,X.useCallback)(()=>{F(JSON.stringify(a,null,2)),R(null)},[a]);(0,X.useEffect)(()=>{M&&me()},[M,me]);let ge=()=>{try{c(In(JSON.parse(P))),R(null)}catch{R(n.jsonParseError)}},ve=async()=>{x(!0),T(null);try{k(await Rn(a))}catch(e){T(e instanceof Error?e.message:n.validateError)}finally{x(!1)}},ye=async()=>{if(_||r.saving)return;let e=le,i=r.dirty;if(!(!e&&!i)){T(null),D(!1);try{if(e){v(!0);try{await zn(a),u(structuredClone(a)),k(null)}finally{v(!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)}}},be=(0,X.useCallback)(()=>{c(structuredClone(l)),k(null),D(!1),T(null),M&&(F(JSON.stringify(l,null,2)),R(null)),r.discard()},[l,M,r.discard]),xe=async()=>{C(!0),T(null);try{await Bn(),await ce({skipFullPageLoading:!0})}catch(e){T(e instanceof Error?e.message:n.reloadError)}finally{C(!1)}},Se=async(e,t)=>{try{let n=await Vn(t);V(t=>{let r=new Map(t);return r.set(e,n),r})}catch(t){V(n=>{let r=new Map(n);return r.set(e,{type:`error`,error:t instanceof Error?t.message:`Error`}),r})}},Ce=(e=null)=>{ie(e),ne(!0)},we=(e,t)=>{c(n=>rr(n,e,t)),j(t=>new Set(t).add(e))},Te=e=>{window.confirm(n.removeProviderConfirm.replace(`{{id}}`,e))&&(c(t=>nr(t,e)),V(t=>{let n=new Map(t);return n.delete(e),n}))},Ee=(e,t,n)=>{W({providerId:e,model:t,isNew:n}),se(!0)},De=e=>{if(!U)return;let{providerId:t,isNew:n}=U;c(r=>{let i=r.providers[t];if(!i)return r;let a=i.models||[];return n?tr(r,t,{models:[...a,e]}):tr(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:Ue(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)(N,{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)(he,{className:`mt-0.5 size-4 shrink-0`}),(0,Y.jsxs)(`span`,{children:[n.loadFileWarning,`: `,p]})]}):null,d?(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:d})]}):null,(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsxs)(K,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:()=>Ce(null),disabled:h,children:[(0,Y.jsx)(Oe,{className:`mr-1 size-4`}),n.addProvider]}),(0,Y.jsx)(K,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:ve,disabled:h||y,children:y?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(s,{className:`mr-1 size-4 animate-spin`}),n.validating]}):n.validate}),(0,Y.jsx)(K,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:be,disabled:h||_||r.saving||!G,children:n.discard}),(0,Y.jsx)(K,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:()=>void ye(),disabled:h||_||r.saving||!G,children:_||r.saving?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(s,{className:`mr-1 size-4 animate-spin`}),n.saving]}):n.save}),(0,Y.jsx)(K,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[8.5rem] justify-center`,onClick:xe,disabled:h||S,children:S?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(s,{className:`mr-1 size-4 animate-spin`}),n.reloading]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(_e,{className:`mr-1 size-4`}),n.reload]})}),(0,Y.jsx)(K,{type:`button`,variant:`ghost`,className:`text-fg-muted`,onClick:()=>{ee(e=>!e),R(null)},children:M?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(de.providers))}),(0,Y.jsx)(`span`,{className:`text-fg-subtle`,children:`|`}),(0,Y.jsx)(`span`,{className:`text-fg-muted`,children:n.statsModels.replace(`{{count}}`,String(de.models))})]})]}),G?(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)(he,{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)(he,{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)(s,{className:`size-4 animate-spin`}),n.loading]}):M?(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(`textarea`,{className:b(Zn(),`min-h-[320px] resize-y font-mono text-xs leading-relaxed`),value:P,onChange:e=>F(e.target.value),spellCheck:!1}),L?(0,Y.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:L}):null,(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(K,{type:`button`,variant:`secondary`,onClick:me,children:n.jsonReset}),(0,Y.jsx)(K,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:ge,children:n.jsonApply})]})]}):Object.keys(a.providers).length===0?(0,Y.jsx)(sr,{ms:n,openAddProvider:Ce}):(0,Y.jsx)(or,{config:a,setConfig:c,expanded:A,toggleExpand:fe,showPw:te,toggleShowPw:pe,testResults:B,runTestKey:Se,ms:n,removeProv:Te,openModelDialog:Ee,setTestResults:V}),ue?(0,Y.jsx)(`div`,{className:`mt-10 border-t border-edge-subtle pt-8 dark:border-edge`,children:(0,Y.jsx)(qn,{...ue})}):null,(0,Y.jsx)(ar,{open:H,onOpenChange:ne,presetKey:re,onConfirm:we,m:n}),(0,Y.jsx)(ir,{open:ae,onOpenChange:e=>{se(e),e||W(null)},providerId:U?.providerId??null,model:U?.model??null,isNew:U?.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 lr(e){let t=await De(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 ur(e){let t=await De(q(`/api/auth/oauth-async/${encodeURIComponent(e)}/status`));if(!t.ok)throw Error(`OAuth status: ${t.status}`);return(await t.json()).payload}async function dr(e,t){let n=await De(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 fr(e){let t=await De(q(`/api/auth/oauth-async/${encodeURIComponent(e)}/cancel`),{method:`POST`});if(!t.ok)throw Error(`Cancel OAuth failed: ${t.status}`)}async function pr(e){let t=await De(q(`/api/auth/oauth-async/${encodeURIComponent(e)}`),{method:`DELETE`});if(!t.ok)throw Error(`Cleanup session failed: ${t.status}`)}async function mr(e){let t=await De(q(`/api/auth/oauth/${encodeURIComponent(e)}`),{method:`DELETE`});if(!t.ok)throw Error(`Revoke OAuth failed: ${t.status}`)}function hr({providerId:e,language:t}){let n=He[e];if(!n)return null;let r=t===`zh`,i=r&&n.descriptionZh?n.descriptionZh:n.description;return i?(0,Y.jsxs)(P,{children:[(0,Y.jsx)(Qe,{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)(u,{className:`size-3.5`,"aria-hidden":!0})})}),(0,Y.jsx)(w,{children:(0,Y.jsxs)(x,{side:`right`,align:`start`,sideOffset:6,className:b(`w-64 rounded-xl border border-edge bg-surface-panel p-3 shadow-md`,G,`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)(v,{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)(ee,{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)(N,{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)(N,{className:`size-3`,"aria-hidden":!0})]}):null]}):null,(0,Y.jsx)(j,{className:`fill-edge`})]})})]}):null}var gr=[`common`,`specialty`,`enterprise`,`oauth`,`extension`];function _r(e){let t=new Map;for(let e of gr)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 vr(e,t){return e.replace(/\{\{(\w+)\}\}/g,(e,n)=>String(t[n]??``))}function yr(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 br({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)(Be,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):(0,Y.jsx)(Fe,{className:`size-3.5`,"aria-hidden":!0})})]})}function xr({row:e,value:t,rowDirty:n,labels:r,language:i,onChange:a,onReload:o,justSaved:c,availableModels:l}){let[d,f]=(0,X.useState)(!1),[p,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(!1),[v,y]=(0,X.useState)(null),[x,C]=(0,X.useState)(!1),[w,T]=(0,X.useState)(null),[E,D]=(0,X.useState)(!1),k=Me(t),A=k&&!p?``:t,j=e.configured&&!k&&!!t,[M,P]=(0,X.useState)(!1),[F,I]=(0,X.useState)(),[L,R]=(0,X.useState)(),[te,z]=(0,X.useState)(),[B,ne]=(0,X.useState)(),[ae,oe]=(0,X.useState)(),[se,U]=(0,X.useState)(``),[W,le]=(0,X.useState)(!1),[ue,G]=(0,X.useState)(null),[de,fe]=(0,X.useState)(null),pe=e.activeKeySource??`none`,ge=(0,X.useMemo)(()=>Je(e.id,i),[e.id,i]);(0,X.useEffect)(()=>()=>{F&&pr(F).catch(()=>{})},[F]),(0,X.useEffect)(()=>{if(!F||!M)return;let e=window.setInterval(()=>{(async()=>{try{let t=await ur(F);z(t.message),ne(t.authUrl),oe(t.instructions),t.status===`waiting_auth`||t.status===`waiting_code`?R(t.status===`waiting_code`?`waiting_code`:`waiting`):t.status===`completed`?(window.clearInterval(e),P(!1),R(`success`),z(t.message),window.setTimeout(()=>o(),800)):(t.status===`failed`||t.status===`cancelled`)&&(window.clearInterval(e),P(!1),R(`error`),z(t.error||t.message||`OAuth failed`))}catch{}})()},1e3);return()=>window.clearInterval(e)},[F,M,o]);let _e=async()=>{P(!0),R(`waiting`),z(r.oauthStarting),I(void 0),ne(void 0),oe(void 0);try{I((await lr(e.id)).sessionId)}catch(e){R(`error`),z(e instanceof Error?e.message:`OAuth failed`),P(!1)}},ve=async()=>{if(F){try{await fr(F)}catch{}I(void 0),P(!1),R(`idle`),z(void 0)}},be=async()=>{if(!(!F||!se.trim()))try{await dr(F,se.trim()),U(``),z(r.oauthProcessingCode)}catch(e){R(`error`),z(e instanceof Error?e.message:`Failed`)}},xe=()=>{window.confirm(vr(r.revokeConfirm,{name:e.name}))&&(y(null),mr(e.id).then(()=>o()).catch(e=>y(e instanceof Error?e.message:r.revokeFailed)))},Se=async()=>{D(!1),C(!0),T(null);try{await me(e.id),T(r.removeKeySuccess),a(e.id,``),window.setTimeout(()=>o(),600)}catch(e){T(e instanceof Error?e.message:r.removeKeyFailed)}finally{C(!1)}},we=e.configured&&k&&pe!==`env`&&pe!==`extension`&&pe!==`models_json`,Te=async()=>{if(!(!t||k))try{await navigator.clipboard.writeText(t),_(!0),window.setTimeout(()=>_(!1),2e3)}catch{}},Ee=async()=>{let e=t.trim();if(!(!e||Me(e))){le(!0),G(null),fe(null);try{let t=await ie(e);if(t.error){fe(!1),G(`${r.testFailed} ${t.error}`);return}fe(!0),t.type===`env`?G(r.testOkEnv):t.type===`command`?G(r.testOkCommand):G(r.testOkLiteral)}catch(e){fe(!1),G(e instanceof Error?e.message:r.testFailed)}finally{le(!1)}}},De=n?r.metaWillSave:e.configured?k?`${r.metaMasked} · ${r.runtimeLabelPrefix} ${yr(r,pe)}`:`${r.runtimeLabelPrefix} ${yr(r,pe)}`:r.metaNotConfigured,Oe=`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)(Be,{className:`size-4 text-emerald-600 dark:text-emerald-400`}):(0,Y.jsx)(Ze,{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)(hr,{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:De})]}),(0,Y.jsx)(K,{type:`button`,variant:`ghost`,className:`h-9 w-9 shrink-0 p-0`,"aria-expanded":d,"aria-controls":Oe,"aria-label":r.expandRowDetails,onClick:()=>f(e=>!e),children:(0,Y.jsx)(ye,{className:b(`size-4 transition-transform`,d&&`rotate-180`),"aria-hidden":!0})})]}),d?(0,Y.jsxs)(`div`,{id:Oe,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:p||!k?`text`:`password`,className:b(`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`,Ce,`dark:border-edge`),value:A,placeholder:k?r.placeholderOverride:e.configured?r.placeholderKeep:r.placeholderKey,disabled:M,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:b(`rounded p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,H.transition,H.press,H.focusRingPanel),title:g?r.copied:r.copy,"aria-label":g?r.copied:r.copy,onClick:()=>void Te(),children:g?(0,Y.jsx)(Be,{className:`size-4`}):(0,Y.jsx)(Fe,{className:`size-4`})}):null,(0,Y.jsx)(`button`,{type:`button`,className:b(`rounded p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg disabled:opacity-40`,H.transition,H.press,H.focusRingPanel),title:p?r.hide:r.show,"aria-label":p?r.hide:r.show,disabled:k,onClick:()=>h(e=>!e),children:p?(0,Y.jsx)(re,{className:`size-4`}):(0,Y.jsx)(V,{className:`size-4`})})]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2 sm:shrink-0`,children:[(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,className:`gap-1`,disabled:M||W||!t.trim()||Me(t),onClick:()=>void Ee(),children:[W?(0,Y.jsx)(s,{className:`size-4 animate-spin`,"aria-hidden":!0}):null,W?r.testingKey:r.testKey]}),e.supportsOAuth?j?(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,className:`gap-1 text-red-600 dark:text-red-400`,onClick:xe,children:[(0,Y.jsx)(m,{className:`size-4`,"aria-hidden":!0}),r.revoke]}):(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,className:`gap-1`,disabled:M,onClick:()=>void _e(),children:[M?(0,Y.jsx)(s,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(O,{className:`size-4`,"aria-hidden":!0}),r.oauth]}):null,we?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,className:`gap-1 text-red-600 dark:text-red-400`,disabled:x,onClick:()=>D(!0),children:[x?(0,Y.jsx)(s,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(S,{className:`size-4`,"aria-hidden":!0}),r.removeKey]}),(0,Y.jsx)(ze,{open:E,title:r.removeKey,description:vr(r.removeKeyConfirm,{name:e.name}),confirmLabel:r.removeKey,cancelLabel:r.cancelOAuth,destructive:!0,onConfirm:()=>void Se(),onCancel:()=>D(!1)})]}):null]})]}),ue?(0,Y.jsx)(`p`,{className:b(`text-xs`,de===!1?`text-red-600 dark:text-red-400`:`text-fg-muted`),role:`status`,children:ue}):null,ge.length>0?(0,Y.jsx)(`div`,{className:`flex flex-col gap-1`,children:ge.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:[ce(e.kind,r),(0,Y.jsx)(N,{className:`size-3`,"aria-hidden":!0})]},`${e.kind}-${e.href}`))}):null]}),te?(0,Y.jsxs)(`div`,{className:b(`flex gap-2 rounded-md px-3 py-2 text-xs`,L===`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:[L===`error`?(0,Y.jsx)(he,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}):L===`success`?(0,Y.jsx)(Be,{className:`mt-0.5 size-4 shrink-0 text-emerald-600`,"aria-hidden":!0}):(0,Y.jsx)(u,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:te})]}):null,v?(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)(he,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:v})]}):null,w?(0,Y.jsxs)(`div`,{className:b(`flex gap-2 rounded-md px-3 py-2 text-xs`,w===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:[w===r.removeKeySuccess?(0,Y.jsx)(Be,{className:`mt-0.5 size-4 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):(0,Y.jsx)(he,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:w})]}):null,(L===`waiting`||L===`waiting_code`)&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[B?(0,Y.jsxs)(`a`,{href:B,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)(N,{className:`size-4`,"aria-hidden":!0}),r.openAuthPage]}):null,(0,Y.jsxs)(K,{type:`button`,variant:`secondary`,className:`gap-1`,onClick:()=>void ve(),children:[(0,Y.jsx)(ee,{className:`size-4`,"aria-hidden":!0}),r.cancelOAuth]})]}),ae?(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)(u,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:ae})]}):null,L===`waiting_code`?(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,Y.jsx)(`input`,{type:`text`,className:b(`min-w-0 flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,Ce,`dark:border-edge`),value:se,placeholder:r.pasteRedirectUrl,onChange:e=>U(e.target.value),onKeyDown:e=>e.key===`Enter`&&void be()}),(0,Y.jsx)(K,{type:`button`,variant:`primary`,className:`shrink-0`,onClick:()=>void be(),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)(u,{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&&!j?(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:r.oauthHint}):null,c?(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)(Be,{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=l.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,(He[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:(He[e.id]?.envVars??[]).map(e=>(0,Y.jsx)(br,{envVar:e,labels:r},e))})]}):null]}):null]})}function Sr(){let e=I(e=>e.language),t=o(e),n=t.providersSettings,i=!!oe(e=>e.token),[a,s]=(0,X.useState)({}),[c,l]=(0,X.useState)({}),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(null),[m,h]=(0,X.useState)(null),[_,v]=(0,X.useState)(()=>new Set([`common`])),[y,x]=(0,X.useState)(``),[S,C]=(0,X.useState)(!1),[w,T]=(0,X.useState)(()=>new Set),E=(0,X.useRef)(``),D=q(`/api/providers/meta`),O=(0,X.useCallback)(async e=>(await xe(e)).payload?.providers??[],[]),{data:k,error:A,isLoading:j,mutate:M}=R(i),{data:N,error:ee,isLoading:P,mutate:L}=r(i?D:null,O,{revalidateOnFocus:!1}),{data:te,mutate:z}=r(i?Ge:null,()=>F(),{revalidateOnFocus:!1}),B=(0,X.useMemo)(()=>!N||k===void 0?null:Te(N,ve(k.payload?.config),te??[]),[N,k,te]),V=A instanceof Error?A.message:A?String(A):ee instanceof Error?ee.message:ee?String(ee):null,H=!!(i&&B===null&&(j||P)&&!V),ne=(0,X.useMemo)(()=>JSON.stringify(a)!==JSON.stringify(c),[a,c]);(0,X.useEffect)(()=>{if(!ne)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[ne]),(0,X.useEffect)(()=>{if(!(!i||B===null)&&!ne){let e={};for(let t of B)e[t.id]=t.apiKey;s(e),l({...e})}},[i,B,ne]);let re=B??[],ie=(0,X.useMemo)(()=>{let e=re,t=y.trim().toLowerCase();return t&&(e=e.filter(e=>{let n=He[e.id]?.aliases??[];return e.id.toLowerCase().includes(t)||e.name.toLowerCase().includes(t)||n.some(e=>e.toLowerCase().includes(t))})),S&&(e=e.filter(e=>!e.configured)),e},[re,y,S]),ae=(0,X.useMemo)(()=>_r(ie),[ie]);(0,X.useEffect)(()=>{let e=E.current;if(E.current=y,y.trim()){let e=new Set;for(let t of gr)(ae.get(t)??[]).length>0&&e.add(t);v(e);return}e.trim()&&v(new Set([`common`]))},[y,ae]);let se=(0,X.useCallback)(async()=>{if(u)return;let e={};for(let t of Object.keys(a)){let n=a[t]?.trim()??``;!n||Me(n)||(e[t]=n)}if(Object.keys(e).length===0){l({...a}),h(`noChanges`),window.setTimeout(()=>h(null),2500);return}d(!0),p(null),h(null);try{await be(e),T(new Set(Object.keys(e)));let t=await z(F(!0))??te??[],[n,r]=await Promise.all([M(),L()]),i=Array.isArray(r)?r:N??[],a=n??k;if(a?.payload){let e=Te(i,ve(a.payload.config),t),n={};for(let t of e)n[t.id]=t.apiKey;s(n),l({...n})}h(`saved`),window.setTimeout(()=>h(null),2500)}catch(e){p(e instanceof Error?e.message:n.saveError)}finally{d(!1)}},[k,a,N,te,M,L,z,n.saveError,u]),U=(0,X.useCallback)(()=>{s({...c}),p(null),h(null),T(new Set)},[c]),W=e=>{v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},ce=(0,X.useCallback)(()=>{M(),L()},[M,L]),le=!!(y.trim()||S);return i?H?(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})]}):re.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:f??V??n.empty})]}),(0,Y.jsx)(K,{type:`button`,variant:`secondary`,onClick:()=>{M(),L()},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:[m===`saved`?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,m===`noChanges`?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.noChangesSaved}):null,(0,Y.jsx)(K,{type:`button`,variant:`secondary`,disabled:!ne||u,onClick:U,children:n.discard}),(0,Y.jsx)(K,{type:`button`,variant:`primary`,disabled:!ne||u,onClick:()=>void se(),children:u?n.saving:n.save})]})]}),ne?(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:Ue(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)(g,{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)(Re,{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:y,onChange:e=>x(e.target.value),placeholder:n.searchPlaceholder,autoComplete:`off`,className:b(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-10 pr-3 text-sm text-fg placeholder:text-fg-subtle`,Ce,`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:S,onChange:e=>C(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]}),le?(0,Y.jsx)(K,{type:`button`,variant:`ghost`,className:`h-9 w-fit self-start text-fg-muted`,onClick:()=>{x(``),C(!1)},children:n.clearFilters}):null]}),f?(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:f}):null,ie.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)(K,{type:`button`,variant:`secondary`,className:`mt-4`,onClick:()=>{x(``),C(!1)},children:n.clearFilters})]}):(0,Y.jsx)(`div`,{className:`flex flex-col gap-3`,children:gr.map(t=>{let r=ae.get(t)??[];if(r.length===0)return null;let i=_.has(t),o=r.filter(e=>e.configured).length,l=`providers-cat-${t}`;return(0,Y.jsxs)(`section`,{className:`overflow-hidden rounded-2xl bg-surface-base`,children:[(0,Y.jsxs)(`button`,{type:`button`,id:`${l}-trigger`,"aria-expanded":i,"aria-controls":l,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:()=>W(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)(Be,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}),vr(n.configuredCount,{count:String(o)})]}):null,(0,Y.jsx)(ye,{className:b(`size-4 text-fg-subtle transition-transform`,i&&`rotate-180`),"aria-hidden":!0})]})]}),i?(0,Y.jsx)(`div`,{id:l,role:`region`,"aria-labelledby":`${l}-trigger`,className:`divide-y divide-edge-subtle`,children:r.map(t=>(0,Y.jsx)(`div`,{id:`provider-row-${t.id}`,children:(0,Y.jsx)(xr,{row:t,value:a[t.id]??``,rowDirty:(a[t.id]??``)!==(c[t.id]??``),labels:n,language:e,onChange:(e,t)=>s(n=>({...n,[e]:t})),onReload:ce,justSaved:w.has(t.id),availableModels:te??[]})},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)(Ze,{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 Cr=[{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 wr(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 Tr(){let e=I(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)(()=>{A()&&l&&u()},[l,u]),!A()||!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)(Ct,{children:[(0,Y.jsxs)(`div`,{className:`mb-4 flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)(Ae,{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:Cr.map(({key:r,pane:o})=>{let s=wr(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)(N,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0})]})]})]},r):null})})]}):null]})}function Er(){return{enabled:!1,provider:`alibaba`,alibaba:{model:`paraformer-v2`},openai:{model:`whisper-1`},fallback:{enabled:!0,order:[`alibaba`,`openai`]}}}function Dr(){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 Or(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function kr(e){let t=Er();if(!Or(e))return t;let n=e.provider===`openai`?`openai`:`alibaba`,r=Or(e.alibaba)?{...t.alibaba,...e.alibaba}:t.alibaba,i=Or(e.openai)?{...t.openai,...e.openai}:t.openai,a=t.fallback??{enabled:!0,order:[`alibaba`,`openai`]};if(Or(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 Ar(e){return typeof e==`string`&&e.trim().length>0?e.trim():`openai`}function jr(e){let t=Dr();if(!Or(e))return t;let n=Ar(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:Or(e.alibaba)?{...t.alibaba,...e.alibaba}:t.alibaba,openai:Or(e.openai)?{...t.openai,...e.openai}:t.openai,edge:Or(e.edge)?{...t.edge,...e.edge}:t.edge,minimax:Or(e.minimax)?{...t.minimax,...e.minimax}:t.minimax,"tts-local-cli":Or(i)?{...t[`tts-local-cli`],...i}:t[`tts-local-cli`]}}function Mr(e){let t=Or(e)?e:{};return{stt:kr(t.stt),tts:jr(t.tts)}}async function Nr(e){await xe(q(`/api/config`),{method:`PATCH`,body:JSON.stringify({stt:e.stt,tts:e.tts})}),qe()}async function Pr(){let e=await xe(q(`/api/voice/models`));if(!e.payload?.models)throw Error(`Missing voice models payload`);return e.payload.models}function Fr(){return b(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,Ce,`dark:border-edge`)}function Ir(){return b(D,_)}var Lr=[{id:`paraformer-v2`,name:`Paraformer v2`},{id:`paraformer-v1`,name:`Paraformer v1`}],Rr=[{id:`whisper-1`,name:`Whisper-1`}],zr=[{id:`tts-1`,name:`TTS-1`},{id:`tts-1-hd`,name:`TTS-1 HD`}],Br=[{id:`alloy`,name:`Alloy`},{id:`echo`,name:`Echo`}],Vr=[{id:`qwen-tts`,name:`Qwen TTS`},{id:`qwen3-tts-flash`,name:`Qwen3 TTS Flash`}],Hr=[{id:`Cherry`,name:`Cherry`},{id:`longxiaochun`,name:`Long Xiao Chun`}],Ur=[{id:`en-US-MichelleNeural`,name:`Michelle (US English)`},{id:`zh-CN-XiaoxiaoNeural`,name:`Xiaoxiao (Chinese)`}],Wr=[{id:`speech-2.8-hd`,name:`Speech 2.8 HD (Recommended)`},{id:`speech-2.8-turbo`,name:`Speech 2.8 Turbo (Fast)`}],Gr=[{id:`male-qn-qingse`,name:`Male Qingse (青涩男声)`},{id:`female-shaonv`,name:`Female Shaonv (少女音)`}];function Kr(){let e=I(e=>e.language),t=o(e),n=t.voiceSettings,i=!!oe(e=>e.token),[a,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(null),[d,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}=R(i),{data:C,error:w,isLoading:T,mutate:E}=r(i?q(`/api/voice/models`):null,Pr,{revalidateOnFocus:!1}),D=(0,X.useMemo)(()=>y?.payload?.config===void 0?null:Mr(y.payload.config),[y]),O=(0,X.useMemo)(()=>!a||!l?!1:JSON.stringify(a)!==JSON.stringify(l),[a,l]);(0,X.useEffect)(()=>{if(!i){c(null),u(null),f(null);return}D===null||C===void 0||O||(c(structuredClone(D)),u(structuredClone(D)),f(C),v(!1))},[i,D,C,O]);let k=!!(i&&(D===null||C===void 0)&&(x||T)),A=b instanceof Error?b.message:b?String(b):w instanceof Error?w.message:w?String(w):null,j=(0,X.useCallback)(e=>{c(t=>t?{...t,stt:{...t.stt,...e}}:null)},[]),M=(0,X.useCallback)(e=>{c(t=>t?{...t,stt:{...t.stt,alibaba:{...t.stt.alibaba,...e}}}:null)},[]),ee=(0,X.useCallback)(e=>{c(t=>t?{...t,stt:{...t.stt,openai:{...t.stt.openai,...e}}}:null)},[]),P=(0,X.useCallback)(e=>{c(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=>{c(t=>t?{...t,tts:{...t.tts,...e}}:null)},[]),L=(0,X.useCallback)(e=>{c(t=>t?{...t,tts:{...t.tts,alibaba:{...t.tts.alibaba,...e}}}:null)},[]),te=(0,X.useCallback)(e=>{c(t=>t?{...t,tts:{...t.tts,openai:{...t.tts.openai,...e}}}:null)},[]),z=(0,X.useCallback)(e=>{c(t=>t?{...t,tts:{...t.tts,edge:{...t.tts.edge,...e}}}:null)},[]),B=(0,X.useCallback)(e=>{c(t=>t?{...t,tts:{...t.tts,minimax:{...t.tts.minimax,...e}}}:null)},[]),V=(0,X.useCallback)(e=>{c(t=>t?{...t,tts:{...t.tts,"tts-local-cli":{...t.tts[`tts-local-cli`],...e}}}:null)},[]),H=(0,X.useCallback)(async()=>{if(!(!a||p)){m(!0),g(null),v(!1);try{await Nr(a);let e=structuredClone(a);u(e),c(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]),ne=(0,X.useCallback)(()=>{l&&(c(structuredClone(l)),g(null),v(!1))},[l]);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)(s,{className:`size-4 animate-spin`}),n.loading]})});if(!a||d===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??A??n.loadError}),(0,Y.jsx)(K,{type:`button`,variant:`secondary`,onClick:()=>{S(),E()},children:n.retry})]});let re=a.stt,ie=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:Ue(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)(N,{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)(K,{type:`button`,variant:`secondary`,disabled:!O||p,onClick:ne,children:n.discard}),(0,Y.jsx)(K,{type:`button`,variant:`primary`,disabled:!O||p,onClick:()=>void H(),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)(qr,{v:n,stt:re,models:d,updateStt:j,updateSttAlibaba:M,updateSttOpenai:ee,updateSttFallback:P}),(0,Y.jsx)(Jr,{v:n,tts:ie,models:d,updateTts:F,updateTtsAlibaba:L,updateTtsOpenai:te,updateTtsEdge:z,updateTtsMinimax:B,updateTtsLocalCli:V})]}),(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 qr({v:e,stt:t,models:n,updateStt:r,updateSttAlibaba:i,updateSttOpenai:a,updateSttFallback:o}){let s=n?.stt?.alibaba?.length?n.stt.alibaba:Lr,c=n?.stt?.openai?.length?n.stt.openai:Rr;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)(d,{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:Ir(),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:b(Fr(),`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:Ir(),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:b(Fr(),`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:Ir(),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 Jr({v:e,tts:t,models:n,updateTts:r,updateTtsAlibaba:i,updateTtsOpenai:a,updateTtsEdge:o,updateTtsMinimax:s,updateTtsLocalCli:c}){let u=t=>t===`off`?e.tts.triggerDescOff:t===`always`?e.tts.triggerDescAlways:t===`inbound`?e.tts.triggerDescInbound:t===`tagged`?e.tts.triggerDescTagged:``,d=n?.tts?.openai?.length?n.tts.openai:zr,f=n?.ttsVoices?.openai?.length?n.ttsVoices.openai:Br,p=n?.tts?.alibaba?.length?n.tts.alibaba:Vr,m=n?.ttsVoices?.alibaba?.length?n.ttsVoices.alibaba:Hr,h=n?.ttsVoices?.edge?.length?n.ttsVoices.edge:Ur,g=n?.tts?.minimax?.length?n.tts.minimax:Wr,_=n?.ttsVoices?.minimax?.length?n.ttsVoices.minimax:Gr;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)(l,{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:Ir(),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:u(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:Ir(),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:b(Fr(),`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:Ir(),value:t.openai?.model??``,onChange:e=>a({model:e.target.value}),children:d.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:Ir(),value:t.openai?.voice??``,onChange:e=>a({voice:e.target.value}),children:f.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:b(Fr(),`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:Ir(),value:t.alibaba?.model??``,onChange:e=>i({model:e.target.value}),children:p.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:Ir(),value:t.alibaba?.voice??``,onChange:e=>i({voice:e.target.value}),children:m.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:b(Fr(),`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:Ir(),value:t.minimax?.model??``,onChange:e=>s({model:e.target.value}),children:g.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:Ir(),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:Ir(),value:t.edge?.voice??``,onChange:e=>o({voice:e.target.value}),children:h.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:b(Fr(),`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:b(Fr(),`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:Ir(),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:Fr(),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 Yr(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 Xr(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 xe(q(`/api/config`),{method:`PATCH`,body:JSON.stringify({tools:{web:{region:t,search:n}}})}),qe()}function Zr({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 Qr(){return b(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,Ce,`dark:border-edge`)}function $r(){return b(D,_)}var ei=[`brave`,`tavily`,`bing`,`searxng`];function ti(){return{type:`brave`,apiKey:``,url:``,disabled:!1}}function ni(){let e=I(e=>e.language),t=o(e),n=t.webSearchSettings,r=t.logs,i=!!oe(e=>e.token),[a,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(null),[d,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}=R(i),S=(0,X.useMemo)(()=>v?.payload?.config===void 0?null:Yr(v.payload.config),[v]);(0,X.useEffect)(()=>{if(!i){c(null),u(null),_.current=!1;return}S!==null&&(_.current||(c(S),u(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||!l?!1:JSON.stringify(a)!==JSON.stringify(l),[a,l]),E=(0,X.useCallback)(e=>{_.current=!0,c(t=>t?{...t,...e}:null)},[]),D=(0,X.useCallback)(async()=>{if(!(!a||d)){f(!0),m(null),g(!1);try{await Xr(a);let e=structuredClone(a);u(e),c(e),_.current=!1,g(!0),window.setTimeout(()=>g(!1),2500)}catch(e){m(e instanceof Error?e.message:n.saveError)}finally{f(!1)}}},[a,d,n.saveError]),O=(0,X.useCallback)(()=>{l&&(_.current=!1,c(structuredClone(l)),m(null),g(!1))},[l]);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)(s,{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:Ue(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)(N,{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)(K,{type:`button`,variant:`secondary`,disabled:!T||d,onClick:O,children:n.discard}),(0,Y.jsx)(K,{type:`button`,variant:`primary`,disabled:!T||d,onClick:()=>void D(),children:d?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)(Ct,{children:[(0,Y.jsx)(wt,{icon:Re,title:n.sectionRegion,subtitle:n.sectionRegionHint}),(0,Y.jsx)(`div`,{className:`flex max-w-md flex-col gap-4`,children:(0,Y.jsx)(Zr,{label:n.regionLabel,description:n.regionDesc,children:(0,Y.jsxs)(`select`,{className:$r(),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)(Ct,{children:[(0,Y.jsx)(wt,{icon:Re,title:n.sectionSearch,subtitle:n.sectionSearchHint}),(0,Y.jsxs)(`div`,{className:`flex max-w-xl flex-col gap-6`,children:[(0,Y.jsx)(Zr,{label:n.maxResultsLabel,description:n.maxResultsDesc,children:(0,Y.jsx)(`input`,{type:`number`,min:1,max:50,className:Qr(),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)(ri,{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)(K,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5 text-sm`,onClick:()=>E({providers:[...a.providers,ti()]}),children:[(0,Y.jsx)(Oe,{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)(K,{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 ri({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:b($r(),`min-w-[8rem]`),value:e.type,onChange:t=>n({...e,type:t.target.value,url:t.target.value===`searxng`?e.url:``}),children:ei.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)(K,{type:`button`,variant:`ghost`,className:`h-8 px-2 text-fg-muted`,onClick:r,children:(0,Y.jsx)(S,{className:`size-4`})})]})]}),e.type===`searxng`?(0,Y.jsx)(Zr,{label:t.urlLabel,description:t.urlDesc,children:(0,Y.jsx)(`input`,{type:`url`,className:Qr(),value:e.url,placeholder:`http://localhost:8080`,onChange:t=>n({...e,url:t.target.value})})}):null,(0,Y.jsx)(Zr,{label:t.apiKeyLabel,description:t.apiKeyDesc,children:(0,Y.jsx)(`input`,{type:`password`,autoComplete:`off`,className:Qr(),value:Me(e.apiKey)?``:e.apiKey,placeholder:Me(e.apiKey)?t.keyPlaceholderMasked:t.keyPlaceholder,onChange:t=>n({...e,apiKey:t.target.value})})})]})}var ii=[`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 ai(){let{section:e}=a(),t=I(e=>e.language),n=o(t);if(e===`agent`||e===`agents`)return(0,Y.jsx)(f,{to:`/agents`,replace:!0});if(!e||!ii.includes(e))return(0,Y.jsx)(f,{to:`/settings/appearance`,replace:!0});let r=e,i=n.settingsSections[r];return r===`appearance`?(0,Y.jsx)(Rt,{}):r===`system`?(0,Y.jsx)(Tr,{}):r===`agent-chat`?(0,Y.jsx)(gt,{}):r===`agent-workspace`?(0,Y.jsx)(_t,{}):r===`agent-browser`?(0,Y.jsx)(xt,{}):r===`agent-runtime`?(0,Y.jsx)(yt,{}):r===`agent-tools`?(0,Y.jsx)(st,{}):r===`agent-system-prompt`?(0,Y.jsx)(pt,{}):r===`providers`?(0,Y.jsx)(Sr,{}):r===`models`?(0,Y.jsx)(cr,{}):r===`image-models`?(0,Y.jsx)(Nn,{}):r===`voice`?(0,Y.jsx)(Kr,{}):r===`gateway`?(0,Y.jsx)(ln,{}):r===`heartbeat`?(0,Y.jsx)(bn,{}):r===`search`?(0,Y.jsx)(ni,{}):r===`dreams`?(0,Y.jsx)(nn,{}):(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{ai as SettingsPage};
|
|
2
|
+
//# sourceMappingURL=settings-page-D7-piKSc.js.map
|