@xopcai/xopc 0.0.26 → 0.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/dist/extensions/telegram/xopc.extension.json +1 -1
  2. package/dist/extensions/weixin/src/adapters/onboard-cli.d.ts +7 -0
  3. package/dist/extensions/weixin/src/adapters/onboard-cli.js +61 -0
  4. package/dist/extensions/weixin/src/adapters/onboard-cli.js.map +1 -0
  5. package/dist/extensions/weixin/src/cli/qr-login.d.ts +5 -0
  6. package/dist/extensions/weixin/src/cli/qr-login.js +1 -1
  7. package/dist/extensions/weixin/src/cli/qr-login.js.map +1 -1
  8. package/dist/extensions/weixin/src/index.js +1 -1
  9. package/dist/extensions/weixin/src/plugin.d.ts +1 -0
  10. package/dist/extensions/weixin/src/plugin.js +2 -0
  11. package/dist/extensions/weixin/src/plugin.js.map +1 -1
  12. package/dist/gateway/static/root/assets/{agents-Clv9i1Kb.js → agents-DplaQYS2.js} +2 -2
  13. package/dist/gateway/static/root/assets/{agents-Clv9i1Kb.js.map → agents-DplaQYS2.js.map} +1 -1
  14. package/dist/gateway/static/root/assets/{apps-page-DqclV-PP.js → apps-page-Co95hLOJ.js} +2 -2
  15. package/dist/gateway/static/root/assets/{apps-page-DqclV-PP.js.map → apps-page-Co95hLOJ.js.map} +1 -1
  16. package/dist/gateway/static/root/assets/{channels-settings-CLyTYjrz.js → channels-settings-CkfSST0k.js} +2 -2
  17. package/dist/gateway/static/root/assets/{channels-settings-CLyTYjrz.js.map → channels-settings-CkfSST0k.js.map} +1 -1
  18. package/dist/gateway/static/root/assets/{cron-page-CU8lutMt.js → cron-page-D9q6KqL8.js} +2 -2
  19. package/dist/gateway/static/root/assets/{cron-page-CU8lutMt.js.map → cron-page-D9q6KqL8.js.map} +1 -1
  20. package/dist/gateway/static/root/assets/{cron-utils-_UjiWax6.js → cron-utils-BmzF4m1y.js} +2 -2
  21. package/dist/gateway/static/root/assets/{cron-utils-_UjiWax6.js.map → cron-utils-BmzF4m1y.js.map} +1 -1
  22. package/dist/gateway/static/root/assets/{dist-Xqb4IGWC.js → dist-Dn-ufXyc.js} +2 -2
  23. package/dist/gateway/static/root/assets/{dist-Xqb4IGWC.js.map → dist-Dn-ufXyc.js.map} +1 -1
  24. package/dist/gateway/static/root/assets/{extension-debug-page-CtTUkAmw.js → extension-debug-page-BZ8xQ74_.js} +2 -2
  25. package/dist/gateway/static/root/assets/{extension-debug-page-CtTUkAmw.js.map → extension-debug-page-BZ8xQ74_.js.map} +1 -1
  26. package/dist/gateway/static/root/assets/{extension-page-C-aQU8qR.js → extension-page-BlNgKxwW.js} +2 -2
  27. package/dist/gateway/static/root/assets/{extension-page-C-aQU8qR.js.map → extension-page-BlNgKxwW.js.map} +1 -1
  28. package/dist/gateway/static/root/assets/{extension-settings-page-b0y9aY-q.js → extension-settings-page-CWTdW_oY.js} +2 -2
  29. package/dist/gateway/static/root/assets/{extension-settings-page-b0y9aY-q.js.map → extension-settings-page-CWTdW_oY.js.map} +1 -1
  30. package/dist/gateway/static/root/assets/index-OT4cGzon.css +1 -0
  31. package/dist/gateway/static/root/assets/{index-Gr2HWo-G.js → index-lV8FGWlt.js} +94 -94
  32. package/dist/gateway/static/root/assets/{index-Gr2HWo-G.js.map → index-lV8FGWlt.js.map} +1 -1
  33. package/dist/gateway/static/root/assets/logs-page-DG31RpvG.js +2 -0
  34. package/dist/gateway/static/root/assets/logs-page-DG31RpvG.js.map +1 -0
  35. package/dist/gateway/static/root/assets/sessions-page-CdmjxDEM.js +2 -0
  36. package/dist/gateway/static/root/assets/{sessions-page-Cryg-36Z.js.map → sessions-page-CdmjxDEM.js.map} +1 -1
  37. package/dist/gateway/static/root/assets/{settings-page-DFNKT9yg.js → settings-page-DU2XLf5s.js} +2 -2
  38. package/dist/gateway/static/root/assets/{settings-page-DFNKT9yg.js.map → settings-page-DU2XLf5s.js.map} +1 -1
  39. package/dist/gateway/static/root/assets/{skills-page-D4gfh0Ih.js → skills-page-lb7vYtlP.js} +2 -2
  40. package/dist/gateway/static/root/assets/{skills-page-D4gfh0Ih.js.map → skills-page-lb7vYtlP.js.map} +1 -1
  41. package/dist/gateway/static/root/index.html +2 -2
  42. package/dist/package.js +1 -1
  43. package/dist/src/channels/index.js +2 -2
  44. package/dist/src/channels/manager.js +2 -2
  45. package/dist/src/channels/weixin/index.js +1 -1
  46. package/dist/src/cli/agent-chat-log-level-preset.d.ts +7 -0
  47. package/dist/src/cli/agent-chat-log-level-preset.js +22 -0
  48. package/dist/src/cli/agent-chat-log-level-preset.js.map +1 -0
  49. package/dist/src/cli/commands/agent/interactive.js +4 -2
  50. package/dist/src/cli/commands/agent/interactive.js.map +1 -1
  51. package/dist/src/cli/commands/agent/stream-renderer.d.ts +14 -0
  52. package/dist/src/cli/commands/agent/stream-renderer.js +99 -0
  53. package/dist/src/cli/commands/agent/stream-renderer.js.map +1 -0
  54. package/dist/src/cli/commands/agent.js +2 -2
  55. package/dist/src/cli/commands/agent.js.map +1 -1
  56. package/dist/src/cli/commands/onboard.js +77 -93
  57. package/dist/src/cli/commands/onboard.js.map +1 -1
  58. package/dist/src/cli/commands/tui.d.ts +1 -0
  59. package/dist/src/cli/commands/tui.js +40 -0
  60. package/dist/src/cli/commands/tui.js.map +1 -0
  61. package/dist/src/cli/index.d.ts +2 -0
  62. package/dist/src/cli/index.js +3 -0
  63. package/dist/src/cli/index.js.map +1 -1
  64. package/dist/src/config/schema.d.ts +6 -0
  65. package/dist/src/config/schema.js +6 -1
  66. package/dist/src/config/schema.js.map +1 -1
  67. package/dist/src/gateway/auth.d.ts +17 -3
  68. package/dist/src/gateway/auth.js +35 -16
  69. package/dist/src/gateway/auth.js.map +1 -1
  70. package/dist/src/gateway/hono/app.js +30 -1
  71. package/dist/src/gateway/hono/app.js.map +1 -1
  72. package/dist/src/gateway/hono/lib/config-payload.d.ts +1 -1
  73. package/dist/src/gateway/hono/middleware/auth.js +4 -3
  74. package/dist/src/gateway/hono/middleware/auth.js.map +1 -1
  75. package/dist/src/gateway/hono/middleware/scopes.d.ts +15 -0
  76. package/dist/src/gateway/hono/middleware/scopes.js +41 -0
  77. package/dist/src/gateway/hono/middleware/scopes.js.map +1 -0
  78. package/dist/src/gateway/security/audit.d.ts +18 -0
  79. package/dist/src/gateway/security/audit.js +68 -0
  80. package/dist/src/gateway/security/audit.js.map +1 -0
  81. package/dist/src/gateway/security/csp.d.ts +19 -0
  82. package/dist/src/gateway/security/csp.js +52 -0
  83. package/dist/src/gateway/security/csp.js.map +1 -0
  84. package/dist/src/gateway/security/dangerous-tools.d.ts +20 -0
  85. package/dist/src/gateway/security/dangerous-tools.js +46 -0
  86. package/dist/src/gateway/security/dangerous-tools.js.map +1 -0
  87. package/dist/src/gateway/security/flood-guard.d.ts +28 -0
  88. package/dist/src/gateway/security/flood-guard.js +42 -0
  89. package/dist/src/gateway/security/flood-guard.js.map +1 -0
  90. package/dist/src/gateway/security/index.d.ts +9 -0
  91. package/dist/src/gateway/security/index.js +10 -0
  92. package/dist/src/gateway/security/known-weak-secrets.d.ts +10 -0
  93. package/dist/src/gateway/security/known-weak-secrets.js +36 -0
  94. package/dist/src/gateway/security/known-weak-secrets.js.map +1 -0
  95. package/dist/src/gateway/security/operator-scopes.d.ts +37 -0
  96. package/dist/src/gateway/security/operator-scopes.js +137 -0
  97. package/dist/src/gateway/security/operator-scopes.js.map +1 -0
  98. package/dist/src/gateway/security/origin-check.d.ts +21 -0
  99. package/dist/src/gateway/security/origin-check.js +56 -0
  100. package/dist/src/gateway/security/origin-check.js.map +1 -0
  101. package/dist/src/gateway/security/preauth-connection-budget.d.ts +17 -0
  102. package/dist/src/gateway/security/preauth-connection-budget.js +49 -0
  103. package/dist/src/gateway/security/preauth-connection-budget.js.map +1 -0
  104. package/dist/src/gateway/security/secret-equal.d.ts +8 -0
  105. package/dist/src/gateway/security/secret-equal.js +30 -0
  106. package/dist/src/gateway/security/secret-equal.js.map +1 -0
  107. package/dist/src/gateway/service.d.ts +1 -1
  108. package/dist/src/gateway/service.js +11 -2
  109. package/dist/src/gateway/service.js.map +1 -1
  110. package/dist/src/tui/backends/embedded-backend.d.ts +42 -0
  111. package/dist/src/tui/backends/embedded-backend.js +160 -0
  112. package/dist/src/tui/backends/embedded-backend.js.map +1 -0
  113. package/dist/src/tui/backends/gateway-sse-backend.d.ts +49 -0
  114. package/dist/src/tui/backends/gateway-sse-backend.js +226 -0
  115. package/dist/src/tui/backends/gateway-sse-backend.js.map +1 -0
  116. package/dist/src/tui/components/assistant-message.d.ts +6 -0
  117. package/dist/src/tui/components/assistant-message.js +19 -0
  118. package/dist/src/tui/components/assistant-message.js.map +1 -0
  119. package/dist/src/tui/components/chat-log.d.ts +19 -0
  120. package/dist/src/tui/components/chat-log.js +99 -0
  121. package/dist/src/tui/components/chat-log.js.map +1 -0
  122. package/dist/src/tui/components/custom-editor.d.ts +13 -0
  123. package/dist/src/tui/components/custom-editor.js +44 -0
  124. package/dist/src/tui/components/custom-editor.js.map +1 -0
  125. package/dist/src/tui/components/tool-execution.d.ts +16 -0
  126. package/dist/src/tui/components/tool-execution.js +76 -0
  127. package/dist/src/tui/components/tool-execution.js.map +1 -0
  128. package/dist/src/tui/components/user-message.d.ts +6 -0
  129. package/dist/src/tui/components/user-message.js +22 -0
  130. package/dist/src/tui/components/user-message.js.map +1 -0
  131. package/dist/src/tui/sse-consumer.d.ts +15 -0
  132. package/dist/src/tui/sse-consumer.js +75 -0
  133. package/dist/src/tui/sse-consumer.js.map +1 -0
  134. package/dist/src/tui/stream-assembler.d.ts +22 -0
  135. package/dist/src/tui/stream-assembler.js +63 -0
  136. package/dist/src/tui/stream-assembler.js.map +1 -0
  137. package/dist/src/tui/theme.d.ts +71 -0
  138. package/dist/src/tui/theme.js +151 -0
  139. package/dist/src/tui/theme.js.map +1 -0
  140. package/dist/src/tui/tui-backend.d.ts +84 -0
  141. package/dist/src/tui/tui-backend.js +1 -0
  142. package/dist/src/tui/tui-types.d.ts +85 -0
  143. package/dist/src/tui/tui-types.js +21 -0
  144. package/dist/src/tui/tui-types.js.map +1 -0
  145. package/dist/src/tui/tui.d.ts +3 -0
  146. package/dist/src/tui/tui.js +526 -0
  147. package/dist/src/tui/tui.js.map +1 -0
  148. package/package.json +9 -3
  149. package/dist/gateway/static/root/assets/index-DhSFfSNN.css +0 -1
  150. package/dist/gateway/static/root/assets/logs-page-DRI33XK4.js +0 -2
  151. package/dist/gateway/static/root/assets/logs-page-DRI33XK4.js.map +0 -1
  152. package/dist/gateway/static/root/assets/sessions-page-Cryg-36Z.js +0 -2
