@xopcai/xopc 0.0.58 → 0.0.59

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 (167) hide show
  1. package/dist/extensions/feishu/src/outbound/media-load.js +1 -1
  2. package/dist/extensions/telegram/src/plugin.js +1 -1
  3. package/dist/extensions/telegram/src/routing-integration.js +2 -2
  4. package/dist/extensions/telegram/xopc.extension.json +1 -1
  5. package/dist/extensions/weixin/src/api/api.js +2 -2
  6. package/dist/extensions/weixin/src/auth/accounts.js +1 -1
  7. package/dist/extensions/weixin/src/cdn/upload.js +1 -1
  8. package/dist/extensions/weixin/src/media/data-url.js +1 -1
  9. package/dist/extensions/weixin/src/messaging/debug-mode.js +1 -1
  10. package/dist/extensions/weixin/src/messaging/inbound.js +1 -1
  11. package/dist/extensions/weixin/src/messaging/process-message.js +1 -1
  12. package/dist/extensions/weixin/src/plugin.js +1 -1
  13. package/dist/extensions/weixin/src/storage/sync-buf.js +1 -1
  14. package/dist/gateway/static/root/assets/{agents-kfTaZM98.js → agents-BgeuYTaG.js} +2 -2
  15. package/dist/gateway/static/root/assets/{agents-kfTaZM98.js.map → agents-BgeuYTaG.js.map} +1 -1
  16. package/dist/gateway/static/root/assets/{apps-page-DD4Y41az.js → apps-page-DXOoxQ3t.js} +2 -2
  17. package/dist/gateway/static/root/assets/{apps-page-DD4Y41az.js.map → apps-page-DXOoxQ3t.js.map} +1 -1
  18. package/dist/gateway/static/root/assets/{channels-settings-CzQhBqZZ.js → channels-settings-BtblELP8.js} +2 -2
  19. package/dist/gateway/static/root/assets/{channels-settings-CzQhBqZZ.js.map → channels-settings-BtblELP8.js.map} +1 -1
  20. package/dist/gateway/static/root/assets/{cron-dreaming-jobs-Bw0WqucT.js → cron-dreaming-jobs-D5kvbjSY.js} +2 -2
  21. package/dist/gateway/static/root/assets/{cron-dreaming-jobs-Bw0WqucT.js.map → cron-dreaming-jobs-D5kvbjSY.js.map} +1 -1
  22. package/dist/gateway/static/root/assets/{cron-page-DzdhjVlI.js → cron-page-4hk422N-.js} +2 -2
  23. package/dist/gateway/static/root/assets/{cron-page-DzdhjVlI.js.map → cron-page-4hk422N-.js.map} +1 -1
  24. package/dist/gateway/static/root/assets/{dist-CwfwOj0f.js → dist-CEmPWsYK.js} +2 -2
  25. package/dist/gateway/static/root/assets/{dist-CwfwOj0f.js.map → dist-CEmPWsYK.js.map} +1 -1
  26. package/dist/gateway/static/root/assets/{extension-debug-page-6MugjoYl.js → extension-debug-page-z0vfOyIu.js} +2 -2
  27. package/dist/gateway/static/root/assets/{extension-debug-page-6MugjoYl.js.map → extension-debug-page-z0vfOyIu.js.map} +1 -1
  28. package/dist/gateway/static/root/assets/{extension-page-DG6W4O_G.js → extension-page-CFaT0yHk.js} +2 -2
  29. package/dist/gateway/static/root/assets/{extension-page-DG6W4O_G.js.map → extension-page-CFaT0yHk.js.map} +1 -1
  30. package/dist/gateway/static/root/assets/{extension-settings-page-DmmeUN--.js → extension-settings-page-7atlEJU0.js} +2 -2
  31. package/dist/gateway/static/root/assets/{extension-settings-page-DmmeUN--.js.map → extension-settings-page-7atlEJU0.js.map} +1 -1
  32. package/dist/gateway/static/root/assets/{heartbeat-config-api-BzwYrxvL.js → heartbeat-config-api-DnmmSrTx.js} +2 -2
  33. package/dist/gateway/static/root/assets/{heartbeat-config-api-BzwYrxvL.js.map → heartbeat-config-api-DnmmSrTx.js.map} +1 -1
  34. package/dist/gateway/static/root/assets/{index-BDiwAtHo.js → index-DvMI6Vqn.js} +4 -4
  35. package/dist/gateway/static/root/assets/{index-BDiwAtHo.js.map → index-DvMI6Vqn.js.map} +1 -1
  36. package/dist/gateway/static/root/assets/{logs-page-BaOXC1YZ.js → logs-page-XKXcjB3g.js} +2 -2
  37. package/dist/gateway/static/root/assets/{logs-page-BaOXC1YZ.js.map → logs-page-XKXcjB3g.js.map} +1 -1
  38. package/dist/gateway/static/root/assets/{sessions-page-C_VA9TOA.js → sessions-page-1DyACBG7.js} +2 -2
  39. package/dist/gateway/static/root/assets/{sessions-page-C_VA9TOA.js.map → sessions-page-1DyACBG7.js.map} +1 -1
  40. package/dist/gateway/static/root/assets/{settings-page-DMjZKSwv.js → settings-page-TrmEN1eQ.js} +2 -2
  41. package/dist/gateway/static/root/assets/{settings-page-DMjZKSwv.js.map → settings-page-TrmEN1eQ.js.map} +1 -1
  42. package/dist/gateway/static/root/assets/{skills-page-vObv6AB7.js → skills-page-Dcvjtm-1.js} +2 -2
  43. package/dist/gateway/static/root/assets/{skills-page-vObv6AB7.js.map → skills-page-Dcvjtm-1.js.map} +1 -1
  44. package/dist/gateway/static/root/assets/{use-image-provider-credentials-CoM2HUB_.js → use-image-provider-credentials-D6TXcMU2.js} +2 -2
  45. package/dist/gateway/static/root/assets/{use-image-provider-credentials-CoM2HUB_.js.map → use-image-provider-credentials-D6TXcMU2.js.map} +1 -1
  46. package/dist/gateway/static/root/index.html +1 -1
  47. package/dist/package.js +1 -1
  48. package/dist/src/agent/agent-manager.js +6 -6
  49. package/dist/src/agent/context/workspace-seed.js +2 -2
  50. package/dist/src/agent/embedded/run-turn.js +6 -2
  51. package/dist/src/agent/embedded/run-turn.js.map +1 -1
  52. package/dist/src/agent/embedded/xopc-auth-storage.d.ts +9 -0
  53. package/dist/src/agent/embedded/xopc-auth-storage.js +13 -1
  54. package/dist/src/agent/embedded/xopc-auth-storage.js.map +1 -1
  55. package/dist/src/agent/embedded/xopc-stream-bridge.d.ts +11 -0
  56. package/dist/src/agent/embedded/xopc-stream-bridge.js +24 -0
  57. package/dist/src/agent/embedded/xopc-stream-bridge.js.map +1 -0
  58. package/dist/src/agent/goals/goal-run-store.js +4 -4
  59. package/dist/src/agent/goals/post-turn.js +2 -2
  60. package/dist/src/agent/image/load-image-media.js +1 -1
  61. package/dist/src/agent/ipc/bus.js +1 -1
  62. package/dist/src/agent/ipc/inbox.js +2 -2
  63. package/dist/src/agent/ipc/socket.js +1 -1
  64. package/dist/src/agent/memory/builtin-memory-store.js +1 -1
  65. package/dist/src/agent/memory/dreaming/deep-promotion.js +1 -1
  66. package/dist/src/agent/memory/dreaming/events.js +1 -1
  67. package/dist/src/agent/memory/dreaming/last-run.js +1 -1
  68. package/dist/src/agent/memory/dreaming/light-sweep.js +1 -1
  69. package/dist/src/agent/memory/dreaming/preview.js +1 -1
  70. package/dist/src/agent/memory/dreaming/rem-patterns.js +1 -1
  71. package/dist/src/agent/memory/dreaming/short-term-store.js +1 -1
  72. package/dist/src/agent/memory/dreaming/utils.js +1 -1
  73. package/dist/src/agent/memory/plugin-discovery.js +1 -1
  74. package/dist/src/agent/models/manager.js +1 -1
  75. package/dist/src/agent/prompt/service-prompt-builder.js +2 -2
  76. package/dist/src/agent/service.js +5 -5
  77. package/dist/src/agent/skills/config.js +1 -1
  78. package/dist/src/agent/skills/hub-hash.js +2 -2
  79. package/dist/src/agent/skills/hub-lock.js +1 -1
  80. package/dist/src/agent/skills/hub-pull.js +1 -1
  81. package/dist/src/agent/skills/index.js +1 -1
  82. package/dist/src/agent/skills/managed-store.js +1 -1
  83. package/dist/src/agent/skills/scanner.js +1 -1
  84. package/dist/src/agent/skills/skill-manage-ops.js +1 -1
  85. package/dist/src/agent/skills/skill-manager.js +1 -1
  86. package/dist/src/agent/tools/dreaming-tool.js +1 -1
  87. package/dist/src/agent/tools/factory.js +1 -1
  88. package/dist/src/agent/tools/image-generate-tool.js +1 -1
  89. package/dist/src/agent/tools/send-media.js +1 -1
  90. package/dist/src/agent/tools/skill-manage-tool.js +1 -1
  91. package/dist/src/agent/tools/write.js +1 -1
  92. package/dist/src/auth/credentials.js +3 -3
  93. package/dist/src/auth/profiles/store.js +1 -1
  94. package/dist/src/auth/sync-provider-auth.js +1 -1
  95. package/dist/src/channels/attachments/inbound-persist.js +1 -1
  96. package/dist/src/channels/attachments/outbound-tts-persist.js +1 -1
  97. package/dist/src/channels/outbound/persist-store.js +1 -1
  98. package/dist/src/channels/pairing/allow-from-file.js +1 -1
  99. package/dist/src/channels/pairing/pairing-store.js +2 -2
  100. package/dist/src/chat-commands/builtins/config.js +2 -2
  101. package/dist/src/chat-commands/context.js +1 -1
  102. package/dist/src/cli/commands/agent.js +1 -1
  103. package/dist/src/cli/commands/doctor/checks/config-health.js +1 -1
  104. package/dist/src/cli/commands/doctor/checks/provider-auth.js +1 -1
  105. package/dist/src/cli/commands/doctor/checks/session-integrity.js +1 -1
  106. package/dist/src/cli/commands/doctor/checks/state-integrity.js +1 -1
  107. package/dist/src/cli/commands/doctor/checks/workspace-status.js +1 -1
  108. package/dist/src/cli/commands/extension-dev.js +1 -1
  109. package/dist/src/cli/commands/extension-marketplace.js +1 -1
  110. package/dist/src/cli/commands/extension-pack.js +1 -1
  111. package/dist/src/cli/commands/image.js +1 -1
  112. package/dist/src/cli/commands/init.js +4 -4
  113. package/dist/src/cli/commands/onboard.js +1 -1
  114. package/dist/src/cli/utils/init-workspace.js +2 -2
  115. package/dist/src/config/index.js +3 -3
  116. package/dist/src/config/loader.js +2 -2
  117. package/dist/src/config/models-json.js +2 -2
  118. package/dist/src/config/profile.js +2 -2
  119. package/dist/src/cron/executor.js +2 -2
  120. package/dist/src/cron/persistence.js +1 -1
  121. package/dist/src/cron/run-log-store.js +1 -1
  122. package/dist/src/daemon/launchd.js +2 -2
  123. package/dist/src/daemon/systemd.js +2 -2
  124. package/dist/src/extensions/health.js +1 -1
  125. package/dist/src/extensions/loader.js +1 -1
  126. package/dist/src/extensions/lockfile.js +2 -2
  127. package/dist/src/gateway/agents-admin.js +2 -2
  128. package/dist/src/gateway/hono/lib/extension-store.js +1 -1
  129. package/dist/src/gateway/hono/lib/static-ui.js +1 -1
  130. package/dist/src/gateway/hono/oauth.js +1 -1
  131. package/dist/src/gateway/hono/routes/auth-registry-extensions.js +1 -1
  132. package/dist/src/gateway/hono/routes/config.js +1 -1
  133. package/dist/src/gateway/hono/routes/dreaming.js +1 -1
  134. package/dist/src/gateway/hono/routes/host-fs.js +1 -1
  135. package/dist/src/gateway/hono/routes/models.js +1 -1
  136. package/dist/src/gateway/hono/routes/workspace.js +3 -3
  137. package/dist/src/gateway/hono/sse.js +2 -2
  138. package/dist/src/gateway/lock.js +2 -2
  139. package/dist/src/gateway/service/run-gateway-agent.js +2 -2
  140. package/dist/src/gateway/service.js +5 -5
  141. package/dist/src/gateway/workspace-fs-file-list.js +1 -1
  142. package/dist/src/gateway/workspace-heartbeat-path.js +1 -1
  143. package/dist/src/infra/update-check.js +1 -1
  144. package/dist/src/infra/update-lock.js +3 -3
  145. package/dist/src/infra/update-runner.js +1 -1
  146. package/dist/src/infra/update-startup.js +2 -2
  147. package/dist/src/infra/write-file-atomic.js +2 -2
  148. package/dist/src/providers/auth-runtime/auth-profile-store.js +1 -1
  149. package/dist/src/providers/index.js +2 -2
  150. package/dist/src/providers/model-registry.js +1 -1
  151. package/dist/src/session/config-store.js +2 -2
  152. package/dist/src/session/parity/jsonl-transcript-io.js +2 -2
  153. package/dist/src/session/parity/sessions-json-file.js +1 -1
  154. package/dist/src/session/parity/transcript-file-lock.js +2 -2
  155. package/dist/src/session/parity/transcript-paths.js +1 -1
  156. package/dist/src/session/search-index-cache.js +1 -1
  157. package/dist/src/session/search-index.js +1 -1
  158. package/dist/src/session/session-title.js +1 -1
  159. package/dist/src/session/store.js +4 -4
  160. package/dist/src/tui/backends/embedded-backend.js +1 -1
  161. package/dist/src/tui/tui.js +1 -1
  162. package/dist/src/utils/logger/audit.js +1 -1
  163. package/dist/src/utils/logger/log-store.js +1 -1
  164. package/dist/src/utils/logger/rotation.js +1 -1
  165. package/dist/src/voice/tts/audio.js +1 -1
  166. package/dist/src/voice/tts/providers/edge-speech.js +1 -1
  167. package/package.json +1 -1
@@ -1,2 +1,2 @@
1
- import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{i as t,t as n}from"./vendor-react-DbimaAId.js";import{i as r}from"./vendor-swr-B5fPo7KK.js";import{$n as i,Ai as a,An as o,Ar as s,Bn as c,Br as l,Bt as u,C as d,Cn as f,Cr as p,Ct as m,Di as h,Dn as g,Dr as _,Ei as v,En as y,Fn as b,Ft as x,Hr as S,It as C,Ln as w,Lt as T,Mn as E,Mt as D,Nt as O,On as k,Or as A,Ot as j,Pt as M,Qr as N,Rn as P,Rt as F,S as I,Sn as L,St as R,Ti as z,Tn as ee,Vn as B,Vr as V,X as H,Xn as te,Xr as ne,Zr as re,_ as ie,_i as U,a as W,b as G,c as ae,cr as oe,dn as K,dr as se,er as ce,fi as le,fn as ue,fr as q,g as de,gi as fe,gn as J,h as pe,hn as Y,hr as me,ir as he,jn as ge,jt as _e,kn as ve,kr as ye,kt as be,l as xe,ln as Se,m as Ce,mi as we,mn as Te,ni as Ee,o as De,or as Oe,p as ke,pi as Ae,pn as je,pr as Me,qn as Ne,ri as Pe,rr as Fe,t as Ie,ui as Le,v as Re,vn as ze,vr as Be,wr as Ve,x as He,xn as Ue,xr as We,y as Ge,yi as Ke,yn as qe,zn as Je,zr as Ye,zt as Xe}from"./index-BDiwAtHo.js";import{i as Ze,n as Qe,r as $e,t as et}from"./use-image-provider-credentials-CoM2HUB_.js";import{E as tt,S as nt,f as rt,r as it,s as at}from"./cron-dreaming-jobs-Bw0WqucT.js";import{_ as ot,a as st,b as ct,c as lt,d as ut,f as dt,g as ft,h as pt,i as mt,l as ht,m as gt,n as _t,o as vt,p as yt,r as bt,s as xt,t as St,u as Ct,v as wt,x as Tt,y as Et}from"./agents-kfTaZM98.js";import{t as Dt}from"./browser-DNXWYwzc.js";import{a as Ot,i as kt,n as At,o as jt,r as Mt,s as Nt,t as Pt}from"./heartbeat-config-api-BzwYrxvL.js";var X=n();function Ft(){return w(`rounded-xl border border-edge-subtle bg-surface-base px-4 py-1 sm:px-5`)}var It={default:{light:{canvas:`#f5f5f7`,panel:`#ffffff`,accent:`#2563eb`,fg:`#1d1d1f`,muted:`#d2d2d7`},dark:{canvas:`#1c1c1e`,panel:`#2c2c2e`,accent:`#3b82f6`,fg:`#f5f5f7`,muted:`#48484a`}},emerald:{light:{canvas:`#f0fdf4`,panel:`#ffffff`,accent:`#059669`,fg:`#052e16`,muted:`#86efac`},dark:{canvas:`#000000`,panel:`#0a0a0a`,accent:`#10b981`,fg:`#d1fae5`,muted:`#134e2a`}},mono:{light:{canvas:`#ffffff`,panel:`#f5f5f5`,accent:`#111111`,fg:`#111111`,muted:`#e5e7eb`},dark:{canvas:`#101010`,panel:`#1a1a1a`,accent:`#737373`,fg:`#fafafa`,muted:`#333333`}},clay:{light:{canvas:`#fffaf0`,panel:`#ffffff`,accent:`#1a3a3a`,fg:`#0a0a0a`,muted:`#e5e5e5`},dark:{canvas:`#0a1a1a`,panel:`#1a2a2a`,accent:`#ffb084`,fg:`#fffaf0`,muted:`#2a3a3a`}}};function Lt({canvas:e,panel:t,accent:n,fg:r,muted:i}){return(0,X.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col justify-center gap-1 p-1.5`,style:{backgroundColor:e},children:(0,X.jsxs)(`div`,{className:`flex flex-col gap-0.5 rounded-sm border p-1`,style:{backgroundColor:t,borderColor:i},children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(`div`,{className:`h-1 w-1 shrink-0 rounded-full`,style:{backgroundColor:n}}),(0,X.jsx)(`div`,{className:`h-1 min-w-0 flex-1 rounded-full`,style:{backgroundColor:r,opacity:.85}})]}),(0,X.jsx)(`div`,{className:`h-1 w-2/3 max-w-[70%] rounded-full`,style:{backgroundColor:i}}),(0,X.jsx)(`div`,{className:`h-1 w-1/2 max-w-[55%] rounded-full`,style:{backgroundColor:i}})]})})}function Rt({scheme:e}){let{light:t,dark:n}=It[e];return(0,X.jsxs)(`div`,{className:`flex h-11 w-full overflow-hidden rounded-md border border-edge-subtle`,children:[(0,X.jsx)(Lt,{...t}),(0,X.jsx)(`div`,{className:`w-px shrink-0 bg-black/12 dark:bg-white/12`,"aria-hidden":!0}),(0,X.jsx)(Lt,{...n})]})}var zt=[{value:`default`,labelKey:`colorSchemeDefault`},{value:`emerald`,labelKey:`colorSchemeLightGreen`},{value:`mono`,labelKey:`colorSchemeModernMono`},{value:`clay`,labelKey:`colorSchemeClay`}];function Bt(){let e=ge(f(e=>e.language)).appearanceSettings,t=L(e=>e.colorScheme),n=L(e=>e.setColorScheme);return(0,X.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,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:e.colorSchemeTitle}),(0,X.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:e.colorSchemeDescription})]}),(0,X.jsx)(`div`,{className:`grid grid-cols-2 gap-3 lg:grid-cols-4`,children:zt.map(({value:r,labelKey:i})=>{let a=t===r;return(0,X.jsxs)(`button`,{type:`button`,"aria-pressed":a,onClick:()=>n(r),className:w(`flex flex-col gap-2 rounded-xl border-2 p-2.5 text-left transition-[border-color,box-shadow] duration-150`,a?`border-accent shadow-[0_0_0_1px_var(--color-accent)]`:`border-edge-subtle hover:border-edge`),children:[(0,X.jsx)(Rt,{scheme:r}),(0,X.jsx)(`span`,{className:w(`text-xs font-medium leading-none`,a?`text-accent-fg`:`text-fg-muted`),children:e[i]})]},r)})})]})}function Vt(){let e=ge(f(e=>e.language)).appearanceSettings;return(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,X.jsxs)(`header`,{className:`flex flex-col gap-1`,children:[(0,X.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight text-fg`,children:e.pageTitle}),(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.subtitle})]}),(0,X.jsxs)(`section`,{className:Ft(),"aria-labelledby":`pref-language-heading`,children:[(0,X.jsx)(`h2`,{id:`pref-language-heading`,className:`sr-only`,children:e.languageTitle}),(0,X.jsx)(Ue,{variant:`page`,sections:[`language`]})]}),(0,X.jsxs)(`section`,{className:Ft(),"aria-labelledby":`pref-appearance-heading`,children:[(0,X.jsx)(`h2`,{id:`pref-appearance-heading`,className:`sr-only`,children:e.themeTitle}),(0,X.jsx)(Ue,{variant:`page`,sections:[`theme`,`font`]}),(0,X.jsx)(Bt,{})]})]})}var Z=e(t(),1);function Ht(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var Ut={enabled:!0,cron:`0 */6 * * *`,lookbackDays:1,limit:50,dedupeSimilarity:.85},Wt={enabled:!0,cron:`0 3 * * *`,minScore:.8,minRecallCount:3,limit:10,recencyHalfLifeDays:14,maxAgeDays:30},Gt={enabled:!0,cron:`0 5 * * 0`,lookbackDays:7,limit:20,minPatternStrength:.6},Kt={enabled:!1,frequency:`0 3 * * *`,timezone:``,deepEnabled:!0,minScore:.8,minRecallCount:3,limit:10,light:Ut,deep:Wt,rem:Gt};function qt(e,t){return Number.isFinite(e)?Math.max(0,Math.min(1,e)):t}function Jt(e,t){let n=typeof e==`string`?Number(e):e;return Number.isFinite(n)?Math.max(0,Math.floor(n)):t}function Yt(e,t){let n=typeof e==`string`?Number(e):e;return Number.isFinite(n)?n:t}function Xt(e){let t=Ht(e)?e:{},n=Ht(t.agents)?t.agents:{},r=Ht(n.defaults)?n.defaults:{},i=Ht(r.memory)?r.memory:{},a=Ht(i.dreaming)?i.dreaming:{},o=Ht(a.phases)?a.phases:{},s=Ht(o.light)?o.light:{},c=Ht(o.deep)?o.deep:{},l=Ht(o.rem)?o.rem:{};return{enabled:a.enabled===!0,frequency:typeof a.frequency==`string`&&a.frequency.trim()?a.frequency.trim():Kt.frequency,timezone:typeof a.timezone==`string`?a.timezone:``,deepEnabled:c.enabled!==!1,minScore:qt(typeof c.minScore==`number`?c.minScore:Number(c.minScore),Kt.minScore),minRecallCount:Math.max(1,Jt(c.minRecallCount,Kt.minRecallCount)),limit:Jt(c.limit,Kt.limit),light:{enabled:s.enabled!==!1,cron:typeof s.cron==`string`&&s.cron.trim()?s.cron.trim():Ut.cron,lookbackDays:Math.max(1,Jt(s.lookbackDays,Ut.lookbackDays)),limit:Jt(s.limit,Ut.limit),dedupeSimilarity:qt(Yt(s.dedupeSimilarity,Ut.dedupeSimilarity),Ut.dedupeSimilarity)},deep:{enabled:c.enabled!==!1,cron:typeof c.cron==`string`&&c.cron.trim()?c.cron.trim():Wt.cron,minScore:qt(Yt(c.minScore,Wt.minScore),Wt.minScore),minRecallCount:Math.max(1,Jt(c.minRecallCount,Wt.minRecallCount)),limit:Jt(c.limit,Wt.limit),recencyHalfLifeDays:Math.max(1,Yt(c.recencyHalfLifeDays,Wt.recencyHalfLifeDays)),maxAgeDays:Math.max(1,Yt(c.maxAgeDays,Wt.maxAgeDays))},rem:{enabled:l.enabled!==!1,cron:typeof l.cron==`string`&&l.cron.trim()?l.cron.trim():Gt.cron,lookbackDays:Math.max(1,Jt(l.lookbackDays,Gt.lookbackDays)),limit:Jt(l.limit,Gt.limit),minPatternStrength:qt(Yt(l.minPatternStrength,Gt.minPatternStrength),Gt.minPatternStrength)}}}async function Zt(e){let t=e.frequency.trim(),n=e.timezone.trim();await J(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:qt(e.light.dedupeSimilarity,Ut.dedupeSimilarity)},deep:{enabled:!!e.deep.enabled,cron:e.deep.cron.trim()||null,minScore:qt(e.deep.minScore,Wt.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:qt(e.rem.minPatternStrength,Gt.minPatternStrength)}}}}}}})}),R()}var Qt=w(`h-9 min-w-0 flex-1 rounded-lg border border-edge-subtle bg-surface-panel px-2.5 py-1.5 text-sm tabular-nums text-fg`,y),$t=w(ve,`h-9 max-w-[11rem] shrink-0 text-xs sm:max-w-[12rem]`);function en(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 tn({valueMs:e,onChangeMs:t,labels:n,disabled:r,presets:i=it,minSeconds:a=1}){let o=(0,Z.useMemo)(()=>new Set(i),[i]),s=(0,Z.useMemo)(()=>o.has(e)?String(e):``,[o,e]),[c,l]=(0,Z.useState)(null),u=Math.max(a,Math.round(e/1e3)),d=c===null?String(u):c;return(0,Z.useEffect)(()=>{l(null)},[e]),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,X.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:n.secondsLabel}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(`input`,{type:`number`,min:a,step:1,disabled:r,className:Qt,value:d,onChange:e=>{let n=e.target.value;l(n);let r=parseInt(n,10);Number.isFinite(r)&&r>=a&&t(r*1e3)},onBlur:()=>{if(c===null)return;let e=parseInt(c,10);t(!Number.isFinite(e)||e<a?a*1e3:e*1e3),l(null)}}),(0,X.jsxs)(`select`,{className:$t,disabled:r,value:s,onChange:e=>{let n=e.target.value;n&&(t(parseInt(n,10)),l(null))},children:[(0,X.jsx)(`option`,{value:``,children:n.presets.custom}),i.map(e=>(0,X.jsx)(`option`,{value:String(e),children:en(e,n.presets)},e))]})]})]})}var nn=w(`mt-1 w-full rounded-lg border border-edge-subtle bg-surface-panel px-2.5 py-1.5 text-sm text-fg`,y),rn=()=>({start:`09:00`,end:`22:00`,timezone:``});function an({value:e,onChange:t,labels:n,disabled:r}){return e?(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-3`,children:[(0,X.jsxs)(`label`,{className:`block min-w-0`,children:[(0,X.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:n.start}),(0,X.jsx)(`input`,{type:`time`,step:60,disabled:r,className:nn,value:e.start,onChange:n=>t({...e,start:n.target.value})})]}),(0,X.jsxs)(`label`,{className:`block min-w-0`,children:[(0,X.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:n.end}),(0,X.jsx)(`input`,{type:`time`,step:60,disabled:r,className:nn,value:e.end,onChange:n=>t({...e,end:n.target.value})})]}),(0,X.jsxs)(`label`,{className:`block min-w-0`,children:[(0,X.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:n.timezone}),(0,X.jsx)(`input`,{type:`text`,disabled:r,className:nn,value:e.timezone,onChange:n=>t({...e,timezone:n.target.value}),placeholder:`Asia/Shanghai`,autoComplete:`off`})]})]}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,className:`text-xs`,disabled:r,onClick:()=>t(null),children:n.clear})]}):(0,X.jsx)(E,{type:`button`,variant:`secondary`,className:`text-sm`,disabled:r,onClick:()=>t(rn()),children:n.add})}function on(e){let{disabled:t,label:n,hint:r,className:i}=e;return(0,X.jsxs)(`div`,{className:w(`flex flex-col gap-2`,i),children:[n?(0,X.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:n}):null,e.kind===`cron`?(0,X.jsx)(Nt,{value:e.value,onChange:e.onChange,labels:e.labels,disabled:t,showHeading:!n}):null,e.kind===`interval`?(0,X.jsx)(tn,{valueMs:e.valueMs,onChangeMs:e.onChangeMs,labels:e.labels,disabled:t,presets:e.presets??it,minSeconds:e.minSeconds}):null,e.kind===`active-hours`?(0,X.jsx)(an,{value:e.value,onChange:e.onChange,labels:e.labels,disabled:t}):null,r?(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:r}):null]})}var sn=`py-4 px-4 sm:px-5`,cn=`mb-3`,ln=`rounded-xl border border-edge-subtle bg-surface-panel/30 p-3 sm:p-4`,un=w(`mt-1 w-full rounded-lg border border-edge-subtle bg-surface-panel px-2.5 py-1.5 text-sm text-fg`,y);function dn(){return`text-xs font-medium text-fg-muted`}function fn(){return`text-sm font-medium text-fg`}function pn({label:e,children:t,className:n}){return(0,X.jsxs)(`div`,{className:n,children:[(0,X.jsx)(`span`,{className:dn(),children:e}),t]})}function Q({label:e,children:t,className:n}){return(0,X.jsxs)(`div`,{className:w(`min-w-0`,n),children:[(0,X.jsx)(`dt`,{className:dn(),children:e}),(0,X.jsx)(`dd`,{className:w(fn(),`mt-0.5`),children:t})]})}function mn(e){return e?e.replace(`T`,` `).replace(`Z`,``):`—`}function hn(e){return e===void 0||!Number.isFinite(e)||e<0?`—`:e<1e3?`${Math.round(e)} ms`:`${(e/1e3).toFixed(2)} s`}function gn({label:e,className:t}){return(0,X.jsx)(`h3`,{className:w(`text-[0.7rem] font-semibold uppercase tracking-wider text-fg-muted`,t),children:e})}function _n({icon:e,title:t,hint:n,enabled:r,onEnabledChange:i,cron:a,onCronChange:o,scheduleLabels:s,disabled:c,onLabel:l,offLabel:u,cronLabel:d,children:f}){return(0,X.jsxs)(`div`,{className:ln,children:[(0,X.jsxs)(`div`,{className:`mb-2.5 flex flex-wrap items-start justify-between gap-2 border-b border-edge-subtle/80 pb-2.5`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2`,children:[(0,X.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:e}),(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:t}),(0,X.jsx)(`p`,{className:`mt-0.5 text-xs leading-snug text-fg-muted`,children:n})]})]}),(0,X.jsxs)(`label`,{className:`inline-flex shrink-0 items-center gap-2 text-xs text-fg`,children:[(0,X.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:r,disabled:c,onChange:e=>i(e.target.checked)}),(0,X.jsx)(`span`,{children:r?l:u})]})]}),(0,X.jsx)(on,{kind:`cron`,className:`mb-2.5`,label:d,value:a,onChange:o,labels:s,disabled:c}),(0,X.jsx)(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-3 lg:grid-cols-4`,children:f})]})}function vn({icon:e,label:t,enabled:n,cron:r,scheduleSummary:i,details:a,t:o}){return(0,X.jsxs)(`div`,{className:w(ln,`space-y-1`),children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e,(0,X.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:t}),(0,X.jsx)(`span`,{className:w(`ml-auto text-xs font-medium`,n?`text-emerald-600 dark:text-emerald-400`:`text-fg-muted`),children:n?o.on:o.off})]}),(0,X.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:i}),(0,X.jsx)(`p`,{className:`truncate font-mono text-[0.65rem] text-fg-subtle`,title:r,children:r}),(0,X.jsx)(`p`,{className:`text-[0.65rem] leading-snug text-fg-muted`,children:a})]})}function yn({label:e,lastRun:t,t:n}){return(0,X.jsxs)(`div`,{className:`border-t border-edge-subtle/80 pt-3`,children:[(0,X.jsx)(gn,{label:e,className:`mb-2`}),t?.exists?(0,X.jsxs)(`details`,{className:`group rounded-lg border border-edge-subtle`,children:[(0,X.jsx)(`summary`,{className:`cursor-pointer list-none px-2.5 py-1.5 text-xs font-medium text-fg-muted marker:hidden [&::-webkit-details-marker]:hidden`,children:(0,X.jsx)(`span`,{className:`underline decoration-edge underline-offset-2 group-open:text-fg`,children:n.lastRunRaw})}),(0,X.jsx)(`pre`,{className:`max-h-40 overflow-auto border-t border-edge-subtle p-2.5 text-xs text-fg-muted`,children:JSON.stringify(t.raw,null,2)})]}):(0,X.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.phaseLastRunEmpty})]})}function bn({t:e,r:t}){let n=t.deep?.skipped;return(0,X.jsxs)(`dl`,{className:`grid grid-cols-2 gap-x-3 gap-y-2 sm:grid-cols-3 lg:grid-cols-4`,children:[(0,X.jsx)(Q,{label:e.lastRunStatus,children:(0,X.jsx)(`span`,{className:t.ok?`text-emerald-600 dark:text-emerald-400`:`text-amber-600 dark:text-amber-400`,children:t.ok?e.lastRunSuccess:e.lastRunFailure})}),(0,X.jsx)(Q,{label:e.lastRunDuration,children:hn(t.durationMs)}),(0,X.jsx)(Q,{label:e.lastRunRanked,children:String(t.deep?.candidatesRanked??`—`)}),(0,X.jsx)(Q,{label:e.lastRunApplied,children:String(t.deep?.applied??`—`)}),(0,X.jsxs)(Q,{label:e.lastRunReason,className:`col-span-2 sm:col-span-3 lg:col-span-4`,children:[(0,X.jsx)(`span`,{className:`block text-pretty`,children:t.reason}),t.errorMessage?(0,X.jsx)(`span`,{className:`mt-1 block text-xs text-amber-600 dark:text-amber-400`,children:`${e.lastRunError}: ${t.errorMessage}`}):null]}),n?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Q,{label:e.lastRunSkipKey,children:String(n.alreadyPromotedKey)}),(0,X.jsx)(Q,{label:e.lastRunSkipRehydrate,children:String(n.rehydrateFailed)}),(0,X.jsx)(Q,{label:e.lastRunSkipContaminated,children:String(n.contaminated)}),(0,X.jsx)(Q,{label:e.lastRunSkipHash,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 Sn(){let e=f(e=>e.language),t=ge(e),n=t.dreamingSettings,a=t.cron.schedulePicker,o=t.cron.scheduleBadge,l=e===`zh`?`zh-CN`:`en-US`,u=!!ze(e=>e.token),{data:d}=m(u),[h,g]=(0,Z.useState)(null),[_,v]=(0,Z.useState)(null),[y,b]=(0,Z.useState)(!1),[x,S]=(0,Z.useState)(!1),[C,T]=(0,Z.useState)(!1),[D,O]=(0,Z.useState)(null),[k,A]=(0,Z.useState)(`deep`),[j,M]=(0,Z.useState)(null),[N,P]=(0,Z.useState)(null),[F,I]=(0,Z.useState)(!1),[L,R]=(0,Z.useState)(!1),[ee,B]=(0,Z.useState)(!1),[V,H]=(0,Z.useState)(null),[ne,re]=(0,Z.useState)(!1),[ie,U]=(0,Z.useState)(null),[W,G]=(0,Z.useState)(null),[ae,oe]=(0,Z.useState)(!1),[K,ce]=(0,Z.useState)(null),[le,ue]=(0,Z.useState)(null),{data:q,error:de,isLoading:fe,mutate:J}=r(u?dt():null,pt,{revalidateOnFocus:!1}),pe=(0,Z.useMemo)(()=>q?xn(q.lock,n):null,[q,n]),Y=(0,Z.useMemo)(()=>{let e=[];return de&&e.push(de instanceof Error?de.message:String(de)),_&&e.push(_),D&&e.push(D),ie&&e.push(ie),K&&e.push(K),V&&e.push(V),e},[de,_,D,ie,K,V]),me=(0,Z.useMemo)(()=>{let e=[];return ee&&e.push(n.configSaved),C&&e.push(n.runQueued),y&&e.push(n.actionOk),e},[ee,C,y,n]),_e=(0,Z.useCallback)(async()=>{b(!1),v(null),T(!1),O(null),B(!1),H(null),U(null),await J()},[J]),ve=(0,Z.useCallback)(async()=>{re(!0),U(null);try{G((await gt(20)).items??[])}catch(e){U(e instanceof Error?e.message:String(e))}finally{re(!1)}},[]),be=(0,Z.useCallback)(async()=>{oe(!0),ce(null);try{ue(await yt(50))}catch(e){ce(e instanceof Error?e.message:String(e))}finally{oe(!1)}},[]),xe=(0,Z.useCallback)(async(e=`deep`)=>{S(!0),T(!1),O(null);try{await ot(e),T(!0),await J()}catch(e){O(e instanceof Error?e.message:String(e))}finally{S(!1)}},[J]),Se=(0,Z.useCallback)(async e=>{g(e),v(null),b(!1);try{await ft(e),b(!0),await J()}catch(e){v(e instanceof Error?e.message:String(e))}finally{g(null)}},[J]),Ce=!u||fe||!!h,we=(0,Z.useMemo)(()=>{let e=d?.payload?.config;return Xt(e??{})},[d]);(0,Z.useEffect)(()=>{if(u){if(!N){P(we),M(we);return}JSON.stringify(we)!==JSON.stringify(N)&&(P(we),M(we))}},[N,we,u]);let Te=(0,Z.useMemo)(()=>!j||!N?!1:JSON.stringify(j)!==JSON.stringify(N),[j,N]),Ee=(0,Z.useCallback)(async()=>{if(j){I(!0),B(!1),H(null);try{await Zt(j),P(j),B(!0),await J()}catch(e){H(e instanceof Error?e.message:String(e))}finally{I(!1)}}},[j,J]),De=(0,Z.useCallback)(async e=>{if(!j||!u)return;let t={...j,enabled:e},n=j;M(t),R(!0),B(!1),H(null);try{await Zt(t),P(t),B(!0),await J()}catch(e){M(n),H(e instanceof Error?e.message:String(e))}finally{R(!1)}},[j,u,J]),Oe=j?.enabled??we.enabled;return(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-4 px-4 py-6`,children:[(0,X.jsxs)(`header`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:n.title}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle})]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[j?(0,X.jsxs)(`label`,{className:w(`inline-flex cursor-pointer items-center gap-2 rounded-xl border px-3 py-1.5 text-sm transition-colors`,Oe?`border-emerald-500/30 bg-emerald-500/5 text-fg`:`border-edge-subtle bg-surface-panel/50 text-fg-muted`),children:[(0,X.jsx)(`span`,{className:`text-xs font-medium`,children:n.configEnabled}),(0,X.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:j.enabled,disabled:!u||F||L,onChange:e=>void De(e.target.checked)}),L?(0,X.jsx)(s,{className:`size-3.5 animate-spin text-fg-muted`,"aria-hidden":!0}):(0,X.jsx)(`span`,{className:w(`text-xs font-semibold`,Oe?`text-emerald-600 dark:text-emerald-400`:``),children:j.enabled?n.on:n.off})]}):null,Oe?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`select`,{className:`rounded-lg border border-edge bg-surface-panel px-2 py-1.5 text-xs text-fg`,value:k,onChange:e=>A(e.target.value),disabled:!u||x,children:[(0,X.jsx)(`option`,{value:`light`,children:`Light`}),(0,X.jsx)(`option`,{value:`deep`,children:`Deep`}),(0,X.jsx)(`option`,{value:`rem`,children:`REM`})]}),(0,X.jsxs)(E,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!u||x,onClick:()=>void xe(k),title:n.runNowHint,children:[x?(0,X.jsx)(s,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,X.jsx)(Be,{className:`mr-2 size-4`,"aria-hidden":!0}),n.runNow]})]}):null,(0,X.jsxs)(E,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!u,onClick:()=>void _e(),children:[(0,X.jsx)(Me,{className:`mr-2 size-4`,"aria-hidden":!0}),n.refresh]})]})]}),Y.length>0?(0,X.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:Y.map((e,t)=>(0,X.jsx)(`p`,{className:`text-sm text-amber-800 dark:text-amber-200/90`,children:e},t))}):null,me.length>0?(0,X.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:me.map((e,t)=>(0,X.jsx)(`p`,{className:`text-sm text-emerald-800 dark:text-emerald-200/90`,children:e},t))}):null,(0,X.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,X.jsxs)(Et,{className:w(`min-w-0`,sn),children:[(0,X.jsx)(ct,{className:cn,icon:he,title:n.configTitle,subtitle:n.configHint,trailing:(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(E,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!u||!j||F||!Te,onClick:()=>void Ee(),children:[F?(0,X.jsx)(s,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,n.saveConfig]}),(0,X.jsx)(E,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!u||!j||F||!Te,onClick:()=>{B(!1),H(null),M(N)},children:n.resetConfig})]})}),j?(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsx)(`div`,{className:ln,children:(0,X.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 lg:grid-cols-12`,children:[(0,X.jsx)(`div`,{className:`lg:col-span-9`,children:(0,X.jsx)(on,{kind:`cron`,label:n.configFrequency,value:j.frequency,onChange:e=>M({...j,frequency:e}),labels:a,disabled:!u||F})}),(0,X.jsx)(pn,{label:n.configTimezone,className:`lg:col-span-3`,children:(0,X.jsx)(`input`,{className:un,value:j.timezone,disabled:!u||F,onChange:e=>M({...j,timezone:e.target.value}),placeholder:`Asia/Shanghai`})})]})}),(0,X.jsxs)(_n,{icon:(0,X.jsx)(te,{className:`size-4 text-amber-500`}),title:n.configPhaseLight,hint:n.configPhaseLightHint,enabled:j.light.enabled,onEnabledChange:e=>M({...j,light:{...j.light,enabled:e}}),cron:j.light.cron,onCronChange:e=>M({...j,light:{...j.light,cron:e}}),scheduleLabels:a,disabled:!u||F,onLabel:n.on,offLabel:n.off,cronLabel:n.configPhaseCron,children:[(0,X.jsx)(pn,{label:n.configLightLookbackDays,children:(0,X.jsx)(`input`,{type:`number`,step:`1`,min:1,className:un,value:j.light.lookbackDays,disabled:!u||F,onChange:e=>M({...j,light:{...j.light,lookbackDays:Number(e.target.value)}})})}),(0,X.jsx)(pn,{label:n.configLightLimit,children:(0,X.jsx)(`input`,{type:`number`,step:`1`,min:0,className:un,value:j.light.limit,disabled:!u||F,onChange:e=>M({...j,light:{...j.light,limit:Number(e.target.value)}})})}),(0,X.jsx)(pn,{label:n.configLightDedupe,children:(0,X.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:un,value:j.light.dedupeSimilarity,disabled:!u||F,onChange:e=>M({...j,light:{...j.light,dedupeSimilarity:Number(e.target.value)}})})})]}),(0,X.jsxs)(_n,{icon:(0,X.jsx)(p,{className:`size-4 text-indigo-500`}),title:n.configPhaseDeep,hint:n.configPhaseDeepHint,enabled:j.deep.enabled,onEnabledChange:e=>M({...j,deep:{...j.deep,enabled:e}}),cron:j.deep.cron,onCronChange:e=>M({...j,deep:{...j.deep,cron:e}}),scheduleLabels:a,disabled:!u||F,onLabel:n.on,offLabel:n.off,cronLabel:n.configPhaseCron,children:[(0,X.jsx)(pn,{label:n.configDeepMinScore,children:(0,X.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:un,value:j.deep.minScore,disabled:!u||F,onChange:e=>M({...j,deep:{...j.deep,minScore:Number(e.target.value)}})})}),(0,X.jsx)(pn,{label:n.configDeepMinRecallCount,children:(0,X.jsx)(`input`,{type:`number`,step:`1`,min:1,className:un,value:j.deep.minRecallCount,disabled:!u||F,onChange:e=>M({...j,deep:{...j.deep,minRecallCount:Number(e.target.value)}})})}),(0,X.jsx)(pn,{label:n.configDeepLimit,children:(0,X.jsx)(`input`,{type:`number`,step:`1`,min:0,className:un,value:j.deep.limit,disabled:!u||F,onChange:e=>M({...j,deep:{...j.deep,limit:Number(e.target.value)}})})}),(0,X.jsx)(pn,{label:n.configDeepHalfLife,children:(0,X.jsx)(`input`,{type:`number`,step:`1`,min:1,className:un,value:j.deep.recencyHalfLifeDays,disabled:!u||F,onChange:e=>M({...j,deep:{...j.deep,recencyHalfLifeDays:Number(e.target.value)}})})}),(0,X.jsx)(pn,{label:n.configDeepMaxAge,children:(0,X.jsx)(`input`,{type:`number`,step:`1`,min:1,className:un,value:j.deep.maxAgeDays,disabled:!u||F,onChange:e=>M({...j,deep:{...j.deep,maxAgeDays:Number(e.target.value)}})})})]}),(0,X.jsxs)(_n,{icon:(0,X.jsx)(i,{className:`size-4 text-purple-500`}),title:n.configPhaseRem,hint:n.configPhaseRemHint,enabled:j.rem.enabled,onEnabledChange:e=>M({...j,rem:{...j.rem,enabled:e}}),cron:j.rem.cron,onCronChange:e=>M({...j,rem:{...j.rem,cron:e}}),scheduleLabels:a,disabled:!u||F,onLabel:n.on,offLabel:n.off,cronLabel:n.configPhaseCron,children:[(0,X.jsx)(pn,{label:n.configRemLookbackDays,children:(0,X.jsx)(`input`,{type:`number`,step:`1`,min:1,className:un,value:j.rem.lookbackDays,disabled:!u||F,onChange:e=>M({...j,rem:{...j.rem,lookbackDays:Number(e.target.value)}})})}),(0,X.jsx)(pn,{label:n.configRemLimit,children:(0,X.jsx)(`input`,{type:`number`,step:`1`,min:0,className:un,value:j.rem.limit,disabled:!u||F,onChange:e=>M({...j,rem:{...j.rem,limit:Number(e.target.value)}})})}),(0,X.jsx)(pn,{label:n.configRemMinStrength,children:(0,X.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:un,value:j.rem.minPatternStrength,disabled:!u||F,onChange:e=>M({...j,rem:{...j.rem,minPatternStrength:Number(e.target.value)}})})})]})]}):(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.configLoading})]}),(0,X.jsxs)(Et,{className:w(`min-w-0`,sn),children:[(0,X.jsx)(ct,{className:cn,icon:z,title:n.runtimeTitle,subtitle:n.runtimeHint,trailing:fe?(0,X.jsx)(s,{className:`size-4 shrink-0 animate-spin text-fg-muted`,"aria-hidden":!0}):null}),(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{className:ln,children:[(0,X.jsx)(gn,{label:n.subsectionSchedule,className:`mb-2`}),(0,X.jsxs)(`dl`,{className:`grid grid-cols-2 gap-x-3 gap-y-2 sm:grid-cols-4`,children:[(0,X.jsx)(Q,{label:n.enabled,children:q?q.config.enabled?n.on:n.off:`—`}),(0,X.jsx)(Q,{label:n.lock,children:(0,X.jsx)(`span`,{className:pe?.className,children:pe?pe.text:`—`})}),(0,X.jsx)(Q,{label:n.timezone,children:q&&q.config.timezone||`—`}),(0,X.jsxs)(Q,{label:n.schedule,className:`col-span-2 sm:col-span-2`,children:[q?(0,X.jsx)(wt,{kind:`cron`,expression:q.config.frequency,locale:l,labels:o,timezone:q.config.timezone||void 0}):`—`,q?.config.frequency?(0,X.jsx)(`p`,{className:`mt-0.5 truncate font-mono text-[0.65rem] text-fg-subtle`,title:q.config.frequency,children:q.config.frequency}):null]})]})]}),(0,X.jsxs)(`div`,{className:ln,children:[(0,X.jsx)(gn,{label:n.subsectionStore,className:`mb-2`}),(0,X.jsxs)(`dl`,{className:`grid grid-cols-2 gap-x-3 gap-y-2 sm:grid-cols-4`,children:[(0,X.jsx)(Q,{label:n.storeEntries,children:q?String(q.store.entryCount):`—`}),(0,X.jsx)(Q,{label:n.storePromoted,children:q?String(q.store.promotedCount):`—`}),(0,X.jsx)(Q,{label:n.storeUpdatedAt,children:q?mn(q.store.updatedAt):`—`}),(0,X.jsx)(Q,{label:n.storeLastPromotedAt,children:q?mn(q.store.lastPromotedAt):`—`})]})]}),q?.config?.phases?(0,X.jsxs)(`div`,{children:[(0,X.jsx)(gn,{label:n.subsectionPhases,className:`mb-2`}),(0,X.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-3`,children:[(0,X.jsx)(vn,{icon:(0,X.jsx)(te,{className:`size-4 text-amber-500`}),label:`Light`,enabled:q.config.phases.light.enabled,cron:q.config.phases.light.cron,scheduleSummary:tt(q.config.phases.light.cron,l,o,{timezone:q.config.timezone||void 0}),details:`lookback=${q.config.phases.light.lookbackDays}d, limit=${q.config.phases.light.limit}, dedupe=${q.config.phases.light.dedupeSimilarity}`,t:n}),(0,X.jsx)(vn,{icon:(0,X.jsx)(p,{className:`size-4 text-indigo-500`}),label:`Deep`,enabled:q.config.phases.deep.enabled,cron:q.config.phases.deep.cron,scheduleSummary:tt(q.config.phases.deep.cron,l,o,{timezone:q.config.timezone||void 0}),details:`minScore=${q.config.phases.deep.minScore}, recalls≥${q.config.phases.deep.minRecallCount}, limit=${q.config.phases.deep.limit}, halfLife=${q.config.phases.deep.recencyHalfLifeDays}d`,t:n}),(0,X.jsx)(vn,{icon:(0,X.jsx)(i,{className:`size-4 text-purple-500`}),label:`REM`,enabled:q.config.phases.rem.enabled,cron:q.config.phases.rem.cron,scheduleSummary:tt(q.config.phases.rem.cron,l,o,{timezone:q.config.timezone||void 0}),details:`lookback=${q.config.phases.rem.lookbackDays}d, limit=${q.config.phases.rem.limit}, strength≥${q.config.phases.rem.minPatternStrength}`,t:n})]})]}):null,(0,X.jsxs)(`div`,{className:ln,children:[(0,X.jsx)(gn,{label:n.subsectionLastRun,className:`mb-2`}),(0,X.jsx)(`p`,{className:`mb-2 text-xs text-fg-muted`,children:n.lastRunBlockHint}),q?.lastRun?.exists?(0,X.jsxs)(`div`,{className:`space-y-2`,children:[q.lastRun.parseError?(0,X.jsxs)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:[n.lastRunParseError,`: `,q.lastRun.parseError]}):null,q.lastRun.record?(0,X.jsx)(`div`,{className:`rounded-lg border border-edge-subtle/80 bg-surface-panel/50 p-2.5`,children:(0,X.jsx)(bn,{t:n,r:q.lastRun.record})}):null,q.lastRun.raw!==void 0&&q.lastRun.raw!==null?(0,X.jsxs)(`details`,{className:`group rounded-lg border border-edge-subtle`,children:[(0,X.jsx)(`summary`,{className:`cursor-pointer list-none px-2.5 py-1.5 text-xs font-medium text-fg-muted marker:hidden [&::-webkit-details-marker]:hidden`,children:(0,X.jsx)(`span`,{className:`underline decoration-edge underline-offset-2 group-open:text-fg`,children:n.lastRunRaw})}),(0,X.jsx)(`pre`,{className:`max-h-40 overflow-auto border-t border-edge-subtle p-2.5 text-xs text-fg-muted`,children:JSON.stringify(q.lastRun.raw,null,2)})]}):null]}):(0,X.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.lastRunEmpty})]}),(0,X.jsx)(yn,{label:n.subsectionLightLastRun,lastRun:q?.lightLastRun,t:n}),(0,X.jsx)(yn,{label:n.subsectionRemLastRun,lastRun:q?.remLastRun,t:n})]})]})]}),(0,X.jsxs)(`div`,{className:`grid gap-4 xl:grid-cols-2`,children:[(0,X.jsxs)(Et,{className:sn,children:[(0,X.jsx)(ct,{className:cn,icon:se,title:n.previewTitle,subtitle:n.previewHint,trailing:(0,X.jsxs)(E,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!u||ne,onClick:()=>void ve(),children:[ne?(0,X.jsx)(s,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,n.previewLoad]})}),W?W.length>0?(0,X.jsx)(`div`,{className:`space-y-2`,children:W.map(e=>{let t=`${e.path}:${e.startLine}-${e.endLine}`,r=e.skippedReason;return(0,X.jsxs)(`div`,{className:`rounded-lg border border-edge-subtle bg-surface-panel/60 px-2.5 py-2`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-fg-muted`,children:[(0,X.jsx)(`span`,{className:`font-medium text-fg`,children:t}),(0,X.jsxs)(`span`,{children:[`score=`,e.score.toFixed(3)]}),(0,X.jsxs)(`span`,{children:[`recalls=`,e.recallCount]}),(0,X.jsxs)(`span`,{children:[`avg=`,e.avgScore.toFixed(3)]}),(0,X.jsxs)(`span`,{children:[`decay=`,e.recencyDecay?.toFixed(3)??`—`]}),r?(0,X.jsx)(`span`,{className:`text-amber-600 dark:text-amber-400`,children:r}):(0,X.jsx)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:n.previewEligible})]}),e.snippet?(0,X.jsx)(`div`,{className:`mt-2 text-sm text-fg`,children:e.snippet}):null]},`${e.key}:${e.hash}:${t}`)})}):(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.previewEmpty}):(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.previewNotLoaded})]}),(0,X.jsxs)(Et,{className:sn,children:[(0,X.jsx)(ct,{className:cn,icon:z,title:n.eventsTitle,subtitle:n.eventsHint,trailing:(0,X.jsxs)(E,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!u||ae,onClick:()=>void be(),children:[ae?(0,X.jsx)(s,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,n.eventsLoad]})}),le?le.length>0?(0,X.jsx)(`div`,{className:`space-y-1.5`,children:le.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,X.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,X.jsx)(`span`,{children:n}),(0,X.jsx)(`span`,{className:`font-medium text-fg`,children:e.phase}),(0,X.jsx)(`span`,{className:w(`font-medium`,e.ok?`text-emerald-600 dark:text-emerald-400`:`text-amber-600 dark:text-amber-400`),children:e.ok?`OK`:`FAIL`}),(0,X.jsx)(`span`,{className:`text-fg-muted`,children:r}),(0,X.jsx)(`span`,{className:`text-fg-muted`,children:hn(e.durationMs)}),(0,X.jsx)(`span`,{className:`ml-auto text-fg-subtle`,children:mn(e.timestamp)})]},`${e.timestamp}:${e.phase}:${t}`)})}):(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.eventsEmpty}):(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.eventsNotLoaded})]})]}),(0,X.jsxs)(Et,{className:w(`max-w-2xl`,sn),children:[(0,X.jsx)(ct,{className:cn,icon:c,title:n.maintenanceTitle,subtitle:n.maintenanceHint}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,X.jsxs)(E,{variant:`secondary`,disabled:Ce,onClick:()=>{confirm(n.confirmResetStore)&&Se(`reset_store`)},children:[h===`reset_store`?(0,X.jsx)(s,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,X.jsx)(Ne,{className:`mr-2 size-4`,"aria-hidden":!0}),n.resetStore]}),(0,X.jsxs)(E,{variant:`secondary`,disabled:Ce,onClick:()=>{confirm(n.confirmClearLock)&&Se(`clear_lock`)},children:[h===`clear_lock`?(0,X.jsx)(s,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,X.jsx)(ye,{className:`mr-2 size-4`,"aria-hidden":!0}),n.clearLock]})]})]})]})}var Cn=e(Dt(),1);function wn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Tn(e){let t=wn(e)?e:{},n=wn(t.gateway)?t.gateway:{},r=wn(n.auth)?n.auth:{},i=r.mode===`none`||r.mode===`token`?r.mode:`token`,a=(wn(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 En(e){let t=e.auth.token.trim().length>0?{mode:e.auth.mode,token:e.auth.token}:{mode:e.auth.mode};await J(K(`/api/config`),{method:`PATCH`,body:JSON.stringify({gateway:{auth:t},update:{channel:e.updateChannel}})}),R()}function Dn(){return w(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,o,`dark:border-edge`)}function On(){let e=f(e=>e.language),t=ge(e),n=t.gatewaySettings,r=ze(e=>e.token),i=ze(e=>e.tokenExpired),a=ze(e=>e.openTokenDialog),o=!!r,[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(null),[p,h]=(0,Z.useState)(!1),[g,_]=(0,Z.useState)(null),[v,y]=(0,Z.useState)(!1),[b,x]=(0,Z.useState)(!1),[S,C]=(0,Z.useState)(!1),w=(0,Z.useRef)(!1),{data:T,error:D,isLoading:O,mutate:k}=m(o),A=(0,Z.useMemo)(()=>T?.payload?.config===void 0?null:structuredClone(Tn(T.payload.config)),[T]);(0,Z.useEffect)(()=>{if(!o){l(null),d(null),w.current=!1;return}A!==null&&(w.current||(l(A),d(structuredClone(A)),y(!1)))},[o,A]);let j=!!(o&&O&&T===void 0&&!D),M=D instanceof Error?D.message:D?String(D):null,P=(0,Z.useMemo)(()=>!c||!u?!1:JSON.stringify(c)!==JSON.stringify(u),[c,u]),F=(0,Z.useCallback)(e=>{w.current=!0,l(t=>t?{...t,auth:{...t.auth,...e}}:null)},[]),I=(0,Z.useCallback)(e=>{w.current=!0,l(t=>t?{...t,updateChannel:e}:null)},[]),L=(0,Z.useCallback)(async()=>{if(!(!c||p)){h(!0),_(null),y(!1);try{await En(c),w.current=!1,d(structuredClone(c)),y(!0),window.setTimeout(()=>y(!1),2500)}catch(e){_(e instanceof Error?e.message:n.saveError)}finally{h(!1)}}},[c,p,n.saveError]),R=(0,Z.useCallback)(()=>{u&&(w.current=!1,l(structuredClone(u)),_(null),y(!1))},[u]),z=(0,Z.useCallback)(async()=>{let e=c?.auth.token;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),C(!0),window.setTimeout(()=>C(!1),2e3))},[c?.auth.token]);return o?j?(0,X.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,X.jsx)(s,{className:`size-4 animate-spin`}),n.loading]})}):c?(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,X.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.gateway}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,X.jsxs)(`a`,{href:qe(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,X.jsx)(N,{className:`size-3.5`})]})]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[v?(0,X.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,X.jsx)(E,{type:`button`,variant:`secondary`,disabled:!P||p,onClick:R,children:n.discard}),(0,X.jsx)(E,{type:`button`,variant:`primary`,disabled:!P||p,onClick:()=>void L(),children:p?n.saving:n.save})]})]}),i?(0,X.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,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(le,{className:`mt-0.5 size-4 shrink-0 text-red-600 dark:text-red-400`}),(0,X.jsx)(`p`,{className:`text-sm text-red-900 dark:text-red-100`,children:n.tokenExpired})]}),(0,X.jsx)(`div`,{children:(0,X.jsx)(E,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:()=>a(),children:n.updateToken})})]}):null,P?(0,X.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,g?(0,X.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:g}):null,c.auth.mode===`none`?(0,X.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,X.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[(0,X.jsxs)(`div`,{className:`mb-5 flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,X.jsx)(Oe,{className:`size-4 text-accent`,strokeWidth:1.75}),t.settingsSections.gateway]}),(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(c.host||c.port!=null)&&(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:n.listenHost}),(0,X.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,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:n.listenPort}),(0,X.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,X.jsx)(`p`,{className:`sm:col-span-2 text-xs text-fg-subtle`,children:n.listenHint})]}),(0,X.jsx)(An,{g:n,value:c.auth.token,show:b,copied:S,onToggleShow:()=>x(e=>!e),onCopy:()=>void z(),onChange:e=>F({token:e})}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,onClick:()=>a(),children:n.changeToken}),r?(0,X.jsx)(kn,{g:n,gatewayToken:r}):null,(0,X.jsxs)(`div`,{className:`space-y-2 border-t border-edge pt-4`,children:[(0,X.jsx)(`label`,{className:`text-sm font-medium text-fg`,htmlFor:`gateway-update-channel`,children:n.updateChannel}),(0,X.jsxs)(`select`,{id:`gateway-update-channel`,value:c.updateChannel,onChange:e=>I(e.target.value),className:Dn(),children:[(0,X.jsx)(`option`,{value:`stable`,children:n.channelStable}),(0,X.jsx)(`option`,{value:`beta`,children:n.channelBeta}),(0,X.jsx)(`option`,{value:`dev`,children:n.channelDev})]}),(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.updateChannelHint})]})]})]})]}):(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:g??M??n.loadError}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,onClick:()=>void k(),children:n.retry})]}):(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.gateway}),(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}function kn({g:e,gatewayToken:t}){let[n,r]=(0,Z.useState)(je),[i,a]=(0,Z.useState)(null),[o,s]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)(!1),u=n.trim(),d=(0,Z.useMemo)(()=>{try{let e=new URL(u);return e.protocol===`http:`||e.protocol===`https:`}catch{return!1}},[u]),f=(0,Z.useMemo)(()=>!t||!d?``:ue({baseUrl:u,gatewayToken:t}),[d,t,u]);(0,Z.useEffect)(()=>{if(!f){a(null),s(!1);return}let e=!1;return s(!1),Cn.toDataURL(f,{width:216,margin:2,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}}).then(t=>{e||a(t)}).catch(()=>{e||(s(!0),a(null))}),()=>{e=!0}},[f]);let p=d&&Te(u),m=(0,Z.useCallback)(async()=>{f&&(await navigator.clipboard.writeText(f).catch(()=>{}),l(!0),window.setTimeout(()=>l(!1),2e3))},[f]);return(0,X.jsxs)(`div`,{className:`space-y-3 border-t border-edge pt-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,X.jsx)(ce,{className:`size-4 text-accent`,strokeWidth:1.75}),e.mobilePairTitle]}),(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.mobilePairSubtitle}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`label`,{className:`text-sm font-medium text-fg`,htmlFor:`gateway-mobile-pair-base`,children:e.mobilePairBaseUrlLabel}),(0,X.jsx)(`input`,{id:`gateway-mobile-pair-base`,className:w(Dn(),`font-mono text-xs`),type:`text`,autoComplete:`off`,spellCheck:!1,value:n,onChange:e=>r(e.target.value)}),(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.mobilePairBaseUrlHint}),d?null:(0,X.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:e.mobilePairInvalidBaseUrl}),p?(0,X.jsx)(`p`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-950 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-100`,children:e.mobilePairLocalhostWarning}):null,(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.mobilePairSecurityNote})]}),f?(0,X.jsxs)(`div`,{className:`flex flex-col items-center gap-3 sm:items-start`,children:[i&&!o?(0,X.jsx)(`img`,{src:i,alt:``,className:`h-56 w-56 rounded-lg border border-edge-subtle bg-white object-contain p-3 dark:border-edge`}):null,!i&&!o?(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.mobilePairEncoding}):null,o?(0,X.jsx)(`p`,{className:`text-center text-sm text-fg-muted sm:text-left`,children:e.mobilePairImageError}):null,(0,X.jsxs)(E,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,disabled:!f,onClick:()=>void m(),children:[c?(0,X.jsx)(U,{className:`size-3.5`}):(0,X.jsx)(Pe,{className:`size-3.5`}),c?e.mobilePairCopied:e.mobilePairCopyLink]})]}):null,(0,X.jsx)(`p`,{className:`break-all font-mono text-[10px] leading-relaxed text-fg-subtle`,children:e.mobilePairSchemeHint})]})}function An({g:e,value:t,show:n,copied:r,onToggleShow:i,onCopy:a,onChange:o}){return(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.accessToken}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,X.jsx)(`input`,{className:w(Dn(),`min-w-0 flex-1 font-mono text-xs`),type:n?`text`:`password`,autoComplete:`off`,value:t,onChange:e=>o(e.target.value),placeholder:e.tokenPlaceholder}),t?(0,X.jsxs)(E,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:a,children:[r?(0,X.jsx)(U,{className:`size-3.5`}):(0,X.jsx)(Pe,{className:`size-3.5`}),r?e.copied:e.copy]}):null,(0,X.jsxs)(E,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:i,children:[n?(0,X.jsx)(re,{className:`size-3.5`}):(0,X.jsx)(ne,{className:`size-3.5`}),n?e.hide:e.show]})]}),(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tokenHelp})]})}function jn(){return K(`/api/channels/status`)}var Mn=at;function Nn(){return w(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,o,`dark:border-edge`)}function Pn(){return w(ve,g)}function Fn(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 In(){let e=f(e=>e.language),t=ge(e),n=t.heartbeatSettings,i=!!ze(e=>e.token),[a,o]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(``),[p,h]=(0,Z.useState)(``),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)(!1),[b,x]=(0,Z.useState)(null),[C,T]=(0,Z.useState)(!1),[D,O]=(0,Z.useState)(!1),[k,A]=(0,Z.useState)(!1),[j,M]=(0,Z.useState)(!1),[P,F]=(0,Z.useState)(null),[I,L]=(0,Z.useState)([]),{data:R,error:z,isLoading:ee,mutate:B}=m(i),{data:V,error:H,isLoading:te,mutate:ne}=r(i?jt():null,Ot,{revalidateOnFocus:!1}),{data:re=[]}=r(i?jn():null,Mn,{revalidateOnFocus:!1}),ie=(0,Z.useMemo)(()=>Fn(R?.payload?.config),[R]),U=(0,Z.useMemo)(()=>Pt(R?.payload?.config??{}),[R]),W=(0,Z.useMemo)(()=>!a||!c?!1:JSON.stringify(a)!==JSON.stringify(c),[a,c]),G=(0,Z.useMemo)(()=>u!==p,[u,p]);(0,Z.useEffect)(()=>{if(!i){o(null),l(null);return}if(R!==void 0&&!W){let e=structuredClone(U);o(e),l(e),T(!1)}},[i,R,U,W]),(0,Z.useEffect)(()=>{!i||V===void 0||G||(d(V),h(V),O(!1))},[i,V,G]);let ae=z instanceof Error?z.message:z?String(z):H instanceof Error?H.message:H?String(H):null,oe=!!(i&&(R===void 0||V===void 0)&&!ae&&(ee||te));(0,Z.useEffect)(()=>{if(!i||!a){L([]);return}let e=a.target.trim();if(!e){L([]);return}let t=!1;return rt(e).then(e=>{t||L(e)}),()=>{t=!0}},[i,a?.target]);let K=(0,Z.useCallback)(()=>{let e=a?.target?.trim();e&&rt(e).then(L)},[a?.target]),se=(0,Z.useCallback)(async()=>{A(!0),M(!1),F(null);try{await kt(),M(!0),window.setTimeout(()=>M(!1),3e3)}catch(e){F(e instanceof Error?e.message:n.triggerError)}finally{A(!1)}},[n.triggerError]),ce=(0,Z.useCallback)(e=>{o(t=>t?{...t,...e}:null)},[]),le=(0,Z.useCallback)(()=>{c&&(o(structuredClone(c)),T(!1),x(null))},[c]),ue=(0,Z.useCallback)(()=>{d(p),O(!1),x(null)},[p]),q=(0,Z.useCallback)(async()=>{if(!(!a||g)){_(!0),x(null),T(!1);try{await At(a),l(structuredClone(a)),T(!0),window.setTimeout(()=>T(!1),2500)}catch(e){x(e instanceof Error?e.message:n.saveConfigError)}finally{_(!1)}}},[a,g,n.saveConfigError]),de=(0,Z.useCallback)(async()=>{if(!v){y(!0),x(null),O(!1);try{await Mt(u),h(u),O(!0),window.setTimeout(()=>O(!1),2500)}catch(e){x(e instanceof Error?e.message:n.saveDocError)}finally{y(!1)}}},[u,v,n.saveDocError]);return i?oe?(0,X.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,X.jsx)(s,{className:`size-4 animate-spin`}),n.loading]})}):a?(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,X.jsx)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.heartbeat}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,X.jsxs)(`a`,{href:qe(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,X.jsx)(N,{className:`size-3.5`})]})]})}),ie?(0,X.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.workspaceLabel,`: `,(0,X.jsx)(`span`,{className:`font-mono text-fg-muted`,children:ie})]}):null,b?(0,X.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:b}):null,(0,X.jsxs)(Et,{children:[(0,X.jsxs)(`div`,{className:`mb-2 flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,X.jsx)(S,{className:`size-4 text-accent`,strokeWidth:1.75}),n.configSection]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsxs)(E,{type:`button`,variant:`secondary`,className:`inline-flex items-center gap-2`,disabled:k,onClick:()=>void se(),children:[k?(0,X.jsx)(s,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,X.jsx)(Be,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),k?n.triggering:n.triggerNow]}),j?(0,X.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.triggered}):null]})]}),(0,X.jsx)(`p`,{className:`mb-4 text-xs text-fg-subtle`,children:n.triggerHint}),P?(0,X.jsx)(`p`,{className:`mb-3 text-sm text-red-600 dark:text-red-400`,children:P}):null,(0,X.jsx)(Ln,{h:n,cron:t.cron,form:a,channels:re,sessionChatIds:I,onRefreshChatIds:K,update:ce,inputClassName:Nn,selectClassName:Pn}),(0,X.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-2`,children:[C?(0,X.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.savedConfig}):null,(0,X.jsx)(E,{type:`button`,variant:`secondary`,disabled:!W||g,onClick:le,children:n.discard}),(0,X.jsx)(E,{type:`button`,variant:`primary`,disabled:!W||g,onClick:()=>void q(),children:g?n.savingConfig:n.saveConfig}),W?(0,X.jsx)(`span`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedConfig}):null]})]}),(0,X.jsxs)(Et,{children:[(0,X.jsx)(`div`,{className:`mb-2 text-sm font-semibold text-fg`,children:n.docSection}),(0,X.jsx)(`p`,{className:`mb-3 text-xs text-fg-subtle`,children:n.docHint}),(0,X.jsx)(`textarea`,{className:w(Nn(),`min-h-[12rem] resize-y font-mono text-xs leading-relaxed`),value:u,onChange:e=>d(e.target.value),spellCheck:!1,"aria-label":n.docSection}),(0,X.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-2`,children:[D?(0,X.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.savedDoc}):null,(0,X.jsx)(E,{type:`button`,variant:`secondary`,disabled:!G||v,onClick:ue,children:n.discard}),(0,X.jsx)(E,{type:`button`,variant:`primary`,disabled:!G||v,onClick:()=>void de(),children:v?n.savingDoc:n.saveDoc}),G?(0,X.jsx)(`span`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedDoc}):null]})]})]}):(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:b??ae??n.loadError}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,onClick:()=>{B(),ne()},children:n.retry})]}):(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.heartbeat}),(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}function Ln({h:e,cron:t,form:n,channels:r,sessionChatIds:i,onRefreshChatIds:a,update:o,inputClassName:s,selectClassName:c}){let l=(0,Z.useMemo)(()=>new Set(r.map(e=>e.name)),[r]),u=n.target.trim(),d=!!(u&&!l.has(u));return(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,X.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:n.enabled,onChange:e=>o({enabled:e.target.checked})}),e.enable]}),(0,X.jsx)(on,{kind:`interval`,label:e.interval,valueMs:n.intervalMs,onChangeMs:e=>o({intervalMs:e}),labels:{secondsLabel:e.intervalSecondsLabel,presets:e.intervalPresets},hint:`${e.intervalHintPreset} ${e.intervalHint}`}),(0,X.jsxs)(`div`,{className:`border-t border-edge-subtle pt-4`,children:[(0,X.jsx)(`div`,{className:`mb-2 text-sm font-medium text-fg`,children:e.deliveryTitle}),(0,X.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,X.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:t.channel}),(0,X.jsxs)(`select`,{className:c(),value:u,onChange:e=>{o({target:e.target.value.trim(),targetChatId:``})},children:[(0,X.jsx)(`option`,{value:``,children:e.channelNone}),d?(0,X.jsxs)(`option`,{value:u,children:[u,` (`,e.customChannelSuffix,`)`]}):null,r.map(e=>(0,X.jsxs)(`option`,{value:e.name,disabled:!e.enabled,children:[e.name,` `,e.enabled?``:`(disabled)`]},e.name))]})]}),u?(0,X.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,X.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:t.recipient}),(0,X.jsxs)(E,{type:`button`,variant:`ghost`,className:`h-7 gap-1 px-2 text-xs`,title:t.refreshRecipientHint,onClick:a,children:[(0,X.jsx)(Me,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0}),t.refreshList]})]}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(`input`,{type:`text`,className:w(s(),`min-w-0 flex-1`),value:n.targetChatId,onChange:e=>o({targetChatId:e.target.value}),placeholder:t.recipientPlaceholder,autoComplete:`off`}),(0,X.jsxs)(`select`,{className:w(c(),`max-w-[10rem] shrink-0 text-xs`),value:n.targetChatId,onChange:e=>{let t=e.target.value;t&&o({targetChatId:t})},children:[(0,X.jsx)(`option`,{value:``,children:t.selectRecipient}),i.length>0?i.map(e=>(0,X.jsx)(`option`,{value:e.chatId,children:nt(e,t.lastActiveLabels)},`${e.channel}-${e.chatId}`)):(0,X.jsx)(`option`,{value:``,disabled:!0,children:t.noRecentChatsOption})]})]}),(0,X.jsx)(`p`,{className:`text-xs text-fg-muted`,children:i.length>0?t.enterManuallyOrSelect:t.noRecentChats})]}):null,(0,X.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:e.deliveryHint})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:e.prompt}),(0,X.jsx)(`textarea`,{className:w(s(),`min-h-[4.5rem] resize-y font-mono text-xs`),value:n.prompt,onChange:e=>o({prompt:e.target.value}),placeholder:e.promptPlaceholder}),(0,X.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:e.promptHint})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:e.ackMaxChars}),(0,X.jsx)(`input`,{type:`number`,min:1,className:s(),value:n.ackMaxChars===``?``:n.ackMaxChars,onChange:e=>{let t=e.target.value;if(t===``)o({ackMaxChars:``});else{let e=parseInt(t,10);o({ackMaxChars:Number.isFinite(e)?e:``})}},placeholder:e.ackDefaultPlaceholder}),(0,X.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:e.ackMaxCharsHint})]}),(0,X.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,X.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:n.isolatedSession,onChange:e=>o({isolatedSession:e.target.checked})}),(0,X.jsxs)(`span`,{children:[e.isolatedSession,(0,X.jsx)(`span`,{className:`mt-1 block text-xs text-fg-subtle`,children:e.isolatedSessionHint})]})]}),(0,X.jsx)(`div`,{className:`border-t border-edge-subtle pt-4`,children:(0,X.jsx)(on,{kind:`active-hours`,label:e.activeHoursTitle,value:n.activeHours,onChange:e=>o({activeHours:e}),labels:{start:e.activeStart,end:e.activeEnd,timezone:e.activeTimezone,add:e.addActiveHours,clear:e.clearActiveHours},hint:e.activeHoursHint})})]})}async function Rn(){let e=await Y(K(`/api/image/providers`));if(!e.ok)throw Error(`Image providers: HTTP ${e.status}`);return(await e.json()).payload?.providers??[]}function zn(e){let t=new Set,n=[];for(let r of e){let e=r.models.length>0?r.models:r.defaultModel?[r.defaultModel]:[];for(let i of e){let e=`${r.id}/${i}`;t.has(e)||(t.add(e),n.push(e))}}return n}function Bn(e,t){let n=zn(e.filter(e=>e.configured===!0));return!t||n.includes(t)?n:[t,...n]}function Vn(e,t){let n=t.trim().toLowerCase();if(!n)return e;let r=n.split(/[/\s]+/).filter(Boolean);return e.filter(e=>{let t=e.toLowerCase();return r.every(e=>t.includes(e))})}var Hn=`image-generation-providers`;function Un({value:e,disabled:t,placeholder:n,searchPlaceholder:i,noMatches:a,registryEmptyHint:o,outOfFilterNote:s,className:c,onChange:l}){let[d,f]=(0,Z.useState)(!1),[p,m]=(0,Z.useState)(``),{data:h,isLoading:g,error:_}=r(Hn,Rn,{revalidateOnFocus:!1}),v=e.trim(),b=(0,Z.useMemo)(()=>zn((h??[]).filter(e=>e.configured===!0)),[h]),x=(0,Z.useMemo)(()=>Bn(h??[],v),[h,v]),S=(0,Z.useMemo)(()=>Vn(x,p),[x,p]),C=!!s&&!!v&&!b.includes(v),E=e.trim()?e:n,D=e.trim()||n,O=(0,Z.useCallback)(e=>{f(e),e||m(``)},[]);return(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,X.jsxs)(Xe,{open:d,onOpenChange:O,modal:!1,children:[(0,X.jsx)(u,{asChild:!0,children:(0,X.jsxs)(`button`,{type:`button`,disabled:t||g,title:g?`…`:D,className:w(ee,`items-center gap-2 rounded-lg border border-edge-subtle bg-surface-panel px-3 py-2 text-left text-sm font-normal text-fg`,H.transition,`hover:border-edge hover:bg-surface-hover/45`,k,`disabled:cursor-not-allowed disabled:opacity-50`,`dark:border-edge-subtle dark:hover:bg-surface-hover/55`,c),"aria-haspopup":`listbox`,"aria-expanded":d,children:[(0,X.jsx)(`span`,{className:`min-w-0 truncate`,children:g?`…`:E}),(0,X.jsx)(Ae,{className:`h-4 w-4 shrink-0 text-fg-subtle opacity-70`,"aria-hidden":!0})]})}),(0,X.jsx)(F,{children:(0,X.jsxs)(T,{className:w(`w-[min(22rem,calc(100vw-2rem))] rounded-xl border border-edge-subtle bg-surface-panel p-1 shadow-elevated dark:border-edge-subtle`,xe),side:`bottom`,sideOffset:4,align:`end`,onOpenAutoFocus:e=>e.preventDefault(),children:[(0,X.jsx)(`input`,{type:`search`,className:w(`mb-1 w-full rounded-lg border border-edge-subtle bg-surface-base px-2.5 py-1.5 text-sm text-fg placeholder:text-fg-disabled dark:bg-surface-hover/40`,y),placeholder:i,value:p,onChange:e=>m(e.target.value),onKeyDown:e=>e.stopPropagation()}),(0,X.jsxs)(`div`,{className:`max-h-60 overflow-auto`,role:`listbox`,"aria-label":i,children:[_?(0,X.jsx)(`div`,{className:`px-2 py-2 text-xs text-red-600 dark:text-red-400`,children:_ instanceof Error?_.message:`Failed to load image providers`}):null,!_&&x.length===0&&!g?(0,X.jsx)(`div`,{className:`px-2 py-3 text-center text-xs text-fg-muted`,children:o??a}):null,!_&&x.length>0&&S.length===0?(0,X.jsx)(`div`,{className:`px-2 py-3 text-center text-xs text-fg-muted`,children:a}):null,S.map(t=>(0,X.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t===e,className:w(`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-fg hover:bg-surface-hover`,t===e&&`bg-surface-hover/90 font-medium dark:bg-surface-hover/70`),onClick:()=>{l(t),f(!1),m(``)},children:[(0,X.jsx)(U,{className:w(`h-4 w-4 shrink-0`,t!==e&&`invisible`),"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm font-medium`,children:t})]},t))]})]})})]}),C?(0,X.jsx)(`p`,{className:`text-xs text-amber-700 dark:text-amber-400/90`,children:s}):null]})}function Wn(e){let{a:t,chat:n,form:r,update:i}=e;return(0,X.jsxs)(Et,{children:[(0,X.jsx)(ct,{icon:V,title:t.cardModelsTitle,subtitle:t.cardModelsSubtitle}),(0,X.jsxs)(`div`,{className:`mt-4 flex flex-col gap-5`,children:[(0,X.jsx)(ut,{label:t.label.imageModel,description:t.desc.imageModel,children:(0,X.jsx)(W,{value:r.imageModel,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,capabilitiesFilter:`vision`,registryEmptyHint:t.visionRegistryEmpty,outOfFilterNote:t.visionOutOfFilterNote,onChange:e=>i({imageModel:e})})}),(0,X.jsx)(ut,{label:t.label.imageModelFallbacks,description:t.desc.imageModelFallbacks,children:(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[r.imageModelFallbacks.map((e,a)=>(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,X.jsx)(W,{value:e,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,capabilitiesFilter:`vision`,registryEmptyHint:t.visionRegistryEmpty,outOfFilterNote:t.visionOutOfFilterNote,onChange:e=>{let t=[...r.imageModelFallbacks];t[a]=e,i({imageModelFallbacks:t})}})}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":t.removeModelFallback,onClick:()=>i({imageModelFallbacks:r.imageModelFallbacks.filter((e,t)=>t!==a)}),children:(0,X.jsx)(Ne,{className:`size-4`,strokeWidth:1.75})})]},a)),(0,X.jsxs)(E,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:()=>i({imageModelFallbacks:[...r.imageModelFallbacks,``]}),children:[(0,X.jsx)(me,{className:`size-4 shrink-0`,strokeWidth:1.75}),t.addModelFallback]})]})}),(0,X.jsx)(ut,{label:t.label.imageGenerationModel,description:t.desc.imageGenerationModel,children:(0,X.jsx)(Un,{value:r.imageGenerationModel,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,registryEmptyHint:t.imageGenRegistryEmpty,outOfFilterNote:t.imageGenOutOfFilterNote,onChange:e=>i({imageGenerationModel:e})})}),(0,X.jsx)(ut,{label:t.label.imageGenerationModelFallbacks,description:t.desc.imageGenerationModelFallbacks,children:(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[r.imageGenerationModelFallbacks.map((e,a)=>(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,X.jsx)(Un,{value:e,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,registryEmptyHint:t.imageGenRegistryEmpty,outOfFilterNote:t.imageGenOutOfFilterNote,onChange:e=>{let t=[...r.imageGenerationModelFallbacks];t[a]=e,i({imageGenerationModelFallbacks:t})}})}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":t.removeModelFallback,onClick:()=>i({imageGenerationModelFallbacks:r.imageGenerationModelFallbacks.filter((e,t)=>t!==a)}),children:(0,X.jsx)(Ne,{className:`size-4`,strokeWidth:1.75})})]},a)),(0,X.jsxs)(E,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:()=>i({imageGenerationModelFallbacks:[...r.imageGenerationModelFallbacks,``]}),children:[(0,X.jsx)(me,{className:`size-4 shrink-0`,strokeWidth:1.75}),t.addModelFallback]})]})})]})]})}function Gn(){return w(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,o)}var Kn=()=>K(Ze);function qn(e){return{imageModel:e.imageModel,imageModelFallbacks:e.imageModelFallbacks,imageGenerationModel:e.imageGenerationModel,imageGenerationModelFallbacks:e.imageGenerationModelFallbacks,imageGenerationModelTimeoutMs:e.imageGenerationModelTimeoutMs,imageGenerationModelAutoProviderFallback:e.imageGenerationModelAutoProviderFallback}}function Jn(e){return{credentialsIntro:e.credentialsIntro,regionHint:e.regionHint,endpointPresetsHint:e.endpointPresetsHint,apiKeyLabel:e.apiKeyLabel,optionalPlaceholder:e.optionalPlaceholder,regionLabel:e.regionLabel,baseUrlLabel:e.baseUrlLabel,imageBaseUrlLabel:e.imageBaseUrlLabel,saveCredentials:e.saveCredentials,savingCredentials:e.savingCredentials,credentialsSaved:e.credentialsSaved,discardCredentials:e.discardCredentials,credentialsNothingToSave:e.credentialsNothingToSave,credentialsSaveError:e.credentialsSaveError,regionPresetDefault:e.regionPresetDefault,regionPresetCustom:e.regionPresetCustom,baseUrlPresetDefault:e.baseUrlPresetDefault,baseUrlPresetCustom:e.baseUrlPresetCustom,openExtensionSettings:e.openExtensionSettings,openImageModelsPage:e.openImageModelsPage,extensionSettingsLinkTitle:e.extensionSettingsLinkTitle,imageModelsLinkTitle:e.imageModelsLinkTitle,configured:e.configured,missingKey:e.missingKey,defaultModel:e.defaultModel,modelsLabel:e.modelsLabel,imageBaseUrlPresetHint:e.imageBaseUrlPresetHint,dashscopeRegion_beijing:e.dashscopeRegion_beijing,dashscopeRegion_singapore:e.dashscopeRegion_singapore,dashscopeRegion_us:e.dashscopeRegion_us,apiKeyMaskedHelp:e.apiKeyMaskedHelp,apiKeyCopy:e.apiKeyCopy,apiKeyCopied:e.apiKeyCopied,apiKeyShow:e.apiKeyShow,apiKeyHide:e.apiKeyHide,apiKeyNotInConfigFile:e.apiKeyNotInConfigFile,apiKeyRevealFailed:e.apiKeyRevealFailed,minimaxClusterLabel:e.minimaxClusterLabel,minimaxClusterHint:e.minimaxClusterHint,falQueueBaseLabel:e.falQueueBaseLabel,falQueueBaseHint:e.falQueueBaseHint}}function Yn(){let e=f(e=>e.language),t=ge(e),n=t.imageModelsSettings,i=!!ze(e=>e.token),[a,o]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(!0),[p,h]=(0,Z.useState)(!1),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)(void 0),b=Se(),x=(0,Z.useMemo)(()=>new Set(b.map(e=>e.id)),[b]),S=(0,Z.useCallback)(async()=>{if(i){d(!0),y(void 0);try{let e=await lt(),t=structuredClone(e);o(t),l(structuredClone(t))}catch(e){y(e instanceof Error?e.message:String(e))}finally{d(!1)}}},[i]);(0,Z.useEffect)(()=>{S()},[S]);let C=(0,Z.useCallback)(e=>{o(t=>t?{...t,...e}:null)},[]),{data:T=[],mutate:D}=r(i?Kn():null,$e,{revalidateOnFocus:!1}),O=m(i),k=et(T),A=(0,Z.useMemo)(()=>!a||!c?!1:JSON.stringify(qn(a))!==JSON.stringify(qn(c)),[a,c]),j=A||k.credDirty;(0,Z.useEffect)(()=>{if(!j)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[j]);let M=(0,Z.useCallback)(async()=>{if(a){h(!0),y(void 0);try{try{ht(a.paramsJson)}catch(e){y(e instanceof SyntaxError?t.agentSettings.advanced.paramsInvalidJson:e instanceof Error?e.message:t.agentSettings.advanced.paramsInvalidJson);return}await Ct(a),l(structuredClone(a)),_(!0),window.setTimeout(()=>_(!1),1500),O.mutate?.()}catch(e){y(e instanceof Error?e.message:String(e))}finally{h(!1)}}},[a,O,t.agentSettings]),N=(0,Z.useCallback)(()=>{c&&(o(structuredClone(c)),y(void 0),_(!1))},[c]),P=(0,Z.useMemo)(()=>Jn(n),[n]),F=(0,Z.useMemo)(()=>({getApiKey:t.providersSettings.getApiKey,getApiKeyIntl:t.providersSettings.getApiKeyIntl,getApiKeyCn:t.providersSettings.getApiKeyCn}),[t.providersSettings]);return i?u||!a?(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main items-center gap-2 px-4 py-8 text-sm text-fg-muted`,children:[(0,X.jsx)(s,{className:`size-4 animate-spin`}),` Loading…`]}):(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[(0,X.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.title}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle})]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[(0,X.jsxs)(E,{type:`button`,variant:`ghost`,onClick:()=>{S(),D(),O.mutate?.()},children:[(0,X.jsx)(Me,{className:`size-3.5`}),(0,X.jsx)(`span`,{className:`ml-1.5`,children:n.refresh})]}),g?(0,X.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,X.jsx)(E,{type:`button`,variant:`secondary`,onClick:N,disabled:!A||p,children:n.discard}),(0,X.jsxs)(E,{type:`button`,variant:`primary`,onClick:()=>void M(),disabled:!A||p,children:[p?(0,X.jsx)(s,{className:`size-3.5 animate-spin`}):(0,X.jsx)(q,{className:`size-3.5`}),(0,X.jsx)(`span`,{className:`ml-1.5`,children:p?n.saving:n.save})]})]})]}),v?(0,X.jsx)(`div`,{className:`rounded-lg border border-red-500/30 bg-red-500/10 px-3 py-2 text-sm text-red-700 dark:text-red-300`,children:v}):null,(0,X.jsx)(Wn,{form:a,update:C,a:t.agentSettings,chat:t.chat}),(0,X.jsxs)(Et,{children:[(0,X.jsx)(ct,{icon:V,title:n.title,subtitle:n.subtitle}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,X.jsx)(`div`,{className:`rounded-lg border border-edge-subtle bg-surface-base px-3 py-2.5 text-xs leading-relaxed text-fg-muted`,children:n.crossLinkHint}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)(`label`,{className:`text-sm font-medium text-fg`,children:n.timeoutLabel}),(0,X.jsx)(`input`,{type:`number`,min:0,step:1e3,className:w(Gn(),`max-w-[12rem]`),value:a.imageGenerationModelTimeoutMs??``,placeholder:`120000`,onChange:e=>{let t=e.target.value.trim(),n=t===``?null:Math.max(0,Math.floor(Number(t)));o(e=>e?{...e,imageGenerationModelTimeoutMs:n&&n>0?n:null}:null)}}),(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.timeoutHint})]}),(0,X.jsxs)(`label`,{className:`flex items-start gap-3 text-sm`,children:[(0,X.jsx)(`input`,{type:`checkbox`,className:`mt-0.5`,checked:a.imageGenerationModelAutoProviderFallback,onChange:e=>o(t=>t?{...t,imageGenerationModelAutoProviderFallback:e.target.checked}:null)}),(0,X.jsxs)(`span`,{className:`flex flex-col gap-0.5`,children:[(0,X.jsx)(`span`,{className:`font-medium text-fg`,children:n.autoFallbackLabel}),(0,X.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:n.autoFallbackHint})]})]})]})]}),(0,X.jsxs)(Et,{children:[(0,X.jsx)(ct,{icon:Oe,title:n.providersTitle,subtitle:``}),T.length===0?(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.providersEmpty}):(0,X.jsx)(Qe,{summaries:T,credDraft:k.credDraft,credDirty:k.credDirty,credSaving:k.credSaving,credError:k.credError,credSavedFlash:k.credSavedFlash,credNoopFlash:k.credNoopFlash,updateCredRow:k.updateCredRow,onDiscardCredentials:k.onDiscardCredentials,onSaveCredentials:()=>void k.saveCredentials(n.credentialsSaveError),extensionIds:x,showExtensionLinks:!0,showImageModelsLink:!1,language:e,apiKeyLinkLabels:F,messages:P})]})]}):(0,X.jsx)(`div`,{className:`mx-auto w-full max-w-app-main px-4 py-8 text-sm text-fg-muted`,children:e===`zh`?`请先登录网关。`:`Connect to a gateway to continue.`})}var Xn=[{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 Zn(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 Qn(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 $n(){let e=await Y(K(`/api/models-json`)),t=await e.json().catch(()=>({}));if(!e.ok||!t.ok||!t.payload)throw Error(Zn(t)||`HTTP ${e.status}`);return{...t.payload,config:Qn(t.payload.config)}}async function er(e){let t=await Y(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(Zn(n)||`HTTP ${t.status}`);return n.payload}async function tr(e){let t=await Y(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(Zn(n)||`HTTP ${t.status}`);return n.payload}async function nr(){let e=await Y(K(`/api/models-json/reload`),{method:`POST`}),t=await e.json().catch(()=>({}));if(!e.ok||!t.ok||!t.payload)throw Error(Zn(t)||`HTTP ${e.status}`);return t.payload}async function rr(e){let t=await Y(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(Zn(n)||`HTTP ${t.status}`);return n.payload}function ir(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 ar(e){return e.startsWith(`!`)}function or(e){return/^[A-Z][A-Z0-9_]*$/.test(e)}function sr(e){return ar(e)?`shell`:or(e)?`env`:`literal`}function cr(e){return e?e.length<=8?`••••`:`${e.slice(0,4)}••••${e.slice(-4)}`:``}function lr(e){let{a:t,chat:n,form:r,update:i}=e;return(0,X.jsxs)(Et,{children:[(0,X.jsx)(ct,{icon:Ee,title:t.label.modelFallbacks,subtitle:t.desc.modelFallbacks}),(0,X.jsxs)(`div`,{className:`mt-4 flex flex-col gap-2`,children:[r.modelFallbacks.map((e,a)=>(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,X.jsx)(W,{value:e,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,onChange:e=>{let t=[...r.modelFallbacks];t[a]=e,i({modelFallbacks:t})}})}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":t.removeModelFallback,onClick:()=>i({modelFallbacks:r.modelFallbacks.filter((e,t)=>t!==a)}),children:(0,X.jsx)(Ne,{className:`size-4`,strokeWidth:1.75})})]},a)),(0,X.jsxs)(E,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:()=>i({modelFallbacks:[...r.modelFallbacks,``]}),children:[(0,X.jsx)(me,{className:`size-4 shrink-0`,strokeWidth:1.75}),t.addModelFallback]})]})]})}var ur={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 dr(e){return e===`openrouter`?`openrouter`:e===`zhipuCn`?`zhipu-cn`:e===`zaiGeneral`?`zai`:e}var fr=[{value:`text`,labelKey:`inputTextOnly`},{value:`text,image`,labelKey:`inputTextVision`}];function pr(){return w(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,o,`dark:border-edge`)}function mr(){return w(ve,g)}function hr(e){return(e.input||[`text`]).includes(`image`)?`text,image`:`text`}function gr(e){return e===`text,image`?[`text`,`image`]:[`text`]}function _r(e,t,n){return{...e,providers:{...e.providers,[t]:{...e.providers[t],...n}}}}function vr(e,t){let n={...e.providers};return delete n[t],{...e,providers:n}}function yr(e,t,n){return{...e,providers:{...e.providers,[t]:n}}}function br({open:e,onOpenChange:t,providerId:n,model:r,isNew:i,onSave:a,m:o}){let[s,c]=(0,Z.useState)(()=>ir(``)),[l,u]=(0,Z.useState)(()=>new Map);(0,Z.useEffect)(()=>{e&&(u(new Map),c(r?{...r}:ir(``)))},[e,r]);let d=(e,t)=>{c(n=>({...n,[e]:t})),u(t=>{let n=new Map(t);return n.delete(e),n})},f=()=>{let e=new Map;return(s.id||``).trim()||e.set(`id`,o.modelIdRequired),s.contextWindow!==void 0&&s.contextWindow<=0&&e.set(`contextWindow`,o.mustBePositive),s.maxTokens!==void 0&&s.maxTokens<=0&&e.set(`maxTokens`,o.mustBePositive),u(e),e.size===0},p=()=>{if(!f())return;let e=(s.id||``).trim();a({...s,id:e,name:s.name?.trim()||e,reasoning:s.reasoning||!1,input:s.input||[`text`],contextWindow:s.contextWindow??128e3,maxTokens:s.maxTokens??16384,cost:{input:s.cost?.input??0,output:s.cost?.output??0,cacheRead:s.cost?.cacheRead??0,cacheWrite:s.cost?.cacheWrite??0}}),t(!1)},m=hr(s);return(0,X.jsx)(O,{open:e,onOpenChange:t,children:(0,X.jsxs)(D,{children:[(0,X.jsx)(_e,{className:w(`xopc-dialog-overlay fixed inset-0 bg-scrim`,ae)}),(0,X.jsxs)(be,{className:w(`xopc-dialog-content fixed left-1/2 top-1/2 max-h-[min(90vh,720px)] w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2`,De,`overflow-y-auto rounded-xl border border-edge bg-surface-panel p-4 shadow-popover dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,X.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(M,{className:`text-base font-semibold text-fg`,children:i?o.addModelTitle:o.editModelTitle}),n?(0,X.jsxs)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:[o.modelProviderLabel,`: `,n]}):null]}),(0,X.jsx)(j,{asChild:!0,children:(0,X.jsx)(`button`,{type:`button`,className:`rounded-lg p-1.5 text-fg-muted hover:bg-surface-base hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,"aria-label":o.close,children:(0,X.jsx)(Je,{className:`size-4`})})})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`label`,{className:`mb-1 block text-xs font-medium text-fg`,children:[o.modelId,(0,X.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,X.jsx)(`input`,{className:w(pr(),l.has(`id`)&&`border-red-500`),value:s.id||``,onChange:e=>d(`id`,e.target.value),placeholder:`e.g. llama3.1:8b`,disabled:!i}),l.has(`id`)?(0,X.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:l.get(`id`)}):null]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:o.displayName}),(0,X.jsx)(`input`,{className:pr(),value:s.name||``,onChange:e=>d(`name`,e.target.value)})]}),(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:o.inputTypes}),(0,X.jsx)(`select`,{className:mr(),value:m,onChange:e=>d(`input`,gr(e.target.value)),children:fr.map(e=>(0,X.jsx)(`option`,{value:e.value,children:o[e.labelKey]},e.value))})]}),(0,X.jsxs)(`label`,{className:`mt-6 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,X.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:s.reasoning||!1,onChange:e=>d(`reasoning`,e.target.checked)}),o.reasoning]})]}),(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:o.contextWindow}),(0,X.jsx)(`input`,{type:`number`,min:1,className:w(pr(),l.has(`contextWindow`)&&`border-red-500`),value:s.contextWindow??128e3,onChange:e=>d(`contextWindow`,parseInt(e.target.value,10)||0)}),l.has(`contextWindow`)?(0,X.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:l.get(`contextWindow`)}):null]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:o.maxOutputTokens}),(0,X.jsx)(`input`,{type:`number`,min:1,className:w(pr(),l.has(`maxTokens`)&&`border-red-500`),value:s.maxTokens??16384,onChange:e=>d(`maxTokens`,parseInt(e.target.value,10)||0)}),l.has(`maxTokens`)?(0,X.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:l.get(`maxTokens`)}):null]})]}),(0,X.jsxs)(`div`,{className:`border-t border-edge-subtle pt-2 dark:border-edge`,children:[(0,X.jsx)(`p`,{className:`mb-2 text-xs font-semibold text-fg`,children:o.costSection}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:o.costInput}),(0,X.jsx)(`input`,{type:`number`,step:`any`,min:0,className:pr(),value:s.cost?.input??0,onChange:e=>d(`cost`,{...s.cost,input:parseFloat(e.target.value)||0,output:s.cost?.output??0,cacheRead:s.cost?.cacheRead??0,cacheWrite:s.cost?.cacheWrite??0})})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:o.costOutput}),(0,X.jsx)(`input`,{type:`number`,step:`any`,min:0,className:pr(),value:s.cost?.output??0,onChange:e=>d(`cost`,{...s.cost,input:s.cost?.input??0,output:parseFloat(e.target.value)||0,cacheRead:s.cost?.cacheRead??0,cacheWrite:s.cost?.cacheWrite??0})})]})]})]})]}),(0,X.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2 border-t border-edge-subtle pt-3 dark:border-edge`,children:[(0,X.jsx)(j,{asChild:!0,children:(0,X.jsx)(E,{type:`button`,variant:`secondary`,children:o.cancel})}),(0,X.jsx)(E,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:p,children:i?o.addModelConfirm:o.saveModelConfirm})]})]})]})})}function xr({open:e,onOpenChange:t,presetKey:n,onConfirm:r,m:i}){let[a,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(`custom`),[l,u]=(0,Z.useState)(``),[d,f]=(0,Z.useState)(`openai-completions`),[p,m]=(0,Z.useState)(``),[h,g]=(0,Z.useState)(null);(0,Z.useEffect)(()=>{if(!e)return;g(null);let t=n||null;if(t&&ur[t]){let e=ur[t];c(t),u(e.baseUrl||``),f(e.api||`openai-completions`),m(e.apiKey??``),o(dr(t))}else c(`custom`),o(``),u(``),f(`openai-completions`),m(``)},[e,n]);let _=e=>{if(c(e),e===`custom`)return;let t=ur[e];t&&(u(t.baseUrl||``),f(t.api||`openai-completions`),m(t.apiKey??``),o(dr(e)))};return(0,X.jsx)(O,{open:e,onOpenChange:t,children:(0,X.jsxs)(D,{children:[(0,X.jsx)(_e,{className:w(`xopc-dialog-overlay fixed inset-0 bg-scrim`,ae)}),(0,X.jsxs)(be,{className:w(`xopc-dialog-content fixed left-1/2 top-1/2 max-h-[min(90vh,640px)] w-[min(100%-2rem,32rem)] -translate-x-1/2 -translate-y-1/2`,De,`overflow-y-auto rounded-xl border border-edge bg-surface-panel p-4 shadow-popover dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,X.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(M,{className:`text-base font-semibold text-fg`,children:i.addProviderTitle}),(0,X.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:i.addProviderSubtitle})]}),(0,X.jsx)(j,{asChild:!0,children:(0,X.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,X.jsx)(Je,{className:`size-4`})})})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:i.presetLabel}),(0,X.jsxs)(`select`,{className:mr(),value:s,onChange:e=>_(e.target.value),children:[(0,X.jsx)(`option`,{value:`custom`,children:i.presetCustom}),(0,X.jsx)(`option`,{value:`ollama`,children:i.presetOllama}),(0,X.jsx)(`option`,{value:`lmstudio`,children:i.presetLmStudio}),(0,X.jsx)(`option`,{value:`openrouter`,children:i.presetOpenRouter}),(0,X.jsx)(`option`,{value:`zhipuCn`,children:i.presetZhipuCn}),(0,X.jsx)(`option`,{value:`zaiGeneral`,children:i.presetZaiGeneral})]})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`label`,{className:`mb-1 block text-xs font-medium text-fg`,children:[i.providerIdLabel,(0,X.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,X.jsx)(`input`,{className:pr(),value:a,onChange:e=>o(e.target.value),placeholder:i.providerIdPlaceholder})]}),(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:i.baseUrl}),(0,X.jsx)(`input`,{className:pr(),value:l,onChange:e=>u(e.target.value),placeholder:`https://…`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:i.apiType}),(0,X.jsx)(`select`,{className:mr(),value:d,onChange:e=>f(e.target.value),children:Xn.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:i.apiKey}),(0,X.jsx)(`input`,{className:pr(),value:p,onChange:e=>m(e.target.value),placeholder:i.apiKeyPlaceholder})]}),h?(0,X.jsxs)(`p`,{className:`flex items-center gap-1 text-xs text-red-600 dark:text-red-400`,children:[(0,X.jsx)(le,{className:`size-3.5 shrink-0`}),h]}):null]}),(0,X.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2 border-t border-edge-subtle pt-3 dark:border-edge`,children:[(0,X.jsx)(j,{asChild:!0,children:(0,X.jsx)(E,{type:`button`,variant:`secondary`,children:i.cancel})}),(0,X.jsx)(E,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:()=>{let e=a.trim();if(!e){g(i.providerIdRequired);return}g(null),r(e,{baseUrl:l.trim()||void 0,api:d,apiKey:p.trim()||void 0,models:[]}),t(!1)},children:i.addProviderConfirm})]})]})]})})}function Sr({config:e,setConfig:t,expanded:n,toggleExpand:r,showPw:i,toggleShowPw:a,testResults:o,runTestKey:s,ms:c,removeProv:l,openModelDialog:u,setTestResults:d}){return(0,X.jsx)(`div`,{className:`flex flex-col gap-3`,children:Object.entries(e.providers).sort(([e],[t])=>e.localeCompare(t)).map(([e,f])=>{let p=n.has(e),m=f.models?.length??0,h=f.apiKey?sr(f.apiKey):null,g=o.get(e),_=i.has(e);return(0,X.jsxs)(`section`,{className:`overflow-hidden rounded-2xl bg-surface-base`,children:[(0,X.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,X.jsxs)(`button`,{type:`button`,className:`flex min-w-0 flex-1 items-center gap-2 text-left text-sm font-semibold text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,onClick:()=>r(e),children:[p?(0,X.jsx)(fe,{className:`size-4 shrink-0 text-fg-muted`}):(0,X.jsx)(we,{className:`size-4 shrink-0 text-fg-muted`}),(0,X.jsx)(`span`,{className:`truncate`,children:e}),m>0?(0,X.jsx)(`span`,{className:`shrink-0 rounded-full bg-accent px-2 py-0.5 text-[10px] font-medium text-white`,children:m}):null,h?(0,X.jsx)(`span`,{className:w(`shrink-0 rounded-full px-2 py-0.5 text-[10px] font-medium`,h===`shell`&&`bg-blue-100 text-blue-800 dark:bg-blue-950 dark:text-blue-200`,h===`env`&&`bg-emerald-100 text-emerald-800 dark:bg-emerald-950 dark:text-emerald-200`,h===`literal`&&`bg-surface-hover text-fg-muted dark:bg-surface-active`),children:h===`shell`?c.badgeShell:h===`env`?c.badgeEnv:c.badgeLiteral}):null]}),(0,X.jsx)(`button`,{type:`button`,className:`rounded-lg p-1.5 text-fg-muted hover:bg-surface-base hover:text-red-600 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 dark:hover:text-red-400`,onClick:()=>l(e),"aria-label":c.removeProvider,children:(0,X.jsx)(Ne,{className:`size-4`})})]}),p?(0,X.jsxs)(`div`,{className:`space-y-4 px-3 py-3`,children:[(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:c.baseUrl}),(0,X.jsx)(`input`,{className:pr(),value:f.baseUrl||``,onChange:n=>t(t=>_r(t,e,{baseUrl:n.target.value}))})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:c.apiType}),(0,X.jsx)(`select`,{className:mr(),value:f.api||`openai-completions`,onChange:n=>t(t=>_r(t,e,{api:n.target.value})),children:Xn.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:c.apiKey}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,X.jsx)(`input`,{className:w(pr(),`min-w-0 flex-1`),type:_?`text`:`password`,autoComplete:`off`,value:f.apiKey||``,onChange:n=>{let r=n.target.value;t(t=>_r(t,e,{apiKey:r})),d(t=>{let n=new Map(t);return n.delete(e),n})},placeholder:c.apiKeyPlaceholder}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>a(e),children:_?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(re,{className:`mr-1 size-3.5`}),c.hide]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(ne,{className:`mr-1 size-3.5`}),c.show]})}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>s(e,f.apiKey||``),children:c.testKey})]}),g?(0,X.jsx)(`p`,{className:w(`mt-1 text-xs`,g.error?`text-red-600 dark:text-red-400`:`text-emerald-700 dark:text-emerald-400`),children:g.error?`${c.testError}: ${g.error}`:`${c.testOk} (${g.type}): ${cr(g.resolved||``)}`}):null,(0,X.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:c.apiKeyHint})]}),(0,X.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,X.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:f.authHeader||!1,onChange:n=>t(t=>_r(t,e,{authHeader:n.target.checked}))}),c.authHeader]}),(0,X.jsxs)(`div`,{className:`border-t border-edge-subtle pt-3 dark:border-edge`,children:[(0,X.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-semibold text-fg`,children:c.modelsSection}),(0,X.jsxs)(E,{type:`button`,variant:`primary`,className:`px-2 py-1 text-xs`,onClick:()=>u(e,null,!0),children:[(0,X.jsx)(me,{className:`mr-1 size-3.5`}),c.addModel]})]}),(f.models||[]).length===0?(0,X.jsx)(`p`,{className:`text-xs text-fg-muted`,children:c.modelsEmpty}):(0,X.jsx)(`ul`,{className:`space-y-2`,children:(f.models||[]).map(n=>(0,X.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,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`div`,{className:`truncate text-sm font-medium text-fg`,children:n.id}),n.name&&n.name!==n.id?(0,X.jsx)(`div`,{className:`truncate text-xs text-fg-muted`,children:n.name}):null]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(0,X.jsx)(`button`,{type:`button`,className:`rounded-lg p-1.5 text-fg-muted hover:bg-surface-panel hover:text-fg`,onClick:()=>u(e,n,!1),"aria-label":c.editModel,children:(0,X.jsx)(We,{className:`size-4`})}),(0,X.jsx)(`button`,{type:`button`,className:`rounded-lg p-1.5 text-fg-muted hover:bg-surface-panel hover:text-red-600 dark:hover:text-red-400`,onClick:()=>{window.confirm(c.removeModelConfirm.replace(`{{id}}`,n.id))&&t(t=>{let r=t.providers[e];return r?_r(t,e,{models:(r.models||[]).filter(e=>e.id!==n.id)}):t})},"aria-label":c.removeModel,children:(0,X.jsx)(Ne,{className:`size-4`})})]})]},n.id))})]})]}):null]},e)})})}function Cr({ms:e,openAddProvider:t}){return(0,X.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,X.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,X.jsx)(Ee,{className:`size-7 text-accent`,strokeWidth:1.5})}),(0,X.jsx)(`h2`,{className:`mb-1 text-base font-semibold text-fg`,children:e.emptyTitle}),(0,X.jsx)(`p`,{className:`mb-6 max-w-md text-sm text-fg-muted`,children:e.emptyDesc}),(0,X.jsxs)(E,{type:`button`,className:`mb-6 bg-accent text-white hover:bg-accent/90`,onClick:()=>t(null),children:[(0,X.jsx)(me,{className:`mr-1 size-4`}),e.emptyCta]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap justify-center gap-2`,children:[(0,X.jsxs)(`button`,{type:`button`,className:w(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,H.transition,H.focusRingBase),onClick:()=>t(`ollama`),children:[(0,X.jsx)(P,{className:`size-3.5`,"aria-hidden":!0}),e.presetOllama]}),(0,X.jsxs)(`button`,{type:`button`,className:w(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,H.transition,H.focusRingBase),onClick:()=>t(`openrouter`),children:[(0,X.jsx)(Ke,{className:`size-3.5`,"aria-hidden":!0}),e.presetOpenRouter]}),(0,X.jsxs)(`button`,{type:`button`,className:w(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,H.transition,H.focusRingBase),onClick:()=>t(`lmstudio`),children:[(0,X.jsx)(Ee,{className:`size-3.5`,"aria-hidden":!0}),e.presetLmStudio]}),(0,X.jsxs)(`button`,{type:`button`,className:w(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,H.transition,H.focusRingBase),onClick:()=>t(`zhipuCn`),children:[(0,X.jsx)(P,{className:`size-3.5`,"aria-hidden":!0}),e.presetZhipuCn]}),(0,X.jsxs)(`button`,{type:`button`,className:w(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,H.transition,H.focusRingBase),onClick:()=>t(`zaiGeneral`),children:[(0,X.jsx)(Ke,{className:`size-3.5`,"aria-hidden":!0}),e.presetZaiGeneral]})]})]})}function wr(){let e=f(e=>e.language),t=ge(e),n=t.modelsSettings,r=xt(t.agentSettings),i=!!ze(e=>e.token),[a,o]=(0,Z.useState)({providers:{}}),[c,l]=(0,Z.useState)({providers:{}}),[u,d]=(0,Z.useState)(``),[p,m]=(0,Z.useState)(),[h,g]=(0,Z.useState)(!0),[_,v]=(0,Z.useState)(!1),[y,b]=(0,Z.useState)(!1),[x,S]=(0,Z.useState)(!1),[C,T]=(0,Z.useState)(null),[D,O]=(0,Z.useState)(!1),[k,A]=(0,Z.useState)(null),[j,M]=(0,Z.useState)(()=>new Set),[P,F]=(0,Z.useState)(!1),[I,L]=(0,Z.useState)(``),[R,z]=(0,Z.useState)(null),[ee,B]=(0,Z.useState)(()=>new Set),[V,H]=(0,Z.useState)(()=>new Map),[te,ne]=(0,Z.useState)(!1),[re,ie]=(0,Z.useState)(null),[U,W]=(0,Z.useState)(!1),[G,ae]=(0,Z.useState)(null),oe=(0,Z.useCallback)(async e=>{let t=!e?.skipFullPageLoading;t&&g(!0),T(null);try{let e=await $n(),t=Qn(e.config);o(t),l(structuredClone(t)),d(e.path),m(e.loadError),A(null),O(!1)}catch(e){T(e instanceof Error?e.message:n.loadError),o({providers:{}}),l({providers:{}})}finally{t&&g(!1)}},[n.loadError]);(0,Z.useEffect)(()=>{if(!i){g(!1);return}oe()},[i,oe]);let K=(0,Z.useMemo)(()=>JSON.stringify(a)!==JSON.stringify(c),[a,c]),se=(0,Z.useMemo)(()=>r.form?{form:r.form,update:r.update,a:t.agentSettings,chat:t.chat}:null,[r.form,r.update,t.agentSettings,t.chat]),ce=K||r.dirty,ue=(0,Z.useMemo)(()=>{let e=Object.keys(a.providers),t=0;for(let e of Object.values(a.providers))t+=e.models?.length??0;return{providers:e.length,models:t}},[a.providers]),q=e=>{M(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},de=e=>{B(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},fe=(0,Z.useCallback)(()=>{L(JSON.stringify(a,null,2)),z(null)},[a]);(0,Z.useEffect)(()=>{P&&fe()},[P,fe]);let J=()=>{try{o(Qn(JSON.parse(I))),z(null)}catch{z(n.jsonParseError)}},pe=async()=>{b(!0),T(null);try{A(await er(a))}catch(e){T(e instanceof Error?e.message:n.validateError)}finally{b(!1)}},Y=async()=>{if(_||r.saving)return;let e=K,i=r.dirty;if(!(!e&&!i)){T(null),O(!1);try{if(e){v(!0);try{await tr(a),l(structuredClone(a)),A(null)}finally{v(!1)}}if(i&&r.form&&!await r.save())throw Error(t.agentSettings.saveError);O(!0)}catch(e){T(e instanceof Error?e.message:n.saveError)}}},he=(0,Z.useCallback)(()=>{o(structuredClone(c)),A(null),O(!1),T(null),P&&(L(JSON.stringify(c,null,2)),z(null)),r.discard()},[c,P,r.discard]),_e=async()=>{S(!0),T(null);try{await nr(),await oe({skipFullPageLoading:!0})}catch(e){T(e instanceof Error?e.message:n.reloadError)}finally{S(!1)}},ve=async(e,t)=>{try{let n=await rr(t);H(t=>{let r=new Map(t);return r.set(e,n),r})}catch(t){H(n=>{let r=new Map(n);return r.set(e,{type:`error`,error:t instanceof Error?t.message:`Error`}),r})}},ye=(e=null)=>{ie(e),ne(!0)},be=(e,t)=>{o(n=>yr(n,e,t)),M(t=>new Set(t).add(e))},xe=e=>{window.confirm(n.removeProviderConfirm.replace(`{{id}}`,e))&&(o(t=>vr(t,e)),H(t=>{let n=new Map(t);return n.delete(e),n}))},Se=(e,t,n)=>{ae({providerId:e,model:t,isNew:n}),W(!0)},Ce=e=>{if(!G)return;let{providerId:t,isNew:n}=G;o(r=>{let i=r.providers[t];if(!i)return r;let a=i.models||[];return n?_r(r,t,{models:[...a,e]}):_r(r,t,{models:a.map(t=>t.id===e.id?e:t)})})};return i?(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-4 px-4 py-8`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.models}),(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.subtitle}),(0,X.jsxs)(`a`,{href:qe(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,X.jsx)(N,{className:`size-3.5`})]})]}),p?(0,X.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,X.jsx)(le,{className:`mt-0.5 size-4 shrink-0`}),(0,X.jsxs)(`span`,{children:[n.loadFileWarning,`: `,p]})]}):null,u?(0,X.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.filePath,`: `,(0,X.jsx)(`code`,{className:`rounded bg-surface-base px-1 py-0.5 font-mono text-fg-muted`,children:u})]}):null,(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsxs)(E,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:()=>ye(null),disabled:h,children:[(0,X.jsx)(me,{className:`mr-1 size-4`}),n.addProvider]}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:pe,disabled:h||y,children:y?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(s,{className:`mr-1 size-4 animate-spin`}),n.validating]}):n.validate}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:he,disabled:h||_||r.saving||!ce,children:n.discard}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:()=>void Y(),disabled:h||_||r.saving||!ce,children:_||r.saving?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(s,{className:`mr-1 size-4 animate-spin`}),n.saving]}):n.save}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[8.5rem] justify-center`,onClick:_e,disabled:h||x,children:x?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(s,{className:`mr-1 size-4 animate-spin`}),n.reloading]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Me,{className:`mr-1 size-4`}),n.reload]})}),(0,X.jsx)(E,{type:`button`,variant:`ghost`,className:`text-fg-muted`,onClick:()=>{F(e=>!e),z(null)},children:P?n.hideJson:n.showJson}),(0,X.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,X.jsx)(`span`,{className:`text-fg-muted`,children:n.statsProviders.replace(`{{count}}`,String(ue.providers))}),(0,X.jsx)(`span`,{className:`text-fg-subtle`,children:`|`}),(0,X.jsx)(`span`,{className:`text-fg-muted`,children:n.statsModels.replace(`{{count}}`,String(ue.models))})]})]}),ce?(0,X.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,D||r.saveOk?(0,X.jsx)(`p`,{className:`text-xs text-emerald-700 dark:text-emerald-400`,role:`status`,children:n.saved}):null,C?(0,X.jsxs)(`p`,{className:`flex items-center gap-1 text-sm text-red-600 dark:text-red-400`,role:`alert`,children:[(0,X.jsx)(le,{className:`size-4 shrink-0`}),C]}):null,r.error?(0,X.jsxs)(`p`,{className:`flex items-center gap-1 text-sm text-red-600 dark:text-red-400`,role:`alert`,children:[(0,X.jsx)(le,{className:`size-4 shrink-0`}),r.error]}):null,k&&k.errors.length>0?(0,X.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,X.jsx)(`p`,{className:`mb-1 text-sm font-medium text-amber-950 dark:text-amber-100`,children:k.valid?n.validationWarnings:n.validationErrors}),(0,X.jsx)(`ul`,{className:`list-inside list-disc space-y-0.5 text-xs text-amber-900 dark:text-amber-200`,children:k.errors.map((e,t)=>(0,X.jsxs)(`li`,{children:[e.path,`: `,e.message,` (`,e.severity,`)`]},`${e.path}-${t}`))})]}):null,h?(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,X.jsx)(s,{className:`size-4 animate-spin`}),n.loading]}):P?(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,X.jsx)(`textarea`,{className:w(pr(),`min-h-[320px] resize-y font-mono text-xs leading-relaxed`),value:I,onChange:e=>L(e.target.value),spellCheck:!1}),R?(0,X.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:R}):null,(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(E,{type:`button`,variant:`secondary`,onClick:fe,children:n.jsonReset}),(0,X.jsx)(E,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:J,children:n.jsonApply})]})]}):Object.keys(a.providers).length===0?(0,X.jsx)(Cr,{ms:n,openAddProvider:ye}):(0,X.jsx)(Sr,{config:a,setConfig:o,expanded:j,toggleExpand:q,showPw:ee,toggleShowPw:de,testResults:V,runTestKey:ve,ms:n,removeProv:xe,openModelDialog:Se,setTestResults:H}),se?(0,X.jsx)(`div`,{className:`mt-10 border-t border-edge-subtle pt-8 dark:border-edge`,children:(0,X.jsx)(lr,{...se})}):null,(0,X.jsx)(xr,{open:te,onOpenChange:ne,presetKey:re,onConfirm:be,m:n}),(0,X.jsx)(br,{open:U,onOpenChange:e=>{W(e),e||ae(null)},providerId:G?.providerId??null,model:G?.model??null,isNew:G?.isNew??!1,onSave:Ce,m:n})]}):(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.models}),(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}async function Tr(e){let t=await Y(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 Y(K(`/api/auth/oauth-async/${encodeURIComponent(e)}/status`));if(!t.ok)throw Error(`OAuth status: ${t.status}`);return(await t.json()).payload}async function Dr(e,t){let n=await Y(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 Or(e){let t=await Y(K(`/api/auth/oauth-async/${encodeURIComponent(e)}/cancel`),{method:`POST`});if(!t.ok)throw Error(`Cancel OAuth failed: ${t.status}`)}async function kr(e){let t=await Y(K(`/api/auth/oauth-async/${encodeURIComponent(e)}`),{method:`DELETE`});if(!t.ok)throw Error(`Cleanup session failed: ${t.status}`)}async function Ar(e){let t=await Y(K(`/api/auth/oauth/${encodeURIComponent(e)}`),{method:`DELETE`});if(!t.ok)throw Error(`Revoke OAuth failed: ${t.status}`)}function jr({providerId:e,language:t}){let n=Ge[e];if(!n)return null;let r=t===`zh`,i=r&&n.descriptionZh?n.descriptionZh:n.description;return i?(0,X.jsxs)(Xe,{children:[(0,X.jsx)(u,{asChild:!0,children:(0,X.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,X.jsx)(l,{className:`size-3.5`,"aria-hidden":!0})})}),(0,X.jsx)(F,{children:(0,X.jsxs)(T,{side:`right`,align:`start`,sideOffset:6,className:w(`w-64 rounded-xl border border-edge bg-surface-panel p-3 shadow-md`,xe,`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,X.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,X.jsx)(`p`,{className:`text-xs font-semibold text-fg`,children:e}),(0,X.jsx)(C,{asChild:!0,children:(0,X.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,X.jsx)(Je,{className:`size-3.5`,"aria-hidden":!0})})})]}),(0,X.jsx)(`p`,{className:`mt-1.5 text-xs leading-relaxed text-fg-muted`,children:i}),n.bestFor&&n.bestFor.length>0?(0,X.jsxs)(`div`,{className:`mt-2`,children:[(0,X.jsx)(`p`,{className:`text-[10px] font-medium uppercase tracking-wide text-fg-subtle`,children:r?`适合场景`:`Best for`}),(0,X.jsx)(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:n.bestFor.map(e=>(0,X.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,X.jsxs)(`div`,{className:`mt-2`,children:[(0,X.jsx)(`p`,{className:`text-[10px] font-medium uppercase tracking-wide text-fg-subtle`,children:r?`免费额度`:`Free tier`}),(0,X.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,X.jsxs)(`div`,{className:`mt-2.5 flex gap-3`,children:[n.pricingUrl?(0,X.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,X.jsx)(N,{className:`size-3`,"aria-hidden":!0})]}):null,n.docsUrl?(0,X.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,X.jsx)(N,{className:`size-3`,"aria-hidden":!0})]}):null]}):null,(0,X.jsx)(x,{className:`fill-edge`})]})})]}):null}var Mr=[`common`,`specialty`,`enterprise`,`oauth`,`extension`];function Nr(e){let t=new Map;for(let e of Mr)t.set(e,[]);for(let n of e){let e=n.category||`specialty`,r=t.get(e)??[];r.push(n),t.set(e,r)}return t}function Pr(e,t){return e.replace(/\{\{(\w+)\}\}/g,(e,n)=>String(t[n]??``))}function Fr(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 Ir({envVar:e,labels:t}){let[n,r]=(0,Z.useState)(!1),i=async()=>{try{await navigator.clipboard.writeText(e),r(!0),window.setTimeout(()=>r(!1),2e3)}catch{}};return(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`code`,{className:`rounded bg-surface-hover px-1.5 py-0.5 font-mono text-[11px] text-fg-muted`,children:e}),(0,X.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,X.jsx)(Le,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):(0,X.jsx)(Pe,{className:`size-3.5`,"aria-hidden":!0})})]})}function Lr({row:e,value:t,rowDirty:n,labels:r,language:i,onChange:a,onReload:c,justSaved:u,availableModels:d}){let[f,p]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)(!1),[g,v]=(0,Z.useState)(!1),[y,b]=(0,Z.useState)(null),[x,S]=(0,Z.useState)(!1),[C,T]=(0,Z.useState)(null),[D,O]=(0,Z.useState)(!1),k=Ce(t),j=k&&!m?``:t,M=e.configured&&!k&&!!t,[P,F]=(0,Z.useState)(!1),[I,L]=(0,Z.useState)(),[R,z]=(0,Z.useState)(),[ee,B]=(0,Z.useState)(),[V,te]=(0,Z.useState)(),[ie,U]=(0,Z.useState)(),[W,ae]=(0,Z.useState)(``),[oe,K]=(0,Z.useState)(!1),[se,ce]=(0,Z.useState)(null),[ue,q]=(0,Z.useState)(null),de=e.activeKeySource??`none`,J=(0,Z.useMemo)(()=>G(e.id,i),[e.id,i]);(0,Z.useEffect)(()=>()=>{I&&kr(I).catch(()=>{})},[I]),(0,Z.useEffect)(()=>{if(!I||!P)return;let e=window.setInterval(()=>{(async()=>{try{let t=await Er(I);B(t.message),te(t.authUrl),U(t.instructions),t.status===`waiting_auth`||t.status===`waiting_code`?z(t.status===`waiting_code`?`waiting_code`:`waiting`):t.status===`completed`?(window.clearInterval(e),F(!1),z(`success`),B(t.message),window.setTimeout(()=>c(),800)):(t.status===`failed`||t.status===`cancelled`)&&(window.clearInterval(e),F(!1),z(`error`),B(t.error||t.message||`OAuth failed`))}catch{}})()},1e3);return()=>window.clearInterval(e)},[I,P,c]);let pe=async()=>{F(!0),z(`waiting`),B(r.oauthStarting),L(void 0),te(void 0),U(void 0);try{L((await Tr(e.id)).sessionId)}catch(e){z(`error`),B(e instanceof Error?e.message:`OAuth failed`),F(!1)}},Y=async()=>{if(I){try{await Or(I)}catch{}L(void 0),F(!1),z(`idle`),B(void 0)}},me=async()=>{if(!(!I||!W.trim()))try{await Dr(I,W.trim()),ae(``),B(r.oauthProcessingCode)}catch(e){z(`error`),B(e instanceof Error?e.message:`Failed`)}},he=()=>{window.confirm(Pr(r.revokeConfirm,{name:e.name}))&&(b(null),Ar(e.id).then(()=>c()).catch(e=>b(e instanceof Error?e.message:r.revokeFailed)))},ge=async()=>{O(!1),S(!0),T(null);try{await ke(e.id),T(r.removeKeySuccess),a(e.id,``),window.setTimeout(()=>c(),600)}catch(e){T(e instanceof Error?e.message:r.removeKeyFailed)}finally{S(!1)}},_e=e.configured&&k&&de!==`env`&&de!==`extension`&&de!==`models_json`,ve=async()=>{if(!(!t||k))try{await navigator.clipboard.writeText(t),v(!0),window.setTimeout(()=>v(!1),2e3)}catch{}},ye=async()=>{let e=t.trim();if(!(!e||Ce(e))){K(!0),ce(null),q(null);try{let t=await Re(e);if(t.error){q(!1),ce(`${r.testFailed} ${t.error}`);return}q(!0),t.type===`env`?ce(r.testOkEnv):t.type===`command`?ce(r.testOkCommand):ce(r.testOkLiteral)}catch(e){q(!1),ce(e instanceof Error?e.message:r.testFailed)}finally{K(!1)}}},be=n?r.metaWillSave:e.configured?k?`${r.metaMasked} · ${r.runtimeLabelPrefix} ${Fr(r,de)}`:`${r.runtimeLabelPrefix} ${Fr(r,de)}`:r.metaNotConfigured,xe=`provider-details-${e.id}`;return(0,X.jsxs)(`div`,{className:`bg-surface-panel`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-3 sm:px-4`,children:[(0,X.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,X.jsx)(Le,{className:`size-4 text-emerald-600 dark:text-emerald-400`}):(0,X.jsx)(Ye,{className:`size-4 text-fg-subtle`,strokeWidth:1.75})}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-semibold text-fg`,children:e.name}),(0,X.jsx)(jr,{providerId:e.id,language:i}),(0,X.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,X.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,X.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:be})]}),(0,X.jsx)(E,{type:`button`,variant:`ghost`,className:`h-9 w-9 shrink-0 p-0`,"aria-expanded":f,"aria-controls":xe,"aria-label":r.expandRowDetails,onClick:()=>p(e=>!e),children:(0,X.jsx)(fe,{className:w(`size-4 transition-transform`,f&&`rotate-180`),"aria-hidden":!0})})]}),f?(0,X.jsxs)(`div`,{id:xe,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,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,X.jsxs)(`div`,{className:`relative flex flex-col gap-2 sm:flex-row sm:gap-2`,children:[(0,X.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,X.jsx)(`input`,{type:m||!k?`text`:`password`,className:w(`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`,o,`dark:border-edge`),value:j,placeholder:k?r.placeholderOverride:e.configured?r.placeholderKeep:r.placeholderKey,disabled:P,onChange:t=>a(e.id,t.target.value),autoComplete:`off`,spellCheck:!1}),(0,X.jsxs)(`div`,{className:`absolute right-1 top-1/2 flex -translate-y-1/2 gap-0.5`,children:[t&&!k?(0,X.jsx)(`button`,{type:`button`,className:w(`rounded p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,H.transition,H.press,H.focusRingPanel),title:g?r.copied:r.copy,"aria-label":g?r.copied:r.copy,onClick:()=>void ve(),children:g?(0,X.jsx)(Le,{className:`size-4`}):(0,X.jsx)(Pe,{className:`size-4`})}):null,(0,X.jsx)(`button`,{type:`button`,className:w(`rounded p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg disabled:opacity-40`,H.transition,H.press,H.focusRingPanel),title:m?r.hide:r.show,"aria-label":m?r.hide:r.show,disabled:k,onClick:()=>h(e=>!e),children:m?(0,X.jsx)(re,{className:`size-4`}):(0,X.jsx)(ne,{className:`size-4`})})]})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2 sm:shrink-0`,children:[(0,X.jsxs)(E,{type:`button`,variant:`secondary`,className:`gap-1`,disabled:P||oe||!t.trim()||Ce(t),onClick:()=>void ye(),children:[oe?(0,X.jsx)(s,{className:`size-4 animate-spin`,"aria-hidden":!0}):null,oe?r.testingKey:r.testKey]}),e.supportsOAuth?M?(0,X.jsxs)(E,{type:`button`,variant:`secondary`,className:`gap-1 text-red-600 dark:text-red-400`,onClick:he,children:[(0,X.jsx)(_,{className:`size-4`,"aria-hidden":!0}),r.revoke]}):(0,X.jsxs)(E,{type:`button`,variant:`secondary`,className:`gap-1`,disabled:P,onClick:()=>void pe(),children:[P?(0,X.jsx)(s,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,X.jsx)(A,{className:`size-4`,"aria-hidden":!0}),r.oauth]}):null,_e?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(E,{type:`button`,variant:`secondary`,className:`gap-1 text-red-600 dark:text-red-400`,disabled:x,onClick:()=>O(!0),children:[x?(0,X.jsx)(s,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,X.jsx)(Ne,{className:`size-4`,"aria-hidden":!0}),r.removeKey]}),(0,X.jsx)(Ie,{open:D,title:r.removeKey,description:Pr(r.removeKeyConfirm,{name:e.name}),confirmLabel:r.removeKey,cancelLabel:r.cancelOAuth,destructive:!0,onConfirm:()=>void ge(),onCancel:()=>O(!1)})]}):null]})]}),se?(0,X.jsx)(`p`,{className:w(`text-xs`,ue===!1?`text-red-600 dark:text-red-400`:`text-fg-muted`),role:`status`,children:se}):null,J.length>0?(0,X.jsx)(`div`,{className:`flex flex-col gap-1`,children:J.map(e=>(0,X.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:[He(e.kind,r),(0,X.jsx)(N,{className:`size-3`,"aria-hidden":!0})]},`${e.kind}-${e.href}`))}):null]}),ee?(0,X.jsxs)(`div`,{className:w(`flex gap-2 rounded-md px-3 py-2 text-xs`,R===`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:[R===`error`?(0,X.jsx)(le,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}):R===`success`?(0,X.jsx)(Le,{className:`mt-0.5 size-4 shrink-0 text-emerald-600`,"aria-hidden":!0}):(0,X.jsx)(l,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,X.jsx)(`span`,{children:ee})]}):null,y?(0,X.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,X.jsx)(le,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,X.jsx)(`span`,{children:y})]}):null,C?(0,X.jsxs)(`div`,{className:w(`flex gap-2 rounded-md px-3 py-2 text-xs`,C===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:[C===r.removeKeySuccess?(0,X.jsx)(Le,{className:`mt-0.5 size-4 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):(0,X.jsx)(le,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,X.jsx)(`span`,{children:C})]}):null,(R===`waiting`||R===`waiting_code`)&&(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[V?(0,X.jsxs)(`a`,{href:V,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,X.jsx)(N,{className:`size-4`,"aria-hidden":!0}),r.openAuthPage]}):null,(0,X.jsxs)(E,{type:`button`,variant:`secondary`,className:`gap-1`,onClick:()=>void Y(),children:[(0,X.jsx)(Je,{className:`size-4`,"aria-hidden":!0}),r.cancelOAuth]})]}),ie?(0,X.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,X.jsx)(l,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,X.jsx)(`span`,{children:ie})]}):null,R===`waiting_code`?(0,X.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,X.jsx)(`input`,{type:`text`,className:w(`min-w-0 flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,o,`dark:border-edge`),value:W,placeholder:r.pasteRedirectUrl,onChange:e=>ae(e.target.value),onKeyDown:e=>e.key===`Enter`&&void me()}),(0,X.jsx)(E,{type:`button`,variant:`primary`,className:`shrink-0`,onClick:()=>void me(),children:r.submitCode})]}):null,k?(0,X.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,X.jsx)(l,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,X.jsx)(`span`,{children:de===`env`?r.envHint:r.maskedStoredHint})]}):null,e.supportsOAuth&&!k&&!M?(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:r.oauthHint}):null,u?(0,X.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,X.jsx)(Le,{className:`mt-0.5 size-3.5 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}),(0,X.jsx)(`span`,{children:(()=>{let t=d.filter(t=>t.provider===e.id);if(t.length===0)return r.savedNoModels;let n=t.slice(0,3).map(e=>e.name||e.id).join(`, `),i=t.length>3?`… (+${t.length-3})`:``;return`${t.length} ${r.savedModelsAvailable}: ${n}${i}`})()})]}):null,(Ge[e.id]?.envVars??[]).length>0?(0,X.jsxs)(`details`,{children:[(0,X.jsx)(`summary`,{className:`cursor-pointer select-none list-none text-xs text-fg-subtle hover:text-fg-muted`,children:r.envVarAlt}),(0,X.jsx)(`div`,{className:`mt-1.5 flex flex-col gap-1`,children:(Ge[e.id]?.envVars??[]).map(e=>(0,X.jsx)(Ir,{envVar:e,labels:r},e))})]}):null]}):null]})}function Rr(){let e=f(e=>e.language),t=ge(e),n=t.providersSettings,i=!!ze(e=>e.token),[a,s]=(0,Z.useState)({}),[c,l]=(0,Z.useState)({}),[u,p]=(0,Z.useState)(!1),[h,g]=(0,Z.useState)(null),[_,y]=(0,Z.useState)(null),[b,x]=(0,Z.useState)(()=>new Set([`common`])),[S,C]=(0,Z.useState)(``),[T,D]=(0,Z.useState)(!1),[O,k]=(0,Z.useState)(()=>new Set),A=(0,Z.useRef)(``),j=K(`/api/providers/meta`),M=(0,Z.useCallback)(async e=>(await J(e)).payload?.providers??[],[]),{data:N,error:P,isLoading:F,mutate:L}=m(i),{data:R,error:z,isLoading:ee,mutate:B}=r(i?j:null,M,{revalidateOnFocus:!1}),{data:V,mutate:H}=r(i?I:null,()=>d(),{revalidateOnFocus:!1}),te=(0,Z.useMemo)(()=>!R||N===void 0?null:pe(R,ie(N.payload?.config),V??[]),[R,N,V]),ne=P instanceof Error?P.message:P?String(P):z instanceof Error?z.message:z?String(z):null,re=!!(i&&te===null&&(F||ee)&&!ne),U=(0,Z.useMemo)(()=>JSON.stringify(a)!==JSON.stringify(c),[a,c]);(0,Z.useEffect)(()=>{if(!U)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[U]),(0,Z.useEffect)(()=>{if(!(!i||te===null)&&!U){let e={};for(let t of te)e[t.id]=t.apiKey;s(e),l({...e})}},[i,te,U]);let W=te??[],G=(0,Z.useMemo)(()=>{let e=W,t=S.trim().toLowerCase();return t&&(e=e.filter(e=>{let n=Ge[e.id]?.aliases??[];return e.id.toLowerCase().includes(t)||e.name.toLowerCase().includes(t)||n.some(e=>e.toLowerCase().includes(t))})),T&&(e=e.filter(e=>!e.configured)),e},[W,S,T]),ae=(0,Z.useMemo)(()=>Nr(G),[G]);(0,Z.useEffect)(()=>{let e=A.current;if(A.current=S,S.trim()){let e=new Set;for(let t of Mr)(ae.get(t)??[]).length>0&&e.add(t);x(e);return}e.trim()&&x(new Set([`common`]))},[S,ae]);let se=(0,Z.useCallback)(async()=>{if(u)return;let e={};for(let t of Object.keys(a)){let n=a[t]?.trim()??``;!n||Ce(n)||(e[t]=n)}if(Object.keys(e).length===0){l({...a}),y(`noChanges`),window.setTimeout(()=>y(null),2500);return}p(!0),g(null),y(null);try{await de(e),k(new Set(Object.keys(e)));let t=await H(d(!0))??V??[],[n,r]=await Promise.all([L(),B()]),i=Array.isArray(r)?r:R??[],a=n??N;if(a?.payload){let e=pe(i,ie(a.payload.config),t),n={};for(let t of e)n[t.id]=t.apiKey;s(n),l({...n})}y(`saved`),window.setTimeout(()=>y(null),2500)}catch(e){g(e instanceof Error?e.message:n.saveError)}finally{p(!1)}},[N,a,R,V,L,B,H,n.saveError,u]),ce=(0,Z.useCallback)(()=>{s({...c}),g(null),y(null),k(new Set)},[c]),le=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},ue=(0,Z.useCallback)(()=>{L(),B()},[L,B]),q=!!(S.trim()||T);return i?re?(0,X.jsxs)(`div`,{className:`mx-auto w-full max-w-app-main px-4 py-8`,children:[(0,X.jsx)(`div`,{className:`h-8 w-48 animate-pulse rounded bg-surface-hover`}),(0,X.jsx)(`div`,{className:`mt-6 h-32 animate-pulse rounded-xl bg-surface-hover`}),(0,X.jsx)(`p`,{className:`mt-4 text-sm text-fg-muted`,children:t.logs.loading})]}):W.length===0?(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-10`,children:[(0,X.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-base px-4 py-3`,children:[(0,X.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:n.loadError}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:h??ne??n.empty})]}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,onClick:()=>{L(),B()},children:t.logs.refresh})]}):(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,X.jsxs)(`header`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.providers}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,X.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:n.rotateHint})]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[_===`saved`?(0,X.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,_===`noChanges`?(0,X.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.noChangesSaved}):null,(0,X.jsx)(E,{type:`button`,variant:`secondary`,disabled:!U||u,onClick:ce,children:n.discard}),(0,X.jsx)(E,{type:`button`,variant:`primary`,disabled:!U||u,onClick:()=>void se(),children:u?n.saving:n.save})]})]}),U?(0,X.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,(0,X.jsxs)(`p`,{className:`text-sm leading-relaxed text-fg-muted`,children:[n.intro,` `,(0,X.jsx)(`a`,{href:qe(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,X.jsx)(v,{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,X.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-center`,children:[(0,X.jsxs)(`div`,{className:`relative min-w-0 flex-1 sm:max-w-md`,children:[(0,X.jsx)(oe,{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,X.jsx)(`input`,{type:`search`,value:S,onChange:e=>C(e.target.value),placeholder:n.searchPlaceholder,autoComplete:`off`,className:w(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-10 pr-3 text-sm text-fg placeholder:text-fg-subtle`,o,`dark:border-edge`),"aria-label":n.searchPlaceholder})]}),(0,X.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg-muted`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:T,onChange:e=>D(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]}),q?(0,X.jsx)(E,{type:`button`,variant:`ghost`,className:`h-9 w-fit self-start text-fg-muted`,onClick:()=>{C(``),D(!1)},children:n.clearFilters}):null]}),h?(0,X.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:h}):null,G.length===0?(0,X.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,X.jsx)(`p`,{children:n.noMatches}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,className:`mt-4`,onClick:()=>{C(``),D(!1)},children:n.clearFilters})]}):(0,X.jsx)(`div`,{className:`flex flex-col gap-3`,children:Mr.map(t=>{let r=ae.get(t)??[];if(r.length===0)return null;let i=b.has(t),o=r.filter(e=>e.configured).length,l=`providers-cat-${t}`;return(0,X.jsxs)(`section`,{className:`overflow-hidden rounded-2xl bg-surface-base`,children:[(0,X.jsxs)(`button`,{type:`button`,id:`${l}-trigger`,"aria-expanded":i,"aria-controls":l,className:`flex w-full items-center justify-between gap-2 border-b border-edge-subtle px-4 py-3 text-left transition-colors hover:bg-surface-hover/60 dark:border-edge-subtle`,onClick:()=>le(t),children:[(0,X.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 text-sm font-semibold text-fg`,children:[(0,X.jsx)(`span`,{className:`truncate`,children:n.categories[t]}),(0,X.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,X.jsxs)(`span`,{className:`flex shrink-0 items-center gap-2`,children:[o>0?(0,X.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-fg-subtle`,children:[(0,X.jsx)(Le,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}),Pr(n.configuredCount,{count:String(o)})]}):null,(0,X.jsx)(fe,{className:w(`size-4 text-fg-subtle transition-transform`,i&&`rotate-180`),"aria-hidden":!0})]})]}),i?(0,X.jsx)(`div`,{id:l,role:`region`,"aria-labelledby":`${l}-trigger`,className:`divide-y divide-edge-subtle`,children:r.map(t=>(0,X.jsx)(`div`,{id:`provider-row-${t.id}`,children:(0,X.jsx)(Lr,{row:t,value:a[t.id]??``,rowDirty:(a[t.id]??``)!==(c[t.id]??``),labels:n,language:e,onChange:(e,t)=>s(n=>({...n,[e]:t})),onReload:ue,justSaved:O.has(t.id),availableModels:V??[]})},t.id))}):null]},t)})})]}):(0,X.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-10`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-3 rounded-2xl bg-surface-base p-6`,children:[(0,X.jsx)(Ye,{className:`mt-0.5 size-5 shrink-0 text-fg-subtle`,strokeWidth:1.75}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h1`,{className:`text-base font-semibold text-fg`,children:t.settingsSections.providers}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.needToken})]})]})})}var zr=[{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 Br(e,t){let n=ge(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 Vr(){let e=f(e=>e.language),t=ge(e).systemSettings,[n,r]=(0,Z.useState)(null),[i,a]=(0,Z.useState)(null),[o,s]=(0,Z.useState)(null),c=typeof window<`u`?window.electronAPI?.system:void 0,l=(0,Z.useCallback)(async()=>{if(c){s(null);try{r(await c.getBehavior()),a(await c.getPermissions())}catch(e){s(e instanceof Error?e.message:String(e))}}},[c]);if((0,Z.useEffect)(()=>{b()&&c&&l()},[c,l]),!b()||!c)return(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.title}),(0,X.jsxs)(`div`,{className:Tt(),children:[(0,X.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:t.desktopOnlyTitle}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:t.desktopOnlyBody})]})]});let u=async e=>{try{let{behavior:t}=await c.setBehavior(e);r(t)}catch(e){s(e instanceof Error?e.message:String(e))}},d=async e=>{try{(await c.openPrivacy(e)).ok||s(`open_privacy failed`)}catch(e){s(e instanceof Error?e.message:String(e))}},p=n?n.platform===`win32`?t.permissionsHintWin:n.platform===`linux`?t.permissionsHintLinux:n.platform===`darwin`?t.permissionsHintDarwin:t.permissionsHint:t.permissionsHint;return(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[(0,X.jsx)(`div`,{children:(0,X.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.title})}),o?(0,X.jsx)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:o}):null,(0,X.jsxs)(Et,{children:[(0,X.jsxs)(`div`,{className:`mb-4 flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,X.jsx)(Fe,{className:`size-4 text-accent`,strokeWidth:1.75}),t.behaviorGroup]}),(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.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,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.openAtLogin}),(0,X.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.openAtLoginDesc})]}),(0,X.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!n,checked:!!n?.openAtLogin,onChange:e=>{u({openAtLogin:e.target.checked})}})]}),(0,X.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,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.keepAwake}),(0,X.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.keepAwakeDesc})]}),(0,X.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!n,checked:!!n?.keepAwakePreferred,onChange:e=>{u({keepAwakePreferred:e.target.checked})}})]}),(0,X.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,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.notifyDesktop}),(0,X.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.notifyDesktopDesc})]}),(0,X.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!n,checked:!!n?.notifyEnabled,onChange:e=>{u({notifyEnabled:e.target.checked})}})]}),(0,X.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,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.notifySound}),(0,X.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.notifySoundDesc})]}),(0,X.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!n,checked:!!n?.notifySoundEnabled,onChange:e=>{u({notifySoundEnabled:e.target.checked})}})]})]})]}),n&&i?(0,X.jsxs)(`section`,{className:Tt(),children:[(0,X.jsxs)(`div`,{className:`mb-4 flex flex-col gap-1 sm:flex-row sm:items-center sm:justify-between`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:t.permissionsTitle}),(0,X.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:p})]}),(0,X.jsx)(`button`,{type:`button`,className:`mt-2 inline-flex max-w-full items-center justify-center rounded-lg border border-edge bg-surface-panel px-3 py-1.5 text-sm font-medium text-fg transition-colors hover:bg-surface-hover sm:mt-0`,onClick:()=>void l(),children:t.refresh})]}),(0,X.jsx)(`ul`,{className:`space-y-3`,children:zr.map(({key:r,pane:o})=>{let l=Br(e,i[r]),u=t.perm[r];return u?(0,X.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,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:u.title}),(0,X.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:u.desc}),(0,X.jsx)(`p`,{className:`mt-1 text-xs font-medium ${l.className}`,children:l.label})]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[r===`microphone`&&n?.platform===`darwin`?(0,X.jsx)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover`,onClick:()=>{(async()=>{try{await c.requestMicrophone(),a(await c.getPermissions())}catch(e){s(e instanceof Error?e.message:String(e))}})()},children:e===`zh`?`请求访问`:`Request`}):null,(0,X.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover`,onClick:()=>void d(o),children:[t.openSettings,(0,X.jsx)(N,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0})]})]})]},r):null})})]}):null]})}function Hr(){return{enabled:!1,provider:`alibaba`,alibaba:{model:`paraformer-v2`},openai:{model:`whisper-1`},fallback:{enabled:!0,order:[`alibaba`,`openai`]}}}function Ur(){return{enabled:!1,provider:`openai`,trigger:`always`,maxTextLength:512,timeoutMs:6e4,alibaba:{model:`qwen-tts`,voice:`Cherry`},openai:{model:`tts-1`,voice:`alloy`},edge:{voice:`en-US-MichelleNeural`},minimax:{model:`speech-2.8-hd`,voice:`male-qn-qingse`},"tts-local-cli":{command:``,outputFormat:`wav`}}}function Wr(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Gr(e){let t=Hr();if(!Wr(e))return t;let n=e.provider===`openai`?`openai`:`alibaba`,r=Wr(e.alibaba)?{...t.alibaba,...e.alibaba}:t.alibaba,i=Wr(e.openai)?{...t.openai,...e.openai}:t.openai,a=t.fallback??{enabled:!0,order:[`alibaba`,`openai`]};if(Wr(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 Kr(e){return typeof e==`string`&&e.trim().length>0?e.trim():`openai`}function qr(e){let t=Ur();if(!Wr(e))return t;let n=Kr(e.provider),r=e.trigger===`off`||e.trigger===`always`||e.trigger===`inbound`||e.trigger===`tagged`?e.trigger:`always`,i=e[`tts-local-cli`];return{enabled:!!e.enabled,provider:n,trigger:r,maxTextLength:typeof e.maxTextLength==`number`&&Number.isFinite(e.maxTextLength)?e.maxTextLength:t.maxTextLength,timeoutMs:typeof e.timeoutMs==`number`&&Number.isFinite(e.timeoutMs)?e.timeoutMs:t.timeoutMs,alibaba:Wr(e.alibaba)?{...t.alibaba,...e.alibaba}:t.alibaba,openai:Wr(e.openai)?{...t.openai,...e.openai}:t.openai,edge:Wr(e.edge)?{...t.edge,...e.edge}:t.edge,minimax:Wr(e.minimax)?{...t.minimax,...e.minimax}:t.minimax,"tts-local-cli":Wr(i)?{...t[`tts-local-cli`],...i}:t[`tts-local-cli`]}}function Jr(e){let t=Wr(e)?e:{};return{stt:Gr(t.stt),tts:qr(t.tts)}}async function Yr(e){await J(K(`/api/config`),{method:`PATCH`,body:JSON.stringify({stt:e.stt,tts:e.tts})}),R()}async function Xr(){let e=await J(K(`/api/voice/models`));if(!e.payload?.models)throw Error(`Missing voice models payload`);return e.payload.models}function Zr(){return w(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,o,`dark:border-edge`)}function Qr(){return w(ve,g)}var $r=[{id:`paraformer-v2`,name:`Paraformer v2`},{id:`paraformer-v1`,name:`Paraformer v1`}],ei=[{id:`whisper-1`,name:`Whisper-1`}],ti=[{id:`tts-1`,name:`TTS-1`},{id:`tts-1-hd`,name:`TTS-1 HD`}],ni=[{id:`alloy`,name:`Alloy`},{id:`echo`,name:`Echo`}],ri=[{id:`qwen-tts`,name:`Qwen TTS`},{id:`qwen3-tts-flash`,name:`Qwen3 TTS Flash`}],ii=[{id:`Cherry`,name:`Cherry`},{id:`longxiaochun`,name:`Long Xiao Chun`}],ai=[{id:`en-US-MichelleNeural`,name:`Michelle (US English)`},{id:`zh-CN-XiaoxiaoNeural`,name:`Xiaoxiao (Chinese)`}],oi=[{id:`speech-2.8-hd`,name:`Speech 2.8 HD (Recommended)`},{id:`speech-2.8-turbo`,name:`Speech 2.8 Turbo (Fast)`}],si=[{id:`male-qn-qingse`,name:`Male Qingse (青涩男声)`},{id:`female-shaonv`,name:`Female Shaonv (少女音)`}];function ci(){let e=f(e=>e.language),t=ge(e),n=t.voiceSettings,i=!!ze(e=>e.token),[a,o]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(null),[p,h]=(0,Z.useState)(!1),[g,_]=(0,Z.useState)(null),[v,y]=(0,Z.useState)(!1),{data:b,error:x,isLoading:S,mutate:C}=m(i),{data:w,error:T,isLoading:D,mutate:O}=r(i?K(`/api/voice/models`):null,Xr,{revalidateOnFocus:!1}),k=(0,Z.useMemo)(()=>b?.payload?.config===void 0?null:Jr(b.payload.config),[b]),A=(0,Z.useMemo)(()=>!a||!c?!1:JSON.stringify(a)!==JSON.stringify(c),[a,c]);(0,Z.useEffect)(()=>{if(!i){o(null),l(null),d(null);return}k===null||w===void 0||A||(o(structuredClone(k)),l(structuredClone(k)),d(w),y(!1))},[i,k,w,A]);let j=!!(i&&(k===null||w===void 0)&&(S||D)),M=x instanceof Error?x.message:x?String(x):T instanceof Error?T.message:T?String(T):null,P=(0,Z.useCallback)(e=>{o(t=>t?{...t,stt:{...t.stt,...e}}:null)},[]),F=(0,Z.useCallback)(e=>{o(t=>t?{...t,stt:{...t.stt,alibaba:{...t.stt.alibaba,...e}}}:null)},[]),I=(0,Z.useCallback)(e=>{o(t=>t?{...t,stt:{...t.stt,openai:{...t.stt.openai,...e}}}:null)},[]),L=(0,Z.useCallback)(e=>{o(t=>{if(!t)return null;let n=t.stt.fallback??{enabled:!0,order:[`alibaba`,`openai`]};return{...t,stt:{...t.stt,fallback:{...n,...e}}}})},[]),R=(0,Z.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,...e}}:null)},[]),z=(0,Z.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,alibaba:{...t.tts.alibaba,...e}}}:null)},[]),ee=(0,Z.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,openai:{...t.tts.openai,...e}}}:null)},[]),B=(0,Z.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,edge:{...t.tts.edge,...e}}}:null)},[]),V=(0,Z.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,minimax:{...t.tts.minimax,...e}}}:null)},[]),H=(0,Z.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,"tts-local-cli":{...t.tts[`tts-local-cli`],...e}}}:null)},[]),te=(0,Z.useCallback)(async()=>{if(!(!a||p)){h(!0),_(null),y(!1);try{await Yr(a);let e=structuredClone(a);l(e),o(e),y(!0),window.setTimeout(()=>y(!1),2500)}catch(e){_(e instanceof Error?e.message:n.saveError)}finally{h(!1)}}},[a,p,n.saveError]),ne=(0,Z.useCallback)(()=>{c&&(o(structuredClone(c)),_(null),y(!1))},[c]);if(!i)return(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.voice}),(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]});if(j)return(0,X.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,X.jsx)(s,{className:`size-4 animate-spin`}),n.loading]})});if(!a||u===null)return(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:g??M??n.loadError}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,onClick:()=>{C(),O()},children:n.retry})]});let re=a.stt,ie=a.tts;return(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,X.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.voice}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,X.jsxs)(`a`,{href:qe(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,X.jsx)(N,{className:`size-3.5`})]})]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[v?(0,X.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,X.jsx)(E,{type:`button`,variant:`secondary`,disabled:!A||p,onClick:ne,children:n.discard}),(0,X.jsx)(E,{type:`button`,variant:`primary`,disabled:!A||p,onClick:()=>void te(),children:p?n.saving:n.save})]})]}),A?(0,X.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,g?(0,X.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:g}):null,(0,X.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,X.jsx)(li,{v:n,stt:re,models:u,updateStt:P,updateSttAlibaba:F,updateSttOpenai:I,updateSttFallback:L}),(0,X.jsx)(ui,{v:n,tts:ie,models:u,updateTts:R,updateTtsAlibaba:z,updateTtsOpenai:ee,updateTtsEdge:B,updateTtsMinimax:V,updateTtsLocalCli:H})]}),(0,X.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,X.jsxs)(`p`,{className:`text-sm text-fg`,children:[(0,X.jsx)(`strong`,{className:`text-accent`,children:n.notes.title}),` `,n.notes.duration]}),(0,X.jsx)(`p`,{className:`mt-2 text-xs text-fg-muted`,children:n.notes.envVars})]})]})}function li({v:e,stt:t,models:n,updateStt:r,updateSttAlibaba:i,updateSttOpenai:a,updateSttFallback:o}){let s=n?.stt?.alibaba?.length?n.stt.alibaba:$r,c=n?.stt?.openai?.length?n.stt.openai:ei;return(0,X.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[(0,X.jsxs)(`div`,{className:`mb-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,X.jsx)(Ve,{className:`size-4 text-accent`,strokeWidth:1.75}),e.stt.title]}),(0,X.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:e.stt.description})]}),(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.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,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.stt.enable}),(0,X.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.stt.enableDesc})]}),(0,X.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:t.enabled,onChange:e=>r({enabled:e.target.checked})})]}),t.enabled?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.stt.provider}),(0,X.jsxs)(`select`,{className:Qr(),value:t.provider,onChange:e=>r({provider:e.target.value}),children:[(0,X.jsx)(`option`,{value:`alibaba`,children:e.stt.alibaba}),(0,X.jsx)(`option`,{value:`openai`,children:e.stt.openai})]})]})}),t.provider===`alibaba`?(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.stt.apiKey}),(0,X.jsx)(`input`,{className:w(Zr(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.alibaba?.apiKey??``,onChange:e=>i({apiKey:e.target.value}),placeholder:`sk-...`}),(0,X.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (DASHSCOPE_API_KEY)`]})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.stt.model}),(0,X.jsx)(`select`,{className:Qr(),value:t.alibaba?.model??``,onChange:e=>i({model:e.target.value}),children:s.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}):(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.stt.apiKey}),(0,X.jsx)(`input`,{className:w(Zr(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.openai?.apiKey??``,onChange:e=>a({apiKey:e.target.value}),placeholder:`sk-...`}),(0,X.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (OPENAI_API_KEY)`]})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.stt.model}),(0,X.jsx)(`select`,{className:Qr(),value:t.openai?.model??``,onChange:e=>a({model:e.target.value}),children:c.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}),(0,X.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,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.stt.fallback}),(0,X.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.stt.fallbackDesc})]}),(0,X.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:t.fallback?.enabled??!0,onChange:e=>o({enabled:e.target.checked})})]})]}):null]})]})}function ui({v:e,tts:t,models:n,updateTts:r,updateTtsAlibaba:i,updateTtsOpenai:a,updateTtsEdge:o,updateTtsMinimax:s,updateTtsLocalCli: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:ti,d=n?.ttsVoices?.openai?.length?n.ttsVoices.openai:ni,f=n?.tts?.alibaba?.length?n.tts.alibaba:ri,p=n?.ttsVoices?.alibaba?.length?n.ttsVoices.alibaba:ii,m=n?.ttsVoices?.edge?.length?n.ttsVoices.edge:ai,h=n?.tts?.minimax?.length?n.tts.minimax:oi,g=n?.ttsVoices?.minimax?.length?n.ttsVoices.minimax:si;return(0,X.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[(0,X.jsxs)(`div`,{className:`mb-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,X.jsx)(B,{className:`size-4 text-accent`,strokeWidth:1.75}),e.tts.title]}),(0,X.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:e.tts.description})]}),(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.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,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.tts.enable}),(0,X.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.tts.enableDesc})]}),(0,X.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:t.enabled,onChange:e=>r({enabled:e.target.checked})})]}),t.enabled?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.tts.trigger}),(0,X.jsxs)(`select`,{className:Qr(),value:t.trigger,onChange:e=>r({trigger:e.target.value}),children:[(0,X.jsx)(`option`,{value:`off`,children:e.tts.triggerOff}),(0,X.jsx)(`option`,{value:`always`,children:e.tts.triggerAlways}),(0,X.jsx)(`option`,{value:`inbound`,children:e.tts.triggerInbound}),(0,X.jsx)(`option`,{value:`tagged`,children:e.tts.triggerTagged})]}),(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:l(t.trigger)})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.tts.provider}),(0,X.jsxs)(`select`,{className:Qr(),value:t.provider,onChange:e=>r({provider:e.target.value}),children:[(0,X.jsx)(`option`,{value:`openai`,children:e.tts.providerOpenai}),(0,X.jsx)(`option`,{value:`alibaba`,children:e.stt.alibaba}),(0,X.jsx)(`option`,{value:`minimax`,children:`MiniMax`}),(0,X.jsx)(`option`,{value:`edge`,children:e.tts.providerEdge}),(0,X.jsx)(`option`,{value:`tts-local-cli`,children:e.tts.providerLocalCli})]})]})]}),t.provider===`openai`?(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,X.jsx)($,{children:e.stt.apiKey}),(0,X.jsx)(`input`,{className:w(Zr(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.openai?.apiKey??``,onChange:e=>a({apiKey:e.target.value}),placeholder:`sk-...`}),(0,X.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (OPENAI_API_KEY)`]})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.stt.model}),(0,X.jsx)(`select`,{className:Qr(),value:t.openai?.model??``,onChange:e=>a({model:e.target.value}),children:u.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.tts.voice}),(0,X.jsx)(`select`,{className:Qr(),value:t.openai?.voice??``,onChange:e=>a({voice:e.target.value}),children:d.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}):null,t.provider===`alibaba`?(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,X.jsx)($,{children:e.stt.apiKey}),(0,X.jsx)(`input`,{className:w(Zr(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.alibaba?.apiKey??``,onChange:e=>i({apiKey:e.target.value}),placeholder:`sk-...`}),(0,X.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (DASHSCOPE_API_KEY)`]})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.stt.model}),(0,X.jsx)(`select`,{className:Qr(),value:t.alibaba?.model??``,onChange:e=>i({model:e.target.value}),children:f.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.tts.voice}),(0,X.jsx)(`select`,{className:Qr(),value:t.alibaba?.voice??``,onChange:e=>i({voice:e.target.value}),children:p.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}):null,t.provider===`minimax`?(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,X.jsx)($,{children:e.stt.apiKey}),(0,X.jsx)(`input`,{className:w(Zr(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.minimax?.apiKey??``,onChange:e=>s({apiKey:e.target.value}),placeholder:`eyJ...`}),(0,X.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (MINIMAX_API_KEY)`]})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.stt.model}),(0,X.jsx)(`select`,{className:Qr(),value:t.minimax?.model??``,onChange:e=>s({model:e.target.value}),children:h.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.tts.voice}),(0,X.jsx)(`select`,{className:Qr(),value:t.minimax?.voice??``,onChange:e=>s({voice:e.target.value}),children:g.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}):null,t.provider===`edge`?(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.tts.voice}),(0,X.jsx)(`select`,{className:Qr(),value:t.edge?.voice??``,onChange:e=>o({voice:e.target.value}),children:m.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))}),(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.edgeHint})]}):null,t.provider===`tts-local-cli`?(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,X.jsx)($,{children:e.tts.localCli.command}),(0,X.jsx)(`input`,{className:w(Zr(),`font-mono text-xs`),type:`text`,autoComplete:`off`,spellCheck:!1,value:t[`tts-local-cli`]?.command??``,onChange:e=>c({command:e.target.value}),placeholder:e.tts.localCli.commandPlaceholder}),(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.commandDesc})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.tts.localCli.cwd}),(0,X.jsx)(`input`,{className:w(Zr(),`font-mono text-xs`),type:`text`,autoComplete:`off`,spellCheck:!1,value:t[`tts-local-cli`]?.cwd??``,onChange:e=>c({cwd:e.target.value}),placeholder:`/path/to/cwd`}),(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.cwdDesc})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.tts.localCli.outputFormat}),(0,X.jsxs)(`select`,{className:Qr(),value:t[`tts-local-cli`]?.outputFormat??`wav`,onChange:e=>c({outputFormat:e.target.value}),children:[(0,X.jsx)(`option`,{value:`wav`,children:`wav`}),(0,X.jsx)(`option`,{value:`mp3`,children:`mp3`}),(0,X.jsx)(`option`,{value:`opus`,children:`opus`})]}),(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.outputFormatDesc})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,X.jsx)($,{children:e.tts.localCli.timeoutMs}),(0,X.jsx)(`input`,{className:Zr(),type:`number`,min:0,step:1e3,value:typeof t[`tts-local-cli`]?.timeoutMs==`number`?String(t[`tts-local-cli`].timeoutMs):``,onChange:e=>{let t=e.target.value.trim();if(t===``){c({timeoutMs:void 0});return}let n=Number(t);Number.isFinite(n)&&n>=0&&c({timeoutMs:n})},placeholder:`30000`}),(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.timeoutMsDesc})]}),(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle sm:col-span-2`,children:e.tts.localCli.hint})]}):null]}):null]})]})}function $({children:e}){return(0,X.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e})}function di(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 fi(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 J(K(`/api/config`),{method:`PATCH`,body:JSON.stringify({tools:{web:{region:t,search:n}}})}),R()}function pi({label:e,description:t,children:n}){return(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e}),n,(0,X.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:t})]})}function mi(){return w(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,o,`dark:border-edge`)}function hi(){return w(ve,g)}var gi=[`brave`,`tavily`,`bing`,`searxng`];function _i(){return{type:`brave`,apiKey:``,url:``,disabled:!1}}function vi(){let e=f(e=>e.language),t=ge(e),n=t.webSearchSettings,r=t.logs,i=!!ze(e=>e.token),[a,o]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(!1),[p,h]=(0,Z.useState)(null),[g,_]=(0,Z.useState)(!1),v=(0,Z.useRef)(!1),{data:y,error:b,isLoading:x,mutate:S}=m(i),C=(0,Z.useMemo)(()=>y?.payload?.config===void 0?null:di(y.payload.config),[y]);(0,Z.useEffect)(()=>{if(!i){o(null),l(null),v.current=!1;return}C!==null&&(v.current||(o(C),l(C)))},[i,C]);let w=!!(i&&x&&y===void 0&&!b),T=b instanceof Error?b.message:b?String(b):null,D=(0,Z.useMemo)(()=>!a||!c?!1:JSON.stringify(a)!==JSON.stringify(c),[a,c]),O=(0,Z.useCallback)(e=>{v.current=!0,o(t=>t?{...t,...e}:null)},[]),k=(0,Z.useCallback)(async()=>{if(!(!a||u)){d(!0),h(null),_(!1);try{await fi(a);let e=structuredClone(a);l(e),o(e),v.current=!1,_(!0),window.setTimeout(()=>_(!1),2500)}catch(e){h(e instanceof Error?e.message:n.saveError)}finally{d(!1)}}},[a,u,n.saveError]),A=(0,Z.useCallback)(()=>{c&&(v.current=!1,o(structuredClone(c)),h(null),_(!1))},[c]);return i?w?(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col items-center gap-3 px-4 py-8`,children:[(0,X.jsx)(s,{className:`size-8 animate-spin text-fg-muted`,"aria-hidden":!0}),(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.loading})]}):a?(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,X.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.title}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,X.jsxs)(`a`,{href:qe(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,X.jsx)(N,{className:`size-3.5`})]})]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[g?(0,X.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,X.jsx)(E,{type:`button`,variant:`secondary`,disabled:!D||u,onClick:A,children:n.discard}),(0,X.jsx)(E,{type:`button`,variant:`primary`,disabled:!D||u,onClick:()=>void k(),children:u?n.saving:n.save})]})]}),D?(0,X.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,p?(0,X.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:p}):null,(0,X.jsxs)(Et,{children:[(0,X.jsx)(ct,{icon:oe,title:n.sectionRegion,subtitle:n.sectionRegionHint}),(0,X.jsx)(`div`,{className:`flex max-w-md flex-col gap-4`,children:(0,X.jsx)(pi,{label:n.regionLabel,description:n.regionDesc,children:(0,X.jsxs)(`select`,{className:hi(),value:a.regionMode,onChange:e=>O({regionMode:e.target.value}),children:[(0,X.jsx)(`option`,{value:`auto`,children:n.regionAuto}),(0,X.jsx)(`option`,{value:`cn`,children:n.regionCn}),(0,X.jsx)(`option`,{value:`global`,children:n.regionGlobal})]})})})]}),(0,X.jsxs)(Et,{children:[(0,X.jsx)(ct,{icon:oe,title:n.sectionSearch,subtitle:n.sectionSearchHint}),(0,X.jsxs)(`div`,{className:`flex max-w-xl flex-col gap-6`,children:[(0,X.jsx)(pi,{label:n.maxResultsLabel,description:n.maxResultsDesc,children:(0,X.jsx)(`input`,{type:`number`,min:1,max:50,className:mi(),value:a.maxResults,onChange:e=>O({maxResults:Math.max(1,Math.min(50,Number(e.target.value)||5))})})}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.providersTitle}),a.providers.map((e,t)=>(0,X.jsx)(yi,{row:e,labels:n,onChange:e=>{let n=[...a.providers];n[t]=e,O({providers:n})},onRemove:()=>{O({providers:a.providers.filter((e,n)=>n!==t)})}},t)),(0,X.jsxs)(E,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5 text-sm`,onClick:()=>O({providers:[...a.providers,_i()]}),children:[(0,X.jsx)(me,{className:`size-4`}),n.addProvider]})]})]})]}),(0,X.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:n.footerHint})]}):(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:p??T??n.loadError}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,onClick:()=>void S(),children:r.refresh})]}):(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-4 px-4 py-6`,children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:n.title}),(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}function yi({row:e,labels:t,onChange:n,onRemove:r}){return(0,X.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,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,X.jsx)(`select`,{className:w(hi(),`min-w-[8rem]`),value:e.type,onChange:t=>n({...e,type:t.target.value,url:t.target.value===`searxng`?e.url:``}),children:gi.map(e=>(0,X.jsx)(`option`,{value:e,children:t.providerTypes[e]},e))}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1.5 text-xs text-fg-muted`,children:[(0,X.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,X.jsx)(E,{type:`button`,variant:`ghost`,className:`h-8 px-2 text-fg-muted`,onClick:r,children:(0,X.jsx)(Ne,{className:`size-4`})})]})]}),e.type===`searxng`?(0,X.jsx)(pi,{label:t.urlLabel,description:t.urlDesc,children:(0,X.jsx)(`input`,{type:`url`,className:mi(),value:e.url,placeholder:`http://localhost:8080`,onChange:t=>n({...e,url:t.target.value})})}):null,(0,X.jsx)(pi,{label:t.apiKeyLabel,description:t.apiKeyDesc,children:(0,X.jsx)(`input`,{type:`password`,autoComplete:`off`,className:mi(),value:Ce(e.apiKey)?``:e.apiKey,placeholder:Ce(e.apiKey)?t.keyPlaceholderMasked:t.keyPlaceholder,onChange:t=>n({...e,apiKey:t.target.value})})})]})}var bi=[`appearance`,`system`,`agent-chat`,`agent-workspace`,`agent-browser`,`agent-runtime`,`agent-tools`,`agent-system-prompt`,`providers`,`models`,`image-models`,`voice`,`gateway`,`heartbeat`,`search`,`dreams`];function xi(){let{section:e}=a(),t=f(e=>e.language),n=ge(t);if(e===`agent`||e===`agents`)return(0,X.jsx)(h,{to:`/agents`,replace:!0});if(!e||!bi.includes(e))return(0,X.jsx)(h,{to:`/settings/appearance`,replace:!0});let r=e,i=n.settingsSections[r];return r===`appearance`?(0,X.jsx)(Vt,{}):r===`system`?(0,X.jsx)(Vr,{}):r===`agent-chat`?(0,X.jsx)(_t,{}):r===`agent-workspace`?(0,X.jsx)(vt,{}):r===`agent-browser`?(0,X.jsx)(St,{}):r===`agent-runtime`?(0,X.jsx)(bt,{}):r===`agent-tools`?(0,X.jsx)(st,{}):r===`agent-system-prompt`?(0,X.jsx)(mt,{}):r===`providers`?(0,X.jsx)(Rr,{}):r===`models`?(0,X.jsx)(wr,{}):r===`image-models`?(0,X.jsx)(Yn,{}):r===`voice`?(0,X.jsx)(ci,{}):r===`gateway`?(0,X.jsx)(On,{}):r===`heartbeat`?(0,X.jsx)(In,{}):r===`search`?(0,X.jsx)(vi,{}):r===`dreams`?(0,X.jsx)(Sn,{}):(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:i}),(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t===`zh`?`设置 · ${i}(即将推出)。`:`Settings · ${i} (coming soon).`})]})}export{xi as SettingsPage};
2
- //# sourceMappingURL=settings-page-DMjZKSwv.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}from"./vendor-swr-B5fPo7KK.js";import{$n as i,Ai as a,An as o,Ar as s,Bn as c,Br as l,Bt as u,C as d,Cn as f,Cr as p,Ct as m,Di as h,Dn as g,Dr as _,Ei as v,En as y,Fn as b,Ft as x,Hr as S,It as C,Ln as w,Lt as T,Mn as E,Mt as D,Nt as O,On as k,Or as A,Ot as j,Pt as M,Qr as N,Rn as P,Rt as F,S as I,Sn as L,St as R,Ti as z,Tn as ee,Vn as B,Vr as V,X as H,Xn as te,Xr as ne,Zr as re,_ as ie,_i as U,a as W,b as G,c as ae,cr as oe,dn as K,dr as se,er as ce,fi as le,fn as ue,fr as q,g as de,gi as fe,gn as J,h as pe,hn as Y,hr as me,ir as he,jn as ge,jt as _e,kn as ve,kr as ye,kt as be,l as xe,ln as Se,m as Ce,mi as we,mn as Te,ni as Ee,o as De,or as Oe,p as ke,pi as Ae,pn as je,pr as Me,qn as Ne,ri as Pe,rr as Fe,t as Ie,ui as Le,v as Re,vn as ze,vr as Be,wr as Ve,x as He,xn as Ue,xr as We,y as Ge,yi as Ke,yn as qe,zn as Je,zr as Ye,zt as Xe}from"./index-DvMI6Vqn.js";import{i as Ze,n as Qe,r as $e,t as et}from"./use-image-provider-credentials-D6TXcMU2.js";import{E as tt,S as nt,f as rt,r as it,s as at}from"./cron-dreaming-jobs-D5kvbjSY.js";import{_ as ot,a as st,b as ct,c as lt,d as ut,f as dt,g as ft,h as pt,i as mt,l as ht,m as gt,n as _t,o as vt,p as yt,r as bt,s as xt,t as St,u as Ct,v as wt,x as Tt,y as Et}from"./agents-BgeuYTaG.js";import{t as Dt}from"./browser-DNXWYwzc.js";import{a as Ot,i as kt,n as At,o as jt,r as Mt,s as Nt,t as Pt}from"./heartbeat-config-api-DnmmSrTx.js";var X=n();function Ft(){return w(`rounded-xl border border-edge-subtle bg-surface-base px-4 py-1 sm:px-5`)}var It={default:{light:{canvas:`#f5f5f7`,panel:`#ffffff`,accent:`#2563eb`,fg:`#1d1d1f`,muted:`#d2d2d7`},dark:{canvas:`#1c1c1e`,panel:`#2c2c2e`,accent:`#3b82f6`,fg:`#f5f5f7`,muted:`#48484a`}},emerald:{light:{canvas:`#f0fdf4`,panel:`#ffffff`,accent:`#059669`,fg:`#052e16`,muted:`#86efac`},dark:{canvas:`#000000`,panel:`#0a0a0a`,accent:`#10b981`,fg:`#d1fae5`,muted:`#134e2a`}},mono:{light:{canvas:`#ffffff`,panel:`#f5f5f5`,accent:`#111111`,fg:`#111111`,muted:`#e5e7eb`},dark:{canvas:`#101010`,panel:`#1a1a1a`,accent:`#737373`,fg:`#fafafa`,muted:`#333333`}},clay:{light:{canvas:`#fffaf0`,panel:`#ffffff`,accent:`#1a3a3a`,fg:`#0a0a0a`,muted:`#e5e5e5`},dark:{canvas:`#0a1a1a`,panel:`#1a2a2a`,accent:`#ffb084`,fg:`#fffaf0`,muted:`#2a3a3a`}}};function Lt({canvas:e,panel:t,accent:n,fg:r,muted:i}){return(0,X.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col justify-center gap-1 p-1.5`,style:{backgroundColor:e},children:(0,X.jsxs)(`div`,{className:`flex flex-col gap-0.5 rounded-sm border p-1`,style:{backgroundColor:t,borderColor:i},children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,X.jsx)(`div`,{className:`h-1 w-1 shrink-0 rounded-full`,style:{backgroundColor:n}}),(0,X.jsx)(`div`,{className:`h-1 min-w-0 flex-1 rounded-full`,style:{backgroundColor:r,opacity:.85}})]}),(0,X.jsx)(`div`,{className:`h-1 w-2/3 max-w-[70%] rounded-full`,style:{backgroundColor:i}}),(0,X.jsx)(`div`,{className:`h-1 w-1/2 max-w-[55%] rounded-full`,style:{backgroundColor:i}})]})})}function Rt({scheme:e}){let{light:t,dark:n}=It[e];return(0,X.jsxs)(`div`,{className:`flex h-11 w-full overflow-hidden rounded-md border border-edge-subtle`,children:[(0,X.jsx)(Lt,{...t}),(0,X.jsx)(`div`,{className:`w-px shrink-0 bg-black/12 dark:bg-white/12`,"aria-hidden":!0}),(0,X.jsx)(Lt,{...n})]})}var zt=[{value:`default`,labelKey:`colorSchemeDefault`},{value:`emerald`,labelKey:`colorSchemeLightGreen`},{value:`mono`,labelKey:`colorSchemeModernMono`},{value:`clay`,labelKey:`colorSchemeClay`}];function Bt(){let e=ge(f(e=>e.language)).appearanceSettings,t=L(e=>e.colorScheme),n=L(e=>e.setColorScheme);return(0,X.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,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:e.colorSchemeTitle}),(0,X.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:e.colorSchemeDescription})]}),(0,X.jsx)(`div`,{className:`grid grid-cols-2 gap-3 lg:grid-cols-4`,children:zt.map(({value:r,labelKey:i})=>{let a=t===r;return(0,X.jsxs)(`button`,{type:`button`,"aria-pressed":a,onClick:()=>n(r),className:w(`flex flex-col gap-2 rounded-xl border-2 p-2.5 text-left transition-[border-color,box-shadow] duration-150`,a?`border-accent shadow-[0_0_0_1px_var(--color-accent)]`:`border-edge-subtle hover:border-edge`),children:[(0,X.jsx)(Rt,{scheme:r}),(0,X.jsx)(`span`,{className:w(`text-xs font-medium leading-none`,a?`text-accent-fg`:`text-fg-muted`),children:e[i]})]},r)})})]})}function Vt(){let e=ge(f(e=>e.language)).appearanceSettings;return(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,X.jsxs)(`header`,{className:`flex flex-col gap-1`,children:[(0,X.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight text-fg`,children:e.pageTitle}),(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.subtitle})]}),(0,X.jsxs)(`section`,{className:Ft(),"aria-labelledby":`pref-language-heading`,children:[(0,X.jsx)(`h2`,{id:`pref-language-heading`,className:`sr-only`,children:e.languageTitle}),(0,X.jsx)(Ue,{variant:`page`,sections:[`language`]})]}),(0,X.jsxs)(`section`,{className:Ft(),"aria-labelledby":`pref-appearance-heading`,children:[(0,X.jsx)(`h2`,{id:`pref-appearance-heading`,className:`sr-only`,children:e.themeTitle}),(0,X.jsx)(Ue,{variant:`page`,sections:[`theme`,`font`]}),(0,X.jsx)(Bt,{})]})]})}var Z=e(t(),1);function Ht(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var Ut={enabled:!0,cron:`0 */6 * * *`,lookbackDays:1,limit:50,dedupeSimilarity:.85},Wt={enabled:!0,cron:`0 3 * * *`,minScore:.8,minRecallCount:3,limit:10,recencyHalfLifeDays:14,maxAgeDays:30},Gt={enabled:!0,cron:`0 5 * * 0`,lookbackDays:7,limit:20,minPatternStrength:.6},Kt={enabled:!1,frequency:`0 3 * * *`,timezone:``,deepEnabled:!0,minScore:.8,minRecallCount:3,limit:10,light:Ut,deep:Wt,rem:Gt};function qt(e,t){return Number.isFinite(e)?Math.max(0,Math.min(1,e)):t}function Jt(e,t){let n=typeof e==`string`?Number(e):e;return Number.isFinite(n)?Math.max(0,Math.floor(n)):t}function Yt(e,t){let n=typeof e==`string`?Number(e):e;return Number.isFinite(n)?n:t}function Xt(e){let t=Ht(e)?e:{},n=Ht(t.agents)?t.agents:{},r=Ht(n.defaults)?n.defaults:{},i=Ht(r.memory)?r.memory:{},a=Ht(i.dreaming)?i.dreaming:{},o=Ht(a.phases)?a.phases:{},s=Ht(o.light)?o.light:{},c=Ht(o.deep)?o.deep:{},l=Ht(o.rem)?o.rem:{};return{enabled:a.enabled===!0,frequency:typeof a.frequency==`string`&&a.frequency.trim()?a.frequency.trim():Kt.frequency,timezone:typeof a.timezone==`string`?a.timezone:``,deepEnabled:c.enabled!==!1,minScore:qt(typeof c.minScore==`number`?c.minScore:Number(c.minScore),Kt.minScore),minRecallCount:Math.max(1,Jt(c.minRecallCount,Kt.minRecallCount)),limit:Jt(c.limit,Kt.limit),light:{enabled:s.enabled!==!1,cron:typeof s.cron==`string`&&s.cron.trim()?s.cron.trim():Ut.cron,lookbackDays:Math.max(1,Jt(s.lookbackDays,Ut.lookbackDays)),limit:Jt(s.limit,Ut.limit),dedupeSimilarity:qt(Yt(s.dedupeSimilarity,Ut.dedupeSimilarity),Ut.dedupeSimilarity)},deep:{enabled:c.enabled!==!1,cron:typeof c.cron==`string`&&c.cron.trim()?c.cron.trim():Wt.cron,minScore:qt(Yt(c.minScore,Wt.minScore),Wt.minScore),minRecallCount:Math.max(1,Jt(c.minRecallCount,Wt.minRecallCount)),limit:Jt(c.limit,Wt.limit),recencyHalfLifeDays:Math.max(1,Yt(c.recencyHalfLifeDays,Wt.recencyHalfLifeDays)),maxAgeDays:Math.max(1,Yt(c.maxAgeDays,Wt.maxAgeDays))},rem:{enabled:l.enabled!==!1,cron:typeof l.cron==`string`&&l.cron.trim()?l.cron.trim():Gt.cron,lookbackDays:Math.max(1,Jt(l.lookbackDays,Gt.lookbackDays)),limit:Jt(l.limit,Gt.limit),minPatternStrength:qt(Yt(l.minPatternStrength,Gt.minPatternStrength),Gt.minPatternStrength)}}}async function Zt(e){let t=e.frequency.trim(),n=e.timezone.trim();await J(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:qt(e.light.dedupeSimilarity,Ut.dedupeSimilarity)},deep:{enabled:!!e.deep.enabled,cron:e.deep.cron.trim()||null,minScore:qt(e.deep.minScore,Wt.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:qt(e.rem.minPatternStrength,Gt.minPatternStrength)}}}}}}})}),R()}var Qt=w(`h-9 min-w-0 flex-1 rounded-lg border border-edge-subtle bg-surface-panel px-2.5 py-1.5 text-sm tabular-nums text-fg`,y),$t=w(ve,`h-9 max-w-[11rem] shrink-0 text-xs sm:max-w-[12rem]`);function en(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 tn({valueMs:e,onChangeMs:t,labels:n,disabled:r,presets:i=it,minSeconds:a=1}){let o=(0,Z.useMemo)(()=>new Set(i),[i]),s=(0,Z.useMemo)(()=>o.has(e)?String(e):``,[o,e]),[c,l]=(0,Z.useState)(null),u=Math.max(a,Math.round(e/1e3)),d=c===null?String(u):c;return(0,Z.useEffect)(()=>{l(null)},[e]),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,X.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:n.secondsLabel}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(`input`,{type:`number`,min:a,step:1,disabled:r,className:Qt,value:d,onChange:e=>{let n=e.target.value;l(n);let r=parseInt(n,10);Number.isFinite(r)&&r>=a&&t(r*1e3)},onBlur:()=>{if(c===null)return;let e=parseInt(c,10);t(!Number.isFinite(e)||e<a?a*1e3:e*1e3),l(null)}}),(0,X.jsxs)(`select`,{className:$t,disabled:r,value:s,onChange:e=>{let n=e.target.value;n&&(t(parseInt(n,10)),l(null))},children:[(0,X.jsx)(`option`,{value:``,children:n.presets.custom}),i.map(e=>(0,X.jsx)(`option`,{value:String(e),children:en(e,n.presets)},e))]})]})]})}var nn=w(`mt-1 w-full rounded-lg border border-edge-subtle bg-surface-panel px-2.5 py-1.5 text-sm text-fg`,y),rn=()=>({start:`09:00`,end:`22:00`,timezone:``});function an({value:e,onChange:t,labels:n,disabled:r}){return e?(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-3`,children:[(0,X.jsxs)(`label`,{className:`block min-w-0`,children:[(0,X.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:n.start}),(0,X.jsx)(`input`,{type:`time`,step:60,disabled:r,className:nn,value:e.start,onChange:n=>t({...e,start:n.target.value})})]}),(0,X.jsxs)(`label`,{className:`block min-w-0`,children:[(0,X.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:n.end}),(0,X.jsx)(`input`,{type:`time`,step:60,disabled:r,className:nn,value:e.end,onChange:n=>t({...e,end:n.target.value})})]}),(0,X.jsxs)(`label`,{className:`block min-w-0`,children:[(0,X.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:n.timezone}),(0,X.jsx)(`input`,{type:`text`,disabled:r,className:nn,value:e.timezone,onChange:n=>t({...e,timezone:n.target.value}),placeholder:`Asia/Shanghai`,autoComplete:`off`})]})]}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,className:`text-xs`,disabled:r,onClick:()=>t(null),children:n.clear})]}):(0,X.jsx)(E,{type:`button`,variant:`secondary`,className:`text-sm`,disabled:r,onClick:()=>t(rn()),children:n.add})}function on(e){let{disabled:t,label:n,hint:r,className:i}=e;return(0,X.jsxs)(`div`,{className:w(`flex flex-col gap-2`,i),children:[n?(0,X.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:n}):null,e.kind===`cron`?(0,X.jsx)(Nt,{value:e.value,onChange:e.onChange,labels:e.labels,disabled:t,showHeading:!n}):null,e.kind===`interval`?(0,X.jsx)(tn,{valueMs:e.valueMs,onChangeMs:e.onChangeMs,labels:e.labels,disabled:t,presets:e.presets??it,minSeconds:e.minSeconds}):null,e.kind===`active-hours`?(0,X.jsx)(an,{value:e.value,onChange:e.onChange,labels:e.labels,disabled:t}):null,r?(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:r}):null]})}var sn=`py-4 px-4 sm:px-5`,cn=`mb-3`,ln=`rounded-xl border border-edge-subtle bg-surface-panel/30 p-3 sm:p-4`,un=w(`mt-1 w-full rounded-lg border border-edge-subtle bg-surface-panel px-2.5 py-1.5 text-sm text-fg`,y);function dn(){return`text-xs font-medium text-fg-muted`}function fn(){return`text-sm font-medium text-fg`}function pn({label:e,children:t,className:n}){return(0,X.jsxs)(`div`,{className:n,children:[(0,X.jsx)(`span`,{className:dn(),children:e}),t]})}function Q({label:e,children:t,className:n}){return(0,X.jsxs)(`div`,{className:w(`min-w-0`,n),children:[(0,X.jsx)(`dt`,{className:dn(),children:e}),(0,X.jsx)(`dd`,{className:w(fn(),`mt-0.5`),children:t})]})}function mn(e){return e?e.replace(`T`,` `).replace(`Z`,``):`—`}function hn(e){return e===void 0||!Number.isFinite(e)||e<0?`—`:e<1e3?`${Math.round(e)} ms`:`${(e/1e3).toFixed(2)} s`}function gn({label:e,className:t}){return(0,X.jsx)(`h3`,{className:w(`text-[0.7rem] font-semibold uppercase tracking-wider text-fg-muted`,t),children:e})}function _n({icon:e,title:t,hint:n,enabled:r,onEnabledChange:i,cron:a,onCronChange:o,scheduleLabels:s,disabled:c,onLabel:l,offLabel:u,cronLabel:d,children:f}){return(0,X.jsxs)(`div`,{className:ln,children:[(0,X.jsxs)(`div`,{className:`mb-2.5 flex flex-wrap items-start justify-between gap-2 border-b border-edge-subtle/80 pb-2.5`,children:[(0,X.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2`,children:[(0,X.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:e}),(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:t}),(0,X.jsx)(`p`,{className:`mt-0.5 text-xs leading-snug text-fg-muted`,children:n})]})]}),(0,X.jsxs)(`label`,{className:`inline-flex shrink-0 items-center gap-2 text-xs text-fg`,children:[(0,X.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:r,disabled:c,onChange:e=>i(e.target.checked)}),(0,X.jsx)(`span`,{children:r?l:u})]})]}),(0,X.jsx)(on,{kind:`cron`,className:`mb-2.5`,label:d,value:a,onChange:o,labels:s,disabled:c}),(0,X.jsx)(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-3 lg:grid-cols-4`,children:f})]})}function vn({icon:e,label:t,enabled:n,cron:r,scheduleSummary:i,details:a,t:o}){return(0,X.jsxs)(`div`,{className:w(ln,`space-y-1`),children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[e,(0,X.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:t}),(0,X.jsx)(`span`,{className:w(`ml-auto text-xs font-medium`,n?`text-emerald-600 dark:text-emerald-400`:`text-fg-muted`),children:n?o.on:o.off})]}),(0,X.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:i}),(0,X.jsx)(`p`,{className:`truncate font-mono text-[0.65rem] text-fg-subtle`,title:r,children:r}),(0,X.jsx)(`p`,{className:`text-[0.65rem] leading-snug text-fg-muted`,children:a})]})}function yn({label:e,lastRun:t,t:n}){return(0,X.jsxs)(`div`,{className:`border-t border-edge-subtle/80 pt-3`,children:[(0,X.jsx)(gn,{label:e,className:`mb-2`}),t?.exists?(0,X.jsxs)(`details`,{className:`group rounded-lg border border-edge-subtle`,children:[(0,X.jsx)(`summary`,{className:`cursor-pointer list-none px-2.5 py-1.5 text-xs font-medium text-fg-muted marker:hidden [&::-webkit-details-marker]:hidden`,children:(0,X.jsx)(`span`,{className:`underline decoration-edge underline-offset-2 group-open:text-fg`,children:n.lastRunRaw})}),(0,X.jsx)(`pre`,{className:`max-h-40 overflow-auto border-t border-edge-subtle p-2.5 text-xs text-fg-muted`,children:JSON.stringify(t.raw,null,2)})]}):(0,X.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.phaseLastRunEmpty})]})}function bn({t:e,r:t}){let n=t.deep?.skipped;return(0,X.jsxs)(`dl`,{className:`grid grid-cols-2 gap-x-3 gap-y-2 sm:grid-cols-3 lg:grid-cols-4`,children:[(0,X.jsx)(Q,{label:e.lastRunStatus,children:(0,X.jsx)(`span`,{className:t.ok?`text-emerald-600 dark:text-emerald-400`:`text-amber-600 dark:text-amber-400`,children:t.ok?e.lastRunSuccess:e.lastRunFailure})}),(0,X.jsx)(Q,{label:e.lastRunDuration,children:hn(t.durationMs)}),(0,X.jsx)(Q,{label:e.lastRunRanked,children:String(t.deep?.candidatesRanked??`—`)}),(0,X.jsx)(Q,{label:e.lastRunApplied,children:String(t.deep?.applied??`—`)}),(0,X.jsxs)(Q,{label:e.lastRunReason,className:`col-span-2 sm:col-span-3 lg:col-span-4`,children:[(0,X.jsx)(`span`,{className:`block text-pretty`,children:t.reason}),t.errorMessage?(0,X.jsx)(`span`,{className:`mt-1 block text-xs text-amber-600 dark:text-amber-400`,children:`${e.lastRunError}: ${t.errorMessage}`}):null]}),n?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Q,{label:e.lastRunSkipKey,children:String(n.alreadyPromotedKey)}),(0,X.jsx)(Q,{label:e.lastRunSkipRehydrate,children:String(n.rehydrateFailed)}),(0,X.jsx)(Q,{label:e.lastRunSkipContaminated,children:String(n.contaminated)}),(0,X.jsx)(Q,{label:e.lastRunSkipHash,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 Sn(){let e=f(e=>e.language),t=ge(e),n=t.dreamingSettings,a=t.cron.schedulePicker,o=t.cron.scheduleBadge,l=e===`zh`?`zh-CN`:`en-US`,u=!!ze(e=>e.token),{data:d}=m(u),[h,g]=(0,Z.useState)(null),[_,v]=(0,Z.useState)(null),[y,b]=(0,Z.useState)(!1),[x,S]=(0,Z.useState)(!1),[C,T]=(0,Z.useState)(!1),[D,O]=(0,Z.useState)(null),[k,A]=(0,Z.useState)(`deep`),[j,M]=(0,Z.useState)(null),[N,P]=(0,Z.useState)(null),[F,I]=(0,Z.useState)(!1),[L,R]=(0,Z.useState)(!1),[ee,B]=(0,Z.useState)(!1),[V,H]=(0,Z.useState)(null),[ne,re]=(0,Z.useState)(!1),[ie,U]=(0,Z.useState)(null),[W,G]=(0,Z.useState)(null),[ae,oe]=(0,Z.useState)(!1),[K,ce]=(0,Z.useState)(null),[le,ue]=(0,Z.useState)(null),{data:q,error:de,isLoading:fe,mutate:J}=r(u?dt():null,pt,{revalidateOnFocus:!1}),pe=(0,Z.useMemo)(()=>q?xn(q.lock,n):null,[q,n]),Y=(0,Z.useMemo)(()=>{let e=[];return de&&e.push(de instanceof Error?de.message:String(de)),_&&e.push(_),D&&e.push(D),ie&&e.push(ie),K&&e.push(K),V&&e.push(V),e},[de,_,D,ie,K,V]),me=(0,Z.useMemo)(()=>{let e=[];return ee&&e.push(n.configSaved),C&&e.push(n.runQueued),y&&e.push(n.actionOk),e},[ee,C,y,n]),_e=(0,Z.useCallback)(async()=>{b(!1),v(null),T(!1),O(null),B(!1),H(null),U(null),await J()},[J]),ve=(0,Z.useCallback)(async()=>{re(!0),U(null);try{G((await gt(20)).items??[])}catch(e){U(e instanceof Error?e.message:String(e))}finally{re(!1)}},[]),be=(0,Z.useCallback)(async()=>{oe(!0),ce(null);try{ue(await yt(50))}catch(e){ce(e instanceof Error?e.message:String(e))}finally{oe(!1)}},[]),xe=(0,Z.useCallback)(async(e=`deep`)=>{S(!0),T(!1),O(null);try{await ot(e),T(!0),await J()}catch(e){O(e instanceof Error?e.message:String(e))}finally{S(!1)}},[J]),Se=(0,Z.useCallback)(async e=>{g(e),v(null),b(!1);try{await ft(e),b(!0),await J()}catch(e){v(e instanceof Error?e.message:String(e))}finally{g(null)}},[J]),Ce=!u||fe||!!h,we=(0,Z.useMemo)(()=>{let e=d?.payload?.config;return Xt(e??{})},[d]);(0,Z.useEffect)(()=>{if(u){if(!N){P(we),M(we);return}JSON.stringify(we)!==JSON.stringify(N)&&(P(we),M(we))}},[N,we,u]);let Te=(0,Z.useMemo)(()=>!j||!N?!1:JSON.stringify(j)!==JSON.stringify(N),[j,N]),Ee=(0,Z.useCallback)(async()=>{if(j){I(!0),B(!1),H(null);try{await Zt(j),P(j),B(!0),await J()}catch(e){H(e instanceof Error?e.message:String(e))}finally{I(!1)}}},[j,J]),De=(0,Z.useCallback)(async e=>{if(!j||!u)return;let t={...j,enabled:e},n=j;M(t),R(!0),B(!1),H(null);try{await Zt(t),P(t),B(!0),await J()}catch(e){M(n),H(e instanceof Error?e.message:String(e))}finally{R(!1)}},[j,u,J]),Oe=j?.enabled??we.enabled;return(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-4 px-4 py-6`,children:[(0,X.jsxs)(`header`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:n.title}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle})]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[j?(0,X.jsxs)(`label`,{className:w(`inline-flex cursor-pointer items-center gap-2 rounded-xl border px-3 py-1.5 text-sm transition-colors`,Oe?`border-emerald-500/30 bg-emerald-500/5 text-fg`:`border-edge-subtle bg-surface-panel/50 text-fg-muted`),children:[(0,X.jsx)(`span`,{className:`text-xs font-medium`,children:n.configEnabled}),(0,X.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:j.enabled,disabled:!u||F||L,onChange:e=>void De(e.target.checked)}),L?(0,X.jsx)(s,{className:`size-3.5 animate-spin text-fg-muted`,"aria-hidden":!0}):(0,X.jsx)(`span`,{className:w(`text-xs font-semibold`,Oe?`text-emerald-600 dark:text-emerald-400`:``),children:j.enabled?n.on:n.off})]}):null,Oe?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`select`,{className:`rounded-lg border border-edge bg-surface-panel px-2 py-1.5 text-xs text-fg`,value:k,onChange:e=>A(e.target.value),disabled:!u||x,children:[(0,X.jsx)(`option`,{value:`light`,children:`Light`}),(0,X.jsx)(`option`,{value:`deep`,children:`Deep`}),(0,X.jsx)(`option`,{value:`rem`,children:`REM`})]}),(0,X.jsxs)(E,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!u||x,onClick:()=>void xe(k),title:n.runNowHint,children:[x?(0,X.jsx)(s,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,X.jsx)(Be,{className:`mr-2 size-4`,"aria-hidden":!0}),n.runNow]})]}):null,(0,X.jsxs)(E,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!u,onClick:()=>void _e(),children:[(0,X.jsx)(Me,{className:`mr-2 size-4`,"aria-hidden":!0}),n.refresh]})]})]}),Y.length>0?(0,X.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:Y.map((e,t)=>(0,X.jsx)(`p`,{className:`text-sm text-amber-800 dark:text-amber-200/90`,children:e},t))}):null,me.length>0?(0,X.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:me.map((e,t)=>(0,X.jsx)(`p`,{className:`text-sm text-emerald-800 dark:text-emerald-200/90`,children:e},t))}):null,(0,X.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,X.jsxs)(Et,{className:w(`min-w-0`,sn),children:[(0,X.jsx)(ct,{className:cn,icon:he,title:n.configTitle,subtitle:n.configHint,trailing:(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(E,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!u||!j||F||!Te,onClick:()=>void Ee(),children:[F?(0,X.jsx)(s,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,n.saveConfig]}),(0,X.jsx)(E,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!u||!j||F||!Te,onClick:()=>{B(!1),H(null),M(N)},children:n.resetConfig})]})}),j?(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsx)(`div`,{className:ln,children:(0,X.jsxs)(`div`,{className:`grid grid-cols-1 gap-2 lg:grid-cols-12`,children:[(0,X.jsx)(`div`,{className:`lg:col-span-9`,children:(0,X.jsx)(on,{kind:`cron`,label:n.configFrequency,value:j.frequency,onChange:e=>M({...j,frequency:e}),labels:a,disabled:!u||F})}),(0,X.jsx)(pn,{label:n.configTimezone,className:`lg:col-span-3`,children:(0,X.jsx)(`input`,{className:un,value:j.timezone,disabled:!u||F,onChange:e=>M({...j,timezone:e.target.value}),placeholder:`Asia/Shanghai`})})]})}),(0,X.jsxs)(_n,{icon:(0,X.jsx)(te,{className:`size-4 text-amber-500`}),title:n.configPhaseLight,hint:n.configPhaseLightHint,enabled:j.light.enabled,onEnabledChange:e=>M({...j,light:{...j.light,enabled:e}}),cron:j.light.cron,onCronChange:e=>M({...j,light:{...j.light,cron:e}}),scheduleLabels:a,disabled:!u||F,onLabel:n.on,offLabel:n.off,cronLabel:n.configPhaseCron,children:[(0,X.jsx)(pn,{label:n.configLightLookbackDays,children:(0,X.jsx)(`input`,{type:`number`,step:`1`,min:1,className:un,value:j.light.lookbackDays,disabled:!u||F,onChange:e=>M({...j,light:{...j.light,lookbackDays:Number(e.target.value)}})})}),(0,X.jsx)(pn,{label:n.configLightLimit,children:(0,X.jsx)(`input`,{type:`number`,step:`1`,min:0,className:un,value:j.light.limit,disabled:!u||F,onChange:e=>M({...j,light:{...j.light,limit:Number(e.target.value)}})})}),(0,X.jsx)(pn,{label:n.configLightDedupe,children:(0,X.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:un,value:j.light.dedupeSimilarity,disabled:!u||F,onChange:e=>M({...j,light:{...j.light,dedupeSimilarity:Number(e.target.value)}})})})]}),(0,X.jsxs)(_n,{icon:(0,X.jsx)(p,{className:`size-4 text-indigo-500`}),title:n.configPhaseDeep,hint:n.configPhaseDeepHint,enabled:j.deep.enabled,onEnabledChange:e=>M({...j,deep:{...j.deep,enabled:e}}),cron:j.deep.cron,onCronChange:e=>M({...j,deep:{...j.deep,cron:e}}),scheduleLabels:a,disabled:!u||F,onLabel:n.on,offLabel:n.off,cronLabel:n.configPhaseCron,children:[(0,X.jsx)(pn,{label:n.configDeepMinScore,children:(0,X.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:un,value:j.deep.minScore,disabled:!u||F,onChange:e=>M({...j,deep:{...j.deep,minScore:Number(e.target.value)}})})}),(0,X.jsx)(pn,{label:n.configDeepMinRecallCount,children:(0,X.jsx)(`input`,{type:`number`,step:`1`,min:1,className:un,value:j.deep.minRecallCount,disabled:!u||F,onChange:e=>M({...j,deep:{...j.deep,minRecallCount:Number(e.target.value)}})})}),(0,X.jsx)(pn,{label:n.configDeepLimit,children:(0,X.jsx)(`input`,{type:`number`,step:`1`,min:0,className:un,value:j.deep.limit,disabled:!u||F,onChange:e=>M({...j,deep:{...j.deep,limit:Number(e.target.value)}})})}),(0,X.jsx)(pn,{label:n.configDeepHalfLife,children:(0,X.jsx)(`input`,{type:`number`,step:`1`,min:1,className:un,value:j.deep.recencyHalfLifeDays,disabled:!u||F,onChange:e=>M({...j,deep:{...j.deep,recencyHalfLifeDays:Number(e.target.value)}})})}),(0,X.jsx)(pn,{label:n.configDeepMaxAge,children:(0,X.jsx)(`input`,{type:`number`,step:`1`,min:1,className:un,value:j.deep.maxAgeDays,disabled:!u||F,onChange:e=>M({...j,deep:{...j.deep,maxAgeDays:Number(e.target.value)}})})})]}),(0,X.jsxs)(_n,{icon:(0,X.jsx)(i,{className:`size-4 text-purple-500`}),title:n.configPhaseRem,hint:n.configPhaseRemHint,enabled:j.rem.enabled,onEnabledChange:e=>M({...j,rem:{...j.rem,enabled:e}}),cron:j.rem.cron,onCronChange:e=>M({...j,rem:{...j.rem,cron:e}}),scheduleLabels:a,disabled:!u||F,onLabel:n.on,offLabel:n.off,cronLabel:n.configPhaseCron,children:[(0,X.jsx)(pn,{label:n.configRemLookbackDays,children:(0,X.jsx)(`input`,{type:`number`,step:`1`,min:1,className:un,value:j.rem.lookbackDays,disabled:!u||F,onChange:e=>M({...j,rem:{...j.rem,lookbackDays:Number(e.target.value)}})})}),(0,X.jsx)(pn,{label:n.configRemLimit,children:(0,X.jsx)(`input`,{type:`number`,step:`1`,min:0,className:un,value:j.rem.limit,disabled:!u||F,onChange:e=>M({...j,rem:{...j.rem,limit:Number(e.target.value)}})})}),(0,X.jsx)(pn,{label:n.configRemMinStrength,children:(0,X.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:un,value:j.rem.minPatternStrength,disabled:!u||F,onChange:e=>M({...j,rem:{...j.rem,minPatternStrength:Number(e.target.value)}})})})]})]}):(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.configLoading})]}),(0,X.jsxs)(Et,{className:w(`min-w-0`,sn),children:[(0,X.jsx)(ct,{className:cn,icon:z,title:n.runtimeTitle,subtitle:n.runtimeHint,trailing:fe?(0,X.jsx)(s,{className:`size-4 shrink-0 animate-spin text-fg-muted`,"aria-hidden":!0}):null}),(0,X.jsxs)(`div`,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{className:ln,children:[(0,X.jsx)(gn,{label:n.subsectionSchedule,className:`mb-2`}),(0,X.jsxs)(`dl`,{className:`grid grid-cols-2 gap-x-3 gap-y-2 sm:grid-cols-4`,children:[(0,X.jsx)(Q,{label:n.enabled,children:q?q.config.enabled?n.on:n.off:`—`}),(0,X.jsx)(Q,{label:n.lock,children:(0,X.jsx)(`span`,{className:pe?.className,children:pe?pe.text:`—`})}),(0,X.jsx)(Q,{label:n.timezone,children:q&&q.config.timezone||`—`}),(0,X.jsxs)(Q,{label:n.schedule,className:`col-span-2 sm:col-span-2`,children:[q?(0,X.jsx)(wt,{kind:`cron`,expression:q.config.frequency,locale:l,labels:o,timezone:q.config.timezone||void 0}):`—`,q?.config.frequency?(0,X.jsx)(`p`,{className:`mt-0.5 truncate font-mono text-[0.65rem] text-fg-subtle`,title:q.config.frequency,children:q.config.frequency}):null]})]})]}),(0,X.jsxs)(`div`,{className:ln,children:[(0,X.jsx)(gn,{label:n.subsectionStore,className:`mb-2`}),(0,X.jsxs)(`dl`,{className:`grid grid-cols-2 gap-x-3 gap-y-2 sm:grid-cols-4`,children:[(0,X.jsx)(Q,{label:n.storeEntries,children:q?String(q.store.entryCount):`—`}),(0,X.jsx)(Q,{label:n.storePromoted,children:q?String(q.store.promotedCount):`—`}),(0,X.jsx)(Q,{label:n.storeUpdatedAt,children:q?mn(q.store.updatedAt):`—`}),(0,X.jsx)(Q,{label:n.storeLastPromotedAt,children:q?mn(q.store.lastPromotedAt):`—`})]})]}),q?.config?.phases?(0,X.jsxs)(`div`,{children:[(0,X.jsx)(gn,{label:n.subsectionPhases,className:`mb-2`}),(0,X.jsxs)(`div`,{className:`grid gap-2 sm:grid-cols-3`,children:[(0,X.jsx)(vn,{icon:(0,X.jsx)(te,{className:`size-4 text-amber-500`}),label:`Light`,enabled:q.config.phases.light.enabled,cron:q.config.phases.light.cron,scheduleSummary:tt(q.config.phases.light.cron,l,o,{timezone:q.config.timezone||void 0}),details:`lookback=${q.config.phases.light.lookbackDays}d, limit=${q.config.phases.light.limit}, dedupe=${q.config.phases.light.dedupeSimilarity}`,t:n}),(0,X.jsx)(vn,{icon:(0,X.jsx)(p,{className:`size-4 text-indigo-500`}),label:`Deep`,enabled:q.config.phases.deep.enabled,cron:q.config.phases.deep.cron,scheduleSummary:tt(q.config.phases.deep.cron,l,o,{timezone:q.config.timezone||void 0}),details:`minScore=${q.config.phases.deep.minScore}, recalls≥${q.config.phases.deep.minRecallCount}, limit=${q.config.phases.deep.limit}, halfLife=${q.config.phases.deep.recencyHalfLifeDays}d`,t:n}),(0,X.jsx)(vn,{icon:(0,X.jsx)(i,{className:`size-4 text-purple-500`}),label:`REM`,enabled:q.config.phases.rem.enabled,cron:q.config.phases.rem.cron,scheduleSummary:tt(q.config.phases.rem.cron,l,o,{timezone:q.config.timezone||void 0}),details:`lookback=${q.config.phases.rem.lookbackDays}d, limit=${q.config.phases.rem.limit}, strength≥${q.config.phases.rem.minPatternStrength}`,t:n})]})]}):null,(0,X.jsxs)(`div`,{className:ln,children:[(0,X.jsx)(gn,{label:n.subsectionLastRun,className:`mb-2`}),(0,X.jsx)(`p`,{className:`mb-2 text-xs text-fg-muted`,children:n.lastRunBlockHint}),q?.lastRun?.exists?(0,X.jsxs)(`div`,{className:`space-y-2`,children:[q.lastRun.parseError?(0,X.jsxs)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:[n.lastRunParseError,`: `,q.lastRun.parseError]}):null,q.lastRun.record?(0,X.jsx)(`div`,{className:`rounded-lg border border-edge-subtle/80 bg-surface-panel/50 p-2.5`,children:(0,X.jsx)(bn,{t:n,r:q.lastRun.record})}):null,q.lastRun.raw!==void 0&&q.lastRun.raw!==null?(0,X.jsxs)(`details`,{className:`group rounded-lg border border-edge-subtle`,children:[(0,X.jsx)(`summary`,{className:`cursor-pointer list-none px-2.5 py-1.5 text-xs font-medium text-fg-muted marker:hidden [&::-webkit-details-marker]:hidden`,children:(0,X.jsx)(`span`,{className:`underline decoration-edge underline-offset-2 group-open:text-fg`,children:n.lastRunRaw})}),(0,X.jsx)(`pre`,{className:`max-h-40 overflow-auto border-t border-edge-subtle p-2.5 text-xs text-fg-muted`,children:JSON.stringify(q.lastRun.raw,null,2)})]}):null]}):(0,X.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.lastRunEmpty})]}),(0,X.jsx)(yn,{label:n.subsectionLightLastRun,lastRun:q?.lightLastRun,t:n}),(0,X.jsx)(yn,{label:n.subsectionRemLastRun,lastRun:q?.remLastRun,t:n})]})]})]}),(0,X.jsxs)(`div`,{className:`grid gap-4 xl:grid-cols-2`,children:[(0,X.jsxs)(Et,{className:sn,children:[(0,X.jsx)(ct,{className:cn,icon:se,title:n.previewTitle,subtitle:n.previewHint,trailing:(0,X.jsxs)(E,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!u||ne,onClick:()=>void ve(),children:[ne?(0,X.jsx)(s,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,n.previewLoad]})}),W?W.length>0?(0,X.jsx)(`div`,{className:`space-y-2`,children:W.map(e=>{let t=`${e.path}:${e.startLine}-${e.endLine}`,r=e.skippedReason;return(0,X.jsxs)(`div`,{className:`rounded-lg border border-edge-subtle bg-surface-panel/60 px-2.5 py-2`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-fg-muted`,children:[(0,X.jsx)(`span`,{className:`font-medium text-fg`,children:t}),(0,X.jsxs)(`span`,{children:[`score=`,e.score.toFixed(3)]}),(0,X.jsxs)(`span`,{children:[`recalls=`,e.recallCount]}),(0,X.jsxs)(`span`,{children:[`avg=`,e.avgScore.toFixed(3)]}),(0,X.jsxs)(`span`,{children:[`decay=`,e.recencyDecay?.toFixed(3)??`—`]}),r?(0,X.jsx)(`span`,{className:`text-amber-600 dark:text-amber-400`,children:r}):(0,X.jsx)(`span`,{className:`text-emerald-600 dark:text-emerald-400`,children:n.previewEligible})]}),e.snippet?(0,X.jsx)(`div`,{className:`mt-2 text-sm text-fg`,children:e.snippet}):null]},`${e.key}:${e.hash}:${t}`)})}):(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.previewEmpty}):(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.previewNotLoaded})]}),(0,X.jsxs)(Et,{className:sn,children:[(0,X.jsx)(ct,{className:cn,icon:z,title:n.eventsTitle,subtitle:n.eventsHint,trailing:(0,X.jsxs)(E,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!u||ae,onClick:()=>void be(),children:[ae?(0,X.jsx)(s,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,n.eventsLoad]})}),le?le.length>0?(0,X.jsx)(`div`,{className:`space-y-1.5`,children:le.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,X.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,X.jsx)(`span`,{children:n}),(0,X.jsx)(`span`,{className:`font-medium text-fg`,children:e.phase}),(0,X.jsx)(`span`,{className:w(`font-medium`,e.ok?`text-emerald-600 dark:text-emerald-400`:`text-amber-600 dark:text-amber-400`),children:e.ok?`OK`:`FAIL`}),(0,X.jsx)(`span`,{className:`text-fg-muted`,children:r}),(0,X.jsx)(`span`,{className:`text-fg-muted`,children:hn(e.durationMs)}),(0,X.jsx)(`span`,{className:`ml-auto text-fg-subtle`,children:mn(e.timestamp)})]},`${e.timestamp}:${e.phase}:${t}`)})}):(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.eventsEmpty}):(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.eventsNotLoaded})]})]}),(0,X.jsxs)(Et,{className:w(`max-w-2xl`,sn),children:[(0,X.jsx)(ct,{className:cn,icon:c,title:n.maintenanceTitle,subtitle:n.maintenanceHint}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,X.jsxs)(E,{variant:`secondary`,disabled:Ce,onClick:()=>{confirm(n.confirmResetStore)&&Se(`reset_store`)},children:[h===`reset_store`?(0,X.jsx)(s,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,X.jsx)(Ne,{className:`mr-2 size-4`,"aria-hidden":!0}),n.resetStore]}),(0,X.jsxs)(E,{variant:`secondary`,disabled:Ce,onClick:()=>{confirm(n.confirmClearLock)&&Se(`clear_lock`)},children:[h===`clear_lock`?(0,X.jsx)(s,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,X.jsx)(ye,{className:`mr-2 size-4`,"aria-hidden":!0}),n.clearLock]})]})]})]})}var Cn=e(Dt(),1);function wn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Tn(e){let t=wn(e)?e:{},n=wn(t.gateway)?t.gateway:{},r=wn(n.auth)?n.auth:{},i=r.mode===`none`||r.mode===`token`?r.mode:`token`,a=(wn(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 En(e){let t=e.auth.token.trim().length>0?{mode:e.auth.mode,token:e.auth.token}:{mode:e.auth.mode};await J(K(`/api/config`),{method:`PATCH`,body:JSON.stringify({gateway:{auth:t},update:{channel:e.updateChannel}})}),R()}function Dn(){return w(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,o,`dark:border-edge`)}function On(){let e=f(e=>e.language),t=ge(e),n=t.gatewaySettings,r=ze(e=>e.token),i=ze(e=>e.tokenExpired),a=ze(e=>e.openTokenDialog),o=!!r,[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(null),[p,h]=(0,Z.useState)(!1),[g,_]=(0,Z.useState)(null),[v,y]=(0,Z.useState)(!1),[b,x]=(0,Z.useState)(!1),[S,C]=(0,Z.useState)(!1),w=(0,Z.useRef)(!1),{data:T,error:D,isLoading:O,mutate:k}=m(o),A=(0,Z.useMemo)(()=>T?.payload?.config===void 0?null:structuredClone(Tn(T.payload.config)),[T]);(0,Z.useEffect)(()=>{if(!o){l(null),d(null),w.current=!1;return}A!==null&&(w.current||(l(A),d(structuredClone(A)),y(!1)))},[o,A]);let j=!!(o&&O&&T===void 0&&!D),M=D instanceof Error?D.message:D?String(D):null,P=(0,Z.useMemo)(()=>!c||!u?!1:JSON.stringify(c)!==JSON.stringify(u),[c,u]),F=(0,Z.useCallback)(e=>{w.current=!0,l(t=>t?{...t,auth:{...t.auth,...e}}:null)},[]),I=(0,Z.useCallback)(e=>{w.current=!0,l(t=>t?{...t,updateChannel:e}:null)},[]),L=(0,Z.useCallback)(async()=>{if(!(!c||p)){h(!0),_(null),y(!1);try{await En(c),w.current=!1,d(structuredClone(c)),y(!0),window.setTimeout(()=>y(!1),2500)}catch(e){_(e instanceof Error?e.message:n.saveError)}finally{h(!1)}}},[c,p,n.saveError]),R=(0,Z.useCallback)(()=>{u&&(w.current=!1,l(structuredClone(u)),_(null),y(!1))},[u]),z=(0,Z.useCallback)(async()=>{let e=c?.auth.token;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),C(!0),window.setTimeout(()=>C(!1),2e3))},[c?.auth.token]);return o?j?(0,X.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,X.jsx)(s,{className:`size-4 animate-spin`}),n.loading]})}):c?(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,X.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.gateway}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,X.jsxs)(`a`,{href:qe(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,X.jsx)(N,{className:`size-3.5`})]})]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[v?(0,X.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,X.jsx)(E,{type:`button`,variant:`secondary`,disabled:!P||p,onClick:R,children:n.discard}),(0,X.jsx)(E,{type:`button`,variant:`primary`,disabled:!P||p,onClick:()=>void L(),children:p?n.saving:n.save})]})]}),i?(0,X.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,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(le,{className:`mt-0.5 size-4 shrink-0 text-red-600 dark:text-red-400`}),(0,X.jsx)(`p`,{className:`text-sm text-red-900 dark:text-red-100`,children:n.tokenExpired})]}),(0,X.jsx)(`div`,{children:(0,X.jsx)(E,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:()=>a(),children:n.updateToken})})]}):null,P?(0,X.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,g?(0,X.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:g}):null,c.auth.mode===`none`?(0,X.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,X.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[(0,X.jsxs)(`div`,{className:`mb-5 flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,X.jsx)(Oe,{className:`size-4 text-accent`,strokeWidth:1.75}),t.settingsSections.gateway]}),(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(c.host||c.port!=null)&&(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:n.listenHost}),(0,X.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,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:n.listenPort}),(0,X.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,X.jsx)(`p`,{className:`sm:col-span-2 text-xs text-fg-subtle`,children:n.listenHint})]}),(0,X.jsx)(An,{g:n,value:c.auth.token,show:b,copied:S,onToggleShow:()=>x(e=>!e),onCopy:()=>void z(),onChange:e=>F({token:e})}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,onClick:()=>a(),children:n.changeToken}),r?(0,X.jsx)(kn,{g:n,gatewayToken:r}):null,(0,X.jsxs)(`div`,{className:`space-y-2 border-t border-edge pt-4`,children:[(0,X.jsx)(`label`,{className:`text-sm font-medium text-fg`,htmlFor:`gateway-update-channel`,children:n.updateChannel}),(0,X.jsxs)(`select`,{id:`gateway-update-channel`,value:c.updateChannel,onChange:e=>I(e.target.value),className:Dn(),children:[(0,X.jsx)(`option`,{value:`stable`,children:n.channelStable}),(0,X.jsx)(`option`,{value:`beta`,children:n.channelBeta}),(0,X.jsx)(`option`,{value:`dev`,children:n.channelDev})]}),(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.updateChannelHint})]})]})]})]}):(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:g??M??n.loadError}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,onClick:()=>void k(),children:n.retry})]}):(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.gateway}),(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}function kn({g:e,gatewayToken:t}){let[n,r]=(0,Z.useState)(je),[i,a]=(0,Z.useState)(null),[o,s]=(0,Z.useState)(!1),[c,l]=(0,Z.useState)(!1),u=n.trim(),d=(0,Z.useMemo)(()=>{try{let e=new URL(u);return e.protocol===`http:`||e.protocol===`https:`}catch{return!1}},[u]),f=(0,Z.useMemo)(()=>!t||!d?``:ue({baseUrl:u,gatewayToken:t}),[d,t,u]);(0,Z.useEffect)(()=>{if(!f){a(null),s(!1);return}let e=!1;return s(!1),Cn.toDataURL(f,{width:216,margin:2,errorCorrectionLevel:`M`,color:{dark:`#000000ff`,light:`#ffffffff`}}).then(t=>{e||a(t)}).catch(()=>{e||(s(!0),a(null))}),()=>{e=!0}},[f]);let p=d&&Te(u),m=(0,Z.useCallback)(async()=>{f&&(await navigator.clipboard.writeText(f).catch(()=>{}),l(!0),window.setTimeout(()=>l(!1),2e3))},[f]);return(0,X.jsxs)(`div`,{className:`space-y-3 border-t border-edge pt-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,X.jsx)(ce,{className:`size-4 text-accent`,strokeWidth:1.75}),e.mobilePairTitle]}),(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.mobilePairSubtitle}),(0,X.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,X.jsx)(`label`,{className:`text-sm font-medium text-fg`,htmlFor:`gateway-mobile-pair-base`,children:e.mobilePairBaseUrlLabel}),(0,X.jsx)(`input`,{id:`gateway-mobile-pair-base`,className:w(Dn(),`font-mono text-xs`),type:`text`,autoComplete:`off`,spellCheck:!1,value:n,onChange:e=>r(e.target.value)}),(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.mobilePairBaseUrlHint}),d?null:(0,X.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:e.mobilePairInvalidBaseUrl}),p?(0,X.jsx)(`p`,{className:`rounded-lg border border-amber-200 bg-amber-50 px-3 py-2 text-xs text-amber-950 dark:border-amber-800 dark:bg-amber-950/40 dark:text-amber-100`,children:e.mobilePairLocalhostWarning}):null,(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.mobilePairSecurityNote})]}),f?(0,X.jsxs)(`div`,{className:`flex flex-col items-center gap-3 sm:items-start`,children:[i&&!o?(0,X.jsx)(`img`,{src:i,alt:``,className:`h-56 w-56 rounded-lg border border-edge-subtle bg-white object-contain p-3 dark:border-edge`}):null,!i&&!o?(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.mobilePairEncoding}):null,o?(0,X.jsx)(`p`,{className:`text-center text-sm text-fg-muted sm:text-left`,children:e.mobilePairImageError}):null,(0,X.jsxs)(E,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,disabled:!f,onClick:()=>void m(),children:[c?(0,X.jsx)(U,{className:`size-3.5`}):(0,X.jsx)(Pe,{className:`size-3.5`}),c?e.mobilePairCopied:e.mobilePairCopyLink]})]}):null,(0,X.jsx)(`p`,{className:`break-all font-mono text-[10px] leading-relaxed text-fg-subtle`,children:e.mobilePairSchemeHint})]})}function An({g:e,value:t,show:n,copied:r,onToggleShow:i,onCopy:a,onChange:o}){return(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.accessToken}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,X.jsx)(`input`,{className:w(Dn(),`min-w-0 flex-1 font-mono text-xs`),type:n?`text`:`password`,autoComplete:`off`,value:t,onChange:e=>o(e.target.value),placeholder:e.tokenPlaceholder}),t?(0,X.jsxs)(E,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:a,children:[r?(0,X.jsx)(U,{className:`size-3.5`}):(0,X.jsx)(Pe,{className:`size-3.5`}),r?e.copied:e.copy]}):null,(0,X.jsxs)(E,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:i,children:[n?(0,X.jsx)(re,{className:`size-3.5`}):(0,X.jsx)(ne,{className:`size-3.5`}),n?e.hide:e.show]})]}),(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tokenHelp})]})}function jn(){return K(`/api/channels/status`)}var Mn=at;function Nn(){return w(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,o,`dark:border-edge`)}function Pn(){return w(ve,g)}function Fn(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 In(){let e=f(e=>e.language),t=ge(e),n=t.heartbeatSettings,i=!!ze(e=>e.token),[a,o]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(``),[p,h]=(0,Z.useState)(``),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)(!1),[b,x]=(0,Z.useState)(null),[C,T]=(0,Z.useState)(!1),[D,O]=(0,Z.useState)(!1),[k,A]=(0,Z.useState)(!1),[j,M]=(0,Z.useState)(!1),[P,F]=(0,Z.useState)(null),[I,L]=(0,Z.useState)([]),{data:R,error:z,isLoading:ee,mutate:B}=m(i),{data:V,error:H,isLoading:te,mutate:ne}=r(i?jt():null,Ot,{revalidateOnFocus:!1}),{data:re=[]}=r(i?jn():null,Mn,{revalidateOnFocus:!1}),ie=(0,Z.useMemo)(()=>Fn(R?.payload?.config),[R]),U=(0,Z.useMemo)(()=>Pt(R?.payload?.config??{}),[R]),W=(0,Z.useMemo)(()=>!a||!c?!1:JSON.stringify(a)!==JSON.stringify(c),[a,c]),G=(0,Z.useMemo)(()=>u!==p,[u,p]);(0,Z.useEffect)(()=>{if(!i){o(null),l(null);return}if(R!==void 0&&!W){let e=structuredClone(U);o(e),l(e),T(!1)}},[i,R,U,W]),(0,Z.useEffect)(()=>{!i||V===void 0||G||(d(V),h(V),O(!1))},[i,V,G]);let ae=z instanceof Error?z.message:z?String(z):H instanceof Error?H.message:H?String(H):null,oe=!!(i&&(R===void 0||V===void 0)&&!ae&&(ee||te));(0,Z.useEffect)(()=>{if(!i||!a){L([]);return}let e=a.target.trim();if(!e){L([]);return}let t=!1;return rt(e).then(e=>{t||L(e)}),()=>{t=!0}},[i,a?.target]);let K=(0,Z.useCallback)(()=>{let e=a?.target?.trim();e&&rt(e).then(L)},[a?.target]),se=(0,Z.useCallback)(async()=>{A(!0),M(!1),F(null);try{await kt(),M(!0),window.setTimeout(()=>M(!1),3e3)}catch(e){F(e instanceof Error?e.message:n.triggerError)}finally{A(!1)}},[n.triggerError]),ce=(0,Z.useCallback)(e=>{o(t=>t?{...t,...e}:null)},[]),le=(0,Z.useCallback)(()=>{c&&(o(structuredClone(c)),T(!1),x(null))},[c]),ue=(0,Z.useCallback)(()=>{d(p),O(!1),x(null)},[p]),q=(0,Z.useCallback)(async()=>{if(!(!a||g)){_(!0),x(null),T(!1);try{await At(a),l(structuredClone(a)),T(!0),window.setTimeout(()=>T(!1),2500)}catch(e){x(e instanceof Error?e.message:n.saveConfigError)}finally{_(!1)}}},[a,g,n.saveConfigError]),de=(0,Z.useCallback)(async()=>{if(!v){y(!0),x(null),O(!1);try{await Mt(u),h(u),O(!0),window.setTimeout(()=>O(!1),2500)}catch(e){x(e instanceof Error?e.message:n.saveDocError)}finally{y(!1)}}},[u,v,n.saveDocError]);return i?oe?(0,X.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,X.jsx)(s,{className:`size-4 animate-spin`}),n.loading]})}):a?(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,X.jsx)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.heartbeat}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,X.jsxs)(`a`,{href:qe(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,X.jsx)(N,{className:`size-3.5`})]})]})}),ie?(0,X.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.workspaceLabel,`: `,(0,X.jsx)(`span`,{className:`font-mono text-fg-muted`,children:ie})]}):null,b?(0,X.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:b}):null,(0,X.jsxs)(Et,{children:[(0,X.jsxs)(`div`,{className:`mb-2 flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,X.jsx)(S,{className:`size-4 text-accent`,strokeWidth:1.75}),n.configSection]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsxs)(E,{type:`button`,variant:`secondary`,className:`inline-flex items-center gap-2`,disabled:k,onClick:()=>void se(),children:[k?(0,X.jsx)(s,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,X.jsx)(Be,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),k?n.triggering:n.triggerNow]}),j?(0,X.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.triggered}):null]})]}),(0,X.jsx)(`p`,{className:`mb-4 text-xs text-fg-subtle`,children:n.triggerHint}),P?(0,X.jsx)(`p`,{className:`mb-3 text-sm text-red-600 dark:text-red-400`,children:P}):null,(0,X.jsx)(Ln,{h:n,cron:t.cron,form:a,channels:re,sessionChatIds:I,onRefreshChatIds:K,update:ce,inputClassName:Nn,selectClassName:Pn}),(0,X.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-2`,children:[C?(0,X.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.savedConfig}):null,(0,X.jsx)(E,{type:`button`,variant:`secondary`,disabled:!W||g,onClick:le,children:n.discard}),(0,X.jsx)(E,{type:`button`,variant:`primary`,disabled:!W||g,onClick:()=>void q(),children:g?n.savingConfig:n.saveConfig}),W?(0,X.jsx)(`span`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedConfig}):null]})]}),(0,X.jsxs)(Et,{children:[(0,X.jsx)(`div`,{className:`mb-2 text-sm font-semibold text-fg`,children:n.docSection}),(0,X.jsx)(`p`,{className:`mb-3 text-xs text-fg-subtle`,children:n.docHint}),(0,X.jsx)(`textarea`,{className:w(Nn(),`min-h-[12rem] resize-y font-mono text-xs leading-relaxed`),value:u,onChange:e=>d(e.target.value),spellCheck:!1,"aria-label":n.docSection}),(0,X.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-2`,children:[D?(0,X.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.savedDoc}):null,(0,X.jsx)(E,{type:`button`,variant:`secondary`,disabled:!G||v,onClick:ue,children:n.discard}),(0,X.jsx)(E,{type:`button`,variant:`primary`,disabled:!G||v,onClick:()=>void de(),children:v?n.savingDoc:n.saveDoc}),G?(0,X.jsx)(`span`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedDoc}):null]})]})]}):(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:b??ae??n.loadError}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,onClick:()=>{B(),ne()},children:n.retry})]}):(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.heartbeat}),(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}function Ln({h:e,cron:t,form:n,channels:r,sessionChatIds:i,onRefreshChatIds:a,update:o,inputClassName:s,selectClassName:c}){let l=(0,Z.useMemo)(()=>new Set(r.map(e=>e.name)),[r]),u=n.target.trim(),d=!!(u&&!l.has(u));return(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,X.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:n.enabled,onChange:e=>o({enabled:e.target.checked})}),e.enable]}),(0,X.jsx)(on,{kind:`interval`,label:e.interval,valueMs:n.intervalMs,onChangeMs:e=>o({intervalMs:e}),labels:{secondsLabel:e.intervalSecondsLabel,presets:e.intervalPresets},hint:`${e.intervalHintPreset} ${e.intervalHint}`}),(0,X.jsxs)(`div`,{className:`border-t border-edge-subtle pt-4`,children:[(0,X.jsx)(`div`,{className:`mb-2 text-sm font-medium text-fg`,children:e.deliveryTitle}),(0,X.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,X.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:t.channel}),(0,X.jsxs)(`select`,{className:c(),value:u,onChange:e=>{o({target:e.target.value.trim(),targetChatId:``})},children:[(0,X.jsx)(`option`,{value:``,children:e.channelNone}),d?(0,X.jsxs)(`option`,{value:u,children:[u,` (`,e.customChannelSuffix,`)`]}):null,r.map(e=>(0,X.jsxs)(`option`,{value:e.name,disabled:!e.enabled,children:[e.name,` `,e.enabled?``:`(disabled)`]},e.name))]})]}),u?(0,X.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,X.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:t.recipient}),(0,X.jsxs)(E,{type:`button`,variant:`ghost`,className:`h-7 gap-1 px-2 text-xs`,title:t.refreshRecipientHint,onClick:a,children:[(0,X.jsx)(Me,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0}),t.refreshList]})]}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(`input`,{type:`text`,className:w(s(),`min-w-0 flex-1`),value:n.targetChatId,onChange:e=>o({targetChatId:e.target.value}),placeholder:t.recipientPlaceholder,autoComplete:`off`}),(0,X.jsxs)(`select`,{className:w(c(),`max-w-[10rem] shrink-0 text-xs`),value:n.targetChatId,onChange:e=>{let t=e.target.value;t&&o({targetChatId:t})},children:[(0,X.jsx)(`option`,{value:``,children:t.selectRecipient}),i.length>0?i.map(e=>(0,X.jsx)(`option`,{value:e.chatId,children:nt(e,t.lastActiveLabels)},`${e.channel}-${e.chatId}`)):(0,X.jsx)(`option`,{value:``,disabled:!0,children:t.noRecentChatsOption})]})]}),(0,X.jsx)(`p`,{className:`text-xs text-fg-muted`,children:i.length>0?t.enterManuallyOrSelect:t.noRecentChats})]}):null,(0,X.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:e.deliveryHint})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:e.prompt}),(0,X.jsx)(`textarea`,{className:w(s(),`min-h-[4.5rem] resize-y font-mono text-xs`),value:n.prompt,onChange:e=>o({prompt:e.target.value}),placeholder:e.promptPlaceholder}),(0,X.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:e.promptHint})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`mb-1 text-sm font-medium text-fg`,children:e.ackMaxChars}),(0,X.jsx)(`input`,{type:`number`,min:1,className:s(),value:n.ackMaxChars===``?``:n.ackMaxChars,onChange:e=>{let t=e.target.value;if(t===``)o({ackMaxChars:``});else{let e=parseInt(t,10);o({ackMaxChars:Number.isFinite(e)?e:``})}},placeholder:e.ackDefaultPlaceholder}),(0,X.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:e.ackMaxCharsHint})]}),(0,X.jsxs)(`label`,{className:`flex cursor-pointer items-start gap-2 text-sm text-fg`,children:[(0,X.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox mt-0.5`,checked:n.isolatedSession,onChange:e=>o({isolatedSession:e.target.checked})}),(0,X.jsxs)(`span`,{children:[e.isolatedSession,(0,X.jsx)(`span`,{className:`mt-1 block text-xs text-fg-subtle`,children:e.isolatedSessionHint})]})]}),(0,X.jsx)(`div`,{className:`border-t border-edge-subtle pt-4`,children:(0,X.jsx)(on,{kind:`active-hours`,label:e.activeHoursTitle,value:n.activeHours,onChange:e=>o({activeHours:e}),labels:{start:e.activeStart,end:e.activeEnd,timezone:e.activeTimezone,add:e.addActiveHours,clear:e.clearActiveHours},hint:e.activeHoursHint})})]})}async function Rn(){let e=await Y(K(`/api/image/providers`));if(!e.ok)throw Error(`Image providers: HTTP ${e.status}`);return(await e.json()).payload?.providers??[]}function zn(e){let t=new Set,n=[];for(let r of e){let e=r.models.length>0?r.models:r.defaultModel?[r.defaultModel]:[];for(let i of e){let e=`${r.id}/${i}`;t.has(e)||(t.add(e),n.push(e))}}return n}function Bn(e,t){let n=zn(e.filter(e=>e.configured===!0));return!t||n.includes(t)?n:[t,...n]}function Vn(e,t){let n=t.trim().toLowerCase();if(!n)return e;let r=n.split(/[/\s]+/).filter(Boolean);return e.filter(e=>{let t=e.toLowerCase();return r.every(e=>t.includes(e))})}var Hn=`image-generation-providers`;function Un({value:e,disabled:t,placeholder:n,searchPlaceholder:i,noMatches:a,registryEmptyHint:o,outOfFilterNote:s,className:c,onChange:l}){let[d,f]=(0,Z.useState)(!1),[p,m]=(0,Z.useState)(``),{data:h,isLoading:g,error:_}=r(Hn,Rn,{revalidateOnFocus:!1}),v=e.trim(),b=(0,Z.useMemo)(()=>zn((h??[]).filter(e=>e.configured===!0)),[h]),x=(0,Z.useMemo)(()=>Bn(h??[],v),[h,v]),S=(0,Z.useMemo)(()=>Vn(x,p),[x,p]),C=!!s&&!!v&&!b.includes(v),E=e.trim()?e:n,D=e.trim()||n,O=(0,Z.useCallback)(e=>{f(e),e||m(``)},[]);return(0,X.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,X.jsxs)(Xe,{open:d,onOpenChange:O,modal:!1,children:[(0,X.jsx)(u,{asChild:!0,children:(0,X.jsxs)(`button`,{type:`button`,disabled:t||g,title:g?`…`:D,className:w(ee,`items-center gap-2 rounded-lg border border-edge-subtle bg-surface-panel px-3 py-2 text-left text-sm font-normal text-fg`,H.transition,`hover:border-edge hover:bg-surface-hover/45`,k,`disabled:cursor-not-allowed disabled:opacity-50`,`dark:border-edge-subtle dark:hover:bg-surface-hover/55`,c),"aria-haspopup":`listbox`,"aria-expanded":d,children:[(0,X.jsx)(`span`,{className:`min-w-0 truncate`,children:g?`…`:E}),(0,X.jsx)(Ae,{className:`h-4 w-4 shrink-0 text-fg-subtle opacity-70`,"aria-hidden":!0})]})}),(0,X.jsx)(F,{children:(0,X.jsxs)(T,{className:w(`w-[min(22rem,calc(100vw-2rem))] rounded-xl border border-edge-subtle bg-surface-panel p-1 shadow-elevated dark:border-edge-subtle`,xe),side:`bottom`,sideOffset:4,align:`end`,onOpenAutoFocus:e=>e.preventDefault(),children:[(0,X.jsx)(`input`,{type:`search`,className:w(`mb-1 w-full rounded-lg border border-edge-subtle bg-surface-base px-2.5 py-1.5 text-sm text-fg placeholder:text-fg-disabled dark:bg-surface-hover/40`,y),placeholder:i,value:p,onChange:e=>m(e.target.value),onKeyDown:e=>e.stopPropagation()}),(0,X.jsxs)(`div`,{className:`max-h-60 overflow-auto`,role:`listbox`,"aria-label":i,children:[_?(0,X.jsx)(`div`,{className:`px-2 py-2 text-xs text-red-600 dark:text-red-400`,children:_ instanceof Error?_.message:`Failed to load image providers`}):null,!_&&x.length===0&&!g?(0,X.jsx)(`div`,{className:`px-2 py-3 text-center text-xs text-fg-muted`,children:o??a}):null,!_&&x.length>0&&S.length===0?(0,X.jsx)(`div`,{className:`px-2 py-3 text-center text-xs text-fg-muted`,children:a}):null,S.map(t=>(0,X.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t===e,className:w(`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-fg hover:bg-surface-hover`,t===e&&`bg-surface-hover/90 font-medium dark:bg-surface-hover/70`),onClick:()=>{l(t),f(!1),m(``)},children:[(0,X.jsx)(U,{className:w(`h-4 w-4 shrink-0`,t!==e&&`invisible`),"aria-hidden":!0}),(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm font-medium`,children:t})]},t))]})]})})]}),C?(0,X.jsx)(`p`,{className:`text-xs text-amber-700 dark:text-amber-400/90`,children:s}):null]})}function Wn(e){let{a:t,chat:n,form:r,update:i}=e;return(0,X.jsxs)(Et,{children:[(0,X.jsx)(ct,{icon:V,title:t.cardModelsTitle,subtitle:t.cardModelsSubtitle}),(0,X.jsxs)(`div`,{className:`mt-4 flex flex-col gap-5`,children:[(0,X.jsx)(ut,{label:t.label.imageModel,description:t.desc.imageModel,children:(0,X.jsx)(W,{value:r.imageModel,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,capabilitiesFilter:`vision`,registryEmptyHint:t.visionRegistryEmpty,outOfFilterNote:t.visionOutOfFilterNote,onChange:e=>i({imageModel:e})})}),(0,X.jsx)(ut,{label:t.label.imageModelFallbacks,description:t.desc.imageModelFallbacks,children:(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[r.imageModelFallbacks.map((e,a)=>(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,X.jsx)(W,{value:e,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,capabilitiesFilter:`vision`,registryEmptyHint:t.visionRegistryEmpty,outOfFilterNote:t.visionOutOfFilterNote,onChange:e=>{let t=[...r.imageModelFallbacks];t[a]=e,i({imageModelFallbacks:t})}})}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":t.removeModelFallback,onClick:()=>i({imageModelFallbacks:r.imageModelFallbacks.filter((e,t)=>t!==a)}),children:(0,X.jsx)(Ne,{className:`size-4`,strokeWidth:1.75})})]},a)),(0,X.jsxs)(E,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:()=>i({imageModelFallbacks:[...r.imageModelFallbacks,``]}),children:[(0,X.jsx)(me,{className:`size-4 shrink-0`,strokeWidth:1.75}),t.addModelFallback]})]})}),(0,X.jsx)(ut,{label:t.label.imageGenerationModel,description:t.desc.imageGenerationModel,children:(0,X.jsx)(Un,{value:r.imageGenerationModel,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,registryEmptyHint:t.imageGenRegistryEmpty,outOfFilterNote:t.imageGenOutOfFilterNote,onChange:e=>i({imageGenerationModel:e})})}),(0,X.jsx)(ut,{label:t.label.imageGenerationModelFallbacks,description:t.desc.imageGenerationModelFallbacks,children:(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[r.imageGenerationModelFallbacks.map((e,a)=>(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,X.jsx)(Un,{value:e,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,registryEmptyHint:t.imageGenRegistryEmpty,outOfFilterNote:t.imageGenOutOfFilterNote,onChange:e=>{let t=[...r.imageGenerationModelFallbacks];t[a]=e,i({imageGenerationModelFallbacks:t})}})}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":t.removeModelFallback,onClick:()=>i({imageGenerationModelFallbacks:r.imageGenerationModelFallbacks.filter((e,t)=>t!==a)}),children:(0,X.jsx)(Ne,{className:`size-4`,strokeWidth:1.75})})]},a)),(0,X.jsxs)(E,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:()=>i({imageGenerationModelFallbacks:[...r.imageGenerationModelFallbacks,``]}),children:[(0,X.jsx)(me,{className:`size-4 shrink-0`,strokeWidth:1.75}),t.addModelFallback]})]})})]})]})}function Gn(){return w(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,o)}var Kn=()=>K(Ze);function qn(e){return{imageModel:e.imageModel,imageModelFallbacks:e.imageModelFallbacks,imageGenerationModel:e.imageGenerationModel,imageGenerationModelFallbacks:e.imageGenerationModelFallbacks,imageGenerationModelTimeoutMs:e.imageGenerationModelTimeoutMs,imageGenerationModelAutoProviderFallback:e.imageGenerationModelAutoProviderFallback}}function Jn(e){return{credentialsIntro:e.credentialsIntro,regionHint:e.regionHint,endpointPresetsHint:e.endpointPresetsHint,apiKeyLabel:e.apiKeyLabel,optionalPlaceholder:e.optionalPlaceholder,regionLabel:e.regionLabel,baseUrlLabel:e.baseUrlLabel,imageBaseUrlLabel:e.imageBaseUrlLabel,saveCredentials:e.saveCredentials,savingCredentials:e.savingCredentials,credentialsSaved:e.credentialsSaved,discardCredentials:e.discardCredentials,credentialsNothingToSave:e.credentialsNothingToSave,credentialsSaveError:e.credentialsSaveError,regionPresetDefault:e.regionPresetDefault,regionPresetCustom:e.regionPresetCustom,baseUrlPresetDefault:e.baseUrlPresetDefault,baseUrlPresetCustom:e.baseUrlPresetCustom,openExtensionSettings:e.openExtensionSettings,openImageModelsPage:e.openImageModelsPage,extensionSettingsLinkTitle:e.extensionSettingsLinkTitle,imageModelsLinkTitle:e.imageModelsLinkTitle,configured:e.configured,missingKey:e.missingKey,defaultModel:e.defaultModel,modelsLabel:e.modelsLabel,imageBaseUrlPresetHint:e.imageBaseUrlPresetHint,dashscopeRegion_beijing:e.dashscopeRegion_beijing,dashscopeRegion_singapore:e.dashscopeRegion_singapore,dashscopeRegion_us:e.dashscopeRegion_us,apiKeyMaskedHelp:e.apiKeyMaskedHelp,apiKeyCopy:e.apiKeyCopy,apiKeyCopied:e.apiKeyCopied,apiKeyShow:e.apiKeyShow,apiKeyHide:e.apiKeyHide,apiKeyNotInConfigFile:e.apiKeyNotInConfigFile,apiKeyRevealFailed:e.apiKeyRevealFailed,minimaxClusterLabel:e.minimaxClusterLabel,minimaxClusterHint:e.minimaxClusterHint,falQueueBaseLabel:e.falQueueBaseLabel,falQueueBaseHint:e.falQueueBaseHint}}function Yn(){let e=f(e=>e.language),t=ge(e),n=t.imageModelsSettings,i=!!ze(e=>e.token),[a,o]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(!0),[p,h]=(0,Z.useState)(!1),[g,_]=(0,Z.useState)(!1),[v,y]=(0,Z.useState)(void 0),b=Se(),x=(0,Z.useMemo)(()=>new Set(b.map(e=>e.id)),[b]),S=(0,Z.useCallback)(async()=>{if(i){d(!0),y(void 0);try{let e=await lt(),t=structuredClone(e);o(t),l(structuredClone(t))}catch(e){y(e instanceof Error?e.message:String(e))}finally{d(!1)}}},[i]);(0,Z.useEffect)(()=>{S()},[S]);let C=(0,Z.useCallback)(e=>{o(t=>t?{...t,...e}:null)},[]),{data:T=[],mutate:D}=r(i?Kn():null,$e,{revalidateOnFocus:!1}),O=m(i),k=et(T),A=(0,Z.useMemo)(()=>!a||!c?!1:JSON.stringify(qn(a))!==JSON.stringify(qn(c)),[a,c]),j=A||k.credDirty;(0,Z.useEffect)(()=>{if(!j)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[j]);let M=(0,Z.useCallback)(async()=>{if(a){h(!0),y(void 0);try{try{ht(a.paramsJson)}catch(e){y(e instanceof SyntaxError?t.agentSettings.advanced.paramsInvalidJson:e instanceof Error?e.message:t.agentSettings.advanced.paramsInvalidJson);return}await Ct(a),l(structuredClone(a)),_(!0),window.setTimeout(()=>_(!1),1500),O.mutate?.()}catch(e){y(e instanceof Error?e.message:String(e))}finally{h(!1)}}},[a,O,t.agentSettings]),N=(0,Z.useCallback)(()=>{c&&(o(structuredClone(c)),y(void 0),_(!1))},[c]),P=(0,Z.useMemo)(()=>Jn(n),[n]),F=(0,Z.useMemo)(()=>({getApiKey:t.providersSettings.getApiKey,getApiKeyIntl:t.providersSettings.getApiKeyIntl,getApiKeyCn:t.providersSettings.getApiKeyCn}),[t.providersSettings]);return i?u||!a?(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main items-center gap-2 px-4 py-8 text-sm text-fg-muted`,children:[(0,X.jsx)(s,{className:`size-4 animate-spin`}),` Loading…`]}):(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[(0,X.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.title}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle})]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[(0,X.jsxs)(E,{type:`button`,variant:`ghost`,onClick:()=>{S(),D(),O.mutate?.()},children:[(0,X.jsx)(Me,{className:`size-3.5`}),(0,X.jsx)(`span`,{className:`ml-1.5`,children:n.refresh})]}),g?(0,X.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,X.jsx)(E,{type:`button`,variant:`secondary`,onClick:N,disabled:!A||p,children:n.discard}),(0,X.jsxs)(E,{type:`button`,variant:`primary`,onClick:()=>void M(),disabled:!A||p,children:[p?(0,X.jsx)(s,{className:`size-3.5 animate-spin`}):(0,X.jsx)(q,{className:`size-3.5`}),(0,X.jsx)(`span`,{className:`ml-1.5`,children:p?n.saving:n.save})]})]})]}),v?(0,X.jsx)(`div`,{className:`rounded-lg border border-red-500/30 bg-red-500/10 px-3 py-2 text-sm text-red-700 dark:text-red-300`,children:v}):null,(0,X.jsx)(Wn,{form:a,update:C,a:t.agentSettings,chat:t.chat}),(0,X.jsxs)(Et,{children:[(0,X.jsx)(ct,{icon:V,title:n.title,subtitle:n.subtitle}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,X.jsx)(`div`,{className:`rounded-lg border border-edge-subtle bg-surface-base px-3 py-2.5 text-xs leading-relaxed text-fg-muted`,children:n.crossLinkHint}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)(`label`,{className:`text-sm font-medium text-fg`,children:n.timeoutLabel}),(0,X.jsx)(`input`,{type:`number`,min:0,step:1e3,className:w(Gn(),`max-w-[12rem]`),value:a.imageGenerationModelTimeoutMs??``,placeholder:`120000`,onChange:e=>{let t=e.target.value.trim(),n=t===``?null:Math.max(0,Math.floor(Number(t)));o(e=>e?{...e,imageGenerationModelTimeoutMs:n&&n>0?n:null}:null)}}),(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:n.timeoutHint})]}),(0,X.jsxs)(`label`,{className:`flex items-start gap-3 text-sm`,children:[(0,X.jsx)(`input`,{type:`checkbox`,className:`mt-0.5`,checked:a.imageGenerationModelAutoProviderFallback,onChange:e=>o(t=>t?{...t,imageGenerationModelAutoProviderFallback:e.target.checked}:null)}),(0,X.jsxs)(`span`,{className:`flex flex-col gap-0.5`,children:[(0,X.jsx)(`span`,{className:`font-medium text-fg`,children:n.autoFallbackLabel}),(0,X.jsx)(`span`,{className:`text-xs text-fg-subtle`,children:n.autoFallbackHint})]})]})]})]}),(0,X.jsxs)(Et,{children:[(0,X.jsx)(ct,{icon:Oe,title:n.providersTitle,subtitle:``}),T.length===0?(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.providersEmpty}):(0,X.jsx)(Qe,{summaries:T,credDraft:k.credDraft,credDirty:k.credDirty,credSaving:k.credSaving,credError:k.credError,credSavedFlash:k.credSavedFlash,credNoopFlash:k.credNoopFlash,updateCredRow:k.updateCredRow,onDiscardCredentials:k.onDiscardCredentials,onSaveCredentials:()=>void k.saveCredentials(n.credentialsSaveError),extensionIds:x,showExtensionLinks:!0,showImageModelsLink:!1,language:e,apiKeyLinkLabels:F,messages:P})]})]}):(0,X.jsx)(`div`,{className:`mx-auto w-full max-w-app-main px-4 py-8 text-sm text-fg-muted`,children:e===`zh`?`请先登录网关。`:`Connect to a gateway to continue.`})}var Xn=[{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 Zn(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 Qn(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 $n(){let e=await Y(K(`/api/models-json`)),t=await e.json().catch(()=>({}));if(!e.ok||!t.ok||!t.payload)throw Error(Zn(t)||`HTTP ${e.status}`);return{...t.payload,config:Qn(t.payload.config)}}async function er(e){let t=await Y(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(Zn(n)||`HTTP ${t.status}`);return n.payload}async function tr(e){let t=await Y(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(Zn(n)||`HTTP ${t.status}`);return n.payload}async function nr(){let e=await Y(K(`/api/models-json/reload`),{method:`POST`}),t=await e.json().catch(()=>({}));if(!e.ok||!t.ok||!t.payload)throw Error(Zn(t)||`HTTP ${e.status}`);return t.payload}async function rr(e){let t=await Y(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(Zn(n)||`HTTP ${t.status}`);return n.payload}function ir(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 ar(e){return e.startsWith(`!`)}function or(e){return/^[A-Z][A-Z0-9_]*$/.test(e)}function sr(e){return ar(e)?`shell`:or(e)?`env`:`literal`}function cr(e){return e?e.length<=8?`••••`:`${e.slice(0,4)}••••${e.slice(-4)}`:``}function lr(e){let{a:t,chat:n,form:r,update:i}=e;return(0,X.jsxs)(Et,{children:[(0,X.jsx)(ct,{icon:Ee,title:t.label.modelFallbacks,subtitle:t.desc.modelFallbacks}),(0,X.jsxs)(`div`,{className:`mt-4 flex flex-col gap-2`,children:[r.modelFallbacks.map((e,a)=>(0,X.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,X.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,X.jsx)(W,{value:e,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,onChange:e=>{let t=[...r.modelFallbacks];t[a]=e,i({modelFallbacks:t})}})}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":t.removeModelFallback,onClick:()=>i({modelFallbacks:r.modelFallbacks.filter((e,t)=>t!==a)}),children:(0,X.jsx)(Ne,{className:`size-4`,strokeWidth:1.75})})]},a)),(0,X.jsxs)(E,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:()=>i({modelFallbacks:[...r.modelFallbacks,``]}),children:[(0,X.jsx)(me,{className:`size-4 shrink-0`,strokeWidth:1.75}),t.addModelFallback]})]})]})}var ur={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 dr(e){return e===`openrouter`?`openrouter`:e===`zhipuCn`?`zhipu-cn`:e===`zaiGeneral`?`zai`:e}var fr=[{value:`text`,labelKey:`inputTextOnly`},{value:`text,image`,labelKey:`inputTextVision`}];function pr(){return w(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,o,`dark:border-edge`)}function mr(){return w(ve,g)}function hr(e){return(e.input||[`text`]).includes(`image`)?`text,image`:`text`}function gr(e){return e===`text,image`?[`text`,`image`]:[`text`]}function _r(e,t,n){return{...e,providers:{...e.providers,[t]:{...e.providers[t],...n}}}}function vr(e,t){let n={...e.providers};return delete n[t],{...e,providers:n}}function yr(e,t,n){return{...e,providers:{...e.providers,[t]:n}}}function br({open:e,onOpenChange:t,providerId:n,model:r,isNew:i,onSave:a,m:o}){let[s,c]=(0,Z.useState)(()=>ir(``)),[l,u]=(0,Z.useState)(()=>new Map);(0,Z.useEffect)(()=>{e&&(u(new Map),c(r?{...r}:ir(``)))},[e,r]);let d=(e,t)=>{c(n=>({...n,[e]:t})),u(t=>{let n=new Map(t);return n.delete(e),n})},f=()=>{let e=new Map;return(s.id||``).trim()||e.set(`id`,o.modelIdRequired),s.contextWindow!==void 0&&s.contextWindow<=0&&e.set(`contextWindow`,o.mustBePositive),s.maxTokens!==void 0&&s.maxTokens<=0&&e.set(`maxTokens`,o.mustBePositive),u(e),e.size===0},p=()=>{if(!f())return;let e=(s.id||``).trim();a({...s,id:e,name:s.name?.trim()||e,reasoning:s.reasoning||!1,input:s.input||[`text`],contextWindow:s.contextWindow??128e3,maxTokens:s.maxTokens??16384,cost:{input:s.cost?.input??0,output:s.cost?.output??0,cacheRead:s.cost?.cacheRead??0,cacheWrite:s.cost?.cacheWrite??0}}),t(!1)},m=hr(s);return(0,X.jsx)(O,{open:e,onOpenChange:t,children:(0,X.jsxs)(D,{children:[(0,X.jsx)(_e,{className:w(`xopc-dialog-overlay fixed inset-0 bg-scrim`,ae)}),(0,X.jsxs)(be,{className:w(`xopc-dialog-content fixed left-1/2 top-1/2 max-h-[min(90vh,720px)] w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2`,De,`overflow-y-auto rounded-xl border border-edge bg-surface-panel p-4 shadow-popover dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,X.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(M,{className:`text-base font-semibold text-fg`,children:i?o.addModelTitle:o.editModelTitle}),n?(0,X.jsxs)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:[o.modelProviderLabel,`: `,n]}):null]}),(0,X.jsx)(j,{asChild:!0,children:(0,X.jsx)(`button`,{type:`button`,className:`rounded-lg p-1.5 text-fg-muted hover:bg-surface-base hover:text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,"aria-label":o.close,children:(0,X.jsx)(Je,{className:`size-4`})})})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`label`,{className:`mb-1 block text-xs font-medium text-fg`,children:[o.modelId,(0,X.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,X.jsx)(`input`,{className:w(pr(),l.has(`id`)&&`border-red-500`),value:s.id||``,onChange:e=>d(`id`,e.target.value),placeholder:`e.g. llama3.1:8b`,disabled:!i}),l.has(`id`)?(0,X.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:l.get(`id`)}):null]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:o.displayName}),(0,X.jsx)(`input`,{className:pr(),value:s.name||``,onChange:e=>d(`name`,e.target.value)})]}),(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:o.inputTypes}),(0,X.jsx)(`select`,{className:mr(),value:m,onChange:e=>d(`input`,gr(e.target.value)),children:fr.map(e=>(0,X.jsx)(`option`,{value:e.value,children:o[e.labelKey]},e.value))})]}),(0,X.jsxs)(`label`,{className:`mt-6 flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,X.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:s.reasoning||!1,onChange:e=>d(`reasoning`,e.target.checked)}),o.reasoning]})]}),(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:o.contextWindow}),(0,X.jsx)(`input`,{type:`number`,min:1,className:w(pr(),l.has(`contextWindow`)&&`border-red-500`),value:s.contextWindow??128e3,onChange:e=>d(`contextWindow`,parseInt(e.target.value,10)||0)}),l.has(`contextWindow`)?(0,X.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:l.get(`contextWindow`)}):null]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:o.maxOutputTokens}),(0,X.jsx)(`input`,{type:`number`,min:1,className:w(pr(),l.has(`maxTokens`)&&`border-red-500`),value:s.maxTokens??16384,onChange:e=>d(`maxTokens`,parseInt(e.target.value,10)||0)}),l.has(`maxTokens`)?(0,X.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:l.get(`maxTokens`)}):null]})]}),(0,X.jsxs)(`div`,{className:`border-t border-edge-subtle pt-2 dark:border-edge`,children:[(0,X.jsx)(`p`,{className:`mb-2 text-xs font-semibold text-fg`,children:o.costSection}),(0,X.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:o.costInput}),(0,X.jsx)(`input`,{type:`number`,step:`any`,min:0,className:pr(),value:s.cost?.input??0,onChange:e=>d(`cost`,{...s.cost,input:parseFloat(e.target.value)||0,output:s.cost?.output??0,cacheRead:s.cost?.cacheRead??0,cacheWrite:s.cost?.cacheWrite??0})})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:o.costOutput}),(0,X.jsx)(`input`,{type:`number`,step:`any`,min:0,className:pr(),value:s.cost?.output??0,onChange:e=>d(`cost`,{...s.cost,input:s.cost?.input??0,output:parseFloat(e.target.value)||0,cacheRead:s.cost?.cacheRead??0,cacheWrite:s.cost?.cacheWrite??0})})]})]})]})]}),(0,X.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2 border-t border-edge-subtle pt-3 dark:border-edge`,children:[(0,X.jsx)(j,{asChild:!0,children:(0,X.jsx)(E,{type:`button`,variant:`secondary`,children:o.cancel})}),(0,X.jsx)(E,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:p,children:i?o.addModelConfirm:o.saveModelConfirm})]})]})]})})}function xr({open:e,onOpenChange:t,presetKey:n,onConfirm:r,m:i}){let[a,o]=(0,Z.useState)(``),[s,c]=(0,Z.useState)(`custom`),[l,u]=(0,Z.useState)(``),[d,f]=(0,Z.useState)(`openai-completions`),[p,m]=(0,Z.useState)(``),[h,g]=(0,Z.useState)(null);(0,Z.useEffect)(()=>{if(!e)return;g(null);let t=n||null;if(t&&ur[t]){let e=ur[t];c(t),u(e.baseUrl||``),f(e.api||`openai-completions`),m(e.apiKey??``),o(dr(t))}else c(`custom`),o(``),u(``),f(`openai-completions`),m(``)},[e,n]);let _=e=>{if(c(e),e===`custom`)return;let t=ur[e];t&&(u(t.baseUrl||``),f(t.api||`openai-completions`),m(t.apiKey??``),o(dr(e)))};return(0,X.jsx)(O,{open:e,onOpenChange:t,children:(0,X.jsxs)(D,{children:[(0,X.jsx)(_e,{className:w(`xopc-dialog-overlay fixed inset-0 bg-scrim`,ae)}),(0,X.jsxs)(be,{className:w(`xopc-dialog-content fixed left-1/2 top-1/2 max-h-[min(90vh,640px)] w-[min(100%-2rem,32rem)] -translate-x-1/2 -translate-y-1/2`,De,`overflow-y-auto rounded-xl border border-edge bg-surface-panel p-4 shadow-popover dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,X.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(M,{className:`text-base font-semibold text-fg`,children:i.addProviderTitle}),(0,X.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:i.addProviderSubtitle})]}),(0,X.jsx)(j,{asChild:!0,children:(0,X.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,X.jsx)(Je,{className:`size-4`})})})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:i.presetLabel}),(0,X.jsxs)(`select`,{className:mr(),value:s,onChange:e=>_(e.target.value),children:[(0,X.jsx)(`option`,{value:`custom`,children:i.presetCustom}),(0,X.jsx)(`option`,{value:`ollama`,children:i.presetOllama}),(0,X.jsx)(`option`,{value:`lmstudio`,children:i.presetLmStudio}),(0,X.jsx)(`option`,{value:`openrouter`,children:i.presetOpenRouter}),(0,X.jsx)(`option`,{value:`zhipuCn`,children:i.presetZhipuCn}),(0,X.jsx)(`option`,{value:`zaiGeneral`,children:i.presetZaiGeneral})]})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsxs)(`label`,{className:`mb-1 block text-xs font-medium text-fg`,children:[i.providerIdLabel,(0,X.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,X.jsx)(`input`,{className:pr(),value:a,onChange:e=>o(e.target.value),placeholder:i.providerIdPlaceholder})]}),(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:i.baseUrl}),(0,X.jsx)(`input`,{className:pr(),value:l,onChange:e=>u(e.target.value),placeholder:`https://…`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:i.apiType}),(0,X.jsx)(`select`,{className:mr(),value:d,onChange:e=>f(e.target.value),children:Xn.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:i.apiKey}),(0,X.jsx)(`input`,{className:pr(),value:p,onChange:e=>m(e.target.value),placeholder:i.apiKeyPlaceholder})]}),h?(0,X.jsxs)(`p`,{className:`flex items-center gap-1 text-xs text-red-600 dark:text-red-400`,children:[(0,X.jsx)(le,{className:`size-3.5 shrink-0`}),h]}):null]}),(0,X.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2 border-t border-edge-subtle pt-3 dark:border-edge`,children:[(0,X.jsx)(j,{asChild:!0,children:(0,X.jsx)(E,{type:`button`,variant:`secondary`,children:i.cancel})}),(0,X.jsx)(E,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:()=>{let e=a.trim();if(!e){g(i.providerIdRequired);return}g(null),r(e,{baseUrl:l.trim()||void 0,api:d,apiKey:p.trim()||void 0,models:[]}),t(!1)},children:i.addProviderConfirm})]})]})]})})}function Sr({config:e,setConfig:t,expanded:n,toggleExpand:r,showPw:i,toggleShowPw:a,testResults:o,runTestKey:s,ms:c,removeProv:l,openModelDialog:u,setTestResults:d}){return(0,X.jsx)(`div`,{className:`flex flex-col gap-3`,children:Object.entries(e.providers).sort(([e],[t])=>e.localeCompare(t)).map(([e,f])=>{let p=n.has(e),m=f.models?.length??0,h=f.apiKey?sr(f.apiKey):null,g=o.get(e),_=i.has(e);return(0,X.jsxs)(`section`,{className:`overflow-hidden rounded-2xl bg-surface-base`,children:[(0,X.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,X.jsxs)(`button`,{type:`button`,className:`flex min-w-0 flex-1 items-center gap-2 text-left text-sm font-semibold text-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,onClick:()=>r(e),children:[p?(0,X.jsx)(fe,{className:`size-4 shrink-0 text-fg-muted`}):(0,X.jsx)(we,{className:`size-4 shrink-0 text-fg-muted`}),(0,X.jsx)(`span`,{className:`truncate`,children:e}),m>0?(0,X.jsx)(`span`,{className:`shrink-0 rounded-full bg-accent px-2 py-0.5 text-[10px] font-medium text-white`,children:m}):null,h?(0,X.jsx)(`span`,{className:w(`shrink-0 rounded-full px-2 py-0.5 text-[10px] font-medium`,h===`shell`&&`bg-blue-100 text-blue-800 dark:bg-blue-950 dark:text-blue-200`,h===`env`&&`bg-emerald-100 text-emerald-800 dark:bg-emerald-950 dark:text-emerald-200`,h===`literal`&&`bg-surface-hover text-fg-muted dark:bg-surface-active`),children:h===`shell`?c.badgeShell:h===`env`?c.badgeEnv:c.badgeLiteral}):null]}),(0,X.jsx)(`button`,{type:`button`,className:`rounded-lg p-1.5 text-fg-muted hover:bg-surface-base hover:text-red-600 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40 dark:hover:text-red-400`,onClick:()=>l(e),"aria-label":c.removeProvider,children:(0,X.jsx)(Ne,{className:`size-4`})})]}),p?(0,X.jsxs)(`div`,{className:`space-y-4 px-3 py-3`,children:[(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:c.baseUrl}),(0,X.jsx)(`input`,{className:pr(),value:f.baseUrl||``,onChange:n=>t(t=>_r(t,e,{baseUrl:n.target.value}))})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:c.apiType}),(0,X.jsx)(`select`,{className:mr(),value:f.api||`openai-completions`,onChange:n=>t(t=>_r(t,e,{api:n.target.value})),children:Xn.map(e=>(0,X.jsx)(`option`,{value:e.value,children:e.label},e.value))})]})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:c.apiKey}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,X.jsx)(`input`,{className:w(pr(),`min-w-0 flex-1`),type:_?`text`:`password`,autoComplete:`off`,value:f.apiKey||``,onChange:n=>{let r=n.target.value;t(t=>_r(t,e,{apiKey:r})),d(t=>{let n=new Map(t);return n.delete(e),n})},placeholder:c.apiKeyPlaceholder}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>a(e),children:_?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(re,{className:`mr-1 size-3.5`}),c.hide]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(ne,{className:`mr-1 size-3.5`}),c.show]})}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>s(e,f.apiKey||``),children:c.testKey})]}),g?(0,X.jsx)(`p`,{className:w(`mt-1 text-xs`,g.error?`text-red-600 dark:text-red-400`:`text-emerald-700 dark:text-emerald-400`),children:g.error?`${c.testError}: ${g.error}`:`${c.testOk} (${g.type}): ${cr(g.resolved||``)}`}):null,(0,X.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:c.apiKeyHint})]}),(0,X.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,X.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:f.authHeader||!1,onChange:n=>t(t=>_r(t,e,{authHeader:n.target.checked}))}),c.authHeader]}),(0,X.jsxs)(`div`,{className:`border-t border-edge-subtle pt-3 dark:border-edge`,children:[(0,X.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-semibold text-fg`,children:c.modelsSection}),(0,X.jsxs)(E,{type:`button`,variant:`primary`,className:`px-2 py-1 text-xs`,onClick:()=>u(e,null,!0),children:[(0,X.jsx)(me,{className:`mr-1 size-3.5`}),c.addModel]})]}),(f.models||[]).length===0?(0,X.jsx)(`p`,{className:`text-xs text-fg-muted`,children:c.modelsEmpty}):(0,X.jsx)(`ul`,{className:`space-y-2`,children:(f.models||[]).map(n=>(0,X.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,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`div`,{className:`truncate text-sm font-medium text-fg`,children:n.id}),n.name&&n.name!==n.id?(0,X.jsx)(`div`,{className:`truncate text-xs text-fg-muted`,children:n.name}):null]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 gap-1`,children:[(0,X.jsx)(`button`,{type:`button`,className:`rounded-lg p-1.5 text-fg-muted hover:bg-surface-panel hover:text-fg`,onClick:()=>u(e,n,!1),"aria-label":c.editModel,children:(0,X.jsx)(We,{className:`size-4`})}),(0,X.jsx)(`button`,{type:`button`,className:`rounded-lg p-1.5 text-fg-muted hover:bg-surface-panel hover:text-red-600 dark:hover:text-red-400`,onClick:()=>{window.confirm(c.removeModelConfirm.replace(`{{id}}`,n.id))&&t(t=>{let r=t.providers[e];return r?_r(t,e,{models:(r.models||[]).filter(e=>e.id!==n.id)}):t})},"aria-label":c.removeModel,children:(0,X.jsx)(Ne,{className:`size-4`})})]})]},n.id))})]})]}):null]},e)})})}function Cr({ms:e,openAddProvider:t}){return(0,X.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,X.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,X.jsx)(Ee,{className:`size-7 text-accent`,strokeWidth:1.5})}),(0,X.jsx)(`h2`,{className:`mb-1 text-base font-semibold text-fg`,children:e.emptyTitle}),(0,X.jsx)(`p`,{className:`mb-6 max-w-md text-sm text-fg-muted`,children:e.emptyDesc}),(0,X.jsxs)(E,{type:`button`,className:`mb-6 bg-accent text-white hover:bg-accent/90`,onClick:()=>t(null),children:[(0,X.jsx)(me,{className:`mr-1 size-4`}),e.emptyCta]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap justify-center gap-2`,children:[(0,X.jsxs)(`button`,{type:`button`,className:w(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,H.transition,H.focusRingBase),onClick:()=>t(`ollama`),children:[(0,X.jsx)(P,{className:`size-3.5`,"aria-hidden":!0}),e.presetOllama]}),(0,X.jsxs)(`button`,{type:`button`,className:w(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,H.transition,H.focusRingBase),onClick:()=>t(`openrouter`),children:[(0,X.jsx)(Ke,{className:`size-3.5`,"aria-hidden":!0}),e.presetOpenRouter]}),(0,X.jsxs)(`button`,{type:`button`,className:w(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,H.transition,H.focusRingBase),onClick:()=>t(`lmstudio`),children:[(0,X.jsx)(Ee,{className:`size-3.5`,"aria-hidden":!0}),e.presetLmStudio]}),(0,X.jsxs)(`button`,{type:`button`,className:w(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,H.transition,H.focusRingBase),onClick:()=>t(`zhipuCn`),children:[(0,X.jsx)(P,{className:`size-3.5`,"aria-hidden":!0}),e.presetZhipuCn]}),(0,X.jsxs)(`button`,{type:`button`,className:w(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,H.transition,H.focusRingBase),onClick:()=>t(`zaiGeneral`),children:[(0,X.jsx)(Ke,{className:`size-3.5`,"aria-hidden":!0}),e.presetZaiGeneral]})]})]})}function wr(){let e=f(e=>e.language),t=ge(e),n=t.modelsSettings,r=xt(t.agentSettings),i=!!ze(e=>e.token),[a,o]=(0,Z.useState)({providers:{}}),[c,l]=(0,Z.useState)({providers:{}}),[u,d]=(0,Z.useState)(``),[p,m]=(0,Z.useState)(),[h,g]=(0,Z.useState)(!0),[_,v]=(0,Z.useState)(!1),[y,b]=(0,Z.useState)(!1),[x,S]=(0,Z.useState)(!1),[C,T]=(0,Z.useState)(null),[D,O]=(0,Z.useState)(!1),[k,A]=(0,Z.useState)(null),[j,M]=(0,Z.useState)(()=>new Set),[P,F]=(0,Z.useState)(!1),[I,L]=(0,Z.useState)(``),[R,z]=(0,Z.useState)(null),[ee,B]=(0,Z.useState)(()=>new Set),[V,H]=(0,Z.useState)(()=>new Map),[te,ne]=(0,Z.useState)(!1),[re,ie]=(0,Z.useState)(null),[U,W]=(0,Z.useState)(!1),[G,ae]=(0,Z.useState)(null),oe=(0,Z.useCallback)(async e=>{let t=!e?.skipFullPageLoading;t&&g(!0),T(null);try{let e=await $n(),t=Qn(e.config);o(t),l(structuredClone(t)),d(e.path),m(e.loadError),A(null),O(!1)}catch(e){T(e instanceof Error?e.message:n.loadError),o({providers:{}}),l({providers:{}})}finally{t&&g(!1)}},[n.loadError]);(0,Z.useEffect)(()=>{if(!i){g(!1);return}oe()},[i,oe]);let K=(0,Z.useMemo)(()=>JSON.stringify(a)!==JSON.stringify(c),[a,c]),se=(0,Z.useMemo)(()=>r.form?{form:r.form,update:r.update,a:t.agentSettings,chat:t.chat}:null,[r.form,r.update,t.agentSettings,t.chat]),ce=K||r.dirty,ue=(0,Z.useMemo)(()=>{let e=Object.keys(a.providers),t=0;for(let e of Object.values(a.providers))t+=e.models?.length??0;return{providers:e.length,models:t}},[a.providers]),q=e=>{M(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},de=e=>{B(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},fe=(0,Z.useCallback)(()=>{L(JSON.stringify(a,null,2)),z(null)},[a]);(0,Z.useEffect)(()=>{P&&fe()},[P,fe]);let J=()=>{try{o(Qn(JSON.parse(I))),z(null)}catch{z(n.jsonParseError)}},pe=async()=>{b(!0),T(null);try{A(await er(a))}catch(e){T(e instanceof Error?e.message:n.validateError)}finally{b(!1)}},Y=async()=>{if(_||r.saving)return;let e=K,i=r.dirty;if(!(!e&&!i)){T(null),O(!1);try{if(e){v(!0);try{await tr(a),l(structuredClone(a)),A(null)}finally{v(!1)}}if(i&&r.form&&!await r.save())throw Error(t.agentSettings.saveError);O(!0)}catch(e){T(e instanceof Error?e.message:n.saveError)}}},he=(0,Z.useCallback)(()=>{o(structuredClone(c)),A(null),O(!1),T(null),P&&(L(JSON.stringify(c,null,2)),z(null)),r.discard()},[c,P,r.discard]),_e=async()=>{S(!0),T(null);try{await nr(),await oe({skipFullPageLoading:!0})}catch(e){T(e instanceof Error?e.message:n.reloadError)}finally{S(!1)}},ve=async(e,t)=>{try{let n=await rr(t);H(t=>{let r=new Map(t);return r.set(e,n),r})}catch(t){H(n=>{let r=new Map(n);return r.set(e,{type:`error`,error:t instanceof Error?t.message:`Error`}),r})}},ye=(e=null)=>{ie(e),ne(!0)},be=(e,t)=>{o(n=>yr(n,e,t)),M(t=>new Set(t).add(e))},xe=e=>{window.confirm(n.removeProviderConfirm.replace(`{{id}}`,e))&&(o(t=>vr(t,e)),H(t=>{let n=new Map(t);return n.delete(e),n}))},Se=(e,t,n)=>{ae({providerId:e,model:t,isNew:n}),W(!0)},Ce=e=>{if(!G)return;let{providerId:t,isNew:n}=G;o(r=>{let i=r.providers[t];if(!i)return r;let a=i.models||[];return n?_r(r,t,{models:[...a,e]}):_r(r,t,{models:a.map(t=>t.id===e.id?e:t)})})};return i?(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-4 px-4 py-8`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.models}),(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.subtitle}),(0,X.jsxs)(`a`,{href:qe(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,X.jsx)(N,{className:`size-3.5`})]})]}),p?(0,X.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,X.jsx)(le,{className:`mt-0.5 size-4 shrink-0`}),(0,X.jsxs)(`span`,{children:[n.loadFileWarning,`: `,p]})]}):null,u?(0,X.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.filePath,`: `,(0,X.jsx)(`code`,{className:`rounded bg-surface-base px-1 py-0.5 font-mono text-fg-muted`,children:u})]}):null,(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsxs)(E,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:()=>ye(null),disabled:h,children:[(0,X.jsx)(me,{className:`mr-1 size-4`}),n.addProvider]}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:pe,disabled:h||y,children:y?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(s,{className:`mr-1 size-4 animate-spin`}),n.validating]}):n.validate}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:he,disabled:h||_||r.saving||!ce,children:n.discard}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:()=>void Y(),disabled:h||_||r.saving||!ce,children:_||r.saving?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(s,{className:`mr-1 size-4 animate-spin`}),n.saving]}):n.save}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[8.5rem] justify-center`,onClick:_e,disabled:h||x,children:x?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(s,{className:`mr-1 size-4 animate-spin`}),n.reloading]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Me,{className:`mr-1 size-4`}),n.reload]})}),(0,X.jsx)(E,{type:`button`,variant:`ghost`,className:`text-fg-muted`,onClick:()=>{F(e=>!e),z(null)},children:P?n.hideJson:n.showJson}),(0,X.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,X.jsx)(`span`,{className:`text-fg-muted`,children:n.statsProviders.replace(`{{count}}`,String(ue.providers))}),(0,X.jsx)(`span`,{className:`text-fg-subtle`,children:`|`}),(0,X.jsx)(`span`,{className:`text-fg-muted`,children:n.statsModels.replace(`{{count}}`,String(ue.models))})]})]}),ce?(0,X.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,D||r.saveOk?(0,X.jsx)(`p`,{className:`text-xs text-emerald-700 dark:text-emerald-400`,role:`status`,children:n.saved}):null,C?(0,X.jsxs)(`p`,{className:`flex items-center gap-1 text-sm text-red-600 dark:text-red-400`,role:`alert`,children:[(0,X.jsx)(le,{className:`size-4 shrink-0`}),C]}):null,r.error?(0,X.jsxs)(`p`,{className:`flex items-center gap-1 text-sm text-red-600 dark:text-red-400`,role:`alert`,children:[(0,X.jsx)(le,{className:`size-4 shrink-0`}),r.error]}):null,k&&k.errors.length>0?(0,X.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,X.jsx)(`p`,{className:`mb-1 text-sm font-medium text-amber-950 dark:text-amber-100`,children:k.valid?n.validationWarnings:n.validationErrors}),(0,X.jsx)(`ul`,{className:`list-inside list-disc space-y-0.5 text-xs text-amber-900 dark:text-amber-200`,children:k.errors.map((e,t)=>(0,X.jsxs)(`li`,{children:[e.path,`: `,e.message,` (`,e.severity,`)`]},`${e.path}-${t}`))})]}):null,h?(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,X.jsx)(s,{className:`size-4 animate-spin`}),n.loading]}):P?(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,X.jsx)(`textarea`,{className:w(pr(),`min-h-[320px] resize-y font-mono text-xs leading-relaxed`),value:I,onChange:e=>L(e.target.value),spellCheck:!1}),R?(0,X.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:R}):null,(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(E,{type:`button`,variant:`secondary`,onClick:fe,children:n.jsonReset}),(0,X.jsx)(E,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:J,children:n.jsonApply})]})]}):Object.keys(a.providers).length===0?(0,X.jsx)(Cr,{ms:n,openAddProvider:ye}):(0,X.jsx)(Sr,{config:a,setConfig:o,expanded:j,toggleExpand:q,showPw:ee,toggleShowPw:de,testResults:V,runTestKey:ve,ms:n,removeProv:xe,openModelDialog:Se,setTestResults:H}),se?(0,X.jsx)(`div`,{className:`mt-10 border-t border-edge-subtle pt-8 dark:border-edge`,children:(0,X.jsx)(lr,{...se})}):null,(0,X.jsx)(xr,{open:te,onOpenChange:ne,presetKey:re,onConfirm:be,m:n}),(0,X.jsx)(br,{open:U,onOpenChange:e=>{W(e),e||ae(null)},providerId:G?.providerId??null,model:G?.model??null,isNew:G?.isNew??!1,onSave:Ce,m:n})]}):(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.models}),(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}async function Tr(e){let t=await Y(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 Y(K(`/api/auth/oauth-async/${encodeURIComponent(e)}/status`));if(!t.ok)throw Error(`OAuth status: ${t.status}`);return(await t.json()).payload}async function Dr(e,t){let n=await Y(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 Or(e){let t=await Y(K(`/api/auth/oauth-async/${encodeURIComponent(e)}/cancel`),{method:`POST`});if(!t.ok)throw Error(`Cancel OAuth failed: ${t.status}`)}async function kr(e){let t=await Y(K(`/api/auth/oauth-async/${encodeURIComponent(e)}`),{method:`DELETE`});if(!t.ok)throw Error(`Cleanup session failed: ${t.status}`)}async function Ar(e){let t=await Y(K(`/api/auth/oauth/${encodeURIComponent(e)}`),{method:`DELETE`});if(!t.ok)throw Error(`Revoke OAuth failed: ${t.status}`)}function jr({providerId:e,language:t}){let n=Ge[e];if(!n)return null;let r=t===`zh`,i=r&&n.descriptionZh?n.descriptionZh:n.description;return i?(0,X.jsxs)(Xe,{children:[(0,X.jsx)(u,{asChild:!0,children:(0,X.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,X.jsx)(l,{className:`size-3.5`,"aria-hidden":!0})})}),(0,X.jsx)(F,{children:(0,X.jsxs)(T,{side:`right`,align:`start`,sideOffset:6,className:w(`w-64 rounded-xl border border-edge bg-surface-panel p-3 shadow-md`,xe,`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,X.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,X.jsx)(`p`,{className:`text-xs font-semibold text-fg`,children:e}),(0,X.jsx)(C,{asChild:!0,children:(0,X.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,X.jsx)(Je,{className:`size-3.5`,"aria-hidden":!0})})})]}),(0,X.jsx)(`p`,{className:`mt-1.5 text-xs leading-relaxed text-fg-muted`,children:i}),n.bestFor&&n.bestFor.length>0?(0,X.jsxs)(`div`,{className:`mt-2`,children:[(0,X.jsx)(`p`,{className:`text-[10px] font-medium uppercase tracking-wide text-fg-subtle`,children:r?`适合场景`:`Best for`}),(0,X.jsx)(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:n.bestFor.map(e=>(0,X.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,X.jsxs)(`div`,{className:`mt-2`,children:[(0,X.jsx)(`p`,{className:`text-[10px] font-medium uppercase tracking-wide text-fg-subtle`,children:r?`免费额度`:`Free tier`}),(0,X.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,X.jsxs)(`div`,{className:`mt-2.5 flex gap-3`,children:[n.pricingUrl?(0,X.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,X.jsx)(N,{className:`size-3`,"aria-hidden":!0})]}):null,n.docsUrl?(0,X.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,X.jsx)(N,{className:`size-3`,"aria-hidden":!0})]}):null]}):null,(0,X.jsx)(x,{className:`fill-edge`})]})})]}):null}var Mr=[`common`,`specialty`,`enterprise`,`oauth`,`extension`];function Nr(e){let t=new Map;for(let e of Mr)t.set(e,[]);for(let n of e){let e=n.category||`specialty`,r=t.get(e)??[];r.push(n),t.set(e,r)}return t}function Pr(e,t){return e.replace(/\{\{(\w+)\}\}/g,(e,n)=>String(t[n]??``))}function Fr(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 Ir({envVar:e,labels:t}){let[n,r]=(0,Z.useState)(!1),i=async()=>{try{await navigator.clipboard.writeText(e),r(!0),window.setTimeout(()=>r(!1),2e3)}catch{}};return(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`code`,{className:`rounded bg-surface-hover px-1.5 py-0.5 font-mono text-[11px] text-fg-muted`,children:e}),(0,X.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,X.jsx)(Le,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):(0,X.jsx)(Pe,{className:`size-3.5`,"aria-hidden":!0})})]})}function Lr({row:e,value:t,rowDirty:n,labels:r,language:i,onChange:a,onReload:c,justSaved:u,availableModels:d}){let[f,p]=(0,Z.useState)(!1),[m,h]=(0,Z.useState)(!1),[g,v]=(0,Z.useState)(!1),[y,b]=(0,Z.useState)(null),[x,S]=(0,Z.useState)(!1),[C,T]=(0,Z.useState)(null),[D,O]=(0,Z.useState)(!1),k=Ce(t),j=k&&!m?``:t,M=e.configured&&!k&&!!t,[P,F]=(0,Z.useState)(!1),[I,L]=(0,Z.useState)(),[R,z]=(0,Z.useState)(),[ee,B]=(0,Z.useState)(),[V,te]=(0,Z.useState)(),[ie,U]=(0,Z.useState)(),[W,ae]=(0,Z.useState)(``),[oe,K]=(0,Z.useState)(!1),[se,ce]=(0,Z.useState)(null),[ue,q]=(0,Z.useState)(null),de=e.activeKeySource??`none`,J=(0,Z.useMemo)(()=>G(e.id,i),[e.id,i]);(0,Z.useEffect)(()=>()=>{I&&kr(I).catch(()=>{})},[I]),(0,Z.useEffect)(()=>{if(!I||!P)return;let e=window.setInterval(()=>{(async()=>{try{let t=await Er(I);B(t.message),te(t.authUrl),U(t.instructions),t.status===`waiting_auth`||t.status===`waiting_code`?z(t.status===`waiting_code`?`waiting_code`:`waiting`):t.status===`completed`?(window.clearInterval(e),F(!1),z(`success`),B(t.message),window.setTimeout(()=>c(),800)):(t.status===`failed`||t.status===`cancelled`)&&(window.clearInterval(e),F(!1),z(`error`),B(t.error||t.message||`OAuth failed`))}catch{}})()},1e3);return()=>window.clearInterval(e)},[I,P,c]);let pe=async()=>{F(!0),z(`waiting`),B(r.oauthStarting),L(void 0),te(void 0),U(void 0);try{L((await Tr(e.id)).sessionId)}catch(e){z(`error`),B(e instanceof Error?e.message:`OAuth failed`),F(!1)}},Y=async()=>{if(I){try{await Or(I)}catch{}L(void 0),F(!1),z(`idle`),B(void 0)}},me=async()=>{if(!(!I||!W.trim()))try{await Dr(I,W.trim()),ae(``),B(r.oauthProcessingCode)}catch(e){z(`error`),B(e instanceof Error?e.message:`Failed`)}},he=()=>{window.confirm(Pr(r.revokeConfirm,{name:e.name}))&&(b(null),Ar(e.id).then(()=>c()).catch(e=>b(e instanceof Error?e.message:r.revokeFailed)))},ge=async()=>{O(!1),S(!0),T(null);try{await ke(e.id),T(r.removeKeySuccess),a(e.id,``),window.setTimeout(()=>c(),600)}catch(e){T(e instanceof Error?e.message:r.removeKeyFailed)}finally{S(!1)}},_e=e.configured&&k&&de!==`env`&&de!==`extension`&&de!==`models_json`,ve=async()=>{if(!(!t||k))try{await navigator.clipboard.writeText(t),v(!0),window.setTimeout(()=>v(!1),2e3)}catch{}},ye=async()=>{let e=t.trim();if(!(!e||Ce(e))){K(!0),ce(null),q(null);try{let t=await Re(e);if(t.error){q(!1),ce(`${r.testFailed} ${t.error}`);return}q(!0),t.type===`env`?ce(r.testOkEnv):t.type===`command`?ce(r.testOkCommand):ce(r.testOkLiteral)}catch(e){q(!1),ce(e instanceof Error?e.message:r.testFailed)}finally{K(!1)}}},be=n?r.metaWillSave:e.configured?k?`${r.metaMasked} · ${r.runtimeLabelPrefix} ${Fr(r,de)}`:`${r.runtimeLabelPrefix} ${Fr(r,de)}`:r.metaNotConfigured,xe=`provider-details-${e.id}`;return(0,X.jsxs)(`div`,{className:`bg-surface-panel`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3 px-3 py-3 sm:px-4`,children:[(0,X.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,X.jsx)(Le,{className:`size-4 text-emerald-600 dark:text-emerald-400`}):(0,X.jsx)(Ye,{className:`size-4 text-fg-subtle`,strokeWidth:1.75})}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-semibold text-fg`,children:e.name}),(0,X.jsx)(jr,{providerId:e.id,language:i}),(0,X.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,X.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,X.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:be})]}),(0,X.jsx)(E,{type:`button`,variant:`ghost`,className:`h-9 w-9 shrink-0 p-0`,"aria-expanded":f,"aria-controls":xe,"aria-label":r.expandRowDetails,onClick:()=>p(e=>!e),children:(0,X.jsx)(fe,{className:w(`size-4 transition-transform`,f&&`rotate-180`),"aria-hidden":!0})})]}),f?(0,X.jsxs)(`div`,{id:xe,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,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,X.jsxs)(`div`,{className:`relative flex flex-col gap-2 sm:flex-row sm:gap-2`,children:[(0,X.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,X.jsx)(`input`,{type:m||!k?`text`:`password`,className:w(`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`,o,`dark:border-edge`),value:j,placeholder:k?r.placeholderOverride:e.configured?r.placeholderKeep:r.placeholderKey,disabled:P,onChange:t=>a(e.id,t.target.value),autoComplete:`off`,spellCheck:!1}),(0,X.jsxs)(`div`,{className:`absolute right-1 top-1/2 flex -translate-y-1/2 gap-0.5`,children:[t&&!k?(0,X.jsx)(`button`,{type:`button`,className:w(`rounded p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,H.transition,H.press,H.focusRingPanel),title:g?r.copied:r.copy,"aria-label":g?r.copied:r.copy,onClick:()=>void ve(),children:g?(0,X.jsx)(Le,{className:`size-4`}):(0,X.jsx)(Pe,{className:`size-4`})}):null,(0,X.jsx)(`button`,{type:`button`,className:w(`rounded p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg disabled:opacity-40`,H.transition,H.press,H.focusRingPanel),title:m?r.hide:r.show,"aria-label":m?r.hide:r.show,disabled:k,onClick:()=>h(e=>!e),children:m?(0,X.jsx)(re,{className:`size-4`}):(0,X.jsx)(ne,{className:`size-4`})})]})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2 sm:shrink-0`,children:[(0,X.jsxs)(E,{type:`button`,variant:`secondary`,className:`gap-1`,disabled:P||oe||!t.trim()||Ce(t),onClick:()=>void ye(),children:[oe?(0,X.jsx)(s,{className:`size-4 animate-spin`,"aria-hidden":!0}):null,oe?r.testingKey:r.testKey]}),e.supportsOAuth?M?(0,X.jsxs)(E,{type:`button`,variant:`secondary`,className:`gap-1 text-red-600 dark:text-red-400`,onClick:he,children:[(0,X.jsx)(_,{className:`size-4`,"aria-hidden":!0}),r.revoke]}):(0,X.jsxs)(E,{type:`button`,variant:`secondary`,className:`gap-1`,disabled:P,onClick:()=>void pe(),children:[P?(0,X.jsx)(s,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,X.jsx)(A,{className:`size-4`,"aria-hidden":!0}),r.oauth]}):null,_e?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(E,{type:`button`,variant:`secondary`,className:`gap-1 text-red-600 dark:text-red-400`,disabled:x,onClick:()=>O(!0),children:[x?(0,X.jsx)(s,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,X.jsx)(Ne,{className:`size-4`,"aria-hidden":!0}),r.removeKey]}),(0,X.jsx)(Ie,{open:D,title:r.removeKey,description:Pr(r.removeKeyConfirm,{name:e.name}),confirmLabel:r.removeKey,cancelLabel:r.cancelOAuth,destructive:!0,onConfirm:()=>void ge(),onCancel:()=>O(!1)})]}):null]})]}),se?(0,X.jsx)(`p`,{className:w(`text-xs`,ue===!1?`text-red-600 dark:text-red-400`:`text-fg-muted`),role:`status`,children:se}):null,J.length>0?(0,X.jsx)(`div`,{className:`flex flex-col gap-1`,children:J.map(e=>(0,X.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:[He(e.kind,r),(0,X.jsx)(N,{className:`size-3`,"aria-hidden":!0})]},`${e.kind}-${e.href}`))}):null]}),ee?(0,X.jsxs)(`div`,{className:w(`flex gap-2 rounded-md px-3 py-2 text-xs`,R===`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:[R===`error`?(0,X.jsx)(le,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}):R===`success`?(0,X.jsx)(Le,{className:`mt-0.5 size-4 shrink-0 text-emerald-600`,"aria-hidden":!0}):(0,X.jsx)(l,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,X.jsx)(`span`,{children:ee})]}):null,y?(0,X.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,X.jsx)(le,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,X.jsx)(`span`,{children:y})]}):null,C?(0,X.jsxs)(`div`,{className:w(`flex gap-2 rounded-md px-3 py-2 text-xs`,C===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:[C===r.removeKeySuccess?(0,X.jsx)(Le,{className:`mt-0.5 size-4 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):(0,X.jsx)(le,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,X.jsx)(`span`,{children:C})]}):null,(R===`waiting`||R===`waiting_code`)&&(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[V?(0,X.jsxs)(`a`,{href:V,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,X.jsx)(N,{className:`size-4`,"aria-hidden":!0}),r.openAuthPage]}):null,(0,X.jsxs)(E,{type:`button`,variant:`secondary`,className:`gap-1`,onClick:()=>void Y(),children:[(0,X.jsx)(Je,{className:`size-4`,"aria-hidden":!0}),r.cancelOAuth]})]}),ie?(0,X.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,X.jsx)(l,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,X.jsx)(`span`,{children:ie})]}):null,R===`waiting_code`?(0,X.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,X.jsx)(`input`,{type:`text`,className:w(`min-w-0 flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,o,`dark:border-edge`),value:W,placeholder:r.pasteRedirectUrl,onChange:e=>ae(e.target.value),onKeyDown:e=>e.key===`Enter`&&void me()}),(0,X.jsx)(E,{type:`button`,variant:`primary`,className:`shrink-0`,onClick:()=>void me(),children:r.submitCode})]}):null,k?(0,X.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,X.jsx)(l,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,X.jsx)(`span`,{children:de===`env`?r.envHint:r.maskedStoredHint})]}):null,e.supportsOAuth&&!k&&!M?(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:r.oauthHint}):null,u?(0,X.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,X.jsx)(Le,{className:`mt-0.5 size-3.5 shrink-0 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}),(0,X.jsx)(`span`,{children:(()=>{let t=d.filter(t=>t.provider===e.id);if(t.length===0)return r.savedNoModels;let n=t.slice(0,3).map(e=>e.name||e.id).join(`, `),i=t.length>3?`… (+${t.length-3})`:``;return`${t.length} ${r.savedModelsAvailable}: ${n}${i}`})()})]}):null,(Ge[e.id]?.envVars??[]).length>0?(0,X.jsxs)(`details`,{children:[(0,X.jsx)(`summary`,{className:`cursor-pointer select-none list-none text-xs text-fg-subtle hover:text-fg-muted`,children:r.envVarAlt}),(0,X.jsx)(`div`,{className:`mt-1.5 flex flex-col gap-1`,children:(Ge[e.id]?.envVars??[]).map(e=>(0,X.jsx)(Ir,{envVar:e,labels:r},e))})]}):null]}):null]})}function Rr(){let e=f(e=>e.language),t=ge(e),n=t.providersSettings,i=!!ze(e=>e.token),[a,s]=(0,Z.useState)({}),[c,l]=(0,Z.useState)({}),[u,p]=(0,Z.useState)(!1),[h,g]=(0,Z.useState)(null),[_,y]=(0,Z.useState)(null),[b,x]=(0,Z.useState)(()=>new Set([`common`])),[S,C]=(0,Z.useState)(``),[T,D]=(0,Z.useState)(!1),[O,k]=(0,Z.useState)(()=>new Set),A=(0,Z.useRef)(``),j=K(`/api/providers/meta`),M=(0,Z.useCallback)(async e=>(await J(e)).payload?.providers??[],[]),{data:N,error:P,isLoading:F,mutate:L}=m(i),{data:R,error:z,isLoading:ee,mutate:B}=r(i?j:null,M,{revalidateOnFocus:!1}),{data:V,mutate:H}=r(i?I:null,()=>d(),{revalidateOnFocus:!1}),te=(0,Z.useMemo)(()=>!R||N===void 0?null:pe(R,ie(N.payload?.config),V??[]),[R,N,V]),ne=P instanceof Error?P.message:P?String(P):z instanceof Error?z.message:z?String(z):null,re=!!(i&&te===null&&(F||ee)&&!ne),U=(0,Z.useMemo)(()=>JSON.stringify(a)!==JSON.stringify(c),[a,c]);(0,Z.useEffect)(()=>{if(!U)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[U]),(0,Z.useEffect)(()=>{if(!(!i||te===null)&&!U){let e={};for(let t of te)e[t.id]=t.apiKey;s(e),l({...e})}},[i,te,U]);let W=te??[],G=(0,Z.useMemo)(()=>{let e=W,t=S.trim().toLowerCase();return t&&(e=e.filter(e=>{let n=Ge[e.id]?.aliases??[];return e.id.toLowerCase().includes(t)||e.name.toLowerCase().includes(t)||n.some(e=>e.toLowerCase().includes(t))})),T&&(e=e.filter(e=>!e.configured)),e},[W,S,T]),ae=(0,Z.useMemo)(()=>Nr(G),[G]);(0,Z.useEffect)(()=>{let e=A.current;if(A.current=S,S.trim()){let e=new Set;for(let t of Mr)(ae.get(t)??[]).length>0&&e.add(t);x(e);return}e.trim()&&x(new Set([`common`]))},[S,ae]);let se=(0,Z.useCallback)(async()=>{if(u)return;let e={};for(let t of Object.keys(a)){let n=a[t]?.trim()??``;!n||Ce(n)||(e[t]=n)}if(Object.keys(e).length===0){l({...a}),y(`noChanges`),window.setTimeout(()=>y(null),2500);return}p(!0),g(null),y(null);try{await de(e),k(new Set(Object.keys(e)));let t=await H(d(!0))??V??[],[n,r]=await Promise.all([L(),B()]),i=Array.isArray(r)?r:R??[],a=n??N;if(a?.payload){let e=pe(i,ie(a.payload.config),t),n={};for(let t of e)n[t.id]=t.apiKey;s(n),l({...n})}y(`saved`),window.setTimeout(()=>y(null),2500)}catch(e){g(e instanceof Error?e.message:n.saveError)}finally{p(!1)}},[N,a,R,V,L,B,H,n.saveError,u]),ce=(0,Z.useCallback)(()=>{s({...c}),g(null),y(null),k(new Set)},[c]),le=e=>{x(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},ue=(0,Z.useCallback)(()=>{L(),B()},[L,B]),q=!!(S.trim()||T);return i?re?(0,X.jsxs)(`div`,{className:`mx-auto w-full max-w-app-main px-4 py-8`,children:[(0,X.jsx)(`div`,{className:`h-8 w-48 animate-pulse rounded bg-surface-hover`}),(0,X.jsx)(`div`,{className:`mt-6 h-32 animate-pulse rounded-xl bg-surface-hover`}),(0,X.jsx)(`p`,{className:`mt-4 text-sm text-fg-muted`,children:t.logs.loading})]}):W.length===0?(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-10`,children:[(0,X.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-base px-4 py-3`,children:[(0,X.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:n.loadError}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:h??ne??n.empty})]}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,onClick:()=>{L(),B()},children:t.logs.refresh})]}):(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,X.jsxs)(`header`,{className:`flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between`,children:[(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.providers}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,X.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:n.rotateHint})]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[_===`saved`?(0,X.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,_===`noChanges`?(0,X.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.noChangesSaved}):null,(0,X.jsx)(E,{type:`button`,variant:`secondary`,disabled:!U||u,onClick:ce,children:n.discard}),(0,X.jsx)(E,{type:`button`,variant:`primary`,disabled:!U||u,onClick:()=>void se(),children:u?n.saving:n.save})]})]}),U?(0,X.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,(0,X.jsxs)(`p`,{className:`text-sm leading-relaxed text-fg-muted`,children:[n.intro,` `,(0,X.jsx)(`a`,{href:qe(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,X.jsx)(v,{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,X.jsxs)(`div`,{className:`flex flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-center`,children:[(0,X.jsxs)(`div`,{className:`relative min-w-0 flex-1 sm:max-w-md`,children:[(0,X.jsx)(oe,{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,X.jsx)(`input`,{type:`search`,value:S,onChange:e=>C(e.target.value),placeholder:n.searchPlaceholder,autoComplete:`off`,className:w(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-10 pr-3 text-sm text-fg placeholder:text-fg-subtle`,o,`dark:border-edge`),"aria-label":n.searchPlaceholder})]}),(0,X.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg-muted`,children:[(0,X.jsx)(`input`,{type:`checkbox`,checked:T,onChange:e=>D(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]}),q?(0,X.jsx)(E,{type:`button`,variant:`ghost`,className:`h-9 w-fit self-start text-fg-muted`,onClick:()=>{C(``),D(!1)},children:n.clearFilters}):null]}),h?(0,X.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:h}):null,G.length===0?(0,X.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,X.jsx)(`p`,{children:n.noMatches}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,className:`mt-4`,onClick:()=>{C(``),D(!1)},children:n.clearFilters})]}):(0,X.jsx)(`div`,{className:`flex flex-col gap-3`,children:Mr.map(t=>{let r=ae.get(t)??[];if(r.length===0)return null;let i=b.has(t),o=r.filter(e=>e.configured).length,l=`providers-cat-${t}`;return(0,X.jsxs)(`section`,{className:`overflow-hidden rounded-2xl bg-surface-base`,children:[(0,X.jsxs)(`button`,{type:`button`,id:`${l}-trigger`,"aria-expanded":i,"aria-controls":l,className:`flex w-full items-center justify-between gap-2 border-b border-edge-subtle px-4 py-3 text-left transition-colors hover:bg-surface-hover/60 dark:border-edge-subtle`,onClick:()=>le(t),children:[(0,X.jsxs)(`span`,{className:`flex min-w-0 items-center gap-2 text-sm font-semibold text-fg`,children:[(0,X.jsx)(`span`,{className:`truncate`,children:n.categories[t]}),(0,X.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,X.jsxs)(`span`,{className:`flex shrink-0 items-center gap-2`,children:[o>0?(0,X.jsxs)(`span`,{className:`flex items-center gap-1 text-xs text-fg-subtle`,children:[(0,X.jsx)(Le,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}),Pr(n.configuredCount,{count:String(o)})]}):null,(0,X.jsx)(fe,{className:w(`size-4 text-fg-subtle transition-transform`,i&&`rotate-180`),"aria-hidden":!0})]})]}),i?(0,X.jsx)(`div`,{id:l,role:`region`,"aria-labelledby":`${l}-trigger`,className:`divide-y divide-edge-subtle`,children:r.map(t=>(0,X.jsx)(`div`,{id:`provider-row-${t.id}`,children:(0,X.jsx)(Lr,{row:t,value:a[t.id]??``,rowDirty:(a[t.id]??``)!==(c[t.id]??``),labels:n,language:e,onChange:(e,t)=>s(n=>({...n,[e]:t})),onReload:ue,justSaved:O.has(t.id),availableModels:V??[]})},t.id))}):null]},t)})})]}):(0,X.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-10`,children:(0,X.jsxs)(`div`,{className:`flex items-start gap-3 rounded-2xl bg-surface-base p-6`,children:[(0,X.jsx)(Ye,{className:`mt-0.5 size-5 shrink-0 text-fg-subtle`,strokeWidth:1.75}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h1`,{className:`text-base font-semibold text-fg`,children:t.settingsSections.providers}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.needToken})]})]})})}var zr=[{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 Br(e,t){let n=ge(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 Vr(){let e=f(e=>e.language),t=ge(e).systemSettings,[n,r]=(0,Z.useState)(null),[i,a]=(0,Z.useState)(null),[o,s]=(0,Z.useState)(null),c=typeof window<`u`?window.electronAPI?.system:void 0,l=(0,Z.useCallback)(async()=>{if(c){s(null);try{r(await c.getBehavior()),a(await c.getPermissions())}catch(e){s(e instanceof Error?e.message:String(e))}}},[c]);if((0,Z.useEffect)(()=>{b()&&c&&l()},[c,l]),!b()||!c)return(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.title}),(0,X.jsxs)(`div`,{className:Tt(),children:[(0,X.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:t.desktopOnlyTitle}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:t.desktopOnlyBody})]})]});let u=async e=>{try{let{behavior:t}=await c.setBehavior(e);r(t)}catch(e){s(e instanceof Error?e.message:String(e))}},d=async e=>{try{(await c.openPrivacy(e)).ok||s(`open_privacy failed`)}catch(e){s(e instanceof Error?e.message:String(e))}},p=n?n.platform===`win32`?t.permissionsHintWin:n.platform===`linux`?t.permissionsHintLinux:n.platform===`darwin`?t.permissionsHintDarwin:t.permissionsHint:t.permissionsHint;return(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[(0,X.jsx)(`div`,{children:(0,X.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.title})}),o?(0,X.jsx)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:o}):null,(0,X.jsxs)(Et,{children:[(0,X.jsxs)(`div`,{className:`mb-4 flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,X.jsx)(Fe,{className:`size-4 text-accent`,strokeWidth:1.75}),t.behaviorGroup]}),(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.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,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.openAtLogin}),(0,X.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.openAtLoginDesc})]}),(0,X.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!n,checked:!!n?.openAtLogin,onChange:e=>{u({openAtLogin:e.target.checked})}})]}),(0,X.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,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.keepAwake}),(0,X.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.keepAwakeDesc})]}),(0,X.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!n,checked:!!n?.keepAwakePreferred,onChange:e=>{u({keepAwakePreferred:e.target.checked})}})]}),(0,X.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,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.notifyDesktop}),(0,X.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.notifyDesktopDesc})]}),(0,X.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!n,checked:!!n?.notifyEnabled,onChange:e=>{u({notifyEnabled:e.target.checked})}})]}),(0,X.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,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:t.toggles.notifySound}),(0,X.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.toggles.notifySoundDesc})]}),(0,X.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,disabled:!n,checked:!!n?.notifySoundEnabled,onChange:e=>{u({notifySoundEnabled:e.target.checked})}})]})]})]}),n&&i?(0,X.jsxs)(`section`,{className:Tt(),children:[(0,X.jsxs)(`div`,{className:`mb-4 flex flex-col gap-1 sm:flex-row sm:items-center sm:justify-between`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:t.permissionsTitle}),(0,X.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:p})]}),(0,X.jsx)(`button`,{type:`button`,className:`mt-2 inline-flex max-w-full items-center justify-center rounded-lg border border-edge bg-surface-panel px-3 py-1.5 text-sm font-medium text-fg transition-colors hover:bg-surface-hover sm:mt-0`,onClick:()=>void l(),children:t.refresh})]}),(0,X.jsx)(`ul`,{className:`space-y-3`,children:zr.map(({key:r,pane:o})=>{let l=Br(e,i[r]),u=t.perm[r];return u?(0,X.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,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:u.title}),(0,X.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:u.desc}),(0,X.jsx)(`p`,{className:`mt-1 text-xs font-medium ${l.className}`,children:l.label})]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-2`,children:[r===`microphone`&&n?.platform===`darwin`?(0,X.jsx)(`button`,{type:`button`,className:`inline-flex items-center gap-1 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover`,onClick:()=>{(async()=>{try{await c.requestMicrophone(),a(await c.getPermissions())}catch(e){s(e instanceof Error?e.message:String(e))}})()},children:e===`zh`?`请求访问`:`Request`}):null,(0,X.jsxs)(`button`,{type:`button`,className:`inline-flex items-center gap-1.5 rounded-lg border border-edge bg-surface-base px-2.5 py-1.5 text-xs font-medium text-fg hover:bg-surface-hover`,onClick:()=>void d(o),children:[t.openSettings,(0,X.jsx)(N,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0})]})]})]},r):null})})]}):null]})}function Hr(){return{enabled:!1,provider:`alibaba`,alibaba:{model:`paraformer-v2`},openai:{model:`whisper-1`},fallback:{enabled:!0,order:[`alibaba`,`openai`]}}}function Ur(){return{enabled:!1,provider:`openai`,trigger:`always`,maxTextLength:512,timeoutMs:6e4,alibaba:{model:`qwen-tts`,voice:`Cherry`},openai:{model:`tts-1`,voice:`alloy`},edge:{voice:`en-US-MichelleNeural`},minimax:{model:`speech-2.8-hd`,voice:`male-qn-qingse`},"tts-local-cli":{command:``,outputFormat:`wav`}}}function Wr(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Gr(e){let t=Hr();if(!Wr(e))return t;let n=e.provider===`openai`?`openai`:`alibaba`,r=Wr(e.alibaba)?{...t.alibaba,...e.alibaba}:t.alibaba,i=Wr(e.openai)?{...t.openai,...e.openai}:t.openai,a=t.fallback??{enabled:!0,order:[`alibaba`,`openai`]};if(Wr(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 Kr(e){return typeof e==`string`&&e.trim().length>0?e.trim():`openai`}function qr(e){let t=Ur();if(!Wr(e))return t;let n=Kr(e.provider),r=e.trigger===`off`||e.trigger===`always`||e.trigger===`inbound`||e.trigger===`tagged`?e.trigger:`always`,i=e[`tts-local-cli`];return{enabled:!!e.enabled,provider:n,trigger:r,maxTextLength:typeof e.maxTextLength==`number`&&Number.isFinite(e.maxTextLength)?e.maxTextLength:t.maxTextLength,timeoutMs:typeof e.timeoutMs==`number`&&Number.isFinite(e.timeoutMs)?e.timeoutMs:t.timeoutMs,alibaba:Wr(e.alibaba)?{...t.alibaba,...e.alibaba}:t.alibaba,openai:Wr(e.openai)?{...t.openai,...e.openai}:t.openai,edge:Wr(e.edge)?{...t.edge,...e.edge}:t.edge,minimax:Wr(e.minimax)?{...t.minimax,...e.minimax}:t.minimax,"tts-local-cli":Wr(i)?{...t[`tts-local-cli`],...i}:t[`tts-local-cli`]}}function Jr(e){let t=Wr(e)?e:{};return{stt:Gr(t.stt),tts:qr(t.tts)}}async function Yr(e){await J(K(`/api/config`),{method:`PATCH`,body:JSON.stringify({stt:e.stt,tts:e.tts})}),R()}async function Xr(){let e=await J(K(`/api/voice/models`));if(!e.payload?.models)throw Error(`Missing voice models payload`);return e.payload.models}function Zr(){return w(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,o,`dark:border-edge`)}function Qr(){return w(ve,g)}var $r=[{id:`paraformer-v2`,name:`Paraformer v2`},{id:`paraformer-v1`,name:`Paraformer v1`}],ei=[{id:`whisper-1`,name:`Whisper-1`}],ti=[{id:`tts-1`,name:`TTS-1`},{id:`tts-1-hd`,name:`TTS-1 HD`}],ni=[{id:`alloy`,name:`Alloy`},{id:`echo`,name:`Echo`}],ri=[{id:`qwen-tts`,name:`Qwen TTS`},{id:`qwen3-tts-flash`,name:`Qwen3 TTS Flash`}],ii=[{id:`Cherry`,name:`Cherry`},{id:`longxiaochun`,name:`Long Xiao Chun`}],ai=[{id:`en-US-MichelleNeural`,name:`Michelle (US English)`},{id:`zh-CN-XiaoxiaoNeural`,name:`Xiaoxiao (Chinese)`}],oi=[{id:`speech-2.8-hd`,name:`Speech 2.8 HD (Recommended)`},{id:`speech-2.8-turbo`,name:`Speech 2.8 Turbo (Fast)`}],si=[{id:`male-qn-qingse`,name:`Male Qingse (青涩男声)`},{id:`female-shaonv`,name:`Female Shaonv (少女音)`}];function ci(){let e=f(e=>e.language),t=ge(e),n=t.voiceSettings,i=!!ze(e=>e.token),[a,o]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(null),[p,h]=(0,Z.useState)(!1),[g,_]=(0,Z.useState)(null),[v,y]=(0,Z.useState)(!1),{data:b,error:x,isLoading:S,mutate:C}=m(i),{data:w,error:T,isLoading:D,mutate:O}=r(i?K(`/api/voice/models`):null,Xr,{revalidateOnFocus:!1}),k=(0,Z.useMemo)(()=>b?.payload?.config===void 0?null:Jr(b.payload.config),[b]),A=(0,Z.useMemo)(()=>!a||!c?!1:JSON.stringify(a)!==JSON.stringify(c),[a,c]);(0,Z.useEffect)(()=>{if(!i){o(null),l(null),d(null);return}k===null||w===void 0||A||(o(structuredClone(k)),l(structuredClone(k)),d(w),y(!1))},[i,k,w,A]);let j=!!(i&&(k===null||w===void 0)&&(S||D)),M=x instanceof Error?x.message:x?String(x):T instanceof Error?T.message:T?String(T):null,P=(0,Z.useCallback)(e=>{o(t=>t?{...t,stt:{...t.stt,...e}}:null)},[]),F=(0,Z.useCallback)(e=>{o(t=>t?{...t,stt:{...t.stt,alibaba:{...t.stt.alibaba,...e}}}:null)},[]),I=(0,Z.useCallback)(e=>{o(t=>t?{...t,stt:{...t.stt,openai:{...t.stt.openai,...e}}}:null)},[]),L=(0,Z.useCallback)(e=>{o(t=>{if(!t)return null;let n=t.stt.fallback??{enabled:!0,order:[`alibaba`,`openai`]};return{...t,stt:{...t.stt,fallback:{...n,...e}}}})},[]),R=(0,Z.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,...e}}:null)},[]),z=(0,Z.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,alibaba:{...t.tts.alibaba,...e}}}:null)},[]),ee=(0,Z.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,openai:{...t.tts.openai,...e}}}:null)},[]),B=(0,Z.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,edge:{...t.tts.edge,...e}}}:null)},[]),V=(0,Z.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,minimax:{...t.tts.minimax,...e}}}:null)},[]),H=(0,Z.useCallback)(e=>{o(t=>t?{...t,tts:{...t.tts,"tts-local-cli":{...t.tts[`tts-local-cli`],...e}}}:null)},[]),te=(0,Z.useCallback)(async()=>{if(!(!a||p)){h(!0),_(null),y(!1);try{await Yr(a);let e=structuredClone(a);l(e),o(e),y(!0),window.setTimeout(()=>y(!1),2500)}catch(e){_(e instanceof Error?e.message:n.saveError)}finally{h(!1)}}},[a,p,n.saveError]),ne=(0,Z.useCallback)(()=>{c&&(o(structuredClone(c)),_(null),y(!1))},[c]);if(!i)return(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:t.settingsSections.voice}),(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]});if(j)return(0,X.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,X.jsx)(s,{className:`size-4 animate-spin`}),n.loading]})});if(!a||u===null)return(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:g??M??n.loadError}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,onClick:()=>{C(),O()},children:n.retry})]});let re=a.stt,ie=a.tts;return(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,X.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:t.settingsSections.voice}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,X.jsxs)(`a`,{href:qe(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,X.jsx)(N,{className:`size-3.5`})]})]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[v?(0,X.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,X.jsx)(E,{type:`button`,variant:`secondary`,disabled:!A||p,onClick:ne,children:n.discard}),(0,X.jsx)(E,{type:`button`,variant:`primary`,disabled:!A||p,onClick:()=>void te(),children:p?n.saving:n.save})]})]}),A?(0,X.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,g?(0,X.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:g}):null,(0,X.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,X.jsx)(li,{v:n,stt:re,models:u,updateStt:P,updateSttAlibaba:F,updateSttOpenai:I,updateSttFallback:L}),(0,X.jsx)(ui,{v:n,tts:ie,models:u,updateTts:R,updateTtsAlibaba:z,updateTtsOpenai:ee,updateTtsEdge:B,updateTtsMinimax:V,updateTtsLocalCli:H})]}),(0,X.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,X.jsxs)(`p`,{className:`text-sm text-fg`,children:[(0,X.jsx)(`strong`,{className:`text-accent`,children:n.notes.title}),` `,n.notes.duration]}),(0,X.jsx)(`p`,{className:`mt-2 text-xs text-fg-muted`,children:n.notes.envVars})]})]})}function li({v:e,stt:t,models:n,updateStt:r,updateSttAlibaba:i,updateSttOpenai:a,updateSttFallback:o}){let s=n?.stt?.alibaba?.length?n.stt.alibaba:$r,c=n?.stt?.openai?.length?n.stt.openai:ei;return(0,X.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[(0,X.jsxs)(`div`,{className:`mb-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,X.jsx)(Ve,{className:`size-4 text-accent`,strokeWidth:1.75}),e.stt.title]}),(0,X.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:e.stt.description})]}),(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.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,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.stt.enable}),(0,X.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.stt.enableDesc})]}),(0,X.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:t.enabled,onChange:e=>r({enabled:e.target.checked})})]}),t.enabled?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.stt.provider}),(0,X.jsxs)(`select`,{className:Qr(),value:t.provider,onChange:e=>r({provider:e.target.value}),children:[(0,X.jsx)(`option`,{value:`alibaba`,children:e.stt.alibaba}),(0,X.jsx)(`option`,{value:`openai`,children:e.stt.openai})]})]})}),t.provider===`alibaba`?(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.stt.apiKey}),(0,X.jsx)(`input`,{className:w(Zr(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.alibaba?.apiKey??``,onChange:e=>i({apiKey:e.target.value}),placeholder:`sk-...`}),(0,X.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (DASHSCOPE_API_KEY)`]})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.stt.model}),(0,X.jsx)(`select`,{className:Qr(),value:t.alibaba?.model??``,onChange:e=>i({model:e.target.value}),children:s.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}):(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.stt.apiKey}),(0,X.jsx)(`input`,{className:w(Zr(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.openai?.apiKey??``,onChange:e=>a({apiKey:e.target.value}),placeholder:`sk-...`}),(0,X.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (OPENAI_API_KEY)`]})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.stt.model}),(0,X.jsx)(`select`,{className:Qr(),value:t.openai?.model??``,onChange:e=>a({model:e.target.value}),children:c.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}),(0,X.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,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.stt.fallback}),(0,X.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.stt.fallbackDesc})]}),(0,X.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:t.fallback?.enabled??!0,onChange:e=>o({enabled:e.target.checked})})]})]}):null]})]})}function ui({v:e,tts:t,models:n,updateTts:r,updateTtsAlibaba:i,updateTtsOpenai:a,updateTtsEdge:o,updateTtsMinimax:s,updateTtsLocalCli: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:ti,d=n?.ttsVoices?.openai?.length?n.ttsVoices.openai:ni,f=n?.tts?.alibaba?.length?n.tts.alibaba:ri,p=n?.ttsVoices?.alibaba?.length?n.ttsVoices.alibaba:ii,m=n?.ttsVoices?.edge?.length?n.ttsVoices.edge:ai,h=n?.tts?.minimax?.length?n.tts.minimax:oi,g=n?.ttsVoices?.minimax?.length?n.ttsVoices.minimax:si;return(0,X.jsxs)(`section`,{className:`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`,children:[(0,X.jsxs)(`div`,{className:`mb-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,X.jsx)(B,{className:`size-4 text-accent`,strokeWidth:1.75}),e.tts.title]}),(0,X.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:e.tts.description})]}),(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(0,X.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,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.tts.enable}),(0,X.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.tts.enableDesc})]}),(0,X.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:t.enabled,onChange:e=>r({enabled:e.target.checked})})]}),t.enabled?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.tts.trigger}),(0,X.jsxs)(`select`,{className:Qr(),value:t.trigger,onChange:e=>r({trigger:e.target.value}),children:[(0,X.jsx)(`option`,{value:`off`,children:e.tts.triggerOff}),(0,X.jsx)(`option`,{value:`always`,children:e.tts.triggerAlways}),(0,X.jsx)(`option`,{value:`inbound`,children:e.tts.triggerInbound}),(0,X.jsx)(`option`,{value:`tagged`,children:e.tts.triggerTagged})]}),(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:l(t.trigger)})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.tts.provider}),(0,X.jsxs)(`select`,{className:Qr(),value:t.provider,onChange:e=>r({provider:e.target.value}),children:[(0,X.jsx)(`option`,{value:`openai`,children:e.tts.providerOpenai}),(0,X.jsx)(`option`,{value:`alibaba`,children:e.stt.alibaba}),(0,X.jsx)(`option`,{value:`minimax`,children:`MiniMax`}),(0,X.jsx)(`option`,{value:`edge`,children:e.tts.providerEdge}),(0,X.jsx)(`option`,{value:`tts-local-cli`,children:e.tts.providerLocalCli})]})]})]}),t.provider===`openai`?(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,X.jsx)($,{children:e.stt.apiKey}),(0,X.jsx)(`input`,{className:w(Zr(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.openai?.apiKey??``,onChange:e=>a({apiKey:e.target.value}),placeholder:`sk-...`}),(0,X.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (OPENAI_API_KEY)`]})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.stt.model}),(0,X.jsx)(`select`,{className:Qr(),value:t.openai?.model??``,onChange:e=>a({model:e.target.value}),children:u.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.tts.voice}),(0,X.jsx)(`select`,{className:Qr(),value:t.openai?.voice??``,onChange:e=>a({voice:e.target.value}),children:d.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}):null,t.provider===`alibaba`?(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,X.jsx)($,{children:e.stt.apiKey}),(0,X.jsx)(`input`,{className:w(Zr(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.alibaba?.apiKey??``,onChange:e=>i({apiKey:e.target.value}),placeholder:`sk-...`}),(0,X.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (DASHSCOPE_API_KEY)`]})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.stt.model}),(0,X.jsx)(`select`,{className:Qr(),value:t.alibaba?.model??``,onChange:e=>i({model:e.target.value}),children:f.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.tts.voice}),(0,X.jsx)(`select`,{className:Qr(),value:t.alibaba?.voice??``,onChange:e=>i({voice:e.target.value}),children:p.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}):null,t.provider===`minimax`?(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,X.jsx)($,{children:e.stt.apiKey}),(0,X.jsx)(`input`,{className:w(Zr(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.minimax?.apiKey??``,onChange:e=>s({apiKey:e.target.value}),placeholder:`eyJ...`}),(0,X.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[e.stt.apiKeyDesc,` (MINIMAX_API_KEY)`]})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.stt.model}),(0,X.jsx)(`select`,{className:Qr(),value:t.minimax?.model??``,onChange:e=>s({model:e.target.value}),children:h.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.tts.voice}),(0,X.jsx)(`select`,{className:Qr(),value:t.minimax?.voice??``,onChange:e=>s({voice:e.target.value}),children:g.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))})]})]}):null,t.provider===`edge`?(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.tts.voice}),(0,X.jsx)(`select`,{className:Qr(),value:t.edge?.voice??``,onChange:e=>o({voice:e.target.value}),children:m.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))}),(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.edgeHint})]}):null,t.provider===`tts-local-cli`?(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,X.jsx)($,{children:e.tts.localCli.command}),(0,X.jsx)(`input`,{className:w(Zr(),`font-mono text-xs`),type:`text`,autoComplete:`off`,spellCheck:!1,value:t[`tts-local-cli`]?.command??``,onChange:e=>c({command:e.target.value}),placeholder:e.tts.localCli.commandPlaceholder}),(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.commandDesc})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.tts.localCli.cwd}),(0,X.jsx)(`input`,{className:w(Zr(),`font-mono text-xs`),type:`text`,autoComplete:`off`,spellCheck:!1,value:t[`tts-local-cli`]?.cwd??``,onChange:e=>c({cwd:e.target.value}),placeholder:`/path/to/cwd`}),(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.cwdDesc})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)($,{children:e.tts.localCli.outputFormat}),(0,X.jsxs)(`select`,{className:Qr(),value:t[`tts-local-cli`]?.outputFormat??`wav`,onChange:e=>c({outputFormat:e.target.value}),children:[(0,X.jsx)(`option`,{value:`wav`,children:`wav`}),(0,X.jsx)(`option`,{value:`mp3`,children:`mp3`}),(0,X.jsx)(`option`,{value:`opus`,children:`opus`})]}),(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.outputFormatDesc})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5 sm:col-span-2`,children:[(0,X.jsx)($,{children:e.tts.localCli.timeoutMs}),(0,X.jsx)(`input`,{className:Zr(),type:`number`,min:0,step:1e3,value:typeof t[`tts-local-cli`]?.timeoutMs==`number`?String(t[`tts-local-cli`].timeoutMs):``,onChange:e=>{let t=e.target.value.trim();if(t===``){c({timeoutMs:void 0});return}let n=Number(t);Number.isFinite(n)&&n>=0&&c({timeoutMs:n})},placeholder:`30000`}),(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tts.localCli.timeoutMsDesc})]}),(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle sm:col-span-2`,children:e.tts.localCli.hint})]}):null]}):null]})]})}function $({children:e}){return(0,X.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e})}function di(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 fi(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 J(K(`/api/config`),{method:`PATCH`,body:JSON.stringify({tools:{web:{region:t,search:n}}})}),R()}function pi({label:e,description:t,children:n}){return(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e}),n,(0,X.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:t})]})}function mi(){return w(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,o,`dark:border-edge`)}function hi(){return w(ve,g)}var gi=[`brave`,`tavily`,`bing`,`searxng`];function _i(){return{type:`brave`,apiKey:``,url:``,disabled:!1}}function vi(){let e=f(e=>e.language),t=ge(e),n=t.webSearchSettings,r=t.logs,i=!!ze(e=>e.token),[a,o]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(!1),[p,h]=(0,Z.useState)(null),[g,_]=(0,Z.useState)(!1),v=(0,Z.useRef)(!1),{data:y,error:b,isLoading:x,mutate:S}=m(i),C=(0,Z.useMemo)(()=>y?.payload?.config===void 0?null:di(y.payload.config),[y]);(0,Z.useEffect)(()=>{if(!i){o(null),l(null),v.current=!1;return}C!==null&&(v.current||(o(C),l(C)))},[i,C]);let w=!!(i&&x&&y===void 0&&!b),T=b instanceof Error?b.message:b?String(b):null,D=(0,Z.useMemo)(()=>!a||!c?!1:JSON.stringify(a)!==JSON.stringify(c),[a,c]),O=(0,Z.useCallback)(e=>{v.current=!0,o(t=>t?{...t,...e}:null)},[]),k=(0,Z.useCallback)(async()=>{if(!(!a||u)){d(!0),h(null),_(!1);try{await fi(a);let e=structuredClone(a);l(e),o(e),v.current=!1,_(!0),window.setTimeout(()=>_(!1),2500)}catch(e){h(e instanceof Error?e.message:n.saveError)}finally{d(!1)}}},[a,u,n.saveError]),A=(0,Z.useCallback)(()=>{c&&(v.current=!1,o(structuredClone(c)),h(null),_(!1))},[c]);return i?w?(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col items-center gap-3 px-4 py-8`,children:[(0,X.jsx)(s,{className:`size-8 animate-spin text-fg-muted`,"aria-hidden":!0}),(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.loading})]}):a?(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-6`,children:[(0,X.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:n.title}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:n.subtitle}),(0,X.jsxs)(`a`,{href:qe(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,X.jsx)(N,{className:`size-3.5`})]})]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-end gap-2`,children:[g?(0,X.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,X.jsx)(E,{type:`button`,variant:`secondary`,disabled:!D||u,onClick:A,children:n.discard}),(0,X.jsx)(E,{type:`button`,variant:`primary`,disabled:!D||u,onClick:()=>void k(),children:u?n.saving:n.save})]})]}),D?(0,X.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,p?(0,X.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:p}):null,(0,X.jsxs)(Et,{children:[(0,X.jsx)(ct,{icon:oe,title:n.sectionRegion,subtitle:n.sectionRegionHint}),(0,X.jsx)(`div`,{className:`flex max-w-md flex-col gap-4`,children:(0,X.jsx)(pi,{label:n.regionLabel,description:n.regionDesc,children:(0,X.jsxs)(`select`,{className:hi(),value:a.regionMode,onChange:e=>O({regionMode:e.target.value}),children:[(0,X.jsx)(`option`,{value:`auto`,children:n.regionAuto}),(0,X.jsx)(`option`,{value:`cn`,children:n.regionCn}),(0,X.jsx)(`option`,{value:`global`,children:n.regionGlobal})]})})})]}),(0,X.jsxs)(Et,{children:[(0,X.jsx)(ct,{icon:oe,title:n.sectionSearch,subtitle:n.sectionSearchHint}),(0,X.jsxs)(`div`,{className:`flex max-w-xl flex-col gap-6`,children:[(0,X.jsx)(pi,{label:n.maxResultsLabel,description:n.maxResultsDesc,children:(0,X.jsx)(`input`,{type:`number`,min:1,max:50,className:mi(),value:a.maxResults,onChange:e=>O({maxResults:Math.max(1,Math.min(50,Number(e.target.value)||5))})})}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:n.providersTitle}),a.providers.map((e,t)=>(0,X.jsx)(yi,{row:e,labels:n,onChange:e=>{let n=[...a.providers];n[t]=e,O({providers:n})},onRemove:()=>{O({providers:a.providers.filter((e,n)=>n!==t)})}},t)),(0,X.jsxs)(E,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5 text-sm`,onClick:()=>O({providers:[...a.providers,_i()]}),children:[(0,X.jsx)(me,{className:`size-4`}),n.addProvider]})]})]})]}),(0,X.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:n.footerHint})]}):(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:p??T??n.loadError}),(0,X.jsx)(E,{type:`button`,variant:`secondary`,onClick:()=>void S(),children:r.refresh})]}):(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-4 px-4 py-6`,children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:n.title}),(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]})}function yi({row:e,labels:t,onChange:n,onRemove:r}){return(0,X.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,X.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,X.jsx)(`select`,{className:w(hi(),`min-w-[8rem]`),value:e.type,onChange:t=>n({...e,type:t.target.value,url:t.target.value===`searxng`?e.url:``}),children:gi.map(e=>(0,X.jsx)(`option`,{value:e,children:t.providerTypes[e]},e))}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-1.5 text-xs text-fg-muted`,children:[(0,X.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,X.jsx)(E,{type:`button`,variant:`ghost`,className:`h-8 px-2 text-fg-muted`,onClick:r,children:(0,X.jsx)(Ne,{className:`size-4`})})]})]}),e.type===`searxng`?(0,X.jsx)(pi,{label:t.urlLabel,description:t.urlDesc,children:(0,X.jsx)(`input`,{type:`url`,className:mi(),value:e.url,placeholder:`http://localhost:8080`,onChange:t=>n({...e,url:t.target.value})})}):null,(0,X.jsx)(pi,{label:t.apiKeyLabel,description:t.apiKeyDesc,children:(0,X.jsx)(`input`,{type:`password`,autoComplete:`off`,className:mi(),value:Ce(e.apiKey)?``:e.apiKey,placeholder:Ce(e.apiKey)?t.keyPlaceholderMasked:t.keyPlaceholder,onChange:t=>n({...e,apiKey:t.target.value})})})]})}var bi=[`appearance`,`system`,`agent-chat`,`agent-workspace`,`agent-browser`,`agent-runtime`,`agent-tools`,`agent-system-prompt`,`providers`,`models`,`image-models`,`voice`,`gateway`,`heartbeat`,`search`,`dreams`];function xi(){let{section:e}=a(),t=f(e=>e.language),n=ge(t);if(e===`agent`||e===`agents`)return(0,X.jsx)(h,{to:`/agents`,replace:!0});if(!e||!bi.includes(e))return(0,X.jsx)(h,{to:`/settings/appearance`,replace:!0});let r=e,i=n.settingsSections[r];return r===`appearance`?(0,X.jsx)(Vt,{}):r===`system`?(0,X.jsx)(Vr,{}):r===`agent-chat`?(0,X.jsx)(_t,{}):r===`agent-workspace`?(0,X.jsx)(vt,{}):r===`agent-browser`?(0,X.jsx)(St,{}):r===`agent-runtime`?(0,X.jsx)(bt,{}):r===`agent-tools`?(0,X.jsx)(st,{}):r===`agent-system-prompt`?(0,X.jsx)(mt,{}):r===`providers`?(0,X.jsx)(Rr,{}):r===`models`?(0,X.jsx)(wr,{}):r===`image-models`?(0,X.jsx)(Yn,{}):r===`voice`?(0,X.jsx)(ci,{}):r===`gateway`?(0,X.jsx)(On,{}):r===`heartbeat`?(0,X.jsx)(In,{}):r===`search`?(0,X.jsx)(vi,{}):r===`dreams`?(0,X.jsx)(Sn,{}):(0,X.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:i}),(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t===`zh`?`设置 · ${i}(即将推出)。`:`Settings · ${i} (coming soon).`})]})}export{xi as SettingsPage};
2
+ //# sourceMappingURL=settings-page-TrmEN1eQ.js.map