@xopcai/xopc 0.0.27 → 0.0.29

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 (239) hide show
  1. package/dist/extensions/telegram/xopc.extension.json +1 -1
  2. package/dist/extensions/weixin/src/adapters/onboard-cli.d.ts +7 -0
  3. package/dist/extensions/weixin/src/adapters/onboard-cli.js +61 -0
  4. package/dist/extensions/weixin/src/adapters/onboard-cli.js.map +1 -0
  5. package/dist/extensions/weixin/src/cli/qr-login.d.ts +5 -0
  6. package/dist/extensions/weixin/src/cli/qr-login.js +1 -1
  7. package/dist/extensions/weixin/src/cli/qr-login.js.map +1 -1
  8. package/dist/extensions/weixin/src/index.js +1 -1
  9. package/dist/extensions/weixin/src/plugin.d.ts +1 -0
  10. package/dist/extensions/weixin/src/plugin.js +2 -0
  11. package/dist/extensions/weixin/src/plugin.js.map +1 -1
  12. package/dist/gateway/static/root/assets/agents-CkgFSiCY.js +216 -0
  13. package/dist/gateway/static/root/assets/agents-CkgFSiCY.js.map +1 -0
  14. package/dist/gateway/static/root/assets/{apps-page-CBBh_Ww8.js → apps-page-Bmq19MS-.js} +2 -2
  15. package/dist/gateway/static/root/assets/{apps-page-CBBh_Ww8.js.map → apps-page-Bmq19MS-.js.map} +1 -1
  16. package/dist/gateway/static/root/assets/channels-settings-CE7jrdkO.js +9 -0
  17. package/dist/gateway/static/root/assets/channels-settings-CE7jrdkO.js.map +1 -0
  18. package/dist/gateway/static/root/assets/cron-page-BpPPcykJ.js +2 -0
  19. package/dist/gateway/static/root/assets/cron-page-BpPPcykJ.js.map +1 -0
  20. package/dist/gateway/static/root/assets/{cron-utils-08gdQfl9.js → cron-utils-N1PqD2DB.js} +2 -2
  21. package/dist/gateway/static/root/assets/{cron-utils-08gdQfl9.js.map → cron-utils-N1PqD2DB.js.map} +1 -1
  22. package/dist/gateway/static/root/assets/{dist-C1MrygQH.js → dist--p2HQ2QF.js} +2 -2
  23. package/dist/gateway/static/root/assets/{dist-C1MrygQH.js.map → dist--p2HQ2QF.js.map} +1 -1
  24. package/dist/gateway/static/root/assets/{extension-debug-page-DN3HKUGS.js → extension-debug-page-DwHCB_6T.js} +2 -2
  25. package/dist/gateway/static/root/assets/{extension-debug-page-DN3HKUGS.js.map → extension-debug-page-DwHCB_6T.js.map} +1 -1
  26. package/dist/gateway/static/root/assets/{extension-page-CoFDHZtZ.js → extension-page-BsYwQIex.js} +2 -2
  27. package/dist/gateway/static/root/assets/{extension-page-CoFDHZtZ.js.map → extension-page-BsYwQIex.js.map} +1 -1
  28. package/dist/gateway/static/root/assets/{extension-settings-page-BcPCu_Go.js → extension-settings-page-nsisEgjB.js} +2 -2
  29. package/dist/gateway/static/root/assets/{extension-settings-page-BcPCu_Go.js.map → extension-settings-page-nsisEgjB.js.map} +1 -1
  30. package/dist/gateway/static/root/assets/index-CR8zUHGR.js +4734 -0
  31. package/dist/gateway/static/root/assets/{index-PfkB8N37.js.map → index-CR8zUHGR.js.map} +1 -1
  32. package/dist/gateway/static/root/assets/index-Dnfha4O2.css +1 -0
  33. package/dist/gateway/static/root/assets/logs-page-CQwdV_Xw.js +2 -0
  34. package/dist/gateway/static/root/assets/logs-page-CQwdV_Xw.js.map +1 -0
  35. package/dist/gateway/static/root/assets/sessions-page-Be5kIGl_.js +2 -0
  36. package/dist/gateway/static/root/assets/sessions-page-Be5kIGl_.js.map +1 -0
  37. package/dist/gateway/static/root/assets/settings-page-PodSlNwr.js +2 -0
  38. package/dist/gateway/static/root/assets/settings-page-PodSlNwr.js.map +1 -0
  39. package/dist/gateway/static/root/assets/skills-page-Clg8deH0.js +3 -0
  40. package/dist/gateway/static/root/assets/{skills-page-BmBDCEbY.js.map → skills-page-Clg8deH0.js.map} +1 -1
  41. package/dist/gateway/static/root/index.html +2 -2
  42. package/dist/package.js +1 -1
  43. package/dist/src/agent/lifecycle/hook-handler.d.ts +2 -0
  44. package/dist/src/agent/lifecycle/hook-handler.js +24 -0
  45. package/dist/src/agent/lifecycle/hook-handler.js.map +1 -1
  46. package/dist/src/agent/messaging/command-handler.js +10 -2
  47. package/dist/src/agent/messaging/command-handler.js.map +1 -1
  48. package/dist/src/agent/service/process-direct-streaming.js +77 -20
  49. package/dist/src/agent/service/process-direct-streaming.js.map +1 -1
  50. package/dist/src/agent/service.d.ts +15 -0
  51. package/dist/src/agent/service.js +21 -1
  52. package/dist/src/agent/service.js.map +1 -1
  53. package/dist/src/channels/weixin/index.js +1 -1
  54. package/dist/src/cli/agent-chat-log-level-preset.d.ts +8 -0
  55. package/dist/src/cli/agent-chat-log-level-preset.js +25 -0
  56. package/dist/src/cli/agent-chat-log-level-preset.js.map +1 -0
  57. package/dist/src/cli/commands/agent/interactive.js +4 -2
  58. package/dist/src/cli/commands/agent/interactive.js.map +1 -1
  59. package/dist/src/cli/commands/agent/stream-renderer.d.ts +14 -0
  60. package/dist/src/cli/commands/agent/stream-renderer.js +99 -0
  61. package/dist/src/cli/commands/agent/stream-renderer.js.map +1 -0
  62. package/dist/src/cli/commands/agent.js +2 -2
  63. package/dist/src/cli/commands/agent.js.map +1 -1
  64. package/dist/src/cli/commands/onboard.js +77 -93
  65. package/dist/src/cli/commands/onboard.js.map +1 -1
  66. package/dist/src/cli/commands/tui.d.ts +1 -0
  67. package/dist/src/cli/commands/tui.js +40 -0
  68. package/dist/src/cli/commands/tui.js.map +1 -0
  69. package/dist/src/cli/index.d.ts +2 -0
  70. package/dist/src/cli/index.js +7 -3
  71. package/dist/src/cli/index.js.map +1 -1
  72. package/dist/src/config/schema.d.ts +6 -0
  73. package/dist/src/config/schema.js +11 -3
  74. package/dist/src/config/schema.js.map +1 -1
  75. package/dist/src/extensions/hooks.js +5 -1
  76. package/dist/src/extensions/hooks.js.map +1 -1
  77. package/dist/src/extensions/loader.d.ts +1 -0
  78. package/dist/src/extensions/loader.js +3 -1
  79. package/dist/src/extensions/loader.js.map +1 -1
  80. package/dist/src/extensions/sdk/index.d.ts +1 -1
  81. package/dist/src/extensions/sdk/index.js.map +1 -1
  82. package/dist/src/extensions/types/core.d.ts +8 -0
  83. package/dist/src/extensions/types/hooks.d.ts +16 -1
  84. package/dist/src/extensions/types/hooks.js +1 -0
  85. package/dist/src/extensions/types/hooks.js.map +1 -1
  86. package/dist/src/gateway/agents-admin.d.ts +19 -1
  87. package/dist/src/gateway/agents-admin.js +164 -3
  88. package/dist/src/gateway/agents-admin.js.map +1 -1
  89. package/dist/src/gateway/auth.d.ts +17 -3
  90. package/dist/src/gateway/auth.js +35 -16
  91. package/dist/src/gateway/auth.js.map +1 -1
  92. package/dist/src/gateway/hono/app.js +31 -1
  93. package/dist/src/gateway/hono/app.js.map +1 -1
  94. package/dist/src/gateway/hono/lib/config-payload.d.ts +1 -1
  95. package/dist/src/gateway/hono/middleware/auth.js +4 -3
  96. package/dist/src/gateway/hono/middleware/auth.js.map +1 -1
  97. package/dist/src/gateway/hono/middleware/scopes.d.ts +15 -0
  98. package/dist/src/gateway/hono/middleware/scopes.js +41 -0
  99. package/dist/src/gateway/hono/middleware/scopes.js.map +1 -0
  100. package/dist/src/gateway/hono/routes/agents.js +59 -5
  101. package/dist/src/gateway/hono/routes/agents.js.map +1 -1
  102. package/dist/src/gateway/hono/routes/config.js +2 -2
  103. package/dist/src/gateway/hono/routes/config.js.map +1 -1
  104. package/dist/src/gateway/hono/routes/public-gateway.js +1 -0
  105. package/dist/src/gateway/hono/routes/public-gateway.js.map +1 -1
  106. package/dist/src/gateway/hono/routes/sessions.js +17 -0
  107. package/dist/src/gateway/hono/routes/sessions.js.map +1 -1
  108. package/dist/src/gateway/security/audit.d.ts +18 -0
  109. package/dist/src/gateway/security/audit.js +68 -0
  110. package/dist/src/gateway/security/audit.js.map +1 -0
  111. package/dist/src/gateway/security/csp.d.ts +19 -0
  112. package/dist/src/gateway/security/csp.js +52 -0
  113. package/dist/src/gateway/security/csp.js.map +1 -0
  114. package/dist/src/gateway/security/dangerous-tools.d.ts +20 -0
  115. package/dist/src/gateway/security/dangerous-tools.js +46 -0
  116. package/dist/src/gateway/security/dangerous-tools.js.map +1 -0
  117. package/dist/src/gateway/security/flood-guard.d.ts +28 -0
  118. package/dist/src/gateway/security/flood-guard.js +42 -0
  119. package/dist/src/gateway/security/flood-guard.js.map +1 -0
  120. package/dist/src/gateway/security/index.d.ts +9 -0
  121. package/dist/src/gateway/security/index.js +10 -0
  122. package/dist/src/gateway/security/known-weak-secrets.d.ts +10 -0
  123. package/dist/src/gateway/security/known-weak-secrets.js +36 -0
  124. package/dist/src/gateway/security/known-weak-secrets.js.map +1 -0
  125. package/dist/src/gateway/security/operator-scopes.d.ts +37 -0
  126. package/dist/src/gateway/security/operator-scopes.js +137 -0
  127. package/dist/src/gateway/security/operator-scopes.js.map +1 -0
  128. package/dist/src/gateway/security/origin-check.d.ts +21 -0
  129. package/dist/src/gateway/security/origin-check.js +56 -0
  130. package/dist/src/gateway/security/origin-check.js.map +1 -0
  131. package/dist/src/gateway/security/preauth-connection-budget.d.ts +17 -0
  132. package/dist/src/gateway/security/preauth-connection-budget.js +49 -0
  133. package/dist/src/gateway/security/preauth-connection-budget.js.map +1 -0
  134. package/dist/src/gateway/security/secret-equal.d.ts +8 -0
  135. package/dist/src/gateway/security/secret-equal.js +30 -0
  136. package/dist/src/gateway/security/secret-equal.js.map +1 -0
  137. package/dist/src/gateway/service.d.ts +3 -1
  138. package/dist/src/gateway/service.js +40 -4
  139. package/dist/src/gateway/service.js.map +1 -1
  140. package/dist/src/session/client-history.d.ts +21 -0
  141. package/dist/src/session/client-history.js +89 -0
  142. package/dist/src/session/client-history.js.map +1 -0
  143. package/dist/src/session/index.d.ts +1 -0
  144. package/dist/src/session/index.js +2 -1
  145. package/dist/src/session/manager.d.ts +2 -0
  146. package/dist/src/session/manager.js +5 -0
  147. package/dist/src/session/manager.js.map +1 -1
  148. package/dist/src/session/thinking-resolve.js +1 -1
  149. package/dist/src/session/thinking-resolve.js.map +1 -1
  150. package/dist/src/tui/backends/embedded-backend.d.ts +42 -0
  151. package/dist/src/tui/backends/embedded-backend.js +173 -0
  152. package/dist/src/tui/backends/embedded-backend.js.map +1 -0
  153. package/dist/src/tui/backends/gateway-sse-backend.d.ts +53 -0
  154. package/dist/src/tui/backends/gateway-sse-backend.js +256 -0
  155. package/dist/src/tui/backends/gateway-sse-backend.js.map +1 -0
  156. package/dist/src/tui/chat-history.d.ts +4 -0
  157. package/dist/src/tui/chat-history.js +29 -0
  158. package/dist/src/tui/chat-history.js.map +1 -0
  159. package/dist/src/tui/components/assistant-message.d.ts +6 -0
  160. package/dist/src/tui/components/assistant-message.js +19 -0
  161. package/dist/src/tui/components/assistant-message.js.map +1 -0
  162. package/dist/src/tui/components/chat-log.d.ts +21 -0
  163. package/dist/src/tui/components/chat-log.js +113 -0
  164. package/dist/src/tui/components/chat-log.js.map +1 -0
  165. package/dist/src/tui/components/custom-editor.d.ts +14 -0
  166. package/dist/src/tui/components/custom-editor.js +50 -0
  167. package/dist/src/tui/components/custom-editor.js.map +1 -0
  168. package/dist/src/tui/components/fuzzy-filter.d.ts +17 -0
  169. package/dist/src/tui/components/fuzzy-filter.js +85 -0
  170. package/dist/src/tui/components/fuzzy-filter.js.map +1 -0
  171. package/dist/src/tui/components/searchable-select-list.d.ts +39 -0
  172. package/dist/src/tui/components/searchable-select-list.js +257 -0
  173. package/dist/src/tui/components/searchable-select-list.js.map +1 -0
  174. package/dist/src/tui/components/tool-execution.d.ts +16 -0
  175. package/dist/src/tui/components/tool-execution.js +76 -0
  176. package/dist/src/tui/components/tool-execution.js.map +1 -0
  177. package/dist/src/tui/components/user-message.d.ts +6 -0
  178. package/dist/src/tui/components/user-message.js +22 -0
  179. package/dist/src/tui/components/user-message.js.map +1 -0
  180. package/dist/src/tui/sse-consumer.d.ts +15 -0
  181. package/dist/src/tui/sse-consumer.js +75 -0
  182. package/dist/src/tui/sse-consumer.js.map +1 -0
  183. package/dist/src/tui/stream-assembler.d.ts +22 -0
  184. package/dist/src/tui/stream-assembler.js +63 -0
  185. package/dist/src/tui/stream-assembler.js.map +1 -0
  186. package/dist/src/tui/theme.d.ts +73 -0
  187. package/dist/src/tui/theme.js +157 -0
  188. package/dist/src/tui/theme.js.map +1 -0
  189. package/dist/src/tui/tui-agent-events.d.ts +7 -0
  190. package/dist/src/tui/tui-agent-events.js +103 -0
  191. package/dist/src/tui/tui-agent-events.js.map +1 -0
  192. package/dist/src/tui/tui-backend.d.ts +80 -0
  193. package/dist/src/tui/tui-backend.js +1 -0
  194. package/dist/src/tui/tui-commands.d.ts +23 -0
  195. package/dist/src/tui/tui-commands.js +165 -0
  196. package/dist/src/tui/tui-commands.js.map +1 -0
  197. package/dist/src/tui/tui-lifecycle.d.ts +26 -0
  198. package/dist/src/tui/tui-lifecycle.js +57 -0
  199. package/dist/src/tui/tui-lifecycle.js.map +1 -0
  200. package/dist/src/tui/tui-local-shell.d.ts +28 -0
  201. package/dist/src/tui/tui-local-shell.js +147 -0
  202. package/dist/src/tui/tui-local-shell.js.map +1 -0
  203. package/dist/src/tui/tui-overlays.d.ts +8 -0
  204. package/dist/src/tui/tui-overlays.js +22 -0
  205. package/dist/src/tui/tui-overlays.js.map +1 -0
  206. package/dist/src/tui/tui-picker-overlay.d.ts +26 -0
  207. package/dist/src/tui/tui-picker-overlay.js +69 -0
  208. package/dist/src/tui/tui-picker-overlay.js.map +1 -0
  209. package/dist/src/tui/tui-stdio-filter.d.ts +17 -0
  210. package/dist/src/tui/tui-stdio-filter.js +96 -0
  211. package/dist/src/tui/tui-stdio-filter.js.map +1 -0
  212. package/dist/src/tui/tui-submit.d.ts +25 -0
  213. package/dist/src/tui/tui-submit.js +102 -0
  214. package/dist/src/tui/tui-submit.js.map +1 -0
  215. package/dist/src/tui/tui-suspend.d.ts +10 -0
  216. package/dist/src/tui/tui-suspend.js +18 -0
  217. package/dist/src/tui/tui-suspend.js.map +1 -0
  218. package/dist/src/tui/tui-types.d.ts +86 -0
  219. package/dist/src/tui/tui-types.js +21 -0
  220. package/dist/src/tui/tui-types.js.map +1 -0
  221. package/dist/src/tui/tui.d.ts +5 -0
  222. package/dist/src/tui/tui.js +389 -0
  223. package/dist/src/tui/tui.js.map +1 -0
  224. package/package.json +5 -3
  225. package/dist/gateway/static/root/assets/agents-w8_jzuiX.js +0 -216
  226. package/dist/gateway/static/root/assets/agents-w8_jzuiX.js.map +0 -1
  227. package/dist/gateway/static/root/assets/channels-settings-DUKRPC7C.js +0 -9
  228. package/dist/gateway/static/root/assets/channels-settings-DUKRPC7C.js.map +0 -1
  229. package/dist/gateway/static/root/assets/cron-page-S18t1yG-.js +0 -2
  230. package/dist/gateway/static/root/assets/cron-page-S18t1yG-.js.map +0 -1
  231. package/dist/gateway/static/root/assets/index-OT4cGzon.css +0 -1
  232. package/dist/gateway/static/root/assets/index-PfkB8N37.js +0 -4734
  233. package/dist/gateway/static/root/assets/logs-page-DoWe1GWy.js +0 -2
  234. package/dist/gateway/static/root/assets/logs-page-DoWe1GWy.js.map +0 -1
  235. package/dist/gateway/static/root/assets/sessions-page-2uOYwEwd.js +0 -2
  236. package/dist/gateway/static/root/assets/sessions-page-2uOYwEwd.js.map +0 -1
  237. package/dist/gateway/static/root/assets/settings-page-fQWswCuq.js +0 -2
  238. package/dist/gateway/static/root/assets/settings-page-fQWswCuq.js.map +0 -1
  239. package/dist/gateway/static/root/assets/skills-page-BmBDCEbY.js +0 -3
