@xopcai/xopc 0.0.34 → 0.0.35

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/dist/extensions/telegram/xopc.extension.json +1 -1
  2. package/dist/gateway/static/root/assets/{agents-BENeGWaV.js → agents-3MgROWaB.js} +2 -2
  3. package/dist/gateway/static/root/assets/{agents-BENeGWaV.js.map → agents-3MgROWaB.js.map} +1 -1
  4. package/dist/gateway/static/root/assets/{apps-page-C8S_3XR3.js → apps-page-Dh89sZVt.js} +2 -2
  5. package/dist/gateway/static/root/assets/{apps-page-C8S_3XR3.js.map → apps-page-Dh89sZVt.js.map} +1 -1
  6. package/dist/gateway/static/root/assets/{channels-settings-Z0gz9LEn.js → channels-settings-BNR4uMFv.js} +2 -2
  7. package/dist/gateway/static/root/assets/{channels-settings-Z0gz9LEn.js.map → channels-settings-BNR4uMFv.js.map} +1 -1
  8. package/dist/gateway/static/root/assets/{cron-api-DHcunvTO.js → cron-api-HehSuhku.js} +2 -2
  9. package/dist/gateway/static/root/assets/{cron-api-DHcunvTO.js.map → cron-api-HehSuhku.js.map} +1 -1
  10. package/dist/gateway/static/root/assets/{cron-page-CdZjOHQ5.js → cron-page-cNl5O7jj.js} +2 -2
  11. package/dist/gateway/static/root/assets/{cron-page-CdZjOHQ5.js.map → cron-page-cNl5O7jj.js.map} +1 -1
  12. package/dist/gateway/static/root/assets/{dist-DPEltH1B.js → dist-RpqJxYGW.js} +2 -2
  13. package/dist/gateway/static/root/assets/{dist-DPEltH1B.js.map → dist-RpqJxYGW.js.map} +1 -1
  14. package/dist/gateway/static/root/assets/{extension-debug-page-DyEkbdRu.js → extension-debug-page-C38A0UVx.js} +2 -2
  15. package/dist/gateway/static/root/assets/{extension-debug-page-DyEkbdRu.js.map → extension-debug-page-C38A0UVx.js.map} +1 -1
  16. package/dist/gateway/static/root/assets/{extension-page-Vr_24oNG.js → extension-page-BHVeBMn8.js} +2 -2
  17. package/dist/gateway/static/root/assets/{extension-page-Vr_24oNG.js.map → extension-page-BHVeBMn8.js.map} +1 -1
  18. package/dist/gateway/static/root/assets/{extension-settings-page-D3wIHYGH.js → extension-settings-page-D1iDIHYn.js} +2 -2
  19. package/dist/gateway/static/root/assets/{extension-settings-page-D3wIHYGH.js.map → extension-settings-page-D1iDIHYn.js.map} +1 -1
  20. package/dist/gateway/static/root/assets/{index-DfzxemgG.js → index-C9ACajYe.js} +5 -5
  21. package/dist/gateway/static/root/assets/{index-DfzxemgG.js.map → index-C9ACajYe.js.map} +1 -1
  22. package/dist/gateway/static/root/assets/{logs-page-D-swbxzE.js → logs-page-DxbZy88k.js} +2 -2
  23. package/dist/gateway/static/root/assets/{logs-page-D-swbxzE.js.map → logs-page-DxbZy88k.js.map} +1 -1
  24. package/dist/gateway/static/root/assets/{sessions-page-CkevfEBJ.js → sessions-page-Cl-1QJM9.js} +2 -2
  25. package/dist/gateway/static/root/assets/{sessions-page-CkevfEBJ.js.map → sessions-page-Cl-1QJM9.js.map} +1 -1
  26. package/dist/gateway/static/root/assets/{settings-page-CGDCcKXO.js → settings-page-DUYYElOB.js} +2 -2
  27. package/dist/gateway/static/root/assets/{settings-page-CGDCcKXO.js.map → settings-page-DUYYElOB.js.map} +1 -1
  28. package/dist/gateway/static/root/assets/skills-page-MiXi4U0-.js +3 -0
  29. package/dist/gateway/static/root/assets/skills-page-MiXi4U0-.js.map +1 -0
  30. package/dist/gateway/static/root/index.html +1 -1
  31. package/dist/package.js +1 -1
  32. package/package.json +1 -1
  33. package/dist/gateway/static/root/assets/skills-page-ZTABuog7.js +0 -3
  34. package/dist/gateway/static/root/assets/skills-page-ZTABuog7.js.map +0 -1
  35. /package/skills/{meta → tools}/skill-creator/LICENSE.txt +0 -0
  36. /package/skills/{meta → tools}/skill-creator/SKILL-zh.md +0 -0
  37. /package/skills/{meta → tools}/skill-creator/SKILL.md +0 -0
  38. /package/skills/{meta → tools}/skill-creator/agents/analyzer.md +0 -0
  39. /package/skills/{meta → tools}/skill-creator/agents/comparator.md +0 -0
  40. /package/skills/{meta → tools}/skill-creator/agents/grader.md +0 -0
  41. /package/skills/{meta → tools}/skill-creator/assets/eval_review.html +0 -0
  42. /package/skills/{meta → tools}/skill-creator/eval-viewer/generate_review.py +0 -0
  43. /package/skills/{meta → tools}/skill-creator/eval-viewer/viewer.html +0 -0
  44. /package/skills/{meta → tools}/skill-creator/references/schemas.md +0 -0
  45. /package/skills/{meta → tools}/skill-creator/scripts/__init__.py +0 -0
  46. /package/skills/{meta → tools}/skill-creator/scripts/aggregate_benchmark.py +0 -0
  47. /package/skills/{meta → tools}/skill-creator/scripts/generate_report.py +0 -0
  48. /package/skills/{meta → tools}/skill-creator/scripts/improve_description.py +0 -0
  49. /package/skills/{meta → tools}/skill-creator/scripts/package_skill.py +0 -0
  50. /package/skills/{meta → tools}/skill-creator/scripts/quick_validate.py +0 -0
  51. /package/skills/{meta → tools}/skill-creator/scripts/run_eval.py +0 -0
  52. /package/skills/{meta → tools}/skill-creator/scripts/run_loop.py +0 -0
  53. /package/skills/{meta → tools}/skill-creator/scripts/utils.py +0 -0
