@xopcai/xopc 0.0.18 → 0.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/extensions/telegram/xopc.extension.json +1 -1
- package/dist/gateway/static/root/assets/{agents-D1c5jt8x.js → agents-ByiiWRbv.js} +2 -2
- package/dist/gateway/static/root/assets/{agents-D1c5jt8x.js.map → agents-ByiiWRbv.js.map} +1 -1
- package/dist/gateway/static/root/assets/{apps-page-bi53w_qy.js → apps-page-BpR0gguZ.js} +2 -2
- package/dist/gateway/static/root/assets/{apps-page-bi53w_qy.js.map → apps-page-BpR0gguZ.js.map} +1 -1
- package/dist/gateway/static/root/assets/{channels-settings-CPWWa4rf.js → channels-settings-h3eQwIPi.js} +2 -2
- package/dist/gateway/static/root/assets/{channels-settings-CPWWa4rf.js.map → channels-settings-h3eQwIPi.js.map} +1 -1
- package/dist/gateway/static/root/assets/{cron-page-CFuU6V8l.js → cron-page-D6wtd-hq.js} +2 -2
- package/dist/gateway/static/root/assets/{cron-page-CFuU6V8l.js.map → cron-page-D6wtd-hq.js.map} +1 -1
- package/dist/gateway/static/root/assets/{cron-utils-D7qRCgCo.js → cron-utils-o-QI_XCC.js} +2 -2
- package/dist/gateway/static/root/assets/{cron-utils-D7qRCgCo.js.map → cron-utils-o-QI_XCC.js.map} +1 -1
- package/dist/gateway/static/root/assets/{dist-CS--Aojm.js → dist-D2Td6E_v.js} +2 -2
- package/dist/gateway/static/root/assets/{dist-CS--Aojm.js.map → dist-D2Td6E_v.js.map} +1 -1
- package/dist/gateway/static/root/assets/{extension-debug-page-DkaqKijm.js → extension-debug-page-BIni4Qq4.js} +2 -2
- package/dist/gateway/static/root/assets/{extension-debug-page-DkaqKijm.js.map → extension-debug-page-BIni4Qq4.js.map} +1 -1
- package/dist/gateway/static/root/assets/{extension-page-5WNq5ZxE.js → extension-page-BRLScNkx.js} +2 -2
- package/dist/gateway/static/root/assets/{extension-page-5WNq5ZxE.js.map → extension-page-BRLScNkx.js.map} +1 -1
- package/dist/gateway/static/root/assets/{extension-settings-page-BM4emw9B.js → extension-settings-page-DjiK9Igx.js} +2 -2
- package/dist/gateway/static/root/assets/{extension-settings-page-BM4emw9B.js.map → extension-settings-page-DjiK9Igx.js.map} +1 -1
- package/dist/gateway/static/root/assets/{index-DJnBAhem.js → index-KGmhufWu.js} +53 -53
- package/dist/gateway/static/root/assets/{index-DJnBAhem.js.map → index-KGmhufWu.js.map} +1 -1
- package/dist/gateway/static/root/assets/{logs-page-Du6UoHCK.js → logs-page-C76F4Y0H.js} +2 -2
- package/dist/gateway/static/root/assets/{logs-page-Du6UoHCK.js.map → logs-page-C76F4Y0H.js.map} +1 -1
- package/dist/gateway/static/root/assets/{sessions-page-CzTpNrb3.js → sessions-page-9jwUqGtS.js} +2 -2
- package/dist/gateway/static/root/assets/{sessions-page-CzTpNrb3.js.map → sessions-page-9jwUqGtS.js.map} +1 -1
- package/dist/gateway/static/root/assets/{settings-page-jqrVlTkQ.js → settings-page-DNG3Zijx.js} +2 -2
- package/dist/gateway/static/root/assets/{settings-page-jqrVlTkQ.js.map → settings-page-DNG3Zijx.js.map} +1 -1
- package/dist/gateway/static/root/assets/{skills-page-Dg_Uk_jM.js → skills-page-BY1cLNEz.js} +2 -2
- package/dist/gateway/static/root/assets/{skills-page-Dg_Uk_jM.js.map → skills-page-BY1cLNEz.js.map} +1 -1
- package/dist/gateway/static/root/index.html +1 -1
- package/dist/package.js +1 -1
- package/package.json +1 -1
package/dist/gateway/static/root/assets/{settings-page-jqrVlTkQ.js → settings-page-DNG3Zijx.js}
RENAMED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{i as t,t as n}from"./vendor-react-DbimaAId.js";import{a as r,r as i}from"./vendor-swr-Dp4nzp5h.js";import{$n as a,At as o,B as s,Bt as c,En as l,Fn as u,Gt as d,H as f,In as p,It as m,Jn as h,Jt as g,Kn as _,Kt as v,L as y,Ln as b,Mt as x,Ot as ee,Qn as S,Qt as C,R as w,Rt as T,S as E,Sr as D,Tn as O,Tr as k,V as A,Vt as j,Wt as M,an as N,at as P,dn as F,dr as te,dt as I,et as L,fr as R,ft as z,gn as ne,it as B,jt as V,kt as re,ln as H,lr as ie,lt as U,mn as W,mr as G,nt as ae,or as oe,ot as K,qn as se,rt as q,sn as ce,sr as le,st as ue,tt as de,ut as fe,wn as pe,xn as me,xr as he,y as J,yn as ge,z as _e,zt as ve}from"./index-DJnBAhem.js";import{a as ye,p as be,v as xe}from"./cron-utils-D7qRCgCo.js";import{i as Se,n as Ce,r as we,t as Te}from"./agents-D1c5jt8x.js";var Y=n();function Ee(){return M(`rounded-xl border border-edge-subtle bg-surface-base px-4 py-1 sm:px-5`)}function De({scheme:e}){return e===`emerald`?(0,Y.jsxs)(`div`,{className:`flex h-10 w-full overflow-hidden rounded-md border border-edge-subtle`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-1 flex-col gap-1 bg-[#0a0a0a] p-1.5`,children:[(0,Y.jsx)(`div`,{className:`h-1 w-8 rounded-full bg-[#134e2a]`}),(0,Y.jsx)(`div`,{className:`h-1 w-5 rounded-full bg-[#134e2a]`})]}),(0,Y.jsx)(`div`,{className:`w-1.5 bg-[#10b981]`}),(0,Y.jsxs)(`div`,{className:`flex flex-1 flex-col gap-1 bg-[#000000] p-1.5`,children:[(0,Y.jsx)(`div`,{className:`h-1 w-6 rounded-full bg-[#34d399]`}),(0,Y.jsx)(`div`,{className:`h-1 w-9 rounded-full bg-[#065f46]`}),(0,Y.jsx)(`div`,{className:`h-1 w-4 rounded-full bg-[#065f46]`})]})]}):(0,Y.jsxs)(`div`,{className:`flex h-10 w-full overflow-hidden rounded-md border border-edge-subtle`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-1 flex-col gap-1 bg-[#f5f5f7] p-1.5`,children:[(0,Y.jsx)(`div`,{className:`h-1 w-8 rounded-full bg-[#d2d2d7]`}),(0,Y.jsx)(`div`,{className:`h-1 w-5 rounded-full bg-[#d2d2d7]`})]}),(0,Y.jsx)(`div`,{className:`w-1.5 bg-[#2563eb]`}),(0,Y.jsxs)(`div`,{className:`flex flex-1 flex-col gap-1 bg-[#ffffff] p-1.5`,children:[(0,Y.jsx)(`div`,{className:`h-1 w-6 rounded-full bg-[#1d1d1f]`}),(0,Y.jsx)(`div`,{className:`h-1 w-9 rounded-full bg-[#d2d2d7]`}),(0,Y.jsx)(`div`,{className:`h-1 w-4 rounded-full bg-[#d2d2d7]`})]})]})}var Oe=[{value:`default`,labelKey:`colorSchemeDefault`},{value:`emerald`,labelKey:`colorSchemeLightGreen`}];function ke(){let e=c(x(e=>e.language)).appearanceSettings,t=V(e=>e.colorScheme),n=V(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:Oe.map(({value:r,labelKey:i})=>{let a=t===r;return(0,Y.jsxs)(`button`,{type:`button`,"aria-pressed":a,onClick:()=>n(r),className:M(`flex flex-col gap-2 rounded-xl border-2 p-2.5 text-left transition-[border-color,box-shadow] duration-150`,a?`border-accent shadow-[0_0_0_1px_var(--color-accent)]`:`border-edge-subtle hover:border-edge`),children:[(0,Y.jsx)(De,{scheme:r}),(0,Y.jsx)(`span`,{className:M(`text-xs font-medium leading-none`,a?`text-accent-fg`:`text-fg-muted`),children:e[i]})]},r)})})]})}function Ae(){let e=c(x(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:Ee(),"aria-labelledby":`pref-language-heading`,children:[(0,Y.jsx)(`h2`,{id:`pref-language-heading`,className:`sr-only`,children:e.languageTitle}),(0,Y.jsx)(o,{variant:`page`,sections:[`language`]})]}),(0,Y.jsxs)(`section`,{className:Ee(),"aria-labelledby":`pref-appearance-heading`,children:[(0,Y.jsx)(`h2`,{id:`pref-appearance-heading`,className:`sr-only`,children:e.themeTitle}),(0,Y.jsx)(o,{variant:`page`,sections:[`theme`,`font`]}),(0,Y.jsx)(ke,{})]})]})}var X=e(t(),1);function je(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Me(e){let t=je(e)?e:{},n=je(t.gateway)?t.gateway:{},r=je(n.auth)?n.auth:{},i=r.mode===`none`||r.mode===`token`?r.mode:`token`;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:``}}}async function Ne(e){let t=e.auth.token.trim().length>0?{mode:e.auth.mode,token:e.auth.token}:{mode:e.auth.mode};await P(q(`/api/config`),{method:`PATCH`,body:JSON.stringify({gateway:{auth:t}})}),L()}function Pe(){return M(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,ve,`dark:border-edge`)}function Fe(){let e=x(e=>e.language),t=c(e),n=t.gatewaySettings,r=ee(e=>e.token),i=ee(e=>e.tokenExpired),a=ee(e=>e.openTokenDialog),o=!!r,[s,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(null),[p,m]=(0,X.useState)(!1),[g,_]=(0,X.useState)(null),[v,y]=(0,X.useState)(!1),[b,S]=(0,X.useState)(!1),[C,w]=(0,X.useState)(!1),T=(0,X.useRef)(!1),{data:E,error:D,isLoading:O,mutate:k}=de(o),A=(0,X.useMemo)(()=>E?.payload?.config===void 0?null:structuredClone(Me(E.payload.config)),[E]);(0,X.useEffect)(()=>{if(!o){u(null),f(null),T.current=!1;return}A!==null&&(T.current||(u(A),f(structuredClone(A)),y(!1)))},[o,A]);let M=!!(o&&O&&E===void 0&&!D),N=D instanceof Error?D.message:D?String(D):null,P=(0,X.useMemo)(()=>!s||!d?!1:JSON.stringify(s)!==JSON.stringify(d),[s,d]),F=(0,X.useCallback)(e=>{T.current=!0,u(t=>t?{...t,auth:{...t.auth,...e}}:null)},[]),te=(0,X.useCallback)(async()=>{if(!(!s||p)){m(!0),_(null),y(!1);try{await Ne(s),T.current=!1,f(structuredClone(s)),y(!0),window.setTimeout(()=>y(!1),2500)}catch(e){_(e instanceof Error?e.message:n.saveError)}finally{m(!1)}}},[s,p,n.saveError]),I=(0,X.useCallback)(async()=>{let e=s?.auth.token;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),w(!0),window.setTimeout(()=>w(!1),2e3))},[s?.auth.token]);return o?M?(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)(l,{className:`size-4 animate-spin`}),n.loading]})}):s?(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:re(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)(h,{className:`size-3.5`})]})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[v?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,Y.jsx)(j,{type:`button`,variant:`primary`,disabled:!P||p,onClick:()=>void te(),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)(le,{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)(j,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:()=>a(),children:n.updateToken})})]}):null,P?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,g?(0,Y.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:g}):null,s.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)(ce,{className:`size-4 text-accent`,strokeWidth:1.75}),t.settingsSections.gateway]}),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(s.host||s.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:s.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:s.port==null?`—`:String(s.port)})]}),(0,Y.jsx)(`p`,{className:`sm:col-span-2 text-xs text-fg-subtle`,children:n.listenHint})]}),(0,Y.jsx)(Ie,{g:n,value:s.auth.token,show:b,copied:C,onToggleShow:()=>S(e=>!e),onCopy:()=>void I(),onChange:e=>F({token:e})}),(0,Y.jsx)(j,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,onClick:()=>a(),children:n.changeToken})]})]})]}):(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:g??N??n.loadError}),(0,Y.jsx)(j,{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 Ie({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:M(Pe(),`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)(j,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:o,children:[r?(0,Y.jsx)(R,{className:`size-3.5`}):(0,Y.jsx)(a,{className:`size-3.5`}),r?e.copied:e.copy]}):null,(0,Y.jsxs)(j,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:i,children:[n?(0,Y.jsx)(se,{className:`size-3.5`}):(0,Y.jsx)(_,{className:`size-3.5`}),n?e.hide:e.show]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tokenHelp})]})}function Le(){return q(`/api/channels/status`)}var Re=be;function ze(){return q(`/api/workspace/heartbeat-md`)}async function Be(){let e=await P(ze());return typeof e.payload?.content==`string`?e.payload.content:``}function Ve(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function He(e){let t=Ve(e)?e:{},n=Ve(t.gateway)?t.gateway:{},r=Ve(n.heartbeat)?n.heartbeat:{},i=r.activeHours,a=Ve(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 Ue(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 We(e){await P(q(`/api/config`),{method:`PATCH`,body:JSON.stringify({gateway:{heartbeat:Ue(e)}})}),L()}async function Ge(e){await P(q(`/api/workspace/heartbeat-md`),{method:`PUT`,body:JSON.stringify({content:e})}),r(ze())}async function Ke(e){await P(q(`/api/heartbeat/trigger`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e?{reason:e}:{})})}var qe=[3e4,6e4,3e5,6e5,9e5,18e5,36e5,72e5],Je=new Set(qe);function Ye(){return M(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,ve,`dark:border-edge`)}function Xe(){return M(T,m)}function Ze(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 Qe(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 $e(){let e=x(e=>e.language),t=c(e),n=t.heartbeatSettings,r=!!ee(e=>e.token),[a,o]=(0,X.useState)(null),[s,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(``),[p,m]=(0,X.useState)(``),[g,_]=(0,X.useState)(!1),[v,y]=(0,X.useState)(!1),[S,C]=(0,X.useState)(null),[w,T]=(0,X.useState)(!1),[E,D]=(0,X.useState)(!1),[O,k]=(0,X.useState)(!1),[A,N]=(0,X.useState)(!1),[P,F]=(0,X.useState)(null),[te,I]=(0,X.useState)([]),{data:L,error:R,isLoading:z,mutate:B}=de(r),{data:V,error:H,isLoading:ie,mutate:U}=i(r?ze():null,Be,{revalidateOnFocus:!1}),{data:W=[]}=i(r?Le():null,Re,{revalidateOnFocus:!1}),G=(0,X.useMemo)(()=>Ze(L?.payload?.config),[L]),ae=(0,X.useMemo)(()=>He(L?.payload?.config??{}),[L]),oe=(0,X.useMemo)(()=>!a||!s?!1:JSON.stringify(a)!==JSON.stringify(s),[a,s]),K=(0,X.useMemo)(()=>d!==p,[d,p]);(0,X.useEffect)(()=>{if(!r){o(null),u(null);return}if(L!==void 0&&!oe){let e=structuredClone(ae);o(e),u(e),T(!1)}},[r,L,ae,oe]),(0,X.useEffect)(()=>{!r||V===void 0||K||(f(V),m(V),D(!1))},[r,V,K]);let se=R instanceof Error?R.message:R?String(R):H instanceof Error?H.message:H?String(H):null,q=!!(r&&(L===void 0||V===void 0)&&!se&&(z||ie));(0,X.useEffect)(()=>{if(!r||!a){I([]);return}let e=a.target.trim();if(!e){I([]);return}let t=!1;return xe(e).then(e=>{t||I(e)}),()=>{t=!0}},[r,a?.target]);let ce=(0,X.useCallback)(()=>{let e=a?.target?.trim();e&&xe(e).then(I)},[a?.target]),le=(0,X.useCallback)(async()=>{k(!0),N(!1),F(null);try{await Ke(),N(!0),window.setTimeout(()=>N(!1),3e3)}catch(e){F(e instanceof Error?e.message:n.triggerError)}finally{k(!1)}},[n.triggerError]),ue=(0,X.useCallback)(e=>{o(t=>t?{...t,...e}:null)},[]),fe=(0,X.useCallback)(async()=>{if(!(!a||g)){_(!0),C(null),T(!1);try{await We(a),u(structuredClone(a)),T(!0),window.setTimeout(()=>T(!1),2500)}catch(e){C(e instanceof Error?e.message:n.saveConfigError)}finally{_(!1)}}},[a,g,n.saveConfigError]),pe=(0,X.useCallback)(async()=>{if(!v){y(!0),C(null),D(!1);try{await Ge(d),m(d),D(!0),window.setTimeout(()=>D(!1),2500)}catch(e){C(e instanceof Error?e.message:n.saveDocError)}finally{y(!1)}}},[d,v,n.saveDocError]);return r?q?(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)(l,{className:`size-4 animate-spin`}),n.loading]})}):a?(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Y.jsx)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.heartbeat}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,Y.jsxs)(`a`,{href:re(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)(h,{className:`size-3.5`})]})]})}),G?(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.workspaceLabel,`: `,(0,Y.jsx)(`span`,{className:`font-mono text-fg-muted`,children:G})]}):null,S?(0,Y.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:S}):null,(0,Y.jsxs)(Ce,{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)(b,{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)(j,{type:`button`,variant:`secondary`,className:`inline-flex items-center gap-2`,disabled:O,onClick:()=>void le(),children:[O?(0,Y.jsx)(l,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(ne,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),O?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}),P?(0,Y.jsx)(`p`,{className:`mb-3 text-sm text-red-600 dark:text-red-400`,children:P}):null,(0,Y.jsx)(et,{h:n,cron:t.cron,form:a,channels:W,sessionChatIds:te,onRefreshChatIds:ce,update:ue,inputClassName:Ye,selectClassName:Xe}),(0,Y.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-2`,children:[w?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.savedConfig}):null,(0,Y.jsx)(j,{type:`button`,variant:`primary`,disabled:!oe||g,onClick:()=>void fe(),children:g?n.savingConfig:n.saveConfig}),oe?(0,Y.jsx)(`span`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedConfig}):null]})]}),(0,Y.jsxs)(Ce,{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:M(Ye(),`min-h-[12rem] resize-y font-mono text-xs leading-relaxed`),value:d,onChange:e=>f(e.target.value),spellCheck:!1,"aria-label":n.docSection}),(0,Y.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-2`,children:[E?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.savedDoc}):null,(0,Y.jsx)(j,{type:`button`,variant:`primary`,disabled:!K||v,onClick:()=>void pe(),children:v?n.savingDoc:n.saveDoc}),K?(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:S??se??n.loadError}),(0,Y.jsx)(j,{type:`button`,variant:`secondary`,onClick:()=>{B(),U()},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 et({h:e,cron:t,form:n,channels:r,sessionChatIds:i,onRefreshChatIds:a,update:o,inputClassName:s,selectClassName:c}){let l=(0,X.useMemo)(()=>new Set(r.map(e=>e.name)),[r]),u=n.target.trim(),d=!!(u&&!l.has(u)),f=(0,X.useMemo)(()=>Je.has(n.intervalMs)?String(n.intervalMs):``,[n.intervalMs]),[p,m]=(0,X.useState)(null),h=Math.max(1,Math.round(n.intervalMs/1e3)),g=p===null?String(h):p;return(0,X.useEffect)(()=>{m(null)},[n.intervalMs]),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:n.enabled,onChange:e=>o({enabled:e.target.checked})}),e.enable]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.interval}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:e.intervalSecondsLabel}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`input`,{type:`number`,min:1,step:1,className:M(s(),`min-w-0 flex-1`),value:g,onChange:e=>{let t=e.target.value;m(t);let n=parseInt(t,10);Number.isFinite(n)&&n>=1&&o({intervalMs:n*1e3})},onBlur:()=>{if(p===null)return;let e=parseInt(p,10);o(!Number.isFinite(e)||e<1?{intervalMs:1e3}:{intervalMs:e*1e3}),m(null)}}),(0,Y.jsxs)(`select`,{className:M(c(),`max-w-[11rem] shrink-0 text-xs`),value:f,onChange:e=>{let t=e.target.value;t&&(o({intervalMs:parseInt(t,10)}),m(null))},children:[(0,Y.jsx)(`option`,{value:``,children:e.intervalPresets.custom}),qe.map(t=>(0,Y.jsx)(`option`,{value:String(t),children:Qe(t,e.intervalPresets)},t))]})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.intervalHintPreset}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.intervalHint})]}),(0,Y.jsxs)(`div`,{className:`border-t border-edge-subtle pt-4`,children:[(0,Y.jsx)(`div`,{className:`mb-2 text-sm font-medium text-fg`,children:e.deliveryTitle}),(0,Y.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:t.channel}),(0,Y.jsxs)(`select`,{className:c(),value:u,onChange:e=>{o({target:e.target.value.trim(),targetChatId:``})},children:[(0,Y.jsx)(`option`,{value:``,children:e.channelNone}),d?(0,Y.jsxs)(`option`,{value:u,children:[u,` (`,e.customChannelSuffix,`)`]}):null,r.map(e=>(0,Y.jsxs)(`option`,{value:e.name,disabled:!e.enabled,children:[e.name,` `,e.enabled?``:`(disabled)`]},e.name))]})]}),u?(0,Y.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:t.recipient}),(0,Y.jsxs)(j,{type:`button`,variant:`ghost`,className:`h-7 gap-1 px-2 text-xs`,title:t.refreshRecipientHint,onClick:a,children:[(0,Y.jsx)(F,{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:M(s(),`min-w-0 flex-1`),value:n.targetChatId,onChange:e=>o({targetChatId:e.target.value}),placeholder:t.recipientPlaceholder,autoComplete:`off`}),(0,Y.jsxs)(`select`,{className:M(c(),`max-w-[10rem] shrink-0 text-xs`),value:n.targetChatId,onChange:e=>{let t=e.target.value;t&&o({targetChatId:t})},children:[(0,Y.jsx)(`option`,{value:``,children:t.selectRecipient}),i.length>0?i.map(e=>(0,Y.jsx)(`option`,{value:e.chatId,children:ye(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:M(s(),`min-h-[4.5rem] resize-y font-mono text-xs`),value:n.prompt,onChange:e=>o({prompt:e.target.value}),placeholder:e.promptPlaceholder}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:e.promptHint})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:e.ackMaxChars}),(0,Y.jsx)(`input`,{type:`number`,min:1,className:s(),value:n.ackMaxChars===``?``:n.ackMaxChars,onChange:e=>{let t=e.target.value;if(t===``)o({ackMaxChars:``});else{let e=parseInt(t,10);o({ackMaxChars:Number.isFinite(e)?e:``})}},placeholder:e.ackDefaultPlaceholder}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:e.ackMaxCharsHint})]}),(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:n.isolatedSession,onChange:e=>o({isolatedSession:e.target.checked})}),(0,Y.jsxs)(`span`,{children:[e.isolatedSession,(0,Y.jsx)(`span`,{className:`mt-1 block text-xs text-fg-subtle`,children:e.isolatedSessionHint})]})]}),(0,Y.jsxs)(`div`,{className:`border-t border-edge-subtle pt-4`,children:[(0,Y.jsx)(`div`,{className:`mb-2 text-sm font-medium text-fg`,children:e.activeHoursTitle}),n.activeHours?(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-xs text-fg`,children:e.activeStart}),(0,Y.jsx)(`input`,{className:s(),value:n.activeHours.start,onChange:e=>o({activeHours:{...n.activeHours,start:e.target.value}}),placeholder:`09:00`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-xs text-fg`,children:e.activeEnd}),(0,Y.jsx)(`input`,{className:s(),value:n.activeHours.end,onChange:e=>o({activeHours:{...n.activeHours,end:e.target.value}}),placeholder:`22:00`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-xs text-fg`,children:e.activeTimezone}),(0,Y.jsx)(`input`,{className:s(),value:n.activeHours.timezone,onChange:e=>o({activeHours:{...n.activeHours,timezone:e.target.value}}),placeholder:`Asia/Shanghai`})]})]}):(0,Y.jsx)(j,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:()=>o({activeHours:{start:`09:00`,end:`22:00`,timezone:``}}),children:e.addActiveHours}),n.activeHours?(0,Y.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:(0,Y.jsx)(j,{type:`button`,variant:`secondary`,className:`text-xs`,onClick:()=>o({activeHours:null}),children:e.clearActiveHours})}):null,(0,Y.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:e.activeHoursHint})]})]})}var tt=[{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 nt(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 rt(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 it(){let e=await B(q(`/api/models-json`)),t=await e.json().catch(()=>({}));if(!e.ok||!t.ok||!t.payload)throw Error(nt(t)||`HTTP ${e.status}`);return{...t.payload,config:rt(t.payload.config)}}async function at(e){let t=await B(q(`/api/models-json/validate`),{method:`POST`,body:JSON.stringify({config:e})}),n=await t.json().catch(()=>({}));if(!t.ok||!n.ok||!n.payload)throw Error(nt(n)||`HTTP ${t.status}`);return n.payload}async function ot(e){let t=await B(q(`/api/models-json`),{method:`PATCH`,body:JSON.stringify({config:e})}),n=await t.json().catch(()=>({}));if(!t.ok||!n.ok||!n.payload)throw Error(nt(n)||`HTTP ${t.status}`);return n.payload}async function st(){let e=await B(q(`/api/models-json/reload`),{method:`POST`}),t=await e.json().catch(()=>({}));if(!e.ok||!t.ok||!t.payload)throw Error(nt(t)||`HTTP ${e.status}`);return t.payload}async function ct(e){let t=await B(q(`/api/models-json/test-api-key`),{method:`POST`,body:JSON.stringify({value:e})}),n=await t.json().catch(()=>({}));if(!t.ok||!n.ok||!n.payload)throw Error(nt(n)||`HTTP ${t.status}`);return n.payload}function lt(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 ut(e){return e.startsWith(`!`)}function dt(e){return/^[A-Z][A-Z0-9_]*$/.test(e)}function ft(e){return ut(e)?`shell`:dt(e)?`env`:`literal`}function pt(e){return e?e.length<=8?`••••`:`${e.slice(0,4)}••••${e.slice(-4)}`:``}var mt={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 ht(e){return e===`openrouter`?`openrouter`:e===`zhipuCn`?`zhipu-cn`:e===`zaiGeneral`?`zai`:e}var gt=[{value:`text`,labelKey:`inputTextOnly`},{value:`text,image`,labelKey:`inputTextVision`}];function Z(){return M(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,ve,`dark:border-edge`)}function _t(){return M(T,m)}function vt(e){return(e.input||[`text`]).includes(`image`)?`text,image`:`text`}function yt(e){return e===`text,image`?[`text`,`image`]:[`text`]}function bt(e,t,n){return{...e,providers:{...e.providers,[t]:{...e.providers[t],...n}}}}function xt(e,t){let n={...e.providers};return delete n[t],{...e,providers:n}}function St(e,t,n){return{...e,providers:{...e.providers,[t]:n}}}function Ct({open:e,onOpenChange:t,presetKey:n,onConfirm:r,m:i}){let[a,o]=(0,X.useState)(``),[s,c]=(0,X.useState)(`custom`),[l,u]=(0,X.useState)(``),[d,f]=(0,X.useState)(`openai-completions`),[p,m]=(0,X.useState)(``),[h,g]=(0,X.useState)(null);(0,X.useEffect)(()=>{if(!e)return;g(null);let t=n||null;if(t&&mt[t]){let e=mt[t];c(t),u(e.baseUrl||``),f(e.api||`openai-completions`),m(e.apiKey??``),o(ht(t))}else c(`custom`),o(``),u(``),f(`openai-completions`),m(``)},[e,n]);let _=e=>{if(c(e),e===`custom`)return;let t=mt[e];t&&(u(t.baseUrl||``),f(t.api||`openai-completions`),m(t.apiKey??``),o(ht(e)))};return(0,Y.jsx)(I,{open:e,onOpenChange:t,children:(0,Y.jsxs)(fe,{children:[(0,Y.jsx)(U,{className:`xopc-dialog-overlay fixed inset-0 z-50 bg-scrim`}),(0,Y.jsxs)(ue,{className:M(`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)(z,{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)(K,{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)(v,{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:_t(),value:s,onChange:e=>_(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:Z(),value:a,onChange:e=>o(e.target.value),placeholder:i.providerIdPlaceholder})]}),(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:i.baseUrl}),(0,Y.jsx)(`input`,{className:Z(),value:l,onChange:e=>u(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:_t(),value:d,onChange:e=>f(e.target.value),children:tt.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:Z(),value:p,onChange:e=>m(e.target.value),placeholder:i.apiKeyPlaceholder})]}),h?(0,Y.jsxs)(`p`,{className:`flex items-center gap-1 text-xs text-red-600 dark:text-red-400`,children:[(0,Y.jsx)(le,{className:`size-3.5 shrink-0`}),h]}):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)(K,{asChild:!0,children:(0,Y.jsx)(j,{type:`button`,variant:`secondary`,children:i.cancel})}),(0,Y.jsx)(j,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:()=>{let e=a.trim();if(!e){g(i.providerIdRequired);return}g(null),r(e,{baseUrl:l.trim()||void 0,api:d,apiKey:p.trim()||void 0,models:[]}),t(!1)},children:i.addProviderConfirm})]})]})]})})}function wt({open:e,onOpenChange:t,providerId:n,model:r,isNew:i,onSave:a,m:o}){let[s,c]=(0,X.useState)(()=>lt(``)),[l,u]=(0,X.useState)(()=>new Map);(0,X.useEffect)(()=>{e&&(u(new Map),c(r?{...r}:lt(``)))},[e,r]);let d=(e,t)=>{c(n=>({...n,[e]:t})),u(t=>{let n=new Map(t);return n.delete(e),n})},f=()=>{let e=new Map;return(s.id||``).trim()||e.set(`id`,o.modelIdRequired),s.contextWindow!==void 0&&s.contextWindow<=0&&e.set(`contextWindow`,o.mustBePositive),s.maxTokens!==void 0&&s.maxTokens<=0&&e.set(`maxTokens`,o.mustBePositive),u(e),e.size===0},p=()=>{if(!f())return;let e=(s.id||``).trim();a({...s,id:e,name:s.name?.trim()||e,reasoning:s.reasoning||!1,input:s.input||[`text`],contextWindow:s.contextWindow??128e3,maxTokens:s.maxTokens??16384,cost:{input:s.cost?.input??0,output:s.cost?.output??0,cacheRead:s.cost?.cacheRead??0,cacheWrite:s.cost?.cacheWrite??0}}),t(!1)},m=vt(s);return(0,Y.jsx)(I,{open:e,onOpenChange:t,children:(0,Y.jsxs)(fe,{children:[(0,Y.jsx)(U,{className:`xopc-dialog-overlay fixed inset-0 z-50 bg-scrim`}),(0,Y.jsxs)(ue,{className:M(`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)(z,{className:`text-base font-semibold text-fg`,children:i?o.addModelTitle:o.editModelTitle}),n?(0,Y.jsxs)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:[o.modelProviderLabel,`: `,n]}):null]}),(0,Y.jsx)(K,{asChild:!0,children:(0,Y.jsx)(`button`,{type:`button`,className:`rounded-lg p-1.5 text-fg-muted hover:bg-surface-base hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,"aria-label":o.close,children:(0,Y.jsx)(v,{className:`size-4`})})})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`mb-1 block text-xs font-medium text-fg`,children:[o.modelId,(0,Y.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,Y.jsx)(`input`,{className:M(Z(),l.has(`id`)&&`border-red-500`),value:s.id||``,onChange:e=>d(`id`,e.target.value),placeholder:`e.g. llama3.1:8b`,disabled:!i}),l.has(`id`)?(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:l.get(`id`)}):null]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:o.displayName}),(0,Y.jsx)(`input`,{className:Z(),value:s.name||``,onChange:e=>d(`name`,e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:o.inputTypes}),(0,Y.jsx)(`select`,{className:_t(),value:m,onChange:e=>d(`input`,yt(e.target.value)),children:gt.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:o[e.labelKey]},e.value))})]}),(0,Y.jsxs)(`label`,{className:`mt-6 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:s.reasoning||!1,onChange:e=>d(`reasoning`,e.target.checked)}),o.reasoning]})]}),(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:o.contextWindow}),(0,Y.jsx)(`input`,{type:`number`,min:1,className:M(Z(),l.has(`contextWindow`)&&`border-red-500`),value:s.contextWindow??128e3,onChange:e=>d(`contextWindow`,parseInt(e.target.value,10)||0)}),l.has(`contextWindow`)?(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:l.get(`contextWindow`)}):null]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:o.maxOutputTokens}),(0,Y.jsx)(`input`,{type:`number`,min:1,className:M(Z(),l.has(`maxTokens`)&&`border-red-500`),value:s.maxTokens??16384,onChange:e=>d(`maxTokens`,parseInt(e.target.value,10)||0)}),l.has(`maxTokens`)?(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:l.get(`maxTokens`)}):null]})]}),(0,Y.jsxs)(`div`,{className:`border-t border-edge-subtle pt-2 dark:border-edge`,children:[(0,Y.jsx)(`p`,{className:`mb-2 text-xs font-semibold text-fg`,children:o.costSection}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:o.costInput}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,min:0,className:Z(),value:s.cost?.input??0,onChange:e=>d(`cost`,{...s.cost,input:parseFloat(e.target.value)||0,output:s.cost?.output??0,cacheRead:s.cost?.cacheRead??0,cacheWrite:s.cost?.cacheWrite??0})})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:o.costOutput}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,min:0,className:Z(),value:s.cost?.output??0,onChange:e=>d(`cost`,{...s.cost,input:s.cost?.input??0,output:parseFloat(e.target.value)||0,cacheRead:s.cost?.cacheRead??0,cacheWrite:s.cost?.cacheWrite??0})})]})]})]})]}),(0,Y.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2 border-t border-edge-subtle pt-3 dark:border-edge`,children:[(0,Y.jsx)(K,{asChild:!0,children:(0,Y.jsx)(j,{type:`button`,variant:`secondary`,children:o.cancel})}),(0,Y.jsx)(j,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:p,children:i?o.addModelConfirm:o.saveModelConfirm})]})]})]})})}function Tt(){let e=x(e=>e.language),t=c(e),n=t.modelsSettings,r=!!ee(e=>e.token),[i,a]=(0,X.useState)({providers:{}}),[o,s]=(0,X.useState)({providers:{}}),[u,f]=(0,X.useState)(``),[p,m]=(0,X.useState)(),[g,v]=(0,X.useState)(!0),[y,b]=(0,X.useState)(!1),[w,T]=(0,X.useState)(!1),[E,D]=(0,X.useState)(!1),[O,k]=(0,X.useState)(null),[A,N]=(0,X.useState)(!1),[P,I]=(0,X.useState)(null),[L,R]=(0,X.useState)(()=>new Set),[z,ne]=(0,X.useState)(!1),[B,V]=(0,X.useState)(``),[H,U]=(0,X.useState)(null),[ae,oe]=(0,X.useState)(()=>new Set),[K,q]=(0,X.useState)(()=>new Map),[ce,ue]=(0,X.useState)(!1),[de,fe]=(0,X.useState)(null),[pe,me]=(0,X.useState)(!1),[he,_e]=(0,X.useState)(null),ve=(0,X.useCallback)(async e=>{let t=!e?.skipFullPageLoading;t&&v(!0),k(null);try{let e=await it(),t=rt(e.config);a(t),s(structuredClone(t)),f(e.path),m(e.loadError),I(null),N(!1)}catch(e){k(e instanceof Error?e.message:n.loadError),a({providers:{}}),s({providers:{}})}finally{t&&v(!1)}},[n.loadError]);(0,X.useEffect)(()=>{if(!r){v(!1);return}ve()},[r,ve]);let ye=(0,X.useMemo)(()=>JSON.stringify(i)!==JSON.stringify(o),[i,o]),be=(0,X.useMemo)(()=>{let e=Object.keys(i.providers),t=0;for(let e of Object.values(i.providers))t+=e.models?.length??0;return{providers:e.length,models:t}},[i.providers]),xe=e=>{R(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Se=e=>{oe(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Ce=(0,X.useCallback)(()=>{V(JSON.stringify(i,null,2)),U(null)},[i]);(0,X.useEffect)(()=>{z&&Ce()},[z,Ce]);let we=()=>{try{a(rt(JSON.parse(B))),U(null)}catch{U(n.jsonParseError)}},Te=async()=>{T(!0),k(null);try{I(await at(i))}catch(e){k(e instanceof Error?e.message:n.validateError)}finally{T(!1)}},Ee=async()=>{if(!y){b(!0),k(null),N(!1);try{await ot(i),s(structuredClone(i)),N(!0),I(null)}catch(e){k(e instanceof Error?e.message:n.saveError)}finally{b(!1)}}},De=async()=>{D(!0),k(null);try{await st(),await ve({skipFullPageLoading:!0})}catch(e){k(e instanceof Error?e.message:n.reloadError)}finally{D(!1)}},Oe=async(e,t)=>{try{let n=await ct(t);q(t=>{let r=new Map(t);return r.set(e,n),r})}catch(t){q(n=>{let r=new Map(n);return r.set(e,{type:`error`,error:t instanceof Error?t.message:`Error`}),r})}},ke=(e=null)=>{fe(e),ue(!0)},Ae=(e,t)=>{a(n=>St(n,e,t)),R(t=>new Set(t).add(e))},je=e=>{window.confirm(n.removeProviderConfirm.replace(`{{id}}`,e))&&(a(t=>xt(t,e)),q(t=>{let n=new Map(t);return n.delete(e),n}))},Me=(e,t,n)=>{_e({providerId:e,model:t,isNew:n}),me(!0)};return r?(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:re(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)(h,{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)(le,{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)(j,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:()=>ke(null),disabled:g,children:[(0,Y.jsx)(W,{className:`mr-1 size-4`}),n.addProvider]}),(0,Y.jsx)(j,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:Te,disabled:g||w,children:w?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(l,{className:`mr-1 size-4 animate-spin`}),n.validating]}):n.validate}),(0,Y.jsx)(j,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:Ee,disabled:g||y||!ye,children:y?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(l,{className:`mr-1 size-4 animate-spin`}),n.saving]}):n.save}),(0,Y.jsx)(j,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[8.5rem] justify-center`,onClick:De,disabled:g||E,children:E?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(l,{className:`mr-1 size-4 animate-spin`}),n.reloading]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(F,{className:`mr-1 size-4`}),n.reload]})}),(0,Y.jsx)(j,{type:`button`,variant:`ghost`,className:`text-fg-muted`,onClick:()=>{ne(e=>!e),U(null)},children:z?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(be.providers))}),(0,Y.jsx)(`span`,{className:`text-fg-subtle`,children:`|`}),(0,Y.jsx)(`span`,{className:`text-fg-muted`,children:n.statsModels.replace(`{{count}}`,String(be.models))})]})]}),ye?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,A?(0,Y.jsx)(`p`,{className:`text-xs text-emerald-700 dark:text-emerald-400`,role:`status`,children:n.saved}):null,O?(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)(le,{className:`size-4 shrink-0`}),O]}):null,P&&P.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:P.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:P.errors.map((e,t)=>(0,Y.jsxs)(`li`,{children:[e.path,`: `,e.message,` (`,e.severity,`)`]},`${e.path}-${t}`))})]}):null,g?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,Y.jsx)(l,{className:`size-4 animate-spin`}),n.loading]}):z?(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(`textarea`,{className:M(Z(),`min-h-[320px] resize-y font-mono text-xs leading-relaxed`),value:B,onChange:e=>V(e.target.value),spellCheck:!1}),H?(0,Y.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:H}):null,(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(j,{type:`button`,variant:`secondary`,onClick:Ce,children:n.jsonReset}),(0,Y.jsx)(j,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:we,children:n.jsonApply})]})]}):Object.keys(i.providers).length===0?(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)(S,{className:`size-7 text-accent`,strokeWidth:1.5})}),(0,Y.jsx)(`h2`,{className:`mb-1 text-base font-semibold text-fg`,children:n.emptyTitle}),(0,Y.jsx)(`p`,{className:`mb-6 max-w-md text-sm text-fg-muted`,children:n.emptyDesc}),(0,Y.jsxs)(j,{type:`button`,className:`mb-6 bg-accent text-white hover:bg-accent/90`,onClick:()=>ke(null),children:[(0,Y.jsx)(W,{className:`mr-1 size-4`}),n.emptyCta]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap justify-center gap-2`,children:[(0,Y.jsxs)(`button`,{type:`button`,className:M(`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`,J.transition,J.focusRingBase),onClick:()=>ke(`ollama`),children:[(0,Y.jsx)(d,{className:`size-3.5`,"aria-hidden":!0}),n.presetOllama]}),(0,Y.jsxs)(`button`,{type:`button`,className:M(`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`,J.transition,J.focusRingBase),onClick:()=>ke(`openrouter`),children:[(0,Y.jsx)(G,{className:`size-3.5`,"aria-hidden":!0}),n.presetOpenRouter]}),(0,Y.jsxs)(`button`,{type:`button`,className:M(`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`,J.transition,J.focusRingBase),onClick:()=>ke(`lmstudio`),children:[(0,Y.jsx)(S,{className:`size-3.5`,"aria-hidden":!0}),n.presetLmStudio]}),(0,Y.jsxs)(`button`,{type:`button`,className:M(`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`,J.transition,J.focusRingBase),onClick:()=>ke(`zhipuCn`),children:[(0,Y.jsx)(d,{className:`size-3.5`,"aria-hidden":!0}),n.presetZhipuCn]}),(0,Y.jsxs)(`button`,{type:`button`,className:M(`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`,J.transition,J.focusRingBase),onClick:()=>ke(`zaiGeneral`),children:[(0,Y.jsx)(G,{className:`size-3.5`,"aria-hidden":!0}),n.presetZaiGeneral]})]})]}):(0,Y.jsx)(`div`,{className:`flex flex-col gap-3`,children:Object.entries(i.providers).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>{let r=L.has(e),i=t.models?.length??0,o=t.apiKey?ft(t.apiKey):null,s=K.get(e),c=ae.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:()=>xe(e),children:[r?(0,Y.jsx)(te,{className:`size-4 shrink-0 text-fg-muted`}):(0,Y.jsx)(ie,{className:`size-4 shrink-0 text-fg-muted`}),(0,Y.jsx)(`span`,{className:`truncate`,children:e}),i>0?(0,Y.jsx)(`span`,{className:`shrink-0 rounded-full bg-accent px-2 py-0.5 text-[10px] font-medium text-white`,children:i}):null,o?(0,Y.jsx)(`span`,{className:M(`shrink-0 rounded-full px-2 py-0.5 text-[10px] font-medium`,o===`shell`&&`bg-blue-100 text-blue-800 dark:bg-blue-950 dark:text-blue-200`,o===`env`&&`bg-emerald-100 text-emerald-800 dark:bg-emerald-950 dark:text-emerald-200`,o===`literal`&&`bg-surface-hover text-fg-muted dark:bg-surface-active`),children:o===`shell`?n.badgeShell:o===`env`?n.badgeEnv:n.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:()=>je(e),"aria-label":n.removeProvider,children:(0,Y.jsx)(C,{className:`size-4`})})]}),r?(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:n.baseUrl}),(0,Y.jsx)(`input`,{className:Z(),value:t.baseUrl||``,onChange:t=>a(n=>bt(n,e,{baseUrl:t.target.value}))})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:n.apiType}),(0,Y.jsx)(`select`,{className:_t(),value:t.api||`openai-completions`,onChange:t=>a(n=>bt(n,e,{api:t.target.value})),children:tt.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:n.apiKey}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Y.jsx)(`input`,{className:M(Z(),`min-w-0 flex-1`),type:c?`text`:`password`,autoComplete:`off`,value:t.apiKey||``,onChange:t=>{let n=t.target.value;a(t=>bt(t,e,{apiKey:n})),q(t=>{let n=new Map(t);return n.delete(e),n})},placeholder:n.apiKeyPlaceholder}),(0,Y.jsx)(j,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>Se(e),children:c?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(se,{className:`mr-1 size-3.5`}),n.hide]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(_,{className:`mr-1 size-3.5`}),n.show]})}),(0,Y.jsx)(j,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>Oe(e,t.apiKey||``),children:n.testKey})]}),s?(0,Y.jsx)(`p`,{className:M(`mt-1 text-xs`,s.error?`text-red-600 dark:text-red-400`:`text-emerald-700 dark:text-emerald-400`),children:s.error?`${n.testError}: ${s.error}`:`${n.testOk} (${s.type}): ${pt(s.resolved||``)}`}):null,(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:n.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:t.authHeader||!1,onChange:t=>a(n=>bt(n,e,{authHeader:t.target.checked}))}),n.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:n.modelsSection}),(0,Y.jsxs)(j,{type:`button`,variant:`primary`,className:`px-2 py-1 text-xs`,onClick:()=>Me(e,null,!0),children:[(0,Y.jsx)(W,{className:`mr-1 size-3.5`}),n.addModel]})]}),(t.models||[]).length===0?(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.modelsEmpty}):(0,Y.jsx)(`ul`,{className:`space-y-2`,children:(t.models||[]).map(t=>(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:t.id}),t.name&&t.name!==t.id?(0,Y.jsx)(`div`,{className:`truncate text-xs text-fg-muted`,children:t.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:()=>Me(e,t,!1),"aria-label":n.editModel,children:(0,Y.jsx)(ge,{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(n.removeModelConfirm.replace(`{{id}}`,t.id))&&a(n=>{let r=n.providers[e];return r?bt(n,e,{models:(r.models||[]).filter(e=>e.id!==t.id)}):n})},"aria-label":n.removeModel,children:(0,Y.jsx)(C,{className:`size-4`})})]})]},t.id))})]})]}):null]},e)})}),(0,Y.jsx)(Ct,{open:ce,onOpenChange:ue,presetKey:de,onConfirm:Ae,m:n}),(0,Y.jsx)(wt,{open:pe,onOpenChange:e=>{me(e),e||_e(null)},providerId:he?.providerId??null,model:he?.model??null,isNew:he?.isNew??!1,onSave:e=>{if(!he)return;let{providerId:t,isNew:n}=he;a(r=>{let i=r.providers[t];if(!i)return r;let a=i.models||[];return n?bt(r,t,{models:[...a,e]}):bt(r,t,{models:a.map(t=>t.id===e.id?e:t)})})},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})]})}function Et(){return{enabled:!1,provider:`alibaba`,alibaba:{model:`paraformer-v2`},openai:{model:`whisper-1`},fallback:{enabled:!0,order:[`alibaba`,`openai`]}}}function Dt(){return{enabled:!1,provider:`openai`,trigger:`always`,maxTextLength:4096,timeoutMs:3e4,alibaba:{model:`qwen-tts`,voice:`Cherry`},openai:{model:`tts-1`,voice:`alloy`},edge:{voice:`zh-CN-XiaoxiaoNeural`},minimax:{model:`speech-2.8-hd`,voice:`male-qn-qingse`}}}function Ot(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function kt(e){let t=Et();if(!Ot(e))return t;let n=e.provider===`openai`?`openai`:`alibaba`,r=Ot(e.alibaba)?{...t.alibaba,...e.alibaba}:t.alibaba,i=Ot(e.openai)?{...t.openai,...e.openai}:t.openai,a=t.fallback??{enabled:!0,order:[`alibaba`,`openai`]};if(Ot(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 At(e){return e===`openai`||e===`alibaba`||e===`edge`||e===`minimax`}function jt(e){let t=Dt();if(!Ot(e))return t;let n=At(e.provider)?e.provider:`openai`,r=e.trigger===`off`||e.trigger===`always`||e.trigger===`inbound`||e.trigger===`tagged`?e.trigger:`always`;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:Ot(e.alibaba)?{...t.alibaba,...e.alibaba}:t.alibaba,openai:Ot(e.openai)?{...t.openai,...e.openai}:t.openai,edge:Ot(e.edge)?{...t.edge,...e.edge}:t.edge,minimax:Ot(e.minimax)?{...t.minimax,...e.minimax}:t.minimax}}function Mt(e){let t=Ot(e)?e:{};return{stt:kt(t.stt),tts:jt(t.tts)}}async function Nt(e){await P(q(`/api/config`),{method:`PATCH`,body:JSON.stringify({stt:e.stt,tts:e.tts})}),L()}async function Pt(){let e=await P(q(`/api/voice/models`));if(!e.payload?.models)throw Error(`Missing voice models payload`);return e.payload.models}function Ft(){return M(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,ve,`dark:border-edge`)}function Q(){return M(T,m)}var It=[{id:`paraformer-v2`,name:`Paraformer v2`},{id:`paraformer-v1`,name:`Paraformer v1`}],Lt=[{id:`whisper-1`,name:`Whisper-1`}],Rt=[{id:`tts-1`,name:`TTS-1`},{id:`tts-1-hd`,name:`TTS-1 HD`}],zt=[{id:`alloy`,name:`Alloy`},{id:`echo`,name:`Echo`}],Bt=[{id:`qwen-tts`,name:`Qwen TTS`},{id:`qwen3-tts-flash`,name:`Qwen3 TTS Flash`}],Vt=[{id:`Cherry`,name:`Cherry`},{id:`longxiaochun`,name:`Long Xiao Chun`}],Ht=[{id:`en-US-MichelleNeural`,name:`Michelle (US English)`},{id:`zh-CN-XiaoxiaoNeural`,name:`Xiaoxiao (Chinese)`}],Ut=[{id:`speech-2.8-hd`,name:`Speech 2.8 HD (Recommended)`},{id:`speech-2.8-turbo`,name:`Speech 2.8 Turbo (Fast)`}],Wt=[{id:`male-qn-qingse`,name:`Male Qingse (青涩男声)`},{id:`female-shaonv`,name:`Female Shaonv (少女音)`}];function Gt(){let e=x(e=>e.language),t=c(e),n=t.voiceSettings,r=!!ee(e=>e.token),[a,o]=(0,X.useState)(null),[s,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(null),[p,m]=(0,X.useState)(!1),[g,_]=(0,X.useState)(null),[v,y]=(0,X.useState)(!1),{data:b,error:S,isLoading:C,mutate:w}=de(r),{data:T,error:E,isLoading:D,mutate:O}=i(r?q(`/api/voice/models`):null,Pt,{revalidateOnFocus:!1}),k=(0,X.useMemo)(()=>b?.payload?.config===void 0?null:Mt(b.payload.config),[b]),A=(0,X.useMemo)(()=>!a||!s?!1:JSON.stringify(a)!==JSON.stringify(s),[a,s]);(0,X.useEffect)(()=>{if(!r){o(null),u(null),f(null);return}k===null||T===void 0||A||(o(structuredClone(k)),u(structuredClone(k)),f(T),y(!1))},[r,k,T,A]);let M=!!(r&&(k===null||T===void 0)&&(C||D)),N=S instanceof Error?S.message:S?String(S):E instanceof Error?E.message:E?String(E):null,P=(0,X.useCallback)(e=>{o(t=>t?{...t,stt:{...t.stt,...e}}:null)},[]),F=(0,X.useCallback)(e=>{o(t=>t?{...t,stt:{...t.stt,alibaba:{...t.stt.alibaba,...e}}}:null)},[]),te=(0,X.useCallback)(e=>{o(t=>t?{...t,stt:{...t.stt,openai:{...t.stt.openai,...e}}}:null)},[]),I=(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}}}})},[]),L=(0,X.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,...e}}:null)},[]),R=(0,X.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,alibaba:{...t.tts.alibaba,...e}}}:null)},[]),z=(0,X.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,openai:{...t.tts.openai,...e}}}:null)},[]),ne=(0,X.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,edge:{...t.tts.edge,...e}}}:null)},[]),B=(0,X.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,minimax:{...t.tts.minimax,...e}}}:null)},[]),V=(0,X.useCallback)(async()=>{if(!(!a||p)){m(!0),_(null),y(!1);try{await Nt(a);let e=structuredClone(a);u(e),o(e),y(!0),window.setTimeout(()=>y(!1),2500)}catch(e){_(e instanceof Error?e.message:n.saveError)}finally{m(!1)}}},[a,p,n.saveError]);if(!r)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(M)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)(l,{className:`size-4 animate-spin`}),n.loading]})});if(!a||d===null)return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:g??N??n.loadError}),(0,Y.jsx)(j,{type:`button`,variant:`secondary`,onClick:()=>{w(),O()},children:n.retry})]});let H=a.stt,ie=a.tts;return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.voice}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,Y.jsxs)(`a`,{href:re(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)(h,{className:`size-3.5`})]})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[v?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,Y.jsx)(j,{type:`button`,variant:`primary`,disabled:!A||p,onClick:()=>void V(),children:p?n.saving:n.save})]})]}),A?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,g?(0,Y.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:g}):null,(0,Y.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Y.jsx)(Kt,{v:n,stt:H,models:d,updateStt:P,updateSttAlibaba:F,updateSttOpenai:te,updateSttFallback:I}),(0,Y.jsx)(qt,{v:n,tts:ie,models:d,updateTts:L,updateTtsAlibaba:R,updateTtsOpenai:z,updateTtsEdge:ne,updateTtsMinimax:B})]}),(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 Kt({v:e,stt:t,models:n,updateStt:r,updateSttAlibaba:i,updateSttOpenai:a,updateSttFallback:o}){let s=n?.stt?.alibaba?.length?n.stt.alibaba:It,c=n?.stt?.openai?.length?n.stt.openai:Lt;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)(me,{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:Q(),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:M(Ft(),`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:Q(),value:t.alibaba?.model??``,onChange:e=>i({model:e.target.value}),children:s.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}):(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.apiKey}),(0,Y.jsx)(`input`,{className:M(Ft(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.openai?.apiKey??``,onChange:e=>a({apiKey:e.target.value}),placeholder:`sk-...`}),(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (OPENAI_API_KEY)`]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:Q(),value:t.openai?.model??``,onChange:e=>a({model:e.target.value}),children:c.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.stt.fallback}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.stt.fallbackDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:t.fallback?.enabled??!0,onChange:e=>o({enabled:e.target.checked})})]})]}):null]})]})}function qt({v:e,tts:t,models:n,updateTts:r,updateTtsAlibaba:i,updateTtsOpenai:a,updateTtsEdge:o,updateTtsMinimax:s}){let c=t=>t===`off`?e.tts.triggerDescOff:t===`always`?e.tts.triggerDescAlways:t===`inbound`?e.tts.triggerDescInbound:t===`tagged`?e.tts.triggerDescTagged:``,l=n?.tts?.openai?.length?n.tts.openai:Rt,u=n?.ttsVoices?.openai?.length?n.ttsVoices.openai:zt,d=n?.tts?.alibaba?.length?n.tts.alibaba:Bt,f=n?.ttsVoices?.alibaba?.length?n.ttsVoices.alibaba:Vt,p=n?.ttsVoices?.edge?.length?n.ttsVoices.edge:Ht,m=n?.tts?.minimax?.length?n.tts.minimax:Ut,h=n?.ttsVoices?.minimax?.length?n.ttsVoices.minimax:Wt;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)(g,{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:Q(),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:c(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:Q(),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})]})]})]}),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:M(Ft(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.openai?.apiKey??``,onChange:e=>a({apiKey:e.target.value}),placeholder:`sk-...`}),(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (OPENAI_API_KEY)`]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:Q(),value:t.openai?.model??``,onChange:e=>a({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 flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.tts.voice}),(0,Y.jsx)(`select`,{className:Q(),value:t.openai?.voice??``,onChange:e=>a({voice:e.target.value}),children:u.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:M(Ft(),`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:Q(),value:t.alibaba?.model??``,onChange:e=>i({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:Q(),value:t.alibaba?.voice??``,onChange:e=>i({voice:e.target.value}),children:f.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:M(Ft(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.minimax?.apiKey??``,onChange:e=>s({apiKey:e.target.value}),placeholder:`eyJ...`}),(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (MINIMAX_API_KEY)`]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:Q(),value:t.minimax?.model??``,onChange:e=>s({model:e.target.value}),children:m.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:Q(),value:t.minimax?.voice??``,onChange:e=>s({voice:e.target.value}),children:h.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:Q(),value:t.edge?.voice??``,onChange:e=>o({voice:e.target.value}),children:p.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]}):null]})]})}function $({children:e}){return(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e})}function Jt(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 Yt(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 P(q(`/api/config`),{method:`PATCH`,body:JSON.stringify({tools:{web:{region:t,search:n}}})}),L()}function Xt(e){return e===`***`||e===`••••••••••••`}function Zt(e){if(!e||typeof e!=`object`||!(`providers`in e))return{};let t=e.providers;if(!t||typeof t!=`object`||Array.isArray(t))return{};let n={};for(let[e,r]of Object.entries(t))typeof r==`string`&&(n[e]=r);return n}function Qt(e,t,n){let r=new Set(n.map(e=>e.provider));return e.map(e=>({...e,configured:e.configured||r.has(e.id),apiKey:t[e.id]||(e.configured||r.has(e.id)?`***`:``)}))}async function $t(e){await P(q(`/api/config`),{method:`PATCH`,body:JSON.stringify({providers:e})}),Promise.all([L(),r(q(`/api/providers/meta`))])}async function en(e){return(await P(q(`/api/models-json/test-api-key`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({value:e})})).payload??{type:`literal`,error:`No response`}}function tn({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 nn(){return M(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,ve,`dark:border-edge`)}function rn(){return M(T,m)}var an=[`brave`,`tavily`,`bing`,`searxng`];function on(){return{type:`brave`,apiKey:``,url:``,disabled:!1}}function sn(){let e=x(e=>e.language),t=c(e),n=t.webSearchSettings,r=t.logs,i=!!ee(e=>e.token),[a,o]=(0,X.useState)(null),[s,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(null),[g,_]=(0,X.useState)(!1),v=(0,X.useRef)(!1),{data:y,error:b,isLoading:S,mutate:C}=de(i),w=(0,X.useMemo)(()=>y?.payload?.config===void 0?null:Jt(y.payload.config),[y]);(0,X.useEffect)(()=>{if(!i){o(null),u(null),v.current=!1;return}w!==null&&(v.current||(o(w),u(w)))},[i,w]);let T=!!(i&&S&&y===void 0&&!b),E=b instanceof Error?b.message:b?String(b):null,D=(0,X.useMemo)(()=>!a||!s?!1:JSON.stringify(a)!==JSON.stringify(s),[a,s]),O=(0,X.useCallback)(e=>{v.current=!0,o(t=>t?{...t,...e}:null)},[]),k=(0,X.useCallback)(async()=>{if(!(!a||d)){f(!0),m(null),_(!1);try{await Yt(a),v.current=!1,_(!0),window.setTimeout(()=>_(!1),2500)}catch(e){m(e instanceof Error?e.message:n.saveError)}finally{f(!1)}}},[a,d,n.saveError]);return i?T?(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)(l,{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:re(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)(h,{className:`size-3.5`})]})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[g?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,Y.jsx)(j,{type:`button`,variant:`primary`,disabled:!D||d,onClick:()=>void k(),children:d?n.saving:n.save})]})]}),D?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,p?(0,Y.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:p}):null,(0,Y.jsxs)(Ce,{children:[(0,Y.jsx)(we,{icon:H,title:n.sectionRegion,subtitle:n.sectionRegionHint}),(0,Y.jsx)(`div`,{className:`flex max-w-md flex-col gap-4`,children:(0,Y.jsx)(tn,{label:n.regionLabel,description:n.regionDesc,children:(0,Y.jsxs)(`select`,{className:rn(),value:a.regionMode,onChange:e=>O({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)(Ce,{children:[(0,Y.jsx)(we,{icon:H,title:n.sectionSearch,subtitle:n.sectionSearchHint}),(0,Y.jsxs)(`div`,{className:`flex max-w-xl flex-col gap-6`,children:[(0,Y.jsx)(tn,{label:n.maxResultsLabel,description:n.maxResultsDesc,children:(0,Y.jsx)(`input`,{type:`number`,min:1,max:50,className:nn(),value:a.maxResults,onChange:e=>O({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)(cn,{row:e,labels:n,onChange:e=>{let n=[...a.providers];n[t]=e,O({providers:n})},onRemove:()=>{O({providers:a.providers.filter((e,n)=>n!==t)})}},t)),(0,Y.jsxs)(j,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5 text-sm`,onClick:()=>O({providers:[...a.providers,on()]}),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:p??E??n.loadError}),(0,Y.jsx)(j,{type:`button`,variant:`secondary`,onClick:()=>void C(),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 cn({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:M(rn(),`min-w-[8rem]`),value:e.type,onChange:t=>n({...e,type:t.target.value,url:t.target.value===`searxng`?e.url:``}),children:an.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)(j,{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)(tn,{label:t.urlLabel,description:t.urlDesc,children:(0,Y.jsx)(`input`,{type:`url`,className:nn(),value:e.url,placeholder:`http://localhost:8080`,onChange:t=>n({...e,url:t.target.value})})}):null,(0,Y.jsx)(tn,{label:t.apiKeyLabel,description:t.apiKeyDesc,children:(0,Y.jsx)(`input`,{type:`password`,autoComplete:`off`,className:nn(),value:Xt(e.apiKey)?``:e.apiKey,placeholder:Xt(e.apiKey)?t.keyPlaceholderMasked:t.keyPlaceholder,onChange:t=>n({...e,apiKey:t.target.value})})})]})}var ln=[{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 un(e,t){let n=c(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 dn(){let e=x(e=>e.language),t=c(e).systemSettings,[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(null),l=typeof window<`u`?window.electronAPI?.system:void 0,u=(0,X.useCallback)(async()=>{if(l){s(null);try{r(await l.getBehavior()),a(await l.getPermissions())}catch(e){s(e instanceof Error?e.message:String(e))}}},[l]);if((0,X.useEffect)(()=>{E()&&l&&u()},[l,u]),!E()||!l)return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.title}),(0,Y.jsxs)(`div`,{className:Se(),children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:t.desktopOnlyTitle}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:t.desktopOnlyBody})]})]});let d=async e=>{try{let{behavior:t}=await l.setBehavior(e);r(t)}catch(e){s(e instanceof Error?e.message:String(e))}},f=async e=>{try{(await l.openPrivacy(e)).ok||s(`open_privacy failed`)}catch(e){s(e instanceof Error?e.message:String(e))}},p=n?n.platform===`win32`?t.permissionsHintWin:n.platform===`linux`?t.permissionsHintLinux:n.platform===`darwin`?t.permissionsHintDarwin:t.permissionsHint:t.permissionsHint;return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.title}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:t.subtitle})]}),o?(0,Y.jsx)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:o}):null,(0,Y.jsxs)(Ce,{children:[(0,Y.jsxs)(`div`,{className:`mb-4 flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)(N,{className:`size-4 text-accent`,strokeWidth:1.75}),t.behaviorGroup]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.openAtLogin}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.openAtLoginDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!n,checked:!!n?.openAtLogin,onChange:e=>{d({openAtLogin:e.target.checked})}})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.keepAwake}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.keepAwakeDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!n,checked:!!n?.keepAwakePreferred,onChange:e=>{d({keepAwakePreferred:e.target.checked})}})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.notifyDesktop}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.notifyDesktopDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!n,checked:!!n?.notifyEnabled,onChange:e=>{d({notifyEnabled:e.target.checked})}})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.notifySound}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.notifySoundDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!n,checked:!!n?.notifySoundEnabled,onChange:e=>{d({notifySoundEnabled:e.target.checked})}})]})]})]}),n&&i?(0,Y.jsxs)(`section`,{className:Se(),children:[(0,Y.jsxs)(`div`,{className:`mb-4 flex flex-col gap-1 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:t.permissionsTitle}),(0,Y.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:p})]}),(0,Y.jsx)(`button`,{type:`button`,className:`mt-2 inline-flex max-w-full items-center justify-center rounded-lg border border-edge bg-surface-panel px-3 py-1.5 text-sm font-medium text-fg transition-colors hover:bg-surface-hover sm:mt-0`,onClick:()=>void u(),children:t.refresh})]}),(0,Y.jsx)(`ul`,{className:`space-y-3`,children:ln.map(({key:r,pane:o})=>{let c=un(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 ${c.className}`,children:c.label})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[r===`microphone`&&n?.platform===`darwin`?(0,Y.jsx)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover`,onClick:()=>{(async()=>{try{await l.requestMicrophone(),a(await l.getPermissions())}catch(e){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 f(o),children:[t.openSettings,(0,Y.jsx)(h,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0})]})]})]},r):null})})]}):null]})}async function fn(e){let t=await B(q(`/api/auth/oauth-async/start`),{method:`POST`,body:JSON.stringify({provider:e})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error||`OAuth start failed: ${t.status}`)}return(await t.json()).payload}async function pn(e){let t=await B(q(`/api/auth/oauth-async/${encodeURIComponent(e)}/status`));if(!t.ok)throw Error(`OAuth status: ${t.status}`);return(await t.json()).payload}async function mn(e,t){let n=await B(q(`/api/auth/oauth-async/${encodeURIComponent(e)}/code`),{method:`POST`,body:JSON.stringify({code:t})});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error||`Submit code failed: ${n.status}`)}}async function hn(e){let t=await B(q(`/api/auth/oauth-async/${encodeURIComponent(e)}/cancel`),{method:`POST`});if(!t.ok)throw Error(`Cancel OAuth failed: ${t.status}`)}async function gn(e){let t=await B(q(`/api/auth/oauth-async/${encodeURIComponent(e)}`),{method:`DELETE`});if(!t.ok)throw Error(`Cleanup session failed: ${t.status}`)}async function _n(e){let t=await B(q(`/api/auth/oauth/${encodeURIComponent(e)}`),{method:`DELETE`});if(!t.ok)throw Error(`Revoke OAuth failed: ${t.status}`)}function vn(e,t){return e===`single`?t.getApiKey:e===`intl`?t.getApiKeyIntl:t.getApiKeyCn}var yn={openai:{apiKeyUrl:`https://platform.openai.com/api-keys`,pricingUrl:`https://openai.com/pricing`,docsUrl:`https://platform.openai.com/docs`,description:`The most widely used LLM provider. Powers ChatGPT.`,descriptionZh:`最广泛使用的 LLM 服务商,ChatGPT 背后的技术。`,bestFor:[`general`,`coding`,`vision`],freeTier:!1,freeTierNote:`Pay-as-you-go; new accounts may receive trial credits.`,aliases:[`chatgpt`,`gpt`,`gpt-4`,`gpt4`,`gpt-4o`,`gpt4o`],envVars:[`OPENAI_API_KEY`]},anthropic:{apiKeyUrl:`https://console.anthropic.com/settings/keys`,pricingUrl:`https://www.anthropic.com/pricing`,docsUrl:`https://docs.anthropic.com`,description:`Known for Claude — excellent at long documents, coding, and nuanced reasoning.`,descriptionZh:`Claude 系列模型,擅长长文档处理、代码和复杂推理。`,bestFor:[`long context`,`coding`,`reasoning`],freeTier:!1,aliases:[`claude`,`claude 3`,`claude sonnet`,`claude opus`,`claude haiku`],envVars:[`ANTHROPIC_OAUTH_TOKEN`,`ANTHROPIC_API_KEY`]},google:{apiKeyUrl:`https://aistudio.google.com/app/apikey`,pricingUrl:`https://ai.google.dev/pricing`,docsUrl:`https://ai.google.dev/docs`,description:`Google Gemini models — strong multimodal and long-context capabilities.`,descriptionZh:`Google Gemini 系列,多模态能力强,支持超长上下文。`,bestFor:[`multimodal`,`long context`,`general`],freeTier:!0,freeTierNote:`Free tier available via Google AI Studio.`,aliases:[`gemini`,`google gemini`,`bard`,`google ai`],envVars:[`GEMINI_API_KEY`,`GOOGLE_API_KEY`]},"google-vertex":{apiKeyUrl:`https://console.cloud.google.com/apis/credentials`,pricingUrl:`https://cloud.google.com/vertex-ai/pricing`,docsUrl:`https://cloud.google.com/vertex-ai/docs`,description:`Google Vertex AI — enterprise-grade Gemini and other models on GCP.`,descriptionZh:`Google Vertex AI,企业级 GCP 托管模型,支持 Gemini 等。`,bestFor:[`enterprise`,`multimodal`,`compliance`],freeTier:!1,aliases:[`vertex`,`vertex ai`,`gcp`,`google cloud`],envVars:[`GOOGLE_CLOUD_PROJECT`,`GOOGLE_CLOUD_LOCATION`]},"google-gemini-cli":{apiKeyUrl:`https://aistudio.google.com/app/apikey`,pricingUrl:`https://ai.google.dev/pricing`,docsUrl:`https://ai.google.dev/docs`,description:`Gemini via CLI token — for users authenticated with the Gemini CLI tool.`,descriptionZh:`通过 Gemini CLI 令牌访问 Gemini,适合已安装 CLI 工具的用户。`,bestFor:[`general`,`multimodal`],freeTier:!0,freeTierNote:`Uses your existing Gemini CLI authentication.`,aliases:[`gemini cli`,`gemini-cli`],envVars:[`GEMINI_CLI_TOKEN`,`GOOGLE_TOKEN`]},"google-antigravity":{apiKeyUrl:`https://console.cloud.google.com/apis/credentials`,pricingUrl:`https://cloud.google.com/pricing`,docsUrl:`https://cloud.google.com/docs`,description:`Google Antigravity — internal/experimental Google AI endpoint.`,descriptionZh:`Google Antigravity,Google 内部/实验性 AI 端点。`,bestFor:[`experimental`],freeTier:!1,aliases:[`antigravity`,`google antigravity`],envVars:[`ANTIGRAVITY_API_KEY`]},groq:{apiKeyUrl:`https://console.groq.com/keys`,pricingUrl:`https://groq.com/pricing/`,docsUrl:`https://console.groq.com/docs`,description:`Extremely fast inference — ideal for latency-sensitive applications.`,descriptionZh:`推理速度极快,适合对延迟敏感的场景。`,bestFor:[`speed`,`cheap`],freeTier:!0,freeTierNote:`Generous free tier with rate limits.`,aliases:[`groq`,`llama on groq`,`mixtral on groq`],envVars:[`GROQ_API_KEY`]},deepseek:{apiKeyUrl:`https://platform.deepseek.com/api_keys`,pricingUrl:`https://api-docs.deepseek.com/quick_start/pricing/`,docsUrl:`https://platform.deepseek.com/api-docs/`,description:`DeepSeek models — OpenAI-compatible API with strong reasoning and low costs.`,descriptionZh:`DeepSeek 模型:OpenAI 兼容 API,推理强、成本低。`,bestFor:[`reasoning`,`cheap`,`coding`],freeTier:!0,freeTierNote:`Free credits may be available for new accounts.`,aliases:[`deepseek`,`deep seek`,`deepseek v4`,`deepseek-v4`,`r1`],envVars:[`DEEPSEEK_API_KEY`]},xai:{apiKeyUrl:`https://console.x.ai/`,pricingUrl:`https://x.ai/api`,docsUrl:`https://docs.x.ai/`,description:`xAI Grok models — real-time web access, strong reasoning.`,descriptionZh:`xAI Grok 系列,支持实时联网,推理能力强。`,bestFor:[`reasoning`,`real-time`],freeTier:!1,aliases:[`grok`,`xai`,`x.ai`],envVars:[`XAI_API_KEY`]},cerebras:{apiKeyUrl:`https://cloud.cerebras.ai/platform/`,pricingUrl:`https://cloud.cerebras.ai/platform/`,docsUrl:`https://inference-docs.cerebras.ai/`,description:`Ultra-fast inference on custom AI chips. Fastest Llama inference available.`,descriptionZh:`基于专用 AI 芯片的超快推理,Llama 推理速度业界最快。`,bestFor:[`speed`],freeTier:!0,freeTierNote:`Free tier available.`,aliases:[`cerebras`],envVars:[`CEREBRAS_API_KEY`]},mistral:{apiKeyUrl:`https://console.mistral.ai/api-keys/`,pricingUrl:`https://mistral.ai/technology/#pricing`,docsUrl:`https://docs.mistral.ai/`,description:`European open-weight models. Good balance of quality and cost.`,descriptionZh:`欧洲开源模型,质量与成本平衡好。`,bestFor:[`general`,`cheap`,`coding`],freeTier:!1,aliases:[`mistral`,`mixtral`,`codestral`],envVars:[`MISTRAL_API_KEY`]},openrouter:{apiKeyUrl:`https://openrouter.ai/keys`,pricingUrl:`https://openrouter.ai/models`,docsUrl:`https://openrouter.ai/docs`,description:`API gateway to 100+ models from many providers with a single key.`,descriptionZh:`统一 API 网关,一个 Key 访问 100+ 模型。`,bestFor:[`general`,`flexibility`],freeTier:!0,freeTierNote:`Some models are free; pay-per-use for others.`,aliases:[`openrouter`,`open router`],envVars:[`OPENROUTER_API_KEY`]},"azure-openai-responses":{apiKeyUrl:`https://portal.azure.com/#view/Microsoft_Azure_ProjectOxford/CognitiveServicesHub/~/OpenAI`,pricingUrl:`https://azure.microsoft.com/en-us/pricing/details/cognitive-services/openai-service/`,docsUrl:`https://learn.microsoft.com/en-us/azure/ai-services/openai/`,description:`OpenAI models hosted on Azure. Enterprise SLA and data residency.`,descriptionZh:`Azure 托管的 OpenAI 模型,企业级 SLA 和数据合规。`,bestFor:[`enterprise`,`compliance`,`coding`],freeTier:!1,aliases:[`azure`,`azure openai`,`aoai`],envVars:[`AZURE_OPENAI_API_KEY`,`AZURE_OPENAI_BASE_URL`]},"amazon-bedrock":{apiKeyUrl:`https://console.aws.amazon.com/iam/home#/security_credentials`,pricingUrl:`https://aws.amazon.com/bedrock/pricing/`,docsUrl:`https://docs.aws.amazon.com/bedrock/`,description:`AWS-hosted models including Claude, Llama, Titan. Enterprise-grade.`,descriptionZh:`AWS 托管模型,包含 Claude、Llama 等,企业级可靠性。`,bestFor:[`enterprise`,`compliance`],freeTier:!1,aliases:[`bedrock`,`aws`,`amazon`],envVars:[`AWS_ACCESS_KEY_ID`,`AWS_SECRET_ACCESS_KEY`,`AWS_REGION`]},minimax:{apiKeyUrl:`https://platform.minimax.io/user-center/basic-information/interface-key`,pricingUrl:`https://platform.minimax.io/docs/guides/models-intro`,docsUrl:`https://platform.minimax.io/docs/guides/quickstart-preparation`,description:`MiniMax — Chinese multimodal model with strong text and audio capabilities.`,descriptionZh:`MiniMax,国产多模态模型,文本和音频能力强。`,bestFor:[`multimodal`,`chinese`],freeTier:!0,freeTierNote:`注册赠送免费额度。`,aliases:[`minimax`,`mini max`,`abab`],envVars:[`MINIMAX_API_KEY`]},"minimax-cn":{apiKeyUrl:`https://platform.minimaxi.com/user-center/basic-information/interface-key`,pricingUrl:`https://platform.minimaxi.com/document/Price`,docsUrl:`https://platform.minimaxi.com/document/Announcement`,description:`MiniMax (China endpoint) — domestic access for Chinese users.`,descriptionZh:`MiniMax 国内端点,国内用户直连访问。`,bestFor:[`multimodal`,`chinese`],freeTier:!0,freeTierNote:`注册赠送免费额度。`,aliases:[`minimax cn`,`minimax china`,`abab`],envVars:[`MINIMAX_CN_API_KEY`,`MINIMAX_API_KEY`]},"kimi-coding":{apiKeyUrl:`https://platform.moonshot.ai/console/api-keys`,apiKeyUrlCn:`https://platform.moonshot.cn/console/api-keys`,pricingUrl:`https://platform.moonshot.ai/docs/pricing/chat`,docsUrl:`https://platform.moonshot.ai/docs`,description:`Kimi Coding — Moonshot model optimized for code generation tasks.`,descriptionZh:`Kimi Coding,Moonshot 专为代码生成优化的模型。`,bestFor:[`coding`,`chinese`],freeTier:!0,freeTierNote:`注册赠送免费额度。`,aliases:[`kimi coding`,`moonshot coding`,`kimi code`],envVars:[`KIMI_API_KEY`,`MOONSHOT_API_KEY`]},huggingface:{apiKeyUrl:`https://huggingface.co/settings/tokens`,pricingUrl:`https://huggingface.co/pricing`,docsUrl:`https://huggingface.co/docs/api-inference/`,description:`Access thousands of open-source models via Hugging Face Inference API.`,descriptionZh:`通过 Hugging Face 访问数千个开源模型。`,bestFor:[`open source`,`flexibility`],freeTier:!0,freeTierNote:`Free tier with rate limits.`,aliases:[`huggingface`,`hugging face`,`hf`],envVars:[`HF_TOKEN`,`HUGGINGFACE_TOKEN`]},opencode:{apiKeyUrl:`https://opencode.ai/auth`,pricingUrl:`https://opencode.ai/docs`,docsUrl:`https://opencode.ai/docs/providers/`,description:`OpenCode — AI coding assistant provider.`,descriptionZh:`OpenCode,AI 代码助手服务商。`,bestFor:[`coding`],freeTier:!1,aliases:[`opencode`,`open code`],envVars:[`OPENCODE_API_KEY`]},"opencode-go":{apiKeyUrl:`https://opencode.ai/auth`,pricingUrl:`https://opencode.ai/docs`,docsUrl:`https://opencode.ai/docs/providers/`,description:`OpenCode Go — AI coding assistant provider (Go variant).`,descriptionZh:`OpenCode Go,AI 代码助手服务商(Go 版本)。`,bestFor:[`coding`],freeTier:!1,aliases:[`opencode go`,`opencode-go`],envVars:[`OPENCODE_API_KEY`]},zai:{apiKeyUrl:`https://z.ai/manage-apikey/apikey-list`,pricingUrl:`https://z.ai/manage-apikey/billing`,docsUrl:`https://docs.z.ai/guides/overview/quick-start`,description:`01.AI Yi models — strong multilingual capabilities.`,descriptionZh:`零一万物 Yi 系列模型,多语言能力强。`,bestFor:[`general`,`chinese`],freeTier:!1,aliases:[`yi`,`01.ai`,`zero one`,`零一万物`],envVars:[`ZAI_API_KEY`]},dashscope:{apiKeyUrl:`https://modelstudio.console.alibabacloud.com/`,apiKeyUrlCn:`https://dashscope.console.aliyun.com/apiKey`,pricingUrl:`https://help.aliyun.com/zh/dashscope/developer-reference/tongyi-thousand-questions-metering-and-billing`,docsUrl:`https://help.aliyun.com/zh/dashscope/`,description:"Alibaba DashScope — image generation, speech, and STT HTTP APIs (service id `dashscope`, not a pi-ai LLM provider).",descriptionZh:`阿里 DashScope:文生图、语音等 HTTP API(服务 id 为 dashscope,非 pi-ai 内置 LLM)。`,bestFor:[`image`,`speech`,`chinese`],freeTier:!0,aliases:[`dash scope`,`alibaba dashscope`],envVars:[`DASHSCOPE_API_KEY`]},"vercel-ai-gateway":{apiKeyUrl:`https://vercel.com/account/tokens`,pricingUrl:`https://vercel.com/pricing`,docsUrl:`https://vercel.com/docs/ai/ai-gateway`,description:`Vercel AI Gateway — route requests to multiple LLM providers via Vercel.`,descriptionZh:`Vercel AI Gateway,通过 Vercel 路由请求到多个 LLM 服务商。`,bestFor:[`flexibility`,`enterprise`],freeTier:!1,aliases:[`vercel gateway`,`vercel ai gateway`],envVars:[`AI_GATEWAY_API_KEY`,`VERCEL_AI_GATEWAY_API_KEY`]},"github-copilot":{apiKeyUrl:`https://github.com/settings/tokens`,pricingUrl:`https://github.com/features/copilot#pricing`,docsUrl:`https://docs.github.com/en/copilot`,description:`GitHub Copilot — use your GitHub token to access Copilot models.`,descriptionZh:`使用 GitHub 令牌访问 Copilot 模型。`,bestFor:[`coding`],freeTier:!0,freeTierNote:`Free for verified students and open-source maintainers.`,aliases:[`github copilot`,`copilot`,`github`],envVars:[`COPILOT_GITHUB_TOKEN`,`GH_TOKEN`,`GITHUB_TOKEN`,`GITHUB_COPILOT_TOKEN`]}};function bn(e,t){let n=yn[e];if(!n)return[];let r=n.apiKeyUrl,i=n.apiKeyUrlCn;return r&&i?t===`zh`?[{href:i,kind:`cn`},{href:r,kind:`intl`}]:[{href:r,kind:`intl`},{href:i,kind:`cn`}]:r?[{href:r,kind:`single`}]:i?[{href:i,kind:`single`}]:[]}function xn({providerId:e,language:t}){let n=yn[e];if(!n)return null;let r=t===`zh`,i=r&&n.descriptionZh?n.descriptionZh:n.description;return i?(0,Y.jsxs)(A,{children:[(0,Y.jsx)(f,{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)(p,{className:`size-3.5`,"aria-hidden":!0})})}),(0,Y.jsx)(s,{children:(0,Y.jsxs)(_e,{side:`right`,align:`start`,sideOffset:6,className:M(`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)(v,{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)(h,{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)(h,{className:`size-3`,"aria-hidden":!0})]}):null]}):null,(0,Y.jsx)(y,{className:`fill-edge`})]})})]}):null}var Sn=[`common`,`specialty`,`enterprise`,`oauth`,`extension`];function Cn(e){let t=new Map;for(let e of Sn)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 wn(e,t){return e.replace(/\{\{(\w+)\}\}/g,(e,n)=>String(t[n]??``))}function Tn(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 En(){let e=x(e=>e.language),t=c(e),n=t.providersSettings,r=!!ee(e=>e.token),[a,o]=(0,X.useState)({}),[s,l]=(0,X.useState)({}),[d,f]=(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)(``),[S,C]=(0,X.useState)(!1),[w,T]=(0,X.useState)(()=>new Set),E=(0,X.useRef)(``),D=q(`/api/providers/meta`),O=(0,X.useCallback)(async e=>(await P(e)).payload?.providers??[],[]),{data:k,error:A,isLoading:N,mutate:F}=de(r),{data:I,error:L,isLoading:R,mutate:z}=i(r?D:null,O,{revalidateOnFocus:!1}),{data:ne,mutate:B}=i(r?`gateway-configured-models`:null,()=>ae(),{revalidateOnFocus:!1}),V=(0,X.useMemo)(()=>!I||k===void 0?null:Qt(I,Zt(k.payload?.config),ne??[]),[I,k,ne]),ie=A instanceof Error?A.message:A?String(A):L instanceof Error?L.message:L?String(L):null,U=!!(r&&V===null&&(N||R)&&!ie),W=(0,X.useMemo)(()=>JSON.stringify(a)!==JSON.stringify(s),[a,s]);(0,X.useEffect)(()=>{if(!W)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[W]),(0,X.useEffect)(()=>{if(!(!r||V===null)&&!W){let e={};for(let t of V)e[t.id]=t.apiKey;o(e),l({...e})}},[r,V,W]);let G=V??[],K=(0,X.useMemo)(()=>{let e=G,t=y.trim().toLowerCase();return t&&(e=e.filter(e=>{let n=yn[e.id]?.aliases??[];return e.id.toLowerCase().includes(t)||e.name.toLowerCase().includes(t)||n.some(e=>e.toLowerCase().includes(t))})),S&&(e=e.filter(e=>!e.configured)),e},[G,y,S]),se=(0,X.useMemo)(()=>Cn(K),[K]);(0,X.useEffect)(()=>{let e=E.current;if(E.current=y,y.trim()){let e=new Set;for(let t of Sn)(se.get(t)??[]).length>0&&e.add(t);v(e);return}e.trim()&&v(new Set([`common`]))},[y,se]);let ce=(0,X.useCallback)(async()=>{if(d)return;let e={};for(let t of Object.keys(a)){let n=a[t]?.trim()??``;!n||Xt(n)||(e[t]=n)}if(Object.keys(e).length===0){l({...a}),g(`noChanges`),window.setTimeout(()=>g(null),2500);return}f(!0),m(null),g(null);try{await $t(e),T(new Set(Object.keys(e)));let t=await B(ae(!0))??ne??[],[n,r]=await Promise.all([F(),z()]),i=Array.isArray(r)?r:I??[],a=n??k;if(a?.payload){let e=Qt(i,Zt(a.payload.config),t),n={};for(let t of e)n[t.id]=t.apiKey;o(n),l({...n})}g(`saved`),window.setTimeout(()=>g(null),2500)}catch(e){m(e instanceof Error?e.message:n.saveError)}finally{f(!1)}},[k,a,I,ne,F,z,B,n.saveError,d]),le=(0,X.useCallback)(()=>{o({...s}),m(null),g(null),T(new Set)},[s]),ue=e=>{v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},fe=(0,X.useCallback)(()=>{F(),z()},[F,z]),pe=!!(y.trim()||S);return r?U?(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})]}):G.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??ie??n.empty})]}),(0,Y.jsx)(j,{type:`button`,variant:`secondary`,onClick:()=>{F(),z()},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)(j,{type:`button`,variant:`secondary`,disabled:!W||d,onClick:le,children:n.discard}),(0,Y.jsx)(j,{type:`button`,variant:`primary`,disabled:!W||d,onClick:()=>void ce(),children:d?n.saving:n.save})]})]}),W?(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:re(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)(he,{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)(H,{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:M(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-10 pr-3 text-sm text-fg placeholder:text-fg-subtle`,ve,`dark:border-edge`),"aria-label":n.searchPlaceholder})]}),(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg-muted`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:S,onChange:e=>C(e.target.checked),className:`size-4 rounded border-edge text-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`}),n.unconfiguredOnly]}),pe?(0,Y.jsx)(j,{type:`button`,variant:`ghost`,className:`h-9 w-fit self-start text-fg-muted`,onClick:()=>{b(``),C(!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,K.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)(j,{type:`button`,variant:`secondary`,className:`mt-4`,onClick:()=>{b(``),C(!1)},children:n.clearFilters})]}):(0,Y.jsx)(`div`,{className:`flex flex-col gap-3`,children:Sn.map(t=>{let r=se.get(t)??[];if(r.length===0)return null;let i=_.has(t),c=r.filter(e=>e.configured).length,l=`providers-cat-${t}`;return(0,Y.jsxs)(`section`,{className:`overflow-hidden rounded-2xl bg-surface-base`,children:[(0,Y.jsxs)(`button`,{type:`button`,id:`${l}-trigger`,"aria-expanded":i,"aria-controls":l,className:`flex w-full items-center justify-between gap-2 border-b border-edge-subtle px-4 py-3 text-left transition-colors hover:bg-surface-hover/60 dark:border-edge-subtle`,onClick:()=>ue(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:[c>0?(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-fg-subtle`,children:[(0,Y.jsx)(oe,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}),wn(n.configuredCount,{count:String(c)})]}):null,(0,Y.jsx)(te,{className:M(`size-4 text-fg-subtle transition-transform`,i&&`rotate-180`),"aria-hidden":!0})]})]}),i?(0,Y.jsx)(`div`,{id:l,role:`region`,"aria-labelledby":`${l}-trigger`,className:`divide-y divide-edge-subtle`,children:r.map(t=>(0,Y.jsx)(`div`,{id:`provider-row-${t.id}`,children:(0,Y.jsx)(On,{row:t,value:a[t.id]??``,rowDirty:(a[t.id]??``)!==(s[t.id]??``),labels:n,language:e,onChange:(e,t)=>o(n=>({...n,[e]:t})),onReload:fe,justSaved:w.has(t.id),availableModels:ne??[]})},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)(u,{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})]})]})})}function Dn({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)(oe,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):(0,Y.jsx)(a,{className:`size-3.5`,"aria-hidden":!0})})]})}function On({row:e,value:t,rowDirty:n,labels:r,language:i,onChange:o,onReload:s,justSaved:c,availableModels:d}){let[f,m]=(0,X.useState)(!1),[g,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(!1),[ee,S]=(0,X.useState)(null),C=Xt(t),w=C&&!g?``:t,T=e.configured&&!C&&!!t,[E,D]=(0,X.useState)(!1),[k,A]=(0,X.useState)(),[N,P]=(0,X.useState)(),[F,I]=(0,X.useState)(),[L,R]=(0,X.useState)(),[z,ne]=(0,X.useState)(),[B,V]=(0,X.useState)(``),[re,H]=(0,X.useState)(!1),[ie,U]=(0,X.useState)(null),[W,G]=(0,X.useState)(null),ae=e.activeKeySource??`none`,K=(0,X.useMemo)(()=>bn(e.id,i),[e.id,i]);(0,X.useEffect)(()=>()=>{k&&gn(k).catch(()=>{})},[k]),(0,X.useEffect)(()=>{if(!k||!E)return;let e=window.setInterval(()=>{(async()=>{try{let t=await pn(k);I(t.message),R(t.authUrl),ne(t.instructions),t.status===`waiting_auth`||t.status===`waiting_code`?P(t.status===`waiting_code`?`waiting_code`:`waiting`):t.status===`completed`?(window.clearInterval(e),D(!1),P(`success`),I(t.message),window.setTimeout(()=>s(),800)):(t.status===`failed`||t.status===`cancelled`)&&(window.clearInterval(e),D(!1),P(`error`),I(t.error||t.message||`OAuth failed`))}catch{}})()},1e3);return()=>window.clearInterval(e)},[k,E,s]);let q=async()=>{D(!0),P(`waiting`),I(r.oauthStarting),A(void 0),R(void 0),ne(void 0);try{A((await fn(e.id)).sessionId)}catch(e){P(`error`),I(e instanceof Error?e.message:`OAuth failed`),D(!1)}},ce=async()=>{if(k){try{await hn(k)}catch{}A(void 0),D(!1),P(`idle`),I(void 0)}},ue=async()=>{if(!(!k||!B.trim()))try{await mn(k,B.trim()),V(``),I(r.oauthProcessingCode)}catch(e){P(`error`),I(e instanceof Error?e.message:`Failed`)}},de=()=>{window.confirm(wn(r.revokeConfirm,{name:e.name}))&&(S(null),_n(e.id).then(()=>s()).catch(e=>S(e instanceof Error?e.message:r.revokeFailed)))},fe=async()=>{if(!(!t||C))try{await navigator.clipboard.writeText(t),x(!0),window.setTimeout(()=>x(!1),2e3)}catch{}},me=async()=>{let e=t.trim();if(!(!e||Xt(e))){H(!0),U(null),G(null);try{let t=await en(e);if(t.error){G(!1),U(`${r.testFailed} ${t.error}`);return}G(!0),t.type===`env`?U(r.testOkEnv):t.type===`command`?U(r.testOkCommand):U(r.testOkLiteral)}catch(e){G(!1),U(e instanceof Error?e.message:r.testFailed)}finally{H(!1)}}},he=n?r.metaWillSave:e.configured?C?`${r.metaMasked} · ${r.runtimeLabelPrefix} ${Tn(r,ae)}`:`${r.runtimeLabelPrefix} ${Tn(r,ae)}`:r.metaNotConfigured,ge=`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)(oe,{className:`size-4 text-emerald-600 dark:text-emerald-400`}):(0,Y.jsx)(u,{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)(xn,{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:he})]}),(0,Y.jsx)(j,{type:`button`,variant:`ghost`,className:`h-9 w-9 shrink-0 p-0`,"aria-expanded":f,"aria-controls":ge,"aria-label":r.expandRowDetails,onClick:()=>m(e=>!e),children:(0,Y.jsx)(te,{className:M(`size-4 transition-transform`,f&&`rotate-180`),"aria-hidden":!0})})]}),f?(0,Y.jsxs)(`div`,{id:ge,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:g||!C?`text`:`password`,className:M(`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`,ve,`dark:border-edge`),value:w,placeholder:C?r.placeholderOverride:e.configured?r.placeholderKeep:r.placeholderKey,disabled:E,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&&!C?(0,Y.jsx)(`button`,{type:`button`,className:M(`rounded p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,J.transition,J.press,J.focusRingPanel),title:b?r.copied:r.copy,"aria-label":b?r.copied:r.copy,onClick:()=>void fe(),children:b?(0,Y.jsx)(oe,{className:`size-4`}):(0,Y.jsx)(a,{className:`size-4`})}):null,(0,Y.jsx)(`button`,{type:`button`,className:M(`rounded p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg disabled:opacity-40`,J.transition,J.press,J.focusRingPanel),title:g?r.hide:r.show,"aria-label":g?r.hide:r.show,disabled:C,onClick:()=>y(e=>!e),children:g?(0,Y.jsx)(se,{className:`size-4`}):(0,Y.jsx)(_,{className:`size-4`})})]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2 sm:shrink-0`,children:[(0,Y.jsxs)(j,{type:`button`,variant:`secondary`,className:`gap-1`,disabled:E||re||!t.trim()||Xt(t),onClick:()=>void me(),children:[re?(0,Y.jsx)(l,{className:`size-4 animate-spin`,"aria-hidden":!0}):null,re?r.testingKey:r.testKey]}),e.supportsOAuth?T?(0,Y.jsxs)(j,{type:`button`,variant:`secondary`,className:`gap-1 text-red-600 dark:text-red-400`,onClick:de,children:[(0,Y.jsx)(pe,{className:`size-4`,"aria-hidden":!0}),r.revoke]}):(0,Y.jsxs)(j,{type:`button`,variant:`secondary`,className:`gap-1`,disabled:E,onClick:()=>void q(),children:[E?(0,Y.jsx)(l,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(O,{className:`size-4`,"aria-hidden":!0}),r.oauth]}):null]})]}),ie?(0,Y.jsx)(`p`,{className:M(`text-xs`,W===!1?`text-red-600 dark:text-red-400`:`text-fg-muted`),role:`status`,children:ie}):null,K.length>0?(0,Y.jsx)(`div`,{className:`flex flex-col gap-1`,children:K.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:[vn(e.kind,r),(0,Y.jsx)(h,{className:`size-3`,"aria-hidden":!0})]},`${e.kind}-${e.href}`))}):null]}),F?(0,Y.jsxs)(`div`,{className:M(`flex gap-2 rounded-md px-3 py-2 text-xs`,N===`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:[N===`error`?(0,Y.jsx)(le,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}):N===`success`?(0,Y.jsx)(oe,{className:`mt-0.5 size-4 shrink-0 text-emerald-600`,"aria-hidden":!0}):(0,Y.jsx)(p,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:F})]}):null,ee?(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)(le,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:ee})]}):null,(N===`waiting`||N===`waiting_code`)&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[L?(0,Y.jsxs)(`a`,{href:L,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)(h,{className:`size-4`,"aria-hidden":!0}),r.openAuthPage]}):null,(0,Y.jsxs)(j,{type:`button`,variant:`secondary`,className:`gap-1`,onClick:()=>void ce(),children:[(0,Y.jsx)(v,{className:`size-4`,"aria-hidden":!0}),r.cancelOAuth]})]}),z?(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)(p,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:z})]}):null,N===`waiting_code`?(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,Y.jsx)(`input`,{type:`text`,className:M(`min-w-0 flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,ve,`dark:border-edge`),value:B,placeholder:r.pasteRedirectUrl,onChange:e=>V(e.target.value),onKeyDown:e=>e.key===`Enter`&&void ue()}),(0,Y.jsx)(j,{type:`button`,variant:`primary`,className:`shrink-0`,onClick:()=>void ue(),children:r.submitCode})]}):null,C?(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)(p,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:ae===`env`?r.envHint:r.maskedStoredHint})]}):null,e.supportsOAuth&&!C&&!T?(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:r.oauthHint}):null,c?(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md bg-surface-hover/60 px-3 py-2 text-xs text-fg-muted dark:bg-surface-hover/40`,children:[(0,Y.jsx)(oe,{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=d.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,(yn[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:(yn[e.id]?.envVars??[]).map(e=>(0,Y.jsx)(Dn,{envVar:e,labels:r},e))})]}):null]}):null]})}var kn=[`appearance`,`system`,`agent-defaults`,`providers`,`models`,`voice`,`gateway`,`heartbeat`,`search`];function An(){let{section:e}=k(),t=x(e=>e.language),n=c(t);if(e===`agent`||e===`agents`)return(0,Y.jsx)(D,{to:`/agents`,replace:!0});if(!e||!kn.includes(e))return(0,Y.jsx)(D,{to:`/settings/appearance`,replace:!0});let r=e,i=n.settingsSections[r];return r===`appearance`?(0,Y.jsx)(Ae,{}):r===`system`?(0,Y.jsx)(dn,{}):r===`agent-defaults`?(0,Y.jsx)(Te,{}):r===`providers`?(0,Y.jsx)(En,{}):r===`models`?(0,Y.jsx)(Tt,{}):r===`voice`?(0,Y.jsx)(Gt,{}):r===`gateway`?(0,Y.jsx)(Fe,{}):r===`heartbeat`?(0,Y.jsx)($e,{}):r===`search`?(0,Y.jsx)(sn,{}):(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{An as SettingsPage};
|
|
2
|
-
//# sourceMappingURL=settings-page-
|
|
1
|
+
import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{i as t,t as n}from"./vendor-react-DbimaAId.js";import{a as r,r as i}from"./vendor-swr-Dp4nzp5h.js";import{$n as a,At as o,B as s,Bt as c,En as l,Fn as u,Gt as d,H as f,In as p,It as m,Jn as h,Jt as g,Kn as _,Kt as v,L as y,Ln as b,Mt as x,Ot as ee,Qn as S,Qt as C,R as w,Rt as T,S as E,Sr as D,Tn as O,Tr as k,V as A,Vt as j,Wt as M,an as N,at as P,dn as F,dr as te,dt as I,et as L,fr as R,ft as z,gn as ne,it as B,jt as V,kt as re,ln as H,lr as ie,lt as U,mn as W,mr as G,nt as ae,or as oe,ot as K,qn as se,rt as q,sn as ce,sr as le,st as ue,tt as de,ut as fe,wn as pe,xn as me,xr as he,y as J,yn as ge,z as _e,zt as ve}from"./index-KGmhufWu.js";import{a as ye,p as be,v as xe}from"./cron-utils-o-QI_XCC.js";import{i as Se,n as Ce,r as we,t as Te}from"./agents-ByiiWRbv.js";var Y=n();function Ee(){return M(`rounded-xl border border-edge-subtle bg-surface-base px-4 py-1 sm:px-5`)}function De({scheme:e}){return e===`emerald`?(0,Y.jsxs)(`div`,{className:`flex h-10 w-full overflow-hidden rounded-md border border-edge-subtle`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-1 flex-col gap-1 bg-[#0a0a0a] p-1.5`,children:[(0,Y.jsx)(`div`,{className:`h-1 w-8 rounded-full bg-[#134e2a]`}),(0,Y.jsx)(`div`,{className:`h-1 w-5 rounded-full bg-[#134e2a]`})]}),(0,Y.jsx)(`div`,{className:`w-1.5 bg-[#10b981]`}),(0,Y.jsxs)(`div`,{className:`flex flex-1 flex-col gap-1 bg-[#000000] p-1.5`,children:[(0,Y.jsx)(`div`,{className:`h-1 w-6 rounded-full bg-[#34d399]`}),(0,Y.jsx)(`div`,{className:`h-1 w-9 rounded-full bg-[#065f46]`}),(0,Y.jsx)(`div`,{className:`h-1 w-4 rounded-full bg-[#065f46]`})]})]}):(0,Y.jsxs)(`div`,{className:`flex h-10 w-full overflow-hidden rounded-md border border-edge-subtle`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-1 flex-col gap-1 bg-[#f5f5f7] p-1.5`,children:[(0,Y.jsx)(`div`,{className:`h-1 w-8 rounded-full bg-[#d2d2d7]`}),(0,Y.jsx)(`div`,{className:`h-1 w-5 rounded-full bg-[#d2d2d7]`})]}),(0,Y.jsx)(`div`,{className:`w-1.5 bg-[#2563eb]`}),(0,Y.jsxs)(`div`,{className:`flex flex-1 flex-col gap-1 bg-[#ffffff] p-1.5`,children:[(0,Y.jsx)(`div`,{className:`h-1 w-6 rounded-full bg-[#1d1d1f]`}),(0,Y.jsx)(`div`,{className:`h-1 w-9 rounded-full bg-[#d2d2d7]`}),(0,Y.jsx)(`div`,{className:`h-1 w-4 rounded-full bg-[#d2d2d7]`})]})]})}var Oe=[{value:`default`,labelKey:`colorSchemeDefault`},{value:`emerald`,labelKey:`colorSchemeLightGreen`}];function ke(){let e=c(x(e=>e.language)).appearanceSettings,t=V(e=>e.colorScheme),n=V(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:Oe.map(({value:r,labelKey:i})=>{let a=t===r;return(0,Y.jsxs)(`button`,{type:`button`,"aria-pressed":a,onClick:()=>n(r),className:M(`flex flex-col gap-2 rounded-xl border-2 p-2.5 text-left transition-[border-color,box-shadow] duration-150`,a?`border-accent shadow-[0_0_0_1px_var(--color-accent)]`:`border-edge-subtle hover:border-edge`),children:[(0,Y.jsx)(De,{scheme:r}),(0,Y.jsx)(`span`,{className:M(`text-xs font-medium leading-none`,a?`text-accent-fg`:`text-fg-muted`),children:e[i]})]},r)})})]})}function Ae(){let e=c(x(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:Ee(),"aria-labelledby":`pref-language-heading`,children:[(0,Y.jsx)(`h2`,{id:`pref-language-heading`,className:`sr-only`,children:e.languageTitle}),(0,Y.jsx)(o,{variant:`page`,sections:[`language`]})]}),(0,Y.jsxs)(`section`,{className:Ee(),"aria-labelledby":`pref-appearance-heading`,children:[(0,Y.jsx)(`h2`,{id:`pref-appearance-heading`,className:`sr-only`,children:e.themeTitle}),(0,Y.jsx)(o,{variant:`page`,sections:[`theme`,`font`]}),(0,Y.jsx)(ke,{})]})]})}var X=e(t(),1);function je(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Me(e){let t=je(e)?e:{},n=je(t.gateway)?t.gateway:{},r=je(n.auth)?n.auth:{},i=r.mode===`none`||r.mode===`token`?r.mode:`token`;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:``}}}async function Ne(e){let t=e.auth.token.trim().length>0?{mode:e.auth.mode,token:e.auth.token}:{mode:e.auth.mode};await P(q(`/api/config`),{method:`PATCH`,body:JSON.stringify({gateway:{auth:t}})}),L()}function Pe(){return M(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,ve,`dark:border-edge`)}function Fe(){let e=x(e=>e.language),t=c(e),n=t.gatewaySettings,r=ee(e=>e.token),i=ee(e=>e.tokenExpired),a=ee(e=>e.openTokenDialog),o=!!r,[s,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(null),[p,m]=(0,X.useState)(!1),[g,_]=(0,X.useState)(null),[v,y]=(0,X.useState)(!1),[b,S]=(0,X.useState)(!1),[C,w]=(0,X.useState)(!1),T=(0,X.useRef)(!1),{data:E,error:D,isLoading:O,mutate:k}=de(o),A=(0,X.useMemo)(()=>E?.payload?.config===void 0?null:structuredClone(Me(E.payload.config)),[E]);(0,X.useEffect)(()=>{if(!o){u(null),f(null),T.current=!1;return}A!==null&&(T.current||(u(A),f(structuredClone(A)),y(!1)))},[o,A]);let M=!!(o&&O&&E===void 0&&!D),N=D instanceof Error?D.message:D?String(D):null,P=(0,X.useMemo)(()=>!s||!d?!1:JSON.stringify(s)!==JSON.stringify(d),[s,d]),F=(0,X.useCallback)(e=>{T.current=!0,u(t=>t?{...t,auth:{...t.auth,...e}}:null)},[]),te=(0,X.useCallback)(async()=>{if(!(!s||p)){m(!0),_(null),y(!1);try{await Ne(s),T.current=!1,f(structuredClone(s)),y(!0),window.setTimeout(()=>y(!1),2500)}catch(e){_(e instanceof Error?e.message:n.saveError)}finally{m(!1)}}},[s,p,n.saveError]),I=(0,X.useCallback)(async()=>{let e=s?.auth.token;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),w(!0),window.setTimeout(()=>w(!1),2e3))},[s?.auth.token]);return o?M?(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)(l,{className:`size-4 animate-spin`}),n.loading]})}):s?(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:re(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)(h,{className:`size-3.5`})]})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[v?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,Y.jsx)(j,{type:`button`,variant:`primary`,disabled:!P||p,onClick:()=>void te(),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)(le,{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)(j,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:()=>a(),children:n.updateToken})})]}):null,P?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,g?(0,Y.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:g}):null,s.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)(ce,{className:`size-4 text-accent`,strokeWidth:1.75}),t.settingsSections.gateway]}),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(s.host||s.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:s.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:s.port==null?`—`:String(s.port)})]}),(0,Y.jsx)(`p`,{className:`sm:col-span-2 text-xs text-fg-subtle`,children:n.listenHint})]}),(0,Y.jsx)(Ie,{g:n,value:s.auth.token,show:b,copied:C,onToggleShow:()=>S(e=>!e),onCopy:()=>void I(),onChange:e=>F({token:e})}),(0,Y.jsx)(j,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,onClick:()=>a(),children:n.changeToken})]})]})]}):(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:g??N??n.loadError}),(0,Y.jsx)(j,{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 Ie({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:M(Pe(),`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)(j,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:o,children:[r?(0,Y.jsx)(R,{className:`size-3.5`}):(0,Y.jsx)(a,{className:`size-3.5`}),r?e.copied:e.copy]}):null,(0,Y.jsxs)(j,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:i,children:[n?(0,Y.jsx)(se,{className:`size-3.5`}):(0,Y.jsx)(_,{className:`size-3.5`}),n?e.hide:e.show]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tokenHelp})]})}function Le(){return q(`/api/channels/status`)}var Re=be;function ze(){return q(`/api/workspace/heartbeat-md`)}async function Be(){let e=await P(ze());return typeof e.payload?.content==`string`?e.payload.content:``}function Ve(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function He(e){let t=Ve(e)?e:{},n=Ve(t.gateway)?t.gateway:{},r=Ve(n.heartbeat)?n.heartbeat:{},i=r.activeHours,a=Ve(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 Ue(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 We(e){await P(q(`/api/config`),{method:`PATCH`,body:JSON.stringify({gateway:{heartbeat:Ue(e)}})}),L()}async function Ge(e){await P(q(`/api/workspace/heartbeat-md`),{method:`PUT`,body:JSON.stringify({content:e})}),r(ze())}async function Ke(e){await P(q(`/api/heartbeat/trigger`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e?{reason:e}:{})})}var qe=[3e4,6e4,3e5,6e5,9e5,18e5,36e5,72e5],Je=new Set(qe);function Ye(){return M(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,ve,`dark:border-edge`)}function Xe(){return M(T,m)}function Ze(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 Qe(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 $e(){let e=x(e=>e.language),t=c(e),n=t.heartbeatSettings,r=!!ee(e=>e.token),[a,o]=(0,X.useState)(null),[s,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(``),[p,m]=(0,X.useState)(``),[g,_]=(0,X.useState)(!1),[v,y]=(0,X.useState)(!1),[S,C]=(0,X.useState)(null),[w,T]=(0,X.useState)(!1),[E,D]=(0,X.useState)(!1),[O,k]=(0,X.useState)(!1),[A,N]=(0,X.useState)(!1),[P,F]=(0,X.useState)(null),[te,I]=(0,X.useState)([]),{data:L,error:R,isLoading:z,mutate:B}=de(r),{data:V,error:H,isLoading:ie,mutate:U}=i(r?ze():null,Be,{revalidateOnFocus:!1}),{data:W=[]}=i(r?Le():null,Re,{revalidateOnFocus:!1}),G=(0,X.useMemo)(()=>Ze(L?.payload?.config),[L]),ae=(0,X.useMemo)(()=>He(L?.payload?.config??{}),[L]),oe=(0,X.useMemo)(()=>!a||!s?!1:JSON.stringify(a)!==JSON.stringify(s),[a,s]),K=(0,X.useMemo)(()=>d!==p,[d,p]);(0,X.useEffect)(()=>{if(!r){o(null),u(null);return}if(L!==void 0&&!oe){let e=structuredClone(ae);o(e),u(e),T(!1)}},[r,L,ae,oe]),(0,X.useEffect)(()=>{!r||V===void 0||K||(f(V),m(V),D(!1))},[r,V,K]);let se=R instanceof Error?R.message:R?String(R):H instanceof Error?H.message:H?String(H):null,q=!!(r&&(L===void 0||V===void 0)&&!se&&(z||ie));(0,X.useEffect)(()=>{if(!r||!a){I([]);return}let e=a.target.trim();if(!e){I([]);return}let t=!1;return xe(e).then(e=>{t||I(e)}),()=>{t=!0}},[r,a?.target]);let ce=(0,X.useCallback)(()=>{let e=a?.target?.trim();e&&xe(e).then(I)},[a?.target]),le=(0,X.useCallback)(async()=>{k(!0),N(!1),F(null);try{await Ke(),N(!0),window.setTimeout(()=>N(!1),3e3)}catch(e){F(e instanceof Error?e.message:n.triggerError)}finally{k(!1)}},[n.triggerError]),ue=(0,X.useCallback)(e=>{o(t=>t?{...t,...e}:null)},[]),fe=(0,X.useCallback)(async()=>{if(!(!a||g)){_(!0),C(null),T(!1);try{await We(a),u(structuredClone(a)),T(!0),window.setTimeout(()=>T(!1),2500)}catch(e){C(e instanceof Error?e.message:n.saveConfigError)}finally{_(!1)}}},[a,g,n.saveConfigError]),pe=(0,X.useCallback)(async()=>{if(!v){y(!0),C(null),D(!1);try{await Ge(d),m(d),D(!0),window.setTimeout(()=>D(!1),2500)}catch(e){C(e instanceof Error?e.message:n.saveDocError)}finally{y(!1)}}},[d,v,n.saveDocError]);return r?q?(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)(l,{className:`size-4 animate-spin`}),n.loading]})}):a?(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Y.jsx)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.heartbeat}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,Y.jsxs)(`a`,{href:re(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)(h,{className:`size-3.5`})]})]})}),G?(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.workspaceLabel,`: `,(0,Y.jsx)(`span`,{className:`font-mono text-fg-muted`,children:G})]}):null,S?(0,Y.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:S}):null,(0,Y.jsxs)(Ce,{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)(b,{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)(j,{type:`button`,variant:`secondary`,className:`inline-flex items-center gap-2`,disabled:O,onClick:()=>void le(),children:[O?(0,Y.jsx)(l,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(ne,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),O?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}),P?(0,Y.jsx)(`p`,{className:`mb-3 text-sm text-red-600 dark:text-red-400`,children:P}):null,(0,Y.jsx)(et,{h:n,cron:t.cron,form:a,channels:W,sessionChatIds:te,onRefreshChatIds:ce,update:ue,inputClassName:Ye,selectClassName:Xe}),(0,Y.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-2`,children:[w?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.savedConfig}):null,(0,Y.jsx)(j,{type:`button`,variant:`primary`,disabled:!oe||g,onClick:()=>void fe(),children:g?n.savingConfig:n.saveConfig}),oe?(0,Y.jsx)(`span`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedConfig}):null]})]}),(0,Y.jsxs)(Ce,{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:M(Ye(),`min-h-[12rem] resize-y font-mono text-xs leading-relaxed`),value:d,onChange:e=>f(e.target.value),spellCheck:!1,"aria-label":n.docSection}),(0,Y.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-2`,children:[E?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.savedDoc}):null,(0,Y.jsx)(j,{type:`button`,variant:`primary`,disabled:!K||v,onClick:()=>void pe(),children:v?n.savingDoc:n.saveDoc}),K?(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:S??se??n.loadError}),(0,Y.jsx)(j,{type:`button`,variant:`secondary`,onClick:()=>{B(),U()},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 et({h:e,cron:t,form:n,channels:r,sessionChatIds:i,onRefreshChatIds:a,update:o,inputClassName:s,selectClassName:c}){let l=(0,X.useMemo)(()=>new Set(r.map(e=>e.name)),[r]),u=n.target.trim(),d=!!(u&&!l.has(u)),f=(0,X.useMemo)(()=>Je.has(n.intervalMs)?String(n.intervalMs):``,[n.intervalMs]),[p,m]=(0,X.useState)(null),h=Math.max(1,Math.round(n.intervalMs/1e3)),g=p===null?String(h):p;return(0,X.useEffect)(()=>{m(null)},[n.intervalMs]),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:n.enabled,onChange:e=>o({enabled:e.target.checked})}),e.enable]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.interval}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:e.intervalSecondsLabel}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`input`,{type:`number`,min:1,step:1,className:M(s(),`min-w-0 flex-1`),value:g,onChange:e=>{let t=e.target.value;m(t);let n=parseInt(t,10);Number.isFinite(n)&&n>=1&&o({intervalMs:n*1e3})},onBlur:()=>{if(p===null)return;let e=parseInt(p,10);o(!Number.isFinite(e)||e<1?{intervalMs:1e3}:{intervalMs:e*1e3}),m(null)}}),(0,Y.jsxs)(`select`,{className:M(c(),`max-w-[11rem] shrink-0 text-xs`),value:f,onChange:e=>{let t=e.target.value;t&&(o({intervalMs:parseInt(t,10)}),m(null))},children:[(0,Y.jsx)(`option`,{value:``,children:e.intervalPresets.custom}),qe.map(t=>(0,Y.jsx)(`option`,{value:String(t),children:Qe(t,e.intervalPresets)},t))]})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.intervalHintPreset}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.intervalHint})]}),(0,Y.jsxs)(`div`,{className:`border-t border-edge-subtle pt-4`,children:[(0,Y.jsx)(`div`,{className:`mb-2 text-sm font-medium text-fg`,children:e.deliveryTitle}),(0,Y.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:t.channel}),(0,Y.jsxs)(`select`,{className:c(),value:u,onChange:e=>{o({target:e.target.value.trim(),targetChatId:``})},children:[(0,Y.jsx)(`option`,{value:``,children:e.channelNone}),d?(0,Y.jsxs)(`option`,{value:u,children:[u,` (`,e.customChannelSuffix,`)`]}):null,r.map(e=>(0,Y.jsxs)(`option`,{value:e.name,disabled:!e.enabled,children:[e.name,` `,e.enabled?``:`(disabled)`]},e.name))]})]}),u?(0,Y.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:t.recipient}),(0,Y.jsxs)(j,{type:`button`,variant:`ghost`,className:`h-7 gap-1 px-2 text-xs`,title:t.refreshRecipientHint,onClick:a,children:[(0,Y.jsx)(F,{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:M(s(),`min-w-0 flex-1`),value:n.targetChatId,onChange:e=>o({targetChatId:e.target.value}),placeholder:t.recipientPlaceholder,autoComplete:`off`}),(0,Y.jsxs)(`select`,{className:M(c(),`max-w-[10rem] shrink-0 text-xs`),value:n.targetChatId,onChange:e=>{let t=e.target.value;t&&o({targetChatId:t})},children:[(0,Y.jsx)(`option`,{value:``,children:t.selectRecipient}),i.length>0?i.map(e=>(0,Y.jsx)(`option`,{value:e.chatId,children:ye(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:M(s(),`min-h-[4.5rem] resize-y font-mono text-xs`),value:n.prompt,onChange:e=>o({prompt:e.target.value}),placeholder:e.promptPlaceholder}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:e.promptHint})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:e.ackMaxChars}),(0,Y.jsx)(`input`,{type:`number`,min:1,className:s(),value:n.ackMaxChars===``?``:n.ackMaxChars,onChange:e=>{let t=e.target.value;if(t===``)o({ackMaxChars:``});else{let e=parseInt(t,10);o({ackMaxChars:Number.isFinite(e)?e:``})}},placeholder:e.ackDefaultPlaceholder}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:e.ackMaxCharsHint})]}),(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:n.isolatedSession,onChange:e=>o({isolatedSession:e.target.checked})}),(0,Y.jsxs)(`span`,{children:[e.isolatedSession,(0,Y.jsx)(`span`,{className:`mt-1 block text-xs text-fg-subtle`,children:e.isolatedSessionHint})]})]}),(0,Y.jsxs)(`div`,{className:`border-t border-edge-subtle pt-4`,children:[(0,Y.jsx)(`div`,{className:`mb-2 text-sm font-medium text-fg`,children:e.activeHoursTitle}),n.activeHours?(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-xs text-fg`,children:e.activeStart}),(0,Y.jsx)(`input`,{className:s(),value:n.activeHours.start,onChange:e=>o({activeHours:{...n.activeHours,start:e.target.value}}),placeholder:`09:00`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-xs text-fg`,children:e.activeEnd}),(0,Y.jsx)(`input`,{className:s(),value:n.activeHours.end,onChange:e=>o({activeHours:{...n.activeHours,end:e.target.value}}),placeholder:`22:00`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-xs text-fg`,children:e.activeTimezone}),(0,Y.jsx)(`input`,{className:s(),value:n.activeHours.timezone,onChange:e=>o({activeHours:{...n.activeHours,timezone:e.target.value}}),placeholder:`Asia/Shanghai`})]})]}):(0,Y.jsx)(j,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:()=>o({activeHours:{start:`09:00`,end:`22:00`,timezone:``}}),children:e.addActiveHours}),n.activeHours?(0,Y.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:(0,Y.jsx)(j,{type:`button`,variant:`secondary`,className:`text-xs`,onClick:()=>o({activeHours:null}),children:e.clearActiveHours})}):null,(0,Y.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:e.activeHoursHint})]})]})}var tt=[{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 nt(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 rt(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 it(){let e=await B(q(`/api/models-json`)),t=await e.json().catch(()=>({}));if(!e.ok||!t.ok||!t.payload)throw Error(nt(t)||`HTTP ${e.status}`);return{...t.payload,config:rt(t.payload.config)}}async function at(e){let t=await B(q(`/api/models-json/validate`),{method:`POST`,body:JSON.stringify({config:e})}),n=await t.json().catch(()=>({}));if(!t.ok||!n.ok||!n.payload)throw Error(nt(n)||`HTTP ${t.status}`);return n.payload}async function ot(e){let t=await B(q(`/api/models-json`),{method:`PATCH`,body:JSON.stringify({config:e})}),n=await t.json().catch(()=>({}));if(!t.ok||!n.ok||!n.payload)throw Error(nt(n)||`HTTP ${t.status}`);return n.payload}async function st(){let e=await B(q(`/api/models-json/reload`),{method:`POST`}),t=await e.json().catch(()=>({}));if(!e.ok||!t.ok||!t.payload)throw Error(nt(t)||`HTTP ${e.status}`);return t.payload}async function ct(e){let t=await B(q(`/api/models-json/test-api-key`),{method:`POST`,body:JSON.stringify({value:e})}),n=await t.json().catch(()=>({}));if(!t.ok||!n.ok||!n.payload)throw Error(nt(n)||`HTTP ${t.status}`);return n.payload}function lt(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 ut(e){return e.startsWith(`!`)}function dt(e){return/^[A-Z][A-Z0-9_]*$/.test(e)}function ft(e){return ut(e)?`shell`:dt(e)?`env`:`literal`}function pt(e){return e?e.length<=8?`••••`:`${e.slice(0,4)}••••${e.slice(-4)}`:``}var mt={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 ht(e){return e===`openrouter`?`openrouter`:e===`zhipuCn`?`zhipu-cn`:e===`zaiGeneral`?`zai`:e}var gt=[{value:`text`,labelKey:`inputTextOnly`},{value:`text,image`,labelKey:`inputTextVision`}];function Z(){return M(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,ve,`dark:border-edge`)}function _t(){return M(T,m)}function vt(e){return(e.input||[`text`]).includes(`image`)?`text,image`:`text`}function yt(e){return e===`text,image`?[`text`,`image`]:[`text`]}function bt(e,t,n){return{...e,providers:{...e.providers,[t]:{...e.providers[t],...n}}}}function xt(e,t){let n={...e.providers};return delete n[t],{...e,providers:n}}function St(e,t,n){return{...e,providers:{...e.providers,[t]:n}}}function Ct({open:e,onOpenChange:t,presetKey:n,onConfirm:r,m:i}){let[a,o]=(0,X.useState)(``),[s,c]=(0,X.useState)(`custom`),[l,u]=(0,X.useState)(``),[d,f]=(0,X.useState)(`openai-completions`),[p,m]=(0,X.useState)(``),[h,g]=(0,X.useState)(null);(0,X.useEffect)(()=>{if(!e)return;g(null);let t=n||null;if(t&&mt[t]){let e=mt[t];c(t),u(e.baseUrl||``),f(e.api||`openai-completions`),m(e.apiKey??``),o(ht(t))}else c(`custom`),o(``),u(``),f(`openai-completions`),m(``)},[e,n]);let _=e=>{if(c(e),e===`custom`)return;let t=mt[e];t&&(u(t.baseUrl||``),f(t.api||`openai-completions`),m(t.apiKey??``),o(ht(e)))};return(0,Y.jsx)(I,{open:e,onOpenChange:t,children:(0,Y.jsxs)(fe,{children:[(0,Y.jsx)(U,{className:`xopc-dialog-overlay fixed inset-0 z-50 bg-scrim`}),(0,Y.jsxs)(ue,{className:M(`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)(z,{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)(K,{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)(v,{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:_t(),value:s,onChange:e=>_(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:Z(),value:a,onChange:e=>o(e.target.value),placeholder:i.providerIdPlaceholder})]}),(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:i.baseUrl}),(0,Y.jsx)(`input`,{className:Z(),value:l,onChange:e=>u(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:_t(),value:d,onChange:e=>f(e.target.value),children:tt.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:Z(),value:p,onChange:e=>m(e.target.value),placeholder:i.apiKeyPlaceholder})]}),h?(0,Y.jsxs)(`p`,{className:`flex items-center gap-1 text-xs text-red-600 dark:text-red-400`,children:[(0,Y.jsx)(le,{className:`size-3.5 shrink-0`}),h]}):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)(K,{asChild:!0,children:(0,Y.jsx)(j,{type:`button`,variant:`secondary`,children:i.cancel})}),(0,Y.jsx)(j,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:()=>{let e=a.trim();if(!e){g(i.providerIdRequired);return}g(null),r(e,{baseUrl:l.trim()||void 0,api:d,apiKey:p.trim()||void 0,models:[]}),t(!1)},children:i.addProviderConfirm})]})]})]})})}function wt({open:e,onOpenChange:t,providerId:n,model:r,isNew:i,onSave:a,m:o}){let[s,c]=(0,X.useState)(()=>lt(``)),[l,u]=(0,X.useState)(()=>new Map);(0,X.useEffect)(()=>{e&&(u(new Map),c(r?{...r}:lt(``)))},[e,r]);let d=(e,t)=>{c(n=>({...n,[e]:t})),u(t=>{let n=new Map(t);return n.delete(e),n})},f=()=>{let e=new Map;return(s.id||``).trim()||e.set(`id`,o.modelIdRequired),s.contextWindow!==void 0&&s.contextWindow<=0&&e.set(`contextWindow`,o.mustBePositive),s.maxTokens!==void 0&&s.maxTokens<=0&&e.set(`maxTokens`,o.mustBePositive),u(e),e.size===0},p=()=>{if(!f())return;let e=(s.id||``).trim();a({...s,id:e,name:s.name?.trim()||e,reasoning:s.reasoning||!1,input:s.input||[`text`],contextWindow:s.contextWindow??128e3,maxTokens:s.maxTokens??16384,cost:{input:s.cost?.input??0,output:s.cost?.output??0,cacheRead:s.cost?.cacheRead??0,cacheWrite:s.cost?.cacheWrite??0}}),t(!1)},m=vt(s);return(0,Y.jsx)(I,{open:e,onOpenChange:t,children:(0,Y.jsxs)(fe,{children:[(0,Y.jsx)(U,{className:`xopc-dialog-overlay fixed inset-0 z-50 bg-scrim`}),(0,Y.jsxs)(ue,{className:M(`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)(z,{className:`text-base font-semibold text-fg`,children:i?o.addModelTitle:o.editModelTitle}),n?(0,Y.jsxs)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:[o.modelProviderLabel,`: `,n]}):null]}),(0,Y.jsx)(K,{asChild:!0,children:(0,Y.jsx)(`button`,{type:`button`,className:`rounded-lg p-1.5 text-fg-muted hover:bg-surface-base hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,"aria-label":o.close,children:(0,Y.jsx)(v,{className:`size-4`})})})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsxs)(`label`,{className:`mb-1 block text-xs font-medium text-fg`,children:[o.modelId,(0,Y.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,Y.jsx)(`input`,{className:M(Z(),l.has(`id`)&&`border-red-500`),value:s.id||``,onChange:e=>d(`id`,e.target.value),placeholder:`e.g. llama3.1:8b`,disabled:!i}),l.has(`id`)?(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:l.get(`id`)}):null]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:o.displayName}),(0,Y.jsx)(`input`,{className:Z(),value:s.name||``,onChange:e=>d(`name`,e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:o.inputTypes}),(0,Y.jsx)(`select`,{className:_t(),value:m,onChange:e=>d(`input`,yt(e.target.value)),children:gt.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:o[e.labelKey]},e.value))})]}),(0,Y.jsxs)(`label`,{className:`mt-6 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:s.reasoning||!1,onChange:e=>d(`reasoning`,e.target.checked)}),o.reasoning]})]}),(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:o.contextWindow}),(0,Y.jsx)(`input`,{type:`number`,min:1,className:M(Z(),l.has(`contextWindow`)&&`border-red-500`),value:s.contextWindow??128e3,onChange:e=>d(`contextWindow`,parseInt(e.target.value,10)||0)}),l.has(`contextWindow`)?(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:l.get(`contextWindow`)}):null]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:o.maxOutputTokens}),(0,Y.jsx)(`input`,{type:`number`,min:1,className:M(Z(),l.has(`maxTokens`)&&`border-red-500`),value:s.maxTokens??16384,onChange:e=>d(`maxTokens`,parseInt(e.target.value,10)||0)}),l.has(`maxTokens`)?(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:l.get(`maxTokens`)}):null]})]}),(0,Y.jsxs)(`div`,{className:`border-t border-edge-subtle pt-2 dark:border-edge`,children:[(0,Y.jsx)(`p`,{className:`mb-2 text-xs font-semibold text-fg`,children:o.costSection}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:o.costInput}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,min:0,className:Z(),value:s.cost?.input??0,onChange:e=>d(`cost`,{...s.cost,input:parseFloat(e.target.value)||0,output:s.cost?.output??0,cacheRead:s.cost?.cacheRead??0,cacheWrite:s.cost?.cacheWrite??0})})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:o.costOutput}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,min:0,className:Z(),value:s.cost?.output??0,onChange:e=>d(`cost`,{...s.cost,input:s.cost?.input??0,output:parseFloat(e.target.value)||0,cacheRead:s.cost?.cacheRead??0,cacheWrite:s.cost?.cacheWrite??0})})]})]})]})]}),(0,Y.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2 border-t border-edge-subtle pt-3 dark:border-edge`,children:[(0,Y.jsx)(K,{asChild:!0,children:(0,Y.jsx)(j,{type:`button`,variant:`secondary`,children:o.cancel})}),(0,Y.jsx)(j,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:p,children:i?o.addModelConfirm:o.saveModelConfirm})]})]})]})})}function Tt(){let e=x(e=>e.language),t=c(e),n=t.modelsSettings,r=!!ee(e=>e.token),[i,a]=(0,X.useState)({providers:{}}),[o,s]=(0,X.useState)({providers:{}}),[u,f]=(0,X.useState)(``),[p,m]=(0,X.useState)(),[g,v]=(0,X.useState)(!0),[y,b]=(0,X.useState)(!1),[w,T]=(0,X.useState)(!1),[E,D]=(0,X.useState)(!1),[O,k]=(0,X.useState)(null),[A,N]=(0,X.useState)(!1),[P,I]=(0,X.useState)(null),[L,R]=(0,X.useState)(()=>new Set),[z,ne]=(0,X.useState)(!1),[B,V]=(0,X.useState)(``),[H,U]=(0,X.useState)(null),[ae,oe]=(0,X.useState)(()=>new Set),[K,q]=(0,X.useState)(()=>new Map),[ce,ue]=(0,X.useState)(!1),[de,fe]=(0,X.useState)(null),[pe,me]=(0,X.useState)(!1),[he,_e]=(0,X.useState)(null),ve=(0,X.useCallback)(async e=>{let t=!e?.skipFullPageLoading;t&&v(!0),k(null);try{let e=await it(),t=rt(e.config);a(t),s(structuredClone(t)),f(e.path),m(e.loadError),I(null),N(!1)}catch(e){k(e instanceof Error?e.message:n.loadError),a({providers:{}}),s({providers:{}})}finally{t&&v(!1)}},[n.loadError]);(0,X.useEffect)(()=>{if(!r){v(!1);return}ve()},[r,ve]);let ye=(0,X.useMemo)(()=>JSON.stringify(i)!==JSON.stringify(o),[i,o]),be=(0,X.useMemo)(()=>{let e=Object.keys(i.providers),t=0;for(let e of Object.values(i.providers))t+=e.models?.length??0;return{providers:e.length,models:t}},[i.providers]),xe=e=>{R(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Se=e=>{oe(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},Ce=(0,X.useCallback)(()=>{V(JSON.stringify(i,null,2)),U(null)},[i]);(0,X.useEffect)(()=>{z&&Ce()},[z,Ce]);let we=()=>{try{a(rt(JSON.parse(B))),U(null)}catch{U(n.jsonParseError)}},Te=async()=>{T(!0),k(null);try{I(await at(i))}catch(e){k(e instanceof Error?e.message:n.validateError)}finally{T(!1)}},Ee=async()=>{if(!y){b(!0),k(null),N(!1);try{await ot(i),s(structuredClone(i)),N(!0),I(null)}catch(e){k(e instanceof Error?e.message:n.saveError)}finally{b(!1)}}},De=async()=>{D(!0),k(null);try{await st(),await ve({skipFullPageLoading:!0})}catch(e){k(e instanceof Error?e.message:n.reloadError)}finally{D(!1)}},Oe=async(e,t)=>{try{let n=await ct(t);q(t=>{let r=new Map(t);return r.set(e,n),r})}catch(t){q(n=>{let r=new Map(n);return r.set(e,{type:`error`,error:t instanceof Error?t.message:`Error`}),r})}},ke=(e=null)=>{fe(e),ue(!0)},Ae=(e,t)=>{a(n=>St(n,e,t)),R(t=>new Set(t).add(e))},je=e=>{window.confirm(n.removeProviderConfirm.replace(`{{id}}`,e))&&(a(t=>xt(t,e)),q(t=>{let n=new Map(t);return n.delete(e),n}))},Me=(e,t,n)=>{_e({providerId:e,model:t,isNew:n}),me(!0)};return r?(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:re(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)(h,{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)(le,{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)(j,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:()=>ke(null),disabled:g,children:[(0,Y.jsx)(W,{className:`mr-1 size-4`}),n.addProvider]}),(0,Y.jsx)(j,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:Te,disabled:g||w,children:w?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(l,{className:`mr-1 size-4 animate-spin`}),n.validating]}):n.validate}),(0,Y.jsx)(j,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:Ee,disabled:g||y||!ye,children:y?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(l,{className:`mr-1 size-4 animate-spin`}),n.saving]}):n.save}),(0,Y.jsx)(j,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[8.5rem] justify-center`,onClick:De,disabled:g||E,children:E?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(l,{className:`mr-1 size-4 animate-spin`}),n.reloading]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(F,{className:`mr-1 size-4`}),n.reload]})}),(0,Y.jsx)(j,{type:`button`,variant:`ghost`,className:`text-fg-muted`,onClick:()=>{ne(e=>!e),U(null)},children:z?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(be.providers))}),(0,Y.jsx)(`span`,{className:`text-fg-subtle`,children:`|`}),(0,Y.jsx)(`span`,{className:`text-fg-muted`,children:n.statsModels.replace(`{{count}}`,String(be.models))})]})]}),ye?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,A?(0,Y.jsx)(`p`,{className:`text-xs text-emerald-700 dark:text-emerald-400`,role:`status`,children:n.saved}):null,O?(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)(le,{className:`size-4 shrink-0`}),O]}):null,P&&P.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:P.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:P.errors.map((e,t)=>(0,Y.jsxs)(`li`,{children:[e.path,`: `,e.message,` (`,e.severity,`)`]},`${e.path}-${t}`))})]}):null,g?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,Y.jsx)(l,{className:`size-4 animate-spin`}),n.loading]}):z?(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(`textarea`,{className:M(Z(),`min-h-[320px] resize-y font-mono text-xs leading-relaxed`),value:B,onChange:e=>V(e.target.value),spellCheck:!1}),H?(0,Y.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:H}):null,(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(j,{type:`button`,variant:`secondary`,onClick:Ce,children:n.jsonReset}),(0,Y.jsx)(j,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:we,children:n.jsonApply})]})]}):Object.keys(i.providers).length===0?(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)(S,{className:`size-7 text-accent`,strokeWidth:1.5})}),(0,Y.jsx)(`h2`,{className:`mb-1 text-base font-semibold text-fg`,children:n.emptyTitle}),(0,Y.jsx)(`p`,{className:`mb-6 max-w-md text-sm text-fg-muted`,children:n.emptyDesc}),(0,Y.jsxs)(j,{type:`button`,className:`mb-6 bg-accent text-white hover:bg-accent/90`,onClick:()=>ke(null),children:[(0,Y.jsx)(W,{className:`mr-1 size-4`}),n.emptyCta]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap justify-center gap-2`,children:[(0,Y.jsxs)(`button`,{type:`button`,className:M(`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`,J.transition,J.focusRingBase),onClick:()=>ke(`ollama`),children:[(0,Y.jsx)(d,{className:`size-3.5`,"aria-hidden":!0}),n.presetOllama]}),(0,Y.jsxs)(`button`,{type:`button`,className:M(`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`,J.transition,J.focusRingBase),onClick:()=>ke(`openrouter`),children:[(0,Y.jsx)(G,{className:`size-3.5`,"aria-hidden":!0}),n.presetOpenRouter]}),(0,Y.jsxs)(`button`,{type:`button`,className:M(`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`,J.transition,J.focusRingBase),onClick:()=>ke(`lmstudio`),children:[(0,Y.jsx)(S,{className:`size-3.5`,"aria-hidden":!0}),n.presetLmStudio]}),(0,Y.jsxs)(`button`,{type:`button`,className:M(`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`,J.transition,J.focusRingBase),onClick:()=>ke(`zhipuCn`),children:[(0,Y.jsx)(d,{className:`size-3.5`,"aria-hidden":!0}),n.presetZhipuCn]}),(0,Y.jsxs)(`button`,{type:`button`,className:M(`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`,J.transition,J.focusRingBase),onClick:()=>ke(`zaiGeneral`),children:[(0,Y.jsx)(G,{className:`size-3.5`,"aria-hidden":!0}),n.presetZaiGeneral]})]})]}):(0,Y.jsx)(`div`,{className:`flex flex-col gap-3`,children:Object.entries(i.providers).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>{let r=L.has(e),i=t.models?.length??0,o=t.apiKey?ft(t.apiKey):null,s=K.get(e),c=ae.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:()=>xe(e),children:[r?(0,Y.jsx)(te,{className:`size-4 shrink-0 text-fg-muted`}):(0,Y.jsx)(ie,{className:`size-4 shrink-0 text-fg-muted`}),(0,Y.jsx)(`span`,{className:`truncate`,children:e}),i>0?(0,Y.jsx)(`span`,{className:`shrink-0 rounded-full bg-accent px-2 py-0.5 text-[10px] font-medium text-white`,children:i}):null,o?(0,Y.jsx)(`span`,{className:M(`shrink-0 rounded-full px-2 py-0.5 text-[10px] font-medium`,o===`shell`&&`bg-blue-100 text-blue-800 dark:bg-blue-950 dark:text-blue-200`,o===`env`&&`bg-emerald-100 text-emerald-800 dark:bg-emerald-950 dark:text-emerald-200`,o===`literal`&&`bg-surface-hover text-fg-muted dark:bg-surface-active`),children:o===`shell`?n.badgeShell:o===`env`?n.badgeEnv:n.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:()=>je(e),"aria-label":n.removeProvider,children:(0,Y.jsx)(C,{className:`size-4`})})]}),r?(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:n.baseUrl}),(0,Y.jsx)(`input`,{className:Z(),value:t.baseUrl||``,onChange:t=>a(n=>bt(n,e,{baseUrl:t.target.value}))})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:n.apiType}),(0,Y.jsx)(`select`,{className:_t(),value:t.api||`openai-completions`,onChange:t=>a(n=>bt(n,e,{api:t.target.value})),children:tt.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:n.apiKey}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Y.jsx)(`input`,{className:M(Z(),`min-w-0 flex-1`),type:c?`text`:`password`,autoComplete:`off`,value:t.apiKey||``,onChange:t=>{let n=t.target.value;a(t=>bt(t,e,{apiKey:n})),q(t=>{let n=new Map(t);return n.delete(e),n})},placeholder:n.apiKeyPlaceholder}),(0,Y.jsx)(j,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>Se(e),children:c?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(se,{className:`mr-1 size-3.5`}),n.hide]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(_,{className:`mr-1 size-3.5`}),n.show]})}),(0,Y.jsx)(j,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>Oe(e,t.apiKey||``),children:n.testKey})]}),s?(0,Y.jsx)(`p`,{className:M(`mt-1 text-xs`,s.error?`text-red-600 dark:text-red-400`:`text-emerald-700 dark:text-emerald-400`),children:s.error?`${n.testError}: ${s.error}`:`${n.testOk} (${s.type}): ${pt(s.resolved||``)}`}):null,(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:n.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:t.authHeader||!1,onChange:t=>a(n=>bt(n,e,{authHeader:t.target.checked}))}),n.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:n.modelsSection}),(0,Y.jsxs)(j,{type:`button`,variant:`primary`,className:`px-2 py-1 text-xs`,onClick:()=>Me(e,null,!0),children:[(0,Y.jsx)(W,{className:`mr-1 size-3.5`}),n.addModel]})]}),(t.models||[]).length===0?(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.modelsEmpty}):(0,Y.jsx)(`ul`,{className:`space-y-2`,children:(t.models||[]).map(t=>(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:t.id}),t.name&&t.name!==t.id?(0,Y.jsx)(`div`,{className:`truncate text-xs text-fg-muted`,children:t.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:()=>Me(e,t,!1),"aria-label":n.editModel,children:(0,Y.jsx)(ge,{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(n.removeModelConfirm.replace(`{{id}}`,t.id))&&a(n=>{let r=n.providers[e];return r?bt(n,e,{models:(r.models||[]).filter(e=>e.id!==t.id)}):n})},"aria-label":n.removeModel,children:(0,Y.jsx)(C,{className:`size-4`})})]})]},t.id))})]})]}):null]},e)})}),(0,Y.jsx)(Ct,{open:ce,onOpenChange:ue,presetKey:de,onConfirm:Ae,m:n}),(0,Y.jsx)(wt,{open:pe,onOpenChange:e=>{me(e),e||_e(null)},providerId:he?.providerId??null,model:he?.model??null,isNew:he?.isNew??!1,onSave:e=>{if(!he)return;let{providerId:t,isNew:n}=he;a(r=>{let i=r.providers[t];if(!i)return r;let a=i.models||[];return n?bt(r,t,{models:[...a,e]}):bt(r,t,{models:a.map(t=>t.id===e.id?e:t)})})},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})]})}function Et(){return{enabled:!1,provider:`alibaba`,alibaba:{model:`paraformer-v2`},openai:{model:`whisper-1`},fallback:{enabled:!0,order:[`alibaba`,`openai`]}}}function Dt(){return{enabled:!1,provider:`openai`,trigger:`always`,maxTextLength:4096,timeoutMs:3e4,alibaba:{model:`qwen-tts`,voice:`Cherry`},openai:{model:`tts-1`,voice:`alloy`},edge:{voice:`zh-CN-XiaoxiaoNeural`},minimax:{model:`speech-2.8-hd`,voice:`male-qn-qingse`}}}function Ot(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function kt(e){let t=Et();if(!Ot(e))return t;let n=e.provider===`openai`?`openai`:`alibaba`,r=Ot(e.alibaba)?{...t.alibaba,...e.alibaba}:t.alibaba,i=Ot(e.openai)?{...t.openai,...e.openai}:t.openai,a=t.fallback??{enabled:!0,order:[`alibaba`,`openai`]};if(Ot(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 At(e){return e===`openai`||e===`alibaba`||e===`edge`||e===`minimax`}function jt(e){let t=Dt();if(!Ot(e))return t;let n=At(e.provider)?e.provider:`openai`,r=e.trigger===`off`||e.trigger===`always`||e.trigger===`inbound`||e.trigger===`tagged`?e.trigger:`always`;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:Ot(e.alibaba)?{...t.alibaba,...e.alibaba}:t.alibaba,openai:Ot(e.openai)?{...t.openai,...e.openai}:t.openai,edge:Ot(e.edge)?{...t.edge,...e.edge}:t.edge,minimax:Ot(e.minimax)?{...t.minimax,...e.minimax}:t.minimax}}function Mt(e){let t=Ot(e)?e:{};return{stt:kt(t.stt),tts:jt(t.tts)}}async function Nt(e){await P(q(`/api/config`),{method:`PATCH`,body:JSON.stringify({stt:e.stt,tts:e.tts})}),L()}async function Pt(){let e=await P(q(`/api/voice/models`));if(!e.payload?.models)throw Error(`Missing voice models payload`);return e.payload.models}function Ft(){return M(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,ve,`dark:border-edge`)}function Q(){return M(T,m)}var It=[{id:`paraformer-v2`,name:`Paraformer v2`},{id:`paraformer-v1`,name:`Paraformer v1`}],Lt=[{id:`whisper-1`,name:`Whisper-1`}],Rt=[{id:`tts-1`,name:`TTS-1`},{id:`tts-1-hd`,name:`TTS-1 HD`}],zt=[{id:`alloy`,name:`Alloy`},{id:`echo`,name:`Echo`}],Bt=[{id:`qwen-tts`,name:`Qwen TTS`},{id:`qwen3-tts-flash`,name:`Qwen3 TTS Flash`}],Vt=[{id:`Cherry`,name:`Cherry`},{id:`longxiaochun`,name:`Long Xiao Chun`}],Ht=[{id:`en-US-MichelleNeural`,name:`Michelle (US English)`},{id:`zh-CN-XiaoxiaoNeural`,name:`Xiaoxiao (Chinese)`}],Ut=[{id:`speech-2.8-hd`,name:`Speech 2.8 HD (Recommended)`},{id:`speech-2.8-turbo`,name:`Speech 2.8 Turbo (Fast)`}],Wt=[{id:`male-qn-qingse`,name:`Male Qingse (青涩男声)`},{id:`female-shaonv`,name:`Female Shaonv (少女音)`}];function Gt(){let e=x(e=>e.language),t=c(e),n=t.voiceSettings,r=!!ee(e=>e.token),[a,o]=(0,X.useState)(null),[s,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(null),[p,m]=(0,X.useState)(!1),[g,_]=(0,X.useState)(null),[v,y]=(0,X.useState)(!1),{data:b,error:S,isLoading:C,mutate:w}=de(r),{data:T,error:E,isLoading:D,mutate:O}=i(r?q(`/api/voice/models`):null,Pt,{revalidateOnFocus:!1}),k=(0,X.useMemo)(()=>b?.payload?.config===void 0?null:Mt(b.payload.config),[b]),A=(0,X.useMemo)(()=>!a||!s?!1:JSON.stringify(a)!==JSON.stringify(s),[a,s]);(0,X.useEffect)(()=>{if(!r){o(null),u(null),f(null);return}k===null||T===void 0||A||(o(structuredClone(k)),u(structuredClone(k)),f(T),y(!1))},[r,k,T,A]);let M=!!(r&&(k===null||T===void 0)&&(C||D)),N=S instanceof Error?S.message:S?String(S):E instanceof Error?E.message:E?String(E):null,P=(0,X.useCallback)(e=>{o(t=>t?{...t,stt:{...t.stt,...e}}:null)},[]),F=(0,X.useCallback)(e=>{o(t=>t?{...t,stt:{...t.stt,alibaba:{...t.stt.alibaba,...e}}}:null)},[]),te=(0,X.useCallback)(e=>{o(t=>t?{...t,stt:{...t.stt,openai:{...t.stt.openai,...e}}}:null)},[]),I=(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}}}})},[]),L=(0,X.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,...e}}:null)},[]),R=(0,X.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,alibaba:{...t.tts.alibaba,...e}}}:null)},[]),z=(0,X.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,openai:{...t.tts.openai,...e}}}:null)},[]),ne=(0,X.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,edge:{...t.tts.edge,...e}}}:null)},[]),B=(0,X.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,minimax:{...t.tts.minimax,...e}}}:null)},[]),V=(0,X.useCallback)(async()=>{if(!(!a||p)){m(!0),_(null),y(!1);try{await Nt(a);let e=structuredClone(a);u(e),o(e),y(!0),window.setTimeout(()=>y(!1),2500)}catch(e){_(e instanceof Error?e.message:n.saveError)}finally{m(!1)}}},[a,p,n.saveError]);if(!r)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(M)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)(l,{className:`size-4 animate-spin`}),n.loading]})});if(!a||d===null)return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:g??N??n.loadError}),(0,Y.jsx)(j,{type:`button`,variant:`secondary`,onClick:()=>{w(),O()},children:n.retry})]});let H=a.stt,ie=a.tts;return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.voice}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,Y.jsxs)(`a`,{href:re(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)(h,{className:`size-3.5`})]})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[v?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,Y.jsx)(j,{type:`button`,variant:`primary`,disabled:!A||p,onClick:()=>void V(),children:p?n.saving:n.save})]})]}),A?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,g?(0,Y.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:g}):null,(0,Y.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Y.jsx)(Kt,{v:n,stt:H,models:d,updateStt:P,updateSttAlibaba:F,updateSttOpenai:te,updateSttFallback:I}),(0,Y.jsx)(qt,{v:n,tts:ie,models:d,updateTts:L,updateTtsAlibaba:R,updateTtsOpenai:z,updateTtsEdge:ne,updateTtsMinimax:B})]}),(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 Kt({v:e,stt:t,models:n,updateStt:r,updateSttAlibaba:i,updateSttOpenai:a,updateSttFallback:o}){let s=n?.stt?.alibaba?.length?n.stt.alibaba:It,c=n?.stt?.openai?.length?n.stt.openai:Lt;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)(me,{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:Q(),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:M(Ft(),`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:Q(),value:t.alibaba?.model??``,onChange:e=>i({model:e.target.value}),children:s.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}):(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.apiKey}),(0,Y.jsx)(`input`,{className:M(Ft(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.openai?.apiKey??``,onChange:e=>a({apiKey:e.target.value}),placeholder:`sk-...`}),(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (OPENAI_API_KEY)`]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:Q(),value:t.openai?.model??``,onChange:e=>a({model:e.target.value}),children:c.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.stt.fallback}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.stt.fallbackDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:t.fallback?.enabled??!0,onChange:e=>o({enabled:e.target.checked})})]})]}):null]})]})}function qt({v:e,tts:t,models:n,updateTts:r,updateTtsAlibaba:i,updateTtsOpenai:a,updateTtsEdge:o,updateTtsMinimax:s}){let c=t=>t===`off`?e.tts.triggerDescOff:t===`always`?e.tts.triggerDescAlways:t===`inbound`?e.tts.triggerDescInbound:t===`tagged`?e.tts.triggerDescTagged:``,l=n?.tts?.openai?.length?n.tts.openai:Rt,u=n?.ttsVoices?.openai?.length?n.ttsVoices.openai:zt,d=n?.tts?.alibaba?.length?n.tts.alibaba:Bt,f=n?.ttsVoices?.alibaba?.length?n.ttsVoices.alibaba:Vt,p=n?.ttsVoices?.edge?.length?n.ttsVoices.edge:Ht,m=n?.tts?.minimax?.length?n.tts.minimax:Ut,h=n?.ttsVoices?.minimax?.length?n.ttsVoices.minimax:Wt;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)(g,{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:Q(),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:c(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:Q(),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})]})]})]}),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:M(Ft(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.openai?.apiKey??``,onChange:e=>a({apiKey:e.target.value}),placeholder:`sk-...`}),(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (OPENAI_API_KEY)`]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:Q(),value:t.openai?.model??``,onChange:e=>a({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 flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.tts.voice}),(0,Y.jsx)(`select`,{className:Q(),value:t.openai?.voice??``,onChange:e=>a({voice:e.target.value}),children:u.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:M(Ft(),`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:Q(),value:t.alibaba?.model??``,onChange:e=>i({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:Q(),value:t.alibaba?.voice??``,onChange:e=>i({voice:e.target.value}),children:f.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:M(Ft(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.minimax?.apiKey??``,onChange:e=>s({apiKey:e.target.value}),placeholder:`eyJ...`}),(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (MINIMAX_API_KEY)`]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)($,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:Q(),value:t.minimax?.model??``,onChange:e=>s({model:e.target.value}),children:m.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:Q(),value:t.minimax?.voice??``,onChange:e=>s({voice:e.target.value}),children:h.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:Q(),value:t.edge?.voice??``,onChange:e=>o({voice:e.target.value}),children:p.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]}):null]})]})}function $({children:e}){return(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e})}function Jt(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 Yt(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 P(q(`/api/config`),{method:`PATCH`,body:JSON.stringify({tools:{web:{region:t,search:n}}})}),L()}function Xt(e){return e===`***`||e===`••••••••••••`}function Zt(e){if(!e||typeof e!=`object`||!(`providers`in e))return{};let t=e.providers;if(!t||typeof t!=`object`||Array.isArray(t))return{};let n={};for(let[e,r]of Object.entries(t))typeof r==`string`&&(n[e]=r);return n}function Qt(e,t,n){let r=new Set(n.map(e=>e.provider));return e.map(e=>({...e,configured:e.configured||r.has(e.id),apiKey:t[e.id]||(e.configured||r.has(e.id)?`***`:``)}))}async function $t(e){await P(q(`/api/config`),{method:`PATCH`,body:JSON.stringify({providers:e})}),Promise.all([L(),r(q(`/api/providers/meta`))])}async function en(e){return(await P(q(`/api/models-json/test-api-key`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({value:e})})).payload??{type:`literal`,error:`No response`}}function tn({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 nn(){return M(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,ve,`dark:border-edge`)}function rn(){return M(T,m)}var an=[`brave`,`tavily`,`bing`,`searxng`];function on(){return{type:`brave`,apiKey:``,url:``,disabled:!1}}function sn(){let e=x(e=>e.language),t=c(e),n=t.webSearchSettings,r=t.logs,i=!!ee(e=>e.token),[a,o]=(0,X.useState)(null),[s,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(null),[g,_]=(0,X.useState)(!1),v=(0,X.useRef)(!1),{data:y,error:b,isLoading:S,mutate:C}=de(i),w=(0,X.useMemo)(()=>y?.payload?.config===void 0?null:Jt(y.payload.config),[y]);(0,X.useEffect)(()=>{if(!i){o(null),u(null),v.current=!1;return}w!==null&&(v.current||(o(w),u(w)))},[i,w]);let T=!!(i&&S&&y===void 0&&!b),E=b instanceof Error?b.message:b?String(b):null,D=(0,X.useMemo)(()=>!a||!s?!1:JSON.stringify(a)!==JSON.stringify(s),[a,s]),O=(0,X.useCallback)(e=>{v.current=!0,o(t=>t?{...t,...e}:null)},[]),k=(0,X.useCallback)(async()=>{if(!(!a||d)){f(!0),m(null),_(!1);try{await Yt(a),v.current=!1,_(!0),window.setTimeout(()=>_(!1),2500)}catch(e){m(e instanceof Error?e.message:n.saveError)}finally{f(!1)}}},[a,d,n.saveError]);return i?T?(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)(l,{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:re(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)(h,{className:`size-3.5`})]})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[g?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,Y.jsx)(j,{type:`button`,variant:`primary`,disabled:!D||d,onClick:()=>void k(),children:d?n.saving:n.save})]})]}),D?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,p?(0,Y.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:p}):null,(0,Y.jsxs)(Ce,{children:[(0,Y.jsx)(we,{icon:H,title:n.sectionRegion,subtitle:n.sectionRegionHint}),(0,Y.jsx)(`div`,{className:`flex max-w-md flex-col gap-4`,children:(0,Y.jsx)(tn,{label:n.regionLabel,description:n.regionDesc,children:(0,Y.jsxs)(`select`,{className:rn(),value:a.regionMode,onChange:e=>O({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)(Ce,{children:[(0,Y.jsx)(we,{icon:H,title:n.sectionSearch,subtitle:n.sectionSearchHint}),(0,Y.jsxs)(`div`,{className:`flex max-w-xl flex-col gap-6`,children:[(0,Y.jsx)(tn,{label:n.maxResultsLabel,description:n.maxResultsDesc,children:(0,Y.jsx)(`input`,{type:`number`,min:1,max:50,className:nn(),value:a.maxResults,onChange:e=>O({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)(cn,{row:e,labels:n,onChange:e=>{let n=[...a.providers];n[t]=e,O({providers:n})},onRemove:()=>{O({providers:a.providers.filter((e,n)=>n!==t)})}},t)),(0,Y.jsxs)(j,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5 text-sm`,onClick:()=>O({providers:[...a.providers,on()]}),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:p??E??n.loadError}),(0,Y.jsx)(j,{type:`button`,variant:`secondary`,onClick:()=>void C(),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 cn({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:M(rn(),`min-w-[8rem]`),value:e.type,onChange:t=>n({...e,type:t.target.value,url:t.target.value===`searxng`?e.url:``}),children:an.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)(j,{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)(tn,{label:t.urlLabel,description:t.urlDesc,children:(0,Y.jsx)(`input`,{type:`url`,className:nn(),value:e.url,placeholder:`http://localhost:8080`,onChange:t=>n({...e,url:t.target.value})})}):null,(0,Y.jsx)(tn,{label:t.apiKeyLabel,description:t.apiKeyDesc,children:(0,Y.jsx)(`input`,{type:`password`,autoComplete:`off`,className:nn(),value:Xt(e.apiKey)?``:e.apiKey,placeholder:Xt(e.apiKey)?t.keyPlaceholderMasked:t.keyPlaceholder,onChange:t=>n({...e,apiKey:t.target.value})})})]})}var ln=[{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 un(e,t){let n=c(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 dn(){let e=x(e=>e.language),t=c(e).systemSettings,[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(null),[o,s]=(0,X.useState)(null),l=typeof window<`u`?window.electronAPI?.system:void 0,u=(0,X.useCallback)(async()=>{if(l){s(null);try{r(await l.getBehavior()),a(await l.getPermissions())}catch(e){s(e instanceof Error?e.message:String(e))}}},[l]);if((0,X.useEffect)(()=>{E()&&l&&u()},[l,u]),!E()||!l)return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.title}),(0,Y.jsxs)(`div`,{className:Se(),children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:t.desktopOnlyTitle}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:t.desktopOnlyBody})]})]});let d=async e=>{try{let{behavior:t}=await l.setBehavior(e);r(t)}catch(e){s(e instanceof Error?e.message:String(e))}},f=async e=>{try{(await l.openPrivacy(e)).ok||s(`open_privacy failed`)}catch(e){s(e instanceof Error?e.message:String(e))}},p=n?n.platform===`win32`?t.permissionsHintWin:n.platform===`linux`?t.permissionsHintLinux:n.platform===`darwin`?t.permissionsHintDarwin:t.permissionsHint:t.permissionsHint;return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.title}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:t.subtitle})]}),o?(0,Y.jsx)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:o}):null,(0,Y.jsxs)(Ce,{children:[(0,Y.jsxs)(`div`,{className:`mb-4 flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)(N,{className:`size-4 text-accent`,strokeWidth:1.75}),t.behaviorGroup]}),(0,Y.jsxs)(`div`,{className:`space-y-2`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.openAtLogin}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.openAtLoginDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!n,checked:!!n?.openAtLogin,onChange:e=>{d({openAtLogin:e.target.checked})}})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.keepAwake}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.keepAwakeDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!n,checked:!!n?.keepAwakePreferred,onChange:e=>{d({keepAwakePreferred:e.target.checked})}})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.notifyDesktop}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.notifyDesktopDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!n,checked:!!n?.notifyEnabled,onChange:e=>{d({notifyEnabled:e.target.checked})}})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.notifySound}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.notifySoundDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!n,checked:!!n?.notifySoundEnabled,onChange:e=>{d({notifySoundEnabled:e.target.checked})}})]})]})]}),n&&i?(0,Y.jsxs)(`section`,{className:Se(),children:[(0,Y.jsxs)(`div`,{className:`mb-4 flex flex-col gap-1 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:t.permissionsTitle}),(0,Y.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:p})]}),(0,Y.jsx)(`button`,{type:`button`,className:`mt-2 inline-flex max-w-full items-center justify-center rounded-lg border border-edge bg-surface-panel px-3 py-1.5 text-sm font-medium text-fg transition-colors hover:bg-surface-hover sm:mt-0`,onClick:()=>void u(),children:t.refresh})]}),(0,Y.jsx)(`ul`,{className:`space-y-3`,children:ln.map(({key:r,pane:o})=>{let c=un(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 ${c.className}`,children:c.label})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[r===`microphone`&&n?.platform===`darwin`?(0,Y.jsx)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover`,onClick:()=>{(async()=>{try{await l.requestMicrophone(),a(await l.getPermissions())}catch(e){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 f(o),children:[t.openSettings,(0,Y.jsx)(h,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0})]})]})]},r):null})})]}):null]})}async function fn(e){let t=await B(q(`/api/auth/oauth-async/start`),{method:`POST`,body:JSON.stringify({provider:e})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error||`OAuth start failed: ${t.status}`)}return(await t.json()).payload}async function pn(e){let t=await B(q(`/api/auth/oauth-async/${encodeURIComponent(e)}/status`));if(!t.ok)throw Error(`OAuth status: ${t.status}`);return(await t.json()).payload}async function mn(e,t){let n=await B(q(`/api/auth/oauth-async/${encodeURIComponent(e)}/code`),{method:`POST`,body:JSON.stringify({code:t})});if(!n.ok){let e=await n.json().catch(()=>({}));throw Error(e.error||`Submit code failed: ${n.status}`)}}async function hn(e){let t=await B(q(`/api/auth/oauth-async/${encodeURIComponent(e)}/cancel`),{method:`POST`});if(!t.ok)throw Error(`Cancel OAuth failed: ${t.status}`)}async function gn(e){let t=await B(q(`/api/auth/oauth-async/${encodeURIComponent(e)}`),{method:`DELETE`});if(!t.ok)throw Error(`Cleanup session failed: ${t.status}`)}async function _n(e){let t=await B(q(`/api/auth/oauth/${encodeURIComponent(e)}`),{method:`DELETE`});if(!t.ok)throw Error(`Revoke OAuth failed: ${t.status}`)}function vn(e,t){return e===`single`?t.getApiKey:e===`intl`?t.getApiKeyIntl:t.getApiKeyCn}var yn={openai:{apiKeyUrl:`https://platform.openai.com/api-keys`,pricingUrl:`https://openai.com/pricing`,docsUrl:`https://platform.openai.com/docs`,description:`The most widely used LLM provider. Powers ChatGPT.`,descriptionZh:`最广泛使用的 LLM 服务商,ChatGPT 背后的技术。`,bestFor:[`general`,`coding`,`vision`],freeTier:!1,freeTierNote:`Pay-as-you-go; new accounts may receive trial credits.`,aliases:[`chatgpt`,`gpt`,`gpt-4`,`gpt4`,`gpt-4o`,`gpt4o`],envVars:[`OPENAI_API_KEY`]},anthropic:{apiKeyUrl:`https://console.anthropic.com/settings/keys`,pricingUrl:`https://www.anthropic.com/pricing`,docsUrl:`https://docs.anthropic.com`,description:`Known for Claude — excellent at long documents, coding, and nuanced reasoning.`,descriptionZh:`Claude 系列模型,擅长长文档处理、代码和复杂推理。`,bestFor:[`long context`,`coding`,`reasoning`],freeTier:!1,aliases:[`claude`,`claude 3`,`claude sonnet`,`claude opus`,`claude haiku`],envVars:[`ANTHROPIC_OAUTH_TOKEN`,`ANTHROPIC_API_KEY`]},google:{apiKeyUrl:`https://aistudio.google.com/app/apikey`,pricingUrl:`https://ai.google.dev/pricing`,docsUrl:`https://ai.google.dev/docs`,description:`Google Gemini models — strong multimodal and long-context capabilities.`,descriptionZh:`Google Gemini 系列,多模态能力强,支持超长上下文。`,bestFor:[`multimodal`,`long context`,`general`],freeTier:!0,freeTierNote:`Free tier available via Google AI Studio.`,aliases:[`gemini`,`google gemini`,`bard`,`google ai`],envVars:[`GEMINI_API_KEY`,`GOOGLE_API_KEY`]},"google-vertex":{apiKeyUrl:`https://console.cloud.google.com/apis/credentials`,pricingUrl:`https://cloud.google.com/vertex-ai/pricing`,docsUrl:`https://cloud.google.com/vertex-ai/docs`,description:`Google Vertex AI — enterprise-grade Gemini and other models on GCP.`,descriptionZh:`Google Vertex AI,企业级 GCP 托管模型,支持 Gemini 等。`,bestFor:[`enterprise`,`multimodal`,`compliance`],freeTier:!1,aliases:[`vertex`,`vertex ai`,`gcp`,`google cloud`],envVars:[`GOOGLE_CLOUD_PROJECT`,`GOOGLE_CLOUD_LOCATION`]},"google-gemini-cli":{apiKeyUrl:`https://aistudio.google.com/app/apikey`,pricingUrl:`https://ai.google.dev/pricing`,docsUrl:`https://ai.google.dev/docs`,description:`Gemini via CLI token — for users authenticated with the Gemini CLI tool.`,descriptionZh:`通过 Gemini CLI 令牌访问 Gemini,适合已安装 CLI 工具的用户。`,bestFor:[`general`,`multimodal`],freeTier:!0,freeTierNote:`Uses your existing Gemini CLI authentication.`,aliases:[`gemini cli`,`gemini-cli`],envVars:[`GEMINI_CLI_TOKEN`,`GOOGLE_TOKEN`]},"google-antigravity":{apiKeyUrl:`https://console.cloud.google.com/apis/credentials`,pricingUrl:`https://cloud.google.com/pricing`,docsUrl:`https://cloud.google.com/docs`,description:`Google Antigravity — internal/experimental Google AI endpoint.`,descriptionZh:`Google Antigravity,Google 内部/实验性 AI 端点。`,bestFor:[`experimental`],freeTier:!1,aliases:[`antigravity`,`google antigravity`],envVars:[`ANTIGRAVITY_API_KEY`]},groq:{apiKeyUrl:`https://console.groq.com/keys`,pricingUrl:`https://groq.com/pricing/`,docsUrl:`https://console.groq.com/docs`,description:`Extremely fast inference — ideal for latency-sensitive applications.`,descriptionZh:`推理速度极快,适合对延迟敏感的场景。`,bestFor:[`speed`,`cheap`],freeTier:!0,freeTierNote:`Generous free tier with rate limits.`,aliases:[`groq`,`llama on groq`,`mixtral on groq`],envVars:[`GROQ_API_KEY`]},deepseek:{apiKeyUrl:`https://platform.deepseek.com/api_keys`,pricingUrl:`https://api-docs.deepseek.com/quick_start/pricing/`,docsUrl:`https://platform.deepseek.com/api-docs/`,description:`DeepSeek models — OpenAI-compatible API with strong reasoning and low costs.`,descriptionZh:`DeepSeek 模型:OpenAI 兼容 API,推理强、成本低。`,bestFor:[`reasoning`,`cheap`,`coding`],freeTier:!0,freeTierNote:`Free credits may be available for new accounts.`,aliases:[`deepseek`,`deep seek`,`deepseek v4`,`deepseek-v4`,`r1`],envVars:[`DEEPSEEK_API_KEY`]},xai:{apiKeyUrl:`https://console.x.ai/`,pricingUrl:`https://x.ai/api`,docsUrl:`https://docs.x.ai/`,description:`xAI Grok models — real-time web access, strong reasoning.`,descriptionZh:`xAI Grok 系列,支持实时联网,推理能力强。`,bestFor:[`reasoning`,`real-time`],freeTier:!1,aliases:[`grok`,`xai`,`x.ai`],envVars:[`XAI_API_KEY`]},cerebras:{apiKeyUrl:`https://cloud.cerebras.ai/platform/`,pricingUrl:`https://cloud.cerebras.ai/platform/`,docsUrl:`https://inference-docs.cerebras.ai/`,description:`Ultra-fast inference on custom AI chips. Fastest Llama inference available.`,descriptionZh:`基于专用 AI 芯片的超快推理,Llama 推理速度业界最快。`,bestFor:[`speed`],freeTier:!0,freeTierNote:`Free tier available.`,aliases:[`cerebras`],envVars:[`CEREBRAS_API_KEY`]},mistral:{apiKeyUrl:`https://console.mistral.ai/api-keys/`,pricingUrl:`https://mistral.ai/technology/#pricing`,docsUrl:`https://docs.mistral.ai/`,description:`European open-weight models. Good balance of quality and cost.`,descriptionZh:`欧洲开源模型,质量与成本平衡好。`,bestFor:[`general`,`cheap`,`coding`],freeTier:!1,aliases:[`mistral`,`mixtral`,`codestral`],envVars:[`MISTRAL_API_KEY`]},openrouter:{apiKeyUrl:`https://openrouter.ai/keys`,pricingUrl:`https://openrouter.ai/models`,docsUrl:`https://openrouter.ai/docs`,description:`API gateway to 100+ models from many providers with a single key.`,descriptionZh:`统一 API 网关,一个 Key 访问 100+ 模型。`,bestFor:[`general`,`flexibility`],freeTier:!0,freeTierNote:`Some models are free; pay-per-use for others.`,aliases:[`openrouter`,`open router`],envVars:[`OPENROUTER_API_KEY`]},"azure-openai-responses":{apiKeyUrl:`https://portal.azure.com/#view/Microsoft_Azure_ProjectOxford/CognitiveServicesHub/~/OpenAI`,pricingUrl:`https://azure.microsoft.com/en-us/pricing/details/cognitive-services/openai-service/`,docsUrl:`https://learn.microsoft.com/en-us/azure/ai-services/openai/`,description:`OpenAI models hosted on Azure. Enterprise SLA and data residency.`,descriptionZh:`Azure 托管的 OpenAI 模型,企业级 SLA 和数据合规。`,bestFor:[`enterprise`,`compliance`,`coding`],freeTier:!1,aliases:[`azure`,`azure openai`,`aoai`],envVars:[`AZURE_OPENAI_API_KEY`,`AZURE_OPENAI_BASE_URL`]},"amazon-bedrock":{apiKeyUrl:`https://console.aws.amazon.com/iam/home#/security_credentials`,pricingUrl:`https://aws.amazon.com/bedrock/pricing/`,docsUrl:`https://docs.aws.amazon.com/bedrock/`,description:`AWS-hosted models including Claude, Llama, Titan. Enterprise-grade.`,descriptionZh:`AWS 托管模型,包含 Claude、Llama 等,企业级可靠性。`,bestFor:[`enterprise`,`compliance`],freeTier:!1,aliases:[`bedrock`,`aws`,`amazon`],envVars:[`AWS_ACCESS_KEY_ID`,`AWS_SECRET_ACCESS_KEY`,`AWS_REGION`]},minimax:{apiKeyUrl:`https://platform.minimax.io/user-center/basic-information/interface-key`,pricingUrl:`https://platform.minimax.io/docs/guides/models-intro`,docsUrl:`https://platform.minimax.io/docs/guides/quickstart-preparation`,description:`MiniMax — Chinese multimodal model with strong text and audio capabilities.`,descriptionZh:`MiniMax,国产多模态模型,文本和音频能力强。`,bestFor:[`multimodal`,`chinese`],freeTier:!0,freeTierNote:`注册赠送免费额度。`,aliases:[`minimax`,`mini max`,`abab`],envVars:[`MINIMAX_API_KEY`]},"minimax-cn":{apiKeyUrl:`https://platform.minimaxi.com/user-center/basic-information/interface-key`,pricingUrl:`https://platform.minimaxi.com/document/Price`,docsUrl:`https://platform.minimaxi.com/document/Announcement`,description:`MiniMax (China endpoint) — domestic access for Chinese users.`,descriptionZh:`MiniMax 国内端点,国内用户直连访问。`,bestFor:[`multimodal`,`chinese`],freeTier:!0,freeTierNote:`注册赠送免费额度。`,aliases:[`minimax cn`,`minimax china`,`abab`],envVars:[`MINIMAX_CN_API_KEY`,`MINIMAX_API_KEY`]},"kimi-coding":{apiKeyUrl:`https://platform.moonshot.ai/console/api-keys`,apiKeyUrlCn:`https://platform.moonshot.cn/console/api-keys`,pricingUrl:`https://platform.moonshot.ai/docs/pricing/chat`,docsUrl:`https://platform.moonshot.ai/docs`,description:`Kimi Coding — Moonshot model optimized for code generation tasks.`,descriptionZh:`Kimi Coding,Moonshot 专为代码生成优化的模型。`,bestFor:[`coding`,`chinese`],freeTier:!0,freeTierNote:`注册赠送免费额度。`,aliases:[`kimi coding`,`moonshot coding`,`kimi code`],envVars:[`KIMI_API_KEY`,`MOONSHOT_API_KEY`]},huggingface:{apiKeyUrl:`https://huggingface.co/settings/tokens`,pricingUrl:`https://huggingface.co/pricing`,docsUrl:`https://huggingface.co/docs/api-inference/`,description:`Access thousands of open-source models via Hugging Face Inference API.`,descriptionZh:`通过 Hugging Face 访问数千个开源模型。`,bestFor:[`open source`,`flexibility`],freeTier:!0,freeTierNote:`Free tier with rate limits.`,aliases:[`huggingface`,`hugging face`,`hf`],envVars:[`HF_TOKEN`,`HUGGINGFACE_TOKEN`]},opencode:{apiKeyUrl:`https://opencode.ai/auth`,pricingUrl:`https://opencode.ai/docs`,docsUrl:`https://opencode.ai/docs/providers/`,description:`OpenCode — AI coding assistant provider.`,descriptionZh:`OpenCode,AI 代码助手服务商。`,bestFor:[`coding`],freeTier:!1,aliases:[`opencode`,`open code`],envVars:[`OPENCODE_API_KEY`]},"opencode-go":{apiKeyUrl:`https://opencode.ai/auth`,pricingUrl:`https://opencode.ai/docs`,docsUrl:`https://opencode.ai/docs/providers/`,description:`OpenCode Go — AI coding assistant provider (Go variant).`,descriptionZh:`OpenCode Go,AI 代码助手服务商(Go 版本)。`,bestFor:[`coding`],freeTier:!1,aliases:[`opencode go`,`opencode-go`],envVars:[`OPENCODE_API_KEY`]},zai:{apiKeyUrl:`https://z.ai/manage-apikey/apikey-list`,pricingUrl:`https://z.ai/manage-apikey/billing`,docsUrl:`https://docs.z.ai/guides/overview/quick-start`,description:`01.AI Yi models — strong multilingual capabilities.`,descriptionZh:`零一万物 Yi 系列模型,多语言能力强。`,bestFor:[`general`,`chinese`],freeTier:!1,aliases:[`yi`,`01.ai`,`zero one`,`零一万物`],envVars:[`ZAI_API_KEY`]},dashscope:{apiKeyUrl:`https://modelstudio.console.alibabacloud.com/`,apiKeyUrlCn:`https://dashscope.console.aliyun.com/apiKey`,pricingUrl:`https://help.aliyun.com/zh/dashscope/developer-reference/tongyi-thousand-questions-metering-and-billing`,docsUrl:`https://help.aliyun.com/zh/dashscope/`,description:"Alibaba DashScope — image generation, speech, and STT HTTP APIs (service id `dashscope`, not a pi-ai LLM provider).",descriptionZh:`阿里 DashScope:文生图、语音等 HTTP API(服务 id 为 dashscope,非 pi-ai 内置 LLM)。`,bestFor:[`image`,`speech`,`chinese`],freeTier:!0,aliases:[`dash scope`,`alibaba dashscope`],envVars:[`DASHSCOPE_API_KEY`]},"vercel-ai-gateway":{apiKeyUrl:`https://vercel.com/account/tokens`,pricingUrl:`https://vercel.com/pricing`,docsUrl:`https://vercel.com/docs/ai/ai-gateway`,description:`Vercel AI Gateway — route requests to multiple LLM providers via Vercel.`,descriptionZh:`Vercel AI Gateway,通过 Vercel 路由请求到多个 LLM 服务商。`,bestFor:[`flexibility`,`enterprise`],freeTier:!1,aliases:[`vercel gateway`,`vercel ai gateway`],envVars:[`AI_GATEWAY_API_KEY`,`VERCEL_AI_GATEWAY_API_KEY`]},"github-copilot":{apiKeyUrl:`https://github.com/settings/tokens`,pricingUrl:`https://github.com/features/copilot#pricing`,docsUrl:`https://docs.github.com/en/copilot`,description:`GitHub Copilot — use your GitHub token to access Copilot models.`,descriptionZh:`使用 GitHub 令牌访问 Copilot 模型。`,bestFor:[`coding`],freeTier:!0,freeTierNote:`Free for verified students and open-source maintainers.`,aliases:[`github copilot`,`copilot`,`github`],envVars:[`COPILOT_GITHUB_TOKEN`,`GH_TOKEN`,`GITHUB_TOKEN`,`GITHUB_COPILOT_TOKEN`]}};function bn(e,t){let n=yn[e];if(!n)return[];let r=n.apiKeyUrl,i=n.apiKeyUrlCn;return r&&i?t===`zh`?[{href:i,kind:`cn`},{href:r,kind:`intl`}]:[{href:r,kind:`intl`},{href:i,kind:`cn`}]:r?[{href:r,kind:`single`}]:i?[{href:i,kind:`single`}]:[]}function xn({providerId:e,language:t}){let n=yn[e];if(!n)return null;let r=t===`zh`,i=r&&n.descriptionZh?n.descriptionZh:n.description;return i?(0,Y.jsxs)(A,{children:[(0,Y.jsx)(f,{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)(p,{className:`size-3.5`,"aria-hidden":!0})})}),(0,Y.jsx)(s,{children:(0,Y.jsxs)(_e,{side:`right`,align:`start`,sideOffset:6,className:M(`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)(v,{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)(h,{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)(h,{className:`size-3`,"aria-hidden":!0})]}):null]}):null,(0,Y.jsx)(y,{className:`fill-edge`})]})})]}):null}var Sn=[`common`,`specialty`,`enterprise`,`oauth`,`extension`];function Cn(e){let t=new Map;for(let e of Sn)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 wn(e,t){return e.replace(/\{\{(\w+)\}\}/g,(e,n)=>String(t[n]??``))}function Tn(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 En(){let e=x(e=>e.language),t=c(e),n=t.providersSettings,r=!!ee(e=>e.token),[a,o]=(0,X.useState)({}),[s,l]=(0,X.useState)({}),[d,f]=(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)(``),[S,C]=(0,X.useState)(!1),[w,T]=(0,X.useState)(()=>new Set),E=(0,X.useRef)(``),D=q(`/api/providers/meta`),O=(0,X.useCallback)(async e=>(await P(e)).payload?.providers??[],[]),{data:k,error:A,isLoading:N,mutate:F}=de(r),{data:I,error:L,isLoading:R,mutate:z}=i(r?D:null,O,{revalidateOnFocus:!1}),{data:ne,mutate:B}=i(r?`gateway-configured-models`:null,()=>ae(),{revalidateOnFocus:!1}),V=(0,X.useMemo)(()=>!I||k===void 0?null:Qt(I,Zt(k.payload?.config),ne??[]),[I,k,ne]),ie=A instanceof Error?A.message:A?String(A):L instanceof Error?L.message:L?String(L):null,U=!!(r&&V===null&&(N||R)&&!ie),W=(0,X.useMemo)(()=>JSON.stringify(a)!==JSON.stringify(s),[a,s]);(0,X.useEffect)(()=>{if(!W)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[W]),(0,X.useEffect)(()=>{if(!(!r||V===null)&&!W){let e={};for(let t of V)e[t.id]=t.apiKey;o(e),l({...e})}},[r,V,W]);let G=V??[],K=(0,X.useMemo)(()=>{let e=G,t=y.trim().toLowerCase();return t&&(e=e.filter(e=>{let n=yn[e.id]?.aliases??[];return e.id.toLowerCase().includes(t)||e.name.toLowerCase().includes(t)||n.some(e=>e.toLowerCase().includes(t))})),S&&(e=e.filter(e=>!e.configured)),e},[G,y,S]),se=(0,X.useMemo)(()=>Cn(K),[K]);(0,X.useEffect)(()=>{let e=E.current;if(E.current=y,y.trim()){let e=new Set;for(let t of Sn)(se.get(t)??[]).length>0&&e.add(t);v(e);return}e.trim()&&v(new Set([`common`]))},[y,se]);let ce=(0,X.useCallback)(async()=>{if(d)return;let e={};for(let t of Object.keys(a)){let n=a[t]?.trim()??``;!n||Xt(n)||(e[t]=n)}if(Object.keys(e).length===0){l({...a}),g(`noChanges`),window.setTimeout(()=>g(null),2500);return}f(!0),m(null),g(null);try{await $t(e),T(new Set(Object.keys(e)));let t=await B(ae(!0))??ne??[],[n,r]=await Promise.all([F(),z()]),i=Array.isArray(r)?r:I??[],a=n??k;if(a?.payload){let e=Qt(i,Zt(a.payload.config),t),n={};for(let t of e)n[t.id]=t.apiKey;o(n),l({...n})}g(`saved`),window.setTimeout(()=>g(null),2500)}catch(e){m(e instanceof Error?e.message:n.saveError)}finally{f(!1)}},[k,a,I,ne,F,z,B,n.saveError,d]),le=(0,X.useCallback)(()=>{o({...s}),m(null),g(null),T(new Set)},[s]),ue=e=>{v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},fe=(0,X.useCallback)(()=>{F(),z()},[F,z]),pe=!!(y.trim()||S);return r?U?(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})]}):G.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??ie??n.empty})]}),(0,Y.jsx)(j,{type:`button`,variant:`secondary`,onClick:()=>{F(),z()},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)(j,{type:`button`,variant:`secondary`,disabled:!W||d,onClick:le,children:n.discard}),(0,Y.jsx)(j,{type:`button`,variant:`primary`,disabled:!W||d,onClick:()=>void ce(),children:d?n.saving:n.save})]})]}),W?(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:re(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)(he,{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)(H,{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:M(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-10 pr-3 text-sm text-fg placeholder:text-fg-subtle`,ve,`dark:border-edge`),"aria-label":n.searchPlaceholder})]}),(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg-muted`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:S,onChange:e=>C(e.target.checked),className:`size-4 rounded border-edge text-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`}),n.unconfiguredOnly]}),pe?(0,Y.jsx)(j,{type:`button`,variant:`ghost`,className:`h-9 w-fit self-start text-fg-muted`,onClick:()=>{b(``),C(!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,K.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)(j,{type:`button`,variant:`secondary`,className:`mt-4`,onClick:()=>{b(``),C(!1)},children:n.clearFilters})]}):(0,Y.jsx)(`div`,{className:`flex flex-col gap-3`,children:Sn.map(t=>{let r=se.get(t)??[];if(r.length===0)return null;let i=_.has(t),c=r.filter(e=>e.configured).length,l=`providers-cat-${t}`;return(0,Y.jsxs)(`section`,{className:`overflow-hidden rounded-2xl bg-surface-base`,children:[(0,Y.jsxs)(`button`,{type:`button`,id:`${l}-trigger`,"aria-expanded":i,"aria-controls":l,className:`flex w-full items-center justify-between gap-2 border-b border-edge-subtle px-4 py-3 text-left transition-colors hover:bg-surface-hover/60 dark:border-edge-subtle`,onClick:()=>ue(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:[c>0?(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-fg-subtle`,children:[(0,Y.jsx)(oe,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}),wn(n.configuredCount,{count:String(c)})]}):null,(0,Y.jsx)(te,{className:M(`size-4 text-fg-subtle transition-transform`,i&&`rotate-180`),"aria-hidden":!0})]})]}),i?(0,Y.jsx)(`div`,{id:l,role:`region`,"aria-labelledby":`${l}-trigger`,className:`divide-y divide-edge-subtle`,children:r.map(t=>(0,Y.jsx)(`div`,{id:`provider-row-${t.id}`,children:(0,Y.jsx)(On,{row:t,value:a[t.id]??``,rowDirty:(a[t.id]??``)!==(s[t.id]??``),labels:n,language:e,onChange:(e,t)=>o(n=>({...n,[e]:t})),onReload:fe,justSaved:w.has(t.id),availableModels:ne??[]})},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)(u,{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})]})]})})}function Dn({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)(oe,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):(0,Y.jsx)(a,{className:`size-3.5`,"aria-hidden":!0})})]})}function On({row:e,value:t,rowDirty:n,labels:r,language:i,onChange:o,onReload:s,justSaved:c,availableModels:d}){let[f,m]=(0,X.useState)(!1),[g,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(!1),[ee,S]=(0,X.useState)(null),C=Xt(t),w=C&&!g?``:t,T=e.configured&&!C&&!!t,[E,D]=(0,X.useState)(!1),[k,A]=(0,X.useState)(),[N,P]=(0,X.useState)(),[F,I]=(0,X.useState)(),[L,R]=(0,X.useState)(),[z,ne]=(0,X.useState)(),[B,V]=(0,X.useState)(``),[re,H]=(0,X.useState)(!1),[ie,U]=(0,X.useState)(null),[W,G]=(0,X.useState)(null),ae=e.activeKeySource??`none`,K=(0,X.useMemo)(()=>bn(e.id,i),[e.id,i]);(0,X.useEffect)(()=>()=>{k&&gn(k).catch(()=>{})},[k]),(0,X.useEffect)(()=>{if(!k||!E)return;let e=window.setInterval(()=>{(async()=>{try{let t=await pn(k);I(t.message),R(t.authUrl),ne(t.instructions),t.status===`waiting_auth`||t.status===`waiting_code`?P(t.status===`waiting_code`?`waiting_code`:`waiting`):t.status===`completed`?(window.clearInterval(e),D(!1),P(`success`),I(t.message),window.setTimeout(()=>s(),800)):(t.status===`failed`||t.status===`cancelled`)&&(window.clearInterval(e),D(!1),P(`error`),I(t.error||t.message||`OAuth failed`))}catch{}})()},1e3);return()=>window.clearInterval(e)},[k,E,s]);let q=async()=>{D(!0),P(`waiting`),I(r.oauthStarting),A(void 0),R(void 0),ne(void 0);try{A((await fn(e.id)).sessionId)}catch(e){P(`error`),I(e instanceof Error?e.message:`OAuth failed`),D(!1)}},ce=async()=>{if(k){try{await hn(k)}catch{}A(void 0),D(!1),P(`idle`),I(void 0)}},ue=async()=>{if(!(!k||!B.trim()))try{await mn(k,B.trim()),V(``),I(r.oauthProcessingCode)}catch(e){P(`error`),I(e instanceof Error?e.message:`Failed`)}},de=()=>{window.confirm(wn(r.revokeConfirm,{name:e.name}))&&(S(null),_n(e.id).then(()=>s()).catch(e=>S(e instanceof Error?e.message:r.revokeFailed)))},fe=async()=>{if(!(!t||C))try{await navigator.clipboard.writeText(t),x(!0),window.setTimeout(()=>x(!1),2e3)}catch{}},me=async()=>{let e=t.trim();if(!(!e||Xt(e))){H(!0),U(null),G(null);try{let t=await en(e);if(t.error){G(!1),U(`${r.testFailed} ${t.error}`);return}G(!0),t.type===`env`?U(r.testOkEnv):t.type===`command`?U(r.testOkCommand):U(r.testOkLiteral)}catch(e){G(!1),U(e instanceof Error?e.message:r.testFailed)}finally{H(!1)}}},he=n?r.metaWillSave:e.configured?C?`${r.metaMasked} · ${r.runtimeLabelPrefix} ${Tn(r,ae)}`:`${r.runtimeLabelPrefix} ${Tn(r,ae)}`:r.metaNotConfigured,ge=`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)(oe,{className:`size-4 text-emerald-600 dark:text-emerald-400`}):(0,Y.jsx)(u,{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)(xn,{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:he})]}),(0,Y.jsx)(j,{type:`button`,variant:`ghost`,className:`h-9 w-9 shrink-0 p-0`,"aria-expanded":f,"aria-controls":ge,"aria-label":r.expandRowDetails,onClick:()=>m(e=>!e),children:(0,Y.jsx)(te,{className:M(`size-4 transition-transform`,f&&`rotate-180`),"aria-hidden":!0})})]}),f?(0,Y.jsxs)(`div`,{id:ge,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:g||!C?`text`:`password`,className:M(`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`,ve,`dark:border-edge`),value:w,placeholder:C?r.placeholderOverride:e.configured?r.placeholderKeep:r.placeholderKey,disabled:E,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&&!C?(0,Y.jsx)(`button`,{type:`button`,className:M(`rounded p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,J.transition,J.press,J.focusRingPanel),title:b?r.copied:r.copy,"aria-label":b?r.copied:r.copy,onClick:()=>void fe(),children:b?(0,Y.jsx)(oe,{className:`size-4`}):(0,Y.jsx)(a,{className:`size-4`})}):null,(0,Y.jsx)(`button`,{type:`button`,className:M(`rounded p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg disabled:opacity-40`,J.transition,J.press,J.focusRingPanel),title:g?r.hide:r.show,"aria-label":g?r.hide:r.show,disabled:C,onClick:()=>y(e=>!e),children:g?(0,Y.jsx)(se,{className:`size-4`}):(0,Y.jsx)(_,{className:`size-4`})})]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2 sm:shrink-0`,children:[(0,Y.jsxs)(j,{type:`button`,variant:`secondary`,className:`gap-1`,disabled:E||re||!t.trim()||Xt(t),onClick:()=>void me(),children:[re?(0,Y.jsx)(l,{className:`size-4 animate-spin`,"aria-hidden":!0}):null,re?r.testingKey:r.testKey]}),e.supportsOAuth?T?(0,Y.jsxs)(j,{type:`button`,variant:`secondary`,className:`gap-1 text-red-600 dark:text-red-400`,onClick:de,children:[(0,Y.jsx)(pe,{className:`size-4`,"aria-hidden":!0}),r.revoke]}):(0,Y.jsxs)(j,{type:`button`,variant:`secondary`,className:`gap-1`,disabled:E,onClick:()=>void q(),children:[E?(0,Y.jsx)(l,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(O,{className:`size-4`,"aria-hidden":!0}),r.oauth]}):null]})]}),ie?(0,Y.jsx)(`p`,{className:M(`text-xs`,W===!1?`text-red-600 dark:text-red-400`:`text-fg-muted`),role:`status`,children:ie}):null,K.length>0?(0,Y.jsx)(`div`,{className:`flex flex-col gap-1`,children:K.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:[vn(e.kind,r),(0,Y.jsx)(h,{className:`size-3`,"aria-hidden":!0})]},`${e.kind}-${e.href}`))}):null]}),F?(0,Y.jsxs)(`div`,{className:M(`flex gap-2 rounded-md px-3 py-2 text-xs`,N===`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:[N===`error`?(0,Y.jsx)(le,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}):N===`success`?(0,Y.jsx)(oe,{className:`mt-0.5 size-4 shrink-0 text-emerald-600`,"aria-hidden":!0}):(0,Y.jsx)(p,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:F})]}):null,ee?(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)(le,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:ee})]}):null,(N===`waiting`||N===`waiting_code`)&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[L?(0,Y.jsxs)(`a`,{href:L,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)(h,{className:`size-4`,"aria-hidden":!0}),r.openAuthPage]}):null,(0,Y.jsxs)(j,{type:`button`,variant:`secondary`,className:`gap-1`,onClick:()=>void ce(),children:[(0,Y.jsx)(v,{className:`size-4`,"aria-hidden":!0}),r.cancelOAuth]})]}),z?(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)(p,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:z})]}):null,N===`waiting_code`?(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,Y.jsx)(`input`,{type:`text`,className:M(`min-w-0 flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,ve,`dark:border-edge`),value:B,placeholder:r.pasteRedirectUrl,onChange:e=>V(e.target.value),onKeyDown:e=>e.key===`Enter`&&void ue()}),(0,Y.jsx)(j,{type:`button`,variant:`primary`,className:`shrink-0`,onClick:()=>void ue(),children:r.submitCode})]}):null,C?(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)(p,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:ae===`env`?r.envHint:r.maskedStoredHint})]}):null,e.supportsOAuth&&!C&&!T?(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:r.oauthHint}):null,c?(0,Y.jsxs)(`div`,{className:`flex items-start gap-2 rounded-md bg-surface-hover/60 px-3 py-2 text-xs text-fg-muted dark:bg-surface-hover/40`,children:[(0,Y.jsx)(oe,{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=d.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,(yn[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:(yn[e.id]?.envVars??[]).map(e=>(0,Y.jsx)(Dn,{envVar:e,labels:r},e))})]}):null]}):null]})}var kn=[`appearance`,`system`,`agent-defaults`,`providers`,`models`,`voice`,`gateway`,`heartbeat`,`search`];function An(){let{section:e}=k(),t=x(e=>e.language),n=c(t);if(e===`agent`||e===`agents`)return(0,Y.jsx)(D,{to:`/agents`,replace:!0});if(!e||!kn.includes(e))return(0,Y.jsx)(D,{to:`/settings/appearance`,replace:!0});let r=e,i=n.settingsSections[r];return r===`appearance`?(0,Y.jsx)(Ae,{}):r===`system`?(0,Y.jsx)(dn,{}):r===`agent-defaults`?(0,Y.jsx)(Te,{}):r===`providers`?(0,Y.jsx)(En,{}):r===`models`?(0,Y.jsx)(Tt,{}):r===`voice`?(0,Y.jsx)(Gt,{}):r===`gateway`?(0,Y.jsx)(Fe,{}):r===`heartbeat`?(0,Y.jsx)($e,{}):r===`search`?(0,Y.jsx)(sn,{}):(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{An as SettingsPage};
|
|
2
|
+
//# sourceMappingURL=settings-page-DNG3Zijx.js.map
|