@@ -1,2 +1,2 @@
1
- import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{i as t,t as n}from"./vendor-react-DbimaAId.js";import{i as r,o as i}from"./vendor-swr-B5fPo7KK.js";import{t as a}from"./cn-BMCV0OMB.js";import{$t as o,A as s,Br as c,Cr as l,Dn as u,En as d,Fr as f,G as p,Gn as m,Gt as h,H as g,Hn as _,Jn as v,Jr as y,Jt as ee,Kt as b,Ln as x,Lr as S,Nn as C,Nr as w,Pn as T,Qr as E,Qt as D,Rr as O,Sn as te,Wn as ne,Wt as k,Xn as A,Yn as j,Yr as M,Yt as N,Zn as P,Zt as F,_r as re,_t as I,a as L,an as R,c as ie,cn as z,cr as ae,ct as B,dn as oe,dt as se,fn as V,ft as H,gt as U,ht as ce,i as le,j as W,jn as G,jr as ue,kn as de,l as fe,lt as pe,m as me,mn as he,mt as ge,n as _e,o as ve,on as K,or as ye,ot as be,p as xe,pn as Se,pt as Ce,qr as we,r as Te,rn as Ee,s as De,sn as q,sr as Oe,st as ke,t as Ae,ut as je,vn as Me,vr as Ne,vt as Pe,wn as Fe,wr as Ie,yr as Le,zn as Re}from"./index-Gr2HWo-G.js";import{a as ze,p as Be,v as Ve}from"./cron-utils-_UjiWax6.js";import{a as He,c as Ue,i as J,l as We,n as Ge,o as Ke,r as qe,s as Je,t as Ye,u as Xe}from"./agents-Clv9i1Kb.js";var Y=n();function Ze(){return a(`rounded-xl border border-edge-subtle bg-surface-base px-4 py-1 sm:px-5`)}function Qe({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 $e=[{value:`default`,labelKey:`colorSchemeDefault`},{value:`emerald`,labelKey:`colorSchemeLightGreen`}];function et(){let e=q(o(e=>e.language)).appearanceSettings,t=D(e=>e.colorScheme),n=D(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:$e.map(({value:r,labelKey:i})=>{let o=t===r;return(0,Y.jsxs)(`button`,{type:`button`,"aria-pressed":o,onClick:()=>n(r),className:a(`flex flex-col gap-2 rounded-xl border-2 p-2.5 text-left transition-[border-color,box-shadow] duration-150`,o?`border-accent shadow-[0_0_0_1px_var(--color-accent)]`:`border-edge-subtle hover:border-edge`),children:[(0,Y.jsx)(Qe,{scheme:r}),(0,Y.jsx)(`span`,{className:a(`text-xs font-medium leading-none`,o?`text-accent-fg`:`text-fg-muted`),children:e[i]})]},r)})})]})}function tt(){let e=q(o(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:Ze(),"aria-labelledby":`pref-language-heading`,children:[(0,Y.jsx)(`h2`,{id:`pref-language-heading`,className:`sr-only`,children:e.languageTitle}),(0,Y.jsx)(F,{variant:`page`,sections:[`language`]})]}),(0,Y.jsxs)(`section`,{className:Ze(),"aria-labelledby":`pref-appearance-heading`,children:[(0,Y.jsx)(`h2`,{id:`pref-appearance-heading`,className:`sr-only`,children:e.themeTitle}),(0,Y.jsx)(F,{variant:`page`,sections:[`theme`,`font`]}),(0,Y.jsx)(et,{})]})]})}var X=e(t(),1);function nt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function rt(e){let t=nt(e)?e:{},n=nt(t.gateway)?t.gateway:{},r=nt(n.auth)?n.auth:{},i=r.mode===`none`||r.mode===`token`?r.mode:`token`,a=(nt(t.update)?t.update:{}).channel,o=a===`beta`||a===`dev`||a===`stable`?a:`stable`;return{host:typeof n.host==`string`?n.host:``,port:typeof n.port==`number`?n.port:void 0,auth:{mode:i,token:typeof r.token==`string`?r.token:``},updateChannel:o}}async function it(e){let t=e.auth.token.trim().length>0?{mode:e.auth.mode,token:e.auth.token}:{mode:e.auth.mode};await b(k(`/api/config`),{method:`PATCH`,body:JSON.stringify({gateway:{auth:t},update:{channel:e.updateChannel}})}),s()}function at(){return a(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,K,`dark:border-edge`)}function ot(){let e=o(e=>e.language),t=q(e),n=t.gatewaySettings,r=ee(e=>e.token),i=ee(e=>e.tokenExpired),a=ee(e=>e.openTokenDialog),s=!!r,[c,l]=(0,X.useState)(null),[u,d]=(0,X.useState)(null),[f,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(!1),[v,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(!1),S=(0,X.useRef)(!1),{data:C,error:T,isLoading:E,mutate:D}=W(s),O=(0,X.useMemo)(()=>C?.payload?.config===void 0?null:structuredClone(rt(C.payload.config)),[C]);(0,X.useEffect)(()=>{if(!s){l(null),d(null),S.current=!1;return}O!==null&&(S.current||(l(O),d(structuredClone(O)),_(!1)))},[s,O]);let te=!!(s&&E&&C===void 0&&!T),ne=T instanceof Error?T.message:T?String(T):null,k=(0,X.useMemo)(()=>!c||!u?!1:JSON.stringify(c)!==JSON.stringify(u),[c,u]),A=(0,X.useCallback)(e=>{S.current=!0,l(t=>t?{...t,auth:{...t.auth,...e}}:null)},[]),j=(0,X.useCallback)(e=>{S.current=!0,l(t=>t?{...t,updateChannel:e}:null)},[]),M=(0,X.useCallback)(async()=>{if(!(!c||f)){p(!0),h(null),_(!1);try{await it(c),S.current=!1,d(structuredClone(c)),_(!0),window.setTimeout(()=>_(!1),2500)}catch(e){h(e instanceof Error?e.message:n.saveError)}finally{p(!1)}}},[c,f,n.saveError]),F=(0,X.useCallback)(async()=>{let e=c?.auth.token;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),x(!0),window.setTimeout(()=>x(!1),2e3))},[c?.auth.token]);return s?te?(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)(P,{className:`size-4 animate-spin`}),n.loading]})}):c?(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.gateway}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,Y.jsxs)(`a`,{href:N(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)(Le,{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)(z,{type:`button`,variant:`primary`,disabled:!k||f,onClick:()=>void M(),children:f?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)(w,{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)(z,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:()=>a(),children:n.updateToken})})]}):null,k?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,m?(0,Y.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:m}):null,c.auth.mode===`none`?(0,Y.jsx)(`p`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-950 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-100`,children:n.authModeNone}):null,(0,Y.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[(0,Y.jsxs)(`div`,{className:`mb-5 flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)(de,{className:`size-4 text-accent`,strokeWidth:1.75}),t.settingsSections.gateway]}),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(c.host||c.port!=null)&&(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:n.listenHost}),(0,Y.jsx)(`div`,{className:`rounded-lg bg-surface-hover/80 px-3 py-2 font-mono text-xs text-fg-muted dark:bg-surface-hover/50`,children:c.host||`—`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:n.listenPort}),(0,Y.jsx)(`div`,{className:`rounded-lg bg-surface-hover/80 px-3 py-2 font-mono text-xs text-fg-muted dark:bg-surface-hover/50`,children:c.port==null?`—`:String(c.port)})]}),(0,Y.jsx)(`p`,{className:`sm:col-span-2 text-xs text-fg-subtle`,children:n.listenHint})]}),(0,Y.jsx)(st,{g:n,value:c.auth.token,show:v,copied:b,onToggleShow:()=>y(e=>!e),onCopy:()=>void F(),onChange:e=>A({token:e})}),(0,Y.jsx)(z,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,onClick:()=>a(),children:n.changeToken}),(0,Y.jsxs)(`div`,{className:`space-y-2 border-t border-edge pt-4`,children:[(0,Y.jsx)(`label`,{className:`text-sm font-medium text-fg`,htmlFor:`gateway-update-channel`,children:n.updateChannel}),(0,Y.jsxs)(`select`,{id:`gateway-update-channel`,value:c.updateChannel,onChange:e=>j(e.target.value),className:at(),children:[(0,Y.jsx)(`option`,{value:`stable`,children:n.channelStable}),(0,Y.jsx)(`option`,{value:`beta`,children:n.channelBeta}),(0,Y.jsx)(`option`,{value:`dev`,children:n.channelDev})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.updateChannelHint})]})]})]})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:m??ne??n.loadError}),(0,Y.jsx)(z,{type:`button`,variant:`secondary`,onClick:()=>void D(),children:n.retry})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.gateway}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}function st({g:e,value:t,show:n,copied:r,onToggleShow:i,onCopy:o,onChange:s}){return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.accessToken}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Y.jsx)(`input`,{className:a(at(),`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)(z,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:o,children:[r?(0,Y.jsx)(O,{className:`size-3.5`}):(0,Y.jsx)(Ie,{className:`size-3.5`}),r?e.copied:e.copy]}):null,(0,Y.jsxs)(z,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:i,children:[n?(0,Y.jsx)(Ne,{className:`size-3.5`}):(0,Y.jsx)(re,{className:`size-3.5`}),n?e.hide:e.show]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tokenHelp})]})}function ct(){return k(`/api/channels/status`)}var lt=Be;function ut(){return k(`/api/workspace/heartbeat-md`)}async function dt(){let e=await b(ut());return typeof e.payload?.content==`string`?e.payload.content:``}function ft(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function pt(e){let t=ft(e)?e:{},n=ft(t.gateway)?t.gateway:{},r=ft(n.heartbeat)?n.heartbeat:{},i=r.activeHours,a=ft(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 mt(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 ht(e){await b(k(`/api/config`),{method:`PATCH`,body:JSON.stringify({gateway:{heartbeat:mt(e)}})}),s()}async function gt(e){await b(k(`/api/workspace/heartbeat-md`),{method:`PUT`,body:JSON.stringify({content:e})}),i(ut())}async function _t(e){await b(k(`/api/heartbeat/trigger`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e?{reason:e}:{})})}var vt=[3e4,6e4,3e5,6e5,9e5,18e5,36e5,72e5],yt=new Set(vt);function bt(){return a(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,K,`dark:border-edge`)}function xt(){return a(R,Ee)}function St(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 Ct(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 wt(){let e=o(e=>e.language),t=q(e),n=t.heartbeatSettings,i=!!ee(e=>e.token),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(``),[p,m]=(0,X.useState)(``),[h,g]=(0,X.useState)(!1),[_,v]=(0,X.useState)(!1),[y,b]=(0,X.useState)(null),[x,S]=(0,X.useState)(!1),[C,w]=(0,X.useState)(!1),[T,E]=(0,X.useState)(!1),[D,O]=(0,X.useState)(!1),[te,ne]=(0,X.useState)(null),[k,A]=(0,X.useState)([]),{data:j,error:M,isLoading:F,mutate:re}=W(i),{data:I,error:L,isLoading:R,mutate:ie}=r(i?ut():null,dt,{revalidateOnFocus:!1}),{data:B=[]}=r(i?ct():null,lt,{revalidateOnFocus:!1}),oe=(0,X.useMemo)(()=>St(j?.payload?.config),[j]),se=(0,X.useMemo)(()=>pt(j?.payload?.config??{}),[j]),V=(0,X.useMemo)(()=>!s||!l?!1:JSON.stringify(s)!==JSON.stringify(l),[s,l]),H=(0,X.useMemo)(()=>d!==p,[d,p]);(0,X.useEffect)(()=>{if(!i){c(null),u(null);return}if(j!==void 0&&!V){let e=structuredClone(se);c(e),u(e),S(!1)}},[i,j,se,V]),(0,X.useEffect)(()=>{!i||I===void 0||H||(f(I),m(I),w(!1))},[i,I,H]);let U=M instanceof Error?M.message:M?String(M):L instanceof Error?L.message:L?String(L):null,ce=!!(i&&(j===void 0||I===void 0)&&!U&&(F||R));(0,X.useEffect)(()=>{if(!i||!s){A([]);return}let e=s.target.trim();if(!e){A([]);return}let t=!1;return Ve(e).then(e=>{t||A(e)}),()=>{t=!0}},[i,s?.target]);let le=(0,X.useCallback)(()=>{let e=s?.target?.trim();e&&Ve(e).then(A)},[s?.target]),G=(0,X.useCallback)(async()=>{E(!0),O(!1),ne(null);try{await _t(),O(!0),window.setTimeout(()=>O(!1),3e3)}catch(e){ne(e instanceof Error?e.message:n.triggerError)}finally{E(!1)}},[n.triggerError]),ue=(0,X.useCallback)(e=>{c(t=>t?{...t,...e}:null)},[]),de=(0,X.useCallback)(async()=>{if(!(!s||h)){g(!0),b(null),S(!1);try{await ht(s),u(structuredClone(s)),S(!0),window.setTimeout(()=>S(!1),2500)}catch(e){b(e instanceof Error?e.message:n.saveConfigError)}finally{g(!1)}}},[s,h,n.saveConfigError]),fe=(0,X.useCallback)(async()=>{if(!_){v(!0),b(null),w(!1);try{await gt(d),m(d),w(!0),window.setTimeout(()=>w(!1),2500)}catch(e){b(e instanceof Error?e.message:n.saveDocError)}finally{v(!1)}}},[d,_,n.saveDocError]);return i?ce?(0,Y.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,Y.jsx)(P,{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.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:N(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)(Le,{className:`size-3.5`})]})]})}),oe?(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.workspaceLabel,`: `,(0,Y.jsx)(`span`,{className:`font-mono text-fg-muted`,children:oe})]}):null,y?(0,Y.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:y}):null,(0,Y.jsxs)(Ge,{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)(ae,{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)(z,{type:`button`,variant:`secondary`,className:`inline-flex items-center gap-2`,disabled:T,onClick:()=>void G(),children:[T?(0,Y.jsx)(P,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(Re,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),T?n.triggering:n.triggerNow]}),D?(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}),te?(0,Y.jsx)(`p`,{className:`mb-3 text-sm text-red-600 dark:text-red-400`,children:te}):null,(0,Y.jsx)(Tt,{h:n,cron:t.cron,form:s,channels:B,sessionChatIds:k,onRefreshChatIds:le,update:ue,inputClassName:bt,selectClassName:xt}),(0,Y.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-2`,children:[x?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.savedConfig}):null,(0,Y.jsx)(z,{type:`button`,variant:`primary`,disabled:!V||h,onClick:()=>void de(),children:h?n.savingConfig:n.saveConfig}),V?(0,Y.jsx)(`span`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedConfig}):null]})]}),(0,Y.jsxs)(Ge,{children:[(0,Y.jsx)(`div`,{className:`mb-2 text-sm font-semibold text-fg`,children:n.docSection}),(0,Y.jsx)(`p`,{className:`mb-3 text-xs text-fg-subtle`,children:n.docHint}),(0,Y.jsx)(`textarea`,{className:a(bt(),`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:[C?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.savedDoc}):null,(0,Y.jsx)(z,{type:`button`,variant:`primary`,disabled:!H||_,onClick:()=>void fe(),children:_?n.savingDoc:n.saveDoc}),H?(0,Y.jsx)(`span`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedDoc}):null]})]})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:y??U??n.loadError}),(0,Y.jsx)(z,{type:`button`,variant:`secondary`,onClick:()=>{re(),ie()},children:n.retry})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.heartbeat}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}function Tt({h:e,cron:t,form:n,channels:r,sessionChatIds:i,onRefreshChatIds:o,update:s,inputClassName:c,selectClassName:l}){let u=(0,X.useMemo)(()=>new Set(r.map(e=>e.name)),[r]),d=n.target.trim(),f=!!(d&&!u.has(d)),p=(0,X.useMemo)(()=>yt.has(n.intervalMs)?String(n.intervalMs):``,[n.intervalMs]),[m,h]=(0,X.useState)(null),g=Math.max(1,Math.round(n.intervalMs/1e3)),_=m===null?String(g):m;return(0,X.useEffect)(()=>{h(null)},[n.intervalMs]),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:n.enabled,onChange:e=>s({enabled:e.target.checked})}),e.enable]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.interval}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:e.intervalSecondsLabel}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`input`,{type:`number`,min:1,step:1,className:a(c(),`min-w-0 flex-1`),value:_,onChange:e=>{let t=e.target.value;h(t);let n=parseInt(t,10);Number.isFinite(n)&&n>=1&&s({intervalMs:n*1e3})},onBlur:()=>{if(m===null)return;let e=parseInt(m,10);s(!Number.isFinite(e)||e<1?{intervalMs:1e3}:{intervalMs:e*1e3}),h(null)}}),(0,Y.jsxs)(`select`,{className:a(l(),`max-w-[11rem] shrink-0 text-xs`),value:p,onChange:e=>{let t=e.target.value;t&&(s({intervalMs:parseInt(t,10)}),h(null))},children:[(0,Y.jsx)(`option`,{value:``,children:e.intervalPresets.custom}),vt.map(t=>(0,Y.jsx)(`option`,{value:String(t),children:Ct(t,e.intervalPresets)},t))]})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.intervalHintPreset}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.intervalHint})]}),(0,Y.jsxs)(`div`,{className:`border-t border-edge-subtle pt-4`,children:[(0,Y.jsx)(`div`,{className:`mb-2 text-sm font-medium text-fg`,children:e.deliveryTitle}),(0,Y.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:t.channel}),(0,Y.jsxs)(`select`,{className:l(),value:d,onChange:e=>{s({target:e.target.value.trim(),targetChatId:``})},children:[(0,Y.jsx)(`option`,{value:``,children:e.channelNone}),f?(0,Y.jsxs)(`option`,{value:d,children:[d,` (`,e.customChannelSuffix,`)`]}):null,r.map(e=>(0,Y.jsxs)(`option`,{value:e.name,disabled:!e.enabled,children:[e.name,` `,e.enabled?``:`(disabled)`]},e.name))]})]}),d?(0,Y.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:t.recipient}),(0,Y.jsxs)(z,{type:`button`,variant:`ghost`,className:`h-7 gap-1 px-2 text-xs`,title:t.refreshRecipientHint,onClick:o,children:[(0,Y.jsx)(T,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0}),t.refreshList]})]}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`input`,{type:`text`,className:a(c(),`min-w-0 flex-1`),value:n.targetChatId,onChange:e=>s({targetChatId:e.target.value}),placeholder:t.recipientPlaceholder,autoComplete:`off`}),(0,Y.jsxs)(`select`,{className:a(l(),`max-w-[10rem] shrink-0 text-xs`),value:n.targetChatId,onChange:e=>{let t=e.target.value;t&&s({targetChatId:t})},children:[(0,Y.jsx)(`option`,{value:``,children:t.selectRecipient}),i.length>0?i.map(e=>(0,Y.jsx)(`option`,{value:e.chatId,children:ze(e,t.lastActiveLabels)},`${e.channel}-${e.chatId}`)):(0,Y.jsx)(`option`,{value:``,disabled:!0,children:t.noRecentChatsOption})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:i.length>0?t.enterManuallyOrSelect:t.noRecentChats})]}):null,(0,Y.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:e.deliveryHint})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:e.prompt}),(0,Y.jsx)(`textarea`,{className:a(c(),`min-h-[4.5rem] resize-y font-mono text-xs`),value:n.prompt,onChange:e=>s({prompt:e.target.value}),placeholder:e.promptPlaceholder}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:e.promptHint})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:e.ackMaxChars}),(0,Y.jsx)(`input`,{type:`number`,min:1,className:c(),value:n.ackMaxChars===``?``:n.ackMaxChars,onChange:e=>{let t=e.target.value;if(t===``)s({ackMaxChars:``});else{let e=parseInt(t,10);s({ackMaxChars:Number.isFinite(e)?e:``})}},placeholder:e.ackDefaultPlaceholder}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:e.ackMaxCharsHint})]}),(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:n.isolatedSession,onChange:e=>s({isolatedSession:e.target.checked})}),(0,Y.jsxs)(`span`,{children:[e.isolatedSession,(0,Y.jsx)(`span`,{className:`mt-1 block text-xs text-fg-subtle`,children:e.isolatedSessionHint})]})]}),(0,Y.jsxs)(`div`,{className:`border-t border-edge-subtle pt-4`,children:[(0,Y.jsx)(`div`,{className:`mb-2 text-sm font-medium text-fg`,children:e.activeHoursTitle}),n.activeHours?(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-xs text-fg`,children:e.activeStart}),(0,Y.jsx)(`input`,{className:c(),value:n.activeHours.start,onChange:e=>s({activeHours:{...n.activeHours,start:e.target.value}}),placeholder:`09:00`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-xs text-fg`,children:e.activeEnd}),(0,Y.jsx)(`input`,{className:c(),value:n.activeHours.end,onChange:e=>s({activeHours:{...n.activeHours,end:e.target.value}}),placeholder:`22:00`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-xs text-fg`,children:e.activeTimezone}),(0,Y.jsx)(`input`,{className:c(),value:n.activeHours.timezone,onChange:e=>s({activeHours:{...n.activeHours,timezone:e.target.value}}),placeholder:`Asia/Shanghai`})]})]}):(0,Y.jsx)(z,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:()=>s({activeHours:{start:`09:00`,end:`22:00`,timezone:``}}),children:e.addActiveHours}),n.activeHours?(0,Y.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:(0,Y.jsx)(z,{type:`button`,variant:`secondary`,className:`text-xs`,onClick:()=>s({activeHours:null}),children:e.clearActiveHours})}):null,(0,Y.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:e.activeHoursHint})]})]})}var Et=[{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 Dt(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 Ot(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 kt(){let e=await h(k(`/api/models-json`)),t=await e.json().catch(()=>({}));if(!e.ok||!t.ok||!t.payload)throw Error(Dt(t)||`HTTP ${e.status}`);return{...t.payload,config:Ot(t.payload.config)}}async function At(e){let t=await h(k(`/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(Dt(n)||`HTTP ${t.status}`);return n.payload}async function jt(e){let t=await h(k(`/api/models-json`),{method:`PATCH`,body:JSON.stringify({config:e})}),n=await t.json().catch(()=>({}));if(!t.ok||!n.ok||!n.payload)throw Error(Dt(n)||`HTTP ${t.status}`);return n.payload}async function Mt(){let e=await h(k(`/api/models-json/reload`),{method:`POST`}),t=await e.json().catch(()=>({}));if(!e.ok||!t.ok||!t.payload)throw Error(Dt(t)||`HTTP ${e.status}`);return t.payload}async function Nt(e){let t=await h(k(`/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(Dt(n)||`HTTP ${t.status}`);return n.payload}function Pt(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 Ft(e){return e.startsWith(`!`)}function It(e){return/^[A-Z][A-Z0-9_]*$/.test(e)}function Lt(e){return Ft(e)?`shell`:It(e)?`env`:`literal`}function Rt(e){return e?e.length<=8?`••••`:`${e.slice(0,4)}••••${e.slice(-4)}`:``}var zt={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 Bt(e){return e===`openrouter`?`openrouter`:e===`zhipuCn`?`zhipu-cn`:e===`zaiGeneral`?`zai`:e}var Vt=[{value:`text`,labelKey:`inputTextOnly`},{value:`text,image`,labelKey:`inputTextVision`}];function Ht(){return a(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,K,`dark:border-edge`)}function Ut(){return a(R,Ee)}function Wt(e){return(e.input||[`text`]).includes(`image`)?`text,image`:`text`}function Gt(e){return e===`text,image`?[`text`,`image`]:[`text`]}function Kt(e,t,n){return{...e,providers:{...e.providers,[t]:{...e.providers[t],...n}}}}function qt(e,t){let n={...e.providers};return delete n[t],{...e,providers:n}}function Jt(e,t,n){return{...e,providers:{...e.providers,[t]:n}}}function Yt({open:e,onOpenChange:t,presetKey:n,onConfirm:r,m:i}){let[o,s]=(0,X.useState)(``),[c,l]=(0,X.useState)(`custom`),[u,d]=(0,X.useState)(``),[f,p]=(0,X.useState)(`openai-completions`),[m,h]=(0,X.useState)(``),[g,_]=(0,X.useState)(null);(0,X.useEffect)(()=>{if(!e)return;_(null);let t=n||null;if(t&&zt[t]){let e=zt[t];l(t),d(e.baseUrl||``),p(e.api||`openai-completions`),h(e.apiKey??``),s(Bt(t))}else l(`custom`),s(``),d(``),p(`openai-completions`),h(``)},[e,n]);let v=e=>{if(l(e),e===`custom`)return;let t=zt[e];t&&(d(t.baseUrl||``),p(t.api||`openai-completions`),h(t.apiKey??``),s(Bt(e)))};return(0,Y.jsx)(se,{open:e,onOpenChange:t,children:(0,Y.jsxs)(je,{children:[(0,Y.jsx)(pe,{className:`xopc-dialog-overlay fixed inset-0 z-50 bg-scrim`}),(0,Y.jsxs)(ke,{className:a(`xopc-dialog-content fixed left-1/2 top-1/2 z-50 max-h-[min(90vh,640px)] w-[min(100%-2rem,32rem)] -translate-x-1/2 -translate-y-1/2`,`overflow-y-auto rounded-xl border border-edge bg-surface-panel p-4 shadow-popover dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,Y.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(H,{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)(be,{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:Ut(),value:c,onChange:e=>v(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:Ht(),value:o,onChange:e=>s(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:Ht(),value:u,onChange:e=>d(e.target.value),placeholder:`https://…`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:i.apiType}),(0,Y.jsx)(`select`,{className:Ut(),value:f,onChange:e=>p(e.target.value),children:Et.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:Ht(),value:m,onChange:e=>h(e.target.value),placeholder:i.apiKeyPlaceholder})]}),g?(0,Y.jsxs)(`p`,{className:`flex items-center gap-1 text-xs text-red-600 dark:text-red-400`,children:[(0,Y.jsx)(w,{className:`size-3.5 shrink-0`}),g]}):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)(be,{asChild:!0,children:(0,Y.jsx)(z,{type:`button`,variant:`secondary`,children:i.cancel})}),(0,Y.jsx)(z,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:()=>{let e=o.trim();if(!e){_(i.providerIdRequired);return}_(null),r(e,{baseUrl:u.trim()||void 0,api:f,apiKey:m.trim()||void 0,models:[]}),t(!1)},children:i.addProviderConfirm})]})]})]})})}function Xt({open:e,onOpenChange:t,providerId:n,model:r,isNew:i,onSave:o,m:s}){let[c,l]=(0,X.useState)(()=>Pt(``)),[u,d]=(0,X.useState)(()=>new Map);(0,X.useEffect)(()=>{e&&(d(new Map),l(r?{...r}:Pt(``)))},[e,r]);let f=(e,t)=>{l(n=>({...n,[e]:t})),d(t=>{let n=new Map(t);return n.delete(e),n})},p=()=>{let e=new Map;return(c.id||``).trim()||e.set(`id`,s.modelIdRequired),c.contextWindow!==void 0&&c.contextWindow<=0&&e.set(`contextWindow`,s.mustBePositive),c.maxTokens!==void 0&&c.maxTokens<=0&&e.set(`maxTokens`,s.mustBePositive),d(e),e.size===0},m=()=>{if(!p())return;let e=(c.id||``).trim();o({...c,id:e,name:c.name?.trim()||e,reasoning:c.reasoning||!1,input:c.input||[`text`],contextWindow:c.contextWindow??128e3,maxTokens:c.maxTokens??16384,cost:{input:c.cost?.input??0,output:c.cost?.output??0,cacheRead:c.cost?.cacheRead??0,cacheWrite:c.cost?.cacheWrite??0}}),t(!1)},h=Wt(c);return(0,Y.jsx)(se,{open:e,onOpenChange:t,children:(0,Y.jsxs)(je,{children:[(0,Y.jsx)(pe,{className:`xopc-dialog-overlay fixed inset-0 z-50 bg-scrim`}),(0,Y.jsxs)(ke,{className:a(`xopc-dialog-content fixed left-1/2 top-1/2 z-50 max-h-[min(90vh,720px)] w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2`,`overflow-y-auto rounded-xl border border-edge bg-surface-panel p-4 shadow-popover dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,Y.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(H,{className:`text-base font-semibold text-fg`,children:i?s.addModelTitle:s.editModelTitle}),n?(0,Y.jsxs)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:[s.modelProviderLabel,`: `,n]}):null]}),(0,Y.jsx)(be,{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":s.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:[s.modelId,(0,Y.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,Y.jsx)(`input`,{className:a(Ht(),u.has(`id`)&&`border-red-500`),value:c.id||``,onChange:e=>f(`id`,e.target.value),placeholder:`e.g. llama3.1:8b`,disabled:!i}),u.has(`id`)?(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:u.get(`id`)}):null]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.displayName}),(0,Y.jsx)(`input`,{className:Ht(),value:c.name||``,onChange:e=>f(`name`,e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.inputTypes}),(0,Y.jsx)(`select`,{className:Ut(),value:h,onChange:e=>f(`input`,Gt(e.target.value)),children:Vt.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:s[e.labelKey]},e.value))})]}),(0,Y.jsxs)(`label`,{className:`mt-6 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:c.reasoning||!1,onChange:e=>f(`reasoning`,e.target.checked)}),s.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:s.contextWindow}),(0,Y.jsx)(`input`,{type:`number`,min:1,className:a(Ht(),u.has(`contextWindow`)&&`border-red-500`),value:c.contextWindow??128e3,onChange:e=>f(`contextWindow`,parseInt(e.target.value,10)||0)}),u.has(`contextWindow`)?(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:u.get(`contextWindow`)}):null]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.maxOutputTokens}),(0,Y.jsx)(`input`,{type:`number`,min:1,className:a(Ht(),u.has(`maxTokens`)&&`border-red-500`),value:c.maxTokens??16384,onChange:e=>f(`maxTokens`,parseInt(e.target.value,10)||0)}),u.has(`maxTokens`)?(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:u.get(`maxTokens`)}):null]})]}),(0,Y.jsxs)(`div`,{className:`border-t border-edge-subtle pt-2 dark:border-edge`,children:[(0,Y.jsx)(`p`,{className:`mb-2 text-xs font-semibold text-fg`,children:s.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:s.costInput}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,min:0,className:Ht(),value:c.cost?.input??0,onChange:e=>f(`cost`,{...c.cost,input:parseFloat(e.target.value)||0,output:c.cost?.output??0,cacheRead:c.cost?.cacheRead??0,cacheWrite:c.cost?.cacheWrite??0})})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:s.costOutput}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,min:0,className:Ht(),value:c.cost?.output??0,onChange:e=>f(`cost`,{...c.cost,input:c.cost?.input??0,output:parseFloat(e.target.value)||0,cacheRead:c.cost?.cacheRead??0,cacheWrite:c.cost?.cacheWrite??0})})]})]})]})]}),(0,Y.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2 border-t border-edge-subtle pt-3 dark:border-edge`,children:[(0,Y.jsx)(be,{asChild:!0,children:(0,Y.jsx)(z,{type:`button`,variant:`secondary`,children:s.cancel})}),(0,Y.jsx)(z,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:m,children:i?s.addModelConfirm:s.saveModelConfirm})]})]})]})})}function Zt(){let e=o(e=>e.language),t=q(e),n=t.modelsSettings,r=!!ee(e=>e.token),[i,s]=(0,X.useState)({providers:{}}),[u,d]=(0,X.useState)({providers:{}}),[p,m]=(0,X.useState)(``),[h,v]=(0,X.useState)(),[y,b]=(0,X.useState)(!0),[C,E]=(0,X.useState)(!1),[D,O]=(0,X.useState)(!1),[te,ne]=(0,X.useState)(!1),[k,A]=(0,X.useState)(null),[j,M]=(0,X.useState)(!1),[F,I]=(0,X.useState)(null),[L,R]=(0,X.useState)(()=>new Set),[ie,ae]=(0,X.useState)(!1),[B,se]=(0,X.useState)(``),[V,H]=(0,X.useState)(null),[U,ce]=(0,X.useState)(()=>new Set),[le,W]=(0,X.useState)(()=>new Map),[G,ue]=(0,X.useState)(!1),[de,fe]=(0,X.useState)(null),[pe,me]=(0,X.useState)(!1),[he,ge]=(0,X.useState)(null),_e=(0,X.useCallback)(async e=>{let t=!e?.skipFullPageLoading;t&&b(!0),A(null);try{let e=await kt(),t=Ot(e.config);s(t),d(structuredClone(t)),m(e.path),v(e.loadError),I(null),M(!1)}catch(e){A(e instanceof Error?e.message:n.loadError),s({providers:{}}),d({providers:{}})}finally{t&&b(!1)}},[n.loadError]);(0,X.useEffect)(()=>{if(!r){b(!1);return}_e()},[r,_e]);let ve=(0,X.useMemo)(()=>JSON.stringify(i)!==JSON.stringify(u),[i,u]),K=(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]),ye=e=>{R(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},be=e=>{ce(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},xe=(0,X.useCallback)(()=>{se(JSON.stringify(i,null,2)),H(null)},[i]);(0,X.useEffect)(()=>{ie&&xe()},[ie,xe]);let Se=()=>{try{s(Ot(JSON.parse(B))),H(null)}catch{H(n.jsonParseError)}},Ce=async()=>{O(!0),A(null);try{I(await At(i))}catch(e){A(e instanceof Error?e.message:n.validateError)}finally{O(!1)}},we=async()=>{if(!C){E(!0),A(null),M(!1);try{await jt(i),d(structuredClone(i)),M(!0),I(null)}catch(e){A(e instanceof Error?e.message:n.saveError)}finally{E(!1)}}},Te=async()=>{ne(!0),A(null);try{await Mt(),await _e({skipFullPageLoading:!0})}catch(e){A(e instanceof Error?e.message:n.reloadError)}finally{ne(!1)}},Ee=async(e,t)=>{try{let n=await Nt(t);W(t=>{let r=new Map(t);return r.set(e,n),r})}catch(t){W(n=>{let r=new Map(n);return r.set(e,{type:`error`,error:t instanceof Error?t.message:`Error`}),r})}},De=(e=null)=>{fe(e),ue(!0)},Oe=(e,t)=>{s(n=>Jt(n,e,t)),R(t=>new Set(t).add(e))},ke=e=>{window.confirm(n.removeProviderConfirm.replace(`{{id}}`,e))&&(s(t=>qt(t,e)),W(t=>{let n=new Map(t);return n.delete(e),n}))},Ae=(e,t,n)=>{ge({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:N(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)(Le,{className:`size-3.5`})]})]}),h?(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)(w,{className:`mt-0.5 size-4 shrink-0`}),(0,Y.jsxs)(`span`,{children:[n.loadFileWarning,`: `,h]})]}):null,p?(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:p})]}):null,(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsxs)(z,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:()=>De(null),disabled:y,children:[(0,Y.jsx)(x,{className:`mr-1 size-4`}),n.addProvider]}),(0,Y.jsx)(z,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:Ce,disabled:y||D,children:D?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(P,{className:`mr-1 size-4 animate-spin`}),n.validating]}):n.validate}),(0,Y.jsx)(z,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:we,disabled:y||C||!ve,children:C?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(P,{className:`mr-1 size-4 animate-spin`}),n.saving]}):n.save}),(0,Y.jsx)(z,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[8.5rem] justify-center`,onClick:Te,disabled:y||te,children:te?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(P,{className:`mr-1 size-4 animate-spin`}),n.reloading]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(T,{className:`mr-1 size-4`}),n.reload]})}),(0,Y.jsx)(z,{type:`button`,variant:`ghost`,className:`text-fg-muted`,onClick:()=>{ae(e=>!e),H(null)},children:ie?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(K.providers))}),(0,Y.jsx)(`span`,{className:`text-fg-subtle`,children:`|`}),(0,Y.jsx)(`span`,{className:`text-fg-muted`,children:n.statsModels.replace(`{{count}}`,String(K.models))})]})]}),ve?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,j?(0,Y.jsx)(`p`,{className:`text-xs text-emerald-700 dark:text-emerald-400`,role:`status`,children:n.saved}):null,k?(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)(w,{className:`size-4 shrink-0`}),k]}):null,F&&F.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:F.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:F.errors.map((e,t)=>(0,Y.jsxs)(`li`,{children:[e.path,`: `,e.message,` (`,e.severity,`)`]},`${e.path}-${t}`))})]}):null,y?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,Y.jsx)(P,{className:`size-4 animate-spin`}),n.loading]}):ie?(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(`textarea`,{className:a(Ht(),`min-h-[320px] resize-y font-mono text-xs leading-relaxed`),value:B,onChange:e=>se(e.target.value),spellCheck:!1}),V?(0,Y.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:V}):null,(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(z,{type:`button`,variant:`secondary`,onClick:xe,children:n.jsonReset}),(0,Y.jsx)(z,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:Se,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)(l,{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)(z,{type:`button`,className:`mb-6 bg-accent text-white hover:bg-accent/90`,onClick:()=>De(null),children:[(0,Y.jsx)(x,{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:a(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,g.transition,g.focusRingBase),onClick:()=>De(`ollama`),children:[(0,Y.jsx)(oe,{className:`size-3.5`,"aria-hidden":!0}),n.presetOllama]}),(0,Y.jsxs)(`button`,{type:`button`,className:a(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,g.transition,g.focusRingBase),onClick:()=>De(`openrouter`),children:[(0,Y.jsx)(c,{className:`size-3.5`,"aria-hidden":!0}),n.presetOpenRouter]}),(0,Y.jsxs)(`button`,{type:`button`,className:a(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,g.transition,g.focusRingBase),onClick:()=>De(`lmstudio`),children:[(0,Y.jsx)(l,{className:`size-3.5`,"aria-hidden":!0}),n.presetLmStudio]}),(0,Y.jsxs)(`button`,{type:`button`,className:a(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,g.transition,g.focusRingBase),onClick:()=>De(`zhipuCn`),children:[(0,Y.jsx)(oe,{className:`size-3.5`,"aria-hidden":!0}),n.presetZhipuCn]}),(0,Y.jsxs)(`button`,{type:`button`,className:a(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,g.transition,g.focusRingBase),onClick:()=>De(`zaiGeneral`),children:[(0,Y.jsx)(c,{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?Lt(t.apiKey):null,c=le.get(e),l=U.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:()=>ye(e),children:[r?(0,Y.jsx)(S,{className:`size-4 shrink-0 text-fg-muted`}):(0,Y.jsx)(f,{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:a(`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:()=>ke(e),"aria-label":n.removeProvider,children:(0,Y.jsx)(Me,{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:Ht(),value:t.baseUrl||``,onChange:t=>s(n=>Kt(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:Ut(),value:t.api||`openai-completions`,onChange:t=>s(n=>Kt(n,e,{api:t.target.value})),children:Et.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:a(Ht(),`min-w-0 flex-1`),type:l?`text`:`password`,autoComplete:`off`,value:t.apiKey||``,onChange:t=>{let n=t.target.value;s(t=>Kt(t,e,{apiKey:n})),W(t=>{let n=new Map(t);return n.delete(e),n})},placeholder:n.apiKeyPlaceholder}),(0,Y.jsx)(z,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>be(e),children:l?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Ne,{className:`mr-1 size-3.5`}),n.hide]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(re,{className:`mr-1 size-3.5`}),n.show]})}),(0,Y.jsx)(z,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>Ee(e,t.apiKey||``),children:n.testKey})]}),c?(0,Y.jsx)(`p`,{className:a(`mt-1 text-xs`,c.error?`text-red-600 dark:text-red-400`:`text-emerald-700 dark:text-emerald-400`),children:c.error?`${n.testError}: ${c.error}`:`${n.testOk} (${c.type}): ${Rt(c.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=>s(n=>Kt(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)(z,{type:`button`,variant:`primary`,className:`px-2 py-1 text-xs`,onClick:()=>Ae(e,null,!0),children:[(0,Y.jsx)(x,{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:()=>Ae(e,t,!1),"aria-label":n.editModel,children:(0,Y.jsx)(_,{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))&&s(n=>{let r=n.providers[e];return r?Kt(n,e,{models:(r.models||[]).filter(e=>e.id!==t.id)}):n})},"aria-label":n.removeModel,children:(0,Y.jsx)(Me,{className:`size-4`})})]})]},t.id))})]})]}):null]},e)})}),(0,Y.jsx)(Yt,{open:G,onOpenChange:ue,presetKey:de,onConfirm:Oe,m:n}),(0,Y.jsx)(Xt,{open:pe,onOpenChange:e=>{me(e),e||ge(null)},providerId:he?.providerId??null,model:he?.model??null,isNew:he?.isNew??!1,onSave:e=>{if(!he)return;let{providerId:t,isNew:n}=he;s(r=>{let i=r.providers[t];if(!i)return r;let a=i.models||[];return n?Kt(r,t,{models:[...a,e]}):Kt(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 Qt(){return{enabled:!1,provider:`alibaba`,alibaba:{model:`paraformer-v2`},openai:{model:`whisper-1`},fallback:{enabled:!0,order:[`alibaba`,`openai`]}}}function $t(){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 en(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function tn(e){let t=Qt();if(!en(e))return t;let n=e.provider===`openai`?`openai`:`alibaba`,r=en(e.alibaba)?{...t.alibaba,...e.alibaba}:t.alibaba,i=en(e.openai)?{...t.openai,...e.openai}:t.openai,a=t.fallback??{enabled:!0,order:[`alibaba`,`openai`]};if(en(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 nn(e){return e===`openai`||e===`alibaba`||e===`edge`||e===`minimax`}function rn(e){let t=$t();if(!en(e))return t;let n=nn(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:en(e.alibaba)?{...t.alibaba,...e.alibaba}:t.alibaba,openai:en(e.openai)?{...t.openai,...e.openai}:t.openai,edge:en(e.edge)?{...t.edge,...e.edge}:t.edge,minimax:en(e.minimax)?{...t.minimax,...e.minimax}:t.minimax}}function an(e){let t=en(e)?e:{};return{stt:tn(t.stt),tts:rn(t.tts)}}async function on(e){await b(k(`/api/config`),{method:`PATCH`,body:JSON.stringify({stt:e.stt,tts:e.tts})}),s()}async function sn(){let e=await b(k(`/api/voice/models`));if(!e.payload?.models)throw Error(`Missing voice models payload`);return e.payload.models}function cn(){return a(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,K,`dark:border-edge`)}function ln(){return a(R,Ee)}var un=[{id:`paraformer-v2`,name:`Paraformer v2`},{id:`paraformer-v1`,name:`Paraformer v1`}],dn=[{id:`whisper-1`,name:`Whisper-1`}],fn=[{id:`tts-1`,name:`TTS-1`},{id:`tts-1-hd`,name:`TTS-1 HD`}],pn=[{id:`alloy`,name:`Alloy`},{id:`echo`,name:`Echo`}],mn=[{id:`qwen-tts`,name:`Qwen TTS`},{id:`qwen3-tts-flash`,name:`Qwen3 TTS Flash`}],hn=[{id:`Cherry`,name:`Cherry`},{id:`longxiaochun`,name:`Long Xiao Chun`}],gn=[{id:`en-US-MichelleNeural`,name:`Michelle (US English)`},{id:`zh-CN-XiaoxiaoNeural`,name:`Xiaoxiao (Chinese)`}],_n=[{id:`speech-2.8-hd`,name:`Speech 2.8 HD (Recommended)`},{id:`speech-2.8-turbo`,name:`Speech 2.8 Turbo (Fast)`}],vn=[{id:`male-qn-qingse`,name:`Male Qingse (青涩男声)`},{id:`female-shaonv`,name:`Female Shaonv (少女音)`}];function yn(){let e=o(e=>e.language),t=q(e),n=t.voiceSettings,i=!!ee(e=>e.token),[a,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),[u,d]=(0,X.useState)(null),[f,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(!1),{data:v,error:y,isLoading:b,mutate:x}=W(i),{data:S,error:C,isLoading:w,mutate:T}=r(i?k(`/api/voice/models`):null,sn,{revalidateOnFocus:!1}),E=(0,X.useMemo)(()=>v?.payload?.config===void 0?null:an(v.payload.config),[v]),D=(0,X.useMemo)(()=>!a||!c?!1:JSON.stringify(a)!==JSON.stringify(c),[a,c]);(0,X.useEffect)(()=>{if(!i){s(null),l(null),d(null);return}E===null||S===void 0||D||(s(structuredClone(E)),l(structuredClone(E)),d(S),_(!1))},[i,E,S,D]);let O=!!(i&&(E===null||S===void 0)&&(b||w)),te=y instanceof Error?y.message:y?String(y):C instanceof Error?C.message:C?String(C):null,ne=(0,X.useCallback)(e=>{s(t=>t?{...t,stt:{...t.stt,...e}}:null)},[]),A=(0,X.useCallback)(e=>{s(t=>t?{...t,stt:{...t.stt,alibaba:{...t.stt.alibaba,...e}}}:null)},[]),j=(0,X.useCallback)(e=>{s(t=>t?{...t,stt:{...t.stt,openai:{...t.stt.openai,...e}}}:null)},[]),M=(0,X.useCallback)(e=>{s(t=>{if(!t)return null;let n=t.stt.fallback??{enabled:!0,order:[`alibaba`,`openai`]};return{...t,stt:{...t.stt,fallback:{...n,...e}}}})},[]),F=(0,X.useCallback)(e=>{s(t=>t?{...t,tts:{...t.tts,...e}}:null)},[]),re=(0,X.useCallback)(e=>{s(t=>t?{...t,tts:{...t.tts,alibaba:{...t.tts.alibaba,...e}}}:null)},[]),I=(0,X.useCallback)(e=>{s(t=>t?{...t,tts:{...t.tts,openai:{...t.tts.openai,...e}}}:null)},[]),L=(0,X.useCallback)(e=>{s(t=>t?{...t,tts:{...t.tts,edge:{...t.tts.edge,...e}}}:null)},[]),R=(0,X.useCallback)(e=>{s(t=>t?{...t,tts:{...t.tts,minimax:{...t.tts.minimax,...e}}}:null)},[]),ie=(0,X.useCallback)(async()=>{if(!(!a||f)){p(!0),h(null),_(!1);try{await on(a);let e=structuredClone(a);l(e),s(e),_(!0),window.setTimeout(()=>_(!1),2500)}catch(e){h(e instanceof Error?e.message:n.saveError)}finally{p(!1)}}},[a,f,n.saveError]);if(!i)return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.voice}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]});if(O)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)(P,{className:`size-4 animate-spin`}),n.loading]})});if(!a||u===null)return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:m??te??n.loadError}),(0,Y.jsx)(z,{type:`button`,variant:`secondary`,onClick:()=>{x(),T()},children:n.retry})]});let ae=a.stt,B=a.tts;return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.voice}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,Y.jsxs)(`a`,{href:N(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)(Le,{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)(z,{type:`button`,variant:`primary`,disabled:!D||f,onClick:()=>void ie(),children:f?n.saving:n.save})]})]}),D?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,m?(0,Y.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:m}):null,(0,Y.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Y.jsx)(bn,{v:n,stt:ae,models:u,updateStt:ne,updateSttAlibaba:A,updateSttOpenai:j,updateSttFallback:M}),(0,Y.jsx)(xn,{v:n,tts:B,models:u,updateTts:F,updateTtsAlibaba:re,updateTtsOpenai:I,updateTtsEdge:L,updateTtsMinimax:R})]}),(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 bn({v:e,stt:t,models:n,updateStt:r,updateSttAlibaba:i,updateSttOpenai:o,updateSttFallback:s}){let c=n?.stt?.alibaba?.length?n.stt.alibaba:un,l=n?.stt?.openai?.length?n.stt.openai:dn;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)(m,{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)(Z,{children:e.stt.provider}),(0,Y.jsxs)(`select`,{className:ln(),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)(Z,{children:e.stt.apiKey}),(0,Y.jsx)(`input`,{className:a(cn(),`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)(Z,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:ln(),value:t.alibaba?.model??``,onChange:e=>i({model:e.target.value}),children:c.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}):(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(Z,{children:e.stt.apiKey}),(0,Y.jsx)(`input`,{className:a(cn(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.openai?.apiKey??``,onChange:e=>o({apiKey:e.target.value}),placeholder:`sk-...`}),(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (OPENAI_API_KEY)`]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(Z,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:ln(),value:t.openai?.model??``,onChange:e=>o({model:e.target.value}),children:l.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.stt.fallback}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.stt.fallbackDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:t.fallback?.enabled??!0,onChange:e=>s({enabled:e.target.checked})})]})]}):null]})]})}function xn({v:e,tts:t,models:n,updateTts:r,updateTtsAlibaba:i,updateTtsOpenai:o,updateTtsEdge:s,updateTtsMinimax:c}){let l=t=>t===`off`?e.tts.triggerDescOff:t===`always`?e.tts.triggerDescAlways:t===`inbound`?e.tts.triggerDescInbound:t===`tagged`?e.tts.triggerDescTagged:``,u=n?.tts?.openai?.length?n.tts.openai:fn,d=n?.ttsVoices?.openai?.length?n.ttsVoices.openai:pn,f=n?.tts?.alibaba?.length?n.tts.alibaba:mn,p=n?.ttsVoices?.alibaba?.length?n.ttsVoices.alibaba:hn,m=n?.ttsVoices?.edge?.length?n.ttsVoices.edge:gn,h=n?.tts?.minimax?.length?n.tts.minimax:_n,g=n?.ttsVoices?.minimax?.length?n.ttsVoices.minimax:vn;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)(he,{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)(Z,{children:e.tts.trigger}),(0,Y.jsxs)(`select`,{className:ln(),value:t.trigger,onChange:e=>r({trigger:e.target.value}),children:[(0,Y.jsx)(`option`,{value:`off`,children:e.tts.triggerOff}),(0,Y.jsx)(`option`,{value:`always`,children:e.tts.triggerAlways}),(0,Y.jsx)(`option`,{value:`inbound`,children:e.tts.triggerInbound}),(0,Y.jsx)(`option`,{value:`tagged`,children:e.tts.triggerTagged})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:l(t.trigger)})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(Z,{children:e.tts.provider}),(0,Y.jsxs)(`select`,{className:ln(),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)(Z,{children:e.stt.apiKey}),(0,Y.jsx)(`input`,{className:a(cn(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.openai?.apiKey??``,onChange:e=>o({apiKey:e.target.value}),placeholder:`sk-...`}),(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (OPENAI_API_KEY)`]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(Z,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:ln(),value:t.openai?.model??``,onChange:e=>o({model:e.target.value}),children:u.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(Z,{children:e.tts.voice}),(0,Y.jsx)(`select`,{className:ln(),value:t.openai?.voice??``,onChange:e=>o({voice:e.target.value}),children:d.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}):null,t.provider===`alibaba`?(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,Y.jsx)(Z,{children:e.stt.apiKey}),(0,Y.jsx)(`input`,{className:a(cn(),`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)(Z,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:ln(),value:t.alibaba?.model??``,onChange:e=>i({model:e.target.value}),children:f.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(Z,{children:e.tts.voice}),(0,Y.jsx)(`select`,{className:ln(),value:t.alibaba?.voice??``,onChange:e=>i({voice:e.target.value}),children:p.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}):null,t.provider===`minimax`?(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,Y.jsx)(Z,{children:e.stt.apiKey}),(0,Y.jsx)(`input`,{className:a(cn(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.minimax?.apiKey??``,onChange:e=>c({apiKey:e.target.value}),placeholder:`eyJ...`}),(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (MINIMAX_API_KEY)`]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(Z,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:ln(),value:t.minimax?.model??``,onChange:e=>c({model:e.target.value}),children:h.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(Z,{children:e.tts.voice}),(0,Y.jsx)(`select`,{className:ln(),value:t.minimax?.voice??``,onChange:e=>c({voice:e.target.value}),children:g.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)(Z,{children:e.tts.voice}),(0,Y.jsx)(`select`,{className:ln(),value:t.edge?.voice??``,onChange:e=>s({voice:e.target.value}),children:m.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.edgeHint})]}):null]}):null]})]})}function Z({children:e}){return(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e})}function Sn(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 Cn(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 b(k(`/api/config`),{method:`PATCH`,body:JSON.stringify({tools:{web:{region:t,search:n}}})}),s()}function wn({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 Tn(){return a(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,K,`dark:border-edge`)}function En(){return a(R,Ee)}var Dn=[`brave`,`tavily`,`bing`,`searxng`];function On(){return{type:`brave`,apiKey:``,url:``,disabled:!1}}function kn(){let e=o(e=>e.language),t=q(e),n=t.webSearchSettings,r=t.logs,i=!!ee(e=>e.token),[a,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(null),[m,h]=(0,X.useState)(!1),g=(0,X.useRef)(!1),{data:_,error:v,isLoading:y,mutate:b}=W(i),S=(0,X.useMemo)(()=>_?.payload?.config===void 0?null:Sn(_.payload.config),[_]);(0,X.useEffect)(()=>{if(!i){s(null),l(null),g.current=!1;return}S!==null&&(g.current||(s(S),l(S)))},[i,S]);let C=!!(i&&y&&_===void 0&&!v),w=v instanceof Error?v.message:v?String(v):null,T=(0,X.useMemo)(()=>!a||!c?!1:JSON.stringify(a)!==JSON.stringify(c),[a,c]),E=(0,X.useCallback)(e=>{g.current=!0,s(t=>t?{...t,...e}:null)},[]),D=(0,X.useCallback)(async()=>{if(!(!a||u)){d(!0),p(null),h(!1);try{await Cn(a),g.current=!1,h(!0),window.setTimeout(()=>h(!1),2500)}catch(e){p(e instanceof Error?e.message:n.saveError)}finally{d(!1)}}},[a,u,n.saveError]);return i?C?(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col items-center gap-3 px-4 py-8`,children:[(0,Y.jsx)(P,{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:N(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)(Le,{className:`size-3.5`})]})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[m?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,Y.jsx)(z,{type:`button`,variant:`primary`,disabled:!T||u,onClick:()=>void D(),children:u?n.saving:n.save})]})]}),T?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,f?(0,Y.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:f}):null,(0,Y.jsxs)(Ge,{children:[(0,Y.jsx)(qe,{icon:G,title:n.sectionRegion,subtitle:n.sectionRegionHint}),(0,Y.jsx)(`div`,{className:`flex max-w-md flex-col gap-4`,children:(0,Y.jsx)(wn,{label:n.regionLabel,description:n.regionDesc,children:(0,Y.jsxs)(`select`,{className:En(),value:a.regionMode,onChange:e=>E({regionMode:e.target.value}),children:[(0,Y.jsx)(`option`,{value:`auto`,children:n.regionAuto}),(0,Y.jsx)(`option`,{value:`cn`,children:n.regionCn}),(0,Y.jsx)(`option`,{value:`global`,children:n.regionGlobal})]})})})]}),(0,Y.jsxs)(Ge,{children:[(0,Y.jsx)(qe,{icon:G,title:n.sectionSearch,subtitle:n.sectionSearchHint}),(0,Y.jsxs)(`div`,{className:`flex max-w-xl flex-col gap-6`,children:[(0,Y.jsx)(wn,{label:n.maxResultsLabel,description:n.maxResultsDesc,children:(0,Y.jsx)(`input`,{type:`number`,min:1,max:50,className:Tn(),value:a.maxResults,onChange:e=>E({maxResults:Math.max(1,Math.min(50,Number(e.target.value)||5))})})}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.providersTitle}),a.providers.map((e,t)=>(0,Y.jsx)(An,{row:e,labels:n,onChange:e=>{let n=[...a.providers];n[t]=e,E({providers:n})},onRemove:()=>{E({providers:a.providers.filter((e,n)=>n!==t)})}},t)),(0,Y.jsxs)(z,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5 text-sm`,onClick:()=>E({providers:[...a.providers,On()]}),children:[(0,Y.jsx)(x,{className:`size-4`}),n.addProvider]})]})]})]}),(0,Y.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:n.footerHint})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:f??w??n.loadError}),(0,Y.jsx)(z,{type:`button`,variant:`secondary`,onClick:()=>void b(),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 An({row:e,labels:t,onChange:n,onRemove:r}){return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-xl border border-edge-subtle bg-surface-panel/60 p-4 dark:border-edge-subtle`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,Y.jsx)(`select`,{className:a(En(),`min-w-[8rem]`),value:e.type,onChange:t=>n({...e,type:t.target.value,url:t.target.value===`searxng`?e.url:``}),children:Dn.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)(z,{type:`button`,variant:`ghost`,className:`h-8 px-2 text-fg-muted`,onClick:r,children:(0,Y.jsx)(Me,{className:`size-4`})})]})]}),e.type===`searxng`?(0,Y.jsx)(wn,{label:t.urlLabel,description:t.urlDesc,children:(0,Y.jsx)(`input`,{type:`url`,className:Tn(),value:e.url,placeholder:`http://localhost:8080`,onChange:t=>n({...e,url:t.target.value})})}):null,(0,Y.jsx)(wn,{label:t.apiKeyLabel,description:t.apiKeyDesc,children:(0,Y.jsx)(`input`,{type:`password`,autoComplete:`off`,className:Tn(),value:_e(e.apiKey)?``:e.apiKey,placeholder:_e(e.apiKey)?t.keyPlaceholderMasked:t.keyPlaceholder,onChange:t=>n({...e,apiKey:t.target.value})})})]})}var jn=[{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 Mn(e,t){let n=q(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 Nn(){let e=o(e=>e.language),t=q(e).systemSettings,[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(null),[s,c]=(0,X.useState)(null),l=typeof window<`u`?window.electronAPI?.system:void 0,u=(0,X.useCallback)(async()=>{if(l){c(null);try{r(await l.getBehavior()),a(await l.getPermissions())}catch(e){c(e instanceof Error?e.message:String(e))}}},[l]);if((0,X.useEffect)(()=>{p()&&l&&u()},[l,u]),!p()||!l)return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.title}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:t.desktopOnlyTitle}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:t.desktopOnlyBody})]})]});let f=async e=>{try{let{behavior:t}=await l.setBehavior(e);r(t)}catch(e){c(e instanceof Error?e.message:String(e))}},m=async e=>{try{(await l.openPrivacy(e)).ok||c(`open_privacy failed`)}catch(e){c(e instanceof Error?e.message:String(e))}},h=n?n.platform===`win32`?t.permissionsHintWin:n.platform===`linux`?t.permissionsHintLinux:n.platform===`darwin`?t.permissionsHintDarwin:t.permissionsHint:t.permissionsHint;return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[(0,Y.jsx)(`div`,{children:(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.title})}),s?(0,Y.jsx)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:s}):null,(0,Y.jsxs)(Ge,{children:[(0,Y.jsxs)(`div`,{className:`mb-4 flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)(d,{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=>{f({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=>{f({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=>{f({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=>{f({notifySoundEnabled:e.target.checked})}})]})]})]}),n&&i?(0,Y.jsxs)(`section`,{className:J(),children:[(0,Y.jsxs)(`div`,{className:`mb-4 flex flex-col gap-1 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:t.permissionsTitle}),(0,Y.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:h})]}),(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:jn.map(({key:r,pane:o})=>{let s=Mn(e,i[r]),u=t.perm[r];return u?(0,Y.jsxs)(`li`,{className:`flex flex-col gap-2 rounded-xl border border-edge-subtle bg-surface-panel/60 px-3 py-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:u.title}),(0,Y.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:u.desc}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs font-medium ${s.className}`,children:s.label})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[r===`microphone`&&n?.platform===`darwin`?(0,Y.jsx)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover`,onClick:()=>{(async()=>{try{await l.requestMicrophone(),a(await l.getPermissions())}catch(e){c(e instanceof Error?e.message:String(e))}})()},children:e===`zh`?`请求访问`:`Request`}):null,(0,Y.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover`,onClick:()=>void m(o),children:[t.openSettings,(0,Y.jsx)(Le,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0})]})]})]},r):null})})]}):null]})}function Pn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var Fn={enabled:!0,cron:`0 */6 * * *`,lookbackDays:1,limit:50,dedupeSimilarity:.85},In={enabled:!0,cron:`0 3 * * *`,minScore:.8,minRecallCount:3,limit:10,recencyHalfLifeDays:14,maxAgeDays:30},Ln={enabled:!0,cron:`0 5 * * 0`,lookbackDays:7,limit:20,minPatternStrength:.6},Rn={enabled:!1,frequency:`0 3 * * *`,timezone:``,deepEnabled:!0,minScore:.8,minRecallCount:3,limit:10,light:Fn,deep:In,rem:Ln};function zn(e,t){return Number.isFinite(e)?Math.max(0,Math.min(1,e)):t}function Bn(e,t){let n=typeof e==`string`?Number(e):e;return Number.isFinite(n)?Math.max(0,Math.floor(n)):t}function Vn(e,t){let n=typeof e==`string`?Number(e):e;return Number.isFinite(n)?n:t}function Hn(e){let t=Pn(e)?e:{},n=Pn(t.agents)?t.agents:{},r=Pn(n.defaults)?n.defaults:{},i=Pn(r.memory)?r.memory:{},a=Pn(i.dreaming)?i.dreaming:{},o=Pn(a.phases)?a.phases:{},s=Pn(o.light)?o.light:{},c=Pn(o.deep)?o.deep:{},l=Pn(o.rem)?o.rem:{};return{enabled:a.enabled===!0,frequency:typeof a.frequency==`string`&&a.frequency.trim()?a.frequency.trim():Rn.frequency,timezone:typeof a.timezone==`string`?a.timezone:``,deepEnabled:c.enabled!==!1,minScore:zn(typeof c.minScore==`number`?c.minScore:Number(c.minScore),Rn.minScore),minRecallCount:Math.max(1,Bn(c.minRecallCount,Rn.minRecallCount)),limit:Bn(c.limit,Rn.limit),light:{enabled:s.enabled!==!1,cron:typeof s.cron==`string`&&s.cron.trim()?s.cron.trim():Fn.cron,lookbackDays:Math.max(1,Bn(s.lookbackDays,Fn.lookbackDays)),limit:Bn(s.limit,Fn.limit),dedupeSimilarity:zn(Vn(s.dedupeSimilarity,Fn.dedupeSimilarity),Fn.dedupeSimilarity)},deep:{enabled:c.enabled!==!1,cron:typeof c.cron==`string`&&c.cron.trim()?c.cron.trim():In.cron,minScore:zn(Vn(c.minScore,In.minScore),In.minScore),minRecallCount:Math.max(1,Bn(c.minRecallCount,In.minRecallCount)),limit:Bn(c.limit,In.limit),recencyHalfLifeDays:Math.max(1,Vn(c.recencyHalfLifeDays,In.recencyHalfLifeDays)),maxAgeDays:Math.max(1,Vn(c.maxAgeDays,In.maxAgeDays))},rem:{enabled:l.enabled!==!1,cron:typeof l.cron==`string`&&l.cron.trim()?l.cron.trim():Ln.cron,lookbackDays:Math.max(1,Bn(l.lookbackDays,Ln.lookbackDays)),limit:Bn(l.limit,Ln.limit),minPatternStrength:zn(Vn(l.minPatternStrength,Ln.minPatternStrength),Ln.minPatternStrength)}}}async function Un(e){let t=e.frequency.trim(),n=e.timezone.trim();await b(k(`/api/config`),{method:`PATCH`,body:JSON.stringify({agents:{defaults:{memory:{dreaming:{enabled:!!e.enabled,frequency:t||null,timezone:n||null,phases:{light:{enabled:!!e.light.enabled,cron:e.light.cron.trim()||null,lookbackDays:Math.max(1,Math.floor(e.light.lookbackDays)),limit:Math.max(0,Math.floor(e.light.limit)),dedupeSimilarity:zn(e.light.dedupeSimilarity,Fn.dedupeSimilarity)},deep:{enabled:!!e.deep.enabled,cron:e.deep.cron.trim()||null,minScore:zn(e.deep.minScore,In.minScore),minRecallCount:Math.max(1,Math.floor(e.deep.minRecallCount)),limit:Math.max(0,Math.floor(e.deep.limit)),recencyHalfLifeDays:Math.max(1,e.deep.recencyHalfLifeDays),maxAgeDays:Math.max(1,e.deep.maxAgeDays)},rem:{enabled:!!e.rem.enabled,cron:e.rem.cron.trim()||null,lookbackDays:Math.max(1,Math.floor(e.rem.lookbackDays)),limit:Math.max(0,Math.floor(e.rem.limit)),minPatternStrength:zn(e.rem.minPatternStrength,Ln.minPatternStrength)}}}}}}})}),s()}function Q(){return`text-xs font-medium text-fg-muted`}function $(){return`text-sm font-medium text-fg`}function Wn(e){return e?e.replace(`T`,` `).replace(`Z`,``):`—`}function Gn(e){return e===void 0||!Number.isFinite(e)||e<0?`—`:e<1e3?`${Math.round(e)} ms`:`${(e/1e3).toFixed(2)} s`}function Kn({label:e,children:t,className:n}){return(0,Y.jsxs)(`div`,{className:a(`space-y-2`,n),children:[(0,Y.jsx)(`h3`,{className:`text-[0.7rem] font-semibold uppercase tracking-wider text-fg-muted`,children:e}),t]})}function qn({icon:e,label:t,enabled:n,cron:r,details:i,t:o}){return(0,Y.jsxs)(`div`,{className:a(J(),`space-y-1.5`),children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e,(0,Y.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:t}),(0,Y.jsx)(`span`,{className:a(`ml-auto text-xs font-medium`,n?`text-emerald-600 dark:text-emerald-400`:`text-fg-muted`),children:n?o.on:o.off})]}),(0,Y.jsx)(`div`,{className:`font-mono text-xs text-fg-muted`,children:r}),(0,Y.jsx)(`div`,{className:`text-xs text-fg-muted`,children:i})]})}function Jn({label:e,lastRun:t,t:n}){return(0,Y.jsx)(Kn,{label:e,children:t?.exists?(0,Y.jsxs)(`details`,{className:`group rounded-lg border border-edge-subtle`,children:[(0,Y.jsx)(`summary`,{className:`cursor-pointer list-none px-3 py-2 text-xs font-medium text-fg-muted marker:hidden [&::-webkit-details-marker]:hidden`,children:(0,Y.jsx)(`span`,{className:`underline decoration-edge underline-offset-2 group-open:text-fg`,children:n.lastRunRaw})}),(0,Y.jsx)(`pre`,{className:`max-h-[12rem] overflow-auto border-t border-edge-subtle p-3 text-xs text-fg-muted`,children:JSON.stringify(t.raw,null,2)})]}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.phaseLastRunEmpty})})}function Yn({t:e,r:t}){let n=t.deep?.skipped;return(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.lastRunStatus}),(0,Y.jsx)(`div`,{className:a($(),t.ok?`text-emerald-600 dark:text-emerald-400`:`text-amber-600 dark:text-amber-400`),children:t.ok?e.lastRunSuccess:e.lastRunFailure})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.lastRunDuration}),(0,Y.jsx)(`div`,{className:$(),children:Gn(t.durationMs)})]}),(0,Y.jsxs)(`div`,{className:a(J(),`sm:col-span-2`),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.lastRunReason}),(0,Y.jsx)(`div`,{className:$(),children:t.reason}),t.errorMessage?(0,Y.jsx)(`div`,{className:`mt-1 text-xs text-amber-600 dark:text-amber-400`,children:`${e.lastRunError}: ${t.errorMessage}`}):null]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.lastRunRanked}),(0,Y.jsx)(`div`,{className:$(),children:String(t.deep?.candidatesRanked??`—`)})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.lastRunApplied}),(0,Y.jsx)(`div`,{className:$(),children:String(t.deep?.applied??`—`)})]}),n?(0,Y.jsxs)(`div`,{className:`sm:col-span-2`,children:[(0,Y.jsx)(`div`,{className:`mb-2 text-xs font-medium text-fg`,children:e.lastRunSkipped}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.lastRunSkipKey}),(0,Y.jsx)(`div`,{className:$(),children:String(n.alreadyPromotedKey)})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.lastRunSkipRehydrate}),(0,Y.jsx)(`div`,{className:$(),children:String(n.rehydrateFailed)})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.lastRunSkipContaminated}),(0,Y.jsx)(`div`,{className:$(),children:String(n.contaminated)})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.lastRunSkipHash}),(0,Y.jsx)(`div`,{className:$(),children:String(n.hashDuplicate)})]})]})]}):null]})}function Xn(e,t){return e.locked?{text:t.lockValueLocked,className:`text-amber-600 dark:text-amber-400`}:{text:t.lockValueUnlocked,className:`text-emerald-600 dark:text-emerald-400`}}function Zn(){let e=q(o(e=>e.language)).dreamingSettings,t=!!ee(e=>e.token),{data:n}=W(t),[i,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(!1),[_,v]=(0,X.useState)(null),[y,b]=(0,X.useState)(`deep`),[x,S]=(0,X.useState)(null),[w,E]=(0,X.useState)(null),[D,O]=(0,X.useState)(!1),[k,j]=(0,X.useState)(!1),[M,N]=(0,X.useState)(null),[F,re]=(0,X.useState)(!1),[I,L]=(0,X.useState)(null),[R,ie]=(0,X.useState)(null),[ae,B]=(0,X.useState)(!1),[oe,se]=(0,X.useState)(null),[V,H]=(0,X.useState)(null),{data:U,error:ce,isLoading:le,mutate:G}=r(t?He():null,Ue,{revalidateOnFocus:!1}),ue=(0,X.useMemo)(()=>U?Xn(U.lock,e):null,[U,e]),de=(0,X.useMemo)(()=>{let e=[];return ce&&e.push(ce instanceof Error?ce.message:String(ce)),c&&e.push(c),_&&e.push(_),I&&e.push(I),oe&&e.push(oe),M&&e.push(M),e},[ce,c,_,I,oe,M]),fe=(0,X.useMemo)(()=>{let t=[];return k&&t.push(e.configSaved),h&&t.push(e.runQueued),d&&t.push(e.actionOk),t},[k,h,d,e]),pe=(0,X.useCallback)(async()=>{f(!1),l(null),g(!1),v(null),j(!1),N(null),L(null),await G()},[G]),me=(0,X.useCallback)(async()=>{re(!0),L(null);try{ie((await Je(20)).items??[])}catch(e){L(e instanceof Error?e.message:String(e))}finally{re(!1)}},[]),he=(0,X.useCallback)(async()=>{B(!0),se(null);try{H(await Ke(50))}catch(e){se(e instanceof Error?e.message:String(e))}finally{B(!1)}},[]),ge=(0,X.useCallback)(async(e=`deep`)=>{m(!0),g(!1),v(null);try{await Xe(e),g(!0),await G()}catch(e){v(e instanceof Error?e.message:String(e))}finally{m(!1)}},[G]),_e=(0,X.useCallback)(async e=>{s(e),l(null),f(!1);try{await We(e),f(!0),await G()}catch(e){l(e instanceof Error?e.message:String(e))}finally{s(null)}},[G]),ve=!t||le||!!i,K=(0,X.useMemo)(()=>{let e=n?.payload?.config;return Hn(e??{})},[n]);(0,X.useEffect)(()=>{if(t){if(!w){E(K),S(K);return}JSON.stringify(K)!==JSON.stringify(w)&&(E(K),S(K))}},[w,K,t]);let ye=(0,X.useMemo)(()=>!x||!w?!1:JSON.stringify(x)!==JSON.stringify(w),[x,w]),be=(0,X.useCallback)(async()=>{if(x){O(!0),j(!1),N(null);try{await Un(x),E(x),j(!0),await G()}catch(e){N(e instanceof Error?e.message:String(e))}finally{O(!1)}}},[x,G]);return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:e.title}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e.subtitle})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 items-center justify-end gap-2`,children:[(0,Y.jsxs)(`select`,{className:`rounded-lg border border-edge bg-surface-panel px-2 py-1.5 text-xs text-fg`,value:y,onChange:e=>b(e.target.value),disabled:!t||p,children:[(0,Y.jsx)(`option`,{value:`light`,children:`Light`}),(0,Y.jsx)(`option`,{value:`deep`,children:`Deep`}),(0,Y.jsx)(`option`,{value:`rem`,children:`REM`})]}),(0,Y.jsxs)(z,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||p,onClick:()=>void ge(y),title:e.runNowHint,children:[p?(0,Y.jsx)(P,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(Re,{className:`mr-2 size-4`,"aria-hidden":!0}),e.runNow]}),(0,Y.jsxs)(z,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t,onClick:()=>void pe(),children:[(0,Y.jsx)(T,{className:`mr-2 size-4`,"aria-hidden":!0}),e.refresh]})]})]}),de.length>0?(0,Y.jsx)(`div`,{className:`space-y-1.5 rounded-2xl border border-amber-500/20 bg-amber-500/5 px-4 py-3`,role:`alert`,children:de.map((e,t)=>(0,Y.jsx)(`p`,{className:`text-sm text-amber-800 dark:text-amber-200/90`,children:e},t))}):null,fe.length>0?(0,Y.jsx)(`div`,{className:`space-y-1.5 rounded-2xl border border-emerald-500/20 bg-emerald-500/5 px-4 py-3`,role:`status`,children:fe.map((e,t)=>(0,Y.jsx)(`p`,{className:`text-sm text-emerald-800 dark:text-emerald-200/90`,children:e},t))}):null,(0,Y.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,Y.jsxs)(Ge,{className:`min-w-0`,children:[(0,Y.jsx)(qe,{icon:u,title:e.configTitle,subtitle:e.configHint,trailing:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(z,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||!x||D||!ye,onClick:()=>void be(),children:[D?(0,Y.jsx)(P,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,e.saveConfig]}),(0,Y.jsx)(z,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||!x||D||!ye,onClick:()=>{j(!1),N(null),S(w)},children:e.resetConfig})]})}),x?(0,Y.jsxs)(`div`,{className:`space-y-5`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-3`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configEnabled}),(0,Y.jsxs)(`label`,{className:`mt-2 inline-flex items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:x.enabled,onChange:e=>S({...x,enabled:e.target.checked})}),(0,Y.jsx)(`span`,{children:x.enabled?e.on:e.off})]})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configFrequency}),(0,Y.jsx)(`input`,{className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle dark:border-edge`,value:x.frequency,onChange:e=>S({...x,frequency:e.target.value}),placeholder:`0 3 * * *`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configTimezone}),(0,Y.jsx)(`input`,{className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle dark:border-edge`,value:x.timezone,onChange:e=>S({...x,timezone:e.target.value}),placeholder:`Asia/Shanghai`})]})]}),(0,Y.jsxs)(Kn,{label:e.configPhaseLight,children:[(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.configPhaseLightHint}),(0,Y.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configPhaseEnabled}),(0,Y.jsxs)(`label`,{className:`mt-2 inline-flex items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:x.light.enabled,onChange:e=>S({...x,light:{...x.light,enabled:e.target.checked}})}),(0,Y.jsx)(`span`,{children:x.light.enabled?e.on:e.off})]})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configPhaseCron}),(0,Y.jsx)(`input`,{className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.light.cron,onChange:e=>S({...x,light:{...x.light,cron:e.target.value}}),placeholder:`0 */6 * * *`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configLightLookbackDays}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.light.lookbackDays,onChange:e=>S({...x,light:{...x.light,lookbackDays:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configLightLimit}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:0,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.light.limit,onChange:e=>S({...x,light:{...x.light,limit:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configLightDedupe}),(0,Y.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.light.dedupeSimilarity,onChange:e=>S({...x,light:{...x.light,dedupeSimilarity:Number(e.target.value)}})})]})]})]}),(0,Y.jsxs)(Kn,{label:e.configPhaseDeep,children:[(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.configPhaseDeepHint}),(0,Y.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configPhaseEnabled}),(0,Y.jsxs)(`label`,{className:`mt-2 inline-flex items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:x.deep.enabled,onChange:e=>S({...x,deep:{...x.deep,enabled:e.target.checked}})}),(0,Y.jsx)(`span`,{children:x.deep.enabled?e.on:e.off})]})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configPhaseCron}),(0,Y.jsx)(`input`,{className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.deep.cron,onChange:e=>S({...x,deep:{...x.deep,cron:e.target.value}}),placeholder:`0 3 * * *`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configDeepMinScore}),(0,Y.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.deep.minScore,onChange:e=>S({...x,deep:{...x.deep,minScore:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configDeepMinRecallCount}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.deep.minRecallCount,onChange:e=>S({...x,deep:{...x.deep,minRecallCount:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configDeepLimit}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:0,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.deep.limit,onChange:e=>S({...x,deep:{...x.deep,limit:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configDeepHalfLife}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.deep.recencyHalfLifeDays,onChange:e=>S({...x,deep:{...x.deep,recencyHalfLifeDays:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configDeepMaxAge}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.deep.maxAgeDays,onChange:e=>S({...x,deep:{...x.deep,maxAgeDays:Number(e.target.value)}})})]})]})]}),(0,Y.jsxs)(Kn,{label:e.configPhaseRem,children:[(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.configPhaseRemHint}),(0,Y.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configPhaseEnabled}),(0,Y.jsxs)(`label`,{className:`mt-2 inline-flex items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:x.rem.enabled,onChange:e=>S({...x,rem:{...x.rem,enabled:e.target.checked}})}),(0,Y.jsx)(`span`,{children:x.rem.enabled?e.on:e.off})]})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configPhaseCron}),(0,Y.jsx)(`input`,{className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.rem.cron,onChange:e=>S({...x,rem:{...x.rem,cron:e.target.value}}),placeholder:`0 5 * * 0`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configRemLookbackDays}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.rem.lookbackDays,onChange:e=>S({...x,rem:{...x.rem,lookbackDays:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configRemLimit}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:0,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.rem.limit,onChange:e=>S({...x,rem:{...x.rem,limit:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configRemMinStrength}),(0,Y.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.rem.minPatternStrength,onChange:e=>S({...x,rem:{...x.rem,minPatternStrength:Number(e.target.value)}})})]})]})]})]}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.configLoading})]}),(0,Y.jsxs)(Ge,{className:`min-w-0`,children:[(0,Y.jsx)(qe,{icon:we,title:e.runtimeTitle,subtitle:e.runtimeHint,trailing:le?(0,Y.jsx)(P,{className:`size-4 shrink-0 animate-spin text-fg-muted`,"aria-hidden":!0}):null}),(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsx)(Kn,{label:e.subsectionSchedule,children:(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.enabled}),(0,Y.jsx)(`div`,{className:$(),children:U?U.config.enabled?e.on:e.off:`—`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.lock}),(0,Y.jsx)(`div`,{className:a($(),ue?.className),children:ue?ue.text:`—`})]}),(0,Y.jsxs)(`div`,{className:a(J(),`sm:col-span-2`),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.schedule}),(0,Y.jsx)(`div`,{className:`mt-1 break-all font-mono text-sm text-fg`,children:U?U.config.frequency:`—`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.timezone}),(0,Y.jsx)(`div`,{className:$(),children:U?U.config.timezone:`—`})]})]})}),(0,Y.jsx)(Kn,{label:e.subsectionStore,children:(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.storeEntries}),(0,Y.jsx)(`div`,{className:$(),children:U?String(U.store.entryCount):`—`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.storePromoted}),(0,Y.jsx)(`div`,{className:$(),children:U?String(U.store.promotedCount):`—`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.storeUpdatedAt}),(0,Y.jsx)(`div`,{className:$(),children:U?Wn(U.store.updatedAt):`—`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.storeLastPromotedAt}),(0,Y.jsx)(`div`,{className:$(),children:U?Wn(U.store.lastPromotedAt):`—`})]})]})}),U?.config?.phases?(0,Y.jsx)(Kn,{label:e.subsectionPhases,children:(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-3`,children:[(0,Y.jsx)(qn,{icon:(0,Y.jsx)(te,{className:`size-4 text-amber-500`}),label:`Light`,enabled:U.config.phases.light.enabled,cron:U.config.phases.light.cron,details:`lookback=${U.config.phases.light.lookbackDays}d, limit=${U.config.phases.light.limit}, dedupe=${U.config.phases.light.dedupeSimilarity}`,t:e}),(0,Y.jsx)(qn,{icon:(0,Y.jsx)(ne,{className:`size-4 text-indigo-500`}),label:`Deep`,enabled:U.config.phases.deep.enabled,cron:U.config.phases.deep.cron,details:`minScore=${U.config.phases.deep.minScore}, recalls≥${U.config.phases.deep.minRecallCount}, limit=${U.config.phases.deep.limit}, halfLife=${U.config.phases.deep.recencyHalfLifeDays}d`,t:e}),(0,Y.jsx)(qn,{icon:(0,Y.jsx)(Fe,{className:`size-4 text-purple-500`}),label:`REM`,enabled:U.config.phases.rem.enabled,cron:U.config.phases.rem.cron,details:`lookback=${U.config.phases.rem.lookbackDays}d, limit=${U.config.phases.rem.limit}, strength≥${U.config.phases.rem.minPatternStrength}`,t:e})]})}):null,(0,Y.jsxs)(Kn,{label:e.subsectionLastRun,children:[(0,Y.jsx)(`p`,{className:`mb-2 text-xs text-fg-muted`,children:e.lastRunBlockHint}),U?.lastRun?.exists?(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[U.lastRun.parseError?(0,Y.jsxs)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:[e.lastRunParseError,`: `,U.lastRun.parseError]}):null,U.lastRun.record?(0,Y.jsx)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel/40 p-2 sm:p-3`,children:(0,Y.jsx)(Yn,{t:e,r:U.lastRun.record})}):null,U.lastRun.raw!==void 0&&U.lastRun.raw!==null?(0,Y.jsxs)(`details`,{className:`group rounded-lg border border-edge-subtle`,children:[(0,Y.jsx)(`summary`,{className:`cursor-pointer list-none px-3 py-2 text-xs font-medium text-fg-muted marker:hidden [&::-webkit-details-marker]:hidden`,children:(0,Y.jsx)(`span`,{className:`underline decoration-edge underline-offset-2 group-open:text-fg`,children:e.lastRunRaw})}),(0,Y.jsx)(`pre`,{className:`max-h-[12rem] overflow-auto border-t border-edge-subtle p-3 text-xs text-fg-muted`,children:JSON.stringify(U.lastRun.raw,null,2)})]}):null]}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.lastRunEmpty})]}),(0,Y.jsx)(Jn,{label:e.subsectionLightLastRun,lastRun:U?.lightLastRun,t:e}),(0,Y.jsx)(Jn,{label:e.subsectionRemLastRun,lastRun:U?.remLastRun,t:e})]})]})]}),(0,Y.jsxs)(Ge,{children:[(0,Y.jsx)(qe,{icon:C,title:e.previewTitle,subtitle:e.previewHint,trailing:(0,Y.jsxs)(z,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||F,onClick:()=>void me(),children:[F?(0,Y.jsx)(P,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,e.previewLoad]})}),R?R.length>0?(0,Y.jsx)(`div`,{className:`space-y-2`,children:R.map(t=>{let n=`${t.path}:${t.startLine}-${t.endLine}`,r=t.skippedReason;return(0,Y.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel/60 px-3 py-3`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-fg-muted`,children:[(0,Y.jsx)(`span`,{className:`font-medium text-fg`,children:n}),(0,Y.jsxs)(`span`,{children:[`score=`,t.score.toFixed(3)]}),(0,Y.jsxs)(`span`,{children:[`recalls=`,t.recallCount]}),(0,Y.jsxs)(`span`,{children:[`avg=`,t.avgScore.toFixed(3)]}),(0,Y.jsxs)(`span`,{children:[`decay=`,t.recencyDecay?.toFixed(3)??`—`]}),r?(0,Y.jsx)(`span`,{className:`text-amber-600 dark:text-amber-400`,children:r}):(0,Y.jsx)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:e.previewEligible})]}),t.snippet?(0,Y.jsx)(`div`,{className:`mt-2 text-sm text-fg`,children:t.snippet}):null]},`${t.key}:${t.hash}:${n}`)})}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.previewEmpty}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.previewNotLoaded})]}),(0,Y.jsxs)(Ge,{children:[(0,Y.jsx)(qe,{icon:we,title:e.eventsTitle,subtitle:e.eventsHint,trailing:(0,Y.jsxs)(z,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||ae,onClick:()=>void he(),children:[ae?(0,Y.jsx)(P,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,e.eventsLoad]})}),V?V.length>0?(0,Y.jsx)(`div`,{className:`space-y-1.5`,children:V.map((e,t)=>{let n=e.phase===`light`?`☀️`:e.phase===`rem`?`✨`:`🌙`,r=e.phase===`light`?`scanned=${e.scannedEntries??0} new=${e.newSignals??0} deduped=${e.deduped??0}`:e.phase===`rem`?`patterns=${e.patternsDiscovered??0} analyzed=${e.entriesAnalyzed??0}`:`candidates=${e.candidates??0} applied=${e.applied??0}`;return(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 rounded-lg border border-edge-subtle bg-surface-panel/60 px-3 py-2 text-xs`,children:[(0,Y.jsx)(`span`,{children:n}),(0,Y.jsx)(`span`,{className:`font-medium text-fg`,children:e.phase}),(0,Y.jsx)(`span`,{className:a(`font-medium`,e.ok?`text-emerald-600 dark:text-emerald-400`:`text-amber-600 dark:text-amber-400`),children:e.ok?`OK`:`FAIL`}),(0,Y.jsx)(`span`,{className:`text-fg-muted`,children:r}),(0,Y.jsx)(`span`,{className:`text-fg-muted`,children:Gn(e.durationMs)}),(0,Y.jsx)(`span`,{className:`ml-auto text-fg-subtle`,children:Wn(e.timestamp)})]},`${e.timestamp}:${e.phase}:${t}`)})}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.eventsEmpty}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.eventsNotLoaded})]}),(0,Y.jsxs)(Ge,{className:`max-w-2xl`,children:[(0,Y.jsx)(qe,{icon:Se,title:e.maintenanceTitle,subtitle:e.maintenanceHint}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,Y.jsxs)(z,{variant:`secondary`,disabled:ve,onClick:()=>{confirm(e.confirmResetStore)&&_e(`reset_store`)},children:[i===`reset_store`?(0,Y.jsx)(P,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(Me,{className:`mr-2 size-4`,"aria-hidden":!0}),e.resetStore]}),(0,Y.jsxs)(z,{variant:`secondary`,disabled:ve,onClick:()=>{confirm(e.confirmClearLock)&&_e(`clear_lock`)},children:[i===`clear_lock`?(0,Y.jsx)(P,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(A,{className:`mr-2 size-4`,"aria-hidden":!0}),e.clearLock]})]})]})]})}function Qn({open:e,title:t,description:n,confirmLabel:r,cancelLabel:i,destructive:o,onConfirm:s,onCancel:c}){return(0,Y.jsx)(se,{open:e,onOpenChange:e=>{e||c()},children:(0,Y.jsxs)(je,{children:[(0,Y.jsx)(pe,{className:`xopc-dialog-overlay fixed inset-0 z-[70] bg-scrim backdrop-blur-[1px]`}),(0,Y.jsxs)(ke,{className:a(`fixed left-1/2 top-1/2 z-[70] w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2`,`rounded-2xl border border-edge bg-surface-panel p-6 shadow-popover outline-none dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,Y.jsx)(H,{className:`text-base font-semibold text-fg`,children:t}),(0,Y.jsx)(B,{className:`mt-2 text-sm text-fg-muted`,children:n}),(0,Y.jsxs)(`div`,{className:`mt-6 flex justify-end gap-2`,children:[(0,Y.jsx)(z,{type:`button`,variant:`secondary`,onClick:c,children:i}),(0,Y.jsx)(z,{type:`button`,variant:`secondary`,className:a(o&&`border-danger/40 bg-danger text-white hover:bg-danger/90 dark:border-danger/40`),onClick:s,children:r})]})]})]})})}async function $n(e){let t=await h(k(`/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 er(e){let t=await h(k(`/api/auth/oauth-async/${encodeURIComponent(e)}/status`));if(!t.ok)throw Error(`OAuth status: ${t.status}`);return(await t.json()).payload}async function tr(e,t){let n=await h(k(`/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 nr(e){let t=await h(k(`/api/auth/oauth-async/${encodeURIComponent(e)}/cancel`),{method:`POST`});if(!t.ok)throw Error(`Cancel OAuth failed: ${t.status}`)}async function rr(e){let t=await h(k(`/api/auth/oauth-async/${encodeURIComponent(e)}`),{method:`DELETE`});if(!t.ok)throw Error(`Cleanup session failed: ${t.status}`)}async function ir(e){let t=await h(k(`/api/auth/oauth/${encodeURIComponent(e)}`),{method:`DELETE`});if(!t.ok)throw Error(`Revoke OAuth failed: ${t.status}`)}function ar({providerId:e,language:t}){let n=De[e];if(!n)return null;let r=t===`zh`,i=r&&n.descriptionZh?n.descriptionZh:n.description;return i?(0,Y.jsxs)(I,{children:[(0,Y.jsx)(Pe,{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)(Oe,{className:`size-3.5`,"aria-hidden":!0})})}),(0,Y.jsx)(U,{children:(0,Y.jsxs)(ce,{side:`right`,align:`start`,sideOffset:6,className:a(`z-50 w-64 rounded-xl border border-edge bg-surface-panel p-3 shadow-md`,`data-[state=open]:animate-in data-[state=closed]:animate-out`,`data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,`data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95`),children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs font-semibold text-fg`,children:e}),(0,Y.jsx)(ge,{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)(Le,{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)(Le,{className:`size-3`,"aria-hidden":!0})]}):null]}):null,(0,Y.jsx)(Ce,{className:`fill-edge`})]})})]}):null}var or=[`common`,`specialty`,`enterprise`,`oauth`,`extension`];function sr(e){let t=new Map;for(let e of or)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 cr(e,t){return e.replace(/\{\{(\w+)\}\}/g,(e,n)=>String(t[n]??``))}function lr(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 ur(){let e=o(e=>e.language),t=q(e),n=t.providersSettings,i=!!ee(e=>e.token),[s,c]=(0,X.useState)({}),[l,u]=(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`])),[x,C]=(0,X.useState)(``),[w,T]=(0,X.useState)(!1),[E,D]=(0,X.useState)(()=>new Set),O=(0,X.useRef)(``),te=k(`/api/providers/meta`),ne=(0,X.useCallback)(async e=>(await b(e)).payload?.providers??[],[]),{data:A,error:j,isLoading:M,mutate:P}=W(i),{data:F,error:re,isLoading:I,mutate:R}=r(i?te:null,ne,{revalidateOnFocus:!1}),{data:ie,mutate:ae}=r(i?xe:null,()=>me(),{revalidateOnFocus:!1}),B=(0,X.useMemo)(()=>!F||A===void 0?null:Te(F,L(A.payload?.config),ie??[]),[F,A,ie]),oe=j instanceof Error?j.message:j?String(j):re instanceof Error?re.message:re?String(re):null,se=!!(i&&B===null&&(M||I)&&!oe),V=(0,X.useMemo)(()=>JSON.stringify(s)!==JSON.stringify(l),[s,l]);(0,X.useEffect)(()=>{if(!V)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[V]),(0,X.useEffect)(()=>{if(!(!i||B===null)&&!V){let e={};for(let t of B)e[t.id]=t.apiKey;c(e),u({...e})}},[i,B,V]);let H=B??[],U=(0,X.useMemo)(()=>{let e=H,t=x.trim().toLowerCase();return t&&(e=e.filter(e=>{let n=De[e.id]?.aliases??[];return e.id.toLowerCase().includes(t)||e.name.toLowerCase().includes(t)||n.some(e=>e.toLowerCase().includes(t))})),w&&(e=e.filter(e=>!e.configured)),e},[H,x,w]),ce=(0,X.useMemo)(()=>sr(U),[U]);(0,X.useEffect)(()=>{let e=O.current;if(O.current=x,x.trim()){let e=new Set;for(let t of or)(ce.get(t)??[]).length>0&&e.add(t);v(e);return}e.trim()&&v(new Set([`common`]))},[x,ce]);let de=(0,X.useCallback)(async()=>{if(d)return;let e={};for(let t of Object.keys(s)){let n=s[t]?.trim()??``;!n||_e(n)||(e[t]=n)}if(Object.keys(e).length===0){u({...s}),g(`noChanges`),window.setTimeout(()=>g(null),2500);return}f(!0),m(null),g(null);try{await le(e),D(new Set(Object.keys(e)));let t=await ae(me(!0))??ie??[],[n,r]=await Promise.all([P(),R()]),i=Array.isArray(r)?r:F??[],a=n??A;if(a?.payload){let e=Te(i,L(a.payload.config),t),n={};for(let t of e)n[t.id]=t.apiKey;c(n),u({...n})}g(`saved`),window.setTimeout(()=>g(null),2500)}catch(e){m(e instanceof Error?e.message:n.saveError)}finally{f(!1)}},[A,s,F,ie,P,R,ae,n.saveError,d]),fe=(0,X.useCallback)(()=>{c({...l}),m(null),g(null),D(new Set)},[l]),pe=e=>{v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},he=(0,X.useCallback)(()=>{P(),R()},[P,R]),ge=!!(x.trim()||w);return i?se?(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})]}):H.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??oe??n.empty})]}),(0,Y.jsx)(z,{type:`button`,variant:`secondary`,onClick:()=>{P(),R()},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)(z,{type:`button`,variant:`secondary`,disabled:!V||d,onClick:fe,children:n.discard}),(0,Y.jsx)(z,{type:`button`,variant:`primary`,disabled:!V||d,onClick:()=>void de(),children:d?n.saving:n.save})]})]}),V?(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:N(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)(y,{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)(G,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-fg-subtle`,strokeWidth:1.75,"aria-hidden":!0}),(0,Y.jsx)(`input`,{type:`search`,value:x,onChange:e=>C(e.target.value),placeholder:n.searchPlaceholder,autoComplete:`off`,className:a(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-10 pr-3 text-sm text-fg placeholder:text-fg-subtle`,K,`dark:border-edge`),"aria-label":n.searchPlaceholder})]}),(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg-muted`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:w,onChange:e=>T(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]}),ge?(0,Y.jsx)(z,{type:`button`,variant:`ghost`,className:`h-9 w-fit self-start text-fg-muted`,onClick:()=>{C(``),T(!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,U.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)(z,{type:`button`,variant:`secondary`,className:`mt-4`,onClick:()=>{C(``),T(!1)},children:n.clearFilters})]}):(0,Y.jsx)(`div`,{className:`flex flex-col gap-3`,children:or.map(t=>{let r=ce.get(t)??[];if(r.length===0)return null;let i=_.has(t),o=r.filter(e=>e.configured).length,u=`providers-cat-${t}`;return(0,Y.jsxs)(`section`,{className:`overflow-hidden rounded-2xl bg-surface-base`,children:[(0,Y.jsxs)(`button`,{type:`button`,id:`${u}-trigger`,"aria-expanded":i,"aria-controls":u,className:`flex w-full items-center justify-between gap-2 border-b border-edge-subtle px-4 py-3 text-left transition-colors hover:bg-surface-hover/60 dark:border-edge-subtle`,onClick:()=>pe(t),children:[(0,Y.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)(`span`,{className:`truncate`,children:n.categories[t]}),(0,Y.jsx)(`span`,{className:`shrink-0 rounded bg-surface-hover px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-fg-subtle`,children:r.length})]}),(0,Y.jsxs)(`span`,{className:`flex shrink-0 items-center gap-2`,children:[o>0?(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-fg-subtle`,children:[(0,Y.jsx)(ue,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}),cr(n.configuredCount,{count:String(o)})]}):null,(0,Y.jsx)(S,{className:a(`size-4 text-fg-subtle transition-transform`,i&&`rotate-180`),"aria-hidden":!0})]})]}),i?(0,Y.jsx)(`div`,{id:u,role:`region`,"aria-labelledby":`${u}-trigger`,className:`divide-y divide-edge-subtle`,children:r.map(t=>(0,Y.jsx)(`div`,{id:`provider-row-${t.id}`,children:(0,Y.jsx)(fr,{row:t,value:s[t.id]??``,rowDirty:(s[t.id]??``)!==(l[t.id]??``),labels:n,language:e,onChange:(e,t)=>c(n=>({...n,[e]:t})),onReload:he,justSaved:E.has(t.id),availableModels:ie??[]})},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)(ye,{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 dr({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)(ue,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):(0,Y.jsx)(Ie,{className:`size-3.5`,"aria-hidden":!0})})]})}function fr({row:e,value:t,rowDirty:n,labels:r,language:i,onChange:o,onReload:s,justSaved:c,availableModels:l}){let[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)(!1),[_,y]=(0,X.useState)(null),[ee,b]=(0,X.useState)(!1),[x,C]=(0,X.useState)(null),[T,E]=(0,X.useState)(!1),D=_e(t),O=D&&!f?``:t,te=e.configured&&!D&&!!t,[ne,k]=(0,X.useState)(!1),[A,M]=(0,X.useState)(),[N,F]=(0,X.useState)(),[I,L]=(0,X.useState)(),[R,ae]=(0,X.useState)(),[B,oe]=(0,X.useState)(),[se,H]=(0,X.useState)(``),[U,ce]=(0,X.useState)(!1),[le,W]=(0,X.useState)(null),[G,de]=(0,X.useState)(null),pe=e.activeKeySource??`none`,me=(0,X.useMemo)(()=>ie(e.id,i),[e.id,i]);(0,X.useEffect)(()=>()=>{A&&rr(A).catch(()=>{})},[A]),(0,X.useEffect)(()=>{if(!A||!ne)return;let e=window.setInterval(()=>{(async()=>{try{let t=await er(A);L(t.message),ae(t.authUrl),oe(t.instructions),t.status===`waiting_auth`||t.status===`waiting_code`?F(t.status===`waiting_code`?`waiting_code`:`waiting`):t.status===`completed`?(window.clearInterval(e),k(!1),F(`success`),L(t.message),window.setTimeout(()=>s(),800)):(t.status===`failed`||t.status===`cancelled`)&&(window.clearInterval(e),k(!1),F(`error`),L(t.error||t.message||`OAuth failed`))}catch{}})()},1e3);return()=>window.clearInterval(e)},[A,ne,s]);let he=async()=>{k(!0),F(`waiting`),L(r.oauthStarting),M(void 0),ae(void 0),oe(void 0);try{M((await $n(e.id)).sessionId)}catch(e){F(`error`),L(e instanceof Error?e.message:`OAuth failed`),k(!1)}},ge=async()=>{if(A){try{await nr(A)}catch{}M(void 0),k(!1),F(`idle`),L(void 0)}},be=async()=>{if(!(!A||!se.trim()))try{await tr(A,se.trim()),H(``),L(r.oauthProcessingCode)}catch(e){F(`error`),L(e instanceof Error?e.message:`Failed`)}},xe=()=>{window.confirm(cr(r.revokeConfirm,{name:e.name}))&&(y(null),ir(e.id).then(()=>s()).catch(e=>y(e instanceof Error?e.message:r.revokeFailed)))},Se=async()=>{E(!1),b(!0),C(null);try{await Ae(e.id),C(r.removeKeySuccess),o(e.id,``),window.setTimeout(()=>s(),600)}catch(e){C(e instanceof Error?e.message:r.removeKeyFailed)}finally{b(!1)}},Ce=e.configured&&D&&pe!==`env`&&pe!==`extension`&&pe!==`models_json`,we=async()=>{if(!(!t||D))try{await navigator.clipboard.writeText(t),h(!0),window.setTimeout(()=>h(!1),2e3)}catch{}},Te=async()=>{let e=t.trim();if(!(!e||_e(e))){ce(!0),W(null),de(null);try{let t=await ve(e);if(t.error){de(!1),W(`${r.testFailed} ${t.error}`);return}de(!0),t.type===`env`?W(r.testOkEnv):t.type===`command`?W(r.testOkCommand):W(r.testOkLiteral)}catch(e){de(!1),W(e instanceof Error?e.message:r.testFailed)}finally{ce(!1)}}},Ee=n?r.metaWillSave:e.configured?D?`${r.metaMasked} · ${r.runtimeLabelPrefix} ${lr(r,pe)}`:`${r.runtimeLabelPrefix} ${lr(r,pe)}`:r.metaNotConfigured,q=`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)(ue,{className:`size-4 text-emerald-600 dark:text-emerald-400`}):(0,Y.jsx)(ye,{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)(ar,{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:Ee})]}),(0,Y.jsx)(z,{type:`button`,variant:`ghost`,className:`h-9 w-9 shrink-0 p-0`,"aria-expanded":u,"aria-controls":q,"aria-label":r.expandRowDetails,onClick:()=>d(e=>!e),children:(0,Y.jsx)(S,{className:a(`size-4 transition-transform`,u&&`rotate-180`),"aria-hidden":!0})})]}),u?(0,Y.jsxs)(`div`,{id:q,role:`region`,className:`space-y-3 border-t border-edge-subtle bg-surface-base/40 px-3 py-3 dark:bg-surface-base/20 sm:px-4`,children:[e.supportsApiKey===!1?null:(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsxs)(`div`,{className:`relative flex flex-col gap-2 sm:flex-row sm:gap-2`,children:[(0,Y.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,Y.jsx)(`input`,{type:f||!D?`text`:`password`,className:a(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-3 pr-20 font-mono text-sm text-fg`,`placeholder:text-fg-subtle`,K,`dark:border-edge`),value:O,placeholder:D?r.placeholderOverride:e.configured?r.placeholderKeep:r.placeholderKey,disabled:ne,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&&!D?(0,Y.jsx)(`button`,{type:`button`,className:a(`rounded p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,g.transition,g.press,g.focusRingPanel),title:m?r.copied:r.copy,"aria-label":m?r.copied:r.copy,onClick:()=>void we(),children:m?(0,Y.jsx)(ue,{className:`size-4`}):(0,Y.jsx)(Ie,{className:`size-4`})}):null,(0,Y.jsx)(`button`,{type:`button`,className:a(`rounded p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg disabled:opacity-40`,g.transition,g.press,g.focusRingPanel),title:f?r.hide:r.show,"aria-label":f?r.hide:r.show,disabled:D,onClick:()=>p(e=>!e),children:f?(0,Y.jsx)(Ne,{className:`size-4`}):(0,Y.jsx)(re,{className:`size-4`})})]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2 sm:shrink-0`,children:[(0,Y.jsxs)(z,{type:`button`,variant:`secondary`,className:`gap-1`,disabled:ne||U||!t.trim()||_e(t),onClick:()=>void Te(),children:[U?(0,Y.jsx)(P,{className:`size-4 animate-spin`,"aria-hidden":!0}):null,U?r.testingKey:r.testKey]}),e.supportsOAuth?te?(0,Y.jsxs)(z,{type:`button`,variant:`secondary`,className:`gap-1 text-red-600 dark:text-red-400`,onClick:xe,children:[(0,Y.jsx)(v,{className:`size-4`,"aria-hidden":!0}),r.revoke]}):(0,Y.jsxs)(z,{type:`button`,variant:`secondary`,className:`gap-1`,disabled:ne,onClick:()=>void he(),children:[ne?(0,Y.jsx)(P,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(j,{className:`size-4`,"aria-hidden":!0}),r.oauth]}):null,Ce?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(z,{type:`button`,variant:`secondary`,className:`gap-1 text-red-600 dark:text-red-400`,disabled:ee,onClick:()=>E(!0),children:[ee?(0,Y.jsx)(P,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(Me,{className:`size-4`,"aria-hidden":!0}),r.removeKey]}),(0,Y.jsx)(Qn,{open:T,title:r.removeKey,description:cr(r.removeKeyConfirm,{name:e.name}),confirmLabel:r.removeKey,cancelLabel:r.cancelOAuth,destructive:!0,onConfirm:()=>void Se(),onCancel:()=>E(!1)})]}):null]})]}),le?(0,Y.jsx)(`p`,{className:a(`text-xs`,G===!1?`text-red-600 dark:text-red-400`:`text-fg-muted`),role:`status`,children:le}):null,me.length>0?(0,Y.jsx)(`div`,{className:`flex flex-col gap-1`,children:me.map(e=>(0,Y.jsxs)(`a`,{href:e.href,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex w-fit items-center gap-1 text-xs font-medium text-accent-fg hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:[fe(e.kind,r),(0,Y.jsx)(Le,{className:`size-3`,"aria-hidden":!0})]},`${e.kind}-${e.href}`))}):null]}),I?(0,Y.jsxs)(`div`,{className:a(`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)(w,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}):N===`success`?(0,Y.jsx)(ue,{className:`mt-0.5 size-4 shrink-0 text-emerald-600`,"aria-hidden":!0}):(0,Y.jsx)(Oe,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:I})]}):null,_?(0,Y.jsxs)(`div`,{className:`flex gap-2 rounded-md border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700 dark:border-red-900/50 dark:bg-red-950/50 dark:text-red-400`,role:`alert`,children:[(0,Y.jsx)(w,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:_})]}):null,x?(0,Y.jsxs)(`div`,{className:a(`flex gap-2 rounded-md px-3 py-2 text-xs`,x===r.removeKeySuccess?`bg-surface-hover/60 text-fg-muted dark:bg-surface-hover/40`:`border border-red-200 bg-red-50 text-red-700 dark:border-red-900/50 dark:bg-red-950/50 dark:text-red-400`),role:`status`,children:[x===r.removeKeySuccess?(0,Y.jsx)(ue,{className:`mt-0.5 size-4 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):(0,Y.jsx)(w,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:x})]}):null,(N===`waiting`||N===`waiting_code`)&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[R?(0,Y.jsxs)(`a`,{href:R,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)(Le,{className:`size-4`,"aria-hidden":!0}),r.openAuthPage]}):null,(0,Y.jsxs)(z,{type:`button`,variant:`secondary`,className:`gap-1`,onClick:()=>void ge(),children:[(0,Y.jsx)(V,{className:`size-4`,"aria-hidden":!0}),r.cancelOAuth]})]}),B?(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)(Oe,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:B})]}):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:a(`min-w-0 flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,K,`dark:border-edge`),value:se,placeholder:r.pasteRedirectUrl,onChange:e=>H(e.target.value),onKeyDown:e=>e.key===`Enter`&&void be()}),(0,Y.jsx)(z,{type:`button`,variant:`primary`,className:`shrink-0`,onClick:()=>void be(),children:r.submitCode})]}):null,D?(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)(Oe,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:pe===`env`?r.envHint:r.maskedStoredHint})]}):null,e.supportsOAuth&&!D&&!te?(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)(ue,{className:`mt-0.5 size-3.5 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:(()=>{let t=l.filter(t=>t.provider===e.id);if(t.length===0)return r.savedNoModels;let n=t.slice(0,3).map(e=>e.name||e.id).join(`, `),i=t.length>3?`… (+${t.length-3})`:``;return`${t.length} ${r.savedModelsAvailable}: ${n}${i}`})()})]}):null,(De[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:(De[e.id]?.envVars??[]).map(e=>(0,Y.jsx)(dr,{envVar:e,labels:r},e))})]}):null]}):null]})}var pr=[`appearance`,`system`,`agent-defaults`,`providers`,`models`,`voice`,`gateway`,`heartbeat`,`search`,`dreams`];function mr(){let{section:e}=E(),t=o(e=>e.language),n=q(t);if(e===`agent`||e===`agents`)return(0,Y.jsx)(M,{to:`/agents`,replace:!0});if(!e||!pr.includes(e))return(0,Y.jsx)(M,{to:`/settings/appearance`,replace:!0});let r=e,i=n.settingsSections[r];return r===`appearance`?(0,Y.jsx)(tt,{}):r===`system`?(0,Y.jsx)(Nn,{}):r===`agent-defaults`?(0,Y.jsx)(Ye,{}):r===`providers`?(0,Y.jsx)(ur,{}):r===`models`?(0,Y.jsx)(Zt,{}):r===`voice`?(0,Y.jsx)(yn,{}):r===`gateway`?(0,Y.jsx)(ot,{}):r===`heartbeat`?(0,Y.jsx)(wt,{}):r===`search`?(0,Y.jsx)(kn,{}):r===`dreams`?(0,Y.jsx)(Zn,{}):(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{mr as SettingsPage};
2
- //# sourceMappingURL=settings-page-DFNKT9yg.js.map
1
+ import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{i as t,t as n}from"./vendor-react-DbimaAId.js";import{i as r,o as i}from"./vendor-swr-B5fPo7KK.js";import{t as a}from"./cn-BMCV0OMB.js";import{$t as o,A as s,Br as c,Cr as l,Dn as u,En as d,Fr as f,G as p,Gn as m,Gt as h,H as g,Hn as _,Jn as v,Jr as y,Jt as ee,Kt as b,Ln as x,Lr as S,Nn as C,Nr as w,Pn as T,Qr as E,Qt as D,Rr as O,Sn as te,Wn as ne,Wt as k,Xn as A,Yn as j,Yr as M,Yt as N,Zn as P,Zt as F,_r as re,_t as I,a as L,an as R,c as ie,cn as z,cr as ae,ct as B,dn as oe,dt as se,fn as V,ft as H,gt as U,ht as ce,i as le,j as W,jn as G,jr as ue,kn as de,l as fe,lt as pe,m as me,mn as he,mt as ge,n as _e,o as ve,on as K,or as ye,ot as be,p as xe,pn as Se,pt as Ce,qr as we,r as Te,rn as Ee,s as De,sn as q,sr as Oe,st as ke,t as Ae,ut as je,vn as Me,vr as Ne,vt as Pe,wn as Fe,wr as Ie,yr as Le,zn as Re}from"./index-lV8FGWlt.js";import{a as ze,p as Be,v as Ve}from"./cron-utils-BmzF4m1y.js";import{a as He,c as Ue,i as J,l as We,n as Ge,o as Ke,r as qe,s as Je,t as Ye,u as Xe}from"./agents-DplaQYS2.js";var Y=n();function Ze(){return a(`rounded-xl border border-edge-subtle bg-surface-base px-4 py-1 sm:px-5`)}function Qe({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 $e=[{value:`default`,labelKey:`colorSchemeDefault`},{value:`emerald`,labelKey:`colorSchemeLightGreen`}];function et(){let e=q(o(e=>e.language)).appearanceSettings,t=D(e=>e.colorScheme),n=D(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:$e.map(({value:r,labelKey:i})=>{let o=t===r;return(0,Y.jsxs)(`button`,{type:`button`,"aria-pressed":o,onClick:()=>n(r),className:a(`flex flex-col gap-2 rounded-xl border-2 p-2.5 text-left transition-[border-color,box-shadow] duration-150`,o?`border-accent shadow-[0_0_0_1px_var(--color-accent)]`:`border-edge-subtle hover:border-edge`),children:[(0,Y.jsx)(Qe,{scheme:r}),(0,Y.jsx)(`span`,{className:a(`text-xs font-medium leading-none`,o?`text-accent-fg`:`text-fg-muted`),children:e[i]})]},r)})})]})}function tt(){let e=q(o(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:Ze(),"aria-labelledby":`pref-language-heading`,children:[(0,Y.jsx)(`h2`,{id:`pref-language-heading`,className:`sr-only`,children:e.languageTitle}),(0,Y.jsx)(F,{variant:`page`,sections:[`language`]})]}),(0,Y.jsxs)(`section`,{className:Ze(),"aria-labelledby":`pref-appearance-heading`,children:[(0,Y.jsx)(`h2`,{id:`pref-appearance-heading`,className:`sr-only`,children:e.themeTitle}),(0,Y.jsx)(F,{variant:`page`,sections:[`theme`,`font`]}),(0,Y.jsx)(et,{})]})]})}var X=e(t(),1);function nt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function rt(e){let t=nt(e)?e:{},n=nt(t.gateway)?t.gateway:{},r=nt(n.auth)?n.auth:{},i=r.mode===`none`||r.mode===`token`?r.mode:`token`,a=(nt(t.update)?t.update:{}).channel,o=a===`beta`||a===`dev`||a===`stable`?a:`stable`;return{host:typeof n.host==`string`?n.host:``,port:typeof n.port==`number`?n.port:void 0,auth:{mode:i,token:typeof r.token==`string`?r.token:``},updateChannel:o}}async function it(e){let t=e.auth.token.trim().length>0?{mode:e.auth.mode,token:e.auth.token}:{mode:e.auth.mode};await b(k(`/api/config`),{method:`PATCH`,body:JSON.stringify({gateway:{auth:t},update:{channel:e.updateChannel}})}),s()}function at(){return a(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,K,`dark:border-edge`)}function ot(){let e=o(e=>e.language),t=q(e),n=t.gatewaySettings,r=ee(e=>e.token),i=ee(e=>e.tokenExpired),a=ee(e=>e.openTokenDialog),s=!!r,[c,l]=(0,X.useState)(null),[u,d]=(0,X.useState)(null),[f,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(!1),[v,y]=(0,X.useState)(!1),[b,x]=(0,X.useState)(!1),S=(0,X.useRef)(!1),{data:C,error:T,isLoading:E,mutate:D}=W(s),O=(0,X.useMemo)(()=>C?.payload?.config===void 0?null:structuredClone(rt(C.payload.config)),[C]);(0,X.useEffect)(()=>{if(!s){l(null),d(null),S.current=!1;return}O!==null&&(S.current||(l(O),d(structuredClone(O)),_(!1)))},[s,O]);let te=!!(s&&E&&C===void 0&&!T),ne=T instanceof Error?T.message:T?String(T):null,k=(0,X.useMemo)(()=>!c||!u?!1:JSON.stringify(c)!==JSON.stringify(u),[c,u]),A=(0,X.useCallback)(e=>{S.current=!0,l(t=>t?{...t,auth:{...t.auth,...e}}:null)},[]),j=(0,X.useCallback)(e=>{S.current=!0,l(t=>t?{...t,updateChannel:e}:null)},[]),M=(0,X.useCallback)(async()=>{if(!(!c||f)){p(!0),h(null),_(!1);try{await it(c),S.current=!1,d(structuredClone(c)),_(!0),window.setTimeout(()=>_(!1),2500)}catch(e){h(e instanceof Error?e.message:n.saveError)}finally{p(!1)}}},[c,f,n.saveError]),F=(0,X.useCallback)(async()=>{let e=c?.auth.token;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),x(!0),window.setTimeout(()=>x(!1),2e3))},[c?.auth.token]);return s?te?(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)(P,{className:`size-4 animate-spin`}),n.loading]})}):c?(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.gateway}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,Y.jsxs)(`a`,{href:N(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)(Le,{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)(z,{type:`button`,variant:`primary`,disabled:!k||f,onClick:()=>void M(),children:f?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)(w,{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)(z,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:()=>a(),children:n.updateToken})})]}):null,k?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,m?(0,Y.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:m}):null,c.auth.mode===`none`?(0,Y.jsx)(`p`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-950 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-100`,children:n.authModeNone}):null,(0,Y.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[(0,Y.jsxs)(`div`,{className:`mb-5 flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)(de,{className:`size-4 text-accent`,strokeWidth:1.75}),t.settingsSections.gateway]}),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(c.host||c.port!=null)&&(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:n.listenHost}),(0,Y.jsx)(`div`,{className:`rounded-lg bg-surface-hover/80 px-3 py-2 font-mono text-xs text-fg-muted dark:bg-surface-hover/50`,children:c.host||`—`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:n.listenPort}),(0,Y.jsx)(`div`,{className:`rounded-lg bg-surface-hover/80 px-3 py-2 font-mono text-xs text-fg-muted dark:bg-surface-hover/50`,children:c.port==null?`—`:String(c.port)})]}),(0,Y.jsx)(`p`,{className:`sm:col-span-2 text-xs text-fg-subtle`,children:n.listenHint})]}),(0,Y.jsx)(st,{g:n,value:c.auth.token,show:v,copied:b,onToggleShow:()=>y(e=>!e),onCopy:()=>void F(),onChange:e=>A({token:e})}),(0,Y.jsx)(z,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,onClick:()=>a(),children:n.changeToken}),(0,Y.jsxs)(`div`,{className:`space-y-2 border-t border-edge pt-4`,children:[(0,Y.jsx)(`label`,{className:`text-sm font-medium text-fg`,htmlFor:`gateway-update-channel`,children:n.updateChannel}),(0,Y.jsxs)(`select`,{id:`gateway-update-channel`,value:c.updateChannel,onChange:e=>j(e.target.value),className:at(),children:[(0,Y.jsx)(`option`,{value:`stable`,children:n.channelStable}),(0,Y.jsx)(`option`,{value:`beta`,children:n.channelBeta}),(0,Y.jsx)(`option`,{value:`dev`,children:n.channelDev})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.updateChannelHint})]})]})]})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:m??ne??n.loadError}),(0,Y.jsx)(z,{type:`button`,variant:`secondary`,onClick:()=>void D(),children:n.retry})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.gateway}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}function st({g:e,value:t,show:n,copied:r,onToggleShow:i,onCopy:o,onChange:s}){return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.accessToken}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,Y.jsx)(`input`,{className:a(at(),`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)(z,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:o,children:[r?(0,Y.jsx)(O,{className:`size-3.5`}):(0,Y.jsx)(Ie,{className:`size-3.5`}),r?e.copied:e.copy]}):null,(0,Y.jsxs)(z,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:i,children:[n?(0,Y.jsx)(Ne,{className:`size-3.5`}):(0,Y.jsx)(re,{className:`size-3.5`}),n?e.hide:e.show]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tokenHelp})]})}function ct(){return k(`/api/channels/status`)}var lt=Be;function ut(){return k(`/api/workspace/heartbeat-md`)}async function dt(){let e=await b(ut());return typeof e.payload?.content==`string`?e.payload.content:``}function ft(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function pt(e){let t=ft(e)?e:{},n=ft(t.gateway)?t.gateway:{},r=ft(n.heartbeat)?n.heartbeat:{},i=r.activeHours,a=ft(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 mt(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 ht(e){await b(k(`/api/config`),{method:`PATCH`,body:JSON.stringify({gateway:{heartbeat:mt(e)}})}),s()}async function gt(e){await b(k(`/api/workspace/heartbeat-md`),{method:`PUT`,body:JSON.stringify({content:e})}),i(ut())}async function _t(e){await b(k(`/api/heartbeat/trigger`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e?{reason:e}:{})})}var vt=[3e4,6e4,3e5,6e5,9e5,18e5,36e5,72e5],yt=new Set(vt);function bt(){return a(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,K,`dark:border-edge`)}function xt(){return a(R,Ee)}function St(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 Ct(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 wt(){let e=o(e=>e.language),t=q(e),n=t.heartbeatSettings,i=!!ee(e=>e.token),[s,c]=(0,X.useState)(null),[l,u]=(0,X.useState)(null),[d,f]=(0,X.useState)(``),[p,m]=(0,X.useState)(``),[h,g]=(0,X.useState)(!1),[_,v]=(0,X.useState)(!1),[y,b]=(0,X.useState)(null),[x,S]=(0,X.useState)(!1),[C,w]=(0,X.useState)(!1),[T,E]=(0,X.useState)(!1),[D,O]=(0,X.useState)(!1),[te,ne]=(0,X.useState)(null),[k,A]=(0,X.useState)([]),{data:j,error:M,isLoading:F,mutate:re}=W(i),{data:I,error:L,isLoading:R,mutate:ie}=r(i?ut():null,dt,{revalidateOnFocus:!1}),{data:B=[]}=r(i?ct():null,lt,{revalidateOnFocus:!1}),oe=(0,X.useMemo)(()=>St(j?.payload?.config),[j]),se=(0,X.useMemo)(()=>pt(j?.payload?.config??{}),[j]),V=(0,X.useMemo)(()=>!s||!l?!1:JSON.stringify(s)!==JSON.stringify(l),[s,l]),H=(0,X.useMemo)(()=>d!==p,[d,p]);(0,X.useEffect)(()=>{if(!i){c(null),u(null);return}if(j!==void 0&&!V){let e=structuredClone(se);c(e),u(e),S(!1)}},[i,j,se,V]),(0,X.useEffect)(()=>{!i||I===void 0||H||(f(I),m(I),w(!1))},[i,I,H]);let U=M instanceof Error?M.message:M?String(M):L instanceof Error?L.message:L?String(L):null,ce=!!(i&&(j===void 0||I===void 0)&&!U&&(F||R));(0,X.useEffect)(()=>{if(!i||!s){A([]);return}let e=s.target.trim();if(!e){A([]);return}let t=!1;return Ve(e).then(e=>{t||A(e)}),()=>{t=!0}},[i,s?.target]);let le=(0,X.useCallback)(()=>{let e=s?.target?.trim();e&&Ve(e).then(A)},[s?.target]),G=(0,X.useCallback)(async()=>{E(!0),O(!1),ne(null);try{await _t(),O(!0),window.setTimeout(()=>O(!1),3e3)}catch(e){ne(e instanceof Error?e.message:n.triggerError)}finally{E(!1)}},[n.triggerError]),ue=(0,X.useCallback)(e=>{c(t=>t?{...t,...e}:null)},[]),de=(0,X.useCallback)(async()=>{if(!(!s||h)){g(!0),b(null),S(!1);try{await ht(s),u(structuredClone(s)),S(!0),window.setTimeout(()=>S(!1),2500)}catch(e){b(e instanceof Error?e.message:n.saveConfigError)}finally{g(!1)}}},[s,h,n.saveConfigError]),fe=(0,X.useCallback)(async()=>{if(!_){v(!0),b(null),w(!1);try{await gt(d),m(d),w(!0),window.setTimeout(()=>w(!1),2500)}catch(e){b(e instanceof Error?e.message:n.saveDocError)}finally{v(!1)}}},[d,_,n.saveDocError]);return i?ce?(0,Y.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,Y.jsx)(P,{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.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:N(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)(Le,{className:`size-3.5`})]})]})}),oe?(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.workspaceLabel,`: `,(0,Y.jsx)(`span`,{className:`font-mono text-fg-muted`,children:oe})]}):null,y?(0,Y.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:y}):null,(0,Y.jsxs)(Ge,{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)(ae,{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)(z,{type:`button`,variant:`secondary`,className:`inline-flex items-center gap-2`,disabled:T,onClick:()=>void G(),children:[T?(0,Y.jsx)(P,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(Re,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),T?n.triggering:n.triggerNow]}),D?(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}),te?(0,Y.jsx)(`p`,{className:`mb-3 text-sm text-red-600 dark:text-red-400`,children:te}):null,(0,Y.jsx)(Tt,{h:n,cron:t.cron,form:s,channels:B,sessionChatIds:k,onRefreshChatIds:le,update:ue,inputClassName:bt,selectClassName:xt}),(0,Y.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-2`,children:[x?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.savedConfig}):null,(0,Y.jsx)(z,{type:`button`,variant:`primary`,disabled:!V||h,onClick:()=>void de(),children:h?n.savingConfig:n.saveConfig}),V?(0,Y.jsx)(`span`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedConfig}):null]})]}),(0,Y.jsxs)(Ge,{children:[(0,Y.jsx)(`div`,{className:`mb-2 text-sm font-semibold text-fg`,children:n.docSection}),(0,Y.jsx)(`p`,{className:`mb-3 text-xs text-fg-subtle`,children:n.docHint}),(0,Y.jsx)(`textarea`,{className:a(bt(),`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:[C?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.savedDoc}):null,(0,Y.jsx)(z,{type:`button`,variant:`primary`,disabled:!H||_,onClick:()=>void fe(),children:_?n.savingDoc:n.saveDoc}),H?(0,Y.jsx)(`span`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedDoc}):null]})]})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:y??U??n.loadError}),(0,Y.jsx)(z,{type:`button`,variant:`secondary`,onClick:()=>{re(),ie()},children:n.retry})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.heartbeat}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}function Tt({h:e,cron:t,form:n,channels:r,sessionChatIds:i,onRefreshChatIds:o,update:s,inputClassName:c,selectClassName:l}){let u=(0,X.useMemo)(()=>new Set(r.map(e=>e.name)),[r]),d=n.target.trim(),f=!!(d&&!u.has(d)),p=(0,X.useMemo)(()=>yt.has(n.intervalMs)?String(n.intervalMs):``,[n.intervalMs]),[m,h]=(0,X.useState)(null),g=Math.max(1,Math.round(n.intervalMs/1e3)),_=m===null?String(g):m;return(0,X.useEffect)(()=>{h(null)},[n.intervalMs]),(0,Y.jsxs)(`div`,{className:`space-y-4`,children:[(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:n.enabled,onChange:e=>s({enabled:e.target.checked})}),e.enable]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.interval}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:e.intervalSecondsLabel}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`input`,{type:`number`,min:1,step:1,className:a(c(),`min-w-0 flex-1`),value:_,onChange:e=>{let t=e.target.value;h(t);let n=parseInt(t,10);Number.isFinite(n)&&n>=1&&s({intervalMs:n*1e3})},onBlur:()=>{if(m===null)return;let e=parseInt(m,10);s(!Number.isFinite(e)||e<1?{intervalMs:1e3}:{intervalMs:e*1e3}),h(null)}}),(0,Y.jsxs)(`select`,{className:a(l(),`max-w-[11rem] shrink-0 text-xs`),value:p,onChange:e=>{let t=e.target.value;t&&(s({intervalMs:parseInt(t,10)}),h(null))},children:[(0,Y.jsx)(`option`,{value:``,children:e.intervalPresets.custom}),vt.map(t=>(0,Y.jsx)(`option`,{value:String(t),children:Ct(t,e.intervalPresets)},t))]})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.intervalHintPreset}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.intervalHint})]}),(0,Y.jsxs)(`div`,{className:`border-t border-edge-subtle pt-4`,children:[(0,Y.jsx)(`div`,{className:`mb-2 text-sm font-medium text-fg`,children:e.deliveryTitle}),(0,Y.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:t.channel}),(0,Y.jsxs)(`select`,{className:l(),value:d,onChange:e=>{s({target:e.target.value.trim(),targetChatId:``})},children:[(0,Y.jsx)(`option`,{value:``,children:e.channelNone}),f?(0,Y.jsxs)(`option`,{value:d,children:[d,` (`,e.customChannelSuffix,`)`]}):null,r.map(e=>(0,Y.jsxs)(`option`,{value:e.name,disabled:!e.enabled,children:[e.name,` `,e.enabled?``:`(disabled)`]},e.name))]})]}),d?(0,Y.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,Y.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:t.recipient}),(0,Y.jsxs)(z,{type:`button`,variant:`ghost`,className:`h-7 gap-1 px-2 text-xs`,title:t.refreshRecipientHint,onClick:o,children:[(0,Y.jsx)(T,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0}),t.refreshList]})]}),(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(`input`,{type:`text`,className:a(c(),`min-w-0 flex-1`),value:n.targetChatId,onChange:e=>s({targetChatId:e.target.value}),placeholder:t.recipientPlaceholder,autoComplete:`off`}),(0,Y.jsxs)(`select`,{className:a(l(),`max-w-[10rem] shrink-0 text-xs`),value:n.targetChatId,onChange:e=>{let t=e.target.value;t&&s({targetChatId:t})},children:[(0,Y.jsx)(`option`,{value:``,children:t.selectRecipient}),i.length>0?i.map(e=>(0,Y.jsx)(`option`,{value:e.chatId,children:ze(e,t.lastActiveLabels)},`${e.channel}-${e.chatId}`)):(0,Y.jsx)(`option`,{value:``,disabled:!0,children:t.noRecentChatsOption})]})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:i.length>0?t.enterManuallyOrSelect:t.noRecentChats})]}):null,(0,Y.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:e.deliveryHint})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:e.prompt}),(0,Y.jsx)(`textarea`,{className:a(c(),`min-h-[4.5rem] resize-y font-mono text-xs`),value:n.prompt,onChange:e=>s({prompt:e.target.value}),placeholder:e.promptPlaceholder}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:e.promptHint})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:e.ackMaxChars}),(0,Y.jsx)(`input`,{type:`number`,min:1,className:c(),value:n.ackMaxChars===``?``:n.ackMaxChars,onChange:e=>{let t=e.target.value;if(t===``)s({ackMaxChars:``});else{let e=parseInt(t,10);s({ackMaxChars:Number.isFinite(e)?e:``})}},placeholder:e.ackDefaultPlaceholder}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:e.ackMaxCharsHint})]}),(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:n.isolatedSession,onChange:e=>s({isolatedSession:e.target.checked})}),(0,Y.jsxs)(`span`,{children:[e.isolatedSession,(0,Y.jsx)(`span`,{className:`mt-1 block text-xs text-fg-subtle`,children:e.isolatedSessionHint})]})]}),(0,Y.jsxs)(`div`,{className:`border-t border-edge-subtle pt-4`,children:[(0,Y.jsx)(`div`,{className:`mb-2 text-sm font-medium text-fg`,children:e.activeHoursTitle}),n.activeHours?(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-xs text-fg`,children:e.activeStart}),(0,Y.jsx)(`input`,{className:c(),value:n.activeHours.start,onChange:e=>s({activeHours:{...n.activeHours,start:e.target.value}}),placeholder:`09:00`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-xs text-fg`,children:e.activeEnd}),(0,Y.jsx)(`input`,{className:c(),value:n.activeHours.end,onChange:e=>s({activeHours:{...n.activeHours,end:e.target.value}}),placeholder:`22:00`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`mb-1 text-xs text-fg`,children:e.activeTimezone}),(0,Y.jsx)(`input`,{className:c(),value:n.activeHours.timezone,onChange:e=>s({activeHours:{...n.activeHours,timezone:e.target.value}}),placeholder:`Asia/Shanghai`})]})]}):(0,Y.jsx)(z,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:()=>s({activeHours:{start:`09:00`,end:`22:00`,timezone:``}}),children:e.addActiveHours}),n.activeHours?(0,Y.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:(0,Y.jsx)(z,{type:`button`,variant:`secondary`,className:`text-xs`,onClick:()=>s({activeHours:null}),children:e.clearActiveHours})}):null,(0,Y.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:e.activeHoursHint})]})]})}var Et=[{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 Dt(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 Ot(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 kt(){let e=await h(k(`/api/models-json`)),t=await e.json().catch(()=>({}));if(!e.ok||!t.ok||!t.payload)throw Error(Dt(t)||`HTTP ${e.status}`);return{...t.payload,config:Ot(t.payload.config)}}async function At(e){let t=await h(k(`/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(Dt(n)||`HTTP ${t.status}`);return n.payload}async function jt(e){let t=await h(k(`/api/models-json`),{method:`PATCH`,body:JSON.stringify({config:e})}),n=await t.json().catch(()=>({}));if(!t.ok||!n.ok||!n.payload)throw Error(Dt(n)||`HTTP ${t.status}`);return n.payload}async function Mt(){let e=await h(k(`/api/models-json/reload`),{method:`POST`}),t=await e.json().catch(()=>({}));if(!e.ok||!t.ok||!t.payload)throw Error(Dt(t)||`HTTP ${e.status}`);return t.payload}async function Nt(e){let t=await h(k(`/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(Dt(n)||`HTTP ${t.status}`);return n.payload}function Pt(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 Ft(e){return e.startsWith(`!`)}function It(e){return/^[A-Z][A-Z0-9_]*$/.test(e)}function Lt(e){return Ft(e)?`shell`:It(e)?`env`:`literal`}function Rt(e){return e?e.length<=8?`••••`:`${e.slice(0,4)}••••${e.slice(-4)}`:``}var zt={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 Bt(e){return e===`openrouter`?`openrouter`:e===`zhipuCn`?`zhipu-cn`:e===`zaiGeneral`?`zai`:e}var Vt=[{value:`text`,labelKey:`inputTextOnly`},{value:`text,image`,labelKey:`inputTextVision`}];function Ht(){return a(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,K,`dark:border-edge`)}function Ut(){return a(R,Ee)}function Wt(e){return(e.input||[`text`]).includes(`image`)?`text,image`:`text`}function Gt(e){return e===`text,image`?[`text`,`image`]:[`text`]}function Kt(e,t,n){return{...e,providers:{...e.providers,[t]:{...e.providers[t],...n}}}}function qt(e,t){let n={...e.providers};return delete n[t],{...e,providers:n}}function Jt(e,t,n){return{...e,providers:{...e.providers,[t]:n}}}function Yt({open:e,onOpenChange:t,presetKey:n,onConfirm:r,m:i}){let[o,s]=(0,X.useState)(``),[c,l]=(0,X.useState)(`custom`),[u,d]=(0,X.useState)(``),[f,p]=(0,X.useState)(`openai-completions`),[m,h]=(0,X.useState)(``),[g,_]=(0,X.useState)(null);(0,X.useEffect)(()=>{if(!e)return;_(null);let t=n||null;if(t&&zt[t]){let e=zt[t];l(t),d(e.baseUrl||``),p(e.api||`openai-completions`),h(e.apiKey??``),s(Bt(t))}else l(`custom`),s(``),d(``),p(`openai-completions`),h(``)},[e,n]);let v=e=>{if(l(e),e===`custom`)return;let t=zt[e];t&&(d(t.baseUrl||``),p(t.api||`openai-completions`),h(t.apiKey??``),s(Bt(e)))};return(0,Y.jsx)(se,{open:e,onOpenChange:t,children:(0,Y.jsxs)(je,{children:[(0,Y.jsx)(pe,{className:`xopc-dialog-overlay fixed inset-0 z-50 bg-scrim`}),(0,Y.jsxs)(ke,{className:a(`xopc-dialog-content fixed left-1/2 top-1/2 z-50 max-h-[min(90vh,640px)] w-[min(100%-2rem,32rem)] -translate-x-1/2 -translate-y-1/2`,`overflow-y-auto rounded-xl border border-edge bg-surface-panel p-4 shadow-popover dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,Y.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(H,{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)(be,{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:Ut(),value:c,onChange:e=>v(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:Ht(),value:o,onChange:e=>s(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:Ht(),value:u,onChange:e=>d(e.target.value),placeholder:`https://…`})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:i.apiType}),(0,Y.jsx)(`select`,{className:Ut(),value:f,onChange:e=>p(e.target.value),children:Et.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:Ht(),value:m,onChange:e=>h(e.target.value),placeholder:i.apiKeyPlaceholder})]}),g?(0,Y.jsxs)(`p`,{className:`flex items-center gap-1 text-xs text-red-600 dark:text-red-400`,children:[(0,Y.jsx)(w,{className:`size-3.5 shrink-0`}),g]}):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)(be,{asChild:!0,children:(0,Y.jsx)(z,{type:`button`,variant:`secondary`,children:i.cancel})}),(0,Y.jsx)(z,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:()=>{let e=o.trim();if(!e){_(i.providerIdRequired);return}_(null),r(e,{baseUrl:u.trim()||void 0,api:f,apiKey:m.trim()||void 0,models:[]}),t(!1)},children:i.addProviderConfirm})]})]})]})})}function Xt({open:e,onOpenChange:t,providerId:n,model:r,isNew:i,onSave:o,m:s}){let[c,l]=(0,X.useState)(()=>Pt(``)),[u,d]=(0,X.useState)(()=>new Map);(0,X.useEffect)(()=>{e&&(d(new Map),l(r?{...r}:Pt(``)))},[e,r]);let f=(e,t)=>{l(n=>({...n,[e]:t})),d(t=>{let n=new Map(t);return n.delete(e),n})},p=()=>{let e=new Map;return(c.id||``).trim()||e.set(`id`,s.modelIdRequired),c.contextWindow!==void 0&&c.contextWindow<=0&&e.set(`contextWindow`,s.mustBePositive),c.maxTokens!==void 0&&c.maxTokens<=0&&e.set(`maxTokens`,s.mustBePositive),d(e),e.size===0},m=()=>{if(!p())return;let e=(c.id||``).trim();o({...c,id:e,name:c.name?.trim()||e,reasoning:c.reasoning||!1,input:c.input||[`text`],contextWindow:c.contextWindow??128e3,maxTokens:c.maxTokens??16384,cost:{input:c.cost?.input??0,output:c.cost?.output??0,cacheRead:c.cost?.cacheRead??0,cacheWrite:c.cost?.cacheWrite??0}}),t(!1)},h=Wt(c);return(0,Y.jsx)(se,{open:e,onOpenChange:t,children:(0,Y.jsxs)(je,{children:[(0,Y.jsx)(pe,{className:`xopc-dialog-overlay fixed inset-0 z-50 bg-scrim`}),(0,Y.jsxs)(ke,{className:a(`xopc-dialog-content fixed left-1/2 top-1/2 z-50 max-h-[min(90vh,720px)] w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2`,`overflow-y-auto rounded-xl border border-edge bg-surface-panel p-4 shadow-popover dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,Y.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(H,{className:`text-base font-semibold text-fg`,children:i?s.addModelTitle:s.editModelTitle}),n?(0,Y.jsxs)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:[s.modelProviderLabel,`: `,n]}):null]}),(0,Y.jsx)(be,{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":s.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:[s.modelId,(0,Y.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,Y.jsx)(`input`,{className:a(Ht(),u.has(`id`)&&`border-red-500`),value:c.id||``,onChange:e=>f(`id`,e.target.value),placeholder:`e.g. llama3.1:8b`,disabled:!i}),u.has(`id`)?(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:u.get(`id`)}):null]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.displayName}),(0,Y.jsx)(`input`,{className:Ht(),value:c.name||``,onChange:e=>f(`name`,e.target.value)})]}),(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.inputTypes}),(0,Y.jsx)(`select`,{className:Ut(),value:h,onChange:e=>f(`input`,Gt(e.target.value)),children:Vt.map(e=>(0,Y.jsx)(`option`,{value:e.value,children:s[e.labelKey]},e.value))})]}),(0,Y.jsxs)(`label`,{className:`mt-6 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:c.reasoning||!1,onChange:e=>f(`reasoning`,e.target.checked)}),s.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:s.contextWindow}),(0,Y.jsx)(`input`,{type:`number`,min:1,className:a(Ht(),u.has(`contextWindow`)&&`border-red-500`),value:c.contextWindow??128e3,onChange:e=>f(`contextWindow`,parseInt(e.target.value,10)||0)}),u.has(`contextWindow`)?(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:u.get(`contextWindow`)}):null]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.maxOutputTokens}),(0,Y.jsx)(`input`,{type:`number`,min:1,className:a(Ht(),u.has(`maxTokens`)&&`border-red-500`),value:c.maxTokens??16384,onChange:e=>f(`maxTokens`,parseInt(e.target.value,10)||0)}),u.has(`maxTokens`)?(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:u.get(`maxTokens`)}):null]})]}),(0,Y.jsxs)(`div`,{className:`border-t border-edge-subtle pt-2 dark:border-edge`,children:[(0,Y.jsx)(`p`,{className:`mb-2 text-xs font-semibold text-fg`,children:s.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:s.costInput}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,min:0,className:Ht(),value:c.cost?.input??0,onChange:e=>f(`cost`,{...c.cost,input:parseFloat(e.target.value)||0,output:c.cost?.output??0,cacheRead:c.cost?.cacheRead??0,cacheWrite:c.cost?.cacheWrite??0})})]}),(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:s.costOutput}),(0,Y.jsx)(`input`,{type:`number`,step:`any`,min:0,className:Ht(),value:c.cost?.output??0,onChange:e=>f(`cost`,{...c.cost,input:c.cost?.input??0,output:parseFloat(e.target.value)||0,cacheRead:c.cost?.cacheRead??0,cacheWrite:c.cost?.cacheWrite??0})})]})]})]})]}),(0,Y.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2 border-t border-edge-subtle pt-3 dark:border-edge`,children:[(0,Y.jsx)(be,{asChild:!0,children:(0,Y.jsx)(z,{type:`button`,variant:`secondary`,children:s.cancel})}),(0,Y.jsx)(z,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:m,children:i?s.addModelConfirm:s.saveModelConfirm})]})]})]})})}function Zt(){let e=o(e=>e.language),t=q(e),n=t.modelsSettings,r=!!ee(e=>e.token),[i,s]=(0,X.useState)({providers:{}}),[u,d]=(0,X.useState)({providers:{}}),[p,m]=(0,X.useState)(``),[h,v]=(0,X.useState)(),[y,b]=(0,X.useState)(!0),[C,E]=(0,X.useState)(!1),[D,O]=(0,X.useState)(!1),[te,ne]=(0,X.useState)(!1),[k,A]=(0,X.useState)(null),[j,M]=(0,X.useState)(!1),[F,I]=(0,X.useState)(null),[L,R]=(0,X.useState)(()=>new Set),[ie,ae]=(0,X.useState)(!1),[B,se]=(0,X.useState)(``),[V,H]=(0,X.useState)(null),[U,ce]=(0,X.useState)(()=>new Set),[le,W]=(0,X.useState)(()=>new Map),[G,ue]=(0,X.useState)(!1),[de,fe]=(0,X.useState)(null),[pe,me]=(0,X.useState)(!1),[he,ge]=(0,X.useState)(null),_e=(0,X.useCallback)(async e=>{let t=!e?.skipFullPageLoading;t&&b(!0),A(null);try{let e=await kt(),t=Ot(e.config);s(t),d(structuredClone(t)),m(e.path),v(e.loadError),I(null),M(!1)}catch(e){A(e instanceof Error?e.message:n.loadError),s({providers:{}}),d({providers:{}})}finally{t&&b(!1)}},[n.loadError]);(0,X.useEffect)(()=>{if(!r){b(!1);return}_e()},[r,_e]);let ve=(0,X.useMemo)(()=>JSON.stringify(i)!==JSON.stringify(u),[i,u]),K=(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]),ye=e=>{R(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},be=e=>{ce(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},xe=(0,X.useCallback)(()=>{se(JSON.stringify(i,null,2)),H(null)},[i]);(0,X.useEffect)(()=>{ie&&xe()},[ie,xe]);let Se=()=>{try{s(Ot(JSON.parse(B))),H(null)}catch{H(n.jsonParseError)}},Ce=async()=>{O(!0),A(null);try{I(await At(i))}catch(e){A(e instanceof Error?e.message:n.validateError)}finally{O(!1)}},we=async()=>{if(!C){E(!0),A(null),M(!1);try{await jt(i),d(structuredClone(i)),M(!0),I(null)}catch(e){A(e instanceof Error?e.message:n.saveError)}finally{E(!1)}}},Te=async()=>{ne(!0),A(null);try{await Mt(),await _e({skipFullPageLoading:!0})}catch(e){A(e instanceof Error?e.message:n.reloadError)}finally{ne(!1)}},Ee=async(e,t)=>{try{let n=await Nt(t);W(t=>{let r=new Map(t);return r.set(e,n),r})}catch(t){W(n=>{let r=new Map(n);return r.set(e,{type:`error`,error:t instanceof Error?t.message:`Error`}),r})}},De=(e=null)=>{fe(e),ue(!0)},Oe=(e,t)=>{s(n=>Jt(n,e,t)),R(t=>new Set(t).add(e))},ke=e=>{window.confirm(n.removeProviderConfirm.replace(`{{id}}`,e))&&(s(t=>qt(t,e)),W(t=>{let n=new Map(t);return n.delete(e),n}))},Ae=(e,t,n)=>{ge({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:N(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)(Le,{className:`size-3.5`})]})]}),h?(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)(w,{className:`mt-0.5 size-4 shrink-0`}),(0,Y.jsxs)(`span`,{children:[n.loadFileWarning,`: `,h]})]}):null,p?(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:p})]}):null,(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,Y.jsxs)(z,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:()=>De(null),disabled:y,children:[(0,Y.jsx)(x,{className:`mr-1 size-4`}),n.addProvider]}),(0,Y.jsx)(z,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:Ce,disabled:y||D,children:D?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(P,{className:`mr-1 size-4 animate-spin`}),n.validating]}):n.validate}),(0,Y.jsx)(z,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:we,disabled:y||C||!ve,children:C?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(P,{className:`mr-1 size-4 animate-spin`}),n.saving]}):n.save}),(0,Y.jsx)(z,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[8.5rem] justify-center`,onClick:Te,disabled:y||te,children:te?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(P,{className:`mr-1 size-4 animate-spin`}),n.reloading]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(T,{className:`mr-1 size-4`}),n.reload]})}),(0,Y.jsx)(z,{type:`button`,variant:`ghost`,className:`text-fg-muted`,onClick:()=>{ae(e=>!e),H(null)},children:ie?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(K.providers))}),(0,Y.jsx)(`span`,{className:`text-fg-subtle`,children:`|`}),(0,Y.jsx)(`span`,{className:`text-fg-muted`,children:n.statsModels.replace(`{{count}}`,String(K.models))})]})]}),ve?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,j?(0,Y.jsx)(`p`,{className:`text-xs text-emerald-700 dark:text-emerald-400`,role:`status`,children:n.saved}):null,k?(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)(w,{className:`size-4 shrink-0`}),k]}):null,F&&F.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:F.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:F.errors.map((e,t)=>(0,Y.jsxs)(`li`,{children:[e.path,`: `,e.message,` (`,e.severity,`)`]},`${e.path}-${t}`))})]}):null,y?(0,Y.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,Y.jsx)(P,{className:`size-4 animate-spin`}),n.loading]}):ie?(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsx)(`textarea`,{className:a(Ht(),`min-h-[320px] resize-y font-mono text-xs leading-relaxed`),value:B,onChange:e=>se(e.target.value),spellCheck:!1}),V?(0,Y.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:V}):null,(0,Y.jsxs)(`div`,{className:`flex gap-2`,children:[(0,Y.jsx)(z,{type:`button`,variant:`secondary`,onClick:xe,children:n.jsonReset}),(0,Y.jsx)(z,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:Se,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)(l,{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)(z,{type:`button`,className:`mb-6 bg-accent text-white hover:bg-accent/90`,onClick:()=>De(null),children:[(0,Y.jsx)(x,{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:a(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,g.transition,g.focusRingBase),onClick:()=>De(`ollama`),children:[(0,Y.jsx)(oe,{className:`size-3.5`,"aria-hidden":!0}),n.presetOllama]}),(0,Y.jsxs)(`button`,{type:`button`,className:a(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,g.transition,g.focusRingBase),onClick:()=>De(`openrouter`),children:[(0,Y.jsx)(c,{className:`size-3.5`,"aria-hidden":!0}),n.presetOpenRouter]}),(0,Y.jsxs)(`button`,{type:`button`,className:a(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,g.transition,g.focusRingBase),onClick:()=>De(`lmstudio`),children:[(0,Y.jsx)(l,{className:`size-3.5`,"aria-hidden":!0}),n.presetLmStudio]}),(0,Y.jsxs)(`button`,{type:`button`,className:a(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,g.transition,g.focusRingBase),onClick:()=>De(`zhipuCn`),children:[(0,Y.jsx)(oe,{className:`size-3.5`,"aria-hidden":!0}),n.presetZhipuCn]}),(0,Y.jsxs)(`button`,{type:`button`,className:a(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,g.transition,g.focusRingBase),onClick:()=>De(`zaiGeneral`),children:[(0,Y.jsx)(c,{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?Lt(t.apiKey):null,c=le.get(e),l=U.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:()=>ye(e),children:[r?(0,Y.jsx)(S,{className:`size-4 shrink-0 text-fg-muted`}):(0,Y.jsx)(f,{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:a(`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:()=>ke(e),"aria-label":n.removeProvider,children:(0,Y.jsx)(Me,{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:Ht(),value:t.baseUrl||``,onChange:t=>s(n=>Kt(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:Ut(),value:t.api||`openai-completions`,onChange:t=>s(n=>Kt(n,e,{api:t.target.value})),children:Et.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:a(Ht(),`min-w-0 flex-1`),type:l?`text`:`password`,autoComplete:`off`,value:t.apiKey||``,onChange:t=>{let n=t.target.value;s(t=>Kt(t,e,{apiKey:n})),W(t=>{let n=new Map(t);return n.delete(e),n})},placeholder:n.apiKeyPlaceholder}),(0,Y.jsx)(z,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>be(e),children:l?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(Ne,{className:`mr-1 size-3.5`}),n.hide]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)(re,{className:`mr-1 size-3.5`}),n.show]})}),(0,Y.jsx)(z,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>Ee(e,t.apiKey||``),children:n.testKey})]}),c?(0,Y.jsx)(`p`,{className:a(`mt-1 text-xs`,c.error?`text-red-600 dark:text-red-400`:`text-emerald-700 dark:text-emerald-400`),children:c.error?`${n.testError}: ${c.error}`:`${n.testOk} (${c.type}): ${Rt(c.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=>s(n=>Kt(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)(z,{type:`button`,variant:`primary`,className:`px-2 py-1 text-xs`,onClick:()=>Ae(e,null,!0),children:[(0,Y.jsx)(x,{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:()=>Ae(e,t,!1),"aria-label":n.editModel,children:(0,Y.jsx)(_,{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))&&s(n=>{let r=n.providers[e];return r?Kt(n,e,{models:(r.models||[]).filter(e=>e.id!==t.id)}):n})},"aria-label":n.removeModel,children:(0,Y.jsx)(Me,{className:`size-4`})})]})]},t.id))})]})]}):null]},e)})}),(0,Y.jsx)(Yt,{open:G,onOpenChange:ue,presetKey:de,onConfirm:Oe,m:n}),(0,Y.jsx)(Xt,{open:pe,onOpenChange:e=>{me(e),e||ge(null)},providerId:he?.providerId??null,model:he?.model??null,isNew:he?.isNew??!1,onSave:e=>{if(!he)return;let{providerId:t,isNew:n}=he;s(r=>{let i=r.providers[t];if(!i)return r;let a=i.models||[];return n?Kt(r,t,{models:[...a,e]}):Kt(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 Qt(){return{enabled:!1,provider:`alibaba`,alibaba:{model:`paraformer-v2`},openai:{model:`whisper-1`},fallback:{enabled:!0,order:[`alibaba`,`openai`]}}}function $t(){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 en(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function tn(e){let t=Qt();if(!en(e))return t;let n=e.provider===`openai`?`openai`:`alibaba`,r=en(e.alibaba)?{...t.alibaba,...e.alibaba}:t.alibaba,i=en(e.openai)?{...t.openai,...e.openai}:t.openai,a=t.fallback??{enabled:!0,order:[`alibaba`,`openai`]};if(en(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 nn(e){return e===`openai`||e===`alibaba`||e===`edge`||e===`minimax`}function rn(e){let t=$t();if(!en(e))return t;let n=nn(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:en(e.alibaba)?{...t.alibaba,...e.alibaba}:t.alibaba,openai:en(e.openai)?{...t.openai,...e.openai}:t.openai,edge:en(e.edge)?{...t.edge,...e.edge}:t.edge,minimax:en(e.minimax)?{...t.minimax,...e.minimax}:t.minimax}}function an(e){let t=en(e)?e:{};return{stt:tn(t.stt),tts:rn(t.tts)}}async function on(e){await b(k(`/api/config`),{method:`PATCH`,body:JSON.stringify({stt:e.stt,tts:e.tts})}),s()}async function sn(){let e=await b(k(`/api/voice/models`));if(!e.payload?.models)throw Error(`Missing voice models payload`);return e.payload.models}function cn(){return a(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,K,`dark:border-edge`)}function ln(){return a(R,Ee)}var un=[{id:`paraformer-v2`,name:`Paraformer v2`},{id:`paraformer-v1`,name:`Paraformer v1`}],dn=[{id:`whisper-1`,name:`Whisper-1`}],fn=[{id:`tts-1`,name:`TTS-1`},{id:`tts-1-hd`,name:`TTS-1 HD`}],pn=[{id:`alloy`,name:`Alloy`},{id:`echo`,name:`Echo`}],mn=[{id:`qwen-tts`,name:`Qwen TTS`},{id:`qwen3-tts-flash`,name:`Qwen3 TTS Flash`}],hn=[{id:`Cherry`,name:`Cherry`},{id:`longxiaochun`,name:`Long Xiao Chun`}],gn=[{id:`en-US-MichelleNeural`,name:`Michelle (US English)`},{id:`zh-CN-XiaoxiaoNeural`,name:`Xiaoxiao (Chinese)`}],_n=[{id:`speech-2.8-hd`,name:`Speech 2.8 HD (Recommended)`},{id:`speech-2.8-turbo`,name:`Speech 2.8 Turbo (Fast)`}],vn=[{id:`male-qn-qingse`,name:`Male Qingse (青涩男声)`},{id:`female-shaonv`,name:`Female Shaonv (少女音)`}];function yn(){let e=o(e=>e.language),t=q(e),n=t.voiceSettings,i=!!ee(e=>e.token),[a,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),[u,d]=(0,X.useState)(null),[f,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)(null),[g,_]=(0,X.useState)(!1),{data:v,error:y,isLoading:b,mutate:x}=W(i),{data:S,error:C,isLoading:w,mutate:T}=r(i?k(`/api/voice/models`):null,sn,{revalidateOnFocus:!1}),E=(0,X.useMemo)(()=>v?.payload?.config===void 0?null:an(v.payload.config),[v]),D=(0,X.useMemo)(()=>!a||!c?!1:JSON.stringify(a)!==JSON.stringify(c),[a,c]);(0,X.useEffect)(()=>{if(!i){s(null),l(null),d(null);return}E===null||S===void 0||D||(s(structuredClone(E)),l(structuredClone(E)),d(S),_(!1))},[i,E,S,D]);let O=!!(i&&(E===null||S===void 0)&&(b||w)),te=y instanceof Error?y.message:y?String(y):C instanceof Error?C.message:C?String(C):null,ne=(0,X.useCallback)(e=>{s(t=>t?{...t,stt:{...t.stt,...e}}:null)},[]),A=(0,X.useCallback)(e=>{s(t=>t?{...t,stt:{...t.stt,alibaba:{...t.stt.alibaba,...e}}}:null)},[]),j=(0,X.useCallback)(e=>{s(t=>t?{...t,stt:{...t.stt,openai:{...t.stt.openai,...e}}}:null)},[]),M=(0,X.useCallback)(e=>{s(t=>{if(!t)return null;let n=t.stt.fallback??{enabled:!0,order:[`alibaba`,`openai`]};return{...t,stt:{...t.stt,fallback:{...n,...e}}}})},[]),F=(0,X.useCallback)(e=>{s(t=>t?{...t,tts:{...t.tts,...e}}:null)},[]),re=(0,X.useCallback)(e=>{s(t=>t?{...t,tts:{...t.tts,alibaba:{...t.tts.alibaba,...e}}}:null)},[]),I=(0,X.useCallback)(e=>{s(t=>t?{...t,tts:{...t.tts,openai:{...t.tts.openai,...e}}}:null)},[]),L=(0,X.useCallback)(e=>{s(t=>t?{...t,tts:{...t.tts,edge:{...t.tts.edge,...e}}}:null)},[]),R=(0,X.useCallback)(e=>{s(t=>t?{...t,tts:{...t.tts,minimax:{...t.tts.minimax,...e}}}:null)},[]),ie=(0,X.useCallback)(async()=>{if(!(!a||f)){p(!0),h(null),_(!1);try{await on(a);let e=structuredClone(a);l(e),s(e),_(!0),window.setTimeout(()=>_(!1),2500)}catch(e){h(e instanceof Error?e.message:n.saveError)}finally{p(!1)}}},[a,f,n.saveError]);if(!i)return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.voice}),(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]});if(O)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)(P,{className:`size-4 animate-spin`}),n.loading]})});if(!a||u===null)return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:m??te??n.loadError}),(0,Y.jsx)(z,{type:`button`,variant:`secondary`,onClick:()=>{x(),T()},children:n.retry})]});let ae=a.stt,B=a.tts;return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.voice}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,Y.jsxs)(`a`,{href:N(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)(Le,{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)(z,{type:`button`,variant:`primary`,disabled:!D||f,onClick:()=>void ie(),children:f?n.saving:n.save})]})]}),D?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,m?(0,Y.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:m}):null,(0,Y.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,Y.jsx)(bn,{v:n,stt:ae,models:u,updateStt:ne,updateSttAlibaba:A,updateSttOpenai:j,updateSttFallback:M}),(0,Y.jsx)(xn,{v:n,tts:B,models:u,updateTts:F,updateTtsAlibaba:re,updateTtsOpenai:I,updateTtsEdge:L,updateTtsMinimax:R})]}),(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 bn({v:e,stt:t,models:n,updateStt:r,updateSttAlibaba:i,updateSttOpenai:o,updateSttFallback:s}){let c=n?.stt?.alibaba?.length?n.stt.alibaba:un,l=n?.stt?.openai?.length?n.stt.openai:dn;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)(m,{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)(Z,{children:e.stt.provider}),(0,Y.jsxs)(`select`,{className:ln(),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)(Z,{children:e.stt.apiKey}),(0,Y.jsx)(`input`,{className:a(cn(),`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)(Z,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:ln(),value:t.alibaba?.model??``,onChange:e=>i({model:e.target.value}),children:c.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}):(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(Z,{children:e.stt.apiKey}),(0,Y.jsx)(`input`,{className:a(cn(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.openai?.apiKey??``,onChange:e=>o({apiKey:e.target.value}),placeholder:`sk-...`}),(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (OPENAI_API_KEY)`]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(Z,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:ln(),value:t.openai?.model??``,onChange:e=>o({model:e.target.value}),children:l.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}),(0,Y.jsxs)(`div`,{className:`flex items-center justify-between gap-2 rounded-xl bg-surface-hover/50 px-3 py-2.5 dark:bg-surface-hover/35`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.stt.fallback}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.stt.fallbackDesc})]}),(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:t.fallback?.enabled??!0,onChange:e=>s({enabled:e.target.checked})})]})]}):null]})]})}function xn({v:e,tts:t,models:n,updateTts:r,updateTtsAlibaba:i,updateTtsOpenai:o,updateTtsEdge:s,updateTtsMinimax:c}){let l=t=>t===`off`?e.tts.triggerDescOff:t===`always`?e.tts.triggerDescAlways:t===`inbound`?e.tts.triggerDescInbound:t===`tagged`?e.tts.triggerDescTagged:``,u=n?.tts?.openai?.length?n.tts.openai:fn,d=n?.ttsVoices?.openai?.length?n.ttsVoices.openai:pn,f=n?.tts?.alibaba?.length?n.tts.alibaba:mn,p=n?.ttsVoices?.alibaba?.length?n.ttsVoices.alibaba:hn,m=n?.ttsVoices?.edge?.length?n.ttsVoices.edge:gn,h=n?.tts?.minimax?.length?n.tts.minimax:_n,g=n?.ttsVoices?.minimax?.length?n.ttsVoices.minimax:vn;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)(he,{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)(Z,{children:e.tts.trigger}),(0,Y.jsxs)(`select`,{className:ln(),value:t.trigger,onChange:e=>r({trigger:e.target.value}),children:[(0,Y.jsx)(`option`,{value:`off`,children:e.tts.triggerOff}),(0,Y.jsx)(`option`,{value:`always`,children:e.tts.triggerAlways}),(0,Y.jsx)(`option`,{value:`inbound`,children:e.tts.triggerInbound}),(0,Y.jsx)(`option`,{value:`tagged`,children:e.tts.triggerTagged})]}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:l(t.trigger)})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(Z,{children:e.tts.provider}),(0,Y.jsxs)(`select`,{className:ln(),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)(Z,{children:e.stt.apiKey}),(0,Y.jsx)(`input`,{className:a(cn(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.openai?.apiKey??``,onChange:e=>o({apiKey:e.target.value}),placeholder:`sk-...`}),(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (OPENAI_API_KEY)`]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(Z,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:ln(),value:t.openai?.model??``,onChange:e=>o({model:e.target.value}),children:u.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(Z,{children:e.tts.voice}),(0,Y.jsx)(`select`,{className:ln(),value:t.openai?.voice??``,onChange:e=>o({voice:e.target.value}),children:d.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}):null,t.provider===`alibaba`?(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,Y.jsx)(Z,{children:e.stt.apiKey}),(0,Y.jsx)(`input`,{className:a(cn(),`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)(Z,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:ln(),value:t.alibaba?.model??``,onChange:e=>i({model:e.target.value}),children:f.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(Z,{children:e.tts.voice}),(0,Y.jsx)(`select`,{className:ln(),value:t.alibaba?.voice??``,onChange:e=>i({voice:e.target.value}),children:p.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}):null,t.provider===`minimax`?(0,Y.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,Y.jsx)(Z,{children:e.stt.apiKey}),(0,Y.jsx)(`input`,{className:a(cn(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.minimax?.apiKey??``,onChange:e=>c({apiKey:e.target.value}),placeholder:`eyJ...`}),(0,Y.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (MINIMAX_API_KEY)`]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(Z,{children:e.stt.model}),(0,Y.jsx)(`select`,{className:ln(),value:t.minimax?.model??``,onChange:e=>c({model:e.target.value}),children:h.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,Y.jsx)(Z,{children:e.tts.voice}),(0,Y.jsx)(`select`,{className:ln(),value:t.minimax?.voice??``,onChange:e=>c({voice:e.target.value}),children:g.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)(Z,{children:e.tts.voice}),(0,Y.jsx)(`select`,{className:ln(),value:t.edge?.voice??``,onChange:e=>s({voice:e.target.value}),children:m.map(e=>(0,Y.jsx)(`option`,{value:e.id,children:e.name},e.id))}),(0,Y.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.edgeHint})]}):null]}):null]})]})}function Z({children:e}){return(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e})}function Sn(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 Cn(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 b(k(`/api/config`),{method:`PATCH`,body:JSON.stringify({tools:{web:{region:t,search:n}}})}),s()}function wn({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 Tn(){return a(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,K,`dark:border-edge`)}function En(){return a(R,Ee)}var Dn=[`brave`,`tavily`,`bing`,`searxng`];function On(){return{type:`brave`,apiKey:``,url:``,disabled:!1}}function kn(){let e=o(e=>e.language),t=q(e),n=t.webSearchSettings,r=t.logs,i=!!ee(e=>e.token),[a,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(null),[m,h]=(0,X.useState)(!1),g=(0,X.useRef)(!1),{data:_,error:v,isLoading:y,mutate:b}=W(i),S=(0,X.useMemo)(()=>_?.payload?.config===void 0?null:Sn(_.payload.config),[_]);(0,X.useEffect)(()=>{if(!i){s(null),l(null),g.current=!1;return}S!==null&&(g.current||(s(S),l(S)))},[i,S]);let C=!!(i&&y&&_===void 0&&!v),w=v instanceof Error?v.message:v?String(v):null,T=(0,X.useMemo)(()=>!a||!c?!1:JSON.stringify(a)!==JSON.stringify(c),[a,c]),E=(0,X.useCallback)(e=>{g.current=!0,s(t=>t?{...t,...e}:null)},[]),D=(0,X.useCallback)(async()=>{if(!(!a||u)){d(!0),p(null),h(!1);try{await Cn(a),g.current=!1,h(!0),window.setTimeout(()=>h(!1),2500)}catch(e){p(e instanceof Error?e.message:n.saveError)}finally{d(!1)}}},[a,u,n.saveError]);return i?C?(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col items-center gap-3 px-4 py-8`,children:[(0,Y.jsx)(P,{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:N(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)(Le,{className:`size-3.5`})]})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[m?(0,Y.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,Y.jsx)(z,{type:`button`,variant:`primary`,disabled:!T||u,onClick:()=>void D(),children:u?n.saving:n.save})]})]}),T?(0,Y.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,f?(0,Y.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:f}):null,(0,Y.jsxs)(Ge,{children:[(0,Y.jsx)(qe,{icon:G,title:n.sectionRegion,subtitle:n.sectionRegionHint}),(0,Y.jsx)(`div`,{className:`flex max-w-md flex-col gap-4`,children:(0,Y.jsx)(wn,{label:n.regionLabel,description:n.regionDesc,children:(0,Y.jsxs)(`select`,{className:En(),value:a.regionMode,onChange:e=>E({regionMode:e.target.value}),children:[(0,Y.jsx)(`option`,{value:`auto`,children:n.regionAuto}),(0,Y.jsx)(`option`,{value:`cn`,children:n.regionCn}),(0,Y.jsx)(`option`,{value:`global`,children:n.regionGlobal})]})})})]}),(0,Y.jsxs)(Ge,{children:[(0,Y.jsx)(qe,{icon:G,title:n.sectionSearch,subtitle:n.sectionSearchHint}),(0,Y.jsxs)(`div`,{className:`flex max-w-xl flex-col gap-6`,children:[(0,Y.jsx)(wn,{label:n.maxResultsLabel,description:n.maxResultsDesc,children:(0,Y.jsx)(`input`,{type:`number`,min:1,max:50,className:Tn(),value:a.maxResults,onChange:e=>E({maxResults:Math.max(1,Math.min(50,Number(e.target.value)||5))})})}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.providersTitle}),a.providers.map((e,t)=>(0,Y.jsx)(An,{row:e,labels:n,onChange:e=>{let n=[...a.providers];n[t]=e,E({providers:n})},onRemove:()=>{E({providers:a.providers.filter((e,n)=>n!==t)})}},t)),(0,Y.jsxs)(z,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5 text-sm`,onClick:()=>E({providers:[...a.providers,On()]}),children:[(0,Y.jsx)(x,{className:`size-4`}),n.addProvider]})]})]})]}),(0,Y.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:n.footerHint})]}):(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:f??w??n.loadError}),(0,Y.jsx)(z,{type:`button`,variant:`secondary`,onClick:()=>void b(),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 An({row:e,labels:t,onChange:n,onRemove:r}){return(0,Y.jsxs)(`div`,{className:`flex flex-col gap-3 rounded-xl border border-edge-subtle bg-surface-panel/60 p-4 dark:border-edge-subtle`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,Y.jsx)(`select`,{className:a(En(),`min-w-[8rem]`),value:e.type,onChange:t=>n({...e,type:t.target.value,url:t.target.value===`searxng`?e.url:``}),children:Dn.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)(z,{type:`button`,variant:`ghost`,className:`h-8 px-2 text-fg-muted`,onClick:r,children:(0,Y.jsx)(Me,{className:`size-4`})})]})]}),e.type===`searxng`?(0,Y.jsx)(wn,{label:t.urlLabel,description:t.urlDesc,children:(0,Y.jsx)(`input`,{type:`url`,className:Tn(),value:e.url,placeholder:`http://localhost:8080`,onChange:t=>n({...e,url:t.target.value})})}):null,(0,Y.jsx)(wn,{label:t.apiKeyLabel,description:t.apiKeyDesc,children:(0,Y.jsx)(`input`,{type:`password`,autoComplete:`off`,className:Tn(),value:_e(e.apiKey)?``:e.apiKey,placeholder:_e(e.apiKey)?t.keyPlaceholderMasked:t.keyPlaceholder,onChange:t=>n({...e,apiKey:t.target.value})})})]})}var jn=[{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 Mn(e,t){let n=q(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 Nn(){let e=o(e=>e.language),t=q(e).systemSettings,[n,r]=(0,X.useState)(null),[i,a]=(0,X.useState)(null),[s,c]=(0,X.useState)(null),l=typeof window<`u`?window.electronAPI?.system:void 0,u=(0,X.useCallback)(async()=>{if(l){c(null);try{r(await l.getBehavior()),a(await l.getPermissions())}catch(e){c(e instanceof Error?e.message:String(e))}}},[l]);if((0,X.useEffect)(()=>{p()&&l&&u()},[l,u]),!p()||!l)return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.title}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:t.desktopOnlyTitle}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:t.desktopOnlyBody})]})]});let f=async e=>{try{let{behavior:t}=await l.setBehavior(e);r(t)}catch(e){c(e instanceof Error?e.message:String(e))}},m=async e=>{try{(await l.openPrivacy(e)).ok||c(`open_privacy failed`)}catch(e){c(e instanceof Error?e.message:String(e))}},h=n?n.platform===`win32`?t.permissionsHintWin:n.platform===`linux`?t.permissionsHintLinux:n.platform===`darwin`?t.permissionsHintDarwin:t.permissionsHint:t.permissionsHint;return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[(0,Y.jsx)(`div`,{children:(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.title})}),s?(0,Y.jsx)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:s}):null,(0,Y.jsxs)(Ge,{children:[(0,Y.jsxs)(`div`,{className:`mb-4 flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)(d,{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=>{f({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=>{f({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=>{f({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=>{f({notifySoundEnabled:e.target.checked})}})]})]})]}),n&&i?(0,Y.jsxs)(`section`,{className:J(),children:[(0,Y.jsxs)(`div`,{className:`mb-4 flex flex-col gap-1 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Y.jsxs)(`div`,{children:[(0,Y.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:t.permissionsTitle}),(0,Y.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:h})]}),(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:jn.map(({key:r,pane:o})=>{let s=Mn(e,i[r]),u=t.perm[r];return u?(0,Y.jsxs)(`li`,{className:`flex flex-col gap-2 rounded-xl border border-edge-subtle bg-surface-panel/60 px-3 py-3 sm:flex-row sm:items-center sm:justify-between`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:u.title}),(0,Y.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:u.desc}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs font-medium ${s.className}`,children:s.label})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[r===`microphone`&&n?.platform===`darwin`?(0,Y.jsx)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover`,onClick:()=>{(async()=>{try{await l.requestMicrophone(),a(await l.getPermissions())}catch(e){c(e instanceof Error?e.message:String(e))}})()},children:e===`zh`?`请求访问`:`Request`}):null,(0,Y.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover`,onClick:()=>void m(o),children:[t.openSettings,(0,Y.jsx)(Le,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0})]})]})]},r):null})})]}):null]})}function Pn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var Fn={enabled:!0,cron:`0 */6 * * *`,lookbackDays:1,limit:50,dedupeSimilarity:.85},In={enabled:!0,cron:`0 3 * * *`,minScore:.8,minRecallCount:3,limit:10,recencyHalfLifeDays:14,maxAgeDays:30},Ln={enabled:!0,cron:`0 5 * * 0`,lookbackDays:7,limit:20,minPatternStrength:.6},Rn={enabled:!1,frequency:`0 3 * * *`,timezone:``,deepEnabled:!0,minScore:.8,minRecallCount:3,limit:10,light:Fn,deep:In,rem:Ln};function zn(e,t){return Number.isFinite(e)?Math.max(0,Math.min(1,e)):t}function Bn(e,t){let n=typeof e==`string`?Number(e):e;return Number.isFinite(n)?Math.max(0,Math.floor(n)):t}function Vn(e,t){let n=typeof e==`string`?Number(e):e;return Number.isFinite(n)?n:t}function Hn(e){let t=Pn(e)?e:{},n=Pn(t.agents)?t.agents:{},r=Pn(n.defaults)?n.defaults:{},i=Pn(r.memory)?r.memory:{},a=Pn(i.dreaming)?i.dreaming:{},o=Pn(a.phases)?a.phases:{},s=Pn(o.light)?o.light:{},c=Pn(o.deep)?o.deep:{},l=Pn(o.rem)?o.rem:{};return{enabled:a.enabled===!0,frequency:typeof a.frequency==`string`&&a.frequency.trim()?a.frequency.trim():Rn.frequency,timezone:typeof a.timezone==`string`?a.timezone:``,deepEnabled:c.enabled!==!1,minScore:zn(typeof c.minScore==`number`?c.minScore:Number(c.minScore),Rn.minScore),minRecallCount:Math.max(1,Bn(c.minRecallCount,Rn.minRecallCount)),limit:Bn(c.limit,Rn.limit),light:{enabled:s.enabled!==!1,cron:typeof s.cron==`string`&&s.cron.trim()?s.cron.trim():Fn.cron,lookbackDays:Math.max(1,Bn(s.lookbackDays,Fn.lookbackDays)),limit:Bn(s.limit,Fn.limit),dedupeSimilarity:zn(Vn(s.dedupeSimilarity,Fn.dedupeSimilarity),Fn.dedupeSimilarity)},deep:{enabled:c.enabled!==!1,cron:typeof c.cron==`string`&&c.cron.trim()?c.cron.trim():In.cron,minScore:zn(Vn(c.minScore,In.minScore),In.minScore),minRecallCount:Math.max(1,Bn(c.minRecallCount,In.minRecallCount)),limit:Bn(c.limit,In.limit),recencyHalfLifeDays:Math.max(1,Vn(c.recencyHalfLifeDays,In.recencyHalfLifeDays)),maxAgeDays:Math.max(1,Vn(c.maxAgeDays,In.maxAgeDays))},rem:{enabled:l.enabled!==!1,cron:typeof l.cron==`string`&&l.cron.trim()?l.cron.trim():Ln.cron,lookbackDays:Math.max(1,Bn(l.lookbackDays,Ln.lookbackDays)),limit:Bn(l.limit,Ln.limit),minPatternStrength:zn(Vn(l.minPatternStrength,Ln.minPatternStrength),Ln.minPatternStrength)}}}async function Un(e){let t=e.frequency.trim(),n=e.timezone.trim();await b(k(`/api/config`),{method:`PATCH`,body:JSON.stringify({agents:{defaults:{memory:{dreaming:{enabled:!!e.enabled,frequency:t||null,timezone:n||null,phases:{light:{enabled:!!e.light.enabled,cron:e.light.cron.trim()||null,lookbackDays:Math.max(1,Math.floor(e.light.lookbackDays)),limit:Math.max(0,Math.floor(e.light.limit)),dedupeSimilarity:zn(e.light.dedupeSimilarity,Fn.dedupeSimilarity)},deep:{enabled:!!e.deep.enabled,cron:e.deep.cron.trim()||null,minScore:zn(e.deep.minScore,In.minScore),minRecallCount:Math.max(1,Math.floor(e.deep.minRecallCount)),limit:Math.max(0,Math.floor(e.deep.limit)),recencyHalfLifeDays:Math.max(1,e.deep.recencyHalfLifeDays),maxAgeDays:Math.max(1,e.deep.maxAgeDays)},rem:{enabled:!!e.rem.enabled,cron:e.rem.cron.trim()||null,lookbackDays:Math.max(1,Math.floor(e.rem.lookbackDays)),limit:Math.max(0,Math.floor(e.rem.limit)),minPatternStrength:zn(e.rem.minPatternStrength,Ln.minPatternStrength)}}}}}}})}),s()}function Q(){return`text-xs font-medium text-fg-muted`}function $(){return`text-sm font-medium text-fg`}function Wn(e){return e?e.replace(`T`,` `).replace(`Z`,``):`—`}function Gn(e){return e===void 0||!Number.isFinite(e)||e<0?`—`:e<1e3?`${Math.round(e)} ms`:`${(e/1e3).toFixed(2)} s`}function Kn({label:e,children:t,className:n}){return(0,Y.jsxs)(`div`,{className:a(`space-y-2`,n),children:[(0,Y.jsx)(`h3`,{className:`text-[0.7rem] font-semibold uppercase tracking-wider text-fg-muted`,children:e}),t]})}function qn({icon:e,label:t,enabled:n,cron:r,details:i,t:o}){return(0,Y.jsxs)(`div`,{className:a(J(),`space-y-1.5`),children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e,(0,Y.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:t}),(0,Y.jsx)(`span`,{className:a(`ml-auto text-xs font-medium`,n?`text-emerald-600 dark:text-emerald-400`:`text-fg-muted`),children:n?o.on:o.off})]}),(0,Y.jsx)(`div`,{className:`font-mono text-xs text-fg-muted`,children:r}),(0,Y.jsx)(`div`,{className:`text-xs text-fg-muted`,children:i})]})}function Jn({label:e,lastRun:t,t:n}){return(0,Y.jsx)(Kn,{label:e,children:t?.exists?(0,Y.jsxs)(`details`,{className:`group rounded-lg border border-edge-subtle`,children:[(0,Y.jsx)(`summary`,{className:`cursor-pointer list-none px-3 py-2 text-xs font-medium text-fg-muted marker:hidden [&::-webkit-details-marker]:hidden`,children:(0,Y.jsx)(`span`,{className:`underline decoration-edge underline-offset-2 group-open:text-fg`,children:n.lastRunRaw})}),(0,Y.jsx)(`pre`,{className:`max-h-[12rem] overflow-auto border-t border-edge-subtle p-3 text-xs text-fg-muted`,children:JSON.stringify(t.raw,null,2)})]}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.phaseLastRunEmpty})})}function Yn({t:e,r:t}){let n=t.deep?.skipped;return(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.lastRunStatus}),(0,Y.jsx)(`div`,{className:a($(),t.ok?`text-emerald-600 dark:text-emerald-400`:`text-amber-600 dark:text-amber-400`),children:t.ok?e.lastRunSuccess:e.lastRunFailure})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.lastRunDuration}),(0,Y.jsx)(`div`,{className:$(),children:Gn(t.durationMs)})]}),(0,Y.jsxs)(`div`,{className:a(J(),`sm:col-span-2`),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.lastRunReason}),(0,Y.jsx)(`div`,{className:$(),children:t.reason}),t.errorMessage?(0,Y.jsx)(`div`,{className:`mt-1 text-xs text-amber-600 dark:text-amber-400`,children:`${e.lastRunError}: ${t.errorMessage}`}):null]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.lastRunRanked}),(0,Y.jsx)(`div`,{className:$(),children:String(t.deep?.candidatesRanked??`—`)})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.lastRunApplied}),(0,Y.jsx)(`div`,{className:$(),children:String(t.deep?.applied??`—`)})]}),n?(0,Y.jsxs)(`div`,{className:`sm:col-span-2`,children:[(0,Y.jsx)(`div`,{className:`mb-2 text-xs font-medium text-fg`,children:e.lastRunSkipped}),(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.lastRunSkipKey}),(0,Y.jsx)(`div`,{className:$(),children:String(n.alreadyPromotedKey)})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.lastRunSkipRehydrate}),(0,Y.jsx)(`div`,{className:$(),children:String(n.rehydrateFailed)})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.lastRunSkipContaminated}),(0,Y.jsx)(`div`,{className:$(),children:String(n.contaminated)})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.lastRunSkipHash}),(0,Y.jsx)(`div`,{className:$(),children:String(n.hashDuplicate)})]})]})]}):null]})}function Xn(e,t){return e.locked?{text:t.lockValueLocked,className:`text-amber-600 dark:text-amber-400`}:{text:t.lockValueUnlocked,className:`text-emerald-600 dark:text-emerald-400`}}function Zn(){let e=q(o(e=>e.language)).dreamingSettings,t=!!ee(e=>e.token),{data:n}=W(t),[i,s]=(0,X.useState)(null),[c,l]=(0,X.useState)(null),[d,f]=(0,X.useState)(!1),[p,m]=(0,X.useState)(!1),[h,g]=(0,X.useState)(!1),[_,v]=(0,X.useState)(null),[y,b]=(0,X.useState)(`deep`),[x,S]=(0,X.useState)(null),[w,E]=(0,X.useState)(null),[D,O]=(0,X.useState)(!1),[k,j]=(0,X.useState)(!1),[M,N]=(0,X.useState)(null),[F,re]=(0,X.useState)(!1),[I,L]=(0,X.useState)(null),[R,ie]=(0,X.useState)(null),[ae,B]=(0,X.useState)(!1),[oe,se]=(0,X.useState)(null),[V,H]=(0,X.useState)(null),{data:U,error:ce,isLoading:le,mutate:G}=r(t?He():null,Ue,{revalidateOnFocus:!1}),ue=(0,X.useMemo)(()=>U?Xn(U.lock,e):null,[U,e]),de=(0,X.useMemo)(()=>{let e=[];return ce&&e.push(ce instanceof Error?ce.message:String(ce)),c&&e.push(c),_&&e.push(_),I&&e.push(I),oe&&e.push(oe),M&&e.push(M),e},[ce,c,_,I,oe,M]),fe=(0,X.useMemo)(()=>{let t=[];return k&&t.push(e.configSaved),h&&t.push(e.runQueued),d&&t.push(e.actionOk),t},[k,h,d,e]),pe=(0,X.useCallback)(async()=>{f(!1),l(null),g(!1),v(null),j(!1),N(null),L(null),await G()},[G]),me=(0,X.useCallback)(async()=>{re(!0),L(null);try{ie((await Je(20)).items??[])}catch(e){L(e instanceof Error?e.message:String(e))}finally{re(!1)}},[]),he=(0,X.useCallback)(async()=>{B(!0),se(null);try{H(await Ke(50))}catch(e){se(e instanceof Error?e.message:String(e))}finally{B(!1)}},[]),ge=(0,X.useCallback)(async(e=`deep`)=>{m(!0),g(!1),v(null);try{await Xe(e),g(!0),await G()}catch(e){v(e instanceof Error?e.message:String(e))}finally{m(!1)}},[G]),_e=(0,X.useCallback)(async e=>{s(e),l(null),f(!1);try{await We(e),f(!0),await G()}catch(e){l(e instanceof Error?e.message:String(e))}finally{s(null)}},[G]),ve=!t||le||!!i,K=(0,X.useMemo)(()=>{let e=n?.payload?.config;return Hn(e??{})},[n]);(0,X.useEffect)(()=>{if(t){if(!w){E(K),S(K);return}JSON.stringify(K)!==JSON.stringify(w)&&(E(K),S(K))}},[w,K,t]);let ye=(0,X.useMemo)(()=>!x||!w?!1:JSON.stringify(x)!==JSON.stringify(w),[x,w]),be=(0,X.useCallback)(async()=>{if(x){O(!0),j(!1),N(null);try{await Un(x),E(x),j(!0),await G()}catch(e){N(e instanceof Error?e.message:String(e))}finally{O(!1)}}},[x,G]);return(0,Y.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[(0,Y.jsxs)(`header`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:e.title}),(0,Y.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e.subtitle})]}),(0,Y.jsxs)(`div`,{className:`flex shrink-0 items-center justify-end gap-2`,children:[(0,Y.jsxs)(`select`,{className:`rounded-lg border border-edge bg-surface-panel px-2 py-1.5 text-xs text-fg`,value:y,onChange:e=>b(e.target.value),disabled:!t||p,children:[(0,Y.jsx)(`option`,{value:`light`,children:`Light`}),(0,Y.jsx)(`option`,{value:`deep`,children:`Deep`}),(0,Y.jsx)(`option`,{value:`rem`,children:`REM`})]}),(0,Y.jsxs)(z,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||p,onClick:()=>void ge(y),title:e.runNowHint,children:[p?(0,Y.jsx)(P,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(Re,{className:`mr-2 size-4`,"aria-hidden":!0}),e.runNow]}),(0,Y.jsxs)(z,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t,onClick:()=>void pe(),children:[(0,Y.jsx)(T,{className:`mr-2 size-4`,"aria-hidden":!0}),e.refresh]})]})]}),de.length>0?(0,Y.jsx)(`div`,{className:`space-y-1.5 rounded-2xl border border-amber-500/20 bg-amber-500/5 px-4 py-3`,role:`alert`,children:de.map((e,t)=>(0,Y.jsx)(`p`,{className:`text-sm text-amber-800 dark:text-amber-200/90`,children:e},t))}):null,fe.length>0?(0,Y.jsx)(`div`,{className:`space-y-1.5 rounded-2xl border border-emerald-500/20 bg-emerald-500/5 px-4 py-3`,role:`status`,children:fe.map((e,t)=>(0,Y.jsx)(`p`,{className:`text-sm text-emerald-800 dark:text-emerald-200/90`,children:e},t))}):null,(0,Y.jsxs)(`div`,{className:`flex flex-col gap-6`,children:[(0,Y.jsxs)(Ge,{className:`min-w-0`,children:[(0,Y.jsx)(qe,{icon:u,title:e.configTitle,subtitle:e.configHint,trailing:(0,Y.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,Y.jsxs)(z,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||!x||D||!ye,onClick:()=>void be(),children:[D?(0,Y.jsx)(P,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,e.saveConfig]}),(0,Y.jsx)(z,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||!x||D||!ye,onClick:()=>{j(!1),N(null),S(w)},children:e.resetConfig})]})}),x?(0,Y.jsxs)(`div`,{className:`space-y-5`,children:[(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-3`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configEnabled}),(0,Y.jsxs)(`label`,{className:`mt-2 inline-flex items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:x.enabled,onChange:e=>S({...x,enabled:e.target.checked})}),(0,Y.jsx)(`span`,{children:x.enabled?e.on:e.off})]})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configFrequency}),(0,Y.jsx)(`input`,{className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle dark:border-edge`,value:x.frequency,onChange:e=>S({...x,frequency:e.target.value}),placeholder:`0 3 * * *`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configTimezone}),(0,Y.jsx)(`input`,{className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle dark:border-edge`,value:x.timezone,onChange:e=>S({...x,timezone:e.target.value}),placeholder:`Asia/Shanghai`})]})]}),(0,Y.jsxs)(Kn,{label:e.configPhaseLight,children:[(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.configPhaseLightHint}),(0,Y.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configPhaseEnabled}),(0,Y.jsxs)(`label`,{className:`mt-2 inline-flex items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:x.light.enabled,onChange:e=>S({...x,light:{...x.light,enabled:e.target.checked}})}),(0,Y.jsx)(`span`,{children:x.light.enabled?e.on:e.off})]})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configPhaseCron}),(0,Y.jsx)(`input`,{className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.light.cron,onChange:e=>S({...x,light:{...x.light,cron:e.target.value}}),placeholder:`0 */6 * * *`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configLightLookbackDays}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.light.lookbackDays,onChange:e=>S({...x,light:{...x.light,lookbackDays:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configLightLimit}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:0,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.light.limit,onChange:e=>S({...x,light:{...x.light,limit:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configLightDedupe}),(0,Y.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.light.dedupeSimilarity,onChange:e=>S({...x,light:{...x.light,dedupeSimilarity:Number(e.target.value)}})})]})]})]}),(0,Y.jsxs)(Kn,{label:e.configPhaseDeep,children:[(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.configPhaseDeepHint}),(0,Y.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configPhaseEnabled}),(0,Y.jsxs)(`label`,{className:`mt-2 inline-flex items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:x.deep.enabled,onChange:e=>S({...x,deep:{...x.deep,enabled:e.target.checked}})}),(0,Y.jsx)(`span`,{children:x.deep.enabled?e.on:e.off})]})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configPhaseCron}),(0,Y.jsx)(`input`,{className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.deep.cron,onChange:e=>S({...x,deep:{...x.deep,cron:e.target.value}}),placeholder:`0 3 * * *`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configDeepMinScore}),(0,Y.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.deep.minScore,onChange:e=>S({...x,deep:{...x.deep,minScore:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configDeepMinRecallCount}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.deep.minRecallCount,onChange:e=>S({...x,deep:{...x.deep,minRecallCount:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configDeepLimit}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:0,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.deep.limit,onChange:e=>S({...x,deep:{...x.deep,limit:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configDeepHalfLife}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.deep.recencyHalfLifeDays,onChange:e=>S({...x,deep:{...x.deep,recencyHalfLifeDays:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configDeepMaxAge}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.deep.maxAgeDays,onChange:e=>S({...x,deep:{...x.deep,maxAgeDays:Number(e.target.value)}})})]})]})]}),(0,Y.jsxs)(Kn,{label:e.configPhaseRem,children:[(0,Y.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.configPhaseRemHint}),(0,Y.jsxs)(`div`,{className:`mt-2 grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-4`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configPhaseEnabled}),(0,Y.jsxs)(`label`,{className:`mt-2 inline-flex items-center gap-2 text-sm text-fg`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:x.rem.enabled,onChange:e=>S({...x,rem:{...x.rem,enabled:e.target.checked}})}),(0,Y.jsx)(`span`,{children:x.rem.enabled?e.on:e.off})]})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configPhaseCron}),(0,Y.jsx)(`input`,{className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.rem.cron,onChange:e=>S({...x,rem:{...x.rem,cron:e.target.value}}),placeholder:`0 5 * * 0`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configRemLookbackDays}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.rem.lookbackDays,onChange:e=>S({...x,rem:{...x.rem,lookbackDays:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configRemLimit}),(0,Y.jsx)(`input`,{type:`number`,step:`1`,min:0,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.rem.limit,onChange:e=>S({...x,rem:{...x.rem,limit:Number(e.target.value)}})})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.configRemMinStrength}),(0,Y.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.rem.minPatternStrength,onChange:e=>S({...x,rem:{...x.rem,minPatternStrength:Number(e.target.value)}})})]})]})]})]}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.configLoading})]}),(0,Y.jsxs)(Ge,{className:`min-w-0`,children:[(0,Y.jsx)(qe,{icon:we,title:e.runtimeTitle,subtitle:e.runtimeHint,trailing:le?(0,Y.jsx)(P,{className:`size-4 shrink-0 animate-spin text-fg-muted`,"aria-hidden":!0}):null}),(0,Y.jsxs)(`div`,{className:`space-y-6`,children:[(0,Y.jsx)(Kn,{label:e.subsectionSchedule,children:(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.enabled}),(0,Y.jsx)(`div`,{className:$(),children:U?U.config.enabled?e.on:e.off:`—`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.lock}),(0,Y.jsx)(`div`,{className:a($(),ue?.className),children:ue?ue.text:`—`})]}),(0,Y.jsxs)(`div`,{className:a(J(),`sm:col-span-2`),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.schedule}),(0,Y.jsx)(`div`,{className:`mt-1 break-all font-mono text-sm text-fg`,children:U?U.config.frequency:`—`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.timezone}),(0,Y.jsx)(`div`,{className:$(),children:U?U.config.timezone:`—`})]})]})}),(0,Y.jsx)(Kn,{label:e.subsectionStore,children:(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 sm:grid-cols-2`,children:[(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.storeEntries}),(0,Y.jsx)(`div`,{className:$(),children:U?String(U.store.entryCount):`—`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.storePromoted}),(0,Y.jsx)(`div`,{className:$(),children:U?String(U.store.promotedCount):`—`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.storeUpdatedAt}),(0,Y.jsx)(`div`,{className:$(),children:U?Wn(U.store.updatedAt):`—`})]}),(0,Y.jsxs)(`div`,{className:J(),children:[(0,Y.jsx)(`div`,{className:Q(),children:e.storeLastPromotedAt}),(0,Y.jsx)(`div`,{className:$(),children:U?Wn(U.store.lastPromotedAt):`—`})]})]})}),U?.config?.phases?(0,Y.jsx)(Kn,{label:e.subsectionPhases,children:(0,Y.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-3`,children:[(0,Y.jsx)(qn,{icon:(0,Y.jsx)(te,{className:`size-4 text-amber-500`}),label:`Light`,enabled:U.config.phases.light.enabled,cron:U.config.phases.light.cron,details:`lookback=${U.config.phases.light.lookbackDays}d, limit=${U.config.phases.light.limit}, dedupe=${U.config.phases.light.dedupeSimilarity}`,t:e}),(0,Y.jsx)(qn,{icon:(0,Y.jsx)(ne,{className:`size-4 text-indigo-500`}),label:`Deep`,enabled:U.config.phases.deep.enabled,cron:U.config.phases.deep.cron,details:`minScore=${U.config.phases.deep.minScore}, recalls≥${U.config.phases.deep.minRecallCount}, limit=${U.config.phases.deep.limit}, halfLife=${U.config.phases.deep.recencyHalfLifeDays}d`,t:e}),(0,Y.jsx)(qn,{icon:(0,Y.jsx)(Fe,{className:`size-4 text-purple-500`}),label:`REM`,enabled:U.config.phases.rem.enabled,cron:U.config.phases.rem.cron,details:`lookback=${U.config.phases.rem.lookbackDays}d, limit=${U.config.phases.rem.limit}, strength≥${U.config.phases.rem.minPatternStrength}`,t:e})]})}):null,(0,Y.jsxs)(Kn,{label:e.subsectionLastRun,children:[(0,Y.jsx)(`p`,{className:`mb-2 text-xs text-fg-muted`,children:e.lastRunBlockHint}),U?.lastRun?.exists?(0,Y.jsxs)(`div`,{className:`space-y-3`,children:[U.lastRun.parseError?(0,Y.jsxs)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:[e.lastRunParseError,`: `,U.lastRun.parseError]}):null,U.lastRun.record?(0,Y.jsx)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel/40 p-2 sm:p-3`,children:(0,Y.jsx)(Yn,{t:e,r:U.lastRun.record})}):null,U.lastRun.raw!==void 0&&U.lastRun.raw!==null?(0,Y.jsxs)(`details`,{className:`group rounded-lg border border-edge-subtle`,children:[(0,Y.jsx)(`summary`,{className:`cursor-pointer list-none px-3 py-2 text-xs font-medium text-fg-muted marker:hidden [&::-webkit-details-marker]:hidden`,children:(0,Y.jsx)(`span`,{className:`underline decoration-edge underline-offset-2 group-open:text-fg`,children:e.lastRunRaw})}),(0,Y.jsx)(`pre`,{className:`max-h-[12rem] overflow-auto border-t border-edge-subtle p-3 text-xs text-fg-muted`,children:JSON.stringify(U.lastRun.raw,null,2)})]}):null]}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.lastRunEmpty})]}),(0,Y.jsx)(Jn,{label:e.subsectionLightLastRun,lastRun:U?.lightLastRun,t:e}),(0,Y.jsx)(Jn,{label:e.subsectionRemLastRun,lastRun:U?.remLastRun,t:e})]})]})]}),(0,Y.jsxs)(Ge,{children:[(0,Y.jsx)(qe,{icon:C,title:e.previewTitle,subtitle:e.previewHint,trailing:(0,Y.jsxs)(z,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||F,onClick:()=>void me(),children:[F?(0,Y.jsx)(P,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,e.previewLoad]})}),R?R.length>0?(0,Y.jsx)(`div`,{className:`space-y-2`,children:R.map(t=>{let n=`${t.path}:${t.startLine}-${t.endLine}`,r=t.skippedReason;return(0,Y.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel/60 px-3 py-3`,children:[(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-fg-muted`,children:[(0,Y.jsx)(`span`,{className:`font-medium text-fg`,children:n}),(0,Y.jsxs)(`span`,{children:[`score=`,t.score.toFixed(3)]}),(0,Y.jsxs)(`span`,{children:[`recalls=`,t.recallCount]}),(0,Y.jsxs)(`span`,{children:[`avg=`,t.avgScore.toFixed(3)]}),(0,Y.jsxs)(`span`,{children:[`decay=`,t.recencyDecay?.toFixed(3)??`—`]}),r?(0,Y.jsx)(`span`,{className:`text-amber-600 dark:text-amber-400`,children:r}):(0,Y.jsx)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:e.previewEligible})]}),t.snippet?(0,Y.jsx)(`div`,{className:`mt-2 text-sm text-fg`,children:t.snippet}):null]},`${t.key}:${t.hash}:${n}`)})}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.previewEmpty}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.previewNotLoaded})]}),(0,Y.jsxs)(Ge,{children:[(0,Y.jsx)(qe,{icon:we,title:e.eventsTitle,subtitle:e.eventsHint,trailing:(0,Y.jsxs)(z,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||ae,onClick:()=>void he(),children:[ae?(0,Y.jsx)(P,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,e.eventsLoad]})}),V?V.length>0?(0,Y.jsx)(`div`,{className:`space-y-1.5`,children:V.map((e,t)=>{let n=e.phase===`light`?`☀️`:e.phase===`rem`?`✨`:`🌙`,r=e.phase===`light`?`scanned=${e.scannedEntries??0} new=${e.newSignals??0} deduped=${e.deduped??0}`:e.phase===`rem`?`patterns=${e.patternsDiscovered??0} analyzed=${e.entriesAnalyzed??0}`:`candidates=${e.candidates??0} applied=${e.applied??0}`;return(0,Y.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 rounded-lg border border-edge-subtle bg-surface-panel/60 px-3 py-2 text-xs`,children:[(0,Y.jsx)(`span`,{children:n}),(0,Y.jsx)(`span`,{className:`font-medium text-fg`,children:e.phase}),(0,Y.jsx)(`span`,{className:a(`font-medium`,e.ok?`text-emerald-600 dark:text-emerald-400`:`text-amber-600 dark:text-amber-400`),children:e.ok?`OK`:`FAIL`}),(0,Y.jsx)(`span`,{className:`text-fg-muted`,children:r}),(0,Y.jsx)(`span`,{className:`text-fg-muted`,children:Gn(e.durationMs)}),(0,Y.jsx)(`span`,{className:`ml-auto text-fg-subtle`,children:Wn(e.timestamp)})]},`${e.timestamp}:${e.phase}:${t}`)})}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.eventsEmpty}):(0,Y.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.eventsNotLoaded})]}),(0,Y.jsxs)(Ge,{className:`max-w-2xl`,children:[(0,Y.jsx)(qe,{icon:Se,title:e.maintenanceTitle,subtitle:e.maintenanceHint}),(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,Y.jsxs)(z,{variant:`secondary`,disabled:ve,onClick:()=>{confirm(e.confirmResetStore)&&_e(`reset_store`)},children:[i===`reset_store`?(0,Y.jsx)(P,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(Me,{className:`mr-2 size-4`,"aria-hidden":!0}),e.resetStore]}),(0,Y.jsxs)(z,{variant:`secondary`,disabled:ve,onClick:()=>{confirm(e.confirmClearLock)&&_e(`clear_lock`)},children:[i===`clear_lock`?(0,Y.jsx)(P,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(A,{className:`mr-2 size-4`,"aria-hidden":!0}),e.clearLock]})]})]})]})}function Qn({open:e,title:t,description:n,confirmLabel:r,cancelLabel:i,destructive:o,onConfirm:s,onCancel:c}){return(0,Y.jsx)(se,{open:e,onOpenChange:e=>{e||c()},children:(0,Y.jsxs)(je,{children:[(0,Y.jsx)(pe,{className:`xopc-dialog-overlay fixed inset-0 z-[70] bg-scrim backdrop-blur-[1px]`}),(0,Y.jsxs)(ke,{className:a(`fixed left-1/2 top-1/2 z-[70] w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2`,`rounded-2xl border border-edge bg-surface-panel p-6 shadow-popover outline-none dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,Y.jsx)(H,{className:`text-base font-semibold text-fg`,children:t}),(0,Y.jsx)(B,{className:`mt-2 text-sm text-fg-muted`,children:n}),(0,Y.jsxs)(`div`,{className:`mt-6 flex justify-end gap-2`,children:[(0,Y.jsx)(z,{type:`button`,variant:`secondary`,onClick:c,children:i}),(0,Y.jsx)(z,{type:`button`,variant:`secondary`,className:a(o&&`border-danger/40 bg-danger text-white hover:bg-danger/90 dark:border-danger/40`),onClick:s,children:r})]})]})]})})}async function $n(e){let t=await h(k(`/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 er(e){let t=await h(k(`/api/auth/oauth-async/${encodeURIComponent(e)}/status`));if(!t.ok)throw Error(`OAuth status: ${t.status}`);return(await t.json()).payload}async function tr(e,t){let n=await h(k(`/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 nr(e){let t=await h(k(`/api/auth/oauth-async/${encodeURIComponent(e)}/cancel`),{method:`POST`});if(!t.ok)throw Error(`Cancel OAuth failed: ${t.status}`)}async function rr(e){let t=await h(k(`/api/auth/oauth-async/${encodeURIComponent(e)}`),{method:`DELETE`});if(!t.ok)throw Error(`Cleanup session failed: ${t.status}`)}async function ir(e){let t=await h(k(`/api/auth/oauth/${encodeURIComponent(e)}`),{method:`DELETE`});if(!t.ok)throw Error(`Revoke OAuth failed: ${t.status}`)}function ar({providerId:e,language:t}){let n=De[e];if(!n)return null;let r=t===`zh`,i=r&&n.descriptionZh?n.descriptionZh:n.description;return i?(0,Y.jsxs)(I,{children:[(0,Y.jsx)(Pe,{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)(Oe,{className:`size-3.5`,"aria-hidden":!0})})}),(0,Y.jsx)(U,{children:(0,Y.jsxs)(ce,{side:`right`,align:`start`,sideOffset:6,className:a(`z-50 w-64 rounded-xl border border-edge bg-surface-panel p-3 shadow-md`,`data-[state=open]:animate-in data-[state=closed]:animate-out`,`data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,`data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95`),children:[(0,Y.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,Y.jsx)(`p`,{className:`text-xs font-semibold text-fg`,children:e}),(0,Y.jsx)(ge,{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)(Le,{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)(Le,{className:`size-3`,"aria-hidden":!0})]}):null]}):null,(0,Y.jsx)(Ce,{className:`fill-edge`})]})})]}):null}var or=[`common`,`specialty`,`enterprise`,`oauth`,`extension`];function sr(e){let t=new Map;for(let e of or)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 cr(e,t){return e.replace(/\{\{(\w+)\}\}/g,(e,n)=>String(t[n]??``))}function lr(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 ur(){let e=o(e=>e.language),t=q(e),n=t.providersSettings,i=!!ee(e=>e.token),[s,c]=(0,X.useState)({}),[l,u]=(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`])),[x,C]=(0,X.useState)(``),[w,T]=(0,X.useState)(!1),[E,D]=(0,X.useState)(()=>new Set),O=(0,X.useRef)(``),te=k(`/api/providers/meta`),ne=(0,X.useCallback)(async e=>(await b(e)).payload?.providers??[],[]),{data:A,error:j,isLoading:M,mutate:P}=W(i),{data:F,error:re,isLoading:I,mutate:R}=r(i?te:null,ne,{revalidateOnFocus:!1}),{data:ie,mutate:ae}=r(i?xe:null,()=>me(),{revalidateOnFocus:!1}),B=(0,X.useMemo)(()=>!F||A===void 0?null:Te(F,L(A.payload?.config),ie??[]),[F,A,ie]),oe=j instanceof Error?j.message:j?String(j):re instanceof Error?re.message:re?String(re):null,se=!!(i&&B===null&&(M||I)&&!oe),V=(0,X.useMemo)(()=>JSON.stringify(s)!==JSON.stringify(l),[s,l]);(0,X.useEffect)(()=>{if(!V)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[V]),(0,X.useEffect)(()=>{if(!(!i||B===null)&&!V){let e={};for(let t of B)e[t.id]=t.apiKey;c(e),u({...e})}},[i,B,V]);let H=B??[],U=(0,X.useMemo)(()=>{let e=H,t=x.trim().toLowerCase();return t&&(e=e.filter(e=>{let n=De[e.id]?.aliases??[];return e.id.toLowerCase().includes(t)||e.name.toLowerCase().includes(t)||n.some(e=>e.toLowerCase().includes(t))})),w&&(e=e.filter(e=>!e.configured)),e},[H,x,w]),ce=(0,X.useMemo)(()=>sr(U),[U]);(0,X.useEffect)(()=>{let e=O.current;if(O.current=x,x.trim()){let e=new Set;for(let t of or)(ce.get(t)??[]).length>0&&e.add(t);v(e);return}e.trim()&&v(new Set([`common`]))},[x,ce]);let de=(0,X.useCallback)(async()=>{if(d)return;let e={};for(let t of Object.keys(s)){let n=s[t]?.trim()??``;!n||_e(n)||(e[t]=n)}if(Object.keys(e).length===0){u({...s}),g(`noChanges`),window.setTimeout(()=>g(null),2500);return}f(!0),m(null),g(null);try{await le(e),D(new Set(Object.keys(e)));let t=await ae(me(!0))??ie??[],[n,r]=await Promise.all([P(),R()]),i=Array.isArray(r)?r:F??[],a=n??A;if(a?.payload){let e=Te(i,L(a.payload.config),t),n={};for(let t of e)n[t.id]=t.apiKey;c(n),u({...n})}g(`saved`),window.setTimeout(()=>g(null),2500)}catch(e){m(e instanceof Error?e.message:n.saveError)}finally{f(!1)}},[A,s,F,ie,P,R,ae,n.saveError,d]),fe=(0,X.useCallback)(()=>{c({...l}),m(null),g(null),D(new Set)},[l]),pe=e=>{v(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},he=(0,X.useCallback)(()=>{P(),R()},[P,R]),ge=!!(x.trim()||w);return i?se?(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})]}):H.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??oe??n.empty})]}),(0,Y.jsx)(z,{type:`button`,variant:`secondary`,onClick:()=>{P(),R()},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)(z,{type:`button`,variant:`secondary`,disabled:!V||d,onClick:fe,children:n.discard}),(0,Y.jsx)(z,{type:`button`,variant:`primary`,disabled:!V||d,onClick:()=>void de(),children:d?n.saving:n.save})]})]}),V?(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:N(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)(y,{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)(G,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-fg-subtle`,strokeWidth:1.75,"aria-hidden":!0}),(0,Y.jsx)(`input`,{type:`search`,value:x,onChange:e=>C(e.target.value),placeholder:n.searchPlaceholder,autoComplete:`off`,className:a(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-10 pr-3 text-sm text-fg placeholder:text-fg-subtle`,K,`dark:border-edge`),"aria-label":n.searchPlaceholder})]}),(0,Y.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg-muted`,children:[(0,Y.jsx)(`input`,{type:`checkbox`,checked:w,onChange:e=>T(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]}),ge?(0,Y.jsx)(z,{type:`button`,variant:`ghost`,className:`h-9 w-fit self-start text-fg-muted`,onClick:()=>{C(``),T(!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,U.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)(z,{type:`button`,variant:`secondary`,className:`mt-4`,onClick:()=>{C(``),T(!1)},children:n.clearFilters})]}):(0,Y.jsx)(`div`,{className:`flex flex-col gap-3`,children:or.map(t=>{let r=ce.get(t)??[];if(r.length===0)return null;let i=_.has(t),o=r.filter(e=>e.configured).length,u=`providers-cat-${t}`;return(0,Y.jsxs)(`section`,{className:`overflow-hidden rounded-2xl bg-surface-base`,children:[(0,Y.jsxs)(`button`,{type:`button`,id:`${u}-trigger`,"aria-expanded":i,"aria-controls":u,className:`flex w-full items-center justify-between gap-2 border-b border-edge-subtle px-4 py-3 text-left transition-colors hover:bg-surface-hover/60 dark:border-edge-subtle`,onClick:()=>pe(t),children:[(0,Y.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 text-sm font-semibold text-fg`,children:[(0,Y.jsx)(`span`,{className:`truncate`,children:n.categories[t]}),(0,Y.jsx)(`span`,{className:`shrink-0 rounded bg-surface-hover px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-fg-subtle`,children:r.length})]}),(0,Y.jsxs)(`span`,{className:`flex shrink-0 items-center gap-2`,children:[o>0?(0,Y.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-fg-subtle`,children:[(0,Y.jsx)(ue,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}),cr(n.configuredCount,{count:String(o)})]}):null,(0,Y.jsx)(S,{className:a(`size-4 text-fg-subtle transition-transform`,i&&`rotate-180`),"aria-hidden":!0})]})]}),i?(0,Y.jsx)(`div`,{id:u,role:`region`,"aria-labelledby":`${u}-trigger`,className:`divide-y divide-edge-subtle`,children:r.map(t=>(0,Y.jsx)(`div`,{id:`provider-row-${t.id}`,children:(0,Y.jsx)(fr,{row:t,value:s[t.id]??``,rowDirty:(s[t.id]??``)!==(l[t.id]??``),labels:n,language:e,onChange:(e,t)=>c(n=>({...n,[e]:t})),onReload:he,justSaved:E.has(t.id),availableModels:ie??[]})},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)(ye,{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 dr({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)(ue,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):(0,Y.jsx)(Ie,{className:`size-3.5`,"aria-hidden":!0})})]})}function fr({row:e,value:t,rowDirty:n,labels:r,language:i,onChange:o,onReload:s,justSaved:c,availableModels:l}){let[u,d]=(0,X.useState)(!1),[f,p]=(0,X.useState)(!1),[m,h]=(0,X.useState)(!1),[_,y]=(0,X.useState)(null),[ee,b]=(0,X.useState)(!1),[x,C]=(0,X.useState)(null),[T,E]=(0,X.useState)(!1),D=_e(t),O=D&&!f?``:t,te=e.configured&&!D&&!!t,[ne,k]=(0,X.useState)(!1),[A,M]=(0,X.useState)(),[N,F]=(0,X.useState)(),[I,L]=(0,X.useState)(),[R,ae]=(0,X.useState)(),[B,oe]=(0,X.useState)(),[se,H]=(0,X.useState)(``),[U,ce]=(0,X.useState)(!1),[le,W]=(0,X.useState)(null),[G,de]=(0,X.useState)(null),pe=e.activeKeySource??`none`,me=(0,X.useMemo)(()=>ie(e.id,i),[e.id,i]);(0,X.useEffect)(()=>()=>{A&&rr(A).catch(()=>{})},[A]),(0,X.useEffect)(()=>{if(!A||!ne)return;let e=window.setInterval(()=>{(async()=>{try{let t=await er(A);L(t.message),ae(t.authUrl),oe(t.instructions),t.status===`waiting_auth`||t.status===`waiting_code`?F(t.status===`waiting_code`?`waiting_code`:`waiting`):t.status===`completed`?(window.clearInterval(e),k(!1),F(`success`),L(t.message),window.setTimeout(()=>s(),800)):(t.status===`failed`||t.status===`cancelled`)&&(window.clearInterval(e),k(!1),F(`error`),L(t.error||t.message||`OAuth failed`))}catch{}})()},1e3);return()=>window.clearInterval(e)},[A,ne,s]);let he=async()=>{k(!0),F(`waiting`),L(r.oauthStarting),M(void 0),ae(void 0),oe(void 0);try{M((await $n(e.id)).sessionId)}catch(e){F(`error`),L(e instanceof Error?e.message:`OAuth failed`),k(!1)}},ge=async()=>{if(A){try{await nr(A)}catch{}M(void 0),k(!1),F(`idle`),L(void 0)}},be=async()=>{if(!(!A||!se.trim()))try{await tr(A,se.trim()),H(``),L(r.oauthProcessingCode)}catch(e){F(`error`),L(e instanceof Error?e.message:`Failed`)}},xe=()=>{window.confirm(cr(r.revokeConfirm,{name:e.name}))&&(y(null),ir(e.id).then(()=>s()).catch(e=>y(e instanceof Error?e.message:r.revokeFailed)))},Se=async()=>{E(!1),b(!0),C(null);try{await Ae(e.id),C(r.removeKeySuccess),o(e.id,``),window.setTimeout(()=>s(),600)}catch(e){C(e instanceof Error?e.message:r.removeKeyFailed)}finally{b(!1)}},Ce=e.configured&&D&&pe!==`env`&&pe!==`extension`&&pe!==`models_json`,we=async()=>{if(!(!t||D))try{await navigator.clipboard.writeText(t),h(!0),window.setTimeout(()=>h(!1),2e3)}catch{}},Te=async()=>{let e=t.trim();if(!(!e||_e(e))){ce(!0),W(null),de(null);try{let t=await ve(e);if(t.error){de(!1),W(`${r.testFailed} ${t.error}`);return}de(!0),t.type===`env`?W(r.testOkEnv):t.type===`command`?W(r.testOkCommand):W(r.testOkLiteral)}catch(e){de(!1),W(e instanceof Error?e.message:r.testFailed)}finally{ce(!1)}}},Ee=n?r.metaWillSave:e.configured?D?`${r.metaMasked} · ${r.runtimeLabelPrefix} ${lr(r,pe)}`:`${r.runtimeLabelPrefix} ${lr(r,pe)}`:r.metaNotConfigured,q=`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)(ue,{className:`size-4 text-emerald-600 dark:text-emerald-400`}):(0,Y.jsx)(ye,{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)(ar,{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:Ee})]}),(0,Y.jsx)(z,{type:`button`,variant:`ghost`,className:`h-9 w-9 shrink-0 p-0`,"aria-expanded":u,"aria-controls":q,"aria-label":r.expandRowDetails,onClick:()=>d(e=>!e),children:(0,Y.jsx)(S,{className:a(`size-4 transition-transform`,u&&`rotate-180`),"aria-hidden":!0})})]}),u?(0,Y.jsxs)(`div`,{id:q,role:`region`,className:`space-y-3 border-t border-edge-subtle bg-surface-base/40 px-3 py-3 dark:bg-surface-base/20 sm:px-4`,children:[e.supportsApiKey===!1?null:(0,Y.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,Y.jsxs)(`div`,{className:`relative flex flex-col gap-2 sm:flex-row sm:gap-2`,children:[(0,Y.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,Y.jsx)(`input`,{type:f||!D?`text`:`password`,className:a(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-3 pr-20 font-mono text-sm text-fg`,`placeholder:text-fg-subtle`,K,`dark:border-edge`),value:O,placeholder:D?r.placeholderOverride:e.configured?r.placeholderKeep:r.placeholderKey,disabled:ne,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&&!D?(0,Y.jsx)(`button`,{type:`button`,className:a(`rounded p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,g.transition,g.press,g.focusRingPanel),title:m?r.copied:r.copy,"aria-label":m?r.copied:r.copy,onClick:()=>void we(),children:m?(0,Y.jsx)(ue,{className:`size-4`}):(0,Y.jsx)(Ie,{className:`size-4`})}):null,(0,Y.jsx)(`button`,{type:`button`,className:a(`rounded p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg disabled:opacity-40`,g.transition,g.press,g.focusRingPanel),title:f?r.hide:r.show,"aria-label":f?r.hide:r.show,disabled:D,onClick:()=>p(e=>!e),children:f?(0,Y.jsx)(Ne,{className:`size-4`}):(0,Y.jsx)(re,{className:`size-4`})})]})]}),(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2 sm:shrink-0`,children:[(0,Y.jsxs)(z,{type:`button`,variant:`secondary`,className:`gap-1`,disabled:ne||U||!t.trim()||_e(t),onClick:()=>void Te(),children:[U?(0,Y.jsx)(P,{className:`size-4 animate-spin`,"aria-hidden":!0}):null,U?r.testingKey:r.testKey]}),e.supportsOAuth?te?(0,Y.jsxs)(z,{type:`button`,variant:`secondary`,className:`gap-1 text-red-600 dark:text-red-400`,onClick:xe,children:[(0,Y.jsx)(v,{className:`size-4`,"aria-hidden":!0}),r.revoke]}):(0,Y.jsxs)(z,{type:`button`,variant:`secondary`,className:`gap-1`,disabled:ne,onClick:()=>void he(),children:[ne?(0,Y.jsx)(P,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(j,{className:`size-4`,"aria-hidden":!0}),r.oauth]}):null,Ce?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(z,{type:`button`,variant:`secondary`,className:`gap-1 text-red-600 dark:text-red-400`,disabled:ee,onClick:()=>E(!0),children:[ee?(0,Y.jsx)(P,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,Y.jsx)(Me,{className:`size-4`,"aria-hidden":!0}),r.removeKey]}),(0,Y.jsx)(Qn,{open:T,title:r.removeKey,description:cr(r.removeKeyConfirm,{name:e.name}),confirmLabel:r.removeKey,cancelLabel:r.cancelOAuth,destructive:!0,onConfirm:()=>void Se(),onCancel:()=>E(!1)})]}):null]})]}),le?(0,Y.jsx)(`p`,{className:a(`text-xs`,G===!1?`text-red-600 dark:text-red-400`:`text-fg-muted`),role:`status`,children:le}):null,me.length>0?(0,Y.jsx)(`div`,{className:`flex flex-col gap-1`,children:me.map(e=>(0,Y.jsxs)(`a`,{href:e.href,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex w-fit items-center gap-1 text-xs font-medium text-accent-fg hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:[fe(e.kind,r),(0,Y.jsx)(Le,{className:`size-3`,"aria-hidden":!0})]},`${e.kind}-${e.href}`))}):null]}),I?(0,Y.jsxs)(`div`,{className:a(`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)(w,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}):N===`success`?(0,Y.jsx)(ue,{className:`mt-0.5 size-4 shrink-0 text-emerald-600`,"aria-hidden":!0}):(0,Y.jsx)(Oe,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:I})]}):null,_?(0,Y.jsxs)(`div`,{className:`flex gap-2 rounded-md border border-red-200 bg-red-50 px-3 py-2 text-xs text-red-700 dark:border-red-900/50 dark:bg-red-950/50 dark:text-red-400`,role:`alert`,children:[(0,Y.jsx)(w,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:_})]}):null,x?(0,Y.jsxs)(`div`,{className:a(`flex gap-2 rounded-md px-3 py-2 text-xs`,x===r.removeKeySuccess?`bg-surface-hover/60 text-fg-muted dark:bg-surface-hover/40`:`border border-red-200 bg-red-50 text-red-700 dark:border-red-900/50 dark:bg-red-950/50 dark:text-red-400`),role:`status`,children:[x===r.removeKeySuccess?(0,Y.jsx)(ue,{className:`mt-0.5 size-4 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):(0,Y.jsx)(w,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:x})]}):null,(N===`waiting`||N===`waiting_code`)&&(0,Y.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[R?(0,Y.jsxs)(`a`,{href:R,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)(Le,{className:`size-4`,"aria-hidden":!0}),r.openAuthPage]}):null,(0,Y.jsxs)(z,{type:`button`,variant:`secondary`,className:`gap-1`,onClick:()=>void ge(),children:[(0,Y.jsx)(V,{className:`size-4`,"aria-hidden":!0}),r.cancelOAuth]})]}),B?(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)(Oe,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:B})]}):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:a(`min-w-0 flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,K,`dark:border-edge`),value:se,placeholder:r.pasteRedirectUrl,onChange:e=>H(e.target.value),onKeyDown:e=>e.key===`Enter`&&void be()}),(0,Y.jsx)(z,{type:`button`,variant:`primary`,className:`shrink-0`,onClick:()=>void be(),children:r.submitCode})]}):null,D?(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)(Oe,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:pe===`env`?r.envHint:r.maskedStoredHint})]}):null,e.supportsOAuth&&!D&&!te?(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)(ue,{className:`mt-0.5 size-3.5 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}),(0,Y.jsx)(`span`,{children:(()=>{let t=l.filter(t=>t.provider===e.id);if(t.length===0)return r.savedNoModels;let n=t.slice(0,3).map(e=>e.name||e.id).join(`, `),i=t.length>3?`… (+${t.length-3})`:``;return`${t.length} ${r.savedModelsAvailable}: ${n}${i}`})()})]}):null,(De[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:(De[e.id]?.envVars??[]).map(e=>(0,Y.jsx)(dr,{envVar:e,labels:r},e))})]}):null]}):null]})}var pr=[`appearance`,`system`,`agent-defaults`,`providers`,`models`,`voice`,`gateway`,`heartbeat`,`search`,`dreams`];function mr(){let{section:e}=E(),t=o(e=>e.language),n=q(t);if(e===`agent`||e===`agents`)return(0,Y.jsx)(M,{to:`/agents`,replace:!0});if(!e||!pr.includes(e))return(0,Y.jsx)(M,{to:`/settings/appearance`,replace:!0});let r=e,i=n.settingsSections[r];return r===`appearance`?(0,Y.jsx)(tt,{}):r===`system`?(0,Y.jsx)(Nn,{}):r===`agent-defaults`?(0,Y.jsx)(Ye,{}):r===`providers`?(0,Y.jsx)(ur,{}):r===`models`?(0,Y.jsx)(Zt,{}):r===`voice`?(0,Y.jsx)(yn,{}):r===`gateway`?(0,Y.jsx)(ot,{}):r===`heartbeat`?(0,Y.jsx)(wt,{}):r===`search`?(0,Y.jsx)(kn,{}):r===`dreams`?(0,Y.jsx)(Zn,{}):(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{mr as SettingsPage};
2
+ //# sourceMappingURL=settings-page-DU2XLf5s.js.map