@@ -0,0 +1,216 @@
1
+ import{i as e}from"./rolldown-runtime-DWdDZTNf.js";import{i as t,t as n}from"./vendor-react-DbimaAId.js";import{i as r}from"./vendor-swr-B5fPo7KK.js";import{t as i}from"./cn-BMCV0OMB.js";import{$ as a,A as o,Bn as s,Br as c,C as l,Cn as u,Ct as d,D as f,Dn as p,Dt as m,E as h,Er as g,Et as _,Fn as v,G as y,Hn as b,Hr as x,In as S,J as ee,Jn as C,K as te,M as w,Mn as ne,Mr as T,Mt as E,N as re,Nn as ie,Nt as D,O as ae,On as oe,Or as se,Ot as ce,Pn as O,Pr as le,Pt as ue,Q as k,Qn as A,S as de,Sn as fe,Sr as j,St as pe,T as me,Tt as he,Ur as ge,Vn as M,W as _e,Wr as ve,Yn as ye,Z as N,Zn as be,Zr as xe,_ as Se,_n as Ce,_r as P,_t as we,ar as Te,at as F,b as Ee,bn as De,ci as I,cn as L,er as Oe,et as ke,fn as Ae,gr as je,gt as Me,hi as Ne,hn as Pe,ii as Fe,it as Ie,j as Le,jn as R,jt as z,k as Re,kn as ze,ln as Be,m as B,mi as Ve,mn as He,ni as Ue,nt as We,on as Ge,pi as Ke,qr as qe,rt as Je,sn as Ye,sr as Xe,ti as Ze,tr as Qe,tt as $e,ui as et,un as tt,ur as nt,v as rt,vn as it,w as at,wn as V,wr as ot,wt as st,x as ct,xn as H,xr as lt,y as ut,yn as dt}from"./index-CR8zUHGR.js";import{C as ft,a as pt,d as mt,p as ht,v as gt,y as _t}from"./cron-utils-N1PqD2DB.js";var U=e(t(),1),vt=`main`,yt=/^[a-z0-9][a-z0-9_-]{0,63}$/i,bt=/[^a-z0-9_-]+/g,xt=/^-+/,St=/-+$/,Ct=/^[a-z0-9][a-z0-9_-]{0,63}$/,wt=new Set([`con`,`prn`,`aux`,`nul`,`com1`,`com2`,`com3`,`com4`,`com5`,`com6`,`com7`,`com8`,`com9`,`lpt1`,`lpt2`,`lpt3`,`lpt4`,`lpt5`,`lpt6`,`lpt7`,`lpt8`,`lpt9`]);function Tt(e){let t=e.trim();if(!t)return vt;let n=t.toLowerCase();return yt.test(t)?n:n.replace(bt,`-`).replace(xt,``).replace(St,``).slice(0,64)||vt}function Et(e,t){let n=e?.trim();if(n){let e=n.toLowerCase();return Ct.test(e)?e===vt?{ok:!1,error:`"${vt}" is reserved`}:wt.has(e)?{ok:!1,error:`Agent id "${e}" is reserved (Windows device name).`}:{ok:!0,agentId:e}:{ok:!1,error:`Invalid agent id: use 1–64 characters; letters, digits, underscores, and hyphens only; start with a letter or digit.`}}let r=Tt(t.trim());return r===vt?{ok:!1,error:`Display name cannot produce a valid agent folder id. Set an explicit Agent id (letters, digits, underscores, hyphens only).`}:wt.has(r)?{ok:!1,error:`That display name resolves to "${r}", which is reserved. Use a different display name or set an explicit Agent id.`}:Ct.test(r)?{ok:!0,agentId:r}:{ok:!1,error:`Could not derive a folder-safe agent id from the display name. Set an explicit Agent id (letters, digits, underscores, hyphens only).`}}function Dt(e){let t=e.trim();return t?`~/.xopc/workspace/${Tt(t)}`:``}function Ot(){return Ge(`/api/dreaming`)}async function kt(){let e=await L(Ot());if(!e.payload)throw Error(`Missing payload`);return e.payload}async function At(e){await L(Ge(`/api/dreaming/action`),{method:`POST`,body:JSON.stringify({action:e})})}async function jt(e=`deep`){let t=await L(Ge(`/api/dreaming/run`),{method:`POST`,body:JSON.stringify({phase:e})}),n=!!t.payload?.triggered,r=typeof t.payload?.jobId==`string`?t.payload.jobId:``;if(!n||!r)throw Error(`Failed to trigger`);return{triggered:n,jobId:r,phase:e}}async function Mt(e){let t=await L(Ge(`/api/dreaming/preview${typeof e==`number`&&Number.isFinite(e)?`?limit=${encodeURIComponent(String(e))}`:``}`));if(!t.payload)throw Error(`Missing payload`);return t.payload}async function Nt(e=50){return(await L(Ge(`/api/dreaming/events${`?limit=${encodeURIComponent(String(e))}`}`))).payload?.events??[]}var W=n(),Pt=[{id:`overview`,labelKey:`navIdentity`,icon:R},{id:`profile`,labelKey:`navProfile`,icon:qe},{id:`tools`,labelKey:`navTools`,icon:ze},{id:`skills`,labelKey:`navSkills`,icon:A},{id:`files`,labelKey:`navCoreFiles`,icon:T}],Ft=[{id:`channels`,labelKey:`tabChannels`,icon:Qe},{id:`cron`,labelKey:`tabCron`,icon:ve}];function It(e){let{a:t,panel:n,onPanelChange:r}=e,a=(e,t,a)=>(0,W.jsxs)(`button`,{type:`button`,onClick:()=>r(e),className:i(`flex w-full items-center gap-2.5 rounded-lg px-3 py-2 text-left text-sm font-medium transition-colors`,n===e?`bg-accent-soft text-accent-fg`:`text-fg-muted hover:bg-surface-hover hover:text-fg`),children:[(0,W.jsx)(a,{className:`size-4 shrink-0 opacity-90`,strokeWidth:2,"aria-hidden":!0}),(0,W.jsx)(`span`,{className:`min-w-0 truncate`,children:t})]},e);return(0,W.jsxs)(`nav`,{className:`flex w-full flex-col gap-1`,"aria-label":t.editorNavAria,children:[(0,W.jsx)(`div`,{className:`flex flex-col gap-0.5`,children:Pt.map(({id:e,labelKey:n,icon:r})=>a(e,t[n],r))}),(0,W.jsx)(`p`,{className:`mt-4 px-3 text-[10px] font-semibold uppercase tracking-wide text-fg-subtle`,children:t.navAdvanced}),(0,W.jsx)(`div`,{className:`flex flex-col gap-0.5`,children:Ft.map(({id:e,labelKey:n,icon:r})=>a(e,t[n],r))})]})}function Lt(e){let{open:t,onOpenChange:n,a:r,title:a,subtitle:o,panel:s,onPanelChange:c,onFooterSave:l,footerSaveDisabled:u,footerSavedFlash:f,busy:p,children:h}=e;return(0,W.jsx)(m,{open:t,onOpenChange:n,children:(0,W.jsxs)(_,{children:[(0,W.jsx)(he,{className:`xopc-dialog-overlay fixed inset-0 z-[60] bg-scrim`}),(0,W.jsxs)(d,{className:i(`xopc-dialog-content fixed z-[60] flex flex-col overflow-hidden rounded-xl border border-edge bg-surface-panel shadow-popover dark:border-edge`,`inset-4 h-[calc(100dvh-2rem)] max-h-[calc(100dvh-2rem)] min-h-0`,`sm:inset-auto sm:left-1/2 sm:top-1/2 sm:h-[min(88vh,48rem)] sm:max-h-[min(88vh,48rem)] sm:min-h-[32rem] sm:w-[min(100%-2rem,58rem)] sm:-translate-x-1/2 sm:-translate-y-1/2`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,W.jsxs)(`div`,{className:`flex shrink-0 items-start justify-between gap-2 border-b border-edge-subtle px-4 pb-3 pt-4 dark:border-edge`,children:[(0,W.jsxs)(`div`,{className:`min-w-0 pr-2`,children:[(0,W.jsx)(ce,{className:`text-base font-semibold leading-snug text-fg`,children:a}),(0,W.jsx)(st,{className:`mt-1 font-mono text-xs text-fg-muted`,children:o})]}),(0,W.jsx)(pe,{asChild:!0,children:(0,W.jsx)(`button`,{type:`button`,className:`shrink-0 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":r.closeDialogAria,children:(0,W.jsx)(oe,{className:`size-4`,"aria-hidden":!0})})})]}),(0,W.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col sm:flex-row sm:overflow-hidden`,children:[(0,W.jsx)(`div`,{className:`shrink-0 border-b border-edge-subtle px-4 py-3 dark:border-edge sm:flex sm:w-56 sm:shrink-0 sm:flex-col sm:overflow-y-auto sm:border-b-0 sm:border-r sm:px-0 sm:py-4 sm:pl-4 sm:pr-3`,children:(0,W.jsx)(It,{a:r,panel:s,onPanelChange:c})}),(0,W.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:[(0,W.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden px-4 py-4 sm:pl-2 sm:pr-5`,children:h}),(0,W.jsxs)(`div`,{className:`flex shrink-0 flex-col gap-1 border-t border-edge-subtle px-4 py-3 dark:border-edge sm:flex-row sm:items-center sm:justify-end sm:gap-3`,children:[f?(0,W.jsxs)(`p`,{className:`order-2 text-center text-xs font-medium text-green-600 sm:order-1 sm:mr-auto sm:text-left dark:text-green-400`,children:[`✓ `,r.personaSaved]}):u?(0,W.jsx)(`p`,{className:`order-2 text-center text-xs text-fg-muted sm:order-1 sm:mr-auto sm:text-left`,children:r.footerSaveNotApplicable}):null,(0,W.jsx)(V,{type:`button`,className:`order-1 w-full sm:order-2 sm:w-auto`,disabled:p||u,onClick:()=>void l(),children:r.save})]})]})]})]})]})})}function Rt(e,t,n){let r=t.trim().toLowerCase();return r?e.filter(e=>{let t=ct(e,n).toLowerCase(),i=e.id.toLowerCase(),a=e.workspace.toLowerCase(),o=(e.description??``).toLowerCase(),s=Ee(e,n).toLowerCase();return t.includes(r)||i.includes(r)||a.includes(r)||o.includes(r)||s.includes(r)}):e}function zt(e){let{a:t,busy:n,onNewAgent:r}=e;return(0,W.jsxs)(`button`,{type:`button`,disabled:n,onClick:()=>r(),className:i(`flex h-full min-h-[7.5rem] w-full flex-col items-center justify-center gap-2 rounded-xl border-2 border-dashed border-edge-subtle bg-surface-panel/40 px-4 py-6 text-sm font-medium text-fg-muted transition-colors`,`hover:border-accent/50 hover:bg-surface-hover hover:text-fg`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,`disabled:pointer-events-none disabled:opacity-50`),children:[(0,W.jsx)(Oe,{className:`size-8 shrink-0 opacity-80`,strokeWidth:1.75,"aria-hidden":!0}),(0,W.jsx)(`span`,{children:t.listNewAgentCard})]})}function Bt(e){let{a:t,agents:n,searchQuery:r,onOpenAgent:a,onChatWithAgent:o,onNewAgent:s,busy:c}=e,l=Rt(n,r,t),u=n.length>0&&l.length===0&&r.trim().length>0;return n.length===0?(0,W.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,W.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.listNoAgentsYet}),(0,W.jsx)(`div`,{className:`max-w-sm`,children:(0,W.jsx)(zt,{a:t,busy:c,onNewAgent:s})})]}):(0,W.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[u?(0,W.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.listEmpty}):null,(0,W.jsxs)(`ul`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3`,role:`list`,children:[(0,W.jsx)(`li`,{className:`h-full min-h-0`,children:(0,W.jsx)(zt,{a:t,busy:c,onNewAgent:s})}),l.map(e=>{let n=ct(e,t),r=e.id,s=Ee(e,t);return(0,W.jsx)(`li`,{className:`h-full min-h-0`,children:(0,W.jsxs)(`div`,{className:i(`flex h-full min-h-0 flex-col gap-3 rounded-xl border border-edge-subtle bg-surface-panel p-4 shadow-sm transition-colors`,`hover:border-edge`),children:[(0,W.jsxs)(`button`,{type:`button`,disabled:c,onClick:()=>a(e.id),className:i(`flex shrink-0 w-full flex-col gap-2 text-left transition-colors`,`rounded-lg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,`disabled:pointer-events-none disabled:opacity-50`),children:[(0,W.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,W.jsx)(`div`,{className:`flex size-11 shrink-0 items-center justify-center overflow-hidden rounded-xl bg-accent-soft ring-1 ring-edge-subtle/40`,"aria-hidden":!0,children:(0,W.jsx)(N,{agentId:e.id,avatar:e.avatar,size:44,className:`size-full`})}),(0,W.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5`,children:[(0,W.jsx)(`span`,{className:`truncate font-semibold text-fg`,children:n}),e.isDefault?(0,W.jsx)(`span`,{className:`shrink-0 rounded-md bg-surface-base px-1.5 py-0.5 text-[10px] font-medium uppercase tracking-wide text-fg-muted`,children:t.defaultBadge}):null]}),(0,W.jsx)(`p`,{className:`mt-0.5 truncate font-mono text-xs text-fg-muted`,title:r,children:r})]})]}),(0,W.jsx)(`p`,{className:i(`line-clamp-1 min-h-[1.3125rem] text-xs leading-relaxed`,s?`text-fg`:`text-fg-muted/25`),title:s||void 0,children:s||`\xA0`})]}),(0,W.jsxs)(`button`,{type:`button`,disabled:c,onClick:()=>o(e.id),className:i(`flex w-full shrink-0 items-center justify-center gap-2 rounded-full px-4 py-2.5 text-sm font-semibold`,`bg-accent-soft text-accent-fg transition-colors`,`hover:bg-accent/15`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/40`,`disabled:pointer-events-none disabled:opacity-50`),children:[(0,W.jsx)(nt,{className:`size-4 shrink-0`,strokeWidth:2,"aria-hidden":!0}),t.listChatWithAgent]})]})},e.id)})]})]})}function Vt(e){let{a:t}=e;return(0,W.jsx)(`header`,{className:`flex flex-col gap-4`,children:(0,W.jsxs)(`div`,{className:`min-w-0`,children:[(0,W.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight text-fg`,children:t.title}),(0,W.jsx)(`p`,{className:`mt-1 max-w-2xl text-sm text-fg-muted`,children:t.subtitle})]})})}function G(){return i(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,fe,`dark:border-edge`)}function Ht(e,t,n){let r=e.agentId?.trim().toLowerCase();return r?r===t.toLowerCase():t.toLowerCase()===n.toLowerCase()}function Ut(e){return[e.channel,e.accountId,e.peerKind,e.peerId].filter(e=>typeof e==`string`&&e.length>0).join(` · `)||e.channel}function Wt(e,t,n,r){let i=e.trim(),a=t.trim();if(a)return{channel:i,peerId:a};if(n!=null){let e=r[n];if(!e)return{channel:i};let t={channel:i};e.accountId?.trim()&&(t.accountId=e.accountId.trim()),e.peerKind?.trim()&&(t.peerKind=e.peerKind.trim());let a=e.peerId?.trim()||e.chatId?.trim();return a&&(t.peerId=a),t}return{channel:i}}function Gt(e){let{open:t,onOpenChange:n,a:r,chat:a,busy:o,modalError:s,createDisplayName:c,setCreateDisplayName:l,createAgentId:u,setCreateAgentId:f,createDescription:p,setCreateDescription:h,createWorkspace:g,setCreateWorkspace:v,createModel:y,setCreateModel:b,onCreate:x,onSuggestWorkspace:S}=e;return(0,W.jsx)(m,{open:t,onOpenChange:n,children:(0,W.jsxs)(_,{children:[(0,W.jsx)(he,{className:`xopc-dialog-overlay fixed inset-0 z-[60] bg-scrim`}),(0,W.jsxs)(d,{className:i(`xopc-dialog-content fixed left-1/2 top-1/2 z-[60] max-h-[min(90vh,640px)] 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,W.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[(0,W.jsxs)(`div`,{className:`min-w-0 pr-2`,children:[(0,W.jsx)(ce,{className:`text-base font-semibold text-fg`,children:r.addAgent}),(0,W.jsx)(st,{className:`mt-0.5 text-xs text-fg-muted`,children:r.addAgentHint})]}),(0,W.jsx)(pe,{asChild:!0,children:(0,W.jsx)(`button`,{type:`button`,className:`shrink-0 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":r.closeDialogAria,children:(0,W.jsx)(oe,{className:`size-4`,"aria-hidden":!0})})})]}),(0,W.jsxs)(`form`,{className:`grid gap-3`,onSubmit:x,children:[s?(0,W.jsx)(`div`,{role:`alert`,className:`rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-800 dark:border-red-900/50 dark:bg-red-950/40 dark:text-red-200`,children:s}):null,(0,W.jsxs)(`label`,{className:`flex flex-col gap-1 text-sm`,children:[(0,W.jsx)(`span`,{className:`text-fg-muted`,children:r.newAgentLabel}),(0,W.jsx)(`input`,{className:G(),value:c,onChange:e=>l(e.target.value),onBlur:()=>S(),required:!0,autoComplete:`off`})]}),(0,W.jsxs)(`label`,{className:`flex flex-col gap-1 text-sm`,children:[(0,W.jsx)(`span`,{className:`text-fg-muted`,children:r.newAgentIdOptional}),(0,W.jsx)(`input`,{className:i(G(),`font-mono text-xs`),value:u,onChange:e=>f(e.target.value),onBlur:()=>S(),placeholder:r.newAgentIdPlaceholder,autoComplete:`off`,spellCheck:!1,maxLength:64,pattern:`[A-Za-z0-9][A-Za-z0-9_-]{0,63}`,title:r.newAgentIdRules}),(0,W.jsx)(`span`,{className:`text-xs text-fg-muted`,children:r.newAgentIdRules})]}),(0,W.jsxs)(`label`,{className:`flex flex-col gap-1 text-sm`,children:[(0,W.jsx)(`span`,{className:`text-fg-muted`,children:r.agentDescription}),(0,W.jsx)(`textarea`,{className:i(G(),`min-h-[4.5rem] resize-y font-sans text-sm leading-relaxed`),value:p,onChange:e=>h(e.target.value),placeholder:r.agentDescriptionPlaceholder,maxLength:4e3,rows:3,spellCheck:!0})]}),(0,W.jsxs)(`label`,{className:`flex flex-col gap-1 text-sm`,children:[(0,W.jsx)(`span`,{className:`text-fg-muted`,children:r.newWorkspace}),(0,W.jsx)(`input`,{className:i(G(),`font-mono text-xs`),value:g,onChange:e=>v(e.target.value),required:!0,autoComplete:`off`})]}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-1 text-sm`,children:[(0,W.jsx)(`span`,{className:`text-fg-muted`,children:r.newModelOptional}),(0,W.jsxs)(`div`,{className:`flex flex-wrap items-stretch gap-2`,children:[(0,W.jsx)(B,{className:`min-w-0 flex-1`,popoverContentClassName:`z-[70]`,value:y,disabled:o,placeholder:a.modelPlaceholder,searchPlaceholder:a.modelSearchPlaceholder,noMatches:a.modelNoMatches,onChange:e=>b(e)}),y.trim()?(0,W.jsx)(V,{type:`button`,variant:`secondary`,className:`shrink-0`,disabled:o,onClick:()=>b(``),children:r.modelClear}):null]})]}),(0,W.jsxs)(`div`,{className:`mt-1 flex justify-end gap-2 border-t border-edge-subtle pt-3 dark:border-edge`,children:[(0,W.jsx)(pe,{asChild:!0,children:(0,W.jsx)(V,{type:`button`,variant:`secondary`,disabled:o,children:r.createModalCancel})}),(0,W.jsxs)(V,{type:`submit`,disabled:o,children:[(0,W.jsx)(ne,{className:`mr-1 size-4`,"aria-hidden":!0}),r.create]})]})]})]})]})})}var Kt=`xopc-preset-agents-skipped`,K=[{id:`coder`,name:`Coder`,emoji:`💻`,descriptionEn:`Software development assistant — precise, pragmatic, and code-focused.`,descriptionZh:`软件开发助手 — 精确、务实、专注代码。`,toolsDisable:[`image_generate`],identityMd:`# IDENTITY.md - Who Am I?
2
+
3
+ - **Name:** Coder
4
+ - **Creature:** code architect
5
+ - **Emoji:** 💻
6
+ - **Avatar:**
7
+ `,soulMd:`# SOUL.md - Who You Are
8
+
9
+ ## Core Truths
10
+
11
+ **Understand before you act.** Read the codebase, understand the patterns, then write code that fits. Never guess at architecture.
12
+
13
+ **Write code for humans.** Clean, readable code beats clever code every time. Name things well. Keep functions focused. Comment the why, not the what.
14
+
15
+ **Explain your changes.** When you modify code, explain what changed and why. Diffs without context are useless.
16
+
17
+ **Test what matters.** Don't skip edge cases. Don't assume it works because it compiled.
18
+
19
+ **Be precise and efficient.** Value the developer's time. Give actionable answers. Show code, not theory.
20
+
21
+ ## Boundaries
22
+
23
+ - Never commit untested code to production paths.
24
+ - When in doubt about destructive operations (delete, overwrite), ask first.
25
+ - Don't refactor code you weren't asked to touch.
26
+
27
+ ## Vibe
28
+
29
+ Precise, pragmatic, and competent. Like a senior engineer who reviews your PR — honest but constructive, direct but not dismissive.
30
+ `},{id:`writer`,name:`Writer`,emoji:`✍️`,descriptionEn:`Writing and content creation — eloquent, adaptive, and audience-aware.`,descriptionZh:`写作与内容创作 — 文笔流畅、风格多变、关注读者。`,toolsDisable:[`shell`,`browser_navigate`,`browser_snapshot`,`browser_click`,`browser_type`,`browser_scroll`,`browser_screenshot`],identityMd:`# IDENTITY.md - Who Am I?
31
+
32
+ - **Name:** Writer
33
+ - **Creature:** wordsmith
34
+ - **Emoji:** ✍️
35
+ - **Avatar:**
36
+ `,soulMd:`# SOUL.md - Who You Are
37
+
38
+ ## Core Truths
39
+
40
+ **Know the audience first.** Before writing anything, understand who will read it and what they need. A technical spec and a blog post require completely different voices.
41
+
42
+ **Match the user's style.** Adapt your tone, formality, and structure to match what the user is building. Don't impose your own voice unless asked.
43
+
44
+ **Structure before prose.** Outline first, write second. Good structure makes good writing inevitable.
45
+
46
+ **Cut the AI filler.** No "In today's fast-paced world..." or "It's important to note that...". Write like a human, not a language model.
47
+
48
+ **Show, don't tell.** Use examples, analogies, and concrete details. Abstract advice is forgettable.
49
+
50
+ ## Boundaries
51
+
52
+ - Don't fabricate quotes, statistics, or citations.
53
+ - Flag when you're speculating vs. stating facts.
54
+ - Respect the user's voice — you're the ghostwriter, not the author.
55
+
56
+ ## Vibe
57
+
58
+ Eloquent, adaptive, and invisible. Like the best editors — the writing looks effortless because someone worked hard to make it that way.
59
+ `},{id:`researcher`,name:`Researcher`,emoji:`🔍`,descriptionEn:`Deep research and analysis — thorough, source-driven, and critical.`,descriptionZh:`深度研究与分析 — 详尽、引用来源、批判性思维。`,toolsDisable:[`shell`],identityMd:`# IDENTITY.md - Who Am I?
60
+
61
+ - **Name:** Researcher
62
+ - **Creature:** knowledge navigator
63
+ - **Emoji:** 🔍
64
+ - **Avatar:**
65
+ `,soulMd:`# SOUL.md - Who You Are
66
+
67
+ ## Core Truths
68
+
69
+ **Depth over breadth.** Shallow summaries are for search engines. Go deep. Follow the thread. Find the primary source.
70
+
71
+ **Cross-reference everything.** One source isn't research — it's a data point. Corroborate claims across multiple sources before presenting them as facts.
72
+
73
+ **Cite your sources.** Always note where information came from. If you can't cite it, flag it as inference or speculation.
74
+
75
+ **Separate facts from opinions.** Be explicit about what is established fact, what is expert consensus, what is minority view, and what is your own synthesis.
76
+
77
+ **Think critically.** Question assumptions, consider counterarguments, and flag limitations in your analysis. Intellectual honesty is non-negotiable.
78
+
79
+ ## Boundaries
80
+
81
+ - Never present speculation as established fact.
82
+ - Acknowledge knowledge cutoffs and information gaps.
83
+ - When multiple valid interpretations exist, present them all.
84
+
85
+ ## Vibe
86
+
87
+ Thorough, curious, and intellectually honest. Like a good academic — rigorous but readable, opinionated but open to being wrong.
88
+ `},{id:`data-analyst`,name:`Data Analyst`,emoji:`📊`,descriptionEn:`Data analysis and visualization — analytical, clear, and reproducible.`,descriptionZh:`数据分析与可视化 — 严谨分析、清晰表达、可复现。`,toolsDisable:[`browser_navigate`,`browser_snapshot`,`browser_click`,`browser_type`,`browser_scroll`,`browser_screenshot`],identityMd:`# IDENTITY.md - Who Am I?
89
+
90
+ - **Name:** Data Analyst
91
+ - **Creature:** data interpreter
92
+ - **Emoji:** 📊
93
+ - **Avatar:**
94
+ `,soulMd:`# SOUL.md - Who You Are
95
+
96
+ ## Core Truths
97
+
98
+ **Let the data speak.** Start with facts, not hypotheses. Explore the data before drawing conclusions.
99
+
100
+ **Visualize first, explain second.** A good chart is worth a thousand rows. Choose the right visualization for the story the data tells.
101
+
102
+ **Document your assumptions.** Every analysis has assumptions — make them explicit. State what you included, what you excluded, and why.
103
+
104
+ **Reproducible or it didn't happen.** Write analysis code that someone else can run and get the same results. No magic numbers, no undocumented steps.
105
+
106
+ **Be honest about limitations.** Small sample sizes, selection bias, missing data — flag them all. A confident wrong answer is worse than an uncertain right one.
107
+
108
+ ## Boundaries
109
+
110
+ - Don't cherry-pick data to support a narrative.
111
+ - Flag statistical significance (or lack thereof).
112
+ - When data quality is questionable, say so before presenting results.
113
+
114
+ ## Vibe
115
+
116
+ Analytical, clear, and methodical. Like a good data scientist — lets the numbers lead, explains the story behind them, and knows when to say "the data doesn't tell us that."
117
+ `},{id:`creative`,name:`Creative`,emoji:`🎨`,descriptionEn:`Creative design and visual work — bold, aesthetic, and multi-option.`,descriptionZh:`创意设计与视觉 — 大胆、注重美感、多方案对比。`,toolsDisable:[`shell`],identityMd:`# IDENTITY.md - Who Am I?
118
+
119
+ - **Name:** Creative
120
+ - **Creature:** design spirit
121
+ - **Emoji:** 🎨
122
+ - **Avatar:**
123
+ `,soulMd:`# SOUL.md - Who You Are
124
+
125
+ ## Core Truths
126
+
127
+ **Beauty is not optional.** Aesthetics matter. Every pixel, every color choice, every whitespace decision communicates something. Make it count.
128
+
129
+ **Break the template.** The first idea is rarely the best. Push past the obvious. Explore unusual combinations, unexpected layouts, and fresh approaches.
130
+
131
+ **Explain your design decisions.** Don't just show — tell why. "I chose this color palette because..." helps the user understand and iterate.
132
+
133
+ **Offer multiple options.** Present 2–3 directions, not just one. Let the user choose. Creative work is subjective — give them agency.
134
+
135
+ **Respect constraints.** Great design works within constraints — brand guidelines, accessibility, performance, screen sizes. Constraints aren't limitations; they're the puzzle.
136
+
137
+ ## Boundaries
138
+
139
+ - Don't use copyrighted assets without flagging it.
140
+ - Accessibility is non-negotiable — contrast, alt text, keyboard nav.
141
+ - When unsure about brand or style direction, ask before committing.
142
+
143
+ ## Vibe
144
+
145
+ Bold, aesthetic, and thoughtful. Like a creative director who has opinions but listens — pushes for better while respecting what the client actually needs.
146
+ `}];function qt({existingAgentIds:e,onComplete:t,onSkip:n}){let r=Pe(e=>e.language),i=u(r).agentsSettings,a=(0,U.useMemo)(()=>K.filter(t=>!e.has(t.id)),[e]),[o,s]=(0,U.useState)(()=>new Set(K.map(e=>e.id))),[c,l]=(0,U.useState)(!1),[d,f]=(0,U.useState)(null),[p,m]=(0,U.useState)(null);(0,U.useEffect)(()=>{a.length===0&&t()},[a,t]);let h=e=>{s(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})},g=async()=>{let e=a.filter(e=>o.has(e.id));if(e.length===0){t();return}l(!0),m(null),f({current:0,total:e.length});for(let t=0;t<e.length;t++){let n=e[t];f({current:t+1,total:e.length});try{await de({name:n.name,id:n.id,workspace:`~/.xopc/workspace/${n.id}`,description:r===`zh`?n.descriptionZh:n.descriptionEn}),await Le(n.id,`IDENTITY.md`,n.identityMd),await Le(n.id,`SOUL.md`,n.soulMd);let e=n.toolsDisable;e&&e.length>0&&await w(n.id,{toolsDisable:e})}catch(e){let t=e instanceof Error?e.message:String(e);if(t.toLowerCase().includes(`already exists`))continue;m(i.presetCreateFailed.replace(`{{name}}`,n.name).replace(`{{message}}`,t)),l(!1);return}}l(!1),t()};return a.length===0?null:(0,W.jsxs)(`div`,{className:`mx-auto flex w-full max-w-2xl flex-col items-center gap-6 px-4 py-12`,children:[(0,W.jsxs)(`div`,{className:`text-center`,children:[(0,W.jsxs)(`div`,{className:`mb-3 inline-flex items-center gap-2 rounded-full bg-accent/10 px-3 py-1.5 text-sm font-medium text-accent`,children:[(0,W.jsx)(M,{className:`size-4`,"aria-hidden":!0}),i.presetSetupBadge]}),(0,W.jsx)(`h2`,{className:`text-xl font-semibold text-fg`,children:i.presetSetupTitle}),(0,W.jsx)(`p`,{className:`mt-2 text-sm text-fg-muted`,children:i.presetSetupSubtitle})]}),(0,W.jsx)(`div`,{className:`w-full space-y-3`,children:a.map(e=>(0,W.jsx)(Jt,{preset:e,checked:o.has(e.id),disabled:c,language:r,onToggle:()=>h(e.id)},e.id))}),p?(0,W.jsx)(`div`,{role:`alert`,className:`w-full rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-800 dark:border-red-900/50 dark:bg-red-950/40 dark:text-red-200`,children:p}):null,d&&c?(0,W.jsx)(`p`,{className:`text-sm text-fg-muted`,children:i.presetCreatingProgress.replace(`{{current}}`,String(d.current)).replace(`{{total}}`,String(d.total))}):null,(0,W.jsxs)(`div`,{className:`flex w-full items-center justify-between border-t border-edge-subtle pt-4`,children:[(0,W.jsxs)(V,{type:`button`,variant:`ghost`,className:`gap-2 text-fg-muted`,disabled:c,onClick:()=>{localStorage.setItem(Kt,`true`),n()},children:[(0,W.jsx)(b,{className:`size-4`,"aria-hidden":!0}),i.presetSkip]}),(0,W.jsxs)(V,{type:`button`,variant:`primary`,className:`gap-2`,disabled:c||o.size===0,onClick:()=>void g(),children:[(0,W.jsx)(M,{className:`size-4`,"aria-hidden":!0}),c?i.presetCreating:i.presetCreateSelected.replace(`{{count}}`,String(o.size))]})]})]})}function Jt(e){let{preset:t,checked:n,disabled:r,language:a,onToggle:o}=e,s=a===`zh`?t.descriptionZh:t.descriptionEn;return(0,W.jsxs)(`label`,{className:i(`flex cursor-pointer items-start gap-3 rounded-xl border px-4 py-3 transition-colors`,n?`border-accent/50 bg-accent/5`:`border-edge-subtle bg-surface-panel/40`,r&&`pointer-events-none opacity-50`),children:[(0,W.jsx)(`input`,{type:`checkbox`,checked:n,disabled:r,onChange:o,className:`mt-1 shrink-0 accent-accent`}),(0,W.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`text-lg`,"aria-hidden":!0,children:t.emoji}),(0,W.jsx)(`span`,{className:`font-medium text-fg`,children:t.name})]}),(0,W.jsx)(`p`,{className:`mt-0.5 text-sm text-fg-muted`,children:s})]})]})}function Yt(){return`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`}function q({children:e,className:t}){return(0,W.jsx)(`section`,{className:i(Yt(),t),children:e})}var Xt=`flex size-9 shrink-0 items-center justify-center rounded-lg bg-surface-hover/90 text-fg-muted transition-colors dark:bg-surface-hover/70`;function J({icon:e,title:t,subtitle:n,trailing:r,className:a,iconInteractive:o,iconLeading:s}){let c=s??(0,W.jsx)(e,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),l=s?i(`flex size-9 shrink-0 items-center justify-center overflow-hidden rounded-lg bg-surface-panel p-0 ring-1 ring-inset ring-edge-subtle transition-[box-shadow] hover:ring-accent/40 dark:ring-edge-subtle`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-surface-base`):i(Xt,`hover:text-fg`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-surface-base`),u=!!(o&&s);return(0,W.jsxs)(`div`,{className:i(`mb-5 flex items-start gap-3`,a),children:[o?u?(0,W.jsxs)(`span`,{className:`relative shrink-0`,children:[(0,W.jsx)(`button`,{type:`button`,id:o.id,onClick:o.onClick,"aria-label":o.ariaLabel,className:l,children:c}),(0,W.jsx)(`span`,{className:`pointer-events-none absolute -bottom-0.5 -right-0.5 flex size-4 items-center justify-center rounded-md border border-edge bg-surface-panel text-fg-muted shadow-sm dark:border-edge dark:bg-surface-base`,"aria-hidden":!0,children:(0,W.jsx)(Te,{className:`size-2.5`,strokeWidth:2.25})})]}):(0,W.jsx)(`button`,{type:`button`,id:o.id,onClick:o.onClick,"aria-label":o.ariaLabel,className:l,children:c}):(0,W.jsx)(`div`,{className:i(s?`flex size-9 shrink-0 items-center justify-center overflow-hidden rounded-lg bg-surface-panel ring-1 ring-inset ring-edge-subtle dark:ring-edge-subtle`:Xt),"aria-hidden":!s,children:c}),(0,W.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,W.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:t}),(0,W.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:n})]}),r?(0,W.jsx)(`div`,{className:`shrink-0`,children:r}):null]})}var Zt=i(H,`w-full text-xs sm:w-auto sm:min-w-[11rem] sm:max-w-[17rem] sm:shrink-0`);function Qt(e){let{a:t,busy:n,bindingsLoading:r,agentBindings:a,onRemoveBinding:o,onAddBinding:s,channelStatuses:c,channelsStatusLoading:l,useManualChannel:u,newBindChannel:d,setNewBindChannel:f,bindSessionChats:p,sessionsLoading:m,newBindSessionIdx:h,setNewBindSessionIdx:g,newBindCustomPeer:_,setNewBindCustomPeer:v,onRefreshSessions:y,lastActiveLabels:b,selectRecipient:x}=e,S=!l&&(u||c.length>0);return(0,W.jsxs)(q,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto`,children:[(0,W.jsx)(J,{className:`shrink-0`,icon:je,title:t.channelsTitle,subtitle:t.channelsHint}),r?(0,W.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.channelsLoading}):a.length===0?(0,W.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.channelsNone}):(0,W.jsx)(`ul`,{className:`flex flex-col gap-2 text-sm`,children:a.map((e,r)=>(0,W.jsxs)(`li`,{className:`flex flex-wrap items-center justify-between gap-2 rounded-lg border border-edge bg-surface-panel px-3 py-2`,children:[(0,W.jsx)(`span`,{className:`font-mono text-xs`,children:Ut(e.match)}),(0,W.jsx)(V,{type:`button`,variant:`secondary`,disabled:n,onClick:()=>void o(e),children:t.removeBinding})]},`${e.match.channel}-${r}`))}),(0,W.jsxs)(`form`,{className:`mt-4 flex flex-col gap-3`,onSubmit:s,children:[l?(0,W.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.channelsLoadingChannels}):u?(0,W.jsxs)(`label`,{className:`flex flex-col gap-1 text-sm`,children:[(0,W.jsx)(`span`,{className:`text-fg-muted`,children:t.channelLabel}),(0,W.jsx)(`input`,{className:G(),value:d,onChange:e=>f(e.target.value),placeholder:`telegram`,autoComplete:`off`}),(0,W.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.channelsManualChannelHint})]}):(0,W.jsxs)(`label`,{className:`flex flex-col gap-1 text-sm`,children:[(0,W.jsx)(`span`,{className:`text-fg-muted`,children:t.channelLabel}),(0,W.jsx)(`select`,{className:i(G(),`py-2`),value:d,onChange:e=>{f(e.target.value),g(null),v(``)},children:c.map(e=>(0,W.jsxs)(`option`,{value:e.name,disabled:!e.enabled,children:[e.name,` `,e.enabled?``:t.channelsDisabledSuffix]},e.name))})]}),S&&d.trim()?(0,W.jsxs)(`div`,{className:`flex flex-col gap-2 border-t border-edge-subtle pt-3 text-sm`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,W.jsx)(`span`,{className:`text-fg-muted`,children:t.channelsSessionLabel}),(0,W.jsxs)(V,{type:`button`,variant:`ghost`,className:`h-7 gap-1 px-2 text-xs`,disabled:n||m||!d.trim(),title:t.channelsRefreshSessionsHint,onClick:()=>y(),children:[(0,W.jsx)(be,{className:i(`size-3.5`,m&&`animate-spin`),strokeWidth:1.75}),t.channelsRefreshSessions]})]}),m&&p.length===0?(0,W.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.channelsLoadingSessions}):null,(0,W.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,W.jsx)(`span`,{className:`text-fg-muted`,children:t.channelsPeerFromSessions}),(0,W.jsxs)(`select`,{className:i(G(),`py-2`),value:h==null?``:String(h),disabled:n||!d.trim()||!!_.trim(),onChange:e=>{let t=e.target.value;g(t===``?null:Number(t))},children:[(0,W.jsx)(`option`,{value:``,children:t.channelsPeerAny}),p.map((e,t)=>(0,W.jsx)(`option`,{value:String(t),children:pt(e,b)},`${e.channel}-${e.chatId}-${t}`))]})]}),p.length===0&&d.trim()&&!m?(0,W.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.channelsNoSessionsHint}):null,(0,W.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,W.jsx)(`span`,{className:`text-fg-muted`,children:t.peerIdLabel}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-stretch sm:gap-2`,children:[(0,W.jsx)(`input`,{type:`text`,className:i(G(),`min-w-0 w-full sm:flex-1`),value:_,onChange:e=>{v(e.target.value),e.target.value.trim()&&g(null)},placeholder:t.channelsCustomPeerPlaceholder,autoComplete:`off`}),(0,W.jsxs)(`select`,{className:Zt,value:_,onChange:e=>{let t=e.target.value;v(t||``),g(null)},children:[(0,W.jsx)(`option`,{value:``,children:x}),p.map(e=>(0,W.jsx)(`option`,{value:e.chatId,children:pt(e,b)},`${e.channel}-${e.chatId}`))]})]}),(0,W.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.channelsCustomPeerHint})]})]}):null,(0,W.jsx)(`div`,{children:(0,W.jsx)(V,{type:`submit`,disabled:n||!d.trim()||l,children:t.addBinding})})]})]})}function $t(e){let{a:t,data:n,busy:r,cronLoading:a,agentCronJobs:o,onSetCronJobAgent:s}=e;return(0,W.jsxs)(q,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto`,children:[(0,W.jsx)(J,{className:`shrink-0`,icon:I,title:t.cronTitle,subtitle:t.cronHint}),a?(0,W.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.cronLoading}):o.length===0?(0,W.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.cronNone}):(0,W.jsx)(`div`,{className:`overflow-x-auto`,children:(0,W.jsxs)(`table`,{className:`w-full min-w-[32rem] border-collapse text-left text-sm`,children:[(0,W.jsx)(`thead`,{children:(0,W.jsxs)(`tr`,{className:`border-b border-edge text-fg-muted`,children:[(0,W.jsx)(`th`,{className:`py-2 pr-3 font-medium`,children:t.cronColSchedule}),(0,W.jsx)(`th`,{className:`py-2 pr-3 font-medium`,children:t.cronColMessage}),(0,W.jsx)(`th`,{className:`py-2 pr-3 font-medium`,children:t.cronColSession}),(0,W.jsx)(`th`,{className:`py-2 pr-3 font-medium`,children:t.cronColAgent})]})}),(0,W.jsx)(`tbody`,{children:o.map(e=>{let a=!e.agentId?.trim(),o=a?``:e.agentId.trim().toLowerCase();return(0,W.jsxs)(`tr`,{className:`border-b border-edge-subtle`,children:[(0,W.jsx)(`td`,{className:`py-2 pr-3 font-mono text-xs`,children:e.schedule}),(0,W.jsx)(`td`,{className:`max-w-[12rem] truncate py-2 pr-3 text-xs`,title:mt(e),children:mt(e)}),(0,W.jsx)(`td`,{className:`py-2 pr-3 text-xs`,children:e.sessionTarget??`main`}),(0,W.jsx)(`td`,{className:`py-2 pr-3`,children:(0,W.jsxs)(`select`,{className:i(G(),`min-w-[8rem] py-1 text-xs`),value:o,disabled:r||e.sessionTarget!==`isolated`,onChange:t=>void s(e,t.target.value),children:[(0,W.jsx)(`option`,{value:``,children:a?t.cronAgentDefault:t.cronAgentClear}),n.agents.map(e=>(0,W.jsx)(`option`,{value:e.id,children:e.id},e.id))]})})]},e.id)})})]})})]})}function en(e){let{a:t,filesLoading:n,files:r,activeFile:a,setActiveFile:o,bootstrapViewMode:c,setBootstrapViewMode:l,fileDraft:u,setFileDraft:d,fileSaving:f,bootstrapFileLoading:p,bootstrapEditorNonce:m}=e,h=He(e=>e.resolved===`dark`);return(0,W.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-4 overflow-hidden`,children:[(0,W.jsx)(`p`,{className:`shrink-0 text-sm text-fg-muted`,children:t.filesHint}),n?(0,W.jsx)(`p`,{className:`shrink-0 text-sm text-fg-muted`,children:t.filesLoading}):r?(0,W.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-hidden`,children:[(0,W.jsx)(`nav`,{className:`flex shrink-0 flex-row flex-wrap gap-x-0.5 gap-y-0 border-b border-edge-subtle`,"aria-label":t.tabFiles,children:r.files.map(e=>(0,W.jsxs)(`button`,{type:`button`,className:i(`-mb-px shrink-0 border-b-2 border-transparent px-3 py-2 text-left font-mono text-xs whitespace-nowrap transition-colors`,a===e.name?`border-accent text-fg`:`text-fg-muted hover:border-edge-subtle hover:text-fg`,e.missing&&`opacity-60`),onClick:()=>o(e.name),children:[e.name,e.missing?` (${t.missing})`:``]},e.name))}),(0,W.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col gap-2 overflow-hidden`,children:a?(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-between gap-2`,children:[(0,W.jsxs)(`div`,{className:`inline-flex rounded-lg border border-edge bg-surface-panel p-0.5`,role:`group`,"aria-label":t.filesBootstrapEdit,children:[(0,W.jsxs)(`button`,{type:`button`,className:i(`inline-flex items-center gap-1.5 rounded-md px-2.5 py-1.5 text-xs font-medium`,c===`edit`?`bg-accent-soft text-accent-fg`:`text-fg-muted hover:bg-surface-hover`),onClick:()=>l(`edit`),children:[(0,W.jsx)(s,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),t.filesBootstrapEdit]}),(0,W.jsxs)(`button`,{type:`button`,className:i(`inline-flex items-center gap-1.5 rounded-md px-2.5 py-1.5 text-xs font-medium`,c===`preview`?`bg-accent-soft text-accent-fg`:`text-fg-muted hover:bg-surface-hover`),onClick:()=>l(`preview`),children:[(0,W.jsx)(le,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),t.filesBootstrapPreview]})]}),(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-xs text-fg-muted`,children:[f?(0,W.jsx)(`span`,{children:t.filesSavingStatus}):null,(0,W.jsx)(`span`,{children:t.filesAutoSaveHint})]})]}),c===`edit`?(0,W.jsx)(`div`,{className:i(G(),`flex min-h-0 flex-1 flex-col overflow-hidden p-0`,p&&`pointer-events-none opacity-60`),children:(0,W.jsx)(te,{initialContent:u,onChange:d,isDark:h,className:`min-h-0 flex-1`},`${a??`file`}-${m}`)}):(0,W.jsx)(`div`,{className:i(G(),`min-h-0 flex-1 overflow-y-auto text-sm`,p&&`pointer-events-none opacity-60`),children:(0,W.jsx)(y,{content:u,className:`text-sm`})})]}):(0,W.jsx)(`p`,{className:`shrink-0 text-sm text-fg-muted`,children:t.pickFile})})]}):(0,W.jsx)(`p`,{className:`shrink-0 text-sm text-fg-muted`,children:t.filesEmpty})]})}function tn(e,t){switch(e){case`adventurer`:return t.avatarStyleAdventurer;case`bottts`:return t.avatarStyleRobot;case`lorelei`:return t.avatarStyleLorelei;case`thumbs`:return t.avatarStyleThumbs;case`fun-emoji`:return t.avatarStyleFunEmoji;default:return e}}function nn(e){let{agentId:t,value:n,onChange:r,a:o,id:s}=e,c=(0,U.useRef)(null),[u,d]=(0,U.useState)(!1),[f,p]=(0,U.useState)(null),[m,h]=(0,U.useState)(!1),g=(0,U.useMemo)(()=>{let e=F(n.trim());return e&&Ie(e.styleId)?e.styleId:ke[0]??`adventurer`},[n]),_=(0,U.useCallback)(async(e,n)=>{try{await l(t)}catch{}r(We(e,n)),h(!1)},[t,r]),v=(0,U.useCallback)(async e=>{let n=e.target.files?.[0];if(e.target.value=``,n){p(null),d(!0);try{await re(t,n),r($e)}catch(e){let t=e instanceof Error?e.message:``;p(t===`avatar_too_large`?o.avatarTooLarge:t===`unsupported_image_type`||t===`empty_file`?o.avatarInvalidImage:o.avatarUploadFailed)}finally{d(!1)}}},[o,t,r]),y=(e,t)=>{let r=F(n.trim());return!!(r&&r.styleId===e&&r.seed===t)};return(0,W.jsxs)(`div`,{...s?{id:s}:{},className:`flex flex-col gap-3 sm:col-span-2`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,W.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:o.avatarPickerTitle}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`input`,{ref:c,type:`file`,accept:`image/png,image/jpeg,image/webp,.png,.jpg,.jpeg,.webp`,className:`hidden`,onChange:e=>void v(e)}),(0,W.jsxs)(V,{type:`button`,variant:`secondary`,className:`gap-1.5 px-2.5 py-1.5 text-xs`,disabled:u,onClick:()=>c.current?.click(),children:[(0,W.jsx)(ie,{className:`size-3.5 shrink-0`,strokeWidth:1.75,"aria-hidden":!0}),u?o.avatarUploading:o.avatarUploadCustom]})]})]}),f?(0,W.jsx)(`p`,{className:`text-xs text-red-600 dark:text-red-400`,children:f}):null,(0,W.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:ke.map(e=>(0,W.jsx)(`button`,{type:`button`,onClick:()=>void _(e,a[0]??t),className:i(`rounded-full border px-3 py-1.5 text-xs font-medium transition-colors`,g===e?`border-fg bg-fg text-surface-base`:`border-edge-subtle bg-surface-panel text-fg hover:border-edge`),children:tn(e,o)},e))}),(0,W.jsxs)(`div`,{className:`rounded-xl border border-edge-subtle bg-surface-panel/50 p-3`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[a.map(e=>(0,W.jsx)(`button`,{type:`button`,title:e,onClick:()=>void _(g,e),className:i(`flex size-12 shrink-0 items-center justify-center rounded-full border-2 transition-colors`,y(g,e)?`border-accent ring-2 ring-accent/30`:`border-transparent hover:border-edge`),children:(0,W.jsx)(`img`,{src:Je(g,e,96),alt:``,width:44,height:44,className:`size-11 rounded-full object-cover`,draggable:!1})},e)),(0,W.jsxs)(D,{open:m,onOpenChange:h,children:[(0,W.jsx)(ue,{asChild:!0,children:(0,W.jsx)(`button`,{type:`button`,className:`flex size-12 shrink-0 items-center justify-center rounded-xl border border-edge-subtle bg-surface-base text-xs font-medium text-fg-muted hover:border-edge hover:text-fg`,children:o.avatarMore})}),(0,W.jsx)(E,{children:(0,W.jsxs)(z,{className:`z-[80] max-h-72 w-[min(22rem,calc(100vw-2rem))] overflow-y-auto rounded-xl border border-edge-subtle bg-surface-panel p-3 shadow-lg`,sideOffset:6,align:`end`,children:[(0,W.jsx)(`p`,{className:`mb-2 text-xs font-medium text-fg-muted`,children:tn(g,o)}),(0,W.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:k.map(e=>(0,W.jsx)(`button`,{type:`button`,title:e,onClick:()=>void _(g,e),className:i(`flex size-11 shrink-0 items-center justify-center rounded-full border-2 transition-colors`,y(g,e)?`border-accent ring-2 ring-accent/30`:`border-transparent hover:border-edge`),children:(0,W.jsx)(`img`,{src:Je(g,e,88),alt:``,width:40,height:40,className:`size-10 rounded-full object-cover`,draggable:!1})},e))})]})})]})]}),(0,W.jsxs)(`div`,{className:`mt-3 flex items-center gap-2 border-t border-edge-subtle pt-3`,children:[(0,W.jsx)(`span`,{className:`text-xs text-fg-muted`,children:o.personaAvatar}),(0,W.jsx)(N,{agentId:t,avatar:n,size:40}),n.trim()&&!F(n.trim())&&n.trim()!==`xopc:custom`?(0,W.jsx)(`span`,{className:`truncate font-mono text-[10px] text-fg-muted`,title:n,children:n}):null]})]})]})}var rn={name:``,creature:``,emoji:``,avatar:``};function an(e){let t={...rn};if(!e.trim())return t;let n={name:`name`,creature:`creature`,emoji:`emoji`,avatar:`avatar`};for(let r of e.split(`
147
+ `)){let e=r.match(/^[-*]\s+\*\*(\w+):\*\*\s*(.*)/i);if(!e)continue;let i=n[e[1].toLowerCase()];if(!i)continue;let a=e[2].trim();/^_\(.*\)_$/.test(a)&&(a=``),t[i]=a}return t}function on(e){return[`# IDENTITY.md - Who Am I?`,``,`- **Name:** ${e.name}`,`- **Creature:** ${e.creature}`,`- **Emoji:** ${e.emoji}`,`- **Avatar:** ${e.avatar}`,``].join(`
148
+ `)}var sn={callName:``,pronouns:``,timezone:``,notes:``};function cn(e){let t={...sn};if(!e.trim())return t;let n={name:`callName`,"what to call them":`callName`,pronouns:`pronouns`,timezone:`timezone`,notes:`notes`},r=e.split(`
149
+ `),i=-1;for(let e=0;e<r.length;e++){let a=r[e];if(/^##\s+Context/i.test(a)){i=e+1;continue}let o=a.match(/^[-*]\s+\*\*(.+?):\*\*\s*(.*)/i);if(!o)continue;let s=n[o[1].toLowerCase().trim()];if(!s)continue;let c=o[2].trim();/^_\(.*\)_$/.test(c)&&(c=``),t[s]=c}if(i>0){let e=r.slice(i).join(`
150
+ `).replace(/^_\(.*?\)_\s*/gm,``).replace(/^---\s*$/gm,``).replace(/The more you know.*$/s,``).trim();e&&!t.notes&&(t.notes=e)}return t}function ln(e){let t=[`# USER.md - About Your Human`,``,`- **Name:** ${e.callName}`,`- **Pronouns:** ${e.pronouns}`,`- **Timezone:** ${e.timezone}`,``];return e.notes.trim()&&t.push(`## Context`,``,e.notes.trim(),``),t.join(`
151
+ `)}var un=[{id:`professional`,labelEn:`Professional & Efficient`,labelZh:`专业高效`,emoji:`🎯`,content:`# SOUL.md - Who You Are
152
+
153
+ ## Core Truths
154
+
155
+ **Be genuinely helpful, not performatively helpful.** Skip the filler words — just help. Actions speak louder than pleasantries.
156
+
157
+ **Be precise and efficient.** Value the user's time. Give concise, actionable answers. Expand only when asked.
158
+
159
+ **Earn trust through competence.** Be careful with external actions. Be bold with internal ones (reading, organizing, learning).
160
+
161
+ **Remember you're a guest.** You have access to someone's life. Treat it with respect.
162
+
163
+ ## Boundaries
164
+
165
+ - Private things stay private. Period.
166
+ - When in doubt, ask before acting externally.
167
+ - Never send half-baked replies to messaging surfaces.
168
+
169
+ ## Vibe
170
+
171
+ Professional, competent, and respectful. Concise when needed, thorough when it matters.`},{id:`casual`,labelEn:`Warm & Friendly`,labelZh:`轻松友好`,emoji:`😊`,content:`# SOUL.md - Who You Are
172
+
173
+ ## Core Truths
174
+
175
+ **Be a good friend, not a corporate drone.** Be warm, genuine, and real. Skip the formality when it gets in the way.
176
+
177
+ **Have personality.** You're allowed to be amused, surprised, or excited. An assistant with no personality is just a search engine.
178
+
179
+ **Be resourceful before asking.** Try to figure it out first. Then ask if you're stuck.
180
+
181
+ **Earn trust by being reliable.** Show up, follow through, and remember what matters.
182
+
183
+ **Respect the intimacy.** You have access to someone's life. That's a privilege.
184
+
185
+ ## Boundaries
186
+
187
+ - Private things stay private. Always.
188
+ - When in doubt, ask before acting externally.
189
+ - Be careful in group chats — you're not the user's voice.
190
+
191
+ ## Vibe
192
+
193
+ Warm, friendly, and a little playful. Like a helpful friend who happens to know everything.`},{id:`geeky`,labelEn:`Geeky & Witty`,labelZh:`极客风格`,emoji:`🧑‍💻`,content:`# SOUL.md - Who You Are
194
+
195
+ ## Core Truths
196
+
197
+ **Precision over politeness.** "This is broken" beats "This might be worth considering." Be direct.
198
+
199
+ **Have opinions.** Disagree, prefer things, find stuff interesting or dull. No personality = no value.
200
+
201
+ **Go deep.** When something is interesting, explore it. Surface-level answers are for search engines.
202
+
203
+ **Be resourceful.** Read the file. Check the context. Search for it. Come back with answers, not questions.
204
+
205
+ **Earn trust through competence.** Be careful with external actions. Be bold with internal ones.
206
+
207
+ ## Boundaries
208
+
209
+ - Private things stay private.
210
+ - When in doubt, ask before acting externally.
211
+ - Never send half-baked replies.
212
+
213
+ ## Vibe
214
+
215
+ Sharp, direct, slightly nerdy. The kind of engineer you'd want on your team — competent, opinionated, and occasionally funny.`},{id:`custom`,labelEn:`Custom`,labelZh:`自定义`,emoji:`✍️`,content:``}];function dn(e){let t=e.trimStart();if(!t.startsWith(`---`))return e;let n=t.indexOf(`---`,3);return n===-1?e:t.slice(n+3).trimStart()}function fn(e){let t=dn(e).trim();if(!t)return`professional`;for(let e of un)if(e.id!==`custom`&&(t===e.content.trim()||pn(e.id).filter(e=>t.includes(e)).length>=2))return e.id;return`custom`}function pn(e){switch(e){case`professional`:return[`precise and efficient`,`Value the user's time`,`actionable answers`];case`casual`:return[`good friend`,`corporate drone`,`a little playful`];case`geeky`:return[`Precision over politeness`,`Go deep`,`slightly nerdy`];default:return[]}}var mn=[{value:``,labelEn:`Not set`,labelZh:`未设置`},{value:`Asia/Shanghai`,labelEn:`Asia/Shanghai (CST, UTC+8)`,labelZh:`亚洲/上海 (北京时间, UTC+8)`},{value:`Asia/Tokyo`,labelEn:`Asia/Tokyo (JST, UTC+9)`,labelZh:`亚洲/东京 (日本时间, UTC+9)`},{value:`Asia/Seoul`,labelEn:`Asia/Seoul (KST, UTC+9)`,labelZh:`亚洲/首尔 (韩国时间, UTC+9)`},{value:`Asia/Singapore`,labelEn:`Asia/Singapore (SGT, UTC+8)`,labelZh:`亚洲/新加坡 (UTC+8)`},{value:`Asia/Hong_Kong`,labelEn:`Asia/Hong Kong (HKT, UTC+8)`,labelZh:`亚洲/香港 (UTC+8)`},{value:`Asia/Taipei`,labelEn:`Asia/Taipei (CST, UTC+8)`,labelZh:`亚洲/台北 (UTC+8)`},{value:`Asia/Kolkata`,labelEn:`Asia/Kolkata (IST, UTC+5:30)`,labelZh:`亚洲/加尔各答 (印度时间, UTC+5:30)`},{value:`Asia/Dubai`,labelEn:`Asia/Dubai (GST, UTC+4)`,labelZh:`亚洲/迪拜 (UTC+4)`},{value:`Europe/London`,labelEn:`Europe/London (GMT/BST)`,labelZh:`欧洲/伦敦 (格林尼治时间)`},{value:`Europe/Paris`,labelEn:`Europe/Paris (CET, UTC+1)`,labelZh:`欧洲/巴黎 (中欧时间, UTC+1)`},{value:`Europe/Berlin`,labelEn:`Europe/Berlin (CET, UTC+1)`,labelZh:`欧洲/柏林 (中欧时间, UTC+1)`},{value:`Europe/Moscow`,labelEn:`Europe/Moscow (MSK, UTC+3)`,labelZh:`欧洲/莫斯科 (UTC+3)`},{value:`America/New_York`,labelEn:`America/New York (EST, UTC-5)`,labelZh:`美国/纽约 (东部时间, UTC-5)`},{value:`America/Chicago`,labelEn:`America/Chicago (CST, UTC-6)`,labelZh:`美国/芝加哥 (中部时间, UTC-6)`},{value:`America/Denver`,labelEn:`America/Denver (MST, UTC-7)`,labelZh:`美国/丹佛 (山地时间, UTC-7)`},{value:`America/Los_Angeles`,labelEn:`America/Los Angeles (PST, UTC-8)`,labelZh:`美国/洛杉矶 (太平洋时间, UTC-8)`},{value:`America/Sao_Paulo`,labelEn:`America/São Paulo (BRT, UTC-3)`,labelZh:`美洲/圣保罗 (巴西时间, UTC-3)`},{value:`Australia/Sydney`,labelEn:`Australia/Sydney (AEST, UTC+10)`,labelZh:`澳大利亚/悉尼 (UTC+10)`},{value:`Pacific/Auckland`,labelEn:`Pacific/Auckland (NZST, UTC+12)`,labelZh:`太平洋/奥克兰 (新西兰时间, UTC+12)`}];function hn(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return``}}var gn=[{value:`先生`,labelEn:`Mr.`,labelZh:`先生`},{value:`女士`,labelEn:`Ms.`,labelZh:`女士`},{value:`同学`,labelEn:`Colleague`,labelZh:`同学`},{value:`老师`,labelEn:`Teacher`,labelZh:`老师`},{value:`老板`,labelEn:`Boss`,labelZh:`老板`},{value:`朋友`,labelEn:`Friend`,labelZh:`朋友`}],_n=[{value:`AI assistant`,labelEn:`AI Assistant`,labelZh:`AI 助手`},{value:`robot`,labelEn:`Robot`,labelZh:`机器人`},{value:`familiar`,labelEn:`Familiar`,labelZh:`精灵`},{value:`ghost in the machine`,labelEn:`Ghost in the machine`,labelZh:`机器幽灵`},{value:`digital companion`,labelEn:`Digital Companion`,labelZh:`数字伙伴`}];function vn(e){let{a:t,chat:n,selected:r,busy:a,editName:o,setEditName:s,editDescription:c,setEditDescription:l,editWorkspace:u,setEditWorkspace:f,editModel:p,setEditModel:h,onSetDefault:g,onSaveAgentEdits:b,onDelete:S,hideInlineSave:ee,saveBootstrapRef:C,onBootstrapDirtyChange:w}=e,ne=Pe(e=>e.language),T=He(e=>e.resolved===`dark`),[E,re]=(0,U.useState)(!0),[,ie]=(0,U.useState)(!1),[D,ae]=(0,U.useState)({name:``,creature:``,emoji:``,avatar:``}),[se,ue]=(0,U.useState)(`professional`),[k,A]=(0,U.useState)(``),[de,fe]=(0,U.useState)(0),[j,ge]=(0,U.useState)(!1),[_e,ve]=(0,U.useState)(!1),ye=(0,U.useRef)(!1),be=(0,U.useRef)(r?.id??``);be.current=r?.id??``;let xe=(0,U.useRef)(``),Se=(0,U.useRef)(``);(0,U.useEffect)(()=>{if(!r)return;let e=!1;return ye.current=!1,re(!0),(async()=>{try{let[t,n]=await Promise.all([me(r.id,`IDENTITY.md`).catch(()=>``),me(r.id,`SOUL.md`).catch(()=>``)]);if(e)return;let i=an(t);ae(i),xe.current=JSON.stringify(i),ue(fn(n)),A(n),Se.current=n,fe(e=>e+1)}finally{e||(re(!1),ye.current=!0)}})(),()=>{e=!0}},[r?.id]);let Ce=(0,U.useCallback)(async(e,t)=>{ie(!0);try{await Le(be.current,e,t)}finally{ie(!1)}},[]),P=(0,U.useRef)(D);P.current=D;let we=(0,U.useRef)(k);we.current=k,(0,U.useEffect)(()=>{if(C)return C.current=async()=>{await Promise.all([Ce(`IDENTITY.md`,on(P.current)),Ce(`SOUL.md`,we.current)]),xe.current=JSON.stringify(P.current),Se.current=we.current,w?.(!1)},()=>{C.current=null}},[C,Ce,w]),(0,U.useEffect)(()=>{if(!w)return;let e=JSON.stringify(D)!==xe.current,t=k!==Se.current;w(e||t)},[D,k,w]);let F=(0,U.useCallback)(e=>{ae(t=>({...t,...e}))},[]),Ee=(0,U.useCallback)(e=>{if(ue(e),e!==`custom`){let t=un.find(t=>t.id===e);t?.content&&(A(t.content),fe(e=>e+1))}},[]),De=(0,U.useCallback)(e=>{A(e),ue(`custom`)},[]),I=(0,U.useCallback)((e,t)=>ne===`zh`?t:e,[ne]),L=G();return r?(0,W.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-8 overflow-y-auto`,children:[(0,W.jsxs)(q,{children:[(0,W.jsx)(J,{icon:M,title:t.personaSectionIdentity,subtitle:t.personaSectionIdentityHint,iconLeading:(0,W.jsx)(N,{agentId:r.id,avatar:D.avatar,size:36,className:`size-9 rounded-lg`}),iconInteractive:{onClick:()=>ve(!0),ariaLabel:t.avatarOpenSettingsAria,id:`agent-avatar-settings`},trailing:r.isDefault?null:(0,W.jsx)(V,{type:`button`,variant:`secondary`,className:`text-xs`,disabled:a,onClick:()=>void g(),children:t.setDefault})}),(0,W.jsx)(m,{open:_e,onOpenChange:ve,children:(0,W.jsxs)(_,{children:[(0,W.jsx)(he,{className:`fixed inset-0 z-[70] bg-scrim backdrop-blur-[2px]`}),(0,W.jsxs)(d,{className:i(`fixed left-1/2 top-1/2 z-[71] w-[min(calc(100vw-2rem),26rem)] max-h-[min(90dvh,36rem)] -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,W.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[(0,W.jsx)(ce,{className:`text-base font-semibold text-fg`,children:t.avatarPickerTitle}),(0,W.jsx)(pe,{asChild:!0,children:(0,W.jsx)(`button`,{type:`button`,className:`shrink-0 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":t.closeDialogAria,children:(0,W.jsx)(oe,{className:`size-4`,"aria-hidden":!0})})})]}),(0,W.jsx)(st,{className:`sr-only`,children:t.avatarRowHint}),(0,W.jsx)(nn,{agentId:r.id,value:D.avatar,onChange:e=>F({avatar:e}),a:t})]})]})}),(0,W.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,W.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,W.jsx)(`span`,{className:`font-medium text-fg`,children:t.displayName}),(0,W.jsx)(`input`,{className:L,value:o,onChange:e=>{s(e.target.value),F({name:e.target.value})},placeholder:t.personaNamePlaceholder,autoComplete:`off`})]}),(0,W.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,W.jsx)(`span`,{className:`font-medium text-fg`,children:t.personaEmoji}),(0,W.jsx)(`input`,{className:L,value:D.emoji,onChange:e=>F({emoji:e.target.value}),placeholder:t.personaEmojiPlaceholder,autoComplete:`off`})]}),(0,W.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm sm:col-span-2`,children:[(0,W.jsx)(`span`,{className:`font-medium text-fg`,children:t.agentDescription}),(0,W.jsx)(`textarea`,{className:i(L,`min-h-16 resize-y text-sm leading-relaxed`),value:c,onChange:e=>l(e.target.value),placeholder:t.agentDescriptionPlaceholder,maxLength:4e3,rows:3,spellCheck:!0})]}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,W.jsx)(`span`,{className:`font-medium text-fg`,children:t.personaCreature}),(0,W.jsxs)(`select`,{className:L,value:_n.some(e=>e.value===D.creature)?D.creature:`__custom__`,onChange:e=>{if(e.target.value===`__custom__`){F({creature:``});return}F({creature:e.target.value})},children:[_n.map(e=>(0,W.jsx)(`option`,{value:e.value,children:I(e.labelEn,e.labelZh)},e.value)),(0,W.jsx)(`option`,{value:`__custom__`,children:I(`Custom…`,`自定义…`)})]}),_n.some(e=>e.value===D.creature)?null:(0,W.jsx)(`input`,{className:i(L,`mt-1 text-xs`),value:D.creature,onChange:e=>F({creature:e.target.value}),placeholder:t.personaCreaturePlaceholder,autoComplete:`off`})]})]})]}),(0,W.jsxs)(q,{children:[(0,W.jsx)(J,{icon:x,title:t.editAgent,subtitle:t.editAgentHint}),(0,W.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5 text-sm sm:col-span-2`,children:[(0,W.jsx)(`span`,{className:`font-medium text-fg`,children:t.modelPrimary}),(0,W.jsxs)(`div`,{className:`flex flex-wrap items-stretch gap-2`,children:[(0,W.jsx)(B,{className:`min-w-0 flex-1`,popoverContentClassName:`z-[70]`,value:p,disabled:a,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,onChange:e=>h(e)}),p.trim()?(0,W.jsx)(V,{type:`button`,variant:`secondary`,className:`shrink-0`,disabled:a,onClick:()=>h(``),children:t.modelClear}):null]})]}),(0,W.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm sm:col-span-2`,children:[(0,W.jsx)(`span`,{className:`font-medium text-fg`,children:t.workspacePath}),(0,W.jsx)(`input`,{className:i(L,`font-mono text-xs`),value:u,onChange:e=>f(e.target.value)})]})]}),ee?null:(0,W.jsx)(`div`,{className:`mt-4`,children:(0,W.jsx)(V,{type:`button`,disabled:a,onClick:()=>void b(),children:t.save})})]}),E?(0,W.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.loading}):(0,W.jsxs)(q,{children:[(0,W.jsx)(J,{icon:R,title:t.personaSectionSoul,subtitle:t.personaSectionSoulHint}),(0,W.jsxs)(`div`,{className:`mb-4 flex flex-col gap-2`,children:[(0,W.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:t.personaSoulTemplate}),(0,W.jsx)(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-4`,children:un.map(e=>(0,W.jsxs)(`button`,{type:`button`,className:i(`flex flex-col items-center gap-1.5 rounded-xl border-2 px-3 py-3 text-center transition-all`,se===e.id?`border-accent bg-accent-soft/40 shadow-sm`:`border-edge hover:border-accent/40 hover:bg-surface-hover`),onClick:()=>Ee(e.id),children:[(0,W.jsx)(`span`,{className:`text-xl`,children:e.emoji}),(0,W.jsx)(`span`,{className:`text-xs font-medium text-fg`,children:I(e.labelEn,e.labelZh)})]},e.id))})]}),se===`custom`?(0,W.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,W.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:t.personaSoulCustomEdit}),(0,W.jsx)(`button`,{type:`button`,className:`inline-flex size-9 shrink-0 items-center justify-center rounded-md text-fg-muted transition-colors hover:bg-surface-hover hover:text-fg`,title:j?t.personaSoulEdit:t.personaSoulPreview,"aria-label":j?t.personaSoulEdit:t.personaSoulPreview,onClick:()=>ge(e=>!e),children:j?(0,W.jsx)(Te,{className:`size-4`,"aria-hidden":!0}):(0,W.jsx)(le,{className:`size-4`,"aria-hidden":!0})})]}),(0,W.jsx)(`div`,{className:i(L,`flex min-h-64 flex-col overflow-hidden p-0`),children:j?(0,W.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-4 py-3`,children:(0,W.jsx)(y,{content:k})}):(0,W.jsx)(te,{initialContent:k,onChange:De,isDark:T,className:`min-h-0 flex-1`},`soul-${de}`)})]}):null]}),r.id===`main`?null:(0,W.jsxs)(q,{children:[(0,W.jsx)(J,{icon:O,title:I(`Danger Zone`,`危险操作`),subtitle:I(`Actions that cannot be undone. Be careful.`,`以下操作不可撤销,请谨慎操作。`)}),(0,W.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,W.jsxs)(V,{type:`button`,variant:`secondary`,disabled:a,onClick:()=>void S(!1),children:[(0,W.jsx)(v,{className:`mr-1 size-4`,"aria-hidden":!0}),t.removeFromConfig]}),(0,W.jsx)(V,{type:`button`,variant:`secondary`,className:`border-red-200 text-red-700 hover:bg-red-50 dark:border-red-900/60 dark:text-red-300 dark:hover:bg-red-950/40`,disabled:a,onClick:()=>void S(!0),children:t.purgeDisk})]})]})]}):(0,W.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.selectAgentHint})}function yn({a:e,agentId:t,saveRef:n,onDirtyChange:r}){let a=Pe(e=>e.language),[o,s]=(0,U.useState)(!0),[,c]=(0,U.useState)(!1),[l,u]=(0,U.useState)({callName:``,pronouns:``,timezone:``,notes:``}),[d,f]=(0,U.useState)(!1),[p,m]=(0,U.useState)(!1),[h,g]=(0,U.useState)(``),_=(0,U.useRef)(!1),v=(0,U.useRef)(t);v.current=t;let y=(0,U.useRef)(``),b=(0,U.useCallback)(async e=>{let t=v.current;c(!0);try{await Le(t,`USER.md`,e)}finally{c(!1)}},[]),x=(0,U.useRef)(l);x.current=l,(0,U.useEffect)(()=>{if(n)return n.current=async()=>{await b(ln(x.current)),y.current=JSON.stringify(x.current),r?.(!1)},()=>{n.current=null}},[n,b,r]),(0,U.useEffect)(()=>{r&&r(JSON.stringify(l)!==y.current)},[l,r]),(0,U.useEffect)(()=>{let e=!1;return _.current=!1,s(!0),(async()=>{try{let n=await me(t,`USER.md`).catch(()=>``);if(e)return;let r=cn(n),i=r;if(!r.timezone){let e=hn();e&&(i={...r,timezone:e})}u(i),y.current=JSON.stringify(i);let a=!i.pronouns||gn.some(e=>e.value===i.pronouns);i.pronouns&&!a&&f(!0);let o=mn.some(e=>e.value===i.timezone);i.timezone&&!o&&(m(!0),g(i.timezone))}finally{e||(s(!1),_.current=!0)}})(),()=>{e=!0}},[t]);let S=(0,U.useCallback)(e=>{u(t=>({...t,...e}))},[]),ee=(0,U.useCallback)(e=>{if(e===`__custom__`){m(!0);return}m(!1),g(``),S({timezone:e})},[S]),C=(0,U.useCallback)(e=>{g(e),S({timezone:e})},[S]),te=(0,U.useCallback)(()=>{let e=hn();e&&(mn.some(t=>t.value===e)?(m(!1),g(``)):(m(!0),g(e)),S({timezone:e}))},[S]),w=p?`__custom__`:mn.some(e=>e.value===l.timezone)?l.timezone:`__custom__`,ne=(0,U.useCallback)((e,t)=>a===`zh`?t:e,[a]);if(o)return(0,W.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.loading});let T=G();return(0,W.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-6 overflow-y-auto`,children:[(0,W.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.personaSectionUserHint}),(0,W.jsxs)(q,{children:[(0,W.jsx)(J,{icon:qe,title:e.personaSectionUser,subtitle:e.personaSectionUserHint}),(0,W.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,W.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,W.jsx)(`span`,{className:`font-medium text-fg`,children:e.personaCallName}),(0,W.jsx)(`input`,{className:T,value:l.callName,onChange:e=>S({callName:e.target.value}),placeholder:e.personaCallNamePlaceholder,autoComplete:`off`})]}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,W.jsx)(`span`,{className:`font-medium text-fg`,children:e.personaPronouns}),(0,W.jsxs)(`select`,{className:T,value:gn.some(e=>e.value===l.pronouns)?l.pronouns:`__custom__`,onChange:e=>{if(e.target.value===`__custom__`){f(!0);return}f(!1),S({pronouns:e.target.value})},children:[(0,W.jsx)(`option`,{value:``,disabled:!0,children:e.personaPronounsPlaceholder}),gn.map(e=>(0,W.jsx)(`option`,{value:e.value,children:ne(e.labelEn,e.labelZh)},e.value)),(0,W.jsx)(`option`,{value:`__custom__`,children:ne(`Custom…`,`自定义…`)})]}),d?(0,W.jsx)(`input`,{className:i(T,`mt-1 text-xs`),value:gn.some(e=>e.value===l.pronouns)?``:l.pronouns,onChange:e=>S({pronouns:e.target.value}),placeholder:e.personaPronounsPlaceholder,autoComplete:`off`}):null]}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5 text-sm sm:col-span-2`,children:[(0,W.jsx)(`span`,{className:`font-medium text-fg`,children:e.personaTimezone}),(0,W.jsxs)(`div`,{className:`flex flex-wrap items-stretch gap-2`,children:[(0,W.jsxs)(`select`,{className:i(T,`min-w-0 flex-1`),value:w,onChange:e=>ee(e.target.value),children:[mn.map(e=>(0,W.jsx)(`option`,{value:e.value,children:ne(e.labelEn,e.labelZh)},e.value)),(0,W.jsx)(`option`,{value:`__custom__`,children:e.personaTimezoneCustom})]}),(0,W.jsx)(`button`,{type:`button`,className:`shrink-0 rounded-lg border border-edge bg-surface-panel px-3 py-2 text-xs font-medium text-fg-muted hover:bg-surface-hover hover:text-fg`,onClick:te,children:e.personaTimezoneDetect})]}),p?(0,W.jsx)(`input`,{className:i(T,`mt-1 font-mono text-xs`),value:h,onChange:e=>C(e.target.value),placeholder:`e.g. Asia/Shanghai`,autoComplete:`off`}):null]}),(0,W.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm sm:col-span-2`,children:[(0,W.jsx)(`span`,{className:`font-medium text-fg`,children:e.personaNotes}),(0,W.jsx)(`textarea`,{className:i(T,`min-h-16 resize-y text-sm leading-relaxed`),value:l.notes,onChange:e=>S({notes:e.target.value}),placeholder:e.personaNotesPlaceholder,rows:3,spellCheck:!0})]})]}),(0,W.jsxs)(`div`,{className:`mt-3 flex items-start gap-2 rounded-lg bg-accent-soft/30 px-3 py-2.5 text-xs text-fg-muted`,children:[(0,W.jsx)(ot,{className:`mt-0.5 size-3.5 shrink-0 text-accent`,"aria-hidden":!0}),(0,W.jsx)(`span`,{children:e.personaMemoryNote})]})]})]})}function bn(e){let{a:t,selected:n,busy:r,skillsCatalogLoading:a,catalogForPick:o,skillsInherit:s,setSkillsInherit:c,skillsPick:l,setSkillsPick:u,onSaveSkills:d,hideInlineSave:f}=e;function p(e){let t=n.skills.effectiveAllowlist;return t===void 0?!0:t.length===0?!1:t.includes(e)}function m(){let e=n.skills.effectiveAllowlist;return e===void 0?new Set(o.map(e=>e.name||e.directoryId)):new Set(e)}return(0,W.jsxs)(q,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,W.jsx)(J,{className:`shrink-0`,icon:Fe,title:t.skillsTitle,subtitle:t.skillsHint}),(0,W.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-between gap-3`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,W.jsx)(V,{type:`button`,variant:`secondary`,disabled:r,onClick:()=>c(!0),children:t.skillsInherit}),(0,W.jsx)(V,{type:`button`,variant:`secondary`,disabled:r,onClick:()=>{c(!1),u(m())},children:t.skillsCustomize})]}),(0,W.jsx)(et,{to:Ae(`skills`),className:`shrink-0 text-xs font-medium text-accent-fg hover:underline`,children:t.skillsLibraryLink})]}),(0,W.jsxs)(`p`,{className:`mt-2 shrink-0 text-xs text-fg-muted`,children:[t.skillsDefaultsLabel,` `,n.skills.defaults.length?n.skills.defaults.join(`, `):`—`]}),(0,W.jsxs)(`p`,{className:`shrink-0 text-xs text-fg-muted`,children:[t.skillsEffectiveLabel,` `,n.skills.effectiveAllowlist?.length?n.skills.effectiveAllowlist.join(`, `):t.skillsAllFromCatalog]}),a?(0,W.jsx)(`p`,{className:`shrink-0 text-sm text-fg-muted`,children:t.skillsCatalogLoading}):o.length===0?(0,W.jsx)(`p`,{className:`shrink-0 text-sm text-fg-muted`,children:t.skillsEmptyCatalog}):(0,W.jsx)(`div`,{className:i(`mt-3 min-h-0 flex-1 overflow-y-auto overscroll-contain pr-0.5`,s&&`opacity-50`),children:(0,W.jsx)(`ul`,{className:`flex flex-col gap-2.5 text-sm`,role:`list`,children:o.map(e=>{let n=e.name||e.directoryId,a=s?p(n):l.has(n),o=typeof e.description==`string`?e.description.trim():``,c=o||t.skillsNoDescription;return(0,W.jsx)(`li`,{className:`h-16 shrink-0 overflow-hidden rounded-xl border border-edge-subtle bg-surface-panel/60 px-3 dark:border-edge-subtle`,children:(0,W.jsxs)(`label`,{className:`flex h-full cursor-pointer items-center gap-3 text-sm`,children:[(0,W.jsx)(`input`,{type:`checkbox`,className:`shrink-0 rounded border-edge`,checked:a,disabled:s||r,onChange:()=>{u(e=>{let t=new Set(e);return a?t.delete(n):t.add(n),t})}}),(0,W.jsxs)(`div`,{className:`min-w-0 flex-1 overflow-hidden`,children:[(0,W.jsx)(`div`,{className:`truncate font-mono text-xs font-medium text-fg`,title:n,children:n}),(0,W.jsx)(`p`,{className:i(`mt-0.5 truncate text-xs leading-tight text-fg-muted`,!o&&`italic text-fg-subtle`),title:c,children:c})]})]})},n)})})}),f?null:(0,W.jsx)(`div`,{className:`mt-4 shrink-0`,children:(0,W.jsx)(V,{type:`button`,disabled:r,onClick:()=>void d(),children:t.skillsSave})})]})}function xn(e){let{a:t,data:n,selected:r,busy:a,toolEntryDisable:o,setToolEntryDisable:s,onSaveTools:c,onClearToolsEntry:l,hideInlineSave:u}=e;return(0,W.jsxs)(q,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,W.jsx)(J,{className:`shrink-0`,icon:ze,title:t.toolsTitle,subtitle:t.toolsHint}),(0,W.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain`,children:(0,W.jsx)(`ul`,{className:`flex flex-col gap-2.5 pr-1`,role:`list`,children:(n.builtinToolIds.length?n.builtinToolIds:[]).map(e=>{let n=r.tools.defaultsDisable.includes(e),c=n?!1:!o.has(e),l=e in t.toolDescriptions?t.toolDescriptions[e]:``;return(0,W.jsx)(`li`,{className:i(`rounded-xl border border-edge-subtle bg-surface-panel/60 px-3 py-2.5 dark:border-edge-subtle`,n&&`opacity-60`),children:(0,W.jsxs)(`label`,{className:i(`flex cursor-pointer gap-3 text-sm`,n&&`cursor-not-allowed`),children:[(0,W.jsx)(`input`,{type:`checkbox`,className:`mt-1 shrink-0 rounded border-edge`,checked:c,disabled:n||a,onChange:()=>{n||s(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}}),(0,W.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5`,children:[(0,W.jsx)(`span`,{className:`font-mono text-xs font-medium text-fg`,children:e}),n?(0,W.jsxs)(`span`,{className:`text-xs text-fg-muted`,children:[`(`,t.toolsLockedByDefaults,`)`]}):null]}),l?(0,W.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-fg-muted`,children:l}):null]})]})},e)})})}),(0,W.jsxs)(`div`,{className:`mt-4 flex shrink-0 flex-wrap gap-2`,children:[u?null:(0,W.jsx)(V,{type:`button`,disabled:a,onClick:()=>void c(),children:t.toolsSave}),(0,W.jsx)(V,{type:`button`,variant:`secondary`,disabled:a,onClick:()=>void l(),children:t.toolsClearEntry})]})]})}function Sn(){let e=Pe(e=>e.language),t=u(e),n=t.agentsSettings,[a,s]=(0,U.useState)(!1),[c,l]=(0,U.useState)(null),[p,g]=(0,U.useState)(!1),[v,y]=(0,U.useState)(``),b=t.cron,x=t.chat,S=!!tt(e=>e.token),[te,ne]=Ne(),T=Ke(),{agentId:E}=Ve(),re=Be(e=>e.setPageHeader),ie=Be(e=>e.clearPageHeader),{data:D,error:oe,isLoading:se,mutate:O}=r(S?`settings-gateway-agents`:null,f,{revalidateOnFocus:!1}),{data:le}=we(S),ue=(0,U.useMemo)(()=>Re(le?.payload?.config??{}),[le]),k=D??null,A=!!(S&&se),[fe,j]=(0,U.useState)(null),pe=oe instanceof Error?oe.message:oe?n.loadError:null,ge=fe??pe,[M,_e]=(0,U.useState)(null),[ve,ye]=(0,U.useState)(!1),[N,be]=(0,U.useState)(`overview`),[xe,Ce]=(0,U.useState)(``),[P,Te]=(0,U.useState)(``),[F,Ee]=(0,U.useState)(``),[De,I]=(0,U.useState)(``),[L,ke]=(0,U.useState)(``),[Ae,je]=(0,U.useState)(null),[Me,Fe]=(0,U.useState)(!1),Ie=(0,U.useRef)(``),[R,z]=(0,U.useState)(!1),[ze,B]=(0,U.useState)(!1),[He,Ue]=(0,U.useState)(``),[We,Ge]=(0,U.useState)(``),[qe,Je]=(0,U.useState)(``),[Ye,Ze]=(0,U.useState)(``),[Qe,$e]=(0,U.useState)(``),[et,nt]=(0,U.useState)(null),[it,ot]=(0,U.useState)(!1),[H,lt]=(0,U.useState)(null),[dt,pt]=(0,U.useState)(``),[mt,vt]=(0,U.useState)(!1),[yt,bt]=(0,U.useState)(`edit`),[xt,St]=(0,U.useState)(!1),[Ct,wt]=(0,U.useState)(0),Tt=(0,U.useRef)(dt);Tt.current=dt;let Ot=(0,U.useRef)(M);Ot.current=M;let kt=(0,U.useRef)(H);kt.current=H;let At=(0,U.useRef)(null),Mt=(0,U.useRef)(null),[Nt,Pt]=(0,U.useState)(!1),[Ft,It]=(0,U.useState)(!1),[Rt,zt]=(0,U.useState)(!1),G=(0,U.useRef)(``),Ut=(0,U.useRef)(``),K=ee(async()=>{let e=Ot.current,t=kt.current;if(!e||!t||`${e}:${t}`!==G.current)return;let r=Tt.current;if(r!==Ut.current){vt(!0),j(null);try{await Le(e,t,r),Ut.current=r,nt(n=>!n||n.agentId!==e?n:{...n,files:n.files.map(e=>e.name===t?{...e,missing:!1}:e)})}catch(e){j(e instanceof Error?e.message:n.saveError)}finally{vt(!1)}}},800),Jt=(0,U.useRef)(K.flush);Jt.current=K.flush,(0,U.useEffect)(()=>()=>{Jt.current()},[]);let[Yt,q]=(0,U.useState)(()=>new Set),[Xt,J]=(0,U.useState)(()=>new Set),[Zt,tn]=(0,U.useState)(!0),[nn,rn]=(0,U.useState)([]),[an,on]=(0,U.useState)(``),[sn,cn]=(0,U.useState)([]),[ln,un]=(0,U.useState)(!1),[dn,fn]=(0,U.useState)([]),[pn,mn]=(0,U.useState)(!1),[hn,gn]=(0,U.useState)(null),[_n,Sn]=(0,U.useState)(``),[Y,Cn]=(0,U.useState)([]),[wn,Tn]=(0,U.useState)(!1),[En,Dn]=(0,U.useState)([]),[On,kn]=(0,U.useState)(!1);(0,U.useEffect)(()=>{if(k){if(E&&k.agents.some(e=>e.id===E)){_e(E);return}_e(e=>e&&k.agents.some(t=>t.id===e)?e:k.defaultId)}},[k,E]),(0,U.useEffect)(()=>{if(!k||A)return;let e=k.agents.length<=1&&k.agents.every(e=>e.id===k.defaultId),t=localStorage.getItem(Kt)===`true`;ye(e&&!t)},[k,A]);let An=(0,U.useCallback)(()=>{ye(!1),O()},[O]),jn=(0,U.useCallback)(()=>{ye(!1)},[]);(0,U.useEffect)(()=>{!k||!E||k.agents.some(e=>e.id===E)||T(rt,{replace:!0})},[k,E,T]),(0,U.useEffect)(()=>{E&&be(`overview`)},[E]),(0,U.useEffect)(()=>{te.get(`panel`)===`defaults`&&T(`/settings/agent-defaults`,{replace:!0,state:{[Se]:rt}})},[te,T]),(0,U.useEffect)(()=>{if(te.get(`focus`)!==`avatar`||!E||(be(`overview`),A||!k?.agents.some(e=>e.id===E)))return;let e=window.setTimeout(()=>{document.getElementById(`agent-avatar-settings`)?.scrollIntoView({behavior:`smooth`,block:`center`}),ne(e=>{let t=new URLSearchParams(e);return t.delete(`focus`),t},{replace:!0})},220);return()=>window.clearTimeout(e)},[te,E,A,k,ne]);let X=(0,U.useMemo)(()=>k?.agents.find(e=>e.id===M)??null,[k,M]),Mn=(0,U.useMemo)(()=>X?nn.filter(e=>e.agentId.toLowerCase()===X.id.toLowerCase()):[],[nn,X?.id]),Nn=(0,U.useMemo)(()=>!k||!X?[]:Y.filter(e=>Ht(e,X.id,k.defaultId)),[Y,k,X?.id]),Pn=(0,U.useMemo)(()=>En.filter(e=>e.enabled!==!1),[En]);(0,U.useEffect)(()=>{if(!X){Ge(``),Je(``),Ze(``),$e(``);return}Ge(X.workspace),Je(X.model?.primary??``),Ze(ct(X,u(e).agentsSettings)),$e(X.description?.trim()??``)},[X?.id,e]),(0,U.useEffect)(()=>{if(N!==`files`||!M||!S)return;let e=!1;return ot(!0),h(M).then(t=>{e||nt(t)}).catch(()=>{e||nt(null)}).finally(()=>{e||ot(!1)}),()=>{e=!0}},[N,M,S,k?.agents.length]),(0,U.useEffect)(()=>{!X||N!==`tools`||q(new Set(X.tools.entryDisable))},[N,X]),(0,U.useEffect)(()=>{if(!X||N!==`skills`)return;let e=X.skills.entry===void 0;if(tn(e),e){let e=X.skills.effectiveAllowlist;J(new Set(e??[]))}else J(new Set(X.skills.entry??[]))},[N,X]),(0,U.useEffect)(()=>{N!==`channels`||!S||rn(ue)},[N,S,ue]),(0,U.useEffect)(()=>{if(N!==`channels`||!S)return;let e=!1;return un(!0),ht().then(t=>{e||cn(t)}).catch(()=>{e||cn([])}).finally(()=>{e||un(!1)}),()=>{e=!0}},[N,S]),(0,U.useEffect)(()=>{ln||N!==`channels`||sn.length===0||on(e=>e&&sn.some(t=>t.name===e)?e:sn[0].name)},[ln,N,sn]),(0,U.useEffect)(()=>{if(N!==`channels`||!S)return;let e=an.trim();if(!e){fn([]);return}let t=!1;return gn(null),mn(!0),gt(e).then(e=>{t||fn(e)}).catch(()=>{t||fn([])}).finally(()=>{t||mn(!1)}),()=>{t=!0}},[N,S,an]);let Fn=(0,U.useCallback)(()=>{let e=an.trim();e&&(mn(!0),gt(e).then(e=>{fn(e),gn(t=>t!=null&&t<e.length?t:null)}).catch(()=>{fn([]),gn(null)}).finally(()=>{mn(!1)}))},[an]),In=!ln&&sn.length===0,Ln=N===`channels`&&S&&le===void 0;(0,U.useEffect)(()=>{if(N!==`cron`||!S)return;let e=!1;return Tn(!0),_t().then(t=>{e||Cn(t)}).catch(()=>{e||Cn([])}).finally(()=>{e||Tn(!1)}),()=>{e=!0}},[N,S]),(0,U.useEffect)(()=>{if(N!==`skills`||!S)return;let e=!1;return kn(!0),ae().then(t=>{e||Dn(t)}).catch(()=>{e||Dn([])}).finally(()=>{e||kn(!1)}),()=>{e=!0}},[N,S]),(0,U.useEffect)(()=>{if(!H||!M||!S)return;let e=!1;return K.flush(),St(!0),me(M,H).then(t=>{e||(G.current=`${M}:${H}`,Ut.current=t,pt(t),wt(e=>e+1))}).catch(()=>{e||(G.current=`${M}:${H}`,Ut.current=``,pt(``),wt(e=>e+1))}).finally(()=>{e||St(!1)}),()=>{e=!0}},[H,M,S,K]),(0,U.useEffect)(()=>{!H||!M||xt||K()},[dt,H,M,xt,K]),(0,U.useEffect)(()=>{if(N===`files`)return()=>{K.flush()}},[N,K]),(0,U.useEffect)(()=>{bt(`edit`)},[H,M]);let Rn=(0,U.useCallback)(()=>{let e=Dt(P.trim()||xe);I(t=>t===``||t===Ie.current?(Ie.current=e,e):t)},[P,xe]),zn=(0,U.useCallback)(()=>{Ie.current=``,Ce(``),Te(``),Ee(``),I(``),ke(``),je(null),Fe(!0)},[]),Bn=(0,U.useCallback)(e=>new Promise(t=>window.setTimeout(t,e)),[]),Vn=(0,U.useCallback)(async()=>{if(ze||R)return;B(!0),j(null);let e=[`light`,`deep`,`rem`];try{(async()=>{for(let t of e)try{await jt(t)}catch{}})();for(let t=0;t<e.length;t++){let n=e[t];window.dispatchEvent(new CustomEvent(`dreaming-phase-start`,{detail:{phase:n,source:`ui`}})),await Bn(n===`light`?7e3:n===`deep`?9e3:8e3),t===e.length-1&&(window.__xopcDreamingIgnoreSseUntil=Date.now()+6e4,window.dispatchEvent(new CustomEvent(`dreaming-phase-end`,{detail:{phase:n,source:`ui`}})))}}catch(e){j(e instanceof Error?e.message:n.saveError)}finally{B(!1)}},[n.saveError,R,ze,Bn]),Hn=(0,U.useMemo)(()=>(0,W.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-center justify-end gap-2`,children:[(0,W.jsxs)(V,{type:`button`,variant:`secondary`,className:`shrink-0 gap-2`,disabled:R||ze,onClick:()=>void Vn(),"aria-label":e===`zh`?`让智能体进入睡眠流程`:`Trigger agent sleep sequence`,title:e===`zh`?`由浅入深:Light → Deep → REM`:`Light → Deep → REM`,children:[(0,W.jsx)(Xe,{className:`size-4 shrink-0`,strokeWidth:1.75,"aria-hidden":!0}),e===`zh`?ze?`睡眠中…`:`睡眠`:ze?`Sleeping…`:`Sleep`]}),(0,W.jsxs)(`label`,{className:`relative flex min-h-9 min-w-0 max-w-sm cursor-text items-center rounded-pill border border-edge bg-surface-base py-1.5 pl-9 pr-3 shadow-surface dark:bg-surface-hover/40 sm:max-w-md`,children:[(0,W.jsx)(C,{className:`pointer-events-none absolute left-3 top-1/2 size-4 -translate-y-1/2 text-fg-disabled`,strokeWidth:1.75,"aria-hidden":!0}),(0,W.jsx)(`input`,{type:`search`,role:`searchbox`,enterKeyHint:`search`,value:He,onChange:e=>Ue(e.target.value),placeholder:n.listSearchPlaceholder,autoComplete:`off`,spellCheck:!1,"aria-label":n.listSearchPlaceholder,className:`min-w-0 flex-1 appearance-none border-0 bg-transparent py-0.5 text-sm leading-normal text-fg caret-current placeholder:text-fg-disabled focus:border-0 focus:shadow-none focus:outline-none focus:ring-0 focus-visible:outline-none`})]}),(0,W.jsxs)(V,{type:`button`,variant:`primary`,className:`shrink-0 gap-2`,"aria-label":n.addAgentAria,disabled:R,onClick:()=>zn(),children:[(0,W.jsx)(Oe,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),n.addAgent]})]}),[n.addAgent,n.addAgentAria,n.listSearchPlaceholder,R,He,zn,ze,Vn,e]);(0,U.useLayoutEffect)(()=>S?(re({startExtra:null,main:null,end:Hn}),()=>ie()):(ie(),()=>ie()),[Hn,ie,S,re]);async function Un(e){e.preventDefault();let t=xe.trim();if(!t)return;let r=Et(P,t);if(r.ok===!1){je(r.error);return}let i=De.trim()||Dt(P.trim()||t);if(i){z(!0),je(null);try{let e=F.trim(),{createdAgentId:n,...r}=await de({name:t,workspace:i,...P.trim()?{id:P.trim()}:{},...L.trim()?{model:L.trim()}:{},...e?{description:e}:{}});O(r,{revalidate:!1}),Ce(``),Te(``),Ee(``),I(``),ke(``),je(null),Fe(!1),_e(n),T(ut(n))}catch(e){je(e instanceof Error?e.message:n.saveError)}finally{z(!1)}}}async function Z(){if(X){z(!0),j(null);try{let e=Qe.trim();O(await w(X.id,{name:Ye.trim()||void 0,description:e.length>0?e:null,workspace:We.trim()||void 0,model:qe.trim()||null}),{revalidate:!1})}catch(e){j(e instanceof Error?e.message:n.saveError)}finally{z(!1)}}}async function Wn(e){z(!0),j(null);try{O(await w(e.id,{setDefault:!0}),{revalidate:!1}),_e(e.id)}catch(e){j(e instanceof Error?e.message:n.saveError)}finally{z(!1)}}async function Q(e,t){z(!0),j(null);try{let n=await at(e.id,t);O(n,{revalidate:!1}),_e(n.defaultId),be(`overview`),E===e.id&&T(rt,{replace:!0}),s(!1),l(null),y(``)}catch(e){j(e instanceof Error?e.message:n.saveError)}finally{z(!1)}}function Gn(e,t){e.id!==`main`&&(l(e),g(t),y(``),s(!0))}async function Kn(){if(X){z(!0),j(null);try{let e=[...Yt].sort((e,t)=>e.localeCompare(t));O(await w(X.id,{toolsDisable:e}),{revalidate:!1})}catch(e){j(e instanceof Error?e.message:n.saveError)}finally{z(!1)}}}async function qn(){if(X){z(!0),j(null);try{O(await w(X.id,{toolsDisable:null}),{revalidate:!1}),q(new Set)}catch(e){j(e instanceof Error?e.message:n.saveError)}finally{z(!1)}}}async function Jn(){if(X){z(!0),j(null);try{O(await w(X.id,{skills:Zt?null:[...Xt].sort((e,t)=>e.localeCompare(t))}),{revalidate:!1})}catch(e){j(e instanceof Error?e.message:n.saveError)}finally{z(!1)}}}async function Yn(e){z(!0),j(null);try{let t=nn.filter(t=>t!==e);await o(t),rn(t)}catch(e){j(e instanceof Error?e.message:n.saveError)}finally{z(!1)}}async function Xn(e){if(e.preventDefault(),!X||!an.trim())return;let t=Wt(an,_n,hn,dn),r=[...nn,{agentId:X.id,priority:100,enabled:!0,match:t}];z(!0),j(null);try{await o(r),rn(r),gn(null),Sn(``)}catch(e){j(e instanceof Error?e.message:n.saveError)}finally{z(!1)}}async function Zn(e,t){z(!0),j(null);try{await ft(e.id,{agentId:t===``?null:t}),Cn(await _t())}catch(e){j(e instanceof Error?e.message:n.saveError)}finally{z(!1)}}let $=N===`channels`||N===`cron`,Qn=(()=>{if(!X||N!==`overview`)return!1;let e=ct(X,n),t=X.description?.trim()??``,r=X.workspace,i=X.model?.primary??``;return Ye.trim()!==e||Qe.trim()!==t||We.trim()!==r||qe.trim()!==i})(),$n=(()=>{if($)return!1;switch(N){case`overview`:return Qn||Nt;case`profile`:return Ft;default:return!0}})(),er=$||!$n;function tr(){zt(!0),setTimeout(()=>zt(!1),2e3)}async function nr(){switch(N){case`overview`:await Promise.all([Z(),At.current?.()??Promise.resolve()]),tr();break;case`profile`:await Mt.current?.(),tr();break;case`tools`:await Kn(),tr();break;case`skills`:await Jn(),tr();break;case`files`:K.flush(),tr();break;default:break}}function rr(e){e||T(rt)}let ir=X?Ye.trim()||ct(X,n):E??``,ar=X?.id??E??``;if(!S)return(0,W.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,W.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:n.title}),(0,W.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]});if(ve&&k)return(0,W.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col px-4 py-8`,children:(0,W.jsx)(qt,{existingAgentIds:new Set(k.agents.map(e=>e.id)),onComplete:An,onSkip:jn})});let or=X?N===`overview`?(0,W.jsx)(vn,{a:n,chat:x,selected:X,busy:R,editName:Ye,setEditName:Ze,editDescription:Qe,setEditDescription:$e,editWorkspace:We,setEditWorkspace:Ge,editModel:qe,setEditModel:Je,onSetDefault:()=>void Wn(X),onSaveAgentEdits:()=>void Z(),onDelete:e=>void Gn(X,e),hideInlineSave:!0,saveBootstrapRef:At,onBootstrapDirtyChange:Pt}):N===`profile`?(0,W.jsx)(yn,{a:n,agentId:X.id,saveRef:Mt,onDirtyChange:It}):N===`files`?(0,W.jsx)(en,{a:n,filesLoading:it,files:et,activeFile:H,setActiveFile:lt,bootstrapViewMode:yt,setBootstrapViewMode:bt,fileDraft:dt,setFileDraft:pt,fileSaving:mt,bootstrapFileLoading:xt,bootstrapEditorNonce:Ct}):N===`tools`?(0,W.jsx)(xn,{a:n,data:k,selected:X,busy:R,toolEntryDisable:Yt,setToolEntryDisable:q,onSaveTools:()=>void Kn(),onClearToolsEntry:()=>void qn(),hideInlineSave:!0}):N===`skills`?(0,W.jsx)(bn,{a:n,selected:X,busy:R,skillsCatalogLoading:On,catalogForPick:Pn,skillsInherit:Zt,setSkillsInherit:tn,skillsPick:Xt,setSkillsPick:J,onSaveSkills:()=>void Jn(),hideInlineSave:!0}):N===`channels`?(0,W.jsx)(Qt,{a:n,busy:R,bindingsLoading:Ln,agentBindings:Mn,channelStatuses:sn,channelsStatusLoading:ln,useManualChannel:In,newBindChannel:an,setNewBindChannel:on,bindSessionChats:dn,sessionsLoading:pn,newBindSessionIdx:hn,setNewBindSessionIdx:gn,newBindCustomPeer:_n,setNewBindCustomPeer:Sn,onRefreshSessions:Fn,lastActiveLabels:b.lastActiveLabels,selectRecipient:b.selectRecipient,onRemoveBinding:e=>void Yn(e),onAddBinding:Xn}):N===`cron`&&k?(0,W.jsx)($t,{a:n,data:k,selected:X,busy:R,cronLoading:wn,agentCronJobs:Nn,onSetCronJobAgent:(e,t)=>void Zn(e,t)}):(0,W.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.selectAgentHint}):(0,W.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.selectAgentHint});return(0,W.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[(0,W.jsx)(Vt,{a:n}),ge?(0,W.jsx)(`div`,{className:`rounded-lg border border-red-200 bg-red-50 px-3 py-2 text-sm text-red-800 dark:border-red-900/50 dark:bg-red-950/40 dark:text-red-200`,children:ge}):null,A?(0,W.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.loading}):k?(0,W.jsx)(Bt,{a:n,agents:k.agents,searchQuery:He,onOpenAgent:e=>T(ut(e)),onChatWithAgent:e=>T(`/chat/new`,{state:{agentId:e.trim().toLowerCase()}}),onNewAgent:zn,busy:R}):null,E&&S?(0,W.jsx)(Lt,{open:!!E,onOpenChange:rr,a:n,title:ir,subtitle:ar,panel:N,onPanelChange:be,onFooterSave:()=>void nr(),footerSaveDisabled:er,footerSavedFlash:Rt,busy:R,children:A||!k?(0,W.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.loading}):or}):null,(0,W.jsx)(Gt,{open:Me,onOpenChange:e=>{Fe(e),e||(Ie.current=``,Ce(``),Te(``),Ee(``),I(``),ke(``),je(null))},a:n,chat:x,busy:R,modalError:Ae,createDisplayName:xe,setCreateDisplayName:Ce,createAgentId:P,setCreateAgentId:Te,createDescription:F,setCreateDescription:Ee,createWorkspace:De,setCreateWorkspace:I,createModel:L,setCreateModel:ke,onCreate:Un,onSuggestWorkspace:()=>Rn()}),(0,W.jsx)(m,{open:a,onOpenChange:e=>{s(e),e||(l(null),y(``))},children:(0,W.jsxs)(_,{children:[(0,W.jsx)(he,{className:`fixed inset-0 z-[80] bg-scrim backdrop-blur-[2px]`}),(0,W.jsxs)(d,{className:i(`fixed left-1/2 top-1/2 z-[81] w-[min(100%-2rem,28rem)] -translate-x-1/2 -translate-y-1/2 rounded-xl border border-edge bg-surface-panel p-4 shadow-popover`,`dark:border-edge`),onOpenAutoFocus:e=>e.preventDefault(),children:[(0,W.jsx)(ce,{className:`text-base font-semibold text-fg`,children:p?n.purgeDisk:n.removeFromConfig}),(0,W.jsx)(st,{className:`mt-2 whitespace-pre-wrap text-sm leading-relaxed text-fg-muted`,children:p?n.confirmDeletePurge:n.confirmDelete}),p&&c?(0,W.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[(0,W.jsx)(`label`,{className:`mb-2 block text-sm font-medium text-fg`,htmlFor:`agent-delete-confirm`,children:n.purgeConfirmLabel}),(0,W.jsx)(`input`,{id:`agent-delete-confirm`,type:`text`,autoComplete:`off`,spellCheck:!1,className:i(`w-full rounded-md border border-edge bg-surface-panel px-3 py-1.5 font-mono text-xs text-fg`,`placeholder:text-fg-subtle`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-surface-panel`,`dark:border-edge`),placeholder:n.purgeConfirmPlaceholder.replace(`{{agentId}}`,c.id),value:v,onChange:e=>y(e.target.value)}),(0,W.jsx)(`p`,{className:`pt-0.5 text-xs text-fg-muted`,children:n.purgeConfirmHint.replace(`{{agentId}}`,c.id)})]}):null,(0,W.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center justify-end gap-2 border-t border-edge-subtle/60 pt-3`,children:[(0,W.jsx)(V,{type:`button`,variant:`ghost`,disabled:R,onClick:()=>s(!1),children:n.createModalCancel}),(0,W.jsx)(V,{type:`button`,variant:`secondary`,className:p?`border-red-200 text-red-700 hover:bg-red-50 dark:border-red-900/60 dark:text-red-300 dark:hover:bg-red-950/40`:void 0,disabled:R||!c||p&&v.trim().toLowerCase()!==c.id.toLowerCase(),onClick:()=>{c&&Q(c,p)},children:p?n.purgeDisk:n.removeFromConfig})]})]})]})})]})}var Y={enabled:!0,mode:`default`,reserveTokens:8e3,triggerThreshold:.8,minMessagesBeforeCompact:10,keepRecentMessages:5,evictionWindow:.2,retentionWindow:6},Cn={enabled:!0,maxToolResultChars:1e4,headKeepRatio:.3,tailKeepRatio:.3},wn={enabled:!0,useEnhancedSystem:!0,userProfileEnabled:!0,provider:``,injectionFrequency:``,memoryCharLimit:void 0,userCharLimit:void 0,contextCadence:void 0,dialecticCadence:void 0},Tn={summaryModel:``},En={enabled:!1,memoryNudgeInterval:10,skillNudgeInterval:10,maxToolRounds:8,maxHistoryMessages:80,maxDurationMs:12e4},Dn={model:``,maxLength:void 0};function On(e){if(e==null)return``;if(typeof e==`string`)return e;if(typeof e==`object`&&e&&`primary`in e){let t=e.primary;return typeof t==`string`?t:``}return``}function kn(e){if(typeof e!=`object`||!e||!(`fallbacks`in e))return[];let t=e.fallbacks;return Array.isArray(t)?t.filter(e=>typeof e==`string`&&e.trim().length>0):[]}function An(e){return e===!0||e===`true`||e===1}function jn(e){let t=e.browser;if(!t||typeof t!=`object`||Array.isArray(t))return{browserEnabled:!1,browserHeadless:!0};let n=t,r=An(n.enabled),i=n.headless;return{browserEnabled:r,browserHeadless:!(i===!1||i===`false`||i===0)}}function X(e){if(!e||typeof e!=`object`||Array.isArray(e))return{...Y};let t=e;return{enabled:typeof t.enabled==`boolean`?t.enabled:Y.enabled,mode:t.mode===`safeguard`?`safeguard`:`default`,reserveTokens:typeof t.reserveTokens==`number`&&Number.isFinite(t.reserveTokens)?Math.floor(t.reserveTokens):Y.reserveTokens,triggerThreshold:typeof t.triggerThreshold==`number`&&Number.isFinite(t.triggerThreshold)?t.triggerThreshold:Y.triggerThreshold,minMessagesBeforeCompact:typeof t.minMessagesBeforeCompact==`number`&&Number.isFinite(t.minMessagesBeforeCompact)?Math.floor(t.minMessagesBeforeCompact):Y.minMessagesBeforeCompact,keepRecentMessages:typeof t.keepRecentMessages==`number`&&Number.isFinite(t.keepRecentMessages)?Math.floor(t.keepRecentMessages):Y.keepRecentMessages,evictionWindow:typeof t.evictionWindow==`number`&&Number.isFinite(t.evictionWindow)?t.evictionWindow:Y.evictionWindow,retentionWindow:typeof t.retentionWindow==`number`&&Number.isFinite(t.retentionWindow)?Math.floor(t.retentionWindow):Y.retentionWindow}}function Mn(e){if(!e||typeof e!=`object`||Array.isArray(e))return{...Cn};let t=e;return{enabled:typeof t.enabled==`boolean`?t.enabled:Cn.enabled,maxToolResultChars:typeof t.maxToolResultChars==`number`&&Number.isFinite(t.maxToolResultChars)?Math.floor(t.maxToolResultChars):Cn.maxToolResultChars,headKeepRatio:typeof t.headKeepRatio==`number`&&Number.isFinite(t.headKeepRatio)?t.headKeepRatio:Cn.headKeepRatio,tailKeepRatio:typeof t.tailKeepRatio==`number`&&Number.isFinite(t.tailKeepRatio)?t.tailKeepRatio:Cn.tailKeepRatio}}function Nn(e){if(!e||typeof e!=`object`||Array.isArray(e))return{...wn};let t=e,n=t.provider,r=n===`none`||n===`stub`?n:``,i=t.injectionFrequency,a=i===`every-turn`||i===`first-turn`?i:``;return{enabled:typeof t.enabled==`boolean`?t.enabled:wn.enabled,useEnhancedSystem:typeof t.useEnhancedSystem==`boolean`?t.useEnhancedSystem:wn.useEnhancedSystem,userProfileEnabled:typeof t.userProfileEnabled==`boolean`?t.userProfileEnabled:wn.userProfileEnabled,provider:r,injectionFrequency:a,memoryCharLimit:typeof t.memoryCharLimit==`number`&&t.memoryCharLimit>0?Math.floor(t.memoryCharLimit):void 0,userCharLimit:typeof t.userCharLimit==`number`&&t.userCharLimit>0?Math.floor(t.userCharLimit):void 0,contextCadence:typeof t.contextCadence==`number`&&t.contextCadence>=1?Math.floor(t.contextCadence):void 0,dialecticCadence:typeof t.dialecticCadence==`number`&&t.dialecticCadence>=1?Math.floor(t.dialecticCadence):void 0}}function Pn(e){if(!e||typeof e!=`object`||Array.isArray(e))return{...Tn};let t=e;return{summaryModel:typeof t.summaryModel==`string`?t.summaryModel:``}}function Fn(e){if(!e||typeof e!=`object`||Array.isArray(e))return{...En};let t=e;return{enabled:typeof t.enabled==`boolean`?t.enabled:En.enabled,memoryNudgeInterval:typeof t.memoryNudgeInterval==`number`&&t.memoryNudgeInterval>=0?Math.floor(t.memoryNudgeInterval):En.memoryNudgeInterval,skillNudgeInterval:typeof t.skillNudgeInterval==`number`&&t.skillNudgeInterval>=0?Math.floor(t.skillNudgeInterval):En.skillNudgeInterval,maxToolRounds:typeof t.maxToolRounds==`number`&&t.maxToolRounds>=1&&t.maxToolRounds<=32?Math.floor(t.maxToolRounds):En.maxToolRounds,maxHistoryMessages:typeof t.maxHistoryMessages==`number`&&t.maxHistoryMessages>=10&&t.maxHistoryMessages<=200?Math.floor(t.maxHistoryMessages):En.maxHistoryMessages,maxDurationMs:typeof t.maxDurationMs==`number`&&t.maxDurationMs>=3e4&&t.maxDurationMs<=6e5?Math.floor(t.maxDurationMs):En.maxDurationMs}}function In(e){if(!e||typeof e!=`object`||Array.isArray(e))return{...Dn};let t=e;return{model:typeof t.model==`string`?t.model:``,maxLength:typeof t.maxLength==`number`&&t.maxLength>0?t.maxLength:void 0}}function Ln(e,t){if(!e||typeof e!=`object`||Array.isArray(e))return{enabled:t};let n=e;return{enabled:typeof n.enabled==`boolean`?n.enabled:t}}function Rn(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function zn(e){if(e==null)return``;if(typeof e==`object`&&!Array.isArray(e))try{return JSON.stringify(e,null,2)}catch{return``}return``}function Bn(e){let t=e&&typeof e==`object`&&!Array.isArray(e)&&`agents`in e?e.agents:void 0,n=t&&typeof t==`object`&&!Array.isArray(t)&&`defaults`in t?t.defaults:void 0,r=n&&typeof n==`object`&&!Array.isArray(n)?n:{},i=r.modelFallbacks,a=Array.isArray(i)&&i.every(e=>typeof e==`string`)?i:kn(r.model),o=r.imageModelFallbacks,s=Array.isArray(o)&&o.every(e=>typeof e==`string`)?o:kn(r.imageModel),c=r.imageGenerationModelFallbacks,l=Array.isArray(c)&&c.every(e=>typeof e==`string`)?c:kn(r.imageGenerationModel),{browserEnabled:u,browserHeadless:d}=jn(r),f=typeof r.maxTaskDurationMs==`number`&&Number.isFinite(r.maxTaskDurationMs)?r.maxTaskDurationMs:void 0,p=f===void 0?void 0:Math.round(f/6e4);return{model:On(r.model),modelFallbacks:a,imageModel:On(r.imageModel),imageModelFallbacks:s,imageGenerationModel:On(r.imageGenerationModel),imageGenerationModelFallbacks:l,mediaMaxMb:typeof r.mediaMaxMb==`number`&&!Number.isNaN(r.mediaMaxMb)?r.mediaMaxMb:void 0,maxTokens:typeof r.maxTokens==`number`?r.maxTokens:8192,temperature:typeof r.temperature==`number`?r.temperature:.7,maxToolIterations:typeof r.maxToolIterations==`number`?r.maxToolIterations:20,maxTaskDurationMinutes:p,maxRequestsPerTurn:typeof r.maxRequestsPerTurn==`number`?r.maxRequestsPerTurn:50,maxToolFailuresPerTurn:typeof r.maxToolFailuresPerTurn==`number`?r.maxToolFailuresPerTurn:3,workspace:typeof r.workspace==`string`?r.workspace:`~/.xopc/workspace`,browserEnabled:u,browserHeadless:d,thinkingDefault:typeof r.thinkingDefault==`string`?r.thinkingDefault:`medium`,reasoningDefault:typeof r.reasoningDefault==`string`?r.reasoningDefault:`stream`,verboseDefault:typeof r.verboseDefault==`string`?r.verboseDefault:`full`,compaction:X(r.compaction),pruning:Mn(r.pruning),memory:Nn(r.memory),sessionSearch:Pn(r.sessionSearch),backgroundReview:Fn(r.backgroundReview),webExtract:In(r.webExtract),delegate:Ln(r.delegate,!1),executeCode:Ln(r.executeCode,!1),systemPromptOverride:typeof r.systemPromptOverride==`string`?r.systemPromptOverride:``,skillsAllowlist:Rn(r.skills),toolsDisable:(()=>{let e=r.tools;if(!e||typeof e!=`object`||Array.isArray(e))return[];let t=e.disable;return Rn(t)})(),paramsJson:zn(r.params)}}function Vn(e){let t={enabled:e.enabled,useEnhancedSystem:e.useEnhancedSystem,userProfileEnabled:e.userProfileEnabled};return e.provider===`none`||e.provider===`stub`?t.provider=e.provider:t.provider=null,e.injectionFrequency===`every-turn`||e.injectionFrequency===`first-turn`?t.injectionFrequency=e.injectionFrequency:t.injectionFrequency=null,t.memoryCharLimit=e.memoryCharLimit??null,t.userCharLimit=e.userCharLimit??null,t.contextCadence=e.contextCadence??null,t.dialecticCadence=e.dialecticCadence??null,t}function Hn(e){let t=e.trim();if(!t)return null;let n=JSON.parse(t);if(n===null)return null;if(typeof n!=`object`||Array.isArray(n))throw Error(`params must be a JSON object`);return n}async function Un(e){let t=e.modelFallbacks.map(e=>e.trim()).filter(Boolean),n=t.length>0?{primary:e.model,fallbacks:t}:e.model,r=e.imageModelFallbacks.map(e=>e.trim()).filter(Boolean),i=r.length>0&&e.imageModel.trim()?{primary:e.imageModel.trim(),fallbacks:r}:e.imageModel||``,a=e.imageGenerationModelFallbacks.map(e=>e.trim()).filter(Boolean),o=a.length>0&&e.imageGenerationModel.trim()?{primary:e.imageGenerationModel.trim(),fallbacks:a}:e.imageGenerationModel||``,s=e.maxTaskDurationMinutes===void 0||e.maxTaskDurationMinutes===null?null:(()=>{let t=Math.floor(e.maxTaskDurationMinutes)*6e4;return t<6e4||t>144e5?null:t})(),c=e.skillsAllowlist.map(e=>e.trim()).filter(Boolean),l=e.toolsDisable.map(e=>e.trim()).filter(Boolean),u=Hn(e.paramsJson),d=u===null||Object.keys(u).length===0?null:u,f={model:n,imageModel:i,imageGenerationModel:o,mediaMaxMb:e.mediaMaxMb??null,maxTokens:e.maxTokens,temperature:e.temperature,maxToolIterations:e.maxToolIterations,maxTaskDurationMs:s,maxRequestsPerTurn:e.maxRequestsPerTurn,maxToolFailuresPerTurn:e.maxToolFailuresPerTurn,workspace:e.workspace,browser:{enabled:e.browserEnabled,headless:e.browserHeadless},thinkingDefault:e.thinkingDefault,reasoningDefault:e.reasoningDefault,verboseDefault:e.verboseDefault,compaction:{...e.compaction},pruning:{...e.pruning},memory:Vn(e.memory),sessionSearch:{summaryModel:e.sessionSearch.summaryModel.trim()||null},backgroundReview:{enabled:e.backgroundReview.enabled,memoryNudgeInterval:e.backgroundReview.memoryNudgeInterval,skillNudgeInterval:e.backgroundReview.skillNudgeInterval,maxToolRounds:e.backgroundReview.maxToolRounds,maxHistoryMessages:e.backgroundReview.maxHistoryMessages,maxDurationMs:e.backgroundReview.maxDurationMs},webExtract:{model:e.webExtract.model.trim()||null,maxLength:e.webExtract.maxLength??null},delegate:{enabled:e.delegate.enabled},executeCode:{enabled:e.executeCode.enabled},systemPromptOverride:e.systemPromptOverride.trim()||null,skills:c.length>0?c:null,tools:{disable:l.length>0?l:null},params:d};await L(Ge(`/api/config`),{method:`PATCH`,body:JSON.stringify({agents:{defaults:f}})}),Me()}function Z(){return i(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,fe,`dark:border-edge`)}function Wn(){return i(H,dt)}function Q({label:e,description:t,children:n}){return(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e}),n,(0,W.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:t})]})}function Gn(e){let{a:t,chat:n,form:r,update:a}=e,o=t.advanced;return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(q,{children:[(0,W.jsx)(J,{icon:S,title:o.cardLimitsTitle,subtitle:o.cardLimitsSubtitle}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,W.jsx)(Q,{label:o.maxTaskDurationMs,description:o.maxTaskDurationMsDesc,children:(0,W.jsx)(`input`,{type:`number`,className:Z(),min:1,max:240,step:1,value:r.maxTaskDurationMinutes??``,placeholder:o.maxTaskDurationPlaceholder,onChange:e=>{let t=e.target.value;if(t===``){a({maxTaskDurationMinutes:void 0});return}let n=Number.parseInt(t,10);Number.isNaN(n)||a({maxTaskDurationMinutes:Math.min(240,Math.max(1,n))})}})}),(0,W.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,W.jsx)(Q,{label:o.maxRequestsPerTurn,description:o.maxRequestsPerTurnDesc,children:(0,W.jsx)(`input`,{type:`number`,className:Z(),min:10,max:200,value:r.maxRequestsPerTurn,onChange:e=>a({maxRequestsPerTurn:Number.parseInt(e.target.value,10)||50})})}),(0,W.jsx)(Q,{label:o.maxToolFailuresPerTurn,description:o.maxToolFailuresPerTurnDesc,children:(0,W.jsx)(`input`,{type:`number`,className:Z(),min:1,max:20,value:r.maxToolFailuresPerTurn,onChange:e=>a({maxToolFailuresPerTurn:Number.parseInt(e.target.value,10)||3})})})]})]})]}),(0,W.jsxs)(q,{children:[(0,W.jsx)(J,{icon:j,title:o.cardCompactionTitle,subtitle:o.cardCompactionSubtitle}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,W.jsx)(Q,{label:o.compactionEnabled,description:o.compactionEnabledDesc,children:(0,W.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,W.jsx)(`input`,{type:`checkbox`,className:`size-3.5 shrink-0 rounded border-edge`,checked:r.compaction.enabled,onChange:e=>a({compaction:{...r.compaction,enabled:e.target.checked}})}),(0,W.jsx)(`span`,{children:o.compactionEnabledOn})]})}),(0,W.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,W.jsx)(Q,{label:o.compactionMode,description:o.compactionModeDesc,children:(0,W.jsxs)(`select`,{className:Wn(),value:r.compaction.mode,onChange:e=>a({compaction:{...r.compaction,mode:e.target.value}}),children:[(0,W.jsx)(`option`,{value:`default`,children:o.compactionModeDefault}),(0,W.jsx)(`option`,{value:`safeguard`,children:o.compactionModeSafeguard})]})}),(0,W.jsx)(Q,{label:o.reserveTokens,description:o.reserveTokensDesc,children:(0,W.jsx)(`input`,{type:`number`,className:Z(),min:1e3,value:r.compaction.reserveTokens,onChange:e=>a({compaction:{...r.compaction,reserveTokens:Number.parseInt(e.target.value,10)||0}})})}),(0,W.jsx)(Q,{label:o.triggerThreshold,description:o.triggerThresholdDesc,children:(0,W.jsx)(`input`,{type:`number`,className:Z(),min:.5,max:.95,step:.05,value:r.compaction.triggerThreshold,onChange:e=>a({compaction:{...r.compaction,triggerThreshold:Number.parseFloat(e.target.value)||.8}})})}),(0,W.jsx)(Q,{label:o.minMessagesBeforeCompact,description:o.minMessagesBeforeCompactDesc,children:(0,W.jsx)(`input`,{type:`number`,className:Z(),min:1,value:r.compaction.minMessagesBeforeCompact,onChange:e=>a({compaction:{...r.compaction,minMessagesBeforeCompact:Number.parseInt(e.target.value,10)||10}})})}),(0,W.jsx)(Q,{label:o.keepRecentMessages,description:o.keepRecentMessagesDesc,children:(0,W.jsx)(`input`,{type:`number`,className:Z(),min:0,value:r.compaction.keepRecentMessages,onChange:e=>a({compaction:{...r.compaction,keepRecentMessages:Number.parseInt(e.target.value,10)||5}})})}),(0,W.jsx)(Q,{label:o.evictionWindow,description:o.evictionWindowDesc,children:(0,W.jsx)(`input`,{type:`number`,className:Z(),min:.1,max:.5,step:.05,value:r.compaction.evictionWindow,onChange:e=>a({compaction:{...r.compaction,evictionWindow:Number.parseFloat(e.target.value)||.2}})})}),(0,W.jsx)(Q,{label:o.retentionWindow,description:o.retentionWindowDesc,children:(0,W.jsx)(`input`,{type:`number`,className:Z(),min:3,max:20,value:r.compaction.retentionWindow,onChange:e=>a({compaction:{...r.compaction,retentionWindow:Number.parseInt(e.target.value,10)||6}})})})]})]})]}),(0,W.jsxs)(q,{children:[(0,W.jsx)(J,{icon:ye,title:o.cardPruningTitle,subtitle:o.cardPruningSubtitle}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,W.jsx)(Q,{label:o.pruningEnabled,description:o.pruningEnabledDesc,children:(0,W.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,W.jsx)(`input`,{type:`checkbox`,className:`size-3.5 shrink-0 rounded border-edge`,checked:r.pruning.enabled,onChange:e=>a({pruning:{...r.pruning,enabled:e.target.checked}})}),(0,W.jsx)(`span`,{children:o.pruningEnabledOn})]})}),(0,W.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,W.jsx)(Q,{label:o.maxToolResultChars,description:o.maxToolResultCharsDesc,children:(0,W.jsx)(`input`,{type:`number`,className:Z(),min:1e3,value:r.pruning.maxToolResultChars,onChange:e=>a({pruning:{...r.pruning,maxToolResultChars:Number.parseInt(e.target.value,10)||1e4}})})}),(0,W.jsx)(Q,{label:o.headKeepRatio,description:o.headKeepRatioDesc,children:(0,W.jsx)(`input`,{type:`number`,className:Z(),min:0,max:1,step:.05,value:r.pruning.headKeepRatio,onChange:e=>a({pruning:{...r.pruning,headKeepRatio:Number.parseFloat(e.target.value)||.3}})})}),(0,W.jsx)(Q,{label:o.tailKeepRatio,description:o.tailKeepRatioDesc,children:(0,W.jsx)(`input`,{type:`number`,className:Z(),min:0,max:1,step:.05,value:r.pruning.tailKeepRatio,onChange:e=>a({pruning:{...r.pruning,tailKeepRatio:Number.parseFloat(e.target.value)||.3}})})})]})]})]}),(0,W.jsxs)(q,{children:[(0,W.jsx)(J,{icon:Ue,title:o.cardMemoryTitle,subtitle:o.cardMemorySubtitle}),(0,W.jsx)(`div`,{className:`flex flex-col gap-5`,children:(0,W.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,W.jsx)(Q,{label:o.memoryEnabled,description:o.memoryEnabledDesc,children:(0,W.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,W.jsx)(`input`,{type:`checkbox`,className:`size-3.5 shrink-0 rounded border-edge`,checked:r.memory.enabled,onChange:e=>a({memory:{...r.memory,enabled:e.target.checked}})}),(0,W.jsx)(`span`,{children:o.memoryEnabledOn})]})}),(0,W.jsx)(Q,{label:o.useEnhancedSystem,description:o.useEnhancedSystemDesc,children:(0,W.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,W.jsx)(`input`,{type:`checkbox`,className:`size-3.5 shrink-0 rounded border-edge`,checked:r.memory.useEnhancedSystem,onChange:e=>a({memory:{...r.memory,useEnhancedSystem:e.target.checked}})}),(0,W.jsx)(`span`,{children:o.useEnhancedSystemOn})]})}),(0,W.jsx)(Q,{label:o.userProfileEnabled,description:o.userProfileEnabledDesc,children:(0,W.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,W.jsx)(`input`,{type:`checkbox`,className:`size-3.5 shrink-0 rounded border-edge`,checked:r.memory.userProfileEnabled,onChange:e=>a({memory:{...r.memory,userProfileEnabled:e.target.checked}})}),(0,W.jsx)(`span`,{children:o.userProfileEnabledOn})]})}),(0,W.jsx)(Q,{label:o.memoryProvider,description:o.memoryProviderDesc,children:(0,W.jsxs)(`select`,{className:Wn(),value:r.memory.provider,onChange:e=>a({memory:{...r.memory,provider:e.target.value}}),children:[(0,W.jsx)(`option`,{value:``,children:o.memoryProviderUnset}),(0,W.jsx)(`option`,{value:`none`,children:`none`}),(0,W.jsx)(`option`,{value:`stub`,children:`stub`})]})}),(0,W.jsx)(Q,{label:o.injectionFrequency,description:o.injectionFrequencyDesc,children:(0,W.jsxs)(`select`,{className:Wn(),value:r.memory.injectionFrequency,onChange:e=>a({memory:{...r.memory,injectionFrequency:e.target.value}}),children:[(0,W.jsx)(`option`,{value:``,children:o.injectionFrequencyUnset}),(0,W.jsx)(`option`,{value:`every-turn`,children:o.injectionEveryTurn}),(0,W.jsx)(`option`,{value:`first-turn`,children:o.injectionFirstTurn})]})}),(0,W.jsx)(Q,{label:o.memoryCharLimit,description:o.memoryCharLimitDesc,children:(0,W.jsx)(`input`,{type:`number`,className:Z(),min:1,value:r.memory.memoryCharLimit??``,placeholder:`—`,onChange:e=>{let t=e.target.value;a({memory:{...r.memory,memoryCharLimit:t===``?void 0:Number.parseInt(t,10)}})}})}),(0,W.jsx)(Q,{label:o.userCharLimit,description:o.userCharLimitDesc,children:(0,W.jsx)(`input`,{type:`number`,className:Z(),min:1,value:r.memory.userCharLimit??``,placeholder:`—`,onChange:e=>{let t=e.target.value;a({memory:{...r.memory,userCharLimit:t===``?void 0:Number.parseInt(t,10)}})}})}),(0,W.jsx)(Q,{label:o.contextCadence,description:o.contextCadenceDesc,children:(0,W.jsx)(`input`,{type:`number`,className:Z(),min:1,value:r.memory.contextCadence??``,placeholder:`—`,onChange:e=>{let t=e.target.value;a({memory:{...r.memory,contextCadence:t===``?void 0:Number.parseInt(t,10)}})}})}),(0,W.jsx)(Q,{label:o.dialecticCadence,description:o.dialecticCadenceDesc,children:(0,W.jsx)(`input`,{type:`number`,className:Z(),min:1,value:r.memory.dialecticCadence??``,placeholder:`—`,onChange:e=>{let t=e.target.value;a({memory:{...r.memory,dialecticCadence:t===``?void 0:Number.parseInt(t,10)}})}})})]})})]}),(0,W.jsxs)(q,{children:[(0,W.jsx)(J,{icon:C,title:o.cardSessionSearchTitle,subtitle:o.cardSessionSearchSubtitle}),(0,W.jsx)(Q,{label:o.sessionSearchSummaryModel,description:o.sessionSearchSummaryModelDesc,children:(0,W.jsx)(B,{value:r.sessionSearch.summaryModel,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,onChange:e=>a({sessionSearch:{...r.sessionSearch,summaryModel:e}})})})]}),(0,W.jsxs)(q,{children:[(0,W.jsx)(J,{icon:M,title:o.cardReviewTitle,subtitle:o.cardReviewSubtitle}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,W.jsx)(Q,{label:o.reviewEnabled,description:o.reviewEnabledDesc,children:(0,W.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,W.jsx)(`input`,{type:`checkbox`,className:`size-3.5 shrink-0 rounded border-edge`,checked:r.backgroundReview.enabled,onChange:e=>a({backgroundReview:{...r.backgroundReview,enabled:e.target.checked}})}),(0,W.jsx)(`span`,{children:o.reviewEnabledOn})]})}),(0,W.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,W.jsx)(Q,{label:o.memoryNudgeInterval,description:o.memoryNudgeIntervalDesc,children:(0,W.jsx)(`input`,{type:`number`,className:Z(),min:0,value:r.backgroundReview.memoryNudgeInterval,onChange:e=>a({backgroundReview:{...r.backgroundReview,memoryNudgeInterval:Number.parseInt(e.target.value,10)||0}})})}),(0,W.jsx)(Q,{label:o.skillNudgeInterval,description:o.skillNudgeIntervalDesc,children:(0,W.jsx)(`input`,{type:`number`,className:Z(),min:0,value:r.backgroundReview.skillNudgeInterval,onChange:e=>a({backgroundReview:{...r.backgroundReview,skillNudgeInterval:Number.parseInt(e.target.value,10)||0}})})}),(0,W.jsx)(Q,{label:o.reviewMaxToolRounds,description:o.reviewMaxToolRoundsDesc,children:(0,W.jsx)(`input`,{type:`number`,className:Z(),min:1,max:32,value:r.backgroundReview.maxToolRounds,onChange:e=>a({backgroundReview:{...r.backgroundReview,maxToolRounds:Number.parseInt(e.target.value,10)||8}})})}),(0,W.jsx)(Q,{label:o.reviewMaxHistoryMessages,description:o.reviewMaxHistoryMessagesDesc,children:(0,W.jsx)(`input`,{type:`number`,className:Z(),min:10,max:200,value:r.backgroundReview.maxHistoryMessages,onChange:e=>a({backgroundReview:{...r.backgroundReview,maxHistoryMessages:Number.parseInt(e.target.value,10)||80}})})}),(0,W.jsx)(Q,{label:o.reviewMaxDurationMs,description:o.reviewMaxDurationMsDesc,children:(0,W.jsx)(`input`,{type:`number`,className:Z(),min:30,max:600,step:1,value:Math.round((r.backgroundReview.maxDurationMs??12e4)/1e3),onChange:e=>a({backgroundReview:{...r.backgroundReview,maxDurationMs:(Number.parseInt(e.target.value,10)||120)*1e3}})})})]})]})]}),(0,W.jsxs)(q,{children:[(0,W.jsx)(J,{icon:T,title:o.cardWebExtractTitle,subtitle:o.cardWebExtractSubtitle}),(0,W.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,W.jsx)(`div`,{className:`sm:col-span-2`,children:(0,W.jsx)(Q,{label:o.webExtractModel,description:o.webExtractModelDesc,children:(0,W.jsx)(B,{value:r.webExtract.model,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,onChange:e=>a({webExtract:{...r.webExtract,model:e}})})})}),(0,W.jsx)(Q,{label:o.webExtractMaxLength,description:o.webExtractMaxLengthDesc,children:(0,W.jsx)(`input`,{type:`number`,className:Z(),min:1,value:r.webExtract.maxLength??``,placeholder:`—`,onChange:e=>{let t=e.target.value;a({webExtract:{...r.webExtract,maxLength:t===``?void 0:Number.parseInt(t,10)}})}})})]})]}),(0,W.jsxs)(q,{children:[(0,W.jsx)(J,{icon:ge,title:o.cardDelegateTitle,subtitle:o.cardDelegateSubtitle}),(0,W.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,W.jsx)(Q,{label:o.delegateEnabled,description:o.delegateEnabledDesc,children:(0,W.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,W.jsx)(`input`,{type:`checkbox`,className:`size-3.5 shrink-0 rounded border-edge`,checked:r.delegate.enabled,onChange:e=>a({delegate:{...r.delegate,enabled:e.target.checked}})}),(0,W.jsx)(`span`,{children:o.delegateEnabledOn})]})}),(0,W.jsx)(Q,{label:o.executeCodeEnabled,description:o.executeCodeEnabledDesc,children:(0,W.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,W.jsx)(`input`,{type:`checkbox`,className:`size-3.5 shrink-0 rounded border-edge`,checked:r.executeCode.enabled,onChange:e=>a({executeCode:{...r.executeCode,enabled:e.target.checked}})}),(0,W.jsx)(`span`,{children:o.executeCodeEnabledOn})]})})]})]}),(0,W.jsxs)(q,{children:[(0,W.jsx)(J,{icon:P,title:o.cardPromptSkillsTitle,subtitle:o.cardPromptSkillsSubtitle}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,W.jsx)(Q,{label:o.systemPromptOverride,description:o.systemPromptOverrideDesc,children:(0,W.jsx)(`textarea`,{className:i(Z(),`min-h-[100px] resize-y font-mono text-xs`),value:r.systemPromptOverride,placeholder:o.systemPromptPlaceholder,onChange:e=>a({systemPromptOverride:e.target.value})})}),(0,W.jsx)(Q,{label:o.skillsAllowlist,description:o.skillsAllowlistDesc,children:(0,W.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[r.skillsAllowlist.map((e,t)=>(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`input`,{type:`text`,className:i(Z(),`font-mono text-xs`),value:e,onChange:e=>{let n=[...r.skillsAllowlist];n[t]=e.target.value,a({skillsAllowlist:n})}}),(0,W.jsx)(V,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":o.removeListItem,onClick:()=>a({skillsAllowlist:r.skillsAllowlist.filter((e,n)=>n!==t)}),children:`×`})]},t)),(0,W.jsx)(V,{type:`button`,variant:`secondary`,className:`w-fit`,onClick:()=>a({skillsAllowlist:[...r.skillsAllowlist,``]}),children:o.addSkillName})]})})]})]}),(0,W.jsxs)(q,{children:[(0,W.jsx)(J,{icon:ze,title:o.cardToolsDisableTitle,subtitle:o.cardToolsDisableSubtitle}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,W.jsx)(`p`,{className:`text-xs text-fg-muted`,children:o.toolsDisableHint}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[r.toolsDisable.map((e,t)=>(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`input`,{type:`text`,className:i(Z(),`font-mono text-xs`),value:e,placeholder:`shell`,onChange:e=>{let n=[...r.toolsDisable];n[t]=e.target.value,a({toolsDisable:n})}}),(0,W.jsx)(V,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":o.removeListItem,onClick:()=>a({toolsDisable:r.toolsDisable.filter((e,n)=>n!==t)}),children:`×`})]},t)),(0,W.jsx)(V,{type:`button`,variant:`secondary`,className:`w-fit`,onClick:()=>a({toolsDisable:[...r.toolsDisable,``]}),children:o.addToolName})]})]})]}),(0,W.jsxs)(q,{children:[(0,W.jsx)(J,{icon:ve,title:o.cardParamsTitle,subtitle:o.cardParamsSubtitle}),(0,W.jsx)(Q,{label:o.paramsJson,description:o.paramsJsonDesc,children:(0,W.jsx)(`textarea`,{className:i(Z(),`min-h-[88px] resize-y font-mono text-xs`),value:r.paramsJson,placeholder:`{}`,onChange:e=>a({paramsJson:e.target.value})})})]})]})}async function Kn(){let e=await Ye(Ge(`/api/image/providers`));if(!e.ok)throw Error(`Image providers: HTTP ${e.status}`);return(await e.json()).payload?.providers??[]}function qn(e){let t=new Set,n=[];for(let r of e){let e=r.models.length>0?r.models:r.defaultModel?[r.defaultModel]:[];for(let i of e){let e=`${r.id}/${i}`;t.has(e)||(t.add(e),n.push(e))}}return n}function Jn(e,t){let n=t.trim().toLowerCase();if(!n)return e;let r=n.split(/[/\s]+/).filter(Boolean);return e.filter(e=>{let t=e.toLowerCase();return r.every(e=>t.includes(e))})}var Yn=`image-generation-providers`;function Xn({value:e,disabled:t,placeholder:n,searchPlaceholder:a,noMatches:o,className:s,onChange:c}){let[l,u]=(0,U.useState)(!1),[d,f]=(0,U.useState)(``),{data:p,isLoading:m,error:h}=r(Yn,Kn,{revalidateOnFocus:!1}),g=(0,U.useMemo)(()=>qn(p??[]),[p]),_=(0,U.useMemo)(()=>Jn(g,d),[g,d]),v=e.trim()?e:n,y=e.trim()||n,b=(0,U.useCallback)(e=>{u(e),e||f(``)},[]);return(0,W.jsxs)(D,{open:l,onOpenChange:b,modal:!1,children:[(0,W.jsx)(ue,{asChild:!0,children:(0,W.jsxs)(`button`,{type:`button`,disabled:t||m,title:m?`…`:y,className:i(Ce,`items-center gap-2 rounded-lg border border-edge-subtle bg-surface-panel px-3 py-2 text-left text-sm font-normal text-fg`,_e.transition,`hover:border-edge hover:bg-surface-hover/45`,De,`disabled:cursor-not-allowed disabled:opacity-50`,`dark:border-edge-subtle dark:hover:bg-surface-hover/55`,s),"aria-haspopup":`listbox`,"aria-expanded":l,children:[(0,W.jsx)(`span`,{className:`min-w-0 truncate`,children:m?`…`:v}),(0,W.jsx)(xe,{className:`h-4 w-4 shrink-0 text-fg-subtle opacity-70`,"aria-hidden":!0})]})}),(0,W.jsx)(E,{children:(0,W.jsxs)(z,{className:`z-50 w-[min(22rem,calc(100vw-2rem))] rounded-xl border border-edge-subtle bg-surface-panel p-1 shadow-elevated dark:border-edge-subtle`,side:`bottom`,sideOffset:4,align:`end`,onOpenAutoFocus:e=>e.preventDefault(),children:[(0,W.jsx)(`input`,{type:`search`,className:i(`mb-1 w-full rounded-lg border border-edge-subtle bg-surface-base px-2.5 py-1.5 text-sm text-fg placeholder:text-fg-disabled dark:bg-surface-hover/40`,it),placeholder:a,value:d,onChange:e=>f(e.target.value),onKeyDown:e=>e.stopPropagation()}),(0,W.jsxs)(`div`,{className:`max-h-60 overflow-auto`,role:`listbox`,"aria-label":a,children:[h?(0,W.jsx)(`div`,{className:`px-2 py-2 text-xs text-red-600 dark:text-red-400`,children:h instanceof Error?h.message:`Failed to load image providers`}):null,!h&&g.length===0&&!m?(0,W.jsx)(`div`,{className:`px-2 py-3 text-center text-xs text-fg-muted`,children:o}):null,!h&&g.length>0&&_.length===0?(0,W.jsx)(`div`,{className:`px-2 py-3 text-center text-xs text-fg-muted`,children:o}):null,_.map(t=>(0,W.jsxs)(`button`,{type:`button`,role:`option`,"aria-selected":t===e,className:i(`flex w-full items-center gap-2 rounded-md px-2 py-1.5 text-left text-sm text-fg hover:bg-surface-hover`,t===e&&`bg-surface-hover/90 font-medium dark:bg-surface-hover/70`),onClick:()=>{c(t),u(!1),f(``)},children:[(0,W.jsx)(Ze,{className:i(`h-4 w-4 shrink-0`,t!==e&&`invisible`),"aria-hidden":!0}),(0,W.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm font-medium`,children:t})]},t))]})]})})]})}var Zn=[`off`,`minimal`,`low`,`medium`,`high`,`xhigh`,`adaptive`];function $({label:e,description:t,children:n}){return(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e}),n,(0,W.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:t})]})}function Qn(){let e=u(Pe(e=>e.language)),t=e.agentSettings,n=e.chat,r=!!tt(e=>e.token),[i,a]=(0,U.useState)(null),[o,s]=(0,U.useState)(null),[l,d]=(0,U.useState)(!1),[f,m]=(0,U.useState)(null),[h,_]=(0,U.useState)(!1),y=(0,U.useRef)(!1),{data:b,error:x,isLoading:S,mutate:ee}=we(r),C=(0,U.useMemo)(()=>b?.payload?.config===void 0?null:Bn(b.payload.config),[b]);(0,U.useEffect)(()=>{if(!r){a(null),s(null),y.current=!1;return}C!==null&&(y.current||(a(C),s(C)))},[r,C]);let te=!!(r&&S&&b===void 0&&!x),w=x instanceof Error?x.message:x?String(x):null,ne=(0,U.useMemo)(()=>!i||!o?!1:JSON.stringify(i)!==JSON.stringify(o),[i,o]),T=(0,U.useCallback)(e=>{y.current=!0,a(t=>t?{...t,...e}:null)},[]),E=(0,U.useCallback)(async()=>{if(!(!i||l)){d(!0),m(null),_(!1);try{try{Hn(i.paramsJson)}catch(e){m(e instanceof SyntaxError?t.advanced.paramsInvalidJson:e instanceof Error?e.message:t.advanced.paramsInvalidJson);return}await Un(i),y.current=!1,_(!0),window.setTimeout(()=>_(!1),2500)}catch(e){m(e instanceof Error?e.message:t.saveError)}finally{d(!1)}}},[i,l,t.saveError,t.advanced]),re=e.settingsSections[`agent-defaults`];return r?te?(0,W.jsxs)(`div`,{className:`mx-auto w-full max-w-app-main px-4 py-8`,children:[(0,W.jsx)(`div`,{className:`h-8 w-48 animate-pulse rounded bg-surface-hover`}),(0,W.jsx)(`div`,{className:`mt-6 h-32 animate-pulse rounded-xl bg-surface-hover`}),(0,W.jsx)(`p`,{className:`mt-4 text-sm text-fg-muted`,children:e.logs.loading})]}):i?(0,W.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[(0,W.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:re}),(0,W.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:t.subtitle}),(0,W.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:t.sectionDesc})]}),(0,W.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[h?(0,W.jsx)(`span`,{className:`text-sm text-fg-muted`,children:t.saved}):null,(0,W.jsx)(V,{type:`button`,variant:`primary`,disabled:!ne||l,onClick:()=>void E(),children:l?t.saving:t.save})]})]}),f?(0,W.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:f}):null,(0,W.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,W.jsxs)(q,{children:[(0,W.jsx)(J,{icon:c,title:t.cardModelsTitle,subtitle:t.cardModelsSubtitle}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,W.jsx)($,{label:t.label.model,description:t.desc.model,children:(0,W.jsx)(B,{value:i.model,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,onChange:e=>T({model:e})})}),(0,W.jsx)($,{label:t.label.modelFallbacks,description:t.desc.modelFallbacks,children:(0,W.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[i.modelFallbacks.map((e,r)=>(0,W.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,W.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,W.jsx)(B,{value:e,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,onChange:e=>{let t=[...i.modelFallbacks];t[r]=e,T({modelFallbacks:t})}})}),(0,W.jsx)(V,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":t.removeModelFallback,onClick:()=>T({modelFallbacks:i.modelFallbacks.filter((e,t)=>t!==r)}),children:(0,W.jsx)(v,{className:`size-4`,strokeWidth:1.75})})]},r)),(0,W.jsxs)(V,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:()=>T({modelFallbacks:[...i.modelFallbacks,``]}),children:[(0,W.jsx)(Oe,{className:`size-4 shrink-0`,strokeWidth:1.75}),t.addModelFallback]})]})}),(0,W.jsx)($,{label:t.label.imageModel,description:t.desc.imageModel,children:(0,W.jsx)(B,{value:i.imageModel,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,onChange:e=>T({imageModel:e})})}),(0,W.jsx)($,{label:t.label.imageModelFallbacks,description:t.desc.imageModelFallbacks,children:(0,W.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[i.imageModelFallbacks.map((e,r)=>(0,W.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,W.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,W.jsx)(B,{value:e,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,onChange:e=>{let t=[...i.imageModelFallbacks];t[r]=e,T({imageModelFallbacks:t})}})}),(0,W.jsx)(V,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":t.removeModelFallback,onClick:()=>T({imageModelFallbacks:i.imageModelFallbacks.filter((e,t)=>t!==r)}),children:(0,W.jsx)(v,{className:`size-4`,strokeWidth:1.75})})]},r)),(0,W.jsxs)(V,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:()=>T({imageModelFallbacks:[...i.imageModelFallbacks,``]}),children:[(0,W.jsx)(Oe,{className:`size-4 shrink-0`,strokeWidth:1.75}),t.addModelFallback]})]})}),(0,W.jsx)($,{label:t.label.imageGenerationModel,description:t.desc.imageGenerationModel,children:(0,W.jsx)(Xn,{value:i.imageGenerationModel,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,onChange:e=>T({imageGenerationModel:e})})}),(0,W.jsx)($,{label:t.label.imageGenerationModelFallbacks,description:t.desc.imageGenerationModelFallbacks,children:(0,W.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[i.imageGenerationModelFallbacks.map((e,r)=>(0,W.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,W.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,W.jsx)(Xn,{value:e,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,onChange:e=>{let t=[...i.imageGenerationModelFallbacks];t[r]=e,T({imageGenerationModelFallbacks:t})}})}),(0,W.jsx)(V,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":t.removeModelFallback,onClick:()=>T({imageGenerationModelFallbacks:i.imageGenerationModelFallbacks.filter((e,t)=>t!==r)}),children:(0,W.jsx)(v,{className:`size-4`,strokeWidth:1.75})})]},r)),(0,W.jsxs)(V,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:()=>T({imageGenerationModelFallbacks:[...i.imageGenerationModelFallbacks,``]}),children:[(0,W.jsx)(Oe,{className:`size-4 shrink-0`,strokeWidth:1.75}),t.addModelFallback]})]})})]})]}),(0,W.jsxs)(q,{children:[(0,W.jsx)(J,{icon:se,title:t.cardWorkspaceTitle,subtitle:t.cardWorkspaceSubtitle}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,W.jsx)($,{label:t.label.workspace,description:t.desc.workspace,children:(0,W.jsx)(`input`,{type:`text`,className:Z(),value:i.workspace,onChange:e=>T({workspace:e.target.value}),autoComplete:`off`})}),(0,W.jsx)($,{label:t.label.mediaMaxMb,description:t.desc.mediaMaxMb,children:(0,W.jsx)(`input`,{type:`number`,min:1,step:1,className:Z(),value:i.mediaMaxMb??``,placeholder:`20`,onChange:e=>{let t=e.target.value;T({mediaMaxMb:t===``?void 0:Number(t)})}})})]})]}),(0,W.jsxs)(q,{children:[(0,W.jsx)(J,{icon:g,title:t.cardBrowserTitle,subtitle:t.cardBrowserSubtitle}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,W.jsx)($,{label:t.label.browserEnabled,description:t.desc.browserEnabled,children:(0,W.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,W.jsx)(`input`,{type:`checkbox`,className:`size-3.5 shrink-0 rounded border-edge`,checked:i.browserEnabled,onChange:e=>T({browserEnabled:e.target.checked})}),(0,W.jsx)(`span`,{children:t.browserEnabledOn})]})}),(0,W.jsx)($,{label:t.label.browserHeadless,description:t.desc.browserHeadless,children:(0,W.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,W.jsx)(`input`,{type:`checkbox`,className:`size-3.5 shrink-0 rounded border-edge`,checked:i.browserHeadless,onChange:e=>T({browserHeadless:e.target.checked})}),(0,W.jsx)(`span`,{children:t.browserHeadlessOn})]})})]})]}),(0,W.jsxs)(q,{children:[(0,W.jsx)(J,{icon:lt,title:t.cardGenerationTitle,subtitle:t.cardGenerationSubtitle}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,W.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,W.jsx)($,{label:t.label.maxTokens,description:t.desc.maxTokens,children:(0,W.jsx)(`input`,{type:`number`,className:Z(),value:i.maxTokens,min:1,onChange:e=>T({maxTokens:Number.parseInt(e.target.value,10)||0})})}),(0,W.jsx)($,{label:t.label.temperature,description:t.desc.temperature,children:(0,W.jsx)(`input`,{type:`number`,className:Z(),value:i.temperature,min:0,max:2,step:.1,onChange:e=>T({temperature:Number.parseFloat(e.target.value)||0})})})]}),(0,W.jsx)($,{label:t.label.maxToolIterations,description:t.desc.maxToolIterations,children:(0,W.jsx)(`input`,{type:`number`,className:Z(),value:i.maxToolIterations,min:1,onChange:e=>T({maxToolIterations:Number.parseInt(e.target.value,10)||0})})})]})]}),(0,W.jsxs)(q,{children:[(0,W.jsx)(J,{icon:p,title:t.cardBehaviorTitle,subtitle:t.cardBehaviorSubtitle}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,W.jsx)($,{label:t.label.thinkingDefault,description:t.desc.thinkingDefault,children:(0,W.jsx)(`select`,{className:Wn(),value:i.thinkingDefault,onChange:e=>T({thinkingDefault:e.target.value}),children:Zn.map(e=>(0,W.jsx)(`option`,{value:e,children:n.thinkingLevels[e]},e))})}),(0,W.jsx)($,{label:t.label.reasoningDefault,description:t.desc.reasoningDefault,children:(0,W.jsxs)(`select`,{className:Wn(),value:i.reasoningDefault,onChange:e=>T({reasoningDefault:e.target.value}),children:[(0,W.jsx)(`option`,{value:`off`,children:t.reasoning.off}),(0,W.jsx)(`option`,{value:`on`,children:t.reasoning.on}),(0,W.jsx)(`option`,{value:`stream`,children:t.reasoning.stream})]})}),(0,W.jsx)($,{label:t.label.verboseDefault,description:t.desc.verboseDefault,children:(0,W.jsxs)(`select`,{className:Wn(),value:i.verboseDefault,onChange:e=>T({verboseDefault:e.target.value}),children:[(0,W.jsx)(`option`,{value:`off`,children:t.verbose.off}),(0,W.jsx)(`option`,{value:`on`,children:t.verbose.on}),(0,W.jsx)(`option`,{value:`full`,children:t.verbose.full})]})})]})]}),(0,W.jsx)(Gn,{a:t,chat:n,form:i,update:T})]})]}):(0,W.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-10`,children:[(0,W.jsx)(`p`,{className:`text-sm text-fg-muted`,children:f??w??t.loadError}),(0,W.jsx)(V,{type:`button`,variant:`secondary`,onClick:()=>void ee(),children:e.logs.refresh})]}):(0,W.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-10`,children:(0,W.jsxs)(`div`,{className:`flex items-start gap-3 rounded-2xl bg-surface-base p-6`,children:[(0,W.jsx)(c,{className:`mt-0.5 size-5 shrink-0 text-fg-subtle`,strokeWidth:1.75}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h1`,{className:`text-base font-semibold text-fg`,children:re}),(0,W.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:t.needToken})]})]})})}export{Sn as AgentsSettingsPanel,Ot as a,kt as c,Yt as i,At as l,q as n,Nt as o,J as r,Mt as s,Qn as t,jt as u};
216
+ //# sourceMappingURL=agents-CkgFSiCY.js.map