@@ -1,2 +1,2 @@
1
- import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{i as t,t as n}from"./vendor-react-DbimaAId.js";import{i as r,o as i}from"./vendor-swr-B5fPo7KK.js";import{t as a}from"./cn-BMCV0OMB.js";import{$n as o,At as s,Bn as c,Ci as l,Cn as u,Cr as d,Dn as f,Dt as p,En as m,Fn as h,Fr as g,Ft as _,Gr as v,It as y,K as b,Kn as x,Mn as S,Mr as C,Mt as w,Nn as T,Nr as E,Nt as D,On as O,Ot as k,Pn as A,Pr as j,Pt as M,Sn as N,Sr as ee,Tn as P,Tt as F,Un as I,Ur as L,Wr as te,Xn as R,Xr as ne,Y as z,Yr as B,Zn as re,a as V,ai as ie,ar as ae,bi as oe,bn as se,br as H,c as ce,cn as U,cr as W,dn as le,fi as ue,fn as G,g as de,gn as fe,gr as pe,h as me,hn as K,hr as he,i as ge,ir as _e,jt as ve,kn as q,kt as ye,l as be,li as xe,ln as Se,m as Ce,n as we,o as Te,oi as Ee,or as De,pn as Oe,pr as ke,qn as Ae,r as je,ri as Me,s as Ne,si as Pe,t as Fe,tr as Ie,u as Le,ui as Re,un as ze,ur as Be,vi as Ve,vn as He,vt as Ue,wn as We,wt as Ge,xr as Ke,yi as qe,yn as Je,yt as Ye}from"./index-DfzxemgG.js";import{i as Xe,l as Ze,y as Qe}from"./cron-api-DHcunvTO.js";import{_ as $e,a as et,b as J,c as tt,d as nt,f as rt,g as it,h as at,i as ot,l as st,m as ct,n as lt,o as ut,p as dt,r as ft,s as pt,t as mt,u as ht,v as gt,y as _t}from"./agents-BENeGWaV.js";import{t as vt}from"./browser-DNXWYwzc.js";var Y=n();function yt(){return a(`rounded-xl border border-edge-subtle bg-surface-base px-4 py-1 sm:px-5`)}var bt={default:{light:{canvas:`#f5f5f7`,panel:`#ffffff`,accent:`#2563eb`,fg:`#1d1d1f`,muted:`#d2d2d7`},dark:{canvas:`#1c1c1e`,panel:`#2c2c2e`,accent:`#3b82f6`,fg:`#f5f5f7`,muted:`#48484a`}},emerald:{light:{canvas:`#f0fdf4`,panel:`#ffffff`,accent:`#059669`,fg:`#052e16`,muted:`#86efac`},dark:{canvas:`#000000`,panel:`#0a0a0a`,accent:`#10b981`,fg:`#d1fae5`,muted:`#134e2a`}},mono:{light:{canvas:`#ffffff`,panel:`#f5f5f5`,accent:`#111111`,fg:`#111111`,muted:`#e5e7eb`},dark:{canvas:`#101010`,panel:`#1a1a1a`,accent:`#737373`,fg:`#fafafa`,muted:`#333333`}}};function xt({canvas:e,panel:t,accent:n,fg:r,muted:i}){return(0,Y.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col justify-center gap-1 p-1.5`,style:{backgroundColor:e},children:(0,Y.jsxs)(`div`,{className:`flex flex-col gap-0.5 rounded-sm border p-1`,style:{backgroundColor:t,borderColor:i},children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`div`,{className:`h-1 w-1 shrink-0 rounded-full`,style:{backgroundColor:n}}),(0,Y.jsx)(`div`,{className:`h-1 min-w-0 flex-1 rounded-full`,style:{backgroundColor:r,opacity:.85}})]}),(0,Y.jsx)(`div`,{className:`h-1 w-2/3 max-w-[70%] rounded-full`,style:{backgroundColor:i}}),(0,Y.jsx)(`div`,{className:`h-1 w-1/2 max-w-[55%] rounded-full`,style:{backgroundColor:i}})]})})}function St({scheme:e}){let{light:t,dark:n}=bt[e];return(0,Y.jsxs)(`div`,{className:`flex h-11 w-full overflow-hidden rounded-md border border-edge-subtle`,children:[(0,Y.jsx)(xt,{...t}),(0,Y.jsx)(`div`,{className:`w-px shrink-0 bg-black/12 dark:bg-white/12`,"aria-hidden":!0}),(0,Y.jsx)(xt,{...n})]})}var Ct=[{value:`default`,labelKey:`colorSchemeDefault`},{value:`emerald`,labelKey:`colorSchemeLightGreen`},{value:`mono`,labelKey:`colorSchemeModernMono`}];function wt(){let e=O(se(e=>e.language)).appearanceSettings,t=Je(e=>e.colorScheme),n=Je(e=>e.setColorScheme);return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2 border-b border-edge-subtle py-3.5 last:border-b-0 sm:py-4`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:e.colorSchemeTitle}),(0,Y.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:e.colorSchemeDescription})]}),(0,Y.jsx)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-3`,children:Ct.map(({value:r,labelKey:i})=>{let o=t===r;return(0,Y.jsxs)(`button`,{type:`button`,"aria-pressed":o,onClick:()=>n(r),className:a(`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,Y.jsx)(St,{scheme:r}),(0,Y.jsx)(`span`,{className:a(`text-xs font-medium leading-none`,o?`text-accent-fg`:`text-fg-muted`),children:e[i]})]},r)})})]})}function Tt(){let e=O(se(e=>e.language)).appearanceSettings;return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col gap-1`,children:[(0,Y.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight text-fg`,children:e.pageTitle}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.subtitle})]}),(0,Y.jsxs)(`section`,{className:yt(),"aria-labelledby":`pref-language-heading`,children:[(0,Y.jsx)(`h2`,{id:`pref-language-heading`,className:`sr-only`,children:e.languageTitle}),(0,Y.jsx)(He,{variant:`page`,sections:[`language`]})]}),(0,Y.jsxs)(`section`,{className:yt(),"aria-labelledby":`pref-appearance-heading`,children:[(0,Y.jsx)(`h2`,{id:`pref-appearance-heading`,className:`sr-only`,children:e.themeTitle}),(0,Y.jsx)(He,{variant:`page`,sections:[`theme`,`font`]}),(0,Y.jsx)(wt,{})]})]})}var X=e(t(),1);function Et(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var Dt={enabled:!0,cron:`0 */6 * * *`,lookbackDays:1,limit:50,dedupeSimilarity:.85},Ot={enabled:!0,cron:`0 3 * * *`,minScore:.8,minRecallCount:3,limit:10,recencyHalfLifeDays:14,maxAgeDays:30},kt={enabled:!0,cron:`0 5 * * 0`,lookbackDays:7,limit:20,minPatternStrength:.6},At={enabled:!1,frequency:`0 3 * * *`,timezone:``,deepEnabled:!0,minScore:.8,minRecallCount:3,limit:10,light:Dt,deep:Ot,rem:kt};function jt(e,t){return Number.isFinite(e)?Math.max(0,Math.min(1,e)):t}function Mt(e,t){let n=typeof e==`string`?Number(e):e;return Number.isFinite(n)?Math.max(0,Math.floor(n)):t}function Nt(e,t){let n=typeof e==`string`?Number(e):e;return Number.isFinite(n)?n:t}function Pt(e){let t=Et(e)?e:{},n=Et(t.agents)?t.agents:{},r=Et(n.defaults)?n.defaults:{},i=Et(r.memory)?r.memory:{},a=Et(i.dreaming)?i.dreaming:{},o=Et(a.phases)?a.phases:{},s=Et(o.light)?o.light:{},c=Et(o.deep)?o.deep:{},l=Et(o.rem)?o.rem:{};return{enabled:a.enabled===!0,frequency:typeof a.frequency==`string`&&a.frequency.trim()?a.frequency.trim():At.frequency,timezone:typeof a.timezone==`string`?a.timezone:``,deepEnabled:c.enabled!==!1,minScore:jt(typeof c.minScore==`number`?c.minScore:Number(c.minScore),At.minScore),minRecallCount:Math.max(1,Mt(c.minRecallCount,At.minRecallCount)),limit:Mt(c.limit,At.limit),light:{enabled:s.enabled!==!1,cron:typeof s.cron==`string`&&s.cron.trim()?s.cron.trim():Dt.cron,lookbackDays:Math.max(1,Mt(s.lookbackDays,Dt.lookbackDays)),limit:Mt(s.limit,Dt.limit),dedupeSimilarity:jt(Nt(s.dedupeSimilarity,Dt.dedupeSimilarity),Dt.dedupeSimilarity)},deep:{enabled:c.enabled!==!1,cron:typeof c.cron==`string`&&c.cron.trim()?c.cron.trim():Ot.cron,minScore:jt(Nt(c.minScore,Ot.minScore),Ot.minScore),minRecallCount:Math.max(1,Mt(c.minRecallCount,Ot.minRecallCount)),limit:Mt(c.limit,Ot.limit),recencyHalfLifeDays:Math.max(1,Nt(c.recencyHalfLifeDays,Ot.recencyHalfLifeDays)),maxAgeDays:Math.max(1,Nt(c.maxAgeDays,Ot.maxAgeDays))},rem:{enabled:l.enabled!==!1,cron:typeof l.cron==`string`&&l.cron.trim()?l.cron.trim():kt.cron,lookbackDays:Math.max(1,Mt(l.lookbackDays,kt.lookbackDays)),limit:Mt(l.limit,kt.limit),minPatternStrength:jt(Nt(l.minPatternStrength,kt.minPatternStrength),kt.minPatternStrength)}}}async function Ft(e){let t=e.frequency.trim(),n=e.timezone.trim();await Oe(U(`/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:jt(e.light.dedupeSimilarity,Dt.dedupeSimilarity)},deep:{enabled:!!e.deep.enabled,cron:e.deep.cron.trim()||null,minScore:jt(e.deep.minScore,Ot.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:jt(e.rem.minPatternStrength,kt.minPatternStrength)}}}}}}})}),Ue()}function Z(){return`text-xs font-medium text-fg-muted`}function Q(){return`text-sm font-medium text-fg`}function It(e){return e?e.replace(`T`,` `).replace(`Z`,``):`—`}function Lt(e){return e===void 0||!Number.isFinite(e)||e<0?`—`:e<1e3?`${Math.round(e)} ms`:`${(e/1e3).toFixed(2)} s`}function Rt({label:e,children:t,className:n}){return(0,Y.jsxs)(`div`,{className:a(`space-y-2`,n),children:[(0,Y.jsx)(`h3`,{className:`text-[0.7rem] font-semibold uppercase tracking-wider text-fg-muted`,children:e}),t]})}function zt({icon:e,label:t,enabled:n,cron:r,details:i,t:o}){return(0,Y.jsxs)(`div`,{className:a(J(),`space-y-1.5`),children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e,(0,Y.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:t}),(0,Y.jsx)(`span`,{className:a(`ml-auto text-xs font-medium`,n?`text-emerald-600 dark:text-emerald-400`:`text-fg-muted`),children:n?o.on:o.off})]}),(0,Y.jsx)(`div`,{className:`font-mono text-xs text-fg-muted`,children:r}),(0,Y.jsx)(`div`,{className:`text-xs text-fg-muted`,children:i})]})}function Bt({label:e,lastRun:t,t:n}){return(0,Y.jsx)(Rt,{label:e,children:t?.exists?(0,Y.jsxs)(`details`,{className:`group rounded-lg border border-edge-subtle`,children:[(0,Y.jsx)(`summary`,{className:`cursor-pointer list-none px-3 py-2 text-xs font-medium text-fg-muted marker:hidden [&::-webkit-details-marker]:hidden`,children:(0,Y.jsx)(`span`,{className:`underline decoration-edge underline-offset-2 group-open:text-fg`,children:n.lastRunRaw})}),(0,Y.jsx)(`pre`,{className:`max-h-[12rem] overflow-auto border-t border-edge-subtle p-3 text-xs text-fg-muted`,children:JSON.stringify(t.raw,null,2)})]}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.phaseLastRunEmpty})})}function Vt({t:e,r:t}){let n=t.deep?.skipped;return(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.lastRunStatus}),(0,Y.jsx)(`div`,{className:a(Q(),t.ok?`text-emerald-600 dark:text-emerald-400`:`text-amber-600 dark:text-amber-400`),children:t.ok?e.lastRunSuccess:e.lastRunFailure})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.lastRunDuration}),(0,Y.jsx)(`div`,{className:Q(),children:Lt(t.durationMs)})]}),(0,Y.jsxs)(`div`,{className:a(J(),`sm:col-span-2`),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.lastRunReason}),(0,Y.jsx)(`div`,{className:Q(),children:t.reason}),t.errorMessage?(0,Y.jsx)(`div`,{className:`mt-1 text-xs text-amber-600 dark:text-amber-400`,children:`${e.lastRunError}: ${t.errorMessage}`}):null]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.lastRunRanked}),(0,Y.jsx)(`div`,{className:Q(),children:String(t.deep?.candidatesRanked??`—`)})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.lastRunApplied}),(0,Y.jsx)(`div`,{className:Q(),children:String(t.deep?.applied??`—`)})]}),n?(0,Y.jsxs)(`div`,{className:`sm:col-span-2`,children:[(0,Y.jsx)(`div`,{className:`mb-2 text-xs font-medium text-fg`,children:e.lastRunSkipped}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.lastRunSkipKey}),(0,Y.jsx)(`div`,{className:Q(),children:String(n.alreadyPromotedKey)})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.lastRunSkipRehydrate}),(0,Y.jsx)(`div`,{className:Q(),children:String(n.rehydrateFailed)})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.lastRunSkipContaminated}),(0,Y.jsx)(`div`,{className:Q(),children:String(n.contaminated)})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.lastRunSkipHash}),(0,Y.jsx)(`div`,{className:Q(),children:String(n.hashDuplicate)})]})]})]}):null]})}function Ht(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 Ut(){let e=O(se(e=>e.language)).dreamingSettings,t=!!K(e=>e.token),{data:n}=Ye(t),[i,o]=(0,X.useState)(null),[s,l]=(0,X.useState)(null),[u,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(!1),[_,v]=(0,X.useState)(null),[y,b]=(0,X.useState)(`deep`),[S,C]=(0,X.useState)(null),[w,T]=(0,X.useState)(null),[E,D]=(0,X.useState)(!1),[k,j]=(0,X.useState)(!1),[M,N]=(0,X.useState)(null),[P,F]=(0,X.useState)(!1),[L,te]=(0,X.useState)(null),[R,ne]=(0,X.useState)(null),[z,B]=(0,X.useState)(!1),[V,ie]=(0,X.useState)(null),[ae,oe]=(0,X.useState)(null),{data:H,error:ce,isLoading:U,mutate:W}=r(t?rt():null,at,{revalidateOnFocus:!1}),le=(0,X.useMemo)(()=>H?Ht(H.lock,e):null,[H,e]),ue=(0,X.useMemo)(()=>{let e=[];return ce&&e.push(ce instanceof Error?ce.message:String(ce)),s&&e.push(s),_&&e.push(_),L&&e.push(L),V&&e.push(V),M&&e.push(M),e},[ce,s,_,L,V,M]),G=(0,X.useMemo)(()=>{let t=[];return k&&t.push(e.configSaved),h&&t.push(e.runQueued),u&&t.push(e.actionOk),t},[k,h,u,e]),de=(0,X.useCallback)(async()=>{f(!1),l(null),g(!1),v(null),j(!1),N(null),te(null),await W()},[W]),fe=(0,X.useCallback)(async()=>{F(!0),te(null);try{ne((await ct(20)).items??[])}catch(e){te(e instanceof Error?e.message:String(e))}finally{F(!1)}},[]),pe=(0,X.useCallback)(async()=>{B(!0),ie(null);try{oe(await dt(50))}catch(e){ie(e instanceof Error?e.message:String(e))}finally{B(!1)}},[]),me=(0,X.useCallback)(async(e=`deep`)=>{m(!0),g(!1),v(null);try{await $e(e),g(!0),await W()}catch(e){v(e instanceof Error?e.message:String(e))}finally{m(!1)}},[W]),ge=(0,X.useCallback)(async e=>{o(e),l(null),f(!1);try{await it(e),f(!0),await W()}catch(e){l(e instanceof Error?e.message:String(e))}finally{o(null)}},[W]),ve=!t||U||!!i,ye=(0,X.useMemo)(()=>{let e=n?.payload?.config;return Pt(e??{})},[n]);(0,X.useEffect)(()=>{if(t){if(!w){T(ye),C(ye);return}JSON.stringify(ye)!==JSON.stringify(w)&&(T(ye),C(ye))}},[w,ye,t]);let be=(0,X.useMemo)(()=>!S||!w?!1:JSON.stringify(S)!==JSON.stringify(w),[S,w]),xe=(0,X.useCallback)(async()=>{if(S){D(!0),j(!1),N(null);try{await Ft(S),T(S),j(!0),await W()}catch(e){N(e instanceof Error?e.message:String(e))}finally{D(!1)}}},[S,W]);return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:e.title}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e.subtitle})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 items-center justify-end gap-2`,children:[(0,Y.jsxs)(`select`,{className:`rounded-lg border border-edge bg-surface-panel px-2 py-1.5 text-xs text-fg`,value:y,onChange:e=>b(e.target.value),disabled:!t||p,children:[(0,Y.jsx)(`option`,{value:`light`,children:`Light`}),(0,Y.jsx)(`option`,{value:`deep`,children:`Deep`}),(0,Y.jsx)(`option`,{value:`rem`,children:`REM`})]}),(0,Y.jsxs)(q,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||p,onClick:()=>void me(y),title:e.runNowHint,children:[p?(0,Y.jsx)(d,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(Be,{className:`mr-2 size-4`,"aria-hidden":!0}),e.runNow]}),(0,Y.jsxs)(q,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t,onClick:()=>void de(),children:[(0,Y.jsx)(De,{className:`mr-2 size-4`,"aria-hidden":!0}),e.refresh]})]})]}),ue.length>0?(0,Y.jsx)(`div`,{className:`space-y-1.5 rounded-2xl border border-amber-500/20 bg-amber-500/5 px-4 py-3`,role:`alert`,children:ue.map((e,t)=>(0,Y.jsx)(`p`,{className:`text-sm text-amber-800 dark:text-amber-200/90`,children:e},t))}):null,G.length>0?(0,Y.jsx)(`div`,{className:`space-y-1.5 rounded-2xl border border-emerald-500/20 bg-emerald-500/5 px-4 py-3`,role:`status`,children:G.map((e,t)=>(0,Y.jsx)(`p`,{className:`text-sm text-emerald-800 dark:text-emerald-200/90`,children:e},t))}):null,(0,Y.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,Y.jsxs)(gt,{className:`min-w-0`,children:[(0,Y.jsx)(_t,{icon:re,title:e.configTitle,subtitle:e.configHint,trailing:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(q,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||!S||E||!be,onClick:()=>void xe(),children:[E?(0,Y.jsx)(d,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,e.saveConfig]}),(0,Y.jsx)(q,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||!S||E||!be,onClick:()=>{j(!1),N(null),C(w)},children:e.resetConfig})]})}),S?(0,Y.jsxs)(`div`,{className:`space-y-5`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-3`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configEnabled}),(0,Y.jsxs)(`label`,{className:`mt-2 inline-flex items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:S.enabled,onChange:e=>C({...S,enabled:e.target.checked})}),(0,Y.jsx)(`span`,{children:S.enabled?e.on:e.off})]})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configFrequency}),(0,Y.jsx)(`input`,{className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle dark:border-edge`,value:S.frequency,onChange:e=>C({...S,frequency:e.target.value}),placeholder:`0 3 * * *`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configTimezone}),(0,Y.jsx)(`input`,{className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle dark:border-edge`,value:S.timezone,onChange:e=>C({...S,timezone:e.target.value}),placeholder:`Asia/Shanghai`})]})]}),(0,Y.jsxs)(Rt,{label:e.configPhaseLight,children:[(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.configPhaseLightHint}),(0,Y.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configPhaseEnabled}),(0,Y.jsxs)(`label`,{className:`mt-2 inline-flex items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:S.light.enabled,onChange:e=>C({...S,light:{...S.light,enabled:e.target.checked}})}),(0,Y.jsx)(`span`,{children:S.light.enabled?e.on:e.off})]})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configPhaseCron}),(0,Y.jsx)(`input`,{className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.light.cron,onChange:e=>C({...S,light:{...S.light,cron:e.target.value}}),placeholder:`0 */6 * * *`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configLightLookbackDays}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.light.lookbackDays,onChange:e=>C({...S,light:{...S.light,lookbackDays:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configLightLimit}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:0,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.light.limit,onChange:e=>C({...S,light:{...S.light,limit:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configLightDedupe}),(0,Y.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.light.dedupeSimilarity,onChange:e=>C({...S,light:{...S.light,dedupeSimilarity:Number(e.target.value)}})})]})]})]}),(0,Y.jsxs)(Rt,{label:e.configPhaseDeep,children:[(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.configPhaseDeepHint}),(0,Y.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configPhaseEnabled}),(0,Y.jsxs)(`label`,{className:`mt-2 inline-flex items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:S.deep.enabled,onChange:e=>C({...S,deep:{...S.deep,enabled:e.target.checked}})}),(0,Y.jsx)(`span`,{children:S.deep.enabled?e.on:e.off})]})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configPhaseCron}),(0,Y.jsx)(`input`,{className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.deep.cron,onChange:e=>C({...S,deep:{...S.deep,cron:e.target.value}}),placeholder:`0 3 * * *`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configDeepMinScore}),(0,Y.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.deep.minScore,onChange:e=>C({...S,deep:{...S.deep,minScore:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configDeepMinRecallCount}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.deep.minRecallCount,onChange:e=>C({...S,deep:{...S.deep,minRecallCount:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configDeepLimit}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:0,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.deep.limit,onChange:e=>C({...S,deep:{...S.deep,limit:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configDeepHalfLife}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.deep.recencyHalfLifeDays,onChange:e=>C({...S,deep:{...S.deep,recencyHalfLifeDays:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configDeepMaxAge}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.deep.maxAgeDays,onChange:e=>C({...S,deep:{...S.deep,maxAgeDays:Number(e.target.value)}})})]})]})]}),(0,Y.jsxs)(Rt,{label:e.configPhaseRem,children:[(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.configPhaseRemHint}),(0,Y.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configPhaseEnabled}),(0,Y.jsxs)(`label`,{className:`mt-2 inline-flex items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:S.rem.enabled,onChange:e=>C({...S,rem:{...S.rem,enabled:e.target.checked}})}),(0,Y.jsx)(`span`,{children:S.rem.enabled?e.on:e.off})]})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configPhaseCron}),(0,Y.jsx)(`input`,{className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.rem.cron,onChange:e=>C({...S,rem:{...S.rem,cron:e.target.value}}),placeholder:`0 5 * * 0`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configRemLookbackDays}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.rem.lookbackDays,onChange:e=>C({...S,rem:{...S.rem,lookbackDays:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configRemLimit}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:0,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.rem.limit,onChange:e=>C({...S,rem:{...S.rem,limit:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configRemMinStrength}),(0,Y.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.rem.minPatternStrength,onChange:e=>C({...S,rem:{...S.rem,minPatternStrength:Number(e.target.value)}})})]})]})]})]}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.configLoading})]}),(0,Y.jsxs)(gt,{className:`min-w-0`,children:[(0,Y.jsx)(_t,{icon:Ve,title:e.runtimeTitle,subtitle:e.runtimeHint,trailing:U?(0,Y.jsx)(d,{className:`size-4 shrink-0 animate-spin text-fg-muted`,"aria-hidden":!0}):null}),(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsx)(Rt,{label:e.subsectionSchedule,children:(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.enabled}),(0,Y.jsx)(`div`,{className:Q(),children:H?H.config.enabled?e.on:e.off:`—`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.lock}),(0,Y.jsx)(`div`,{className:a(Q(),le?.className),children:le?le.text:`—`})]}),(0,Y.jsxs)(`div`,{className:a(J(),`sm:col-span-2`),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.schedule}),(0,Y.jsx)(`div`,{className:`mt-1 break-all font-mono text-sm text-fg`,children:H?H.config.frequency:`—`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.timezone}),(0,Y.jsx)(`div`,{className:Q(),children:H?H.config.timezone:`—`})]})]})}),(0,Y.jsx)(Rt,{label:e.subsectionStore,children:(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.storeEntries}),(0,Y.jsx)(`div`,{className:Q(),children:H?String(H.store.entryCount):`—`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.storePromoted}),(0,Y.jsx)(`div`,{className:Q(),children:H?String(H.store.promotedCount):`—`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.storeUpdatedAt}),(0,Y.jsx)(`div`,{className:Q(),children:H?It(H.store.updatedAt):`—`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.storeLastPromotedAt}),(0,Y.jsx)(`div`,{className:Q(),children:H?It(H.store.lastPromotedAt):`—`})]})]})}),H?.config?.phases?(0,Y.jsx)(Rt,{label:e.subsectionPhases,children:(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-3`,children:[(0,Y.jsx)(zt,{icon:(0,Y.jsx)(I,{className:`size-4 text-amber-500`}),label:`Light`,enabled:H.config.phases.light.enabled,cron:H.config.phases.light.cron,details:`lookback=${H.config.phases.light.lookbackDays}d, limit=${H.config.phases.light.limit}, dedupe=${H.config.phases.light.dedupeSimilarity}`,t:e}),(0,Y.jsx)(zt,{icon:(0,Y.jsx)(he,{className:`size-4 text-indigo-500`}),label:`Deep`,enabled:H.config.phases.deep.enabled,cron:H.config.phases.deep.cron,details:`minScore=${H.config.phases.deep.minScore}, recalls≥${H.config.phases.deep.minRecallCount}, limit=${H.config.phases.deep.limit}, halfLife=${H.config.phases.deep.recencyHalfLifeDays}d`,t:e}),(0,Y.jsx)(zt,{icon:(0,Y.jsx)(x,{className:`size-4 text-purple-500`}),label:`REM`,enabled:H.config.phases.rem.enabled,cron:H.config.phases.rem.cron,details:`lookback=${H.config.phases.rem.lookbackDays}d, limit=${H.config.phases.rem.limit}, strength≥${H.config.phases.rem.minPatternStrength}`,t:e})]})}):null,(0,Y.jsxs)(Rt,{label:e.subsectionLastRun,children:[(0,Y.jsx)(`p`,{className:`mb-2 text-xs text-fg-muted`,children:e.lastRunBlockHint}),H?.lastRun?.exists?(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[H.lastRun.parseError?(0,Y.jsxs)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:[e.lastRunParseError,`: `,H.lastRun.parseError]}):null,H.lastRun.record?(0,Y.jsx)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel/40 p-2 sm:p-3`,children:(0,Y.jsx)(Vt,{t:e,r:H.lastRun.record})}):null,H.lastRun.raw!==void 0&&H.lastRun.raw!==null?(0,Y.jsxs)(`details`,{className:`group rounded-lg border border-edge-subtle`,children:[(0,Y.jsx)(`summary`,{className:`cursor-pointer list-none px-3 py-2 text-xs font-medium text-fg-muted marker:hidden [&::-webkit-details-marker]:hidden`,children:(0,Y.jsx)(`span`,{className:`underline decoration-edge underline-offset-2 group-open:text-fg`,children:e.lastRunRaw})}),(0,Y.jsx)(`pre`,{className:`max-h-[12rem] overflow-auto border-t border-edge-subtle p-3 text-xs text-fg-muted`,children:JSON.stringify(H.lastRun.raw,null,2)})]}):null]}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.lastRunEmpty})]}),(0,Y.jsx)(Bt,{label:e.subsectionLightLastRun,lastRun:H?.lightLastRun,t:e}),(0,Y.jsx)(Bt,{label:e.subsectionRemLastRun,lastRun:H?.remLastRun,t:e})]})]})]}),(0,Y.jsxs)(gt,{children:[(0,Y.jsx)(_t,{icon:_e,title:e.previewTitle,subtitle:e.previewHint,trailing:(0,Y.jsxs)(q,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||P,onClick:()=>void fe(),children:[P?(0,Y.jsx)(d,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,e.previewLoad]})}),R?R.length>0?(0,Y.jsx)(`div`,{className:`space-y-2`,children:R.map(t=>{let n=`${t.path}:${t.startLine}-${t.endLine}`,r=t.skippedReason;return(0,Y.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel/60 px-3 py-3`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-fg-muted`,children:[(0,Y.jsx)(`span`,{className:`font-medium text-fg`,children:n}),(0,Y.jsxs)(`span`,{children:[`score=`,t.score.toFixed(3)]}),(0,Y.jsxs)(`span`,{children:[`recalls=`,t.recallCount]}),(0,Y.jsxs)(`span`,{children:[`avg=`,t.avgScore.toFixed(3)]}),(0,Y.jsxs)(`span`,{children:[`decay=`,t.recencyDecay?.toFixed(3)??`—`]}),r?(0,Y.jsx)(`span`,{className:`text-amber-600 dark:text-amber-400`,children:r}):(0,Y.jsx)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:e.previewEligible})]}),t.snippet?(0,Y.jsx)(`div`,{className:`mt-2 text-sm text-fg`,children:t.snippet}):null]},`${t.key}:${t.hash}:${n}`)})}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.previewEmpty}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.previewNotLoaded})]}),(0,Y.jsxs)(gt,{children:[(0,Y.jsx)(_t,{icon:Ve,title:e.eventsTitle,subtitle:e.eventsHint,trailing:(0,Y.jsxs)(q,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||z,onClick:()=>void pe(),children:[z?(0,Y.jsx)(d,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,e.eventsLoad]})}),ae?ae.length>0?(0,Y.jsx)(`div`,{className:`space-y-1.5`,children:ae.map((e,t)=>{let n=e.phase===`light`?`☀️`:e.phase===`rem`?`✨`:`🌙`,r=e.phase===`light`?`scanned=${e.scannedEntries??0} new=${e.newSignals??0} deduped=${e.deduped??0}`:e.phase===`rem`?`patterns=${e.patternsDiscovered??0} analyzed=${e.entriesAnalyzed??0}`:`candidates=${e.candidates??0} applied=${e.applied??0}`;return(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 rounded-lg border border-edge-subtle bg-surface-panel/60 px-3 py-2 text-xs`,children:[(0,Y.jsx)(`span`,{children:n}),(0,Y.jsx)(`span`,{className:`font-medium text-fg`,children:e.phase}),(0,Y.jsx)(`span`,{className:a(`font-medium`,e.ok?`text-emerald-600 dark:text-emerald-400`:`text-amber-600 dark:text-amber-400`),children:e.ok?`OK`:`FAIL`}),(0,Y.jsx)(`span`,{className:`text-fg-muted`,children:r}),(0,Y.jsx)(`span`,{className:`text-fg-muted`,children:Lt(e.durationMs)}),(0,Y.jsx)(`span`,{className:`ml-auto text-fg-subtle`,children:It(e.timestamp)})]},`${e.timestamp}:${e.phase}:${t}`)})}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.eventsEmpty}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.eventsNotLoaded})]}),(0,Y.jsxs)(gt,{className:`max-w-2xl`,children:[(0,Y.jsx)(_t,{icon:A,title:e.maintenanceTitle,subtitle:e.maintenanceHint}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,Y.jsxs)(q,{variant:`secondary`,disabled:ve,onClick:()=>{confirm(e.confirmResetStore)&&ge(`reset_store`)},children:[i===`reset_store`?(0,Y.jsx)(d,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(c,{className:`mr-2 size-4`,"aria-hidden":!0}),e.resetStore]}),(0,Y.jsxs)(q,{variant:`secondary`,disabled:ve,onClick:()=>{confirm(e.confirmClearLock)&&ge(`clear_lock`)},children:[i===`clear_lock`?(0,Y.jsx)(d,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(ee,{className:`mr-2 size-4`,"aria-hidden":!0}),e.clearLock]})]})]})]})}var Wt=e(vt(),1);function Gt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Kt(e){let t=Gt(e)?e:{},n=Gt(t.gateway)?t.gateway:{},r=Gt(n.auth)?n.auth:{},i=r.mode===`none`||r.mode===`token`?r.mode:`token`,a=(Gt(t.update)?t.update:{}).channel,o=a===`beta`||a===`dev`||a===`stable`?a:`stable`;return{host:typeof n.host==`string`?n.host:``,port:typeof n.port==`number`?n.port:void 0,auth:{mode:i,token:typeof r.token==`string`?r.token:``},updateChannel:o}}async function qt(e){let t=e.auth.token.trim().length>0?{mode:e.auth.mode,token:e.auth.token}:{mode:e.auth.mode};await Oe(U(`/api/config`),{method:`PATCH`,body:JSON.stringify({gateway:{auth:t},update:{channel:e.updateChannel}})}),Ue()}function Jt(){return a(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,f,`dark:border-edge`)}function Yt(){let e=se(e=>e.language),t=O(e),n=t.gatewaySettings,r=K(e=>e.token),i=K(e=>e.tokenExpired),a=K(e=>e.openTokenDialog),s=!!r,[c,l]=(0,X.useState)(null),[u,f]=(0,X.useState)(null),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(null),[_,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(!1),[S,C]=(0,X.useState)(!1),w=(0,X.useRef)(!1),{data:T,error:E,isLoading:D,mutate:k}=Ye(s),A=(0,X.useMemo)(()=>T?.payload?.config===void 0?null:structuredClone(Kt(T.payload.config)),[T]);(0,X.useEffect)(()=>{if(!s){l(null),f(null),w.current=!1;return}A!==null&&(w.current||(l(A),f(structuredClone(A)),y(!1)))},[s,A]);let j=!!(s&&D&&T===void 0&&!E),M=E instanceof Error?E.message:E?String(E):null,N=(0,X.useMemo)(()=>!c||!u?!1:JSON.stringify(c)!==JSON.stringify(u),[c,u]),ee=(0,X.useCallback)(e=>{w.current=!0,l(t=>t?{...t,auth:{...t.auth,...e}}:null)},[]),P=(0,X.useCallback)(e=>{w.current=!0,l(t=>t?{...t,updateChannel:e}:null)},[]),F=(0,X.useCallback)(async()=>{if(!(!c||p)){m(!0),g(null),y(!1);try{await qt(c),w.current=!1,f(structuredClone(c)),y(!0),window.setTimeout(()=>y(!1),2500)}catch(e){g(e instanceof Error?e.message:n.saveError)}finally{m(!1)}}},[c,p,n.saveError]),I=(0,X.useCallback)(()=>{u&&(w.current=!1,l(structuredClone(u)),g(null),y(!1))},[u]),L=(0,X.useCallback)(async()=>{let e=c?.auth.token;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),C(!0),window.setTimeout(()=>C(!1),2e3))},[c?.auth.token]);return s?j?(0,Y.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,Y.jsx)(d,{className:`size-4 animate-spin`}),n.loading]})}):c?(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.gateway}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,Y.jsxs)(`a`,{href:fe(e,`gateway`),target:`_blank`,rel:`noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-sm text-accent hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,children:[n.docsLink,(0,Y.jsx)(v,{className:`size-3.5`})]})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[_?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,Y.jsx)(q,{type:`button`,variant:`secondary`,disabled:!N||p,onClick:I,children:n.discard}),(0,Y.jsx)(q,{type:`button`,variant:`primary`,disabled:!N||p,onClick:()=>void F(),children:p?n.saving:n.save})]})]}),i?(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-lg border border-red-200 bg-red-50 px-4 py-3 dark:border-red-900/50 dark:bg-red-950/40`,role:`alert`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(ie,{className:`mt-0.5 size-4 shrink-0 text-red-600 dark:text-red-400`}),(0,Y.jsx)(`p`,{className:`text-sm text-red-900 dark:text-red-100`,children:n.tokenExpired})]}),(0,Y.jsx)(`div`,{children:(0,Y.jsx)(q,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:()=>a(),children:n.updateToken})})]}):null,N?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,h?(0,Y.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:h}):null,c.auth.mode===`none`?(0,Y.jsx)(`p`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-950 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-100`,children:n.authModeNone}):null,(0,Y.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[(0,Y.jsxs)(`div`,{className:`mb-5 flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)(o,{className:`size-4 text-accent`,strokeWidth:1.75}),t.settingsSections.gateway]}),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(c.host||c.port!=null)&&(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:n.listenHost}),(0,Y.jsx)(`div`,{className:`rounded-lg bg-surface-hover/80 px-3 py-2 font-mono text-xs text-fg-muted dark:bg-surface-hover/50`,children:c.host||`—`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:n.listenPort}),(0,Y.jsx)(`div`,{className:`rounded-lg bg-surface-hover/80 px-3 py-2 font-mono text-xs text-fg-muted dark:bg-surface-hover/50`,children:c.port==null?`—`:String(c.port)})]}),(0,Y.jsx)(`p`,{className:`sm:col-span-2 text-xs text-fg-subtle`,children:n.listenHint})]}),(0,Y.jsx)(Zt,{g:n,value:c.auth.token,show:b,copied:S,onToggleShow:()=>x(e=>!e),onCopy:()=>void L(),onChange:e=>ee({token:e})}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,onClick:()=>a(),children:n.changeToken}),r?(0,Y.jsx)(Xt,{g:n,gatewayToken:r}):null,(0,Y.jsxs)(`div`,{className:`space-y-2 border-t border-edge pt-4`,children:[(0,Y.jsx)(`label`,{className:`text-sm font-medium text-fg`,htmlFor:`gateway-update-channel`,children:n.updateChannel}),(0,Y.jsxs)(`select`,{id:`gateway-update-channel`,value:c.updateChannel,onChange:e=>P(e.target.value),className:Jt(),children:[(0,Y.jsx)(`option`,{value:`stable`,children:n.channelStable}),(0,Y.jsx)(`option`,{value:`beta`,children:n.channelBeta}),(0,Y.jsx)(`option`,{value:`dev`,children:n.channelDev})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.updateChannelHint})]})]})]})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:h??M??n.loadError}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,onClick:()=>void k(),children:n.retry})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.gateway}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}function Xt({g:e,gatewayToken:t}){let[n,r]=(0,X.useState)(ze),[i,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(!1),[l,u]=(0,X.useState)(!1),d=n.trim(),f=(0,X.useMemo)(()=>{try{let e=new URL(d);return e.protocol===`http:`||e.protocol===`https:`}catch{return!1}},[d]),p=(0,X.useMemo)(()=>!t||!f?``:Se({baseUrl:d,gatewayToken:t}),[f,t,d]);(0,X.useEffect)(()=>{if(!p){o(null),c(!1);return}let e=!1;return c(!1),Wt.toDataURL(p,{width:216,margin:2,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}}).then(t=>{e||o(t)}).catch(()=>{e||(c(!0),o(null))}),()=>{e=!0}},[p]);let m=f&&le(d),h=(0,X.useCallback)(async()=>{p&&(await navigator.clipboard.writeText(p).catch(()=>{}),u(!0),window.setTimeout(()=>u(!1),2e3))},[p]);return(0,Y.jsxs)(`div`,{className:`space-y-3 border-t border-edge pt-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)(Ae,{className:`size-4 text-accent`,strokeWidth:1.75}),e.mobilePairTitle]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.mobilePairSubtitle}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{className:`text-sm font-medium text-fg`,htmlFor:`gateway-mobile-pair-base`,children:e.mobilePairBaseUrlLabel}),(0,Y.jsx)(`input`,{id:`gateway-mobile-pair-base`,className:a(Jt(),`font-mono text-xs`),type:`text`,autoComplete:`off`,spellCheck:!1,value:n,onChange:e=>r(e.target.value)}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.mobilePairBaseUrlHint}),f?null:(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:e.mobilePairInvalidBaseUrl}),m?(0,Y.jsx)(`p`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-950 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-100`,children:e.mobilePairLocalhostWarning}):null,(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.mobilePairSecurityNote})]}),p?(0,Y.jsxs)(`div`,{className:`flex flex-col items-center gap-3 sm:items-start`,children:[i&&!s?(0,Y.jsx)(`img`,{src:i,alt:``,className:`h-56 w-56 rounded-lg border border-edge-subtle bg-white object-contain p-3 dark:border-edge`}):null,!i&&!s?(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.mobilePairEncoding}):null,s?(0,Y.jsx)(`p`,{className:`text-center text-sm text-fg-muted sm:text-left`,children:e.mobilePairImageError}):null,(0,Y.jsxs)(q,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,disabled:!p,onClick:()=>void h(),children:[l?(0,Y.jsx)(Re,{className:`size-3.5`}):(0,Y.jsx)(ne,{className:`size-3.5`}),l?e.mobilePairCopied:e.mobilePairCopyLink]})]}):null,(0,Y.jsx)(`p`,{className:`break-all font-mono text-[10px] leading-relaxed text-fg-subtle`,children:e.mobilePairSchemeHint})]})}function Zt({g:e,value:t,show:n,copied:r,onToggleShow:i,onCopy:o,onChange:s}){return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.accessToken}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Y.jsx)(`input`,{className:a(Jt(),`min-w-0 flex-1 font-mono text-xs`),type:n?`text`:`password`,autoComplete:`off`,value:t,onChange:e=>s(e.target.value),placeholder:e.tokenPlaceholder}),t?(0,Y.jsxs)(q,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:o,children:[r?(0,Y.jsx)(Re,{className:`size-3.5`}):(0,Y.jsx)(ne,{className:`size-3.5`}),r?e.copied:e.copy]}):null,(0,Y.jsxs)(q,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:i,children:[n?(0,Y.jsx)(te,{className:`size-3.5`}):(0,Y.jsx)(L,{className:`size-3.5`}),n?e.hide:e.show]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tokenHelp})]})}function Qt(){return U(`/api/channels/status`)}var $t=Xe;function en(){return U(`/api/workspace/heartbeat-md`)}async function tn(){let e=await Oe(en());return typeof e.payload?.content==`string`?e.payload.content:``}function nn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function rn(e){let t=nn(e)?e:{},n=nn(t.gateway)?t.gateway:{},r=nn(n.heartbeat)?n.heartbeat:{},i=r.activeHours,a=nn(i)?i:null,o=a&&typeof a.start==`string`&&typeof a.end==`string`&&a.start&&a.end?{start:a.start,end:a.end,timezone:typeof a.timezone==`string`?a.timezone:``}:null;return{enabled:!!(r.enabled??!0),intervalMs:typeof r.intervalMs==`number`&&Number.isFinite(r.intervalMs)?r.intervalMs:18e5,target:typeof r.target==`string`?r.target:``,targetChatId:typeof r.targetChatId==`string`?r.targetChatId:``,prompt:typeof r.prompt==`string`?r.prompt:``,ackMaxChars:typeof r.ackMaxChars==`number`&&Number.isFinite(r.ackMaxChars)?r.ackMaxChars:``,isolatedSession:!!r.isolatedSession,activeHours:o}}function an(e){let t={enabled:e.enabled,intervalMs:e.intervalMs};return e.target.trim()?t.target=e.target.trim():t.target=null,e.targetChatId.trim()?t.targetChatId=e.targetChatId.trim():t.targetChatId=null,e.prompt.trim()?t.prompt=e.prompt.trim():t.prompt=null,e.ackMaxChars===``||e.ackMaxChars===void 0?t.ackMaxChars=null:t.ackMaxChars=e.ackMaxChars,e.isolatedSession?t.isolatedSession=!0:t.isolatedSession=null,e.activeHours?.start?.trim()&&e.activeHours?.end?.trim()?t.activeHours={start:e.activeHours.start.trim(),end:e.activeHours.end.trim(),...e.activeHours.timezone.trim()?{timezone:e.activeHours.timezone.trim()}:{}}:t.activeHours=null,t}async function on(e){await Oe(U(`/api/config`),{method:`PATCH`,body:JSON.stringify({gateway:{heartbeat:an(e)}})}),Ue()}async function sn(e){await Oe(U(`/api/workspace/heartbeat-md`),{method:`PUT`,body:JSON.stringify({content:e})}),i(en())}async function cn(e){await Oe(U(`/api/heartbeat/trigger`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e?{reason:e}:{})})}var ln=[3e4,6e4,3e5,6e5,9e5,18e5,36e5,72e5],un=new Set(ln);function dn(){return a(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,f,`dark:border-edge`)}function fn(){return a(m,We)}function pn(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 mn(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 hn(){let e=se(e=>e.language),t=O(e),n=t.heartbeatSettings,i=!!K(e=>e.token),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),[u,f]=(0,X.useState)(``),[p,m]=(0,X.useState)(``),[h,_]=(0,X.useState)(!1),[y,b]=(0,X.useState)(!1),[x,S]=(0,X.useState)(null),[C,w]=(0,X.useState)(!1),[T,E]=(0,X.useState)(!1),[D,k]=(0,X.useState)(!1),[A,j]=(0,X.useState)(!1),[M,N]=(0,X.useState)(null),[ee,P]=(0,X.useState)([]),{data:F,error:I,isLoading:L,mutate:te}=Ye(i),{data:R,error:ne,isLoading:z,mutate:B}=r(i?en():null,tn,{revalidateOnFocus:!1}),{data:re=[]}=r(i?Qt():null,$t,{revalidateOnFocus:!1}),V=(0,X.useMemo)(()=>pn(F?.payload?.config),[F]),ie=(0,X.useMemo)(()=>rn(F?.payload?.config??{}),[F]),ae=(0,X.useMemo)(()=>!o||!c?!1:JSON.stringify(o)!==JSON.stringify(c),[o,c]),oe=(0,X.useMemo)(()=>u!==p,[u,p]);(0,X.useEffect)(()=>{if(!i){s(null),l(null);return}if(F!==void 0&&!ae){let e=structuredClone(ie);s(e),l(e),w(!1)}},[i,F,ie,ae]),(0,X.useEffect)(()=>{!i||R===void 0||oe||(f(R),m(R),E(!1))},[i,R,oe]);let H=I instanceof Error?I.message:I?String(I):ne instanceof Error?ne.message:ne?String(ne):null,ce=!!(i&&(F===void 0||R===void 0)&&!H&&(L||z));(0,X.useEffect)(()=>{if(!i||!o){P([]);return}let e=o.target.trim();if(!e){P([]);return}let t=!1;return Ze(e).then(e=>{t||P(e)}),()=>{t=!0}},[i,o?.target]);let U=(0,X.useCallback)(()=>{let e=o?.target?.trim();e&&Ze(e).then(P)},[o?.target]),W=(0,X.useCallback)(async()=>{k(!0),j(!1),N(null);try{await cn(),j(!0),window.setTimeout(()=>j(!1),3e3)}catch(e){N(e instanceof Error?e.message:n.triggerError)}finally{k(!1)}},[n.triggerError]),le=(0,X.useCallback)(e=>{s(t=>t?{...t,...e}:null)},[]),ue=(0,X.useCallback)(()=>{c&&(s(structuredClone(c)),w(!1),S(null))},[c]),G=(0,X.useCallback)(()=>{f(p),E(!1),S(null)},[p]),de=(0,X.useCallback)(async()=>{if(!(!o||h)){_(!0),S(null),w(!1);try{await on(o),l(structuredClone(o)),w(!0),window.setTimeout(()=>w(!1),2500)}catch(e){S(e instanceof Error?e.message:n.saveConfigError)}finally{_(!1)}}},[o,h,n.saveConfigError]),pe=(0,X.useCallback)(async()=>{if(!y){b(!0),S(null),E(!1);try{await sn(u),m(u),E(!0),window.setTimeout(()=>E(!1),2500)}catch(e){S(e instanceof Error?e.message:n.saveDocError)}finally{b(!1)}}},[u,y,n.saveDocError]);return i?ce?(0,Y.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,Y.jsx)(d,{className:`size-4 animate-spin`}),n.loading]})}):o?(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Y.jsx)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.heartbeat}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,Y.jsxs)(`a`,{href:fe(e,`heartbeat`),target:`_blank`,rel:`noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-sm text-accent hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,children:[n.docsLink,(0,Y.jsx)(v,{className:`size-3.5`})]})]})}),V?(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.workspaceLabel,`: `,(0,Y.jsx)(`span`,{className:`font-mono text-fg-muted`,children:V})]}):null,x?(0,Y.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:x}):null,(0,Y.jsxs)(gt,{children:[(0,Y.jsxs)(`div`,{className:`mb-2 flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)(g,{className:`size-4 text-accent`,strokeWidth:1.75}),n.configSection]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsxs)(q,{type:`button`,variant:`secondary`,className:`inline-flex items-center gap-2`,disabled:D,onClick:()=>void W(),children:[D?(0,Y.jsx)(d,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(Be,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),D?n.triggering:n.triggerNow]}),A?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.triggered}):null]})]}),(0,Y.jsx)(`p`,{className:`mb-4 text-xs text-fg-subtle`,children:n.triggerHint}),M?(0,Y.jsx)(`p`,{className:`mb-3 text-sm text-red-600 dark:text-red-400`,children:M}):null,(0,Y.jsx)(gn,{h:n,cron:t.cron,form:o,channels:re,sessionChatIds:ee,onRefreshChatIds:U,update:le,inputClassName:dn,selectClassName:fn}),(0,Y.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-2`,children:[C?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.savedConfig}):null,(0,Y.jsx)(q,{type:`button`,variant:`secondary`,disabled:!ae||h,onClick:ue,children:n.discard}),(0,Y.jsx)(q,{type:`button`,variant:`primary`,disabled:!ae||h,onClick:()=>void de(),children:h?n.savingConfig:n.saveConfig}),ae?(0,Y.jsx)(`span`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedConfig}):null]})]}),(0,Y.jsxs)(gt,{children:[(0,Y.jsx)(`div`,{className:`mb-2 text-sm font-semibold text-fg`,children:n.docSection}),(0,Y.jsx)(`p`,{className:`mb-3 text-xs text-fg-subtle`,children:n.docHint}),(0,Y.jsx)(`textarea`,{className:a(dn(),`min-h-[12rem] resize-y font-mono text-xs leading-relaxed`),value:u,onChange:e=>f(e.target.value),spellCheck:!1,"aria-label":n.docSection}),(0,Y.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-2`,children:[T?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.savedDoc}):null,(0,Y.jsx)(q,{type:`button`,variant:`secondary`,disabled:!oe||y,onClick:G,children:n.discard}),(0,Y.jsx)(q,{type:`button`,variant:`primary`,disabled:!oe||y,onClick:()=>void pe(),children:y?n.savingDoc:n.saveDoc}),oe?(0,Y.jsx)(`span`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedDoc}):null]})]})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:x??H??n.loadError}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,onClick:()=>{te(),B()},children:n.retry})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.heartbeat}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}function gn({h:e,cron:t,form:n,channels:r,sessionChatIds:i,onRefreshChatIds:o,update:s,inputClassName:c,selectClassName:l}){let u=(0,X.useMemo)(()=>new Set(r.map(e=>e.name)),[r]),d=n.target.trim(),f=!!(d&&!u.has(d)),p=(0,X.useMemo)(()=>un.has(n.intervalMs)?String(n.intervalMs):``,[n.intervalMs]),[m,h]=(0,X.useState)(null),g=Math.max(1,Math.round(n.intervalMs/1e3)),_=m===null?String(g):m;return(0,X.useEffect)(()=>{h(null)},[n.intervalMs]),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:n.enabled,onChange:e=>s({enabled:e.target.checked})}),e.enable]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.interval}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:e.intervalSecondsLabel}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`input`,{type:`number`,min:1,step:1,className:a(c(),`min-w-0 flex-1`),value:_,onChange:e=>{let t=e.target.value;h(t);let n=parseInt(t,10);Number.isFinite(n)&&n>=1&&s({intervalMs:n*1e3})},onBlur:()=>{if(m===null)return;let e=parseInt(m,10);s(!Number.isFinite(e)||e<1?{intervalMs:1e3}:{intervalMs:e*1e3}),h(null)}}),(0,Y.jsxs)(`select`,{className:a(l(),`max-w-[11rem] shrink-0 text-xs`),value:p,onChange:e=>{let t=e.target.value;t&&(s({intervalMs:parseInt(t,10)}),h(null))},children:[(0,Y.jsx)(`option`,{value:``,children:e.intervalPresets.custom}),ln.map(t=>(0,Y.jsx)(`option`,{value:String(t),children:mn(t,e.intervalPresets)},t))]})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.intervalHintPreset}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.intervalHint})]}),(0,Y.jsxs)(`div`,{className:`border-t border-edge-subtle pt-4`,children:[(0,Y.jsx)(`div`,{className:`mb-2 text-sm font-medium text-fg`,children:e.deliveryTitle}),(0,Y.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:t.channel}),(0,Y.jsxs)(`select`,{className:l(),value:d,onChange:e=>{s({target:e.target.value.trim(),targetChatId:``})},children:[(0,Y.jsx)(`option`,{value:``,children:e.channelNone}),f?(0,Y.jsxs)(`option`,{value:d,children:[d,` (`,e.customChannelSuffix,`)`]}):null,r.map(e=>(0,Y.jsxs)(`option`,{value:e.name,disabled:!e.enabled,children:[e.name,` `,e.enabled?``:`(disabled)`]},e.name))]})]}),d?(0,Y.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:t.recipient}),(0,Y.jsxs)(q,{type:`button`,variant:`ghost`,className:`h-7 gap-1 px-2 text-xs`,title:t.refreshRecipientHint,onClick:o,children:[(0,Y.jsx)(De,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0}),t.refreshList]})]}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`input`,{type:`text`,className:a(c(),`min-w-0 flex-1`),value:n.targetChatId,onChange:e=>s({targetChatId:e.target.value}),placeholder:t.recipientPlaceholder,autoComplete:`off`}),(0,Y.jsxs)(`select`,{className:a(l(),`max-w-[10rem] shrink-0 text-xs`),value:n.targetChatId,onChange:e=>{let t=e.target.value;t&&s({targetChatId:t})},children:[(0,Y.jsx)(`option`,{value:``,children:t.selectRecipient}),i.length>0?i.map(e=>(0,Y.jsx)(`option`,{value:e.chatId,children:Qe(e,t.lastActiveLabels)},`${e.channel}-${e.chatId}`)):(0,Y.jsx)(`option`,{value:``,disabled:!0,children:t.noRecentChatsOption})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:i.length>0?t.enterManuallyOrSelect:t.noRecentChats})]}):null,(0,Y.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:e.deliveryHint})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:e.prompt}),(0,Y.jsx)(`textarea`,{className:a(c(),`min-h-[4.5rem] resize-y font-mono text-xs`),value:n.prompt,onChange:e=>s({prompt:e.target.value}),placeholder:e.promptPlaceholder}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:e.promptHint})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:e.ackMaxChars}),(0,Y.jsx)(`input`,{type:`number`,min:1,className:c(),value:n.ackMaxChars===``?``:n.ackMaxChars,onChange:e=>{let t=e.target.value;if(t===``)s({ackMaxChars:``});else{let e=parseInt(t,10);s({ackMaxChars:Number.isFinite(e)?e:``})}},placeholder:e.ackDefaultPlaceholder}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:e.ackMaxCharsHint})]}),(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:n.isolatedSession,onChange:e=>s({isolatedSession:e.target.checked})}),(0,Y.jsxs)(`span`,{children:[e.isolatedSession,(0,Y.jsx)(`span`,{className:`mt-1 block text-xs text-fg-subtle`,children:e.isolatedSessionHint})]})]}),(0,Y.jsxs)(`div`,{className:`border-t border-edge-subtle pt-4`,children:[(0,Y.jsx)(`div`,{className:`mb-2 text-sm font-medium text-fg`,children:e.activeHoursTitle}),n.activeHours?(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-xs text-fg`,children:e.activeStart}),(0,Y.jsx)(`input`,{className:c(),value:n.activeHours.start,onChange:e=>s({activeHours:{...n.activeHours,start:e.target.value}}),placeholder:`09:00`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-xs text-fg`,children:e.activeEnd}),(0,Y.jsx)(`input`,{className:c(),value:n.activeHours.end,onChange:e=>s({activeHours:{...n.activeHours,end:e.target.value}}),placeholder:`22:00`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-xs text-fg`,children:e.activeTimezone}),(0,Y.jsx)(`input`,{className:c(),value:n.activeHours.timezone,onChange:e=>s({activeHours:{...n.activeHours,timezone:e.target.value}}),placeholder:`Asia/Shanghai`})]})]}):(0,Y.jsx)(q,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:()=>s({activeHours:{start:`09:00`,end:`22:00`,timezone:``}}),children:e.addActiveHours}),n.activeHours?(0,Y.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:(0,Y.jsx)(q,{type:`button`,variant:`secondary`,className:`text-xs`,onClick:()=>s({activeHours:null}),children:e.clearActiveHours})}):null,(0,Y.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:e.activeHoursHint})]})]})}async function _n(){let e=await G(U(`/api/image/providers`));if(!e.ok)throw Error(`Image providers: HTTP ${e.status}`);return(await e.json()).payload?.providers??[]}function vn(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 yn(e,t){let n=vn(e.filter(e=>e.configured===!0));return!t||n.includes(t)?n:[t,...n]}function bn(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 xn=`image-generation-providers`;function Sn({value:e,disabled:t,placeholder:n,searchPlaceholder:i,noMatches:o,registryEmptyHint:s,outOfFilterNote:c,className:l,onChange:d}){let[f,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)(``),{data:g,isLoading:v,error:x}=r(xn,_n,{revalidateOnFocus:!1}),S=e.trim(),C=(0,X.useMemo)(()=>vn((g??[]).filter(e=>e.configured===!0)),[g]),w=(0,X.useMemo)(()=>yn(g??[],S),[g,S]),T=(0,X.useMemo)(()=>bn(w,m),[w,m]),E=!!c&&!!S&&!C.includes(S),O=e.trim()?e:n,k=e.trim()||n,A=(0,X.useCallback)(e=>{p(e),e||h(``)},[]);return(0,Y.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,Y.jsxs)(_,{open:f,onOpenChange:A,modal:!1,children:[(0,Y.jsx)(y,{asChild:!0,children:(0,Y.jsxs)(`button`,{type:`button`,disabled:t||v,title:v?`…`:k,className:a(N,`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`,b.transition,`hover:border-edge hover:bg-surface-hover/45`,P,`disabled:cursor-not-allowed disabled:opacity-50`,`dark:border-edge-subtle dark:hover:bg-surface-hover/55`,l),"aria-haspopup":`listbox`,"aria-expanded":f,children:[(0,Y.jsx)(`span`,{className:`min-w-0 truncate`,children:v?`…`:O}),(0,Y.jsx)(Ee,{className:`h-4 w-4 shrink-0 text-fg-subtle opacity-70`,"aria-hidden":!0})]})}),(0,Y.jsx)(M,{children:(0,Y.jsxs)(D,{className:`z-50 w-[min(22rem,calc(100vw-2rem))] rounded-xl border border-edge-subtle bg-surface-panel p-1 shadow-elevated dark:border-edge-subtle`,side:`bottom`,sideOffset:4,align:`end`,onOpenAutoFocus:e=>e.preventDefault(),children:[(0,Y.jsx)(`input`,{type:`search`,className:a(`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`,u),placeholder:i,value:m,onChange:e=>h(e.target.value),onKeyDown:e=>e.stopPropagation()}),(0,Y.jsxs)(`div`,{className:`max-h-60 overflow-auto`,role:`listbox`,"aria-label":i,children:[x?(0,Y.jsx)(`div`,{className:`px-2 py-2 text-xs text-red-600 dark:text-red-400`,children:x instanceof Error?x.message:`Failed to load image providers`}):null,!x&&w.length===0&&!v?(0,Y.jsx)(`div`,{className:`px-2 py-3 text-center text-xs text-fg-muted`,children:s??o}):null,!x&&w.length>0&&T.length===0?(0,Y.jsx)(`div`,{className:`px-2 py-3 text-center text-xs text-fg-muted`,children:o}):null,T.map(t=>(0,Y.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t===e,className:a(`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-fg hover:bg-surface-hover`,t===e&&`bg-surface-hover/90 font-medium dark:bg-surface-hover/70`),onClick:()=>{d(t),p(!1),h(``)},children:[(0,Y.jsx)(Re,{className:a(`h-4 w-4 shrink-0`,t!==e&&`invisible`),"aria-hidden":!0}),(0,Y.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm font-medium`,children:t})]},t))]})]})})]}),E?(0,Y.jsx)(`p`,{className:`text-xs text-amber-700 dark:text-amber-400/90`,children:c}):null]})}function Cn(e){let{a:t,chat:n,form:r,update:i}=e;return(0,Y.jsxs)(gt,{children:[(0,Y.jsx)(_t,{icon:j,title:t.cardModelsTitle,subtitle:t.cardModelsSubtitle}),(0,Y.jsxs)(`div`,{className:`mt-4 flex flex-col gap-5`,children:[(0,Y.jsx)(nt,{label:t.label.imageModel,description:t.desc.imageModel,children:(0,Y.jsx)(Ce,{value:r.imageModel,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,capabilitiesFilter:`vision`,registryEmptyHint:t.visionRegistryEmpty,outOfFilterNote:t.visionOutOfFilterNote,onChange:e=>i({imageModel:e})})}),(0,Y.jsx)(nt,{label:t.label.imageModelFallbacks,description:t.desc.imageModelFallbacks,children:(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[r.imageModelFallbacks.map((e,a)=>(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Y.jsx)(Ce,{value:e,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,capabilitiesFilter:`vision`,registryEmptyHint:t.visionRegistryEmpty,outOfFilterNote:t.visionOutOfFilterNote,onChange:e=>{let t=[...r.imageModelFallbacks];t[a]=e,i({imageModelFallbacks:t})}})}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":t.removeModelFallback,onClick:()=>i({imageModelFallbacks:r.imageModelFallbacks.filter((e,t)=>t!==a)}),children:(0,Y.jsx)(c,{className:`size-4`,strokeWidth:1.75})})]},a)),(0,Y.jsxs)(q,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:()=>i({imageModelFallbacks:[...r.imageModelFallbacks,``]}),children:[(0,Y.jsx)(W,{className:`size-4 shrink-0`,strokeWidth:1.75}),t.addModelFallback]})]})}),(0,Y.jsx)(nt,{label:t.label.imageGenerationModel,description:t.desc.imageGenerationModel,children:(0,Y.jsx)(Sn,{value:r.imageGenerationModel,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,registryEmptyHint:t.imageGenRegistryEmpty,outOfFilterNote:t.imageGenOutOfFilterNote,onChange:e=>i({imageGenerationModel:e})})}),(0,Y.jsx)(nt,{label:t.label.imageGenerationModelFallbacks,description:t.desc.imageGenerationModelFallbacks,children:(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[r.imageGenerationModelFallbacks.map((e,a)=>(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Y.jsx)(Sn,{value:e,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,registryEmptyHint:t.imageGenRegistryEmpty,outOfFilterNote:t.imageGenOutOfFilterNote,onChange:e=>{let t=[...r.imageGenerationModelFallbacks];t[a]=e,i({imageGenerationModelFallbacks:t})}})}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":t.removeModelFallback,onClick:()=>i({imageGenerationModelFallbacks:r.imageGenerationModelFallbacks.filter((e,t)=>t!==a)}),children:(0,Y.jsx)(c,{className:`size-4`,strokeWidth:1.75})})]},a)),(0,Y.jsxs)(q,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:()=>i({imageGenerationModelFallbacks:[...r.imageGenerationModelFallbacks,``]}),children:[(0,Y.jsx)(W,{className:`size-4 shrink-0`,strokeWidth:1.75}),t.addModelFallback]})]})})]})]})}function wn(){return a(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,f)}var Tn=`/api/image/providers`;function En(e){return{imageModel:e.imageModel,imageModelFallbacks:e.imageModelFallbacks,imageGenerationModel:e.imageGenerationModel,imageGenerationModelFallbacks:e.imageGenerationModelFallbacks,imageGenerationModelTimeoutMs:e.imageGenerationModelTimeoutMs,imageGenerationModelAutoProviderFallback:e.imageGenerationModelAutoProviderFallback}}async function Dn(){return(await Oe(U(Tn)))?.payload?.providers??[]}function On(){let e=se(e=>e.language),t=O(e),n=t.imageModelsSettings,i=!!K(e=>e.token),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(null),[f,p]=(0,X.useState)(!0),[m,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(!1),[v,y]=(0,X.useState)(void 0),b=(0,X.useCallback)(async()=>{if(i){p(!0),y(void 0);try{let e=await tt(),t=structuredClone(e);c(t),u(structuredClone(t))}catch(e){y(e instanceof Error?e.message:String(e))}finally{p(!1)}}},[i]);(0,X.useEffect)(()=>{b()},[b]);let x=(0,X.useCallback)(e=>{c(t=>t?{...t,...e}:null)},[]),{data:S=[],mutate:C}=r(i?Tn:null,Dn,{revalidateOnFocus:!1}),w=Ye(i),T=(0,X.useMemo)(()=>!s||!l?!1:JSON.stringify(En(s))!==JSON.stringify(En(l)),[s,l]),E=(0,X.useCallback)(async()=>{if(s){h(!0),y(void 0);try{try{st(s.paramsJson)}catch(e){y(e instanceof SyntaxError?t.agentSettings.advanced.paramsInvalidJson:e instanceof Error?e.message:t.agentSettings.advanced.paramsInvalidJson);return}await ht(s),u(structuredClone(s)),_(!0),window.setTimeout(()=>_(!1),1500),w.mutate?.()}catch(e){y(e instanceof Error?e.message:String(e))}finally{h(!1)}}},[s,w,t.agentSettings]),D=(0,X.useCallback)(()=>{l&&(c(structuredClone(l)),y(void 0),_(!1))},[l]);return i?f||!s?(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main items-center gap-2 px-4 py-8 text-sm text-fg-muted`,children:[(0,Y.jsx)(d,{className:`size-4 animate-spin`}),` Loading…`]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.title}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[(0,Y.jsxs)(q,{type:`button`,variant:`ghost`,onClick:()=>{b(),C()},children:[(0,Y.jsx)(De,{className:`size-3.5`}),(0,Y.jsx)(`span`,{className:`ml-1.5`,children:n.refresh})]}),g?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,Y.jsx)(q,{type:`button`,variant:`secondary`,onClick:D,disabled:!T||m,children:n.discard}),(0,Y.jsxs)(q,{type:`button`,variant:`primary`,onClick:()=>void E(),disabled:!T||m,children:[m?(0,Y.jsx)(d,{className:`size-3.5 animate-spin`}):(0,Y.jsx)(ae,{className:`size-3.5`}),(0,Y.jsx)(`span`,{className:`ml-1.5`,children:m?n.saving:n.save})]})]})]}),v?(0,Y.jsx)(`div`,{className:`rounded-lg border border-red-500/30 bg-red-500/10 px-3 py-2 text-sm text-red-700 dark:text-red-300`,children:v}):null,(0,Y.jsx)(Cn,{form:s,update:x,a:t.agentSettings,chat:t.chat}),(0,Y.jsxs)(gt,{children:[(0,Y.jsx)(_t,{icon:j,title:n.title,subtitle:n.subtitle}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Y.jsx)(`div`,{className:`rounded-lg border border-edge-subtle bg-surface-base px-3 py-2.5 text-xs leading-relaxed text-fg-muted`,children:n.crossLinkHint}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(`label`,{className:`text-sm font-medium text-fg`,children:n.timeoutLabel}),(0,Y.jsx)(`input`,{type:`number`,min:0,step:1e3,className:a(wn(),`max-w-[12rem]`),value:s.imageGenerationModelTimeoutMs??``,placeholder:`120000`,onChange:e=>{let t=e.target.value.trim(),n=t===``?null:Math.max(0,Math.floor(Number(t)));c(e=>e?{...e,imageGenerationModelTimeoutMs:n&&n>0?n:null}:null)}}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.timeoutHint})]}),(0,Y.jsxs)(`label`,{className:`flex items-start gap-3 text-sm`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`mt-0.5`,checked:s.imageGenerationModelAutoProviderFallback,onChange:e=>c(t=>t?{...t,imageGenerationModelAutoProviderFallback:e.target.checked}:null)}),(0,Y.jsxs)(`span`,{className:`flex flex-col gap-0.5`,children:[(0,Y.jsx)(`span`,{className:`font-medium text-fg`,children:n.autoFallbackLabel}),(0,Y.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:n.autoFallbackHint})]})]})]})]}),(0,Y.jsxs)(gt,{children:[(0,Y.jsx)(_t,{icon:o,title:n.providersTitle,subtitle:``}),S.length===0?(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.providersEmpty}):(0,Y.jsx)(`div`,{className:`flex flex-col gap-3`,children:S.map(e=>(0,Y.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface-panel px-4 py-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-semibold text-fg`,children:e.label??e.id}),(0,Y.jsxs)(`span`,{className:`text-xs text-fg-subtle`,children:[`(`,e.id,`)`]})]}),e.configured?(0,Y.jsx)(`span`,{className:`rounded-full bg-accent-soft px-2 py-0.5 text-xs font-medium text-accent-fg`,children:n.configured}):(0,Y.jsx)(`span`,{className:`rounded-full border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 text-xs font-medium text-amber-700 dark:text-amber-300`,children:n.missingKey})]}),e.defaultModel?(0,Y.jsxs)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:[(0,Y.jsxs)(`span`,{className:`text-fg-muted`,children:[n.defaultModel,`:`]}),` `,e.id,`/`,e.defaultModel]}):null,e.models.length>0?(0,Y.jsxs)(`p`,{className:`mt-0.5 text-xs text-fg-subtle`,children:[(0,Y.jsxs)(`span`,{className:`text-fg-muted`,children:[n.modelsLabel,`:`]}),` `,e.models.map(t=>`${e.id}/${t}`).join(`, `)]}):null]},e.id))})]})]}):(0,Y.jsx)(`div`,{className:`mx-auto w-full max-w-app-main px-4 py-8 text-sm text-fg-muted`,children:e===`zh`?`请先登录网关。`:`Connect to a gateway to continue.`})}var kn=[{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 An(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 jn(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 Mn(){let e=await G(U(`/api/models-json`)),t=await e.json().catch(()=>({}));if(!e.ok||!t.ok||!t.payload)throw Error(An(t)||`HTTP ${e.status}`);return{...t.payload,config:jn(t.payload.config)}}async function Nn(e){let t=await G(U(`/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(An(n)||`HTTP ${t.status}`);return n.payload}async function Pn(e){let t=await G(U(`/api/models-json`),{method:`PATCH`,body:JSON.stringify({config:e})}),n=await t.json().catch(()=>({}));if(!t.ok||!n.ok||!n.payload)throw Error(An(n)||`HTTP ${t.status}`);return n.payload}async function Fn(){let e=await G(U(`/api/models-json/reload`),{method:`POST`}),t=await e.json().catch(()=>({}));if(!e.ok||!t.ok||!t.payload)throw Error(An(t)||`HTTP ${e.status}`);return t.payload}async function In(e){let t=await G(U(`/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(An(n)||`HTTP ${t.status}`);return n.payload}function Ln(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 Rn(e){return e.startsWith(`!`)}function zn(e){return/^[A-Z][A-Z0-9_]*$/.test(e)}function Bn(e){return Rn(e)?`shell`:zn(e)?`env`:`literal`}function Vn(e){return e?e.length<=8?`••••`:`${e.slice(0,4)}••••${e.slice(-4)}`:``}function Hn(e){let{a:t,chat:n,form:r,update:i}=e;return(0,Y.jsxs)(gt,{children:[(0,Y.jsx)(_t,{icon:B,title:t.label.modelFallbacks,subtitle:t.desc.modelFallbacks}),(0,Y.jsxs)(`div`,{className:`mt-4 flex flex-col gap-2`,children:[r.modelFallbacks.map((e,a)=>(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Y.jsx)(Ce,{value:e,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,onChange:e=>{let t=[...r.modelFallbacks];t[a]=e,i({modelFallbacks:t})}})}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":t.removeModelFallback,onClick:()=>i({modelFallbacks:r.modelFallbacks.filter((e,t)=>t!==a)}),children:(0,Y.jsx)(c,{className:`size-4`,strokeWidth:1.75})})]},a)),(0,Y.jsxs)(q,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:()=>i({modelFallbacks:[...r.modelFallbacks,``]}),children:[(0,Y.jsx)(W,{className:`size-4 shrink-0`,strokeWidth:1.75}),t.addModelFallback]})]})]})}var Un={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 Wn(e){return e===`openrouter`?`openrouter`:e===`zhipuCn`?`zhipu-cn`:e===`zaiGeneral`?`zai`:e}var Gn=[{value:`text`,labelKey:`inputTextOnly`},{value:`text,image`,labelKey:`inputTextVision`}];function Kn(){return a(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,f,`dark:border-edge`)}function qn(){return a(m,We)}function Jn(e){return(e.input||[`text`]).includes(`image`)?`text,image`:`text`}function Yn(e){return e===`text,image`?[`text`,`image`]:[`text`]}function Xn(e,t,n){return{...e,providers:{...e.providers,[t]:{...e.providers[t],...n}}}}function Zn(e,t){let n={...e.providers};return delete n[t],{...e,providers:n}}function Qn(e,t,n){return{...e,providers:{...e.providers,[t]:n}}}function $n({open:e,onOpenChange:t,providerId:n,model:r,isNew:i,onSave:o,m:c}){let[l,u]=(0,X.useState)(()=>Ln(``)),[d,f]=(0,X.useState)(()=>new Map);(0,X.useEffect)(()=>{e&&(f(new Map),u(r?{...r}:Ln(``)))},[e,r]);let m=(e,t)=>{u(n=>({...n,[e]:t})),f(t=>{let n=new Map(t);return n.delete(e),n})},h=()=>{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},g=()=>{if(!h())return;let e=(l.id||``).trim();o({...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}}),t(!1)},_=Jn(l);return(0,Y.jsx)(ye,{open:e,onOpenChange:t,children:(0,Y.jsxs)(k,{children:[(0,Y.jsx)(p,{className:`xopc-dialog-overlay fixed inset-0 z-50 bg-scrim`}),(0,Y.jsxs)(F,{className:a(`xopc-dialog-content fixed left-1/2 top-1/2 z-50 max-h-[min(90vh,720px)] w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2`,`overflow-y-auto rounded-xl border border-edge bg-surface-panel p-4 shadow-popover dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,Y.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(s,{className:`text-base font-semibold text-fg`,children:i?c.addModelTitle:c.editModelTitle}),n?(0,Y.jsxs)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:[c.modelProviderLabel,`: `,n]}):null]}),(0,Y.jsx)(Ge,{asChild:!0,children:(0,Y.jsx)(`button`,{type:`button`,className:`rounded-lg p-1.5 text-fg-muted hover:bg-surface-base hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,"aria-label":c.close,children:(0,Y.jsx)(T,{className:`size-4`})})})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`mb-1 block text-xs font-medium text-fg`,children:[c.modelId,(0,Y.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,Y.jsx)(`input`,{className:a(Kn(),d.has(`id`)&&`border-red-500`),value:l.id||``,onChange:e=>m(`id`,e.target.value),placeholder:`e.g. llama3.1:8b`,disabled:!i}),d.has(`id`)?(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:d.get(`id`)}):null]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:c.displayName}),(0,Y.jsx)(`input`,{className:Kn(),value:l.name||``,onChange:e=>m(`name`,e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:c.inputTypes}),(0,Y.jsx)(`select`,{className:qn(),value:_,onChange:e=>m(`input`,Yn(e.target.value)),children:Gn.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:c[e.labelKey]},e.value))})]}),(0,Y.jsxs)(`label`,{className:`mt-6 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:l.reasoning||!1,onChange:e=>m(`reasoning`,e.target.checked)}),c.reasoning]})]}),(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:c.contextWindow}),(0,Y.jsx)(`input`,{type:`number`,min:1,className:a(Kn(),d.has(`contextWindow`)&&`border-red-500`),value:l.contextWindow??128e3,onChange:e=>m(`contextWindow`,parseInt(e.target.value,10)||0)}),d.has(`contextWindow`)?(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:d.get(`contextWindow`)}):null]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:c.maxOutputTokens}),(0,Y.jsx)(`input`,{type:`number`,min:1,className:a(Kn(),d.has(`maxTokens`)&&`border-red-500`),value:l.maxTokens??16384,onChange:e=>m(`maxTokens`,parseInt(e.target.value,10)||0)}),d.has(`maxTokens`)?(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:d.get(`maxTokens`)}):null]})]}),(0,Y.jsxs)(`div`,{className:`border-t border-edge-subtle pt-2 dark:border-edge`,children:[(0,Y.jsx)(`p`,{className:`mb-2 text-xs font-semibold text-fg`,children:c.costSection}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:c.costInput}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,min:0,className:Kn(),value:l.cost?.input??0,onChange:e=>m(`cost`,{...l.cost,input:parseFloat(e.target.value)||0,output:l.cost?.output??0,cacheRead:l.cost?.cacheRead??0,cacheWrite:l.cost?.cacheWrite??0})})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:c.costOutput}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,min:0,className:Kn(),value:l.cost?.output??0,onChange:e=>m(`cost`,{...l.cost,input:l.cost?.input??0,output:parseFloat(e.target.value)||0,cacheRead:l.cost?.cacheRead??0,cacheWrite:l.cost?.cacheWrite??0})})]})]})]})]}),(0,Y.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2 border-t border-edge-subtle pt-3 dark:border-edge`,children:[(0,Y.jsx)(Ge,{asChild:!0,children:(0,Y.jsx)(q,{type:`button`,variant:`secondary`,children:c.cancel})}),(0,Y.jsx)(q,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:g,children:i?c.addModelConfirm:c.saveModelConfirm})]})]})]})})}function er({open:e,onOpenChange:t,presetKey:n,onConfirm:r,m:i}){let[o,c]=(0,X.useState)(``),[l,u]=(0,X.useState)(`custom`),[d,f]=(0,X.useState)(``),[m,h]=(0,X.useState)(`openai-completions`),[g,_]=(0,X.useState)(``),[v,y]=(0,X.useState)(null);(0,X.useEffect)(()=>{if(!e)return;y(null);let t=n||null;if(t&&Un[t]){let e=Un[t];u(t),f(e.baseUrl||``),h(e.api||`openai-completions`),_(e.apiKey??``),c(Wn(t))}else u(`custom`),c(``),f(``),h(`openai-completions`),_(``)},[e,n]);let b=e=>{if(u(e),e===`custom`)return;let t=Un[e];t&&(f(t.baseUrl||``),h(t.api||`openai-completions`),_(t.apiKey??``),c(Wn(e)))};return(0,Y.jsx)(ye,{open:e,onOpenChange:t,children:(0,Y.jsxs)(k,{children:[(0,Y.jsx)(p,{className:`xopc-dialog-overlay fixed inset-0 z-50 bg-scrim`}),(0,Y.jsxs)(F,{className:a(`xopc-dialog-content fixed left-1/2 top-1/2 z-50 max-h-[min(90vh,640px)] w-[min(100%-2rem,32rem)] -translate-x-1/2 -translate-y-1/2`,`overflow-y-auto rounded-xl border border-edge bg-surface-panel p-4 shadow-popover dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,Y.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(s,{className:`text-base font-semibold text-fg`,children:i.addProviderTitle}),(0,Y.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:i.addProviderSubtitle})]}),(0,Y.jsx)(Ge,{asChild:!0,children:(0,Y.jsx)(`button`,{type:`button`,className:`rounded-lg p-1.5 text-fg-muted hover:bg-surface-base hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,"aria-label":i.close,children:(0,Y.jsx)(T,{className:`size-4`})})})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:i.presetLabel}),(0,Y.jsxs)(`select`,{className:qn(),value:l,onChange:e=>b(e.target.value),children:[(0,Y.jsx)(`option`,{value:`custom`,children:i.presetCustom}),(0,Y.jsx)(`option`,{value:`ollama`,children:i.presetOllama}),(0,Y.jsx)(`option`,{value:`lmstudio`,children:i.presetLmStudio}),(0,Y.jsx)(`option`,{value:`openrouter`,children:i.presetOpenRouter}),(0,Y.jsx)(`option`,{value:`zhipuCn`,children:i.presetZhipuCn}),(0,Y.jsx)(`option`,{value:`zaiGeneral`,children:i.presetZaiGeneral})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`mb-1 block text-xs font-medium text-fg`,children:[i.providerIdLabel,(0,Y.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,Y.jsx)(`input`,{className:Kn(),value:o,onChange:e=>c(e.target.value),placeholder:i.providerIdPlaceholder})]}),(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:i.baseUrl}),(0,Y.jsx)(`input`,{className:Kn(),value:d,onChange:e=>f(e.target.value),placeholder:`https://…`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:i.apiType}),(0,Y.jsx)(`select`,{className:qn(),value:m,onChange:e=>h(e.target.value),children:kn.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:i.apiKey}),(0,Y.jsx)(`input`,{className:Kn(),value:g,onChange:e=>_(e.target.value),placeholder:i.apiKeyPlaceholder})]}),v?(0,Y.jsxs)(`p`,{className:`flex items-center gap-1 text-xs text-red-600 dark:text-red-400`,children:[(0,Y.jsx)(ie,{className:`size-3.5 shrink-0`}),v]}):null]}),(0,Y.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2 border-t border-edge-subtle pt-3 dark:border-edge`,children:[(0,Y.jsx)(Ge,{asChild:!0,children:(0,Y.jsx)(q,{type:`button`,variant:`secondary`,children:i.cancel})}),(0,Y.jsx)(q,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:()=>{let e=o.trim();if(!e){y(i.providerIdRequired);return}y(null),r(e,{baseUrl:d.trim()||void 0,api:m,apiKey:g.trim()||void 0,models:[]}),t(!1)},children:i.addProviderConfirm})]})]})]})})}function tr({config:e,setConfig:t,expanded:n,toggleExpand:r,showPw:i,toggleShowPw:o,testResults:s,runTestKey:l,ms:u,removeProv:d,openModelDialog:f,setTestResults:p}){return(0,Y.jsx)(`div`,{className:`flex flex-col gap-3`,children:Object.entries(e.providers).sort(([e],[t])=>e.localeCompare(t)).map(([e,m])=>{let h=n.has(e),g=m.models?.length??0,_=m.apiKey?Bn(m.apiKey):null,v=s.get(e),y=i.has(e);return(0,Y.jsxs)(`section`,{className:`overflow-hidden rounded-2xl bg-surface-base`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b border-edge-subtle bg-surface-hover/35 px-3 py-2 dark:border-edge-subtle`,children:[(0,Y.jsxs)(`button`,{type:`button`,className:`flex min-w-0 flex-1 items-center gap-2 text-left text-sm font-semibold text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,onClick:()=>r(e),children:[h?(0,Y.jsx)(xe,{className:`size-4 shrink-0 text-fg-muted`}):(0,Y.jsx)(Pe,{className:`size-4 shrink-0 text-fg-muted`}),(0,Y.jsx)(`span`,{className:`truncate`,children:e}),g>0?(0,Y.jsx)(`span`,{className:`shrink-0 rounded-full bg-accent px-2 py-0.5 text-[10px] font-medium text-white`,children:g}):null,_?(0,Y.jsx)(`span`,{className:a(`shrink-0 rounded-full px-2 py-0.5 text-[10px] font-medium`,_===`shell`&&`bg-blue-100 text-blue-800 dark:bg-blue-950 dark:text-blue-200`,_===`env`&&`bg-emerald-100 text-emerald-800 dark:bg-emerald-950 dark:text-emerald-200`,_===`literal`&&`bg-surface-hover text-fg-muted dark:bg-surface-active`),children:_===`shell`?u.badgeShell:_===`env`?u.badgeEnv:u.badgeLiteral}):null]}),(0,Y.jsx)(`button`,{type:`button`,className:`rounded-lg p-1.5 text-fg-muted hover:bg-surface-base hover:text-red-600 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 dark:hover:text-red-400`,onClick:()=>d(e),"aria-label":u.removeProvider,children:(0,Y.jsx)(c,{className:`size-4`})})]}),h?(0,Y.jsxs)(`div`,{className:`space-y-4 px-3 py-3`,children:[(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:u.baseUrl}),(0,Y.jsx)(`input`,{className:Kn(),value:m.baseUrl||``,onChange:n=>t(t=>Xn(t,e,{baseUrl:n.target.value}))})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:u.apiType}),(0,Y.jsx)(`select`,{className:qn(),value:m.api||`openai-completions`,onChange:n=>t(t=>Xn(t,e,{api:n.target.value})),children:kn.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:u.apiKey}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Y.jsx)(`input`,{className:a(Kn(),`min-w-0 flex-1`),type:y?`text`:`password`,autoComplete:`off`,value:m.apiKey||``,onChange:n=>{let r=n.target.value;t(t=>Xn(t,e,{apiKey:r})),p(t=>{let n=new Map(t);return n.delete(e),n})},placeholder:u.apiKeyPlaceholder}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>o(e),children:y?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(te,{className:`mr-1 size-3.5`}),u.hide]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(L,{className:`mr-1 size-3.5`}),u.show]})}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>l(e,m.apiKey||``),children:u.testKey})]}),v?(0,Y.jsx)(`p`,{className:a(`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}): ${Vn(v.resolved||``)}`}):null,(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:u.apiKeyHint})]}),(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:m.authHeader||!1,onChange:n=>t(t=>Xn(t,e,{authHeader:n.target.checked}))}),u.authHeader]}),(0,Y.jsxs)(`div`,{className:`border-t border-edge-subtle pt-3 dark:border-edge`,children:[(0,Y.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-semibold text-fg`,children:u.modelsSection}),(0,Y.jsxs)(q,{type:`button`,variant:`primary`,className:`px-2 py-1 text-xs`,onClick:()=>f(e,null,!0),children:[(0,Y.jsx)(W,{className:`mr-1 size-3.5`}),u.addModel]})]}),(m.models||[]).length===0?(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:u.modelsEmpty}):(0,Y.jsx)(`ul`,{className:`space-y-2`,children:(m.models||[]).map(n=>(0,Y.jsxs)(`li`,{className:`flex items-center justify-between gap-2 rounded-lg border border-edge-subtle bg-surface-base px-3 py-2 dark:border-edge`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`div`,{className:`truncate text-sm font-medium text-fg`,children:n.id}),n.name&&n.name!==n.id?(0,Y.jsx)(`div`,{className:`truncate text-xs text-fg-muted`,children:n.name}):null]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(0,Y.jsx)(`button`,{type:`button`,className:`rounded-lg p-1.5 text-fg-muted hover:bg-surface-panel hover:text-fg`,onClick:()=>f(e,n,!1),"aria-label":u.editModel,children:(0,Y.jsx)(ke,{className:`size-4`})}),(0,Y.jsx)(`button`,{type:`button`,className:`rounded-lg p-1.5 text-fg-muted hover:bg-surface-panel hover:text-red-600 dark:hover:text-red-400`,onClick:()=>{window.confirm(u.removeModelConfirm.replace(`{{id}}`,n.id))&&t(t=>{let r=t.providers[e];return r?Xn(t,e,{models:(r.models||[]).filter(e=>e.id!==n.id)}):t})},"aria-label":u.removeModel,children:(0,Y.jsx)(c,{className:`size-4`})})]})]},n.id))})]})]}):null]},e)})})}function nr({ms:e,openAddProvider:t}){return(0,Y.jsxs)(`div`,{className:`flex flex-col items-center rounded-xl border-2 border-dashed border-edge-subtle bg-surface-panel px-6 py-12 text-center dark:border-edge`,children:[(0,Y.jsx)(`div`,{className:`mb-4 flex size-14 items-center justify-center rounded-full border border-edge bg-surface-base dark:border-edge`,children:(0,Y.jsx)(B,{className:`size-7 text-accent`,strokeWidth:1.5})}),(0,Y.jsx)(`h2`,{className:`mb-1 text-base font-semibold text-fg`,children:e.emptyTitle}),(0,Y.jsx)(`p`,{className:`mb-6 max-w-md text-sm text-fg-muted`,children:e.emptyDesc}),(0,Y.jsxs)(q,{type:`button`,className:`mb-6 bg-accent text-white hover:bg-accent/90`,onClick:()=>t(null),children:[(0,Y.jsx)(W,{className:`mr-1 size-4`}),e.emptyCta]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap justify-center gap-2`,children:[(0,Y.jsxs)(`button`,{type:`button`,className:a(`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`,b.transition,b.focusRingBase),onClick:()=>t(`ollama`),children:[(0,Y.jsx)(S,{className:`size-3.5`,"aria-hidden":!0}),e.presetOllama]}),(0,Y.jsxs)(`button`,{type:`button`,className:a(`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`,b.transition,b.focusRingBase),onClick:()=>t(`openrouter`),children:[(0,Y.jsx)(ue,{className:`size-3.5`,"aria-hidden":!0}),e.presetOpenRouter]}),(0,Y.jsxs)(`button`,{type:`button`,className:a(`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`,b.transition,b.focusRingBase),onClick:()=>t(`lmstudio`),children:[(0,Y.jsx)(B,{className:`size-3.5`,"aria-hidden":!0}),e.presetLmStudio]}),(0,Y.jsxs)(`button`,{type:`button`,className:a(`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`,b.transition,b.focusRingBase),onClick:()=>t(`zhipuCn`),children:[(0,Y.jsx)(S,{className:`size-3.5`,"aria-hidden":!0}),e.presetZhipuCn]}),(0,Y.jsxs)(`button`,{type:`button`,className:a(`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`,b.transition,b.focusRingBase),onClick:()=>t(`zaiGeneral`),children:[(0,Y.jsx)(ue,{className:`size-3.5`,"aria-hidden":!0}),e.presetZaiGeneral]})]})]})}function rr(){let e=se(e=>e.language),t=O(e),n=t.modelsSettings,r=pt(t.agentSettings),i=!!K(e=>e.token),[o,s]=(0,X.useState)({providers:{}}),[c,l]=(0,X.useState)({providers:{}}),[u,f]=(0,X.useState)(``),[p,m]=(0,X.useState)(),[h,g]=(0,X.useState)(!0),[_,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(!1),[S,C]=(0,X.useState)(!1),[w,T]=(0,X.useState)(null),[E,D]=(0,X.useState)(!1),[k,A]=(0,X.useState)(null),[j,M]=(0,X.useState)(()=>new Set),[N,ee]=(0,X.useState)(!1),[P,F]=(0,X.useState)(``),[I,L]=(0,X.useState)(null),[te,R]=(0,X.useState)(()=>new Set),[ne,z]=(0,X.useState)(()=>new Map),[B,re]=(0,X.useState)(!1),[V,ae]=(0,X.useState)(null),[oe,H]=(0,X.useState)(!1),[ce,U]=(0,X.useState)(null),le=(0,X.useCallback)(async e=>{let t=!e?.skipFullPageLoading;t&&g(!0),T(null);try{let e=await Mn(),t=jn(e.config);s(t),l(structuredClone(t)),f(e.path),m(e.loadError),A(null),D(!1)}catch(e){T(e instanceof Error?e.message:n.loadError),s({providers:{}}),l({providers:{}})}finally{t&&g(!1)}},[n.loadError]);(0,X.useEffect)(()=>{if(!i){g(!1);return}le()},[i,le]);let ue=(0,X.useMemo)(()=>JSON.stringify(o)!==JSON.stringify(c),[o,c]),G=(0,X.useMemo)(()=>r.form?{form:r.form,update:r.update,a:t.agentSettings,chat:t.chat}:null,[r.form,r.update,t.agentSettings,t.chat]),de=ue||r.dirty,pe=(0,X.useMemo)(()=>{let e=Object.keys(o.providers),t=0;for(let e of Object.values(o.providers))t+=e.models?.length??0;return{providers:e.length,models:t}},[o.providers]),me=e=>{M(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},he=e=>{R(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},ge=(0,X.useCallback)(()=>{F(JSON.stringify(o,null,2)),L(null)},[o]);(0,X.useEffect)(()=>{N&&ge()},[N,ge]);let _e=()=>{try{s(jn(JSON.parse(P))),L(null)}catch{L(n.jsonParseError)}},ve=async()=>{x(!0),T(null);try{A(await Nn(o))}catch(e){T(e instanceof Error?e.message:n.validateError)}finally{x(!1)}},ye=async()=>{if(_||r.saving)return;let e=ue,i=r.dirty;if(!(!e&&!i)){T(null),D(!1);try{if(e){y(!0);try{await Pn(o),l(structuredClone(o)),A(null)}finally{y(!1)}}if(i&&r.form&&!await r.save())throw Error(t.agentSettings.saveError);D(!0)}catch(e){T(e instanceof Error?e.message:n.saveError)}}},be=(0,X.useCallback)(()=>{s(structuredClone(c)),A(null),D(!1),T(null),N&&(F(JSON.stringify(c,null,2)),L(null)),r.discard()},[c,N,r.discard]),xe=async()=>{C(!0),T(null);try{await Fn(),await le({skipFullPageLoading:!0})}catch(e){T(e instanceof Error?e.message:n.reloadError)}finally{C(!1)}},Se=async(e,t)=>{try{let n=await In(t);z(t=>{let r=new Map(t);return r.set(e,n),r})}catch(t){z(n=>{let r=new Map(n);return r.set(e,{type:`error`,error:t instanceof Error?t.message:`Error`}),r})}},Ce=(e=null)=>{ae(e),re(!0)},we=(e,t)=>{s(n=>Qn(n,e,t)),M(t=>new Set(t).add(e))},Te=e=>{window.confirm(n.removeProviderConfirm.replace(`{{id}}`,e))&&(s(t=>Zn(t,e)),z(t=>{let n=new Map(t);return n.delete(e),n}))},Ee=(e,t,n)=>{U({providerId:e,model:t,isNew:n}),H(!0)},Oe=e=>{if(!ce)return;let{providerId:t,isNew:n}=ce;s(r=>{let i=r.providers[t];if(!i)return r;let a=i.models||[];return n?Xn(r,t,{models:[...a,e]}):Xn(r,t,{models:a.map(t=>t.id===e.id?e:t)})})};return i?(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-4 px-4 py-8`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.models}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.subtitle}),(0,Y.jsxs)(`a`,{href:fe(e,`models`),target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-sm text-accent hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,children:[n.docsLink,(0,Y.jsx)(v,{className:`size-3.5`})]})]}),p?(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-100`,role:`status`,children:[(0,Y.jsx)(ie,{className:`mt-0.5 size-4 shrink-0`}),(0,Y.jsxs)(`span`,{children:[n.loadFileWarning,`: `,p]})]}):null,u?(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.filePath,`: `,(0,Y.jsx)(`code`,{className:`rounded bg-surface-base px-1 py-0.5 font-mono text-fg-muted`,children:u})]}):null,(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsxs)(q,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:()=>Ce(null),disabled:h,children:[(0,Y.jsx)(W,{className:`mr-1 size-4`}),n.addProvider]}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:ve,disabled:h||b,children:b?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(d,{className:`mr-1 size-4 animate-spin`}),n.validating]}):n.validate}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:be,disabled:h||_||r.saving||!de,children:n.discard}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:()=>void ye(),disabled:h||_||r.saving||!de,children:_||r.saving?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(d,{className:`mr-1 size-4 animate-spin`}),n.saving]}):n.save}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[8.5rem] justify-center`,onClick:xe,disabled:h||S,children:S?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(d,{className:`mr-1 size-4 animate-spin`}),n.reloading]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(De,{className:`mr-1 size-4`}),n.reload]})}),(0,Y.jsx)(q,{type:`button`,variant:`ghost`,className:`text-fg-muted`,onClick:()=>{ee(e=>!e),L(null)},children:N?n.hideJson:n.showJson}),(0,Y.jsxs)(`div`,{className:`ml-auto flex items-center gap-2 rounded-lg border border-edge-subtle bg-surface-panel px-3 py-1.5 text-sm dark:border-edge`,children:[(0,Y.jsx)(`span`,{className:`text-fg-muted`,children:n.statsProviders.replace(`{{count}}`,String(pe.providers))}),(0,Y.jsx)(`span`,{className:`text-fg-subtle`,children:`|`}),(0,Y.jsx)(`span`,{className:`text-fg-muted`,children:n.statsModels.replace(`{{count}}`,String(pe.models))})]})]}),de?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,E||r.saveOk?(0,Y.jsx)(`p`,{className:`text-xs text-emerald-700 dark:text-emerald-400`,role:`status`,children:n.saved}):null,w?(0,Y.jsxs)(`p`,{className:`flex items-center gap-1 text-sm text-red-600 dark:text-red-400`,role:`alert`,children:[(0,Y.jsx)(ie,{className:`size-4 shrink-0`}),w]}):null,r.error?(0,Y.jsxs)(`p`,{className:`flex items-center gap-1 text-sm text-red-600 dark:text-red-400`,role:`alert`,children:[(0,Y.jsx)(ie,{className:`size-4 shrink-0`}),r.error]}):null,k&&k.errors.length>0?(0,Y.jsxs)(`div`,{className:`rounded-lg border border-amber-200 bg-amber-50/80 px-3 py-2 dark:border-amber-800 dark:bg-amber-950/30`,role:`status`,children:[(0,Y.jsx)(`p`,{className:`mb-1 text-sm font-medium text-amber-950 dark:text-amber-100`,children:k.valid?n.validationWarnings:n.validationErrors}),(0,Y.jsx)(`ul`,{className:`list-inside list-disc space-y-0.5 text-xs text-amber-900 dark:text-amber-200`,children:k.errors.map((e,t)=>(0,Y.jsxs)(`li`,{children:[e.path,`: `,e.message,` (`,e.severity,`)`]},`${e.path}-${t}`))})]}):null,h?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,Y.jsx)(d,{className:`size-4 animate-spin`}),n.loading]}):N?(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(`textarea`,{className:a(Kn(),`min-h-[320px] resize-y font-mono text-xs leading-relaxed`),value:P,onChange:e=>F(e.target.value),spellCheck:!1}),I?(0,Y.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:I}):null,(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(q,{type:`button`,variant:`secondary`,onClick:ge,children:n.jsonReset}),(0,Y.jsx)(q,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:_e,children:n.jsonApply})]})]}):Object.keys(o.providers).length===0?(0,Y.jsx)(nr,{ms:n,openAddProvider:Ce}):(0,Y.jsx)(tr,{config:o,setConfig:s,expanded:j,toggleExpand:me,showPw:te,toggleShowPw:he,testResults:ne,runTestKey:Se,ms:n,removeProv:Te,openModelDialog:Ee,setTestResults:z}),G?(0,Y.jsx)(`div`,{className:`mt-10 border-t border-edge-subtle pt-8 dark:border-edge`,children:(0,Y.jsx)(Hn,{...G})}):null,(0,Y.jsx)(er,{open:B,onOpenChange:re,presetKey:V,onConfirm:we,m:n}),(0,Y.jsx)($n,{open:oe,onOpenChange:e=>{H(e),e||U(null)},providerId:ce?.providerId??null,model:ce?.model??null,isNew:ce?.isNew??!1,onSave:Oe,m:n})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.models}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}async function ir(e){let t=await G(U(`/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 ar(e){let t=await G(U(`/api/auth/oauth-async/${encodeURIComponent(e)}/status`));if(!t.ok)throw Error(`OAuth status: ${t.status}`);return(await t.json()).payload}async function or(e,t){let n=await G(U(`/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 sr(e){let t=await G(U(`/api/auth/oauth-async/${encodeURIComponent(e)}/cancel`),{method:`POST`});if(!t.ok)throw Error(`Cancel OAuth failed: ${t.status}`)}async function cr(e){let t=await G(U(`/api/auth/oauth-async/${encodeURIComponent(e)}`),{method:`DELETE`});if(!t.ok)throw Error(`Cleanup session failed: ${t.status}`)}async function lr(e){let t=await G(U(`/api/auth/oauth/${encodeURIComponent(e)}`),{method:`DELETE`});if(!t.ok)throw Error(`Revoke OAuth failed: ${t.status}`)}function ur({providerId:e,language:t}){let n=Ne[e];if(!n)return null;let r=t===`zh`,i=r&&n.descriptionZh?n.descriptionZh:n.description;return i?(0,Y.jsxs)(_,{children:[(0,Y.jsx)(y,{asChild:!0,children:(0,Y.jsx)(`button`,{type:`button`,className:`rounded p-0.5 text-fg-subtle hover:bg-surface-hover hover:text-fg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,"aria-label":r?`${e} 详情`:`${e} info`,children:(0,Y.jsx)(E,{className:`size-3.5`,"aria-hidden":!0})})}),(0,Y.jsx)(M,{children:(0,Y.jsxs)(D,{side:`right`,align:`start`,sideOffset:6,className:a(`z-50 w-64 rounded-xl border border-edge bg-surface-panel p-3 shadow-md`,`data-[state=open]:animate-in data-[state=closed]:animate-out`,`data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,`data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95`),children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs font-semibold text-fg`,children:e}),(0,Y.jsx)(w,{asChild:!0,children:(0,Y.jsx)(`button`,{type:`button`,className:`shrink-0 rounded p-0.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,"aria-label":r?`关闭`:`Close`,children:(0,Y.jsx)(T,{className:`size-3.5`,"aria-hidden":!0})})})]}),(0,Y.jsx)(`p`,{className:`mt-1.5 text-xs leading-relaxed text-fg-muted`,children:i}),n.bestFor&&n.bestFor.length>0?(0,Y.jsxs)(`div`,{className:`mt-2`,children:[(0,Y.jsx)(`p`,{className:`text-[10px] font-medium uppercase tracking-wide text-fg-subtle`,children:r?`适合场景`:`Best for`}),(0,Y.jsx)(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:n.bestFor.map(e=>(0,Y.jsx)(`span`,{className:`rounded bg-surface-hover px-1.5 py-0.5 text-[10px] font-medium text-fg-muted`,children:e},e))})]}):null,n.freeTier===void 0?null:(0,Y.jsxs)(`div`,{className:`mt-2`,children:[(0,Y.jsx)(`p`,{className:`text-[10px] font-medium uppercase tracking-wide text-fg-subtle`,children:r?`免费额度`:`Free tier`}),(0,Y.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:n.freeTier?n.freeTierNote??(r?`有免费额度`:`Available`):r?`无免费额度(按量付费)`:`None (pay-as-you-go)`})]}),n.pricingUrl||n.docsUrl?(0,Y.jsxs)(`div`,{className:`mt-2.5 flex gap-3`,children:[n.pricingUrl?(0,Y.jsxs)(`a`,{href:n.pricingUrl,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-0.5 text-xs text-accent-fg hover:underline`,children:[r?`定价`:`Pricing`,(0,Y.jsx)(v,{className:`size-3`,"aria-hidden":!0})]}):null,n.docsUrl?(0,Y.jsxs)(`a`,{href:n.docsUrl,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-0.5 text-xs text-accent-fg hover:underline`,children:[r?`文档`:`Docs`,(0,Y.jsx)(v,{className:`size-3`,"aria-hidden":!0})]}):null]}):null,(0,Y.jsx)(ve,{className:`fill-edge`})]})})]}):null}var dr=[`common`,`specialty`,`enterprise`,`oauth`,`extension`];function fr(e){let t=new Map;for(let e of dr)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 pr(e,t){return e.replace(/\{\{(\w+)\}\}/g,(e,n)=>String(t[n]??``))}function mr(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 hr({envVar:e,labels:t}){let[n,r]=(0,X.useState)(!1),i=async()=>{try{await navigator.clipboard.writeText(e),r(!0),window.setTimeout(()=>r(!1),2e3)}catch{}};return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`code`,{className:`rounded bg-surface-hover px-1.5 py-0.5 font-mono text-[11px] text-fg-muted`,children:e}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>void i(),className:`rounded p-0.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,title:n?t.copied:t.copy,"aria-label":n?t.copied:t.copy,children:n?(0,Y.jsx)(Me,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):(0,Y.jsx)(ne,{className:`size-3.5`,"aria-hidden":!0})})]})}function gr({row:e,value:t,rowDirty:n,labels:r,language:i,onChange:o,onReload:s,justSaved:l,availableModels:u}){let[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(!1),[_,y]=(0,X.useState)(!1),[x,S]=(0,X.useState)(null),[w,D]=(0,X.useState)(!1),[O,k]=(0,X.useState)(null),[A,j]=(0,X.useState)(!1),M=we(t),N=M&&!h?``:t,ee=e.configured&&!M&&!!t,[P,F]=(0,X.useState)(!1),[I,R]=(0,X.useState)(),[z,B]=(0,X.useState)(),[re,V]=(0,X.useState)(),[ae,oe]=(0,X.useState)(),[se,U]=(0,X.useState)(),[W,le]=(0,X.useState)(``),[ue,G]=(0,X.useState)(!1),[de,fe]=(0,X.useState)(null),[pe,me]=(0,X.useState)(null),K=e.activeKeySource??`none`,he=(0,X.useMemo)(()=>ce(e.id,i),[e.id,i]);(0,X.useEffect)(()=>()=>{I&&cr(I).catch(()=>{})},[I]),(0,X.useEffect)(()=>{if(!I||!P)return;let e=window.setInterval(()=>{(async()=>{try{let t=await ar(I);V(t.message),oe(t.authUrl),U(t.instructions),t.status===`waiting_auth`||t.status===`waiting_code`?B(t.status===`waiting_code`?`waiting_code`:`waiting`):t.status===`completed`?(window.clearInterval(e),F(!1),B(`success`),V(t.message),window.setTimeout(()=>s(),800)):(t.status===`failed`||t.status===`cancelled`)&&(window.clearInterval(e),F(!1),B(`error`),V(t.error||t.message||`OAuth failed`))}catch{}})()},1e3);return()=>window.clearInterval(e)},[I,P,s]);let ge=async()=>{F(!0),B(`waiting`),V(r.oauthStarting),R(void 0),oe(void 0),U(void 0);try{R((await ir(e.id)).sessionId)}catch(e){B(`error`),V(e instanceof Error?e.message:`OAuth failed`),F(!1)}},_e=async()=>{if(I){try{await sr(I)}catch{}R(void 0),F(!1),B(`idle`),V(void 0)}},ve=async()=>{if(!(!I||!W.trim()))try{await or(I,W.trim()),le(``),V(r.oauthProcessingCode)}catch(e){B(`error`),V(e instanceof Error?e.message:`Failed`)}},ye=()=>{window.confirm(pr(r.revokeConfirm,{name:e.name}))&&(S(null),lr(e.id).then(()=>s()).catch(e=>S(e instanceof Error?e.message:r.revokeFailed)))},Se=async()=>{j(!1),D(!0),k(null);try{await Fe(e.id),k(r.removeKeySuccess),o(e.id,``),window.setTimeout(()=>s(),600)}catch(e){k(e instanceof Error?e.message:r.removeKeyFailed)}finally{D(!1)}},Ce=e.configured&&M&&K!==`env`&&K!==`extension`&&K!==`models_json`,Ee=async()=>{if(!(!t||M))try{await navigator.clipboard.writeText(t),y(!0),window.setTimeout(()=>y(!1),2e3)}catch{}},De=async()=>{let e=t.trim();if(!(!e||we(e))){G(!0),fe(null),me(null);try{let t=await Te(e);if(t.error){me(!1),fe(`${r.testFailed} ${t.error}`);return}me(!0),t.type===`env`?fe(r.testOkEnv):t.type===`command`?fe(r.testOkCommand):fe(r.testOkLiteral)}catch(e){me(!1),fe(e instanceof Error?e.message:r.testFailed)}finally{G(!1)}}},Oe=n?r.metaWillSave:e.configured?M?`${r.metaMasked} · ${r.runtimeLabelPrefix} ${mr(r,K)}`:`${r.runtimeLabelPrefix} ${mr(r,K)}`:r.metaNotConfigured,ke=`provider-details-${e.id}`;return(0,Y.jsxs)(`div`,{className:`bg-surface-panel`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-3 sm:px-4`,children:[(0,Y.jsx)(`div`,{className:`flex size-8 shrink-0 items-center justify-center rounded-md bg-surface-hover/80 dark:bg-surface-hover/50`,"aria-hidden":!0,children:e.configured?(0,Y.jsx)(Me,{className:`size-4 text-emerald-600 dark:text-emerald-400`}):(0,Y.jsx)(C,{className:`size-4 text-fg-subtle`,strokeWidth:1.75})}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-semibold text-fg`,children:e.name}),(0,Y.jsx)(ur,{providerId:e.id,language:i}),(0,Y.jsx)(`span`,{className:`rounded bg-surface-hover px-1.5 py-0.5 font-mono text-[10px] font-medium uppercase tracking-wide text-fg-subtle`,children:e.id}),(0,Y.jsx)(`span`,{className:`rounded bg-surface-hover px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-fg-subtle`,children:e.category})]}),(0,Y.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:Oe})]}),(0,Y.jsx)(q,{type:`button`,variant:`ghost`,className:`h-9 w-9 shrink-0 p-0`,"aria-expanded":p,"aria-controls":ke,"aria-label":r.expandRowDetails,onClick:()=>m(e=>!e),children:(0,Y.jsx)(xe,{className:a(`size-4 transition-transform`,p&&`rotate-180`),"aria-hidden":!0})})]}),p?(0,Y.jsxs)(`div`,{id:ke,role:`region`,className:`space-y-3 border-t border-edge-subtle bg-surface-base/40 px-3 py-3 dark:bg-surface-base/20 sm:px-4`,children:[e.supportsApiKey===!1?null:(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsxs)(`div`,{className:`relative flex flex-col gap-2 sm:flex-row sm:gap-2`,children:[(0,Y.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,Y.jsx)(`input`,{type:h||!M?`text`:`password`,className:a(`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`,f,`dark:border-edge`),value:N,placeholder:M?r.placeholderOverride:e.configured?r.placeholderKeep:r.placeholderKey,disabled:P,onChange:t=>o(e.id,t.target.value),autoComplete:`off`,spellCheck:!1}),(0,Y.jsxs)(`div`,{className:`absolute right-1 top-1/2 flex -translate-y-1/2 gap-0.5`,children:[t&&!M?(0,Y.jsx)(`button`,{type:`button`,className:a(`rounded p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,b.transition,b.press,b.focusRingPanel),title:_?r.copied:r.copy,"aria-label":_?r.copied:r.copy,onClick:()=>void Ee(),children:_?(0,Y.jsx)(Me,{className:`size-4`}):(0,Y.jsx)(ne,{className:`size-4`})}):null,(0,Y.jsx)(`button`,{type:`button`,className:a(`rounded p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg disabled:opacity-40`,b.transition,b.press,b.focusRingPanel),title:h?r.hide:r.show,"aria-label":h?r.hide:r.show,disabled:M,onClick:()=>g(e=>!e),children:h?(0,Y.jsx)(te,{className:`size-4`}):(0,Y.jsx)(L,{className:`size-4`})})]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2 sm:shrink-0`,children:[(0,Y.jsxs)(q,{type:`button`,variant:`secondary`,className:`gap-1`,disabled:P||ue||!t.trim()||we(t),onClick:()=>void De(),children:[ue?(0,Y.jsx)(d,{className:`size-4 animate-spin`,"aria-hidden":!0}):null,ue?r.testingKey:r.testKey]}),e.supportsOAuth?ee?(0,Y.jsxs)(q,{type:`button`,variant:`secondary`,className:`gap-1 text-red-600 dark:text-red-400`,onClick:ye,children:[(0,Y.jsx)(H,{className:`size-4`,"aria-hidden":!0}),r.revoke]}):(0,Y.jsxs)(q,{type:`button`,variant:`secondary`,className:`gap-1`,disabled:P,onClick:()=>void ge(),children:[P?(0,Y.jsx)(d,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(Ke,{className:`size-4`,"aria-hidden":!0}),r.oauth]}):null,Ce?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(q,{type:`button`,variant:`secondary`,className:`gap-1 text-red-600 dark:text-red-400`,disabled:w,onClick:()=>j(!0),children:[w?(0,Y.jsx)(d,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(c,{className:`size-4`,"aria-hidden":!0}),r.removeKey]}),(0,Y.jsx)(Le,{open:A,title:r.removeKey,description:pr(r.removeKeyConfirm,{name:e.name}),confirmLabel:r.removeKey,cancelLabel:r.cancelOAuth,destructive:!0,onConfirm:()=>void Se(),onCancel:()=>j(!1)})]}):null]})]}),de?(0,Y.jsx)(`p`,{className:a(`text-xs`,pe===!1?`text-red-600 dark:text-red-400`:`text-fg-muted`),role:`status`,children:de}):null,he.length>0?(0,Y.jsx)(`div`,{className:`flex flex-col gap-1`,children:he.map(e=>(0,Y.jsxs)(`a`,{href:e.href,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex w-fit items-center gap-1 text-xs font-medium text-accent-fg hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:[be(e.kind,r),(0,Y.jsx)(v,{className:`size-3`,"aria-hidden":!0})]},`${e.kind}-${e.href}`))}):null]}),re?(0,Y.jsxs)(`div`,{className:a(`flex gap-2 rounded-md px-3 py-2 text-xs`,z===`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:[z===`error`?(0,Y.jsx)(ie,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}):z===`success`?(0,Y.jsx)(Me,{className:`mt-0.5 size-4 shrink-0 text-emerald-600`,"aria-hidden":!0}):(0,Y.jsx)(E,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:re})]}):null,x?(0,Y.jsxs)(`div`,{className:`flex gap-2 rounded-md border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700 dark:border-red-900/50 dark:bg-red-950/50 dark:text-red-400`,role:`alert`,children:[(0,Y.jsx)(ie,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:x})]}):null,O?(0,Y.jsxs)(`div`,{className:a(`flex gap-2 rounded-md px-3 py-2 text-xs`,O===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:[O===r.removeKeySuccess?(0,Y.jsx)(Me,{className:`mt-0.5 size-4 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):(0,Y.jsx)(ie,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:O})]}):null,(z===`waiting`||z===`waiting_code`)&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[ae?(0,Y.jsxs)(`a`,{href:ae,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1.5 rounded-md bg-accent px-3 py-2 text-sm font-medium text-white hover:bg-accent-hover`,children:[(0,Y.jsx)(v,{className:`size-4`,"aria-hidden":!0}),r.openAuthPage]}):null,(0,Y.jsxs)(q,{type:`button`,variant:`secondary`,className:`gap-1`,onClick:()=>void _e(),children:[(0,Y.jsx)(T,{className:`size-4`,"aria-hidden":!0}),r.cancelOAuth]})]}),se?(0,Y.jsxs)(`div`,{className:`flex gap-2 rounded-md bg-surface-hover/60 px-3 py-2 text-xs text-fg-muted dark:bg-surface-hover/40`,children:[(0,Y.jsx)(E,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:se})]}):null,z===`waiting_code`?(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,Y.jsx)(`input`,{type:`text`,className:a(`min-w-0 flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,f,`dark:border-edge`),value:W,placeholder:r.pasteRedirectUrl,onChange:e=>le(e.target.value),onKeyDown:e=>e.key===`Enter`&&void ve()}),(0,Y.jsx)(q,{type:`button`,variant:`primary`,className:`shrink-0`,onClick:()=>void ve(),children:r.submitCode})]}):null,M?(0,Y.jsxs)(`div`,{className:`flex gap-2 rounded-md bg-surface-hover/60 px-3 py-2 text-xs text-fg-muted dark:bg-surface-hover/40`,children:[(0,Y.jsx)(E,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:K===`env`?r.envHint:r.maskedStoredHint})]}):null,e.supportsOAuth&&!M&&!ee?(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:r.oauthHint}):null,l?(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md bg-surface-hover/60 px-3 py-2 text-xs text-fg-muted dark:bg-surface-hover/40`,children:[(0,Y.jsx)(Me,{className:`mt-0.5 size-3.5 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:(()=>{let t=u.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,(Ne[e.id]?.envVars??[]).length>0?(0,Y.jsxs)(`details`,{children:[(0,Y.jsx)(`summary`,{className:`cursor-pointer select-none list-none text-xs text-fg-subtle hover:text-fg-muted`,children:r.envVarAlt}),(0,Y.jsx)(`div`,{className:`mt-1.5 flex flex-col gap-1`,children:(Ne[e.id]?.envVars??[]).map(e=>(0,Y.jsx)(hr,{envVar:e,labels:r},e))})]}):null]}):null]})}function _r(){let e=se(e=>e.language),t=O(e),n=t.providersSettings,i=!!K(e=>e.token),[o,s]=(0,X.useState)({}),[c,l]=(0,X.useState)({}),[u,d]=(0,X.useState)(!1),[p,m]=(0,X.useState)(null),[h,g]=(0,X.useState)(null),[_,v]=(0,X.useState)(()=>new Set([`common`])),[y,b]=(0,X.useState)(``),[x,S]=(0,X.useState)(!1),[w,T]=(0,X.useState)(()=>new Set),E=(0,X.useRef)(``),D=U(`/api/providers/meta`),k=(0,X.useCallback)(async e=>(await Oe(e)).payload?.providers??[],[]),{data:A,error:j,isLoading:M,mutate:N}=Ye(i),{data:ee,error:P,isLoading:F,mutate:I}=r(i?D:null,k,{revalidateOnFocus:!1}),{data:L,mutate:te}=r(i?me:null,()=>de(),{revalidateOnFocus:!1}),R=(0,X.useMemo)(()=>!ee||A===void 0?null:je(ee,V(A.payload?.config),L??[]),[ee,A,L]),ne=j instanceof Error?j.message:j?String(j):P instanceof Error?P.message:P?String(P):null,z=!!(i&&R===null&&(M||F)&&!ne),B=(0,X.useMemo)(()=>JSON.stringify(o)!==JSON.stringify(c),[o,c]);(0,X.useEffect)(()=>{if(!B)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[B]),(0,X.useEffect)(()=>{if(!(!i||R===null)&&!B){let e={};for(let t of R)e[t.id]=t.apiKey;s(e),l({...e})}},[i,R,B]);let re=R??[],ie=(0,X.useMemo)(()=>{let e=re,t=y.trim().toLowerCase();return t&&(e=e.filter(e=>{let n=Ne[e.id]?.aliases??[];return e.id.toLowerCase().includes(t)||e.name.toLowerCase().includes(t)||n.some(e=>e.toLowerCase().includes(t))})),x&&(e=e.filter(e=>!e.configured)),e},[re,y,x]),ae=(0,X.useMemo)(()=>fr(ie),[ie]);(0,X.useEffect)(()=>{let e=E.current;if(E.current=y,y.trim()){let e=new Set;for(let t of dr)(ae.get(t)??[]).length>0&&e.add(t);v(e);return}e.trim()&&v(new Set([`common`]))},[y,ae]);let oe=(0,X.useCallback)(async()=>{if(u)return;let e={};for(let t of Object.keys(o)){let n=o[t]?.trim()??``;!n||we(n)||(e[t]=n)}if(Object.keys(e).length===0){l({...o}),g(`noChanges`),window.setTimeout(()=>g(null),2500);return}d(!0),m(null),g(null);try{await ge(e),T(new Set(Object.keys(e)));let t=await te(de(!0))??L??[],[n,r]=await Promise.all([N(),I()]),i=Array.isArray(r)?r:ee??[],a=n??A;if(a?.payload){let e=je(i,V(a.payload.config),t),n={};for(let t of e)n[t.id]=t.apiKey;s(n),l({...n})}g(`saved`),window.setTimeout(()=>g(null),2500)}catch(e){m(e instanceof Error?e.message:n.saveError)}finally{d(!1)}},[A,o,ee,L,N,I,te,n.saveError,u]),H=(0,X.useCallback)(()=>{s({...c}),m(null),g(null),T(new Set)},[c]),ce=e=>{v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},W=(0,X.useCallback)(()=>{N(),I()},[N,I]),le=!!(y.trim()||x);return i?z?(0,Y.jsxs)(`div`,{className:`mx-auto w-full max-w-app-main px-4 py-8`,children:[(0,Y.jsx)(`div`,{className:`h-8 w-48 animate-pulse rounded bg-surface-hover`}),(0,Y.jsx)(`div`,{className:`mt-6 h-32 animate-pulse rounded-xl bg-surface-hover`}),(0,Y.jsx)(`p`,{className:`mt-4 text-sm text-fg-muted`,children:t.logs.loading})]}):re.length===0?(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-10`,children:[(0,Y.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-base px-4 py-3`,children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:n.loadError}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:p??ne??n.empty})]}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,onClick:()=>{N(),I()},children:t.logs.refresh})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.providers}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,Y.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:n.rotateHint})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[h===`saved`?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,h===`noChanges`?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.noChangesSaved}):null,(0,Y.jsx)(q,{type:`button`,variant:`secondary`,disabled:!B||u,onClick:H,children:n.discard}),(0,Y.jsx)(q,{type:`button`,variant:`primary`,disabled:!B||u,onClick:()=>void oe(),children:u?n.saving:n.save})]})]}),B?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,(0,Y.jsxs)(`p`,{className:`text-sm leading-relaxed text-fg-muted`,children:[n.intro,` `,(0,Y.jsx)(`a`,{href:fe(e,`models`),target:`_blank`,rel:`noopener noreferrer`,className:`font-medium text-accent-fg hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:n.docsLink}),` · `,(0,Y.jsx)(qe,{to:`/settings/models`,className:`font-medium text-accent-fg hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:n.modelsLink})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-center`,children:[(0,Y.jsxs)(`div`,{className:`relative min-w-0 flex-1 sm:max-w-md`,children:[(0,Y.jsx)(Ie,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-fg-subtle`,strokeWidth:1.75,"aria-hidden":!0}),(0,Y.jsx)(`input`,{type:`search`,value:y,onChange:e=>b(e.target.value),placeholder:n.searchPlaceholder,autoComplete:`off`,className:a(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-10 pr-3 text-sm text-fg placeholder:text-fg-subtle`,f,`dark:border-edge`),"aria-label":n.searchPlaceholder})]}),(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg-muted`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:x,onChange:e=>S(e.target.checked),className:`size-4 rounded border-edge text-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`}),n.unconfiguredOnly]}),le?(0,Y.jsx)(q,{type:`button`,variant:`ghost`,className:`h-9 w-fit self-start text-fg-muted`,onClick:()=>{b(``),S(!1)},children:n.clearFilters}):null]}),p?(0,Y.jsx)(`div`,{className:`rounded-md border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-red-900/50 dark:bg-red-950/50 dark:text-red-400`,role:`alert`,children:p}):null,ie.length===0?(0,Y.jsxs)(`div`,{className:`rounded-xl border border-dashed border-edge-subtle bg-surface-base px-4 py-8 text-center text-sm text-fg-muted`,children:[(0,Y.jsx)(`p`,{children:n.noMatches}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,className:`mt-4`,onClick:()=>{b(``),S(!1)},children:n.clearFilters})]}):(0,Y.jsx)(`div`,{className:`flex flex-col gap-3`,children:dr.map(t=>{let r=ae.get(t)??[];if(r.length===0)return null;let i=_.has(t),l=r.filter(e=>e.configured).length,u=`providers-cat-${t}`;return(0,Y.jsxs)(`section`,{className:`overflow-hidden rounded-2xl bg-surface-base`,children:[(0,Y.jsxs)(`button`,{type:`button`,id:`${u}-trigger`,"aria-expanded":i,"aria-controls":u,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:()=>ce(t),children:[(0,Y.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)(`span`,{className:`truncate`,children:n.categories[t]}),(0,Y.jsx)(`span`,{className:`shrink-0 rounded bg-surface-hover px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-fg-subtle`,children:r.length})]}),(0,Y.jsxs)(`span`,{className:`flex shrink-0 items-center gap-2`,children:[l>0?(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-fg-subtle`,children:[(0,Y.jsx)(Me,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}),pr(n.configuredCount,{count:String(l)})]}):null,(0,Y.jsx)(xe,{className:a(`size-4 text-fg-subtle transition-transform`,i&&`rotate-180`),"aria-hidden":!0})]})]}),i?(0,Y.jsx)(`div`,{id:u,role:`region`,"aria-labelledby":`${u}-trigger`,className:`divide-y divide-edge-subtle`,children:r.map(t=>(0,Y.jsx)(`div`,{id:`provider-row-${t.id}`,children:(0,Y.jsx)(gr,{row:t,value:o[t.id]??``,rowDirty:(o[t.id]??``)!==(c[t.id]??``),labels:n,language:e,onChange:(e,t)=>s(n=>({...n,[e]:t})),onReload:W,justSaved:w.has(t.id),availableModels:L??[]})},t.id))}):null]},t)})})]}):(0,Y.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-10`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-3 rounded-2xl bg-surface-base p-6`,children:[(0,Y.jsx)(C,{className:`mt-0.5 size-5 shrink-0 text-fg-subtle`,strokeWidth:1.75}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-base font-semibold text-fg`,children:t.settingsSections.providers}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.needToken})]})]})})}var vr=[{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 yr(e,t){let n=O(e).systemSettings.status;return t===`granted`?{label:n.granted,className:`text-emerald-600 dark:text-emerald-400`}:t===`denied`?{label:n.denied,className:`text-amber-600 dark:text-amber-400`}:{label:n.unknown,className:`text-fg-muted`}}function br(){let e=se(e=>e.language),t=O(e).systemSettings,[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(null),c=typeof window<`u`?window.electronAPI?.system:void 0,l=(0,X.useCallback)(async()=>{if(c){s(null);try{r(await c.getBehavior()),a(await c.getPermissions())}catch(e){s(e instanceof Error?e.message:String(e))}}},[c]);if((0,X.useEffect)(()=>{z()&&c&&l()},[c,l]),!z()||!c)return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.title}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:t.desktopOnlyTitle}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:t.desktopOnlyBody})]})]});let u=async e=>{try{let{behavior:t}=await c.setBehavior(e);r(t)}catch(e){s(e instanceof Error?e.message:String(e))}},d=async e=>{try{(await c.openPrivacy(e)).ok||s(`open_privacy failed`)}catch(e){s(e instanceof Error?e.message:String(e))}},f=n?n.platform===`win32`?t.permissionsHintWin:n.platform===`linux`?t.permissionsHintLinux:n.platform===`darwin`?t.permissionsHintDarwin:t.permissionsHint:t.permissionsHint;return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[(0,Y.jsx)(`div`,{children:(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.title})}),o?(0,Y.jsx)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:o}):null,(0,Y.jsxs)(gt,{children:[(0,Y.jsxs)(`div`,{className:`mb-4 flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)(R,{className:`size-4 text-accent`,strokeWidth:1.75}),t.behaviorGroup]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.openAtLogin}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.openAtLoginDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!n,checked:!!n?.openAtLogin,onChange:e=>{u({openAtLogin:e.target.checked})}})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.keepAwake}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.keepAwakeDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!n,checked:!!n?.keepAwakePreferred,onChange:e=>{u({keepAwakePreferred:e.target.checked})}})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.notifyDesktop}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.notifyDesktopDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!n,checked:!!n?.notifyEnabled,onChange:e=>{u({notifyEnabled:e.target.checked})}})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.notifySound}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.notifySoundDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!n,checked:!!n?.notifySoundEnabled,onChange:e=>{u({notifySoundEnabled:e.target.checked})}})]})]})]}),n&&i?(0,Y.jsxs)(`section`,{className:J(),children:[(0,Y.jsxs)(`div`,{className:`mb-4 flex flex-col gap-1 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:t.permissionsTitle}),(0,Y.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:f})]}),(0,Y.jsx)(`button`,{type:`button`,className:`mt-2 inline-flex max-w-full items-center justify-center rounded-lg border border-edge bg-surface-panel px-3 py-1.5 text-sm font-medium text-fg transition-colors hover:bg-surface-hover sm:mt-0`,onClick:()=>void l(),children:t.refresh})]}),(0,Y.jsx)(`ul`,{className:`space-y-3`,children:vr.map(({key:r,pane:o})=>{let l=yr(e,i[r]),u=t.perm[r];return u?(0,Y.jsxs)(`li`,{className:`flex flex-col gap-2 rounded-xl border border-edge-subtle bg-surface-panel/60 px-3 py-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:u.title}),(0,Y.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:u.desc}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs font-medium ${l.className}`,children:l.label})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[r===`microphone`&&n?.platform===`darwin`?(0,Y.jsx)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover`,onClick:()=>{(async()=>{try{await c.requestMicrophone(),a(await c.getPermissions())}catch(e){s(e instanceof Error?e.message:String(e))}})()},children:e===`zh`?`请求访问`:`Request`}):null,(0,Y.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover`,onClick:()=>void d(o),children:[t.openSettings,(0,Y.jsx)(v,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0})]})]})]},r):null})})]}):null]})}function xr(){return{enabled:!1,provider:`alibaba`,alibaba:{model:`paraformer-v2`},openai:{model:`whisper-1`},fallback:{enabled:!0,order:[`alibaba`,`openai`]}}}function Sr(){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 Cr(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function wr(e){let t=xr();if(!Cr(e))return t;let n=e.provider===`openai`?`openai`:`alibaba`,r=Cr(e.alibaba)?{...t.alibaba,...e.alibaba}:t.alibaba,i=Cr(e.openai)?{...t.openai,...e.openai}:t.openai,a=t.fallback??{enabled:!0,order:[`alibaba`,`openai`]};if(Cr(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 Tr(e){return typeof e==`string`&&e.trim().length>0?e.trim():`openai`}function Er(e){let t=Sr();if(!Cr(e))return t;let n=Tr(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:Cr(e.alibaba)?{...t.alibaba,...e.alibaba}:t.alibaba,openai:Cr(e.openai)?{...t.openai,...e.openai}:t.openai,edge:Cr(e.edge)?{...t.edge,...e.edge}:t.edge,minimax:Cr(e.minimax)?{...t.minimax,...e.minimax}:t.minimax,"tts-local-cli":Cr(i)?{...t[`tts-local-cli`],...i}:t[`tts-local-cli`]}}function Dr(e){let t=Cr(e)?e:{};return{stt:wr(t.stt),tts:Er(t.tts)}}async function Or(e){await Oe(U(`/api/config`),{method:`PATCH`,body:JSON.stringify({stt:e.stt,tts:e.tts})}),Ue()}async function kr(){let e=await Oe(U(`/api/voice/models`));if(!e.payload?.models)throw Error(`Missing voice models payload`);return e.payload.models}function Ar(){return a(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,f,`dark:border-edge`)}function jr(){return a(m,We)}var Mr=[{id:`paraformer-v2`,name:`Paraformer v2`},{id:`paraformer-v1`,name:`Paraformer v1`}],Nr=[{id:`whisper-1`,name:`Whisper-1`}],Pr=[{id:`tts-1`,name:`TTS-1`},{id:`tts-1-hd`,name:`TTS-1 HD`}],Fr=[{id:`alloy`,name:`Alloy`},{id:`echo`,name:`Echo`}],Ir=[{id:`qwen-tts`,name:`Qwen TTS`},{id:`qwen3-tts-flash`,name:`Qwen3 TTS Flash`}],Lr=[{id:`Cherry`,name:`Cherry`},{id:`longxiaochun`,name:`Long Xiao Chun`}],Rr=[{id:`en-US-MichelleNeural`,name:`Michelle (US English)`},{id:`zh-CN-XiaoxiaoNeural`,name:`Xiaoxiao (Chinese)`}],zr=[{id:`speech-2.8-hd`,name:`Speech 2.8 HD (Recommended)`},{id:`speech-2.8-turbo`,name:`Speech 2.8 Turbo (Fast)`}],Br=[{id:`male-qn-qingse`,name:`Male Qingse (青涩男声)`},{id:`female-shaonv`,name:`Female Shaonv (少女音)`}];function Vr(){let e=se(e=>e.language),t=O(e),n=t.voiceSettings,i=!!K(e=>e.token),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(null),[f,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(!1),{data:y,error:b,isLoading:x,mutate:S}=Ye(i),{data:C,error:w,isLoading:T,mutate:E}=r(i?U(`/api/voice/models`):null,kr,{revalidateOnFocus:!1}),D=(0,X.useMemo)(()=>y?.payload?.config===void 0?null:Dr(y.payload.config),[y]),k=(0,X.useMemo)(()=>!a||!s?!1:JSON.stringify(a)!==JSON.stringify(s),[a,s]);(0,X.useEffect)(()=>{if(!i){o(null),c(null),u(null);return}D===null||C===void 0||k||(o(structuredClone(D)),c(structuredClone(D)),u(C),_(!1))},[i,D,C,k]);let A=!!(i&&(D===null||C===void 0)&&(x||T)),j=b instanceof Error?b.message:b?String(b):w instanceof Error?w.message:w?String(w):null,M=(0,X.useCallback)(e=>{o(t=>t?{...t,stt:{...t.stt,...e}}:null)},[]),N=(0,X.useCallback)(e=>{o(t=>t?{...t,stt:{...t.stt,alibaba:{...t.stt.alibaba,...e}}}:null)},[]),ee=(0,X.useCallback)(e=>{o(t=>t?{...t,stt:{...t.stt,openai:{...t.stt.openai,...e}}}:null)},[]),P=(0,X.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}}}})},[]),F=(0,X.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,...e}}:null)},[]),I=(0,X.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,alibaba:{...t.tts.alibaba,...e}}}:null)},[]),L=(0,X.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,openai:{...t.tts.openai,...e}}}:null)},[]),te=(0,X.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,edge:{...t.tts.edge,...e}}}:null)},[]),R=(0,X.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,minimax:{...t.tts.minimax,...e}}}:null)},[]),ne=(0,X.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,"tts-local-cli":{...t.tts[`tts-local-cli`],...e}}}:null)},[]),z=(0,X.useCallback)(async()=>{if(!(!a||f)){p(!0),h(null),_(!1);try{await Or(a);let e=structuredClone(a);c(e),o(e),_(!0),window.setTimeout(()=>_(!1),2500)}catch(e){h(e instanceof Error?e.message:n.saveError)}finally{p(!1)}}},[a,f,n.saveError]),B=(0,X.useCallback)(()=>{s&&(o(structuredClone(s)),h(null),_(!1))},[s]);if(!i)return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.voice}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]});if(A)return(0,Y.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,Y.jsx)(d,{className:`size-4 animate-spin`}),n.loading]})});if(!a||l===null)return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:m??j??n.loadError}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,onClick:()=>{S(),E()},children:n.retry})]});let re=a.stt,V=a.tts;return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.voice}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,Y.jsxs)(`a`,{href:fe(e,`voice`),target:`_blank`,rel:`noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-sm text-accent hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,children:[n.docsLink,(0,Y.jsx)(v,{className:`size-3.5`})]})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[g?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,Y.jsx)(q,{type:`button`,variant:`secondary`,disabled:!k||f,onClick:B,children:n.discard}),(0,Y.jsx)(q,{type:`button`,variant:`primary`,disabled:!k||f,onClick:()=>void z(),children:f?n.saving:n.save})]})]}),k?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,m?(0,Y.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:m}):null,(0,Y.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Y.jsx)(Hr,{v:n,stt:re,models:l,updateStt:M,updateSttAlibaba:N,updateSttOpenai:ee,updateSttFallback:P}),(0,Y.jsx)(Ur,{v:n,tts:V,models:l,updateTts:F,updateTtsAlibaba:I,updateTtsOpenai:L,updateTtsEdge:te,updateTtsMinimax:R,updateTtsLocalCli:ne})]}),(0,Y.jsxs)(`div`,{className:`rounded-xl border border-accent/25 bg-accent/5 px-4 py-3 dark:border-accent/30 dark:bg-accent/10`,children:[(0,Y.jsxs)(`p`,{className:`text-sm text-fg`,children:[(0,Y.jsx)(`strong`,{className:`text-accent`,children:n.notes.title}),` `,n.notes.duration]}),(0,Y.jsx)(`p`,{className:`mt-2 text-xs text-fg-muted`,children:n.notes.envVars})]})]})}function Hr({v:e,stt:t,models:n,updateStt:r,updateSttAlibaba:i,updateSttOpenai:o,updateSttFallback:s}){let c=n?.stt?.alibaba?.length?n.stt.alibaba:Mr,l=n?.stt?.openai?.length?n.stt.openai:Nr;return(0,Y.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[(0,Y.jsxs)(`div`,{className:`mb-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)(pe,{className:`size-4 text-accent`,strokeWidth:1.75}),e.stt.title]}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:e.stt.description})]}),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.stt.enable}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.stt.enableDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:t.enabled,onChange:e=>r({enabled:e.target.checked})})]}),t.enabled?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.provider}),(0,Y.jsxs)(`select`,{className:jr(),value:t.provider,onChange:e=>r({provider:e.target.value}),children:[(0,Y.jsx)(`option`,{value:`alibaba`,children:e.stt.alibaba}),(0,Y.jsx)(`option`,{value:`openai`,children:e.stt.openai})]})]})}),t.provider===`alibaba`?(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.apiKey}),(0,Y.jsx)(`input`,{className:a(Ar(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.alibaba?.apiKey??``,onChange:e=>i({apiKey:e.target.value}),placeholder:`sk-...`}),(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (DASHSCOPE_API_KEY)`]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:jr(),value:t.alibaba?.model??``,onChange:e=>i({model:e.target.value}),children:c.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}):(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.apiKey}),(0,Y.jsx)(`input`,{className:a(Ar(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.openai?.apiKey??``,onChange:e=>o({apiKey:e.target.value}),placeholder:`sk-...`}),(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (OPENAI_API_KEY)`]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:jr(),value:t.openai?.model??``,onChange:e=>o({model:e.target.value}),children:l.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.stt.fallback}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.stt.fallbackDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:t.fallback?.enabled??!0,onChange:e=>s({enabled:e.target.checked})})]})]}):null]})]})}function Ur({v:e,tts:t,models:n,updateTts:r,updateTtsAlibaba:i,updateTtsOpenai:o,updateTtsEdge:s,updateTtsMinimax:c,updateTtsLocalCli:l}){let u=t=>t===`off`?e.tts.triggerDescOff:t===`always`?e.tts.triggerDescAlways:t===`inbound`?e.tts.triggerDescInbound:t===`tagged`?e.tts.triggerDescTagged:``,d=n?.tts?.openai?.length?n.tts.openai:Pr,f=n?.ttsVoices?.openai?.length?n.ttsVoices.openai:Fr,p=n?.tts?.alibaba?.length?n.tts.alibaba:Ir,m=n?.ttsVoices?.alibaba?.length?n.ttsVoices.alibaba:Lr,g=n?.ttsVoices?.edge?.length?n.ttsVoices.edge:Rr,_=n?.tts?.minimax?.length?n.tts.minimax:zr,v=n?.ttsVoices?.minimax?.length?n.ttsVoices.minimax:Br;return(0,Y.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[(0,Y.jsxs)(`div`,{className:`mb-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)(h,{className:`size-4 text-accent`,strokeWidth:1.75}),e.tts.title]}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:e.tts.description})]}),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.tts.enable}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.tts.enableDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:t.enabled,onChange:e=>r({enabled:e.target.checked})})]}),t.enabled?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.tts.trigger}),(0,Y.jsxs)(`select`,{className:jr(),value:t.trigger,onChange:e=>r({trigger:e.target.value}),children:[(0,Y.jsx)(`option`,{value:`off`,children:e.tts.triggerOff}),(0,Y.jsx)(`option`,{value:`always`,children:e.tts.triggerAlways}),(0,Y.jsx)(`option`,{value:`inbound`,children:e.tts.triggerInbound}),(0,Y.jsx)(`option`,{value:`tagged`,children:e.tts.triggerTagged})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:u(t.trigger)})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.tts.provider}),(0,Y.jsxs)(`select`,{className:jr(),value:t.provider,onChange:e=>r({provider:e.target.value}),children:[(0,Y.jsx)(`option`,{value:`openai`,children:e.tts.providerOpenai}),(0,Y.jsx)(`option`,{value:`alibaba`,children:e.stt.alibaba}),(0,Y.jsx)(`option`,{value:`minimax`,children:`MiniMax`}),(0,Y.jsx)(`option`,{value:`edge`,children:e.tts.providerEdge}),(0,Y.jsx)(`option`,{value:`tts-local-cli`,children:e.tts.providerLocalCli})]})]})]}),t.provider===`openai`?(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,Y.jsx)($,{children:e.stt.apiKey}),(0,Y.jsx)(`input`,{className:a(Ar(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.openai?.apiKey??``,onChange:e=>o({apiKey:e.target.value}),placeholder:`sk-...`}),(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (OPENAI_API_KEY)`]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:jr(),value:t.openai?.model??``,onChange:e=>o({model:e.target.value}),children:d.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.tts.voice}),(0,Y.jsx)(`select`,{className:jr(),value:t.openai?.voice??``,onChange:e=>o({voice:e.target.value}),children:f.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}):null,t.provider===`alibaba`?(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,Y.jsx)($,{children:e.stt.apiKey}),(0,Y.jsx)(`input`,{className:a(Ar(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.alibaba?.apiKey??``,onChange:e=>i({apiKey:e.target.value}),placeholder:`sk-...`}),(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (DASHSCOPE_API_KEY)`]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:jr(),value:t.alibaba?.model??``,onChange:e=>i({model:e.target.value}),children:p.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.tts.voice}),(0,Y.jsx)(`select`,{className:jr(),value:t.alibaba?.voice??``,onChange:e=>i({voice:e.target.value}),children:m.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}):null,t.provider===`minimax`?(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,Y.jsx)($,{children:e.stt.apiKey}),(0,Y.jsx)(`input`,{className:a(Ar(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.minimax?.apiKey??``,onChange:e=>c({apiKey:e.target.value}),placeholder:`eyJ...`}),(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (MINIMAX_API_KEY)`]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:jr(),value:t.minimax?.model??``,onChange:e=>c({model:e.target.value}),children:_.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.tts.voice}),(0,Y.jsx)(`select`,{className:jr(),value:t.minimax?.voice??``,onChange:e=>c({voice:e.target.value}),children:v.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}):null,t.provider===`edge`?(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.tts.voice}),(0,Y.jsx)(`select`,{className:jr(),value:t.edge?.voice??``,onChange:e=>s({voice:e.target.value}),children:g.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.edgeHint})]}):null,t.provider===`tts-local-cli`?(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,Y.jsx)($,{children:e.tts.localCli.command}),(0,Y.jsx)(`input`,{className:a(Ar(),`font-mono text-xs`),type:`text`,autoComplete:`off`,spellCheck:!1,value:t[`tts-local-cli`]?.command??``,onChange:e=>l({command:e.target.value}),placeholder:e.tts.localCli.commandPlaceholder}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.commandDesc})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.tts.localCli.cwd}),(0,Y.jsx)(`input`,{className:a(Ar(),`font-mono text-xs`),type:`text`,autoComplete:`off`,spellCheck:!1,value:t[`tts-local-cli`]?.cwd??``,onChange:e=>l({cwd:e.target.value}),placeholder:`/path/to/cwd`}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.cwdDesc})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.tts.localCli.outputFormat}),(0,Y.jsxs)(`select`,{className:jr(),value:t[`tts-local-cli`]?.outputFormat??`wav`,onChange:e=>l({outputFormat:e.target.value}),children:[(0,Y.jsx)(`option`,{value:`wav`,children:`wav`}),(0,Y.jsx)(`option`,{value:`mp3`,children:`mp3`}),(0,Y.jsx)(`option`,{value:`opus`,children:`opus`})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.outputFormatDesc})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,Y.jsx)($,{children:e.tts.localCli.timeoutMs}),(0,Y.jsx)(`input`,{className:Ar(),type:`number`,min:0,step:1e3,value:typeof t[`tts-local-cli`]?.timeoutMs==`number`?String(t[`tts-local-cli`].timeoutMs):``,onChange:e=>{let t=e.target.value.trim();if(t===``){l({timeoutMs:void 0});return}let n=Number(t);Number.isFinite(n)&&n>=0&&l({timeoutMs:n})},placeholder:`30000`}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.timeoutMsDesc})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle sm:col-span-2`,children:e.tts.localCli.hint})]}):null]}):null]})]})}function $({children:e}){return(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e})}function Wr(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 Gr(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 Oe(U(`/api/config`),{method:`PATCH`,body:JSON.stringify({tools:{web:{region:t,search:n}}})}),Ue()}function Kr({label:e,description:t,children:n}){return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e}),n,(0,Y.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:t})]})}function qr(){return a(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,f,`dark:border-edge`)}function Jr(){return a(m,We)}var Yr=[`brave`,`tavily`,`bing`,`searxng`];function Xr(){return{type:`brave`,apiKey:``,url:``,disabled:!1}}function Zr(){let e=se(e=>e.language),t=O(e),n=t.webSearchSettings,r=t.logs,i=!!K(e=>e.token),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(!1),[f,p]=(0,X.useState)(null),[m,h]=(0,X.useState)(!1),g=(0,X.useRef)(!1),{data:_,error:y,isLoading:b,mutate:x}=Ye(i),S=(0,X.useMemo)(()=>_?.payload?.config===void 0?null:Wr(_.payload.config),[_]);(0,X.useEffect)(()=>{if(!i){o(null),c(null),g.current=!1;return}S!==null&&(g.current||(o(S),c(S)))},[i,S]);let C=!!(i&&b&&_===void 0&&!y),w=y instanceof Error?y.message:y?String(y):null,T=(0,X.useMemo)(()=>!a||!s?!1:JSON.stringify(a)!==JSON.stringify(s),[a,s]),E=(0,X.useCallback)(e=>{g.current=!0,o(t=>t?{...t,...e}:null)},[]),D=(0,X.useCallback)(async()=>{if(!(!a||l)){u(!0),p(null),h(!1);try{await Gr(a);let e=structuredClone(a);c(e),o(e),g.current=!1,h(!0),window.setTimeout(()=>h(!1),2500)}catch(e){p(e instanceof Error?e.message:n.saveError)}finally{u(!1)}}},[a,l,n.saveError]),k=(0,X.useCallback)(()=>{s&&(g.current=!1,o(structuredClone(s)),p(null),h(!1))},[s]);return i?C?(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col items-center gap-3 px-4 py-8`,children:[(0,Y.jsx)(d,{className:`size-8 animate-spin text-fg-muted`,"aria-hidden":!0}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.loading})]}):a?(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.title}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,Y.jsxs)(`a`,{href:fe(e,`gateway`),target:`_blank`,rel:`noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-sm text-accent hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,children:[n.docsLink,(0,Y.jsx)(v,{className:`size-3.5`})]})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[m?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,Y.jsx)(q,{type:`button`,variant:`secondary`,disabled:!T||l,onClick:k,children:n.discard}),(0,Y.jsx)(q,{type:`button`,variant:`primary`,disabled:!T||l,onClick:()=>void D(),children:l?n.saving:n.save})]})]}),T?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,f?(0,Y.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:f}):null,(0,Y.jsxs)(gt,{children:[(0,Y.jsx)(_t,{icon:Ie,title:n.sectionRegion,subtitle:n.sectionRegionHint}),(0,Y.jsx)(`div`,{className:`flex max-w-md flex-col gap-4`,children:(0,Y.jsx)(Kr,{label:n.regionLabel,description:n.regionDesc,children:(0,Y.jsxs)(`select`,{className:Jr(),value:a.regionMode,onChange:e=>E({regionMode:e.target.value}),children:[(0,Y.jsx)(`option`,{value:`auto`,children:n.regionAuto}),(0,Y.jsx)(`option`,{value:`cn`,children:n.regionCn}),(0,Y.jsx)(`option`,{value:`global`,children:n.regionGlobal})]})})})]}),(0,Y.jsxs)(gt,{children:[(0,Y.jsx)(_t,{icon:Ie,title:n.sectionSearch,subtitle:n.sectionSearchHint}),(0,Y.jsxs)(`div`,{className:`flex max-w-xl flex-col gap-6`,children:[(0,Y.jsx)(Kr,{label:n.maxResultsLabel,description:n.maxResultsDesc,children:(0,Y.jsx)(`input`,{type:`number`,min:1,max:50,className:qr(),value:a.maxResults,onChange:e=>E({maxResults:Math.max(1,Math.min(50,Number(e.target.value)||5))})})}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.providersTitle}),a.providers.map((e,t)=>(0,Y.jsx)(Qr,{row:e,labels:n,onChange:e=>{let n=[...a.providers];n[t]=e,E({providers:n})},onRemove:()=>{E({providers:a.providers.filter((e,n)=>n!==t)})}},t)),(0,Y.jsxs)(q,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5 text-sm`,onClick:()=>E({providers:[...a.providers,Xr()]}),children:[(0,Y.jsx)(W,{className:`size-4`}),n.addProvider]})]})]})]}),(0,Y.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:n.footerHint})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:f??w??n.loadError}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,onClick:()=>void x(),children:r.refresh})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-4 px-4 py-6`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:n.title}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}function Qr({row:e,labels:t,onChange:n,onRemove:r}){return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-xl border border-edge-subtle bg-surface-panel/60 p-4 dark:border-edge-subtle`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,Y.jsx)(`select`,{className:a(Jr(),`min-w-[8rem]`),value:e.type,onChange:t=>n({...e,type:t.target.value,url:t.target.value===`searxng`?e.url:``}),children:Yr.map(e=>(0,Y.jsx)(`option`,{value:e,children:t.providerTypes[e]},e))}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1.5 text-xs text-fg-muted`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`size-3.5 rounded border-edge`,checked:e.disabled,onChange:t=>n({...e,disabled:t.target.checked})}),t.disabled]}),(0,Y.jsx)(q,{type:`button`,variant:`ghost`,className:`h-8 px-2 text-fg-muted`,onClick:r,children:(0,Y.jsx)(c,{className:`size-4`})})]})]}),e.type===`searxng`?(0,Y.jsx)(Kr,{label:t.urlLabel,description:t.urlDesc,children:(0,Y.jsx)(`input`,{type:`url`,className:qr(),value:e.url,placeholder:`http://localhost:8080`,onChange:t=>n({...e,url:t.target.value})})}):null,(0,Y.jsx)(Kr,{label:t.apiKeyLabel,description:t.apiKeyDesc,children:(0,Y.jsx)(`input`,{type:`password`,autoComplete:`off`,className:qr(),value:we(e.apiKey)?``:e.apiKey,placeholder:we(e.apiKey)?t.keyPlaceholderMasked:t.keyPlaceholder,onChange:t=>n({...e,apiKey:t.target.value})})})]})}var $r=[`appearance`,`system`,`agent-chat`,`agent-workspace`,`agent-browser`,`agent-runtime`,`agent-tools`,`agent-system-prompt`,`providers`,`models`,`image-models`,`voice`,`gateway`,`heartbeat`,`search`,`dreams`];function ei(){let{section:e}=l(),t=se(e=>e.language),n=O(t);if(e===`agent`||e===`agents`)return(0,Y.jsx)(oe,{to:`/agents`,replace:!0});if(!e||!$r.includes(e))return(0,Y.jsx)(oe,{to:`/settings/appearance`,replace:!0});let r=e,i=n.settingsSections[r];return r===`appearance`?(0,Y.jsx)(Tt,{}):r===`system`?(0,Y.jsx)(br,{}):r===`agent-chat`?(0,Y.jsx)(lt,{}):r===`agent-workspace`?(0,Y.jsx)(ut,{}):r===`agent-browser`?(0,Y.jsx)(mt,{}):r===`agent-runtime`?(0,Y.jsx)(ft,{}):r===`agent-tools`?(0,Y.jsx)(et,{}):r===`agent-system-prompt`?(0,Y.jsx)(ot,{}):r===`providers`?(0,Y.jsx)(_r,{}):r===`models`?(0,Y.jsx)(rr,{}):r===`image-models`?(0,Y.jsx)(On,{}):r===`voice`?(0,Y.jsx)(Vr,{}):r===`gateway`?(0,Y.jsx)(Yt,{}):r===`heartbeat`?(0,Y.jsx)(hn,{}):r===`search`?(0,Y.jsx)(Zr,{}):r===`dreams`?(0,Y.jsx)(Ut,{}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:i}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t===`zh`?`设置 · ${i}(即将推出)。`:`Settings · ${i} (coming soon).`})]})}export{ei as SettingsPage};
2
- //# sourceMappingURL=settings-page-CGDCcKXO.js.map
1
+ import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{i as t,t as n}from"./vendor-react-DbimaAId.js";import{i as r,o as i}from"./vendor-swr-B5fPo7KK.js";import{t as a}from"./cn-BMCV0OMB.js";import{$n as o,At as s,Bn as c,Ci as l,Cn as u,Cr as d,Dn as f,Dt as p,En as m,Fn as h,Fr as g,Ft as _,Gr as v,It as y,K as b,Kn as x,Mn as S,Mr as C,Mt as w,Nn as T,Nr as E,Nt as D,On as O,Ot as k,Pn as A,Pr as j,Pt as M,Sn as N,Sr as ee,Tn as P,Tt as F,Un as I,Ur as L,Wr as te,Xn as R,Xr as ne,Y as z,Yr as B,Zn as re,a as V,ai as ie,ar as ae,bi as oe,bn as se,br as H,c as ce,cn as U,cr as W,dn as le,fi as ue,fn as G,g as de,gn as fe,gr as pe,h as me,hn as K,hr as he,i as ge,ir as _e,jt as ve,kn as q,kt as ye,l as be,li as xe,ln as Se,m as Ce,n as we,o as Te,oi as Ee,or as De,pn as Oe,pr as ke,qn as Ae,r as je,ri as Me,s as Ne,si as Pe,t as Fe,tr as Ie,u as Le,ui as Re,un as ze,ur as Be,vi as Ve,vn as He,vt as Ue,wn as We,wt as Ge,xr as Ke,yi as qe,yn as Je,yt as Ye}from"./index-C9ACajYe.js";import{i as Xe,l as Ze,y as Qe}from"./cron-api-HehSuhku.js";import{_ as $e,a as et,b as J,c as tt,d as nt,f as rt,g as it,h as at,i as ot,l as st,m as ct,n as lt,o as ut,p as dt,r as ft,s as pt,t as mt,u as ht,v as gt,y as _t}from"./agents-3MgROWaB.js";import{t as vt}from"./browser-DNXWYwzc.js";var Y=n();function yt(){return a(`rounded-xl border border-edge-subtle bg-surface-base px-4 py-1 sm:px-5`)}var bt={default:{light:{canvas:`#f5f5f7`,panel:`#ffffff`,accent:`#2563eb`,fg:`#1d1d1f`,muted:`#d2d2d7`},dark:{canvas:`#1c1c1e`,panel:`#2c2c2e`,accent:`#3b82f6`,fg:`#f5f5f7`,muted:`#48484a`}},emerald:{light:{canvas:`#f0fdf4`,panel:`#ffffff`,accent:`#059669`,fg:`#052e16`,muted:`#86efac`},dark:{canvas:`#000000`,panel:`#0a0a0a`,accent:`#10b981`,fg:`#d1fae5`,muted:`#134e2a`}},mono:{light:{canvas:`#ffffff`,panel:`#f5f5f5`,accent:`#111111`,fg:`#111111`,muted:`#e5e7eb`},dark:{canvas:`#101010`,panel:`#1a1a1a`,accent:`#737373`,fg:`#fafafa`,muted:`#333333`}}};function xt({canvas:e,panel:t,accent:n,fg:r,muted:i}){return(0,Y.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col justify-center gap-1 p-1.5`,style:{backgroundColor:e},children:(0,Y.jsxs)(`div`,{className:`flex flex-col gap-0.5 rounded-sm border p-1`,style:{backgroundColor:t,borderColor:i},children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,Y.jsx)(`div`,{className:`h-1 w-1 shrink-0 rounded-full`,style:{backgroundColor:n}}),(0,Y.jsx)(`div`,{className:`h-1 min-w-0 flex-1 rounded-full`,style:{backgroundColor:r,opacity:.85}})]}),(0,Y.jsx)(`div`,{className:`h-1 w-2/3 max-w-[70%] rounded-full`,style:{backgroundColor:i}}),(0,Y.jsx)(`div`,{className:`h-1 w-1/2 max-w-[55%] rounded-full`,style:{backgroundColor:i}})]})})}function St({scheme:e}){let{light:t,dark:n}=bt[e];return(0,Y.jsxs)(`div`,{className:`flex h-11 w-full overflow-hidden rounded-md border border-edge-subtle`,children:[(0,Y.jsx)(xt,{...t}),(0,Y.jsx)(`div`,{className:`w-px shrink-0 bg-black/12 dark:bg-white/12`,"aria-hidden":!0}),(0,Y.jsx)(xt,{...n})]})}var Ct=[{value:`default`,labelKey:`colorSchemeDefault`},{value:`emerald`,labelKey:`colorSchemeLightGreen`},{value:`mono`,labelKey:`colorSchemeModernMono`}];function wt(){let e=O(se(e=>e.language)).appearanceSettings,t=Je(e=>e.colorScheme),n=Je(e=>e.setColorScheme);return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2 border-b border-edge-subtle py-3.5 last:border-b-0 sm:py-4`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:e.colorSchemeTitle}),(0,Y.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:e.colorSchemeDescription})]}),(0,Y.jsx)(`div`,{className:`grid grid-cols-2 gap-3 sm:grid-cols-3`,children:Ct.map(({value:r,labelKey:i})=>{let o=t===r;return(0,Y.jsxs)(`button`,{type:`button`,"aria-pressed":o,onClick:()=>n(r),className:a(`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,Y.jsx)(St,{scheme:r}),(0,Y.jsx)(`span`,{className:a(`text-xs font-medium leading-none`,o?`text-accent-fg`:`text-fg-muted`),children:e[i]})]},r)})})]})}function Tt(){let e=O(se(e=>e.language)).appearanceSettings;return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col gap-1`,children:[(0,Y.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight text-fg`,children:e.pageTitle}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.subtitle})]}),(0,Y.jsxs)(`section`,{className:yt(),"aria-labelledby":`pref-language-heading`,children:[(0,Y.jsx)(`h2`,{id:`pref-language-heading`,className:`sr-only`,children:e.languageTitle}),(0,Y.jsx)(He,{variant:`page`,sections:[`language`]})]}),(0,Y.jsxs)(`section`,{className:yt(),"aria-labelledby":`pref-appearance-heading`,children:[(0,Y.jsx)(`h2`,{id:`pref-appearance-heading`,className:`sr-only`,children:e.themeTitle}),(0,Y.jsx)(He,{variant:`page`,sections:[`theme`,`font`]}),(0,Y.jsx)(wt,{})]})]})}var X=e(t(),1);function Et(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var Dt={enabled:!0,cron:`0 */6 * * *`,lookbackDays:1,limit:50,dedupeSimilarity:.85},Ot={enabled:!0,cron:`0 3 * * *`,minScore:.8,minRecallCount:3,limit:10,recencyHalfLifeDays:14,maxAgeDays:30},kt={enabled:!0,cron:`0 5 * * 0`,lookbackDays:7,limit:20,minPatternStrength:.6},At={enabled:!1,frequency:`0 3 * * *`,timezone:``,deepEnabled:!0,minScore:.8,minRecallCount:3,limit:10,light:Dt,deep:Ot,rem:kt};function jt(e,t){return Number.isFinite(e)?Math.max(0,Math.min(1,e)):t}function Mt(e,t){let n=typeof e==`string`?Number(e):e;return Number.isFinite(n)?Math.max(0,Math.floor(n)):t}function Nt(e,t){let n=typeof e==`string`?Number(e):e;return Number.isFinite(n)?n:t}function Pt(e){let t=Et(e)?e:{},n=Et(t.agents)?t.agents:{},r=Et(n.defaults)?n.defaults:{},i=Et(r.memory)?r.memory:{},a=Et(i.dreaming)?i.dreaming:{},o=Et(a.phases)?a.phases:{},s=Et(o.light)?o.light:{},c=Et(o.deep)?o.deep:{},l=Et(o.rem)?o.rem:{};return{enabled:a.enabled===!0,frequency:typeof a.frequency==`string`&&a.frequency.trim()?a.frequency.trim():At.frequency,timezone:typeof a.timezone==`string`?a.timezone:``,deepEnabled:c.enabled!==!1,minScore:jt(typeof c.minScore==`number`?c.minScore:Number(c.minScore),At.minScore),minRecallCount:Math.max(1,Mt(c.minRecallCount,At.minRecallCount)),limit:Mt(c.limit,At.limit),light:{enabled:s.enabled!==!1,cron:typeof s.cron==`string`&&s.cron.trim()?s.cron.trim():Dt.cron,lookbackDays:Math.max(1,Mt(s.lookbackDays,Dt.lookbackDays)),limit:Mt(s.limit,Dt.limit),dedupeSimilarity:jt(Nt(s.dedupeSimilarity,Dt.dedupeSimilarity),Dt.dedupeSimilarity)},deep:{enabled:c.enabled!==!1,cron:typeof c.cron==`string`&&c.cron.trim()?c.cron.trim():Ot.cron,minScore:jt(Nt(c.minScore,Ot.minScore),Ot.minScore),minRecallCount:Math.max(1,Mt(c.minRecallCount,Ot.minRecallCount)),limit:Mt(c.limit,Ot.limit),recencyHalfLifeDays:Math.max(1,Nt(c.recencyHalfLifeDays,Ot.recencyHalfLifeDays)),maxAgeDays:Math.max(1,Nt(c.maxAgeDays,Ot.maxAgeDays))},rem:{enabled:l.enabled!==!1,cron:typeof l.cron==`string`&&l.cron.trim()?l.cron.trim():kt.cron,lookbackDays:Math.max(1,Mt(l.lookbackDays,kt.lookbackDays)),limit:Mt(l.limit,kt.limit),minPatternStrength:jt(Nt(l.minPatternStrength,kt.minPatternStrength),kt.minPatternStrength)}}}async function Ft(e){let t=e.frequency.trim(),n=e.timezone.trim();await Oe(U(`/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:jt(e.light.dedupeSimilarity,Dt.dedupeSimilarity)},deep:{enabled:!!e.deep.enabled,cron:e.deep.cron.trim()||null,minScore:jt(e.deep.minScore,Ot.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:jt(e.rem.minPatternStrength,kt.minPatternStrength)}}}}}}})}),Ue()}function Z(){return`text-xs font-medium text-fg-muted`}function Q(){return`text-sm font-medium text-fg`}function It(e){return e?e.replace(`T`,` `).replace(`Z`,``):`—`}function Lt(e){return e===void 0||!Number.isFinite(e)||e<0?`—`:e<1e3?`${Math.round(e)} ms`:`${(e/1e3).toFixed(2)} s`}function Rt({label:e,children:t,className:n}){return(0,Y.jsxs)(`div`,{className:a(`space-y-2`,n),children:[(0,Y.jsx)(`h3`,{className:`text-[0.7rem] font-semibold uppercase tracking-wider text-fg-muted`,children:e}),t]})}function zt({icon:e,label:t,enabled:n,cron:r,details:i,t:o}){return(0,Y.jsxs)(`div`,{className:a(J(),`space-y-1.5`),children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e,(0,Y.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:t}),(0,Y.jsx)(`span`,{className:a(`ml-auto text-xs font-medium`,n?`text-emerald-600 dark:text-emerald-400`:`text-fg-muted`),children:n?o.on:o.off})]}),(0,Y.jsx)(`div`,{className:`font-mono text-xs text-fg-muted`,children:r}),(0,Y.jsx)(`div`,{className:`text-xs text-fg-muted`,children:i})]})}function Bt({label:e,lastRun:t,t:n}){return(0,Y.jsx)(Rt,{label:e,children:t?.exists?(0,Y.jsxs)(`details`,{className:`group rounded-lg border border-edge-subtle`,children:[(0,Y.jsx)(`summary`,{className:`cursor-pointer list-none px-3 py-2 text-xs font-medium text-fg-muted marker:hidden [&::-webkit-details-marker]:hidden`,children:(0,Y.jsx)(`span`,{className:`underline decoration-edge underline-offset-2 group-open:text-fg`,children:n.lastRunRaw})}),(0,Y.jsx)(`pre`,{className:`max-h-[12rem] overflow-auto border-t border-edge-subtle p-3 text-xs text-fg-muted`,children:JSON.stringify(t.raw,null,2)})]}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.phaseLastRunEmpty})})}function Vt({t:e,r:t}){let n=t.deep?.skipped;return(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.lastRunStatus}),(0,Y.jsx)(`div`,{className:a(Q(),t.ok?`text-emerald-600 dark:text-emerald-400`:`text-amber-600 dark:text-amber-400`),children:t.ok?e.lastRunSuccess:e.lastRunFailure})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.lastRunDuration}),(0,Y.jsx)(`div`,{className:Q(),children:Lt(t.durationMs)})]}),(0,Y.jsxs)(`div`,{className:a(J(),`sm:col-span-2`),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.lastRunReason}),(0,Y.jsx)(`div`,{className:Q(),children:t.reason}),t.errorMessage?(0,Y.jsx)(`div`,{className:`mt-1 text-xs text-amber-600 dark:text-amber-400`,children:`${e.lastRunError}: ${t.errorMessage}`}):null]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.lastRunRanked}),(0,Y.jsx)(`div`,{className:Q(),children:String(t.deep?.candidatesRanked??`—`)})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.lastRunApplied}),(0,Y.jsx)(`div`,{className:Q(),children:String(t.deep?.applied??`—`)})]}),n?(0,Y.jsxs)(`div`,{className:`sm:col-span-2`,children:[(0,Y.jsx)(`div`,{className:`mb-2 text-xs font-medium text-fg`,children:e.lastRunSkipped}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.lastRunSkipKey}),(0,Y.jsx)(`div`,{className:Q(),children:String(n.alreadyPromotedKey)})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.lastRunSkipRehydrate}),(0,Y.jsx)(`div`,{className:Q(),children:String(n.rehydrateFailed)})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.lastRunSkipContaminated}),(0,Y.jsx)(`div`,{className:Q(),children:String(n.contaminated)})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.lastRunSkipHash}),(0,Y.jsx)(`div`,{className:Q(),children:String(n.hashDuplicate)})]})]})]}):null]})}function Ht(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 Ut(){let e=O(se(e=>e.language)).dreamingSettings,t=!!K(e=>e.token),{data:n}=Ye(t),[i,o]=(0,X.useState)(null),[s,l]=(0,X.useState)(null),[u,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(!1),[_,v]=(0,X.useState)(null),[y,b]=(0,X.useState)(`deep`),[S,C]=(0,X.useState)(null),[w,T]=(0,X.useState)(null),[E,D]=(0,X.useState)(!1),[k,j]=(0,X.useState)(!1),[M,N]=(0,X.useState)(null),[P,F]=(0,X.useState)(!1),[L,te]=(0,X.useState)(null),[R,ne]=(0,X.useState)(null),[z,B]=(0,X.useState)(!1),[V,ie]=(0,X.useState)(null),[ae,oe]=(0,X.useState)(null),{data:H,error:ce,isLoading:U,mutate:W}=r(t?rt():null,at,{revalidateOnFocus:!1}),le=(0,X.useMemo)(()=>H?Ht(H.lock,e):null,[H,e]),ue=(0,X.useMemo)(()=>{let e=[];return ce&&e.push(ce instanceof Error?ce.message:String(ce)),s&&e.push(s),_&&e.push(_),L&&e.push(L),V&&e.push(V),M&&e.push(M),e},[ce,s,_,L,V,M]),G=(0,X.useMemo)(()=>{let t=[];return k&&t.push(e.configSaved),h&&t.push(e.runQueued),u&&t.push(e.actionOk),t},[k,h,u,e]),de=(0,X.useCallback)(async()=>{f(!1),l(null),g(!1),v(null),j(!1),N(null),te(null),await W()},[W]),fe=(0,X.useCallback)(async()=>{F(!0),te(null);try{ne((await ct(20)).items??[])}catch(e){te(e instanceof Error?e.message:String(e))}finally{F(!1)}},[]),pe=(0,X.useCallback)(async()=>{B(!0),ie(null);try{oe(await dt(50))}catch(e){ie(e instanceof Error?e.message:String(e))}finally{B(!1)}},[]),me=(0,X.useCallback)(async(e=`deep`)=>{m(!0),g(!1),v(null);try{await $e(e),g(!0),await W()}catch(e){v(e instanceof Error?e.message:String(e))}finally{m(!1)}},[W]),ge=(0,X.useCallback)(async e=>{o(e),l(null),f(!1);try{await it(e),f(!0),await W()}catch(e){l(e instanceof Error?e.message:String(e))}finally{o(null)}},[W]),ve=!t||U||!!i,ye=(0,X.useMemo)(()=>{let e=n?.payload?.config;return Pt(e??{})},[n]);(0,X.useEffect)(()=>{if(t){if(!w){T(ye),C(ye);return}JSON.stringify(ye)!==JSON.stringify(w)&&(T(ye),C(ye))}},[w,ye,t]);let be=(0,X.useMemo)(()=>!S||!w?!1:JSON.stringify(S)!==JSON.stringify(w),[S,w]),xe=(0,X.useCallback)(async()=>{if(S){D(!0),j(!1),N(null);try{await Ft(S),T(S),j(!0),await W()}catch(e){N(e instanceof Error?e.message:String(e))}finally{D(!1)}}},[S,W]);return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:e.title}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e.subtitle})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 items-center justify-end gap-2`,children:[(0,Y.jsxs)(`select`,{className:`rounded-lg border border-edge bg-surface-panel px-2 py-1.5 text-xs text-fg`,value:y,onChange:e=>b(e.target.value),disabled:!t||p,children:[(0,Y.jsx)(`option`,{value:`light`,children:`Light`}),(0,Y.jsx)(`option`,{value:`deep`,children:`Deep`}),(0,Y.jsx)(`option`,{value:`rem`,children:`REM`})]}),(0,Y.jsxs)(q,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||p,onClick:()=>void me(y),title:e.runNowHint,children:[p?(0,Y.jsx)(d,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(Be,{className:`mr-2 size-4`,"aria-hidden":!0}),e.runNow]}),(0,Y.jsxs)(q,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t,onClick:()=>void de(),children:[(0,Y.jsx)(De,{className:`mr-2 size-4`,"aria-hidden":!0}),e.refresh]})]})]}),ue.length>0?(0,Y.jsx)(`div`,{className:`space-y-1.5 rounded-2xl border border-amber-500/20 bg-amber-500/5 px-4 py-3`,role:`alert`,children:ue.map((e,t)=>(0,Y.jsx)(`p`,{className:`text-sm text-amber-800 dark:text-amber-200/90`,children:e},t))}):null,G.length>0?(0,Y.jsx)(`div`,{className:`space-y-1.5 rounded-2xl border border-emerald-500/20 bg-emerald-500/5 px-4 py-3`,role:`status`,children:G.map((e,t)=>(0,Y.jsx)(`p`,{className:`text-sm text-emerald-800 dark:text-emerald-200/90`,children:e},t))}):null,(0,Y.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,Y.jsxs)(gt,{className:`min-w-0`,children:[(0,Y.jsx)(_t,{icon:re,title:e.configTitle,subtitle:e.configHint,trailing:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(q,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||!S||E||!be,onClick:()=>void xe(),children:[E?(0,Y.jsx)(d,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,e.saveConfig]}),(0,Y.jsx)(q,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||!S||E||!be,onClick:()=>{j(!1),N(null),C(w)},children:e.resetConfig})]})}),S?(0,Y.jsxs)(`div`,{className:`space-y-5`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-3`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configEnabled}),(0,Y.jsxs)(`label`,{className:`mt-2 inline-flex items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:S.enabled,onChange:e=>C({...S,enabled:e.target.checked})}),(0,Y.jsx)(`span`,{children:S.enabled?e.on:e.off})]})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configFrequency}),(0,Y.jsx)(`input`,{className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle dark:border-edge`,value:S.frequency,onChange:e=>C({...S,frequency:e.target.value}),placeholder:`0 3 * * *`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configTimezone}),(0,Y.jsx)(`input`,{className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle dark:border-edge`,value:S.timezone,onChange:e=>C({...S,timezone:e.target.value}),placeholder:`Asia/Shanghai`})]})]}),(0,Y.jsxs)(Rt,{label:e.configPhaseLight,children:[(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.configPhaseLightHint}),(0,Y.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configPhaseEnabled}),(0,Y.jsxs)(`label`,{className:`mt-2 inline-flex items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:S.light.enabled,onChange:e=>C({...S,light:{...S.light,enabled:e.target.checked}})}),(0,Y.jsx)(`span`,{children:S.light.enabled?e.on:e.off})]})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configPhaseCron}),(0,Y.jsx)(`input`,{className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.light.cron,onChange:e=>C({...S,light:{...S.light,cron:e.target.value}}),placeholder:`0 */6 * * *`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configLightLookbackDays}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.light.lookbackDays,onChange:e=>C({...S,light:{...S.light,lookbackDays:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configLightLimit}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:0,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.light.limit,onChange:e=>C({...S,light:{...S.light,limit:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configLightDedupe}),(0,Y.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.light.dedupeSimilarity,onChange:e=>C({...S,light:{...S.light,dedupeSimilarity:Number(e.target.value)}})})]})]})]}),(0,Y.jsxs)(Rt,{label:e.configPhaseDeep,children:[(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.configPhaseDeepHint}),(0,Y.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configPhaseEnabled}),(0,Y.jsxs)(`label`,{className:`mt-2 inline-flex items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:S.deep.enabled,onChange:e=>C({...S,deep:{...S.deep,enabled:e.target.checked}})}),(0,Y.jsx)(`span`,{children:S.deep.enabled?e.on:e.off})]})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configPhaseCron}),(0,Y.jsx)(`input`,{className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.deep.cron,onChange:e=>C({...S,deep:{...S.deep,cron:e.target.value}}),placeholder:`0 3 * * *`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configDeepMinScore}),(0,Y.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.deep.minScore,onChange:e=>C({...S,deep:{...S.deep,minScore:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configDeepMinRecallCount}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.deep.minRecallCount,onChange:e=>C({...S,deep:{...S.deep,minRecallCount:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configDeepLimit}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:0,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.deep.limit,onChange:e=>C({...S,deep:{...S.deep,limit:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configDeepHalfLife}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.deep.recencyHalfLifeDays,onChange:e=>C({...S,deep:{...S.deep,recencyHalfLifeDays:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configDeepMaxAge}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.deep.maxAgeDays,onChange:e=>C({...S,deep:{...S.deep,maxAgeDays:Number(e.target.value)}})})]})]})]}),(0,Y.jsxs)(Rt,{label:e.configPhaseRem,children:[(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.configPhaseRemHint}),(0,Y.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configPhaseEnabled}),(0,Y.jsxs)(`label`,{className:`mt-2 inline-flex items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:S.rem.enabled,onChange:e=>C({...S,rem:{...S.rem,enabled:e.target.checked}})}),(0,Y.jsx)(`span`,{children:S.rem.enabled?e.on:e.off})]})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configPhaseCron}),(0,Y.jsx)(`input`,{className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.rem.cron,onChange:e=>C({...S,rem:{...S.rem,cron:e.target.value}}),placeholder:`0 5 * * 0`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configRemLookbackDays}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.rem.lookbackDays,onChange:e=>C({...S,rem:{...S.rem,lookbackDays:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configRemLimit}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:0,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.rem.limit,onChange:e=>C({...S,rem:{...S.rem,limit:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.configRemMinStrength}),(0,Y.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:S.rem.minPatternStrength,onChange:e=>C({...S,rem:{...S.rem,minPatternStrength:Number(e.target.value)}})})]})]})]})]}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.configLoading})]}),(0,Y.jsxs)(gt,{className:`min-w-0`,children:[(0,Y.jsx)(_t,{icon:Ve,title:e.runtimeTitle,subtitle:e.runtimeHint,trailing:U?(0,Y.jsx)(d,{className:`size-4 shrink-0 animate-spin text-fg-muted`,"aria-hidden":!0}):null}),(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsx)(Rt,{label:e.subsectionSchedule,children:(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.enabled}),(0,Y.jsx)(`div`,{className:Q(),children:H?H.config.enabled?e.on:e.off:`—`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.lock}),(0,Y.jsx)(`div`,{className:a(Q(),le?.className),children:le?le.text:`—`})]}),(0,Y.jsxs)(`div`,{className:a(J(),`sm:col-span-2`),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.schedule}),(0,Y.jsx)(`div`,{className:`mt-1 break-all font-mono text-sm text-fg`,children:H?H.config.frequency:`—`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.timezone}),(0,Y.jsx)(`div`,{className:Q(),children:H?H.config.timezone:`—`})]})]})}),(0,Y.jsx)(Rt,{label:e.subsectionStore,children:(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.storeEntries}),(0,Y.jsx)(`div`,{className:Q(),children:H?String(H.store.entryCount):`—`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.storePromoted}),(0,Y.jsx)(`div`,{className:Q(),children:H?String(H.store.promotedCount):`—`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.storeUpdatedAt}),(0,Y.jsx)(`div`,{className:Q(),children:H?It(H.store.updatedAt):`—`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Z(),children:e.storeLastPromotedAt}),(0,Y.jsx)(`div`,{className:Q(),children:H?It(H.store.lastPromotedAt):`—`})]})]})}),H?.config?.phases?(0,Y.jsx)(Rt,{label:e.subsectionPhases,children:(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-3`,children:[(0,Y.jsx)(zt,{icon:(0,Y.jsx)(I,{className:`size-4 text-amber-500`}),label:`Light`,enabled:H.config.phases.light.enabled,cron:H.config.phases.light.cron,details:`lookback=${H.config.phases.light.lookbackDays}d, limit=${H.config.phases.light.limit}, dedupe=${H.config.phases.light.dedupeSimilarity}`,t:e}),(0,Y.jsx)(zt,{icon:(0,Y.jsx)(he,{className:`size-4 text-indigo-500`}),label:`Deep`,enabled:H.config.phases.deep.enabled,cron:H.config.phases.deep.cron,details:`minScore=${H.config.phases.deep.minScore}, recalls≥${H.config.phases.deep.minRecallCount}, limit=${H.config.phases.deep.limit}, halfLife=${H.config.phases.deep.recencyHalfLifeDays}d`,t:e}),(0,Y.jsx)(zt,{icon:(0,Y.jsx)(x,{className:`size-4 text-purple-500`}),label:`REM`,enabled:H.config.phases.rem.enabled,cron:H.config.phases.rem.cron,details:`lookback=${H.config.phases.rem.lookbackDays}d, limit=${H.config.phases.rem.limit}, strength≥${H.config.phases.rem.minPatternStrength}`,t:e})]})}):null,(0,Y.jsxs)(Rt,{label:e.subsectionLastRun,children:[(0,Y.jsx)(`p`,{className:`mb-2 text-xs text-fg-muted`,children:e.lastRunBlockHint}),H?.lastRun?.exists?(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[H.lastRun.parseError?(0,Y.jsxs)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:[e.lastRunParseError,`: `,H.lastRun.parseError]}):null,H.lastRun.record?(0,Y.jsx)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel/40 p-2 sm:p-3`,children:(0,Y.jsx)(Vt,{t:e,r:H.lastRun.record})}):null,H.lastRun.raw!==void 0&&H.lastRun.raw!==null?(0,Y.jsxs)(`details`,{className:`group rounded-lg border border-edge-subtle`,children:[(0,Y.jsx)(`summary`,{className:`cursor-pointer list-none px-3 py-2 text-xs font-medium text-fg-muted marker:hidden [&::-webkit-details-marker]:hidden`,children:(0,Y.jsx)(`span`,{className:`underline decoration-edge underline-offset-2 group-open:text-fg`,children:e.lastRunRaw})}),(0,Y.jsx)(`pre`,{className:`max-h-[12rem] overflow-auto border-t border-edge-subtle p-3 text-xs text-fg-muted`,children:JSON.stringify(H.lastRun.raw,null,2)})]}):null]}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.lastRunEmpty})]}),(0,Y.jsx)(Bt,{label:e.subsectionLightLastRun,lastRun:H?.lightLastRun,t:e}),(0,Y.jsx)(Bt,{label:e.subsectionRemLastRun,lastRun:H?.remLastRun,t:e})]})]})]}),(0,Y.jsxs)(gt,{children:[(0,Y.jsx)(_t,{icon:_e,title:e.previewTitle,subtitle:e.previewHint,trailing:(0,Y.jsxs)(q,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||P,onClick:()=>void fe(),children:[P?(0,Y.jsx)(d,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,e.previewLoad]})}),R?R.length>0?(0,Y.jsx)(`div`,{className:`space-y-2`,children:R.map(t=>{let n=`${t.path}:${t.startLine}-${t.endLine}`,r=t.skippedReason;return(0,Y.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel/60 px-3 py-3`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-fg-muted`,children:[(0,Y.jsx)(`span`,{className:`font-medium text-fg`,children:n}),(0,Y.jsxs)(`span`,{children:[`score=`,t.score.toFixed(3)]}),(0,Y.jsxs)(`span`,{children:[`recalls=`,t.recallCount]}),(0,Y.jsxs)(`span`,{children:[`avg=`,t.avgScore.toFixed(3)]}),(0,Y.jsxs)(`span`,{children:[`decay=`,t.recencyDecay?.toFixed(3)??`—`]}),r?(0,Y.jsx)(`span`,{className:`text-amber-600 dark:text-amber-400`,children:r}):(0,Y.jsx)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:e.previewEligible})]}),t.snippet?(0,Y.jsx)(`div`,{className:`mt-2 text-sm text-fg`,children:t.snippet}):null]},`${t.key}:${t.hash}:${n}`)})}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.previewEmpty}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.previewNotLoaded})]}),(0,Y.jsxs)(gt,{children:[(0,Y.jsx)(_t,{icon:Ve,title:e.eventsTitle,subtitle:e.eventsHint,trailing:(0,Y.jsxs)(q,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||z,onClick:()=>void pe(),children:[z?(0,Y.jsx)(d,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,e.eventsLoad]})}),ae?ae.length>0?(0,Y.jsx)(`div`,{className:`space-y-1.5`,children:ae.map((e,t)=>{let n=e.phase===`light`?`☀️`:e.phase===`rem`?`✨`:`🌙`,r=e.phase===`light`?`scanned=${e.scannedEntries??0} new=${e.newSignals??0} deduped=${e.deduped??0}`:e.phase===`rem`?`patterns=${e.patternsDiscovered??0} analyzed=${e.entriesAnalyzed??0}`:`candidates=${e.candidates??0} applied=${e.applied??0}`;return(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 rounded-lg border border-edge-subtle bg-surface-panel/60 px-3 py-2 text-xs`,children:[(0,Y.jsx)(`span`,{children:n}),(0,Y.jsx)(`span`,{className:`font-medium text-fg`,children:e.phase}),(0,Y.jsx)(`span`,{className:a(`font-medium`,e.ok?`text-emerald-600 dark:text-emerald-400`:`text-amber-600 dark:text-amber-400`),children:e.ok?`OK`:`FAIL`}),(0,Y.jsx)(`span`,{className:`text-fg-muted`,children:r}),(0,Y.jsx)(`span`,{className:`text-fg-muted`,children:Lt(e.durationMs)}),(0,Y.jsx)(`span`,{className:`ml-auto text-fg-subtle`,children:It(e.timestamp)})]},`${e.timestamp}:${e.phase}:${t}`)})}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.eventsEmpty}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.eventsNotLoaded})]}),(0,Y.jsxs)(gt,{className:`max-w-2xl`,children:[(0,Y.jsx)(_t,{icon:A,title:e.maintenanceTitle,subtitle:e.maintenanceHint}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,Y.jsxs)(q,{variant:`secondary`,disabled:ve,onClick:()=>{confirm(e.confirmResetStore)&&ge(`reset_store`)},children:[i===`reset_store`?(0,Y.jsx)(d,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(c,{className:`mr-2 size-4`,"aria-hidden":!0}),e.resetStore]}),(0,Y.jsxs)(q,{variant:`secondary`,disabled:ve,onClick:()=>{confirm(e.confirmClearLock)&&ge(`clear_lock`)},children:[i===`clear_lock`?(0,Y.jsx)(d,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(ee,{className:`mr-2 size-4`,"aria-hidden":!0}),e.clearLock]})]})]})]})}var Wt=e(vt(),1);function Gt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Kt(e){let t=Gt(e)?e:{},n=Gt(t.gateway)?t.gateway:{},r=Gt(n.auth)?n.auth:{},i=r.mode===`none`||r.mode===`token`?r.mode:`token`,a=(Gt(t.update)?t.update:{}).channel,o=a===`beta`||a===`dev`||a===`stable`?a:`stable`;return{host:typeof n.host==`string`?n.host:``,port:typeof n.port==`number`?n.port:void 0,auth:{mode:i,token:typeof r.token==`string`?r.token:``},updateChannel:o}}async function qt(e){let t=e.auth.token.trim().length>0?{mode:e.auth.mode,token:e.auth.token}:{mode:e.auth.mode};await Oe(U(`/api/config`),{method:`PATCH`,body:JSON.stringify({gateway:{auth:t},update:{channel:e.updateChannel}})}),Ue()}function Jt(){return a(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,f,`dark:border-edge`)}function Yt(){let e=se(e=>e.language),t=O(e),n=t.gatewaySettings,r=K(e=>e.token),i=K(e=>e.tokenExpired),a=K(e=>e.openTokenDialog),s=!!r,[c,l]=(0,X.useState)(null),[u,f]=(0,X.useState)(null),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(null),[_,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(!1),[S,C]=(0,X.useState)(!1),w=(0,X.useRef)(!1),{data:T,error:E,isLoading:D,mutate:k}=Ye(s),A=(0,X.useMemo)(()=>T?.payload?.config===void 0?null:structuredClone(Kt(T.payload.config)),[T]);(0,X.useEffect)(()=>{if(!s){l(null),f(null),w.current=!1;return}A!==null&&(w.current||(l(A),f(structuredClone(A)),y(!1)))},[s,A]);let j=!!(s&&D&&T===void 0&&!E),M=E instanceof Error?E.message:E?String(E):null,N=(0,X.useMemo)(()=>!c||!u?!1:JSON.stringify(c)!==JSON.stringify(u),[c,u]),ee=(0,X.useCallback)(e=>{w.current=!0,l(t=>t?{...t,auth:{...t.auth,...e}}:null)},[]),P=(0,X.useCallback)(e=>{w.current=!0,l(t=>t?{...t,updateChannel:e}:null)},[]),F=(0,X.useCallback)(async()=>{if(!(!c||p)){m(!0),g(null),y(!1);try{await qt(c),w.current=!1,f(structuredClone(c)),y(!0),window.setTimeout(()=>y(!1),2500)}catch(e){g(e instanceof Error?e.message:n.saveError)}finally{m(!1)}}},[c,p,n.saveError]),I=(0,X.useCallback)(()=>{u&&(w.current=!1,l(structuredClone(u)),g(null),y(!1))},[u]),L=(0,X.useCallback)(async()=>{let e=c?.auth.token;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),C(!0),window.setTimeout(()=>C(!1),2e3))},[c?.auth.token]);return s?j?(0,Y.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,Y.jsx)(d,{className:`size-4 animate-spin`}),n.loading]})}):c?(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.gateway}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,Y.jsxs)(`a`,{href:fe(e,`gateway`),target:`_blank`,rel:`noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-sm text-accent hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,children:[n.docsLink,(0,Y.jsx)(v,{className:`size-3.5`})]})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[_?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,Y.jsx)(q,{type:`button`,variant:`secondary`,disabled:!N||p,onClick:I,children:n.discard}),(0,Y.jsx)(q,{type:`button`,variant:`primary`,disabled:!N||p,onClick:()=>void F(),children:p?n.saving:n.save})]})]}),i?(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-lg border border-red-200 bg-red-50 px-4 py-3 dark:border-red-900/50 dark:bg-red-950/40`,role:`alert`,children:[(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(ie,{className:`mt-0.5 size-4 shrink-0 text-red-600 dark:text-red-400`}),(0,Y.jsx)(`p`,{className:`text-sm text-red-900 dark:text-red-100`,children:n.tokenExpired})]}),(0,Y.jsx)(`div`,{children:(0,Y.jsx)(q,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:()=>a(),children:n.updateToken})})]}):null,N?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,h?(0,Y.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:h}):null,c.auth.mode===`none`?(0,Y.jsx)(`p`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-950 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-100`,children:n.authModeNone}):null,(0,Y.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[(0,Y.jsxs)(`div`,{className:`mb-5 flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)(o,{className:`size-4 text-accent`,strokeWidth:1.75}),t.settingsSections.gateway]}),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(c.host||c.port!=null)&&(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:n.listenHost}),(0,Y.jsx)(`div`,{className:`rounded-lg bg-surface-hover/80 px-3 py-2 font-mono text-xs text-fg-muted dark:bg-surface-hover/50`,children:c.host||`—`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:n.listenPort}),(0,Y.jsx)(`div`,{className:`rounded-lg bg-surface-hover/80 px-3 py-2 font-mono text-xs text-fg-muted dark:bg-surface-hover/50`,children:c.port==null?`—`:String(c.port)})]}),(0,Y.jsx)(`p`,{className:`sm:col-span-2 text-xs text-fg-subtle`,children:n.listenHint})]}),(0,Y.jsx)(Zt,{g:n,value:c.auth.token,show:b,copied:S,onToggleShow:()=>x(e=>!e),onCopy:()=>void L(),onChange:e=>ee({token:e})}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,onClick:()=>a(),children:n.changeToken}),r?(0,Y.jsx)(Xt,{g:n,gatewayToken:r}):null,(0,Y.jsxs)(`div`,{className:`space-y-2 border-t border-edge pt-4`,children:[(0,Y.jsx)(`label`,{className:`text-sm font-medium text-fg`,htmlFor:`gateway-update-channel`,children:n.updateChannel}),(0,Y.jsxs)(`select`,{id:`gateway-update-channel`,value:c.updateChannel,onChange:e=>P(e.target.value),className:Jt(),children:[(0,Y.jsx)(`option`,{value:`stable`,children:n.channelStable}),(0,Y.jsx)(`option`,{value:`beta`,children:n.channelBeta}),(0,Y.jsx)(`option`,{value:`dev`,children:n.channelDev})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.updateChannelHint})]})]})]})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:h??M??n.loadError}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,onClick:()=>void k(),children:n.retry})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.gateway}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}function Xt({g:e,gatewayToken:t}){let[n,r]=(0,X.useState)(ze),[i,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(!1),[l,u]=(0,X.useState)(!1),d=n.trim(),f=(0,X.useMemo)(()=>{try{let e=new URL(d);return e.protocol===`http:`||e.protocol===`https:`}catch{return!1}},[d]),p=(0,X.useMemo)(()=>!t||!f?``:Se({baseUrl:d,gatewayToken:t}),[f,t,d]);(0,X.useEffect)(()=>{if(!p){o(null),c(!1);return}let e=!1;return c(!1),Wt.toDataURL(p,{width:216,margin:2,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}}).then(t=>{e||o(t)}).catch(()=>{e||(c(!0),o(null))}),()=>{e=!0}},[p]);let m=f&&le(d),h=(0,X.useCallback)(async()=>{p&&(await navigator.clipboard.writeText(p).catch(()=>{}),u(!0),window.setTimeout(()=>u(!1),2e3))},[p]);return(0,Y.jsxs)(`div`,{className:`space-y-3 border-t border-edge pt-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)(Ae,{className:`size-4 text-accent`,strokeWidth:1.75}),e.mobilePairTitle]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.mobilePairSubtitle}),(0,Y.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,Y.jsx)(`label`,{className:`text-sm font-medium text-fg`,htmlFor:`gateway-mobile-pair-base`,children:e.mobilePairBaseUrlLabel}),(0,Y.jsx)(`input`,{id:`gateway-mobile-pair-base`,className:a(Jt(),`font-mono text-xs`),type:`text`,autoComplete:`off`,spellCheck:!1,value:n,onChange:e=>r(e.target.value)}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.mobilePairBaseUrlHint}),f?null:(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:e.mobilePairInvalidBaseUrl}),m?(0,Y.jsx)(`p`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-950 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-100`,children:e.mobilePairLocalhostWarning}):null,(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.mobilePairSecurityNote})]}),p?(0,Y.jsxs)(`div`,{className:`flex flex-col items-center gap-3 sm:items-start`,children:[i&&!s?(0,Y.jsx)(`img`,{src:i,alt:``,className:`h-56 w-56 rounded-lg border border-edge-subtle bg-white object-contain p-3 dark:border-edge`}):null,!i&&!s?(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.mobilePairEncoding}):null,s?(0,Y.jsx)(`p`,{className:`text-center text-sm text-fg-muted sm:text-left`,children:e.mobilePairImageError}):null,(0,Y.jsxs)(q,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,disabled:!p,onClick:()=>void h(),children:[l?(0,Y.jsx)(Re,{className:`size-3.5`}):(0,Y.jsx)(ne,{className:`size-3.5`}),l?e.mobilePairCopied:e.mobilePairCopyLink]})]}):null,(0,Y.jsx)(`p`,{className:`break-all font-mono text-[10px] leading-relaxed text-fg-subtle`,children:e.mobilePairSchemeHint})]})}function Zt({g:e,value:t,show:n,copied:r,onToggleShow:i,onCopy:o,onChange:s}){return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.accessToken}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Y.jsx)(`input`,{className:a(Jt(),`min-w-0 flex-1 font-mono text-xs`),type:n?`text`:`password`,autoComplete:`off`,value:t,onChange:e=>s(e.target.value),placeholder:e.tokenPlaceholder}),t?(0,Y.jsxs)(q,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:o,children:[r?(0,Y.jsx)(Re,{className:`size-3.5`}):(0,Y.jsx)(ne,{className:`size-3.5`}),r?e.copied:e.copy]}):null,(0,Y.jsxs)(q,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:i,children:[n?(0,Y.jsx)(te,{className:`size-3.5`}):(0,Y.jsx)(L,{className:`size-3.5`}),n?e.hide:e.show]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tokenHelp})]})}function Qt(){return U(`/api/channels/status`)}var $t=Xe;function en(){return U(`/api/workspace/heartbeat-md`)}async function tn(){let e=await Oe(en());return typeof e.payload?.content==`string`?e.payload.content:``}function nn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function rn(e){let t=nn(e)?e:{},n=nn(t.gateway)?t.gateway:{},r=nn(n.heartbeat)?n.heartbeat:{},i=r.activeHours,a=nn(i)?i:null,o=a&&typeof a.start==`string`&&typeof a.end==`string`&&a.start&&a.end?{start:a.start,end:a.end,timezone:typeof a.timezone==`string`?a.timezone:``}:null;return{enabled:!!(r.enabled??!0),intervalMs:typeof r.intervalMs==`number`&&Number.isFinite(r.intervalMs)?r.intervalMs:18e5,target:typeof r.target==`string`?r.target:``,targetChatId:typeof r.targetChatId==`string`?r.targetChatId:``,prompt:typeof r.prompt==`string`?r.prompt:``,ackMaxChars:typeof r.ackMaxChars==`number`&&Number.isFinite(r.ackMaxChars)?r.ackMaxChars:``,isolatedSession:!!r.isolatedSession,activeHours:o}}function an(e){let t={enabled:e.enabled,intervalMs:e.intervalMs};return e.target.trim()?t.target=e.target.trim():t.target=null,e.targetChatId.trim()?t.targetChatId=e.targetChatId.trim():t.targetChatId=null,e.prompt.trim()?t.prompt=e.prompt.trim():t.prompt=null,e.ackMaxChars===``||e.ackMaxChars===void 0?t.ackMaxChars=null:t.ackMaxChars=e.ackMaxChars,e.isolatedSession?t.isolatedSession=!0:t.isolatedSession=null,e.activeHours?.start?.trim()&&e.activeHours?.end?.trim()?t.activeHours={start:e.activeHours.start.trim(),end:e.activeHours.end.trim(),...e.activeHours.timezone.trim()?{timezone:e.activeHours.timezone.trim()}:{}}:t.activeHours=null,t}async function on(e){await Oe(U(`/api/config`),{method:`PATCH`,body:JSON.stringify({gateway:{heartbeat:an(e)}})}),Ue()}async function sn(e){await Oe(U(`/api/workspace/heartbeat-md`),{method:`PUT`,body:JSON.stringify({content:e})}),i(en())}async function cn(e){await Oe(U(`/api/heartbeat/trigger`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e?{reason:e}:{})})}var ln=[3e4,6e4,3e5,6e5,9e5,18e5,36e5,72e5],un=new Set(ln);function dn(){return a(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,f,`dark:border-edge`)}function fn(){return a(m,We)}function pn(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 mn(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 hn(){let e=se(e=>e.language),t=O(e),n=t.heartbeatSettings,i=!!K(e=>e.token),[o,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),[u,f]=(0,X.useState)(``),[p,m]=(0,X.useState)(``),[h,_]=(0,X.useState)(!1),[y,b]=(0,X.useState)(!1),[x,S]=(0,X.useState)(null),[C,w]=(0,X.useState)(!1),[T,E]=(0,X.useState)(!1),[D,k]=(0,X.useState)(!1),[A,j]=(0,X.useState)(!1),[M,N]=(0,X.useState)(null),[ee,P]=(0,X.useState)([]),{data:F,error:I,isLoading:L,mutate:te}=Ye(i),{data:R,error:ne,isLoading:z,mutate:B}=r(i?en():null,tn,{revalidateOnFocus:!1}),{data:re=[]}=r(i?Qt():null,$t,{revalidateOnFocus:!1}),V=(0,X.useMemo)(()=>pn(F?.payload?.config),[F]),ie=(0,X.useMemo)(()=>rn(F?.payload?.config??{}),[F]),ae=(0,X.useMemo)(()=>!o||!c?!1:JSON.stringify(o)!==JSON.stringify(c),[o,c]),oe=(0,X.useMemo)(()=>u!==p,[u,p]);(0,X.useEffect)(()=>{if(!i){s(null),l(null);return}if(F!==void 0&&!ae){let e=structuredClone(ie);s(e),l(e),w(!1)}},[i,F,ie,ae]),(0,X.useEffect)(()=>{!i||R===void 0||oe||(f(R),m(R),E(!1))},[i,R,oe]);let H=I instanceof Error?I.message:I?String(I):ne instanceof Error?ne.message:ne?String(ne):null,ce=!!(i&&(F===void 0||R===void 0)&&!H&&(L||z));(0,X.useEffect)(()=>{if(!i||!o){P([]);return}let e=o.target.trim();if(!e){P([]);return}let t=!1;return Ze(e).then(e=>{t||P(e)}),()=>{t=!0}},[i,o?.target]);let U=(0,X.useCallback)(()=>{let e=o?.target?.trim();e&&Ze(e).then(P)},[o?.target]),W=(0,X.useCallback)(async()=>{k(!0),j(!1),N(null);try{await cn(),j(!0),window.setTimeout(()=>j(!1),3e3)}catch(e){N(e instanceof Error?e.message:n.triggerError)}finally{k(!1)}},[n.triggerError]),le=(0,X.useCallback)(e=>{s(t=>t?{...t,...e}:null)},[]),ue=(0,X.useCallback)(()=>{c&&(s(structuredClone(c)),w(!1),S(null))},[c]),G=(0,X.useCallback)(()=>{f(p),E(!1),S(null)},[p]),de=(0,X.useCallback)(async()=>{if(!(!o||h)){_(!0),S(null),w(!1);try{await on(o),l(structuredClone(o)),w(!0),window.setTimeout(()=>w(!1),2500)}catch(e){S(e instanceof Error?e.message:n.saveConfigError)}finally{_(!1)}}},[o,h,n.saveConfigError]),pe=(0,X.useCallback)(async()=>{if(!y){b(!0),S(null),E(!1);try{await sn(u),m(u),E(!0),window.setTimeout(()=>E(!1),2500)}catch(e){S(e instanceof Error?e.message:n.saveDocError)}finally{b(!1)}}},[u,y,n.saveDocError]);return i?ce?(0,Y.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,Y.jsx)(d,{className:`size-4 animate-spin`}),n.loading]})}):o?(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Y.jsx)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.heartbeat}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,Y.jsxs)(`a`,{href:fe(e,`heartbeat`),target:`_blank`,rel:`noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-sm text-accent hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,children:[n.docsLink,(0,Y.jsx)(v,{className:`size-3.5`})]})]})}),V?(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.workspaceLabel,`: `,(0,Y.jsx)(`span`,{className:`font-mono text-fg-muted`,children:V})]}):null,x?(0,Y.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:x}):null,(0,Y.jsxs)(gt,{children:[(0,Y.jsxs)(`div`,{className:`mb-2 flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)(g,{className:`size-4 text-accent`,strokeWidth:1.75}),n.configSection]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsxs)(q,{type:`button`,variant:`secondary`,className:`inline-flex items-center gap-2`,disabled:D,onClick:()=>void W(),children:[D?(0,Y.jsx)(d,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(Be,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),D?n.triggering:n.triggerNow]}),A?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.triggered}):null]})]}),(0,Y.jsx)(`p`,{className:`mb-4 text-xs text-fg-subtle`,children:n.triggerHint}),M?(0,Y.jsx)(`p`,{className:`mb-3 text-sm text-red-600 dark:text-red-400`,children:M}):null,(0,Y.jsx)(gn,{h:n,cron:t.cron,form:o,channels:re,sessionChatIds:ee,onRefreshChatIds:U,update:le,inputClassName:dn,selectClassName:fn}),(0,Y.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-2`,children:[C?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.savedConfig}):null,(0,Y.jsx)(q,{type:`button`,variant:`secondary`,disabled:!ae||h,onClick:ue,children:n.discard}),(0,Y.jsx)(q,{type:`button`,variant:`primary`,disabled:!ae||h,onClick:()=>void de(),children:h?n.savingConfig:n.saveConfig}),ae?(0,Y.jsx)(`span`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedConfig}):null]})]}),(0,Y.jsxs)(gt,{children:[(0,Y.jsx)(`div`,{className:`mb-2 text-sm font-semibold text-fg`,children:n.docSection}),(0,Y.jsx)(`p`,{className:`mb-3 text-xs text-fg-subtle`,children:n.docHint}),(0,Y.jsx)(`textarea`,{className:a(dn(),`min-h-[12rem] resize-y font-mono text-xs leading-relaxed`),value:u,onChange:e=>f(e.target.value),spellCheck:!1,"aria-label":n.docSection}),(0,Y.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-2`,children:[T?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.savedDoc}):null,(0,Y.jsx)(q,{type:`button`,variant:`secondary`,disabled:!oe||y,onClick:G,children:n.discard}),(0,Y.jsx)(q,{type:`button`,variant:`primary`,disabled:!oe||y,onClick:()=>void pe(),children:y?n.savingDoc:n.saveDoc}),oe?(0,Y.jsx)(`span`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedDoc}):null]})]})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:x??H??n.loadError}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,onClick:()=>{te(),B()},children:n.retry})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.heartbeat}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}function gn({h:e,cron:t,form:n,channels:r,sessionChatIds:i,onRefreshChatIds:o,update:s,inputClassName:c,selectClassName:l}){let u=(0,X.useMemo)(()=>new Set(r.map(e=>e.name)),[r]),d=n.target.trim(),f=!!(d&&!u.has(d)),p=(0,X.useMemo)(()=>un.has(n.intervalMs)?String(n.intervalMs):``,[n.intervalMs]),[m,h]=(0,X.useState)(null),g=Math.max(1,Math.round(n.intervalMs/1e3)),_=m===null?String(g):m;return(0,X.useEffect)(()=>{h(null)},[n.intervalMs]),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:n.enabled,onChange:e=>s({enabled:e.target.checked})}),e.enable]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.interval}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:e.intervalSecondsLabel}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`input`,{type:`number`,min:1,step:1,className:a(c(),`min-w-0 flex-1`),value:_,onChange:e=>{let t=e.target.value;h(t);let n=parseInt(t,10);Number.isFinite(n)&&n>=1&&s({intervalMs:n*1e3})},onBlur:()=>{if(m===null)return;let e=parseInt(m,10);s(!Number.isFinite(e)||e<1?{intervalMs:1e3}:{intervalMs:e*1e3}),h(null)}}),(0,Y.jsxs)(`select`,{className:a(l(),`max-w-[11rem] shrink-0 text-xs`),value:p,onChange:e=>{let t=e.target.value;t&&(s({intervalMs:parseInt(t,10)}),h(null))},children:[(0,Y.jsx)(`option`,{value:``,children:e.intervalPresets.custom}),ln.map(t=>(0,Y.jsx)(`option`,{value:String(t),children:mn(t,e.intervalPresets)},t))]})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.intervalHintPreset}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.intervalHint})]}),(0,Y.jsxs)(`div`,{className:`border-t border-edge-subtle pt-4`,children:[(0,Y.jsx)(`div`,{className:`mb-2 text-sm font-medium text-fg`,children:e.deliveryTitle}),(0,Y.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:t.channel}),(0,Y.jsxs)(`select`,{className:l(),value:d,onChange:e=>{s({target:e.target.value.trim(),targetChatId:``})},children:[(0,Y.jsx)(`option`,{value:``,children:e.channelNone}),f?(0,Y.jsxs)(`option`,{value:d,children:[d,` (`,e.customChannelSuffix,`)`]}):null,r.map(e=>(0,Y.jsxs)(`option`,{value:e.name,disabled:!e.enabled,children:[e.name,` `,e.enabled?``:`(disabled)`]},e.name))]})]}),d?(0,Y.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:t.recipient}),(0,Y.jsxs)(q,{type:`button`,variant:`ghost`,className:`h-7 gap-1 px-2 text-xs`,title:t.refreshRecipientHint,onClick:o,children:[(0,Y.jsx)(De,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0}),t.refreshList]})]}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`input`,{type:`text`,className:a(c(),`min-w-0 flex-1`),value:n.targetChatId,onChange:e=>s({targetChatId:e.target.value}),placeholder:t.recipientPlaceholder,autoComplete:`off`}),(0,Y.jsxs)(`select`,{className:a(l(),`max-w-[10rem] shrink-0 text-xs`),value:n.targetChatId,onChange:e=>{let t=e.target.value;t&&s({targetChatId:t})},children:[(0,Y.jsx)(`option`,{value:``,children:t.selectRecipient}),i.length>0?i.map(e=>(0,Y.jsx)(`option`,{value:e.chatId,children:Qe(e,t.lastActiveLabels)},`${e.channel}-${e.chatId}`)):(0,Y.jsx)(`option`,{value:``,disabled:!0,children:t.noRecentChatsOption})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:i.length>0?t.enterManuallyOrSelect:t.noRecentChats})]}):null,(0,Y.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:e.deliveryHint})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:e.prompt}),(0,Y.jsx)(`textarea`,{className:a(c(),`min-h-[4.5rem] resize-y font-mono text-xs`),value:n.prompt,onChange:e=>s({prompt:e.target.value}),placeholder:e.promptPlaceholder}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:e.promptHint})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:e.ackMaxChars}),(0,Y.jsx)(`input`,{type:`number`,min:1,className:c(),value:n.ackMaxChars===``?``:n.ackMaxChars,onChange:e=>{let t=e.target.value;if(t===``)s({ackMaxChars:``});else{let e=parseInt(t,10);s({ackMaxChars:Number.isFinite(e)?e:``})}},placeholder:e.ackDefaultPlaceholder}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:e.ackMaxCharsHint})]}),(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:n.isolatedSession,onChange:e=>s({isolatedSession:e.target.checked})}),(0,Y.jsxs)(`span`,{children:[e.isolatedSession,(0,Y.jsx)(`span`,{className:`mt-1 block text-xs text-fg-subtle`,children:e.isolatedSessionHint})]})]}),(0,Y.jsxs)(`div`,{className:`border-t border-edge-subtle pt-4`,children:[(0,Y.jsx)(`div`,{className:`mb-2 text-sm font-medium text-fg`,children:e.activeHoursTitle}),n.activeHours?(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-xs text-fg`,children:e.activeStart}),(0,Y.jsx)(`input`,{className:c(),value:n.activeHours.start,onChange:e=>s({activeHours:{...n.activeHours,start:e.target.value}}),placeholder:`09:00`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-xs text-fg`,children:e.activeEnd}),(0,Y.jsx)(`input`,{className:c(),value:n.activeHours.end,onChange:e=>s({activeHours:{...n.activeHours,end:e.target.value}}),placeholder:`22:00`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-xs text-fg`,children:e.activeTimezone}),(0,Y.jsx)(`input`,{className:c(),value:n.activeHours.timezone,onChange:e=>s({activeHours:{...n.activeHours,timezone:e.target.value}}),placeholder:`Asia/Shanghai`})]})]}):(0,Y.jsx)(q,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:()=>s({activeHours:{start:`09:00`,end:`22:00`,timezone:``}}),children:e.addActiveHours}),n.activeHours?(0,Y.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:(0,Y.jsx)(q,{type:`button`,variant:`secondary`,className:`text-xs`,onClick:()=>s({activeHours:null}),children:e.clearActiveHours})}):null,(0,Y.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:e.activeHoursHint})]})]})}async function _n(){let e=await G(U(`/api/image/providers`));if(!e.ok)throw Error(`Image providers: HTTP ${e.status}`);return(await e.json()).payload?.providers??[]}function vn(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 yn(e,t){let n=vn(e.filter(e=>e.configured===!0));return!t||n.includes(t)?n:[t,...n]}function bn(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 xn=`image-generation-providers`;function Sn({value:e,disabled:t,placeholder:n,searchPlaceholder:i,noMatches:o,registryEmptyHint:s,outOfFilterNote:c,className:l,onChange:d}){let[f,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)(``),{data:g,isLoading:v,error:x}=r(xn,_n,{revalidateOnFocus:!1}),S=e.trim(),C=(0,X.useMemo)(()=>vn((g??[]).filter(e=>e.configured===!0)),[g]),w=(0,X.useMemo)(()=>yn(g??[],S),[g,S]),T=(0,X.useMemo)(()=>bn(w,m),[w,m]),E=!!c&&!!S&&!C.includes(S),O=e.trim()?e:n,k=e.trim()||n,A=(0,X.useCallback)(e=>{p(e),e||h(``)},[]);return(0,Y.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,Y.jsxs)(_,{open:f,onOpenChange:A,modal:!1,children:[(0,Y.jsx)(y,{asChild:!0,children:(0,Y.jsxs)(`button`,{type:`button`,disabled:t||v,title:v?`…`:k,className:a(N,`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`,b.transition,`hover:border-edge hover:bg-surface-hover/45`,P,`disabled:cursor-not-allowed disabled:opacity-50`,`dark:border-edge-subtle dark:hover:bg-surface-hover/55`,l),"aria-haspopup":`listbox`,"aria-expanded":f,children:[(0,Y.jsx)(`span`,{className:`min-w-0 truncate`,children:v?`…`:O}),(0,Y.jsx)(Ee,{className:`h-4 w-4 shrink-0 text-fg-subtle opacity-70`,"aria-hidden":!0})]})}),(0,Y.jsx)(M,{children:(0,Y.jsxs)(D,{className:`z-50 w-[min(22rem,calc(100vw-2rem))] rounded-xl border border-edge-subtle bg-surface-panel p-1 shadow-elevated dark:border-edge-subtle`,side:`bottom`,sideOffset:4,align:`end`,onOpenAutoFocus:e=>e.preventDefault(),children:[(0,Y.jsx)(`input`,{type:`search`,className:a(`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`,u),placeholder:i,value:m,onChange:e=>h(e.target.value),onKeyDown:e=>e.stopPropagation()}),(0,Y.jsxs)(`div`,{className:`max-h-60 overflow-auto`,role:`listbox`,"aria-label":i,children:[x?(0,Y.jsx)(`div`,{className:`px-2 py-2 text-xs text-red-600 dark:text-red-400`,children:x instanceof Error?x.message:`Failed to load image providers`}):null,!x&&w.length===0&&!v?(0,Y.jsx)(`div`,{className:`px-2 py-3 text-center text-xs text-fg-muted`,children:s??o}):null,!x&&w.length>0&&T.length===0?(0,Y.jsx)(`div`,{className:`px-2 py-3 text-center text-xs text-fg-muted`,children:o}):null,T.map(t=>(0,Y.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t===e,className:a(`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-fg hover:bg-surface-hover`,t===e&&`bg-surface-hover/90 font-medium dark:bg-surface-hover/70`),onClick:()=>{d(t),p(!1),h(``)},children:[(0,Y.jsx)(Re,{className:a(`h-4 w-4 shrink-0`,t!==e&&`invisible`),"aria-hidden":!0}),(0,Y.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm font-medium`,children:t})]},t))]})]})})]}),E?(0,Y.jsx)(`p`,{className:`text-xs text-amber-700 dark:text-amber-400/90`,children:c}):null]})}function Cn(e){let{a:t,chat:n,form:r,update:i}=e;return(0,Y.jsxs)(gt,{children:[(0,Y.jsx)(_t,{icon:j,title:t.cardModelsTitle,subtitle:t.cardModelsSubtitle}),(0,Y.jsxs)(`div`,{className:`mt-4 flex flex-col gap-5`,children:[(0,Y.jsx)(nt,{label:t.label.imageModel,description:t.desc.imageModel,children:(0,Y.jsx)(Ce,{value:r.imageModel,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,capabilitiesFilter:`vision`,registryEmptyHint:t.visionRegistryEmpty,outOfFilterNote:t.visionOutOfFilterNote,onChange:e=>i({imageModel:e})})}),(0,Y.jsx)(nt,{label:t.label.imageModelFallbacks,description:t.desc.imageModelFallbacks,children:(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[r.imageModelFallbacks.map((e,a)=>(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Y.jsx)(Ce,{value:e,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,capabilitiesFilter:`vision`,registryEmptyHint:t.visionRegistryEmpty,outOfFilterNote:t.visionOutOfFilterNote,onChange:e=>{let t=[...r.imageModelFallbacks];t[a]=e,i({imageModelFallbacks:t})}})}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":t.removeModelFallback,onClick:()=>i({imageModelFallbacks:r.imageModelFallbacks.filter((e,t)=>t!==a)}),children:(0,Y.jsx)(c,{className:`size-4`,strokeWidth:1.75})})]},a)),(0,Y.jsxs)(q,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:()=>i({imageModelFallbacks:[...r.imageModelFallbacks,``]}),children:[(0,Y.jsx)(W,{className:`size-4 shrink-0`,strokeWidth:1.75}),t.addModelFallback]})]})}),(0,Y.jsx)(nt,{label:t.label.imageGenerationModel,description:t.desc.imageGenerationModel,children:(0,Y.jsx)(Sn,{value:r.imageGenerationModel,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,registryEmptyHint:t.imageGenRegistryEmpty,outOfFilterNote:t.imageGenOutOfFilterNote,onChange:e=>i({imageGenerationModel:e})})}),(0,Y.jsx)(nt,{label:t.label.imageGenerationModelFallbacks,description:t.desc.imageGenerationModelFallbacks,children:(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[r.imageGenerationModelFallbacks.map((e,a)=>(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Y.jsx)(Sn,{value:e,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,registryEmptyHint:t.imageGenRegistryEmpty,outOfFilterNote:t.imageGenOutOfFilterNote,onChange:e=>{let t=[...r.imageGenerationModelFallbacks];t[a]=e,i({imageGenerationModelFallbacks:t})}})}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":t.removeModelFallback,onClick:()=>i({imageGenerationModelFallbacks:r.imageGenerationModelFallbacks.filter((e,t)=>t!==a)}),children:(0,Y.jsx)(c,{className:`size-4`,strokeWidth:1.75})})]},a)),(0,Y.jsxs)(q,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:()=>i({imageGenerationModelFallbacks:[...r.imageGenerationModelFallbacks,``]}),children:[(0,Y.jsx)(W,{className:`size-4 shrink-0`,strokeWidth:1.75}),t.addModelFallback]})]})})]})]})}function wn(){return a(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,f)}var Tn=`/api/image/providers`;function En(e){return{imageModel:e.imageModel,imageModelFallbacks:e.imageModelFallbacks,imageGenerationModel:e.imageGenerationModel,imageGenerationModelFallbacks:e.imageGenerationModelFallbacks,imageGenerationModelTimeoutMs:e.imageGenerationModelTimeoutMs,imageGenerationModelAutoProviderFallback:e.imageGenerationModelAutoProviderFallback}}async function Dn(){return(await Oe(U(Tn)))?.payload?.providers??[]}function On(){let e=se(e=>e.language),t=O(e),n=t.imageModelsSettings,i=!!K(e=>e.token),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(null),[f,p]=(0,X.useState)(!0),[m,h]=(0,X.useState)(!1),[g,_]=(0,X.useState)(!1),[v,y]=(0,X.useState)(void 0),b=(0,X.useCallback)(async()=>{if(i){p(!0),y(void 0);try{let e=await tt(),t=structuredClone(e);c(t),u(structuredClone(t))}catch(e){y(e instanceof Error?e.message:String(e))}finally{p(!1)}}},[i]);(0,X.useEffect)(()=>{b()},[b]);let x=(0,X.useCallback)(e=>{c(t=>t?{...t,...e}:null)},[]),{data:S=[],mutate:C}=r(i?Tn:null,Dn,{revalidateOnFocus:!1}),w=Ye(i),T=(0,X.useMemo)(()=>!s||!l?!1:JSON.stringify(En(s))!==JSON.stringify(En(l)),[s,l]),E=(0,X.useCallback)(async()=>{if(s){h(!0),y(void 0);try{try{st(s.paramsJson)}catch(e){y(e instanceof SyntaxError?t.agentSettings.advanced.paramsInvalidJson:e instanceof Error?e.message:t.agentSettings.advanced.paramsInvalidJson);return}await ht(s),u(structuredClone(s)),_(!0),window.setTimeout(()=>_(!1),1500),w.mutate?.()}catch(e){y(e instanceof Error?e.message:String(e))}finally{h(!1)}}},[s,w,t.agentSettings]),D=(0,X.useCallback)(()=>{l&&(c(structuredClone(l)),y(void 0),_(!1))},[l]);return i?f||!s?(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main items-center gap-2 px-4 py-8 text-sm text-fg-muted`,children:[(0,Y.jsx)(d,{className:`size-4 animate-spin`}),` Loading…`]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.title}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[(0,Y.jsxs)(q,{type:`button`,variant:`ghost`,onClick:()=>{b(),C()},children:[(0,Y.jsx)(De,{className:`size-3.5`}),(0,Y.jsx)(`span`,{className:`ml-1.5`,children:n.refresh})]}),g?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,Y.jsx)(q,{type:`button`,variant:`secondary`,onClick:D,disabled:!T||m,children:n.discard}),(0,Y.jsxs)(q,{type:`button`,variant:`primary`,onClick:()=>void E(),disabled:!T||m,children:[m?(0,Y.jsx)(d,{className:`size-3.5 animate-spin`}):(0,Y.jsx)(ae,{className:`size-3.5`}),(0,Y.jsx)(`span`,{className:`ml-1.5`,children:m?n.saving:n.save})]})]})]}),v?(0,Y.jsx)(`div`,{className:`rounded-lg border border-red-500/30 bg-red-500/10 px-3 py-2 text-sm text-red-700 dark:text-red-300`,children:v}):null,(0,Y.jsx)(Cn,{form:s,update:x,a:t.agentSettings,chat:t.chat}),(0,Y.jsxs)(gt,{children:[(0,Y.jsx)(_t,{icon:j,title:n.title,subtitle:n.subtitle}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Y.jsx)(`div`,{className:`rounded-lg border border-edge-subtle bg-surface-base px-3 py-2.5 text-xs leading-relaxed text-fg-muted`,children:n.crossLinkHint}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(`label`,{className:`text-sm font-medium text-fg`,children:n.timeoutLabel}),(0,Y.jsx)(`input`,{type:`number`,min:0,step:1e3,className:a(wn(),`max-w-[12rem]`),value:s.imageGenerationModelTimeoutMs??``,placeholder:`120000`,onChange:e=>{let t=e.target.value.trim(),n=t===``?null:Math.max(0,Math.floor(Number(t)));c(e=>e?{...e,imageGenerationModelTimeoutMs:n&&n>0?n:null}:null)}}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.timeoutHint})]}),(0,Y.jsxs)(`label`,{className:`flex items-start gap-3 text-sm`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`mt-0.5`,checked:s.imageGenerationModelAutoProviderFallback,onChange:e=>c(t=>t?{...t,imageGenerationModelAutoProviderFallback:e.target.checked}:null)}),(0,Y.jsxs)(`span`,{className:`flex flex-col gap-0.5`,children:[(0,Y.jsx)(`span`,{className:`font-medium text-fg`,children:n.autoFallbackLabel}),(0,Y.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:n.autoFallbackHint})]})]})]})]}),(0,Y.jsxs)(gt,{children:[(0,Y.jsx)(_t,{icon:o,title:n.providersTitle,subtitle:``}),S.length===0?(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.providersEmpty}):(0,Y.jsx)(`div`,{className:`flex flex-col gap-3`,children:S.map(e=>(0,Y.jsxs)(`div`,{className:`rounded-lg border border-edge bg-surface-panel px-4 py-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-semibold text-fg`,children:e.label??e.id}),(0,Y.jsxs)(`span`,{className:`text-xs text-fg-subtle`,children:[`(`,e.id,`)`]})]}),e.configured?(0,Y.jsx)(`span`,{className:`rounded-full bg-accent-soft px-2 py-0.5 text-xs font-medium text-accent-fg`,children:n.configured}):(0,Y.jsx)(`span`,{className:`rounded-full border border-amber-500/40 bg-amber-500/10 px-2 py-0.5 text-xs font-medium text-amber-700 dark:text-amber-300`,children:n.missingKey})]}),e.defaultModel?(0,Y.jsxs)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:[(0,Y.jsxs)(`span`,{className:`text-fg-muted`,children:[n.defaultModel,`:`]}),` `,e.id,`/`,e.defaultModel]}):null,e.models.length>0?(0,Y.jsxs)(`p`,{className:`mt-0.5 text-xs text-fg-subtle`,children:[(0,Y.jsxs)(`span`,{className:`text-fg-muted`,children:[n.modelsLabel,`:`]}),` `,e.models.map(t=>`${e.id}/${t}`).join(`, `)]}):null]},e.id))})]})]}):(0,Y.jsx)(`div`,{className:`mx-auto w-full max-w-app-main px-4 py-8 text-sm text-fg-muted`,children:e===`zh`?`请先登录网关。`:`Connect to a gateway to continue.`})}var kn=[{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 An(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 jn(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 Mn(){let e=await G(U(`/api/models-json`)),t=await e.json().catch(()=>({}));if(!e.ok||!t.ok||!t.payload)throw Error(An(t)||`HTTP ${e.status}`);return{...t.payload,config:jn(t.payload.config)}}async function Nn(e){let t=await G(U(`/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(An(n)||`HTTP ${t.status}`);return n.payload}async function Pn(e){let t=await G(U(`/api/models-json`),{method:`PATCH`,body:JSON.stringify({config:e})}),n=await t.json().catch(()=>({}));if(!t.ok||!n.ok||!n.payload)throw Error(An(n)||`HTTP ${t.status}`);return n.payload}async function Fn(){let e=await G(U(`/api/models-json/reload`),{method:`POST`}),t=await e.json().catch(()=>({}));if(!e.ok||!t.ok||!t.payload)throw Error(An(t)||`HTTP ${e.status}`);return t.payload}async function In(e){let t=await G(U(`/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(An(n)||`HTTP ${t.status}`);return n.payload}function Ln(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 Rn(e){return e.startsWith(`!`)}function zn(e){return/^[A-Z][A-Z0-9_]*$/.test(e)}function Bn(e){return Rn(e)?`shell`:zn(e)?`env`:`literal`}function Vn(e){return e?e.length<=8?`••••`:`${e.slice(0,4)}••••${e.slice(-4)}`:``}function Hn(e){let{a:t,chat:n,form:r,update:i}=e;return(0,Y.jsxs)(gt,{children:[(0,Y.jsx)(_t,{icon:B,title:t.label.modelFallbacks,subtitle:t.desc.modelFallbacks}),(0,Y.jsxs)(`div`,{className:`mt-4 flex flex-col gap-2`,children:[r.modelFallbacks.map((e,a)=>(0,Y.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,Y.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,Y.jsx)(Ce,{value:e,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,onChange:e=>{let t=[...r.modelFallbacks];t[a]=e,i({modelFallbacks:t})}})}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":t.removeModelFallback,onClick:()=>i({modelFallbacks:r.modelFallbacks.filter((e,t)=>t!==a)}),children:(0,Y.jsx)(c,{className:`size-4`,strokeWidth:1.75})})]},a)),(0,Y.jsxs)(q,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:()=>i({modelFallbacks:[...r.modelFallbacks,``]}),children:[(0,Y.jsx)(W,{className:`size-4 shrink-0`,strokeWidth:1.75}),t.addModelFallback]})]})]})}var Un={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 Wn(e){return e===`openrouter`?`openrouter`:e===`zhipuCn`?`zhipu-cn`:e===`zaiGeneral`?`zai`:e}var Gn=[{value:`text`,labelKey:`inputTextOnly`},{value:`text,image`,labelKey:`inputTextVision`}];function Kn(){return a(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,f,`dark:border-edge`)}function qn(){return a(m,We)}function Jn(e){return(e.input||[`text`]).includes(`image`)?`text,image`:`text`}function Yn(e){return e===`text,image`?[`text`,`image`]:[`text`]}function Xn(e,t,n){return{...e,providers:{...e.providers,[t]:{...e.providers[t],...n}}}}function Zn(e,t){let n={...e.providers};return delete n[t],{...e,providers:n}}function Qn(e,t,n){return{...e,providers:{...e.providers,[t]:n}}}function $n({open:e,onOpenChange:t,providerId:n,model:r,isNew:i,onSave:o,m:c}){let[l,u]=(0,X.useState)(()=>Ln(``)),[d,f]=(0,X.useState)(()=>new Map);(0,X.useEffect)(()=>{e&&(f(new Map),u(r?{...r}:Ln(``)))},[e,r]);let m=(e,t)=>{u(n=>({...n,[e]:t})),f(t=>{let n=new Map(t);return n.delete(e),n})},h=()=>{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},g=()=>{if(!h())return;let e=(l.id||``).trim();o({...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}}),t(!1)},_=Jn(l);return(0,Y.jsx)(ye,{open:e,onOpenChange:t,children:(0,Y.jsxs)(k,{children:[(0,Y.jsx)(p,{className:`xopc-dialog-overlay fixed inset-0 z-50 bg-scrim`}),(0,Y.jsxs)(F,{className:a(`xopc-dialog-content fixed left-1/2 top-1/2 z-50 max-h-[min(90vh,720px)] w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2`,`overflow-y-auto rounded-xl border border-edge bg-surface-panel p-4 shadow-popover dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,Y.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(s,{className:`text-base font-semibold text-fg`,children:i?c.addModelTitle:c.editModelTitle}),n?(0,Y.jsxs)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:[c.modelProviderLabel,`: `,n]}):null]}),(0,Y.jsx)(Ge,{asChild:!0,children:(0,Y.jsx)(`button`,{type:`button`,className:`rounded-lg p-1.5 text-fg-muted hover:bg-surface-base hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,"aria-label":c.close,children:(0,Y.jsx)(T,{className:`size-4`})})})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`mb-1 block text-xs font-medium text-fg`,children:[c.modelId,(0,Y.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,Y.jsx)(`input`,{className:a(Kn(),d.has(`id`)&&`border-red-500`),value:l.id||``,onChange:e=>m(`id`,e.target.value),placeholder:`e.g. llama3.1:8b`,disabled:!i}),d.has(`id`)?(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:d.get(`id`)}):null]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:c.displayName}),(0,Y.jsx)(`input`,{className:Kn(),value:l.name||``,onChange:e=>m(`name`,e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:c.inputTypes}),(0,Y.jsx)(`select`,{className:qn(),value:_,onChange:e=>m(`input`,Yn(e.target.value)),children:Gn.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:c[e.labelKey]},e.value))})]}),(0,Y.jsxs)(`label`,{className:`mt-6 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:l.reasoning||!1,onChange:e=>m(`reasoning`,e.target.checked)}),c.reasoning]})]}),(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:c.contextWindow}),(0,Y.jsx)(`input`,{type:`number`,min:1,className:a(Kn(),d.has(`contextWindow`)&&`border-red-500`),value:l.contextWindow??128e3,onChange:e=>m(`contextWindow`,parseInt(e.target.value,10)||0)}),d.has(`contextWindow`)?(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:d.get(`contextWindow`)}):null]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:c.maxOutputTokens}),(0,Y.jsx)(`input`,{type:`number`,min:1,className:a(Kn(),d.has(`maxTokens`)&&`border-red-500`),value:l.maxTokens??16384,onChange:e=>m(`maxTokens`,parseInt(e.target.value,10)||0)}),d.has(`maxTokens`)?(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:d.get(`maxTokens`)}):null]})]}),(0,Y.jsxs)(`div`,{className:`border-t border-edge-subtle pt-2 dark:border-edge`,children:[(0,Y.jsx)(`p`,{className:`mb-2 text-xs font-semibold text-fg`,children:c.costSection}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:c.costInput}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,min:0,className:Kn(),value:l.cost?.input??0,onChange:e=>m(`cost`,{...l.cost,input:parseFloat(e.target.value)||0,output:l.cost?.output??0,cacheRead:l.cost?.cacheRead??0,cacheWrite:l.cost?.cacheWrite??0})})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:c.costOutput}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,min:0,className:Kn(),value:l.cost?.output??0,onChange:e=>m(`cost`,{...l.cost,input:l.cost?.input??0,output:parseFloat(e.target.value)||0,cacheRead:l.cost?.cacheRead??0,cacheWrite:l.cost?.cacheWrite??0})})]})]})]})]}),(0,Y.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2 border-t border-edge-subtle pt-3 dark:border-edge`,children:[(0,Y.jsx)(Ge,{asChild:!0,children:(0,Y.jsx)(q,{type:`button`,variant:`secondary`,children:c.cancel})}),(0,Y.jsx)(q,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:g,children:i?c.addModelConfirm:c.saveModelConfirm})]})]})]})})}function er({open:e,onOpenChange:t,presetKey:n,onConfirm:r,m:i}){let[o,c]=(0,X.useState)(``),[l,u]=(0,X.useState)(`custom`),[d,f]=(0,X.useState)(``),[m,h]=(0,X.useState)(`openai-completions`),[g,_]=(0,X.useState)(``),[v,y]=(0,X.useState)(null);(0,X.useEffect)(()=>{if(!e)return;y(null);let t=n||null;if(t&&Un[t]){let e=Un[t];u(t),f(e.baseUrl||``),h(e.api||`openai-completions`),_(e.apiKey??``),c(Wn(t))}else u(`custom`),c(``),f(``),h(`openai-completions`),_(``)},[e,n]);let b=e=>{if(u(e),e===`custom`)return;let t=Un[e];t&&(f(t.baseUrl||``),h(t.api||`openai-completions`),_(t.apiKey??``),c(Wn(e)))};return(0,Y.jsx)(ye,{open:e,onOpenChange:t,children:(0,Y.jsxs)(k,{children:[(0,Y.jsx)(p,{className:`xopc-dialog-overlay fixed inset-0 z-50 bg-scrim`}),(0,Y.jsxs)(F,{className:a(`xopc-dialog-content fixed left-1/2 top-1/2 z-50 max-h-[min(90vh,640px)] w-[min(100%-2rem,32rem)] -translate-x-1/2 -translate-y-1/2`,`overflow-y-auto rounded-xl border border-edge bg-surface-panel p-4 shadow-popover dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,Y.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(s,{className:`text-base font-semibold text-fg`,children:i.addProviderTitle}),(0,Y.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:i.addProviderSubtitle})]}),(0,Y.jsx)(Ge,{asChild:!0,children:(0,Y.jsx)(`button`,{type:`button`,className:`rounded-lg p-1.5 text-fg-muted hover:bg-surface-base hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,"aria-label":i.close,children:(0,Y.jsx)(T,{className:`size-4`})})})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:i.presetLabel}),(0,Y.jsxs)(`select`,{className:qn(),value:l,onChange:e=>b(e.target.value),children:[(0,Y.jsx)(`option`,{value:`custom`,children:i.presetCustom}),(0,Y.jsx)(`option`,{value:`ollama`,children:i.presetOllama}),(0,Y.jsx)(`option`,{value:`lmstudio`,children:i.presetLmStudio}),(0,Y.jsx)(`option`,{value:`openrouter`,children:i.presetOpenRouter}),(0,Y.jsx)(`option`,{value:`zhipuCn`,children:i.presetZhipuCn}),(0,Y.jsx)(`option`,{value:`zaiGeneral`,children:i.presetZaiGeneral})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`mb-1 block text-xs font-medium text-fg`,children:[i.providerIdLabel,(0,Y.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,Y.jsx)(`input`,{className:Kn(),value:o,onChange:e=>c(e.target.value),placeholder:i.providerIdPlaceholder})]}),(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:i.baseUrl}),(0,Y.jsx)(`input`,{className:Kn(),value:d,onChange:e=>f(e.target.value),placeholder:`https://…`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:i.apiType}),(0,Y.jsx)(`select`,{className:qn(),value:m,onChange:e=>h(e.target.value),children:kn.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:i.apiKey}),(0,Y.jsx)(`input`,{className:Kn(),value:g,onChange:e=>_(e.target.value),placeholder:i.apiKeyPlaceholder})]}),v?(0,Y.jsxs)(`p`,{className:`flex items-center gap-1 text-xs text-red-600 dark:text-red-400`,children:[(0,Y.jsx)(ie,{className:`size-3.5 shrink-0`}),v]}):null]}),(0,Y.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2 border-t border-edge-subtle pt-3 dark:border-edge`,children:[(0,Y.jsx)(Ge,{asChild:!0,children:(0,Y.jsx)(q,{type:`button`,variant:`secondary`,children:i.cancel})}),(0,Y.jsx)(q,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:()=>{let e=o.trim();if(!e){y(i.providerIdRequired);return}y(null),r(e,{baseUrl:d.trim()||void 0,api:m,apiKey:g.trim()||void 0,models:[]}),t(!1)},children:i.addProviderConfirm})]})]})]})})}function tr({config:e,setConfig:t,expanded:n,toggleExpand:r,showPw:i,toggleShowPw:o,testResults:s,runTestKey:l,ms:u,removeProv:d,openModelDialog:f,setTestResults:p}){return(0,Y.jsx)(`div`,{className:`flex flex-col gap-3`,children:Object.entries(e.providers).sort(([e],[t])=>e.localeCompare(t)).map(([e,m])=>{let h=n.has(e),g=m.models?.length??0,_=m.apiKey?Bn(m.apiKey):null,v=s.get(e),y=i.has(e);return(0,Y.jsxs)(`section`,{className:`overflow-hidden rounded-2xl bg-surface-base`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 border-b border-edge-subtle bg-surface-hover/35 px-3 py-2 dark:border-edge-subtle`,children:[(0,Y.jsxs)(`button`,{type:`button`,className:`flex min-w-0 flex-1 items-center gap-2 text-left text-sm font-semibold text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,onClick:()=>r(e),children:[h?(0,Y.jsx)(xe,{className:`size-4 shrink-0 text-fg-muted`}):(0,Y.jsx)(Pe,{className:`size-4 shrink-0 text-fg-muted`}),(0,Y.jsx)(`span`,{className:`truncate`,children:e}),g>0?(0,Y.jsx)(`span`,{className:`shrink-0 rounded-full bg-accent px-2 py-0.5 text-[10px] font-medium text-white`,children:g}):null,_?(0,Y.jsx)(`span`,{className:a(`shrink-0 rounded-full px-2 py-0.5 text-[10px] font-medium`,_===`shell`&&`bg-blue-100 text-blue-800 dark:bg-blue-950 dark:text-blue-200`,_===`env`&&`bg-emerald-100 text-emerald-800 dark:bg-emerald-950 dark:text-emerald-200`,_===`literal`&&`bg-surface-hover text-fg-muted dark:bg-surface-active`),children:_===`shell`?u.badgeShell:_===`env`?u.badgeEnv:u.badgeLiteral}):null]}),(0,Y.jsx)(`button`,{type:`button`,className:`rounded-lg p-1.5 text-fg-muted hover:bg-surface-base hover:text-red-600 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 dark:hover:text-red-400`,onClick:()=>d(e),"aria-label":u.removeProvider,children:(0,Y.jsx)(c,{className:`size-4`})})]}),h?(0,Y.jsxs)(`div`,{className:`space-y-4 px-3 py-3`,children:[(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:u.baseUrl}),(0,Y.jsx)(`input`,{className:Kn(),value:m.baseUrl||``,onChange:n=>t(t=>Xn(t,e,{baseUrl:n.target.value}))})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:u.apiType}),(0,Y.jsx)(`select`,{className:qn(),value:m.api||`openai-completions`,onChange:n=>t(t=>Xn(t,e,{api:n.target.value})),children:kn.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:u.apiKey}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Y.jsx)(`input`,{className:a(Kn(),`min-w-0 flex-1`),type:y?`text`:`password`,autoComplete:`off`,value:m.apiKey||``,onChange:n=>{let r=n.target.value;t(t=>Xn(t,e,{apiKey:r})),p(t=>{let n=new Map(t);return n.delete(e),n})},placeholder:u.apiKeyPlaceholder}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>o(e),children:y?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(te,{className:`mr-1 size-3.5`}),u.hide]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(L,{className:`mr-1 size-3.5`}),u.show]})}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>l(e,m.apiKey||``),children:u.testKey})]}),v?(0,Y.jsx)(`p`,{className:a(`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}): ${Vn(v.resolved||``)}`}):null,(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:u.apiKeyHint})]}),(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:m.authHeader||!1,onChange:n=>t(t=>Xn(t,e,{authHeader:n.target.checked}))}),u.authHeader]}),(0,Y.jsxs)(`div`,{className:`border-t border-edge-subtle pt-3 dark:border-edge`,children:[(0,Y.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-semibold text-fg`,children:u.modelsSection}),(0,Y.jsxs)(q,{type:`button`,variant:`primary`,className:`px-2 py-1 text-xs`,onClick:()=>f(e,null,!0),children:[(0,Y.jsx)(W,{className:`mr-1 size-3.5`}),u.addModel]})]}),(m.models||[]).length===0?(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:u.modelsEmpty}):(0,Y.jsx)(`ul`,{className:`space-y-2`,children:(m.models||[]).map(n=>(0,Y.jsxs)(`li`,{className:`flex items-center justify-between gap-2 rounded-lg border border-edge-subtle bg-surface-base px-3 py-2 dark:border-edge`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`div`,{className:`truncate text-sm font-medium text-fg`,children:n.id}),n.name&&n.name!==n.id?(0,Y.jsx)(`div`,{className:`truncate text-xs text-fg-muted`,children:n.name}):null]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(0,Y.jsx)(`button`,{type:`button`,className:`rounded-lg p-1.5 text-fg-muted hover:bg-surface-panel hover:text-fg`,onClick:()=>f(e,n,!1),"aria-label":u.editModel,children:(0,Y.jsx)(ke,{className:`size-4`})}),(0,Y.jsx)(`button`,{type:`button`,className:`rounded-lg p-1.5 text-fg-muted hover:bg-surface-panel hover:text-red-600 dark:hover:text-red-400`,onClick:()=>{window.confirm(u.removeModelConfirm.replace(`{{id}}`,n.id))&&t(t=>{let r=t.providers[e];return r?Xn(t,e,{models:(r.models||[]).filter(e=>e.id!==n.id)}):t})},"aria-label":u.removeModel,children:(0,Y.jsx)(c,{className:`size-4`})})]})]},n.id))})]})]}):null]},e)})})}function nr({ms:e,openAddProvider:t}){return(0,Y.jsxs)(`div`,{className:`flex flex-col items-center rounded-xl border-2 border-dashed border-edge-subtle bg-surface-panel px-6 py-12 text-center dark:border-edge`,children:[(0,Y.jsx)(`div`,{className:`mb-4 flex size-14 items-center justify-center rounded-full border border-edge bg-surface-base dark:border-edge`,children:(0,Y.jsx)(B,{className:`size-7 text-accent`,strokeWidth:1.5})}),(0,Y.jsx)(`h2`,{className:`mb-1 text-base font-semibold text-fg`,children:e.emptyTitle}),(0,Y.jsx)(`p`,{className:`mb-6 max-w-md text-sm text-fg-muted`,children:e.emptyDesc}),(0,Y.jsxs)(q,{type:`button`,className:`mb-6 bg-accent text-white hover:bg-accent/90`,onClick:()=>t(null),children:[(0,Y.jsx)(W,{className:`mr-1 size-4`}),e.emptyCta]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap justify-center gap-2`,children:[(0,Y.jsxs)(`button`,{type:`button`,className:a(`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`,b.transition,b.focusRingBase),onClick:()=>t(`ollama`),children:[(0,Y.jsx)(S,{className:`size-3.5`,"aria-hidden":!0}),e.presetOllama]}),(0,Y.jsxs)(`button`,{type:`button`,className:a(`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`,b.transition,b.focusRingBase),onClick:()=>t(`openrouter`),children:[(0,Y.jsx)(ue,{className:`size-3.5`,"aria-hidden":!0}),e.presetOpenRouter]}),(0,Y.jsxs)(`button`,{type:`button`,className:a(`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`,b.transition,b.focusRingBase),onClick:()=>t(`lmstudio`),children:[(0,Y.jsx)(B,{className:`size-3.5`,"aria-hidden":!0}),e.presetLmStudio]}),(0,Y.jsxs)(`button`,{type:`button`,className:a(`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`,b.transition,b.focusRingBase),onClick:()=>t(`zhipuCn`),children:[(0,Y.jsx)(S,{className:`size-3.5`,"aria-hidden":!0}),e.presetZhipuCn]}),(0,Y.jsxs)(`button`,{type:`button`,className:a(`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`,b.transition,b.focusRingBase),onClick:()=>t(`zaiGeneral`),children:[(0,Y.jsx)(ue,{className:`size-3.5`,"aria-hidden":!0}),e.presetZaiGeneral]})]})]})}function rr(){let e=se(e=>e.language),t=O(e),n=t.modelsSettings,r=pt(t.agentSettings),i=!!K(e=>e.token),[o,s]=(0,X.useState)({providers:{}}),[c,l]=(0,X.useState)({providers:{}}),[u,f]=(0,X.useState)(``),[p,m]=(0,X.useState)(),[h,g]=(0,X.useState)(!0),[_,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(!1),[S,C]=(0,X.useState)(!1),[w,T]=(0,X.useState)(null),[E,D]=(0,X.useState)(!1),[k,A]=(0,X.useState)(null),[j,M]=(0,X.useState)(()=>new Set),[N,ee]=(0,X.useState)(!1),[P,F]=(0,X.useState)(``),[I,L]=(0,X.useState)(null),[te,R]=(0,X.useState)(()=>new Set),[ne,z]=(0,X.useState)(()=>new Map),[B,re]=(0,X.useState)(!1),[V,ae]=(0,X.useState)(null),[oe,H]=(0,X.useState)(!1),[ce,U]=(0,X.useState)(null),le=(0,X.useCallback)(async e=>{let t=!e?.skipFullPageLoading;t&&g(!0),T(null);try{let e=await Mn(),t=jn(e.config);s(t),l(structuredClone(t)),f(e.path),m(e.loadError),A(null),D(!1)}catch(e){T(e instanceof Error?e.message:n.loadError),s({providers:{}}),l({providers:{}})}finally{t&&g(!1)}},[n.loadError]);(0,X.useEffect)(()=>{if(!i){g(!1);return}le()},[i,le]);let ue=(0,X.useMemo)(()=>JSON.stringify(o)!==JSON.stringify(c),[o,c]),G=(0,X.useMemo)(()=>r.form?{form:r.form,update:r.update,a:t.agentSettings,chat:t.chat}:null,[r.form,r.update,t.agentSettings,t.chat]),de=ue||r.dirty,pe=(0,X.useMemo)(()=>{let e=Object.keys(o.providers),t=0;for(let e of Object.values(o.providers))t+=e.models?.length??0;return{providers:e.length,models:t}},[o.providers]),me=e=>{M(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},he=e=>{R(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},ge=(0,X.useCallback)(()=>{F(JSON.stringify(o,null,2)),L(null)},[o]);(0,X.useEffect)(()=>{N&&ge()},[N,ge]);let _e=()=>{try{s(jn(JSON.parse(P))),L(null)}catch{L(n.jsonParseError)}},ve=async()=>{x(!0),T(null);try{A(await Nn(o))}catch(e){T(e instanceof Error?e.message:n.validateError)}finally{x(!1)}},ye=async()=>{if(_||r.saving)return;let e=ue,i=r.dirty;if(!(!e&&!i)){T(null),D(!1);try{if(e){y(!0);try{await Pn(o),l(structuredClone(o)),A(null)}finally{y(!1)}}if(i&&r.form&&!await r.save())throw Error(t.agentSettings.saveError);D(!0)}catch(e){T(e instanceof Error?e.message:n.saveError)}}},be=(0,X.useCallback)(()=>{s(structuredClone(c)),A(null),D(!1),T(null),N&&(F(JSON.stringify(c,null,2)),L(null)),r.discard()},[c,N,r.discard]),xe=async()=>{C(!0),T(null);try{await Fn(),await le({skipFullPageLoading:!0})}catch(e){T(e instanceof Error?e.message:n.reloadError)}finally{C(!1)}},Se=async(e,t)=>{try{let n=await In(t);z(t=>{let r=new Map(t);return r.set(e,n),r})}catch(t){z(n=>{let r=new Map(n);return r.set(e,{type:`error`,error:t instanceof Error?t.message:`Error`}),r})}},Ce=(e=null)=>{ae(e),re(!0)},we=(e,t)=>{s(n=>Qn(n,e,t)),M(t=>new Set(t).add(e))},Te=e=>{window.confirm(n.removeProviderConfirm.replace(`{{id}}`,e))&&(s(t=>Zn(t,e)),z(t=>{let n=new Map(t);return n.delete(e),n}))},Ee=(e,t,n)=>{U({providerId:e,model:t,isNew:n}),H(!0)},Oe=e=>{if(!ce)return;let{providerId:t,isNew:n}=ce;s(r=>{let i=r.providers[t];if(!i)return r;let a=i.models||[];return n?Xn(r,t,{models:[...a,e]}):Xn(r,t,{models:a.map(t=>t.id===e.id?e:t)})})};return i?(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-4 px-4 py-8`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.models}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.subtitle}),(0,Y.jsxs)(`a`,{href:fe(e,`models`),target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1 text-sm text-accent hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,children:[n.docsLink,(0,Y.jsx)(v,{className:`size-3.5`})]})]}),p?(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-sm text-amber-900 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-100`,role:`status`,children:[(0,Y.jsx)(ie,{className:`mt-0.5 size-4 shrink-0`}),(0,Y.jsxs)(`span`,{children:[n.loadFileWarning,`: `,p]})]}):null,u?(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.filePath,`: `,(0,Y.jsx)(`code`,{className:`rounded bg-surface-base px-1 py-0.5 font-mono text-fg-muted`,children:u})]}):null,(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsxs)(q,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:()=>Ce(null),disabled:h,children:[(0,Y.jsx)(W,{className:`mr-1 size-4`}),n.addProvider]}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:ve,disabled:h||b,children:b?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(d,{className:`mr-1 size-4 animate-spin`}),n.validating]}):n.validate}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:be,disabled:h||_||r.saving||!de,children:n.discard}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:()=>void ye(),disabled:h||_||r.saving||!de,children:_||r.saving?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(d,{className:`mr-1 size-4 animate-spin`}),n.saving]}):n.save}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[8.5rem] justify-center`,onClick:xe,disabled:h||S,children:S?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(d,{className:`mr-1 size-4 animate-spin`}),n.reloading]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(De,{className:`mr-1 size-4`}),n.reload]})}),(0,Y.jsx)(q,{type:`button`,variant:`ghost`,className:`text-fg-muted`,onClick:()=>{ee(e=>!e),L(null)},children:N?n.hideJson:n.showJson}),(0,Y.jsxs)(`div`,{className:`ml-auto flex items-center gap-2 rounded-lg border border-edge-subtle bg-surface-panel px-3 py-1.5 text-sm dark:border-edge`,children:[(0,Y.jsx)(`span`,{className:`text-fg-muted`,children:n.statsProviders.replace(`{{count}}`,String(pe.providers))}),(0,Y.jsx)(`span`,{className:`text-fg-subtle`,children:`|`}),(0,Y.jsx)(`span`,{className:`text-fg-muted`,children:n.statsModels.replace(`{{count}}`,String(pe.models))})]})]}),de?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,E||r.saveOk?(0,Y.jsx)(`p`,{className:`text-xs text-emerald-700 dark:text-emerald-400`,role:`status`,children:n.saved}):null,w?(0,Y.jsxs)(`p`,{className:`flex items-center gap-1 text-sm text-red-600 dark:text-red-400`,role:`alert`,children:[(0,Y.jsx)(ie,{className:`size-4 shrink-0`}),w]}):null,r.error?(0,Y.jsxs)(`p`,{className:`flex items-center gap-1 text-sm text-red-600 dark:text-red-400`,role:`alert`,children:[(0,Y.jsx)(ie,{className:`size-4 shrink-0`}),r.error]}):null,k&&k.errors.length>0?(0,Y.jsxs)(`div`,{className:`rounded-lg border border-amber-200 bg-amber-50/80 px-3 py-2 dark:border-amber-800 dark:bg-amber-950/30`,role:`status`,children:[(0,Y.jsx)(`p`,{className:`mb-1 text-sm font-medium text-amber-950 dark:text-amber-100`,children:k.valid?n.validationWarnings:n.validationErrors}),(0,Y.jsx)(`ul`,{className:`list-inside list-disc space-y-0.5 text-xs text-amber-900 dark:text-amber-200`,children:k.errors.map((e,t)=>(0,Y.jsxs)(`li`,{children:[e.path,`: `,e.message,` (`,e.severity,`)`]},`${e.path}-${t}`))})]}):null,h?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,Y.jsx)(d,{className:`size-4 animate-spin`}),n.loading]}):N?(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(`textarea`,{className:a(Kn(),`min-h-[320px] resize-y font-mono text-xs leading-relaxed`),value:P,onChange:e=>F(e.target.value),spellCheck:!1}),I?(0,Y.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:I}):null,(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(q,{type:`button`,variant:`secondary`,onClick:ge,children:n.jsonReset}),(0,Y.jsx)(q,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:_e,children:n.jsonApply})]})]}):Object.keys(o.providers).length===0?(0,Y.jsx)(nr,{ms:n,openAddProvider:Ce}):(0,Y.jsx)(tr,{config:o,setConfig:s,expanded:j,toggleExpand:me,showPw:te,toggleShowPw:he,testResults:ne,runTestKey:Se,ms:n,removeProv:Te,openModelDialog:Ee,setTestResults:z}),G?(0,Y.jsx)(`div`,{className:`mt-10 border-t border-edge-subtle pt-8 dark:border-edge`,children:(0,Y.jsx)(Hn,{...G})}):null,(0,Y.jsx)(er,{open:B,onOpenChange:re,presetKey:V,onConfirm:we,m:n}),(0,Y.jsx)($n,{open:oe,onOpenChange:e=>{H(e),e||U(null)},providerId:ce?.providerId??null,model:ce?.model??null,isNew:ce?.isNew??!1,onSave:Oe,m:n})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.models}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}async function ir(e){let t=await G(U(`/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 ar(e){let t=await G(U(`/api/auth/oauth-async/${encodeURIComponent(e)}/status`));if(!t.ok)throw Error(`OAuth status: ${t.status}`);return(await t.json()).payload}async function or(e,t){let n=await G(U(`/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 sr(e){let t=await G(U(`/api/auth/oauth-async/${encodeURIComponent(e)}/cancel`),{method:`POST`});if(!t.ok)throw Error(`Cancel OAuth failed: ${t.status}`)}async function cr(e){let t=await G(U(`/api/auth/oauth-async/${encodeURIComponent(e)}`),{method:`DELETE`});if(!t.ok)throw Error(`Cleanup session failed: ${t.status}`)}async function lr(e){let t=await G(U(`/api/auth/oauth/${encodeURIComponent(e)}`),{method:`DELETE`});if(!t.ok)throw Error(`Revoke OAuth failed: ${t.status}`)}function ur({providerId:e,language:t}){let n=Ne[e];if(!n)return null;let r=t===`zh`,i=r&&n.descriptionZh?n.descriptionZh:n.description;return i?(0,Y.jsxs)(_,{children:[(0,Y.jsx)(y,{asChild:!0,children:(0,Y.jsx)(`button`,{type:`button`,className:`rounded p-0.5 text-fg-subtle hover:bg-surface-hover hover:text-fg-muted focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,"aria-label":r?`${e} 详情`:`${e} info`,children:(0,Y.jsx)(E,{className:`size-3.5`,"aria-hidden":!0})})}),(0,Y.jsx)(M,{children:(0,Y.jsxs)(D,{side:`right`,align:`start`,sideOffset:6,className:a(`z-50 w-64 rounded-xl border border-edge bg-surface-panel p-3 shadow-md`,`data-[state=open]:animate-in data-[state=closed]:animate-out`,`data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,`data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95`),children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs font-semibold text-fg`,children:e}),(0,Y.jsx)(w,{asChild:!0,children:(0,Y.jsx)(`button`,{type:`button`,className:`shrink-0 rounded p-0.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,"aria-label":r?`关闭`:`Close`,children:(0,Y.jsx)(T,{className:`size-3.5`,"aria-hidden":!0})})})]}),(0,Y.jsx)(`p`,{className:`mt-1.5 text-xs leading-relaxed text-fg-muted`,children:i}),n.bestFor&&n.bestFor.length>0?(0,Y.jsxs)(`div`,{className:`mt-2`,children:[(0,Y.jsx)(`p`,{className:`text-[10px] font-medium uppercase tracking-wide text-fg-subtle`,children:r?`适合场景`:`Best for`}),(0,Y.jsx)(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:n.bestFor.map(e=>(0,Y.jsx)(`span`,{className:`rounded bg-surface-hover px-1.5 py-0.5 text-[10px] font-medium text-fg-muted`,children:e},e))})]}):null,n.freeTier===void 0?null:(0,Y.jsxs)(`div`,{className:`mt-2`,children:[(0,Y.jsx)(`p`,{className:`text-[10px] font-medium uppercase tracking-wide text-fg-subtle`,children:r?`免费额度`:`Free tier`}),(0,Y.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:n.freeTier?n.freeTierNote??(r?`有免费额度`:`Available`):r?`无免费额度(按量付费)`:`None (pay-as-you-go)`})]}),n.pricingUrl||n.docsUrl?(0,Y.jsxs)(`div`,{className:`mt-2.5 flex gap-3`,children:[n.pricingUrl?(0,Y.jsxs)(`a`,{href:n.pricingUrl,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-0.5 text-xs text-accent-fg hover:underline`,children:[r?`定价`:`Pricing`,(0,Y.jsx)(v,{className:`size-3`,"aria-hidden":!0})]}):null,n.docsUrl?(0,Y.jsxs)(`a`,{href:n.docsUrl,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-0.5 text-xs text-accent-fg hover:underline`,children:[r?`文档`:`Docs`,(0,Y.jsx)(v,{className:`size-3`,"aria-hidden":!0})]}):null]}):null,(0,Y.jsx)(ve,{className:`fill-edge`})]})})]}):null}var dr=[`common`,`specialty`,`enterprise`,`oauth`,`extension`];function fr(e){let t=new Map;for(let e of dr)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 pr(e,t){return e.replace(/\{\{(\w+)\}\}/g,(e,n)=>String(t[n]??``))}function mr(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 hr({envVar:e,labels:t}){let[n,r]=(0,X.useState)(!1),i=async()=>{try{await navigator.clipboard.writeText(e),r(!0),window.setTimeout(()=>r(!1),2e3)}catch{}};return(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsx)(`code`,{className:`rounded bg-surface-hover px-1.5 py-0.5 font-mono text-[11px] text-fg-muted`,children:e}),(0,Y.jsx)(`button`,{type:`button`,onClick:()=>void i(),className:`rounded p-0.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,title:n?t.copied:t.copy,"aria-label":n?t.copied:t.copy,children:n?(0,Y.jsx)(Me,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):(0,Y.jsx)(ne,{className:`size-3.5`,"aria-hidden":!0})})]})}function gr({row:e,value:t,rowDirty:n,labels:r,language:i,onChange:o,onReload:s,justSaved:l,availableModels:u}){let[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(!1),[_,y]=(0,X.useState)(!1),[x,S]=(0,X.useState)(null),[w,D]=(0,X.useState)(!1),[O,k]=(0,X.useState)(null),[A,j]=(0,X.useState)(!1),M=we(t),N=M&&!h?``:t,ee=e.configured&&!M&&!!t,[P,F]=(0,X.useState)(!1),[I,R]=(0,X.useState)(),[z,B]=(0,X.useState)(),[re,V]=(0,X.useState)(),[ae,oe]=(0,X.useState)(),[se,U]=(0,X.useState)(),[W,le]=(0,X.useState)(``),[ue,G]=(0,X.useState)(!1),[de,fe]=(0,X.useState)(null),[pe,me]=(0,X.useState)(null),K=e.activeKeySource??`none`,he=(0,X.useMemo)(()=>ce(e.id,i),[e.id,i]);(0,X.useEffect)(()=>()=>{I&&cr(I).catch(()=>{})},[I]),(0,X.useEffect)(()=>{if(!I||!P)return;let e=window.setInterval(()=>{(async()=>{try{let t=await ar(I);V(t.message),oe(t.authUrl),U(t.instructions),t.status===`waiting_auth`||t.status===`waiting_code`?B(t.status===`waiting_code`?`waiting_code`:`waiting`):t.status===`completed`?(window.clearInterval(e),F(!1),B(`success`),V(t.message),window.setTimeout(()=>s(),800)):(t.status===`failed`||t.status===`cancelled`)&&(window.clearInterval(e),F(!1),B(`error`),V(t.error||t.message||`OAuth failed`))}catch{}})()},1e3);return()=>window.clearInterval(e)},[I,P,s]);let ge=async()=>{F(!0),B(`waiting`),V(r.oauthStarting),R(void 0),oe(void 0),U(void 0);try{R((await ir(e.id)).sessionId)}catch(e){B(`error`),V(e instanceof Error?e.message:`OAuth failed`),F(!1)}},_e=async()=>{if(I){try{await sr(I)}catch{}R(void 0),F(!1),B(`idle`),V(void 0)}},ve=async()=>{if(!(!I||!W.trim()))try{await or(I,W.trim()),le(``),V(r.oauthProcessingCode)}catch(e){B(`error`),V(e instanceof Error?e.message:`Failed`)}},ye=()=>{window.confirm(pr(r.revokeConfirm,{name:e.name}))&&(S(null),lr(e.id).then(()=>s()).catch(e=>S(e instanceof Error?e.message:r.revokeFailed)))},Se=async()=>{j(!1),D(!0),k(null);try{await Fe(e.id),k(r.removeKeySuccess),o(e.id,``),window.setTimeout(()=>s(),600)}catch(e){k(e instanceof Error?e.message:r.removeKeyFailed)}finally{D(!1)}},Ce=e.configured&&M&&K!==`env`&&K!==`extension`&&K!==`models_json`,Ee=async()=>{if(!(!t||M))try{await navigator.clipboard.writeText(t),y(!0),window.setTimeout(()=>y(!1),2e3)}catch{}},De=async()=>{let e=t.trim();if(!(!e||we(e))){G(!0),fe(null),me(null);try{let t=await Te(e);if(t.error){me(!1),fe(`${r.testFailed} ${t.error}`);return}me(!0),t.type===`env`?fe(r.testOkEnv):t.type===`command`?fe(r.testOkCommand):fe(r.testOkLiteral)}catch(e){me(!1),fe(e instanceof Error?e.message:r.testFailed)}finally{G(!1)}}},Oe=n?r.metaWillSave:e.configured?M?`${r.metaMasked} · ${r.runtimeLabelPrefix} ${mr(r,K)}`:`${r.runtimeLabelPrefix} ${mr(r,K)}`:r.metaNotConfigured,ke=`provider-details-${e.id}`;return(0,Y.jsxs)(`div`,{className:`bg-surface-panel`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-3 sm:px-4`,children:[(0,Y.jsx)(`div`,{className:`flex size-8 shrink-0 items-center justify-center rounded-md bg-surface-hover/80 dark:bg-surface-hover/50`,"aria-hidden":!0,children:e.configured?(0,Y.jsx)(Me,{className:`size-4 text-emerald-600 dark:text-emerald-400`}):(0,Y.jsx)(C,{className:`size-4 text-fg-subtle`,strokeWidth:1.75})}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-sm font-semibold text-fg`,children:e.name}),(0,Y.jsx)(ur,{providerId:e.id,language:i}),(0,Y.jsx)(`span`,{className:`rounded bg-surface-hover px-1.5 py-0.5 font-mono text-[10px] font-medium uppercase tracking-wide text-fg-subtle`,children:e.id}),(0,Y.jsx)(`span`,{className:`rounded bg-surface-hover px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-fg-subtle`,children:e.category})]}),(0,Y.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:Oe})]}),(0,Y.jsx)(q,{type:`button`,variant:`ghost`,className:`h-9 w-9 shrink-0 p-0`,"aria-expanded":p,"aria-controls":ke,"aria-label":r.expandRowDetails,onClick:()=>m(e=>!e),children:(0,Y.jsx)(xe,{className:a(`size-4 transition-transform`,p&&`rotate-180`),"aria-hidden":!0})})]}),p?(0,Y.jsxs)(`div`,{id:ke,role:`region`,className:`space-y-3 border-t border-edge-subtle bg-surface-base/40 px-3 py-3 dark:bg-surface-base/20 sm:px-4`,children:[e.supportsApiKey===!1?null:(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsxs)(`div`,{className:`relative flex flex-col gap-2 sm:flex-row sm:gap-2`,children:[(0,Y.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,Y.jsx)(`input`,{type:h||!M?`text`:`password`,className:a(`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`,f,`dark:border-edge`),value:N,placeholder:M?r.placeholderOverride:e.configured?r.placeholderKeep:r.placeholderKey,disabled:P,onChange:t=>o(e.id,t.target.value),autoComplete:`off`,spellCheck:!1}),(0,Y.jsxs)(`div`,{className:`absolute right-1 top-1/2 flex -translate-y-1/2 gap-0.5`,children:[t&&!M?(0,Y.jsx)(`button`,{type:`button`,className:a(`rounded p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,b.transition,b.press,b.focusRingPanel),title:_?r.copied:r.copy,"aria-label":_?r.copied:r.copy,onClick:()=>void Ee(),children:_?(0,Y.jsx)(Me,{className:`size-4`}):(0,Y.jsx)(ne,{className:`size-4`})}):null,(0,Y.jsx)(`button`,{type:`button`,className:a(`rounded p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg disabled:opacity-40`,b.transition,b.press,b.focusRingPanel),title:h?r.hide:r.show,"aria-label":h?r.hide:r.show,disabled:M,onClick:()=>g(e=>!e),children:h?(0,Y.jsx)(te,{className:`size-4`}):(0,Y.jsx)(L,{className:`size-4`})})]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2 sm:shrink-0`,children:[(0,Y.jsxs)(q,{type:`button`,variant:`secondary`,className:`gap-1`,disabled:P||ue||!t.trim()||we(t),onClick:()=>void De(),children:[ue?(0,Y.jsx)(d,{className:`size-4 animate-spin`,"aria-hidden":!0}):null,ue?r.testingKey:r.testKey]}),e.supportsOAuth?ee?(0,Y.jsxs)(q,{type:`button`,variant:`secondary`,className:`gap-1 text-red-600 dark:text-red-400`,onClick:ye,children:[(0,Y.jsx)(H,{className:`size-4`,"aria-hidden":!0}),r.revoke]}):(0,Y.jsxs)(q,{type:`button`,variant:`secondary`,className:`gap-1`,disabled:P,onClick:()=>void ge(),children:[P?(0,Y.jsx)(d,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(Ke,{className:`size-4`,"aria-hidden":!0}),r.oauth]}):null,Ce?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(q,{type:`button`,variant:`secondary`,className:`gap-1 text-red-600 dark:text-red-400`,disabled:w,onClick:()=>j(!0),children:[w?(0,Y.jsx)(d,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(c,{className:`size-4`,"aria-hidden":!0}),r.removeKey]}),(0,Y.jsx)(Le,{open:A,title:r.removeKey,description:pr(r.removeKeyConfirm,{name:e.name}),confirmLabel:r.removeKey,cancelLabel:r.cancelOAuth,destructive:!0,onConfirm:()=>void Se(),onCancel:()=>j(!1)})]}):null]})]}),de?(0,Y.jsx)(`p`,{className:a(`text-xs`,pe===!1?`text-red-600 dark:text-red-400`:`text-fg-muted`),role:`status`,children:de}):null,he.length>0?(0,Y.jsx)(`div`,{className:`flex flex-col gap-1`,children:he.map(e=>(0,Y.jsxs)(`a`,{href:e.href,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex w-fit items-center gap-1 text-xs font-medium text-accent-fg hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:[be(e.kind,r),(0,Y.jsx)(v,{className:`size-3`,"aria-hidden":!0})]},`${e.kind}-${e.href}`))}):null]}),re?(0,Y.jsxs)(`div`,{className:a(`flex gap-2 rounded-md px-3 py-2 text-xs`,z===`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:[z===`error`?(0,Y.jsx)(ie,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}):z===`success`?(0,Y.jsx)(Me,{className:`mt-0.5 size-4 shrink-0 text-emerald-600`,"aria-hidden":!0}):(0,Y.jsx)(E,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:re})]}):null,x?(0,Y.jsxs)(`div`,{className:`flex gap-2 rounded-md border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700 dark:border-red-900/50 dark:bg-red-950/50 dark:text-red-400`,role:`alert`,children:[(0,Y.jsx)(ie,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:x})]}):null,O?(0,Y.jsxs)(`div`,{className:a(`flex gap-2 rounded-md px-3 py-2 text-xs`,O===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:[O===r.removeKeySuccess?(0,Y.jsx)(Me,{className:`mt-0.5 size-4 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):(0,Y.jsx)(ie,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:O})]}):null,(z===`waiting`||z===`waiting_code`)&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[ae?(0,Y.jsxs)(`a`,{href:ae,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1.5 rounded-md bg-accent px-3 py-2 text-sm font-medium text-white hover:bg-accent-hover`,children:[(0,Y.jsx)(v,{className:`size-4`,"aria-hidden":!0}),r.openAuthPage]}):null,(0,Y.jsxs)(q,{type:`button`,variant:`secondary`,className:`gap-1`,onClick:()=>void _e(),children:[(0,Y.jsx)(T,{className:`size-4`,"aria-hidden":!0}),r.cancelOAuth]})]}),se?(0,Y.jsxs)(`div`,{className:`flex gap-2 rounded-md bg-surface-hover/60 px-3 py-2 text-xs text-fg-muted dark:bg-surface-hover/40`,children:[(0,Y.jsx)(E,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:se})]}):null,z===`waiting_code`?(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,Y.jsx)(`input`,{type:`text`,className:a(`min-w-0 flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,f,`dark:border-edge`),value:W,placeholder:r.pasteRedirectUrl,onChange:e=>le(e.target.value),onKeyDown:e=>e.key===`Enter`&&void ve()}),(0,Y.jsx)(q,{type:`button`,variant:`primary`,className:`shrink-0`,onClick:()=>void ve(),children:r.submitCode})]}):null,M?(0,Y.jsxs)(`div`,{className:`flex gap-2 rounded-md bg-surface-hover/60 px-3 py-2 text-xs text-fg-muted dark:bg-surface-hover/40`,children:[(0,Y.jsx)(E,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:K===`env`?r.envHint:r.maskedStoredHint})]}):null,e.supportsOAuth&&!M&&!ee?(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:r.oauthHint}):null,l?(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md bg-surface-hover/60 px-3 py-2 text-xs text-fg-muted dark:bg-surface-hover/40`,children:[(0,Y.jsx)(Me,{className:`mt-0.5 size-3.5 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:(()=>{let t=u.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,(Ne[e.id]?.envVars??[]).length>0?(0,Y.jsxs)(`details`,{children:[(0,Y.jsx)(`summary`,{className:`cursor-pointer select-none list-none text-xs text-fg-subtle hover:text-fg-muted`,children:r.envVarAlt}),(0,Y.jsx)(`div`,{className:`mt-1.5 flex flex-col gap-1`,children:(Ne[e.id]?.envVars??[]).map(e=>(0,Y.jsx)(hr,{envVar:e,labels:r},e))})]}):null]}):null]})}function _r(){let e=se(e=>e.language),t=O(e),n=t.providersSettings,i=!!K(e=>e.token),[o,s]=(0,X.useState)({}),[c,l]=(0,X.useState)({}),[u,d]=(0,X.useState)(!1),[p,m]=(0,X.useState)(null),[h,g]=(0,X.useState)(null),[_,v]=(0,X.useState)(()=>new Set([`common`])),[y,b]=(0,X.useState)(``),[x,S]=(0,X.useState)(!1),[w,T]=(0,X.useState)(()=>new Set),E=(0,X.useRef)(``),D=U(`/api/providers/meta`),k=(0,X.useCallback)(async e=>(await Oe(e)).payload?.providers??[],[]),{data:A,error:j,isLoading:M,mutate:N}=Ye(i),{data:ee,error:P,isLoading:F,mutate:I}=r(i?D:null,k,{revalidateOnFocus:!1}),{data:L,mutate:te}=r(i?me:null,()=>de(),{revalidateOnFocus:!1}),R=(0,X.useMemo)(()=>!ee||A===void 0?null:je(ee,V(A.payload?.config),L??[]),[ee,A,L]),ne=j instanceof Error?j.message:j?String(j):P instanceof Error?P.message:P?String(P):null,z=!!(i&&R===null&&(M||F)&&!ne),B=(0,X.useMemo)(()=>JSON.stringify(o)!==JSON.stringify(c),[o,c]);(0,X.useEffect)(()=>{if(!B)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[B]),(0,X.useEffect)(()=>{if(!(!i||R===null)&&!B){let e={};for(let t of R)e[t.id]=t.apiKey;s(e),l({...e})}},[i,R,B]);let re=R??[],ie=(0,X.useMemo)(()=>{let e=re,t=y.trim().toLowerCase();return t&&(e=e.filter(e=>{let n=Ne[e.id]?.aliases??[];return e.id.toLowerCase().includes(t)||e.name.toLowerCase().includes(t)||n.some(e=>e.toLowerCase().includes(t))})),x&&(e=e.filter(e=>!e.configured)),e},[re,y,x]),ae=(0,X.useMemo)(()=>fr(ie),[ie]);(0,X.useEffect)(()=>{let e=E.current;if(E.current=y,y.trim()){let e=new Set;for(let t of dr)(ae.get(t)??[]).length>0&&e.add(t);v(e);return}e.trim()&&v(new Set([`common`]))},[y,ae]);let oe=(0,X.useCallback)(async()=>{if(u)return;let e={};for(let t of Object.keys(o)){let n=o[t]?.trim()??``;!n||we(n)||(e[t]=n)}if(Object.keys(e).length===0){l({...o}),g(`noChanges`),window.setTimeout(()=>g(null),2500);return}d(!0),m(null),g(null);try{await ge(e),T(new Set(Object.keys(e)));let t=await te(de(!0))??L??[],[n,r]=await Promise.all([N(),I()]),i=Array.isArray(r)?r:ee??[],a=n??A;if(a?.payload){let e=je(i,V(a.payload.config),t),n={};for(let t of e)n[t.id]=t.apiKey;s(n),l({...n})}g(`saved`),window.setTimeout(()=>g(null),2500)}catch(e){m(e instanceof Error?e.message:n.saveError)}finally{d(!1)}},[A,o,ee,L,N,I,te,n.saveError,u]),H=(0,X.useCallback)(()=>{s({...c}),m(null),g(null),T(new Set)},[c]),ce=e=>{v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},W=(0,X.useCallback)(()=>{N(),I()},[N,I]),le=!!(y.trim()||x);return i?z?(0,Y.jsxs)(`div`,{className:`mx-auto w-full max-w-app-main px-4 py-8`,children:[(0,Y.jsx)(`div`,{className:`h-8 w-48 animate-pulse rounded bg-surface-hover`}),(0,Y.jsx)(`div`,{className:`mt-6 h-32 animate-pulse rounded-xl bg-surface-hover`}),(0,Y.jsx)(`p`,{className:`mt-4 text-sm text-fg-muted`,children:t.logs.loading})]}):re.length===0?(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-10`,children:[(0,Y.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-base px-4 py-3`,children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:n.loadError}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:p??ne??n.empty})]}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,onClick:()=>{N(),I()},children:t.logs.refresh})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.providers}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,Y.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:n.rotateHint})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[h===`saved`?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,h===`noChanges`?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.noChangesSaved}):null,(0,Y.jsx)(q,{type:`button`,variant:`secondary`,disabled:!B||u,onClick:H,children:n.discard}),(0,Y.jsx)(q,{type:`button`,variant:`primary`,disabled:!B||u,onClick:()=>void oe(),children:u?n.saving:n.save})]})]}),B?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,(0,Y.jsxs)(`p`,{className:`text-sm leading-relaxed text-fg-muted`,children:[n.intro,` `,(0,Y.jsx)(`a`,{href:fe(e,`models`),target:`_blank`,rel:`noopener noreferrer`,className:`font-medium text-accent-fg hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:n.docsLink}),` · `,(0,Y.jsx)(qe,{to:`/settings/models`,className:`font-medium text-accent-fg hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:n.modelsLink})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-center`,children:[(0,Y.jsxs)(`div`,{className:`relative min-w-0 flex-1 sm:max-w-md`,children:[(0,Y.jsx)(Ie,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-fg-subtle`,strokeWidth:1.75,"aria-hidden":!0}),(0,Y.jsx)(`input`,{type:`search`,value:y,onChange:e=>b(e.target.value),placeholder:n.searchPlaceholder,autoComplete:`off`,className:a(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-10 pr-3 text-sm text-fg placeholder:text-fg-subtle`,f,`dark:border-edge`),"aria-label":n.searchPlaceholder})]}),(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg-muted`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:x,onChange:e=>S(e.target.checked),className:`size-4 rounded border-edge text-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`}),n.unconfiguredOnly]}),le?(0,Y.jsx)(q,{type:`button`,variant:`ghost`,className:`h-9 w-fit self-start text-fg-muted`,onClick:()=>{b(``),S(!1)},children:n.clearFilters}):null]}),p?(0,Y.jsx)(`div`,{className:`rounded-md border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-700 dark:border-red-900/50 dark:bg-red-950/50 dark:text-red-400`,role:`alert`,children:p}):null,ie.length===0?(0,Y.jsxs)(`div`,{className:`rounded-xl border border-dashed border-edge-subtle bg-surface-base px-4 py-8 text-center text-sm text-fg-muted`,children:[(0,Y.jsx)(`p`,{children:n.noMatches}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,className:`mt-4`,onClick:()=>{b(``),S(!1)},children:n.clearFilters})]}):(0,Y.jsx)(`div`,{className:`flex flex-col gap-3`,children:dr.map(t=>{let r=ae.get(t)??[];if(r.length===0)return null;let i=_.has(t),l=r.filter(e=>e.configured).length,u=`providers-cat-${t}`;return(0,Y.jsxs)(`section`,{className:`overflow-hidden rounded-2xl bg-surface-base`,children:[(0,Y.jsxs)(`button`,{type:`button`,id:`${u}-trigger`,"aria-expanded":i,"aria-controls":u,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:()=>ce(t),children:[(0,Y.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)(`span`,{className:`truncate`,children:n.categories[t]}),(0,Y.jsx)(`span`,{className:`shrink-0 rounded bg-surface-hover px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-fg-subtle`,children:r.length})]}),(0,Y.jsxs)(`span`,{className:`flex shrink-0 items-center gap-2`,children:[l>0?(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-fg-subtle`,children:[(0,Y.jsx)(Me,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}),pr(n.configuredCount,{count:String(l)})]}):null,(0,Y.jsx)(xe,{className:a(`size-4 text-fg-subtle transition-transform`,i&&`rotate-180`),"aria-hidden":!0})]})]}),i?(0,Y.jsx)(`div`,{id:u,role:`region`,"aria-labelledby":`${u}-trigger`,className:`divide-y divide-edge-subtle`,children:r.map(t=>(0,Y.jsx)(`div`,{id:`provider-row-${t.id}`,children:(0,Y.jsx)(gr,{row:t,value:o[t.id]??``,rowDirty:(o[t.id]??``)!==(c[t.id]??``),labels:n,language:e,onChange:(e,t)=>s(n=>({...n,[e]:t})),onReload:W,justSaved:w.has(t.id),availableModels:L??[]})},t.id))}):null]},t)})})]}):(0,Y.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-10`,children:(0,Y.jsxs)(`div`,{className:`flex items-start gap-3 rounded-2xl bg-surface-base p-6`,children:[(0,Y.jsx)(C,{className:`mt-0.5 size-5 shrink-0 text-fg-subtle`,strokeWidth:1.75}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-base font-semibold text-fg`,children:t.settingsSections.providers}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.needToken})]})]})})}var vr=[{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 yr(e,t){let n=O(e).systemSettings.status;return t===`granted`?{label:n.granted,className:`text-emerald-600 dark:text-emerald-400`}:t===`denied`?{label:n.denied,className:`text-amber-600 dark:text-amber-400`}:{label:n.unknown,className:`text-fg-muted`}}function br(){let e=se(e=>e.language),t=O(e).systemSettings,[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(null),c=typeof window<`u`?window.electronAPI?.system:void 0,l=(0,X.useCallback)(async()=>{if(c){s(null);try{r(await c.getBehavior()),a(await c.getPermissions())}catch(e){s(e instanceof Error?e.message:String(e))}}},[c]);if((0,X.useEffect)(()=>{z()&&c&&l()},[c,l]),!z()||!c)return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.title}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:t.desktopOnlyTitle}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:t.desktopOnlyBody})]})]});let u=async e=>{try{let{behavior:t}=await c.setBehavior(e);r(t)}catch(e){s(e instanceof Error?e.message:String(e))}},d=async e=>{try{(await c.openPrivacy(e)).ok||s(`open_privacy failed`)}catch(e){s(e instanceof Error?e.message:String(e))}},f=n?n.platform===`win32`?t.permissionsHintWin:n.platform===`linux`?t.permissionsHintLinux:n.platform===`darwin`?t.permissionsHintDarwin:t.permissionsHint:t.permissionsHint;return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[(0,Y.jsx)(`div`,{children:(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.title})}),o?(0,Y.jsx)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:o}):null,(0,Y.jsxs)(gt,{children:[(0,Y.jsxs)(`div`,{className:`mb-4 flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)(R,{className:`size-4 text-accent`,strokeWidth:1.75}),t.behaviorGroup]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.openAtLogin}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.openAtLoginDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!n,checked:!!n?.openAtLogin,onChange:e=>{u({openAtLogin:e.target.checked})}})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.keepAwake}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.keepAwakeDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!n,checked:!!n?.keepAwakePreferred,onChange:e=>{u({keepAwakePreferred:e.target.checked})}})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.notifyDesktop}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.notifyDesktopDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!n,checked:!!n?.notifyEnabled,onChange:e=>{u({notifyEnabled:e.target.checked})}})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.notifySound}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.notifySoundDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!n,checked:!!n?.notifySoundEnabled,onChange:e=>{u({notifySoundEnabled:e.target.checked})}})]})]})]}),n&&i?(0,Y.jsxs)(`section`,{className:J(),children:[(0,Y.jsxs)(`div`,{className:`mb-4 flex flex-col gap-1 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:t.permissionsTitle}),(0,Y.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:f})]}),(0,Y.jsx)(`button`,{type:`button`,className:`mt-2 inline-flex max-w-full items-center justify-center rounded-lg border border-edge bg-surface-panel px-3 py-1.5 text-sm font-medium text-fg transition-colors hover:bg-surface-hover sm:mt-0`,onClick:()=>void l(),children:t.refresh})]}),(0,Y.jsx)(`ul`,{className:`space-y-3`,children:vr.map(({key:r,pane:o})=>{let l=yr(e,i[r]),u=t.perm[r];return u?(0,Y.jsxs)(`li`,{className:`flex flex-col gap-2 rounded-xl border border-edge-subtle bg-surface-panel/60 px-3 py-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:u.title}),(0,Y.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:u.desc}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs font-medium ${l.className}`,children:l.label})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[r===`microphone`&&n?.platform===`darwin`?(0,Y.jsx)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover`,onClick:()=>{(async()=>{try{await c.requestMicrophone(),a(await c.getPermissions())}catch(e){s(e instanceof Error?e.message:String(e))}})()},children:e===`zh`?`请求访问`:`Request`}):null,(0,Y.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover`,onClick:()=>void d(o),children:[t.openSettings,(0,Y.jsx)(v,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0})]})]})]},r):null})})]}):null]})}function xr(){return{enabled:!1,provider:`alibaba`,alibaba:{model:`paraformer-v2`},openai:{model:`whisper-1`},fallback:{enabled:!0,order:[`alibaba`,`openai`]}}}function Sr(){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 Cr(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function wr(e){let t=xr();if(!Cr(e))return t;let n=e.provider===`openai`?`openai`:`alibaba`,r=Cr(e.alibaba)?{...t.alibaba,...e.alibaba}:t.alibaba,i=Cr(e.openai)?{...t.openai,...e.openai}:t.openai,a=t.fallback??{enabled:!0,order:[`alibaba`,`openai`]};if(Cr(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 Tr(e){return typeof e==`string`&&e.trim().length>0?e.trim():`openai`}function Er(e){let t=Sr();if(!Cr(e))return t;let n=Tr(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:Cr(e.alibaba)?{...t.alibaba,...e.alibaba}:t.alibaba,openai:Cr(e.openai)?{...t.openai,...e.openai}:t.openai,edge:Cr(e.edge)?{...t.edge,...e.edge}:t.edge,minimax:Cr(e.minimax)?{...t.minimax,...e.minimax}:t.minimax,"tts-local-cli":Cr(i)?{...t[`tts-local-cli`],...i}:t[`tts-local-cli`]}}function Dr(e){let t=Cr(e)?e:{};return{stt:wr(t.stt),tts:Er(t.tts)}}async function Or(e){await Oe(U(`/api/config`),{method:`PATCH`,body:JSON.stringify({stt:e.stt,tts:e.tts})}),Ue()}async function kr(){let e=await Oe(U(`/api/voice/models`));if(!e.payload?.models)throw Error(`Missing voice models payload`);return e.payload.models}function Ar(){return a(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,f,`dark:border-edge`)}function jr(){return a(m,We)}var Mr=[{id:`paraformer-v2`,name:`Paraformer v2`},{id:`paraformer-v1`,name:`Paraformer v1`}],Nr=[{id:`whisper-1`,name:`Whisper-1`}],Pr=[{id:`tts-1`,name:`TTS-1`},{id:`tts-1-hd`,name:`TTS-1 HD`}],Fr=[{id:`alloy`,name:`Alloy`},{id:`echo`,name:`Echo`}],Ir=[{id:`qwen-tts`,name:`Qwen TTS`},{id:`qwen3-tts-flash`,name:`Qwen3 TTS Flash`}],Lr=[{id:`Cherry`,name:`Cherry`},{id:`longxiaochun`,name:`Long Xiao Chun`}],Rr=[{id:`en-US-MichelleNeural`,name:`Michelle (US English)`},{id:`zh-CN-XiaoxiaoNeural`,name:`Xiaoxiao (Chinese)`}],zr=[{id:`speech-2.8-hd`,name:`Speech 2.8 HD (Recommended)`},{id:`speech-2.8-turbo`,name:`Speech 2.8 Turbo (Fast)`}],Br=[{id:`male-qn-qingse`,name:`Male Qingse (青涩男声)`},{id:`female-shaonv`,name:`Female Shaonv (少女音)`}];function Vr(){let e=se(e=>e.language),t=O(e),n=t.voiceSettings,i=!!K(e=>e.token),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(null),[f,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(!1),{data:y,error:b,isLoading:x,mutate:S}=Ye(i),{data:C,error:w,isLoading:T,mutate:E}=r(i?U(`/api/voice/models`):null,kr,{revalidateOnFocus:!1}),D=(0,X.useMemo)(()=>y?.payload?.config===void 0?null:Dr(y.payload.config),[y]),k=(0,X.useMemo)(()=>!a||!s?!1:JSON.stringify(a)!==JSON.stringify(s),[a,s]);(0,X.useEffect)(()=>{if(!i){o(null),c(null),u(null);return}D===null||C===void 0||k||(o(structuredClone(D)),c(structuredClone(D)),u(C),_(!1))},[i,D,C,k]);let A=!!(i&&(D===null||C===void 0)&&(x||T)),j=b instanceof Error?b.message:b?String(b):w instanceof Error?w.message:w?String(w):null,M=(0,X.useCallback)(e=>{o(t=>t?{...t,stt:{...t.stt,...e}}:null)},[]),N=(0,X.useCallback)(e=>{o(t=>t?{...t,stt:{...t.stt,alibaba:{...t.stt.alibaba,...e}}}:null)},[]),ee=(0,X.useCallback)(e=>{o(t=>t?{...t,stt:{...t.stt,openai:{...t.stt.openai,...e}}}:null)},[]),P=(0,X.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}}}})},[]),F=(0,X.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,...e}}:null)},[]),I=(0,X.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,alibaba:{...t.tts.alibaba,...e}}}:null)},[]),L=(0,X.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,openai:{...t.tts.openai,...e}}}:null)},[]),te=(0,X.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,edge:{...t.tts.edge,...e}}}:null)},[]),R=(0,X.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,minimax:{...t.tts.minimax,...e}}}:null)},[]),ne=(0,X.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,"tts-local-cli":{...t.tts[`tts-local-cli`],...e}}}:null)},[]),z=(0,X.useCallback)(async()=>{if(!(!a||f)){p(!0),h(null),_(!1);try{await Or(a);let e=structuredClone(a);c(e),o(e),_(!0),window.setTimeout(()=>_(!1),2500)}catch(e){h(e instanceof Error?e.message:n.saveError)}finally{p(!1)}}},[a,f,n.saveError]),B=(0,X.useCallback)(()=>{s&&(o(structuredClone(s)),h(null),_(!1))},[s]);if(!i)return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.voice}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]});if(A)return(0,Y.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,Y.jsx)(d,{className:`size-4 animate-spin`}),n.loading]})});if(!a||l===null)return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:m??j??n.loadError}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,onClick:()=>{S(),E()},children:n.retry})]});let re=a.stt,V=a.tts;return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.voice}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,Y.jsxs)(`a`,{href:fe(e,`voice`),target:`_blank`,rel:`noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-sm text-accent hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,children:[n.docsLink,(0,Y.jsx)(v,{className:`size-3.5`})]})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[g?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,Y.jsx)(q,{type:`button`,variant:`secondary`,disabled:!k||f,onClick:B,children:n.discard}),(0,Y.jsx)(q,{type:`button`,variant:`primary`,disabled:!k||f,onClick:()=>void z(),children:f?n.saving:n.save})]})]}),k?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,m?(0,Y.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:m}):null,(0,Y.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Y.jsx)(Hr,{v:n,stt:re,models:l,updateStt:M,updateSttAlibaba:N,updateSttOpenai:ee,updateSttFallback:P}),(0,Y.jsx)(Ur,{v:n,tts:V,models:l,updateTts:F,updateTtsAlibaba:I,updateTtsOpenai:L,updateTtsEdge:te,updateTtsMinimax:R,updateTtsLocalCli:ne})]}),(0,Y.jsxs)(`div`,{className:`rounded-xl border border-accent/25 bg-accent/5 px-4 py-3 dark:border-accent/30 dark:bg-accent/10`,children:[(0,Y.jsxs)(`p`,{className:`text-sm text-fg`,children:[(0,Y.jsx)(`strong`,{className:`text-accent`,children:n.notes.title}),` `,n.notes.duration]}),(0,Y.jsx)(`p`,{className:`mt-2 text-xs text-fg-muted`,children:n.notes.envVars})]})]})}function Hr({v:e,stt:t,models:n,updateStt:r,updateSttAlibaba:i,updateSttOpenai:o,updateSttFallback:s}){let c=n?.stt?.alibaba?.length?n.stt.alibaba:Mr,l=n?.stt?.openai?.length?n.stt.openai:Nr;return(0,Y.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[(0,Y.jsxs)(`div`,{className:`mb-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)(pe,{className:`size-4 text-accent`,strokeWidth:1.75}),e.stt.title]}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:e.stt.description})]}),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.stt.enable}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.stt.enableDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:t.enabled,onChange:e=>r({enabled:e.target.checked})})]}),t.enabled?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.provider}),(0,Y.jsxs)(`select`,{className:jr(),value:t.provider,onChange:e=>r({provider:e.target.value}),children:[(0,Y.jsx)(`option`,{value:`alibaba`,children:e.stt.alibaba}),(0,Y.jsx)(`option`,{value:`openai`,children:e.stt.openai})]})]})}),t.provider===`alibaba`?(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.apiKey}),(0,Y.jsx)(`input`,{className:a(Ar(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.alibaba?.apiKey??``,onChange:e=>i({apiKey:e.target.value}),placeholder:`sk-...`}),(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (DASHSCOPE_API_KEY)`]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:jr(),value:t.alibaba?.model??``,onChange:e=>i({model:e.target.value}),children:c.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}):(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.apiKey}),(0,Y.jsx)(`input`,{className:a(Ar(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.openai?.apiKey??``,onChange:e=>o({apiKey:e.target.value}),placeholder:`sk-...`}),(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (OPENAI_API_KEY)`]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:jr(),value:t.openai?.model??``,onChange:e=>o({model:e.target.value}),children:l.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.stt.fallback}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.stt.fallbackDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:t.fallback?.enabled??!0,onChange:e=>s({enabled:e.target.checked})})]})]}):null]})]})}function Ur({v:e,tts:t,models:n,updateTts:r,updateTtsAlibaba:i,updateTtsOpenai:o,updateTtsEdge:s,updateTtsMinimax:c,updateTtsLocalCli:l}){let u=t=>t===`off`?e.tts.triggerDescOff:t===`always`?e.tts.triggerDescAlways:t===`inbound`?e.tts.triggerDescInbound:t===`tagged`?e.tts.triggerDescTagged:``,d=n?.tts?.openai?.length?n.tts.openai:Pr,f=n?.ttsVoices?.openai?.length?n.ttsVoices.openai:Fr,p=n?.tts?.alibaba?.length?n.tts.alibaba:Ir,m=n?.ttsVoices?.alibaba?.length?n.ttsVoices.alibaba:Lr,g=n?.ttsVoices?.edge?.length?n.ttsVoices.edge:Rr,_=n?.tts?.minimax?.length?n.tts.minimax:zr,v=n?.ttsVoices?.minimax?.length?n.ttsVoices.minimax:Br;return(0,Y.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[(0,Y.jsxs)(`div`,{className:`mb-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)(h,{className:`size-4 text-accent`,strokeWidth:1.75}),e.tts.title]}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:e.tts.description})]}),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.tts.enable}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.tts.enableDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:t.enabled,onChange:e=>r({enabled:e.target.checked})})]}),t.enabled?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.tts.trigger}),(0,Y.jsxs)(`select`,{className:jr(),value:t.trigger,onChange:e=>r({trigger:e.target.value}),children:[(0,Y.jsx)(`option`,{value:`off`,children:e.tts.triggerOff}),(0,Y.jsx)(`option`,{value:`always`,children:e.tts.triggerAlways}),(0,Y.jsx)(`option`,{value:`inbound`,children:e.tts.triggerInbound}),(0,Y.jsx)(`option`,{value:`tagged`,children:e.tts.triggerTagged})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:u(t.trigger)})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.tts.provider}),(0,Y.jsxs)(`select`,{className:jr(),value:t.provider,onChange:e=>r({provider:e.target.value}),children:[(0,Y.jsx)(`option`,{value:`openai`,children:e.tts.providerOpenai}),(0,Y.jsx)(`option`,{value:`alibaba`,children:e.stt.alibaba}),(0,Y.jsx)(`option`,{value:`minimax`,children:`MiniMax`}),(0,Y.jsx)(`option`,{value:`edge`,children:e.tts.providerEdge}),(0,Y.jsx)(`option`,{value:`tts-local-cli`,children:e.tts.providerLocalCli})]})]})]}),t.provider===`openai`?(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,Y.jsx)($,{children:e.stt.apiKey}),(0,Y.jsx)(`input`,{className:a(Ar(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.openai?.apiKey??``,onChange:e=>o({apiKey:e.target.value}),placeholder:`sk-...`}),(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (OPENAI_API_KEY)`]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:jr(),value:t.openai?.model??``,onChange:e=>o({model:e.target.value}),children:d.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.tts.voice}),(0,Y.jsx)(`select`,{className:jr(),value:t.openai?.voice??``,onChange:e=>o({voice:e.target.value}),children:f.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}):null,t.provider===`alibaba`?(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,Y.jsx)($,{children:e.stt.apiKey}),(0,Y.jsx)(`input`,{className:a(Ar(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.alibaba?.apiKey??``,onChange:e=>i({apiKey:e.target.value}),placeholder:`sk-...`}),(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (DASHSCOPE_API_KEY)`]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:jr(),value:t.alibaba?.model??``,onChange:e=>i({model:e.target.value}),children:p.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.tts.voice}),(0,Y.jsx)(`select`,{className:jr(),value:t.alibaba?.voice??``,onChange:e=>i({voice:e.target.value}),children:m.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}):null,t.provider===`minimax`?(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,Y.jsx)($,{children:e.stt.apiKey}),(0,Y.jsx)(`input`,{className:a(Ar(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.minimax?.apiKey??``,onChange:e=>c({apiKey:e.target.value}),placeholder:`eyJ...`}),(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (MINIMAX_API_KEY)`]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:jr(),value:t.minimax?.model??``,onChange:e=>c({model:e.target.value}),children:_.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.tts.voice}),(0,Y.jsx)(`select`,{className:jr(),value:t.minimax?.voice??``,onChange:e=>c({voice:e.target.value}),children:v.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}):null,t.provider===`edge`?(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.tts.voice}),(0,Y.jsx)(`select`,{className:jr(),value:t.edge?.voice??``,onChange:e=>s({voice:e.target.value}),children:g.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.edgeHint})]}):null,t.provider===`tts-local-cli`?(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,Y.jsx)($,{children:e.tts.localCli.command}),(0,Y.jsx)(`input`,{className:a(Ar(),`font-mono text-xs`),type:`text`,autoComplete:`off`,spellCheck:!1,value:t[`tts-local-cli`]?.command??``,onChange:e=>l({command:e.target.value}),placeholder:e.tts.localCli.commandPlaceholder}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.commandDesc})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.tts.localCli.cwd}),(0,Y.jsx)(`input`,{className:a(Ar(),`font-mono text-xs`),type:`text`,autoComplete:`off`,spellCheck:!1,value:t[`tts-local-cli`]?.cwd??``,onChange:e=>l({cwd:e.target.value}),placeholder:`/path/to/cwd`}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.cwdDesc})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.tts.localCli.outputFormat}),(0,Y.jsxs)(`select`,{className:jr(),value:t[`tts-local-cli`]?.outputFormat??`wav`,onChange:e=>l({outputFormat:e.target.value}),children:[(0,Y.jsx)(`option`,{value:`wav`,children:`wav`}),(0,Y.jsx)(`option`,{value:`mp3`,children:`mp3`}),(0,Y.jsx)(`option`,{value:`opus`,children:`opus`})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.outputFormatDesc})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,Y.jsx)($,{children:e.tts.localCli.timeoutMs}),(0,Y.jsx)(`input`,{className:Ar(),type:`number`,min:0,step:1e3,value:typeof t[`tts-local-cli`]?.timeoutMs==`number`?String(t[`tts-local-cli`].timeoutMs):``,onChange:e=>{let t=e.target.value.trim();if(t===``){l({timeoutMs:void 0});return}let n=Number(t);Number.isFinite(n)&&n>=0&&l({timeoutMs:n})},placeholder:`30000`}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.timeoutMsDesc})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle sm:col-span-2`,children:e.tts.localCli.hint})]}):null]}):null]})]})}function $({children:e}){return(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e})}function Wr(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 Gr(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 Oe(U(`/api/config`),{method:`PATCH`,body:JSON.stringify({tools:{web:{region:t,search:n}}})}),Ue()}function Kr({label:e,description:t,children:n}){return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e}),n,(0,Y.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:t})]})}function qr(){return a(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,f,`dark:border-edge`)}function Jr(){return a(m,We)}var Yr=[`brave`,`tavily`,`bing`,`searxng`];function Xr(){return{type:`brave`,apiKey:``,url:``,disabled:!1}}function Zr(){let e=se(e=>e.language),t=O(e),n=t.webSearchSettings,r=t.logs,i=!!K(e=>e.token),[a,o]=(0,X.useState)(null),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(!1),[f,p]=(0,X.useState)(null),[m,h]=(0,X.useState)(!1),g=(0,X.useRef)(!1),{data:_,error:y,isLoading:b,mutate:x}=Ye(i),S=(0,X.useMemo)(()=>_?.payload?.config===void 0?null:Wr(_.payload.config),[_]);(0,X.useEffect)(()=>{if(!i){o(null),c(null),g.current=!1;return}S!==null&&(g.current||(o(S),c(S)))},[i,S]);let C=!!(i&&b&&_===void 0&&!y),w=y instanceof Error?y.message:y?String(y):null,T=(0,X.useMemo)(()=>!a||!s?!1:JSON.stringify(a)!==JSON.stringify(s),[a,s]),E=(0,X.useCallback)(e=>{g.current=!0,o(t=>t?{...t,...e}:null)},[]),D=(0,X.useCallback)(async()=>{if(!(!a||l)){u(!0),p(null),h(!1);try{await Gr(a);let e=structuredClone(a);c(e),o(e),g.current=!1,h(!0),window.setTimeout(()=>h(!1),2500)}catch(e){p(e instanceof Error?e.message:n.saveError)}finally{u(!1)}}},[a,l,n.saveError]),k=(0,X.useCallback)(()=>{s&&(g.current=!1,o(structuredClone(s)),p(null),h(!1))},[s]);return i?C?(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col items-center gap-3 px-4 py-8`,children:[(0,Y.jsx)(d,{className:`size-8 animate-spin text-fg-muted`,"aria-hidden":!0}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.loading})]}):a?(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.title}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,Y.jsxs)(`a`,{href:fe(e,`gateway`),target:`_blank`,rel:`noreferrer`,className:`mt-1 inline-flex items-center gap-1 text-sm text-accent hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,children:[n.docsLink,(0,Y.jsx)(v,{className:`size-3.5`})]})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[m?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,Y.jsx)(q,{type:`button`,variant:`secondary`,disabled:!T||l,onClick:k,children:n.discard}),(0,Y.jsx)(q,{type:`button`,variant:`primary`,disabled:!T||l,onClick:()=>void D(),children:l?n.saving:n.save})]})]}),T?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,f?(0,Y.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:f}):null,(0,Y.jsxs)(gt,{children:[(0,Y.jsx)(_t,{icon:Ie,title:n.sectionRegion,subtitle:n.sectionRegionHint}),(0,Y.jsx)(`div`,{className:`flex max-w-md flex-col gap-4`,children:(0,Y.jsx)(Kr,{label:n.regionLabel,description:n.regionDesc,children:(0,Y.jsxs)(`select`,{className:Jr(),value:a.regionMode,onChange:e=>E({regionMode:e.target.value}),children:[(0,Y.jsx)(`option`,{value:`auto`,children:n.regionAuto}),(0,Y.jsx)(`option`,{value:`cn`,children:n.regionCn}),(0,Y.jsx)(`option`,{value:`global`,children:n.regionGlobal})]})})})]}),(0,Y.jsxs)(gt,{children:[(0,Y.jsx)(_t,{icon:Ie,title:n.sectionSearch,subtitle:n.sectionSearchHint}),(0,Y.jsxs)(`div`,{className:`flex max-w-xl flex-col gap-6`,children:[(0,Y.jsx)(Kr,{label:n.maxResultsLabel,description:n.maxResultsDesc,children:(0,Y.jsx)(`input`,{type:`number`,min:1,max:50,className:qr(),value:a.maxResults,onChange:e=>E({maxResults:Math.max(1,Math.min(50,Number(e.target.value)||5))})})}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.providersTitle}),a.providers.map((e,t)=>(0,Y.jsx)(Qr,{row:e,labels:n,onChange:e=>{let n=[...a.providers];n[t]=e,E({providers:n})},onRemove:()=>{E({providers:a.providers.filter((e,n)=>n!==t)})}},t)),(0,Y.jsxs)(q,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5 text-sm`,onClick:()=>E({providers:[...a.providers,Xr()]}),children:[(0,Y.jsx)(W,{className:`size-4`}),n.addProvider]})]})]})]}),(0,Y.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:n.footerHint})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:f??w??n.loadError}),(0,Y.jsx)(q,{type:`button`,variant:`secondary`,onClick:()=>void x(),children:r.refresh})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-4 px-4 py-6`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:n.title}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}function Qr({row:e,labels:t,onChange:n,onRemove:r}){return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-xl border border-edge-subtle bg-surface-panel/60 p-4 dark:border-edge-subtle`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,Y.jsx)(`select`,{className:a(Jr(),`min-w-[8rem]`),value:e.type,onChange:t=>n({...e,type:t.target.value,url:t.target.value===`searxng`?e.url:``}),children:Yr.map(e=>(0,Y.jsx)(`option`,{value:e,children:t.providerTypes[e]},e))}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1.5 text-xs text-fg-muted`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`size-3.5 rounded border-edge`,checked:e.disabled,onChange:t=>n({...e,disabled:t.target.checked})}),t.disabled]}),(0,Y.jsx)(q,{type:`button`,variant:`ghost`,className:`h-8 px-2 text-fg-muted`,onClick:r,children:(0,Y.jsx)(c,{className:`size-4`})})]})]}),e.type===`searxng`?(0,Y.jsx)(Kr,{label:t.urlLabel,description:t.urlDesc,children:(0,Y.jsx)(`input`,{type:`url`,className:qr(),value:e.url,placeholder:`http://localhost:8080`,onChange:t=>n({...e,url:t.target.value})})}):null,(0,Y.jsx)(Kr,{label:t.apiKeyLabel,description:t.apiKeyDesc,children:(0,Y.jsx)(`input`,{type:`password`,autoComplete:`off`,className:qr(),value:we(e.apiKey)?``:e.apiKey,placeholder:we(e.apiKey)?t.keyPlaceholderMasked:t.keyPlaceholder,onChange:t=>n({...e,apiKey:t.target.value})})})]})}var $r=[`appearance`,`system`,`agent-chat`,`agent-workspace`,`agent-browser`,`agent-runtime`,`agent-tools`,`agent-system-prompt`,`providers`,`models`,`image-models`,`voice`,`gateway`,`heartbeat`,`search`,`dreams`];function ei(){let{section:e}=l(),t=se(e=>e.language),n=O(t);if(e===`agent`||e===`agents`)return(0,Y.jsx)(oe,{to:`/agents`,replace:!0});if(!e||!$r.includes(e))return(0,Y.jsx)(oe,{to:`/settings/appearance`,replace:!0});let r=e,i=n.settingsSections[r];return r===`appearance`?(0,Y.jsx)(Tt,{}):r===`system`?(0,Y.jsx)(br,{}):r===`agent-chat`?(0,Y.jsx)(lt,{}):r===`agent-workspace`?(0,Y.jsx)(ut,{}):r===`agent-browser`?(0,Y.jsx)(mt,{}):r===`agent-runtime`?(0,Y.jsx)(ft,{}):r===`agent-tools`?(0,Y.jsx)(et,{}):r===`agent-system-prompt`?(0,Y.jsx)(ot,{}):r===`providers`?(0,Y.jsx)(_r,{}):r===`models`?(0,Y.jsx)(rr,{}):r===`image-models`?(0,Y.jsx)(On,{}):r===`voice`?(0,Y.jsx)(Vr,{}):r===`gateway`?(0,Y.jsx)(Yt,{}):r===`heartbeat`?(0,Y.jsx)(hn,{}):r===`search`?(0,Y.jsx)(Zr,{}):r===`dreams`?(0,Y.jsx)(Ut,{}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:i}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t===`zh`?`设置 · ${i}(即将推出)。`:`Settings · ${i} (coming soon).`})]})}export{ei as SettingsPage};
2
+ //# sourceMappingURL=settings-page-DUYYElOB.js.map