@xopcai/xopc 0.0.23 → 0.0.25

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 (170) hide show
  1. package/dist/extensions/feishu/xopc.extension.json +1 -1
  2. package/dist/extensions/telegram/xopc.extension.json +1 -1
  3. package/dist/gateway/static/root/assets/agents-C_bPhtBs.js +216 -0
  4. package/dist/gateway/static/root/assets/agents-C_bPhtBs.js.map +1 -0
  5. package/dist/gateway/static/root/assets/apps-page-DbzO48lg.js +2 -0
  6. package/dist/gateway/static/root/assets/apps-page-DbzO48lg.js.map +1 -0
  7. package/dist/gateway/static/root/assets/{attachment-preview-renderer-CebH7fCz.js → attachment-preview-renderer-CxMJMbD2.js} +4 -4
  8. package/dist/gateway/static/root/assets/{attachment-preview-renderer-CebH7fCz.js.map → attachment-preview-renderer-CxMJMbD2.js.map} +1 -1
  9. package/dist/gateway/static/root/assets/{attachment-process-heavy-Dbf1--O6.js → attachment-process-heavy-EFXPGfWk.js} +6 -6
  10. package/dist/gateway/static/root/assets/{attachment-process-heavy-Dbf1--O6.js.map → attachment-process-heavy-EFXPGfWk.js.map} +1 -1
  11. package/dist/gateway/static/root/assets/{attachment-utils-core-Dt6UxMPV.js → attachment-utils-core-ECbeoa9H.js} +1 -1
  12. package/dist/gateway/static/root/assets/attachment-utils-core-ECbeoa9H.js.map +1 -0
  13. package/dist/gateway/static/root/assets/channels-settings-CeGoU9v8.js +9 -0
  14. package/dist/gateway/static/root/assets/{channels-settings-CGzrrBlT.js.map → channels-settings-CeGoU9v8.js.map} +1 -1
  15. package/dist/gateway/static/root/assets/cn-BMCV0OMB.js +2 -0
  16. package/dist/gateway/static/root/assets/cn-BMCV0OMB.js.map +1 -0
  17. package/dist/gateway/static/root/assets/cron-page-DpEYUvxB.js +2 -0
  18. package/dist/gateway/static/root/assets/{cron-page-BGCdDf2w.js.map → cron-page-DpEYUvxB.js.map} +1 -1
  19. package/dist/gateway/static/root/assets/cron-utils-Cvv0F3pa.js +3 -0
  20. package/dist/gateway/static/root/assets/{cron-utils-Dnks4wWv.js.map → cron-utils-Cvv0F3pa.js.map} +1 -1
  21. package/dist/gateway/static/root/assets/dist-C41N3YrO.js +2 -0
  22. package/dist/gateway/static/root/assets/{dist-BG1ChbY9.js.map → dist-C41N3YrO.js.map} +1 -1
  23. package/dist/gateway/static/root/assets/{docx-preview-DxcHM3sR.js → docx-preview-F-jKDMNv.js} +2 -2
  24. package/dist/gateway/static/root/assets/{docx-preview-DxcHM3sR.js.map → docx-preview-F-jKDMNv.js.map} +1 -1
  25. package/dist/gateway/static/root/assets/{excel-worksheet-utils-Dk66snKA.js → excel-worksheet-utils-DPfAinZn.js} +1 -1
  26. package/dist/gateway/static/root/assets/{excel-worksheet-utils-Dk66snKA.js.map → excel-worksheet-utils-DPfAinZn.js.map} +1 -1
  27. package/dist/gateway/static/root/assets/extension-debug-page-CkkYZjNP.js +2 -0
  28. package/dist/gateway/static/root/assets/{extension-debug-page-CRC16AbL.js.map → extension-debug-page-CkkYZjNP.js.map} +1 -1
  29. package/dist/gateway/static/root/assets/extension-page-BjUIPVNG.js +2 -0
  30. package/dist/gateway/static/root/assets/{extension-page-BagrJnbm.js.map → extension-page-BjUIPVNG.js.map} +1 -1
  31. package/dist/gateway/static/root/assets/extension-settings-page-CwuFDOdk.js +2 -0
  32. package/dist/gateway/static/root/assets/extension-settings-page-CwuFDOdk.js.map +1 -0
  33. package/dist/gateway/static/root/assets/index-DwzwDCjW.js +150 -0
  34. package/dist/gateway/static/root/assets/index-DwzwDCjW.js.map +1 -0
  35. package/dist/gateway/static/root/assets/index-dhtHG1nU.css +1 -0
  36. package/dist/gateway/static/root/assets/{jszip.min-DVUfmhpE.js → jszip.min-CL3dfyxs.js} +1 -1
  37. package/dist/gateway/static/root/assets/{jszip.min-DVUfmhpE.js.map → jszip.min-CL3dfyxs.js.map} +1 -1
  38. package/dist/gateway/static/root/assets/logs-page-BtwGPuw2.js +2 -0
  39. package/dist/gateway/static/root/assets/{logs-page-Bo9EsE_D.js.map → logs-page-BtwGPuw2.js.map} +1 -1
  40. package/dist/gateway/static/root/assets/{pdf--jE7rvON.js → pdf-CX6ji-QC.js} +1 -1
  41. package/dist/gateway/static/root/assets/{pdf--jE7rvON.js.map → pdf-CX6ji-QC.js.map} +1 -1
  42. package/dist/gateway/static/root/assets/sessions-page-4rKFDn2k.js +2 -0
  43. package/dist/gateway/static/root/assets/{sessions-page-CDgXq8qp.js.map → sessions-page-4rKFDn2k.js.map} +1 -1
  44. package/dist/gateway/static/root/assets/settings-page-iYLSxQYc.js +2 -0
  45. package/dist/gateway/static/root/assets/settings-page-iYLSxQYc.js.map +1 -0
  46. package/dist/gateway/static/root/assets/skills-page-_siDuHeF.js +3 -0
  47. package/dist/gateway/static/root/assets/{skills-page-BRS5qYTw.js.map → skills-page-_siDuHeF.js.map} +1 -1
  48. package/dist/gateway/static/root/assets/vendor-swr-B5fPo7KK.js +2 -0
  49. package/dist/gateway/static/root/assets/{vendor-swr-Dp4nzp5h.js.map → vendor-swr-B5fPo7KK.js.map} +1 -1
  50. package/dist/gateway/static/root/assets/{xlsx-DVk38js7.js → xlsx-CPtvfmVF.js} +1 -1
  51. package/dist/gateway/static/root/assets/{xlsx-DVk38js7.js.map → xlsx-CPtvfmVF.js.map} +1 -1
  52. package/dist/gateway/static/root/index.html +5 -4
  53. package/dist/package.js +1 -1
  54. package/dist/src/agent/image/tool-model-config.js +2 -2
  55. package/dist/src/agent/image/tool-model-config.js.map +1 -1
  56. package/dist/src/agent/memory/dreaming/config.d.ts +20 -0
  57. package/dist/src/agent/memory/dreaming/config.js +44 -0
  58. package/dist/src/agent/memory/dreaming/config.js.map +1 -0
  59. package/dist/src/agent/memory/dreaming/constants.d.ts +8 -0
  60. package/dist/src/agent/memory/dreaming/constants.js +14 -0
  61. package/dist/src/agent/memory/dreaming/constants.js.map +1 -0
  62. package/dist/src/agent/memory/dreaming/deep-promotion.d.ts +22 -0
  63. package/dist/src/agent/memory/dreaming/deep-promotion.js +337 -0
  64. package/dist/src/agent/memory/dreaming/deep-promotion.js.map +1 -0
  65. package/dist/src/agent/memory/dreaming/preview.d.ts +26 -0
  66. package/dist/src/agent/memory/dreaming/preview.js +176 -0
  67. package/dist/src/agent/memory/dreaming/preview.js.map +1 -0
  68. package/dist/src/agent/memory/dreaming/short-term-store.d.ts +45 -0
  69. package/dist/src/agent/memory/dreaming/short-term-store.js +187 -0
  70. package/dist/src/agent/memory/dreaming/short-term-store.js.map +1 -0
  71. package/dist/src/agent/orchestration/agent-orchestrator.js +17 -0
  72. package/dist/src/agent/orchestration/agent-orchestrator.js.map +1 -1
  73. package/dist/src/agent/service.d.ts +6 -0
  74. package/dist/src/agent/service.js +52 -0
  75. package/dist/src/agent/service.js.map +1 -1
  76. package/dist/src/agent/tools/dreaming-tool.d.ts +7 -0
  77. package/dist/src/agent/tools/dreaming-tool.js +102 -0
  78. package/dist/src/agent/tools/dreaming-tool.js.map +1 -0
  79. package/dist/src/agent/tools/execute-code-tool.js +1 -1
  80. package/dist/src/agent/tools/execute-code-tool.js.map +1 -1
  81. package/dist/src/agent/tools/factory.js +5 -0
  82. package/dist/src/agent/tools/factory.js.map +1 -1
  83. package/dist/src/agent/tools/index.d.ts +1 -0
  84. package/dist/src/agent/tools/index.js +2 -1
  85. package/dist/src/agent/tools/memory-tool.js +9 -2
  86. package/dist/src/agent/tools/memory-tool.js.map +1 -1
  87. package/dist/src/cli/commands/extension-dev.d.ts +2 -0
  88. package/dist/src/cli/commands/extension-dev.js +196 -0
  89. package/dist/src/cli/commands/extension-dev.js.map +1 -0
  90. package/dist/src/cli/commands/extension-marketplace.d.ts +4 -0
  91. package/dist/src/cli/commands/extension-marketplace.js +145 -0
  92. package/dist/src/cli/commands/extension-marketplace.js.map +1 -0
  93. package/dist/src/cli/commands/extension-pack.d.ts +2 -0
  94. package/dist/src/cli/commands/extension-pack.js +242 -0
  95. package/dist/src/cli/commands/extension-pack.js.map +1 -0
  96. package/dist/src/cli/commands/extension.js +13 -0
  97. package/dist/src/cli/commands/extension.js.map +1 -1
  98. package/dist/src/cli/index.js +5 -1
  99. package/dist/src/cli/index.js.map +1 -1
  100. package/dist/src/config/schema.d.ts +39 -0
  101. package/dist/src/config/schema.js +17 -2
  102. package/dist/src/config/schema.js.map +1 -1
  103. package/dist/src/extensions/api.d.ts +6 -1
  104. package/dist/src/extensions/api.js +30 -0
  105. package/dist/src/extensions/api.js.map +1 -1
  106. package/dist/src/extensions/engine-check.d.ts +14 -0
  107. package/dist/src/extensions/engine-check.js +148 -0
  108. package/dist/src/extensions/engine-check.js.map +1 -0
  109. package/dist/src/extensions/loader.js +23 -0
  110. package/dist/src/extensions/loader.js.map +1 -1
  111. package/dist/src/extensions/marketplace.d.ts +24 -0
  112. package/dist/src/extensions/marketplace.js +98 -0
  113. package/dist/src/extensions/marketplace.js.map +1 -0
  114. package/dist/src/extensions/normalize-manifest.js +16 -4
  115. package/dist/src/extensions/normalize-manifest.js.map +1 -1
  116. package/dist/src/extensions/sdk/index.d.ts +2 -0
  117. package/dist/src/extensions/sdk/index.js +2 -1
  118. package/dist/src/extensions/sdk/index.js.map +1 -1
  119. package/dist/src/extensions/sdk/testing.d.ts +49 -3
  120. package/dist/src/extensions/sdk/testing.js +174 -5
  121. package/dist/src/extensions/sdk/testing.js.map +1 -1
  122. package/dist/src/extensions/types/core.d.ts +5 -0
  123. package/dist/src/extensions/types/manifest.d.ts +17 -0
  124. package/dist/src/extensions/when-context.d.ts +6 -0
  125. package/dist/src/extensions/when-context.js +28 -0
  126. package/dist/src/extensions/when-context.js.map +1 -0
  127. package/dist/src/extensions/when-expression.d.ts +11 -0
  128. package/dist/src/extensions/when-expression.js +215 -0
  129. package/dist/src/extensions/when-expression.js.map +1 -0
  130. package/dist/src/gateway/hono/app.js +1 -1
  131. package/dist/src/gateway/hono/app.js.map +1 -1
  132. package/dist/src/gateway/hono/lib/config-payload.d.ts +13 -0
  133. package/dist/src/gateway/hono/routes/auth-registry-extensions.js +28 -0
  134. package/dist/src/gateway/hono/routes/auth-registry-extensions.js.map +1 -1
  135. package/dist/src/gateway/hono/routes/config.js +48 -0
  136. package/dist/src/gateway/hono/routes/config.js.map +1 -1
  137. package/dist/src/gateway/hono/routes/dreaming.d.ts +3 -0
  138. package/dist/src/gateway/hono/routes/dreaming.js +198 -0
  139. package/dist/src/gateway/hono/routes/dreaming.js.map +1 -0
  140. package/dist/src/gateway/hono/routes/index.js +2 -0
  141. package/dist/src/gateway/hono/routes/index.js.map +1 -1
  142. package/dist/src/gateway/lock.js +1 -1
  143. package/dist/src/gateway/service.js +7 -0
  144. package/dist/src/gateway/service.js.map +1 -1
  145. package/dist/src/providers/index.d.ts +6 -3
  146. package/dist/src/providers/index.js +12 -23
  147. package/dist/src/providers/index.js.map +1 -1
  148. package/package.json +2 -1
  149. package/dist/gateway/static/root/assets/agents-BY_DaknM.js +0 -216
  150. package/dist/gateway/static/root/assets/agents-BY_DaknM.js.map +0 -1
  151. package/dist/gateway/static/root/assets/apps-page-BO3nQbJY.js +0 -2
  152. package/dist/gateway/static/root/assets/apps-page-BO3nQbJY.js.map +0 -1
  153. package/dist/gateway/static/root/assets/attachment-utils-core-Dt6UxMPV.js.map +0 -1
  154. package/dist/gateway/static/root/assets/channels-settings-CGzrrBlT.js +0 -9
  155. package/dist/gateway/static/root/assets/cron-page-BGCdDf2w.js +0 -2
  156. package/dist/gateway/static/root/assets/cron-utils-Dnks4wWv.js +0 -3
  157. package/dist/gateway/static/root/assets/dist-BG1ChbY9.js +0 -2
  158. package/dist/gateway/static/root/assets/extension-debug-page-CRC16AbL.js +0 -2
  159. package/dist/gateway/static/root/assets/extension-page-BagrJnbm.js +0 -2
  160. package/dist/gateway/static/root/assets/extension-settings-page-DEpxRKKK.js +0 -2
  161. package/dist/gateway/static/root/assets/extension-settings-page-DEpxRKKK.js.map +0 -1
  162. package/dist/gateway/static/root/assets/index-CYVs9x8D.css +0 -1
  163. package/dist/gateway/static/root/assets/index-KNzRh6gu.js +0 -150
  164. package/dist/gateway/static/root/assets/index-KNzRh6gu.js.map +0 -1
  165. package/dist/gateway/static/root/assets/logs-page-Bo9EsE_D.js +0 -2
  166. package/dist/gateway/static/root/assets/sessions-page-CDgXq8qp.js +0 -2
  167. package/dist/gateway/static/root/assets/settings-page-BWMTFST6.js +0 -2
  168. package/dist/gateway/static/root/assets/settings-page-BWMTFST6.js.map +0 -1
  169. package/dist/gateway/static/root/assets/skills-page-BRS5qYTw.js +0 -3
  170. package/dist/gateway/static/root/assets/vendor-swr-Dp4nzp5h.js +0 -2
