@xopcai/xopc 0.0.25 → 0.0.27

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 (90) hide show
  1. package/dist/extensions/telegram/xopc.extension.json +1 -1
  2. package/dist/gateway/static/root/assets/agents-w8_jzuiX.js +216 -0
  3. package/dist/gateway/static/root/assets/agents-w8_jzuiX.js.map +1 -0
  4. package/dist/gateway/static/root/assets/{apps-page-DbzO48lg.js → apps-page-CBBh_Ww8.js} +2 -2
  5. package/dist/gateway/static/root/assets/{apps-page-DbzO48lg.js.map → apps-page-CBBh_Ww8.js.map} +1 -1
  6. package/dist/gateway/static/root/assets/channels-settings-DUKRPC7C.js +9 -0
  7. package/dist/gateway/static/root/assets/{channels-settings-CeGoU9v8.js.map → channels-settings-DUKRPC7C.js.map} +1 -1
  8. package/dist/gateway/static/root/assets/cron-page-S18t1yG-.js +2 -0
  9. package/dist/gateway/static/root/assets/{cron-page-DpEYUvxB.js.map → cron-page-S18t1yG-.js.map} +1 -1
  10. package/dist/gateway/static/root/assets/{cron-utils-Cvv0F3pa.js → cron-utils-08gdQfl9.js} +2 -2
  11. package/dist/gateway/static/root/assets/{cron-utils-Cvv0F3pa.js.map → cron-utils-08gdQfl9.js.map} +1 -1
  12. package/dist/gateway/static/root/assets/dist-C1MrygQH.js +2 -0
  13. package/dist/gateway/static/root/assets/{dist-C41N3YrO.js.map → dist-C1MrygQH.js.map} +1 -1
  14. package/dist/gateway/static/root/assets/{extension-debug-page-CkkYZjNP.js → extension-debug-page-DN3HKUGS.js} +2 -2
  15. package/dist/gateway/static/root/assets/{extension-debug-page-CkkYZjNP.js.map → extension-debug-page-DN3HKUGS.js.map} +1 -1
  16. package/dist/gateway/static/root/assets/{extension-page-BjUIPVNG.js → extension-page-CoFDHZtZ.js} +2 -2
  17. package/dist/gateway/static/root/assets/{extension-page-BjUIPVNG.js.map → extension-page-CoFDHZtZ.js.map} +1 -1
  18. package/dist/gateway/static/root/assets/{extension-settings-page-CwuFDOdk.js → extension-settings-page-BcPCu_Go.js} +2 -2
  19. package/dist/gateway/static/root/assets/{extension-settings-page-CwuFDOdk.js.map → extension-settings-page-BcPCu_Go.js.map} +1 -1
  20. package/dist/gateway/static/root/assets/index-OT4cGzon.css +1 -0
  21. package/dist/gateway/static/root/assets/index-PfkB8N37.js +4734 -0
  22. package/dist/gateway/static/root/assets/index-PfkB8N37.js.map +1 -0
  23. package/dist/gateway/static/root/assets/logs-page-DoWe1GWy.js +2 -0
  24. package/dist/gateway/static/root/assets/{logs-page-BtwGPuw2.js.map → logs-page-DoWe1GWy.js.map} +1 -1
  25. package/dist/gateway/static/root/assets/sessions-page-2uOYwEwd.js +2 -0
  26. package/dist/gateway/static/root/assets/{sessions-page-4rKFDn2k.js.map → sessions-page-2uOYwEwd.js.map} +1 -1
  27. package/dist/gateway/static/root/assets/settings-page-fQWswCuq.js +2 -0
  28. package/dist/gateway/static/root/assets/settings-page-fQWswCuq.js.map +1 -0
  29. package/dist/gateway/static/root/assets/skills-page-BmBDCEbY.js +3 -0
  30. package/dist/gateway/static/root/assets/{skills-page-_siDuHeF.js.map → skills-page-BmBDCEbY.js.map} +1 -1
  31. package/dist/gateway/static/root/index.html +2 -2
  32. package/dist/package.js +1 -1
  33. package/dist/src/agent/memory/dreaming/config.d.ts +37 -9
  34. package/dist/src/agent/memory/dreaming/config.js +60 -18
  35. package/dist/src/agent/memory/dreaming/config.js.map +1 -1
  36. package/dist/src/agent/memory/dreaming/constants.d.ts +22 -1
  37. package/dist/src/agent/memory/dreaming/constants.js +26 -2
  38. package/dist/src/agent/memory/dreaming/constants.js.map +1 -1
  39. package/dist/src/agent/memory/dreaming/deep-promotion.d.ts +5 -6
  40. package/dist/src/agent/memory/dreaming/deep-promotion.js +90 -156
  41. package/dist/src/agent/memory/dreaming/deep-promotion.js.map +1 -1
  42. package/dist/src/agent/memory/dreaming/events.d.ts +36 -0
  43. package/dist/src/agent/memory/dreaming/events.js +44 -0
  44. package/dist/src/agent/memory/dreaming/events.js.map +1 -0
  45. package/dist/src/agent/memory/dreaming/last-run.d.ts +80 -0
  46. package/dist/src/agent/memory/dreaming/last-run.js +98 -0
  47. package/dist/src/agent/memory/dreaming/last-run.js.map +1 -0
  48. package/dist/src/agent/memory/dreaming/light-sweep.d.ts +19 -0
  49. package/dist/src/agent/memory/dreaming/light-sweep.js +328 -0
  50. package/dist/src/agent/memory/dreaming/light-sweep.js.map +1 -0
  51. package/dist/src/agent/memory/dreaming/preview.d.ts +3 -1
  52. package/dist/src/agent/memory/dreaming/preview.js +11 -90
  53. package/dist/src/agent/memory/dreaming/preview.js.map +1 -1
  54. package/dist/src/agent/memory/dreaming/rem-patterns.d.ts +21 -0
  55. package/dist/src/agent/memory/dreaming/rem-patterns.js +286 -0
  56. package/dist/src/agent/memory/dreaming/rem-patterns.js.map +1 -0
  57. package/dist/src/agent/memory/dreaming/short-term-store.d.ts +20 -0
  58. package/dist/src/agent/memory/dreaming/short-term-store.js +25 -15
  59. package/dist/src/agent/memory/dreaming/short-term-store.js.map +1 -1
  60. package/dist/src/agent/memory/dreaming/utils.d.ts +42 -0
  61. package/dist/src/agent/memory/dreaming/utils.js +141 -0
  62. package/dist/src/agent/memory/dreaming/utils.js.map +1 -0
  63. package/dist/src/agent/orchestration/agent-orchestrator.js +54 -12
  64. package/dist/src/agent/orchestration/agent-orchestrator.js.map +1 -1
  65. package/dist/src/agent/service.js +54 -28
  66. package/dist/src/agent/service.js.map +1 -1
  67. package/dist/src/config/schema.d.ts +54 -0
  68. package/dist/src/config/schema.js +34 -8
  69. package/dist/src/config/schema.js.map +1 -1
  70. package/dist/src/gateway/hono/lib/config-payload.d.ts +18 -0
  71. package/dist/src/gateway/hono/routes/dreaming.js +105 -15
  72. package/dist/src/gateway/hono/routes/dreaming.js.map +1 -1
  73. package/dist/src/gateway/hono/routes/models.js +26 -1
  74. package/dist/src/gateway/hono/routes/models.js.map +1 -1
  75. package/dist/src/gateway/hono/routes/public-gateway.js +1 -0
  76. package/dist/src/gateway/hono/routes/public-gateway.js.map +1 -1
  77. package/package.json +1 -1
  78. package/dist/gateway/static/root/assets/agents-C_bPhtBs.js +0 -216
  79. package/dist/gateway/static/root/assets/agents-C_bPhtBs.js.map +0 -1
  80. package/dist/gateway/static/root/assets/channels-settings-CeGoU9v8.js +0 -9
  81. package/dist/gateway/static/root/assets/cron-page-DpEYUvxB.js +0 -2
  82. package/dist/gateway/static/root/assets/dist-C41N3YrO.js +0 -2
  83. package/dist/gateway/static/root/assets/index-DwzwDCjW.js +0 -150
  84. package/dist/gateway/static/root/assets/index-DwzwDCjW.js.map +0 -1
  85. package/dist/gateway/static/root/assets/index-dhtHG1nU.css +0 -1
  86. package/dist/gateway/static/root/assets/logs-page-BtwGPuw2.js +0 -2
  87. package/dist/gateway/static/root/assets/sessions-page-4rKFDn2k.js +0 -2
  88. package/dist/gateway/static/root/assets/settings-page-iYLSxQYc.js +0 -2
  89. package/dist/gateway/static/root/assets/settings-page-iYLSxQYc.js.map +0 -1
  90. package/dist/gateway/static/root/assets/skills-page-_siDuHeF.js +0 -3
@@ -2,7 +2,7 @@
2
2
  "id": "telegram",
3
3
  "name": "Telegram Channel",
4
4
  "description": "Bundled Telegram Bot channel (private workspace sources; ships inside @xopcai/xopc dist/)",
5
- "version": "0.0.25",
5
+ "version": "0.0.27",
6
6
  "kind": "channel",
7
7
  "main": "src/index.ts",
8
8
  "channels": ["telegram"],
