@xopcai/xopc 0.0.66 → 0.0.67
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/telegram/xopc.extension.json +1 -1
- package/dist/gateway/static/root/assets/{agents-JiJR38n1.js → agents-CmhOU0fB.js} +2 -2
- package/dist/gateway/static/root/assets/{agents-JiJR38n1.js.map → agents-CmhOU0fB.js.map} +1 -1
- package/dist/gateway/static/root/assets/{apps-page-aBDyr7Im.js → apps-page-CzS9A_6L.js} +2 -2
- package/dist/gateway/static/root/assets/{apps-page-aBDyr7Im.js.map → apps-page-CzS9A_6L.js.map} +1 -1
- package/dist/gateway/static/root/assets/{channels-settings-DXxfgG4N.js → channels-settings-Bn0YSztA.js} +2 -2
- package/dist/gateway/static/root/assets/{channels-settings-DXxfgG4N.js.map → channels-settings-Bn0YSztA.js.map} +1 -1
- package/dist/gateway/static/root/assets/{cron-dreaming-jobs-3--QJSP5.js → cron-dreaming-jobs-bAYsiHdF.js} +2 -2
- package/dist/gateway/static/root/assets/{cron-dreaming-jobs-3--QJSP5.js.map → cron-dreaming-jobs-bAYsiHdF.js.map} +1 -1
- package/dist/gateway/static/root/assets/{cron-page-CCn-JwBy.js → cron-page-CKqDtScu.js} +2 -2
- package/dist/gateway/static/root/assets/{cron-page-CCn-JwBy.js.map → cron-page-CKqDtScu.js.map} +1 -1
- package/dist/gateway/static/root/assets/{dist-BS-cwfHQ.js → dist-CUMhnSuX.js} +2 -2
- package/dist/gateway/static/root/assets/{dist-BS-cwfHQ.js.map → dist-CUMhnSuX.js.map} +1 -1
- package/dist/gateway/static/root/assets/{extension-debug-page-M8JS4Jid.js → extension-debug-page-BDls5xp3.js} +2 -2
- package/dist/gateway/static/root/assets/{extension-debug-page-M8JS4Jid.js.map → extension-debug-page-BDls5xp3.js.map} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-C8gjVE_t.js → extension-page-BSfv53OO.js} +2 -2
- package/dist/gateway/static/root/assets/{extension-page-C8gjVE_t.js.map → extension-page-BSfv53OO.js.map} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-DeY2M2di.js → extension-settings-page-B0nkVsLi.js} +2 -2
- package/dist/gateway/static/root/assets/{extension-settings-page-DeY2M2di.js.map → extension-settings-page-B0nkVsLi.js.map} +1 -1
- package/dist/gateway/static/root/assets/{heartbeat-config-api-DWmeyjyR.js → heartbeat-config-api-P5zdbIBw.js} +2 -2
- package/dist/gateway/static/root/assets/{heartbeat-config-api-DWmeyjyR.js.map → heartbeat-config-api-P5zdbIBw.js.map} +1 -1
- package/dist/gateway/static/root/assets/{index-Cc57jhuG.js → index-DAglRwh4.js} +5 -5
- package/dist/gateway/static/root/assets/{index-Cc57jhuG.js.map → index-DAglRwh4.js.map} +1 -1
- package/dist/gateway/static/root/assets/index-DHj3Cf9B.css +1 -0
- package/dist/gateway/static/root/assets/{logs-page-kIsSDMqb.js → logs-page-CfGDv4k7.js} +2 -2
- package/dist/gateway/static/root/assets/{logs-page-kIsSDMqb.js.map → logs-page-CfGDv4k7.js.map} +1 -1
- package/dist/gateway/static/root/assets/{sessions-page-Da9gjMh7.js → sessions-page-DoGE8N-O.js} +2 -2
- package/dist/gateway/static/root/assets/{sessions-page-Da9gjMh7.js.map → sessions-page-DoGE8N-O.js.map} +1 -1
- package/dist/gateway/static/root/assets/settings-page-C5VrwDoO.js +3 -0
- package/dist/gateway/static/root/assets/settings-page-C5VrwDoO.js.map +1 -0
- package/dist/gateway/static/root/assets/{skills-page-B_msZcLx.js → skills-page-ADUi69Fa.js} +2 -2
- package/dist/gateway/static/root/assets/{skills-page-B_msZcLx.js.map → skills-page-ADUi69Fa.js.map} +1 -1
- package/dist/gateway/static/root/assets/{use-image-provider-credentials-Bs8xl2E3.js → use-image-provider-credentials-C4x4dNv2.js} +2 -2
- package/dist/gateway/static/root/assets/{use-image-provider-credentials-Bs8xl2E3.js.map → use-image-provider-credentials-C4x4dNv2.js.map} +1 -1
- package/dist/gateway/static/root/index.html +2 -2
- package/dist/package.js +1 -1
- package/dist/src/cli/commands/tunnel.js +69 -8
- package/dist/src/cli/commands/tunnel.js.map +1 -1
- package/dist/src/config/schema.d.ts +2 -0
- package/dist/src/config/schema.js +2 -0
- package/dist/src/config/schema.js.map +1 -1
- package/dist/src/gateway/hono/lib/config-payload.d.ts +2 -5
- package/dist/src/gateway/hono/lib/config-payload.js +3 -5
- package/dist/src/gateway/hono/lib/config-payload.js.map +1 -1
- package/dist/src/gateway/hono/routes/tunnel.js +12 -10
- package/dist/src/gateway/hono/routes/tunnel.js.map +1 -1
- package/dist/src/tunnel/acme-client.d.ts +11 -0
- package/dist/src/tunnel/acme-client.js +54 -10
- package/dist/src/tunnel/acme-client.js.map +1 -1
- package/dist/src/tunnel/env.d.ts +14 -3
- package/dist/src/tunnel/env.js +34 -5
- package/dist/src/tunnel/env.js.map +1 -1
- package/dist/src/tunnel/frpc-binary.d.ts +6 -1
- package/dist/src/tunnel/frpc-binary.js +66 -40
- package/dist/src/tunnel/frpc-binary.js.map +1 -1
- package/dist/src/tunnel/frpc-extract.d.ts +10 -0
- package/dist/src/tunnel/frpc-extract.js +129 -0
- package/dist/src/tunnel/frpc-extract.js.map +1 -0
- package/dist/src/tunnel/gateway-lifecycle.d.ts +3 -1
- package/dist/src/tunnel/gateway-lifecycle.js +6 -4
- package/dist/src/tunnel/gateway-lifecycle.js.map +1 -1
- package/dist/src/tunnel/index.d.ts +3 -1
- package/dist/src/tunnel/index.js +2 -2
- package/dist/src/tunnel/tls-server.js +5 -0
- package/dist/src/tunnel/tls-server.js.map +1 -1
- package/dist/src/tunnel/tunnel-config.js +11 -1
- package/dist/src/tunnel/tunnel-config.js.map +1 -1
- package/dist/src/tunnel/tunnel-e2e-config.d.ts +4 -1
- package/dist/src/tunnel/tunnel-e2e-config.js +10 -3
- package/dist/src/tunnel/tunnel-e2e-config.js.map +1 -1
- package/dist/src/tunnel/tunnel-service.d.ts +4 -0
- package/dist/src/tunnel/tunnel-service.js +66 -5
- package/dist/src/tunnel/tunnel-service.js.map +1 -1
- package/dist/src/tunnel/tunnel-types.d.ts +16 -0
- package/package.json +3 -3
- package/dist/gateway/static/root/assets/index-B5gp15_q.css +0 -1
- package/dist/gateway/static/root/assets/settings-page-B0spIRVS.js +0 -3
- package/dist/gateway/static/root/assets/settings-page-B0spIRVS.js.map +0 -1
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{a as t,n,t as r}from"./vendor-react-vzx_MT5D.js";import{a as i,i as a}from"./vendor-swr-CQnUjdeQ.js";import{$ as o,$r as s,Ai as c,Bi as l,Bn as u,Br as d,Bt as f,C as p,Cn as m,Cr as h,Dr as g,Ei as _,En as v,Er as y,Fn as b,Fr as x,Gn as S,Gt as C,Hn as w,Ht as T,In as E,Jn as D,Jt as O,Kt as k,Ln as A,Mi as j,Mn as M,Mr as N,Mt as P,Nn as F,Nt as I,Oi as L,On as R,Pr as z,Q as B,Qr as V,Ri as H,Rn as U,Rr as W,Rt as G,S as ee,Si as te,Sn as K,Sr as q,Ti as ne,Tn as J,Tr as re,Ui as ie,Ut as ae,Vn as oe,Vr as Y,Vt as se,Wt as ce,Xn as le,Xr as ue,Xt as de,Yn as fe,Yt as pe,Z as me,Zn as he,Zr as ge,_ as _e,_i as ve,a as ye,ai as be,b as xe,bi as Se,ci as Ce,dr as we,ei as Te,et as Ee,g as De,gr as Oe,h as ke,it as Ae,jn as je,ki as Me,kn as Ne,kr as Pe,l as Fe,li as Ie,lr as Le,m as Re,mi as ze,mr as Be,nr as Ve,nt as He,or as Ue,ot as We,pi as Ge,pr as Ke,qn as X,qt as qe,rr as Je,rt as Ye,s as Xe,si as Ze,t as Qe,tt as $e,u as et,ur as tt,v as nt,vi as rt,vr as it,w as at,wi as ot,wn as st,x as ct,xn as lt,xr as ut,y as dt,yn as ft,zi as pt,zn as mt,zr as ht,zt as gt}from"./index-DAglRwh4.js";import{i as _t,n as vt,r as yt,t as bt}from"./use-image-provider-credentials-C4x4dNv2.js";import{E as xt,S as St,f as Ct,r as wt,s as Tt}from"./cron-dreaming-jobs-bAYsiHdF.js";import{_ as Et,a as Dt,b as Ot,c as kt,d as At,f as jt,g as Mt,h as Nt,i as Pt,l as Ft,m as It,n as Lt,o as Rt,p as zt,r as Bt,s as Vt,t as Ht,u as Ut,v as Wt,x as Gt,y as Kt}from"./agents-CmhOU0fB.js";import{t as qt}from"./browser-DNXWYwzc.js";import{a as Jt,i as Yt,n as Xt,o as Zt,r as Qt,s as $t,t as en}from"./heartbeat-config-api-P5zdbIBw.js";var Z=n(),Q=r();function tn(){return X(`rounded-xl border border-edge-subtle bg-surface-base px-4 py-1 sm:px-5`)}var nn={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`}},clay:{light:{canvas:`#fffaf0`,panel:`#ffffff`,accent:`#1a3a3a`,fg:`#0a0a0a`,muted:`#e5e5e5`},dark:{canvas:`#0a1a1a`,panel:`#1a2a2a`,accent:`#ffb084`,fg:`#fffaf0`,muted:`#2a3a3a`}}};function rn(e){let t=(0,Z.c)(24),{canvas:n,panel:r,accent:i,fg:a,muted:o}=e,s;t[0]===n?s=t[1]:(s={backgroundColor:n},t[0]=n,t[1]=s);let c;t[2]!==o||t[3]!==r?(c={backgroundColor:r,borderColor:o},t[2]=o,t[3]=r,t[4]=c):c=t[4];let l;t[5]===i?l=t[6]:(l=(0,Q.jsx)(`div`,{className:`size-1 shrink-0 rounded-full`,style:{backgroundColor:i}}),t[5]=i,t[6]=l);let u;t[7]===a?u=t[8]:(u=(0,Q.jsx)(`div`,{className:`h-1 min-w-0 flex-1 rounded-full`,style:{backgroundColor:a,opacity:.85}}),t[7]=a,t[8]=u);let d;t[9]!==l||t[10]!==u?(d=(0,Q.jsxs)(`div`,{className:`flex items-center gap-1`,children:[l,u]}),t[9]=l,t[10]=u,t[11]=d):d=t[11];let f;t[12]===o?f=t[13]:(f=(0,Q.jsx)(`div`,{className:`h-1 w-2/3 max-w-[70%] rounded-full`,style:{backgroundColor:o}}),t[12]=o,t[13]=f);let p;t[14]===o?p=t[15]:(p=(0,Q.jsx)(`div`,{className:`size-1/2 max-w-[55%] rounded-full`,style:{backgroundColor:o}}),t[14]=o,t[15]=p);let m;t[16]!==c||t[17]!==d||t[18]!==f||t[19]!==p?(m=(0,Q.jsxs)(`div`,{className:`flex flex-col gap-0.5 rounded-sm border p-1`,style:c,children:[d,f,p]}),t[16]=c,t[17]=d,t[18]=f,t[19]=p,t[20]=m):m=t[20];let h;return t[21]!==s||t[22]!==m?(h=(0,Q.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col justify-center gap-1 p-1.5`,style:s,children:m}),t[21]=s,t[22]=m,t[23]=h):h=t[23],h}function an(e){let t=(0,Z.c)(8),{scheme:n}=e,{light:r,dark:i}=nn[n],a;t[0]===r?a=t[1]:(a=(0,Q.jsx)(rn,{...r}),t[0]=r,t[1]=a);let o;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(o=(0,Q.jsx)(`div`,{className:`w-px shrink-0 bg-black/12 dark:bg-white/12`,"aria-hidden":!0}),t[2]=o):o=t[2];let s;t[3]===i?s=t[4]:(s=(0,Q.jsx)(rn,{...i}),t[3]=i,t[4]=s);let c;return t[5]!==a||t[6]!==s?(c=(0,Q.jsxs)(`div`,{className:`flex h-11 w-full overflow-hidden rounded-md border border-edge-subtle`,children:[a,o,s]}),t[5]=a,t[6]=s,t[7]=c):c=t[7],c}var on=[{value:`default`,labelKey:`colorSchemeDefault`},{value:`emerald`,labelKey:`colorSchemeLightGreen`},{value:`mono`,labelKey:`colorSchemeModernMono`},{value:`clay`,labelKey:`colorSchemeClay`}];function sn(){let e=(0,Z.c)(18),t=F(un),n;e[0]===t?n=e[1]:(n=oe(t),e[0]=t,e[1]=n);let r=n.appearanceSettings,i=M(ln),a=M(cn),o;e[2]===r.colorSchemeTitle?o=e[3]:(o=(0,Q.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:r.colorSchemeTitle}),e[2]=r.colorSchemeTitle,e[3]=o);let s;e[4]===r.colorSchemeDescription?s=e[5]:(s=(0,Q.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:r.colorSchemeDescription}),e[4]=r.colorSchemeDescription,e[5]=s);let c;e[6]!==o||e[7]!==s?(c=(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[o,s]}),e[6]=o,e[7]=s,e[8]=c):c=e[8];let l;e[9]!==r||e[10]!==i||e[11]!==a?(l=on.map(e=>{let{value:t,labelKey:n}=e,o=i===t;return(0,Q.jsxs)(`button`,{type:`button`,"aria-pressed":o,onClick:()=>a(t),className:X(`flex flex-col gap-2 rounded-xl border-2 p-2.5 text-left transition-[border-color,box-shadow] duration-150`,o?`border-accent shadow-[0_0_0_1px_var(--color-accent)]`:`border-edge-subtle hover:border-edge`),children:[(0,Q.jsx)(an,{scheme:t}),(0,Q.jsx)(`span`,{className:X(`text-xs font-medium leading-none`,o?`text-accent-fg`:`text-fg-muted`),children:r[n]})]},t)}),e[9]=r,e[10]=i,e[11]=a,e[12]=l):l=e[12];let u;e[13]===l?u=e[14]:(u=(0,Q.jsx)(`div`,{className:`grid grid-cols-2 gap-3 lg:grid-cols-4`,children:l}),e[13]=l,e[14]=u);let d;return e[15]!==c||e[16]!==u?(d=(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2 border-b border-edge-subtle py-3.5 last:border-b-0 sm:py-4`,children:[c,u]}),e[15]=c,e[16]=u,e[17]=d):d=e[17],d}function cn(e){return e.setColorScheme}function ln(e){return e.colorScheme}function un(e){return e.language}function dn(){let e=(0,Z.c)(26),t=F(fn),n;e[0]===t?n=e[1]:(n=oe(t),e[0]=t,e[1]=n);let r=n.appearanceSettings,i;e[2]===r.pageTitle?i=e[3]:(i=(0,Q.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight text-fg`,children:r.pageTitle}),e[2]=r.pageTitle,e[3]=i);let a;e[4]===r.subtitle?a=e[5]:(a=(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:r.subtitle}),e[4]=r.subtitle,e[5]=a);let o;e[6]!==i||e[7]!==a?(o=(0,Q.jsxs)(`header`,{className:`flex flex-col gap-1`,children:[i,a]}),e[6]=i,e[7]=a,e[8]=o):o=e[8];let s;e[9]===Symbol.for(`react.memo_cache_sentinel`)?(s=tn(),e[9]=s):s=e[9];let c;e[10]===r.languageTitle?c=e[11]:(c=(0,Q.jsx)(`h2`,{id:`pref-language-heading`,className:`sr-only`,children:r.languageTitle}),e[10]=r.languageTitle,e[11]=c);let l;e[12]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,Q.jsx)(je,{variant:`page`,sections:[`language`]}),e[12]=l):l=e[12];let u;e[13]===c?u=e[14]:(u=(0,Q.jsxs)(`section`,{className:s,"aria-labelledby":`pref-language-heading`,children:[c,l]}),e[13]=c,e[14]=u);let d;e[15]===Symbol.for(`react.memo_cache_sentinel`)?(d=tn(),e[15]=d):d=e[15];let f;e[16]===r.themeTitle?f=e[17]:(f=(0,Q.jsx)(`h2`,{id:`pref-appearance-heading`,className:`sr-only`,children:r.themeTitle}),e[16]=r.themeTitle,e[17]=f);let p,m;e[18]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,Q.jsx)(je,{variant:`page`,sections:[`theme`,`font`]}),m=(0,Q.jsx)(sn,{}),e[18]=p,e[19]=m):(p=e[18],m=e[19]);let h;e[20]===f?h=e[21]:(h=(0,Q.jsxs)(`section`,{className:d,"aria-labelledby":`pref-appearance-heading`,children:[f,p,m]}),e[20]=f,e[21]=h);let g;return e[22]!==h||e[23]!==o||e[24]!==u?(g=(0,Q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[o,u,h]}),e[22]=h,e[23]=o,e[24]=u,e[25]=g):g=e[25],g}function fn(e){return e.language}var $=e(t(),1);function pn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var mn={enabled:!0,cron:`0 */6 * * *`,lookbackDays:1,limit:50,dedupeSimilarity:.85},hn={enabled:!0,cron:`0 3 * * *`,minScore:.8,minRecallCount:3,limit:10,recencyHalfLifeDays:14,maxAgeDays:30},gn={enabled:!0,cron:`0 5 * * 0`,lookbackDays:7,limit:20,minPatternStrength:.6},_n={enabled:!1,frequency:`0 3 * * *`,timezone:``,deepEnabled:!0,minScore:.8,minRecallCount:3,limit:10,light:mn,deep:hn,rem:gn};function vn(e,t){return Number.isFinite(e)?Math.max(0,Math.min(1,e)):t}function yn(e,t){let n=typeof e==`string`?Number(e):e;return Number.isFinite(n)?Math.max(0,Math.floor(n)):t}function bn(e,t){let n=typeof e==`string`?Number(e):e;return Number.isFinite(n)?n:t}function xn(e){let t=pn(e)?e:{},n=pn(t.agents)?t.agents:{},r=pn(n.defaults)?n.defaults:{},i=pn(r.memory)?r.memory:{},a=pn(i.dreaming)?i.dreaming:{},o=pn(a.phases)?a.phases:{},s=pn(o.light)?o.light:{},c=pn(o.deep)?o.deep:{},l=pn(o.rem)?o.rem:{};return{enabled:a.enabled===!0,frequency:typeof a.frequency==`string`&&a.frequency.trim()?a.frequency.trim():_n.frequency,timezone:typeof a.timezone==`string`?a.timezone:``,deepEnabled:c.enabled!==!1,minScore:vn(typeof c.minScore==`number`?c.minScore:Number(c.minScore),_n.minScore),minRecallCount:Math.max(1,yn(c.minRecallCount,_n.minRecallCount)),limit:yn(c.limit,_n.limit),light:{enabled:s.enabled!==!1,cron:typeof s.cron==`string`&&s.cron.trim()?s.cron.trim():mn.cron,lookbackDays:Math.max(1,yn(s.lookbackDays,mn.lookbackDays)),limit:yn(s.limit,mn.limit),dedupeSimilarity:vn(bn(s.dedupeSimilarity,mn.dedupeSimilarity),mn.dedupeSimilarity)},deep:{enabled:c.enabled!==!1,cron:typeof c.cron==`string`&&c.cron.trim()?c.cron.trim():hn.cron,minScore:vn(bn(c.minScore,hn.minScore),hn.minScore),minRecallCount:Math.max(1,yn(c.minRecallCount,hn.minRecallCount)),limit:yn(c.limit,hn.limit),recencyHalfLifeDays:Math.max(1,bn(c.recencyHalfLifeDays,hn.recencyHalfLifeDays)),maxAgeDays:Math.max(1,bn(c.maxAgeDays,hn.maxAgeDays))},rem:{enabled:l.enabled!==!1,cron:typeof l.cron==`string`&&l.cron.trim()?l.cron.trim():gn.cron,lookbackDays:Math.max(1,yn(l.lookbackDays,gn.lookbackDays)),limit:yn(l.limit,gn.limit),minPatternStrength:vn(bn(l.minPatternStrength,gn.minPatternStrength),gn.minPatternStrength)}}}async function Sn(e){let t=e.frequency.trim(),n=e.timezone.trim();await v(lt(`/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:vn(e.light.dedupeSimilarity,mn.dedupeSimilarity)},deep:{enabled:!!e.deep.enabled,cron:e.deep.cron.trim()||null,minScore:vn(e.deep.minScore,hn.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:vn(e.rem.minPatternStrength,gn.minPatternStrength)}}}}}}})}),P()}var Cn=X(`h-9 min-w-0 flex-1 rounded-lg border border-edge-subtle bg-surface-panel px-2.5 py-1.5 text-sm tabular-nums text-fg`,E),wn=X(mt,`h-9 max-w-[11rem] shrink-0 text-xs sm:max-w-[12rem]`);function Tn(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 En({valueMs:e,onChangeMs:t,labels:n,disabled:r,presets:i=wt,minSeconds:a=1}){let o=(0,$.useMemo)(()=>new Set(i),[i]),s=(0,$.useMemo)(()=>o.has(e)?String(e):``,[o,e]),[c,l]=(0,$.useState)(null),u=(0,$.useRef)(e);u.current!==e&&(u.current=e,l(null));let d=Math.max(a,Math.round(e/1e3)),f=c===null?String(d):c;return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Q.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:n.secondsLabel}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`input`,{type:`number`,min:a,step:1,disabled:r,className:Cn,value:f,onChange:e=>{let n=e.target.value;l(n);let r=parseInt(n,10);Number.isFinite(r)&&r>=a&&t(r*1e3)},onBlur:()=>{if(c===null)return;let e=parseInt(c,10);t(!Number.isFinite(e)||e<a?a*1e3:e*1e3),l(null)}}),(0,Q.jsxs)(`select`,{className:wn,disabled:r,value:s,onChange:e=>{let n=e.target.value;n&&(t(parseInt(n,10)),l(null))},children:[(0,Q.jsx)(`option`,{value:``,children:n.presets.custom}),i.map(e=>(0,Q.jsx)(`option`,{value:String(e),children:Tn(e,n.presets)},e))]})]})]})}var Dn=X(`mt-1 w-full rounded-lg border border-edge-subtle bg-surface-panel px-2.5 py-1.5 text-sm text-fg`,E),On=()=>({start:`09:00`,end:`22:00`,timezone:``});function kn(e){let t=(0,Z.c)(55),{value:n,onChange:r,labels:i,disabled:a}=e;if(!n){let e;t[0]===r?e=t[1]:(e=()=>r(On()),t[0]=r,t[1]=e);let n;return t[2]!==a||t[3]!==i.add||t[4]!==e?(n=(0,Q.jsx)(w,{type:`button`,variant:`secondary`,className:`text-sm`,disabled:a,onClick:e,children:i.add}),t[2]=a,t[3]=i.add,t[4]=e,t[5]=n):n=t[5],n}let o;t[6]===i.start?o=t[7]:(o=(0,Q.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:i.start}),t[6]=i.start,t[7]=o);let s;t[8]!==r||t[9]!==n?(s=e=>r({...n,start:e.target.value}),t[8]=r,t[9]=n,t[10]=s):s=t[10];let c;t[11]!==a||t[12]!==s||t[13]!==n.start?(c=(0,Q.jsx)(`input`,{type:`time`,step:60,disabled:a,className:Dn,value:n.start,onChange:s}),t[11]=a,t[12]=s,t[13]=n.start,t[14]=c):c=t[14];let l;t[15]!==o||t[16]!==c?(l=(0,Q.jsxs)(`label`,{className:`block min-w-0`,children:[o,c]}),t[15]=o,t[16]=c,t[17]=l):l=t[17];let u;t[18]===i.end?u=t[19]:(u=(0,Q.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:i.end}),t[18]=i.end,t[19]=u);let d;t[20]!==r||t[21]!==n?(d=e=>r({...n,end:e.target.value}),t[20]=r,t[21]=n,t[22]=d):d=t[22];let f;t[23]!==a||t[24]!==d||t[25]!==n.end?(f=(0,Q.jsx)(`input`,{type:`time`,step:60,disabled:a,className:Dn,value:n.end,onChange:d}),t[23]=a,t[24]=d,t[25]=n.end,t[26]=f):f=t[26];let p;t[27]!==u||t[28]!==f?(p=(0,Q.jsxs)(`label`,{className:`block min-w-0`,children:[u,f]}),t[27]=u,t[28]=f,t[29]=p):p=t[29];let m;t[30]===i.timezone?m=t[31]:(m=(0,Q.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:i.timezone}),t[30]=i.timezone,t[31]=m);let h;t[32]!==r||t[33]!==n?(h=e=>r({...n,timezone:e.target.value}),t[32]=r,t[33]=n,t[34]=h):h=t[34];let g;t[35]!==a||t[36]!==h||t[37]!==n.timezone?(g=(0,Q.jsx)(`input`,{type:`text`,disabled:a,className:Dn,value:n.timezone,onChange:h,placeholder:`Asia/Shanghai`,autoComplete:`off`}),t[35]=a,t[36]=h,t[37]=n.timezone,t[38]=g):g=t[38];let _;t[39]!==g||t[40]!==m?(_=(0,Q.jsxs)(`label`,{className:`block min-w-0`,children:[m,g]}),t[39]=g,t[40]=m,t[41]=_):_=t[41];let v;t[42]!==_||t[43]!==l||t[44]!==p?(v=(0,Q.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-3`,children:[l,p,_]}),t[42]=_,t[43]=l,t[44]=p,t[45]=v):v=t[45];let y;t[46]===r?y=t[47]:(y=()=>r(null),t[46]=r,t[47]=y);let b;t[48]!==a||t[49]!==i.clear||t[50]!==y?(b=(0,Q.jsx)(w,{type:`button`,variant:`secondary`,className:`text-xs`,disabled:a,onClick:y,children:i.clear}),t[48]=a,t[49]=i.clear,t[50]=y,t[51]=b):b=t[51];let x;return t[52]!==v||t[53]!==b?(x=(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[v,b]}),t[52]=v,t[53]=b,t[54]=x):x=t[54],x}function An(e){let t=(0,Z.c)(34),{disabled:n,label:r,hint:i,className:a}=e,o;t[0]===a?o=t[1]:(o=X(`flex flex-col gap-2`,a),t[0]=a,t[1]=o);let s;t[2]===r?s=t[3]:(s=r?(0,Q.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:r}):null,t[2]=r,t[3]=s);let c;t[4]!==n||t[5]!==r||t[6]!==e.kind||t[7]!==e.labels||t[8]!==e.onChange||t[9]!==e.value?(c=e.kind===`cron`?(0,Q.jsx)($t,{value:e.value,onChange:e.onChange,labels:e.labels,disabled:n,showHeading:!r}):null,t[4]=n,t[5]=r,t[6]=e.kind,t[7]=e.labels,t[8]=e.onChange,t[9]=e.value,t[10]=c):c=t[10];let l;t[11]!==n||t[12]!==e.kind||t[13]!==e.labels||t[14]!==e.minSeconds||t[15]!==e.onChangeMs||t[16]!==e.presets||t[17]!==e.valueMs?(l=e.kind===`interval`?(0,Q.jsx)(En,{valueMs:e.valueMs,onChangeMs:e.onChangeMs,labels:e.labels,disabled:n,presets:e.presets??wt,minSeconds:e.minSeconds}):null,t[11]=n,t[12]=e.kind,t[13]=e.labels,t[14]=e.minSeconds,t[15]=e.onChangeMs,t[16]=e.presets,t[17]=e.valueMs,t[18]=l):l=t[18];let u;t[19]!==n||t[20]!==e.kind||t[21]!==e.labels||t[22]!==e.onChange||t[23]!==e.value?(u=e.kind===`active-hours`?(0,Q.jsx)(kn,{value:e.value,onChange:e.onChange,labels:e.labels,disabled:n}):null,t[19]=n,t[20]=e.kind,t[21]=e.labels,t[22]=e.onChange,t[23]=e.value,t[24]=u):u=t[24];let d;t[25]===i?d=t[26]:(d=i?(0,Q.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:i}):null,t[25]=i,t[26]=d);let f;return t[27]!==o||t[28]!==s||t[29]!==c||t[30]!==l||t[31]!==u||t[32]!==d?(f=(0,Q.jsxs)(`div`,{className:o,children:[s,c,l,u,d]}),t[27]=o,t[28]=s,t[29]=c,t[30]=l,t[31]=u,t[32]=d,t[33]=f):f=t[33],f}var jn=`p-4 sm:px-5`,Mn=`mb-3`,Nn=`rounded-xl border border-edge-subtle bg-surface-panel/30 p-3 sm:p-4`,Pn=X(`mt-1 w-full rounded-lg border border-edge-subtle bg-surface-panel px-2.5 py-1.5 text-sm text-fg`,E),Fn=`text-xs font-medium text-fg-muted`,In=`text-sm font-medium text-fg`;function Ln(e){let t=(0,Z.c)(6),{label:n,children:r,className:i}=e,a;t[0]===n?a=t[1]:(a=(0,Q.jsx)(`span`,{className:Fn,children:n}),t[0]=n,t[1]=a);let o;return t[2]!==r||t[3]!==i||t[4]!==a?(o=(0,Q.jsxs)(`div`,{className:i,children:[a,r]}),t[2]=r,t[3]=i,t[4]=a,t[5]=o):o=t[5],o}function Rn(e){let t=(0,Z.c)(11),{label:n,children:r,className:i}=e,a;t[0]===i?a=t[1]:(a=X(`min-w-0`,i),t[0]=i,t[1]=a);let o;t[2]===n?o=t[3]:(o=(0,Q.jsx)(`dt`,{className:Fn,children:n}),t[2]=n,t[3]=o);let s;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(s=X(In,`mt-0.5`),t[4]=s):s=t[4];let c;t[5]===r?c=t[6]:(c=(0,Q.jsx)(`dd`,{className:s,children:r}),t[5]=r,t[6]=c);let l;return t[7]!==a||t[8]!==o||t[9]!==c?(l=(0,Q.jsxs)(`div`,{className:a,children:[o,c]}),t[7]=a,t[8]=o,t[9]=c,t[10]=l):l=t[10],l}function zn(e){let t=(0,Z.c)(5),{label:n,className:r}=e,i;t[0]===r?i=t[1]:(i=X(`text-[0.7rem] font-semibold uppercase tracking-wider text-fg-muted`,r),t[0]=r,t[1]=i);let a;return t[2]!==n||t[3]!==i?(a=(0,Q.jsx)(`h3`,{className:i,children:n}),t[2]=n,t[3]=i,t[4]=a):a=t[4],a}function Bn(e){return e?e.replace(`T`,` `).replace(`Z`,``):`—`}function Vn(e){return e===void 0||!Number.isFinite(e)||e<0?`—`:e<1e3?`${Math.round(e)} ms`:`${(e/1e3).toFixed(2)} s`}function Hn(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 Un(e){let t=(0,Z.c)(38),{icon:n,title:r,hint:i,enabled:a,onEnabledChange:o,cron:s,onCronChange:c,scheduleLabels:l,disabled:u,onLabel:d,offLabel:f,cronLabel:p,children:m}=e,h;t[0]===n?h=t[1]:(h=(0,Q.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:n}),t[0]=n,t[1]=h);let g;t[2]===r?g=t[3]:(g=(0,Q.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:r}),t[2]=r,t[3]=g);let _;t[4]===i?_=t[5]:(_=(0,Q.jsx)(`p`,{className:`mt-0.5 text-xs leading-snug text-fg-muted`,children:i}),t[4]=i,t[5]=_);let v;t[6]!==g||t[7]!==_?(v=(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[g,_]}),t[6]=g,t[7]=_,t[8]=v):v=t[8];let y;t[9]!==h||t[10]!==v?(y=(0,Q.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2`,children:[h,v]}),t[9]=h,t[10]=v,t[11]=y):y=t[11];let b;t[12]===o?b=t[13]:(b=e=>o(e.target.checked),t[12]=o,t[13]=b);let x;t[14]!==u||t[15]!==a||t[16]!==b?(x=(0,Q.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:a,disabled:u,onChange:b}),t[14]=u,t[15]=a,t[16]=b,t[17]=x):x=t[17];let S=a?d:f,C;t[18]===S?C=t[19]:(C=(0,Q.jsx)(`span`,{children:S}),t[18]=S,t[19]=C);let w;t[20]!==x||t[21]!==C?(w=(0,Q.jsxs)(`label`,{className:`inline-flex shrink-0 items-center gap-2 text-xs text-fg`,children:[x,C]}),t[20]=x,t[21]=C,t[22]=w):w=t[22];let T;t[23]!==w||t[24]!==y?(T=(0,Q.jsxs)(`div`,{className:`mb-2.5 flex flex-wrap items-start justify-between gap-2 border-b border-edge-subtle/80 pb-2.5`,children:[y,w]}),t[23]=w,t[24]=y,t[25]=T):T=t[25];let E;t[26]!==s||t[27]!==p||t[28]!==u||t[29]!==c||t[30]!==l?(E=(0,Q.jsx)(An,{kind:`cron`,className:`mb-2.5`,label:p,value:s,onChange:c,labels:l,disabled:u}),t[26]=s,t[27]=p,t[28]=u,t[29]=c,t[30]=l,t[31]=E):E=t[31];let D;t[32]===m?D=t[33]:(D=(0,Q.jsx)(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-3 lg:grid-cols-4`,children:m}),t[32]=m,t[33]=D);let O;return t[34]!==T||t[35]!==E||t[36]!==D?(O=(0,Q.jsxs)(`div`,{className:Nn,children:[T,E,D]}),t[34]=T,t[35]=E,t[36]=D,t[37]=O):O=t[37],O}function Wn(e){let t=(0,Z.c)(23),{icon:n,label:r,enabled:i,cron:a,scheduleSummary:o,details:s,t:c}=e,l;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(l=X(Nn,`space-y-1`),t[0]=l):l=t[0];let u;t[1]===r?u=t[2]:(u=(0,Q.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:r}),t[1]=r,t[2]=u);let d=i?`text-emerald-600 dark:text-emerald-400`:`text-fg-muted`,f;t[3]===d?f=t[4]:(f=X(`ml-auto text-xs font-medium`,d),t[3]=d,t[4]=f);let p=i?c.on:c.off,m;t[5]!==f||t[6]!==p?(m=(0,Q.jsx)(`span`,{className:f,children:p}),t[5]=f,t[6]=p,t[7]=m):m=t[7];let h;t[8]!==n||t[9]!==u||t[10]!==m?(h=(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n,u,m]}),t[8]=n,t[9]=u,t[10]=m,t[11]=h):h=t[11];let g;t[12]===o?g=t[13]:(g=(0,Q.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:o}),t[12]=o,t[13]=g);let _;t[14]===a?_=t[15]:(_=(0,Q.jsx)(`p`,{className:`truncate font-mono text-[0.65rem] text-fg-subtle`,title:a,children:a}),t[14]=a,t[15]=_);let v;t[16]===s?v=t[17]:(v=(0,Q.jsx)(`p`,{className:`text-[0.65rem] leading-snug text-fg-muted`,children:s}),t[16]=s,t[17]=v);let y;return t[18]!==v||t[19]!==h||t[20]!==g||t[21]!==_?(y=(0,Q.jsxs)(`div`,{className:l,children:[h,g,_,v]}),t[18]=v,t[19]=h,t[20]=g,t[21]=_,t[22]=y):y=t[22],y}function Gn(e){let t=(0,Z.c)(9),{label:n,lastRun:r,t:i}=e,a;t[0]===n?a=t[1]:(a=(0,Q.jsx)(zn,{label:n,className:`mb-2`}),t[0]=n,t[1]=a);let o;t[2]!==r||t[3]!==i.lastRunRaw||t[4]!==i.phaseLastRunEmpty?(o=r?.exists?(0,Q.jsxs)(`details`,{className:`group rounded-lg border border-edge-subtle`,children:[(0,Q.jsx)(`summary`,{className:`cursor-pointer list-none px-2.5 py-1.5 text-xs font-medium text-fg-muted marker:hidden [&::-webkit-details-marker]:hidden`,children:(0,Q.jsx)(`span`,{className:`underline decoration-edge underline-offset-2 group-open:text-fg`,children:i.lastRunRaw})}),(0,Q.jsx)(`pre`,{className:`max-h-40 overflow-auto border-t border-edge-subtle p-2.5 text-xs text-fg-muted`,children:JSON.stringify(r.raw,null,2)})]}):(0,Q.jsx)(`p`,{className:`text-xs text-fg-muted`,children:i.phaseLastRunEmpty}),t[2]=r,t[3]=i.lastRunRaw,t[4]=i.phaseLastRunEmpty,t[5]=o):o=t[5];let s;return t[6]!==a||t[7]!==o?(s=(0,Q.jsxs)(`div`,{className:`border-t border-edge-subtle/80 pt-3`,children:[a,o]}),t[6]=a,t[7]=o,t[8]=s):s=t[8],s}function Kn(e){let t=(0,Z.c)(39),{t:n,r}=e,i=r.deep?.skipped,a=r.ok?`text-emerald-600 dark:text-emerald-400`:`text-amber-600 dark:text-amber-400`,o=r.ok?n.lastRunSuccess:n.lastRunFailure,s;t[0]!==a||t[1]!==o?(s=(0,Q.jsx)(`span`,{className:a,children:o}),t[0]=a,t[1]=o,t[2]=s):s=t[2];let c;t[3]!==n.lastRunStatus||t[4]!==s?(c=(0,Q.jsx)(Rn,{label:n.lastRunStatus,children:s}),t[3]=n.lastRunStatus,t[4]=s,t[5]=c):c=t[5];let l=n.lastRunDuration,u;t[6]===r.durationMs?u=t[7]:(u=Vn(r.durationMs),t[6]=r.durationMs,t[7]=u);let d;t[8]!==n.lastRunDuration||t[9]!==u?(d=(0,Q.jsx)(Rn,{label:l,children:u}),t[8]=n.lastRunDuration,t[9]=u,t[10]=d):d=t[10];let f=n.lastRunRanked,p=String(r.deep?.candidatesRanked??`—`),m;t[11]!==n.lastRunRanked||t[12]!==p?(m=(0,Q.jsx)(Rn,{label:f,children:p}),t[11]=n.lastRunRanked,t[12]=p,t[13]=m):m=t[13];let h=n.lastRunApplied,g=String(r.deep?.applied??`—`),_;t[14]!==n.lastRunApplied||t[15]!==g?(_=(0,Q.jsx)(Rn,{label:h,children:g}),t[14]=n.lastRunApplied,t[15]=g,t[16]=_):_=t[16];let v;t[17]===r.reason?v=t[18]:(v=(0,Q.jsx)(`span`,{className:`block text-pretty`,children:r.reason}),t[17]=r.reason,t[18]=v);let y;t[19]!==r.errorMessage||t[20]!==n.lastRunError?(y=r.errorMessage?(0,Q.jsx)(`span`,{className:`mt-1 block text-xs text-amber-600 dark:text-amber-400`,children:`${n.lastRunError}: ${r.errorMessage}`}):null,t[19]=r.errorMessage,t[20]=n.lastRunError,t[21]=y):y=t[21];let b;t[22]!==n.lastRunReason||t[23]!==v||t[24]!==y?(b=(0,Q.jsxs)(Rn,{label:n.lastRunReason,className:`col-span-2 sm:col-span-3 lg:col-span-4`,children:[v,y]}),t[22]=n.lastRunReason,t[23]=v,t[24]=y,t[25]=b):b=t[25];let x;t[26]!==i||t[27]!==n.lastRunSkipContaminated||t[28]!==n.lastRunSkipHash||t[29]!==n.lastRunSkipKey||t[30]!==n.lastRunSkipRehydrate?(x=i?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Rn,{label:n.lastRunSkipKey,children:String(i.alreadyPromotedKey)}),(0,Q.jsx)(Rn,{label:n.lastRunSkipRehydrate,children:String(i.rehydrateFailed)}),(0,Q.jsx)(Rn,{label:n.lastRunSkipContaminated,children:String(i.contaminated)}),(0,Q.jsx)(Rn,{label:n.lastRunSkipHash,children:String(i.hashDuplicate)})]}):null,t[26]=i,t[27]=n.lastRunSkipContaminated,t[28]=n.lastRunSkipHash,t[29]=n.lastRunSkipKey,t[30]=n.lastRunSkipRehydrate,t[31]=x):x=t[31];let S;return t[32]!==m||t[33]!==_||t[34]!==b||t[35]!==x||t[36]!==c||t[37]!==d?(S=(0,Q.jsxs)(`dl`,{className:`grid grid-cols-2 gap-x-3 gap-y-2 sm:grid-cols-3 lg:grid-cols-4`,children:[c,d,m,_,b,x]}),t[32]=m,t[33]=_,t[34]=b,t[35]=x,t[36]=c,t[37]=d,t[38]=S):S=t[38],S}function qn(e){let t=(0,Z.c)(58),{t:n,schedulePickerLabels:r,hasToken:i,cfgForm:a,cfgBaseline:o,cfgSaving:s,cfgDirty:c,setCfgForm:l,setCfgOk:u,setCfgError:d,saveConfig:f}=e,p;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(p=X(`min-w-0`,jn),t[0]=p):p=t[0];let m=!i||!a||s||!c,h;t[1]===f?h=t[2]:(h=()=>void f(),t[1]=f,t[2]=h);let g;t[3]===s?g=t[4]:(g=s?(0,Q.jsx)(Y,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,t[3]=s,t[4]=g);let _;t[5]!==n.saveConfig||t[6]!==m||t[7]!==h||t[8]!==g?(_=(0,Q.jsxs)(w,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:m,onClick:h,children:[g,n.saveConfig]}),t[5]=n.saveConfig,t[6]=m,t[7]=h,t[8]=g,t[9]=_):_=t[9];let v=!i||!a||s||!c,y;t[10]!==o||t[11]!==d||t[12]!==l||t[13]!==u?(y=()=>{u(!1),d(null),l(o)},t[10]=o,t[11]=d,t[12]=l,t[13]=u,t[14]=y):y=t[14];let b;t[15]!==n.resetConfig||t[16]!==v||t[17]!==y?(b=(0,Q.jsx)(w,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:v,onClick:y,children:n.resetConfig}),t[15]=n.resetConfig,t[16]=v,t[17]=y,t[18]=b):b=t[18];let x;t[19]!==_||t[20]!==b?(x=(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[_,b]}),t[19]=_,t[20]=b,t[21]=x):x=t[21];let S;t[22]!==n.configHint||t[23]!==n.configTitle||t[24]!==x?(S=(0,Q.jsx)(Ot,{className:Mn,icon:Be,title:n.configTitle,subtitle:n.configHint,trailing:x}),t[22]=n.configHint,t[23]=n.configTitle,t[24]=x,t[25]=S):S=t[25];let C;t[26]!==a||t[27]!==s||t[28]!==i||t[29]!==r||t[30]!==l||t[31]!==n.configDeepHalfLife||t[32]!==n.configDeepLimit||t[33]!==n.configDeepMaxAge||t[34]!==n.configDeepMinRecallCount||t[35]!==n.configDeepMinScore||t[36]!==n.configFrequency||t[37]!==n.configLightDedupe||t[38]!==n.configLightLimit||t[39]!==n.configLightLookbackDays||t[40]!==n.configLoading||t[41]!==n.configPhaseCron||t[42]!==n.configPhaseDeep||t[43]!==n.configPhaseDeepHint||t[44]!==n.configPhaseLight||t[45]!==n.configPhaseLightHint||t[46]!==n.configPhaseRem||t[47]!==n.configPhaseRemHint||t[48]!==n.configRemLimit||t[49]!==n.configRemLookbackDays||t[50]!==n.configRemMinStrength||t[51]!==n.configTimezone||t[52]!==n.off||t[53]!==n.on?(C=a?(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[(0,Q.jsx)(`div`,{className:Nn,children:(0,Q.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 lg:grid-cols-12`,children:[(0,Q.jsx)(`div`,{className:`lg:col-span-9`,children:(0,Q.jsx)(An,{kind:`cron`,label:n.configFrequency,value:a.frequency,onChange:e=>l(t=>t&&{...t,frequency:e}),labels:r,disabled:!i||s})}),(0,Q.jsx)(Ln,{label:n.configTimezone,className:`lg:col-span-3`,children:(0,Q.jsx)(`input`,{className:Pn,value:a.timezone,disabled:!i||s,onChange:e=>l(t=>t&&{...t,timezone:e.target.value}),placeholder:`Asia/Shanghai`})})]})}),(0,Q.jsxs)(Un,{icon:(0,Q.jsx)(Ue,{className:`size-4 text-amber-500`}),title:n.configPhaseLight,hint:n.configPhaseLightHint,enabled:a.light.enabled,onEnabledChange:e=>l(t=>t&&{...t,light:{...t.light,enabled:e}}),cron:a.light.cron,onCronChange:e=>l(t=>t&&{...t,light:{...t.light,cron:e}}),scheduleLabels:r,disabled:!i||s,onLabel:n.on,offLabel:n.off,cronLabel:n.configPhaseCron,children:[(0,Q.jsx)(Ln,{label:n.configLightLookbackDays,children:(0,Q.jsx)(`input`,{type:`number`,step:`1`,min:1,className:Pn,value:a.light.lookbackDays,disabled:!i||s,onChange:e=>l(t=>t&&{...t,light:{...t.light,lookbackDays:Number(e.target.value)}})})}),(0,Q.jsx)(Ln,{label:n.configLightLimit,children:(0,Q.jsx)(`input`,{type:`number`,step:`1`,min:0,className:Pn,value:a.light.limit,disabled:!i||s,onChange:e=>l(t=>t&&{...t,light:{...t.light,limit:Number(e.target.value)}})})}),(0,Q.jsx)(Ln,{label:n.configLightDedupe,children:(0,Q.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:Pn,value:a.light.dedupeSimilarity,disabled:!i||s,onChange:e=>l(t=>t&&{...t,light:{...t.light,dedupeSimilarity:Number(e.target.value)}})})})]}),(0,Q.jsxs)(Un,{icon:(0,Q.jsx)(z,{className:`size-4 text-indigo-500`}),title:n.configPhaseDeep,hint:n.configPhaseDeepHint,enabled:a.deep.enabled,onEnabledChange:e=>l(t=>t&&{...t,deep:{...t.deep,enabled:e}}),cron:a.deep.cron,onCronChange:e=>l(t=>t&&{...t,deep:{...t.deep,cron:e}}),scheduleLabels:r,disabled:!i||s,onLabel:n.on,offLabel:n.off,cronLabel:n.configPhaseCron,children:[(0,Q.jsx)(Ln,{label:n.configDeepMinScore,children:(0,Q.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:Pn,value:a.deep.minScore,disabled:!i||s,onChange:e=>l(t=>t&&{...t,deep:{...t.deep,minScore:Number(e.target.value)}})})}),(0,Q.jsx)(Ln,{label:n.configDeepMinRecallCount,children:(0,Q.jsx)(`input`,{type:`number`,step:`1`,min:1,className:Pn,value:a.deep.minRecallCount,disabled:!i||s,onChange:e=>l(t=>t&&{...t,deep:{...t.deep,minRecallCount:Number(e.target.value)}})})}),(0,Q.jsx)(Ln,{label:n.configDeepLimit,children:(0,Q.jsx)(`input`,{type:`number`,step:`1`,min:0,className:Pn,value:a.deep.limit,disabled:!i||s,onChange:e=>l(t=>t&&{...t,deep:{...t.deep,limit:Number(e.target.value)}})})}),(0,Q.jsx)(Ln,{label:n.configDeepHalfLife,children:(0,Q.jsx)(`input`,{type:`number`,step:`1`,min:1,className:Pn,value:a.deep.recencyHalfLifeDays,disabled:!i||s,onChange:e=>l(t=>t&&{...t,deep:{...t.deep,recencyHalfLifeDays:Number(e.target.value)}})})}),(0,Q.jsx)(Ln,{label:n.configDeepMaxAge,children:(0,Q.jsx)(`input`,{type:`number`,step:`1`,min:1,className:Pn,value:a.deep.maxAgeDays,disabled:!i||s,onChange:e=>l(t=>t&&{...t,deep:{...t.deep,maxAgeDays:Number(e.target.value)}})})})]}),(0,Q.jsxs)(Un,{icon:(0,Q.jsx)(Le,{className:`size-4 text-purple-500`}),title:n.configPhaseRem,hint:n.configPhaseRemHint,enabled:a.rem.enabled,onEnabledChange:e=>l(t=>t&&{...t,rem:{...t.rem,enabled:e}}),cron:a.rem.cron,onCronChange:e=>l(t=>t&&{...t,rem:{...t.rem,cron:e}}),scheduleLabels:r,disabled:!i||s,onLabel:n.on,offLabel:n.off,cronLabel:n.configPhaseCron,children:[(0,Q.jsx)(Ln,{label:n.configRemLookbackDays,children:(0,Q.jsx)(`input`,{type:`number`,step:`1`,min:1,className:Pn,value:a.rem.lookbackDays,disabled:!i||s,onChange:e=>l(t=>t&&{...t,rem:{...t.rem,lookbackDays:Number(e.target.value)}})})}),(0,Q.jsx)(Ln,{label:n.configRemLimit,children:(0,Q.jsx)(`input`,{type:`number`,step:`1`,min:0,className:Pn,value:a.rem.limit,disabled:!i||s,onChange:e=>l(t=>t&&{...t,rem:{...t.rem,limit:Number(e.target.value)}})})}),(0,Q.jsx)(Ln,{label:n.configRemMinStrength,children:(0,Q.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:Pn,value:a.rem.minPatternStrength,disabled:!i||s,onChange:e=>l(t=>t&&{...t,rem:{...t.rem,minPatternStrength:Number(e.target.value)}})})})]})]}):(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.configLoading}),t[26]=a,t[27]=s,t[28]=i,t[29]=r,t[30]=l,t[31]=n.configDeepHalfLife,t[32]=n.configDeepLimit,t[33]=n.configDeepMaxAge,t[34]=n.configDeepMinRecallCount,t[35]=n.configDeepMinScore,t[36]=n.configFrequency,t[37]=n.configLightDedupe,t[38]=n.configLightLimit,t[39]=n.configLightLookbackDays,t[40]=n.configLoading,t[41]=n.configPhaseCron,t[42]=n.configPhaseDeep,t[43]=n.configPhaseDeepHint,t[44]=n.configPhaseLight,t[45]=n.configPhaseLightHint,t[46]=n.configPhaseRem,t[47]=n.configPhaseRemHint,t[48]=n.configRemLimit,t[49]=n.configRemLookbackDays,t[50]=n.configRemMinStrength,t[51]=n.configTimezone,t[52]=n.off,t[53]=n.on,t[54]=C):C=t[54];let T;return t[55]!==S||t[56]!==C?(T=(0,Q.jsxs)(Kt,{className:p,children:[S,C]}),t[55]=S,t[56]=C,t[57]=T):T=t[57],T}function Jn(e){let t=(0,Z.c)(20),{t:n,hasToken:r,eventsLoading:i,events:a,loadEvents:o}=e,s=!r||i,c;t[0]===o?c=t[1]:(c=()=>void o(),t[0]=o,t[1]=c);let l;t[2]===i?l=t[3]:(l=i?(0,Q.jsx)(Y,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,t[2]=i,t[3]=l);let u;t[4]!==n.eventsLoad||t[5]!==s||t[6]!==c||t[7]!==l?(u=(0,Q.jsxs)(w,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:s,onClick:c,children:[l,n.eventsLoad]}),t[4]=n.eventsLoad,t[5]=s,t[6]=c,t[7]=l,t[8]=u):u=t[8];let d;t[9]!==n.eventsHint||t[10]!==n.eventsTitle||t[11]!==u?(d=(0,Q.jsx)(Ot,{className:Mn,icon:H,title:n.eventsTitle,subtitle:n.eventsHint,trailing:u}),t[9]=n.eventsHint,t[10]=n.eventsTitle,t[11]=u,t[12]=d):d=t[12];let f;t[13]!==a||t[14]!==n.eventsEmpty||t[15]!==n.eventsNotLoaded?(f=a?a.length>0?(0,Q.jsx)(`div`,{className:`space-y-1.5`,children:a.map(Yn)}):(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.eventsEmpty}):(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.eventsNotLoaded}),t[13]=a,t[14]=n.eventsEmpty,t[15]=n.eventsNotLoaded,t[16]=f):f=t[16];let p;return t[17]!==d||t[18]!==f?(p=(0,Q.jsxs)(Kt,{className:jn,children:[d,f]}),t[17]=d,t[18]=f,t[19]=p):p=t[19],p}function Yn(e){let t=e.phase===`light`?`☀️`:e.phase===`rem`?`✨`:`🌙`,n=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,Q.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,Q.jsx)(`span`,{children:t}),(0,Q.jsx)(`span`,{className:`font-medium text-fg`,children:e.phase}),(0,Q.jsx)(`span`,{className:X(`font-medium`,e.ok?`text-emerald-600 dark:text-emerald-400`:`text-amber-600 dark:text-amber-400`),children:e.ok?`OK`:`FAIL`}),(0,Q.jsx)(`span`,{className:`text-fg-muted`,children:n}),(0,Q.jsx)(`span`,{className:`text-fg-muted`,children:Vn(e.durationMs)}),(0,Q.jsx)(`span`,{className:`ml-auto text-fg-subtle`,children:Bn(e.timestamp)})]},`${e.timestamp}:${e.phase}`)}function Xn(e){let t=(0,Z.c)(40),{t:n,cfgForm:r,dreamingEnabled:i,hasToken:a,cfgSaving:o,enableSaving:s,runPhase:c,setRunPhase:l,runBusy:u,doRunNow:d,doRefresh:f,setDreamingEnabled:p}=e,m;t[0]===n.title?m=t[1]:(m=(0,Q.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:n.title}),t[0]=n.title,t[1]=m);let g;t[2]===n.subtitle?g=t[3]:(g=(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),t[2]=n.subtitle,t[3]=g);let _;t[4]!==m||t[5]!==g?(_=(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[m,g]}),t[4]=m,t[5]=g,t[6]=_):_=t[6];let v;t[7]!==r||t[8]!==o||t[9]!==i||t[10]!==s||t[11]!==a||t[12]!==p||t[13]!==n.configEnabled||t[14]!==n.off||t[15]!==n.on?(v=r?(0,Q.jsxs)(`label`,{className:X(`inline-flex cursor-pointer items-center gap-2 rounded-xl border px-3 py-1.5 text-sm transition-colors`,i?`border-emerald-500/30 bg-emerald-500/5 text-fg`:`border-edge-subtle bg-surface-panel/50 text-fg-muted`),children:[(0,Q.jsx)(`span`,{className:`text-xs font-medium`,children:n.configEnabled}),(0,Q.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:r.enabled,disabled:!a||o||s,onChange:e=>void p(e.target.checked)}),s?(0,Q.jsx)(Y,{className:`size-3.5 animate-spin text-fg-muted`,"aria-hidden":!0}):(0,Q.jsx)(`span`,{className:X(`text-xs font-semibold`,i?`text-emerald-600 dark:text-emerald-400`:``),children:r.enabled?n.on:n.off})]}):null,t[7]=r,t[8]=o,t[9]=i,t[10]=s,t[11]=a,t[12]=p,t[13]=n.configEnabled,t[14]=n.off,t[15]=n.on,t[16]=v):v=t[16];let y;t[17]!==d||t[18]!==i||t[19]!==a||t[20]!==u||t[21]!==c||t[22]!==l||t[23]!==n.runNow||t[24]!==n.runNowHint?(y=i?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`select`,{className:`rounded-lg border border-edge bg-surface-panel px-2 py-1.5 text-xs text-fg`,value:c,onChange:e=>l(e.target.value),disabled:!a||u,children:[(0,Q.jsx)(`option`,{value:`light`,children:`Light`}),(0,Q.jsx)(`option`,{value:`deep`,children:`Deep`}),(0,Q.jsx)(`option`,{value:`rem`,children:`REM`})]}),(0,Q.jsxs)(w,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!a||u,onClick:()=>void d(c),title:n.runNowHint,children:[u?(0,Q.jsx)(Y,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,Q.jsx)(Pe,{className:`mr-2 size-4`,"aria-hidden":!0}),n.runNow]})]}):null,t[17]=d,t[18]=i,t[19]=a,t[20]=u,t[21]=c,t[22]=l,t[23]=n.runNow,t[24]=n.runNowHint,t[25]=y):y=t[25];let b=!a,x;t[26]===f?x=t[27]:(x=()=>void f(),t[26]=f,t[27]=x);let S;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,Q.jsx)(h,{className:`mr-2 size-4`,"aria-hidden":!0}),t[28]=S):S=t[28];let C;t[29]!==n.refresh||t[30]!==b||t[31]!==x?(C=(0,Q.jsxs)(w,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:b,onClick:x,children:[S,n.refresh]}),t[29]=n.refresh,t[30]=b,t[31]=x,t[32]=C):C=t[32];let T;t[33]!==v||t[34]!==y||t[35]!==C?(T=(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[v,y,C]}),t[33]=v,t[34]=y,t[35]=C,t[36]=T):T=t[36];let E;return t[37]!==T||t[38]!==_?(E=(0,Q.jsxs)(`header`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[_,T]}),t[37]=T,t[38]=_,t[39]=E):E=t[39],E}function Zn(e){let t=(0,Z.c)(30),{t:n,disabled:r,actionBusy:i,doAction:a}=e,o;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=X(`max-w-2xl`,jn),t[0]=o):o=t[0];let s;t[1]!==n.maintenanceHint||t[2]!==n.maintenanceTitle?(s=(0,Q.jsx)(Ot,{className:Mn,icon:le,title:n.maintenanceTitle,subtitle:n.maintenanceHint}),t[1]=n.maintenanceHint,t[2]=n.maintenanceTitle,t[3]=s):s=t[3];let c;t[4]!==a||t[5]!==n.confirmResetStore?(c=()=>{confirm(n.confirmResetStore)&&a(`reset_store`)},t[4]=a,t[5]=n.confirmResetStore,t[6]=c):c=t[6];let l;t[7]===i?l=t[8]:(l=i===`reset_store`?(0,Q.jsx)(Y,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,Q.jsx)(Je,{className:`mr-2 size-4`,"aria-hidden":!0}),t[7]=i,t[8]=l);let u;t[9]!==r||t[10]!==n.resetStore||t[11]!==c||t[12]!==l?(u=(0,Q.jsxs)(w,{variant:`secondary`,disabled:r,onClick:c,children:[l,n.resetStore]}),t[9]=r,t[10]=n.resetStore,t[11]=c,t[12]=l,t[13]=u):u=t[13];let f;t[14]!==a||t[15]!==n.confirmClearLock?(f=()=>{confirm(n.confirmClearLock)&&a(`clear_lock`)},t[14]=a,t[15]=n.confirmClearLock,t[16]=f):f=t[16];let p;t[17]===i?p=t[18]:(p=i===`clear_lock`?(0,Q.jsx)(Y,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,Q.jsx)(d,{className:`mr-2 size-4`,"aria-hidden":!0}),t[17]=i,t[18]=p);let m;t[19]!==r||t[20]!==n.clearLock||t[21]!==f||t[22]!==p?(m=(0,Q.jsxs)(w,{variant:`secondary`,disabled:r,onClick:f,children:[p,n.clearLock]}),t[19]=r,t[20]=n.clearLock,t[21]=f,t[22]=p,t[23]=m):m=t[23];let h;t[24]!==u||t[25]!==m?(h=(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[u,m]}),t[24]=u,t[25]=m,t[26]=h):h=t[26];let g;return t[27]!==s||t[28]!==h?(g=(0,Q.jsxs)(Kt,{className:o,children:[s,h]}),t[27]=s,t[28]=h,t[29]=g):g=t[29],g}function Qn(e){let t=(0,Z.c)(21),{t:n,hasToken:r,previewLoading:i,previewItems:a,loadPreview:o}=e,s=!r||i,c;t[0]===o?c=t[1]:(c=()=>void o(),t[0]=o,t[1]=c);let l;t[2]===i?l=t[3]:(l=i?(0,Q.jsx)(Y,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,t[2]=i,t[3]=l);let u;t[4]!==n.previewLoad||t[5]!==s||t[6]!==c||t[7]!==l?(u=(0,Q.jsxs)(w,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:s,onClick:c,children:[l,n.previewLoad]}),t[4]=n.previewLoad,t[5]=s,t[6]=c,t[7]=l,t[8]=u):u=t[8];let d;t[9]!==n.previewHint||t[10]!==n.previewTitle||t[11]!==u?(d=(0,Q.jsx)(Ot,{className:Mn,icon:ut,title:n.previewTitle,subtitle:n.previewHint,trailing:u}),t[9]=n.previewHint,t[10]=n.previewTitle,t[11]=u,t[12]=d):d=t[12];let f;t[13]!==a||t[14]!==n.previewEligible||t[15]!==n.previewEmpty||t[16]!==n.previewNotLoaded?(f=a?a.length>0?(0,Q.jsx)(`div`,{className:`space-y-2`,children:a.map(e=>{let t=`${e.path}:${e.startLine}-${e.endLine}`,r=e.skippedReason;return(0,Q.jsxs)(`div`,{className:`rounded-lg border border-edge-subtle bg-surface-panel/60 px-2.5 py-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-fg-muted`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-fg`,children:t}),(0,Q.jsxs)(`span`,{children:[`score=`,e.score.toFixed(3)]}),(0,Q.jsxs)(`span`,{children:[`recalls=`,e.recallCount]}),(0,Q.jsxs)(`span`,{children:[`avg=`,e.avgScore.toFixed(3)]}),(0,Q.jsxs)(`span`,{children:[`decay=`,e.recencyDecay?.toFixed(3)??`—`]}),r?(0,Q.jsx)(`span`,{className:`text-amber-600 dark:text-amber-400`,children:r}):(0,Q.jsx)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:n.previewEligible})]}),e.snippet?(0,Q.jsx)(`div`,{className:`mt-2 text-sm text-fg`,children:e.snippet}):null]},`${e.key}:${e.hash}:${t}`)})}):(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.previewEmpty}):(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.previewNotLoaded}),t[13]=a,t[14]=n.previewEligible,t[15]=n.previewEmpty,t[16]=n.previewNotLoaded,t[17]=f):f=t[17];let p;return t[18]!==d||t[19]!==f?(p=(0,Q.jsxs)(Kt,{className:jn,children:[d,f]}),t[18]=d,t[19]=f,t[20]=p):p=t[20],p}function $n(e){let t=(0,Z.c)(100),{t:n,data:r,isLoading:i,localeTag:a,scheduleBadgeLabels:o}=e,s;t[0]!==r||t[1]!==n?(s=r?Hn(r.lock,n):null,t[0]=r,t[1]=n,t[2]=s):s=t[2];let c=s,l;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(l=X(`min-w-0`,jn),t[3]=l):l=t[3];let u;t[4]===i?u=t[5]:(u=i?(0,Q.jsx)(Y,{className:`size-4 shrink-0 animate-spin text-fg-muted`,"aria-hidden":!0}):null,t[4]=i,t[5]=u);let d;t[6]!==n.runtimeHint||t[7]!==n.runtimeTitle||t[8]!==u?(d=(0,Q.jsx)(Ot,{className:Mn,icon:H,title:n.runtimeTitle,subtitle:n.runtimeHint,trailing:u}),t[6]=n.runtimeHint,t[7]=n.runtimeTitle,t[8]=u,t[9]=d):d=t[9];let f;t[10]===n.subsectionSchedule?f=t[11]:(f=(0,Q.jsx)(zn,{label:n.subsectionSchedule,className:`mb-2`}),t[10]=n.subsectionSchedule,t[11]=f);let p=r?r.config.enabled?n.on:n.off:`—`,m;t[12]!==n.enabled||t[13]!==p?(m=(0,Q.jsx)(Rn,{label:n.enabled,children:p}),t[12]=n.enabled,t[13]=p,t[14]=m):m=t[14];let h=c?.className,g=c?c.text:`—`,_;t[15]!==h||t[16]!==g?(_=(0,Q.jsx)(`span`,{className:h,children:g}),t[15]=h,t[16]=g,t[17]=_):_=t[17];let v;t[18]!==n.lock||t[19]!==_?(v=(0,Q.jsx)(Rn,{label:n.lock,children:_}),t[18]=n.lock,t[19]=_,t[20]=v):v=t[20];let y=r&&r.config.timezone||`—`,b;t[21]!==n.timezone||t[22]!==y?(b=(0,Q.jsx)(Rn,{label:n.timezone,children:y}),t[21]=n.timezone,t[22]=y,t[23]=b):b=t[23];let x;t[24]!==r||t[25]!==a||t[26]!==o?(x=r?(0,Q.jsx)(Wt,{kind:`cron`,expression:r.config.frequency,locale:a,labels:o,timezone:r.config.timezone||void 0}):`—`,t[24]=r,t[25]=a,t[26]=o,t[27]=x):x=t[27];let S;t[28]===r?S=t[29]:(S=r?.config.frequency?(0,Q.jsx)(`p`,{className:`mt-0.5 truncate font-mono text-[0.65rem] text-fg-subtle`,title:r.config.frequency,children:r.config.frequency}):null,t[28]=r,t[29]=S);let C;t[30]!==n.schedule||t[31]!==x||t[32]!==S?(C=(0,Q.jsxs)(Rn,{label:n.schedule,className:`col-span-2 sm:col-span-2`,children:[x,S]}),t[30]=n.schedule,t[31]=x,t[32]=S,t[33]=C):C=t[33];let w;t[34]!==v||t[35]!==b||t[36]!==C||t[37]!==m?(w=(0,Q.jsxs)(`dl`,{className:`grid grid-cols-2 gap-x-3 gap-y-2 sm:grid-cols-4`,children:[m,v,b,C]}),t[34]=v,t[35]=b,t[36]=C,t[37]=m,t[38]=w):w=t[38];let T;t[39]!==w||t[40]!==f?(T=(0,Q.jsxs)(`div`,{className:Nn,children:[f,w]}),t[39]=w,t[40]=f,t[41]=T):T=t[41];let E;t[42]===n.subsectionStore?E=t[43]:(E=(0,Q.jsx)(zn,{label:n.subsectionStore,className:`mb-2`}),t[42]=n.subsectionStore,t[43]=E);let D=r?String(r.store.entryCount):`—`,O;t[44]!==n.storeEntries||t[45]!==D?(O=(0,Q.jsx)(Rn,{label:n.storeEntries,children:D}),t[44]=n.storeEntries,t[45]=D,t[46]=O):O=t[46];let k=r?String(r.store.promotedCount):`—`,A;t[47]!==n.storePromoted||t[48]!==k?(A=(0,Q.jsx)(Rn,{label:n.storePromoted,children:k}),t[47]=n.storePromoted,t[48]=k,t[49]=A):A=t[49];let j;t[50]===r?j=t[51]:(j=r?Bn(r.store.updatedAt):`—`,t[50]=r,t[51]=j);let M;t[52]!==n.storeUpdatedAt||t[53]!==j?(M=(0,Q.jsx)(Rn,{label:n.storeUpdatedAt,children:j}),t[52]=n.storeUpdatedAt,t[53]=j,t[54]=M):M=t[54];let N;t[55]===r?N=t[56]:(N=r?Bn(r.store.lastPromotedAt):`—`,t[55]=r,t[56]=N);let P;t[57]!==n.storeLastPromotedAt||t[58]!==N?(P=(0,Q.jsx)(Rn,{label:n.storeLastPromotedAt,children:N}),t[57]=n.storeLastPromotedAt,t[58]=N,t[59]=P):P=t[59];let F;t[60]!==O||t[61]!==A||t[62]!==M||t[63]!==P?(F=(0,Q.jsxs)(`dl`,{className:`grid grid-cols-2 gap-x-3 gap-y-2 sm:grid-cols-4`,children:[O,A,M,P]}),t[60]=O,t[61]=A,t[62]=M,t[63]=P,t[64]=F):F=t[64];let I;t[65]!==E||t[66]!==F?(I=(0,Q.jsxs)(`div`,{className:Nn,children:[E,F]}),t[65]=E,t[66]=F,t[67]=I):I=t[67];let L;t[68]!==r||t[69]!==a||t[70]!==o||t[71]!==n?(L=r?.config?.phases?(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(zn,{label:n.subsectionPhases,className:`mb-2`}),(0,Q.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-3`,children:[(0,Q.jsx)(Wn,{icon:(0,Q.jsx)(Ue,{className:`size-4 text-amber-500`}),label:`Light`,enabled:r.config.phases.light.enabled,cron:r.config.phases.light.cron,scheduleSummary:xt(r.config.phases.light.cron,a,o,{timezone:r.config.timezone||void 0}),details:`lookback=${r.config.phases.light.lookbackDays}d, limit=${r.config.phases.light.limit}, dedupe=${r.config.phases.light.dedupeSimilarity}`,t:n}),(0,Q.jsx)(Wn,{icon:(0,Q.jsx)(z,{className:`size-4 text-indigo-500`}),label:`Deep`,enabled:r.config.phases.deep.enabled,cron:r.config.phases.deep.cron,scheduleSummary:xt(r.config.phases.deep.cron,a,o,{timezone:r.config.timezone||void 0}),details:`minScore=${r.config.phases.deep.minScore}, recalls≥${r.config.phases.deep.minRecallCount}, limit=${r.config.phases.deep.limit}, halfLife=${r.config.phases.deep.recencyHalfLifeDays}d`,t:n}),(0,Q.jsx)(Wn,{icon:(0,Q.jsx)(Le,{className:`size-4 text-purple-500`}),label:`REM`,enabled:r.config.phases.rem.enabled,cron:r.config.phases.rem.cron,scheduleSummary:xt(r.config.phases.rem.cron,a,o,{timezone:r.config.timezone||void 0}),details:`lookback=${r.config.phases.rem.lookbackDays}d, limit=${r.config.phases.rem.limit}, strength≥${r.config.phases.rem.minPatternStrength}`,t:n})]})]}):null,t[68]=r,t[69]=a,t[70]=o,t[71]=n,t[72]=L):L=t[72];let R;t[73]===n.subsectionLastRun?R=t[74]:(R=(0,Q.jsx)(zn,{label:n.subsectionLastRun,className:`mb-2`}),t[73]=n.subsectionLastRun,t[74]=R);let B;t[75]===n.lastRunBlockHint?B=t[76]:(B=(0,Q.jsx)(`p`,{className:`mb-2 text-xs text-fg-muted`,children:n.lastRunBlockHint}),t[75]=n.lastRunBlockHint,t[76]=B);let V;t[77]!==r||t[78]!==n?(V=r?.lastRun?.exists?(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[r.lastRun.parseError?(0,Q.jsxs)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:[n.lastRunParseError,`: `,r.lastRun.parseError]}):null,r.lastRun.record?(0,Q.jsx)(`div`,{className:`rounded-lg border border-edge-subtle/80 bg-surface-panel/50 p-2.5`,children:(0,Q.jsx)(Kn,{t:n,r:r.lastRun.record})}):null,r.lastRun.raw!==void 0&&r.lastRun.raw!==null?(0,Q.jsxs)(`details`,{className:`group rounded-lg border border-edge-subtle`,children:[(0,Q.jsx)(`summary`,{className:`cursor-pointer list-none px-2.5 py-1.5 text-xs font-medium text-fg-muted marker:hidden [&::-webkit-details-marker]:hidden`,children:(0,Q.jsx)(`span`,{className:`underline decoration-edge underline-offset-2 group-open:text-fg`,children:n.lastRunRaw})}),(0,Q.jsx)(`pre`,{className:`max-h-40 overflow-auto border-t border-edge-subtle p-2.5 text-xs text-fg-muted`,children:JSON.stringify(r.lastRun.raw,null,2)})]}):null]}):(0,Q.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.lastRunEmpty}),t[77]=r,t[78]=n,t[79]=V):V=t[79];let U;t[80]!==R||t[81]!==B||t[82]!==V?(U=(0,Q.jsxs)(`div`,{className:Nn,children:[R,B,V]}),t[80]=R,t[81]=B,t[82]=V,t[83]=U):U=t[83];let W=r?.lightLastRun,G;t[84]!==n||t[85]!==W?(G=(0,Q.jsx)(Gn,{label:n.subsectionLightLastRun,lastRun:W,t:n}),t[84]=n,t[85]=W,t[86]=G):G=t[86];let ee=r?.remLastRun,te;t[87]!==n||t[88]!==ee?(te=(0,Q.jsx)(Gn,{label:n.subsectionRemLastRun,lastRun:ee,t:n}),t[87]=n,t[88]=ee,t[89]=te):te=t[89];let K;t[90]!==T||t[91]!==I||t[92]!==L||t[93]!==U||t[94]!==G||t[95]!==te?(K=(0,Q.jsxs)(`div`,{className:`space-y-3`,children:[T,I,L,U,G,te]}),t[90]=T,t[91]=I,t[92]=L,t[93]=U,t[94]=G,t[95]=te,t[96]=K):K=t[96];let q;return t[97]!==K||t[98]!==d?(q=(0,Q.jsxs)(Kt,{className:l,children:[d,K]}),t[97]=K,t[98]=d,t[99]=q):q=t[99],q}function er(){let e=F(e=>e.language),t=oe(e),n=t.dreamingSettings,r=t.cron.schedulePicker,i=t.cron.scheduleBadge,o=e===`zh`?`zh-CN`:`en-US`,s=!!R(e=>e.token),{data:c}=I(s),[l,u]=(0,$.useState)(null),[d,f]=(0,$.useState)(null),[p,m]=(0,$.useState)(!1),[h,g]=(0,$.useState)(!1),[_,v]=(0,$.useState)(!1),[y,b]=(0,$.useState)(null),[x,S]=(0,$.useState)(`deep`),[C,w]=(0,$.useState)(null),[T,E]=(0,$.useState)(null),[D,O]=(0,$.useState)(!1),[k,A]=(0,$.useState)(!1),[j,M]=(0,$.useState)(!1),[N,P]=(0,$.useState)(null),[L,z]=(0,$.useState)(!1),[B,V]=(0,$.useState)(null),[H,U]=(0,$.useState)(null),[W,G]=(0,$.useState)(!1),[ee,te]=(0,$.useState)(null),[K,q]=(0,$.useState)(null),{data:ne,error:J,isLoading:re,mutate:ie}=a(s?jt():null,Nt,{revalidateOnFocus:!1}),ae=(0,$.useMemo)(()=>{let e=[];return J&&e.push(J instanceof Error?J.message:String(J)),d&&e.push(d),y&&e.push(y),B&&e.push(B),ee&&e.push(ee),N&&e.push(N),e},[J,d,y,B,ee,N]),Y=(0,$.useMemo)(()=>{let e=[];return j&&e.push(n.configSaved),_&&e.push(n.runQueued),p&&e.push(n.actionOk),e},[j,_,p,n]),se=(0,$.useCallback)(async()=>{m(!1),f(null),v(!1),b(null),M(!1),P(null),V(null),await ie()},[ie]),ce=(0,$.useCallback)(async()=>{z(!0),V(null);try{U((await It(20)).items??[])}catch(e){V(e instanceof Error?e.message:String(e))}finally{z(!1)}},[]),le=(0,$.useCallback)(async()=>{G(!0),te(null);try{q(await zt(50))}catch(e){te(e instanceof Error?e.message:String(e))}finally{G(!1)}},[]),ue=(0,$.useCallback)(async(e=`deep`)=>{g(!0),v(!1),b(null);try{await Et(e),v(!0),await ie()}catch(e){b(e instanceof Error?e.message:String(e))}finally{g(!1)}},[ie]),de=(0,$.useCallback)(async e=>{u(e),f(null),m(!1);try{await Mt(e),m(!0),await ie()}catch(e){f(e instanceof Error?e.message:String(e))}finally{u(null)}},[ie]),fe=!s||re||!!l,pe=(0,$.useMemo)(()=>{let e=c?.payload?.config;return xn(e??{})},[c]);(0,$.useEffect)(()=>{if(s){if(!T){E(pe),w(pe);return}JSON.stringify(pe)!==JSON.stringify(T)&&(E(pe),w(pe))}},[T,pe,s]);let me=(0,$.useMemo)(()=>!C||!T?!1:JSON.stringify(C)!==JSON.stringify(T),[C,T]),he=(0,$.useCallback)(async()=>{if(C){O(!0),M(!1),P(null);try{await Sn(C),E(C),M(!0),await ie()}catch(e){P(e instanceof Error?e.message:String(e))}finally{O(!1)}}},[C,ie]),ge=(0,$.useCallback)(async e=>{if(!C||!s)return;let t={...C,enabled:e},n=C;w(t),A(!0),M(!1),P(null);try{await Sn(t),E(t),M(!0),await ie()}catch(e){w(n),P(e instanceof Error?e.message:String(e))}finally{A(!1)}},[C,s,ie]);return(0,Q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-4 px-4 py-6`,children:[(0,Q.jsx)(Xn,{t:n,cfgForm:C,dreamingEnabled:C?.enabled??pe.enabled,hasToken:s,cfgSaving:D,enableSaving:k,runPhase:x,setRunPhase:S,runBusy:h,doRunNow:ue,doRefresh:se,setDreamingEnabled:ge}),ae.length>0?(0,Q.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:ae.map(e=>(0,Q.jsx)(`p`,{className:`text-sm text-amber-800 dark:text-amber-200/90`,children:e},e))}):null,Y.length>0?(0,Q.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:Y.map(e=>(0,Q.jsx)(`p`,{className:`text-sm text-emerald-800 dark:text-emerald-200/90`,children:e},e))}):null,(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.jsx)(qn,{t:n,schedulePickerLabels:r,hasToken:s,cfgForm:C,cfgBaseline:T,cfgSaving:D,cfgDirty:me,setCfgForm:w,setCfgOk:M,setCfgError:P,saveConfig:he}),(0,Q.jsx)($n,{t:n,data:ne,isLoading:re,localeTag:o,scheduleBadgeLabels:i})]}),(0,Q.jsxs)(`div`,{className:`grid gap-4 xl:grid-cols-2`,children:[(0,Q.jsx)(Qn,{t:n,hasToken:s,previewLoading:L,previewItems:H,loadPreview:ce}),(0,Q.jsx)(Jn,{t:n,hasToken:s,eventsLoading:W,events:K,loadEvents:le})]}),(0,Q.jsx)(Zn,{t:n,disabled:fe,actionBusy:l,doAction:de})]})}var tr=18790,nr={enabled:!0,maxAttempts:5,windowMs:9e5,blockDurationMs:3e5};function rr(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function ir(e){return e===`***`||e===`••••••••••••`}function ar(e){return e===`none`||e===`token`||e===`password`?e:`token`}function or(e){let t=rr(e)?e:{};return{enabled:t.enabled!==!1,maxAttempts:typeof t.maxAttempts==`number`&&Number.isFinite(t.maxAttempts)?Math.max(1,Math.floor(t.maxAttempts)):nr.maxAttempts,windowMs:typeof t.windowMs==`number`&&Number.isFinite(t.windowMs)&&t.windowMs>0?Math.floor(t.windowMs):nr.windowMs,blockDurationMs:typeof t.blockDurationMs==`number`&&Number.isFinite(t.blockDurationMs)&&t.blockDurationMs>0?Math.floor(t.blockDurationMs):nr.blockDurationMs}}function sr(e){return e===`auto`||e===`off`||e===`explicit`?e:`auto`}function cr(e,t=24){return Array.isArray(e)?e.filter(e=>typeof e==`string`&&e.trim().length>0).map(e=>e.trim()).slice(0,t):[]}function lr(e){let t=rr(e)?e:{},n=rr(t.gateway)?t.gateway:{},r=rr(n.auth)?n.auth:{},i=(rr(t.update)?t.update:{}).channel,a=i===`beta`||i===`dev`||i===`stable`?i:`stable`,o=Array.isArray(n.corsOrigins)?n.corsOrigins.filter(e=>typeof e==`string`&&e.trim().length>0):[];return{host:typeof n.host==`string`?n.host:``,port:typeof n.port==`number`&&Number.isFinite(n.port)?Math.floor(n.port):tr,auth:{mode:ar(r.mode),token:typeof r.token==`string`?r.token:``,password:typeof r.password==`string`?r.password:``,rateLimit:or(r.rateLimit)},corsOrigins:o,maxSseConnections:typeof n.maxSseConnections==`number`&&Number.isFinite(n.maxSseConnections)?Math.max(1,Math.floor(n.maxSseConnections)):100,channelConnectDeferMode:sr(n.channelConnectDeferMode),channelConnectDeferIds:cr(n.channelConnectDeferIds),channelConnectDeferSkipIds:cr(n.channelConnectDeferSkipIds),updateChannel:a}}function ur(e){let t={mode:e.auth.mode,rateLimit:e.auth.rateLimit};if(e.auth.mode===`token`){let n=e.auth.token.trim();n.length>0&&!ir(n)&&(t.token=e.auth.token),t.password=null}else if(e.auth.mode===`password`){let n=e.auth.password.trim();n.length>0&&!ir(n)&&(t.password=e.auth.password),t.token=null}return t}async function dr(e){await v(lt(`/api/config`),{method:`PATCH`,body:JSON.stringify({gateway:{host:e.host.trim()||`127.0.0.1`,port:e.port,auth:ur(e),corsOrigins:e.corsOrigins,maxSseConnections:e.maxSseConnections,channelConnectDeferMode:e.channelConnectDeferMode,channelConnectDeferIds:e.channelConnectDeferIds,channelConnectDeferSkipIds:e.channelConnectDeferSkipIds},update:{channel:e.updateChannel}})}),P()}function fr(){return X(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,u,`dark:border-edge`)}function pr(){let e=F(e=>e.language),t=oe(e),n=t.gatewaySettings,r=R(e=>e.token),i=R(e=>e.tokenExpired),a=R(e=>e.openTokenDialog),o=!!r,[s,c]=(0,$.useState)(null),[l,u]=(0,$.useState)(null),[d,f]=(0,$.useState)(!1),[p,m]=(0,$.useState)(null),[h,g]=(0,$.useState)(!1),[_,v]=(0,$.useState)(!1),[y,b]=(0,$.useState)(!1),[x,S]=(0,$.useState)(!1),C=(0,$.useRef)(!1),{data:T,error:E,isLoading:D,mutate:O}=I(o),k=(0,$.useMemo)(()=>T?.payload?.config===void 0?null:structuredClone(lr(T.payload.config)),[T]);(0,$.useEffect)(()=>{if(!o){c(null),u(null),C.current=!1;return}k!==null&&(C.current||(c(k),u(structuredClone(k)),g(!1)))},[o,k]);let A=!!(o&&D&&T===void 0&&!E),j=E instanceof Error?E.message:E?String(E):null,M=(0,$.useMemo)(()=>!s||!l?!1:JSON.stringify(s)!==JSON.stringify(l),[s,l]),N=(0,$.useCallback)(e=>{C.current=!0,c(t=>t?{...t,auth:{...t.auth,...e}}:null)},[]),P=(0,$.useCallback)(e=>{C.current=!0,c(t=>t?{...t,updateChannel:e}:null)},[]),L=(0,$.useCallback)(e=>{C.current=!0,c(t=>t?{...t,corsOrigins:e}:null)},[]),z=(0,$.useCallback)(e=>{C.current=!0,c(t=>t?{...t,host:e}:null)},[]),B=(0,$.useCallback)(e=>{C.current=!0,c(t=>t?{...t,port:e}:null)},[]),V=(0,$.useCallback)(e=>{C.current=!0,c(t=>t?{...t,auth:{...t.auth,rateLimit:{...t.auth.rateLimit,...e}}}:null)},[]),H=(0,$.useCallback)(e=>{C.current=!0,c(t=>t?{...t,maxSseConnections:e}:null)},[]),U=(0,$.useCallback)(e=>{C.current=!0,c(t=>t?{...t,channelConnectDeferMode:e}:null)},[]),W=(0,$.useCallback)(e=>{C.current=!0,c(t=>t?{...t,channelConnectDeferIds:e}:null)},[]),G=(0,$.useCallback)(e=>{C.current=!0,c(t=>t?{...t,channelConnectDeferSkipIds:e}:null)},[]),ee=(0,$.useCallback)(async()=>{if(!(!s||d)){f(!0),m(null),g(!1);try{await dr(s),C.current=!1,u(structuredClone(s)),g(!0),window.setTimeout(()=>g(!1),2500)}catch(e){m(e instanceof Error?e.message:n.saveError)}finally{f(!1)}}},[s,d,n.saveError]),te=(0,$.useCallback)(()=>{l&&(C.current=!1,c(structuredClone(l)),m(null),g(!1))},[l]),K=(0,$.useCallback)(async()=>{let e=s?.auth.token;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),S(!0),window.setTimeout(()=>S(!1),2e3))},[s?.auth.token]);return o?A?(0,Q.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,Q.jsx)(Y,{className:`size-4 animate-spin`}),n.loading]})}):s?(0,Q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Q.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.gateway}),(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,Q.jsxs)(`a`,{href:Ne(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,Q.jsx)(Ie,{className:`size-3.5`})]})]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[h?(0,Q.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,Q.jsx)(w,{type:`button`,variant:`secondary`,disabled:!M||d,onClick:te,children:n.discard}),(0,Q.jsx)(w,{type:`button`,variant:`primary`,disabled:!M||d,onClick:()=>void ee(),children:d?n.saving:n.save})]})]}),i?(0,Q.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,Q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Q.jsx)(ot,{className:`mt-0.5 size-4 shrink-0 text-red-600 dark:text-red-400`}),(0,Q.jsx)(`p`,{className:`text-sm text-red-900 dark:text-red-100`,children:n.tokenExpired})]}),(0,Q.jsx)(`div`,{children:(0,Q.jsx)(w,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:()=>a(),children:n.updateToken})})]}):null,M?(0,Q.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,p?(0,Q.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:p}):null,(0,Q.jsx)(`p`,{className:`rounded-lg border border-edge bg-surface-panel/60 px-3 py-2 text-xs text-fg-subtle`,children:n.restartHint}),s.auth.mode===`none`?(0,Q.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,Q.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[(0,Q.jsxs)(`div`,{className:`mb-5 flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Q.jsx)(Oe,{className:`size-4 text-accent`,strokeWidth:1.75}),t.settingsSections.gateway]}),(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[(0,Q.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,htmlFor:`gateway-listen-host`,children:n.listenHost}),(0,Q.jsx)(`input`,{id:`gateway-listen-host`,className:X(fr(),`font-mono text-xs`),value:s.host,onChange:e=>z(e.target.value),placeholder:n.listenHostPlaceholder,autoComplete:`off`})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,htmlFor:`gateway-listen-port`,children:n.listenPort}),(0,Q.jsx)(`input`,{id:`gateway-listen-port`,type:`number`,min:1,max:65535,className:X(fr(),`font-mono text-xs`),value:s.port,onChange:e=>{let t=Number(e.target.value);B(Number.isFinite(t)?Math.max(1,Math.min(65535,Math.floor(t))):s.port)}})]}),(0,Q.jsx)(`p`,{className:`sm:col-span-2 text-xs text-fg-subtle`,children:n.listenHint})]}),(0,Q.jsxs)(`div`,{className:`space-y-2 border-t border-edge pt-4`,children:[(0,Q.jsx)(`label`,{className:`text-sm font-medium text-fg`,htmlFor:`gateway-auth-mode`,children:n.authMode}),(0,Q.jsxs)(`select`,{id:`gateway-auth-mode`,value:s.auth.mode,onChange:e=>N({mode:e.target.value}),className:fr(),children:[(0,Q.jsx)(`option`,{value:`token`,children:n.authModeToken}),(0,Q.jsx)(`option`,{value:`password`,children:n.authModePassword}),(0,Q.jsx)(`option`,{value:`none`,children:n.authModeNoneLabel})]})]}),s.auth.mode===`token`?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(vr,{g:n,id:`gateway-access-token`,label:n.accessToken,help:n.tokenHelp,placeholder:n.tokenPlaceholder,value:s.auth.token,show:_,copied:x,onToggleShow:()=>v(e=>!e),onCopy:()=>void K(),onChange:e=>N({token:e})}),(0,Q.jsx)(w,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,onClick:()=>a(),children:n.changeToken})]}):null,s.auth.mode===`password`?(0,Q.jsx)(vr,{g:n,id:`gateway-auth-password`,label:n.authPassword,help:n.authPasswordHelp,placeholder:n.authPasswordPlaceholder,value:s.auth.password,show:y,onToggleShow:()=>b(e=>!e),onChange:e=>N({password:e})}):null,s.auth.mode===`none`?null:(0,Q.jsx)(_r,{g:n,rateLimit:s.auth.rateLimit,onChange:V}),(0,Q.jsxs)(`div`,{className:`space-y-2 border-t border-edge pt-4`,children:[(0,Q.jsx)(`label`,{className:`text-sm font-medium text-fg`,htmlFor:`gateway-update-channel`,children:n.updateChannel}),(0,Q.jsxs)(`select`,{id:`gateway-update-channel`,value:s.updateChannel,onChange:e=>P(e.target.value),className:fr(),children:[(0,Q.jsx)(`option`,{value:`stable`,children:n.channelStable}),(0,Q.jsx)(`option`,{value:`beta`,children:n.channelBeta}),(0,Q.jsx)(`option`,{value:`dev`,children:n.channelDev})]}),(0,Q.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.updateChannelHint})]}),(0,Q.jsx)(gr,{g:n,origins:s.corsOrigins,onChange:L})]})]}),(0,Q.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[(0,Q.jsxs)(`div`,{className:`mb-5 flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Q.jsx)(we,{className:`size-4 text-accent`,strokeWidth:1.75}),n.advancedSection]}),(0,Q.jsx)(`p`,{className:`mb-4 text-xs text-fg-subtle`,children:n.advancedSectionHint}),(0,Q.jsx)(mr,{g:n,form:s,onMaxSseConnectionsChange:H,onDeferModeChange:U,onDeferIdsChange:W,onSkipIdsChange:G})]})]}):(0,Q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:p??j??n.loadError}),(0,Q.jsx)(w,{type:`button`,variant:`secondary`,onClick:()=>void O(),children:n.retry})]}):(0,Q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Q.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.gateway}),(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}function mr(e){let t=(0,Z.c)(58),{g:n,form:r,onMaxSseConnectionsChange:i,onDeferModeChange:a,onDeferIdsChange:o,onSkipIdsChange:s}=e,c;t[0]===n.maxSseConnections?c=t[1]:(c=(0,Q.jsx)(`label`,{className:`mb-1 block text-sm font-medium text-fg`,htmlFor:`gateway-max-sse`,children:n.maxSseConnections}),t[0]=n.maxSseConnections,t[1]=c);let l;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(l=X(fr(),`max-w-xs font-mono text-xs`),t[2]=l):l=t[2];let u;t[3]===i?u=t[4]:(u=e=>{let t=Number(e.target.value);Number.isFinite(t)&&i(Math.max(1,Math.floor(t)))},t[3]=i,t[4]=u);let d;t[5]!==r.maxSseConnections||t[6]!==u?(d=(0,Q.jsx)(`input`,{id:`gateway-max-sse`,type:`number`,min:1,className:l,value:r.maxSseConnections,onChange:u}),t[5]=r.maxSseConnections,t[6]=u,t[7]=d):d=t[7];let f;t[8]===n.maxSseConnectionsHint?f=t[9]:(f=(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:n.maxSseConnectionsHint}),t[8]=n.maxSseConnectionsHint,t[9]=f);let p;t[10]!==c||t[11]!==d||t[12]!==f?(p=(0,Q.jsxs)(`div`,{children:[c,d,f]}),t[10]=c,t[11]=d,t[12]=f,t[13]=p):p=t[13];let m;t[14]===n.channelConnectDeferMode?m=t[15]:(m=(0,Q.jsx)(`label`,{className:`text-sm font-medium text-fg`,htmlFor:`gateway-channel-defer-mode`,children:n.channelConnectDeferMode}),t[14]=n.channelConnectDeferMode,t[15]=m);let h=r.channelConnectDeferMode,g;t[16]===a?g=t[17]:(g=e=>a(e.target.value),t[16]=a,t[17]=g);let _;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(_=fr(),t[18]=_):_=t[18];let v;t[19]===n.channelConnectDeferModeAuto?v=t[20]:(v=(0,Q.jsx)(`option`,{value:`auto`,children:n.channelConnectDeferModeAuto}),t[19]=n.channelConnectDeferModeAuto,t[20]=v);let y;t[21]===n.channelConnectDeferModeOff?y=t[22]:(y=(0,Q.jsx)(`option`,{value:`off`,children:n.channelConnectDeferModeOff}),t[21]=n.channelConnectDeferModeOff,t[22]=y);let b;t[23]===n.channelConnectDeferModeExplicit?b=t[24]:(b=(0,Q.jsx)(`option`,{value:`explicit`,children:n.channelConnectDeferModeExplicit}),t[23]=n.channelConnectDeferModeExplicit,t[24]=b);let x;t[25]!==r.channelConnectDeferMode||t[26]!==v||t[27]!==y||t[28]!==b||t[29]!==g?(x=(0,Q.jsxs)(`select`,{id:`gateway-channel-defer-mode`,value:h,onChange:g,className:_,children:[v,y,b]}),t[25]=r.channelConnectDeferMode,t[26]=v,t[27]=y,t[28]=b,t[29]=g,t[30]=x):x=t[30];let S;t[31]===n.channelConnectDeferModeHint?S=t[32]:(S=(0,Q.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.channelConnectDeferModeHint}),t[31]=n.channelConnectDeferModeHint,t[32]=S);let C;t[33]!==x||t[34]!==S||t[35]!==m?(C=(0,Q.jsxs)(`div`,{className:`space-y-2 border-t border-edge pt-4`,children:[m,x,S]}),t[33]=x,t[34]=S,t[35]=m,t[36]=C):C=t[36];let w;t[37]!==r.channelConnectDeferIds||t[38]!==r.channelConnectDeferMode||t[39]!==n.channelConnectDeferIds||t[40]!==n.channelConnectDeferIdsHint||t[41]!==n.channelIdListEmpty||t[42]!==n.channelIdListPlaceholder||t[43]!==o?(w=r.channelConnectDeferMode===`explicit`?(0,Q.jsx)(hr,{title:n.channelConnectDeferIds,hint:n.channelConnectDeferIdsHint,emptyText:n.channelIdListEmpty,placeholder:n.channelIdListPlaceholder,values:r.channelConnectDeferIds,maxItems:24,onChange:o}):null,t[37]=r.channelConnectDeferIds,t[38]=r.channelConnectDeferMode,t[39]=n.channelConnectDeferIds,t[40]=n.channelConnectDeferIdsHint,t[41]=n.channelIdListEmpty,t[42]=n.channelIdListPlaceholder,t[43]=o,t[44]=w):w=t[44];let T;t[45]!==r.channelConnectDeferMode||t[46]!==r.channelConnectDeferSkipIds||t[47]!==n.channelConnectDeferSkipIds||t[48]!==n.channelConnectDeferSkipIdsHint||t[49]!==n.channelIdListEmpty||t[50]!==n.channelIdListPlaceholder||t[51]!==s?(T=r.channelConnectDeferMode===`off`?null:(0,Q.jsx)(hr,{title:n.channelConnectDeferSkipIds,hint:n.channelConnectDeferSkipIdsHint,emptyText:n.channelIdListEmpty,placeholder:n.channelIdListPlaceholder,values:r.channelConnectDeferSkipIds,maxItems:24,onChange:s}),t[45]=r.channelConnectDeferMode,t[46]=r.channelConnectDeferSkipIds,t[47]=n.channelConnectDeferSkipIds,t[48]=n.channelConnectDeferSkipIdsHint,t[49]=n.channelIdListEmpty,t[50]=n.channelIdListPlaceholder,t[51]=s,t[52]=T):T=t[52];let E;return t[53]!==C||t[54]!==w||t[55]!==T||t[56]!==p?(E=(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[p,C,w,T]}),t[53]=C,t[54]=w,t[55]=T,t[56]=p,t[57]=E):E=t[57],E}function hr(e){let t=(0,Z.c)(25),{title:n,hint:r,emptyText:i,placeholder:a,values:o,maxItems:s,onChange:c,children:l}=e,u;t[0]!==s||t[1]!==c||t[2]!==o?(u=e=>{let t=e.trim();!t||o.includes(t)||o.length>=s||c([...o,t])},t[0]=s,t[1]=c,t[2]=o,t[3]=u):u=t[3];let d=u,f;t[4]===n?f=t[5]:(f=(0,Q.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n}),t[4]=n,t[5]=f);let p;t[6]===r?p=t[7]:(p=(0,Q.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:r}),t[6]=r,t[7]=p);let m;t[8]!==i||t[9]!==c||t[10]!==o?(m=o.length===0?(0,Q.jsx)(`p`,{className:`text-xs text-fg-muted`,children:i}):(0,Q.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:o.map(e=>(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-edge bg-surface-panel px-2 py-0.5 font-mono text-xs text-fg`,children:[e,(0,Q.jsx)(`button`,{type:`button`,className:`text-fg-muted hover:text-fg`,"aria-label":`Remove ${e}`,onClick:()=>c(o.filter(t=>t!==e)),children:`×`})]},e))}),t[8]=i,t[9]=c,t[10]=o,t[11]=m):m=t[11];let h;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(h=X(fr(),`font-mono text-xs`),t[12]=h):h=t[12];let g=o.length>=s,_;t[13]===d?_=t[14]:(_=e=>{e.key===`Enter`&&(e.preventDefault(),d(e.target.value),e.target.value=``)},t[13]=d,t[14]=_);let v;t[15]!==a||t[16]!==g||t[17]!==_?(v=(0,Q.jsx)(`input`,{className:h,placeholder:a,disabled:g,onKeyDown:_}),t[15]=a,t[16]=g,t[17]=_,t[18]=v):v=t[18];let y;return t[19]!==l||t[20]!==f||t[21]!==p||t[22]!==m||t[23]!==v?(y=(0,Q.jsxs)(`div`,{className:`space-y-2 border-t border-edge pt-4`,children:[f,p,m,v,l]}),t[19]=l,t[20]=f,t[21]=p,t[22]=m,t[23]=v,t[24]=y):y=t[24],y}function gr(e){let t=(0,Z.c)(13),{g:n,origins:r,onChange:i}=e,a;t[0]===r?a=t[1]:(a=r.includes(`*`),t[0]=r,t[1]=a);let o=a,s;t[2]!==n.corsOriginsWildcardWarning||t[3]!==o?(s=o?(0,Q.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.corsOriginsWildcardWarning}):null,t[2]=n.corsOriginsWildcardWarning,t[3]=o,t[4]=s):s=t[4];let c;return t[5]!==n.corsOrigins||t[6]!==n.corsOriginsEmpty||t[7]!==n.corsOriginsHint||t[8]!==n.corsOriginsPlaceholder||t[9]!==i||t[10]!==r||t[11]!==s?(c=(0,Q.jsx)(hr,{title:n.corsOrigins,hint:n.corsOriginsHint,emptyText:n.corsOriginsEmpty,placeholder:n.corsOriginsPlaceholder,values:r,maxItems:128,onChange:i,children:s}),t[5]=n.corsOrigins,t[6]=n.corsOriginsEmpty,t[7]=n.corsOriginsHint,t[8]=n.corsOriginsPlaceholder,t[9]=i,t[10]=r,t[11]=s,t[12]=c):c=t[12],c}function _r(e){let t=(0,Z.c)(63),{g:n,rateLimit:r,onChange:i}=e,a;t[0]===n.rateLimitTitle?a=t[1]:(a=(0,Q.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.rateLimitTitle}),t[0]=n.rateLimitTitle,t[1]=a);let o;t[2]===n.rateLimitHint?o=t[3]:(o=(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:n.rateLimitHint}),t[2]=n.rateLimitHint,t[3]=o);let s;t[4]!==a||t[5]!==o?(s=(0,Q.jsxs)(`div`,{children:[a,o]}),t[4]=a,t[5]=o,t[6]=s):s=t[6];let c;t[7]===i?c=t[8]:(c=e=>i({enabled:e.target.checked}),t[7]=i,t[8]=c);let l;t[9]!==r.enabled||t[10]!==c?(l=(0,Q.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:r.enabled,onChange:c}),t[9]=r.enabled,t[10]=c,t[11]=l):l=t[11];let u;t[12]!==n.rateLimitEnabled||t[13]!==l?(u=(0,Q.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[l,n.rateLimitEnabled]}),t[12]=n.rateLimitEnabled,t[13]=l,t[14]=u):u=t[14];let d;t[15]===n.rateLimitMaxAttempts?d=t[16]:(d=(0,Q.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,htmlFor:`gateway-rate-max`,children:n.rateLimitMaxAttempts}),t[15]=n.rateLimitMaxAttempts,t[16]=d);let f;t[17]===Symbol.for(`react.memo_cache_sentinel`)?(f=fr(),t[17]=f):f=t[17];let p=!r.enabled,m;t[18]===i?m=t[19]:(m=e=>{let t=Number(e.target.value);Number.isFinite(t)&&i({maxAttempts:Math.max(1,Math.floor(t))})},t[18]=i,t[19]=m);let h;t[20]!==r.maxAttempts||t[21]!==m||t[22]!==p?(h=(0,Q.jsx)(`input`,{id:`gateway-rate-max`,type:`number`,min:1,className:f,value:r.maxAttempts,disabled:p,onChange:m}),t[20]=r.maxAttempts,t[21]=m,t[22]=p,t[23]=h):h=t[23];let g;t[24]!==h||t[25]!==d?(g=(0,Q.jsxs)(`div`,{children:[d,h]}),t[24]=h,t[25]=d,t[26]=g):g=t[26];let _;t[27]===n.rateLimitWindowMinutes?_=t[28]:(_=(0,Q.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,htmlFor:`gateway-rate-window`,children:n.rateLimitWindowMinutes}),t[27]=n.rateLimitWindowMinutes,t[28]=_);let v;t[29]===Symbol.for(`react.memo_cache_sentinel`)?(v=fr(),t[29]=v):v=t[29];let y;t[30]===r.windowMs?y=t[31]:(y=Math.round(r.windowMs/6e4),t[30]=r.windowMs,t[31]=y);let b=!r.enabled,x;t[32]===i?x=t[33]:(x=e=>{let t=Number(e.target.value);Number.isFinite(t)&&t>0&&i({windowMs:Math.floor(t)*6e4})},t[32]=i,t[33]=x);let S;t[34]!==y||t[35]!==b||t[36]!==x?(S=(0,Q.jsx)(`input`,{id:`gateway-rate-window`,type:`number`,min:1,className:v,value:y,disabled:b,onChange:x}),t[34]=y,t[35]=b,t[36]=x,t[37]=S):S=t[37];let C;t[38]!==_||t[39]!==S?(C=(0,Q.jsxs)(`div`,{children:[_,S]}),t[38]=_,t[39]=S,t[40]=C):C=t[40];let w;t[41]===n.rateLimitBlockMinutes?w=t[42]:(w=(0,Q.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,htmlFor:`gateway-rate-block`,children:n.rateLimitBlockMinutes}),t[41]=n.rateLimitBlockMinutes,t[42]=w);let T;t[43]===Symbol.for(`react.memo_cache_sentinel`)?(T=fr(),t[43]=T):T=t[43];let E;t[44]===r.blockDurationMs?E=t[45]:(E=Math.round(r.blockDurationMs/6e4),t[44]=r.blockDurationMs,t[45]=E);let D=!r.enabled,O;t[46]===i?O=t[47]:(O=e=>{let t=Number(e.target.value);Number.isFinite(t)&&t>0&&i({blockDurationMs:Math.floor(t)*6e4})},t[46]=i,t[47]=O);let k;t[48]!==E||t[49]!==D||t[50]!==O?(k=(0,Q.jsx)(`input`,{id:`gateway-rate-block`,type:`number`,min:1,className:T,value:E,disabled:D,onChange:O}),t[48]=E,t[49]=D,t[50]=O,t[51]=k):k=t[51];let A;t[52]!==w||t[53]!==k?(A=(0,Q.jsxs)(`div`,{children:[w,k]}),t[52]=w,t[53]=k,t[54]=A):A=t[54];let j;t[55]!==g||t[56]!==C||t[57]!==A?(j=(0,Q.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[g,C,A]}),t[55]=g,t[56]=C,t[57]=A,t[58]=j):j=t[58];let M;return t[59]!==j||t[60]!==s||t[61]!==u?(M=(0,Q.jsxs)(`div`,{className:`space-y-3 border-t border-edge pt-4`,children:[s,u,j]}),t[59]=j,t[60]=s,t[61]=u,t[62]=M):M=t[62],M}function vr(e){let t=(0,Z.c)(34),{g:n,id:r,label:i,help:a,placeholder:o,value:s,show:c,copied:l,onToggleShow:u,onCopy:d,onChange:f}=e,p;t[0]!==r||t[1]!==i?(p=(0,Q.jsx)(`label`,{className:`text-sm font-medium text-fg`,htmlFor:r,children:i}),t[0]=r,t[1]=i,t[2]=p):p=t[2];let m;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(m=X(fr(),`min-w-0 flex-1 font-mono text-xs`),t[3]=m):m=t[3];let h=c?`text`:`password`,g;t[4]===f?g=t[5]:(g=e=>f(e.target.value),t[4]=f,t[5]=g);let _;t[6]!==r||t[7]!==o||t[8]!==h||t[9]!==g||t[10]!==s?(_=(0,Q.jsx)(`input`,{id:r,className:m,type:h,autoComplete:`off`,value:s,onChange:g,placeholder:o}),t[6]=r,t[7]=o,t[8]=h,t[9]=g,t[10]=s,t[11]=_):_=t[11];let v;t[12]!==l||t[13]!==n.copied||t[14]!==n.copy||t[15]!==d||t[16]!==s?(v=s&&d?(0,Q.jsxs)(w,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:d,children:[l?(0,Q.jsx)(Me,{className:`size-3.5`}):(0,Q.jsx)(ze,{className:`size-3.5`}),l?n.copied:n.copy]}):null,t[12]=l,t[13]=n.copied,t[14]=n.copy,t[15]=d,t[16]=s,t[17]=v):v=t[17];let y;t[18]===c?y=t[19]:(y=c?(0,Q.jsx)(Ce,{className:`size-3.5`}):(0,Q.jsx)(Ze,{className:`size-3.5`}),t[18]=c,t[19]=y);let b=c?n.hide:n.show,x;t[20]!==u||t[21]!==y||t[22]!==b?(x=(0,Q.jsxs)(w,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:u,children:[y,b]}),t[20]=u,t[21]=y,t[22]=b,t[23]=x):x=t[23];let S;t[24]!==_||t[25]!==v||t[26]!==x?(S=(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[_,v,x]}),t[24]=_,t[25]=v,t[26]=x,t[27]=S):S=t[27];let C;t[28]===a?C=t[29]:(C=(0,Q.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:a}),t[28]=a,t[29]=C);let T;return t[30]!==p||t[31]!==S||t[32]!==C?(T=(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[p,S,C]}),t[30]=p,t[31]=S,t[32]=C,t[33]=T):T=t[33],T}function yr(){return lt(`/api/channels/status`)}var br=Tt;function xr(){return X(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,u,`dark:border-edge`)}function Sr(){return X(mt,A)}function Cr(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 wr(){let e=F(e=>e.language),t=oe(e),n=t.heartbeatSettings,r=!!R(e=>e.token),[i,o]=(0,$.useState)(null),[c,l]=(0,$.useState)(null),[u,d]=(0,$.useState)(``),[f,p]=(0,$.useState)(``),[m,h]=(0,$.useState)(!1),[g,_]=(0,$.useState)(!1),[v,y]=(0,$.useState)(null),[b,x]=(0,$.useState)(!1),[S,C]=(0,$.useState)(!1),[T,E]=(0,$.useState)(!1),[D,O]=(0,$.useState)(!1),[k,A]=(0,$.useState)(null),[j,M]=(0,$.useState)([]),{data:N,error:P,isLoading:L,mutate:z}=I(r),{data:B,error:V,isLoading:H,mutate:U}=a(r?Zt():null,Jt,{revalidateOnFocus:!1}),{data:W=[]}=a(r?yr():null,br,{revalidateOnFocus:!1}),G=(0,$.useMemo)(()=>Cr(N?.payload?.config),[N]),ee=(0,$.useMemo)(()=>en(N?.payload?.config??{}),[N]),te=(0,$.useMemo)(()=>!i||!c?!1:JSON.stringify(i)!==JSON.stringify(c),[i,c]),K=(0,$.useMemo)(()=>u!==f,[u,f]);(0,$.useEffect)(()=>{if(!r){o(null),l(null);return}if(N!==void 0&&!te){let e=structuredClone(ee);o(e),l(e),x(!1)}},[r,N,ee,te]),(0,$.useEffect)(()=>{!r||B===void 0||K||(d(B),p(B),C(!1))},[r,B,K]);let q=P instanceof Error?P.message:P?String(P):V instanceof Error?V.message:V?String(V):null,ne=!!(r&&(N===void 0||B===void 0)&&!q&&(L||H));(0,$.useEffect)(()=>{if(!r||!i){M([]);return}let e=i.target.trim();if(!e){M([]);return}let t=!1;return Ct(e).then(e=>{t||M(e)}),()=>{t=!0}},[r,i?.target]);let J=(0,$.useCallback)(()=>{let e=i?.target?.trim();e&&Ct(e).then(M)},[i?.target]),re=(0,$.useCallback)(async()=>{E(!0),O(!1),A(null);try{await Yt(),O(!0),window.setTimeout(()=>O(!1),3e3)}catch(e){A(e instanceof Error?e.message:n.triggerError)}finally{E(!1)}},[n.triggerError]),ie=(0,$.useCallback)(e=>{o(t=>t?{...t,...e}:null)},[]),ae=(0,$.useCallback)(()=>{c&&(o(structuredClone(c)),x(!1),y(null))},[c]),se=(0,$.useCallback)(()=>{d(f),C(!1),y(null)},[f]),ce=(0,$.useCallback)(async()=>{if(!(!i||m)){h(!0),y(null),x(!1);try{await Xt(i),l(structuredClone(i)),x(!0),window.setTimeout(()=>x(!1),2500)}catch(e){y(e instanceof Error?e.message:n.saveConfigError)}finally{h(!1)}}},[i,m,n.saveConfigError]),le=(0,$.useCallback)(async()=>{if(!g){_(!0),y(null),C(!1);try{await Qt(u),p(u),C(!0),window.setTimeout(()=>C(!1),2500)}catch(e){y(e instanceof Error?e.message:n.saveDocError)}finally{_(!1)}}},[u,g,n.saveDocError]);return r?ne?(0,Q.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,Q.jsx)(Y,{className:`size-4 animate-spin`}),n.loading]})}):i?(0,Q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Q.jsx)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.heartbeat}),(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,Q.jsxs)(`a`,{href:Ne(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,Q.jsx)(Ie,{className:`size-3.5`})]})]})}),G?(0,Q.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.workspaceLabel,`: `,(0,Q.jsx)(`span`,{className:`font-mono text-fg-muted`,children:G})]}):null,v?(0,Q.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:v}):null,(0,Q.jsxs)(Kt,{children:[(0,Q.jsxs)(`div`,{className:`mb-2 flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Q.jsx)(s,{className:`size-4 text-accent`,strokeWidth:1.75}),n.configSection]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsxs)(w,{type:`button`,variant:`secondary`,className:`inline-flex items-center gap-2`,disabled:T,onClick:()=>void re(),children:[T?(0,Q.jsx)(Y,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Q.jsx)(Pe,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),T?n.triggering:n.triggerNow]}),D?(0,Q.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.triggered}):null]})]}),(0,Q.jsx)(`p`,{className:`mb-4 text-xs text-fg-subtle`,children:n.triggerHint}),k?(0,Q.jsx)(`p`,{className:`mb-3 text-sm text-red-600 dark:text-red-400`,children:k}):null,(0,Q.jsx)(Tr,{h:n,cron:t.cron,form:i,channels:W,sessionChatIds:j,onRefreshChatIds:J,update:ie,inputClassName:xr,selectClassName:Sr}),(0,Q.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-2`,children:[b?(0,Q.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.savedConfig}):null,(0,Q.jsx)(w,{type:`button`,variant:`secondary`,disabled:!te||m,onClick:ae,children:n.discard}),(0,Q.jsx)(w,{type:`button`,variant:`primary`,disabled:!te||m,onClick:()=>void ce(),children:m?n.savingConfig:n.saveConfig}),te?(0,Q.jsx)(`span`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedConfig}):null]})]}),(0,Q.jsxs)(Kt,{children:[(0,Q.jsx)(`div`,{className:`mb-2 text-sm font-semibold text-fg`,children:n.docSection}),(0,Q.jsx)(`p`,{className:`mb-3 text-xs text-fg-subtle`,children:n.docHint}),(0,Q.jsx)(`textarea`,{className:X(xr(),`min-h-[12rem] resize-y font-mono text-xs leading-relaxed`),value:u,onChange:e=>d(e.target.value),spellCheck:!1,"aria-label":n.docSection}),(0,Q.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-2`,children:[S?(0,Q.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.savedDoc}):null,(0,Q.jsx)(w,{type:`button`,variant:`secondary`,disabled:!K||g,onClick:se,children:n.discard}),(0,Q.jsx)(w,{type:`button`,variant:`primary`,disabled:!K||g,onClick:()=>void le(),children:g?n.savingDoc:n.saveDoc}),K?(0,Q.jsx)(`span`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedDoc}):null]})]})]}):(0,Q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:v??q??n.loadError}),(0,Q.jsx)(w,{type:`button`,variant:`secondary`,onClick:()=>{z(),U()},children:n.retry})]}):(0,Q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Q.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.heartbeat}),(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}function Tr(e){let t=(0,Z.c)(156),{h:n,cron:r,form:i,channels:a,sessionChatIds:o,onRefreshChatIds:s,update:c,inputClassName:l,selectClassName:u}=e,d;t[0]===a?d=t[1]:(d=new Set(a.map(Dr)),t[0]=a,t[1]=d);let f=d,p;t[2]===i.target?p=t[3]:(p=i.target.trim(),t[2]=i.target,t[3]=p);let m=p,g=!!(m&&!f.has(m)),_;t[4]===c?_=t[5]:(_=e=>c({enabled:e.target.checked}),t[4]=c,t[5]=_);let v;t[6]!==i.enabled||t[7]!==_?(v=(0,Q.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:i.enabled,onChange:_}),t[6]=i.enabled,t[7]=_,t[8]=v):v=t[8];let y;t[9]!==n.enable||t[10]!==v?(y=(0,Q.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[v,n.enable]}),t[9]=n.enable,t[10]=v,t[11]=y):y=t[11];let b;t[12]===c?b=t[13]:(b=e=>c({includeSystemPromptSection:e.target.checked}),t[12]=c,t[13]=b);let x;t[14]!==i.includeSystemPromptSection||t[15]!==b?(x=(0,Q.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:i.includeSystemPromptSection,onChange:b}),t[14]=i.includeSystemPromptSection,t[15]=b,t[16]=x):x=t[16];let S;t[17]===n.includeSystemPromptSectionHint?S=t[18]:(S=(0,Q.jsx)(`span`,{className:`mt-1 block text-xs text-fg-subtle`,children:n.includeSystemPromptSectionHint}),t[17]=n.includeSystemPromptSectionHint,t[18]=S);let C;t[19]!==n.includeSystemPromptSection||t[20]!==S?(C=(0,Q.jsxs)(`span`,{children:[n.includeSystemPromptSection,S]}),t[19]=n.includeSystemPromptSection,t[20]=S,t[21]=C):C=t[21];let T;t[22]!==x||t[23]!==C?(T=(0,Q.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[x,C]}),t[22]=x,t[23]=C,t[24]=T):T=t[24];let E;t[25]===c?E=t[26]:(E=e=>c({intervalMs:e}),t[25]=c,t[26]=E);let D;t[27]!==n.intervalPresets||t[28]!==n.intervalSecondsLabel?(D={secondsLabel:n.intervalSecondsLabel,presets:n.intervalPresets},t[27]=n.intervalPresets,t[28]=n.intervalSecondsLabel,t[29]=D):D=t[29];let O=`${n.intervalHintPreset} ${n.intervalHint}`,k;t[30]!==i.intervalMs||t[31]!==n.interval||t[32]!==E||t[33]!==D||t[34]!==O?(k=(0,Q.jsx)(An,{kind:`interval`,label:n.interval,valueMs:i.intervalMs,onChangeMs:E,labels:D,hint:O}),t[30]=i.intervalMs,t[31]=n.interval,t[32]=E,t[33]=D,t[34]=O,t[35]=k):k=t[35];let A;t[36]===n.deliveryTitle?A=t[37]:(A=(0,Q.jsx)(`div`,{className:`mb-2 text-sm font-medium text-fg`,children:n.deliveryTitle}),t[36]=n.deliveryTitle,t[37]=A);let j;t[38]===r.channel?j=t[39]:(j=(0,Q.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:r.channel}),t[38]=r.channel,t[39]=j);let M;t[40]===u?M=t[41]:(M=u(),t[40]=u,t[41]=M);let N;t[42]===c?N=t[43]:(N=e=>{c({target:e.target.value.trim(),targetChatId:``})},t[42]=c,t[43]=N);let P;t[44]===n.channelNone?P=t[45]:(P=(0,Q.jsx)(`option`,{value:``,children:n.channelNone}),t[44]=n.channelNone,t[45]=P);let F;t[46]!==n.customChannelSuffix||t[47]!==g||t[48]!==m?(F=g?(0,Q.jsxs)(`option`,{value:m,children:[m,` (`,n.customChannelSuffix,`)`]}):null,t[46]=n.customChannelSuffix,t[47]=g,t[48]=m,t[49]=F):F=t[49];let I;t[50]===a?I=t[51]:(I=a.map(Er),t[50]=a,t[51]=I);let L;t[52]!==M||t[53]!==N||t[54]!==P||t[55]!==F||t[56]!==I||t[57]!==m?(L=(0,Q.jsxs)(`select`,{className:M,value:m,onChange:N,children:[P,F,I]}),t[52]=M,t[53]=N,t[54]=P,t[55]=F,t[56]=I,t[57]=m,t[58]=L):L=t[58];let R;t[59]!==j||t[60]!==L?(R=(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[j,L]}),t[59]=j,t[60]=L,t[61]=R):R=t[61];let z;t[62]!==r.enterManuallyOrSelect||t[63]!==r.lastActiveLabels||t[64]!==r.noRecentChats||t[65]!==r.noRecentChatsOption||t[66]!==r.recipient||t[67]!==r.recipientPlaceholder||t[68]!==r.refreshList||t[69]!==r.refreshRecipientHint||t[70]!==r.selectRecipient||t[71]!==i.targetChatId||t[72]!==l||t[73]!==s||t[74]!==u||t[75]!==o||t[76]!==m||t[77]!==c?(z=m?(0,Q.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:r.recipient}),(0,Q.jsxs)(w,{type:`button`,variant:`ghost`,className:`h-7 gap-1 px-2 text-xs`,title:r.refreshRecipientHint,onClick:s,children:[(0,Q.jsx)(h,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0}),r.refreshList]})]}),(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(`input`,{type:`text`,className:X(l(),`min-w-0 flex-1`),value:i.targetChatId,onChange:e=>c({targetChatId:e.target.value}),placeholder:r.recipientPlaceholder,autoComplete:`off`}),(0,Q.jsxs)(`select`,{className:X(u(),`max-w-[10rem] shrink-0 text-xs`),value:i.targetChatId,onChange:e=>{let t=e.target.value;t&&c({targetChatId:t})},children:[(0,Q.jsx)(`option`,{value:``,children:r.selectRecipient}),o.length>0?o.map(e=>(0,Q.jsx)(`option`,{value:e.chatId,children:St(e,r.lastActiveLabels)},`${e.channel}-${e.chatId}`)):(0,Q.jsx)(`option`,{value:``,disabled:!0,children:r.noRecentChatsOption})]})]}),(0,Q.jsx)(`p`,{className:`text-xs text-fg-muted`,children:o.length>0?r.enterManuallyOrSelect:r.noRecentChats})]}):null,t[62]=r.enterManuallyOrSelect,t[63]=r.lastActiveLabels,t[64]=r.noRecentChats,t[65]=r.noRecentChatsOption,t[66]=r.recipient,t[67]=r.recipientPlaceholder,t[68]=r.refreshList,t[69]=r.refreshRecipientHint,t[70]=r.selectRecipient,t[71]=i.targetChatId,t[72]=l,t[73]=s,t[74]=u,t[75]=o,t[76]=m,t[77]=c,t[78]=z):z=t[78];let B;t[79]===n.deliveryHint?B=t[80]:(B=(0,Q.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:n.deliveryHint}),t[79]=n.deliveryHint,t[80]=B);let V;t[81]!==A||t[82]!==R||t[83]!==z||t[84]!==B?(V=(0,Q.jsxs)(`div`,{className:`border-t border-edge-subtle pt-4`,children:[A,R,z,B]}),t[81]=A,t[82]=R,t[83]=z,t[84]=B,t[85]=V):V=t[85];let H;t[86]===n.prompt?H=t[87]:(H=(0,Q.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:n.prompt}),t[86]=n.prompt,t[87]=H);let U;t[88]===l?U=t[89]:(U=X(l(),`min-h-[4.5rem] resize-y font-mono text-xs`),t[88]=l,t[89]=U);let W;t[90]===c?W=t[91]:(W=e=>c({prompt:e.target.value}),t[90]=c,t[91]=W);let G;t[92]!==i.prompt||t[93]!==n.promptPlaceholder||t[94]!==U||t[95]!==W?(G=(0,Q.jsx)(`textarea`,{className:U,value:i.prompt,onChange:W,placeholder:n.promptPlaceholder}),t[92]=i.prompt,t[93]=n.promptPlaceholder,t[94]=U,t[95]=W,t[96]=G):G=t[96];let ee;t[97]===n.promptHint?ee=t[98]:(ee=(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:n.promptHint}),t[97]=n.promptHint,t[98]=ee);let te;t[99]!==H||t[100]!==G||t[101]!==ee?(te=(0,Q.jsxs)(`div`,{children:[H,G,ee]}),t[99]=H,t[100]=G,t[101]=ee,t[102]=te):te=t[102];let K;t[103]===n.ackMaxChars?K=t[104]:(K=(0,Q.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:n.ackMaxChars}),t[103]=n.ackMaxChars,t[104]=K);let q;t[105]===l?q=t[106]:(q=l(),t[105]=l,t[106]=q);let ne=i.ackMaxChars===``?``:i.ackMaxChars,J;t[107]===c?J=t[108]:(J=e=>{let t=e.target.value;if(t===``)c({ackMaxChars:``});else{let e=parseInt(t,10);c({ackMaxChars:Number.isFinite(e)?e:``})}},t[107]=c,t[108]=J);let re;t[109]!==n.ackDefaultPlaceholder||t[110]!==q||t[111]!==ne||t[112]!==J?(re=(0,Q.jsx)(`input`,{type:`number`,min:1,className:q,value:ne,onChange:J,placeholder:n.ackDefaultPlaceholder}),t[109]=n.ackDefaultPlaceholder,t[110]=q,t[111]=ne,t[112]=J,t[113]=re):re=t[113];let ie;t[114]===n.ackMaxCharsHint?ie=t[115]:(ie=(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:n.ackMaxCharsHint}),t[114]=n.ackMaxCharsHint,t[115]=ie);let ae;t[116]!==K||t[117]!==re||t[118]!==ie?(ae=(0,Q.jsxs)(`div`,{children:[K,re,ie]}),t[116]=K,t[117]=re,t[118]=ie,t[119]=ae):ae=t[119];let oe;t[120]===c?oe=t[121]:(oe=e=>c({isolatedSession:e.target.checked}),t[120]=c,t[121]=oe);let Y;t[122]!==i.isolatedSession||t[123]!==oe?(Y=(0,Q.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:i.isolatedSession,onChange:oe}),t[122]=i.isolatedSession,t[123]=oe,t[124]=Y):Y=t[124];let se;t[125]===n.isolatedSessionHint?se=t[126]:(se=(0,Q.jsx)(`span`,{className:`mt-1 block text-xs text-fg-subtle`,children:n.isolatedSessionHint}),t[125]=n.isolatedSessionHint,t[126]=se);let ce;t[127]!==n.isolatedSession||t[128]!==se?(ce=(0,Q.jsxs)(`span`,{children:[n.isolatedSession,se]}),t[127]=n.isolatedSession,t[128]=se,t[129]=ce):ce=t[129];let le;t[130]!==Y||t[131]!==ce?(le=(0,Q.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[Y,ce]}),t[130]=Y,t[131]=ce,t[132]=le):le=t[132];let ue;t[133]===c?ue=t[134]:(ue=e=>c({activeHours:e}),t[133]=c,t[134]=ue);let de;t[135]!==n.activeEnd||t[136]!==n.activeStart||t[137]!==n.activeTimezone||t[138]!==n.addActiveHours||t[139]!==n.clearActiveHours?(de={start:n.activeStart,end:n.activeEnd,timezone:n.activeTimezone,add:n.addActiveHours,clear:n.clearActiveHours},t[135]=n.activeEnd,t[136]=n.activeStart,t[137]=n.activeTimezone,t[138]=n.addActiveHours,t[139]=n.clearActiveHours,t[140]=de):de=t[140];let fe;t[141]!==i.activeHours||t[142]!==n.activeHoursHint||t[143]!==n.activeHoursTitle||t[144]!==ue||t[145]!==de?(fe=(0,Q.jsx)(`div`,{className:`border-t border-edge-subtle pt-4`,children:(0,Q.jsx)(An,{kind:`active-hours`,label:n.activeHoursTitle,value:i.activeHours,onChange:ue,labels:de,hint:n.activeHoursHint})}),t[141]=i.activeHours,t[142]=n.activeHoursHint,t[143]=n.activeHoursTitle,t[144]=ue,t[145]=de,t[146]=fe):fe=t[146];let pe;return t[147]!==T||t[148]!==k||t[149]!==V||t[150]!==te||t[151]!==ae||t[152]!==le||t[153]!==fe||t[154]!==y?(pe=(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[y,T,k,V,te,ae,le,fe]}),t[147]=T,t[148]=k,t[149]=V,t[150]=te,t[151]=ae,t[152]=le,t[153]=fe,t[154]=y,t[155]=pe):pe=t[155],pe}function Er(e){return(0,Q.jsxs)(`option`,{value:e.name,disabled:!e.enabled,children:[e.name,` `,e.enabled?``:`(disabled)`]},e.name)}function Dr(e){return e.name}function Or(){return X(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,u,`dark:border-edge`)}function kr(e){let t=(0,Z.c)(47),{pairQr:n}=e,r=F(Ar),i;t[0]===r?i=t[1]:(i=oe(r),t[0]=r,t[1]=i);let a=i.tunnelSettings,{tunnelActive:o,tunnelStatus:s,tunnelQr:c,pairBaseUrl:l,setPairBaseUrl:u,baseOk:d,localhostWarn:f,deepLink:p,qrPayload:m,qrDataUrl:h,qrGenFailed:g,encoding:_,linkCopied:v,copyDeepLink:y}=n,b;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,Q.jsx)(tt,{className:`size-4 text-accent`,strokeWidth:1.75}),t[2]=b):b=t[2];let x;t[3]===a.pairTitle?x=t[4]:(x=(0,Q.jsxs)(`div`,{className:`mb-3 flex items-center gap-2 text-sm font-semibold text-fg`,children:[b,a.pairTitle]}),t[3]=a.pairTitle,t[4]=x);let S=o?a.pairTunnelActive:a.pairSubtitle,C;t[5]===S?C=t[6]:(C=(0,Q.jsx)(`p`,{className:`mb-3 text-xs text-fg-subtle`,children:S}),t[5]=S,t[6]=C);let T;t[7]!==d||t[8]!==f||t[9]!==l||t[10]!==u||t[11]!==a.pairBaseUrlHint||t[12]!==a.pairBaseUrlLabel||t[13]!==a.pairInvalidBaseUrl||t[14]!==a.pairLocalhostWarning||t[15]!==a.pairTunnelLanUrl||t[16]!==a.pairTunnelPublicUrl||t[17]!==o||t[18]!==c||t[19]!==s?.publicUrl?(T=o?(0,Q.jsxs)(`div`,{className:`mb-3 space-y-2 rounded-lg border border-edge bg-surface-panel px-3 py-3`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-xs font-medium text-fg-muted`,children:a.pairTunnelPublicUrl}),(0,Q.jsx)(`div`,{className:`mt-0.5 break-all font-mono text-xs text-fg`,children:s?.publicUrl})]}),c?.lanUrl?(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-xs font-medium text-fg-muted`,children:a.pairTunnelLanUrl}),(0,Q.jsx)(`div`,{className:`mt-0.5 break-all font-mono text-xs text-fg`,children:c.lanUrl})]}):null]}):(0,Q.jsxs)(`div`,{className:`mb-3 space-y-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-sm font-medium text-fg`,htmlFor:`tunnel-mobile-pair-base`,children:a.pairBaseUrlLabel}),(0,Q.jsx)(`input`,{id:`tunnel-mobile-pair-base`,className:X(Or(),`font-mono text-xs`),type:`text`,autoComplete:`off`,spellCheck:!1,value:l,onChange:e=>u(e.target.value)}),(0,Q.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:a.pairBaseUrlHint}),d?null:(0,Q.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:a.pairInvalidBaseUrl}),f?(0,Q.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:a.pairLocalhostWarning}):null]}),t[7]=d,t[8]=f,t[9]=l,t[10]=u,t[11]=a.pairBaseUrlHint,t[12]=a.pairBaseUrlLabel,t[13]=a.pairInvalidBaseUrl,t[14]=a.pairLocalhostWarning,t[15]=a.pairTunnelLanUrl,t[16]=a.pairTunnelPublicUrl,t[17]=o,t[18]=c,t[19]=s?.publicUrl,t[20]=T):T=t[20];let E;t[21]===a.pairSecurityNote?E=t[22]:(E=(0,Q.jsx)(`p`,{className:`mb-3 text-xs text-fg-subtle`,children:a.pairSecurityNote}),t[21]=a.pairSecurityNote,t[22]=E);let D;t[23]!==y||t[24]!==p||t[25]!==_||t[26]!==v||t[27]!==h||t[28]!==g||t[29]!==a.pairCopied||t[30]!==a.pairCopyLink||t[31]!==a.pairEncoding||t[32]!==a.pairImageError?(D=p?(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-3 sm:items-start`,children:[h&&!g?(0,Q.jsx)(`img`,{src:h,alt:``,className:`size-56 rounded-lg border border-edge-subtle bg-white object-contain p-3 dark:border-edge`}):null,_?(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:a.pairEncoding}):null,g?(0,Q.jsx)(`p`,{className:`text-center text-sm text-fg-muted sm:text-left`,children:a.pairImageError}):null,(0,Q.jsxs)(w,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,disabled:!p,onClick:()=>void y(),children:[v?(0,Q.jsx)(Me,{className:`size-3.5`}):(0,Q.jsx)(ze,{className:`size-3.5`}),v?a.pairCopied:a.pairCopyLink]})]}):null,t[23]=y,t[24]=p,t[25]=_,t[26]=v,t[27]=h,t[28]=g,t[29]=a.pairCopied,t[30]=a.pairCopyLink,t[31]=a.pairEncoding,t[32]=a.pairImageError,t[33]=D):D=t[33];let O;t[34]!==m||t[35]!==a.deeplinkTitle?(O=m?(0,Q.jsxs)(`details`,{className:`mt-3 rounded-lg border border-edge bg-surface-panel px-3 py-2`,children:[(0,Q.jsx)(`summary`,{className:`cursor-pointer text-xs font-medium text-fg-muted`,children:a.deeplinkTitle}),(0,Q.jsx)(`p`,{className:`mt-2 break-all font-mono text-[10px] leading-relaxed text-fg-subtle`,children:m})]}):null,t[34]=m,t[35]=a.deeplinkTitle,t[36]=O):O=t[36];let k;t[37]===a.pairSchemeHint?k=t[38]:(k=(0,Q.jsx)(`p`,{className:`mt-3 break-all font-mono text-[10px] leading-relaxed text-fg-subtle`,children:a.pairSchemeHint}),t[37]=a.pairSchemeHint,t[38]=k);let A;return t[39]!==k||t[40]!==x||t[41]!==C||t[42]!==T||t[43]!==E||t[44]!==D||t[45]!==O?(A=(0,Q.jsxs)(Kt,{children:[x,C,T,E,D,O,k]}),t[39]=k,t[40]=x,t[41]=C,t[42]=T,t[43]=E,t[44]=D,t[45]=O,t[46]=A):A=t[46],A}function Ar(e){return e.language}function jr(e){let t=(0,Z.c)(40),{open:n,title:r,intro:i,bullets:a,checkboxLabel:o,confirmLabel:s,cancelLabel:c,onConfirm:l,onCancel:u}=e,[d,p]=(0,$.useState)(!1),m;t[0]===u?m=t[1]:(m=e=>{e||(p(!1),u())},t[0]=u,t[1]=m);let h;t[2]===Symbol.for(`react.memo_cache_sentinel`)?(h=(0,Q.jsx)(se,{className:X(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,Fe)}),t[2]=h):h=t[2];let g;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(g=X(`fixed left-1/2 top-1/2 max-h-[min(90vh,40rem)] w-[min(100%-2rem,32rem)] -translate-x-1/2 -translate-y-1/2`,`overflow-y-auto rounded-2xl border border-edge bg-surface-panel p-6 shadow-popover outline-none dark:border-edge`,Xe),t[3]=g):g=t[3];let _;t[4]===r?_=t[5]:(_=(0,Q.jsx)(ce,{className:`text-base font-semibold text-fg`,children:r}),t[4]=r,t[5]=_);let v;t[6]===i?v=t[7]:(v=(0,Q.jsx)(f,{className:`mt-2 text-sm text-fg-muted`,children:i}),t[6]=i,t[7]=v);let y;t[8]===a?y=t[9]:(y=a.map(Mr),t[8]=a,t[9]=y);let b;t[10]===y?b=t[11]:(b=(0,Q.jsx)(`ul`,{className:`mt-4 list-disc space-y-2 pl-5 text-sm text-fg-muted`,children:y}),t[10]=y,t[11]=b);let x;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(x=e=>p(e.target.checked),t[12]=x):x=t[12];let S;t[13]===d?S=t[14]:(S=(0,Q.jsx)(`input`,{type:`checkbox`,className:`mt-0.5 size-4 shrink-0 rounded border-edge accent-accent`,checked:d,onChange:x}),t[13]=d,t[14]=S);let C;t[15]===o?C=t[16]:(C=(0,Q.jsx)(`span`,{children:o}),t[15]=o,t[16]=C);let E;t[17]!==C||t[18]!==S?(E=(0,Q.jsxs)(`label`,{className:`mt-5 flex cursor-pointer items-start gap-3 text-sm text-fg`,children:[S,C]}),t[17]=C,t[18]=S,t[19]=E):E=t[19];let D;t[20]!==c||t[21]!==u?(D=(0,Q.jsx)(w,{type:`button`,variant:`secondary`,onClick:u,children:c}),t[20]=c,t[21]=u,t[22]=D):D=t[22];let O=!d,k;t[23]!==s||t[24]!==l||t[25]!==O?(k=(0,Q.jsx)(w,{type:`button`,disabled:O,onClick:l,children:s}),t[23]=s,t[24]=l,t[25]=O,t[26]=k):k=t[26];let A;t[27]!==D||t[28]!==k?(A=(0,Q.jsxs)(`div`,{className:`mt-6 flex justify-end gap-2`,children:[D,k]}),t[27]=D,t[28]=k,t[29]=A):A=t[29];let j;t[30]!==E||t[31]!==A||t[32]!==_||t[33]!==v||t[34]!==b?(j=(0,Q.jsxs)(T,{children:[h,(0,Q.jsxs)(gt,{className:g,onOpenAutoFocus:Nr,children:[_,v,b,E,A]})]}),t[30]=E,t[31]=A,t[32]=_,t[33]=v,t[34]=b,t[35]=j):j=t[35];let M;return t[36]!==n||t[37]!==m||t[38]!==j?(M=(0,Q.jsx)(ae,{open:n,onOpenChange:m,children:j}),t[36]=n,t[37]=m,t[38]=j,t[39]=M):M=t[39],M}function Mr(e){return(0,Q.jsx)(`li`,{children:e},e)}function Nr(e){return e.preventDefault()}async function Pr(){return v(lt(`/api/tunnel/status`))}async function Fr(){await v(lt(`/api/tunnel/consent`),{method:`POST`,body:JSON.stringify({})})}async function Ir(){return v(lt(`/api/tunnel/start`),{method:`POST`,body:JSON.stringify({})})}async function Lr(e){return v(lt(`/api/tunnel/stop`),{method:`POST`,body:JSON.stringify({release:e?.release===!0})})}async function Rr(){return v(lt(`/api/tunnel/qr`))}async function zr(){return v(lt(`/api/tunnel/pair`),{method:`POST`,body:JSON.stringify({})})}async function Br(e){await v(lt(`/api/config`),{method:`PATCH`,body:JSON.stringify({tunnel:e})})}var Vr=e(qt(),1),Hr={width:216,margin:2,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}};async function Ur(e){return Vr.toDataURL(e,Hr)}function Wr(e){let t=!!e,{mutate:n}=i(),{data:r}=a(t?`tunnel-status`:null,Pr,{refreshInterval:6e4});(0,$.useEffect)(()=>{let e=()=>{n(`tunnel-status`),n(`tunnel-qr`),n(`tunnel-pair`)};return window.addEventListener(`tunnel-status`,e),()=>window.removeEventListener(`tunnel-status`,e)},[n]);let o=r?.state===`connected`&&!!r.publicUrl?.trim(),{data:s,mutate:c}=a(o&&t?`tunnel-qr`:null,Rr,{refreshInterval:4*6e4}),{data:l,mutate:u}=a(!o&&t?`tunnel-pair`:null,zr,{refreshInterval:4*6e4}),[d,f]=(0,$.useState)(m),[p,h]=(0,$.useState)(null),[g,_]=(0,$.useState)(!1),[v,y]=(0,$.useState)(!1),[b,x]=(0,$.useState)(``),S=d.trim(),C=(0,$.useMemo)(()=>{try{let e=new URL(S);return e.protocol===`http:`||e.protocol===`https:`}catch{return!1}},[S]),w=(0,$.useMemo)(()=>e?b.trim()?b.trim():o&&s?.qrPayload?.trim()?s.qrPayload.trim():!C||!l?.pairingSecret?``:K({baseUrl:S,pairingSecret:l.pairingSecret,lanUrl:null}):``,[C,e,l?.pairingSecret,b,S,o,s?.qrPayload]);(0,$.useEffect)(()=>{if(!w){h(null),_(!1);return}let e=!1;return _(!1),Ur(w).then(t=>{e||h(t)}).catch(()=>{e||(_(!0),h(null))}),()=>{e=!0}},[w]);let T=(0,$.useCallback)(async e=>{if(e?.trim()){x(e.trim()),c({qrPayload:e.trim(),publicUrl:r?.publicUrl??``,lanUrl:s?.lanUrl??null},!1);return}x(``),o?await c():await u()},[u,c,o,s?.lanUrl,r?.publicUrl]);return{tunnelActive:o,tunnelStatus:r,tunnelQr:s,pairBaseUrl:d,setPairBaseUrl:f,baseOk:C,localhostWarn:C&&st(S),deepLink:w,qrPayload:w,qrDataUrl:p,qrGenFailed:g,encoding:!!(w&&!p&&!g),linkCopied:v,copyDeepLink:(0,$.useCallback)(async()=>{w&&(await navigator.clipboard.writeText(w).catch(()=>{}),y(!0),window.setTimeout(()=>y(!1),2e3))},[w]),refreshQr:T}}function Gr(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}var Kr=[`preparing_frpc`,`registering`,`provisioning_tls`,`starting_frpc`];function qr(e){return e?e===`reconnecting_frpc`?Kr.indexOf(`starting_frpc`):Kr.indexOf(e):-1}function Jr(e,t){if(t.state===`connected`)return`done`;let n=t.startProgress?.phase,r=Kr.indexOf(e),i=qr(n);return i<0?t.state===`connecting`||t.state===`reconnecting`?`active`:`pending`:r<i?`done`:r===i?`active`:`pending`}function Yr(e,t,n){let r=n.startProgress;if(Jr(t,n)!==`active`)return null;if(t===`preparing_frpc`&&n.frpcDownload)return n.frpcDownload.phase===`extracting`?e.frpcExtracting:n.frpcDownload.percent==null?e.frpcDownloading:e.frpcDownloadingPercent.replace(`{{percent}}`,String(n.frpcDownload.percent));if(t===`registering`&&r?.publicUrl)return e.stepRegisterDetail;if(t===`provisioning_tls`&&r?.acmeStep)switch(r.acmeStep){case`checking`:return e.stepTlsChecking;case`dns_challenge`:return e.stepTlsDnsChallenge;case`dns_propagation`:return e.stepTlsDnsPropagation;case`ca_validation`:return e.stepTlsCaValidation;case`issuing`:return e.stepTlsIssuing;default:return e.stepTlsDetail}return t===`starting_frpc`?r?.phase===`reconnecting_frpc`?e.stepReconnectDetail:e.stepFrpcDetail:null}function Xr(e,t){switch(t){case`preparing_frpc`:return e.stepPrepareFrpc;case`registering`:return e.stepRegister;case`provisioning_tls`:return e.stepTls;case`starting_frpc`:return e.stepFrpcLogin}}function Zr(e){if(!e)return null;let t=Math.max(0,Math.floor((Date.now()-new Date(e).getTime())/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}m ${t%60}s`}function Qr(e){let t=(0,Z.c)(37),{status:n,t:r}=e,[,i]=(0,$.useState)(0),a;t[0]!==i||t[1]!==n.state?(a=()=>{if(n.state!==`connecting`&&n.state!==`reconnecting`)return;let e=window.setInterval(()=>i($r),1e3);return()=>window.clearInterval(e)},t[0]=i,t[1]=n.state,t[2]=a):a=t[2];let o=n.startProgress?.startedAt,s;if(t[3]!==n.state||t[4]!==o?(s=[n.state,o],t[3]=n.state,t[4]=o,t[5]=s):s=t[5],(0,$.useEffect)(a,s),!(n.state===`connecting`||n.state===`reconnecting`||n.state===`connected`&&n.startProgress))return null;let c=n.config?.e2e?.enabled!==!1,l,u,d,f,p;if(t[6]!==c||t[7]!==n||t[8]!==r){let e;t[14]===c?e=t[15]:(e=e=>e!==`provisioning_tls`||c,t[14]=c,t[15]=e);let i=Kr.filter(e),a=Zr(n.startProgress?.startedAt);l=!!n.publicUrl&&n.state!==`connected`&&n.startProgress?.phase!==`registering`,u=`mt-3 space-y-3 rounded-lg border border-edge-subtle bg-surface-panel px-3 py-3`;let o;t[16]===r.startProgressTitle?o=t[17]:(o=(0,Q.jsx)(`p`,{className:`text-xs font-medium text-fg`,children:r.startProgressTitle}),t[16]=r.startProgressTitle,t[17]=o);let s;t[18]===r.startProgressHint?s=t[19]:(s=(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:r.startProgressHint}),t[18]=r.startProgressHint,t[19]=s),t[20]!==s||t[21]!==o?(d=(0,Q.jsxs)(`div`,{children:[o,s]}),t[20]=s,t[21]=o,t[22]=d):d=t[22];let m;t[23]!==n||t[24]!==r?(m=e=>{let t=Jr(e,n),i=Yr(r,e,n);return(0,Q.jsxs)(`li`,{className:`flex gap-2 text-xs`,children:[(0,Q.jsx)(`span`,{className:`mt-0.5 shrink-0 text-fg-subtle`,"aria-hidden":!0,children:t===`done`?(0,Q.jsx)(Me,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`}):t===`active`?(0,Q.jsx)(Y,{className:`size-3.5 animate-spin text-accent`}):(0,Q.jsx)(Se,{className:`size-3.5`})}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`div`,{className:X(`font-medium`,t===`active`?`text-fg`:t===`done`?`text-fg-muted`:`text-fg-subtle`),children:Xr(r,e)}),i?(0,Q.jsx)(`div`,{className:`mt-0.5 text-fg-muted`,children:i}):null,e===`preparing_frpc`&&t===`active`&&n.frpcDownload&&n.frpcDownload.phase===`downloading`?(0,Q.jsxs)(`div`,{className:`mt-2 space-y-1`,children:[(0,Q.jsx)(`div`,{className:`h-1.5 w-full overflow-hidden rounded-full bg-surface-panel`,children:(0,Q.jsx)(`div`,{className:X(`h-full rounded-full bg-accent transition-[width] duration-300`,n.frpcDownload.percent==null&&`w-1/3 animate-pulse`),style:n.frpcDownload.percent==null?void 0:{width:`${n.frpcDownload.percent}%`}})}),n.frpcDownload.bytesReceived!=null&&n.frpcDownload.totalBytes?(0,Q.jsxs)(`p`,{className:`text-fg-subtle`,children:[Gr(n.frpcDownload.bytesReceived),` /`,` `,Gr(n.frpcDownload.totalBytes)]}):null]}):null]})]},e)},t[23]=n,t[24]=r,t[25]=m):m=t[25];let h=i.map(m);t[26]===h?f=t[27]:(f=(0,Q.jsx)(`ol`,{className:`space-y-2`,children:h}),t[26]=h,t[27]=f),p=a&&n.startProgress?(0,Q.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:r.startProgressElapsed.replace(`{{elapsed}}`,a)}):null,t[6]=c,t[7]=n,t[8]=r,t[9]=l,t[10]=u,t[11]=d,t[12]=f,t[13]=p}else l=t[9],u=t[10],d=t[11],f=t[12],p=t[13];let m;t[28]!==l||t[29]!==r.publicUrlPendingNotice?(m=l?(0,Q.jsx)(`p`,{className:`text-xs text-fg-muted`,children:r.publicUrlPendingNotice}):null,t[28]=l,t[29]=r.publicUrlPendingNotice,t[30]=m):m=t[30];let h;return t[31]!==u||t[32]!==d||t[33]!==f||t[34]!==p||t[35]!==m?(h=(0,Q.jsxs)(`div`,{className:u,children:[d,f,p,m]}),t[31]=u,t[32]=d,t[33]=f,t[34]=p,t[35]=m,t[36]=h):h=t[36],h}function $r(e){return e+1}function ei(e,t){return t.state===`connected`?e.statusConnected:t.state===`error`?e.statusError:t.startProgress?.phase===`reconnecting_frpc`?e.statusReconnecting:t.startProgress?.phase===`provisioning_tls`?e.statusProvisioningTls:t.startProgress?.phase===`starting_frpc`?e.statusStartingFrpc:t.startProgress?.phase===`registering`?e.statusRegistering:t.startProgress?.phase===`preparing_frpc`||t.frpcDownload?e.statusPreparingFrpc:t.state===`connecting`||t.state===`reconnecting`?e.statusConnecting:e.statusOff}function ti(e){return e.state===`connected`?`bg-emerald-500`:e.state===`connecting`||e.state===`reconnecting`?`bg-amber-500 animate-pulse`:e.state===`error`?`bg-red-500`:`bg-fg-subtle`}function ni(e){if(!e)return`—`;let t=Date.now()-new Date(e).getTime();if(t<0)return`—`;let n=Math.floor(t/6e4);return n<60?`${n}m`:`${Math.floor(n/60)}h ${n%60}m`}function ri(){let e=oe(F(e=>e.language)).tunnelSettings,t=R(e=>e.token),n=!!t,[r,i]=(0,$.useState)(null),[o,s]=(0,$.useState)(!1),[c,l]=(0,$.useState)(!1),[u,d]=(0,$.useState)(!1),[f,p]=(0,$.useState)(!1),[m,g]=(0,$.useState)(!1),[_,v]=(0,$.useState)(!1),[y,b]=(0,$.useState)(!1),[x,S]=(0,$.useState)(!1),[C,T]=(0,$.useState)(``),[E,D]=(0,$.useState)(!1),[O,k]=(0,$.useState)(null),A=Wr(t??``),{data:j}=I(n),{data:M,error:N,isLoading:L,mutate:z}=a(n?`tunnel-status`:null,Pr,{refreshInterval:e=>o?1e3:e?.frpcDownload||e?.state===`connecting`||e?.state===`reconnecting`?2e3:6e4}),B=(0,$.useMemo)(()=>{let e=j?.payload?.config;if(e&&typeof e==`object`&&!Array.isArray(e)){let t=e.tunnel;if(t&&typeof t==`object`&&!Array.isArray(t)&&t.autoStart===!0)return!0}return M?.config?.autoStart===!0},[j,M?.config?.autoStart]),V=ke((0,$.useMemo)(()=>{let e=j?.payload?.config;if(e&&typeof e==`object`&&!Array.isArray(e)){let t=e.tunnel;if(t&&typeof t==`object`&&!Array.isArray(t)){let e=t.registrationSecret;if(typeof e==`string`)return e}}return``},[j])),H=M?.registrationSecret?.source===`env`,U=M?.registrationSecret?.source===`missing`;(0,$.useEffect)(()=>{let e=()=>{z()};return window.addEventListener(`tunnel-status`,e),()=>window.removeEventListener(`tunnel-status`,e)},[z]);let W=(0,$.useMemo)(()=>[e.consentBullet1,e.consentBullet2,e.consentBullet3],[e.consentBullet1,e.consentBullet2,e.consentBullet3]),G=(0,$.useCallback)(async()=>{i(null),s(!0);try{let e=await Ir();await z(),P(),await A.refreshQr(e.qrPayload)}catch(e){i(e instanceof Error?e.message:String(e))}finally{s(!1)}},[z,A.refreshQr]),ee=(0,$.useCallback)(()=>{if(M?.consentRequired){g(!0);return}G()},[M?.consentRequired,G]),te=(0,$.useCallback)(async()=>{g(!1),i(null);try{await Fr(),await z(),await G()}catch(e){i(e instanceof Error?e.message:String(e))}},[z,G]),K=(0,$.useCallback)(async()=>{i(null),l(!0);try{await Lr(),await A.refreshQr(),await z(),P()}catch(e){i(e instanceof Error?e.message:String(e))}finally{l(!1)}},[z,A.refreshQr]),q=(0,$.useCallback)(async e=>{d(!0),i(null);try{await Br({autoStart:e}),P()}catch(e){i(e instanceof Error?e.message:String(e))}finally{d(!1)}},[]),ne=(0,$.useCallback)(()=>{if(B){q(!1);return}if(M?.consentRequired){i(e.consentExpiredBanner);return}if(!M?.canAutoStart){i(e.autoStartHint);return}v(!0)},[q,M?.canAutoStart,M?.consentRequired,e,B]),J=(0,$.useCallback)(async()=>{let t=C.trim();if(t){D(!0),i(null),k(null);try{await Br({registrationSecret:t}),T(``),k(e.brokerSecretSaved),P(),await z()}catch(e){i(e instanceof Error?e.message:String(e))}finally{D(!1)}}},[C,z,e.brokerSecretSaved]),ie=(0,$.useCallback)(async()=>{D(!0),i(null),k(null);try{await Br({registrationSecret:null}),T(``),k(e.brokerSecretCleared),P(),await z()}catch(e){i(e instanceof Error?e.message:String(e))}finally{D(!1)}},[z,e.brokerSecretCleared]),ae=(0,$.useCallback)(async()=>{b(!1),i(null),S(!0);try{await Lr({release:!0}),await A.refreshQr(),await z(),P()}catch(e){i(e instanceof Error?e.message:String(e))}finally{S(!1)}},[z,A.refreshQr]),se=(0,$.useCallback)(async()=>{M?.publicUrl&&(await navigator.clipboard.writeText(M.publicUrl).catch(()=>{}),p(!0),window.setTimeout(()=>p(!1),2e3))},[M?.publicUrl]);if(!n)return(0,Q.jsx)(`div`,{className:`mx-auto w-full max-w-app-main px-4 py-8`,children:(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.needToken})});let ce=M??{enabled:!1,state:`disconnected`,subdomain:null,publicUrl:null,connectedSince:null,frpcPid:null,lastHeartbeatAt:null,lastError:null,consentRequired:!0,config:{autoStart:B,brokerUrl:`https://frp.xopc.ai/api`}},le=M?.consentRequired&&(ce.enabled||B||M?.consent?.acceptedAt);return(0,Q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:e.title}),(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e.subtitle})]}),(0,Q.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-amber-500/30 bg-amber-500/5 px-3 py-2 text-xs text-fg-muted`,children:[(0,Q.jsx)(Ve,{className:`mt-0.5 size-4 shrink-0 text-amber-600 dark:text-amber-400`}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`p`,{className:`font-medium text-fg`,children:e.riskBannerTitle}),(0,Q.jsx)(`p`,{className:`mt-1`,children:e.riskBannerBody})]})]}),le?(0,Q.jsx)(`div`,{className:`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-xs text-fg-muted`,children:e.consentExpiredBanner}):null,(0,Q.jsxs)(Kt,{children:[(0,Q.jsx)(`h2`,{className:`mb-3 text-sm font-semibold text-fg`,children:e.statusTitle}),L&&!M?(0,Q.jsxs)(`p`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,Q.jsx)(Y,{className:`size-4 animate-spin`}),e.loading]}):null,N?(0,Q.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:N instanceof Error?N.message:String(N)}):null,(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium text-fg`,children:[(0,Q.jsx)(`span`,{className:X(`size-2.5 rounded-full`,ti(ce)),"aria-hidden":!0}),ei(e,ce)]}),(0,Q.jsx)(Qr,{status:ce,t:e}),ce.publicUrl?(0,Q.jsx)(`p`,{className:`font-mono text-xs text-fg-subtle break-all`,children:ce.publicUrl}):null,ce.connectedSince?(0,Q.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.uptime,`: `,ni(ce.connectedSince)]}):null,ce.lastError&&ce.state===`error`?(0,Q.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:ce.lastError}):null,(0,Q.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.lanHint})]}),(0,Q.jsx)(kr,{pairQr:A}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[ce.enabled?(0,Q.jsxs)(w,{type:`button`,variant:`secondary`,disabled:c,onClick:()=>void K(),children:[c?(0,Q.jsx)(Y,{className:`size-4 animate-spin`}):null,e.stop]}):(0,Q.jsxs)(w,{type:`button`,disabled:o,onClick:ee,children:[o?(0,Q.jsx)(Y,{className:`size-4 animate-spin`}):(0,Q.jsx)(re,{className:`size-4`}),e.start]}),ce.publicUrl?(0,Q.jsxs)(w,{type:`button`,variant:`secondary`,onClick:()=>void se(),children:[f?(0,Q.jsx)(Me,{className:`size-4`}):(0,Q.jsx)(ze,{className:`size-4`}),f?e.copied:e.copyUrl]}):null,ce.enabled?(0,Q.jsxs)(w,{type:`button`,variant:`ghost`,onClick:()=>void A.refreshQr(),children:[(0,Q.jsx)(h,{className:`size-4`}),e.refreshQr]}):null,ce.subdomain||ce.publicUrl?(0,Q.jsxs)(w,{type:`button`,variant:`secondary`,disabled:x||c,className:`border-danger/40 text-danger hover:bg-danger/10`,onClick:()=>b(!0),children:[x?(0,Q.jsx)(Y,{className:`size-4 animate-spin`}):null,e.release]}):null]}),ce.subdomain||ce.publicUrl?(0,Q.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.releaseHint}):null,(0,Q.jsxs)(Kt,{children:[(0,Q.jsx)(`h2`,{className:`mb-1 text-sm font-semibold text-fg`,children:e.brokerSecretTitle}),(0,Q.jsx)(`p`,{className:`mb-3 text-xs text-fg-muted`,children:e.brokerSecretHint}),H?(0,Q.jsx)(`p`,{className:`mb-3 text-xs text-fg-subtle`,children:e.brokerSecretEnvHint}):null,U&&!H?(0,Q.jsx)(`p`,{className:`mb-3 text-xs text-amber-700 dark:text-amber-400`,children:e.brokerSecretMissingHint}):null,H?null:(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`label`,{className:`sr-only`,htmlFor:`tunnel-broker-secret`,children:e.brokerSecretTitle}),(0,Q.jsx)(`input`,{id:`tunnel-broker-secret`,type:`password`,autoComplete:`off`,className:`w-full rounded-md border border-edge bg-surface-panel px-3 py-2 font-mono text-sm text-fg`,placeholder:V?e.brokerSecretPlaceholderKeep:e.brokerSecretPlaceholder,value:C,disabled:E,onChange:e=>T(e.target.value)}),(0,Q.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,Q.jsxs)(w,{type:`button`,variant:`secondary`,disabled:E||!C.trim(),onClick:()=>void J(),children:[E?(0,Q.jsx)(Y,{className:`size-4 animate-spin`}):null,e.brokerSecretSave]}),V?(0,Q.jsx)(w,{type:`button`,variant:`ghost`,disabled:E,onClick:()=>void ie(),children:e.brokerSecretClear}):null]})]}),O?(0,Q.jsx)(`p`,{className:`mt-2 text-xs text-emerald-700 dark:text-emerald-400`,children:O}):null]}),(0,Q.jsxs)(Kt,{children:[(0,Q.jsx)(`h2`,{className:`mb-3 text-sm font-semibold text-fg`,children:e.optionsTitle}),(0,Q.jsxs)(`label`,{className:X(`flex items-center gap-3 text-sm text-fg`,!B&&!M?.canAutoStart?`cursor-not-allowed opacity-60`:`cursor-pointer`),children:[(0,Q.jsx)(`input`,{type:`checkbox`,className:`size-4 rounded border-edge accent-accent`,checked:B,disabled:u||!B&&!M?.canAutoStart,onChange:ne}),e.autoStart]}),!M?.canAutoStart&&!B?(0,Q.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:e.autoStartHint}):null]}),r?(0,Q.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:r}):null,(0,Q.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-edge-subtle bg-surface-panel px-3 py-2 text-xs text-fg-subtle`,children:[(0,Q.jsx)(Te,{className:`mt-0.5 size-4 shrink-0 text-accent`}),(0,Q.jsx)(`span`,{children:e.brokerNote})]}),(0,Q.jsx)(jr,{open:m,title:e.consentTitle,intro:e.consentIntro,bullets:W,checkboxLabel:e.consentCheckbox,confirmLabel:le?e.consentReconfirm:e.consentConfirm,cancelLabel:e.consentCancel,onConfirm:()=>void te(),onCancel:()=>g(!1)},m?`consent-open`:`consent-closed`),(0,Q.jsx)(Qe,{open:_,title:e.autoStartConfirmTitle,description:e.autoStartConfirmBody,confirmLabel:e.autoStartConfirmLabel,cancelLabel:e.consentCancel,onConfirm:()=>{v(!1),q(!0)},onCancel:()=>v(!1)}),(0,Q.jsx)(Qe,{open:y,title:e.releaseConfirmTitle,description:e.releaseConfirmBody,confirmLabel:e.releaseConfirmLabel,cancelLabel:e.consentCancel,destructive:!0,onConfirm:()=>void ae(),onCancel:()=>b(!1)})]})}function ii(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:e<1024*1024*1024?`${(e/(1024*1024)).toFixed(1)} MB`:`${(e/(1024*1024*1024)).toFixed(1)} GB`}function ai(e,t){let n=new Date(e).getTime()-Date.now(),r=Math.abs(n),i=n<0;if(r<6e4)return t===`zh`?`刚刚`:`just now`;let a=Math.floor(r/6e4);if(a<60){let e=t===`zh`?`${a} 分钟`:`${a}m`;return i?t===`zh`?`${e}前`:`${e} ago`:e}let o=Math.floor(a/60);if(o<24){let e=t===`zh`?`${o} 小时`:`${o}h`;return i?t===`zh`?`${e}前`:`${e} ago`:e}let s=Math.floor(o/24),c=t===`zh`?`${s} 天`:`${s}d`;return i?t===`zh`?`${c}前`:`${c} ago`:c}var oi=[{value:36e5,key:`1h`},{value:216e5,key:`6h`},{value:864e5,key:`24h`},{value:2592e5,key:`3d`},{value:6048e5,key:`7d`}];function si(){let e=(0,Z.c)(72),t=F(pi),n;e[0]===t?n=e[1]:(n=oe(t),e[0]=t,e[1]=n);let r=n.sharesSettings,i=!!R(fi),o;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(o={refreshInterval:3e4},e[2]=o):o=e[2];let{data:s,error:c,isLoading:l,mutate:u}=a(i?`shares-list`:null,Ee,o),d;e[3]===s?.payload?.shares?d=e[4]:(d=s?.payload?.shares??[],e[3]=s?.payload?.shares,e[4]=d);let f=d,[p,m]=(0,$.useState)(!1),g;bb0:{if(p){g=f;break bb0}let t;e[5]===f?t=e[6]:(t=f.filter(di),e[5]=f,e[6]=t),g=t}let _=g,v;e[7]===f?v=e[8]:(v=f.filter(ui),e[7]=f,e[8]=v);let y=v.length,b;e[9]===f?b=e[10]:(b=f.filter(li),e[9]=f,e[10]=b);let x=b.length;if(!i){let t;return e[11]===r.needToken?t=e[12]:(t=(0,Q.jsx)(`div`,{className:`mx-auto w-full max-w-app-main px-4 py-8`,children:(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:r.needToken})}),e[11]=r.needToken,e[12]=t),t}let S;e[13]===r.title?S=e[14]:(S=(0,Q.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:r.title}),e[13]=r.title,e[14]=S);let C;e[15]===r.subtitle?C=e[16]:(C=(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:r.subtitle}),e[15]=r.subtitle,e[16]=C);let T;e[17]!==S||e[18]!==C?(T=(0,Q.jsxs)(`div`,{children:[S,C]}),e[17]=S,e[18]=C,e[19]=T):T=e[19];let E;e[20]===u?E=e[21]:(E=()=>void u(),e[20]=u,e[21]=E);let D;e[22]!==r||e[23]!==E?(D=(0,Q.jsx)(mi,{t:r,onCreated:E}),e[22]=r,e[23]=E,e[24]=D):D=e[24];let O=p?r.allSharesTitle:r.listTitle,k;e[25]===y?k=e[26]:(k=y>0&&(0,Q.jsxs)(`span`,{className:`ml-2 text-xs font-normal text-fg-muted`,children:[`(`,y,`)`]}),e[25]=y,e[26]=k);let A;e[27]!==O||e[28]!==k?(A=(0,Q.jsxs)(`h2`,{className:`text-sm font-semibold text-fg`,children:[O,k]}),e[27]=O,e[28]=k,e[29]=A):A=e[29];let j;e[30]===u?j=e[31]:(j=()=>void u(),e[30]=u,e[31]=j);let M=l&&`animate-spin`,N;e[32]===M?N=e[33]:(N=X(`size-3.5`,M),e[32]=M,e[33]=N);let P;e[34]===N?P=e[35]:(P=(0,Q.jsx)(h,{className:N}),e[34]=N,e[35]=P);let I;e[36]!==l||e[37]!==j||e[38]!==P?(I=(0,Q.jsx)(w,{type:`button`,variant:`ghost`,className:`px-2 py-1`,onClick:j,disabled:l,children:P}),e[36]=l,e[37]=j,e[38]=P,e[39]=I):I=e[39];let L;e[40]!==x||e[41]!==p||e[42]!==r.hideExpired||e[43]!==r.showExpired?(L=x>0&&(0,Q.jsx)(`button`,{type:`button`,className:`text-xs text-accent hover:underline`,onClick:()=>m(ci),children:p?r.hideExpired:r.showExpired}),e[40]=x,e[41]=p,e[42]=r.hideExpired,e[43]=r.showExpired,e[44]=L):L=e[44];let z;e[45]!==I||e[46]!==L?(z=(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[I,L]}),e[45]=I,e[46]=L,e[47]=z):z=e[47];let B;e[48]!==A||e[49]!==z?(B=(0,Q.jsxs)(`div`,{className:`mb-3 flex items-center justify-between`,children:[A,z]}),e[48]=A,e[49]=z,e[50]=B):B=e[50];let V;e[51]!==s||e[52]!==c||e[53]!==_||e[54]!==l||e[55]!==t||e[56]!==u||e[57]!==r?(V=l&&!s?(0,Q.jsxs)(`p`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,Q.jsx)(Y,{className:`size-4 animate-spin`}),r.loading]}):c?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-red-600 dark:text-red-400`,children:[(0,Q.jsx)(`span`,{children:r.error}),(0,Q.jsx)(w,{type:`button`,variant:`ghost`,className:`px-2 py-1 text-xs`,onClick:()=>void u(),children:r.retry})]}):_.length===0?(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:r.emptyState}):(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:_.map(e=>(0,Q.jsx)(hi,{share:e,t:r,language:t,onRevoked:()=>void u(),onExtended:()=>void u()},e.id))}),e[51]=s,e[52]=c,e[53]=_,e[54]=l,e[55]=t,e[56]=u,e[57]=r,e[58]=V):V=e[58];let H;e[59]!==x||e[60]!==u||e[61]!==p||e[62]!==r?(H=x>0&&p&&(0,Q.jsx)(gi,{t:r,onCleaned:()=>void u()}),e[59]=x,e[60]=u,e[61]=p,e[62]=r,e[63]=H):H=e[63];let U;e[64]!==B||e[65]!==V||e[66]!==H?(U=(0,Q.jsxs)(Kt,{children:[B,V,H]}),e[64]=B,e[65]=V,e[66]=H,e[67]=U):U=e[67];let W;return e[68]!==D||e[69]!==U||e[70]!==T?(W=(0,Q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[T,D,U]}),e[68]=D,e[69]=U,e[70]=T,e[71]=W):W=e[71],W}function ci(e){return!e}function li(e){return e.expired||e.revoked}function ui(e){return!e.expired&&!e.revoked}function di(e){return!e.expired&&!e.revoked}function fi(e){return e.token}function pi(e){return e.language}function mi({t:e,onCreated:t}){let[n,r]=(0,$.useState)(!1),[i,a]=(0,$.useState)(``),[o,s]=(0,$.useState)(864e5),[c,l]=(0,$.useState)(null),[u,d]=(0,$.useState)(``),[f,p]=(0,$.useState)(!1),[m,h]=(0,$.useState)(null),[g,_]=(0,$.useState)(null),[v,b]=(0,$.useState)(!1),x=(0,$.useCallback)(async()=>{if(i.trim()){p(!0),_(null),h(null);try{h((await B({path:i.trim(),ttlMs:o,maxViews:c,description:u.trim()||void 0})).payload),b(!0),t()}catch(e){_(e instanceof Error?e.message:String(e))}finally{p(!1)}}},[i,o,c,u,t]),S=(0,$.useCallback)(()=>{a(``),d(``),l(null),s(864e5),h(null),_(null)},[]);return n?(0,Q.jsxs)(Kt,{children:[(0,Q.jsx)(`h2`,{className:`mb-1 text-sm font-semibold text-fg`,children:e.createTitle}),(0,Q.jsx)(`p`,{className:`mb-4 text-xs text-fg-muted`,children:e.createHint}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Q.jsx)(`span`,{className:`text-xs font-medium text-fg`,children:e.pathLabel}),(0,Q.jsx)(`input`,{type:`text`,className:`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle focus:outline-none focus:ring-2 focus:ring-accent`,placeholder:e.pathPlaceholder,value:i,onChange:e=>a(e.target.value)})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-3`,children:[(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Q.jsx)(`span`,{className:`text-xs font-medium text-fg`,children:e.ttlLabel}),(0,Q.jsx)(`select`,{className:`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg focus:outline-none focus:ring-2 focus:ring-accent`,value:o,onChange:e=>s(Number(e.target.value)),children:oi.map(t=>(0,Q.jsx)(`option`,{value:t.value,children:e.ttlOptions[t.key]},t.key))})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Q.jsx)(`span`,{className:`text-xs font-medium text-fg`,children:e.maxViewsLabel}),(0,Q.jsxs)(`select`,{className:`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg focus:outline-none focus:ring-2 focus:ring-accent`,value:c??`unlimited`,onChange:e=>l(e.target.value===`unlimited`?null:Number(e.target.value)),children:[(0,Q.jsx)(`option`,{value:`unlimited`,children:e.maxViewsUnlimited}),(0,Q.jsx)(`option`,{value:`1`,children:`1`}),(0,Q.jsx)(`option`,{value:`5`,children:`5`}),(0,Q.jsx)(`option`,{value:`10`,children:`10`}),(0,Q.jsx)(`option`,{value:`50`,children:`50`}),(0,Q.jsx)(`option`,{value:`100`,children:`100`})]})]})]}),(0,Q.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Q.jsx)(`span`,{className:`text-xs font-medium text-fg`,children:e.descriptionLabel}),(0,Q.jsx)(`input`,{type:`text`,className:`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle focus:outline-none focus:ring-2 focus:ring-accent`,placeholder:e.descriptionPlaceholder,value:u,onChange:e=>d(e.target.value)})]}),(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 pt-1`,children:[(0,Q.jsxs)(w,{type:`button`,disabled:f||!i.trim(),onClick:()=>void x(),children:[f?(0,Q.jsx)(Y,{className:`size-4 animate-spin`}):(0,Q.jsx)(y,{className:`size-4`}),f?e.creating:e.createButton]}),(0,Q.jsx)(w,{type:`button`,variant:`ghost`,onClick:()=>{S(),r(!1)},children:e.cancel})]}),g&&(0,Q.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:g})]}),(0,Q.jsx)(Ye,{open:v,onOpenChange:e=>{b(e),e||h(null)},result:m})]}):(0,Q.jsxs)(w,{type:`button`,onClick:()=>r(!0),className:`self-start`,children:[(0,Q.jsx)(y,{className:`size-4`}),e.createTitle]})}function hi({share:e,t,language:n,onRevoked:r,onExtended:i}){let[a,s]=(0,$.useState)(!1),[c,l]=(0,$.useState)(!1),[u,d]=(0,$.useState)(!1),[f,p]=(0,$.useState)(!1),m=!e.expired&&!e.revoked,h=e.revoked?t.statusRevoked:e.expired?t.statusExpired:t.statusActive,g=e.revoked?`text-red-600 dark:text-red-400`:e.expired?`text-fg-subtle`:`text-emerald-600 dark:text-emerald-400`,_=(0,$.useCallback)(async()=>{s(!1),l(!0);try{await $e(e.id),r()}catch{}finally{l(!1)}},[e.id,r]),v=(0,$.useCallback)(async()=>{d(e=>!e)},[]),y=(0,$.useCallback)(async()=>{p(!0);try{await o(e.id,864e5),i()}catch{}finally{p(!1)}},[e.id,i]);return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`rounded-lg border border-edge-subtle bg-surface-panel px-3 py-2.5`,children:[(0,Q.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,Q.jsx)(be,{className:`mt-0.5 size-4 shrink-0 text-fg-muted`}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`truncate text-sm font-medium text-fg`,children:e.fileName}),(0,Q.jsx)(`span`,{className:X(`text-xs font-medium`,g),children:h})]}),(0,Q.jsx)(`p`,{className:`truncate text-xs text-fg-subtle`,children:e.workspaceRelativePath}),(0,Q.jsxs)(`div`,{className:`mt-1 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-fg-muted`,children:[(0,Q.jsx)(`span`,{children:ii(e.fileSize)}),(0,Q.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,Q.jsx)(ve,{className:`size-3`}),e.expired?n===`zh`?`已过期`:`expired`:ai(e.expiresAt,n)]}),(0,Q.jsxs)(`span`,{children:[t.views,`: `,e.viewCount,e.maxViews!==null&&` ${t.viewsOf} ${e.maxViews}`]}),e.description&&(0,Q.jsx)(`span`,{className:`italic text-fg-subtle`,children:e.description})]})]}),(0,Q.jsx)(`div`,{className:`flex shrink-0 items-center gap-1`,children:m&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(w,{type:`button`,variant:`ghost`,className:`px-2 py-1`,title:t.copyUrl,onClick:()=>void v(),children:u?(0,Q.jsx)(Me,{className:`size-3.5 text-emerald-500`}):(0,Q.jsx)(ze,{className:`size-3.5`})}),(0,Q.jsx)(w,{type:`button`,variant:`ghost`,className:`px-2 py-1`,onClick:()=>void y(),disabled:f,title:t.extend,children:f?(0,Q.jsx)(Y,{className:`size-3.5 animate-spin`}):(0,Q.jsx)(ve,{className:`size-3.5`})}),(0,Q.jsx)(w,{type:`button`,variant:`ghost`,className:`px-2 py-1 text-red-600 hover:text-red-700 dark:text-red-400`,onClick:()=>s(!0),disabled:c,children:c?(0,Q.jsx)(Y,{className:`size-3.5 animate-spin`}):(0,Q.jsx)(Je,{className:`size-3.5`})})]})})]}),m&&u?(0,Q.jsxs)(`div`,{className:`mt-3 border-t border-edge-subtle pt-3 pl-7`,children:[(0,Q.jsx)(Ae,{shareUrl:e.shareUrl,lanUrl:e.lanUrl,reachability:e.reachability,compact:!0}),(0,Q.jsx)(`div`,{className:`mt-2`,children:(0,Q.jsx)(He,{reachability:e.reachability})})]}):null]}),(0,Q.jsx)(Qe,{open:a,title:t.revokeConfirmTitle,description:t.revokeConfirmBody,confirmLabel:t.revokeConfirmLabel,cancelLabel:t.cancel,destructive:!0,onConfirm:()=>void _(),onCancel:()=>s(!1)})]})}function gi({t:e,onCleaned:t}){let[n,r]=(0,$.useState)(!1),[i,a]=(0,$.useState)(!1),o=(0,$.useCallback)(async()=>{r(!1),a(!0);try{await me(),t()}catch{}finally{a(!1)}},[t]);return(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`mt-3 flex justify-end`,children:(0,Q.jsxs)(w,{type:`button`,variant:`secondary`,disabled:i,onClick:()=>r(!0),className:`border-danger/40 px-2 py-1 text-xs text-danger hover:bg-danger/10`,children:[i?(0,Q.jsx)(Y,{className:`size-3.5 animate-spin`}):(0,Q.jsx)(Je,{className:`size-3.5`}),e.cleanExpired]})}),(0,Q.jsx)(Qe,{open:n,title:e.cleanExpiredConfirmTitle,description:e.cleanExpiredConfirmBody,confirmLabel:e.cleanExpiredConfirmLabel,cancelLabel:e.cancel,destructive:!0,onConfirm:()=>void o(),onCancel:()=>r(!1)})]})}async function _i(){let e=await J(lt(`/api/image/providers`));if(!e.ok)throw Error(`Image providers: HTTP ${e.status}`);return(await e.json()).payload?.providers??[]}function vi(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 yi(e,t){let n=vi(e.filter(e=>e.configured===!0));return!t||n.includes(t)?n:[t,...n]}function bi(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 xi=`image-generation-providers`;function Si(e){let t=(0,Z.c)(80),{value:n,disabled:r,placeholder:i,searchPlaceholder:o,noMatches:s,registryEmptyHint:c,outOfFilterNote:l,className:u,onChange:d}=e,[f,p]=(0,$.useState)(!1),[m,h]=(0,$.useState)(``),g;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(g={revalidateOnFocus:!1},t[0]=g):g=t[0];let{data:_,isLoading:v,error:y}=a(xi,_i,g),x;t[1]===n?x=t[2]:(x=n.trim(),t[1]=n,t[2]=x);let S=x,C;t[3]===_?C=t[4]:(C=vi((_??[]).filter(Ti)),t[3]=_,t[4]=C);let w=C,T;t[5]===_?T=t[6]:(T=_??[],t[5]=_,t[6]=T);let D;t[7]!==T||t[8]!==S?(D=yi(T,S),t[7]=T,t[8]=S,t[9]=D):D=t[9];let k=D,A;t[10]!==k||t[11]!==m?(A=bi(k,m),t[10]=k,t[11]=m,t[12]=A):A=t[12];let j=A,M;t[13]!==w||t[14]!==l||t[15]!==S?(M=!!l&&!!S&&!w.includes(S),t[13]=w,t[14]=l,t[15]=S,t[16]=M):M=t[16];let N=M,P;t[17]!==i||t[18]!==n?(P=n.trim()?n:i,t[17]=i,t[18]=n,t[19]=P):P=t[19];let F=P,I;t[20]!==i||t[21]!==n?(I=n.trim()||i,t[20]=i,t[21]=n,t[22]=I):I=t[22];let L=I,R;t[23]===Symbol.for(`react.memo_cache_sentinel`)?(R=e=>{p(e),e||h(``)},t[23]=R):R=t[23];let z=R,B=r||v,V=v?`…`:L,H;t[24]===u?H=t[25]:(H=X(b,`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`,We.transition,`hover:border-edge hover:bg-surface-hover/45`,U,`disabled:cursor-not-allowed disabled:opacity-50`,`dark:border-edge-subtle dark:hover:bg-surface-hover/55`,u),t[24]=u,t[25]=H);let W=v?`…`:F,G;t[26]===W?G=t[27]:(G=(0,Q.jsx)(`span`,{className:`min-w-0 truncate`,children:W}),t[26]=W,t[27]=G);let ee;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(ee=(0,Q.jsx)(ne,{className:`size-4 shrink-0 text-fg-subtle opacity-70`,"aria-hidden":!0}),t[28]=ee):ee=t[28];let te;t[29]!==f||t[30]!==B||t[31]!==V||t[32]!==H||t[33]!==G?(te=(0,Q.jsx)(de,{asChild:!0,children:(0,Q.jsxs)(`button`,{type:`button`,disabled:B,title:V,className:H,"aria-haspopup":`listbox`,"aria-expanded":f,children:[G,ee]})}),t[29]=f,t[30]=B,t[31]=V,t[32]=H,t[33]=G,t[34]=te):te=t[34];let K;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(K=X(`w-[min(22rem,calc(100vw-2rem))] rounded-xl border border-edge-subtle bg-surface-panel p-1 shadow-elevated dark:border-edge-subtle`,et),t[35]=K):K=t[35];let q;t[36]===Symbol.for(`react.memo_cache_sentinel`)?(q=X(`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`,E),t[36]=q):q=t[36];let J;t[37]===Symbol.for(`react.memo_cache_sentinel`)?(J=e=>h(e.target.value),t[37]=J):J=t[37];let re;t[38]!==m||t[39]!==o?(re=(0,Q.jsx)(`input`,{type:`search`,className:q,placeholder:o,value:m,onChange:J,onKeyDown:Ci}),t[38]=m,t[39]=o,t[40]=re):re=t[40];let ie;t[41]===y?ie=t[42]:(ie=y?(0,Q.jsx)(`div`,{className:`p-2 text-xs text-red-600 dark:text-red-400`,children:y instanceof Error?y.message:`Failed to load image providers`}):null,t[41]=y,t[42]=ie);let ae;t[43]!==k||t[44]!==y||t[45]!==v||t[46]!==s||t[47]!==c?(ae=!y&&k.length===0&&!v?(0,Q.jsx)(`div`,{className:`px-2 py-3 text-center text-xs text-fg-muted`,children:c??s}):null,t[43]=k,t[44]=y,t[45]=v,t[46]=s,t[47]=c,t[48]=ae):ae=t[48];let oe;t[49]!==k||t[50]!==y||t[51]!==j.length||t[52]!==s?(oe=!y&&k.length>0&&j.length===0?(0,Q.jsx)(`div`,{className:`px-2 py-3 text-center text-xs text-fg-muted`,children:s}):null,t[49]=k,t[50]=y,t[51]=j.length,t[52]=s,t[53]=oe):oe=t[53];let Y;if(t[54]!==j||t[55]!==d||t[56]!==n){let e;t[58]!==d||t[59]!==n?(e=e=>(0,Q.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":e===n,className:X(`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-fg hover:bg-surface-hover`,e===n&&`bg-surface-hover/90 font-medium dark:bg-surface-hover/70`),onClick:()=>{d(e),p(!1),h(``)},children:[(0,Q.jsx)(Me,{className:X(`size-4 shrink-0`,e!==n&&`invisible`),"aria-hidden":!0}),(0,Q.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm font-medium`,children:e})]},e),t[58]=d,t[59]=n,t[60]=e):e=t[60],Y=j.map(e),t[54]=j,t[55]=d,t[56]=n,t[57]=Y}else Y=t[57];let se;t[61]!==o||t[62]!==ie||t[63]!==ae||t[64]!==oe||t[65]!==Y?(se=(0,Q.jsxs)(`div`,{className:`max-h-60 overflow-auto`,role:`listbox`,"aria-label":o,children:[ie,ae,oe,Y]}),t[61]=o,t[62]=ie,t[63]=ae,t[64]=oe,t[65]=Y,t[66]=se):se=t[66];let ce;t[67]!==re||t[68]!==se?(ce=(0,Q.jsx)(O,{children:(0,Q.jsxs)(qe,{className:K,side:`bottom`,sideOffset:4,align:`end`,onOpenAutoFocus:wi,children:[re,se]})}),t[67]=re,t[68]=se,t[69]=ce):ce=t[69];let le;t[70]!==f||t[71]!==te||t[72]!==ce?(le=(0,Q.jsxs)(pe,{open:f,onOpenChange:z,modal:!1,children:[te,ce]}),t[70]=f,t[71]=te,t[72]=ce,t[73]=le):le=t[73];let ue;t[74]!==l||t[75]!==N?(ue=N?(0,Q.jsx)(`p`,{className:`text-xs text-amber-700 dark:text-amber-400/90`,children:l}):null,t[74]=l,t[75]=N,t[76]=ue):ue=t[76];let fe;return t[77]!==le||t[78]!==ue?(fe=(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[le,ue]}),t[77]=le,t[78]=ue,t[79]=fe):fe=t[79],fe}function Ci(e){return e.stopPropagation()}function wi(e){return e.preventDefault()}function Ti(e){return e.configured===!0}function Ei(e){let t=(0,Z.c)(85),{a:n,chat:r,form:i,update:a}=e,o;t[0]!==n.cardModelsSubtitle||t[1]!==n.cardModelsTitle?(o=(0,Q.jsx)(Ot,{icon:V,title:n.cardModelsTitle,subtitle:n.cardModelsSubtitle}),t[0]=n.cardModelsSubtitle,t[1]=n.cardModelsTitle,t[2]=o):o=t[2];let s;t[3]===a?s=t[4]:(s=e=>a({imageModel:e}),t[3]=a,t[4]=s);let c;t[5]!==n.visionOutOfFilterNote||t[6]!==n.visionRegistryEmpty||t[7]!==r.modelNoMatches||t[8]!==r.modelPlaceholder||t[9]!==r.modelSearchPlaceholder||t[10]!==i.imageModel||t[11]!==s?(c=(0,Q.jsx)(ye,{value:i.imageModel,placeholder:r.modelPlaceholder,searchPlaceholder:r.modelSearchPlaceholder,noMatches:r.modelNoMatches,capabilitiesFilter:`vision`,registryEmptyHint:n.visionRegistryEmpty,outOfFilterNote:n.visionOutOfFilterNote,onChange:s}),t[5]=n.visionOutOfFilterNote,t[6]=n.visionRegistryEmpty,t[7]=r.modelNoMatches,t[8]=r.modelPlaceholder,t[9]=r.modelSearchPlaceholder,t[10]=i.imageModel,t[11]=s,t[12]=c):c=t[12];let l;t[13]!==n.desc.imageModel||t[14]!==n.label.imageModel||t[15]!==c?(l=(0,Q.jsx)(At,{label:n.label.imageModel,description:n.desc.imageModel,children:c}),t[13]=n.desc.imageModel,t[14]=n.label.imageModel,t[15]=c,t[16]=l):l=t[16];let u=n.label.imageModelFallbacks,d=n.desc.imageModelFallbacks,f;t[17]!==n.removeModelFallback||t[18]!==n.visionOutOfFilterNote||t[19]!==n.visionRegistryEmpty||t[20]!==r.modelNoMatches||t[21]!==r.modelPlaceholder||t[22]!==r.modelSearchPlaceholder||t[23]!==i.imageModelFallbacks||t[24]!==a?(f=i.imageModelFallbacks.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Q.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Q.jsx)(ye,{value:e,placeholder:r.modelPlaceholder,searchPlaceholder:r.modelSearchPlaceholder,noMatches:r.modelNoMatches,capabilitiesFilter:`vision`,registryEmptyHint:n.visionRegistryEmpty,outOfFilterNote:n.visionOutOfFilterNote,onChange:e=>{let n=[...i.imageModelFallbacks];n[t]=e,a({imageModelFallbacks:n})}})}),(0,Q.jsx)(w,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":n.removeModelFallback,onClick:()=>a({imageModelFallbacks:i.imageModelFallbacks.filter((e,n)=>n!==t)}),children:(0,Q.jsx)(Je,{className:`size-4`,strokeWidth:1.75})})]},t)),t[17]=n.removeModelFallback,t[18]=n.visionOutOfFilterNote,t[19]=n.visionRegistryEmpty,t[20]=r.modelNoMatches,t[21]=r.modelPlaceholder,t[22]=r.modelSearchPlaceholder,t[23]=i.imageModelFallbacks,t[24]=a,t[25]=f):f=t[25];let p;t[26]!==i.imageModelFallbacks||t[27]!==a?(p=()=>a({imageModelFallbacks:[...i.imageModelFallbacks,``]}),t[26]=i.imageModelFallbacks,t[27]=a,t[28]=p):p=t[28];let m;t[29]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,Q.jsx)(y,{className:`size-4 shrink-0`,strokeWidth:1.75}),t[29]=m):m=t[29];let h;t[30]!==n.addModelFallback||t[31]!==p?(h=(0,Q.jsxs)(w,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:p,children:[m,n.addModelFallback]}),t[30]=n.addModelFallback,t[31]=p,t[32]=h):h=t[32];let g;t[33]!==f||t[34]!==h?(g=(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[f,h]}),t[33]=f,t[34]=h,t[35]=g):g=t[35];let _;t[36]!==n.desc.imageModelFallbacks||t[37]!==n.label.imageModelFallbacks||t[38]!==g?(_=(0,Q.jsx)(At,{label:u,description:d,children:g}),t[36]=n.desc.imageModelFallbacks,t[37]=n.label.imageModelFallbacks,t[38]=g,t[39]=_):_=t[39];let v;t[40]===a?v=t[41]:(v=e=>a({imageGenerationModel:e}),t[40]=a,t[41]=v);let b;t[42]!==n.imageGenOutOfFilterNote||t[43]!==n.imageGenRegistryEmpty||t[44]!==r.modelNoMatches||t[45]!==r.modelPlaceholder||t[46]!==r.modelSearchPlaceholder||t[47]!==i.imageGenerationModel||t[48]!==v?(b=(0,Q.jsx)(Si,{value:i.imageGenerationModel,placeholder:r.modelPlaceholder,searchPlaceholder:r.modelSearchPlaceholder,noMatches:r.modelNoMatches,registryEmptyHint:n.imageGenRegistryEmpty,outOfFilterNote:n.imageGenOutOfFilterNote,onChange:v}),t[42]=n.imageGenOutOfFilterNote,t[43]=n.imageGenRegistryEmpty,t[44]=r.modelNoMatches,t[45]=r.modelPlaceholder,t[46]=r.modelSearchPlaceholder,t[47]=i.imageGenerationModel,t[48]=v,t[49]=b):b=t[49];let x;t[50]!==n.desc.imageGenerationModel||t[51]!==n.label.imageGenerationModel||t[52]!==b?(x=(0,Q.jsx)(At,{label:n.label.imageGenerationModel,description:n.desc.imageGenerationModel,children:b}),t[50]=n.desc.imageGenerationModel,t[51]=n.label.imageGenerationModel,t[52]=b,t[53]=x):x=t[53];let S=n.label.imageGenerationModelFallbacks,C=n.desc.imageGenerationModelFallbacks,T;t[54]!==n.imageGenOutOfFilterNote||t[55]!==n.imageGenRegistryEmpty||t[56]!==n.removeModelFallback||t[57]!==r.modelNoMatches||t[58]!==r.modelPlaceholder||t[59]!==r.modelSearchPlaceholder||t[60]!==i.imageGenerationModelFallbacks||t[61]!==a?(T=i.imageGenerationModelFallbacks.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Q.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Q.jsx)(Si,{value:e,placeholder:r.modelPlaceholder,searchPlaceholder:r.modelSearchPlaceholder,noMatches:r.modelNoMatches,registryEmptyHint:n.imageGenRegistryEmpty,outOfFilterNote:n.imageGenOutOfFilterNote,onChange:e=>{let n=[...i.imageGenerationModelFallbacks];n[t]=e,a({imageGenerationModelFallbacks:n})}})}),(0,Q.jsx)(w,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":n.removeModelFallback,onClick:()=>a({imageGenerationModelFallbacks:i.imageGenerationModelFallbacks.filter((e,n)=>n!==t)}),children:(0,Q.jsx)(Je,{className:`size-4`,strokeWidth:1.75})})]},t)),t[54]=n.imageGenOutOfFilterNote,t[55]=n.imageGenRegistryEmpty,t[56]=n.removeModelFallback,t[57]=r.modelNoMatches,t[58]=r.modelPlaceholder,t[59]=r.modelSearchPlaceholder,t[60]=i.imageGenerationModelFallbacks,t[61]=a,t[62]=T):T=t[62];let E;t[63]!==i.imageGenerationModelFallbacks||t[64]!==a?(E=()=>a({imageGenerationModelFallbacks:[...i.imageGenerationModelFallbacks,``]}),t[63]=i.imageGenerationModelFallbacks,t[64]=a,t[65]=E):E=t[65];let D;t[66]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,Q.jsx)(y,{className:`size-4 shrink-0`,strokeWidth:1.75}),t[66]=D):D=t[66];let O;t[67]!==n.addModelFallback||t[68]!==E?(O=(0,Q.jsxs)(w,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:E,children:[D,n.addModelFallback]}),t[67]=n.addModelFallback,t[68]=E,t[69]=O):O=t[69];let k;t[70]!==T||t[71]!==O?(k=(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[T,O]}),t[70]=T,t[71]=O,t[72]=k):k=t[72];let A;t[73]!==n.desc.imageGenerationModelFallbacks||t[74]!==n.label.imageGenerationModelFallbacks||t[75]!==k?(A=(0,Q.jsx)(At,{label:S,description:C,children:k}),t[73]=n.desc.imageGenerationModelFallbacks,t[74]=n.label.imageGenerationModelFallbacks,t[75]=k,t[76]=A):A=t[76];let j;t[77]!==_||t[78]!==x||t[79]!==A||t[80]!==l?(j=(0,Q.jsxs)(`div`,{className:`mt-4 flex flex-col gap-5`,children:[l,_,x,A]}),t[77]=_,t[78]=x,t[79]=A,t[80]=l,t[81]=j):j=t[81];let M;return t[82]!==o||t[83]!==j?(M=(0,Q.jsxs)(Kt,{children:[o,j]}),t[82]=o,t[83]=j,t[84]=M):M=t[84],M}function Di(){return X(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,u)}var Oi=()=>lt(_t);function ki(e){return{imageModel:e.imageModel,imageModelFallbacks:e.imageModelFallbacks,imageGenerationModel:e.imageGenerationModel,imageGenerationModelFallbacks:e.imageGenerationModelFallbacks,imageGenerationModelTimeoutMs:e.imageGenerationModelTimeoutMs,imageGenerationModelAutoProviderFallback:e.imageGenerationModelAutoProviderFallback}}function Ai(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 ji(){let e=F(e=>e.language),t=oe(e),n=t.imageModelsSettings,r=!!R(e=>e.token),[i,o]=(0,$.useState)(null),[s,c]=(0,$.useState)(null),[l,u]=(0,$.useState)(!0),[d,f]=(0,$.useState)(!1),[p,m]=(0,$.useState)(!1),[g,_]=(0,$.useState)(void 0),v=ft(),y=(0,$.useMemo)(()=>new Set(v.map(e=>e.id)),[v]),b=(0,$.useCallback)(async()=>{if(r){u(!0),_(void 0);try{let e=await kt(),t=structuredClone(e);o(t),c(structuredClone(t))}catch(e){_(e instanceof Error?e.message:String(e))}finally{u(!1)}}},[r]);(0,$.useEffect)(()=>{b()},[b]);let x=(0,$.useCallback)(e=>{o(t=>t?{...t,...e}:null)},[]),{data:S=[],mutate:C}=a(r?Oi():null,yt,{revalidateOnFocus:!1}),T=I(r),E=bt(S),D=(0,$.useMemo)(()=>!i||!s?!1:JSON.stringify(ki(i))!==JSON.stringify(ki(s)),[i,s]),O=D||E.credDirty;(0,$.useEffect)(()=>{if(!O)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[O]);let k=(0,$.useCallback)(async()=>{if(i){f(!0),_(void 0);try{try{Ft(i.paramsJson)}catch(e){_(e instanceof SyntaxError?t.agentSettings.advanced.paramsInvalidJson:e instanceof Error?e.message:t.agentSettings.advanced.paramsInvalidJson);return}await Ut(i),c(structuredClone(i)),m(!0),window.setTimeout(()=>m(!1),1500),T.mutate?.()}catch(e){_(e instanceof Error?e.message:String(e))}finally{f(!1)}}},[i,T,t.agentSettings]),A=(0,$.useCallback)(()=>{s&&(o(structuredClone(s)),_(void 0),m(!1))},[s]),j=(0,$.useMemo)(()=>Ai(n),[n]),M=(0,$.useMemo)(()=>({getApiKey:t.providersSettings.getApiKey,getApiKeyIntl:t.providersSettings.getApiKeyIntl,getApiKeyCn:t.providersSettings.getApiKeyCn}),[t.providersSettings]);return r?l||!i?(0,Q.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,Q.jsx)(Y,{className:`size-4 animate-spin`}),` Loading…`]}):(0,Q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[(0,Q.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.title}),(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle})]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[(0,Q.jsxs)(w,{type:`button`,variant:`ghost`,onClick:()=>{b(),C(),T.mutate?.()},children:[(0,Q.jsx)(h,{className:`size-3.5`}),(0,Q.jsx)(`span`,{className:`ml-1.5`,children:n.refresh})]}),p?(0,Q.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,Q.jsx)(w,{type:`button`,variant:`secondary`,onClick:A,disabled:!D||d,children:n.discard}),(0,Q.jsxs)(w,{type:`button`,variant:`primary`,onClick:()=>void k(),disabled:!D||d,children:[d?(0,Q.jsx)(Y,{className:`size-3.5 animate-spin`}):(0,Q.jsx)(q,{className:`size-3.5`}),(0,Q.jsx)(`span`,{className:`ml-1.5`,children:d?n.saving:n.save})]})]})]}),g?(0,Q.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:g}):null,(0,Q.jsx)(Ei,{form:i,update:x,a:t.agentSettings,chat:t.chat}),(0,Q.jsxs)(Kt,{children:[(0,Q.jsx)(Ot,{icon:V,title:n.title,subtitle:n.subtitle}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.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,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(`label`,{className:`text-sm font-medium text-fg`,children:n.timeoutLabel}),(0,Q.jsx)(`input`,{type:`number`,min:0,step:1e3,className:X(Di(),`max-w-[12rem]`),value:i.imageGenerationModelTimeoutMs??``,placeholder:`120000`,onChange:e=>{let t=e.target.value.trim(),n=t===``?null:Math.max(0,Math.floor(Number(t)));o(e=>e?{...e,imageGenerationModelTimeoutMs:n&&n>0?n:null}:null)}}),(0,Q.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.timeoutHint})]}),(0,Q.jsxs)(`label`,{className:`flex items-start gap-3 text-sm`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,className:`mt-0.5`,checked:i.imageGenerationModelAutoProviderFallback,onChange:e=>o(t=>t?{...t,imageGenerationModelAutoProviderFallback:e.target.checked}:null),"aria-label":n.autoFallbackLabel}),(0,Q.jsxs)(`span`,{className:`flex flex-col gap-0.5`,children:[(0,Q.jsx)(`span`,{className:`font-medium text-fg`,children:n.autoFallbackLabel}),(0,Q.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:n.autoFallbackHint})]})]})]})]}),(0,Q.jsxs)(Kt,{children:[(0,Q.jsx)(Ot,{icon:Oe,title:n.providersTitle,subtitle:``}),S.length===0?(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.providersEmpty}):(0,Q.jsx)(vt,{summaries:S,credDraft:E.credDraft,credDirty:E.credDirty,credSaving:E.credSaving,credError:E.credError,credSavedFlash:E.credSavedFlash,credNoopFlash:E.credNoopFlash,updateCredRow:E.updateCredRow,onDiscardCredentials:E.onDiscardCredentials,onSaveCredentials:()=>void E.saveCredentials(n.credentialsSaveError),extensionIds:y,showExtensionLinks:!0,showImageModelsLink:!1,language:e,apiKeyLinkLabels:M,messages:j})]})]}):(0,Q.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 Mi=[{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 Ni(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 Pi(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 Fi(){let e=await J(lt(`/api/models-json`)),t=await e.json().catch(()=>({}));if(!e.ok||!t.ok||!t.payload)throw Error(Ni(t)||`HTTP ${e.status}`);return{...t.payload,config:Pi(t.payload.config)}}async function Ii(e){let t=await J(lt(`/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(Ni(n)||`HTTP ${t.status}`);return n.payload}async function Li(e){let t=await J(lt(`/api/models-json`),{method:`PATCH`,body:JSON.stringify({config:e})}),n=await t.json().catch(()=>({}));if(!t.ok||!n.ok||!n.payload)throw Error(Ni(n)||`HTTP ${t.status}`);return n.payload}async function Ri(){let e=await J(lt(`/api/models-json/reload`),{method:`POST`}),t=await e.json().catch(()=>({}));if(!e.ok||!t.ok||!t.payload)throw Error(Ni(t)||`HTTP ${e.status}`);return t.payload}async function zi(e){let t=await J(lt(`/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(Ni(n)||`HTTP ${t.status}`);return n.payload}function Bi(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 Vi(e){return e.startsWith(`!`)}function Hi(e){return/^[A-Z][A-Z0-9_]*$/.test(e)}function Ui(e){return Vi(e)?`shell`:Hi(e)?`env`:`literal`}function Wi(e){return e?e.length<=8?`••••`:`${e.slice(0,4)}••••${e.slice(-4)}`:``}function Gi(e){let t=(0,Z.c)(21),{a:n,chat:r,form:i,update:a}=e,o;t[0]!==n.desc.modelFallbacks||t[1]!==n.label.modelFallbacks?(o=(0,Q.jsx)(Ot,{icon:Ge,title:n.label.modelFallbacks,subtitle:n.desc.modelFallbacks}),t[0]=n.desc.modelFallbacks,t[1]=n.label.modelFallbacks,t[2]=o):o=t[2];let s;t[3]!==n.removeModelFallback||t[4]!==r||t[5]!==i.modelFallbacks||t[6]!==a?(s=i.modelFallbacks.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Q.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Q.jsx)(ye,{value:e,placeholder:r.modelPlaceholder,searchPlaceholder:r.modelSearchPlaceholder,noMatches:r.modelNoMatches,onChange:e=>{let n=[...i.modelFallbacks];n[t]=e,a({modelFallbacks:n})}})}),(0,Q.jsx)(w,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":n.removeModelFallback,onClick:()=>a({modelFallbacks:i.modelFallbacks.filter((e,n)=>n!==t)}),children:(0,Q.jsx)(Je,{className:`size-4`,strokeWidth:1.75})})]},t)),t[3]=n.removeModelFallback,t[4]=r,t[5]=i.modelFallbacks,t[6]=a,t[7]=s):s=t[7];let c;t[8]!==i.modelFallbacks||t[9]!==a?(c=()=>a({modelFallbacks:[...i.modelFallbacks,``]}),t[8]=i.modelFallbacks,t[9]=a,t[10]=c):c=t[10];let l;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(l=(0,Q.jsx)(y,{className:`size-4 shrink-0`,strokeWidth:1.75}),t[11]=l):l=t[11];let u;t[12]!==n.addModelFallback||t[13]!==c?(u=(0,Q.jsxs)(w,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:c,children:[l,n.addModelFallback]}),t[12]=n.addModelFallback,t[13]=c,t[14]=u):u=t[14];let d;t[15]!==s||t[16]!==u?(d=(0,Q.jsxs)(`div`,{className:`mt-4 flex flex-col gap-2`,children:[s,u]}),t[15]=s,t[16]=u,t[17]=d):d=t[17];let f;return t[18]!==o||t[19]!==d?(f=(0,Q.jsxs)(Kt,{children:[o,d]}),t[18]=o,t[19]=d,t[20]=f):f=t[20],f}var Ki={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 qi(e){return e===`openrouter`?`openrouter`:e===`zhipuCn`?`zhipu-cn`:e===`zaiGeneral`?`zai`:e}var Ji=[{value:`text`,labelKey:`inputTextOnly`},{value:`text,image`,labelKey:`inputTextVision`}];function Yi(){return X(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,u,`dark:border-edge`)}function Xi(){return X(mt,A)}function Zi(e){return(e.input||[`text`]).includes(`image`)?`text,image`:`text`}function Qi(e){return e===`text,image`?[`text`,`image`]:[`text`]}function $i(e,t,n){return{...e,providers:{...e.providers,[t]:{...e.providers[t],...n}}}}function ea(e,t){let n={...e.providers};return delete n[t],{...e,providers:n}}function ta(e,t,n){return{...e,providers:{...e.providers,[t]:n}}}function na(e){let t=(0,Z.c)(163),{open:n,onOpenChange:r,providerId:i,model:a,isNew:o,onSave:s,m:c}=e,[l,u]=(0,$.useState)(aa),[d,f]=(0,$.useState)(ia),p,m;t[0]!==a||t[1]!==n?(p=()=>{n&&(f(new Map),u(a?{...a}:Bi(``)))},m=[n,a],t[0]=a,t[1]=n,t[2]=p,t[3]=m):(p=t[2],m=t[3]),(0,$.useEffect)(p,m);let h;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(h=(e,t)=>{u(n=>({...n,[e]:t})),f(t=>{let n=new Map(t);return n.delete(e),n})},t[4]=h):h=t[4];let g=h,_;t[5]!==l.contextWindow||t[6]!==l.id||t[7]!==l.maxTokens||t[8]!==c.modelIdRequired||t[9]!==c.mustBePositive?(_=()=>{let e=new Map;return(l.id||``).trim()||e.set(`id`,c.modelIdRequired),l.contextWindow!==void 0&&l.contextWindow<=0&&e.set(`contextWindow`,c.mustBePositive),l.maxTokens!==void 0&&l.maxTokens<=0&&e.set(`maxTokens`,c.mustBePositive),f(e),e.size===0},t[5]=l.contextWindow,t[6]=l.id,t[7]=l.maxTokens,t[8]=c.modelIdRequired,t[9]=c.mustBePositive,t[10]=_):_=t[10];let v=_,y;t[11]!==l||t[12]!==r||t[13]!==s||t[14]!==v?(y=()=>{if(!v())return;let e=(l.id||``).trim();s({...l,id:e,name:l.name?.trim()||e,reasoning:l.reasoning||!1,input:l.input||[`text`],contextWindow:l.contextWindow??128e3,maxTokens:l.maxTokens??16384,cost:{input:l.cost?.input??0,output:l.cost?.output??0,cacheRead:l.cost?.cacheRead??0,cacheWrite:l.cost?.cacheWrite??0}}),r(!1)},t[11]=l,t[12]=r,t[13]=s,t[14]=v,t[15]=y):y=t[15];let b=y,x=l,S;t[16]===x?S=t[17]:(S=Zi(x),t[16]=x,t[17]=S);let C=S,E;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(E=(0,Q.jsx)(se,{className:X(`xopc-dialog-overlay fixed inset-0 bg-scrim`,Fe)}),t[18]=E):E=t[18];let D;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(D=X(`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`,Xe,`overflow-y-auto rounded-xl border border-edge bg-surface-panel p-4 shadow-popover dark:border-edge`),t[19]=D):D=t[19];let O=o?c.addModelTitle:c.editModelTitle,k;t[20]===O?k=t[21]:(k=(0,Q.jsx)(ce,{className:`text-base font-semibold text-fg`,children:O}),t[20]=O,t[21]=k);let A;t[22]!==c.modelProviderLabel||t[23]!==i?(A=i?(0,Q.jsxs)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:[c.modelProviderLabel,`: `,i]}):null,t[22]=c.modelProviderLabel,t[23]=i,t[24]=A):A=t[24];let j;t[25]!==k||t[26]!==A?(j=(0,Q.jsxs)(`div`,{children:[k,A]}),t[25]=k,t[26]=A,t[27]=j):j=t[27];let M;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(M=(0,Q.jsx)(fe,{className:`size-4`}),t[28]=M):M=t[28];let N;t[29]===c.close?N=t[30]:(N=(0,Q.jsx)(G,{asChild:!0,children:(0,Q.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":c.close,children:M})}),t[29]=c.close,t[30]=N);let P;t[31]!==j||t[32]!==N?(P=(0,Q.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[j,N]}),t[31]=j,t[32]=N,t[33]=P):P=t[33];let F;t[34]===Symbol.for(`react.memo_cache_sentinel`)?(F=(0,Q.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`}),t[34]=F):F=t[34];let I;t[35]===c.modelId?I=t[36]:(I=(0,Q.jsxs)(`label`,{className:`mb-1 block text-xs font-medium text-fg`,children:[c.modelId,F]}),t[35]=c.modelId,t[36]=I);let L;t[37]===d?L=t[38]:(L=X(Yi(),d.has(`id`)&&`border-red-500`),t[37]=d,t[38]=L);let R=l.id||``,z;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(z=e=>g(`id`,e.target.value),t[39]=z):z=t[39];let B=!o,V;t[40]!==L||t[41]!==R||t[42]!==B?(V=(0,Q.jsx)(`input`,{className:L,value:R,onChange:z,placeholder:`e.g. llama3.1:8b`,disabled:B}),t[40]=L,t[41]=R,t[42]=B,t[43]=V):V=t[43];let H;t[44]===d?H=t[45]:(H=d.has(`id`)?(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:d.get(`id`)}):null,t[44]=d,t[45]=H);let U;t[46]!==I||t[47]!==V||t[48]!==H?(U=(0,Q.jsxs)(`div`,{children:[I,V,H]}),t[46]=I,t[47]=V,t[48]=H,t[49]=U):U=t[49];let W;t[50]===c.displayName?W=t[51]:(W=(0,Q.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:c.displayName}),t[50]=c.displayName,t[51]=W);let ee;t[52]===Symbol.for(`react.memo_cache_sentinel`)?(ee=Yi(),t[52]=ee):ee=t[52];let te=l.name||``,K;t[53]===Symbol.for(`react.memo_cache_sentinel`)?(K=e=>g(`name`,e.target.value),t[53]=K):K=t[53];let q;t[54]===te?q=t[55]:(q=(0,Q.jsx)(`input`,{className:ee,value:te,onChange:K}),t[54]=te,t[55]=q);let ne;t[56]!==W||t[57]!==q?(ne=(0,Q.jsxs)(`div`,{children:[W,q]}),t[56]=W,t[57]=q,t[58]=ne):ne=t[58];let J;t[59]===c.inputTypes?J=t[60]:(J=(0,Q.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:c.inputTypes}),t[59]=c.inputTypes,t[60]=J);let re;t[61]===Symbol.for(`react.memo_cache_sentinel`)?(re=Xi(),t[61]=re):re=t[61];let ie;t[62]===Symbol.for(`react.memo_cache_sentinel`)?(ie=e=>g(`input`,Qi(e.target.value)),t[62]=ie):ie=t[62];let oe;t[63]===c?oe=t[64]:(oe=Ji.map(e=>(0,Q.jsx)(`option`,{value:e.value,children:c[e.labelKey]},e.value)),t[63]=c,t[64]=oe);let Y;t[65]!==C||t[66]!==oe?(Y=(0,Q.jsx)(`select`,{className:re,value:C,onChange:ie,children:oe}),t[65]=C,t[66]=oe,t[67]=Y):Y=t[67];let le;t[68]!==J||t[69]!==Y?(le=(0,Q.jsxs)(`div`,{children:[J,Y]}),t[68]=J,t[69]=Y,t[70]=le):le=t[70];let ue=l.reasoning||!1,de;t[71]===Symbol.for(`react.memo_cache_sentinel`)?(de=e=>g(`reasoning`,e.target.checked),t[71]=de):de=t[71];let pe;t[72]===ue?pe=t[73]:(pe=(0,Q.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:ue,onChange:de}),t[72]=ue,t[73]=pe);let me;t[74]!==c.reasoning||t[75]!==pe?(me=(0,Q.jsxs)(`label`,{className:`mt-6 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[pe,c.reasoning]}),t[74]=c.reasoning,t[75]=pe,t[76]=me):me=t[76];let he;t[77]!==le||t[78]!==me?(he=(0,Q.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[le,me]}),t[77]=le,t[78]=me,t[79]=he):he=t[79];let ge;t[80]===c.contextWindow?ge=t[81]:(ge=(0,Q.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:c.contextWindow}),t[80]=c.contextWindow,t[81]=ge);let _e;t[82]===d?_e=t[83]:(_e=X(Yi(),d.has(`contextWindow`)&&`border-red-500`),t[82]=d,t[83]=_e);let ve=l.contextWindow??128e3,ye;t[84]===Symbol.for(`react.memo_cache_sentinel`)?(ye=e=>g(`contextWindow`,parseInt(e.target.value,10)||0),t[84]=ye):ye=t[84];let be;t[85]!==_e||t[86]!==ve?(be=(0,Q.jsx)(`input`,{type:`number`,min:1,className:_e,value:ve,onChange:ye}),t[85]=_e,t[86]=ve,t[87]=be):be=t[87];let xe;t[88]===d?xe=t[89]:(xe=d.has(`contextWindow`)?(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:d.get(`contextWindow`)}):null,t[88]=d,t[89]=xe);let Se;t[90]!==ge||t[91]!==be||t[92]!==xe?(Se=(0,Q.jsxs)(`div`,{children:[ge,be,xe]}),t[90]=ge,t[91]=be,t[92]=xe,t[93]=Se):Se=t[93];let Ce;t[94]===c.maxOutputTokens?Ce=t[95]:(Ce=(0,Q.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:c.maxOutputTokens}),t[94]=c.maxOutputTokens,t[95]=Ce);let we;t[96]===d?we=t[97]:(we=X(Yi(),d.has(`maxTokens`)&&`border-red-500`),t[96]=d,t[97]=we);let Te=l.maxTokens??16384,Ee;t[98]===Symbol.for(`react.memo_cache_sentinel`)?(Ee=e=>g(`maxTokens`,parseInt(e.target.value,10)||0),t[98]=Ee):Ee=t[98];let De;t[99]!==we||t[100]!==Te?(De=(0,Q.jsx)(`input`,{type:`number`,min:1,className:we,value:Te,onChange:Ee}),t[99]=we,t[100]=Te,t[101]=De):De=t[101];let Oe;t[102]===d?Oe=t[103]:(Oe=d.has(`maxTokens`)?(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:d.get(`maxTokens`)}):null,t[102]=d,t[103]=Oe);let ke;t[104]!==Ce||t[105]!==De||t[106]!==Oe?(ke=(0,Q.jsxs)(`div`,{children:[Ce,De,Oe]}),t[104]=Ce,t[105]=De,t[106]=Oe,t[107]=ke):ke=t[107];let Ae;t[108]!==Se||t[109]!==ke?(Ae=(0,Q.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[Se,ke]}),t[108]=Se,t[109]=ke,t[110]=Ae):Ae=t[110];let je;t[111]===c.costSection?je=t[112]:(je=(0,Q.jsx)(`p`,{className:`mb-2 text-xs font-semibold text-fg`,children:c.costSection}),t[111]=c.costSection,t[112]=je);let Me;t[113]===c.costInput?Me=t[114]:(Me=(0,Q.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:c.costInput}),t[113]=c.costInput,t[114]=Me);let Ne;t[115]===Symbol.for(`react.memo_cache_sentinel`)?(Ne=Yi(),t[115]=Ne):Ne=t[115];let Pe=l.cost?.input??0,Ie;t[116]===l.cost?Ie=t[117]:(Ie=e=>g(`cost`,{...l.cost,input:parseFloat(e.target.value)||0,output:l.cost?.output??0,cacheRead:l.cost?.cacheRead??0,cacheWrite:l.cost?.cacheWrite??0}),t[116]=l.cost,t[117]=Ie);let Le;t[118]!==Pe||t[119]!==Ie?(Le=(0,Q.jsx)(`input`,{type:`number`,step:`any`,min:0,className:Ne,value:Pe,onChange:Ie}),t[118]=Pe,t[119]=Ie,t[120]=Le):Le=t[120];let Re;t[121]!==Me||t[122]!==Le?(Re=(0,Q.jsxs)(`div`,{children:[Me,Le]}),t[121]=Me,t[122]=Le,t[123]=Re):Re=t[123];let ze;t[124]===c.costOutput?ze=t[125]:(ze=(0,Q.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:c.costOutput}),t[124]=c.costOutput,t[125]=ze);let Be;t[126]===Symbol.for(`react.memo_cache_sentinel`)?(Be=Yi(),t[126]=Be):Be=t[126];let Ve=l.cost?.output??0,He;t[127]===l.cost?He=t[128]:(He=e=>g(`cost`,{...l.cost,input:l.cost?.input??0,output:parseFloat(e.target.value)||0,cacheRead:l.cost?.cacheRead??0,cacheWrite:l.cost?.cacheWrite??0}),t[127]=l.cost,t[128]=He);let Ue;t[129]!==Ve||t[130]!==He?(Ue=(0,Q.jsx)(`input`,{type:`number`,step:`any`,min:0,className:Be,value:Ve,onChange:He}),t[129]=Ve,t[130]=He,t[131]=Ue):Ue=t[131];let We;t[132]!==ze||t[133]!==Ue?(We=(0,Q.jsxs)(`div`,{children:[ze,Ue]}),t[132]=ze,t[133]=Ue,t[134]=We):We=t[134];let Ge;t[135]!==Re||t[136]!==We?(Ge=(0,Q.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[Re,We]}),t[135]=Re,t[136]=We,t[137]=Ge):Ge=t[137];let Ke;t[138]!==je||t[139]!==Ge?(Ke=(0,Q.jsxs)(`div`,{className:`border-t border-edge-subtle pt-2 dark:border-edge`,children:[je,Ge]}),t[138]=je,t[139]=Ge,t[140]=Ke):Ke=t[140];let qe;t[141]!==U||t[142]!==ne||t[143]!==he||t[144]!==Ae||t[145]!==Ke?(qe=(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[U,ne,he,Ae,Ke]}),t[141]=U,t[142]=ne,t[143]=he,t[144]=Ae,t[145]=Ke,t[146]=qe):qe=t[146];let Je;t[147]===c.cancel?Je=t[148]:(Je=(0,Q.jsx)(G,{asChild:!0,children:(0,Q.jsx)(w,{type:`button`,variant:`secondary`,children:c.cancel})}),t[147]=c.cancel,t[148]=Je);let Ye=o?c.addModelConfirm:c.saveModelConfirm,Ze;t[149]!==b||t[150]!==Ye?(Ze=(0,Q.jsx)(w,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:b,children:Ye}),t[149]=b,t[150]=Ye,t[151]=Ze):Ze=t[151];let Qe;t[152]!==Je||t[153]!==Ze?(Qe=(0,Q.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2 border-t border-edge-subtle pt-3 dark:border-edge`,children:[Je,Ze]}),t[152]=Je,t[153]=Ze,t[154]=Qe):Qe=t[154];let $e;t[155]!==P||t[156]!==qe||t[157]!==Qe?($e=(0,Q.jsxs)(T,{children:[E,(0,Q.jsxs)(gt,{className:D,onOpenAutoFocus:ra,children:[P,qe,Qe]})]}),t[155]=P,t[156]=qe,t[157]=Qe,t[158]=$e):$e=t[158];let et;return t[159]!==r||t[160]!==n||t[161]!==$e?(et=(0,Q.jsx)(ae,{open:n,onOpenChange:r,children:$e}),t[159]=r,t[160]=n,t[161]=$e,t[162]=et):et=t[162],et}function ra(e){return e.preventDefault()}function ia(){return new Map}function aa(){return Bi(``)}function oa(e){let t=(0,Z.c)(122),{open:n,onOpenChange:r,presetKey:i,onConfirm:a,m:o}=e,[s,c]=(0,$.useState)(``),[l,u]=(0,$.useState)(`custom`),[d,f]=(0,$.useState)(``),[p,m]=(0,$.useState)(`openai-completions`),[h,g]=(0,$.useState)(``),[_,v]=(0,$.useState)(null),y,b;t[0]!==n||t[1]!==i?(y=()=>{if(!n)return;v(null);let e=i||null;if(e&&Ki[e]){let t=Ki[e];u(e),f(t.baseUrl||``),m(t.api||`openai-completions`),g(t.apiKey??``),c(qi(e))}else u(`custom`),c(``),f(``),m(`openai-completions`),g(``)},b=[n,i],t[0]=n,t[1]=i,t[2]=y,t[3]=b):(y=t[2],b=t[3]),(0,$.useEffect)(y,b);let x;t[4]===Symbol.for(`react.memo_cache_sentinel`)?(x=e=>{if(u(e),e===`custom`)return;let t=Ki[e];t&&(f(t.baseUrl||``),m(t.api||`openai-completions`),g(t.apiKey??``),c(qi(e)))},t[4]=x):x=t[4];let S=x,C;t[5]!==p||t[6]!==h||t[7]!==d||t[8]!==o.providerIdRequired||t[9]!==a||t[10]!==r||t[11]!==s?(C=()=>{let e=s.trim();if(!e){v(o.providerIdRequired);return}v(null),a(e,{baseUrl:d.trim()||void 0,api:p,apiKey:h.trim()||void 0,models:[]}),r(!1)},t[5]=p,t[6]=h,t[7]=d,t[8]=o.providerIdRequired,t[9]=a,t[10]=r,t[11]=s,t[12]=C):C=t[12];let E=C,D;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,Q.jsx)(se,{className:X(`xopc-dialog-overlay fixed inset-0 bg-scrim`,Fe)}),t[13]=D):D=t[13];let O;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(O=X(`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`,Xe,`overflow-y-auto rounded-xl border border-edge bg-surface-panel p-4 shadow-popover dark:border-edge`),t[14]=O):O=t[14];let k;t[15]===o.addProviderTitle?k=t[16]:(k=(0,Q.jsx)(ce,{className:`text-base font-semibold text-fg`,children:o.addProviderTitle}),t[15]=o.addProviderTitle,t[16]=k);let A;t[17]===o.addProviderSubtitle?A=t[18]:(A=(0,Q.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:o.addProviderSubtitle}),t[17]=o.addProviderSubtitle,t[18]=A);let j;t[19]!==k||t[20]!==A?(j=(0,Q.jsxs)(`div`,{children:[k,A]}),t[19]=k,t[20]=A,t[21]=j):j=t[21];let M;t[22]===Symbol.for(`react.memo_cache_sentinel`)?(M=(0,Q.jsx)(fe,{className:`size-4`}),t[22]=M):M=t[22];let N;t[23]===o.close?N=t[24]:(N=(0,Q.jsx)(G,{asChild:!0,children:(0,Q.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:M})}),t[23]=o.close,t[24]=N);let P;t[25]!==N||t[26]!==j?(P=(0,Q.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[j,N]}),t[25]=N,t[26]=j,t[27]=P):P=t[27];let F;t[28]===o.presetLabel?F=t[29]:(F=(0,Q.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:o.presetLabel}),t[28]=o.presetLabel,t[29]=F);let I;t[30]===Symbol.for(`react.memo_cache_sentinel`)?(I=Xi(),t[30]=I):I=t[30];let L;t[31]===Symbol.for(`react.memo_cache_sentinel`)?(L=e=>S(e.target.value),t[31]=L):L=t[31];let R;t[32]===o.presetCustom?R=t[33]:(R=(0,Q.jsx)(`option`,{value:`custom`,children:o.presetCustom}),t[32]=o.presetCustom,t[33]=R);let z;t[34]===o.presetOllama?z=t[35]:(z=(0,Q.jsx)(`option`,{value:`ollama`,children:o.presetOllama}),t[34]=o.presetOllama,t[35]=z);let B;t[36]===o.presetLmStudio?B=t[37]:(B=(0,Q.jsx)(`option`,{value:`lmstudio`,children:o.presetLmStudio}),t[36]=o.presetLmStudio,t[37]=B);let V;t[38]===o.presetOpenRouter?V=t[39]:(V=(0,Q.jsx)(`option`,{value:`openrouter`,children:o.presetOpenRouter}),t[38]=o.presetOpenRouter,t[39]=V);let H;t[40]===o.presetZhipuCn?H=t[41]:(H=(0,Q.jsx)(`option`,{value:`zhipuCn`,children:o.presetZhipuCn}),t[40]=o.presetZhipuCn,t[41]=H);let U;t[42]===o.presetZaiGeneral?U=t[43]:(U=(0,Q.jsx)(`option`,{value:`zaiGeneral`,children:o.presetZaiGeneral}),t[42]=o.presetZaiGeneral,t[43]=U);let W;t[44]!==l||t[45]!==R||t[46]!==z||t[47]!==B||t[48]!==V||t[49]!==H||t[50]!==U?(W=(0,Q.jsxs)(`select`,{className:I,value:l,onChange:L,children:[R,z,B,V,H,U]}),t[44]=l,t[45]=R,t[46]=z,t[47]=B,t[48]=V,t[49]=H,t[50]=U,t[51]=W):W=t[51];let ee;t[52]!==F||t[53]!==W?(ee=(0,Q.jsxs)(`div`,{children:[F,W]}),t[52]=F,t[53]=W,t[54]=ee):ee=t[54];let te;t[55]===Symbol.for(`react.memo_cache_sentinel`)?(te=(0,Q.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`}),t[55]=te):te=t[55];let K;t[56]===o.providerIdLabel?K=t[57]:(K=(0,Q.jsxs)(`label`,{className:`mb-1 block text-xs font-medium text-fg`,children:[o.providerIdLabel,te]}),t[56]=o.providerIdLabel,t[57]=K);let q;t[58]===Symbol.for(`react.memo_cache_sentinel`)?(q=Yi(),t[58]=q):q=t[58];let ne;t[59]===Symbol.for(`react.memo_cache_sentinel`)?(ne=e=>c(e.target.value),t[59]=ne):ne=t[59];let J;t[60]!==o.providerIdPlaceholder||t[61]!==s?(J=(0,Q.jsx)(`input`,{className:q,value:s,onChange:ne,placeholder:o.providerIdPlaceholder}),t[60]=o.providerIdPlaceholder,t[61]=s,t[62]=J):J=t[62];let re;t[63]!==K||t[64]!==J?(re=(0,Q.jsxs)(`div`,{children:[K,J]}),t[63]=K,t[64]=J,t[65]=re):re=t[65];let ie;t[66]===o.baseUrl?ie=t[67]:(ie=(0,Q.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:o.baseUrl}),t[66]=o.baseUrl,t[67]=ie);let oe;t[68]===Symbol.for(`react.memo_cache_sentinel`)?(oe=Yi(),t[68]=oe):oe=t[68];let Y;t[69]===Symbol.for(`react.memo_cache_sentinel`)?(Y=e=>f(e.target.value),t[69]=Y):Y=t[69];let le;t[70]===d?le=t[71]:(le=(0,Q.jsx)(`input`,{className:oe,value:d,onChange:Y,placeholder:`https://…`}),t[70]=d,t[71]=le);let ue;t[72]!==ie||t[73]!==le?(ue=(0,Q.jsxs)(`div`,{children:[ie,le]}),t[72]=ie,t[73]=le,t[74]=ue):ue=t[74];let de;t[75]===o.apiType?de=t[76]:(de=(0,Q.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:o.apiType}),t[75]=o.apiType,t[76]=de);let pe;t[77]===Symbol.for(`react.memo_cache_sentinel`)?(pe=Xi(),t[77]=pe):pe=t[77];let me,he;t[78]===Symbol.for(`react.memo_cache_sentinel`)?(me=e=>m(e.target.value),he=Mi.map(sa),t[78]=me,t[79]=he):(me=t[78],he=t[79]);let ge;t[80]===p?ge=t[81]:(ge=(0,Q.jsx)(`select`,{className:pe,value:p,onChange:me,children:he}),t[80]=p,t[81]=ge);let _e;t[82]!==de||t[83]!==ge?(_e=(0,Q.jsxs)(`div`,{children:[de,ge]}),t[82]=de,t[83]=ge,t[84]=_e):_e=t[84];let ve;t[85]!==ue||t[86]!==_e?(ve=(0,Q.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[ue,_e]}),t[85]=ue,t[86]=_e,t[87]=ve):ve=t[87];let ye;t[88]===o.apiKey?ye=t[89]:(ye=(0,Q.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:o.apiKey}),t[88]=o.apiKey,t[89]=ye);let be;t[90]===Symbol.for(`react.memo_cache_sentinel`)?(be=Yi(),t[90]=be):be=t[90];let xe;t[91]===Symbol.for(`react.memo_cache_sentinel`)?(xe=e=>g(e.target.value),t[91]=xe):xe=t[91];let Se;t[92]!==h||t[93]!==o.apiKeyPlaceholder?(Se=(0,Q.jsx)(`input`,{className:be,value:h,onChange:xe,placeholder:o.apiKeyPlaceholder}),t[92]=h,t[93]=o.apiKeyPlaceholder,t[94]=Se):Se=t[94];let Ce;t[95]!==ye||t[96]!==Se?(Ce=(0,Q.jsxs)(`div`,{children:[ye,Se]}),t[95]=ye,t[96]=Se,t[97]=Ce):Ce=t[97];let we;t[98]===_?we=t[99]:(we=_?(0,Q.jsxs)(`p`,{className:`flex items-center gap-1 text-xs text-red-600 dark:text-red-400`,children:[(0,Q.jsx)(ot,{className:`size-3.5 shrink-0`}),_]}):null,t[98]=_,t[99]=we);let Te;t[100]!==ee||t[101]!==re||t[102]!==ve||t[103]!==Ce||t[104]!==we?(Te=(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[ee,re,ve,Ce,we]}),t[100]=ee,t[101]=re,t[102]=ve,t[103]=Ce,t[104]=we,t[105]=Te):Te=t[105];let Ee;t[106]===o.cancel?Ee=t[107]:(Ee=(0,Q.jsx)(G,{asChild:!0,children:(0,Q.jsx)(w,{type:`button`,variant:`secondary`,children:o.cancel})}),t[106]=o.cancel,t[107]=Ee);let De;t[108]!==E||t[109]!==o.addProviderConfirm?(De=(0,Q.jsx)(w,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:E,children:o.addProviderConfirm}),t[108]=E,t[109]=o.addProviderConfirm,t[110]=De):De=t[110];let Oe;t[111]!==Ee||t[112]!==De?(Oe=(0,Q.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2 border-t border-edge-subtle pt-3 dark:border-edge`,children:[Ee,De]}),t[111]=Ee,t[112]=De,t[113]=Oe):Oe=t[113];let ke;t[114]!==P||t[115]!==Te||t[116]!==Oe?(ke=(0,Q.jsxs)(T,{children:[D,(0,Q.jsxs)(gt,{className:O,onOpenAutoFocus:ca,children:[P,Te,Oe]})]}),t[114]=P,t[115]=Te,t[116]=Oe,t[117]=ke):ke=t[117];let Ae;return t[118]!==r||t[119]!==n||t[120]!==ke?(Ae=(0,Q.jsx)(ae,{open:n,onOpenChange:r,children:ke}),t[118]=r,t[119]=n,t[120]=ke,t[121]=Ae):Ae=t[121],Ae}function sa(e){return(0,Q.jsx)(`option`,{value:e.value,children:e.label},e.value)}function ca(e){return e.preventDefault()}function la(e){let t=(0,Z.c)(27),{config:n,setConfig:r,expanded:i,toggleExpand:a,showPw:o,toggleShowPw:s,testResults:c,runTestKey:l,ms:u,removeProv:d,openModelDialog:f,setTestResults:p}=e,m;if(t[0]!==n.providers||t[1]!==i||t[2]!==u||t[3]!==f||t[4]!==d||t[5]!==l||t[6]!==r||t[7]!==p||t[8]!==o||t[9]!==c||t[10]!==a||t[11]!==s){let e;t[13]!==i||t[14]!==u||t[15]!==f||t[16]!==d||t[17]!==l||t[18]!==r||t[19]!==p||t[20]!==o||t[21]!==c||t[22]!==a||t[23]!==s?(e=e=>{let[t,n]=e,m=i.has(t),h=n.models?.length??0,g=n.apiKey?Ui(n.apiKey):null,v=c.get(t),b=o.has(t);return(0,Q.jsxs)(`section`,{className:`overflow-hidden rounded-2xl bg-surface-base`,children:[(0,Q.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,Q.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:()=>a(t),children:[m?(0,Q.jsx)(L,{className:`size-4 shrink-0 text-fg-muted`}):(0,Q.jsx)(_,{className:`size-4 shrink-0 text-fg-muted`}),(0,Q.jsx)(`span`,{className:`truncate`,children:t}),h>0?(0,Q.jsx)(`span`,{className:`shrink-0 rounded-full bg-accent px-2 py-0.5 text-[10px] font-medium text-white`,children:h}):null,g?(0,Q.jsx)(`span`,{className:X(`shrink-0 rounded-full px-2 py-0.5 text-[10px] font-medium`,g===`shell`&&`bg-blue-100 text-blue-800 dark:bg-blue-950 dark:text-blue-200`,g===`env`&&`bg-emerald-100 text-emerald-800 dark:bg-emerald-950 dark:text-emerald-200`,g===`literal`&&`bg-surface-hover text-fg-muted dark:bg-surface-active`),children:g===`shell`?u.badgeShell:g===`env`?u.badgeEnv:u.badgeLiteral}):null]}),(0,Q.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:()=>d(t),"aria-label":u.removeProvider,children:(0,Q.jsx)(Je,{className:`size-4`})})]}),m?(0,Q.jsxs)(`div`,{className:`space-y-4 p-3`,children:[(0,Q.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:u.baseUrl}),(0,Q.jsx)(`input`,{className:Yi(),value:n.baseUrl||``,onChange:e=>r(n=>$i(n,t,{baseUrl:e.target.value}))})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:u.apiType}),(0,Q.jsx)(`select`,{className:Xi(),value:n.api||`openai-completions`,onChange:e=>r(n=>$i(n,t,{api:e.target.value})),children:Mi.map(ua)})]})]}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:u.apiKey}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Q.jsx)(`input`,{className:X(Yi(),`min-w-0 flex-1`),type:b?`text`:`password`,autoComplete:`off`,value:n.apiKey||``,onChange:e=>{let n=e.target.value;r(e=>$i(e,t,{apiKey:n})),p(e=>{let n=new Map(e);return n.delete(t),n})},placeholder:u.apiKeyPlaceholder}),(0,Q.jsx)(w,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>s(t),children:b?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Ce,{className:`mr-1 size-3.5`}),u.hide]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Ze,{className:`mr-1 size-3.5`}),u.show]})}),(0,Q.jsx)(w,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>l(t,n.apiKey||``),children:u.testKey})]}),v?(0,Q.jsx)(`p`,{className:X(`mt-1 text-xs`,v.error?`text-red-600 dark:text-red-400`:`text-emerald-700 dark:text-emerald-400`),children:v.error?`${u.testError}: ${v.error}`:`${u.testOk} (${v.type}): ${Wi(v.resolved||``)}`}):null,(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:u.apiKeyHint})]}),(0,Q.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,Q.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:n.authHeader||!1,onChange:e=>r(n=>$i(n,t,{authHeader:e.target.checked}))}),u.authHeader]}),(0,Q.jsxs)(`div`,{className:`border-t border-edge-subtle pt-3 dark:border-edge`,children:[(0,Q.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-semibold text-fg`,children:u.modelsSection}),(0,Q.jsxs)(w,{type:`button`,variant:`primary`,className:`px-2 py-1 text-xs`,onClick:()=>f(t,null,!0),children:[(0,Q.jsx)(y,{className:`mr-1 size-3.5`}),u.addModel]})]}),(n.models||[]).length===0?(0,Q.jsx)(`p`,{className:`text-xs text-fg-muted`,children:u.modelsEmpty}):(0,Q.jsx)(`ul`,{className:`space-y-2`,children:(n.models||[]).map(e=>(0,Q.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,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`div`,{className:`truncate text-sm font-medium text-fg`,children:e.id}),e.name&&e.name!==e.id?(0,Q.jsx)(`div`,{className:`truncate text-xs text-fg-muted`,children:e.name}):null]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(0,Q.jsx)(`button`,{type:`button`,className:`rounded-lg p-1.5 text-fg-muted hover:bg-surface-panel hover:text-fg`,onClick:()=>f(t,e,!1),"aria-label":u.editModel,children:(0,Q.jsx)(N,{className:`size-4`})}),(0,Q.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(u.removeModelConfirm.replace(`{{id}}`,e.id))&&r(n=>{let r=n.providers[t];return r?$i(n,t,{models:(r.models||[]).filter(t=>t.id!==e.id)}):n})},"aria-label":u.removeModel,children:(0,Q.jsx)(Je,{className:`size-4`})})]})]},e.id))})]})]}):null]},t)},t[13]=i,t[14]=u,t[15]=f,t[16]=d,t[17]=l,t[18]=r,t[19]=p,t[20]=o,t[21]=c,t[22]=a,t[23]=s,t[24]=e):e=t[24],m=Object.entries(n.providers).sort(da).map(e),t[0]=n.providers,t[1]=i,t[2]=u,t[3]=f,t[4]=d,t[5]=l,t[6]=r,t[7]=p,t[8]=o,t[9]=c,t[10]=a,t[11]=s,t[12]=m}else m=t[12];let h;return t[25]===m?h=t[26]:(h=(0,Q.jsx)(`div`,{className:`flex flex-col gap-3`,children:m}),t[25]=m,t[26]=h),h}function ua(e){return(0,Q.jsx)(`option`,{value:e.value,children:e.label},e.value)}function da(e,t){let[n]=e,[r]=t;return n.localeCompare(r)}function fa(e){let t=(0,Z.c)(57),{ms:n,openAddProvider:r}=e,i;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(i=(0,Q.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,Q.jsx)(Ge,{className:`size-7 text-accent`,strokeWidth:1.5})}),t[0]=i):i=t[0];let a;t[1]===n.emptyTitle?a=t[2]:(a=(0,Q.jsx)(`h2`,{className:`mb-1 text-base font-semibold text-fg`,children:n.emptyTitle}),t[1]=n.emptyTitle,t[2]=a);let o;t[3]===n.emptyDesc?o=t[4]:(o=(0,Q.jsx)(`p`,{className:`mb-6 max-w-md text-sm text-fg-muted`,children:n.emptyDesc}),t[3]=n.emptyDesc,t[4]=o);let s;t[5]===r?s=t[6]:(s=()=>r(null),t[5]=r,t[6]=s);let c;t[7]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,Q.jsx)(y,{className:`mr-1 size-4`}),t[7]=c):c=t[7];let l;t[8]!==n.emptyCta||t[9]!==s?(l=(0,Q.jsxs)(w,{type:`button`,className:`mb-6 bg-accent text-white hover:bg-accent/90`,onClick:s,children:[c,n.emptyCta]}),t[8]=n.emptyCta,t[9]=s,t[10]=l):l=t[10];let u;t[11]===Symbol.for(`react.memo_cache_sentinel`)?(u=X(`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`,We.transition,We.focusRingBase),t[11]=u):u=t[11];let d;t[12]===r?d=t[13]:(d=()=>r(`ollama`),t[12]=r,t[13]=d);let f;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(f=(0,Q.jsx)(D,{className:`size-3.5`,"aria-hidden":!0}),t[14]=f):f=t[14];let p;t[15]!==n.presetOllama||t[16]!==d?(p=(0,Q.jsxs)(`button`,{type:`button`,className:u,onClick:d,children:[f,n.presetOllama]}),t[15]=n.presetOllama,t[16]=d,t[17]=p):p=t[17];let m;t[18]===Symbol.for(`react.memo_cache_sentinel`)?(m=X(`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`,We.transition,We.focusRingBase),t[18]=m):m=t[18];let h;t[19]===r?h=t[20]:(h=()=>r(`openrouter`),t[19]=r,t[20]=h);let g;t[21]===Symbol.for(`react.memo_cache_sentinel`)?(g=(0,Q.jsx)(j,{className:`size-3.5`,"aria-hidden":!0}),t[21]=g):g=t[21];let _;t[22]!==n.presetOpenRouter||t[23]!==h?(_=(0,Q.jsxs)(`button`,{type:`button`,className:m,onClick:h,children:[g,n.presetOpenRouter]}),t[22]=n.presetOpenRouter,t[23]=h,t[24]=_):_=t[24];let v;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(v=X(`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`,We.transition,We.focusRingBase),t[25]=v):v=t[25];let b;t[26]===r?b=t[27]:(b=()=>r(`lmstudio`),t[26]=r,t[27]=b);let x;t[28]===Symbol.for(`react.memo_cache_sentinel`)?(x=(0,Q.jsx)(Ge,{className:`size-3.5`,"aria-hidden":!0}),t[28]=x):x=t[28];let S;t[29]!==n.presetLmStudio||t[30]!==b?(S=(0,Q.jsxs)(`button`,{type:`button`,className:v,onClick:b,children:[x,n.presetLmStudio]}),t[29]=n.presetLmStudio,t[30]=b,t[31]=S):S=t[31];let C;t[32]===Symbol.for(`react.memo_cache_sentinel`)?(C=X(`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`,We.transition,We.focusRingBase),t[32]=C):C=t[32];let T;t[33]===r?T=t[34]:(T=()=>r(`zhipuCn`),t[33]=r,t[34]=T);let E;t[35]===Symbol.for(`react.memo_cache_sentinel`)?(E=(0,Q.jsx)(D,{className:`size-3.5`,"aria-hidden":!0}),t[35]=E):E=t[35];let O;t[36]!==n.presetZhipuCn||t[37]!==T?(O=(0,Q.jsxs)(`button`,{type:`button`,className:C,onClick:T,children:[E,n.presetZhipuCn]}),t[36]=n.presetZhipuCn,t[37]=T,t[38]=O):O=t[38];let k;t[39]===Symbol.for(`react.memo_cache_sentinel`)?(k=X(`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`,We.transition,We.focusRingBase),t[39]=k):k=t[39];let A;t[40]===r?A=t[41]:(A=()=>r(`zaiGeneral`),t[40]=r,t[41]=A);let M;t[42]===Symbol.for(`react.memo_cache_sentinel`)?(M=(0,Q.jsx)(j,{className:`size-3.5`,"aria-hidden":!0}),t[42]=M):M=t[42];let N;t[43]!==n.presetZaiGeneral||t[44]!==A?(N=(0,Q.jsxs)(`button`,{type:`button`,className:k,onClick:A,children:[M,n.presetZaiGeneral]}),t[43]=n.presetZaiGeneral,t[44]=A,t[45]=N):N=t[45];let P;t[46]!==p||t[47]!==_||t[48]!==S||t[49]!==O||t[50]!==N?(P=(0,Q.jsxs)(`div`,{className:`flex flex-wrap justify-center gap-2`,children:[p,_,S,O,N]}),t[46]=p,t[47]=_,t[48]=S,t[49]=O,t[50]=N,t[51]=P):P=t[51];let F;return t[52]!==a||t[53]!==P||t[54]!==o||t[55]!==l?(F=(0,Q.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:[i,a,o,l,P]}),t[52]=a,t[53]=P,t[54]=o,t[55]=l,t[56]=F):F=t[56],F}function pa(){let e=F(e=>e.language),t=oe(e),n=t.modelsSettings,r=Vt(t.agentSettings),i=!!R(e=>e.token),[a,o]=(0,$.useState)({providers:{}}),[s,c]=(0,$.useState)({providers:{}}),[l,u]=(0,$.useState)(``),[d,f]=(0,$.useState)(),[p,m]=(0,$.useState)(!0),[g,_]=(0,$.useState)(!1),[v,b]=(0,$.useState)(!1),[x,S]=(0,$.useState)(!1),[C,T]=(0,$.useState)(null),[E,D]=(0,$.useState)(!1),[O,k]=(0,$.useState)(null),[A,j]=(0,$.useState)(()=>new Set),[M,N]=(0,$.useState)(!1),[P,I]=(0,$.useState)(``),[L,z]=(0,$.useState)(null),[B,V]=(0,$.useState)(()=>new Set),[H,U]=(0,$.useState)(()=>new Map),[W,G]=(0,$.useState)(!1),[ee,te]=(0,$.useState)(null),[K,q]=(0,$.useState)(!1),[ne,J]=(0,$.useState)(null),re=(0,$.useCallback)(async e=>{let t=!e?.skipFullPageLoading;t&&m(!0),T(null);try{let e=await Fi(),t=Pi(e.config);o(t),c(structuredClone(t)),u(e.path),f(e.loadError),k(null),D(!1)}catch(e){T(e instanceof Error?e.message:n.loadError),o({providers:{}}),c({providers:{}})}finally{t&&m(!1)}},[n.loadError]);(0,$.useEffect)(()=>{if(!i){m(!1);return}re()},[i,re]);let ie=(0,$.useMemo)(()=>JSON.stringify(a)!==JSON.stringify(s),[a,s]),ae=(0,$.useMemo)(()=>r.form?{form:r.form,update:r.update,a:t.agentSettings,chat:t.chat}:null,[r.form,r.update,t.agentSettings,t.chat]),se=ie||r.dirty,ce=(0,$.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]),le=e=>{j(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},ue=e=>{V(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},de=(0,$.useCallback)(()=>{I(JSON.stringify(a,null,2)),z(null)},[a]);(0,$.useEffect)(()=>{M&&de()},[M,de]);let fe=()=>{try{o(Pi(JSON.parse(P))),z(null)}catch{z(n.jsonParseError)}},pe=async()=>{b(!0),T(null);try{k(await Ii(a))}catch(e){T(e instanceof Error?e.message:n.validateError)}finally{b(!1)}},me=async()=>{if(g||r.saving)return;let e=ie,i=r.dirty;if(!(!e&&!i)){T(null),D(!1);try{if(e){_(!0);try{await Li(a),c(structuredClone(a)),k(null)}finally{_(!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)}}},he=(0,$.useCallback)(()=>{o(structuredClone(s)),k(null),D(!1),T(null),M&&(I(JSON.stringify(s,null,2)),z(null)),r.discard()},[s,M,r.discard]),ge=async()=>{S(!0),T(null);try{await Ri(),await re({skipFullPageLoading:!0})}catch(e){T(e instanceof Error?e.message:n.reloadError)}finally{S(!1)}},_e=async(e,t)=>{try{let n=await zi(t);U(t=>{let r=new Map(t);return r.set(e,n),r})}catch(t){U(n=>{let r=new Map(n);return r.set(e,{type:`error`,error:t instanceof Error?t.message:`Error`}),r})}},ve=(e=null)=>{te(e),G(!0)},ye=(e,t)=>{o(n=>ta(n,e,t)),j(t=>new Set(t).add(e))},be=e=>{window.confirm(n.removeProviderConfirm.replace(`{{id}}`,e))&&(o(t=>ea(t,e)),U(t=>{let n=new Map(t);return n.delete(e),n}))},xe=(e,t,n)=>{J({providerId:e,model:t,isNew:n}),q(!0)},Se=e=>{if(!ne)return;let{providerId:t,isNew:n}=ne;o(r=>{let i=r.providers[t];if(!i)return r;let a=i.models||[];return n?$i(r,t,{models:[...a,e]}):$i(r,t,{models:a.map(t=>t.id===e.id?e:t)})})};return i?(0,Q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-4 px-4 py-8`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Q.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.models}),(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.subtitle}),(0,Q.jsxs)(`a`,{href:Ne(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,Q.jsx)(Ie,{className:`size-3.5`})]})]}),d?(0,Q.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,Q.jsx)(ot,{className:`mt-0.5 size-4 shrink-0`}),(0,Q.jsxs)(`span`,{children:[n.loadFileWarning,`: `,d]})]}):null,l?(0,Q.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.filePath,`: `,(0,Q.jsx)(`code`,{className:`rounded bg-surface-base px-1 py-0.5 font-mono text-fg-muted`,children:l})]}):null,(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsxs)(w,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:()=>ve(null),disabled:p,children:[(0,Q.jsx)(y,{className:`mr-1 size-4`}),n.addProvider]}),(0,Q.jsx)(w,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:pe,disabled:p||v,children:v?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Y,{className:`mr-1 size-4 animate-spin`}),n.validating]}):n.validate}),(0,Q.jsx)(w,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:he,disabled:p||g||r.saving||!se,children:n.discard}),(0,Q.jsx)(w,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:()=>void me(),disabled:p||g||r.saving||!se,children:g||r.saving?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Y,{className:`mr-1 size-4 animate-spin`}),n.saving]}):n.save}),(0,Q.jsx)(w,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[8.5rem] justify-center`,onClick:ge,disabled:p||x,children:x?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Y,{className:`mr-1 size-4 animate-spin`}),n.reloading]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(h,{className:`mr-1 size-4`}),n.reload]})}),(0,Q.jsx)(w,{type:`button`,variant:`ghost`,className:`text-fg-muted`,onClick:()=>{N(e=>!e),z(null)},children:M?n.hideJson:n.showJson}),(0,Q.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,Q.jsx)(`span`,{className:`text-fg-muted`,children:n.statsProviders.replace(`{{count}}`,String(ce.providers))}),(0,Q.jsx)(`span`,{className:`text-fg-subtle`,children:`|`}),(0,Q.jsx)(`span`,{className:`text-fg-muted`,children:n.statsModels.replace(`{{count}}`,String(ce.models))})]})]}),se?(0,Q.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,E||r.saveOk?(0,Q.jsx)(`p`,{className:`text-xs text-emerald-700 dark:text-emerald-400`,role:`status`,children:n.saved}):null,C?(0,Q.jsxs)(`p`,{className:`flex items-center gap-1 text-sm text-red-600 dark:text-red-400`,role:`alert`,children:[(0,Q.jsx)(ot,{className:`size-4 shrink-0`}),C]}):null,r.error?(0,Q.jsxs)(`p`,{className:`flex items-center gap-1 text-sm text-red-600 dark:text-red-400`,role:`alert`,children:[(0,Q.jsx)(ot,{className:`size-4 shrink-0`}),r.error]}):null,O&&O.errors.length>0?(0,Q.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,Q.jsx)(`p`,{className:`mb-1 text-sm font-medium text-amber-950 dark:text-amber-100`,children:O.valid?n.validationWarnings:n.validationErrors}),(0,Q.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=>(0,Q.jsxs)(`li`,{children:[e.path,`: `,e.message,` (`,e.severity,`)`]},`${e.path}-${e.severity}-${e.message}`))})]}):null,p?(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,Q.jsx)(Y,{className:`size-4 animate-spin`}),n.loading]}):M?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsx)(`textarea`,{className:X(Yi(),`min-h-[320px] resize-y font-mono text-xs leading-relaxed`),value:P,onChange:e=>I(e.target.value),spellCheck:!1}),L?(0,Q.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:L}):null,(0,Q.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Q.jsx)(w,{type:`button`,variant:`secondary`,onClick:de,children:n.jsonReset}),(0,Q.jsx)(w,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:fe,children:n.jsonApply})]})]}):Object.keys(a.providers).length===0?(0,Q.jsx)(fa,{ms:n,openAddProvider:ve}):(0,Q.jsx)(la,{config:a,setConfig:o,expanded:A,toggleExpand:le,showPw:B,toggleShowPw:ue,testResults:H,runTestKey:_e,ms:n,removeProv:be,openModelDialog:xe,setTestResults:U}),ae?(0,Q.jsx)(`div`,{className:`mt-10 border-t border-edge-subtle pt-8 dark:border-edge`,children:(0,Q.jsx)(Gi,{...ae})}):null,(0,Q.jsx)(oa,{open:W,onOpenChange:G,presetKey:ee,onConfirm:ye,m:n}),(0,Q.jsx)(na,{open:K,onOpenChange:e=>{q(e),e||J(null)},providerId:ne?.providerId??null,model:ne?.model??null,isNew:ne?.isNew??!1,onSave:Se,m:n})]}):(0,Q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Q.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.models}),(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}async function ma(e){let t=await J(lt(`/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 ha(e){let t=await J(lt(`/api/auth/oauth-async/${encodeURIComponent(e)}/status`));if(!t.ok)throw Error(`OAuth status: ${t.status}`);return(await t.json()).payload}async function ga(e,t){let n=await J(lt(`/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 _a(e){let t=await J(lt(`/api/auth/oauth-async/${encodeURIComponent(e)}/cancel`),{method:`POST`});if(!t.ok)throw Error(`Cancel OAuth failed: ${t.status}`)}async function va(e){let t=await J(lt(`/api/auth/oauth-async/${encodeURIComponent(e)}`),{method:`DELETE`});if(!t.ok)throw Error(`Cleanup session failed: ${t.status}`)}async function ya(e){let t=await J(lt(`/api/auth/oauth/${encodeURIComponent(e)}`),{method:`DELETE`});if(!t.ok)throw Error(`Revoke OAuth failed: ${t.status}`)}function ba(e){let t=(0,Z.c)(35),{providerId:n,language:r}=e,i=xe[n];if(!i)return null;let a=r===`zh`,o=a&&i.descriptionZh?i.descriptionZh:i.description;if(!o)return null;let s=a?`${n} 详情`:`${n} info`,c;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(c=(0,Q.jsx)(ge,{className:`size-3.5`,"aria-hidden":!0}),t[0]=c):c=t[0];let l;t[1]===s?l=t[2]:(l=(0,Q.jsx)(de,{asChild:!0,children:(0,Q.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":s,children:c})}),t[1]=s,t[2]=l);let u;t[3]===Symbol.for(`react.memo_cache_sentinel`)?(u=X(`w-64 rounded-xl border border-edge bg-surface-panel p-3 shadow-md`,et,`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`),t[3]=u):u=t[3];let d;t[4]===n?d=t[5]:(d=(0,Q.jsx)(`p`,{className:`text-xs font-semibold text-fg`,children:n}),t[4]=n,t[5]=d);let f=a?`关闭`:`Close`,p;t[6]===Symbol.for(`react.memo_cache_sentinel`)?(p=(0,Q.jsx)(fe,{className:`size-3.5`,"aria-hidden":!0}),t[6]=p):p=t[6];let m;t[7]===f?m=t[8]:(m=(0,Q.jsx)(k,{asChild:!0,children:(0,Q.jsx)(`button`,{type:`button`,className:`shrink-0 rounded p-0.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,"aria-label":f,children:p})}),t[7]=f,t[8]=m);let h;t[9]!==d||t[10]!==m?(h=(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[d,m]}),t[9]=d,t[10]=m,t[11]=h):h=t[11];let g;t[12]===o?g=t[13]:(g=(0,Q.jsx)(`p`,{className:`mt-1.5 text-xs leading-relaxed text-fg-muted`,children:o}),t[12]=o,t[13]=g);let _;t[14]!==i.bestFor||t[15]!==a?(_=i.bestFor&&i.bestFor.length>0?(0,Q.jsxs)(`div`,{className:`mt-2`,children:[(0,Q.jsx)(`p`,{className:`text-[10px] font-medium uppercase tracking-wide text-fg-subtle`,children:a?`适合场景`:`Best for`}),(0,Q.jsx)(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:i.bestFor.map(xa)})]}):null,t[14]=i.bestFor,t[15]=a,t[16]=_):_=t[16];let v;t[17]!==i.freeTier||t[18]!==i.freeTierNote||t[19]!==a?(v=i.freeTier===void 0?null:(0,Q.jsxs)(`div`,{className:`mt-2`,children:[(0,Q.jsx)(`p`,{className:`text-[10px] font-medium uppercase tracking-wide text-fg-subtle`,children:a?`免费额度`:`Free tier`}),(0,Q.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:i.freeTier?i.freeTierNote??(a?`有免费额度`:`Available`):a?`无免费额度(按量付费)`:`None (pay-as-you-go)`})]}),t[17]=i.freeTier,t[18]=i.freeTierNote,t[19]=a,t[20]=v):v=t[20];let y;t[21]!==i.docsUrl||t[22]!==i.pricingUrl||t[23]!==a?(y=i.pricingUrl||i.docsUrl?(0,Q.jsxs)(`div`,{className:`mt-2.5 flex gap-3`,children:[i.pricingUrl?(0,Q.jsxs)(`a`,{href:i.pricingUrl,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-0.5 text-xs text-accent-fg hover:underline`,children:[a?`定价`:`Pricing`,(0,Q.jsx)(Ie,{className:`size-3`,"aria-hidden":!0})]}):null,i.docsUrl?(0,Q.jsxs)(`a`,{href:i.docsUrl,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-0.5 text-xs text-accent-fg hover:underline`,children:[a?`文档`:`Docs`,(0,Q.jsx)(Ie,{className:`size-3`,"aria-hidden":!0})]}):null]}):null,t[21]=i.docsUrl,t[22]=i.pricingUrl,t[23]=a,t[24]=y):y=t[24];let b;t[25]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,Q.jsx)(C,{className:`fill-edge`}),t[25]=b):b=t[25];let x;t[26]!==g||t[27]!==_||t[28]!==v||t[29]!==y||t[30]!==h?(x=(0,Q.jsx)(O,{children:(0,Q.jsxs)(qe,{side:`right`,align:`start`,sideOffset:6,className:u,children:[h,g,_,v,y,b]})}),t[26]=g,t[27]=_,t[28]=v,t[29]=y,t[30]=h,t[31]=x):x=t[31];let S;return t[32]!==x||t[33]!==l?(S=(0,Q.jsxs)(pe,{children:[l,x]}),t[32]=x,t[33]=l,t[34]=S):S=t[34],S}function xa(e){return(0,Q.jsx)(`span`,{className:`rounded bg-surface-hover px-1.5 py-0.5 text-[10px] font-medium text-fg-muted`,children:e},e)}var Sa=[`common`,`specialty`,`enterprise`,`oauth`,`extension`];function Ca(e){let t=new Map;for(let e of Sa)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 wa(e,t){return e.replace(/\{\{(\w+)\}\}/g,(e,n)=>String(t[n]??``))}function Ta(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 Ea(e){let t=(0,Z.c)(16),{envVar:n,labels:r}=e,[i,a]=(0,$.useState)(!1),o;t[0]===n?o=t[1]:(o=async()=>{try{await navigator.clipboard.writeText(n),a(!0),window.setTimeout(()=>a(!1),2e3)}catch{}},t[0]=n,t[1]=o);let s=o,c;t[2]===n?c=t[3]:(c=(0,Q.jsx)(`code`,{className:`rounded bg-surface-hover px-1.5 py-0.5 font-mono text-[11px] text-fg-muted`,children:n}),t[2]=n,t[3]=c);let l;t[4]===s?l=t[5]:(l=()=>void s(),t[4]=s,t[5]=l);let u=i?r.copied:r.copy,d=i?r.copied:r.copy,f;t[6]===i?f=t[7]:(f=i?(0,Q.jsx)(te,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):(0,Q.jsx)(ze,{className:`size-3.5`,"aria-hidden":!0}),t[6]=i,t[7]=f);let p;t[8]!==l||t[9]!==u||t[10]!==d||t[11]!==f?(p=(0,Q.jsx)(`button`,{type:`button`,onClick:l,className:`rounded p-0.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,title:u,"aria-label":d,children:f}),t[8]=l,t[9]=u,t[10]=d,t[11]=f,t[12]=p):p=t[12];let m;return t[13]!==c||t[14]!==p?(m=(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[c,p]}),t[13]=c,t[14]=p,t[15]=m):m=t[15],m}function Da({row:e,value:t,rowDirty:n,labels:r,language:i,onChange:a,onReload:o,justSaved:s,availableModels:c}){let[l,d]=(0,$.useState)(!1),[f,p]=(0,$.useState)(!1),[m,h]=(0,$.useState)(!1),[g,_]=(0,$.useState)(null),[v,y]=(0,$.useState)(!1),[b,x]=(0,$.useState)(null),[S,C]=(0,$.useState)(!1),T=ke(t),E=T&&!f?``:t,D=e.configured&&!T&&!!t,[O,k]=(0,$.useState)(!1),[A,j]=(0,$.useState)(),[M,N]=(0,$.useState)(),[P,F]=(0,$.useState)(),[I,R]=(0,$.useState)(),[z,B]=(0,$.useState)(),[V,H]=(0,$.useState)(``),[U,G]=(0,$.useState)(!1),[K,q]=(0,$.useState)(null),[ne,J]=(0,$.useState)(null),re=e.activeKeySource??`none`,ie=(0,$.useMemo)(()=>ct(e.id,i),[e.id,i]);(0,$.useEffect)(()=>()=>{A&&va(A).catch(()=>{})},[A]),(0,$.useEffect)(()=>{if(!A||!O)return;let e=window.setInterval(()=>{(async()=>{try{let t=await ha(A);F(t.message),R(t.authUrl),B(t.instructions),t.status===`waiting_auth`||t.status===`waiting_code`?N(t.status===`waiting_code`?`waiting_code`:`waiting`):t.status===`completed`?(window.clearInterval(e),k(!1),N(`success`),F(t.message),window.setTimeout(()=>o(),800)):(t.status===`failed`||t.status===`cancelled`)&&(window.clearInterval(e),k(!1),N(`error`),F(t.error||t.message||`OAuth failed`))}catch{}})()},1e3);return()=>window.clearInterval(e)},[A,O,o]);let ae=async()=>{k(!0),N(`waiting`),F(r.oauthStarting),j(void 0),R(void 0),B(void 0);try{j((await ma(e.id)).sessionId)}catch(e){N(`error`),F(e instanceof Error?e.message:`OAuth failed`),k(!1)}},oe=async()=>{if(A){try{await _a(A)}catch{}j(void 0),k(!1),N(`idle`),F(void 0)}},se=async()=>{if(!(!A||!V.trim()))try{await ga(A,V.trim()),H(``),F(r.oauthProcessingCode)}catch(e){N(`error`),F(e instanceof Error?e.message:`Failed`)}},ce=()=>{window.confirm(wa(r.revokeConfirm,{name:e.name}))&&(_(null),ya(e.id).then(()=>o()).catch(e=>_(e instanceof Error?e.message:r.revokeFailed)))},le=async()=>{C(!1),y(!0),x(null);try{await Re(e.id),x(r.removeKeySuccess),a(e.id,``),window.setTimeout(()=>o(),600)}catch(e){x(e instanceof Error?e.message:r.removeKeyFailed)}finally{y(!1)}},de=e.configured&&T&&re!==`env`&&re!==`extension`&&re!==`models_json`,pe=async()=>{if(!(!t||T))try{await navigator.clipboard.writeText(t),h(!0),window.setTimeout(()=>h(!1),2e3)}catch{}},me=async()=>{let e=t.trim();if(!(!e||ke(e))){G(!0),q(null),J(null);try{let t=await dt(e);if(t.error){J(!1),q(`${r.testFailed} ${t.error}`);return}J(!0),t.type===`env`?q(r.testOkEnv):t.type===`command`?q(r.testOkCommand):q(r.testOkLiteral)}catch(e){J(!1),q(e instanceof Error?e.message:r.testFailed)}finally{G(!1)}}},he=n?r.metaWillSave:e.configured?T?`${r.metaMasked} · ${r.runtimeLabelPrefix} ${Ta(r,re)}`:`${r.runtimeLabelPrefix} ${Ta(r,re)}`:r.metaNotConfigured,_e=`provider-details-${e.id}`;return(0,Q.jsxs)(`div`,{className:`bg-surface-panel`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 p-3 sm:px-4`,children:[(0,Q.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,Q.jsx)(te,{className:`size-4 text-emerald-600 dark:text-emerald-400`}):(0,Q.jsx)(ue,{className:`size-4 text-fg-subtle`,strokeWidth:1.75})}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Q.jsx)(`span`,{className:`text-sm font-semibold text-fg`,children:e.name}),(0,Q.jsx)(ba,{providerId:e.id,language:i}),(0,Q.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,Q.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,Q.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:he})]}),(0,Q.jsx)(w,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 p-0`,"aria-expanded":l,"aria-controls":_e,"aria-label":r.expandRowDetails,onClick:()=>d(e=>!e),children:(0,Q.jsx)(L,{className:X(`size-4 transition-transform`,l&&`rotate-180`),"aria-hidden":!0})})]}),l?(0,Q.jsxs)(`div`,{id:_e,role:`region`,className:`space-y-3 border-t border-edge-subtle bg-surface-base/40 p-3 dark:bg-surface-base/20 sm:px-4`,children:[e.supportsApiKey===!1?null:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Q.jsxs)(`div`,{className:`relative flex flex-col gap-2 sm:flex-row sm:gap-2`,children:[(0,Q.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,Q.jsx)(`input`,{type:f||!T?`text`:`password`,className:X(`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`,u,`dark:border-edge`),value:E,placeholder:T?r.placeholderOverride:e.configured?r.placeholderKeep:r.placeholderKey,disabled:O,onChange:t=>a(e.id,t.target.value),autoComplete:`off`,spellCheck:!1}),(0,Q.jsxs)(`div`,{className:`absolute right-1 top-1/2 flex -translate-y-1/2 gap-0.5`,children:[t&&!T?(0,Q.jsx)(`button`,{type:`button`,className:X(`rounded p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,We.transition,We.press,We.focusRingPanel),title:m?r.copied:r.copy,"aria-label":m?r.copied:r.copy,onClick:()=>void pe(),children:m?(0,Q.jsx)(te,{className:`size-4`}):(0,Q.jsx)(ze,{className:`size-4`})}):null,(0,Q.jsx)(`button`,{type:`button`,className:X(`rounded p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg disabled:opacity-40`,We.transition,We.press,We.focusRingPanel),title:f?r.hide:r.show,"aria-label":f?r.hide:r.show,disabled:T,onClick:()=>p(e=>!e),children:f?(0,Q.jsx)(Ce,{className:`size-4`}):(0,Q.jsx)(Ze,{className:`size-4`})})]})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2 sm:shrink-0`,children:[(0,Q.jsxs)(w,{type:`button`,variant:`secondary`,className:`gap-1`,disabled:O||U||!t.trim()||ke(t),onClick:()=>void me(),children:[U?(0,Q.jsx)(Y,{className:`size-4 animate-spin`,"aria-hidden":!0}):null,U?r.testingKey:r.testKey]}),e.supportsOAuth?D?(0,Q.jsxs)(w,{type:`button`,variant:`secondary`,className:`gap-1 text-red-600 dark:text-red-400`,onClick:ce,children:[(0,Q.jsx)(W,{className:`size-4`,"aria-hidden":!0}),r.revoke]}):(0,Q.jsxs)(w,{type:`button`,variant:`secondary`,className:`gap-1`,disabled:O,onClick:()=>void ae(),children:[O?(0,Q.jsx)(Y,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Q.jsx)(ht,{className:`size-4`,"aria-hidden":!0}),r.oauth]}):null,de?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(w,{type:`button`,variant:`secondary`,className:`gap-1 text-red-600 dark:text-red-400`,disabled:v,onClick:()=>C(!0),children:[v?(0,Q.jsx)(Y,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Q.jsx)(Je,{className:`size-4`,"aria-hidden":!0}),r.removeKey]}),(0,Q.jsx)(Qe,{open:S,title:r.removeKey,description:wa(r.removeKeyConfirm,{name:e.name}),confirmLabel:r.removeKey,cancelLabel:r.cancelOAuth,destructive:!0,onConfirm:()=>void le(),onCancel:()=>C(!1)})]}):null]})]}),K?(0,Q.jsx)(`p`,{className:X(`text-xs`,ne===!1?`text-red-600 dark:text-red-400`:`text-fg-muted`),role:`status`,children:K}):null,ie.length>0?(0,Q.jsx)(`div`,{className:`flex flex-col gap-1`,children:ie.map(e=>(0,Q.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:[ee(e.kind,r),(0,Q.jsx)(Ie,{className:`size-3`,"aria-hidden":!0})]},`${e.kind}-${e.href}`))}):null]}),P?(0,Q.jsxs)(`div`,{className:X(`flex gap-2 rounded-md px-3 py-2 text-xs`,M===`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:[M===`error`?(0,Q.jsx)(ot,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}):M===`success`?(0,Q.jsx)(te,{className:`mt-0.5 size-4 shrink-0 text-emerald-600`,"aria-hidden":!0}):(0,Q.jsx)(ge,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Q.jsx)(`span`,{children:P})]}):null,g?(0,Q.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,Q.jsx)(ot,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Q.jsx)(`span`,{children:g})]}):null,b?(0,Q.jsxs)(`div`,{className:X(`flex gap-2 rounded-md px-3 py-2 text-xs`,b===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:[b===r.removeKeySuccess?(0,Q.jsx)(te,{className:`mt-0.5 size-4 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):(0,Q.jsx)(ot,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Q.jsx)(`span`,{children:b})]}):null,(M===`waiting`||M===`waiting_code`)&&(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[I?(0,Q.jsxs)(`a`,{href:I,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,Q.jsx)(Ie,{className:`size-4`,"aria-hidden":!0}),r.openAuthPage]}):null,(0,Q.jsxs)(w,{type:`button`,variant:`secondary`,className:`gap-1`,onClick:()=>void oe(),children:[(0,Q.jsx)(fe,{className:`size-4`,"aria-hidden":!0}),r.cancelOAuth]})]}),z?(0,Q.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,Q.jsx)(ge,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Q.jsx)(`span`,{children:z})]}):null,M===`waiting_code`?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,Q.jsx)(`input`,{type:`text`,className:X(`min-w-0 flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,u,`dark:border-edge`),value:V,placeholder:r.pasteRedirectUrl,onChange:e=>H(e.target.value),onKeyDown:e=>e.key===`Enter`&&void se()}),(0,Q.jsx)(w,{type:`button`,variant:`primary`,className:`shrink-0`,onClick:()=>void se(),children:r.submitCode})]}):null,T?(0,Q.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,Q.jsx)(ge,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Q.jsx)(`span`,{children:re===`env`?r.envHint:r.maskedStoredHint})]}):null,e.supportsOAuth&&!T&&!D?(0,Q.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:r.oauthHint}):null,s?(0,Q.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,Q.jsx)(te,{className:`mt-0.5 size-3.5 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}),(0,Q.jsx)(`span`,{children:(()=>{let t=c.filter(t=>t.provider===e.id);if(t.length===0)return r.savedNoModels;let n=t.slice(0,3).map(e=>e.name||e.id).join(`, `),i=t.length>3?`… (+${t.length-3})`:``;return`${t.length} ${r.savedModelsAvailable}: ${n}${i}`})()})]}):null,(xe[e.id]?.envVars??[]).length>0?(0,Q.jsxs)(`details`,{children:[(0,Q.jsx)(`summary`,{className:`cursor-pointer select-none list-none text-xs text-fg-subtle hover:text-fg-muted`,children:r.envVarAlt}),(0,Q.jsx)(`div`,{className:`mt-1.5 flex flex-col gap-1`,children:(xe[e.id]?.envVars??[]).map(e=>(0,Q.jsx)(Ea,{envVar:e,labels:r},e))})]}):null]}):null]})}function Oa(){let e=F(e=>e.language),t=oe(e),n=t.providersSettings,r=!!R(e=>e.token),[i,o]=(0,$.useState)({}),[s,c]=(0,$.useState)({}),[l,d]=(0,$.useState)(!1),[f,m]=(0,$.useState)(null),[h,g]=(0,$.useState)(null),[_,y]=(0,$.useState)(()=>new Set([`common`])),[b,x]=(0,$.useState)(``),[S,C]=(0,$.useState)(!1),[T,E]=(0,$.useState)(()=>new Set),D=(0,$.useRef)(``),O=lt(`/api/providers/meta`),k=(0,$.useCallback)(async e=>(await v(e)).payload?.providers??[],[]),{data:A,error:j,isLoading:M,mutate:N}=I(r),{data:P,error:z,isLoading:B,mutate:V}=a(r?O:null,k,{revalidateOnFocus:!1}),{data:H,mutate:U}=a(r?p:null,()=>at(),{revalidateOnFocus:!1}),W=(0,$.useMemo)(()=>!P||A===void 0?null:De(P,nt(A.payload?.config),H??[]),[P,A,H]),G=j instanceof Error?j.message:j?String(j):z instanceof Error?z.message:z?String(z):null,ee=!!(r&&W===null&&(M||B)&&!G),K=(0,$.useMemo)(()=>JSON.stringify(i)!==JSON.stringify(s),[i,s]);(0,$.useEffect)(()=>{if(!K)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[K]),(0,$.useEffect)(()=>{if(!(!r||W===null)&&!K){let e={};for(let t of W)e[t.id]=t.apiKey;o(e),c({...e})}},[r,W,K]);let q=W??[],ne=(0,$.useMemo)(()=>{let e=q,t=b.trim().toLowerCase();return t&&(e=e.filter(e=>{let n=xe[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},[q,b,S]),J=(0,$.useMemo)(()=>Ca(ne),[ne]);(0,$.useEffect)(()=>{let e=D.current;if(D.current=b,b.trim()){let e=new Set;for(let t of Sa)(J.get(t)??[]).length>0&&e.add(t);y(e);return}e.trim()&&y(new Set([`common`]))},[b,J]);let re=(0,$.useCallback)(async()=>{if(l)return;let e={};for(let t of Object.keys(i)){let n=i[t]?.trim()??``;!n||ke(n)||(e[t]=n)}if(Object.keys(e).length===0){c({...i}),g(`noChanges`),window.setTimeout(()=>g(null),2500);return}d(!0),m(null),g(null);try{await _e(e),E(new Set(Object.keys(e)));let t=await U(at(!0))??H??[],[n,r]=await Promise.all([N(),V()]),i=Array.isArray(r)?r:P??[],a=n??A;if(a?.payload){let e=De(i,nt(a.payload.config),t),n={};for(let t of e)n[t.id]=t.apiKey;o(n),c({...n})}g(`saved`),window.setTimeout(()=>g(null),2500)}catch(e){m(e instanceof Error?e.message:n.saveError)}finally{d(!1)}},[A,i,P,H,N,V,U,n.saveError,l]),ie=(0,$.useCallback)(()=>{o({...s}),m(null),g(null),E(new Set)},[s]),ae=e=>{y(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Y=(0,$.useCallback)(()=>{N(),V()},[N,V]),se=!!(b.trim()||S);return r?ee?(0,Q.jsxs)(`div`,{className:`mx-auto w-full max-w-app-main px-4 py-8`,children:[(0,Q.jsx)(`div`,{className:`h-8 w-48 animate-pulse rounded bg-surface-hover`}),(0,Q.jsx)(`div`,{className:`mt-6 h-32 animate-pulse rounded-xl bg-surface-hover`}),(0,Q.jsx)(`p`,{className:`mt-4 text-sm text-fg-muted`,children:t.logs.loading})]}):q.length===0?(0,Q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-10`,children:[(0,Q.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-base px-4 py-3`,children:[(0,Q.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:n.loadError}),(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:f??G??n.empty})]}),(0,Q.jsx)(w,{type:`button`,variant:`secondary`,onClick:()=>{N(),V()},children:t.logs.refresh})]}):(0,Q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Q.jsxs)(`header`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.providers}),(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,Q.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:n.rotateHint})]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[h===`saved`?(0,Q.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,h===`noChanges`?(0,Q.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.noChangesSaved}):null,(0,Q.jsx)(w,{type:`button`,variant:`secondary`,disabled:!K||l,onClick:ie,children:n.discard}),(0,Q.jsx)(w,{type:`button`,variant:`primary`,disabled:!K||l,onClick:()=>void re(),children:l?n.saving:n.save})]})]}),K?(0,Q.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,(0,Q.jsxs)(`p`,{className:`text-sm leading-relaxed text-fg-muted`,children:[n.intro,` `,(0,Q.jsx)(`a`,{href:Ne(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,Q.jsx)(pt,{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,Q.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-center`,children:[(0,Q.jsxs)(`div`,{className:`relative min-w-0 flex-1 sm:max-w-md`,children:[(0,Q.jsx)(it,{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,Q.jsx)(`input`,{type:`search`,value:b,onChange:e=>x(e.target.value),placeholder:n.searchPlaceholder,autoComplete:`off`,className:X(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-10 pr-3 text-sm text-fg placeholder:text-fg-subtle`,u,`dark:border-edge`),"aria-label":n.searchPlaceholder})]}),(0,Q.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg-muted`,children:[(0,Q.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]}),se?(0,Q.jsx)(w,{type:`button`,variant:`ghost`,className:`h-9 w-fit self-start text-fg-muted`,onClick:()=>{x(``),C(!1)},children:n.clearFilters}):null]}),f?(0,Q.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,ne.length===0?(0,Q.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,Q.jsx)(`p`,{children:n.noMatches}),(0,Q.jsx)(w,{type:`button`,variant:`secondary`,className:`mt-4`,onClick:()=>{x(``),C(!1)},children:n.clearFilters})]}):(0,Q.jsx)(`div`,{className:`flex flex-col gap-3`,children:Sa.map(t=>{let r=J.get(t)??[];if(r.length===0)return null;let a=_.has(t),c=r.filter(e=>e.configured).length,l=`providers-cat-${t}`;return(0,Q.jsxs)(`section`,{className:`overflow-hidden rounded-2xl bg-surface-base`,children:[(0,Q.jsxs)(`button`,{type:`button`,id:`${l}-trigger`,"aria-expanded":a,"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:()=>ae(t),children:[(0,Q.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Q.jsx)(`span`,{className:`truncate`,children:n.categories[t]}),(0,Q.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,Q.jsxs)(`span`,{className:`flex shrink-0 items-center gap-2`,children:[c>0?(0,Q.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-fg-subtle`,children:[(0,Q.jsx)(te,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}),wa(n.configuredCount,{count:String(c)})]}):null,(0,Q.jsx)(L,{className:X(`size-4 text-fg-subtle transition-transform`,a&&`rotate-180`),"aria-hidden":!0})]})]}),a?(0,Q.jsx)(`div`,{id:l,role:`region`,"aria-labelledby":`${l}-trigger`,className:`divide-y divide-edge-subtle`,children:r.map(t=>(0,Q.jsx)(`div`,{id:`provider-row-${t.id}`,children:(0,Q.jsx)(Da,{row:t,value:i[t.id]??``,rowDirty:(i[t.id]??``)!==(s[t.id]??``),labels:n,language:e,onChange:(e,t)=>o(n=>({...n,[e]:t})),onReload:Y,justSaved:T.has(t.id),availableModels:H??[]})},t.id))}):null]},t)})})]}):(0,Q.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-10`,children:(0,Q.jsxs)(`div`,{className:`flex items-start gap-3 rounded-2xl bg-surface-base p-6`,children:[(0,Q.jsx)(ue,{className:`mt-0.5 size-5 shrink-0 text-fg-subtle`,strokeWidth:1.75}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h1`,{className:`text-base font-semibold text-fg`,children:t.settingsSections.providers}),(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.needToken})]})]})})}var ka=[{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 Aa(e,t){let n=oe(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 ja(){let e=(0,Z.c)(105),t=F(Ma),n;e[0]===t?n=e[1]:(n=oe(t),e[0]=t,e[1]=n);let r=n.systemSettings,[i,a]=(0,$.useState)(null),[o,s]=(0,$.useState)(null),[c,l]=(0,$.useState)(null),u=typeof window<`u`?window.electronAPI?.system:void 0,d;e[2]===Symbol.for(`react.memo_cache_sentinel`)?(d=async()=>{if(u){l(null);try{a(await u.getBehavior()),s(await u.getPermissions())}catch(e){let t=e;l(t instanceof Error?t.message:String(t))}}},e[2]=d):d=e[2];let f=d,p,m;if(e[3]===Symbol.for(`react.memo_cache_sentinel`)?(p=()=>{S()&&u&&f()},m=[u,f],e[3]=p,e[4]=m):(p=e[3],m=e[4]),(0,$.useEffect)(p,m),!S()||!u){let t;e[5]===r.title?t=e[6]:(t=(0,Q.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:r.title}),e[5]=r.title,e[6]=t);let n;e[7]===Symbol.for(`react.memo_cache_sentinel`)?(n=Gt(),e[7]=n):n=e[7];let i;e[8]===r.desktopOnlyTitle?i=e[9]:(i=(0,Q.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:r.desktopOnlyTitle}),e[8]=r.desktopOnlyTitle,e[9]=i);let a;e[10]===r.desktopOnlyBody?a=e[11]:(a=(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:r.desktopOnlyBody}),e[10]=r.desktopOnlyBody,e[11]=a);let o;e[12]!==i||e[13]!==a?(o=(0,Q.jsxs)(`div`,{className:n,children:[i,a]}),e[12]=i,e[13]=a,e[14]=o):o=e[14];let s;return e[15]!==t||e[16]!==o?(s=(0,Q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[t,o]}),e[15]=t,e[16]=o,e[17]=s):s=e[17],s}let h;e[18]===Symbol.for(`react.memo_cache_sentinel`)?(h=async e=>{try{let{behavior:t}=await u.setBehavior(e);a(t)}catch(e){let t=e;l(t instanceof Error?t.message:String(t))}},e[18]=h):h=e[18];let g=h,_;e[19]===Symbol.for(`react.memo_cache_sentinel`)?(_=async e=>{try{(await u.openPrivacy(e)).ok||l(`open_privacy failed`)}catch(e){let t=e;l(t instanceof Error?t.message:String(t))}},e[19]=_):_=e[19];let v=_,y;bb0:{if(!i){y=r.permissionsHint;break bb0}if(i.platform===`win32`){y=r.permissionsHintWin;break bb0}if(i.platform===`linux`){y=r.permissionsHintLinux;break bb0}if(i.platform===`darwin`){y=r.permissionsHintDarwin;break bb0}y=r.permissionsHint}let b=y,x;e[20]===r.title?x=e[21]:(x=(0,Q.jsx)(`div`,{children:(0,Q.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:r.title})}),e[20]=r.title,e[21]=x);let C;e[22]===c?C=e[23]:(C=c?(0,Q.jsx)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:c}):null,e[22]=c,e[23]=C);let w;e[24]===Symbol.for(`react.memo_cache_sentinel`)?(w=(0,Q.jsx)(Ke,{className:`size-4 text-accent`,strokeWidth:1.75}),e[24]=w):w=e[24];let T;e[25]===r.behaviorGroup?T=e[26]:(T=(0,Q.jsxs)(`div`,{className:`mb-4 flex items-center gap-2 text-sm font-semibold text-fg`,children:[w,r.behaviorGroup]}),e[25]=r.behaviorGroup,e[26]=T);let E;e[27]===r.toggles.openAtLogin?E=e[28]:(E=(0,Q.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:r.toggles.openAtLogin}),e[27]=r.toggles.openAtLogin,e[28]=E);let D;e[29]===r.toggles.openAtLoginDesc?D=e[30]:(D=(0,Q.jsx)(`p`,{className:`text-xs text-fg-muted`,children:r.toggles.openAtLoginDesc}),e[29]=r.toggles.openAtLoginDesc,e[30]=D);let O;e[31]!==E||e[32]!==D?(O=(0,Q.jsxs)(`div`,{children:[E,D]}),e[31]=E,e[32]=D,e[33]=O):O=e[33];let k=!i,A=!!i?.openAtLogin,j;e[34]===Symbol.for(`react.memo_cache_sentinel`)?(j=e=>{g({openAtLogin:e.target.checked})},e[34]=j):j=e[34];let M;e[35]!==k||e[36]!==A?(M=(0,Q.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:k,checked:A,onChange:j}),e[35]=k,e[36]=A,e[37]=M):M=e[37];let N;e[38]!==O||e[39]!==M?(N=(0,Q.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:[O,M]}),e[38]=O,e[39]=M,e[40]=N):N=e[40];let P;e[41]===r.toggles.keepAwake?P=e[42]:(P=(0,Q.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:r.toggles.keepAwake}),e[41]=r.toggles.keepAwake,e[42]=P);let I;e[43]===r.toggles.keepAwakeDesc?I=e[44]:(I=(0,Q.jsx)(`p`,{className:`text-xs text-fg-muted`,children:r.toggles.keepAwakeDesc}),e[43]=r.toggles.keepAwakeDesc,e[44]=I);let L;e[45]!==P||e[46]!==I?(L=(0,Q.jsxs)(`div`,{children:[P,I]}),e[45]=P,e[46]=I,e[47]=L):L=e[47];let R=!i,z=!!i?.keepAwakePreferred,B;e[48]===Symbol.for(`react.memo_cache_sentinel`)?(B=e=>{g({keepAwakePreferred:e.target.checked})},e[48]=B):B=e[48];let V;e[49]!==R||e[50]!==z?(V=(0,Q.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:R,checked:z,onChange:B}),e[49]=R,e[50]=z,e[51]=V):V=e[51];let H;e[52]!==L||e[53]!==V?(H=(0,Q.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:[L,V]}),e[52]=L,e[53]=V,e[54]=H):H=e[54];let U;e[55]===r.toggles.notifyDesktop?U=e[56]:(U=(0,Q.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:r.toggles.notifyDesktop}),e[55]=r.toggles.notifyDesktop,e[56]=U);let W;e[57]===r.toggles.notifyDesktopDesc?W=e[58]:(W=(0,Q.jsx)(`p`,{className:`text-xs text-fg-muted`,children:r.toggles.notifyDesktopDesc}),e[57]=r.toggles.notifyDesktopDesc,e[58]=W);let G;e[59]!==U||e[60]!==W?(G=(0,Q.jsxs)(`div`,{children:[U,W]}),e[59]=U,e[60]=W,e[61]=G):G=e[61];let ee=!i,te=!!i?.notifyEnabled,K;e[62]===Symbol.for(`react.memo_cache_sentinel`)?(K=e=>{g({notifyEnabled:e.target.checked})},e[62]=K):K=e[62];let q;e[63]!==ee||e[64]!==te?(q=(0,Q.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:ee,checked:te,onChange:K}),e[63]=ee,e[64]=te,e[65]=q):q=e[65];let ne;e[66]!==G||e[67]!==q?(ne=(0,Q.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:[G,q]}),e[66]=G,e[67]=q,e[68]=ne):ne=e[68];let J;e[69]===r.toggles.notifySound?J=e[70]:(J=(0,Q.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:r.toggles.notifySound}),e[69]=r.toggles.notifySound,e[70]=J);let re;e[71]===r.toggles.notifySoundDesc?re=e[72]:(re=(0,Q.jsx)(`p`,{className:`text-xs text-fg-muted`,children:r.toggles.notifySoundDesc}),e[71]=r.toggles.notifySoundDesc,e[72]=re);let ie;e[73]!==J||e[74]!==re?(ie=(0,Q.jsxs)(`div`,{children:[J,re]}),e[73]=J,e[74]=re,e[75]=ie):ie=e[75];let ae=!i,Y=!!i?.notifySoundEnabled,se;e[76]===Symbol.for(`react.memo_cache_sentinel`)?(se=e=>{g({notifySoundEnabled:e.target.checked})},e[76]=se):se=e[76];let ce;e[77]!==ae||e[78]!==Y?(ce=(0,Q.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:ae,checked:Y,onChange:se}),e[77]=ae,e[78]=Y,e[79]=ce):ce=e[79];let le;e[80]!==ie||e[81]!==ce?(le=(0,Q.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:[ie,ce]}),e[80]=ie,e[81]=ce,e[82]=le):le=e[82];let ue;e[83]!==N||e[84]!==H||e[85]!==ne||e[86]!==le?(ue=(0,Q.jsxs)(`div`,{className:`space-y-2`,children:[N,H,ne,le]}),e[83]=N,e[84]=H,e[85]=ne,e[86]=le,e[87]=ue):ue=e[87];let de;e[88]!==T||e[89]!==ue?(de=(0,Q.jsxs)(Kt,{children:[T,ue]}),e[88]=T,e[89]=ue,e[90]=de):de=e[90];let fe;e[91]!==i||e[92]!==t||e[93]!==b||e[94]!==o||e[95]!==r.openSettings||e[96]!==r.perm||e[97]!==r.permissionsTitle||e[98]!==r.refresh?(fe=i&&o?(0,Q.jsxs)(`section`,{className:Gt(),children:[(0,Q.jsxs)(`div`,{className:`mb-4 flex flex-col gap-1 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:r.permissionsTitle}),(0,Q.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:b})]}),(0,Q.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 f(),children:r.refresh})]}),(0,Q.jsx)(`ul`,{className:`space-y-3`,children:ka.map(e=>{let{key:n,pane:a}=e,c=Aa(t,o[n]),d=r.perm[n];return d?(0,Q.jsxs)(`li`,{className:`flex flex-col gap-2 rounded-xl border border-edge-subtle bg-surface-panel/60 p-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:d.title}),(0,Q.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:d.desc}),(0,Q.jsx)(`p`,{className:`mt-1 text-xs font-medium ${c.className}`,children:c.label})]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[n===`microphone`&&i?.platform===`darwin`?(0,Q.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 u.requestMicrophone(),s(await u.getPermissions())}catch(e){let t=e;l(t instanceof Error?t.message:String(t))}})()},children:t===`zh`?`请求访问`:`Request`}):null,(0,Q.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 v(a),children:[r.openSettings,(0,Q.jsx)(Ie,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0})]})]})]},n):null})})]}):null,e[91]=i,e[92]=t,e[93]=b,e[94]=o,e[95]=r.openSettings,e[96]=r.perm,e[97]=r.permissionsTitle,e[98]=r.refresh,e[99]=fe):fe=e[99];let pe;return e[100]!==de||e[101]!==fe||e[102]!==x||e[103]!==C?(pe=(0,Q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[x,C,de,fe]}),e[100]=de,e[101]=fe,e[102]=x,e[103]=C,e[104]=pe):pe=e[104],pe}function Ma(e){return e.language}function Na(){return{enabled:!1,provider:`alibaba`,alibaba:{model:`paraformer-v2`},openai:{model:`whisper-1`},fallback:{enabled:!0,order:[`alibaba`,`openai`]}}}function Pa(){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 Fa(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Ia(e){let t=Na();if(!Fa(e))return t;let n=e.provider===`openai`?`openai`:`alibaba`,r=Fa(e.alibaba)?{...t.alibaba,...e.alibaba}:t.alibaba,i=Fa(e.openai)?{...t.openai,...e.openai}:t.openai,a=t.fallback??{enabled:!0,order:[`alibaba`,`openai`]};if(Fa(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 La(e){return typeof e==`string`&&e.trim().length>0?e.trim():`openai`}function Ra(e){let t=Pa();if(!Fa(e))return t;let n=La(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:Fa(e.alibaba)?{...t.alibaba,...e.alibaba}:t.alibaba,openai:Fa(e.openai)?{...t.openai,...e.openai}:t.openai,edge:Fa(e.edge)?{...t.edge,...e.edge}:t.edge,minimax:Fa(e.minimax)?{...t.minimax,...e.minimax}:t.minimax,"tts-local-cli":Fa(i)?{...t[`tts-local-cli`],...i}:t[`tts-local-cli`]}}function za(e){let t=Fa(e)?e:{};return{stt:Ia(t.stt),tts:Ra(t.tts)}}async function Ba(e){await v(lt(`/api/config`),{method:`PATCH`,body:JSON.stringify({stt:e.stt,tts:e.tts})}),P()}async function Va(){let e=await v(lt(`/api/voice/models`));if(!e.payload?.models)throw Error(`Missing voice models payload`);return e.payload.models}function Ha(){return X(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,u,`dark:border-edge`)}function Ua(){return X(mt,A)}var Wa=[{id:`paraformer-v2`,name:`Paraformer v2`},{id:`paraformer-v1`,name:`Paraformer v1`}],Ga=[{id:`whisper-1`,name:`Whisper-1`}],Ka=[{id:`tts-1`,name:`TTS-1`},{id:`tts-1-hd`,name:`TTS-1 HD`}],qa=[{id:`alloy`,name:`Alloy`},{id:`echo`,name:`Echo`}],Ja=[{id:`qwen-tts`,name:`Qwen TTS`},{id:`qwen3-tts-flash`,name:`Qwen3 TTS Flash`}],Ya=[{id:`Cherry`,name:`Cherry`},{id:`longxiaochun`,name:`Long Xiao Chun`}],Xa=[{id:`en-US-MichelleNeural`,name:`Michelle (US English)`},{id:`zh-CN-XiaoxiaoNeural`,name:`Xiaoxiao (Chinese)`}],Za=[{id:`speech-2.8-hd`,name:`Speech 2.8 HD (Recommended)`},{id:`speech-2.8-turbo`,name:`Speech 2.8 Turbo (Fast)`}],Qa=[{id:`male-qn-qingse`,name:`Male Qingse (青涩男声)`},{id:`female-shaonv`,name:`Female Shaonv (少女音)`}];function $a(){let e=F(e=>e.language),t=oe(e),n=t.voiceSettings,r=!!R(e=>e.token),[i,o]=(0,$.useState)(null),[s,c]=(0,$.useState)(null),[l,u]=(0,$.useState)(null),[d,f]=(0,$.useState)(!1),[p,m]=(0,$.useState)(null),[h,g]=(0,$.useState)(!1),{data:_,error:v,isLoading:y,mutate:b}=I(r),{data:x,error:S,isLoading:C,mutate:T}=a(r?lt(`/api/voice/models`):null,Va,{revalidateOnFocus:!1}),E=(0,$.useMemo)(()=>_?.payload?.config===void 0?null:za(_.payload.config),[_]),D=(0,$.useMemo)(()=>!i||!s?!1:JSON.stringify(i)!==JSON.stringify(s),[i,s]);(0,$.useEffect)(()=>{if(!r){o(null),c(null),u(null);return}E===null||x===void 0||D||(o(structuredClone(E)),c(structuredClone(E)),u(x),g(!1))},[r,E,x,D]);let O=!!(r&&(E===null||x===void 0)&&(y||C)),k=v instanceof Error?v.message:v?String(v):S instanceof Error?S.message:S?String(S):null,A=(0,$.useCallback)(e=>{o(t=>t?{...t,stt:{...t.stt,...e}}:null)},[]),j=(0,$.useCallback)(e=>{o(t=>t?{...t,stt:{...t.stt,alibaba:{...t.stt.alibaba,...e}}}:null)},[]),M=(0,$.useCallback)(e=>{o(t=>t?{...t,stt:{...t.stt,openai:{...t.stt.openai,...e}}}:null)},[]),N=(0,$.useCallback)(e=>{o(t=>{if(!t)return null;let n=t.stt.fallback??{enabled:!0,order:[`alibaba`,`openai`]};return{...t,stt:{...t.stt,fallback:{...n,...e}}}})},[]),P=(0,$.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,...e}}:null)},[]),L=(0,$.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,alibaba:{...t.tts.alibaba,...e}}}:null)},[]),z=(0,$.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,openai:{...t.tts.openai,...e}}}:null)},[]),B=(0,$.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,edge:{...t.tts.edge,...e}}}:null)},[]),V=(0,$.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,minimax:{...t.tts.minimax,...e}}}:null)},[]),H=(0,$.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,"tts-local-cli":{...t.tts[`tts-local-cli`],...e}}}:null)},[]),U=(0,$.useCallback)(async()=>{if(!(!i||d)){f(!0),m(null),g(!1);try{await Ba(i);let e=structuredClone(i);c(e),o(e),g(!0),window.setTimeout(()=>g(!1),2500)}catch(e){m(e instanceof Error?e.message:n.saveError)}finally{f(!1)}}},[i,d,n.saveError]),W=(0,$.useCallback)(()=>{s&&(o(structuredClone(s)),m(null),g(!1))},[s]);if(!r)return(0,Q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Q.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.voice}),(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]});if(O)return(0,Q.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,Q.jsx)(Y,{className:`size-4 animate-spin`}),n.loading]})});if(!i||l===null)return(0,Q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:p??k??n.loadError}),(0,Q.jsx)(w,{type:`button`,variant:`secondary`,onClick:()=>{b(),T()},children:n.retry})]});let G=i.stt,ee=i.tts;return(0,Q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Q.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.voice}),(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,Q.jsxs)(`a`,{href:Ne(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,Q.jsx)(Ie,{className:`size-3.5`})]})]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[h?(0,Q.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,Q.jsx)(w,{type:`button`,variant:`secondary`,disabled:!D||d,onClick:W,children:n.discard}),(0,Q.jsx)(w,{type:`button`,variant:`primary`,disabled:!D||d,onClick:()=>void U(),children:d?n.saving:n.save})]})]}),D?(0,Q.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,p?(0,Q.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:p}):null,(0,Q.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Q.jsx)(eo,{v:n,stt:G,models:l,updateStt:A,updateSttAlibaba:j,updateSttOpenai:M,updateSttFallback:N}),(0,Q.jsx)(ro,{v:n,tts:ee,models:l,updateTts:P,updateTtsAlibaba:L,updateTtsOpenai:z,updateTtsEdge:B,updateTtsMinimax:V,updateTtsLocalCli:H})]}),(0,Q.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,Q.jsxs)(`p`,{className:`text-sm text-fg`,children:[(0,Q.jsx)(`strong`,{className:`text-accent`,children:n.notes.title}),` `,n.notes.duration]}),(0,Q.jsx)(`p`,{className:`mt-2 text-xs text-fg-muted`,children:n.notes.envVars})]})]})}function eo(e){let t=(0,Z.c)(51),{v:n,stt:r,models:i,updateStt:a,updateSttAlibaba:o,updateSttOpenai:s,updateSttFallback:c}=e,l=i?.stt?.alibaba?.length?i.stt.alibaba:Wa,u=i?.stt?.openai?.length?i.stt.openai:Ga,d;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(d=(0,Q.jsx)(x,{className:`size-4 text-accent`,strokeWidth:1.75}),t[0]=d):d=t[0];let f;t[1]===n.stt.title?f=t[2]:(f=(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[d,n.stt.title]}),t[1]=n.stt.title,t[2]=f);let p;t[3]===n.stt.description?p=t[4]:(p=(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:n.stt.description}),t[3]=n.stt.description,t[4]=p);let m;t[5]!==f||t[6]!==p?(m=(0,Q.jsxs)(`div`,{className:`mb-4`,children:[f,p]}),t[5]=f,t[6]=p,t[7]=m):m=t[7];let h;t[8]===n.stt.enable?h=t[9]:(h=(0,Q.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.stt.enable}),t[8]=n.stt.enable,t[9]=h);let g;t[10]===n.stt.enableDesc?g=t[11]:(g=(0,Q.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.stt.enableDesc}),t[10]=n.stt.enableDesc,t[11]=g);let _;t[12]!==h||t[13]!==g?(_=(0,Q.jsxs)(`div`,{children:[h,g]}),t[12]=h,t[13]=g,t[14]=_):_=t[14];let v;t[15]===a?v=t[16]:(v=e=>a({enabled:e.target.checked}),t[15]=a,t[16]=v);let y;t[17]!==r.enabled||t[18]!==v?(y=(0,Q.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:r.enabled,onChange:v}),t[17]=r.enabled,t[18]=v,t[19]=y):y=t[19];let b;t[20]!==_||t[21]!==y?(b=(0,Q.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:[_,y]}),t[20]=_,t[21]=y,t[22]=b):b=t[22];let S;t[23]!==l||t[24]!==u||t[25]!==r.alibaba?.apiKey||t[26]!==r.alibaba?.model||t[27]!==r.enabled||t[28]!==r.fallback?.enabled||t[29]!==r.openai?.apiKey||t[30]!==r.openai?.model||t[31]!==r.provider||t[32]!==a||t[33]!==o||t[34]!==c||t[35]!==s||t[36]!==n.stt.alibaba||t[37]!==n.stt.apiKey||t[38]!==n.stt.apiKeyDesc||t[39]!==n.stt.fallback||t[40]!==n.stt.fallbackDesc||t[41]!==n.stt.model||t[42]!==n.stt.openai||t[43]!==n.stt.provider?(S=r.enabled?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(fo,{children:n.stt.provider}),(0,Q.jsxs)(`select`,{className:Ua(),value:r.provider,onChange:e=>a({provider:e.target.value}),children:[(0,Q.jsx)(`option`,{value:`alibaba`,children:n.stt.alibaba}),(0,Q.jsx)(`option`,{value:`openai`,children:n.stt.openai})]})]})}),r.provider===`alibaba`?(0,Q.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(fo,{children:n.stt.apiKey}),(0,Q.jsx)(`input`,{className:X(Ha(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:r.alibaba?.apiKey??``,onChange:e=>o({apiKey:e.target.value}),placeholder:`sk-...`}),(0,Q.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.stt.apiKeyDesc,` (DASHSCOPE_API_KEY)`]})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(fo,{children:n.stt.model}),(0,Q.jsx)(`select`,{className:Ua(),value:r.alibaba?.model??``,onChange:e=>o({model:e.target.value}),children:l.map(no)})]})]}):(0,Q.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(fo,{children:n.stt.apiKey}),(0,Q.jsx)(`input`,{className:X(Ha(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:r.openai?.apiKey??``,onChange:e=>s({apiKey:e.target.value}),placeholder:`sk-...`}),(0,Q.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.stt.apiKeyDesc,` (OPENAI_API_KEY)`]})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(fo,{children:n.stt.model}),(0,Q.jsx)(`select`,{className:Ua(),value:r.openai?.model??``,onChange:e=>s({model:e.target.value}),children:u.map(to)})]})]}),(0,Q.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,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.stt.fallback}),(0,Q.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.stt.fallbackDesc})]}),(0,Q.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:r.fallback?.enabled??!0,onChange:e=>c({enabled:e.target.checked})})]})]}):null,t[23]=l,t[24]=u,t[25]=r.alibaba?.apiKey,t[26]=r.alibaba?.model,t[27]=r.enabled,t[28]=r.fallback?.enabled,t[29]=r.openai?.apiKey,t[30]=r.openai?.model,t[31]=r.provider,t[32]=a,t[33]=o,t[34]=c,t[35]=s,t[36]=n.stt.alibaba,t[37]=n.stt.apiKey,t[38]=n.stt.apiKeyDesc,t[39]=n.stt.fallback,t[40]=n.stt.fallbackDesc,t[41]=n.stt.model,t[42]=n.stt.openai,t[43]=n.stt.provider,t[44]=S):S=t[44];let C;t[45]!==b||t[46]!==S?(C=(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[b,S]}),t[45]=b,t[46]=S,t[47]=C):C=t[47];let w;return t[48]!==C||t[49]!==m?(w=(0,Q.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[m,C]}),t[48]=C,t[49]=m,t[50]=w):w=t[50],w}function to(e){return(0,Q.jsx)(`option`,{value:e.id,children:e.name},e.id)}function no(e){return(0,Q.jsx)(`option`,{value:e.id,children:e.name},e.id)}function ro(e){let t=(0,Z.c)(63),{v:n,tts:r,models:i,updateTts:a,updateTtsAlibaba:o,updateTtsOpenai:s,updateTtsEdge:c,updateTtsMinimax:l,updateTtsLocalCli:u}=e,d;t[0]!==n.tts.triggerDescAlways||t[1]!==n.tts.triggerDescInbound||t[2]!==n.tts.triggerDescOff||t[3]!==n.tts.triggerDescTagged?(d=e=>e===`off`?n.tts.triggerDescOff:e===`always`?n.tts.triggerDescAlways:e===`inbound`?n.tts.triggerDescInbound:e===`tagged`?n.tts.triggerDescTagged:``,t[0]=n.tts.triggerDescAlways,t[1]=n.tts.triggerDescInbound,t[2]=n.tts.triggerDescOff,t[3]=n.tts.triggerDescTagged,t[4]=d):d=t[4];let f=d,p=i?.tts?.openai?.length?i.tts.openai:Ka,m=i?.ttsVoices?.openai?.length?i.ttsVoices.openai:qa,h=i?.tts?.alibaba?.length?i.tts.alibaba:Ja,g=i?.ttsVoices?.alibaba?.length?i.ttsVoices.alibaba:Ya,_=i?.ttsVoices?.edge?.length?i.ttsVoices.edge:Xa,v=i?.tts?.minimax?.length?i.tts.minimax:Za,y=i?.ttsVoices?.minimax?.length?i.ttsVoices.minimax:Qa,b;t[5]===Symbol.for(`react.memo_cache_sentinel`)?(b=(0,Q.jsx)(he,{className:`size-4 text-accent`,strokeWidth:1.75}),t[5]=b):b=t[5];let x;t[6]===n.tts.title?x=t[7]:(x=(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[b,n.tts.title]}),t[6]=n.tts.title,t[7]=x);let S;t[8]===n.tts.description?S=t[9]:(S=(0,Q.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:n.tts.description}),t[8]=n.tts.description,t[9]=S);let C;t[10]!==x||t[11]!==S?(C=(0,Q.jsxs)(`div`,{className:`mb-4`,children:[x,S]}),t[10]=x,t[11]=S,t[12]=C):C=t[12];let w;t[13]===n.tts.enable?w=t[14]:(w=(0,Q.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.tts.enable}),t[13]=n.tts.enable,t[14]=w);let T;t[15]===n.tts.enableDesc?T=t[16]:(T=(0,Q.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.tts.enableDesc}),t[15]=n.tts.enableDesc,t[16]=T);let E;t[17]!==w||t[18]!==T?(E=(0,Q.jsxs)(`div`,{children:[w,T]}),t[17]=w,t[18]=T,t[19]=E):E=t[19];let D;t[20]===a?D=t[21]:(D=e=>a({enabled:e.target.checked}),t[20]=a,t[21]=D);let O;t[22]!==D||t[23]!==r.enabled?(O=(0,Q.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:r.enabled,onChange:D}),t[22]=D,t[23]=r.enabled,t[24]=O):O=t[24];let k;t[25]!==O||t[26]!==E?(k=(0,Q.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:[E,O]}),t[25]=O,t[26]=E,t[27]=k):k=t[27];let A;t[28]!==f||t[29]!==r||t[30]!==h||t[31]!==v||t[32]!==p||t[33]!==g||t[34]!==_||t[35]!==y||t[36]!==m||t[37]!==a||t[38]!==o||t[39]!==c||t[40]!==u||t[41]!==l||t[42]!==s||t[43]!==n.stt||t[44]!==n.tts.edgeHint||t[45]!==n.tts.localCli||t[46]!==n.tts.provider||t[47]!==n.tts.providerEdge||t[48]!==n.tts.providerLocalCli||t[49]!==n.tts.providerOpenai||t[50]!==n.tts.trigger||t[51]!==n.tts.triggerAlways||t[52]!==n.tts.triggerInbound||t[53]!==n.tts.triggerOff||t[54]!==n.tts.triggerTagged||t[55]!==n.tts.voice?(A=r.enabled?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(fo,{children:n.tts.trigger}),(0,Q.jsxs)(`select`,{className:Ua(),value:r.trigger,onChange:e=>a({trigger:e.target.value}),children:[(0,Q.jsx)(`option`,{value:`off`,children:n.tts.triggerOff}),(0,Q.jsx)(`option`,{value:`always`,children:n.tts.triggerAlways}),(0,Q.jsx)(`option`,{value:`inbound`,children:n.tts.triggerInbound}),(0,Q.jsx)(`option`,{value:`tagged`,children:n.tts.triggerTagged})]}),(0,Q.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:f(r.trigger)})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(fo,{children:n.tts.provider}),(0,Q.jsxs)(`select`,{className:Ua(),value:r.provider,onChange:e=>a({provider:e.target.value}),children:[(0,Q.jsx)(`option`,{value:`openai`,children:n.tts.providerOpenai}),(0,Q.jsx)(`option`,{value:`alibaba`,children:n.stt.alibaba}),(0,Q.jsx)(`option`,{value:`minimax`,children:`MiniMax`}),(0,Q.jsx)(`option`,{value:`edge`,children:n.tts.providerEdge}),(0,Q.jsx)(`option`,{value:`tts-local-cli`,children:n.tts.providerLocalCli})]})]})]}),r.provider===`openai`?(0,Q.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,Q.jsx)(fo,{children:n.stt.apiKey}),(0,Q.jsx)(`input`,{className:X(Ha(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:r.openai?.apiKey??``,onChange:e=>s({apiKey:e.target.value}),placeholder:`sk-...`}),(0,Q.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.stt.apiKeyDesc,` (OPENAI_API_KEY)`]})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(fo,{children:n.stt.model}),(0,Q.jsx)(`select`,{className:Ua(),value:r.openai?.model??``,onChange:e=>s({model:e.target.value}),children:p.map(uo)})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(fo,{children:n.tts.voice}),(0,Q.jsx)(`select`,{className:Ua(),value:r.openai?.voice??``,onChange:e=>s({voice:e.target.value}),children:m.map(lo)})]})]}):null,r.provider===`alibaba`?(0,Q.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,Q.jsx)(fo,{children:n.stt.apiKey}),(0,Q.jsx)(`input`,{className:X(Ha(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:r.alibaba?.apiKey??``,onChange:e=>o({apiKey:e.target.value}),placeholder:`sk-...`}),(0,Q.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.stt.apiKeyDesc,` (DASHSCOPE_API_KEY)`]})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(fo,{children:n.stt.model}),(0,Q.jsx)(`select`,{className:Ua(),value:r.alibaba?.model??``,onChange:e=>o({model:e.target.value}),children:h.map(co)})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(fo,{children:n.tts.voice}),(0,Q.jsx)(`select`,{className:Ua(),value:r.alibaba?.voice??``,onChange:e=>o({voice:e.target.value}),children:g.map(so)})]})]}):null,r.provider===`minimax`?(0,Q.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,Q.jsx)(fo,{children:n.stt.apiKey}),(0,Q.jsx)(`input`,{className:X(Ha(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:r.minimax?.apiKey??``,onChange:e=>l({apiKey:e.target.value}),placeholder:`eyJ...`}),(0,Q.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.stt.apiKeyDesc,` (MINIMAX_API_KEY)`]})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(fo,{children:n.stt.model}),(0,Q.jsx)(`select`,{className:Ua(),value:r.minimax?.model??``,onChange:e=>l({model:e.target.value}),children:v.map(oo)})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(fo,{children:n.tts.voice}),(0,Q.jsx)(`select`,{className:Ua(),value:r.minimax?.voice??``,onChange:e=>l({voice:e.target.value}),children:y.map(ao)})]})]}):null,r.provider===`edge`?(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(fo,{children:n.tts.voice}),(0,Q.jsx)(`select`,{className:Ua(),value:r.edge?.voice??``,onChange:e=>c({voice:e.target.value}),children:_.map(io)}),(0,Q.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.tts.edgeHint})]}):null,r.provider===`tts-local-cli`?(0,Q.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,Q.jsx)(fo,{children:n.tts.localCli.command}),(0,Q.jsx)(`input`,{className:X(Ha(),`font-mono text-xs`),type:`text`,autoComplete:`off`,spellCheck:!1,value:r[`tts-local-cli`]?.command??``,onChange:e=>u({command:e.target.value}),placeholder:n.tts.localCli.commandPlaceholder}),(0,Q.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.tts.localCli.commandDesc})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(fo,{children:n.tts.localCli.cwd}),(0,Q.jsx)(`input`,{className:X(Ha(),`font-mono text-xs`),type:`text`,autoComplete:`off`,spellCheck:!1,value:r[`tts-local-cli`]?.cwd??``,onChange:e=>u({cwd:e.target.value}),placeholder:`/path/to/cwd`}),(0,Q.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.tts.localCli.cwdDesc})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(fo,{children:n.tts.localCli.outputFormat}),(0,Q.jsxs)(`select`,{className:Ua(),value:r[`tts-local-cli`]?.outputFormat??`wav`,onChange:e=>u({outputFormat:e.target.value}),children:[(0,Q.jsx)(`option`,{value:`wav`,children:`wav`}),(0,Q.jsx)(`option`,{value:`mp3`,children:`mp3`}),(0,Q.jsx)(`option`,{value:`opus`,children:`opus`})]}),(0,Q.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.tts.localCli.outputFormatDesc})]}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,Q.jsx)(fo,{children:n.tts.localCli.timeoutMs}),(0,Q.jsx)(`input`,{className:Ha(),type:`number`,min:0,step:1e3,value:typeof r[`tts-local-cli`]?.timeoutMs==`number`?String(r[`tts-local-cli`].timeoutMs):``,onChange:e=>{let t=e.target.value.trim();if(t===``){u({timeoutMs:void 0});return}let n=Number(t);Number.isFinite(n)&&n>=0&&u({timeoutMs:n})},placeholder:`30000`}),(0,Q.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.tts.localCli.timeoutMsDesc})]}),(0,Q.jsx)(`p`,{className:`text-xs text-fg-subtle sm:col-span-2`,children:n.tts.localCli.hint})]}):null]}):null,t[28]=f,t[29]=r,t[30]=h,t[31]=v,t[32]=p,t[33]=g,t[34]=_,t[35]=y,t[36]=m,t[37]=a,t[38]=o,t[39]=c,t[40]=u,t[41]=l,t[42]=s,t[43]=n.stt,t[44]=n.tts.edgeHint,t[45]=n.tts.localCli,t[46]=n.tts.provider,t[47]=n.tts.providerEdge,t[48]=n.tts.providerLocalCli,t[49]=n.tts.providerOpenai,t[50]=n.tts.trigger,t[51]=n.tts.triggerAlways,t[52]=n.tts.triggerInbound,t[53]=n.tts.triggerOff,t[54]=n.tts.triggerTagged,t[55]=n.tts.voice,t[56]=A):A=t[56];let j;t[57]!==k||t[58]!==A?(j=(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[k,A]}),t[57]=k,t[58]=A,t[59]=j):j=t[59];let M;return t[60]!==j||t[61]!==C?(M=(0,Q.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[C,j]}),t[60]=j,t[61]=C,t[62]=M):M=t[62],M}function io(e){return(0,Q.jsx)(`option`,{value:e.id,children:e.name},e.id)}function ao(e){return(0,Q.jsx)(`option`,{value:e.id,children:e.name},e.id)}function oo(e){return(0,Q.jsx)(`option`,{value:e.id,children:e.name},e.id)}function so(e){return(0,Q.jsx)(`option`,{value:e.id,children:e.name},e.id)}function co(e){return(0,Q.jsx)(`option`,{value:e.id,children:e.name},e.id)}function lo(e){return(0,Q.jsx)(`option`,{value:e.id,children:e.name},e.id)}function uo(e){return(0,Q.jsx)(`option`,{value:e.id,children:e.name},e.id)}function fo(e){let t=(0,Z.c)(2),{children:n}=e,r;return t[0]===n?r=t[1]:(r=(0,Q.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n}),t[0]=n,t[1]=r),r}function po(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 mo(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 v(lt(`/api/config`),{method:`PATCH`,body:JSON.stringify({tools:{web:{region:t,search:n}}})}),P()}function ho(e){let t=(0,Z.c)(8),{label:n,description:r,children:i}=e,a;t[0]===n?a=t[1]:(a=(0,Q.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n}),t[0]=n,t[1]=a);let o;t[2]===r?o=t[3]:(o=(0,Q.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:r}),t[2]=r,t[3]=o);let s;return t[4]!==i||t[5]!==a||t[6]!==o?(s=(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[a,i,o]}),t[4]=i,t[5]=a,t[6]=o,t[7]=s):s=t[7],s}function go(){return X(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,u,`dark:border-edge`)}function _o(){return X(mt,A)}var vo=[`brave`,`tavily`,`bing`,`searxng`];function yo(){return{type:`brave`,apiKey:``,url:``,disabled:!1}}function bo(){let e=F(e=>e.language),t=oe(e),n=t.webSearchSettings,r=t.logs,i=!!R(e=>e.token),[a,o]=(0,$.useState)(null),[s,c]=(0,$.useState)(null),[l,u]=(0,$.useState)(!1),[d,f]=(0,$.useState)(null),[p,m]=(0,$.useState)(!1),h=(0,$.useRef)(!1),{data:g,error:_,isLoading:v,mutate:b}=I(i),x=(0,$.useMemo)(()=>g?.payload?.config===void 0?null:po(g.payload.config),[g]);(0,$.useEffect)(()=>{if(!i){o(null),c(null),h.current=!1;return}x!==null&&(h.current||(o(x),c(x)))},[i,x]);let S=!!(i&&v&&g===void 0&&!_),C=_ instanceof Error?_.message:_?String(_):null,T=(0,$.useMemo)(()=>!a||!s?!1:JSON.stringify(a)!==JSON.stringify(s),[a,s]),E=(0,$.useCallback)(e=>{h.current=!0,o(t=>t?{...t,...e}:null)},[]),D=(0,$.useCallback)(async()=>{if(!(!a||l)){u(!0),f(null),m(!1);try{await mo(a);let e=structuredClone(a);c(e),o(e),h.current=!1,m(!0),window.setTimeout(()=>m(!1),2500)}catch(e){f(e instanceof Error?e.message:n.saveError)}finally{u(!1)}}},[a,l,n.saveError]),O=(0,$.useCallback)(()=>{s&&(h.current=!1,o(structuredClone(s)),f(null),m(!1))},[s]);return i?S?(0,Q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col items-center gap-3 px-4 py-8`,children:[(0,Q.jsx)(Y,{className:`size-8 animate-spin text-fg-muted`,"aria-hidden":!0}),(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.loading})]}):a?(0,Q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Q.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.title}),(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,Q.jsxs)(`a`,{href:Ne(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,Q.jsx)(Ie,{className:`size-3.5`})]})]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[p?(0,Q.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,Q.jsx)(w,{type:`button`,variant:`secondary`,disabled:!T||l,onClick:O,children:n.discard}),(0,Q.jsx)(w,{type:`button`,variant:`primary`,disabled:!T||l,onClick:()=>void D(),children:l?n.saving:n.save})]})]}),T?(0,Q.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,d?(0,Q.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:d}):null,(0,Q.jsxs)(Kt,{children:[(0,Q.jsx)(Ot,{icon:it,title:n.sectionRegion,subtitle:n.sectionRegionHint}),(0,Q.jsx)(`div`,{className:`flex max-w-md flex-col gap-4`,children:(0,Q.jsx)(ho,{label:n.regionLabel,description:n.regionDesc,children:(0,Q.jsxs)(`select`,{className:_o(),value:a.regionMode,onChange:e=>E({regionMode:e.target.value}),children:[(0,Q.jsx)(`option`,{value:`auto`,children:n.regionAuto}),(0,Q.jsx)(`option`,{value:`cn`,children:n.regionCn}),(0,Q.jsx)(`option`,{value:`global`,children:n.regionGlobal})]})})})]}),(0,Q.jsxs)(Kt,{children:[(0,Q.jsx)(Ot,{icon:it,title:n.sectionSearch,subtitle:n.sectionSearchHint}),(0,Q.jsxs)(`div`,{className:`flex max-w-xl flex-col gap-6`,children:[(0,Q.jsx)(ho,{label:n.maxResultsLabel,description:n.maxResultsDesc,children:(0,Q.jsx)(`input`,{type:`number`,min:1,max:50,className:go(),value:a.maxResults,onChange:e=>E({maxResults:Math.max(1,Math.min(50,Number(e.target.value)||5))})})}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Q.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.providersTitle}),a.providers.map((e,t)=>(0,Q.jsx)(xo,{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,Q.jsxs)(w,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5 text-sm`,onClick:()=>E({providers:[...a.providers,yo()]}),children:[(0,Q.jsx)(y,{className:`size-4`}),n.addProvider]})]})]})]}),(0,Q.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:n.footerHint})]}):(0,Q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:d??C??n.loadError}),(0,Q.jsx)(w,{type:`button`,variant:`secondary`,onClick:()=>void b(),children:r.refresh})]}):(0,Q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-4 px-4 py-6`,children:[(0,Q.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:n.title}),(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}function xo(e){let t=(0,Z.c)(49),{row:n,labels:r,onChange:i,onRemove:a}=e,o;t[0]===Symbol.for(`react.memo_cache_sentinel`)?(o=X(_o(),`min-w-[8rem]`),t[0]=o):o=t[0];let s=n.type,c;t[1]!==i||t[2]!==n?(c=e=>i({...n,type:e.target.value,url:e.target.value===`searxng`?n.url:``}),t[1]=i,t[2]=n,t[3]=c):c=t[3];let l;t[4]===r.providerTypes?l=t[5]:(l=vo.map(e=>(0,Q.jsx)(`option`,{value:e,children:r.providerTypes[e]},e)),t[4]=r.providerTypes,t[5]=l);let u;t[6]!==n.type||t[7]!==c||t[8]!==l?(u=(0,Q.jsx)(`select`,{className:o,value:s,onChange:c,children:l}),t[6]=n.type,t[7]=c,t[8]=l,t[9]=u):u=t[9];let d;t[10]!==i||t[11]!==n?(d=e=>i({...n,disabled:e.target.checked}),t[10]=i,t[11]=n,t[12]=d):d=t[12];let f;t[13]!==n.disabled||t[14]!==d?(f=(0,Q.jsx)(`input`,{type:`checkbox`,className:`size-3.5 rounded border-edge`,checked:n.disabled,onChange:d}),t[13]=n.disabled,t[14]=d,t[15]=f):f=t[15];let p;t[16]!==r.disabled||t[17]!==f?(p=(0,Q.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1.5 text-xs text-fg-muted`,children:[f,r.disabled]}),t[16]=r.disabled,t[17]=f,t[18]=p):p=t[18];let m;t[19]===Symbol.for(`react.memo_cache_sentinel`)?(m=(0,Q.jsx)(Je,{className:`size-4`}),t[19]=m):m=t[19];let h;t[20]===a?h=t[21]:(h=(0,Q.jsx)(w,{type:`button`,variant:`ghost`,className:`h-8 px-2 text-fg-muted`,onClick:a,children:m}),t[20]=a,t[21]=h);let g;t[22]!==h||t[23]!==p?(g=(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[p,h]}),t[22]=h,t[23]=p,t[24]=g):g=t[24];let _;t[25]!==g||t[26]!==u?(_=(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[u,g]}),t[25]=g,t[26]=u,t[27]=_):_=t[27];let v;t[28]!==r.urlDesc||t[29]!==r.urlLabel||t[30]!==i||t[31]!==n?(v=n.type===`searxng`?(0,Q.jsx)(ho,{label:r.urlLabel,description:r.urlDesc,children:(0,Q.jsx)(`input`,{type:`url`,className:go(),value:n.url,placeholder:`http://localhost:8080`,onChange:e=>i({...n,url:e.target.value})})}):null,t[28]=r.urlDesc,t[29]=r.urlLabel,t[30]=i,t[31]=n,t[32]=v):v=t[32];let y=r.apiKeyLabel,b=r.apiKeyDesc,x;t[33]===Symbol.for(`react.memo_cache_sentinel`)?(x=go(),t[33]=x):x=t[33];let S=ke(n.apiKey)?``:n.apiKey,C=ke(n.apiKey)?r.keyPlaceholderMasked:r.keyPlaceholder,T;t[34]!==i||t[35]!==n?(T=e=>i({...n,apiKey:e.target.value}),t[34]=i,t[35]=n,t[36]=T):T=t[36];let E;t[37]!==S||t[38]!==C||t[39]!==T?(E=(0,Q.jsx)(`input`,{type:`password`,autoComplete:`off`,className:x,value:S,placeholder:C,onChange:T}),t[37]=S,t[38]=C,t[39]=T,t[40]=E):E=t[40];let D;t[41]!==r.apiKeyDesc||t[42]!==r.apiKeyLabel||t[43]!==E?(D=(0,Q.jsx)(ho,{label:y,description:b,children:E}),t[41]=r.apiKeyDesc,t[42]=r.apiKeyLabel,t[43]=E,t[44]=D):D=t[44];let O;return t[45]!==_||t[46]!==v||t[47]!==D?(O=(0,Q.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:[_,v,D]}),t[45]=_,t[46]=v,t[47]=D,t[48]=O):O=t[48],O}function So(e){let t=e.trim();if(!t)return null;try{let e=JSON.parse(t);if(e&&typeof e==`object`&&!Array.isArray(e))return Object.entries(e).map(([e,t])=>({key:e,value:t==null?``:String(t)}))}catch{}let n=[];for(let e of t.split(/\r?\n/)){let t=e.trim();if(!t)continue;let r=t.indexOf(`:`);if(r>0){n.push({key:t.slice(0,r).trim(),value:t.slice(r+1).trim()});continue}let i=t.indexOf(`=`);i>0&&n.push({key:t.slice(0,i).trim(),value:t.slice(i+1).trim()})}return n.length>0?n:null}function Co(e){let t={};for(let n of e){let e=n.key.trim();e&&(t[e]=n.value)}return Object.keys(t).length>0?t:void 0}function wo(e){if(!e||typeof e!=`object`)return[{key:``,value:``}];let t=Object.entries(e).map(([e,t])=>({key:e,value:t==null?``:String(t)}));return t.length>0?t:[{key:``,value:``}]}function To(e){let t=e.trim();if(t)return t.split(/\s+/).filter(Boolean)}function Eo(e){let t=e.trim();if(!t)return;let n=JSON.parse(t);if(!n||typeof n!=`object`||Array.isArray(n))throw Error(`Expected a JSON object`);return n}function Do(e){if(e.transport===`stdio`){let t={command:e.command.trim()},n=To(e.argsText);return n?.length&&(t.args=n),e.cwd.trim()&&(t.cwd=e.cwd.trim()),e.envJson.trim()&&(t.env=Eo(e.envJson)),e.connectionTimeoutMs!=null&&Number.isFinite(e.connectionTimeoutMs)&&(t.connectionTimeoutMs=e.connectionTimeoutMs),t}let t={url:e.url.trim(),transport:e.transport},n=Co(e.headers);return n&&(t.headers=n),e.connectionTimeoutMs!=null&&Number.isFinite(e.connectionTimeoutMs)&&(t.connectionTimeoutMs=e.connectionTimeoutMs),t}function Oo(e,t){let n=typeof t.url==`string`&&t.url.trim().length>0,r=typeof t.transport==`string`?t.transport.trim().toLowerCase():``,i=n?r===`sse`?`sse`:`streamable-http`:`stdio`,a=t.headers&&typeof t.headers==`object`&&!Array.isArray(t.headers)?t.headers:void 0;return{id:e,transport:i,command:typeof t.command==`string`?t.command:``,argsText:Array.isArray(t.args)?t.args.map(String).join(` `):``,envJson:t.env&&typeof t.env==`object`?JSON.stringify(t.env,null,2):``,cwd:typeof t.cwd==`string`?t.cwd:typeof t.workingDirectory==`string`?t.workingDirectory:``,url:typeof t.url==`string`?t.url:``,headers:wo(a),connectionTimeoutMs:typeof t.connectionTimeoutMs==`number`&&Number.isFinite(t.connectionTimeoutMs)?t.connectionTimeoutMs:void 0}}function ko(e=``){return{id:e,transport:`stdio`,command:``,argsText:``,envJson:``,cwd:``,url:``,headers:[{key:`Authorization`,value:``}],connectionTimeoutMs:void 0}}function Ao(e){let t=e&&typeof e==`object`&&`mcp`in e?e.mcp:void 0,n=t&&typeof t==`object`?t:{},r=n.servers,i=r&&typeof r==`object`&&!Array.isArray(r)?Object.entries(r).filter(([,e])=>e&&typeof e==`object`).map(([e,t])=>Oo(e,t)).sort((e,t)=>e.id.localeCompare(t.id)):[],a=typeof n.sessionIdleTtlMs==`number`?n.sessionIdleTtlMs:void 0;return{sessionIdleTtlMinutes:a==null?void 0:a===0?0:Math.round(a/6e4),servers:i}}function jo(e){return Do(e)}async function Mo(e){let t={};for(let n of e.servers){let e=n.id.trim();e&&(t[e]=Do(n))}let n={servers:t};e.sessionIdleTtlMinutes!=null&&Number.isFinite(e.sessionIdleTtlMinutes)&&(n.sessionIdleTtlMs=e.sessionIdleTtlMinutes===0?0:Math.round(e.sessionIdleTtlMinutes*6e4)),await v(lt(`/api/config`),{method:`PATCH`,body:JSON.stringify({mcp:n})}),P()}function No(e){if(!Array.isArray(e))return[];let t=[];for(let n of e){if(typeof n==`string`){let e=n.trim();e&&t.push({name:e});continue}if(!n||typeof n!=`object`)continue;let e=n;if(typeof e.name!=`string`)continue;let r=e.name.trim();if(!r)continue;let i=typeof e.shortName==`string`&&e.shortName.trim()?e.shortName.trim():void 0,a=typeof e.description==`string`&&e.description.trim()?e.description.trim():void 0;t.push({name:r,shortName:i,description:a})}return t}async function Po(e,t){let n=await v(lt(`/api/mcp/servers/${encodeURIComponent(e)}/test`),{method:`POST`,body:t?JSON.stringify({server:t}):void 0});if(!n.payload)throw Error(n.error??`MCP test failed`);let r=No(n.payload.tools);return{serverId:n.payload.serverId??e,toolCount:typeof n.payload.toolCount==`number`?n.payload.toolCount:r.length,tools:r}}function Fo(e){return e.connectionTimeoutMs==null||!Number.isFinite(e.connectionTimeoutMs)?``:String(Math.round(e.connectionTimeoutMs/1e3))}function Io(e){let t=e.trim();if(!t)return;let n=Number.parseInt(t,10);if(!(!Number.isFinite(n)||n<1||n>600))return n*1e3}function Lo(e,t){return e.id.trim()||`draft-${t}`}function Ro(){return X(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,u)}function zo({label:e,optionalLabel:t,addLabel:n,removeHeaderAria:r,pasteLabel:i,pasteFailed:a,keyPlaceholder:o,valuePlaceholder:s,headers:c,onChange:l}){let u=(e,t)=>{l(c.map((n,r)=>r===e?{...n,...t}:n))},d=()=>{l([...c,{key:``,value:``}])},f=e=>{let t=c.filter((t,n)=>n!==e);l(t.length>0?t:[{key:``,value:``}])},p=async()=>{try{let e=So(await navigator.clipboard.readText());if(!e?.length){window.alert(a);return}l(e)}catch{window.alert(a)}};return(0,Q.jsxs)(`div`,{className:`flex flex-col gap-2 md:col-span-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-1.5 text-sm font-medium text-fg`,children:[(0,Q.jsx)(`span`,{children:e}),t?(0,Q.jsx)(`span`,{className:`font-normal text-fg-subtle`,children:t}):null]}),(0,Q.jsxs)(w,{type:`button`,variant:`ghost`,className:`h-8 gap-1.5 px-2 text-xs`,onClick:()=>void p(),children:[(0,Q.jsx)(rt,{className:`size-3.5`,"aria-hidden":!0}),i]})]}),(0,Q.jsx)(`div`,{className:`flex flex-col gap-2`,children:c.map((e,t)=>(0,Q.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(`input`,{className:X(Ro(),`min-w-0 flex-1 font-mono text-xs`),value:e.key,placeholder:o,onChange:e=>u(t,{key:e.target.value})}),(0,Q.jsx)(`input`,{className:X(Ro(),`min-w-0 flex-[1.4] font-mono text-xs`),value:e.value,placeholder:s,onChange:e=>u(t,{value:e.target.value})}),(0,Q.jsx)(w,{type:`button`,variant:`ghost`,className:`size-9 shrink-0 px-0`,disabled:c.length<=1&&!e.key&&!e.value,onClick:()=>f(t),"aria-label":r,children:(0,Q.jsx)(Je,{className:`size-4 text-fg-subtle`,"aria-hidden":!0})})]},`header-${t}`))}),(0,Q.jsxs)(`button`,{type:`button`,className:`self-start text-sm text-accent hover:underline`,onClick:d,children:[`+ `,n]})]})}var Bo=[`stdio`,`sse`,`streamable-http`];function Vo(e){let t=(0,Z.c)(11),{label:n,description:r,required:i,children:a}=e,o;t[0]===i?o=t[1]:(o=i?(0,Q.jsx)(`span`,{className:`ml-0.5 text-danger`,children:`*`}):null,t[0]=i,t[1]=o);let s;t[2]!==n||t[3]!==o?(s=(0,Q.jsxs)(`div`,{className:`text-sm font-medium text-fg`,children:[n,o]}),t[2]=n,t[3]=o,t[4]=s):s=t[4];let c;t[5]===r?c=t[6]:(c=r?(0,Q.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:r}):null,t[5]=r,t[6]=c);let l;return t[7]!==a||t[8]!==s||t[9]!==c?(l=(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[s,a,c]}),t[7]=a,t[8]=s,t[9]=c,t[10]=l):l=t[10],l}function Ho(){return X(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,u)}function Uo(e){if(e.transport===`stdio`){let t=e.command.trim();if(!t)return``;let n=e.argsText.trim();return n?`${t} ${n}`:t}return e.url.trim()}function Wo(e){let t=(0,Z.c)(99),{row:n,expanded:r,onToggle:i,t:a,testing:o,toolState:s,onUpdate:c,onRemove:l,onTest:u,onViewTools:d}=e,f;t[0]!==n.id||t[1]!==a.cardUntitled?(f=n.id.trim()||a.cardUntitled,t[0]=n.id,t[1]=a.cardUntitled,t[2]=f):f=t[2];let p=f,m;t[3]===n?m=t[4]:(m=Uo(n),t[3]=n,t[4]=m);let h=m,_=a.transportLabels[n.transport],v=r?a.cardCollapseAria:a.cardExpandAria,y=r&&`rotate-180`,b;t[5]===y?b=t[6]:(b=X(`mt-0.5 size-4 shrink-0 text-fg-subtle transition-transform`,y),t[5]=y,t[6]=b);let x;t[7]===b?x=t[8]:(x=(0,Q.jsx)(L,{className:b,"aria-hidden":!0}),t[7]=b,t[8]=x);let S;t[9]===Symbol.for(`react.memo_cache_sentinel`)?(S=(0,Q.jsx)(g,{className:`size-4 shrink-0 text-accent`,"aria-hidden":!0}),t[9]=S):S=t[9];let C;t[10]===p?C=t[11]:(C=(0,Q.jsx)(`span`,{className:`truncate font-medium text-fg`,children:p}),t[10]=p,t[11]=C);let T;t[12]===_?T=t[13]:(T=(0,Q.jsx)(`span`,{className:`rounded-md border border-edge bg-surface-base px-1.5 py-0.5 text-[11px] text-fg-muted`,children:_}),t[12]=_,t[13]=T);let E;t[14]!==s.status||t[15]!==s.tools?(E=s.status===`ok`&&s.tools.length>0?(0,Q.jsxs)(`span`,{className:`inline-flex items-center gap-1 rounded-md border border-edge bg-surface-base px-1.5 py-0.5 text-[11px] text-fg-muted`,children:[(0,Q.jsx)(le,{className:`size-3`,"aria-hidden":!0}),s.tools.length]}):null,t[14]=s.status,t[15]=s.tools,t[16]=E):E=t[16];let O;t[17]!==E||t[18]!==C||t[19]!==T?(O=(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[S,C,T,E]}),t[17]=E,t[18]=C,t[19]=T,t[20]=O):O=t[20];let k;t[21]!==r||t[22]!==h?(k=!r&&h?(0,Q.jsx)(`p`,{className:`mt-1 truncate font-mono text-xs text-fg-subtle`,title:h,children:h}):null,t[21]=r,t[22]=h,t[23]=k):k=t[23];let A;t[24]!==r||t[25]!==s.message||t[26]!==s.status?(A=!r&&s.status===`error`?(0,Q.jsx)(`p`,{className:`mt-1 truncate text-xs text-red-600 dark:text-red-300`,title:s.message,children:s.message}):null,t[24]=r,t[25]=s.message,t[26]=s.status,t[27]=A):A=t[27];let j;t[28]!==O||t[29]!==k||t[30]!==A?(j=(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[O,k,A]}),t[28]=O,t[29]=k,t[30]=A,t[31]=j):j=t[31];let M;t[32]!==r||t[33]!==i||t[34]!==j||t[35]!==v||t[36]!==x?(M=(0,Q.jsxs)(`button`,{type:`button`,className:`flex min-w-0 flex-1 items-start gap-2 rounded-lg text-left hover:opacity-90`,"aria-expanded":r,"aria-label":v,onClick:i,children:[x,j]}),t[32]=r,t[33]=i,t[34]=j,t[35]=v,t[36]=x,t[37]=M):M=t[37];let N;t[38]!==n.id||t[39]!==o?(N=!n.id.trim()||o,t[38]=n.id,t[39]=o,t[40]=N):N=t[40];let P;t[41]===u?P=t[42]:(P=e=>{e.stopPropagation(),u()},t[41]=u,t[42]=P);let F;t[43]===o?F=t[44]:(F=o?(0,Q.jsx)(Y,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Q.jsx)(D,{className:`size-4`,"aria-hidden":!0}),t[43]=o,t[44]=F);let I;t[45]!==a.testConnection||t[46]!==N||t[47]!==P||t[48]!==F?(I=(0,Q.jsxs)(w,{type:`button`,variant:`ghost`,className:`h-8 px-2 text-xs`,disabled:N,onClick:P,children:[F,a.testConnection]}),t[45]=a.testConnection,t[46]=N,t[47]=P,t[48]=F,t[49]=I):I=t[49];let R;t[50]===l?R=t[51]:(R=e=>{e.stopPropagation(),l()},t[50]=l,t[51]=R);let z;t[52]===Symbol.for(`react.memo_cache_sentinel`)?(z=(0,Q.jsx)(Je,{className:`size-4`,"aria-hidden":!0}),t[52]=z):z=t[52];let B;t[53]!==a.removeServer||t[54]!==R?(B=(0,Q.jsxs)(w,{type:`button`,variant:`ghost`,className:`h-8 px-2 text-xs`,onClick:R,children:[z,a.removeServer]}),t[53]=a.removeServer,t[54]=R,t[55]=B):B=t[55];let V;t[56]!==I||t[57]!==B?(V=(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1`,children:[I,B]}),t[56]=I,t[57]=B,t[58]=V):V=t[58];let H;t[59]!==M||t[60]!==V?(H=(0,Q.jsxs)(`div`,{className:`flex items-start gap-2 p-4`,children:[M,V]}),t[59]=M,t[60]=V,t[61]=H):H=t[61];let U;t[62]!==r||t[63]!==c||t[64]!==d||t[65]!==n||t[66]!==a.addHeader||t[67]!==a.argsHint||t[68]!==a.argsLabel||t[69]!==a.commandLabel||t[70]!==a.cwdLabel||t[71]!==a.envHint||t[72]!==a.envLabel||t[73]!==a.headerKeyPlaceholder||t[74]!==a.headerValuePlaceholder||t[75]!==a.headersLabel||t[76]!==a.optionalSuffix||t[77]!==a.pasteHeaders||t[78]!==a.pasteHeadersFailed||t[79]!==a.removeHeader||t[80]!==a.serverIdLabel||t[81]!==a.serverIdPlaceholder||t[82]!==a.timeoutHint||t[83]!==a.timeoutLabel||t[84]!==a.timeoutPlaceholder||t[85]!==a.toolsEmpty||t[86]!==a.toolsLoading||t[87]!==a.toolsTitle||t[88]!==a.transportLabel||t[89]!==a.transportLabels||t[90]!==a.urlLabel||t[91]!==a.viewAllTools||t[92]!==s.message||t[93]!==s.status||t[94]!==s.tools?(U=r?(0,Q.jsxs)(`div`,{className:`border-t border-edge px-4 pb-4 pt-3`,children:[(0,Q.jsxs)(`div`,{className:`grid gap-4 md:grid-cols-2`,children:[(0,Q.jsx)(Vo,{label:a.transportLabel,required:!0,children:(0,Q.jsx)(`select`,{className:Ho(),value:n.transport,onChange:e=>c({transport:e.target.value}),children:Bo.map(e=>(0,Q.jsx)(`option`,{value:e,children:a.transportLabels[e]},e))})}),(0,Q.jsx)(Vo,{label:a.serverIdLabel,required:!0,children:(0,Q.jsx)(`input`,{className:Ho(),value:n.id,placeholder:a.serverIdPlaceholder,onChange:e=>c({id:e.target.value})})}),n.transport===`stdio`?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(Vo,{label:a.commandLabel,children:(0,Q.jsx)(`input`,{className:Ho(),value:n.command,onChange:e=>c({command:e.target.value})})}),(0,Q.jsx)(Vo,{label:a.argsLabel,description:a.argsHint,children:(0,Q.jsx)(`input`,{className:Ho(),value:n.argsText,onChange:e=>c({argsText:e.target.value})})}),(0,Q.jsx)(Vo,{label:a.cwdLabel,children:(0,Q.jsx)(`input`,{className:Ho(),value:n.cwd,onChange:e=>c({cwd:e.target.value})})}),(0,Q.jsx)(Vo,{label:a.envLabel,description:a.envHint,children:(0,Q.jsx)(`textarea`,{className:X(Ho(),`min-h-[4rem] font-mono text-xs`),value:n.envJson,onChange:e=>c({envJson:e.target.value})})})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(`div`,{className:`md:col-span-2`,children:(0,Q.jsx)(Vo,{label:a.urlLabel,required:!0,children:(0,Q.jsx)(`input`,{className:X(Ho(),`font-mono text-xs`),value:n.url,placeholder:`https://example.com/mcp`,onChange:e=>c({url:e.target.value})})})}),(0,Q.jsx)(zo,{label:a.headersLabel,optionalLabel:a.optionalSuffix,addLabel:a.addHeader,removeHeaderAria:a.removeHeader,pasteLabel:a.pasteHeaders,pasteFailed:a.pasteHeadersFailed,keyPlaceholder:a.headerKeyPlaceholder,valuePlaceholder:a.headerValuePlaceholder,headers:n.headers,onChange:e=>c({headers:e})})]}),(0,Q.jsx)(Vo,{label:a.timeoutLabel,description:a.timeoutHint,children:(0,Q.jsx)(`input`,{type:`number`,min:1,max:600,className:Ho(),value:Fo(n),placeholder:a.timeoutPlaceholder,onChange:e=>c({connectionTimeoutMs:Io(e.target.value)})})})]}),s.status===`loading`?(0,Q.jsxs)(`div`,{className:`mt-4 flex items-center gap-2 text-sm text-fg-muted`,children:[(0,Q.jsx)(Y,{className:`size-4 animate-spin`,"aria-hidden":!0}),a.toolsLoading]}):null,s.status===`error`?(0,Q.jsx)(`p`,{className:`mt-4 rounded-lg border border-red-500/30 bg-red-500/10 px-3 py-2 text-xs text-red-600 dark:text-red-300`,children:s.message}):null,s.status===`ok`?(0,Q.jsx)(`div`,{className:`mt-4 rounded-lg border border-edge bg-surface-base px-3 py-2.5`,children:(0,Q.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-medium text-fg`,children:[(0,Q.jsx)(le,{className:`size-4 text-accent`,"aria-hidden":!0}),s.tools.length===0?a.toolsEmpty:a.toolsTitle.replace(`{{count}}`,String(s.tools.length))]}),s.tools.length>0?(0,Q.jsx)(w,{type:`button`,variant:`ghost`,className:`h-8 text-xs`,onClick:()=>d(s.tools),children:a.viewAllTools}):null]})}):null]}):null,t[62]=r,t[63]=c,t[64]=d,t[65]=n,t[66]=a.addHeader,t[67]=a.argsHint,t[68]=a.argsLabel,t[69]=a.commandLabel,t[70]=a.cwdLabel,t[71]=a.envHint,t[72]=a.envLabel,t[73]=a.headerKeyPlaceholder,t[74]=a.headerValuePlaceholder,t[75]=a.headersLabel,t[76]=a.optionalSuffix,t[77]=a.pasteHeaders,t[78]=a.pasteHeadersFailed,t[79]=a.removeHeader,t[80]=a.serverIdLabel,t[81]=a.serverIdPlaceholder,t[82]=a.timeoutHint,t[83]=a.timeoutLabel,t[84]=a.timeoutPlaceholder,t[85]=a.toolsEmpty,t[86]=a.toolsLoading,t[87]=a.toolsTitle,t[88]=a.transportLabel,t[89]=a.transportLabels,t[90]=a.urlLabel,t[91]=a.viewAllTools,t[92]=s.message,t[93]=s.status,t[94]=s.tools,t[95]=U):U=t[95];let W;return t[96]!==H||t[97]!==U?(W=(0,Q.jsxs)(`div`,{className:`rounded-xl border border-edge bg-surface-panel`,children:[H,U]}),t[96]=H,t[97]=U,t[98]=W):W=t[98],W}function Go(e,t){return e?t&&e.startsWith(t)?e.slice(t.length):e:``}function Ko(e,t,n){let r=t.trim().toLowerCase();if(!r)return!0;let i=e.shortName||Go(e.name,n);return[e.name,i,e.description].filter(Boolean).join(`
|
|
2
|
+
`).toLowerCase().includes(r)}function qo(e,t){return e?t&&e.startsWith(t)?e.slice(t.length):e:``}function Jo(e){let t=(0,Z.c)(55),{open:n,onOpenChange:r,serverId:i,title:a,subtitle:o,searchPlaceholder:s,searchEmptyLabel:c,emptyLabel:l,closeLabel:d,tools:p,stripPrefix:m}=e,[h,g]=(0,$.useState)(``),_,v;t[0]===n?(_=t[1],v=t[2]):(_=()=>{n||g(``)},v=[n],t[0]=n,t[1]=_,t[2]=v),(0,$.useEffect)(_,v);let y;if(t[3]!==h||t[4]!==m||t[5]!==p){let e;t[7]!==h||t[8]!==m?(e=e=>Ko(e,h,m),t[7]=h,t[8]=m,t[9]=e):e=t[9],y=p.filter(e),t[3]=h,t[4]=m,t[5]=p,t[6]=y}else y=t[6];let b=y,x;t[10]===h?x=t[11]:(x=h.trim(),t[10]=h,t[11]=x);let S=x.length>0,C;t[12]===Symbol.for(`react.memo_cache_sentinel`)?(C=(0,Q.jsx)(se,{className:X(`xopc-dialog-overlay fixed inset-0 bg-scrim backdrop-blur-[1px]`,Fe)}),t[12]=C):C=t[12];let E;t[13]===Symbol.for(`react.memo_cache_sentinel`)?(E=X(`fixed left-1/2 top-1/2 flex max-h-[min(88vh,40rem)] w-[min(100%-2rem,min(92vw,36rem))] -translate-x-1/2 -translate-y-1/2 flex-col`,Xe,`rounded-2xl border border-edge bg-surface-panel shadow-popover outline-none dark:border-edge`),t[13]=E):E=t[13];let D;t[14]===Symbol.for(`react.memo_cache_sentinel`)?(D=(0,Q.jsx)(le,{className:`size-4 shrink-0 text-accent`,"aria-hidden":!0}),t[14]=D):D=t[14];let O;t[15]===a?O=t[16]:(O=(0,Q.jsxs)(ce,{className:`flex items-center gap-2 text-base font-semibold text-fg`,children:[D,a]}),t[15]=a,t[16]=O);let k;t[17]!==i||t[18]!==o||t[19]!==p.length?(k=o.replace(`{{serverId}}`,i).replace(`{{count}}`,String(p.length)),t[17]=i,t[18]=o,t[19]=p.length,t[20]=k):k=t[20];let A;t[21]===k?A=t[22]:(A=(0,Q.jsx)(f,{className:`mt-1 text-sm text-fg-muted`,children:k}),t[21]=k,t[22]=A);let j;t[23]!==A||t[24]!==O?(j=(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[O,A]}),t[23]=A,t[24]=O,t[25]=j):j=t[25];let M;t[26]===Symbol.for(`react.memo_cache_sentinel`)?(M=(0,Q.jsx)(fe,{className:`size-4`,"aria-hidden":!0}),t[26]=M):M=t[26];let N;t[27]===d?N=t[28]:(N=(0,Q.jsx)(G,{asChild:!0,children:(0,Q.jsx)(w,{type:`button`,variant:`ghost`,className:`size-8 shrink-0 px-0`,"aria-label":d,children:M})}),t[27]=d,t[28]=N);let P;t[29]!==j||t[30]!==N?(P=(0,Q.jsxs)(`div`,{className:`flex items-start justify-between gap-3 border-b border-edge px-5 py-4`,children:[j,N]}),t[29]=j,t[30]=N,t[31]=P):P=t[31];let F;t[32]!==b||t[33]!==S||t[34]!==h||t[35]!==s||t[36]!==p.length?(F=p.length>0?(0,Q.jsxs)(`div`,{className:`border-b border-edge px-5 py-3`,children:[(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(it,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-fg-subtle`,"aria-hidden":!0}),(0,Q.jsx)(`input`,{type:`search`,value:h,placeholder:s,"aria-label":s,className:X(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-9 pr-3 text-sm text-fg`,`placeholder:text-fg-subtle`,u),onChange:e=>g(e.target.value)})]}),S?(0,Q.jsxs)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:[b.length,` / `,p.length]}):null]}):null,t[32]=b,t[33]=S,t[34]=h,t[35]=s,t[36]=p.length,t[37]=F):F=t[37];let I;t[38]!==l||t[39]!==b||t[40]!==c||t[41]!==m||t[42]!==p.length?(I=(0,Q.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-5 py-4`,children:p.length===0?(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:l}):b.length===0?(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:c}):(0,Q.jsx)(`ul`,{className:`flex flex-col gap-2`,children:b.map((e,t)=>{let n=e.shortName||qo(e.name,m)||e.name||`?`,r=e.name||`tool-${t}`;return(0,Q.jsxs)(`li`,{className:`min-w-0 rounded-lg border border-edge bg-surface-base px-3 py-2.5`,children:[(0,Q.jsx)(`div`,{className:`truncate font-mono text-sm font-medium text-fg`,title:e.name===n?n:e.name,children:n}),e.description?(0,Q.jsx)(`p`,{className:`mt-1 truncate text-xs leading-relaxed text-fg-muted`,title:e.description,children:e.description}):null]},r)})})}),t[38]=l,t[39]=b,t[40]=c,t[41]=m,t[42]=p.length,t[43]=I):I=t[43];let L;t[44]===d?L=t[45]:(L=(0,Q.jsx)(`div`,{className:`flex justify-end border-t border-edge px-5 py-3`,children:(0,Q.jsx)(G,{asChild:!0,children:(0,Q.jsx)(w,{type:`button`,variant:`secondary`,children:d})})}),t[44]=d,t[45]=L);let R;t[46]!==P||t[47]!==F||t[48]!==I||t[49]!==L?(R=(0,Q.jsxs)(T,{children:[C,(0,Q.jsxs)(gt,{className:E,children:[P,F,I,L]})]}),t[46]=P,t[47]=F,t[48]=I,t[49]=L,t[50]=R):R=t[50];let z;return t[51]!==r||t[52]!==n||t[53]!==R?(z=(0,Q.jsx)(ae,{open:n,onOpenChange:r,children:R}),t[51]=r,t[52]=n,t[53]=R,t[54]=z):z=t[54],z}function Yo(){return X(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,u)}function Xo(){let e=oe(F(e=>e.language)),t=e.mcpSettings,n=!!R(e=>e.token),[r,i]=(0,$.useState)(null),[a,o]=(0,$.useState)(null),[s,l]=(0,$.useState)(!1),[u,d]=(0,$.useState)(null),[f,p]=(0,$.useState)(!1),[m,h]=(0,$.useState)(null),[_,v]=(0,$.useState)({}),[b,x]=(0,$.useState)(null),[S,C]=(0,$.useState)(()=>new Set),T=(0,$.useRef)(!1),{data:E,error:D,isLoading:O,mutate:k}=I(n),A=(0,$.useMemo)(()=>E?.payload?.config===void 0?null:Ao(E.payload.config),[E]);(0,$.useEffect)(()=>{if(!n){i(null),o(null),T.current=!1,C(new Set);return}A!==null&&(T.current||(i(A),o(A),C(new Set)))},[n,A]);let j=!!(n&&O&&E===void 0&&!D),M=D instanceof Error?D.message:D?String(D):null,N=(0,$.useMemo)(()=>!r||!a?!1:JSON.stringify(r)!==JSON.stringify(a),[r,a]),P=(0,$.useCallback)(e=>{C(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},[]),L=(0,$.useCallback)((e,t)=>{T.current=!0,i(n=>{if(!n)return n;let r=[...n.servers],i=r[e];if(!i)return n;if(r[e]={...i,...t},t.id&&t.id!==i.id){let n=Lo(i,e),r=Lo({...i,...t},e);v(e=>{let t={...e};return n!==r&&t[n]&&(t[r]=t[n],delete t[n]),delete t[i.id],t}),C(e=>{if(!e.has(n))return e;let t=new Set(e);return t.delete(n),t.add(r),t})}return{...n,servers:r}})},[]),z=(0,$.useCallback)(()=>{T.current=!0,i(e=>{if(!e)return e;let t=e.servers.length;return C(e=>new Set(e).add(`draft-${t}`)),{...e,servers:[...e.servers,ko(`server-${t+1}`)]}})},[]),B=(0,$.useCallback)(e=>{T.current=!0,i(t=>{if(!t)return t;let n=t.servers[e];if(n){let t=Lo(n,e);C(e=>{let n=new Set(e);return n.delete(t),n}),n.id&&v(e=>{let t={...e};return delete t[n.id],t})}return{...t,servers:t.servers.filter((t,n)=>n!==e)}})},[]),V=(0,$.useCallback)(async()=>{if(!(!r||s)){l(!0),d(null),p(!1);try{await Mo(r);let e=structuredClone(r);o(e),i(e),T.current=!1,p(!0),C(new Set),k()}catch(e){d(e instanceof Error?e.message:String(e))}finally{l(!1)}}},[r,k,s]),H=(0,$.useCallback)(async(e,t)=>{if(e.trim()){h(e),d(null),v(t=>({...t,[e]:{status:`loading`}}));try{let n=t?jo(t):void 0,r=await Po(e.trim(),n);v(t=>({...t,[e]:{status:`ok`,tools:r.tools}}))}catch(t){let n=t instanceof Error?t.message:String(t);v(t=>({...t,[e]:{status:`error`,message:n}}))}finally{h(null)}}},[]);return n?j||!r?(0,Q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-4 px-4 py-8`,children:[(0,Q.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.title}),(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.loading})]}):(0,Q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.title}),(0,Q.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:t.subtitle})]}),(M||u)&&(0,Q.jsx)(`p`,{className:`rounded-lg border border-red-500/30 bg-red-500/10 px-3 py-2 text-sm text-red-600 dark:text-red-300`,children:u??M}),f&&(0,Q.jsx)(`p`,{className:`rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg-muted`,children:t.saved}),(0,Q.jsxs)(Kt,{children:[(0,Q.jsx)(Ot,{icon:c,title:t.globalTitle,subtitle:t.globalHint}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Q.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.idleTtlLabel}),(0,Q.jsx)(`input`,{type:`number`,min:0,className:Yo(),value:r.sessionIdleTtlMinutes??``,placeholder:t.idleTtlPlaceholder,onChange:e=>{T.current=!0;let t=e.target.value.trim();i(e=>e&&{...e,sessionIdleTtlMinutes:t===``?void 0:Number.parseInt(t,10)})}}),(0,Q.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:t.idleTtlHint})]})]}),(0,Q.jsxs)(Kt,{children:[(0,Q.jsx)(Ot,{icon:g,title:t.serversTitle,subtitle:t.serversHint}),(0,Q.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[r.servers.length===0?(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.serversEmpty}):null,r.servers.map((e,n)=>{let r=Lo(e,n),i=_[e.id]??{status:`idle`};return(0,Q.jsx)(Wo,{row:e,expanded:S.has(r),onToggle:()=>P(r),t,testing:m===e.id,toolState:i,onUpdate:e=>L(n,e),onRemove:()=>B(n),onTest:()=>void H(e.id,e),onViewTools:t=>x({serverId:e.id,tools:t})},r)}),(0,Q.jsxs)(w,{type:`button`,variant:`ghost`,className:`self-start`,onClick:z,children:[(0,Q.jsx)(y,{className:`size-4`,"aria-hidden":!0}),t.addServer]})]})]}),(0,Q.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Q.jsxs)(w,{type:`button`,disabled:!N||s,onClick:()=>void V(),children:[s?(0,Q.jsx)(Y,{className:`size-4 animate-spin`,"aria-hidden":!0}):null,s?t.saving:t.save]}),(0,Q.jsx)(w,{type:`button`,variant:`ghost`,disabled:!N||s,onClick:()=>{a&&(T.current=!1,i(structuredClone(a)),p(!1),d(null),v({}),C(new Set))},children:t.discard})]}),(0,Q.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:t.disableHint}),b?(0,Q.jsx)(Jo,{open:!0,onOpenChange:e=>{e||x(null)},serverId:b.serverId,title:t.toolsDialogTitle,subtitle:t.toolsDialogSubtitle,searchPlaceholder:t.toolsDialogSearchPlaceholder,searchEmptyLabel:t.toolsDialogSearchEmpty,emptyLabel:t.toolsEmpty,closeLabel:t.toolsDialogClose,tools:b.tools,stripPrefix:`${b.serverId.trim()}__`}):null]}):(0,Q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-4 px-4 py-8`,children:[(0,Q.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.title}),(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.token.description})]})}var Zo=[`appearance`,`system`,`agent-chat`,`agent-workspace`,`agent-browser`,`agent-runtime`,`agent-tools`,`agent-mcp`,`agent-system-prompt`,`providers`,`models`,`image-models`,`voice`,`gateway`,`heartbeat`,`tunnel`,`shares`,`search`,`dreams`];function Qo(){let e=(0,Z.c)(30),{section:t}=ie(),n=F($o),r;e[0]===n?r=e[1]:(r=oe(n),e[0]=n,e[1]=r);let i=r;if(t===`agent`||t===`agents`){let t;return e[2]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,Q.jsx)(l,{to:`/agents`,replace:!0}),e[2]=t):t=e[2],t}if(!t||!Zo.includes(t)){let t;return e[3]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,Q.jsx)(l,{to:`/settings/appearance`,replace:!0}),e[3]=t):t=e[3],t}let a=t,o=i.settingsSections[a];if(a===`appearance`){let t;return e[4]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,Q.jsx)(dn,{}),e[4]=t):t=e[4],t}if(a===`system`){let t;return e[5]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,Q.jsx)(ja,{}),e[5]=t):t=e[5],t}if(a===`agent-chat`){let t;return e[6]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,Q.jsx)(Lt,{}),e[6]=t):t=e[6],t}if(a===`agent-workspace`){let t;return e[7]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,Q.jsx)(Rt,{}),e[7]=t):t=e[7],t}if(a===`agent-browser`){let t;return e[8]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,Q.jsx)(Ht,{}),e[8]=t):t=e[8],t}if(a===`agent-runtime`){let t;return e[9]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,Q.jsx)(Bt,{}),e[9]=t):t=e[9],t}if(a===`agent-tools`){let t;return e[10]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,Q.jsx)(Dt,{}),e[10]=t):t=e[10],t}if(a===`agent-system-prompt`){let t;return e[11]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,Q.jsx)(Pt,{}),e[11]=t):t=e[11],t}if(a===`providers`){let t;return e[12]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,Q.jsx)(Oa,{}),e[12]=t):t=e[12],t}if(a===`models`){let t;return e[13]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,Q.jsx)(pa,{}),e[13]=t):t=e[13],t}if(a===`image-models`){let t;return e[14]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,Q.jsx)(ji,{}),e[14]=t):t=e[14],t}if(a===`voice`){let t;return e[15]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,Q.jsx)($a,{}),e[15]=t):t=e[15],t}if(a===`gateway`){let t;return e[16]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,Q.jsx)(pr,{}),e[16]=t):t=e[16],t}if(a===`heartbeat`){let t;return e[17]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,Q.jsx)(wr,{}),e[17]=t):t=e[17],t}if(a===`tunnel`){let t;return e[18]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,Q.jsx)(ri,{}),e[18]=t):t=e[18],t}if(a===`shares`){let t;return e[19]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,Q.jsx)(si,{}),e[19]=t):t=e[19],t}if(a===`search`){let t;return e[20]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,Q.jsx)(bo,{}),e[20]=t):t=e[20],t}if(a===`agent-mcp`){let t;return e[21]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,Q.jsx)(Xo,{}),e[21]=t):t=e[21],t}if(a===`dreams`){let t;return e[22]===Symbol.for(`react.memo_cache_sentinel`)?(t=(0,Q.jsx)(er,{}),e[22]=t):t=e[22],t}let s;e[23]===o?s=e[24]:(s=(0,Q.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:o}),e[23]=o,e[24]=s);let c=n===`zh`?`设置 · ${o}(即将推出)。`:`Settings · ${o} (coming soon).`,u;e[25]===c?u=e[26]:(u=(0,Q.jsx)(`p`,{className:`text-sm text-fg-muted`,children:c}),e[25]=c,e[26]=u);let d;return e[27]!==s||e[28]!==u?(d=(0,Q.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[s,u]}),e[27]=s,e[28]=u,e[29]=d):d=e[29],d}function $o(e){return e.language}export{Qo as SettingsPage};
|
|
3
|
+
//# sourceMappingURL=settings-page-C5VrwDoO.js.map
|