@@ -0,0 +1,2 @@
1
+ import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{i as t,t as n}from"./vendor-react-DbimaAId.js";import{i as r,o as i}from"./vendor-swr-B5fPo7KK.js";import{t as a}from"./cn-BMCV0OMB.js";import{A as o,Dn as s,Dr as c,Gn as l,Gt as u,In as d,Ir as f,Jt as p,Kn as m,Nr as h,Pn as g,Pr as _,Qt as v,Tn as y,Ur as b,Ut as x,V as S,Vn as C,W as w,Wn as T,Wr as E,Wt as D,Xt as O,Zt as k,_n as A,_t as j,a as ee,an as M,at as te,br as N,c as P,ct as F,dn as I,dt as L,f as R,ft as z,gt as B,hr as ne,ht as V,i as re,in as H,ir as ie,jn as ae,jr as U,k as W,kn as oe,kr as G,lt as se,mr as ce,mt as le,n as ue,nn as de,nr as fe,o as pe,on as K,ot as me,p as he,pn as ge,pr as _e,pt as ve,qn as q,qr as ye,qt as be,r as xe,rr as Se,s as Ce,sn as J,t as we,un as Te,ut as Ee,yr as De,zn as Oe}from"./index-DwzwDCjW.js";import{a as ke,p as Ae,v as je}from"./cron-utils-Cvv0F3pa.js";import{i as Y,n as Me,r as Ne,t as Pe}from"./agents-C_bPhtBs.js";var X=n();function Fe(){return a(`rounded-xl border border-edge-subtle bg-surface-base px-4 py-1 sm:px-5`)}function Ie({scheme:e}){return e===`emerald`?(0,X.jsxs)(`div`,{className:`flex h-10 w-full overflow-hidden rounded-md border border-edge-subtle`,children:[(0,X.jsxs)(`div`,{className:`flex flex-1 flex-col gap-1 bg-[#0a0a0a] p-1.5`,children:[(0,X.jsx)(`div`,{className:`h-1 w-8 rounded-full bg-[#134e2a]`}),(0,X.jsx)(`div`,{className:`h-1 w-5 rounded-full bg-[#134e2a]`})]}),(0,X.jsx)(`div`,{className:`w-1.5 bg-[#10b981]`}),(0,X.jsxs)(`div`,{className:`flex flex-1 flex-col gap-1 bg-[#000000] p-1.5`,children:[(0,X.jsx)(`div`,{className:`h-1 w-6 rounded-full bg-[#34d399]`}),(0,X.jsx)(`div`,{className:`h-1 w-9 rounded-full bg-[#065f46]`}),(0,X.jsx)(`div`,{className:`h-1 w-4 rounded-full bg-[#065f46]`})]})]}):(0,X.jsxs)(`div`,{className:`flex h-10 w-full overflow-hidden rounded-md border border-edge-subtle`,children:[(0,X.jsxs)(`div`,{className:`flex flex-1 flex-col gap-1 bg-[#f5f5f7] p-1.5`,children:[(0,X.jsx)(`div`,{className:`h-1 w-8 rounded-full bg-[#d2d2d7]`}),(0,X.jsx)(`div`,{className:`h-1 w-5 rounded-full bg-[#d2d2d7]`})]}),(0,X.jsx)(`div`,{className:`w-1.5 bg-[#2563eb]`}),(0,X.jsxs)(`div`,{className:`flex flex-1 flex-col gap-1 bg-[#ffffff] p-1.5`,children:[(0,X.jsx)(`div`,{className:`h-1 w-6 rounded-full bg-[#1d1d1f]`}),(0,X.jsx)(`div`,{className:`h-1 w-9 rounded-full bg-[#d2d2d7]`}),(0,X.jsx)(`div`,{className:`h-1 w-4 rounded-full bg-[#d2d2d7]`})]})]})}var Le=[{value:`default`,labelKey:`colorSchemeDefault`},{value:`emerald`,labelKey:`colorSchemeLightGreen`}];function Re(){let e=K(v(e=>e.language)).appearanceSettings,t=k(e=>e.colorScheme),n=k(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 sm:grid-cols-3`,children:Le.map(({value:r,labelKey:i})=>{let o=t===r;return(0,X.jsxs)(`button`,{type:`button`,"aria-pressed":o,onClick:()=>n(r),className:a(`flex flex-col gap-2 rounded-xl border-2 p-2.5 text-left transition-[border-color,box-shadow] duration-150`,o?`border-accent shadow-[0_0_0_1px_var(--color-accent)]`:`border-edge-subtle hover:border-edge`),children:[(0,X.jsx)(Ie,{scheme:r}),(0,X.jsx)(`span`,{className:a(`text-xs font-medium leading-none`,o?`text-accent-fg`:`text-fg-muted`),children:e[i]})]},r)})})]})}function ze(){let e=K(v(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:Fe(),"aria-labelledby":`pref-language-heading`,children:[(0,X.jsx)(`h2`,{id:`pref-language-heading`,className:`sr-only`,children:e.languageTitle}),(0,X.jsx)(O,{variant:`page`,sections:[`language`]})]}),(0,X.jsxs)(`section`,{className:Fe(),"aria-labelledby":`pref-appearance-heading`,children:[(0,X.jsx)(`h2`,{id:`pref-appearance-heading`,className:`sr-only`,children:e.themeTitle}),(0,X.jsx)(O,{variant:`page`,sections:[`theme`,`font`]}),(0,X.jsx)(Re,{})]})]})}var Z=e(t(),1);function Be(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Ve(e){let t=Be(e)?e:{},n=Be(t.gateway)?t.gateway:{},r=Be(n.auth)?n.auth:{},i=r.mode===`none`||r.mode===`token`?r.mode:`token`,a=(Be(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 He(e){let t=e.auth.token.trim().length>0?{mode:e.auth.mode,token:e.auth.token}:{mode:e.auth.mode};await u(x(`/api/config`),{method:`PATCH`,body:JSON.stringify({gateway:{auth:t},update:{channel:e.updateChannel}})}),W()}function Ue(){return a(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,M,`dark:border-edge`)}function We(){let e=v(e=>e.language),t=K(e),n=t.gatewaySettings,r=be(e=>e.token),i=be(e=>e.tokenExpired),a=be(e=>e.openTokenDialog),c=!!r,[l,u]=(0,Z.useState)(null),[d,f]=(0,Z.useState)(null),[m,h]=(0,Z.useState)(!1),[g,_]=(0,Z.useState)(null),[y,b]=(0,Z.useState)(!1),[x,S]=(0,Z.useState)(!1),[C,w]=(0,Z.useState)(!1),T=(0,Z.useRef)(!1),{data:E,error:D,isLoading:O,mutate:k}=o(c),A=(0,Z.useMemo)(()=>E?.payload?.config===void 0?null:structuredClone(Ve(E.payload.config)),[E]);(0,Z.useEffect)(()=>{if(!c){u(null),f(null),T.current=!1;return}A!==null&&(T.current||(u(A),f(structuredClone(A)),b(!1)))},[c,A]);let j=!!(c&&O&&E===void 0&&!D),ee=D instanceof Error?D.message:D?String(D):null,M=(0,Z.useMemo)(()=>!l||!d?!1:JSON.stringify(l)!==JSON.stringify(d),[l,d]),te=(0,Z.useCallback)(e=>{T.current=!0,u(t=>t?{...t,auth:{...t.auth,...e}}:null)},[]),N=(0,Z.useCallback)(e=>{T.current=!0,u(t=>t?{...t,updateChannel:e}:null)},[]),P=(0,Z.useCallback)(async()=>{if(!(!l||m)){h(!0),_(null),b(!1);try{await He(l),T.current=!1,f(structuredClone(l)),b(!0),window.setTimeout(()=>b(!1),2500)}catch(e){_(e instanceof Error?e.message:n.saveError)}finally{h(!1)}}},[l,m,n.saveError]),F=(0,Z.useCallback)(async()=>{let e=l?.auth.token;e&&(await navigator.clipboard.writeText(e).catch(()=>{}),w(!0),window.setTimeout(()=>w(!1),2e3))},[l?.auth.token]);return c?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)(q,{className:`size-4 animate-spin`}),n.loading]})}):l?(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:p(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)(ne,{className:`size-3.5`})]})]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[y?(0,X.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,X.jsx)(J,{type:`button`,variant:`primary`,disabled:!M||m,onClick:()=>void P(),children:m?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)(G,{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)(J,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:()=>a(),children:n.updateToken})})]}):null,M?(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,l.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)(s,{className:`size-4 text-accent`,strokeWidth:1.75}),t.settingsSections.gateway]}),(0,X.jsxs)(`div`,{className:`space-y-4`,children:[(l.host||l.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:l.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:l.port==null?`—`:String(l.port)})]}),(0,X.jsx)(`p`,{className:`sm:col-span-2 text-xs text-fg-subtle`,children:n.listenHint})]}),(0,X.jsx)(Ge,{g:n,value:l.auth.token,show:x,copied:C,onToggleShow:()=>S(e=>!e),onCopy:()=>void F(),onChange:e=>te({token:e})}),(0,X.jsx)(J,{type:`button`,variant:`secondary`,className:`w-full sm:w-auto`,onClick:()=>a(),children:n.changeToken}),(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:l.updateChannel,onChange:e=>N(e.target.value),className:Ue(),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??ee??n.loadError}),(0,X.jsx)(J,{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 Ge({g:e,value:t,show:n,copied:r,onToggleShow:i,onCopy:o,onChange:s}){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:a(Ue(),`min-w-0 flex-1 font-mono text-xs`),type:n?`text`:`password`,autoComplete:`off`,value:t,onChange:e=>s(e.target.value),placeholder:e.tokenPlaceholder}),t?(0,X.jsxs)(J,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:o,children:[r?(0,X.jsx)(_,{className:`size-3.5`}):(0,X.jsx)(N,{className:`size-3.5`}),r?e.copied:e.copy]}):null,(0,X.jsxs)(J,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:i,children:[n?(0,X.jsx)(ce,{className:`size-3.5`}):(0,X.jsx)(_e,{className:`size-3.5`}),n?e.hide:e.show]})]}),(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle`,children:e.tokenHelp})]})}function Ke(){return x(`/api/channels/status`)}var qe=Ae;function Je(){return x(`/api/workspace/heartbeat-md`)}async function Ye(){let e=await u(Je());return typeof e.payload?.content==`string`?e.payload.content:``}function Xe(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Ze(e){let t=Xe(e)?e:{},n=Xe(t.gateway)?t.gateway:{},r=Xe(n.heartbeat)?n.heartbeat:{},i=r.activeHours,a=Xe(i)?i:null,o=a&&typeof a.start==`string`&&typeof a.end==`string`&&a.start&&a.end?{start:a.start,end:a.end,timezone:typeof a.timezone==`string`?a.timezone:``}:null;return{enabled:!!(r.enabled??!0),intervalMs:typeof r.intervalMs==`number`&&Number.isFinite(r.intervalMs)?r.intervalMs:18e5,target:typeof r.target==`string`?r.target:``,targetChatId:typeof r.targetChatId==`string`?r.targetChatId:``,prompt:typeof r.prompt==`string`?r.prompt:``,ackMaxChars:typeof r.ackMaxChars==`number`&&Number.isFinite(r.ackMaxChars)?r.ackMaxChars:``,isolatedSession:!!r.isolatedSession,activeHours:o}}function Qe(e){let t={enabled:e.enabled,intervalMs:e.intervalMs};return e.target.trim()?t.target=e.target.trim():t.target=null,e.targetChatId.trim()?t.targetChatId=e.targetChatId.trim():t.targetChatId=null,e.prompt.trim()?t.prompt=e.prompt.trim():t.prompt=null,e.ackMaxChars===``||e.ackMaxChars===void 0?t.ackMaxChars=null:t.ackMaxChars=e.ackMaxChars,e.isolatedSession?t.isolatedSession=!0:t.isolatedSession=null,e.activeHours?.start?.trim()&&e.activeHours?.end?.trim()?t.activeHours={start:e.activeHours.start.trim(),end:e.activeHours.end.trim(),...e.activeHours.timezone.trim()?{timezone:e.activeHours.timezone.trim()}:{}}:t.activeHours=null,t}async function $e(e){await u(x(`/api/config`),{method:`PATCH`,body:JSON.stringify({gateway:{heartbeat:Qe(e)}})}),W()}async function et(e){await u(x(`/api/workspace/heartbeat-md`),{method:`PUT`,body:JSON.stringify({content:e})}),i(Je())}async function tt(e){await u(x(`/api/heartbeat/trigger`),{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify(e?{reason:e}:{})})}var nt=[3e4,6e4,3e5,6e5,9e5,18e5,36e5,72e5],rt=new Set(nt);function it(){return a(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,M,`dark:border-edge`)}function at(){return a(H,de)}function ot(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 st(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 ct(){let e=v(e=>e.language),t=K(e),n=t.heartbeatSettings,i=!!be(e=>e.token),[s,c]=(0,Z.useState)(null),[l,u]=(0,Z.useState)(null),[f,m]=(0,Z.useState)(``),[h,g]=(0,Z.useState)(``),[_,y]=(0,Z.useState)(!1),[b,x]=(0,Z.useState)(!1),[S,C]=(0,Z.useState)(null),[w,T]=(0,Z.useState)(!1),[E,D]=(0,Z.useState)(!1),[O,k]=(0,Z.useState)(!1),[A,j]=(0,Z.useState)(!1),[ee,M]=(0,Z.useState)(null),[te,N]=(0,Z.useState)([]),{data:P,error:F,isLoading:I,mutate:L}=o(i),{data:R,error:z,isLoading:B,mutate:V}=r(i?Je():null,Ye,{revalidateOnFocus:!1}),{data:re=[]}=r(i?Ke():null,qe,{revalidateOnFocus:!1}),H=(0,Z.useMemo)(()=>ot(P?.payload?.config),[P]),ae=(0,Z.useMemo)(()=>Ze(P?.payload?.config??{}),[P]),U=(0,Z.useMemo)(()=>!s||!l?!1:JSON.stringify(s)!==JSON.stringify(l),[s,l]),W=(0,Z.useMemo)(()=>f!==h,[f,h]);(0,Z.useEffect)(()=>{if(!i){c(null),u(null);return}if(P!==void 0&&!U){let e=structuredClone(ae);c(e),u(e),T(!1)}},[i,P,ae,U]),(0,Z.useEffect)(()=>{!i||R===void 0||W||(m(R),g(R),D(!1))},[i,R,W]);let oe=F instanceof Error?F.message:F?String(F):z instanceof Error?z.message:z?String(z):null,G=!!(i&&(P===void 0||R===void 0)&&!oe&&(I||B));(0,Z.useEffect)(()=>{if(!i||!s){N([]);return}let e=s.target.trim();if(!e){N([]);return}let t=!1;return je(e).then(e=>{t||N(e)}),()=>{t=!0}},[i,s?.target]);let se=(0,Z.useCallback)(()=>{let e=s?.target?.trim();e&&je(e).then(N)},[s?.target]),ce=(0,Z.useCallback)(async()=>{k(!0),j(!1),M(null);try{await tt(),j(!0),window.setTimeout(()=>j(!1),3e3)}catch(e){M(e instanceof Error?e.message:n.triggerError)}finally{k(!1)}},[n.triggerError]),le=(0,Z.useCallback)(e=>{c(t=>t?{...t,...e}:null)},[]),ue=(0,Z.useCallback)(async()=>{if(!(!s||_)){y(!0),C(null),T(!1);try{await $e(s),u(structuredClone(s)),T(!0),window.setTimeout(()=>T(!1),2500)}catch(e){C(e instanceof Error?e.message:n.saveConfigError)}finally{y(!1)}}},[s,_,n.saveConfigError]),de=(0,Z.useCallback)(async()=>{if(!b){x(!0),C(null),D(!1);try{await et(f),g(f),D(!0),window.setTimeout(()=>D(!1),2500)}catch(e){C(e instanceof Error?e.message:n.saveDocError)}finally{x(!1)}}},[f,b,n.saveDocError]);return i?G?(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)(q,{className:`size-4 animate-spin`}),n.loading]})}):s?(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:p(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)(ne,{className:`size-3.5`})]})]})}),H?(0,X.jsxs)(`p`,{className:`text-xs text-fg-subtle`,children:[n.workspaceLabel,`: `,(0,X.jsx)(`span`,{className:`font-mono text-fg-muted`,children:H})]}):null,S?(0,X.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:S}):null,(0,X.jsxs)(Me,{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)(ie,{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)(J,{type:`button`,variant:`secondary`,className:`inline-flex items-center gap-2`,disabled:O,onClick:()=>void ce(),children:[O?(0,X.jsx)(q,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,X.jsx)(d,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),O?n.triggering:n.triggerNow]}),A?(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}),ee?(0,X.jsx)(`p`,{className:`mb-3 text-sm text-red-600 dark:text-red-400`,children:ee}):null,(0,X.jsx)(lt,{h:n,cron:t.cron,form:s,channels:re,sessionChatIds:te,onRefreshChatIds:se,update:le,inputClassName:it,selectClassName:at}),(0,X.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-2`,children:[w?(0,X.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.savedConfig}):null,(0,X.jsx)(J,{type:`button`,variant:`primary`,disabled:!U||_,onClick:()=>void ue(),children:_?n.savingConfig:n.saveConfig}),U?(0,X.jsx)(`span`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedConfig}):null]})]}),(0,X.jsxs)(Me,{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:a(it(),`min-h-[12rem] resize-y font-mono text-xs leading-relaxed`),value:f,onChange:e=>m(e.target.value),spellCheck:!1,"aria-label":n.docSection}),(0,X.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center gap-2`,children:[E?(0,X.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.savedDoc}):null,(0,X.jsx)(J,{type:`button`,variant:`primary`,disabled:!W||b,onClick:()=>void de(),children:b?n.savingDoc:n.saveDoc}),W?(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:S??oe??n.loadError}),(0,X.jsx)(J,{type:`button`,variant:`secondary`,onClick:()=>{L(),V()},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 lt({h:e,cron:t,form:n,channels:r,sessionChatIds:i,onRefreshChatIds:o,update:s,inputClassName:c,selectClassName:l}){let u=(0,Z.useMemo)(()=>new Set(r.map(e=>e.name)),[r]),d=n.target.trim(),f=!!(d&&!u.has(d)),p=(0,Z.useMemo)(()=>rt.has(n.intervalMs)?String(n.intervalMs):``,[n.intervalMs]),[m,h]=(0,Z.useState)(null),g=Math.max(1,Math.round(n.intervalMs/1e3)),_=m===null?String(g):m;return(0,Z.useEffect)(()=>{h(null)},[n.intervalMs]),(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=>s({enabled:e.target.checked})}),e.enable]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,X.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e.interval}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,X.jsx)(`span`,{className:`text-xs font-medium text-fg-muted`,children:e.intervalSecondsLabel}),(0,X.jsxs)(`div`,{className:`flex gap-2`,children:[(0,X.jsx)(`input`,{type:`number`,min:1,step:1,className:a(c(),`min-w-0 flex-1`),value:_,onChange:e=>{let t=e.target.value;h(t);let n=parseInt(t,10);Number.isFinite(n)&&n>=1&&s({intervalMs:n*1e3})},onBlur:()=>{if(m===null)return;let e=parseInt(m,10);s(!Number.isFinite(e)||e<1?{intervalMs:1e3}:{intervalMs:e*1e3}),h(null)}}),(0,X.jsxs)(`select`,{className:a(l(),`max-w-[11rem] shrink-0 text-xs`),value:p,onChange:e=>{let t=e.target.value;t&&(s({intervalMs:parseInt(t,10)}),h(null))},children:[(0,X.jsx)(`option`,{value:``,children:e.intervalPresets.custom}),nt.map(t=>(0,X.jsx)(`option`,{value:String(t),children:st(t,e.intervalPresets)},t))]})]})]}),(0,X.jsx)(`p`,{className:`text-xs text-fg-muted`,children:e.intervalHintPreset}),(0,X.jsx)(`p`,{className:`text-xs text-fg-subtle`,children: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:l(),value:d,onChange:e=>{s({target:e.target.value.trim(),targetChatId:``})},children:[(0,X.jsx)(`option`,{value:``,children:e.channelNone}),f?(0,X.jsxs)(`option`,{value:d,children:[d,` (`,e.customChannelSuffix,`)`]}):null,r.map(e=>(0,X.jsxs)(`option`,{value:e.name,disabled:!e.enabled,children:[e.name,` `,e.enabled?``:`(disabled)`]},e.name))]})]}),d?(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)(J,{type:`button`,variant:`ghost`,className:`h-7 gap-1 px-2 text-xs`,title:t.refreshRecipientHint,onClick:o,children:[(0,X.jsx)(ae,{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:a(c(),`min-w-0 flex-1`),value:n.targetChatId,onChange:e=>s({targetChatId:e.target.value}),placeholder:t.recipientPlaceholder,autoComplete:`off`}),(0,X.jsxs)(`select`,{className:a(l(),`max-w-[10rem] shrink-0 text-xs`),value:n.targetChatId,onChange:e=>{let t=e.target.value;t&&s({targetChatId:t})},children:[(0,X.jsx)(`option`,{value:``,children:t.selectRecipient}),i.length>0?i.map(e=>(0,X.jsx)(`option`,{value:e.chatId,children:ke(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:a(c(),`min-h-[4.5rem] resize-y font-mono text-xs`),value:n.prompt,onChange:e=>s({prompt:e.target.value}),placeholder:e.promptPlaceholder}),(0,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:c(),value:n.ackMaxChars===``?``:n.ackMaxChars,onChange:e=>{let t=e.target.value;if(t===``)s({ackMaxChars:``});else{let e=parseInt(t,10);s({ackMaxChars:Number.isFinite(e)?e:``})}},placeholder:e.ackDefaultPlaceholder}),(0,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=>s({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.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.activeHoursTitle}),n.activeHours?(0,X.jsxs)(`div`,{className:`grid gap-3 sm:grid-cols-3`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`mb-1 text-xs text-fg`,children:e.activeStart}),(0,X.jsx)(`input`,{className:c(),value:n.activeHours.start,onChange:e=>s({activeHours:{...n.activeHours,start:e.target.value}}),placeholder:`09:00`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`mb-1 text-xs text-fg`,children:e.activeEnd}),(0,X.jsx)(`input`,{className:c(),value:n.activeHours.end,onChange:e=>s({activeHours:{...n.activeHours,end:e.target.value}}),placeholder:`22:00`})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`mb-1 text-xs text-fg`,children:e.activeTimezone}),(0,X.jsx)(`input`,{className:c(),value:n.activeHours.timezone,onChange:e=>s({activeHours:{...n.activeHours,timezone:e.target.value}}),placeholder:`Asia/Shanghai`})]})]}):(0,X.jsx)(J,{type:`button`,variant:`secondary`,className:`text-sm`,onClick:()=>s({activeHours:{start:`09:00`,end:`22:00`,timezone:``}}),children:e.addActiveHours}),n.activeHours?(0,X.jsx)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:(0,X.jsx)(J,{type:`button`,variant:`secondary`,className:`text-xs`,onClick:()=>s({activeHours:null}),children:e.clearActiveHours})}):null,(0,X.jsx)(`p`,{className:`mt-2 text-xs text-fg-subtle`,children:e.activeHoursHint})]})]})}var ut=[{value:`openai-completions`,label:`OpenAI Completions`},{value:`openai-responses`,label:`OpenAI Responses`},{value:`anthropic-messages`,label:`Anthropic Messages`},{value:`google-generative-ai`,label:`Google Generative AI`},{value:`azure-openai-responses`,label:`Azure OpenAI`},{value:`bedrock-converse-stream`,label:`AWS Bedrock`},{value:`openai-codex-responses`,label:`OpenAI Codex`},{value:`google-gemini-cli`,label:`Google Gemini CLI`},{value:`google-vertex`,label:`Google Vertex AI`}];function dt(e){if(!e||typeof e!=`object`)return;let t=e;if(typeof t.error==`string`)return t.error;if(t.error&&typeof t.error==`object`&&`message`in t.error){let e=t.error.message;return typeof e==`string`?e:void 0}}function ft(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 pt(){let e=await D(x(`/api/models-json`)),t=await e.json().catch(()=>({}));if(!e.ok||!t.ok||!t.payload)throw Error(dt(t)||`HTTP ${e.status}`);return{...t.payload,config:ft(t.payload.config)}}async function mt(e){let t=await D(x(`/api/models-json/validate`),{method:`POST`,body:JSON.stringify({config:e})}),n=await t.json().catch(()=>({}));if(!t.ok||!n.ok||!n.payload)throw Error(dt(n)||`HTTP ${t.status}`);return n.payload}async function ht(e){let t=await D(x(`/api/models-json`),{method:`PATCH`,body:JSON.stringify({config:e})}),n=await t.json().catch(()=>({}));if(!t.ok||!n.ok||!n.payload)throw Error(dt(n)||`HTTP ${t.status}`);return n.payload}async function gt(){let e=await D(x(`/api/models-json/reload`),{method:`POST`}),t=await e.json().catch(()=>({}));if(!e.ok||!t.ok||!t.payload)throw Error(dt(t)||`HTTP ${e.status}`);return t.payload}async function _t(e){let t=await D(x(`/api/models-json/test-api-key`),{method:`POST`,body:JSON.stringify({value:e})}),n=await t.json().catch(()=>({}));if(!t.ok||!n.ok||!n.payload)throw Error(dt(n)||`HTTP ${t.status}`);return n.payload}function vt(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 yt(e){return e.startsWith(`!`)}function bt(e){return/^[A-Z][A-Z0-9_]*$/.test(e)}function xt(e){return yt(e)?`shell`:bt(e)?`env`:`literal`}function St(e){return e?e.length<=8?`••••`:`${e.slice(0,4)}••••${e.slice(-4)}`:``}var Ct={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 wt(e){return e===`openrouter`?`openrouter`:e===`zhipuCn`?`zhipu-cn`:e===`zaiGeneral`?`zai`:e}var Tt=[{value:`text`,labelKey:`inputTextOnly`},{value:`text,image`,labelKey:`inputTextVision`}];function Et(){return a(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,M,`dark:border-edge`)}function Dt(){return a(H,de)}function Ot(e){return(e.input||[`text`]).includes(`image`)?`text,image`:`text`}function kt(e){return e===`text,image`?[`text`,`image`]:[`text`]}function At(e,t,n){return{...e,providers:{...e.providers,[t]:{...e.providers[t],...n}}}}function jt(e,t){let n={...e.providers};return delete n[t],{...e,providers:n}}function Mt(e,t,n){return{...e,providers:{...e.providers,[t]:n}}}function Nt({open:e,onOpenChange:t,presetKey:n,onConfirm:r,m:i}){let[o,s]=(0,Z.useState)(``),[c,l]=(0,Z.useState)(`custom`),[u,d]=(0,Z.useState)(``),[f,p]=(0,Z.useState)(`openai-completions`),[m,h]=(0,Z.useState)(``),[g,_]=(0,Z.useState)(null);(0,Z.useEffect)(()=>{if(!e)return;_(null);let t=n||null;if(t&&Ct[t]){let e=Ct[t];l(t),d(e.baseUrl||``),p(e.api||`openai-completions`),h(e.apiKey??``),s(wt(t))}else l(`custom`),s(``),d(``),p(`openai-completions`),h(``)},[e,n]);let v=e=>{if(l(e),e===`custom`)return;let t=Ct[e];t&&(d(t.baseUrl||``),p(t.api||`openai-completions`),h(t.apiKey??``),s(wt(e)))};return(0,X.jsx)(Ee,{open:e,onOpenChange:t,children:(0,X.jsxs)(se,{children:[(0,X.jsx)(F,{className:`xopc-dialog-overlay fixed inset-0 z-50 bg-scrim`}),(0,X.jsxs)(me,{className:a(`xopc-dialog-content fixed left-1/2 top-1/2 z-50 max-h-[min(90vh,640px)] w-[min(100%-2rem,32rem)] -translate-x-1/2 -translate-y-1/2`,`overflow-y-auto rounded-xl border border-edge bg-surface-panel p-4 shadow-popover dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,X.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(L,{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)(te,{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)(I,{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:Dt(),value:c,onChange:e=>v(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:Et(),value:o,onChange:e=>s(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:Et(),value:u,onChange:e=>d(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:Dt(),value:f,onChange:e=>p(e.target.value),children:ut.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:Et(),value:m,onChange:e=>h(e.target.value),placeholder:i.apiKeyPlaceholder})]}),g?(0,X.jsxs)(`p`,{className:`flex items-center gap-1 text-xs text-red-600 dark:text-red-400`,children:[(0,X.jsx)(G,{className:`size-3.5 shrink-0`}),g]}):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)(te,{asChild:!0,children:(0,X.jsx)(J,{type:`button`,variant:`secondary`,children:i.cancel})}),(0,X.jsx)(J,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:()=>{let e=o.trim();if(!e){_(i.providerIdRequired);return}_(null),r(e,{baseUrl:u.trim()||void 0,api:f,apiKey:m.trim()||void 0,models:[]}),t(!1)},children:i.addProviderConfirm})]})]})]})})}function Pt({open:e,onOpenChange:t,providerId:n,model:r,isNew:i,onSave:o,m:s}){let[c,l]=(0,Z.useState)(()=>vt(``)),[u,d]=(0,Z.useState)(()=>new Map);(0,Z.useEffect)(()=>{e&&(d(new Map),l(r?{...r}:vt(``)))},[e,r]);let f=(e,t)=>{l(n=>({...n,[e]:t})),d(t=>{let n=new Map(t);return n.delete(e),n})},p=()=>{let e=new Map;return(c.id||``).trim()||e.set(`id`,s.modelIdRequired),c.contextWindow!==void 0&&c.contextWindow<=0&&e.set(`contextWindow`,s.mustBePositive),c.maxTokens!==void 0&&c.maxTokens<=0&&e.set(`maxTokens`,s.mustBePositive),d(e),e.size===0},m=()=>{if(!p())return;let e=(c.id||``).trim();o({...c,id:e,name:c.name?.trim()||e,reasoning:c.reasoning||!1,input:c.input||[`text`],contextWindow:c.contextWindow??128e3,maxTokens:c.maxTokens??16384,cost:{input:c.cost?.input??0,output:c.cost?.output??0,cacheRead:c.cost?.cacheRead??0,cacheWrite:c.cost?.cacheWrite??0}}),t(!1)},h=Ot(c);return(0,X.jsx)(Ee,{open:e,onOpenChange:t,children:(0,X.jsxs)(se,{children:[(0,X.jsx)(F,{className:`xopc-dialog-overlay fixed inset-0 z-50 bg-scrim`}),(0,X.jsxs)(me,{className:a(`xopc-dialog-content fixed left-1/2 top-1/2 z-50 max-h-[min(90vh,720px)] w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2`,`overflow-y-auto rounded-xl border border-edge bg-surface-panel p-4 shadow-popover dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,X.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(L,{className:`text-base font-semibold text-fg`,children:i?s.addModelTitle:s.editModelTitle}),n?(0,X.jsxs)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:[s.modelProviderLabel,`: `,n]}):null]}),(0,X.jsx)(te,{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":s.close,children:(0,X.jsx)(I,{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:[s.modelId,(0,X.jsx)(`span`,{className:`text-red-600 dark:text-red-400`,children:` *`})]}),(0,X.jsx)(`input`,{className:a(Et(),u.has(`id`)&&`border-red-500`),value:c.id||``,onChange:e=>f(`id`,e.target.value),placeholder:`e.g. llama3.1:8b`,disabled:!i}),u.has(`id`)?(0,X.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:u.get(`id`)}):null]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.displayName}),(0,X.jsx)(`input`,{className:Et(),value:c.name||``,onChange:e=>f(`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:s.inputTypes}),(0,X.jsx)(`select`,{className:Dt(),value:h,onChange:e=>f(`input`,kt(e.target.value)),children:Tt.map(e=>(0,X.jsx)(`option`,{value:e.value,children:s[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:c.reasoning||!1,onChange:e=>f(`reasoning`,e.target.checked)}),s.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:s.contextWindow}),(0,X.jsx)(`input`,{type:`number`,min:1,className:a(Et(),u.has(`contextWindow`)&&`border-red-500`),value:c.contextWindow??128e3,onChange:e=>f(`contextWindow`,parseInt(e.target.value,10)||0)}),u.has(`contextWindow`)?(0,X.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:u.get(`contextWindow`)}):null]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:s.maxOutputTokens}),(0,X.jsx)(`input`,{type:`number`,min:1,className:a(Et(),u.has(`maxTokens`)&&`border-red-500`),value:c.maxTokens??16384,onChange:e=>f(`maxTokens`,parseInt(e.target.value,10)||0)}),u.has(`maxTokens`)?(0,X.jsx)(`p`,{className:`mt-1 text-xs text-red-600 dark:text-red-400`,children:u.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:s.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:s.costInput}),(0,X.jsx)(`input`,{type:`number`,step:`any`,min:0,className:Et(),value:c.cost?.input??0,onChange:e=>f(`cost`,{...c.cost,input:parseFloat(e.target.value)||0,output:c.cost?.output??0,cacheRead:c.cost?.cacheRead??0,cacheWrite:c.cost?.cacheWrite??0})})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`mb-1 block text-xs text-fg-muted`,children:s.costOutput}),(0,X.jsx)(`input`,{type:`number`,step:`any`,min:0,className:Et(),value:c.cost?.output??0,onChange:e=>f(`cost`,{...c.cost,input:c.cost?.input??0,output:parseFloat(e.target.value)||0,cacheRead:c.cost?.cacheRead??0,cacheWrite:c.cost?.cacheWrite??0})})]})]})]})]}),(0,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)(te,{asChild:!0,children:(0,X.jsx)(J,{type:`button`,variant:`secondary`,children:s.cancel})}),(0,X.jsx)(J,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:m,children:i?s.addModelConfirm:s.saveModelConfirm})]})]})]})})}function Ft(){let e=v(e=>e.language),t=K(e),n=t.modelsSettings,r=!!be(e=>e.token),[i,o]=(0,Z.useState)({providers:{}}),[s,c]=(0,Z.useState)({providers:{}}),[l,u]=(0,Z.useState)(``),[d,m]=(0,Z.useState)(),[_,y]=(0,Z.useState)(!0),[b,x]=(0,Z.useState)(!1),[C,w]=(0,Z.useState)(!1),[T,E]=(0,Z.useState)(!1),[D,O]=(0,Z.useState)(null),[k,j]=(0,Z.useState)(!1),[ee,M]=(0,Z.useState)(null),[te,N]=(0,Z.useState)(()=>new Set),[P,F]=(0,Z.useState)(!1),[I,L]=(0,Z.useState)(``),[R,z]=(0,Z.useState)(null),[B,V]=(0,Z.useState)(()=>new Set),[re,H]=(0,Z.useState)(()=>new Map),[ie,W]=(0,Z.useState)(!1),[oe,se]=(0,Z.useState)(null),[le,ue]=(0,Z.useState)(!1),[de,fe]=(0,Z.useState)(null),pe=(0,Z.useCallback)(async e=>{let t=!e?.skipFullPageLoading;t&&y(!0),O(null);try{let e=await pt(),t=ft(e.config);o(t),c(structuredClone(t)),u(e.path),m(e.loadError),M(null),j(!1)}catch(e){O(e instanceof Error?e.message:n.loadError),o({providers:{}}),c({providers:{}})}finally{t&&y(!1)}},[n.loadError]);(0,Z.useEffect)(()=>{if(!r){y(!1);return}pe()},[r,pe]);let me=(0,Z.useMemo)(()=>JSON.stringify(i)!==JSON.stringify(s),[i,s]),he=(0,Z.useMemo)(()=>{let e=Object.keys(i.providers),t=0;for(let e of Object.values(i.providers))t+=e.models?.length??0;return{providers:e.length,models:t}},[i.providers]),ge=e=>{N(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},ve=e=>{V(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},ye=(0,Z.useCallback)(()=>{L(JSON.stringify(i,null,2)),z(null)},[i]);(0,Z.useEffect)(()=>{P&&ye()},[P,ye]);let xe=()=>{try{o(ft(JSON.parse(I))),z(null)}catch{z(n.jsonParseError)}},Se=async()=>{w(!0),O(null);try{M(await mt(i))}catch(e){O(e instanceof Error?e.message:n.validateError)}finally{w(!1)}},Ce=async()=>{if(!b){x(!0),O(null),j(!1);try{await ht(i),c(structuredClone(i)),j(!0),M(null)}catch(e){O(e instanceof Error?e.message:n.saveError)}finally{x(!1)}}},we=async()=>{E(!0),O(null);try{await gt(),await pe({skipFullPageLoading:!0})}catch(e){O(e instanceof Error?e.message:n.reloadError)}finally{E(!1)}},Ee=async(e,t)=>{try{let n=await _t(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})}},ke=(e=null)=>{se(e),W(!0)},Ae=(e,t)=>{o(n=>Mt(n,e,t)),N(t=>new Set(t).add(e))},je=e=>{window.confirm(n.removeProviderConfirm.replace(`{{id}}`,e))&&(o(t=>jt(t,e)),H(t=>{let n=new Map(t);return n.delete(e),n}))},Y=(e,t,n)=>{fe({providerId:e,model:t,isNew:n}),ue(!0)};return r?(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:p(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)(ne,{className:`size-3.5`})]})]}),d?(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)(G,{className:`mt-0.5 size-4 shrink-0`}),(0,X.jsxs)(`span`,{children:[n.loadFileWarning,`: `,d]})]}):null,l?(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:l})]}):null,(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsxs)(J,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:()=>ke(null),disabled:_,children:[(0,X.jsx)(g,{className:`mr-1 size-4`}),n.addProvider]}),(0,X.jsx)(J,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:Se,disabled:_||C,children:C?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(q,{className:`mr-1 size-4 animate-spin`}),n.validating]}):n.validate}),(0,X.jsx)(J,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[7.5rem] justify-center`,onClick:Ce,disabled:_||b||!me,children:b?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(q,{className:`mr-1 size-4 animate-spin`}),n.saving]}):n.save}),(0,X.jsx)(J,{type:`button`,variant:`secondary`,className:`inline-flex min-h-9 min-w-[8.5rem] justify-center`,onClick:we,disabled:_||T,children:T?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(q,{className:`mr-1 size-4 animate-spin`}),n.reloading]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(ae,{className:`mr-1 size-4`}),n.reload]})}),(0,X.jsx)(J,{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(he.providers))}),(0,X.jsx)(`span`,{className:`text-fg-subtle`,children:`|`}),(0,X.jsx)(`span`,{className:`text-fg-muted`,children:n.statsModels.replace(`{{count}}`,String(he.models))})]})]}),me?(0,X.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,k?(0,X.jsx)(`p`,{className:`text-xs text-emerald-700 dark:text-emerald-400`,role:`status`,children:n.saved}):null,D?(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)(G,{className:`size-4 shrink-0`}),D]}):null,ee&&ee.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:ee.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:ee.errors.map((e,t)=>(0,X.jsxs)(`li`,{children:[e.path,`: `,e.message,` (`,e.severity,`)`]},`${e.path}-${t}`))})]}):null,_?(0,X.jsxs)(`div`,{className:`flex items-center gap-2 text-sm text-fg-muted`,children:[(0,X.jsx)(q,{className:`size-4 animate-spin`}),n.loading]}):P?(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,X.jsx)(`textarea`,{className:a(Et(),`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)(J,{type:`button`,variant:`secondary`,onClick:ye,children:n.jsonReset}),(0,X.jsx)(J,{type:`button`,className:`bg-accent text-white hover:bg-accent/90`,onClick:xe,children:n.jsonApply})]})]}):Object.keys(i.providers).length===0?(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)(De,{className:`size-7 text-accent`,strokeWidth:1.5})}),(0,X.jsx)(`h2`,{className:`mb-1 text-base font-semibold text-fg`,children:n.emptyTitle}),(0,X.jsx)(`p`,{className:`mb-6 max-w-md text-sm text-fg-muted`,children:n.emptyDesc}),(0,X.jsxs)(J,{type:`button`,className:`mb-6 bg-accent text-white hover:bg-accent/90`,onClick:()=>ke(null),children:[(0,X.jsx)(g,{className:`mr-1 size-4`}),n.emptyCta]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap justify-center gap-2`,children:[(0,X.jsxs)(`button`,{type:`button`,className:a(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,S.transition,S.focusRingBase),onClick:()=>ke(`ollama`),children:[(0,X.jsx)(Te,{className:`size-3.5`,"aria-hidden":!0}),n.presetOllama]}),(0,X.jsxs)(`button`,{type:`button`,className:a(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,S.transition,S.focusRingBase),onClick:()=>ke(`openrouter`),children:[(0,X.jsx)(f,{className:`size-3.5`,"aria-hidden":!0}),n.presetOpenRouter]}),(0,X.jsxs)(`button`,{type:`button`,className:a(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,S.transition,S.focusRingBase),onClick:()=>ke(`lmstudio`),children:[(0,X.jsx)(De,{className:`size-3.5`,"aria-hidden":!0}),n.presetLmStudio]}),(0,X.jsxs)(`button`,{type:`button`,className:a(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,S.transition,S.focusRingBase),onClick:()=>ke(`zhipuCn`),children:[(0,X.jsx)(Te,{className:`size-3.5`,"aria-hidden":!0}),n.presetZhipuCn]}),(0,X.jsxs)(`button`,{type:`button`,className:a(`inline-flex items-center gap-1.5 rounded-full border border-edge bg-surface-base px-3 py-1.5 text-xs text-fg hover:border-accent hover:text-accent dark:border-edge`,S.transition,S.focusRingBase),onClick:()=>ke(`zaiGeneral`),children:[(0,X.jsx)(f,{className:`size-3.5`,"aria-hidden":!0}),n.presetZaiGeneral]})]})]}):(0,X.jsx)(`div`,{className:`flex flex-col gap-3`,children:Object.entries(i.providers).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>{let r=te.has(e),i=t.models?.length??0,s=t.apiKey?xt(t.apiKey):null,c=re.get(e),l=B.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:()=>ge(e),children:[r?(0,X.jsx)(h,{className:`size-4 shrink-0 text-fg-muted`}):(0,X.jsx)(U,{className:`size-4 shrink-0 text-fg-muted`}),(0,X.jsx)(`span`,{className:`truncate`,children:e}),i>0?(0,X.jsx)(`span`,{className:`shrink-0 rounded-full bg-accent px-2 py-0.5 text-[10px] font-medium text-white`,children:i}):null,s?(0,X.jsx)(`span`,{className:a(`shrink-0 rounded-full px-2 py-0.5 text-[10px] font-medium`,s===`shell`&&`bg-blue-100 text-blue-800 dark:bg-blue-950 dark:text-blue-200`,s===`env`&&`bg-emerald-100 text-emerald-800 dark:bg-emerald-950 dark:text-emerald-200`,s===`literal`&&`bg-surface-hover text-fg-muted dark:bg-surface-active`),children:s===`shell`?n.badgeShell:s===`env`?n.badgeEnv:n.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:()=>je(e),"aria-label":n.removeProvider,children:(0,X.jsx)(A,{className:`size-4`})})]}),r?(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:n.baseUrl}),(0,X.jsx)(`input`,{className:Et(),value:t.baseUrl||``,onChange:t=>o(n=>At(n,e,{baseUrl:t.target.value}))})]}),(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`label`,{className:`mb-1 block text-xs font-medium text-fg-muted`,children:n.apiType}),(0,X.jsx)(`select`,{className:Dt(),value:t.api||`openai-completions`,onChange:t=>o(n=>At(n,e,{api:t.target.value})),children:ut.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:n.apiKey}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,X.jsx)(`input`,{className:a(Et(),`min-w-0 flex-1`),type:l?`text`:`password`,autoComplete:`off`,value:t.apiKey||``,onChange:t=>{let n=t.target.value;o(t=>At(t,e,{apiKey:n})),H(t=>{let n=new Map(t);return n.delete(e),n})},placeholder:n.apiKeyPlaceholder}),(0,X.jsx)(J,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>ve(e),children:l?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(ce,{className:`mr-1 size-3.5`}),n.hide]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(_e,{className:`mr-1 size-3.5`}),n.show]})}),(0,X.jsx)(J,{type:`button`,variant:`secondary`,className:`px-2 py-1 text-xs`,onClick:()=>Ee(e,t.apiKey||``),children:n.testKey})]}),c?(0,X.jsx)(`p`,{className:a(`mt-1 text-xs`,c.error?`text-red-600 dark:text-red-400`:`text-emerald-700 dark:text-emerald-400`),children:c.error?`${n.testError}: ${c.error}`:`${n.testOk} (${c.type}): ${St(c.resolved||``)}`}):null,(0,X.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:n.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:t.authHeader||!1,onChange:t=>o(n=>At(n,e,{authHeader:t.target.checked}))}),n.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:n.modelsSection}),(0,X.jsxs)(J,{type:`button`,variant:`primary`,className:`px-2 py-1 text-xs`,onClick:()=>Y(e,null,!0),children:[(0,X.jsx)(g,{className:`mr-1 size-3.5`}),n.addModel]})]}),(t.models||[]).length===0?(0,X.jsx)(`p`,{className:`text-xs text-fg-muted`,children:n.modelsEmpty}):(0,X.jsx)(`ul`,{className:`space-y-2`,children:(t.models||[]).map(t=>(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:t.id}),t.name&&t.name!==t.id?(0,X.jsx)(`div`,{className:`truncate text-xs text-fg-muted`,children:t.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:()=>Y(e,t,!1),"aria-label":n.editModel,children:(0,X.jsx)(Oe,{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(n.removeModelConfirm.replace(`{{id}}`,t.id))&&o(n=>{let r=n.providers[e];return r?At(n,e,{models:(r.models||[]).filter(e=>e.id!==t.id)}):n})},"aria-label":n.removeModel,children:(0,X.jsx)(A,{className:`size-4`})})]})]},t.id))})]})]}):null]},e)})}),(0,X.jsx)(Nt,{open:ie,onOpenChange:W,presetKey:oe,onConfirm:Ae,m:n}),(0,X.jsx)(Pt,{open:le,onOpenChange:e=>{ue(e),e||fe(null)},providerId:de?.providerId??null,model:de?.model??null,isNew:de?.isNew??!1,onSave:e=>{if(!de)return;let{providerId:t,isNew:n}=de;o(r=>{let i=r.providers[t];if(!i)return r;let a=i.models||[];return n?At(r,t,{models:[...a,e]}):At(r,t,{models:a.map(t=>t.id===e.id?e:t)})})},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})]})}function It(){return{enabled:!1,provider:`alibaba`,alibaba:{model:`paraformer-v2`},openai:{model:`whisper-1`},fallback:{enabled:!0,order:[`alibaba`,`openai`]}}}function Lt(){return{enabled:!1,provider:`openai`,trigger:`always`,maxTextLength:4096,timeoutMs:3e4,alibaba:{model:`qwen-tts`,voice:`Cherry`},openai:{model:`tts-1`,voice:`alloy`},edge:{voice:`zh-CN-XiaoxiaoNeural`},minimax:{model:`speech-2.8-hd`,voice:`male-qn-qingse`}}}function Rt(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function zt(e){let t=It();if(!Rt(e))return t;let n=e.provider===`openai`?`openai`:`alibaba`,r=Rt(e.alibaba)?{...t.alibaba,...e.alibaba}:t.alibaba,i=Rt(e.openai)?{...t.openai,...e.openai}:t.openai,a=t.fallback??{enabled:!0,order:[`alibaba`,`openai`]};if(Rt(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 Bt(e){return e===`openai`||e===`alibaba`||e===`edge`||e===`minimax`}function Vt(e){let t=Lt();if(!Rt(e))return t;let n=Bt(e.provider)?e.provider:`openai`,r=e.trigger===`off`||e.trigger===`always`||e.trigger===`inbound`||e.trigger===`tagged`?e.trigger:`always`;return{enabled:!!e.enabled,provider:n,trigger:r,maxTextLength:typeof e.maxTextLength==`number`&&Number.isFinite(e.maxTextLength)?e.maxTextLength:t.maxTextLength,timeoutMs:typeof e.timeoutMs==`number`&&Number.isFinite(e.timeoutMs)?e.timeoutMs:t.timeoutMs,alibaba:Rt(e.alibaba)?{...t.alibaba,...e.alibaba}:t.alibaba,openai:Rt(e.openai)?{...t.openai,...e.openai}:t.openai,edge:Rt(e.edge)?{...t.edge,...e.edge}:t.edge,minimax:Rt(e.minimax)?{...t.minimax,...e.minimax}:t.minimax}}function Ht(e){let t=Rt(e)?e:{};return{stt:zt(t.stt),tts:Vt(t.tts)}}async function Ut(e){await u(x(`/api/config`),{method:`PATCH`,body:JSON.stringify({stt:e.stt,tts:e.tts})}),W()}async function Wt(){let e=await u(x(`/api/voice/models`));if(!e.payload?.models)throw Error(`Missing voice models payload`);return e.payload.models}function Gt(){return a(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,M,`dark:border-edge`)}function Kt(){return a(H,de)}var qt=[{id:`paraformer-v2`,name:`Paraformer v2`},{id:`paraformer-v1`,name:`Paraformer v1`}],Jt=[{id:`whisper-1`,name:`Whisper-1`}],Yt=[{id:`tts-1`,name:`TTS-1`},{id:`tts-1-hd`,name:`TTS-1 HD`}],Xt=[{id:`alloy`,name:`Alloy`},{id:`echo`,name:`Echo`}],Zt=[{id:`qwen-tts`,name:`Qwen TTS`},{id:`qwen3-tts-flash`,name:`Qwen3 TTS Flash`}],Qt=[{id:`Cherry`,name:`Cherry`},{id:`longxiaochun`,name:`Long Xiao Chun`}],$t=[{id:`en-US-MichelleNeural`,name:`Michelle (US English)`},{id:`zh-CN-XiaoxiaoNeural`,name:`Xiaoxiao (Chinese)`}],en=[{id:`speech-2.8-hd`,name:`Speech 2.8 HD (Recommended)`},{id:`speech-2.8-turbo`,name:`Speech 2.8 Turbo (Fast)`}],tn=[{id:`male-qn-qingse`,name:`Male Qingse (青涩男声)`},{id:`female-shaonv`,name:`Female Shaonv (少女音)`}];function nn(){let e=v(e=>e.language),t=K(e),n=t.voiceSettings,i=!!be(e=>e.token),[a,s]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(null),[f,m]=(0,Z.useState)(!1),[h,g]=(0,Z.useState)(null),[_,y]=(0,Z.useState)(!1),{data:b,error:S,isLoading:C,mutate:w}=o(i),{data:T,error:E,isLoading:D,mutate:O}=r(i?x(`/api/voice/models`):null,Wt,{revalidateOnFocus:!1}),k=(0,Z.useMemo)(()=>b?.payload?.config===void 0?null:Ht(b.payload.config),[b]),A=(0,Z.useMemo)(()=>!a||!c?!1:JSON.stringify(a)!==JSON.stringify(c),[a,c]);(0,Z.useEffect)(()=>{if(!i){s(null),l(null),d(null);return}k===null||T===void 0||A||(s(structuredClone(k)),l(structuredClone(k)),d(T),y(!1))},[i,k,T,A]);let j=!!(i&&(k===null||T===void 0)&&(C||D)),ee=S instanceof Error?S.message:S?String(S):E instanceof Error?E.message:E?String(E):null,M=(0,Z.useCallback)(e=>{s(t=>t?{...t,stt:{...t.stt,...e}}:null)},[]),te=(0,Z.useCallback)(e=>{s(t=>t?{...t,stt:{...t.stt,alibaba:{...t.stt.alibaba,...e}}}:null)},[]),N=(0,Z.useCallback)(e=>{s(t=>t?{...t,stt:{...t.stt,openai:{...t.stt.openai,...e}}}:null)},[]),P=(0,Z.useCallback)(e=>{s(t=>{if(!t)return null;let n=t.stt.fallback??{enabled:!0,order:[`alibaba`,`openai`]};return{...t,stt:{...t.stt,fallback:{...n,...e}}}})},[]),F=(0,Z.useCallback)(e=>{s(t=>t?{...t,tts:{...t.tts,...e}}:null)},[]),I=(0,Z.useCallback)(e=>{s(t=>t?{...t,tts:{...t.tts,alibaba:{...t.tts.alibaba,...e}}}:null)},[]),L=(0,Z.useCallback)(e=>{s(t=>t?{...t,tts:{...t.tts,openai:{...t.tts.openai,...e}}}:null)},[]),R=(0,Z.useCallback)(e=>{s(t=>t?{...t,tts:{...t.tts,edge:{...t.tts.edge,...e}}}:null)},[]),z=(0,Z.useCallback)(e=>{s(t=>t?{...t,tts:{...t.tts,minimax:{...t.tts.minimax,...e}}}:null)},[]),B=(0,Z.useCallback)(async()=>{if(!(!a||f)){m(!0),g(null),y(!1);try{await Ut(a);let e=structuredClone(a);l(e),s(e),y(!0),window.setTimeout(()=>y(!1),2500)}catch(e){g(e instanceof Error?e.message:n.saveError)}finally{m(!1)}}},[a,f,n.saveError]);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)(q,{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:h??ee??n.loadError}),(0,X.jsx)(J,{type:`button`,variant:`secondary`,onClick:()=>{w(),O()},children:n.retry})]});let V=a.stt,re=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:p(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)(ne,{className:`size-3.5`})]})]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[_?(0,X.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,X.jsx)(J,{type:`button`,variant:`primary`,disabled:!A||f,onClick:()=>void B(),children:f?n.saving:n.save})]})]}),A?(0,X.jsx)(`p`,{className:`text-xs text-amber-800 dark:text-amber-200`,children:n.unsavedHint}):null,h?(0,X.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:h}):null,(0,X.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,X.jsx)(rn,{v:n,stt:V,models:u,updateStt:M,updateSttAlibaba:te,updateSttOpenai:N,updateSttFallback:P}),(0,X.jsx)(an,{v:n,tts:re,models:u,updateTts:F,updateTtsAlibaba:I,updateTtsOpenai:L,updateTtsEdge:R,updateTtsMinimax:z})]}),(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 rn({v:e,stt:t,models:n,updateStt:r,updateSttAlibaba:i,updateSttOpenai:o,updateSttFallback:s}){let c=n?.stt?.alibaba?.length?n.stt.alibaba:qt,l=n?.stt?.openai?.length?n.stt.openai:Jt;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)(C,{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)(Q,{children:e.stt.provider}),(0,X.jsxs)(`select`,{className:Kt(),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)(Q,{children:e.stt.apiKey}),(0,X.jsx)(`input`,{className:a(Gt(),`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)(Q,{children:e.stt.model}),(0,X.jsx)(`select`,{className:Kt(),value:t.alibaba?.model??``,onChange:e=>i({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:`grid gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)(Q,{children:e.stt.apiKey}),(0,X.jsx)(`input`,{className:a(Gt(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.openai?.apiKey??``,onChange:e=>o({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)(Q,{children:e.stt.model}),(0,X.jsx)(`select`,{className:Kt(),value:t.openai?.model??``,onChange:e=>o({model:e.target.value}),children:l.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=>s({enabled:e.target.checked})})]})]}):null]})]})}function an({v:e,tts:t,models:n,updateTts:r,updateTtsAlibaba:i,updateTtsOpenai:o,updateTtsEdge:s,updateTtsMinimax:c}){let l=t=>t===`off`?e.tts.triggerDescOff:t===`always`?e.tts.triggerDescAlways:t===`inbound`?e.tts.triggerDescInbound:t===`tagged`?e.tts.triggerDescTagged:``,u=n?.tts?.openai?.length?n.tts.openai:Yt,d=n?.ttsVoices?.openai?.length?n.ttsVoices.openai:Xt,f=n?.tts?.alibaba?.length?n.tts.alibaba:Zt,p=n?.ttsVoices?.alibaba?.length?n.ttsVoices.alibaba:Qt,m=n?.ttsVoices?.edge?.length?n.ttsVoices.edge:$t,h=n?.tts?.minimax?.length?n.tts.minimax:en,g=n?.ttsVoices?.minimax?.length?n.ttsVoices.minimax:tn;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)(ge,{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)(Q,{children:e.tts.trigger}),(0,X.jsxs)(`select`,{className:Kt(),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)(Q,{children:e.tts.provider}),(0,X.jsxs)(`select`,{className:Kt(),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})]})]})]}),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)(Q,{children:e.stt.apiKey}),(0,X.jsx)(`input`,{className:a(Gt(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.openai?.apiKey??``,onChange:e=>o({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)(Q,{children:e.stt.model}),(0,X.jsx)(`select`,{className:Kt(),value:t.openai?.model??``,onChange:e=>o({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)(Q,{children:e.tts.voice}),(0,X.jsx)(`select`,{className:Kt(),value:t.openai?.voice??``,onChange:e=>o({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)(Q,{children:e.stt.apiKey}),(0,X.jsx)(`input`,{className:a(Gt(),`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)(Q,{children:e.stt.model}),(0,X.jsx)(`select`,{className:Kt(),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)(Q,{children:e.tts.voice}),(0,X.jsx)(`select`,{className:Kt(),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)(Q,{children:e.stt.apiKey}),(0,X.jsx)(`input`,{className:a(Gt(),`font-mono text-xs`),type:`password`,autoComplete:`off`,value:t.minimax?.apiKey??``,onChange:e=>c({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)(Q,{children:e.stt.model}),(0,X.jsx)(`select`,{className:Kt(),value:t.minimax?.model??``,onChange:e=>c({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)(Q,{children:e.tts.voice}),(0,X.jsx)(`select`,{className:Kt(),value:t.minimax?.voice??``,onChange:e=>c({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)(Q,{children:e.tts.voice}),(0,X.jsx)(`select`,{className:Kt(),value:t.edge?.voice??``,onChange:e=>s({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]}):null]})]})}function Q({children:e}){return(0,X.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e})}function on(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 sn(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 u(x(`/api/config`),{method:`PATCH`,body:JSON.stringify({tools:{web:{region:t,search:n}}})}),W()}function cn({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 ln(){return a(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,M,`dark:border-edge`)}function un(){return a(H,de)}var dn=[`brave`,`tavily`,`bing`,`searxng`];function fn(){return{type:`brave`,apiKey:``,url:``,disabled:!1}}function pn(){let e=v(e=>e.language),t=K(e),n=t.webSearchSettings,r=t.logs,i=!!be(e=>e.token),[a,s]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(null),[u,d]=(0,Z.useState)(!1),[f,m]=(0,Z.useState)(null),[h,_]=(0,Z.useState)(!1),y=(0,Z.useRef)(!1),{data:b,error:x,isLoading:S,mutate:C}=o(i),w=(0,Z.useMemo)(()=>b?.payload?.config===void 0?null:on(b.payload.config),[b]);(0,Z.useEffect)(()=>{if(!i){s(null),l(null),y.current=!1;return}w!==null&&(y.current||(s(w),l(w)))},[i,w]);let T=!!(i&&S&&b===void 0&&!x),E=x instanceof Error?x.message:x?String(x):null,D=(0,Z.useMemo)(()=>!a||!c?!1:JSON.stringify(a)!==JSON.stringify(c),[a,c]),O=(0,Z.useCallback)(e=>{y.current=!0,s(t=>t?{...t,...e}:null)},[]),k=(0,Z.useCallback)(async()=>{if(!(!a||u)){d(!0),m(null),_(!1);try{await sn(a),y.current=!1,_(!0),window.setTimeout(()=>_(!1),2500)}catch(e){m(e instanceof Error?e.message:n.saveError)}finally{d(!1)}}},[a,u,n.saveError]);return i?T?(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)(q,{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:p(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)(ne,{className:`size-3.5`})]})]}),(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[h?(0,X.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,(0,X.jsx)(J,{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,f?(0,X.jsx)(`p`,{className:`text-sm text-red-600 dark:text-red-400`,children:f}):null,(0,X.jsxs)(Me,{children:[(0,X.jsx)(Ne,{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)(cn,{label:n.regionLabel,description:n.regionDesc,children:(0,X.jsxs)(`select`,{className:un(),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)(Me,{children:[(0,X.jsx)(Ne,{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)(cn,{label:n.maxResultsLabel,description:n.maxResultsDesc,children:(0,X.jsx)(`input`,{type:`number`,min:1,max:50,className:ln(),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)(mn,{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)(J,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5 text-sm`,onClick:()=>O({providers:[...a.providers,fn()]}),children:[(0,X.jsx)(g,{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:f??E??n.loadError}),(0,X.jsx)(J,{type:`button`,variant:`secondary`,onClick:()=>void C(),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 mn({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:a(un(),`min-w-[8rem]`),value:e.type,onChange:t=>n({...e,type:t.target.value,url:t.target.value===`searxng`?e.url:``}),children:dn.map(e=>(0,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)(J,{type:`button`,variant:`ghost`,className:`h-8 px-2 text-fg-muted`,onClick:r,children:(0,X.jsx)(A,{className:`size-4`})})]})]}),e.type===`searxng`?(0,X.jsx)(cn,{label:t.urlLabel,description:t.urlDesc,children:(0,X.jsx)(`input`,{type:`url`,className:ln(),value:e.url,placeholder:`http://localhost:8080`,onChange:t=>n({...e,url:t.target.value})})}):null,(0,X.jsx)(cn,{label:t.apiKeyLabel,description:t.apiKeyDesc,children:(0,X.jsx)(`input`,{type:`password`,autoComplete:`off`,className:ln(),value:we(e.apiKey)?``:e.apiKey,placeholder:we(e.apiKey)?t.keyPlaceholderMasked:t.keyPlaceholder,onChange:t=>n({...e,apiKey:t.target.value})})})]})}var hn=[{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 gn(e,t){let n=K(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 _n(){let e=v(e=>e.language),t=K(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)(()=>{w()&&c&&l()},[c,l]),!w()||!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:Y(),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))}},f=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)(Me,{children:[(0,X.jsxs)(`div`,{className:`mb-4 flex items-center gap-2 text-sm font-semibold text-fg`,children:[(0,X.jsx)(y,{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:Y(),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:f})]}),(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:hn.map(({key:r,pane:o})=>{let l=gn(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)(ne,{className:`size-3.5`,strokeWidth:1.75,"aria-hidden":!0})]})]})]},r):null})})]}):null]})}function vn(){return x(`/api/dreaming`)}async function yn(){let e=await u(vn());if(!e.payload)throw Error(`Missing payload`);return e.payload}async function bn(e){await u(x(`/api/dreaming/action`),{method:`POST`,body:JSON.stringify({action:e})})}async function xn(){let e=await u(x(`/api/dreaming/run`),{method:`POST`,body:JSON.stringify({})}),t=!!e.payload?.triggered,n=typeof e.payload?.jobId==`string`?e.payload.jobId:``;if(!t||!n)throw Error(`Failed to trigger`);return{triggered:t,jobId:n}}async function Sn(e){let t=await u(x(`/api/dreaming/preview${typeof e==`number`&&Number.isFinite(e)?`?limit=${encodeURIComponent(String(e))}`:``}`));if(!t.payload)throw Error(`Missing payload`);return t.payload}function Cn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}var wn={enabled:!1,frequency:`0 3 * * *`,timezone:``,deepEnabled:!0,minScore:.8,minRecallCount:3,limit:10};function Tn(e,t){return Number.isFinite(e)?Math.max(0,Math.min(1,e)):t}function En(e,t){let n=typeof e==`string`?Number(e):e;return Number.isFinite(n)?Math.max(0,Math.floor(n)):t}function Dn(e){let t=Cn(e)?e:{},n=Cn(t.agents)?t.agents:{},r=Cn(n.defaults)?n.defaults:{},i=Cn(r.memory)?r.memory:{},a=Cn(i.dreaming)?i.dreaming:{},o=Cn(a.phases)?a.phases:{},s=Cn(o.deep)?o.deep:{};return{enabled:a.enabled===!0,frequency:typeof a.frequency==`string`&&a.frequency.trim()?a.frequency.trim():wn.frequency,timezone:typeof a.timezone==`string`?a.timezone:``,deepEnabled:s.enabled!==!1,minScore:Tn(typeof s.minScore==`number`?s.minScore:Number(s.minScore),wn.minScore),minRecallCount:Math.max(1,En(s.minRecallCount,wn.minRecallCount)),limit:En(s.limit,wn.limit)}}async function On(e){let t=e.frequency.trim(),n=e.timezone.trim();await u(x(`/api/config`),{method:`PATCH`,body:JSON.stringify({agents:{defaults:{memory:{dreaming:{enabled:!!e.enabled,frequency:t||null,timezone:n||null,phases:{deep:{enabled:!!e.deepEnabled,minScore:Tn(e.minScore,wn.minScore),minRecallCount:Math.max(1,Math.floor(e.minRecallCount)),limit:Math.max(0,Math.floor(e.limit))}}}}}}})}),W()}function $(){return`text-xs font-medium text-fg-muted`}function kn(){return`text-sm font-medium text-fg`}function An(e){return e?e.replace(`T`,` `).replace(`Z`,``):`—`}function jn(e){return e.locked?{text:`Locked`,className:`text-amber-600 dark:text-amber-400`}:{text:`Unlocked`,className:`text-emerald-600 dark:text-emerald-400`}}function Mn(){let e=K(v(e=>e.language)).dreamingSettings,t=!!be(e=>e.token),{data:n}=o(t),[i,s]=(0,Z.useState)(null),[c,l]=(0,Z.useState)(null),[u,f]=(0,Z.useState)(!1),[p,h]=(0,Z.useState)(!1),[g,_]=(0,Z.useState)(!1),[y,b]=(0,Z.useState)(null),[x,S]=(0,Z.useState)(null),[C,w]=(0,Z.useState)(null),[T,E]=(0,Z.useState)(!1),[D,O]=(0,Z.useState)(!1),[k,j]=(0,Z.useState)(null),[ee,M]=(0,Z.useState)(!1),[te,N]=(0,Z.useState)(null),[P,F]=(0,Z.useState)(null),{data:I,error:L,isLoading:R,mutate:z}=r(t?vn():null,yn,{revalidateOnFocus:!1}),B=(0,Z.useMemo)(()=>I?jn(I.lock):null,[I]),ne=(0,Z.useCallback)(async()=>{f(!1),l(null),_(!1),b(null),O(!1),j(null),N(null),await z()},[z]),V=(0,Z.useCallback)(async()=>{M(!0),N(null);try{F((await Sn(20)).items??[])}catch(e){N(e instanceof Error?e.message:String(e))}finally{M(!1)}},[]),re=(0,Z.useCallback)(async()=>{h(!0),_(!1),b(null);try{await xn(),_(!0),await z()}catch(e){b(e instanceof Error?e.message:String(e))}finally{h(!1)}},[z]),H=(0,Z.useCallback)(async e=>{s(e),l(null),f(!1);try{await bn(e),f(!0),await z()}catch(e){l(e instanceof Error?e.message:String(e))}finally{s(null)}},[z]),ie=!t||R||!!i,U=(0,Z.useMemo)(()=>{let e=n?.payload?.config;return Dn(e??{})},[n]);(0,Z.useEffect)(()=>{if(t){if(!C){w(U),S(U);return}JSON.stringify(U)!==JSON.stringify(C)&&(w(U),S(U))}},[C,U,t]);let W=(0,Z.useMemo)(()=>!x||!C?!1:JSON.stringify(x)!==JSON.stringify(C),[x,C]),oe=(0,Z.useCallback)(async()=>{if(x){E(!0),O(!1),j(null);try{await On(x),w(x),O(!0),await z()}catch(e){j(e instanceof Error?e.message:String(e))}finally{E(!1)}}},[x,z]);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.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,X.jsxs)(`div`,{className:`min-w-0`,children:[(0,X.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:e.title}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:e.subtitle})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(J,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||p,onClick:()=>void re(),title:e.runNowHint,children:[p?(0,X.jsx)(q,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,X.jsx)(d,{className:`mr-2 size-4`,"aria-hidden":!0}),e.runNow]}),(0,X.jsxs)(J,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t,onClick:()=>void ne(),children:[(0,X.jsx)(ae,{className:`mr-2 size-4`,"aria-hidden":!0}),e.refresh]})]})]}),L?(0,X.jsx)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:L instanceof Error?L.message:String(L)}):null,c?(0,X.jsx)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:c}):null,y?(0,X.jsx)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:y}):null,u?(0,X.jsx)(`p`,{className:`text-sm text-emerald-600 dark:text-emerald-400`,role:`status`,children:e.actionOk}):null,g?(0,X.jsx)(`p`,{className:`text-sm text-emerald-600 dark:text-emerald-400`,role:`status`,children:e.runQueued}):null,te?(0,X.jsx)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:te}):null,k?(0,X.jsx)(`p`,{className:`text-sm text-amber-600 dark:text-amber-400`,role:`alert`,children:k}):null,D?(0,X.jsx)(`p`,{className:`text-sm text-emerald-600 dark:text-emerald-400`,role:`status`,children:e.configSaved}):null,(0,X.jsxs)(Me,{children:[(0,X.jsxs)(`div`,{className:`mb-4 flex items-start justify-between gap-3`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:e.configTitle}),(0,X.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:e.configHint})]}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,X.jsxs)(J,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||!x||T||!W,onClick:()=>void oe(),children:[T?(0,X.jsx)(q,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,e.saveConfig]}),(0,X.jsx)(J,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||!x||T||!W,onClick:()=>{O(!1),j(null),S(C)},children:e.resetConfig})]})]}),x?(0,X.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{className:Y(),children:[(0,X.jsx)(`div`,{className:$(),children:e.configEnabled}),(0,X.jsxs)(`label`,{className:`mt-2 inline-flex items-center gap-2 text-sm text-fg`,children:[(0,X.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:x.enabled,onChange:e=>S({...x,enabled:e.target.checked})}),(0,X.jsx)(`span`,{children:x.enabled?e.on:e.off})]})]}),(0,X.jsxs)(`div`,{className:Y(),children:[(0,X.jsx)(`div`,{className:$(),children:e.configDeepEnabled}),(0,X.jsxs)(`label`,{className:`mt-2 inline-flex items-center gap-2 text-sm text-fg`,children:[(0,X.jsx)(`input`,{type:`checkbox`,className:`ui-checkbox`,checked:x.deepEnabled,onChange:e=>S({...x,deepEnabled:e.target.checked})}),(0,X.jsx)(`span`,{children:x.deepEnabled?e.on:e.off})]})]}),(0,X.jsxs)(`div`,{className:Y(),children:[(0,X.jsx)(`div`,{className:$(),children:e.configFrequency}),(0,X.jsx)(`input`,{className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle dark:border-edge`,value:x.frequency,onChange:e=>S({...x,frequency:e.target.value}),placeholder:`0 3 * * *`})]}),(0,X.jsxs)(`div`,{className:Y(),children:[(0,X.jsx)(`div`,{className:$(),children:e.configTimezone}),(0,X.jsx)(`input`,{className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg placeholder:text-fg-subtle dark:border-edge`,value:x.timezone,onChange:e=>S({...x,timezone:e.target.value}),placeholder:`Asia/Shanghai`})]}),(0,X.jsxs)(`div`,{className:Y(),children:[(0,X.jsx)(`div`,{className:$(),children:e.configMinScore}),(0,X.jsx)(`input`,{type:`number`,step:`0.01`,min:0,max:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.minScore,onChange:e=>S({...x,minScore:Number(e.target.value)})})]}),(0,X.jsxs)(`div`,{className:Y(),children:[(0,X.jsx)(`div`,{className:$(),children:e.configMinRecallCount}),(0,X.jsx)(`input`,{type:`number`,step:`1`,min:1,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.minRecallCount,onChange:e=>S({...x,minRecallCount:Number(e.target.value)})})]}),(0,X.jsxs)(`div`,{className:Y(),children:[(0,X.jsx)(`div`,{className:$(),children:e.configLimit}),(0,X.jsx)(`input`,{type:`number`,step:`1`,min:0,className:`mt-2 w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg dark:border-edge`,value:x.limit,onChange:e=>S({...x,limit:Number(e.target.value)})})]})]}):(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.configLoading})]}),(0,X.jsxs)(Me,{children:[(0,X.jsxs)(`div`,{className:`mb-4 flex items-start justify-between gap-3`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:e.previewTitle}),(0,X.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:e.previewHint})]}),(0,X.jsxs)(J,{variant:`secondary`,className:`px-2.5 py-1.5 text-xs`,disabled:!t||ee,onClick:()=>void V(),children:[ee?(0,X.jsx)(q,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):null,e.previewLoad]})]}),P?P.length>0?(0,X.jsx)(`div`,{className:`space-y-2`,children:P.map(t=>{let n=`${t.path}:${t.startLine}-${t.endLine}`,r=t.skippedReason;return(0,X.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel/60 px-3 py-3`,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:n}),(0,X.jsxs)(`span`,{children:[`score=`,t.score.toFixed(3)]}),(0,X.jsxs)(`span`,{children:[`recalls=`,t.recallCount]}),(0,X.jsxs)(`span`,{children:[`avg=`,t.avgScore.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:e.previewEligible})]}),t.snippet?(0,X.jsx)(`div`,{className:`mt-2 text-sm text-fg`,children:t.snippet}):null]},`${t.key}:${t.hash}:${n}`)})}):(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.previewEmpty}):(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.previewNotLoaded})]}),(0,X.jsxs)(Me,{children:[(0,X.jsxs)(`div`,{className:`mb-4 flex items-center justify-between gap-3`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:e.statusTitle}),(0,X.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:e.statusHint})]}),R?(0,X.jsx)(q,{className:`size-4 animate-spin text-fg-muted`,"aria-hidden":!0}):null]}),(0,X.jsxs)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2`,children:[(0,X.jsxs)(`div`,{className:Y(),children:[(0,X.jsx)(`div`,{className:$(),children:e.enabled}),(0,X.jsx)(`div`,{className:kn(),children:I?I.config.enabled?e.on:e.off:`—`})]}),(0,X.jsxs)(`div`,{className:Y(),children:[(0,X.jsx)(`div`,{className:$(),children:e.schedule}),(0,X.jsx)(`div`,{className:kn(),children:I?I.config.frequency:`—`})]}),(0,X.jsxs)(`div`,{className:Y(),children:[(0,X.jsx)(`div`,{className:$(),children:e.timezone}),(0,X.jsx)(`div`,{className:kn(),children:I?I.config.timezone:`—`})]}),(0,X.jsxs)(`div`,{className:Y(),children:[(0,X.jsx)(`div`,{className:$(),children:e.lock}),(0,X.jsx)(`div`,{className:a(kn(),B?.className),children:B?B.text:`—`})]}),(0,X.jsxs)(`div`,{className:Y(),children:[(0,X.jsx)(`div`,{className:$(),children:e.storeEntries}),(0,X.jsx)(`div`,{className:kn(),children:I?String(I.store.entryCount):`—`})]}),(0,X.jsxs)(`div`,{className:Y(),children:[(0,X.jsx)(`div`,{className:$(),children:e.storePromoted}),(0,X.jsx)(`div`,{className:kn(),children:I?String(I.store.promotedCount):`—`})]}),(0,X.jsxs)(`div`,{className:Y(),children:[(0,X.jsx)(`div`,{className:$(),children:e.storeUpdatedAt}),(0,X.jsx)(`div`,{className:kn(),children:I?An(I.store.updatedAt):`—`})]}),(0,X.jsxs)(`div`,{className:Y(),children:[(0,X.jsx)(`div`,{className:$(),children:e.storeLastPromotedAt}),(0,X.jsx)(`div`,{className:kn(),children:I?An(I.store.lastPromotedAt):`—`})]})]}),I?(0,X.jsx)(`div`,{className:`mt-4 text-xs text-fg-muted`,children:(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`span`,{className:`font-medium text-fg`,children:e.deepGate}),` `,e.deepGateValue.replace(`{{minScore}}`,String(I.config.deep.minScore)).replace(`{{minRecallCount}}`,String(I.config.deep.minRecallCount)).replace(`{{limit}}`,String(I.config.deep.limit))]})}):null]}),(0,X.jsxs)(Me,{children:[(0,X.jsxs)(`div`,{className:`mb-4`,children:[(0,X.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:e.lastRunTitle}),(0,X.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:e.lastRunHint})]}),I?.lastRun?.exists?(0,X.jsx)(`pre`,{className:`max-h-[14rem] overflow-auto rounded-xl border border-edge bg-surface-panel/60 p-3 text-xs text-fg-muted`,children:JSON.stringify(I.lastRun.raw,null,2)}):(0,X.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.lastRunEmpty})]}),(0,X.jsxs)(Me,{children:[(0,X.jsxs)(`div`,{className:`mb-4`,children:[(0,X.jsx)(`div`,{className:`text-sm font-semibold text-fg`,children:e.maintenanceTitle}),(0,X.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:e.maintenanceHint})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,X.jsxs)(J,{variant:`secondary`,disabled:ie,onClick:()=>{confirm(e.confirmResetStore)&&H(`reset_store`)},children:[i===`reset_store`?(0,X.jsx)(q,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,X.jsx)(A,{className:`mr-2 size-4`,"aria-hidden":!0}),e.resetStore]}),(0,X.jsxs)(J,{variant:`secondary`,disabled:ie,onClick:()=>{confirm(e.confirmClearLock)&&H(`clear_lock`)},children:[i===`clear_lock`?(0,X.jsx)(q,{className:`mr-2 size-4 animate-spin`,"aria-hidden":!0}):(0,X.jsx)(m,{className:`mr-2 size-4`,"aria-hidden":!0}),e.clearLock]})]})]})]})}async function Nn(e){let t=await D(x(`/api/auth/oauth-async/start`),{method:`POST`,body:JSON.stringify({provider:e})});if(!t.ok){let e=await t.json().catch(()=>({}));throw Error(e.error||`OAuth start failed: ${t.status}`)}return(await t.json()).payload}async function Pn(e){let t=await D(x(`/api/auth/oauth-async/${encodeURIComponent(e)}/status`));if(!t.ok)throw Error(`OAuth status: ${t.status}`);return(await t.json()).payload}async function Fn(e,t){let n=await D(x(`/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 In(e){let t=await D(x(`/api/auth/oauth-async/${encodeURIComponent(e)}/cancel`),{method:`POST`});if(!t.ok)throw Error(`Cancel OAuth failed: ${t.status}`)}async function Ln(e){let t=await D(x(`/api/auth/oauth-async/${encodeURIComponent(e)}`),{method:`DELETE`});if(!t.ok)throw Error(`Cleanup session failed: ${t.status}`)}async function Rn(e){let t=await D(x(`/api/auth/oauth/${encodeURIComponent(e)}`),{method:`DELETE`});if(!t.ok)throw Error(`Revoke OAuth failed: ${t.status}`)}function zn({providerId:e,language:t}){let n=pe[e];if(!n)return null;let r=t===`zh`,i=r&&n.descriptionZh?n.descriptionZh:n.description;return i?(0,X.jsxs)(B,{children:[(0,X.jsx)(j,{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)(Se,{className:`size-3.5`,"aria-hidden":!0})})}),(0,X.jsx)(V,{children:(0,X.jsxs)(le,{side:`right`,align:`start`,sideOffset:6,className:a(`z-50 w-64 rounded-xl border border-edge bg-surface-panel p-3 shadow-md`,`data-[state=open]:animate-in data-[state=closed]:animate-out`,`data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,`data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95`),children:[(0,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)(ve,{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)(I,{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)(ne,{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)(ne,{className:`size-3`,"aria-hidden":!0})]}):null]}):null,(0,X.jsx)(z,{className:`fill-edge`})]})})]}):null}var Bn=[`common`,`specialty`,`enterprise`,`oauth`,`extension`];function Vn(e){let t=new Map;for(let e of Bn)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 Hn(e,t){return e.replace(/\{\{(\w+)\}\}/g,(e,n)=>String(t[n]??``))}function Un(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 Wn(){let e=v(e=>e.language),t=K(e),n=t.providersSettings,i=!!be(e=>e.token),[s,l]=(0,Z.useState)({}),[d,f]=(0,Z.useState)({}),[m,g]=(0,Z.useState)(!1),[_,y]=(0,Z.useState)(null),[S,C]=(0,Z.useState)(null),[w,T]=(0,Z.useState)(()=>new Set([`common`])),[E,D]=(0,Z.useState)(``),[O,k]=(0,Z.useState)(!1),[A,j]=(0,Z.useState)(()=>new Set),ee=(0,Z.useRef)(``),te=x(`/api/providers/meta`),N=(0,Z.useCallback)(async e=>(await u(e)).payload?.providers??[],[]),{data:P,error:F,isLoading:I,mutate:L}=o(i),{data:z,error:B,isLoading:ne,mutate:V}=r(i?te:null,N,{revalidateOnFocus:!1}),{data:H,mutate:ie}=r(i?R:null,()=>he(),{revalidateOnFocus:!1}),ae=(0,Z.useMemo)(()=>!z||P===void 0?null:ue(z,re(P.payload?.config),H??[]),[z,P,H]),U=F instanceof Error?F.message:F?String(F):B instanceof Error?B.message:B?String(B):null,W=!!(i&&ae===null&&(I||ne)&&!U),G=(0,Z.useMemo)(()=>JSON.stringify(s)!==JSON.stringify(d),[s,d]);(0,Z.useEffect)(()=>{if(!G)return;let e=e=>{e.preventDefault(),e.returnValue=``};return window.addEventListener(`beforeunload`,e),()=>window.removeEventListener(`beforeunload`,e)},[G]),(0,Z.useEffect)(()=>{if(!(!i||ae===null)&&!G){let e={};for(let t of ae)e[t.id]=t.apiKey;l(e),f({...e})}},[i,ae,G]);let se=ae??[],ce=(0,Z.useMemo)(()=>{let e=se,t=E.trim().toLowerCase();return t&&(e=e.filter(e=>{let n=pe[e.id]?.aliases??[];return e.id.toLowerCase().includes(t)||e.name.toLowerCase().includes(t)||n.some(e=>e.toLowerCase().includes(t))})),O&&(e=e.filter(e=>!e.configured)),e},[se,E,O]),le=(0,Z.useMemo)(()=>Vn(ce),[ce]);(0,Z.useEffect)(()=>{let e=ee.current;if(ee.current=E,E.trim()){let e=new Set;for(let t of Bn)(le.get(t)??[]).length>0&&e.add(t);T(e);return}e.trim()&&T(new Set([`common`]))},[E,le]);let de=(0,Z.useCallback)(async()=>{if(m)return;let e={};for(let t of Object.keys(s)){let n=s[t]?.trim()??``;!n||we(n)||(e[t]=n)}if(Object.keys(e).length===0){f({...s}),C(`noChanges`),window.setTimeout(()=>C(null),2500);return}g(!0),y(null),C(null);try{await xe(e),j(new Set(Object.keys(e)));let t=await ie(he(!0))??H??[],[n,r]=await Promise.all([L(),V()]),i=Array.isArray(r)?r:z??[],a=n??P;if(a?.payload){let e=ue(i,re(a.payload.config),t),n={};for(let t of e)n[t.id]=t.apiKey;l(n),f({...n})}C(`saved`),window.setTimeout(()=>C(null),2500)}catch(e){y(e instanceof Error?e.message:n.saveError)}finally{g(!1)}},[P,s,z,H,L,V,ie,n.saveError,m]),me=(0,Z.useCallback)(()=>{l({...d}),y(null),C(null),j(new Set)},[d]),ge=e=>{T(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},_e=(0,Z.useCallback)(()=>{L(),V()},[L,V]),ve=!!(E.trim()||O);return i?W?(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})]}):se.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:_??U??n.empty})]}),(0,X.jsx)(J,{type:`button`,variant:`secondary`,onClick:()=>{L(),V()},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:[S===`saved`?(0,X.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.saved}):null,S===`noChanges`?(0,X.jsx)(`span`,{className:`text-sm text-fg-muted`,children:n.noChangesSaved}):null,(0,X.jsx)(J,{type:`button`,variant:`secondary`,disabled:!G||m,onClick:me,children:n.discard}),(0,X.jsx)(J,{type:`button`,variant:`primary`,disabled:!G||m,onClick:()=>void de(),children:m?n.saving:n.save})]})]}),G?(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:p(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)(b,{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:E,onChange:e=>D(e.target.value),placeholder:n.searchPlaceholder,autoComplete:`off`,className:a(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-10 pr-3 text-sm text-fg placeholder:text-fg-subtle`,M,`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:O,onChange:e=>k(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]}),ve?(0,X.jsx)(J,{type:`button`,variant:`ghost`,className:`h-9 w-fit self-start text-fg-muted`,onClick:()=>{D(``),k(!1)},children:n.clearFilters}):null]}),_?(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:_}):null,ce.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)(J,{type:`button`,variant:`secondary`,className:`mt-4`,onClick:()=>{D(``),k(!1)},children:n.clearFilters})]}):(0,X.jsx)(`div`,{className:`flex flex-col gap-3`,children:Bn.map(t=>{let r=le.get(t)??[];if(r.length===0)return null;let i=w.has(t),o=r.filter(e=>e.configured).length,u=`providers-cat-${t}`;return(0,X.jsxs)(`section`,{className:`overflow-hidden rounded-2xl bg-surface-base`,children:[(0,X.jsxs)(`button`,{type:`button`,id:`${u}-trigger`,"aria-expanded":i,"aria-controls":u,className:`flex w-full items-center justify-between gap-2 border-b border-edge-subtle px-4 py-3 text-left transition-colors hover:bg-surface-hover/60 dark:border-edge-subtle`,onClick:()=>ge(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)(c,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}),Hn(n.configuredCount,{count:String(o)})]}):null,(0,X.jsx)(h,{className:a(`size-4 text-fg-subtle transition-transform`,i&&`rotate-180`),"aria-hidden":!0})]})]}),i?(0,X.jsx)(`div`,{id:u,role:`region`,"aria-labelledby":`${u}-trigger`,className:`divide-y divide-edge-subtle`,children:r.map(t=>(0,X.jsx)(`div`,{id:`provider-row-${t.id}`,children:(0,X.jsx)(Kn,{row:t,value:s[t.id]??``,rowDirty:(s[t.id]??``)!==(d[t.id]??``),labels:n,language:e,onChange:(e,t)=>l(n=>({...n,[e]:t})),onReload:_e,justSaved:A.has(t.id),availableModels:H??[]})},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)(fe,{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})]})]})})}function Gn({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)(c,{className:`size-3.5 text-emerald-600 dark:text-emerald-400`,"aria-hidden":!0}):(0,X.jsx)(N,{className:`size-3.5`,"aria-hidden":!0})})]})}function Kn({row:e,value:t,rowDirty:n,labels:r,language:i,onChange:o,onReload:s,justSaved:u,availableModels:d}){let[f,p]=(0,Z.useState)(!1),[m,g]=(0,Z.useState)(!1),[_,v]=(0,Z.useState)(!1),[y,b]=(0,Z.useState)(null),x=we(t),C=x&&!m?``:t,w=e.configured&&!x&&!!t,[E,D]=(0,Z.useState)(!1),[O,k]=(0,Z.useState)(),[A,j]=(0,Z.useState)(),[te,F]=(0,Z.useState)(),[L,R]=(0,Z.useState)(),[z,B]=(0,Z.useState)(),[V,re]=(0,Z.useState)(``),[H,ie]=(0,Z.useState)(!1),[ae,U]=(0,Z.useState)(null),[W,oe]=(0,Z.useState)(null),se=e.activeKeySource??`none`,le=(0,Z.useMemo)(()=>Ce(e.id,i),[e.id,i]);(0,Z.useEffect)(()=>()=>{O&&Ln(O).catch(()=>{})},[O]),(0,Z.useEffect)(()=>{if(!O||!E)return;let e=window.setInterval(()=>{(async()=>{try{let t=await Pn(O);F(t.message),R(t.authUrl),B(t.instructions),t.status===`waiting_auth`||t.status===`waiting_code`?j(t.status===`waiting_code`?`waiting_code`:`waiting`):t.status===`completed`?(window.clearInterval(e),D(!1),j(`success`),F(t.message),window.setTimeout(()=>s(),800)):(t.status===`failed`||t.status===`cancelled`)&&(window.clearInterval(e),D(!1),j(`error`),F(t.error||t.message||`OAuth failed`))}catch{}})()},1e3);return()=>window.clearInterval(e)},[O,E,s]);let ue=async()=>{D(!0),j(`waiting`),F(r.oauthStarting),k(void 0),R(void 0),B(void 0);try{k((await Nn(e.id)).sessionId)}catch(e){j(`error`),F(e instanceof Error?e.message:`OAuth failed`),D(!1)}},de=async()=>{if(O){try{await In(O)}catch{}k(void 0),D(!1),j(`idle`),F(void 0)}},K=async()=>{if(!(!O||!V.trim()))try{await Fn(O,V.trim()),re(``),F(r.oauthProcessingCode)}catch(e){j(`error`),F(e instanceof Error?e.message:`Failed`)}},me=()=>{window.confirm(Hn(r.revokeConfirm,{name:e.name}))&&(b(null),Rn(e.id).then(()=>s()).catch(e=>b(e instanceof Error?e.message:r.revokeFailed)))},he=async()=>{if(!(!t||x))try{await navigator.clipboard.writeText(t),v(!0),window.setTimeout(()=>v(!1),2e3)}catch{}},ge=async()=>{let e=t.trim();if(!(!e||we(e))){ie(!0),U(null),oe(null);try{let t=await ee(e);if(t.error){oe(!1),U(`${r.testFailed} ${t.error}`);return}oe(!0),t.type===`env`?U(r.testOkEnv):t.type===`command`?U(r.testOkCommand):U(r.testOkLiteral)}catch(e){oe(!1),U(e instanceof Error?e.message:r.testFailed)}finally{ie(!1)}}},ve=n?r.metaWillSave:e.configured?x?`${r.metaMasked} · ${r.runtimeLabelPrefix} ${Un(r,se)}`:`${r.runtimeLabelPrefix} ${Un(r,se)}`:r.metaNotConfigured,ye=`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)(c,{className:`size-4 text-emerald-600 dark:text-emerald-400`}):(0,X.jsx)(fe,{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)(zn,{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:ve})]}),(0,X.jsx)(J,{type:`button`,variant:`ghost`,className:`h-9 w-9 shrink-0 p-0`,"aria-expanded":f,"aria-controls":ye,"aria-label":r.expandRowDetails,onClick:()=>p(e=>!e),children:(0,X.jsx)(h,{className:a(`size-4 transition-transform`,f&&`rotate-180`),"aria-hidden":!0})})]}),f?(0,X.jsxs)(`div`,{id:ye,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||!x?`text`:`password`,className:a(`w-full rounded-lg border border-edge bg-surface-panel py-2 pl-3 pr-20 font-mono text-sm text-fg`,`placeholder:text-fg-subtle`,M,`dark:border-edge`),value:C,placeholder:x?r.placeholderOverride:e.configured?r.placeholderKeep:r.placeholderKey,disabled:E,onChange:t=>o(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&&!x?(0,X.jsx)(`button`,{type:`button`,className:a(`rounded p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg`,S.transition,S.press,S.focusRingPanel),title:_?r.copied:r.copy,"aria-label":_?r.copied:r.copy,onClick:()=>void he(),children:_?(0,X.jsx)(c,{className:`size-4`}):(0,X.jsx)(N,{className:`size-4`})}):null,(0,X.jsx)(`button`,{type:`button`,className:a(`rounded p-1.5 text-fg-subtle hover:bg-surface-hover hover:text-fg disabled:opacity-40`,S.transition,S.press,S.focusRingPanel),title:m?r.hide:r.show,"aria-label":m?r.hide:r.show,disabled:x,onClick:()=>g(e=>!e),children:m?(0,X.jsx)(ce,{className:`size-4`}):(0,X.jsx)(_e,{className:`size-4`})})]})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2 sm:shrink-0`,children:[(0,X.jsxs)(J,{type:`button`,variant:`secondary`,className:`gap-1`,disabled:E||H||!t.trim()||we(t),onClick:()=>void ge(),children:[H?(0,X.jsx)(q,{className:`size-4 animate-spin`,"aria-hidden":!0}):null,H?r.testingKey:r.testKey]}),e.supportsOAuth?w?(0,X.jsxs)(J,{type:`button`,variant:`secondary`,className:`gap-1 text-red-600 dark:text-red-400`,onClick:me,children:[(0,X.jsx)(T,{className:`size-4`,"aria-hidden":!0}),r.revoke]}):(0,X.jsxs)(J,{type:`button`,variant:`secondary`,className:`gap-1`,disabled:E,onClick:()=>void ue(),children:[E?(0,X.jsx)(q,{className:`size-4 animate-spin`,"aria-hidden":!0}):(0,X.jsx)(l,{className:`size-4`,"aria-hidden":!0}),r.oauth]}):null]})]}),ae?(0,X.jsx)(`p`,{className:a(`text-xs`,W===!1?`text-red-600 dark:text-red-400`:`text-fg-muted`),role:`status`,children:ae}):null,le.length>0?(0,X.jsx)(`div`,{className:`flex flex-col gap-1`,children:le.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:[P(e.kind,r),(0,X.jsx)(ne,{className:`size-3`,"aria-hidden":!0})]},`${e.kind}-${e.href}`))}):null]}),te?(0,X.jsxs)(`div`,{className:a(`flex gap-2 rounded-md px-3 py-2 text-xs`,A===`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:[A===`error`?(0,X.jsx)(G,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}):A===`success`?(0,X.jsx)(c,{className:`mt-0.5 size-4 shrink-0 text-emerald-600`,"aria-hidden":!0}):(0,X.jsx)(Se,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,X.jsx)(`span`,{children:te})]}):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)(G,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,X.jsx)(`span`,{children:y})]}):null,(A===`waiting`||A===`waiting_code`)&&(0,X.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[L?(0,X.jsxs)(`a`,{href:L,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1.5 rounded-md bg-accent px-3 py-2 text-sm font-medium text-white hover:bg-accent-hover`,children:[(0,X.jsx)(ne,{className:`size-4`,"aria-hidden":!0}),r.openAuthPage]}):null,(0,X.jsxs)(J,{type:`button`,variant:`secondary`,className:`gap-1`,onClick:()=>void de(),children:[(0,X.jsx)(I,{className:`size-4`,"aria-hidden":!0}),r.cancelOAuth]})]}),z?(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)(Se,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,X.jsx)(`span`,{children:z})]}):null,A===`waiting_code`?(0,X.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row`,children:[(0,X.jsx)(`input`,{type:`text`,className:a(`min-w-0 flex-1 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,M,`dark:border-edge`),value:V,placeholder:r.pasteRedirectUrl,onChange:e=>re(e.target.value),onKeyDown:e=>e.key===`Enter`&&void K()}),(0,X.jsx)(J,{type:`button`,variant:`primary`,className:`shrink-0`,onClick:()=>void K(),children:r.submitCode})]}):null,x?(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)(Se,{className:`mt-0.5 size-4 shrink-0`,"aria-hidden":!0}),(0,X.jsx)(`span`,{children:se===`env`?r.envHint:r.maskedStoredHint})]}):null,e.supportsOAuth&&!x&&!w?(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)(c,{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,(pe[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:(pe[e.id]?.envVars??[]).map(e=>(0,X.jsx)(Gn,{envVar:e,labels:r},e))})]}):null]}):null]})}var qn=[`appearance`,`system`,`agent-defaults`,`providers`,`models`,`voice`,`gateway`,`heartbeat`,`search`,`dreams`];function Jn(){let{section:e}=ye(),t=v(e=>e.language),n=K(t);if(e===`agent`||e===`agents`)return(0,X.jsx)(E,{to:`/agents`,replace:!0});if(!e||!qn.includes(e))return(0,X.jsx)(E,{to:`/settings/appearance`,replace:!0});let r=e,i=n.settingsSections[r];return r===`appearance`?(0,X.jsx)(ze,{}):r===`system`?(0,X.jsx)(_n,{}):r===`agent-defaults`?(0,X.jsx)(Pe,{}):r===`providers`?(0,X.jsx)(Wn,{}):r===`models`?(0,X.jsx)(Ft,{}):r===`voice`?(0,X.jsx)(nn,{}):r===`gateway`?(0,X.jsx)(We,{}):r===`heartbeat`?(0,X.jsx)(ct,{}):r===`search`?(0,X.jsx)(pn,{}):r===`dreams`?(0,X.jsx)(Mn,{}):(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{Jn as SettingsPage};
2
+ //# sourceMappingURL=settings-page-iYLSxQYc.js.map