@@ -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{$n as a,$r as o,$t as s,A as c,Ar as l,C as u,Cn as d,Cr as f,D as p,Dr as m,E as h,Er as g,Fn as _,Gt as v,H as y,Hn as b,Hr as x,Jr as S,Jt as ee,K as C,Kr as w,Kt as T,Ln as E,Mn as te,O as ne,Pn as re,Pr as D,Qr as ie,Qt as ae,Rn as O,Rr as oe,S as se,T as ce,Tn as le,Tr as k,U as ue,Vr as de,W as A,Wn as fe,Wt as j,Xt as pe,Zr as me,_ as he,_n as M,_r as ge,_t as _e,an as ve,ar as N,b as ye,cn as P,ct as be,dn as F,dr as I,dt as xe,er as Se,f as L,fn as Ce,ft as we,gn as Te,gt as Ee,hn as De,hr as Oe,ht as ke,in as Ae,ir as je,j as Me,jn as Ne,k as Pe,lr as Fe,lt as Ie,nn as Le,on as Re,ot as ze,pn as R,qn as z,qt as Be,rn as Ve,sn as He,sr as Ue,st as We,tn as Ge,ut as Ke,v as qe,vn as Je,vt as Ye,w as Xe,wn as Ze,x as Qe,y as $e,yn as et,zr as tt}from"./index-PfkB8N37.js";import{C as nt,a as rt,d as it,p as at,v as ot,y as st}from"./cron-utils-08gdQfl9.js";var B=e(t(),1),ct=`main`,lt=/^[a-z0-9][a-z0-9_-]{0,63}$/i,ut=/[^a-z0-9_-]+/g,dt=/^-+/,ft=/-+$/,pt=/^[a-z0-9][a-z0-9_-]{0,63}$/,V=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 mt(e){let t=e.trim();if(!t)return ct;let n=t.toLowerCase();return lt.test(t)?n:n.replace(ut,`-`).replace(dt,``).replace(ft,``).slice(0,64)||ct}function ht(e,t){let n=e?.trim();if(n){let e=n.toLowerCase();return pt.test(e)?e===ct?{ok:!1,error:`"${ct}" is reserved`}:V.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=mt(t.trim());return r===ct?{ok:!1,error:`Display name cannot produce a valid agent folder id. Set an explicit Agent id (letters, digits, underscores, hyphens only).`}:V.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.`}:pt.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 gt(e){let t=e.trim();return t?`~/.xopc/workspace/${mt(t)}`:``}function _t(){return j(`/api/dreaming`)}async function vt(){let e=await T(_t());if(!e.payload)throw Error(`Missing payload`);return e.payload}async function yt(e){await T(j(`/api/dreaming/action`),{method:`POST`,body:JSON.stringify({action:e})})}async function bt(e=`deep`){let t=await T(j(`/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 xt(e){let t=await T(j(`/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 St(e=50){return(await T(j(`/api/dreaming/events${`?limit=${encodeURIComponent(String(e))}`}`))).payload?.events??[]}var H=n(),Ct=[{id:`overview`,labelKey:`navIdentity`,icon:De},{id:`profile`,labelKey:`navProfile`,icon:l},{id:`tools`,labelKey:`navTools`,icon:R},{id:`skills`,labelKey:`navSkills`,icon:_},{id:`files`,labelKey:`navCoreFiles`,icon:Oe}],wt=[{id:`channels`,labelKey:`tabChannels`,icon:O},{id:`cron`,labelKey:`tabCron`,icon:m}];function Tt(e){let{a:t,panel:n,onPanelChange:r}=e,a=(e,t,a)=>(0,H.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,H.jsx)(a,{className:`size-4 shrink-0 opacity-90`,strokeWidth:2,"aria-hidden":!0}),(0,H.jsx)(`span`,{className:`min-w-0 truncate`,children:t})]},e);return(0,H.jsxs)(`nav`,{className:`flex w-full flex-col gap-1`,"aria-label":t.editorNavAria,children:[(0,H.jsx)(`div`,{className:`flex flex-col gap-0.5`,children:Ct.map(({id:e,labelKey:n,icon:r})=>a(e,t[n],r))}),(0,H.jsx)(`p`,{className:`mt-4 px-3 text-[10px] font-semibold uppercase tracking-wide text-fg-subtle`,children:t.navAdvanced}),(0,H.jsx)(`div`,{className:`flex flex-col gap-0.5`,children:wt.map(({id:e,labelKey:n,icon:r})=>a(e,t[n],r))})]})}function Et(e){let{open:t,onOpenChange:n,a:r,title:a,subtitle:o,panel:s,onPanelChange:c,onFooterSave:l,footerSaveDisabled:u,footerSavedFlash:d,busy:f,children:p}=e;return(0,H.jsx)(xe,{open:t,onOpenChange:n,children:(0,H.jsxs)(Ke,{children:[(0,H.jsx)(Ie,{className:`xopc-dialog-overlay fixed inset-0 z-[60] bg-scrim`}),(0,H.jsxs)(We,{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,H.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,H.jsxs)(`div`,{className:`min-w-0 pr-2`,children:[(0,H.jsx)(we,{className:`text-base font-semibold leading-snug text-fg`,children:a}),(0,H.jsx)(be,{className:`mt-1 font-mono text-xs text-fg-muted`,children:o})]}),(0,H.jsx)(ze,{asChild:!0,children:(0,H.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,H.jsx)(Ce,{className:`size-4`,"aria-hidden":!0})})})]}),(0,H.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col sm:flex-row sm:overflow-hidden`,children:[(0,H.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,H.jsx)(Tt,{a:r,panel:s,onPanelChange:c})}),(0,H.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col overflow-hidden`,children:[(0,H.jsx)(`div`,{className:`flex min-h-0 flex-1 flex-col overflow-hidden px-4 py-4 sm:pl-2 sm:pr-5`,children:p}),(0,H.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:[d?(0,H.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,H.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,H.jsx)(P,{type:`button`,className:`order-1 w-full sm:order-2 sm:w-auto`,disabled:f||u,onClick:()=>void l(),children:r.save})]})]})]})]})]})})}function Dt(e,t){let n=t.trim().toLowerCase();return n?e.filter(e=>{let t=(e.name??``).toLowerCase(),r=e.id.toLowerCase(),i=e.workspace.toLowerCase(),a=(e.description??``).toLowerCase();return t.includes(n)||r.includes(n)||i.includes(n)||a.includes(n)}):e}function Ot(e){let{a:t,busy:n,onNewAgent:r}=e;return(0,H.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,H.jsx)(E,{className:`size-8 shrink-0 opacity-80`,strokeWidth:1.75,"aria-hidden":!0}),(0,H.jsx)(`span`,{children:t.listNewAgentCard})]})}function kt(e){let{a:t,agents:n,searchQuery:r,onOpenAgent:a,onChatWithAgent:o,onNewAgent:s,busy:c}=e,l=Dt(n,r),u=n.length>0&&l.length===0&&r.trim().length>0;return n.length===0?(0,H.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(0,H.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.listNoAgentsYet}),(0,H.jsx)(`div`,{className:`max-w-sm`,children:(0,H.jsx)(Ot,{a:t,busy:c,onNewAgent:s})})]}):(0,H.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[u?(0,H.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.listEmpty}):null,(0,H.jsxs)(`ul`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3`,role:`list`,children:[(0,H.jsx)(`li`,{className:`h-full min-h-0`,children:(0,H.jsx)(Ot,{a:t,busy:c,onNewAgent:s})}),l.map(e=>{let n=e.name?.trim()?e.name.trim():e.id,r=e.id,s=e.description?.trim()??``;return(0,H.jsx)(`li`,{className:`h-full min-h-0`,children:(0,H.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,H.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,H.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,H.jsx)(`span`,{className:`flex size-11 shrink-0 items-center justify-center rounded-xl bg-accent-soft text-accent-fg`,"aria-hidden":!0,children:(0,H.jsx)(de,{className:`size-6`,strokeWidth:1.75})}),(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5`,children:[(0,H.jsx)(`span`,{className:`truncate font-semibold text-fg`,children:n}),e.isDefault?(0,H.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,H.jsx)(`p`,{className:`mt-0.5 truncate font-mono text-xs text-fg-muted`,title:r,children:r})]})]}),(0,H.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,H.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,H.jsx)(z,{className:`size-4 shrink-0`,strokeWidth:2,"aria-hidden":!0}),t.listChatWithAgent]})]})},e.id)})]})]})}function At(e){let{a:t}=e;return(0,H.jsx)(`header`,{className:`flex flex-col gap-4`,children:(0,H.jsxs)(`div`,{className:`min-w-0`,children:[(0,H.jsx)(`h1`,{className:`text-xl font-semibold tracking-tight text-fg`,children:t.title}),(0,H.jsx)(`p`,{className:`mt-1 max-w-2xl text-sm text-fg-muted`,children:t.subtitle})]})})}function U(){return i(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,Re,`dark:border-edge`)}function jt(e,t,n){let r=e.agentId?.trim().toLowerCase();return r?r===t.toLowerCase():t.toLowerCase()===n.toLowerCase()}function Mt(e){return[e.channel,e.accountId,e.peerKind,e.peerId].filter(e=>typeof e==`string`&&e.length>0).join(` · `)||e.channel}function Nt(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 Pt(e){let{open:t,onOpenChange:n,a:r,chat:a,busy:o,modalError:s,createDisplayName:c,setCreateDisplayName:l,createAgentId:u,setCreateAgentId:d,createDescription:f,setCreateDescription:p,createWorkspace:m,setCreateWorkspace:h,createModel:g,setCreateModel:_,onCreate:v,onSuggestWorkspace:y}=e;return(0,H.jsx)(xe,{open:t,onOpenChange:n,children:(0,H.jsxs)(Ke,{children:[(0,H.jsx)(Ie,{className:`xopc-dialog-overlay fixed inset-0 z-[60] bg-scrim`}),(0,H.jsxs)(We,{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,H.jsxs)(`div`,{className:`mb-3 flex items-start justify-between gap-2`,children:[(0,H.jsxs)(`div`,{className:`min-w-0 pr-2`,children:[(0,H.jsx)(we,{className:`text-base font-semibold text-fg`,children:r.addAgent}),(0,H.jsx)(be,{className:`mt-0.5 text-xs text-fg-muted`,children:r.addAgentHint})]}),(0,H.jsx)(ze,{asChild:!0,children:(0,H.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,H.jsx)(Ce,{className:`size-4`,"aria-hidden":!0})})})]}),(0,H.jsxs)(`form`,{className:`grid gap-3`,onSubmit:v,children:[s?(0,H.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,H.jsxs)(`label`,{className:`flex flex-col gap-1 text-sm`,children:[(0,H.jsx)(`span`,{className:`text-fg-muted`,children:r.newAgentLabel}),(0,H.jsx)(`input`,{className:U(),value:c,onChange:e=>l(e.target.value),onBlur:()=>y(),required:!0,autoComplete:`off`})]}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1 text-sm`,children:[(0,H.jsx)(`span`,{className:`text-fg-muted`,children:r.newAgentIdOptional}),(0,H.jsx)(`input`,{className:i(U(),`font-mono text-xs`),value:u,onChange:e=>d(e.target.value),onBlur:()=>y(),placeholder:r.newAgentIdPlaceholder,autoComplete:`off`,spellCheck:!1,maxLength:64,pattern:`[A-Za-z0-9][A-Za-z0-9_-]{0,63}`,title:r.newAgentIdRules}),(0,H.jsx)(`span`,{className:`text-xs text-fg-muted`,children:r.newAgentIdRules})]}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1 text-sm`,children:[(0,H.jsx)(`span`,{className:`text-fg-muted`,children:r.agentDescription}),(0,H.jsx)(`textarea`,{className:i(U(),`min-h-[4.5rem] resize-y font-sans text-sm leading-relaxed`),value:f,onChange:e=>p(e.target.value),placeholder:r.agentDescriptionPlaceholder,maxLength:4e3,rows:3,spellCheck:!0})]}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1 text-sm`,children:[(0,H.jsx)(`span`,{className:`text-fg-muted`,children:r.newWorkspace}),(0,H.jsx)(`input`,{className:i(U(),`font-mono text-xs`),value:m,onChange:e=>h(e.target.value),required:!0,autoComplete:`off`})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1 text-sm`,children:[(0,H.jsx)(`span`,{className:`text-fg-muted`,children:r.newModelOptional}),(0,H.jsxs)(`div`,{className:`flex flex-wrap items-stretch gap-2`,children:[(0,H.jsx)(L,{className:`min-w-0 flex-1`,popoverContentClassName:`z-[70]`,value:g,disabled:o,placeholder:a.modelPlaceholder,searchPlaceholder:a.modelSearchPlaceholder,noMatches:a.modelNoMatches,onChange:e=>_(e)}),g.trim()?(0,H.jsx)(P,{type:`button`,variant:`secondary`,className:`shrink-0`,disabled:o,onClick:()=>_(``),children:r.modelClear}):null]})]}),(0,H.jsxs)(`div`,{className:`mt-1 flex justify-end gap-2 border-t border-edge-subtle pt-3 dark:border-edge`,children:[(0,H.jsx)(ze,{asChild:!0,children:(0,H.jsx)(P,{type:`button`,variant:`secondary`,disabled:o,children:r.createModalCancel})}),(0,H.jsxs)(P,{type:`submit`,disabled:o,children:[(0,H.jsx)(Te,{className:`mr-1 size-4`,"aria-hidden":!0}),r.create]})]})]})]})]})})}var Ft=`xopc-preset-agents-skipped`,It=[{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 Lt({existingAgentIds:e,onComplete:t,onSkip:n}){let r=s(e=>e.language),i=He(r).agentsSettings,a=(0,B.useMemo)(()=>It.filter(t=>!e.has(t.id)),[e]),[o,c]=(0,B.useState)(()=>new Set(It.map(e=>e.id))),[l,u]=(0,B.useState)(!1),[d,f]=(0,B.useState)(null),[p,m]=(0,B.useState)(null);(0,B.useEffect)(()=>{a.length===0&&t()},[a,t]);let h=e=>{c(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}u(!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 ye({name:n.name,id:n.id,workspace:`~/.xopc/workspace/${n.id}`,description:r===`zh`?n.descriptionZh:n.descriptionEn}),await ne(n.id,`IDENTITY.md`,n.identityMd),await ne(n.id,`SOUL.md`,n.soulMd);let e=n.toolsDisable;e&&e.length>0&&await Pe(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)),u(!1);return}}u(!1),t()};return a.length===0?null:(0,H.jsxs)(`div`,{className:`mx-auto flex w-full max-w-2xl flex-col items-center gap-6 px-4 py-12`,children:[(0,H.jsxs)(`div`,{className:`text-center`,children:[(0,H.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,H.jsx)(Ze,{className:`size-4`,"aria-hidden":!0}),i.presetSetupBadge]}),(0,H.jsx)(`h2`,{className:`text-xl font-semibold text-fg`,children:i.presetSetupTitle}),(0,H.jsx)(`p`,{className:`mt-2 text-sm text-fg-muted`,children:i.presetSetupSubtitle})]}),(0,H.jsx)(`div`,{className:`w-full space-y-3`,children:a.map(e=>(0,H.jsx)(Rt,{preset:e,checked:o.has(e.id),disabled:l,language:r,onToggle:()=>h(e.id)},e.id))}),p?(0,H.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&&l?(0,H.jsx)(`p`,{className:`text-sm text-fg-muted`,children:i.presetCreatingProgress.replace(`{{current}}`,String(d.current)).replace(`{{total}}`,String(d.total))}):null,(0,H.jsxs)(`div`,{className:`flex w-full items-center justify-between border-t border-edge-subtle pt-4`,children:[(0,H.jsxs)(P,{type:`button`,variant:`ghost`,className:`gap-2 text-fg-muted`,disabled:l,onClick:()=>{localStorage.setItem(Ft,`true`),n()},children:[(0,H.jsx)(le,{className:`size-4`,"aria-hidden":!0}),i.presetSkip]}),(0,H.jsxs)(P,{type:`button`,variant:`primary`,className:`gap-2`,disabled:l||o.size===0,onClick:()=>void g(),children:[(0,H.jsx)(Ze,{className:`size-4`,"aria-hidden":!0}),l?i.presetCreating:i.presetCreateSelected.replace(`{{count}}`,String(o.size))]})]})]})}function Rt(e){let{preset:t,checked:n,disabled:r,language:a,onToggle:o}=e,s=a===`zh`?t.descriptionZh:t.descriptionEn;return(0,H.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,H.jsx)(`input`,{type:`checkbox`,checked:n,disabled:r,onChange:o,className:`mt-1 shrink-0 accent-accent`}),(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(`span`,{className:`text-lg`,"aria-hidden":!0,children:t.emoji}),(0,H.jsx)(`span`,{className:`font-medium text-fg`,children:t.name})]}),(0,H.jsx)(`p`,{className:`mt-0.5 text-sm text-fg-muted`,children:s})]})]})}function zt(){return`rounded-2xl bg-surface-base px-4 py-5 sm:px-5`}function W({children:e,className:t}){return(0,H.jsx)(`section`,{className:i(zt(),t),children:e})}function G({icon:e,title:t,subtitle:n,trailing:r,className:a}){return(0,H.jsxs)(`div`,{className:i(`mb-5 flex items-start gap-3`,a),children:[(0,H.jsx)(`div`,{className:`flex size-9 shrink-0 items-center justify-center rounded-lg bg-surface-hover/90 text-fg-muted dark:bg-surface-hover/70`,"aria-hidden":!0,children:(0,H.jsx)(e,{className:`size-4`,strokeWidth:1.75})}),(0,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsx)(`h2`,{className:`text-sm font-semibold text-fg`,children:t}),(0,H.jsx)(`p`,{className:`mt-0.5 text-xs text-fg-muted`,children:n})]}),r?(0,H.jsx)(`div`,{className:`shrink-0`,children:r}):null]})}var Bt=i(ve,`w-full text-xs sm:w-auto sm:min-w-[11rem] sm:max-w-[17rem] sm:shrink-0`);function Vt(e){let{a:t,busy:n,bindingsLoading:r,agentBindings:o,onRemoveBinding:s,onAddBinding:c,channelStatuses:l,channelsStatusLoading:u,useManualChannel:d,newBindChannel:f,setNewBindChannel:p,bindSessionChats:m,sessionsLoading:h,newBindSessionIdx:g,setNewBindSessionIdx:_,newBindCustomPeer:v,setNewBindCustomPeer:y,onRefreshSessions:b,lastActiveLabels:x,selectRecipient:S}=e,ee=!u&&(d||l.length>0);return(0,H.jsxs)(W,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto`,children:[(0,H.jsx)(G,{className:`shrink-0`,icon:a,title:t.channelsTitle,subtitle:t.channelsHint}),r?(0,H.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.channelsLoading}):o.length===0?(0,H.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.channelsNone}):(0,H.jsx)(`ul`,{className:`flex flex-col gap-2 text-sm`,children:o.map((e,r)=>(0,H.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,H.jsx)(`span`,{className:`font-mono text-xs`,children:Mt(e.match)}),(0,H.jsx)(P,{type:`button`,variant:`secondary`,disabled:n,onClick:()=>void s(e),children:t.removeBinding})]},`${e.match.channel}-${r}`))}),(0,H.jsxs)(`form`,{className:`mt-4 flex flex-col gap-3`,onSubmit:c,children:[u?(0,H.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.channelsLoadingChannels}):d?(0,H.jsxs)(`label`,{className:`flex flex-col gap-1 text-sm`,children:[(0,H.jsx)(`span`,{className:`text-fg-muted`,children:t.channelLabel}),(0,H.jsx)(`input`,{className:U(),value:f,onChange:e=>p(e.target.value),placeholder:`telegram`,autoComplete:`off`}),(0,H.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.channelsManualChannelHint})]}):(0,H.jsxs)(`label`,{className:`flex flex-col gap-1 text-sm`,children:[(0,H.jsx)(`span`,{className:`text-fg-muted`,children:t.channelLabel}),(0,H.jsx)(`select`,{className:i(U(),`py-2`),value:f,onChange:e=>{p(e.target.value),_(null),y(``)},children:l.map(e=>(0,H.jsxs)(`option`,{value:e.name,disabled:!e.enabled,children:[e.name,` `,e.enabled?``:t.channelsDisabledSuffix]},e.name))})]}),ee&&f.trim()?(0,H.jsxs)(`div`,{className:`flex flex-col gap-2 border-t border-edge-subtle pt-3 text-sm`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,H.jsx)(`span`,{className:`text-fg-muted`,children:t.channelsSessionLabel}),(0,H.jsxs)(P,{type:`button`,variant:`ghost`,className:`h-7 gap-1 px-2 text-xs`,disabled:n||h||!f.trim(),title:t.channelsRefreshSessionsHint,onClick:()=>b(),children:[(0,H.jsx)(re,{className:i(`size-3.5`,h&&`animate-spin`),strokeWidth:1.75}),t.channelsRefreshSessions]})]}),h&&m.length===0?(0,H.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.channelsLoadingSessions}):null,(0,H.jsxs)(`label`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`span`,{className:`text-fg-muted`,children:t.channelsPeerFromSessions}),(0,H.jsxs)(`select`,{className:i(U(),`py-2`),value:g==null?``:String(g),disabled:n||!f.trim()||!!v.trim(),onChange:e=>{let t=e.target.value;_(t===``?null:Number(t))},children:[(0,H.jsx)(`option`,{value:``,children:t.channelsPeerAny}),m.map((e,t)=>(0,H.jsx)(`option`,{value:String(t),children:rt(e,x)},`${e.channel}-${e.chatId}-${t}`))]})]}),m.length===0&&f.trim()&&!h?(0,H.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.channelsNoSessionsHint}):null,(0,H.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,H.jsx)(`span`,{className:`text-fg-muted`,children:t.peerIdLabel}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-stretch sm:gap-2`,children:[(0,H.jsx)(`input`,{type:`text`,className:i(U(),`min-w-0 w-full sm:flex-1`),value:v,onChange:e=>{y(e.target.value),e.target.value.trim()&&_(null)},placeholder:t.channelsCustomPeerPlaceholder,autoComplete:`off`}),(0,H.jsxs)(`select`,{className:Bt,value:v,onChange:e=>{let t=e.target.value;y(t||``),_(null)},children:[(0,H.jsx)(`option`,{value:``,children:S}),m.map(e=>(0,H.jsx)(`option`,{value:e.chatId,children:rt(e,x)},`${e.channel}-${e.chatId}`))]})]}),(0,H.jsx)(`p`,{className:`text-xs text-fg-muted`,children:t.channelsCustomPeerHint})]})]}):null,(0,H.jsx)(`div`,{children:(0,H.jsx)(P,{type:`submit`,disabled:n||!f.trim()||u,children:t.addBinding})})]})]})}function Ht(e){let{a:t,data:n,busy:r,cronLoading:a,agentCronJobs:o,onSetCronJobAgent:s}=e;return(0,H.jsxs)(W,{className:`flex min-h-0 flex-1 flex-col overflow-y-auto`,children:[(0,H.jsx)(G,{className:`shrink-0`,icon:w,title:t.cronTitle,subtitle:t.cronHint}),a?(0,H.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.cronLoading}):o.length===0?(0,H.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.cronNone}):(0,H.jsx)(`div`,{className:`overflow-x-auto`,children:(0,H.jsxs)(`table`,{className:`w-full min-w-[32rem] border-collapse text-left text-sm`,children:[(0,H.jsx)(`thead`,{children:(0,H.jsxs)(`tr`,{className:`border-b border-edge text-fg-muted`,children:[(0,H.jsx)(`th`,{className:`py-2 pr-3 font-medium`,children:t.cronColSchedule}),(0,H.jsx)(`th`,{className:`py-2 pr-3 font-medium`,children:t.cronColMessage}),(0,H.jsx)(`th`,{className:`py-2 pr-3 font-medium`,children:t.cronColSession}),(0,H.jsx)(`th`,{className:`py-2 pr-3 font-medium`,children:t.cronColAgent})]})}),(0,H.jsx)(`tbody`,{children:o.map(e=>{let a=!e.agentId?.trim(),o=a?``:e.agentId.trim().toLowerCase();return(0,H.jsxs)(`tr`,{className:`border-b border-edge-subtle`,children:[(0,H.jsx)(`td`,{className:`py-2 pr-3 font-mono text-xs`,children:e.schedule}),(0,H.jsx)(`td`,{className:`max-w-[12rem] truncate py-2 pr-3 text-xs`,title:it(e),children:it(e)}),(0,H.jsx)(`td`,{className:`py-2 pr-3 text-xs`,children:e.sessionTarget??`main`}),(0,H.jsx)(`td`,{className:`py-2 pr-3`,children:(0,H.jsxs)(`select`,{className:i(U(),`min-w-[8rem] py-1 text-xs`),value:o,disabled:r||e.sessionTarget!==`isolated`,onChange:t=>void s(e,t.target.value),children:[(0,H.jsx)(`option`,{value:``,children:a?t.cronAgentDefault:t.cronAgentClear}),n.agents.map(e=>(0,H.jsx)(`option`,{value:e.id,children:e.id},e.id))]})})]},e.id)})})]})})]})}function Ut(e){let{a:t,filesLoading:n,files:r,activeFile:a,setActiveFile:o,bootstrapViewMode:s,setBootstrapViewMode:c,fileDraft:l,setFileDraft:u,fileSaving:f,bootstrapFileLoading:p,bootstrapEditorNonce:m}=e,h=ae(e=>e.resolved===`dark`);return(0,H.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-4 overflow-hidden`,children:[(0,H.jsx)(`p`,{className:`shrink-0 text-sm text-fg-muted`,children:t.filesHint}),n?(0,H.jsx)(`p`,{className:`shrink-0 text-sm text-fg-muted`,children:t.filesLoading}):r?(0,H.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-3 overflow-hidden`,children:[(0,H.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,H.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,H.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col gap-2 overflow-hidden`,children:a?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-between gap-2`,children:[(0,H.jsxs)(`div`,{className:`inline-flex rounded-lg border border-edge bg-surface-panel p-0.5`,role:`group`,"aria-label":t.filesBootstrapEdit,children:[(0,H.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`,s===`edit`?`bg-accent-soft text-accent-fg`:`text-fg-muted hover:bg-surface-hover`),onClick:()=>c(`edit`),children:[(0,H.jsx)(d,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),t.filesBootstrapEdit]}),(0,H.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`,s===`preview`?`bg-accent-soft text-accent-fg`:`text-fg-muted hover:bg-surface-hover`),onClick:()=>c(`preview`),children:[(0,H.jsx)(ge,{className:`size-3.5 shrink-0`,"aria-hidden":!0}),t.filesBootstrapPreview]})]}),(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 text-xs text-fg-muted`,children:[f?(0,H.jsx)(`span`,{children:t.filesSavingStatus}):null,(0,H.jsx)(`span`,{children:t.filesAutoSaveHint})]})]}),s===`edit`?(0,H.jsx)(`div`,{className:i(U(),`flex min-h-0 flex-1 flex-col overflow-hidden p-0`,p&&`pointer-events-none opacity-60`),children:(0,H.jsx)(A,{initialContent:l,onChange:u,isDark:h,className:`min-h-0 flex-1`},`${a??`file`}-${m}`)}):(0,H.jsx)(`div`,{className:i(U(),`min-h-0 flex-1 overflow-y-auto text-sm`,p&&`pointer-events-none opacity-60`),children:(0,H.jsx)(ue,{content:l,className:`text-sm`})})]}):(0,H.jsx)(`p`,{className:`shrink-0 text-sm text-fg-muted`,children:t.pickFile})})]}):(0,H.jsx)(`p`,{className:`shrink-0 text-sm text-fg-muted`,children:t.filesEmpty})]})}var Wt={name:``,creature:``,emoji:``,avatar:``};function Gt(e){let t={...Wt};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 Kt(e){return[`# IDENTITY.md - Who Am I?`,``,`- **Name:** ${e.name}`,`- **Creature:** ${e.creature}`,`- **Emoji:** ${e.emoji}`,`- **Avatar:** ${e.avatar}`,``].join(`
148
+ `)}var qt={callName:``,pronouns:``,timezone:``,notes:``};function Jt(e){let t={...qt};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 K(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 Yt=[{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 Xt(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 Zt(e){let t=Xt(e).trim();if(!t)return`professional`;for(let e of Yt)if(e.id!==`custom`&&(t===e.content.trim()||Qt(e.id).filter(e=>t.includes(e)).length>=2))return e.id;return`custom`}function Qt(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 $t=[{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 en(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{return``}}var tn=[{value:`先生`,labelEn:`Mr.`,labelZh:`先生`},{value:`女士`,labelEn:`Ms.`,labelZh:`女士`},{value:`同学`,labelEn:`Colleague`,labelZh:`同学`},{value:`老师`,labelEn:`Teacher`,labelZh:`老师`},{value:`老板`,labelEn:`Boss`,labelZh:`老板`},{value:`朋友`,labelEn:`Friend`,labelZh:`朋友`}],nn=[{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 rn(e){let{a:t,chat:n,selected:r,busy:a,editName:o,setEditName:c,editDescription:l,setEditDescription:u,editWorkspace:d,setEditWorkspace:f,editModel:p,setEditModel:m,onSetDefault:h,onSaveAgentEdits:g,onDelete:_,hideInlineSave:v,saveBootstrapRef:y,onBootstrapDirtyChange:x}=e,S=s(e=>e.language),ee=ae(e=>e.resolved===`dark`),[C,w]=(0,B.useState)(!0),[,T]=(0,B.useState)(!1),[E,te]=(0,B.useState)({name:``,creature:``,emoji:``,avatar:``}),[re,D]=(0,B.useState)(`professional`),[ie,O]=(0,B.useState)(``),[oe,ce]=(0,B.useState)(0),[le,de]=(0,B.useState)(!1),fe=(0,B.useRef)(!1),j=(0,B.useRef)(r?.id??``);j.current=r?.id??``;let pe=(0,B.useRef)(``),me=(0,B.useRef)(``);(0,B.useEffect)(()=>{if(!r)return;let e=!1;return fe.current=!1,w(!0),(async()=>{try{let[t,n]=await Promise.all([se(r.id,`IDENTITY.md`).catch(()=>``),se(r.id,`SOUL.md`).catch(()=>``)]);if(e)return;let i=Gt(t);te(i),pe.current=JSON.stringify(i),D(Zt(n)),O(n),me.current=n,ce(e=>e+1)}finally{e||(w(!1),fe.current=!0)}})(),()=>{e=!0}},[r?.id]);let he=(0,B.useCallback)(async(e,t)=>{T(!0);try{await ne(j.current,e,t)}finally{T(!1)}},[]),_e=(0,B.useRef)(E);_e.current=E;let ve=(0,B.useRef)(ie);ve.current=ie,(0,B.useEffect)(()=>{if(y)return y.current=async()=>{await Promise.all([he(`IDENTITY.md`,Kt(_e.current)),he(`SOUL.md`,ve.current)]),pe.current=JSON.stringify(_e.current),me.current=ve.current,x?.(!1)},()=>{y.current=null}},[y,he,x]),(0,B.useEffect)(()=>{if(!x)return;let e=JSON.stringify(E)!==pe.current,t=ie!==me.current;x(e||t)},[E,ie,x]);let N=(0,B.useCallback)(e=>{te(t=>({...t,...e}))},[]),ye=(0,B.useCallback)(e=>{if(D(e),e!==`custom`){let t=Yt.find(t=>t.id===e);t?.content&&(O(t.content),ce(e=>e+1))}},[]),be=(0,B.useCallback)(e=>{O(e),D(`custom`)},[]),F=(0,B.useCallback)((e,t)=>S===`zh`?t:e,[S]),I=U();return r?(0,H.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-8 overflow-y-auto`,children:[(0,H.jsxs)(W,{children:[(0,H.jsx)(G,{icon:Ze,title:t.personaSectionIdentity,subtitle:t.personaSectionIdentityHint,trailing:r.isDefault?null:(0,H.jsx)(P,{type:`button`,variant:`secondary`,className:`text-xs`,disabled:a,onClick:()=>void h(),children:t.setDefault})}),(0,H.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,H.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,H.jsx)(`span`,{className:`font-medium text-fg`,children:t.displayName}),(0,H.jsx)(`input`,{className:I,value:o,onChange:e=>{c(e.target.value),N({name:e.target.value})},placeholder:t.personaNamePlaceholder,autoComplete:`off`})]}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,H.jsx)(`span`,{className:`font-medium text-fg`,children:t.personaEmoji}),(0,H.jsx)(`input`,{className:I,value:E.emoji,onChange:e=>N({emoji:e.target.value}),placeholder:t.personaEmojiPlaceholder,autoComplete:`off`})]}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm sm:col-span-2`,children:[(0,H.jsx)(`span`,{className:`font-medium text-fg`,children:t.agentDescription}),(0,H.jsx)(`textarea`,{className:i(I,`min-h-16 resize-y text-sm leading-relaxed`),value:l,onChange:e=>u(e.target.value),placeholder:t.agentDescriptionPlaceholder,maxLength:4e3,rows:3,spellCheck:!0})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,H.jsx)(`span`,{className:`font-medium text-fg`,children:t.personaCreature}),(0,H.jsxs)(`select`,{className:I,value:nn.some(e=>e.value===E.creature)?E.creature:`__custom__`,onChange:e=>{if(e.target.value===`__custom__`){N({creature:``});return}N({creature:e.target.value})},children:[nn.map(e=>(0,H.jsx)(`option`,{value:e.value,children:F(e.labelEn,e.labelZh)},e.value)),(0,H.jsx)(`option`,{value:`__custom__`,children:F(`Custom…`,`自定义…`)})]}),nn.some(e=>e.value===E.creature)?null:(0,H.jsx)(`input`,{className:i(I,`mt-1 text-xs`),value:E.creature,onChange:e=>N({creature:e.target.value}),placeholder:t.personaCreaturePlaceholder,autoComplete:`off`})]}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm sm:col-span-2`,children:[(0,H.jsx)(`span`,{className:`font-medium text-fg`,children:t.personaAvatar}),(0,H.jsx)(`input`,{className:i(I,`font-mono text-xs`),value:E.avatar,onChange:e=>N({avatar:e.target.value}),placeholder:t.personaAvatarPlaceholder,autoComplete:`off`})]})]})]}),(0,H.jsxs)(W,{children:[(0,H.jsx)(G,{icon:k,title:t.editAgent,subtitle:t.editAgentHint}),(0,H.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5 text-sm sm:col-span-2`,children:[(0,H.jsx)(`span`,{className:`font-medium text-fg`,children:t.modelPrimary}),(0,H.jsxs)(`div`,{className:`flex flex-wrap items-stretch gap-2`,children:[(0,H.jsx)(L,{className:`min-w-0 flex-1`,popoverContentClassName:`z-[70]`,value:p,disabled:a,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,onChange:e=>m(e)}),p.trim()?(0,H.jsx)(P,{type:`button`,variant:`secondary`,className:`shrink-0`,disabled:a,onClick:()=>m(``),children:t.modelClear}):null]})]}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm sm:col-span-2`,children:[(0,H.jsx)(`span`,{className:`font-medium text-fg`,children:t.workspacePath}),(0,H.jsx)(`input`,{className:i(I,`font-mono text-xs`),value:d,onChange:e=>f(e.target.value)})]})]}),v?null:(0,H.jsx)(`div`,{className:`mt-4`,children:(0,H.jsx)(P,{type:`button`,disabled:a,onClick:()=>void g(),children:t.save})})]}),C?(0,H.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.loading}):(0,H.jsxs)(W,{children:[(0,H.jsx)(G,{icon:De,title:t.personaSectionSoul,subtitle:t.personaSectionSoulHint}),(0,H.jsxs)(`div`,{className:`mb-4 flex flex-col gap-2`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:t.personaSoulTemplate}),(0,H.jsx)(`div`,{className:`grid grid-cols-2 gap-2 sm:grid-cols-4`,children:Yt.map(e=>(0,H.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`,re===e.id?`border-accent bg-accent-soft/40 shadow-sm`:`border-edge hover:border-accent/40 hover:bg-surface-hover`),onClick:()=>ye(e.id),children:[(0,H.jsx)(`span`,{className:`text-xl`,children:e.emoji}),(0,H.jsx)(`span`,{className:`text-xs font-medium text-fg`,children:F(e.labelEn,e.labelZh)})]},e.id))})]}),re===`custom`?(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,H.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,H.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:t.personaSoulCustomEdit}),(0,H.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:le?t.personaSoulEdit:t.personaSoulPreview,"aria-label":le?t.personaSoulEdit:t.personaSoulPreview,onClick:()=>de(e=>!e),children:le?(0,H.jsx)(b,{className:`size-4`,"aria-hidden":!0}):(0,H.jsx)(ge,{className:`size-4`,"aria-hidden":!0})})]}),(0,H.jsx)(`div`,{className:i(I,`flex min-h-64 flex-col overflow-hidden p-0`),children:le?(0,H.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-4 py-3`,children:(0,H.jsx)(ue,{content:ie})}):(0,H.jsx)(A,{initialContent:ie,onChange:be,isDark:ee,className:`min-h-0 flex-1`},`soul-${oe}`)})]}):null]}),r.id===`main`?null:(0,H.jsxs)(W,{children:[(0,H.jsx)(G,{icon:M,title:F(`Danger Zone`,`危险操作`),subtitle:F(`Actions that cannot be undone. Be careful.`,`以下操作不可撤销,请谨慎操作。`)}),(0,H.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,H.jsxs)(P,{type:`button`,variant:`secondary`,disabled:a,onClick:()=>void _(!1),children:[(0,H.jsx)(Je,{className:`mr-1 size-4`,"aria-hidden":!0}),t.removeFromConfig]}),(0,H.jsx)(P,{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 _(!0),children:t.purgeDisk})]})]})]}):(0,H.jsx)(`p`,{className:`text-sm text-fg-muted`,children:t.selectAgentHint})}function an({a:e,agentId:t,saveRef:n,onDirtyChange:r}){let a=s(e=>e.language),[o,c]=(0,B.useState)(!0),[,u]=(0,B.useState)(!1),[d,f]=(0,B.useState)({callName:``,pronouns:``,timezone:``,notes:``}),[p,m]=(0,B.useState)(!1),[h,g]=(0,B.useState)(!1),[_,v]=(0,B.useState)(``),y=(0,B.useRef)(!1),b=(0,B.useRef)(t);b.current=t;let x=(0,B.useRef)(``),S=(0,B.useCallback)(async e=>{let t=b.current;u(!0);try{await ne(t,`USER.md`,e)}finally{u(!1)}},[]),ee=(0,B.useRef)(d);ee.current=d,(0,B.useEffect)(()=>{if(n)return n.current=async()=>{await S(K(ee.current)),x.current=JSON.stringify(ee.current),r?.(!1)},()=>{n.current=null}},[n,S,r]),(0,B.useEffect)(()=>{r&&r(JSON.stringify(d)!==x.current)},[d,r]),(0,B.useEffect)(()=>{let e=!1;return y.current=!1,c(!0),(async()=>{try{let n=await se(t,`USER.md`).catch(()=>``);if(e)return;let r=Jt(n),i=r;if(!r.timezone){let e=en();e&&(i={...r,timezone:e})}f(i),x.current=JSON.stringify(i);let a=!i.pronouns||tn.some(e=>e.value===i.pronouns);i.pronouns&&!a&&m(!0);let o=$t.some(e=>e.value===i.timezone);i.timezone&&!o&&(g(!0),v(i.timezone))}finally{e||(c(!1),y.current=!0)}})(),()=>{e=!0}},[t]);let C=(0,B.useCallback)(e=>{f(t=>({...t,...e}))},[]),w=(0,B.useCallback)(e=>{if(e===`__custom__`){g(!0);return}g(!1),v(``),C({timezone:e})},[C]),T=(0,B.useCallback)(e=>{v(e),C({timezone:e})},[C]),E=(0,B.useCallback)(()=>{let e=en();e&&($t.some(t=>t.value===e)?(g(!1),v(``)):(g(!0),v(e)),C({timezone:e}))},[C]),te=h?`__custom__`:$t.some(e=>e.value===d.timezone)?d.timezone:`__custom__`,re=(0,B.useCallback)((e,t)=>a===`zh`?t:e,[a]);if(o)return(0,H.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.loading});let D=U();return(0,H.jsxs)(`div`,{className:`flex min-h-0 flex-1 flex-col gap-6 overflow-y-auto`,children:[(0,H.jsx)(`p`,{className:`text-sm text-fg-muted`,children:e.personaSectionUserHint}),(0,H.jsxs)(W,{children:[(0,H.jsx)(G,{icon:l,title:e.personaSectionUser,subtitle:e.personaSectionUserHint}),(0,H.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,H.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,H.jsx)(`span`,{className:`font-medium text-fg`,children:e.personaCallName}),(0,H.jsx)(`input`,{className:D,value:d.callName,onChange:e=>C({callName:e.target.value}),placeholder:e.personaCallNamePlaceholder,autoComplete:`off`})]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5 text-sm`,children:[(0,H.jsx)(`span`,{className:`font-medium text-fg`,children:e.personaPronouns}),(0,H.jsxs)(`select`,{className:D,value:tn.some(e=>e.value===d.pronouns)?d.pronouns:`__custom__`,onChange:e=>{if(e.target.value===`__custom__`){m(!0);return}m(!1),C({pronouns:e.target.value})},children:[(0,H.jsx)(`option`,{value:``,disabled:!0,children:e.personaPronounsPlaceholder}),tn.map(e=>(0,H.jsx)(`option`,{value:e.value,children:re(e.labelEn,e.labelZh)},e.value)),(0,H.jsx)(`option`,{value:`__custom__`,children:re(`Custom…`,`自定义…`)})]}),p?(0,H.jsx)(`input`,{className:i(D,`mt-1 text-xs`),value:tn.some(e=>e.value===d.pronouns)?``:d.pronouns,onChange:e=>C({pronouns:e.target.value}),placeholder:e.personaPronounsPlaceholder,autoComplete:`off`}):null]}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5 text-sm sm:col-span-2`,children:[(0,H.jsx)(`span`,{className:`font-medium text-fg`,children:e.personaTimezone}),(0,H.jsxs)(`div`,{className:`flex flex-wrap items-stretch gap-2`,children:[(0,H.jsxs)(`select`,{className:i(D,`min-w-0 flex-1`),value:te,onChange:e=>w(e.target.value),children:[$t.map(e=>(0,H.jsx)(`option`,{value:e.value,children:re(e.labelEn,e.labelZh)},e.value)),(0,H.jsx)(`option`,{value:`__custom__`,children:e.personaTimezoneCustom})]}),(0,H.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:E,children:e.personaTimezoneDetect})]}),h?(0,H.jsx)(`input`,{className:i(D,`mt-1 font-mono text-xs`),value:_,onChange:e=>T(e.target.value),placeholder:`e.g. Asia/Shanghai`,autoComplete:`off`}):null]}),(0,H.jsxs)(`label`,{className:`flex flex-col gap-1.5 text-sm sm:col-span-2`,children:[(0,H.jsx)(`span`,{className:`font-medium text-fg`,children:e.personaNotes}),(0,H.jsx)(`textarea`,{className:i(D,`min-h-16 resize-y text-sm leading-relaxed`),value:d.notes,onChange:e=>C({notes:e.target.value}),placeholder:e.personaNotesPlaceholder,rows:3,spellCheck:!0})]})]}),(0,H.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,H.jsx)(Ue,{className:`mt-0.5 size-3.5 shrink-0 text-accent`,"aria-hidden":!0}),(0,H.jsx)(`span`,{children:e.personaMemoryNote})]})]})]})}function on(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,H.jsxs)(W,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,H.jsx)(G,{className:`shrink-0`,icon:x,title:t.skillsTitle,subtitle:t.skillsHint}),(0,H.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-between gap-3`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,H.jsx)(P,{type:`button`,variant:`secondary`,disabled:r,onClick:()=>c(!0),children:t.skillsInherit}),(0,H.jsx)(P,{type:`button`,variant:`secondary`,disabled:r,onClick:()=>{c(!1),u(m())},children:t.skillsCustomize})]}),(0,H.jsx)(S,{to:pe(`skills`),className:`shrink-0 text-xs font-medium text-accent-fg hover:underline`,children:t.skillsLibraryLink})]}),(0,H.jsxs)(`p`,{className:`mt-2 shrink-0 text-xs text-fg-muted`,children:[t.skillsDefaultsLabel,` `,n.skills.defaults.length?n.skills.defaults.join(`, `):`—`]}),(0,H.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,H.jsx)(`p`,{className:`shrink-0 text-sm text-fg-muted`,children:t.skillsCatalogLoading}):o.length===0?(0,H.jsx)(`p`,{className:`shrink-0 text-sm text-fg-muted`,children:t.skillsEmptyCatalog}):(0,H.jsx)(`div`,{className:i(`mt-3 min-h-0 flex-1 overflow-y-auto overscroll-contain pr-0.5`,s&&`opacity-50`),children:(0,H.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,H.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,H.jsxs)(`label`,{className:`flex h-full cursor-pointer items-center gap-3 text-sm`,children:[(0,H.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,H.jsxs)(`div`,{className:`min-w-0 flex-1 overflow-hidden`,children:[(0,H.jsx)(`div`,{className:`truncate font-mono text-xs font-medium text-fg`,title:n,children:n}),(0,H.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,H.jsx)(`div`,{className:`mt-4 shrink-0`,children:(0,H.jsx)(P,{type:`button`,disabled:r,onClick:()=>void d(),children:t.skillsSave})})]})}function sn(e){let{a:t,data:n,selected:r,busy:a,toolEntryDisable:o,setToolEntryDisable:s,onSaveTools:c,onClearToolsEntry:l,hideInlineSave:u}=e;return(0,H.jsxs)(W,{className:`flex min-h-0 flex-1 flex-col`,children:[(0,H.jsx)(G,{className:`shrink-0`,icon:R,title:t.toolsTitle,subtitle:t.toolsHint}),(0,H.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto overscroll-contain`,children:(0,H.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,H.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,H.jsxs)(`label`,{className:i(`flex cursor-pointer gap-3 text-sm`,n&&`cursor-not-allowed`),children:[(0,H.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,H.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,H.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-0.5`,children:[(0,H.jsx)(`span`,{className:`font-mono text-xs font-medium text-fg`,children:e}),n?(0,H.jsxs)(`span`,{className:`text-xs text-fg-muted`,children:[`(`,t.toolsLockedByDefaults,`)`]}):null]}),l?(0,H.jsx)(`p`,{className:`mt-1 text-xs leading-relaxed text-fg-muted`,children:l}):null]})]})},e)})})}),(0,H.jsxs)(`div`,{className:`mt-4 flex shrink-0 flex-wrap gap-2`,children:[u?null:(0,H.jsx)(P,{type:`button`,disabled:a,onClick:()=>void c(),children:t.toolsSave}),(0,H.jsx)(P,{type:`button`,variant:`secondary`,disabled:a,onClick:()=>void l(),children:t.toolsClearEntry})]})]})}function cn(){let e=s(e=>e.language),t=He(e),n=t.agentsSettings,[a,c]=(0,B.useState)(!1),[l,d]=(0,B.useState)(null),[f,m]=(0,B.useState)(!1),[g,_]=(0,B.useState)(``),v=t.cron,y=t.chat,b=!!ee(e=>e.token),[x]=o(),S=me(),{agentId:w}=ie(),T=Be(e=>e.setPageHeader),te=Be(e=>e.clearPageHeader),{data:re,error:D,isLoading:ae,mutate:O}=r(b?`settings-gateway-agents`:null,Xe,{revalidateOnFocus:!1}),{data:oe}=Me(b),le=(0,B.useMemo)(()=>h(oe?.payload?.config??{}),[oe]),k=re??null,ue=!!(b&&ae),[de,A]=(0,B.useState)(null),j=D instanceof Error?D.message:D?n.loadError:null,pe=de??j,[M,ge]=(0,B.useState)(null),[_e,ve]=(0,B.useState)(!1),[N,F]=(0,B.useState)(`overview`),[I,Se]=(0,B.useState)(``),[L,Ce]=(0,B.useState)(``),[Te,Ee]=(0,B.useState)(``),[De,Oe]=(0,B.useState)(``),[ke,Ae]=(0,B.useState)(``),[je,Fe]=(0,B.useState)(null),[Le,Re]=(0,B.useState)(!1),ze=(0,B.useRef)(``),[R,z]=(0,B.useState)(!1),[Ve,Ue]=(0,B.useState)(!1),[Ge,Je]=(0,B.useState)(``),[Ye,Ze]=(0,B.useState)(``),[et,tt]=(0,B.useState)(``),[rt,it]=(0,B.useState)(``),[ct,lt]=(0,B.useState)(``),[ut,dt]=(0,B.useState)(null),[ft,pt]=(0,B.useState)(!1),[V,mt]=(0,B.useState)(null),[_t,vt]=(0,B.useState)(``),[yt,xt]=(0,B.useState)(!1),[St,Ct]=(0,B.useState)(`edit`),[wt,Tt]=(0,B.useState)(!1),[Dt,Ot]=(0,B.useState)(0),U=(0,B.useRef)(_t);U.current=_t;let Mt=(0,B.useRef)(M);Mt.current=M;let It=(0,B.useRef)(V);It.current=V;let Rt=(0,B.useRef)(null),zt=(0,B.useRef)(null),[W,G]=(0,B.useState)(!1),[Bt,Wt]=(0,B.useState)(!1),[Gt,Kt]=(0,B.useState)(!1),qt=(0,B.useRef)(``),Jt=(0,B.useRef)(``),K=C(async()=>{let e=Mt.current,t=It.current;if(!e||!t||`${e}:${t}`!==qt.current)return;let r=U.current;if(r!==Jt.current){xt(!0),A(null);try{await ne(e,t,r),Jt.current=r,dt(n=>!n||n.agentId!==e?n:{...n,files:n.files.map(e=>e.name===t?{...e,missing:!1}:e)})}catch(e){A(e instanceof Error?e.message:n.saveError)}finally{xt(!1)}}},800),Yt=(0,B.useRef)(K.flush);Yt.current=K.flush,(0,B.useEffect)(()=>()=>{Yt.current()},[]);let[Xt,Zt]=(0,B.useState)(()=>new Set),[Qt,$t]=(0,B.useState)(()=>new Set),[en,tn]=(0,B.useState)(!0),[nn,cn]=(0,B.useState)([]),[q,ln]=(0,B.useState)(``),[J,un]=(0,B.useState)([]),[Y,dn]=(0,B.useState)(!1),[fn,pn]=(0,B.useState)([]),[mn,hn]=(0,B.useState)(!1),[gn,_n]=(0,B.useState)(null),[vn,yn]=(0,B.useState)(``),[bn,xn]=(0,B.useState)([]),[Sn,Cn]=(0,B.useState)(!1),[wn,Tn]=(0,B.useState)([]),[En,Dn]=(0,B.useState)(!1);(0,B.useEffect)(()=>{if(k){if(w&&k.agents.some(e=>e.id===w)){ge(w);return}ge(e=>e&&k.agents.some(t=>t.id===e)?e:k.defaultId)}},[k,w]),(0,B.useEffect)(()=>{if(!k||ue)return;let e=k.agents.length<=1&&k.agents.every(e=>e.id===k.defaultId),t=localStorage.getItem(Ft)===`true`;ve(e&&!t)},[k,ue]);let On=(0,B.useCallback)(()=>{ve(!1),O()},[O]),X=(0,B.useCallback)(()=>{ve(!1)},[]);(0,B.useEffect)(()=>{!k||!w||k.agents.some(e=>e.id===w)||S(qe,{replace:!0})},[k,w,S]),(0,B.useEffect)(()=>{w&&F(`overview`)},[w]),(0,B.useEffect)(()=>{x.get(`panel`)===`defaults`&&S(`/settings/agent-defaults`,{replace:!0,state:{[he]:qe}})},[x,S]);let Z=(0,B.useMemo)(()=>k?.agents.find(e=>e.id===M)??null,[k,M]),Q=(0,B.useMemo)(()=>Z?nn.filter(e=>e.agentId.toLowerCase()===Z.id.toLowerCase()):[],[nn,Z?.id]),kn=(0,B.useMemo)(()=>!k||!Z?[]:bn.filter(e=>jt(e,Z.id,k.defaultId)),[bn,k,Z?.id]),An=(0,B.useMemo)(()=>wn.filter(e=>e.enabled!==!1),[wn]);(0,B.useEffect)(()=>{if(!Z){Ze(``),tt(``),it(``),lt(``);return}Ze(Z.workspace),tt(Z.model?.primary??``),it(Z.name?.trim()?Z.name.trim():Z.id),lt(Z.description?.trim()??``)},[Z?.id]),(0,B.useEffect)(()=>{if(N!==`files`||!M||!b)return;let e=!1;return pt(!0),u(M).then(t=>{e||dt(t)}).catch(()=>{e||dt(null)}).finally(()=>{e||pt(!1)}),()=>{e=!0}},[N,M,b,k?.agents.length]),(0,B.useEffect)(()=>{!Z||N!==`tools`||Zt(new Set(Z.tools.entryDisable))},[N,Z]),(0,B.useEffect)(()=>{if(!Z||N!==`skills`)return;let e=Z.skills.entry===void 0;if(tn(e),e){let e=Z.skills.effectiveAllowlist;$t(new Set(e??[]))}else $t(new Set(Z.skills.entry??[]))},[N,Z]),(0,B.useEffect)(()=>{N!==`channels`||!b||cn(le)},[N,b,le]),(0,B.useEffect)(()=>{if(N!==`channels`||!b)return;let e=!1;return dn(!0),at().then(t=>{e||un(t)}).catch(()=>{e||un([])}).finally(()=>{e||dn(!1)}),()=>{e=!0}},[N,b]),(0,B.useEffect)(()=>{Y||N!==`channels`||J.length===0||ln(e=>e&&J.some(t=>t.name===e)?e:J[0].name)},[Y,N,J]),(0,B.useEffect)(()=>{if(N!==`channels`||!b)return;let e=q.trim();if(!e){pn([]);return}let t=!1;return _n(null),hn(!0),ot(e).then(e=>{t||pn(e)}).catch(()=>{t||pn([])}).finally(()=>{t||hn(!1)}),()=>{t=!0}},[N,b,q]);let jn=(0,B.useCallback)(()=>{let e=q.trim();e&&(hn(!0),ot(e).then(e=>{pn(e),_n(t=>t!=null&&t<e.length?t:null)}).catch(()=>{pn([]),_n(null)}).finally(()=>{hn(!1)}))},[q]),Mn=!Y&&J.length===0,Nn=N===`channels`&&b&&oe===void 0;(0,B.useEffect)(()=>{if(N!==`cron`||!b)return;let e=!1;return Cn(!0),st().then(t=>{e||xn(t)}).catch(()=>{e||xn([])}).finally(()=>{e||Cn(!1)}),()=>{e=!0}},[N,b]),(0,B.useEffect)(()=>{if(N!==`skills`||!b)return;let e=!1;return Dn(!0),ce().then(t=>{e||Tn(t)}).catch(()=>{e||Tn([])}).finally(()=>{e||Dn(!1)}),()=>{e=!0}},[N,b]),(0,B.useEffect)(()=>{if(!V||!M||!b)return;let e=!1;return K.flush(),Tt(!0),se(M,V).then(t=>{e||(qt.current=`${M}:${V}`,Jt.current=t,vt(t),Ot(e=>e+1))}).catch(()=>{e||(qt.current=`${M}:${V}`,Jt.current=``,vt(``),Ot(e=>e+1))}).finally(()=>{e||Tt(!1)}),()=>{e=!0}},[V,M,b,K]),(0,B.useEffect)(()=>{!V||!M||wt||K()},[_t,V,M,wt,K]),(0,B.useEffect)(()=>{if(N===`files`)return()=>{K.flush()}},[N,K]),(0,B.useEffect)(()=>{Ct(`edit`)},[V,M]);let Pn=(0,B.useCallback)(()=>{let e=gt(L.trim()||I);Oe(t=>t===``||t===ze.current?(ze.current=e,e):t)},[L,I]),Fn=(0,B.useCallback)(()=>{ze.current=``,Se(``),Ce(``),Ee(``),Oe(``),Ae(``),Fe(null),Re(!0)},[]),$=(0,B.useCallback)(e=>new Promise(t=>window.setTimeout(t,e)),[]),In=(0,B.useCallback)(async()=>{if(Ve||R)return;Ue(!0),A(null);let e=[`light`,`deep`,`rem`];try{(async()=>{for(let t of e)try{await bt(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 $(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){A(e instanceof Error?e.message:n.saveError)}finally{Ue(!1)}},[n.saveError,R,Ve,$]),Ln=(0,B.useMemo)(()=>(0,H.jsxs)(`div`,{className:`flex min-w-0 flex-1 flex-wrap items-center justify-end gap-2`,children:[(0,H.jsxs)(P,{type:`button`,variant:`secondary`,className:`shrink-0 gap-2`,disabled:R||Ve,onClick:()=>void In(),"aria-label":e===`zh`?`让智能体进入睡眠流程`:`Trigger agent sleep sequence`,title:e===`zh`?`由浅入深:Light → Deep → REM`:`Light → Deep → REM`,children:[(0,H.jsx)(fe,{className:`size-4 shrink-0`,strokeWidth:1.75,"aria-hidden":!0}),e===`zh`?Ve?`睡眠中…`:`睡眠`:Ve?`Sleeping…`:`Sleep`]}),(0,H.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,H.jsx)(Ne,{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,H.jsx)(`input`,{type:`search`,role:`searchbox`,enterKeyHint:`search`,value:Ge,onChange:e=>Je(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,H.jsxs)(P,{type:`button`,variant:`primary`,className:`shrink-0 gap-2`,"aria-label":n.addAgentAria,disabled:R,onClick:()=>Fn(),children:[(0,H.jsx)(E,{className:`size-4`,strokeWidth:1.75,"aria-hidden":!0}),n.addAgent]})]}),[n.addAgent,n.addAgentAria,n.listSearchPlaceholder,R,Ge,Fn,Ve,In,e]);(0,B.useLayoutEffect)(()=>b?(T({startExtra:null,main:null,end:Ln}),()=>te()):(te(),()=>te()),[Ln,te,b,T]);async function Rn(e){e.preventDefault();let t=I.trim();if(!t)return;let r=ht(L,t);if(r.ok===!1){Fe(r.error);return}let i=De.trim()||gt(L.trim()||t);if(i){z(!0),Fe(null);try{let e=Te.trim(),{createdAgentId:n,...r}=await ye({name:t,workspace:i,...L.trim()?{id:L.trim()}:{},...ke.trim()?{model:ke.trim()}:{},...e?{description:e}:{}});O(r,{revalidate:!1}),Se(``),Ce(``),Ee(``),Oe(``),Ae(``),Fe(null),Re(!1),ge(n),S($e(n))}catch(e){Fe(e instanceof Error?e.message:n.saveError)}finally{z(!1)}}}async function zn(){if(Z){z(!0),A(null);try{let e=ct.trim();O(await Pe(Z.id,{name:rt.trim()||void 0,description:e.length>0?e:null,workspace:Ye.trim()||void 0,model:et.trim()||null}),{revalidate:!1})}catch(e){A(e instanceof Error?e.message:n.saveError)}finally{z(!1)}}}async function Bn(e){z(!0),A(null);try{O(await Pe(e.id,{setDefault:!0}),{revalidate:!1}),ge(e.id)}catch(e){A(e instanceof Error?e.message:n.saveError)}finally{z(!1)}}async function Vn(e,t){z(!0),A(null);try{let n=await Qe(e.id,t);O(n,{revalidate:!1}),ge(n.defaultId),F(`overview`),w===e.id&&S(qe,{replace:!0}),c(!1),d(null),_(``)}catch(e){A(e instanceof Error?e.message:n.saveError)}finally{z(!1)}}function Hn(e,t){e.id!==`main`&&(d(e),m(t),_(``),c(!0))}async function Un(){if(Z){z(!0),A(null);try{let e=[...Xt].sort((e,t)=>e.localeCompare(t));O(await Pe(Z.id,{toolsDisable:e}),{revalidate:!1})}catch(e){A(e instanceof Error?e.message:n.saveError)}finally{z(!1)}}}async function Wn(){if(Z){z(!0),A(null);try{O(await Pe(Z.id,{toolsDisable:null}),{revalidate:!1}),Zt(new Set)}catch(e){A(e instanceof Error?e.message:n.saveError)}finally{z(!1)}}}async function Gn(){if(Z){z(!0),A(null);try{O(await Pe(Z.id,{skills:en?null:[...Qt].sort((e,t)=>e.localeCompare(t))}),{revalidate:!1})}catch(e){A(e instanceof Error?e.message:n.saveError)}finally{z(!1)}}}async function Kn(e){z(!0),A(null);try{let t=nn.filter(t=>t!==e);await p(t),cn(t)}catch(e){A(e instanceof Error?e.message:n.saveError)}finally{z(!1)}}async function qn(e){if(e.preventDefault(),!Z||!q.trim())return;let t=Nt(q,vn,gn,fn),r=[...nn,{agentId:Z.id,priority:100,enabled:!0,match:t}];z(!0),A(null);try{await p(r),cn(r),_n(null),yn(``)}catch(e){A(e instanceof Error?e.message:n.saveError)}finally{z(!1)}}async function Jn(e,t){z(!0),A(null);try{await nt(e.id,{agentId:t===``?null:t}),xn(await st())}catch(e){A(e instanceof Error?e.message:n.saveError)}finally{z(!1)}}let Yn=N===`channels`||N===`cron`,Xn=(()=>{if(!Z||N!==`overview`)return!1;let e=Z.name?.trim()||Z.id,t=Z.description?.trim()??``,n=Z.workspace,r=Z.model?.primary??``;return rt.trim()!==e||ct.trim()!==t||Ye.trim()!==n||et.trim()!==r})(),Zn=(()=>{if(Yn)return!1;switch(N){case`overview`:return Xn||W;case`profile`:return Bt;default:return!0}})(),Qn=Yn||!Zn;function $n(){Kt(!0),setTimeout(()=>Kt(!1),2e3)}async function er(){switch(N){case`overview`:await Promise.all([zn(),Rt.current?.()??Promise.resolve()]),$n();break;case`profile`:await zt.current?.(),$n();break;case`tools`:await Un(),$n();break;case`skills`:await Gn(),$n();break;case`files`:K.flush(),$n();break;default:break}}function tr(e){e||S(qe)}let nr=Z?rt.trim()||Z.name?.trim()||Z.id:w??``,rr=Z?.id??w??``;if(!b)return(0,H.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-8`,children:[(0,H.jsx)(`h1`,{className:`text-lg font-semibold text-fg`,children:n.title}),(0,H.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.needToken})]});if(_e&&k)return(0,H.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col px-4 py-8`,children:(0,H.jsx)(Lt,{existingAgentIds:new Set(k.agents.map(e=>e.id)),onComplete:On,onSkip:X})});let ir=Z?N===`overview`?(0,H.jsx)(rn,{a:n,chat:y,selected:Z,busy:R,editName:rt,setEditName:it,editDescription:ct,setEditDescription:lt,editWorkspace:Ye,setEditWorkspace:Ze,editModel:et,setEditModel:tt,onSetDefault:()=>void Bn(Z),onSaveAgentEdits:()=>void zn(),onDelete:e=>void Hn(Z,e),hideInlineSave:!0,saveBootstrapRef:Rt,onBootstrapDirtyChange:G}):N===`profile`?(0,H.jsx)(an,{a:n,agentId:Z.id,saveRef:zt,onDirtyChange:Wt}):N===`files`?(0,H.jsx)(Ut,{a:n,filesLoading:ft,files:ut,activeFile:V,setActiveFile:mt,bootstrapViewMode:St,setBootstrapViewMode:Ct,fileDraft:_t,setFileDraft:vt,fileSaving:yt,bootstrapFileLoading:wt,bootstrapEditorNonce:Dt}):N===`tools`?(0,H.jsx)(sn,{a:n,data:k,selected:Z,busy:R,toolEntryDisable:Xt,setToolEntryDisable:Zt,onSaveTools:()=>void Un(),onClearToolsEntry:()=>void Wn(),hideInlineSave:!0}):N===`skills`?(0,H.jsx)(on,{a:n,selected:Z,busy:R,skillsCatalogLoading:En,catalogForPick:An,skillsInherit:en,setSkillsInherit:tn,skillsPick:Qt,setSkillsPick:$t,onSaveSkills:()=>void Gn(),hideInlineSave:!0}):N===`channels`?(0,H.jsx)(Vt,{a:n,busy:R,bindingsLoading:Nn,agentBindings:Q,channelStatuses:J,channelsStatusLoading:Y,useManualChannel:Mn,newBindChannel:q,setNewBindChannel:ln,bindSessionChats:fn,sessionsLoading:mn,newBindSessionIdx:gn,setNewBindSessionIdx:_n,newBindCustomPeer:vn,setNewBindCustomPeer:yn,onRefreshSessions:jn,lastActiveLabels:v.lastActiveLabels,selectRecipient:v.selectRecipient,onRemoveBinding:e=>void Kn(e),onAddBinding:qn}):N===`cron`&&k?(0,H.jsx)(Ht,{a:n,data:k,selected:Z,busy:R,cronLoading:Sn,agentCronJobs:kn,onSetCronJobAgent:(e,t)=>void Jn(e,t)}):(0,H.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.selectAgentHint}):(0,H.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.selectAgentHint});return(0,H.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[(0,H.jsx)(At,{a:n}),pe?(0,H.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:pe}):null,ue?(0,H.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.loading}):k?(0,H.jsx)(kt,{a:n,agents:k.agents,searchQuery:Ge,onOpenAgent:e=>S($e(e)),onChatWithAgent:e=>S(`/chat/new`,{state:{agentId:e.trim().toLowerCase()}}),onNewAgent:Fn,busy:R}):null,w&&b?(0,H.jsx)(Et,{open:!!w,onOpenChange:tr,a:n,title:nr,subtitle:rr,panel:N,onPanelChange:F,onFooterSave:()=>void er(),footerSaveDisabled:Qn,footerSavedFlash:Gt,busy:R,children:ue||!k?(0,H.jsx)(`p`,{className:`text-sm text-fg-muted`,children:n.loading}):ir}):null,(0,H.jsx)(Pt,{open:Le,onOpenChange:e=>{Re(e),e||(ze.current=``,Se(``),Ce(``),Ee(``),Oe(``),Ae(``),Fe(null))},a:n,chat:y,busy:R,modalError:je,createDisplayName:I,setCreateDisplayName:Se,createAgentId:L,setCreateAgentId:Ce,createDescription:Te,setCreateDescription:Ee,createWorkspace:De,setCreateWorkspace:Oe,createModel:ke,setCreateModel:Ae,onCreate:Rn,onSuggestWorkspace:()=>Pn()}),(0,H.jsx)(xe,{open:a,onOpenChange:e=>{c(e),e||(d(null),_(``))},children:(0,H.jsxs)(Ke,{children:[(0,H.jsx)(Ie,{className:`fixed inset-0 z-[80] bg-scrim backdrop-blur-[2px]`}),(0,H.jsxs)(We,{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,H.jsx)(we,{className:`text-base font-semibold text-fg`,children:f?n.purgeDisk:n.removeFromConfig}),(0,H.jsx)(be,{className:`mt-2 whitespace-pre-wrap text-sm leading-relaxed text-fg-muted`,children:f?n.confirmDeletePurge:n.confirmDelete}),f&&l?(0,H.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[(0,H.jsx)(`label`,{className:`mb-2 block text-sm font-medium text-fg`,htmlFor:`agent-delete-confirm`,children:n.purgeConfirmLabel}),(0,H.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}}`,l.id),value:g,onChange:e=>_(e.target.value)}),(0,H.jsx)(`p`,{className:`pt-0.5 text-xs text-fg-muted`,children:n.purgeConfirmHint.replace(`{{agentId}}`,l.id)})]}):null,(0,H.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center justify-end gap-2 border-t border-edge-subtle/60 pt-3`,children:[(0,H.jsx)(P,{type:`button`,variant:`ghost`,disabled:R,onClick:()=>c(!1),children:n.createModalCancel}),(0,H.jsx)(P,{type:`button`,variant:`secondary`,className:f?`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||!l||f&&g.trim().toLowerCase()!==l.id.toLowerCase(),onClick:()=>{l&&Vn(l,f)},children:f?n.purgeDisk:n.removeFromConfig})]})]})]})})]})}var q={enabled:!0,mode:`default`,reserveTokens:8e3,triggerThreshold:.8,minMessagesBeforeCompact:10,keepRecentMessages:5,evictionWindow:.2,retentionWindow:6},ln={enabled:!0,maxToolResultChars:1e4,headKeepRatio:.3,tailKeepRatio:.3},J={enabled:!0,useEnhancedSystem:!0,userProfileEnabled:!0,provider:``,injectionFrequency:``,memoryCharLimit:void 0,userCharLimit:void 0,contextCadence:void 0,dialecticCadence:void 0},un={summaryModel:``},Y={enabled:!1,memoryNudgeInterval:10,skillNudgeInterval:10,maxToolRounds:8,maxHistoryMessages:80,maxDurationMs:12e4},dn={model:``,maxLength:void 0};function fn(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 pn(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 mn(e){return e===!0||e===`true`||e===1}function hn(e){let t=e.browser;if(!t||typeof t!=`object`||Array.isArray(t))return{browserEnabled:!1,browserHeadless:!0};let n=t,r=mn(n.enabled),i=n.headless;return{browserEnabled:r,browserHeadless:!(i===!1||i===`false`||i===0)}}function gn(e){if(!e||typeof e!=`object`||Array.isArray(e))return{...q};let t=e;return{enabled:typeof t.enabled==`boolean`?t.enabled:q.enabled,mode:t.mode===`safeguard`?`safeguard`:`default`,reserveTokens:typeof t.reserveTokens==`number`&&Number.isFinite(t.reserveTokens)?Math.floor(t.reserveTokens):q.reserveTokens,triggerThreshold:typeof t.triggerThreshold==`number`&&Number.isFinite(t.triggerThreshold)?t.triggerThreshold:q.triggerThreshold,minMessagesBeforeCompact:typeof t.minMessagesBeforeCompact==`number`&&Number.isFinite(t.minMessagesBeforeCompact)?Math.floor(t.minMessagesBeforeCompact):q.minMessagesBeforeCompact,keepRecentMessages:typeof t.keepRecentMessages==`number`&&Number.isFinite(t.keepRecentMessages)?Math.floor(t.keepRecentMessages):q.keepRecentMessages,evictionWindow:typeof t.evictionWindow==`number`&&Number.isFinite(t.evictionWindow)?t.evictionWindow:q.evictionWindow,retentionWindow:typeof t.retentionWindow==`number`&&Number.isFinite(t.retentionWindow)?Math.floor(t.retentionWindow):q.retentionWindow}}function _n(e){if(!e||typeof e!=`object`||Array.isArray(e))return{...ln};let t=e;return{enabled:typeof t.enabled==`boolean`?t.enabled:ln.enabled,maxToolResultChars:typeof t.maxToolResultChars==`number`&&Number.isFinite(t.maxToolResultChars)?Math.floor(t.maxToolResultChars):ln.maxToolResultChars,headKeepRatio:typeof t.headKeepRatio==`number`&&Number.isFinite(t.headKeepRatio)?t.headKeepRatio:ln.headKeepRatio,tailKeepRatio:typeof t.tailKeepRatio==`number`&&Number.isFinite(t.tailKeepRatio)?t.tailKeepRatio:ln.tailKeepRatio}}function vn(e){if(!e||typeof e!=`object`||Array.isArray(e))return{...J};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:J.enabled,useEnhancedSystem:typeof t.useEnhancedSystem==`boolean`?t.useEnhancedSystem:J.useEnhancedSystem,userProfileEnabled:typeof t.userProfileEnabled==`boolean`?t.userProfileEnabled:J.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 yn(e){if(!e||typeof e!=`object`||Array.isArray(e))return{...un};let t=e;return{summaryModel:typeof t.summaryModel==`string`?t.summaryModel:``}}function bn(e){if(!e||typeof e!=`object`||Array.isArray(e))return{...Y};let t=e;return{enabled:typeof t.enabled==`boolean`?t.enabled:Y.enabled,memoryNudgeInterval:typeof t.memoryNudgeInterval==`number`&&t.memoryNudgeInterval>=0?Math.floor(t.memoryNudgeInterval):Y.memoryNudgeInterval,skillNudgeInterval:typeof t.skillNudgeInterval==`number`&&t.skillNudgeInterval>=0?Math.floor(t.skillNudgeInterval):Y.skillNudgeInterval,maxToolRounds:typeof t.maxToolRounds==`number`&&t.maxToolRounds>=1&&t.maxToolRounds<=32?Math.floor(t.maxToolRounds):Y.maxToolRounds,maxHistoryMessages:typeof t.maxHistoryMessages==`number`&&t.maxHistoryMessages>=10&&t.maxHistoryMessages<=200?Math.floor(t.maxHistoryMessages):Y.maxHistoryMessages,maxDurationMs:typeof t.maxDurationMs==`number`&&t.maxDurationMs>=3e4&&t.maxDurationMs<=6e5?Math.floor(t.maxDurationMs):Y.maxDurationMs}}function xn(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 Sn(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 Cn(e){return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function wn(e){if(e==null)return``;if(typeof e==`object`&&!Array.isArray(e))try{return JSON.stringify(e,null,2)}catch{return``}return``}function Tn(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:pn(r.model),o=r.imageModelFallbacks,s=Array.isArray(o)&&o.every(e=>typeof e==`string`)?o:pn(r.imageModel),c=r.imageGenerationModelFallbacks,l=Array.isArray(c)&&c.every(e=>typeof e==`string`)?c:pn(r.imageGenerationModel),{browserEnabled:u,browserHeadless:d}=hn(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:fn(r.model),modelFallbacks:a,imageModel:fn(r.imageModel),imageModelFallbacks:s,imageGenerationModel:fn(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:`off`,verboseDefault:typeof r.verboseDefault==`string`?r.verboseDefault:`off`,compaction:gn(r.compaction),pruning:_n(r.pruning),memory:vn(r.memory),sessionSearch:yn(r.sessionSearch),backgroundReview:bn(r.backgroundReview),webExtract:xn(r.webExtract),delegate:Sn(r.delegate,!1),executeCode:Sn(r.executeCode,!1),systemPromptOverride:typeof r.systemPromptOverride==`string`?r.systemPromptOverride:``,skillsAllowlist:Cn(r.skills),toolsDisable:(()=>{let e=r.tools;if(!e||typeof e!=`object`||Array.isArray(e))return[];let t=e.disable;return Cn(t)})(),paramsJson:wn(r.params)}}function En(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 Dn(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 On(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})(),l=e.skillsAllowlist.map(e=>e.trim()).filter(Boolean),u=e.toolsDisable.map(e=>e.trim()).filter(Boolean),d=Dn(e.paramsJson),f=d===null||Object.keys(d).length===0?null:d,p={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:En(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:l.length>0?l:null,tools:{disable:u.length>0?u:null},params:f};await T(j(`/api/config`),{method:`PATCH`,body:JSON.stringify({agents:{defaults:p}})}),c()}function X(){return i(`w-full rounded-lg border border-edge bg-surface-panel px-3 py-2 text-sm text-fg`,`placeholder:text-fg-subtle`,Re,`dark:border-edge`)}function Z(){return i(ve,Ve)}function Q({label:e,description:t,children:n}){return(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e}),n,(0,H.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:t})]})}function kn(e){let{a:t,chat:n,form:r,update:a}=e,o=t.advanced;return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(W,{children:[(0,H.jsx)(G,{icon:et,title:o.cardLimitsTitle,subtitle:o.cardLimitsSubtitle}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,H.jsx)(Q,{label:o.maxTaskDurationMs,description:o.maxTaskDurationMsDesc,children:(0,H.jsx)(`input`,{type:`number`,className:X(),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,H.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,H.jsx)(Q,{label:o.maxRequestsPerTurn,description:o.maxRequestsPerTurnDesc,children:(0,H.jsx)(`input`,{type:`number`,className:X(),min:10,max:200,value:r.maxRequestsPerTurn,onChange:e=>a({maxRequestsPerTurn:Number.parseInt(e.target.value,10)||50})})}),(0,H.jsx)(Q,{label:o.maxToolFailuresPerTurn,description:o.maxToolFailuresPerTurnDesc,children:(0,H.jsx)(`input`,{type:`number`,className:X(),min:1,max:20,value:r.maxToolFailuresPerTurn,onChange:e=>a({maxToolFailuresPerTurn:Number.parseInt(e.target.value,10)||3})})})]})]})]}),(0,H.jsxs)(W,{children:[(0,H.jsx)(G,{icon:N,title:o.cardCompactionTitle,subtitle:o.cardCompactionSubtitle}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,H.jsx)(Q,{label:o.compactionEnabled,description:o.compactionEnabledDesc,children:(0,H.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,H.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,H.jsx)(`span`,{children:o.compactionEnabledOn})]})}),(0,H.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,H.jsx)(Q,{label:o.compactionMode,description:o.compactionModeDesc,children:(0,H.jsxs)(`select`,{className:Z(),value:r.compaction.mode,onChange:e=>a({compaction:{...r.compaction,mode:e.target.value}}),children:[(0,H.jsx)(`option`,{value:`default`,children:o.compactionModeDefault}),(0,H.jsx)(`option`,{value:`safeguard`,children:o.compactionModeSafeguard})]})}),(0,H.jsx)(Q,{label:o.reserveTokens,description:o.reserveTokensDesc,children:(0,H.jsx)(`input`,{type:`number`,className:X(),min:1e3,value:r.compaction.reserveTokens,onChange:e=>a({compaction:{...r.compaction,reserveTokens:Number.parseInt(e.target.value,10)||0}})})}),(0,H.jsx)(Q,{label:o.triggerThreshold,description:o.triggerThresholdDesc,children:(0,H.jsx)(`input`,{type:`number`,className:X(),min:.5,max:.95,step:.05,value:r.compaction.triggerThreshold,onChange:e=>a({compaction:{...r.compaction,triggerThreshold:Number.parseFloat(e.target.value)||.8}})})}),(0,H.jsx)(Q,{label:o.minMessagesBeforeCompact,description:o.minMessagesBeforeCompactDesc,children:(0,H.jsx)(`input`,{type:`number`,className:X(),min:1,value:r.compaction.minMessagesBeforeCompact,onChange:e=>a({compaction:{...r.compaction,minMessagesBeforeCompact:Number.parseInt(e.target.value,10)||10}})})}),(0,H.jsx)(Q,{label:o.keepRecentMessages,description:o.keepRecentMessagesDesc,children:(0,H.jsx)(`input`,{type:`number`,className:X(),min:0,value:r.compaction.keepRecentMessages,onChange:e=>a({compaction:{...r.compaction,keepRecentMessages:Number.parseInt(e.target.value,10)||5}})})}),(0,H.jsx)(Q,{label:o.evictionWindow,description:o.evictionWindowDesc,children:(0,H.jsx)(`input`,{type:`number`,className:X(),min:.1,max:.5,step:.05,value:r.compaction.evictionWindow,onChange:e=>a({compaction:{...r.compaction,evictionWindow:Number.parseFloat(e.target.value)||.2}})})}),(0,H.jsx)(Q,{label:o.retentionWindow,description:o.retentionWindowDesc,children:(0,H.jsx)(`input`,{type:`number`,className:X(),min:3,max:20,value:r.compaction.retentionWindow,onChange:e=>a({compaction:{...r.compaction,retentionWindow:Number.parseInt(e.target.value,10)||6}})})})]})]})]}),(0,H.jsxs)(W,{children:[(0,H.jsx)(G,{icon:te,title:o.cardPruningTitle,subtitle:o.cardPruningSubtitle}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,H.jsx)(Q,{label:o.pruningEnabled,description:o.pruningEnabledDesc,children:(0,H.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,H.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,H.jsx)(`span`,{children:o.pruningEnabledOn})]})}),(0,H.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,H.jsx)(Q,{label:o.maxToolResultChars,description:o.maxToolResultCharsDesc,children:(0,H.jsx)(`input`,{type:`number`,className:X(),min:1e3,value:r.pruning.maxToolResultChars,onChange:e=>a({pruning:{...r.pruning,maxToolResultChars:Number.parseInt(e.target.value,10)||1e4}})})}),(0,H.jsx)(Q,{label:o.headKeepRatio,description:o.headKeepRatioDesc,children:(0,H.jsx)(`input`,{type:`number`,className:X(),min:0,max:1,step:.05,value:r.pruning.headKeepRatio,onChange:e=>a({pruning:{...r.pruning,headKeepRatio:Number.parseFloat(e.target.value)||.3}})})}),(0,H.jsx)(Q,{label:o.tailKeepRatio,description:o.tailKeepRatioDesc,children:(0,H.jsx)(`input`,{type:`number`,className:X(),min:0,max:1,step:.05,value:r.pruning.tailKeepRatio,onChange:e=>a({pruning:{...r.pruning,tailKeepRatio:Number.parseFloat(e.target.value)||.3}})})})]})]})]}),(0,H.jsxs)(W,{children:[(0,H.jsx)(G,{icon:tt,title:o.cardMemoryTitle,subtitle:o.cardMemorySubtitle}),(0,H.jsx)(`div`,{className:`flex flex-col gap-5`,children:(0,H.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,H.jsx)(Q,{label:o.memoryEnabled,description:o.memoryEnabledDesc,children:(0,H.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,H.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,H.jsx)(`span`,{children:o.memoryEnabledOn})]})}),(0,H.jsx)(Q,{label:o.useEnhancedSystem,description:o.useEnhancedSystemDesc,children:(0,H.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,H.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,H.jsx)(`span`,{children:o.useEnhancedSystemOn})]})}),(0,H.jsx)(Q,{label:o.userProfileEnabled,description:o.userProfileEnabledDesc,children:(0,H.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,H.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,H.jsx)(`span`,{children:o.userProfileEnabledOn})]})}),(0,H.jsx)(Q,{label:o.memoryProvider,description:o.memoryProviderDesc,children:(0,H.jsxs)(`select`,{className:Z(),value:r.memory.provider,onChange:e=>a({memory:{...r.memory,provider:e.target.value}}),children:[(0,H.jsx)(`option`,{value:``,children:o.memoryProviderUnset}),(0,H.jsx)(`option`,{value:`none`,children:`none`}),(0,H.jsx)(`option`,{value:`stub`,children:`stub`})]})}),(0,H.jsx)(Q,{label:o.injectionFrequency,description:o.injectionFrequencyDesc,children:(0,H.jsxs)(`select`,{className:Z(),value:r.memory.injectionFrequency,onChange:e=>a({memory:{...r.memory,injectionFrequency:e.target.value}}),children:[(0,H.jsx)(`option`,{value:``,children:o.injectionFrequencyUnset}),(0,H.jsx)(`option`,{value:`every-turn`,children:o.injectionEveryTurn}),(0,H.jsx)(`option`,{value:`first-turn`,children:o.injectionFirstTurn})]})}),(0,H.jsx)(Q,{label:o.memoryCharLimit,description:o.memoryCharLimitDesc,children:(0,H.jsx)(`input`,{type:`number`,className:X(),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,H.jsx)(Q,{label:o.userCharLimit,description:o.userCharLimitDesc,children:(0,H.jsx)(`input`,{type:`number`,className:X(),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,H.jsx)(Q,{label:o.contextCadence,description:o.contextCadenceDesc,children:(0,H.jsx)(`input`,{type:`number`,className:X(),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,H.jsx)(Q,{label:o.dialecticCadence,description:o.dialecticCadenceDesc,children:(0,H.jsx)(`input`,{type:`number`,className:X(),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,H.jsxs)(W,{children:[(0,H.jsx)(G,{icon:Ne,title:o.cardSessionSearchTitle,subtitle:o.cardSessionSearchSubtitle}),(0,H.jsx)(Q,{label:o.sessionSearchSummaryModel,description:o.sessionSearchSummaryModelDesc,children:(0,H.jsx)(L,{value:r.sessionSearch.summaryModel,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,onChange:e=>a({sessionSearch:{...r.sessionSearch,summaryModel:e}})})})]}),(0,H.jsxs)(W,{children:[(0,H.jsx)(G,{icon:Ze,title:o.cardReviewTitle,subtitle:o.cardReviewSubtitle}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,H.jsx)(Q,{label:o.reviewEnabled,description:o.reviewEnabledDesc,children:(0,H.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,H.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,H.jsx)(`span`,{children:o.reviewEnabledOn})]})}),(0,H.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,H.jsx)(Q,{label:o.memoryNudgeInterval,description:o.memoryNudgeIntervalDesc,children:(0,H.jsx)(`input`,{type:`number`,className:X(),min:0,value:r.backgroundReview.memoryNudgeInterval,onChange:e=>a({backgroundReview:{...r.backgroundReview,memoryNudgeInterval:Number.parseInt(e.target.value,10)||0}})})}),(0,H.jsx)(Q,{label:o.skillNudgeInterval,description:o.skillNudgeIntervalDesc,children:(0,H.jsx)(`input`,{type:`number`,className:X(),min:0,value:r.backgroundReview.skillNudgeInterval,onChange:e=>a({backgroundReview:{...r.backgroundReview,skillNudgeInterval:Number.parseInt(e.target.value,10)||0}})})}),(0,H.jsx)(Q,{label:o.reviewMaxToolRounds,description:o.reviewMaxToolRoundsDesc,children:(0,H.jsx)(`input`,{type:`number`,className:X(),min:1,max:32,value:r.backgroundReview.maxToolRounds,onChange:e=>a({backgroundReview:{...r.backgroundReview,maxToolRounds:Number.parseInt(e.target.value,10)||8}})})}),(0,H.jsx)(Q,{label:o.reviewMaxHistoryMessages,description:o.reviewMaxHistoryMessagesDesc,children:(0,H.jsx)(`input`,{type:`number`,className:X(),min:10,max:200,value:r.backgroundReview.maxHistoryMessages,onChange:e=>a({backgroundReview:{...r.backgroundReview,maxHistoryMessages:Number.parseInt(e.target.value,10)||80}})})}),(0,H.jsx)(Q,{label:o.reviewMaxDurationMs,description:o.reviewMaxDurationMsDesc,children:(0,H.jsx)(`input`,{type:`number`,className:X(),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,H.jsxs)(W,{children:[(0,H.jsx)(G,{icon:Oe,title:o.cardWebExtractTitle,subtitle:o.cardWebExtractSubtitle}),(0,H.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,H.jsx)(`div`,{className:`sm:col-span-2`,children:(0,H.jsx)(Q,{label:o.webExtractModel,description:o.webExtractModelDesc,children:(0,H.jsx)(L,{value:r.webExtract.model,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,onChange:e=>a({webExtract:{...r.webExtract,model:e}})})})}),(0,H.jsx)(Q,{label:o.webExtractMaxLength,description:o.webExtractMaxLengthDesc,children:(0,H.jsx)(`input`,{type:`number`,className:X(),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,H.jsxs)(W,{children:[(0,H.jsx)(G,{icon:g,title:o.cardDelegateTitle,subtitle:o.cardDelegateSubtitle}),(0,H.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,H.jsx)(Q,{label:o.delegateEnabled,description:o.delegateEnabledDesc,children:(0,H.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,H.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,H.jsx)(`span`,{children:o.delegateEnabledOn})]})}),(0,H.jsx)(Q,{label:o.executeCodeEnabled,description:o.executeCodeEnabledDesc,children:(0,H.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,H.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,H.jsx)(`span`,{children:o.executeCodeEnabledOn})]})})]})]}),(0,H.jsxs)(W,{children:[(0,H.jsx)(G,{icon:Se,title:o.cardPromptSkillsTitle,subtitle:o.cardPromptSkillsSubtitle}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,H.jsx)(Q,{label:o.systemPromptOverride,description:o.systemPromptOverrideDesc,children:(0,H.jsx)(`textarea`,{className:i(X(),`min-h-[100px] resize-y font-mono text-xs`),value:r.systemPromptOverride,placeholder:o.systemPromptPlaceholder,onChange:e=>a({systemPromptOverride:e.target.value})})}),(0,H.jsx)(Q,{label:o.skillsAllowlist,description:o.skillsAllowlistDesc,children:(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[r.skillsAllowlist.map((e,t)=>(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(`input`,{type:`text`,className:i(X(),`font-mono text-xs`),value:e,onChange:e=>{let n=[...r.skillsAllowlist];n[t]=e.target.value,a({skillsAllowlist:n})}}),(0,H.jsx)(P,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":o.removeListItem,onClick:()=>a({skillsAllowlist:r.skillsAllowlist.filter((e,n)=>n!==t)}),children:`×`})]},t)),(0,H.jsx)(P,{type:`button`,variant:`secondary`,className:`w-fit`,onClick:()=>a({skillsAllowlist:[...r.skillsAllowlist,``]}),children:o.addSkillName})]})})]})]}),(0,H.jsxs)(W,{children:[(0,H.jsx)(G,{icon:R,title:o.cardToolsDisableTitle,subtitle:o.cardToolsDisableSubtitle}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,H.jsx)(`p`,{className:`text-xs text-fg-muted`,children:o.toolsDisableHint}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[r.toolsDisable.map((e,t)=>(0,H.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,H.jsx)(`input`,{type:`text`,className:i(X(),`font-mono text-xs`),value:e,placeholder:`shell`,onChange:e=>{let n=[...r.toolsDisable];n[t]=e.target.value,a({toolsDisable:n})}}),(0,H.jsx)(P,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":o.removeListItem,onClick:()=>a({toolsDisable:r.toolsDisable.filter((e,n)=>n!==t)}),children:`×`})]},t)),(0,H.jsx)(P,{type:`button`,variant:`secondary`,className:`w-fit`,onClick:()=>a({toolsDisable:[...r.toolsDisable,``]}),children:o.addToolName})]})]})]}),(0,H.jsxs)(W,{children:[(0,H.jsx)(G,{icon:m,title:o.cardParamsTitle,subtitle:o.cardParamsSubtitle}),(0,H.jsx)(Q,{label:o.paramsJson,description:o.paramsJsonDesc,children:(0,H.jsx)(`textarea`,{className:i(X(),`min-h-[88px] resize-y font-mono text-xs`),value:r.paramsJson,placeholder:`{}`,onChange:e=>a({paramsJson:e.target.value})})})]})]})}async function An(){let e=await v(j(`/api/image/providers`));if(!e.ok)throw Error(`Image providers: HTTP ${e.status}`);return(await e.json()).payload?.providers??[]}function jn(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 Mn(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 Nn=`image-generation-providers`;function Pn({value:e,disabled:t,placeholder:n,searchPlaceholder:a,noMatches:o,className:s,onChange:c}){let[l,u]=(0,B.useState)(!1),[d,f]=(0,B.useState)(``),{data:p,isLoading:m,error:h}=r(Nn,An,{revalidateOnFocus:!1}),g=(0,B.useMemo)(()=>jn(p??[]),[p]),_=(0,B.useMemo)(()=>Mn(g,d),[g,d]),v=e.trim()?e:n,b=e.trim()||n,x=(0,B.useCallback)(e=>{u(e),e||f(``)},[]);return(0,H.jsxs)(_e,{open:l,onOpenChange:x,modal:!1,children:[(0,H.jsx)(Ye,{asChild:!0,children:(0,H.jsxs)(`button`,{type:`button`,disabled:t||m,title:m?`…`:b,className:i(Ge,`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`,y.transition,`hover:border-edge hover:bg-surface-hover/45`,Ae,`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,H.jsx)(`span`,{className:`min-w-0 truncate`,children:m?`…`:v}),(0,H.jsx)(D,{className:`h-4 w-4 shrink-0 text-fg-subtle opacity-70`,"aria-hidden":!0})]})}),(0,H.jsx)(Ee,{children:(0,H.jsxs)(ke,{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,H.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`,Le),placeholder:a,value:d,onChange:e=>f(e.target.value),onKeyDown:e=>e.stopPropagation()}),(0,H.jsxs)(`div`,{className:`max-h-60 overflow-auto`,role:`listbox`,"aria-label":a,children:[h?(0,H.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,H.jsx)(`div`,{className:`px-2 py-3 text-center text-xs text-fg-muted`,children:o}):null,!h&&g.length>0&&_.length===0?(0,H.jsx)(`div`,{className:`px-2 py-3 text-center text-xs text-fg-muted`,children:o}):null,_.map(t=>(0,H.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,H.jsx)(oe,{className:i(`h-4 w-4 shrink-0`,t!==e&&`invisible`),"aria-hidden":!0}),(0,H.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm font-medium`,children:t})]},t))]})]})})]})}var Fn=[`off`,`minimal`,`low`,`medium`,`high`,`xhigh`,`adaptive`];function $({label:e,description:t,children:n}){return(0,H.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,H.jsx)(`div`,{className:`text-sm font-medium text-fg`,children:e}),n,(0,H.jsx)(`p`,{className:`text-xs leading-relaxed text-fg-subtle`,children:t})]})}function In(){let e=He(s(e=>e.language)),t=e.agentSettings,n=e.chat,r=!!ee(e=>e.token),[i,a]=(0,B.useState)(null),[o,c]=(0,B.useState)(null),[l,u]=(0,B.useState)(!1),[d,p]=(0,B.useState)(null),[m,h]=(0,B.useState)(!1),g=(0,B.useRef)(!1),{data:_,error:v,isLoading:y,mutate:b}=Me(r),x=(0,B.useMemo)(()=>_?.payload?.config===void 0?null:Tn(_.payload.config),[_]);(0,B.useEffect)(()=>{if(!r){a(null),c(null),g.current=!1;return}x!==null&&(g.current||(a(x),c(x)))},[r,x]);let S=!!(r&&y&&_===void 0&&!v),C=v instanceof Error?v.message:v?String(v):null,w=(0,B.useMemo)(()=>!i||!o?!1:JSON.stringify(i)!==JSON.stringify(o),[i,o]),T=(0,B.useCallback)(e=>{g.current=!0,a(t=>t?{...t,...e}:null)},[]),te=(0,B.useCallback)(async()=>{if(!(!i||l)){u(!0),p(null),h(!1);try{try{Dn(i.paramsJson)}catch(e){p(e instanceof SyntaxError?t.advanced.paramsInvalidJson:e instanceof Error?e.message:t.advanced.paramsInvalidJson);return}await On(i),g.current=!1,h(!0),window.setTimeout(()=>h(!1),2500)}catch(e){p(e instanceof Error?e.message:t.saveError)}finally{u(!1)}}},[i,l,t.saveError,t.advanced]),ne=e.settingsSections[`agent-defaults`];return r?S?(0,H.jsxs)(`div`,{className:`mx-auto w-full max-w-app-main px-4 py-8`,children:[(0,H.jsx)(`div`,{className:`h-8 w-48 animate-pulse rounded bg-surface-hover`}),(0,H.jsx)(`div`,{className:`mt-6 h-32 animate-pulse rounded-xl bg-surface-hover`}),(0,H.jsx)(`p`,{className:`mt-4 text-sm text-fg-muted`,children:e.logs.loading})]}):i?(0,H.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-6 px-4 py-8`,children:[(0,H.jsxs)(`header`,{className:`flex flex-col gap-2 sm:flex-row sm:items-start sm:justify-between`,children:[(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h1`,{className:`text-lg font-semibold tracking-tight text-fg`,children:ne}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:t.subtitle}),(0,H.jsx)(`p`,{className:`mt-1 text-xs text-fg-subtle`,children:t.sectionDesc})]}),(0,H.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[m?(0,H.jsx)(`span`,{className:`text-sm text-fg-muted`,children:t.saved}):null,(0,H.jsx)(P,{type:`button`,variant:`primary`,disabled:!w||l,onClick:()=>void te(),children:l?t.saving:t.save})]})]}),d?(0,H.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:d}):null,(0,H.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,H.jsxs)(W,{children:[(0,H.jsx)(G,{icon:f,title:t.cardModelsTitle,subtitle:t.cardModelsSubtitle}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,H.jsx)($,{label:t.label.model,description:t.desc.model,children:(0,H.jsx)(L,{value:i.model,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,onChange:e=>T({model:e})})}),(0,H.jsx)($,{label:t.label.modelFallbacks,description:t.desc.modelFallbacks,children:(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[i.modelFallbacks.map((e,r)=>(0,H.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,H.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,H.jsx)(L,{value:e,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,onChange:e=>{let t=[...i.modelFallbacks];t[r]=e,T({modelFallbacks:t})}})}),(0,H.jsx)(P,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":t.removeModelFallback,onClick:()=>T({modelFallbacks:i.modelFallbacks.filter((e,t)=>t!==r)}),children:(0,H.jsx)(Je,{className:`size-4`,strokeWidth:1.75})})]},r)),(0,H.jsxs)(P,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:()=>T({modelFallbacks:[...i.modelFallbacks,``]}),children:[(0,H.jsx)(E,{className:`size-4 shrink-0`,strokeWidth:1.75}),t.addModelFallback]})]})}),(0,H.jsx)($,{label:t.label.imageModel,description:t.desc.imageModel,children:(0,H.jsx)(L,{value:i.imageModel,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,onChange:e=>T({imageModel:e})})}),(0,H.jsx)($,{label:t.label.imageModelFallbacks,description:t.desc.imageModelFallbacks,children:(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[i.imageModelFallbacks.map((e,r)=>(0,H.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,H.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,H.jsx)(L,{value:e,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,onChange:e=>{let t=[...i.imageModelFallbacks];t[r]=e,T({imageModelFallbacks:t})}})}),(0,H.jsx)(P,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":t.removeModelFallback,onClick:()=>T({imageModelFallbacks:i.imageModelFallbacks.filter((e,t)=>t!==r)}),children:(0,H.jsx)(Je,{className:`size-4`,strokeWidth:1.75})})]},r)),(0,H.jsxs)(P,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:()=>T({imageModelFallbacks:[...i.imageModelFallbacks,``]}),children:[(0,H.jsx)(E,{className:`size-4 shrink-0`,strokeWidth:1.75}),t.addModelFallback]})]})}),(0,H.jsx)($,{label:t.label.imageGenerationModel,description:t.desc.imageGenerationModel,children:(0,H.jsx)(Pn,{value:i.imageGenerationModel,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,onChange:e=>T({imageGenerationModel:e})})}),(0,H.jsx)($,{label:t.label.imageGenerationModelFallbacks,description:t.desc.imageGenerationModelFallbacks,children:(0,H.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[i.imageGenerationModelFallbacks.map((e,r)=>(0,H.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,H.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,H.jsx)(Pn,{value:e,placeholder:n.modelPlaceholder,searchPlaceholder:n.modelSearchPlaceholder,noMatches:n.modelNoMatches,onChange:e=>{let t=[...i.imageGenerationModelFallbacks];t[r]=e,T({imageGenerationModelFallbacks:t})}})}),(0,H.jsx)(P,{type:`button`,variant:`secondary`,className:`shrink-0`,"aria-label":t.removeModelFallback,onClick:()=>T({imageGenerationModelFallbacks:i.imageGenerationModelFallbacks.filter((e,t)=>t!==r)}),children:(0,H.jsx)(Je,{className:`size-4`,strokeWidth:1.75})})]},r)),(0,H.jsxs)(P,{type:`button`,variant:`secondary`,className:`w-fit gap-1.5`,onClick:()=>T({imageGenerationModelFallbacks:[...i.imageGenerationModelFallbacks,``]}),children:[(0,H.jsx)(E,{className:`size-4 shrink-0`,strokeWidth:1.75}),t.addModelFallback]})]})})]})]}),(0,H.jsxs)(W,{children:[(0,H.jsx)(G,{icon:I,title:t.cardWorkspaceTitle,subtitle:t.cardWorkspaceSubtitle}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,H.jsx)($,{label:t.label.workspace,description:t.desc.workspace,children:(0,H.jsx)(`input`,{type:`text`,className:X(),value:i.workspace,onChange:e=>T({workspace:e.target.value}),autoComplete:`off`})}),(0,H.jsx)($,{label:t.label.mediaMaxMb,description:t.desc.mediaMaxMb,children:(0,H.jsx)(`input`,{type:`number`,min:1,step:1,className:X(),value:i.mediaMaxMb??``,placeholder:`20`,onChange:e=>{let t=e.target.value;T({mediaMaxMb:t===``?void 0:Number(t)})}})})]})]}),(0,H.jsxs)(W,{children:[(0,H.jsx)(G,{icon:Fe,title:t.cardBrowserTitle,subtitle:t.cardBrowserSubtitle}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,H.jsx)($,{label:t.label.browserEnabled,description:t.desc.browserEnabled,children:(0,H.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,H.jsx)(`input`,{type:`checkbox`,className:`size-3.5 shrink-0 rounded border-edge`,checked:i.browserEnabled,onChange:e=>T({browserEnabled:e.target.checked})}),(0,H.jsx)(`span`,{children:t.browserEnabledOn})]})}),(0,H.jsx)($,{label:t.label.browserHeadless,description:t.desc.browserHeadless,children:(0,H.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-2 text-sm text-fg`,children:[(0,H.jsx)(`input`,{type:`checkbox`,className:`size-3.5 shrink-0 rounded border-edge`,checked:i.browserHeadless,onChange:e=>T({browserHeadless:e.target.checked})}),(0,H.jsx)(`span`,{children:t.browserHeadlessOn})]})})]})]}),(0,H.jsxs)(W,{children:[(0,H.jsx)(G,{icon:je,title:t.cardGenerationTitle,subtitle:t.cardGenerationSubtitle}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,H.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,H.jsx)($,{label:t.label.maxTokens,description:t.desc.maxTokens,children:(0,H.jsx)(`input`,{type:`number`,className:X(),value:i.maxTokens,min:1,onChange:e=>T({maxTokens:Number.parseInt(e.target.value,10)||0})})}),(0,H.jsx)($,{label:t.label.temperature,description:t.desc.temperature,children:(0,H.jsx)(`input`,{type:`number`,className:X(),value:i.temperature,min:0,max:2,step:.1,onChange:e=>T({temperature:Number.parseFloat(e.target.value)||0})})})]}),(0,H.jsx)($,{label:t.label.maxToolIterations,description:t.desc.maxToolIterations,children:(0,H.jsx)(`input`,{type:`number`,className:X(),value:i.maxToolIterations,min:1,onChange:e=>T({maxToolIterations:Number.parseInt(e.target.value,10)||0})})})]})]}),(0,H.jsxs)(W,{children:[(0,H.jsx)(G,{icon:F,title:t.cardBehaviorTitle,subtitle:t.cardBehaviorSubtitle}),(0,H.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,H.jsx)($,{label:t.label.thinkingDefault,description:t.desc.thinkingDefault,children:(0,H.jsx)(`select`,{className:Z(),value:i.thinkingDefault,onChange:e=>T({thinkingDefault:e.target.value}),children:Fn.map(e=>(0,H.jsx)(`option`,{value:e,children:n.thinkingLevels[e]},e))})}),(0,H.jsx)($,{label:t.label.reasoningDefault,description:t.desc.reasoningDefault,children:(0,H.jsxs)(`select`,{className:Z(),value:i.reasoningDefault,onChange:e=>T({reasoningDefault:e.target.value}),children:[(0,H.jsx)(`option`,{value:`off`,children:t.reasoning.off}),(0,H.jsx)(`option`,{value:`on`,children:t.reasoning.on}),(0,H.jsx)(`option`,{value:`stream`,children:t.reasoning.stream})]})}),(0,H.jsx)($,{label:t.label.verboseDefault,description:t.desc.verboseDefault,children:(0,H.jsxs)(`select`,{className:Z(),value:i.verboseDefault,onChange:e=>T({verboseDefault:e.target.value}),children:[(0,H.jsx)(`option`,{value:`off`,children:t.verbose.off}),(0,H.jsx)(`option`,{value:`on`,children:t.verbose.on}),(0,H.jsx)(`option`,{value:`full`,children:t.verbose.full})]})})]})]}),(0,H.jsx)(kn,{a:t,chat:n,form:i,update:T})]})]}):(0,H.jsxs)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-10`,children:[(0,H.jsx)(`p`,{className:`text-sm text-fg-muted`,children:d??C??t.loadError}),(0,H.jsx)(P,{type:`button`,variant:`secondary`,onClick:()=>void b(),children:e.logs.refresh})]}):(0,H.jsx)(`div`,{className:`mx-auto flex w-full max-w-app-main flex-col gap-3 px-4 py-10`,children:(0,H.jsxs)(`div`,{className:`flex items-start gap-3 rounded-2xl bg-surface-base p-6`,children:[(0,H.jsx)(f,{className:`mt-0.5 size-5 shrink-0 text-fg-subtle`,strokeWidth:1.75}),(0,H.jsxs)(`div`,{children:[(0,H.jsx)(`h1`,{className:`text-base font-semibold text-fg`,children:ne}),(0,H.jsx)(`p`,{className:`mt-1 text-sm text-fg-muted`,children:t.needToken})]})]})})}export{cn as AgentsSettingsPanel,_t as a,vt as c,zt as i,yt as l,W as n,St as o,G as r,xt as s,In as t,bt as u};
216
+ //# sourceMappingURL=agents-w8_jzuiX.js.map