bazilion 0.58.1 → 0.58.2

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 (39) hide show
  1. package/dist/cli.js +1 -1
  2. package/dist/cli.js.map +1 -1
  3. package/dist/web/client/assets/{AddProviderDialog-DIxB5CRz.js → AddProviderDialog-BsUXLr-m.js} +1 -1
  4. package/dist/web/client/assets/{AgentTemplateParts-B9JD9mno.js → AgentTemplateParts-BaeuW_3n.js} +1 -1
  5. package/dist/web/client/assets/{ConfirmDialog-D-Qk9p6V.js → ConfirmDialog-D8f2wI5x.js} +1 -1
  6. package/dist/web/client/assets/{ConnectionsView-Dfbn7vfB.js → ConnectionsView-BUZcfBHw.js} +1 -1
  7. package/dist/web/client/assets/{SkillsParts-DN_JvpRU.js → SkillsParts-jMYdOiWh.js} +1 -1
  8. package/dist/web/client/assets/{SpawnTeamModal-Btj3My2v.js → SpawnTeamModal-Dq7D3Zlc.js} +1 -1
  9. package/dist/web/client/assets/{TeamForm-BX_68QZQ.js → TeamForm-Crz3mvXu.js} +1 -1
  10. package/dist/web/client/assets/{TeamThread-CJXudrt6.js → TeamThread-qTkvxv27.js} +1 -1
  11. package/dist/web/client/assets/{UnsavedChangesGuard-B_e5_ck_.js → UnsavedChangesGuard-DGzP-x1t.js} +1 -1
  12. package/dist/web/client/assets/{_id-DoP6Mlct.js → _id-CiqTBi2Q.js} +1 -1
  13. package/dist/web/client/assets/{_id-BJt13p-G.js → _id-DsZBpW5G.js} +1 -1
  14. package/dist/web/client/assets/{access-DnkUj0iM.js → access-ssWsYTEU.js} +1 -1
  15. package/dist/web/client/assets/{agents-CrfF2ZOS.js → agents-BmkaQvWh.js} +1 -1
  16. package/dist/web/client/assets/{agents-Cv07gKT0.js → agents-D3tZ58Dh.js} +1 -1
  17. package/dist/web/client/assets/{attention-TQpP915m.js → attention-ChHdu7E8.js} +1 -1
  18. package/dist/web/client/assets/{config-CKPln0Ng.js → config-DPsq6Zy9.js} +1 -1
  19. package/dist/web/client/assets/{index-Bwz8tnmS.js → index-CVVVmIFC.js} +2 -2
  20. package/dist/web/client/assets/{login-C-FCzcQU.js → login-B-Kpyw9o.js} +1 -1
  21. package/dist/web/client/assets/{manage-BSGsiEPw.js → manage-Dwe9yQl9.js} +1 -1
  22. package/dist/web/client/assets/{mcp-DDw8SGMV.js → mcp-73AMOCv3.js} +1 -1
  23. package/dist/web/client/assets/routes-Lj8n-RF7.js +85 -0
  24. package/dist/web/client/assets/{skills-H_AVE6G7.js → skills-DmYDuDbl.js} +1 -1
  25. package/dist/web/client/assets/{style-HG30duye.js → style-B9Vy-99n.js} +1 -1
  26. package/dist/web/client/assets/{system-C7vZKVdU.js → system-t9hcqYBg.js} +1 -1
  27. package/dist/web/client/assets/{teams-Dcy3Wb4u.js → teams-5B2cyDin.js} +1 -1
  28. package/dist/web/client/assets/{teams-DcxoMrsV.js → teams-Nk_bHpr0.js} +1 -1
  29. package/dist/web/client/assets/{telegram-CUw1r_J5.js → telegram-BWfL_OIt.js} +1 -1
  30. package/dist/web/client/assets/{tools-BNZxmJJk.js → tools-mdAuMsYJ.js} +1 -1
  31. package/dist/web/client/assets/{usage-BhqvXWtk.js → usage-CWu7R8ZD.js} +1 -1
  32. package/dist/web/client/assets/{welcome-4H9Gvu-u.js → welcome-BuRNFxpc.js} +1 -1
  33. package/dist/web/server/assets/{_tanstack-start-manifest_v-Df5LTm5g.js → _tanstack-start-manifest_v-gHDkHqeS.js} +57 -57
  34. package/dist/web/server/assets/{router-q3PwQgDH.js → router-yEsciAts.js} +2 -2
  35. package/dist/web/server/assets/{routes-Do8a2liK.js → routes-Bfkccvfb.js} +4 -14
  36. package/dist/web/server/assets/{routes-DRtxA9c1.js → routes-CjtC0rDs.js} +1 -1
  37. package/dist/web/server/server.js +2 -2
  38. package/package.json +1 -1
  39. package/dist/web/client/assets/routes-C5KzZ73E.js +0 -85
@@ -0,0 +1,85 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/ConnectionsView-BUZcfBHw.js","assets/createLucideIcon-CZHSSDYA.js","assets/index-CVVVmIFC.js","assets/preload-helper-CZOd_z6l.js","assets/Button-CoKQRO-s.js","assets/parts-C104qEuC.js","assets/es2015-DZDOQ3kj.js","assets/index-Cofc7zhl.css","assets/ConfirmDialog-D8f2wI5x.js","assets/Segmented-iylzLwE6.js","assets/UnsavedChangesGuard-DGzP-x1t.js","assets/TeamThread-qTkvxv27.js","assets/use-resource-qjIkNQDY.js","assets/images-BULrW-FC.js","assets/arrow-right-BqqfPqVi.js","assets/network-BqmVqC4_.js","assets/style-B9Vy-99n.js","assets/manage-Dwe9yQl9.js","assets/style-DLioOiRN.css","assets/message-square-B_pULba_.js"])))=>i.map(i=>d[i]);
2
+ import{$ as e,Z as t,a as n,c as r,d as i,h as a,i as o,o as s,r as c,s as l,t as u}from"./createLucideIcon-CZHSSDYA.js";import{a as d,r as f,t as p,u as m}from"./preload-helper-CZOd_z6l.js";import{t as h}from"./UnsavedChangesGuard-DGzP-x1t.js";import{t as g}from"./Button-CoKQRO-s.js";import{C as _,S as v,b as y,x as b}from"./es2015-DZDOQ3kj.js";import{A as x,B as S,C,E as w,S as T,T as E,V as D,W as O,_ as k,a as A,b as j,c as ee,d as M,f as te,g as N,h as P,i as ne,j as re,k as ie,n as ae,o as oe,p as se,r as ce,v as le,y as F}from"./parts-C104qEuC.js";import{n as I,t as ue}from"./download-Dr0PgyMr.js";import{n as L,t as de}from"./images-BULrW-FC.js";import{t as R}from"./arrow-right-BqqfPqVi.js";import{t as fe}from"./bot-BHky7KAX.js";import{t as pe}from"./chart-column-DTsDbzL0.js";import{t as me}from"./chevron-right-D1shxvdo.js";import{a as he,c as ge,d as z,f as _e,i as ve,l as ye,n as be,o as xe,p as Se,r as Ce,s as we,t as Te,u as Ee}from"./TeamThread-qTkvxv27.js";import{t as De}from"./file-text-D6OTHixJ.js";import{t as Oe}from"./list-checks-DdTdAQXS.js";import{t as ke}from"./message-square-B_pULba_.js";import{n as Ae,t as je}from"./wrench-BLEJjETg.js";import{t as Me}from"./network-BqmVqC4_.js";import{t as B}from"./plus-CEKaHPBw.js";import{t as Ne}from"./shield-alert-CO7P-cbq.js";import{i as Pe,n as Fe,t as Ie}from"./SkillsParts-jMYdOiWh.js";import{t as Le}from"./users-round-cxQ5HF-C.js";import{$ as Re,A as ze,At as Be,C as Ve,Dt as He,E as Ue,Et as We,F as Ge,Ft as Ke,H as qe,J as Je,K as Ye,M as Xe,N as Ze,Nt as Qe,O as V,Ot as $e,P as et,Pt as tt,Q as nt,St as rt,Tt as it,X as H,Y as at,at as ot,ct as st,dt as ct,et as lt,ht as ut,it as dt,j as ft,k as pt,lt as mt,mt as ht,nt as gt,ot as U,q as _t,rt as vt,st as yt,tt as bt,ut as xt,v as St,vt as Ct,w as wt,x as Tt,xt as Et,yt as Dt}from"./index-CVVVmIFC.js";import{D as Ot,O as kt,S as At,_ as jt,x as Mt}from"./manage-Dwe9yQl9.js";import{n as Nt,r as W,t as Pt}from"./use-resource-qjIkNQDY.js";import{t as Ft}from"./ConfirmDialog-D8f2wI5x.js";import{t as It}from"./Segmented-iylzLwE6.js";import{i as Lt,n as Rt,r as zt,t as Bt}from"./agent-actions-B-9KIwn6.js";import{t as Vt}from"./SpawnTeamModal-Dq7D3Zlc.js";import{t as Ht}from"./TeamForm-Crz3mvXu.js";var Ut=u(`arrow-left-right`,[[`path`,{d:`M8 3 4 7l4 4`,key:`9rb6wj`}],[`path`,{d:`M4 7h16`,key:`6tx8e3`}],[`path`,{d:`m16 21 4-4-4-4`,key:`siv7j2`}],[`path`,{d:`M20 17H4`,key:`h6l3hr`}]]),Wt=u(`arrow-right-left`,[[`path`,{d:`m16 3 4 4-4 4`,key:`1x1c3m`}],[`path`,{d:`M20 7H4`,key:`zbl0bi`}],[`path`,{d:`m8 21-4-4 4-4`,key:`h9nckh`}],[`path`,{d:`M4 17h16`,key:`g4d7ey`}]]),Gt=u(`book-open-check`,[[`path`,{d:`M12 21V7`,key:`gj6g52`}],[`path`,{d:`m16 12 2 2 4-4`,key:`mdajum`}],[`path`,{d:`M22 6V4a1 1 0 0 0-1-1h-5a4 4 0 0 0-4 4 4 4 0 0 0-4-4H3a1 1 0 0 0-1 1v13a1 1 0 0 0 1 1h6a3 3 0 0 1 3 3 3 3 0 0 1 3-3h6a1 1 0 0 0 1-1v-1.3`,key:`8arnkb`}]]),Kt=u(`book-open`,[[`path`,{d:`M12 7v14`,key:`1akyts`}],[`path`,{d:`M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z`,key:`ruj8y`}]]),qt=u(`calendar-clock`,[[`path`,{d:`M16 14v2.2l1.6 1`,key:`fo4ql5`}],[`path`,{d:`M16 2v4`,key:`4m81vk`}],[`path`,{d:`M21 7.5V6a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h3.5`,key:`1osxxc`}],[`path`,{d:`M3 10h5`,key:`r794hk`}],[`path`,{d:`M8 2v4`,key:`1cmpym`}],[`circle`,{cx:`16`,cy:`16`,r:`6`,key:`qoo3c4`}]]),Jt=u(`circle-question-mark`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`,key:`1u773s`}],[`path`,{d:`M12 17h.01`,key:`p32p05`}]]),Yt=u(`columns-2`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M12 3v18`,key:`108xh3`}]]),Xt=u(`corner-down-left`,[[`path`,{d:`M20 4v7a4 4 0 0 1-4 4H4`,key:`6o5b7l`}],[`path`,{d:`m9 10-5 5 5 5`,key:`1kshq7`}]]),Zt=u(`folder-open`,[[`path`,{d:`m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2`,key:`usdka0`}]]),Qt=u(`git-branch`,[[`path`,{d:`M15 6a9 9 0 0 0-9 9V3`,key:`1cii5b`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}],[`circle`,{cx:`6`,cy:`18`,r:`3`,key:`fqmcym`}]]),$t=u(`globe`,[[`circle`,{cx:`12`,cy:`12`,r:`10`,key:`1mglay`}],[`path`,{d:`M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20`,key:`13o1zl`}],[`path`,{d:`M2 12h20`,key:`9i4pu4`}]]),en=u(`history`,[[`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`,key:`1357e3`}],[`path`,{d:`M3 3v5h5`,key:`1xhq8a`}],[`path`,{d:`M12 7v5l4 2`,key:`1fdv2h`}]]),tn=u(`image`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,ry:`2`,key:`1m3agn`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}]]),nn=u(`inbox`,[[`polyline`,{points:`22 12 16 12 14 15 10 15 8 12 2 12`,key:`o97t9d`}],[`path`,{d:`M5.45 5.11 2 12v6a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6l-3.45-6.89A2 2 0 0 0 16.76 4H7.24a2 2 0 0 0-1.79 1.11z`,key:`oot6mr`}]]),rn=u(`layout-template`,[[`rect`,{width:`18`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`f1a2em`}],[`rect`,{width:`9`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`jqznyg`}],[`rect`,{width:`5`,height:`7`,x:`16`,y:`14`,rx:`1`,key:`q5h2i8`}]]),an=u(`lightbulb`,[[`path`,{d:`M15 14c.2-1 .7-1.7 1.5-2.5 1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5.7.7 1.3 1.5 1.5 2.5`,key:`1gvzjb`}],[`path`,{d:`M9 18h6`,key:`x1upvd`}],[`path`,{d:`M10 22h4`,key:`ceow96`}]]),on=u(`message-square-warning`,[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M12 15h.01`,key:`q59x07`}],[`path`,{d:`M12 7v4`,key:`xawao1`}]]),sn=u(`notebook-text`,[[`path`,{d:`M2 6h4`,key:`aawbzj`}],[`path`,{d:`M2 10h4`,key:`l0bgd4`}],[`path`,{d:`M2 14h4`,key:`1gsvsf`}],[`path`,{d:`M2 18h4`,key:`1bu2t1`}],[`rect`,{width:`16`,height:`20`,x:`4`,y:`2`,rx:`2`,key:`1nb95v`}],[`path`,{d:`M9.5 8h5`,key:`11mslq`}],[`path`,{d:`M9.5 12H16`,key:`ktog6x`}],[`path`,{d:`M9.5 16H14`,key:`p1seyn`}]]),cn=u(`octagon-x`,[[`path`,{d:`m15 9-6 6`,key:`1uzhvr`}],[`path`,{d:`M2.586 16.726A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2h6.624a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586z`,key:`2d38gg`}],[`path`,{d:`m9 9 6 6`,key:`z0biqf`}]]),ln=u(`panel-left`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M9 3v18`,key:`fh3hqa`}]]),un=u(`panel-right`,[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}]]),dn=u(`paperclip`,[[`path`,{d:`m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551`,key:`1miecu`}]]),fn=u(`pencil-line`,[[`path`,{d:`M13 21h8`,key:`1jsn5i`}],[`path`,{d:`m15 5 4 4`,key:`1mk7zo`}],[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}]]),pn=u(`pencil`,[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}],[`path`,{d:`m15 5 4 4`,key:`1mk7zo`}]]),mn=u(`refresh-cw`,[[`path`,{d:`M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8`,key:`v9h5vc`}],[`path`,{d:`M21 3v5h-5`,key:`1q7to0`}],[`path`,{d:`M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16`,key:`3uifl3`}],[`path`,{d:`M8 16H3v5`,key:`1cv678`}]]),hn=u(`send`,[[`path`,{d:`M14.536 21.686a.5.5 0 0 0 .937-.024l6.5-19a.496.496 0 0 0-.635-.635l-19 6.5a.5.5 0 0 0-.024.937l7.93 3.18a2 2 0 0 1 1.112 1.11z`,key:`1ffxy3`}],[`path`,{d:`m21.854 2.147-10.94 10.939`,key:`12cjpa`}]]),gn=u(`sticky-note`,[[`path`,{d:`M21 9a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 15 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2z`,key:`1dfntj`}],[`path`,{d:`M15 3v5a1 1 0 0 0 1 1h5`,key:`6s6qgf`}]]),_n=u(`terminal`,[[`path`,{d:`M12 19h8`,key:`baeox8`}],[`path`,{d:`m4 17 6-6-6-6`,key:`1yngyt`}]]),vn=u(`trash-2`,[[`path`,{d:`M10 11v6`,key:`nco0om`}],[`path`,{d:`M14 11v6`,key:`outv1u`}],[`path`,{d:`M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6`,key:`miytrc`}],[`path`,{d:`M3 6h18`,key:`d0wm0j`}],[`path`,{d:`M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2`,key:`e791ji`}]]),G=e(t(),1),yn=/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/;function bn(e){let t=[],n=[],r=0,i=0,a=!1,o=e.replace(/\n$/,``).split(`
3
+ `);for(let e of o){let o=yn.exec(e);o?(r=Number(o[1]),i=Number(o[2]),a=!0,n.push({kind:`hunk`,text:e})):a?e.startsWith(`+`)?n.push({kind:`add`,text:e.slice(1),newLine:i++}):e.startsWith(`-`)?n.push({kind:`remove`,text:e.slice(1),oldLine:r++}):e.startsWith(`\\`)?n.push({kind:`note`,text:e.slice(1).trim()}):n.push({kind:`context`,text:e.slice(1),oldLine:r++,newLine:i++}):t.push(e)}return{header:t,lines:n}}function xn(e){let t=[],n=[],r=[],i=()=>{for(let e=0;e<Math.max(n.length,r.length);e++)t.push({kind:`pair`,left:n[e]??null,right:r[e]??null});n=[],r=[]};for(let a of e)a.kind===`remove`?(r.length>0&&i(),n.push({line:a.oldLine,text:a.text,changed:!0})):a.kind===`add`?r.push({line:a.newLine,text:a.text,changed:!0}):(i(),a.kind===`context`?t.push({kind:`pair`,left:{line:a.oldLine,text:a.text,changed:!1},right:{line:a.newLine,text:a.text,changed:!1}}):t.push(a));return i(),t}function Sn(e){switch(e){case`added`:return`added`;case`modified`:return`modified`;case`deleted`:return`deleted`;case`renamed`:return`renamed`;case`copied`:return`copied`;case`type_changed`:return`type changed`;case`unmerged`:return`unmerged`;case`untracked`:return`untracked`;default:return`changed`}}function Cn(e){let t=Sn(e.status);return e.excludedReason===`credential_shaped`?`${t} · content withheld (credential-shaped)`:e.excludedReason===`bazilion_state`?`${t} · content withheld (Bazilion state)`:e.binary?`${t} · binary`:e.addedLines===null||e.deletedLines===null?t:`${t} · +${e.addedLines} −${e.deletedLines}`}function wn(e,t){switch(e){case`not_repository`:return`This Team workspace is not a Git repository, so there are no changes to review.`;case`unsupported_layout`:return`${t} Bazilion does not widen mounts or run repository helpers to make inspection work; use a repository whose work tree and metadata are reachable from the Team root.`;case`invalid_base`:return`That comparison base is not a branch, tag, commit id or revision such as HEAD~1.`;case`unknown_base`:return`That comparison base does not name a commit in this repository.`;default:return t}}function Tn(e,t){(t==null||t>e.length)&&(t=e.length);for(var n=0,r=Array(t);n<t;n++)r[n]=e[n];return r}function En(e){if(Array.isArray(e))return e}function Dn(e,t){var n=e==null?null:typeof Symbol<`u`&&e[Symbol.iterator]||e[`@@iterator`];if(n!=null){var r,i,a,o,s=[],c=!0,l=!1;try{if(a=(n=n.call(e)).next,t!==0)for(;!(c=(r=a.call(n)).done)&&(s.push(r.value),s.length!==t);c=!0);}catch(e){l=!0,i=e}finally{try{if(!c&&n.return!=null&&(o=n.return(),Object(o)!==o))return}finally{if(l)throw i}}return s}}function On(){throw TypeError(`Invalid attempt to destructure non-iterable instance.
4
+ In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function kn(e,t){return En(e)||Dn(e,t)||An(e,t)||On()}function An(e,t){if(e){if(typeof e==`string`)return Tn(e,t);var n={}.toString.call(e).slice(8,-1);return n===`Object`&&e.constructor&&(n=e.constructor.name),n===`Map`||n===`Set`?Array.from(e):n===`Arguments`||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?Tn(e,t):void 0}}var jn=Object.entries,Mn=Object.setPrototypeOf,Nn=Object.isFrozen,Pn=Object.getPrototypeOf,Fn=Object.getOwnPropertyDescriptor,K=Object.freeze,In=Object.seal,Ln=Object.create,Rn=typeof Reflect<`u`&&Reflect,zn=Rn.apply,Bn=Rn.construct;K||=function(e){return e},In||=function(e){return e},zn||=function(e,t){var n=[...arguments].slice(2);return e.apply(t,n)},Bn||=function(e){return new e(...[...arguments].slice(1))};var Vn=Y(Array.prototype.forEach),Hn=Y(Array.prototype.lastIndexOf),Un=Y(Array.prototype.pop),Wn=Y(Array.prototype.push),Gn=Y(Array.prototype.splice),Kn=Array.isArray,qn=Y(String.prototype.toLowerCase),Jn=Y(String.prototype.toString),Yn=Y(String.prototype.match),Xn=Y(String.prototype.replace),Zn=Y(String.prototype.indexOf),Qn=Y(String.prototype.trim),$n=Y(Number.prototype.toString),er=Y(Boolean.prototype.toString),tr=typeof BigInt>`u`?null:Y(BigInt.prototype.toString),nr=typeof Symbol>`u`?null:Y(Symbol.prototype.toString),q=Y(Object.prototype.hasOwnProperty),rr=Y(Object.prototype.toString),J=Y(RegExp.prototype.test),ir=ar(TypeError);function Y(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);var n=[...arguments].slice(1);return zn(e,t,n)}}function ar(e){return function(){return Bn(e,[...arguments])}}function X(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:qn;if(Mn&&Mn(e,null),!Kn(t))return e;let r=t.length;for(;r--;){let i=t[r];if(typeof i==`string`){let e=n(i);e!==i&&(Nn(t)||(t[r]=e),i=e)}e[i]=!0}return e}function or(e){for(let t=0;t<e.length;t++)q(e,t)||(e[t]=null);return e}function sr(e){let t=Ln(null);for(let r of jn(e)){var n=kn(r,2);let i=n[0],a=n[1];q(e,i)&&(Kn(a)?t[i]=or(a):a&&typeof a==`object`&&a.constructor===Object?t[i]=sr(a):t[i]=a)}return t}function cr(e){switch(typeof e){case`string`:return e;case`number`:return $n(e);case`boolean`:return er(e);case`bigint`:return tr?tr(e):`0`;case`symbol`:return nr?nr(e):`Symbol()`;case`undefined`:return rr(e);case`function`:case`object`:{if(e===null)return rr(e);let t=e,n=lr(t,`toString`);if(typeof n==`function`){let e=n(t);return typeof e==`string`?e:rr(e)}return rr(e)}default:return rr(e)}}function lr(e,t){for(;e!==null;){let n=Fn(e,t);if(n){if(n.get)return Y(n.get);if(typeof n.value==`function`)return Y(n.value)}e=Pn(e)}function n(){return null}return n}function ur(e){try{return J(e,``),!0}catch{return!1}}var dr=K(`a.abbr.acronym.address.area.article.aside.audio.b.bdi.bdo.big.blink.blockquote.body.br.button.canvas.caption.center.cite.code.col.colgroup.content.data.datalist.dd.decorator.del.details.dfn.dialog.dir.div.dl.dt.element.em.fieldset.figcaption.figure.font.footer.form.h1.h2.h3.h4.h5.h6.head.header.hgroup.hr.html.i.img.input.ins.kbd.label.legend.li.main.map.mark.marquee.menu.menuitem.meter.nav.nobr.ol.optgroup.option.output.p.picture.pre.progress.q.rp.rt.ruby.s.samp.search.section.select.shadow.slot.small.source.spacer.span.strike.strong.style.sub.summary.sup.table.tbody.td.template.textarea.tfoot.th.thead.time.tr.track.tt.u.ul.var.video.wbr`.split(`.`)),fr=K(`svg.a.altglyph.altglyphdef.altglyphitem.animatecolor.animatemotion.animatetransform.circle.clippath.defs.desc.ellipse.enterkeyhint.exportparts.filter.font.g.glyph.glyphref.hkern.image.inputmode.line.lineargradient.marker.mask.metadata.mpath.part.path.pattern.polygon.polyline.radialgradient.rect.stop.style.switch.symbol.text.textpath.title.tref.tspan.view.vkern`.split(`.`)),pr=K([`feBlend`,`feColorMatrix`,`feComponentTransfer`,`feComposite`,`feConvolveMatrix`,`feDiffuseLighting`,`feDisplacementMap`,`feDistantLight`,`feDropShadow`,`feFlood`,`feFuncA`,`feFuncB`,`feFuncG`,`feFuncR`,`feGaussianBlur`,`feImage`,`feMerge`,`feMergeNode`,`feMorphology`,`feOffset`,`fePointLight`,`feSpecularLighting`,`feSpotLight`,`feTile`,`feTurbulence`]),mr=K([`animate`,`color-profile`,`cursor`,`discard`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`foreignobject`,`hatch`,`hatchpath`,`mesh`,`meshgradient`,`meshpatch`,`meshrow`,`missing-glyph`,`script`,`set`,`solidcolor`,`unknown`,`use`]),hr=K(`math.menclose.merror.mfenced.mfrac.mglyph.mi.mlabeledtr.mmultiscripts.mn.mo.mover.mpadded.mphantom.mroot.mrow.ms.mspace.msqrt.mstyle.msub.msup.msubsup.mtable.mtd.mtext.mtr.munder.munderover.mprescripts`.split(`.`)),gr=K([`maction`,`maligngroup`,`malignmark`,`mlongdiv`,`mscarries`,`mscarry`,`msgroup`,`mstack`,`msline`,`msrow`,`semantics`,`annotation`,`annotation-xml`,`mprescripts`,`none`]),_r=K([`#text`]),vr=K(`accept.action.align.alt.autocapitalize.autocomplete.autopictureinpicture.autoplay.background.bgcolor.border.capture.cellpadding.cellspacing.checked.cite.class.clear.color.cols.colspan.command.commandfor.controls.controlslist.coords.crossorigin.datetime.decoding.default.dir.disabled.disablepictureinpicture.disableremoteplayback.download.draggable.enctype.enterkeyhint.exportparts.face.for.headers.height.hidden.high.href.hreflang.id.inert.inputmode.integrity.ismap.kind.label.lang.list.loading.loop.low.max.maxlength.media.method.min.minlength.multiple.muted.name.nonce.noshade.novalidate.nowrap.open.optimum.part.pattern.placeholder.playsinline.popover.popovertarget.popovertargetaction.poster.preload.pubdate.radiogroup.readonly.rel.required.rev.reversed.role.rows.rowspan.spellcheck.scope.selected.shape.size.sizes.slot.span.srclang.start.src.srcset.step.style.summary.tabindex.title.translate.type.usemap.valign.value.width.wrap.xmlns`.split(`.`)),yr=K(`accent-height.accumulate.additive.alignment-baseline.amplitude.ascent.attributename.attributetype.azimuth.basefrequency.baseline-shift.begin.bias.by.class.clip.clippathunits.clip-path.clip-rule.color.color-interpolation.color-interpolation-filters.color-profile.color-rendering.cx.cy.d.dx.dy.diffuseconstant.direction.display.divisor.dur.edgemode.elevation.end.exponent.fill.fill-opacity.fill-rule.filter.filterunits.flood-color.flood-opacity.font-family.font-size.font-size-adjust.font-stretch.font-style.font-variant.font-weight.fx.fy.g1.g2.glyph-name.glyphref.gradientunits.gradienttransform.height.href.id.image-rendering.in.in2.intercept.k.k1.k2.k3.k4.kerning.keypoints.keysplines.keytimes.lang.lengthadjust.letter-spacing.kernelmatrix.kernelunitlength.lighting-color.local.marker-end.marker-mid.marker-start.markerheight.markerunits.markerwidth.maskcontentunits.maskunits.max.mask.mask-type.media.method.mode.min.name.numoctaves.offset.operator.opacity.order.orient.orientation.origin.overflow.paint-order.path.pathlength.patterncontentunits.patterntransform.patternunits.points.preservealpha.preserveaspectratio.primitiveunits.r.rx.ry.radius.refx.refy.repeatcount.repeatdur.restart.result.rotate.scale.seed.shape-rendering.slope.specularconstant.specularexponent.spreadmethod.startoffset.stddeviation.stitchtiles.stop-color.stop-opacity.stroke-dasharray.stroke-dashoffset.stroke-linecap.stroke-linejoin.stroke-miterlimit.stroke-opacity.stroke.stroke-width.style.surfacescale.systemlanguage.tabindex.tablevalues.targetx.targety.transform.transform-origin.text-anchor.text-decoration.text-rendering.textlength.type.u1.u2.unicode.values.viewbox.visibility.version.vert-adv-y.vert-origin-x.vert-origin-y.width.word-spacing.wrap.writing-mode.xchannelselector.ychannelselector.x.x1.x2.xmlns.y.y1.y2.z.zoomandpan`.split(`.`)),br=K(`accent.accentunder.align.bevelled.close.columnalign.columnlines.columnspacing.columnspan.denomalign.depth.dir.display.displaystyle.encoding.fence.frame.height.href.id.largeop.length.linethickness.lquote.lspace.mathbackground.mathcolor.mathsize.mathvariant.maxsize.minsize.movablelimits.notation.numalign.open.rowalign.rowlines.rowspacing.rowspan.rspace.rquote.scriptlevel.scriptminsize.scriptsizemultiplier.selection.separator.separators.stretchy.subscriptshift.supscriptshift.symmetric.voffset.width.xmlns`.split(`.`)),xr=K([`xlink:href`,`xml:id`,`xlink:title`,`xml:space`,`xmlns:xlink`]),Sr=In(/{{[\w\W]*|^[\w\W]*}}/g),Cr=In(/<%[\w\W]*|^[\w\W]*%>/g),wr=In(/\${[\w\W]*/g),Tr=In(/^data-[\-\w.\u00B7-\uFFFF]+$/),Er=In(/^aria-[\-\w]+$/),Dr=In(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),Or=In(/^(?:\w+script|data):/i),kr=In(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),Ar=In(/^html$/i),jr=In(/^[a-z][.\w]*(-[.\w]+)+$/i),Mr=In(/<[/\w!]/g),Nr=In(/<[/\w]/g),Pr=In(/<\/no(script|embed|frames)/i),Fr=In(/\/>/i),Ir={element:1,attribute:2,text:3,cdataSection:4,entityReference:5,entityNode:6,processingInstruction:7,comment:8,document:9,documentType:10,documentFragment:11,notation:12},Lr=function(){return typeof window>`u`?null:window},Rr=function(e,t){if(typeof e!=`object`||typeof e.createPolicy!=`function`)return null;let n=null,r=`data-tt-policy-suffix`;t&&t.hasAttribute(r)&&(n=t.getAttribute(r));let i=`dompurify`+(n?`#`+n:``);try{return e.createPolicy(i,{createHTML(e){return e},createScriptURL(e){return e}})}catch{return console.warn(`TrustedTypes policy `+i+` could not be created.`),null}},zr=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}},Br=function(e,t,n,r){return q(e,t)&&Kn(e[t])?X(r.base?sr(r.base):{},e[t],r.transform):n};function Vr(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:Lr(),t=e=>Vr(e);if(t.version=`3.4.11`,t.removed=[],!e||!e.document||e.document.nodeType!==Ir.document||!e.Element)return t.isSupported=!1,t;let n=e.document,r=n,i=r.currentScript;e.DocumentFragment;let a=e.HTMLTemplateElement,o=e.Node,s=e.Element,c=e.NodeFilter;e.NamedNodeMap===void 0&&(e.NamedNodeMap||e.MozNamedAttrMap),e.HTMLFormElement;let l=e.DOMParser,u=e.trustedTypes,d=s.prototype,f=lr(d,`cloneNode`),p=lr(d,`remove`),m=lr(d,`nextSibling`),h=lr(d,`childNodes`),g=lr(d,`parentNode`),_=lr(d,`shadowRoot`),v=lr(d,`attributes`),y=o&&o.prototype?lr(o.prototype,`nodeType`):null,b=o&&o.prototype?lr(o.prototype,`nodeName`):null;if(typeof a==`function`){let e=n.createElement(`template`);e.content&&e.content.ownerDocument&&(n=e.content.ownerDocument)}let x,S=``,C,w=!1,T=0,E=function(){if(T>0)throw ir(`A configured TRUSTED_TYPES_POLICY callback (createHTML or createScriptURL) must not call DOMPurify.sanitize, as that causes infinite recursion. Do not pass a policy whose callbacks wrap DOMPurify as TRUSTED_TYPES_POLICY; see the "DOMPurify and Trusted Types" section of the README.`)},D=function(e){E(),T++;try{return x.createHTML(e)}finally{T--}},O=function(e){E(),T++;try{return x.createScriptURL(e)}finally{T--}},k=function(){return w||=(C=Rr(u,i),!0),C},A=n,j=A.implementation,ee=A.createNodeIterator,M=A.createDocumentFragment,te=A.getElementsByTagName,N=r.importNode,P=zr();t.isSupported=typeof jn==`function`&&typeof g==`function`&&j&&j.createHTMLDocument!==void 0;let ne=Sr,re=Cr,ie=wr,ae=Tr,oe=Er,se=Or,ce=kr,le=jr,F=Dr,I=null,ue=X({},[...dr,...fr,...pr,...hr,..._r]),L=null,de=X({},[...vr,...yr,...br,...xr]),R=Object.seal(Ln(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),fe=null,pe=null,me=Object.seal(Ln(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}})),he=!0,ge=!0,z=!1,_e=!0,ve=!1,ye=!0,be=!1,xe=!1,Se=null,Ce=null,we=!1,Te=!1,Ee=!1,De=!1,Oe=!0,ke=!1,Ae=`user-content-`,je=!0,Me=!1,B={},Ne=null,Pe=X({},`annotation-xml.audio.colgroup.desc.foreignobject.head.iframe.math.mi.mn.mo.ms.mtext.noembed.noframes.noscript.plaintext.script.selectedcontent.style.svg.template.thead.title.video.xmp`.split(`.`)),Fe=null,Ie=X({},[`audio`,`video`,`img`,`source`,`image`,`track`]),Le=null,Re=X({},[`alt`,`class`,`for`,`id`,`label`,`name`,`pattern`,`placeholder`,`role`,`summary`,`title`,`value`,`style`,`xmlns`]),ze=`http://www.w3.org/1998/Math/MathML`,Be=`http://www.w3.org/2000/svg`,Ve=`http://www.w3.org/1999/xhtml`,He=Ve,Ue=!1,We=null,Ge=X({},[ze,Be,Ve],Jn),Ke=K([`mi`,`mo`,`mn`,`ms`,`mtext`]),qe=X({},Ke),Je=K([`annotation-xml`]),Ye=X({},Je),Xe=X({},[`title`,`style`,`font`,`a`,`script`]),Ze=null,Qe=[`application/xhtml+xml`,`text/html`],V=null,$e=null,et=n.createElement(`form`),tt=function(e){return e instanceof RegExp||e instanceof Function},nt=function(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if($e&&$e===e)return;(!e||typeof e!=`object`)&&(e={}),e=sr(e),Ze=Qe.indexOf(e.PARSER_MEDIA_TYPE)===-1?`text/html`:e.PARSER_MEDIA_TYPE,V=Ze===`application/xhtml+xml`?Jn:qn,I=Br(e,`ALLOWED_TAGS`,ue,{transform:V}),L=Br(e,`ALLOWED_ATTR`,de,{transform:V}),We=Br(e,`ALLOWED_NAMESPACES`,Ge,{transform:Jn}),Le=Br(e,`ADD_URI_SAFE_ATTR`,Re,{transform:V,base:Re}),Fe=Br(e,`ADD_DATA_URI_TAGS`,Ie,{transform:V,base:Ie}),Ne=Br(e,`FORBID_CONTENTS`,Pe,{transform:V}),fe=Br(e,`FORBID_TAGS`,sr({}),{transform:V}),pe=Br(e,`FORBID_ATTR`,sr({}),{transform:V}),B=q(e,`USE_PROFILES`)?e.USE_PROFILES&&typeof e.USE_PROFILES==`object`?sr(e.USE_PROFILES):e.USE_PROFILES:!1,he=e.ALLOW_ARIA_ATTR!==!1,ge=e.ALLOW_DATA_ATTR!==!1,z=e.ALLOW_UNKNOWN_PROTOCOLS||!1,_e=e.ALLOW_SELF_CLOSE_IN_ATTR!==!1,ve=e.SAFE_FOR_TEMPLATES||!1,ye=e.SAFE_FOR_XML!==!1,be=e.WHOLE_DOCUMENT||!1,Te=e.RETURN_DOM||!1,Ee=e.RETURN_DOM_FRAGMENT||!1,De=e.RETURN_TRUSTED_TYPE||!1,we=e.FORCE_BODY||!1,Oe=e.SANITIZE_DOM!==!1,ke=e.SANITIZE_NAMED_PROPS||!1,je=e.KEEP_CONTENT!==!1,Me=e.IN_PLACE||!1,F=ur(e.ALLOWED_URI_REGEXP)?e.ALLOWED_URI_REGEXP:Dr,He=typeof e.NAMESPACE==`string`?e.NAMESPACE:Ve,qe=q(e,`MATHML_TEXT_INTEGRATION_POINTS`)&&e.MATHML_TEXT_INTEGRATION_POINTS&&typeof e.MATHML_TEXT_INTEGRATION_POINTS==`object`?sr(e.MATHML_TEXT_INTEGRATION_POINTS):X({},Ke),Ye=q(e,`HTML_INTEGRATION_POINTS`)&&e.HTML_INTEGRATION_POINTS&&typeof e.HTML_INTEGRATION_POINTS==`object`?sr(e.HTML_INTEGRATION_POINTS):X({},Je);let t=q(e,`CUSTOM_ELEMENT_HANDLING`)&&e.CUSTOM_ELEMENT_HANDLING&&typeof e.CUSTOM_ELEMENT_HANDLING==`object`?sr(e.CUSTOM_ELEMENT_HANDLING):Ln(null);if(R=Ln(null),q(t,`tagNameCheck`)&&tt(t.tagNameCheck)&&(R.tagNameCheck=t.tagNameCheck),q(t,`attributeNameCheck`)&&tt(t.attributeNameCheck)&&(R.attributeNameCheck=t.attributeNameCheck),q(t,`allowCustomizedBuiltInElements`)&&typeof t.allowCustomizedBuiltInElements==`boolean`&&(R.allowCustomizedBuiltInElements=t.allowCustomizedBuiltInElements),In(R),ve&&(ge=!1),Ee&&(Te=!0),B&&(I=X({},_r),L=Ln(null),B.html===!0&&(X(I,dr),X(L,vr)),B.svg===!0&&(X(I,fr),X(L,yr),X(L,xr)),B.svgFilters===!0&&(X(I,pr),X(L,yr),X(L,xr)),B.mathMl===!0&&(X(I,hr),X(L,br),X(L,xr))),me.tagCheck=null,me.attributeCheck=null,q(e,`ADD_TAGS`)&&(typeof e.ADD_TAGS==`function`?me.tagCheck=e.ADD_TAGS:Kn(e.ADD_TAGS)&&(I===ue&&(I=sr(I)),X(I,e.ADD_TAGS,V))),q(e,`ADD_ATTR`)&&(typeof e.ADD_ATTR==`function`?me.attributeCheck=e.ADD_ATTR:Kn(e.ADD_ATTR)&&(L===de&&(L=sr(L)),X(L,e.ADD_ATTR,V))),q(e,`ADD_URI_SAFE_ATTR`)&&Kn(e.ADD_URI_SAFE_ATTR)&&X(Le,e.ADD_URI_SAFE_ATTR,V),q(e,`FORBID_CONTENTS`)&&Kn(e.FORBID_CONTENTS)&&(Ne===Pe&&(Ne=sr(Ne)),X(Ne,e.FORBID_CONTENTS,V)),q(e,`ADD_FORBID_CONTENTS`)&&Kn(e.ADD_FORBID_CONTENTS)&&(Ne===Pe&&(Ne=sr(Ne)),X(Ne,e.ADD_FORBID_CONTENTS,V)),je&&(I[`#text`]=!0),be&&X(I,[`html`,`head`,`body`]),I.table&&(X(I,[`tbody`]),delete fe.tbody),e.TRUSTED_TYPES_POLICY){if(typeof e.TRUSTED_TYPES_POLICY.createHTML!=`function`)throw ir(`TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.`);if(typeof e.TRUSTED_TYPES_POLICY.createScriptURL!=`function`)throw ir(`TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.`);let t=x;x=e.TRUSTED_TYPES_POLICY;try{S=D(``)}catch(e){throw x=t,e}}else e.TRUSTED_TYPES_POLICY===null?(x=void 0,S=``):(x===void 0&&(x=k()),x&&typeof S==`string`&&(S=D(``)));K&&K(e),$e=e},rt=X({},[...fr,...pr,...mr]),it=X({},[...hr,...gr]),H=function(e,t,n){return t.namespaceURI===Ve?e===`svg`:t.namespaceURI===ze?e===`svg`&&(n===`annotation-xml`||qe[n]):!!rt[e]},at=function(e,t,n){return t.namespaceURI===Ve?e===`math`:t.namespaceURI===Be?e===`math`&&Ye[n]:!!it[e]},ot=function(e,t,n){return t.namespaceURI===Be&&!Ye[n]||t.namespaceURI===ze&&!qe[n]?!1:!it[e]&&(Xe[e]||!rt[e])},st=function(e){let t=g(e);(!t||!t.tagName)&&(t={namespaceURI:He,tagName:`template`});let n=qn(e.tagName),r=qn(t.tagName);return We[e.namespaceURI]?e.namespaceURI===Be?H(n,t,r):e.namespaceURI===ze?at(n,t,r):e.namespaceURI===Ve?ot(n,t,r):!!(Ze===`application/xhtml+xml`&&We[e.namespaceURI]):!1},ct=function(e){Wn(t.removed,{element:e});try{g(e).removeChild(e)}catch{if(p(e),!g(e))throw ir(`a node selected for removal could not be detached from its tree and cannot be safely returned; refusing to sanitize in place`)}},lt=function(e){let t=h(e);if(t){let e=[];Vn(t,t=>{Wn(e,t)}),Vn(e,e=>{try{p(e)}catch{}})}let n=v(e);if(n)for(let t=n.length-1;t>=0;--t){let r=n[t],i=r&&r.name;if(typeof i==`string`)try{e.removeAttribute(i)}catch{}}},ut=function(e,n){try{Wn(t.removed,{attribute:n.getAttributeNode(e),from:n})}catch{Wn(t.removed,{attribute:null,from:n})}if(n.removeAttribute(e),e===`is`)if(Te||Ee)try{ct(n)}catch{}else try{n.setAttribute(e,``)}catch{}},dt=function(e){let t=v(e);if(t)for(let n=t.length-1;n>=0;--n){let r=t[n],i=r&&r.name;if(!(typeof i!=`string`||L[V(i)]))try{e.removeAttribute(i)}catch{}}},ft=function(e){let t=[e];for(;t.length>0;){let e=t.pop();(y?y(e):e.nodeType)===Ir.element&&dt(e);let n=h(e);if(n)for(let e=n.length-1;e>=0;--e)t.push(n[e])}},pt=function(e){let t=null,r=null;if(we)e=`<remove></remove>`+e;else{let t=Yn(e,/^[\r\n\t ]+/);r=t&&t[0]}Ze===`application/xhtml+xml`&&He===Ve&&(e=`<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>`+e+`</body></html>`);let i=x?D(e):e;if(He===Ve)try{t=new l().parseFromString(i,Ze)}catch{}if(!t||!t.documentElement){t=j.createDocument(He,`template`,null);try{t.documentElement.innerHTML=Ue?S:i}catch{}}let a=t.body||t.documentElement;return e&&r&&a.insertBefore(n.createTextNode(r),a.childNodes[0]||null),He===Ve?te.call(t,be?`html`:`body`)[0]:be?t.documentElement:a},mt=function(e){return ee.call(e.ownerDocument||e,e,c.SHOW_ELEMENT|c.SHOW_COMMENT|c.SHOW_TEXT|c.SHOW_PROCESSING_INSTRUCTION|c.SHOW_CDATA_SECTION,null)},ht=function(e){return e=Xn(e,ne,` `),e=Xn(e,re,` `),e=Xn(e,ie,` `),e},gt=function(e){e.normalize();let t=ee.call(e.ownerDocument||e,e,c.SHOW_TEXT|c.SHOW_COMMENT|c.SHOW_CDATA_SECTION|c.SHOW_PROCESSING_INSTRUCTION,null),n=t.nextNode();for(;n;)n.data=ht(n.data),n=t.nextNode();let r=e.querySelectorAll?.call(e,`template`);r&&Vn(r,e=>{_t(e.content)&&gt(e.content)})},U=function(e){let t=b?b(e):null;return typeof t!=`string`||V(t)!==`form`?!1:typeof e.nodeName!=`string`||typeof e.textContent!=`string`||typeof e.removeChild!=`function`||e.attributes!==v(e)||typeof e.removeAttribute!=`function`||typeof e.setAttribute!=`function`||typeof e.namespaceURI!=`string`||typeof e.insertBefore!=`function`||typeof e.hasChildNodes!=`function`||e.nodeType!==y(e)||e.childNodes!==h(e)},_t=function(e){if(!y||typeof e!=`object`||!e)return!1;try{return y(e)===Ir.documentFragment}catch{return!1}},vt=function(e){if(!y||typeof e!=`object`||!e)return!1;try{return typeof y(e)==`number`}catch{return!1}};function yt(e,n,r){e.length!==0&&Vn(e,e=>{e.call(t,n,r,$e)})}let bt=function(e,t){return!!(ye&&e.hasChildNodes()&&!vt(e.firstElementChild)&&J(Mr,e.textContent)&&J(Mr,e.innerHTML)||ye&&e.namespaceURI===Ve&&t===`style`&&vt(e.firstElementChild)||e.nodeType===Ir.processingInstruction||ye&&e.nodeType===Ir.comment&&J(Nr,e.data))},xt=function(e,t){if(!fe[t]&&Tt(t)&&(R.tagNameCheck instanceof RegExp&&J(R.tagNameCheck,t)||R.tagNameCheck instanceof Function&&R.tagNameCheck(t)))return!1;if(je&&!Ne[t]){let t=g(e),n=h(e);if(n&&t){let r=n.length;for(let i=r-1;i>=0;--i){let r=Me?n[i]:f(n[i],!0);t.insertBefore(r,m(e))}}}return ct(e),!0},St=function(e){if(yt(P.beforeSanitizeElements,e,null),U(e))return ct(e),!0;let n=V(b?b(e):e.nodeName);if(yt(P.uponSanitizeElement,e,{tagName:n,allowedTags:I}),bt(e,n))return ct(e),!0;if(fe[n]||!(me.tagCheck instanceof Function&&me.tagCheck(n))&&!I[n])return xt(e,n);if((y?y(e):e.nodeType)===Ir.element&&!st(e)||(n===`noscript`||n===`noembed`||n===`noframes`)&&J(Pr,e.innerHTML))return ct(e),!0;if(ve&&e.nodeType===Ir.text){let n=ht(e.textContent);e.textContent!==n&&(Wn(t.removed,{element:e.cloneNode()}),e.textContent=n)}return yt(P.afterSanitizeElements,e,null),!1},Ct=function(e,t,r){if(pe[t]||Oe&&(t===`id`||t===`name`)&&(r in n||r in et))return!1;let i=L[t]||me.attributeCheck instanceof Function&&me.attributeCheck(t,e);if(!(ge&&J(ae,t))&&!(he&&J(oe,t))){if(!i){if(!(Tt(e)&&(R.tagNameCheck instanceof RegExp&&J(R.tagNameCheck,e)||R.tagNameCheck instanceof Function&&R.tagNameCheck(e))&&(R.attributeNameCheck instanceof RegExp&&J(R.attributeNameCheck,t)||R.attributeNameCheck instanceof Function&&R.attributeNameCheck(t,e))||t===`is`&&R.allowCustomizedBuiltInElements&&(R.tagNameCheck instanceof RegExp&&J(R.tagNameCheck,r)||R.tagNameCheck instanceof Function&&R.tagNameCheck(r))))return!1}else if(!Le[t]&&!J(F,Xn(r,ce,``))&&!((t===`src`||t===`xlink:href`||t===`href`)&&e!==`script`&&Zn(r,`data:`)===0&&Fe[e])&&!(z&&!J(se,Xn(r,ce,``)))&&r)return!1}return!0},wt=X({},[`annotation-xml`,`color-profile`,`font-face`,`font-face-format`,`font-face-name`,`font-face-src`,`font-face-uri`,`missing-glyph`]),Tt=function(e){return!wt[qn(e)]&&J(le,e)},Et=function(e,t,n,r){if(x&&typeof u==`object`&&typeof u.getAttributeType==`function`&&!n)switch(u.getAttributeType(e,t)){case`TrustedHTML`:return D(r);case`TrustedScriptURL`:return O(r)}return r},Dt=function(e,n,r,i){try{r?e.setAttributeNS(r,n,i):e.setAttribute(n,i),U(e)?ct(e):Un(t.removed)}catch{ut(n,e)}},Ot=function(e){yt(P.beforeSanitizeAttributes,e,null);let t=e.attributes;if(!t||U(e))return;let n={attrName:``,attrValue:``,keepAttr:!0,allowedAttributes:L,forceKeepAttr:void 0},r=t.length,i=V(e.nodeName);for(;r--;){let a=t[r],o=a.name,s=a.namespaceURI,c=a.value,l=V(o),u=c,d=o===`value`?u:Qn(u);if(n.attrName=l,n.attrValue=d,n.keepAttr=!0,n.forceKeepAttr=void 0,yt(P.uponSanitizeAttribute,e,n),d=n.attrValue,ke&&(l===`id`||l===`name`)&&Zn(d,Ae)!==0&&(ut(o,e),d=Ae+d),ye&&J(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,d)){ut(o,e);continue}if(l===`attributename`&&Yn(d,`href`)){ut(o,e);continue}if(!n.forceKeepAttr){if(!n.keepAttr){ut(o,e);continue}if(!_e&&J(Fr,d)){ut(o,e);continue}if(ve&&(d=ht(d)),!Ct(i,l,d)){ut(o,e);continue}d=Et(i,l,s,d),d!==u&&Dt(e,o,s,d)}}yt(P.afterSanitizeAttributes,e,null)},kt=function(e){let t=null,n=mt(e);for(yt(P.beforeSanitizeShadowDOM,e,null);t=n.nextNode();)if(yt(P.uponSanitizeShadowNode,t,null),St(t),Ot(t),_t(t.content)&&kt(t.content),(y?y(t):t.nodeType)===Ir.element){let e=_(t);_t(e)&&(At(e),kt(e))}yt(P.afterSanitizeShadowDOM,e,null)},At=function(e){let t=[{node:e,shadow:null}];for(;t.length>0;){let e=t.pop();if(e.shadow){kt(e.shadow);continue}let n=e.node,r=(y?y(n):n.nodeType)===Ir.element,i=h(n);if(i)for(let e=i.length-1;e>=0;--e)t.push({node:i[e],shadow:null});if(r){let e=b?b(n):null;if(typeof e==`string`&&V(e)===`template`){let e=n.content;_t(e)&&t.push({node:e,shadow:null})}}if(r){let e=_(n);_t(e)&&t.push({node:null,shadow:e},{node:e,shadow:null})}}};return t.sanitize=function(e){let n=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},i=null,a=null,o=null,s=null;if(Ue=!e,Ue&&(e=`<!-->`),typeof e!=`string`&&!vt(e)&&(e=cr(e),typeof e!=`string`))throw ir(`dirty is not a string, aborting`);if(!t.isSupported)return e;xe?(I=Se,L=Ce):nt(n),(P.uponSanitizeElement.length>0||P.uponSanitizeAttribute.length>0)&&(I=sr(I)),P.uponSanitizeAttribute.length>0&&(L=sr(L)),t.removed=[];let c=Me&&typeof e!=`string`&&vt(e);if(c){let t=b?b(e):e.nodeName;if(typeof t==`string`){let e=V(t);if(!I[e]||fe[e])throw ir(`root node is forbidden and cannot be sanitized in-place`)}if(U(e))throw ir(`root node is clobbered and cannot be sanitized in-place`);try{At(e)}catch(t){throw lt(e),t}}else if(vt(e))i=pt(`<!---->`),a=i.ownerDocument.importNode(e,!0),a.nodeType===Ir.element&&a.nodeName===`BODY`||a.nodeName===`HTML`?i=a:i.appendChild(a),At(a);else{if(!Te&&!ve&&!be&&e.indexOf(`<`)===-1)return x&&De?D(e):e;if(i=pt(e),!i)return Te?null:De?S:``}i&&we&&ct(i.firstChild);let l=mt(c?e:i);try{for(;o=l.nextNode();)St(o),Ot(o),_t(o.content)&&kt(o.content)}catch(t){throw c&&lt(e),t}if(c)return Vn(t.removed,e=>{e.element&&ft(e.element)}),ve&&gt(e),e;if(Te){if(ve&&gt(i),Ee)for(s=M.call(i.ownerDocument);i.firstChild;)s.appendChild(i.firstChild);else s=i;return(L.shadowroot||L.shadowrootmode)&&(s=N.call(r,s,!0)),s}let u=be?i.outerHTML:i.innerHTML;return be&&I[`!doctype`]&&i.ownerDocument&&i.ownerDocument.doctype&&i.ownerDocument.doctype.name&&J(Ar,i.ownerDocument.doctype.name)&&(u=`<!DOCTYPE `+i.ownerDocument.doctype.name+`>
5
+ `+u),ve&&(u=ht(u)),x&&De?D(u):u},t.setConfig=function(){nt(arguments.length>0&&arguments[0]!==void 0?arguments[0]:{}),xe=!0,Se=I,Ce=L},t.clearConfig=function(){$e=null,xe=!1,Se=null,Ce=null,x=C,S=``},t.isValidAttribute=function(e,t,n){return $e||nt({}),Ct(V(e),V(t),n)},t.addHook=function(e,t){typeof t==`function`&&q(P,e)&&Wn(P[e],t)},t.removeHook=function(e,t){if(q(P,e)){if(t!==void 0){let n=Hn(P[e],t);return n===-1?void 0:Gn(P[e],n,1)[0]}return Un(P[e])}},t.removeHooks=function(e){q(P,e)&&(P[e]=[])},t.removeAllHooks=function(){P=zr()},t}var Hr=Vr();function Ur(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var Wr=Ur();function Gr(e){Wr=e}var Kr={exec:()=>null};function qr(e){let t=[];return n=>{let r=Math.max(0,Math.min(3,n-1)),i=t[r];return i||(i=e(r),t[r]=i),i}}function Z(e,t=``){let n=typeof e==`string`?e:e.source,r={replace:(e,t)=>{let i=typeof t==`string`?t:t.source;return i=i.replace(Yr.caret,`$1`),n=n.replace(e,i),r},getRegex:()=>new RegExp(n,t)};return r}var Jr=((e=``)=>{try{return!!RegExp(`(?<=1)(?<!1)`+e)}catch{return!1}})(),Yr={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:qr(e=>RegExp(`^ {0,${e}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:qr(e=>RegExp(`^ {0,${e}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`)),fencesBeginRegex:qr(e=>RegExp(`^ {0,${e}}(?:\`\`\`|~~~)`)),headingBeginRegex:qr(e=>RegExp(`^ {0,${e}}#`)),htmlBeginRegex:qr(e=>RegExp(`^ {0,${e}}<(?:[a-z].*>|!--)`,`i`)),blockquoteBeginRegex:qr(e=>RegExp(`^ {0,${e}}>`))},Xr=/^(?:[ \t]*(?:\n|$))+/,Zr=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,Qr=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,$r=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,ei=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,ti=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,ni=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,ri=Z(ni).replace(/bull/g,ti).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,``).getRegex(),ii=Z(ni).replace(/bull/g,ti).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),ai=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,oi=/^[^\n]+/,si=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,ci=Z(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace(`label`,si).replace(`title`,/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),li=Z(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,ti).getRegex(),ui=`address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul`,di=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,fi=Z(`^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))`,`i`).replace(`comment`,di).replace(`tag`,ui).replace(`attribute`,/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),pi=Z(ai).replace(`hr`,$r).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,ui).getRegex(),mi={blockquote:Z(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace(`paragraph`,pi).getRegex(),code:Zr,def:ci,fences:Qr,heading:ei,hr:$r,html:fi,lheading:ri,list:li,newline:Xr,paragraph:pi,table:Kr,text:oi},hi=Z(`^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)`).replace(`hr`,$r).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`blockquote`,` {0,3}>`).replace(`code`,`(?: {4}| {0,3} )[^\\n]`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,ui).getRegex(),gi={...mi,lheading:ii,table:hi,paragraph:Z(ai).replace(`hr`,$r).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`table`,hi).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,ui).getRegex()},_i={...mi,html:Z(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace(`comment`,di).replace(/tag/g,`(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b`).getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:Kr,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:Z(ai).replace(`hr`,$r).replace(`heading`,` *#{1,6} *[^
6
+ ]`).replace(`lheading`,ri).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`|fences`,``).replace(`|list`,``).replace(`|html`,``).replace(`|tag`,``).getRegex()},vi=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,yi=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,bi=/^( {2,}|\\)\n(?!\s*$)/,xi=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,Si=/[\p{P}\p{S}]/u,Ci=/[\s\p{P}\p{S}]/u,wi=/[^\s\p{P}\p{S}]/u,Ti=Z(/^((?![*_])punctSpace)/,`u`).replace(/punctSpace/g,Ci).getRegex(),Ei=/(?!~)[\p{P}\p{S}]/u,Di=/(?!~)[\s\p{P}\p{S}]/u,Oi=/(?:[^\s\p{P}\p{S}]|~)/u,ki=Z(/link|precode-code|html/,`g`).replace(`link`,/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace(`precode-`,Jr?"(?<!`)()":"(^^|[^`])").replace(`code`,/(?<b>`+)[^`]+\k<b>(?!`)/).replace(`html`,/<(?! )[^<>]*?>/).getRegex(),Ai=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,ji=Z(Ai,`u`).replace(/punct/g,Si).getRegex(),Mi=Z(Ai,`u`).replace(/punct/g,Ei).getRegex(),Ni=`^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)`,Pi=Z(Ni,`gu`).replace(/notPunctSpace/g,wi).replace(/punctSpace/g,Ci).replace(/punct/g,Si).getRegex(),Fi=Z(Ni,`gu`).replace(/notPunctSpace/g,Oi).replace(/punctSpace/g,Di).replace(/punct/g,Ei).getRegex(),Ii=Z(`^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)`,`gu`).replace(/notPunctSpace/g,wi).replace(/punctSpace/g,Ci).replace(/punct/g,Si).getRegex(),Li=Z(/^~~?(?:((?!~)punct)|[^\s~])/,`u`).replace(/punct/g,Si).getRegex(),Ri=Z(`^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)`,`gu`).replace(/notPunctSpace/g,wi).replace(/punctSpace/g,Ci).replace(/punct/g,Si).getRegex(),zi=Z(/\\(punct)/,`gu`).replace(/punct/g,Si).getRegex(),Bi=Z(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace(`scheme`,/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace(`email`,/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),Vi=Z(di).replace(`(?:-->|$)`,`-->`).getRegex(),Hi=Z(`^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>`).replace(`comment`,Vi).replace(`attribute`,/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),Ui=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,Wi=Z(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace(`label`,Ui).replace(`href`,/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace(`title`,/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Gi=Z(/^!?\[(label)\]\[(ref)\]/).replace(`label`,Ui).replace(`ref`,si).getRegex(),Ki=Z(/^!?\[(ref)\](?:\[\])?/).replace(`ref`,si).getRegex(),qi=Z(`reflink|nolink(?!\\()`,`g`).replace(`reflink`,Gi).replace(`nolink`,Ki).getRegex(),Ji=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,Yi={_backpedal:Kr,anyPunctuation:zi,autolink:Bi,blockSkip:ki,br:bi,code:yi,del:Kr,delLDelim:Kr,delRDelim:Kr,emStrongLDelim:ji,emStrongRDelimAst:Pi,emStrongRDelimUnd:Ii,escape:vi,link:Wi,nolink:Ki,punctuation:Ti,reflink:Gi,reflinkSearch:qi,tag:Hi,text:xi,url:Kr},Xi={...Yi,link:Z(/^!?\[(label)\]\((.*?)\)/).replace(`label`,Ui).getRegex(),reflink:Z(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace(`label`,Ui).getRegex()},Zi={...Yi,emStrongRDelimAst:Fi,emStrongLDelim:Mi,delLDelim:Li,delRDelim:Ri,url:Z(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace(`protocol`,Ji).replace(`email`,/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:Z(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace(`protocol`,Ji).getRegex()},Qi={...Zi,br:Z(bi).replace(`{2,}`,`*`).getRegex(),text:Z(Zi.text).replace(`\\b_`,`\\b_| {2,}\\n`).replace(/\{2,\}/g,`*`).getRegex()},$i={normal:mi,gfm:gi,pedantic:_i},ea={normal:Yi,gfm:Zi,breaks:Qi,pedantic:Xi},ta={"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`,"'":`&#39;`},na=e=>ta[e];function ra(e,t){if(t){if(Yr.escapeTest.test(e))return e.replace(Yr.escapeReplace,na)}else if(Yr.escapeTestNoEncode.test(e))return e.replace(Yr.escapeReplaceNoEncode,na);return e}function ia(e){try{e=encodeURI(e).replace(Yr.percentDecode,`%`)}catch{return null}return e}function aa(e,t){let n=e.replace(Yr.findPipe,(e,t,n)=>{let r=!1,i=t;for(;--i>=0&&n[i]===`\\`;)r=!r;return r?`|`:` |`}).split(Yr.splitPipe),r=0;if(n[0].trim()||n.shift(),n.length>0&&!n.at(-1)?.trim()&&n.pop(),t)if(n.length>t)n.splice(t);else for(;n.length<t;)n.push(``);for(;r<n.length;r++)n[r]=n[r].trim().replace(Yr.slashPipe,`|`);return n}function oa(e,t,n){let r=e.length;if(r===0)return``;let i=0;for(;i<r;){let a=e.charAt(r-i-1);if(a===t&&!n)i++;else if(a!==t&&n)i++;else break}return e.slice(0,r-i)}function sa(e){let t=e.split(`
7
+ `),n=t.length-1;for(;n>=0&&Yr.blankLine.test(t[n]);)n--;return t.length-n<=2?e:t.slice(0,n+1).join(`
8
+ `)}function ca(e,t){if(e.indexOf(t[1])===-1)return-1;let n=0;for(let r=0;r<e.length;r++)if(e[r]===`\\`)r++;else if(e[r]===t[0])n++;else if(e[r]===t[1]&&(n--,n<0))return r;return n>0?-2:-1}function la(e,t=0){let n=t,r=``;for(let t of e)if(t===` `){let e=4-n%4;r+=` `.repeat(e),n+=e}else r+=t,n++;return r}function ua(e,t,n,r,i){let a=t.href,o=t.title||null,s=e[1].replace(i.other.outputLinkReplace,`$1`);r.state.inLink=!0;let c={type:e[0].charAt(0)===`!`?`image`:`link`,raw:n,href:a,title:o,text:s,tokens:r.inlineTokens(s)};return r.state.inLink=!1,c}function da(e,t,n){let r=e.match(n.other.indentCodeCompensation);if(r===null)return t;let i=r[1];return t.split(`
9
+ `).map(e=>{let t=e.match(n.other.beginningSpace);if(t===null)return e;let[r]=t;return r.length>=i.length?e.slice(i.length):e}).join(`
10
+ `)}var fa=class{options;rules;lexer;constructor(e){this.options=e||Wr}space(e){let t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:`space`,raw:t[0]}}code(e){let t=this.rules.block.code.exec(e);if(t){let e=this.options.pedantic?t[0]:sa(t[0]);return{type:`code`,raw:e,codeBlockStyle:`indented`,text:e.replace(this.rules.other.codeRemoveIndent,``)}}}fences(e){let t=this.rules.block.fences.exec(e);if(t){let e=t[0],n=da(e,t[3]||``,this.rules);return{type:`code`,raw:e,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,`$1`):t[2],text:n}}}heading(e){let t=this.rules.block.heading.exec(e);if(t){let e=t[2].trim();if(this.rules.other.endingHash.test(e)){let t=oa(e,`#`);(this.options.pedantic||!t||this.rules.other.endingSpaceChar.test(t))&&(e=t.trim())}return{type:`heading`,raw:oa(t[0],`
11
+ `),depth:t[1].length,text:e,tokens:this.lexer.inline(e)}}}hr(e){let t=this.rules.block.hr.exec(e);if(t)return{type:`hr`,raw:oa(t[0],`
12
+ `)}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let e=oa(t[0],`
13
+ `).split(`
14
+ `),n=``,r=``,i=[];for(;e.length>0;){let t=!1,a=[],o;for(o=0;o<e.length;o++)if(this.rules.other.blockquoteStart.test(e[o]))a.push(e[o]),t=!0;else if(!t)a.push(e[o]);else break;e=e.slice(o);let s=a.join(`
15
+ `),c=s.replace(this.rules.other.blockquoteSetextReplace,`
16
+ $1`).replace(this.rules.other.blockquoteSetextReplace2,``);n=n?`${n}
17
+ ${s}`:s,r=r?`${r}
18
+ ${c}`:c;let l=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(c,i,!0),this.lexer.state.top=l,e.length===0)break;let u=i.at(-1);if(u?.type===`code`)break;if(u?.type===`blockquote`){let t=u,a=t.raw+`
19
+ `+e.join(`
20
+ `),o=this.blockquote(a);i[i.length-1]=o,n=n.substring(0,n.length-t.raw.length)+o.raw,r=r.substring(0,r.length-t.text.length)+o.text;break}else if(u?.type===`list`){let t=u,a=t.raw+`
21
+ `+e.join(`
22
+ `),o=this.list(a);i[i.length-1]=o,n=n.substring(0,n.length-u.raw.length)+o.raw,r=r.substring(0,r.length-t.raw.length)+o.raw,e=a.substring(i.at(-1).raw.length).split(`
23
+ `);continue}}return{type:`blockquote`,raw:n,tokens:i,text:r}}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[1].trim(),r=n.length>1,i={type:`list`,raw:``,ordered:r,start:r?+n.slice(0,-1):``,loose:!1,items:[]};n=r?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=r?n:`[*+-]`);let a=this.rules.other.listItemRegex(n),o=!1;for(;e;){let n=!1,r=``,s=``;if(!(t=a.exec(e))||this.rules.block.hr.test(e))break;r=t[0],e=e.substring(r.length);let c=la(t[2].split(`
24
+ `,1)[0],t[1].length),l=e.split(`
25
+ `,1)[0],u=!c.trim(),d=0;if(this.options.pedantic?(d=2,s=c.trimStart()):u?d=t[1].length+1:(d=c.search(this.rules.other.nonSpaceChar),d=d>4?1:d,s=c.slice(d),d+=t[1].length),u&&this.rules.other.blankLine.test(l)&&(r+=l+`
26
+ `,e=e.substring(l.length+1),n=!0),!n){let t=this.rules.other.nextBulletRegex(d),n=this.rules.other.hrRegex(d),i=this.rules.other.fencesBeginRegex(d),a=this.rules.other.headingBeginRegex(d),o=this.rules.other.htmlBeginRegex(d),f=this.rules.other.blockquoteBeginRegex(d);for(;e;){let p=e.split(`
27
+ `,1)[0],m;if(l=p,this.options.pedantic?(l=l.replace(this.rules.other.listReplaceNesting,` `),m=l):m=l.replace(this.rules.other.tabCharGlobal,` `),i.test(l)||a.test(l)||o.test(l)||f.test(l)||t.test(l)||n.test(l))break;if(m.search(this.rules.other.nonSpaceChar)>=d||!l.trim())s+=`
28
+ `+m.slice(d);else{if(u||c.replace(this.rules.other.tabCharGlobal,` `).search(this.rules.other.nonSpaceChar)>=4||i.test(c)||a.test(c)||n.test(c))break;s+=`
29
+ `+l}u=!l.trim(),r+=p+`
30
+ `,e=e.substring(p.length+1),c=m.slice(d)}}i.loose||(o?i.loose=!0:this.rules.other.doubleBlankLine.test(r)&&(o=!0)),i.items.push({type:`list_item`,raw:r,task:!!this.options.gfm&&this.rules.other.listIsTask.test(s),loose:!1,text:s,tokens:[]}),i.raw+=r}let s=i.items.at(-1);if(s)s.raw=s.raw.trimEnd(),s.text=s.text.trimEnd();else return;i.raw=i.raw.trimEnd();for(let e of i.items){this.lexer.state.top=!1,e.tokens=this.lexer.blockTokens(e.text,[]);let t=e.tokens[0];if(e.task&&(t?.type===`text`||t?.type===`paragraph`)){e.text=e.text.replace(this.rules.other.listReplaceTask,``),t.raw=t.raw.replace(this.rules.other.listReplaceTask,``),t.text=t.text.replace(this.rules.other.listReplaceTask,``);for(let e=this.lexer.inlineQueue.length-1;e>=0;e--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[e].src)){this.lexer.inlineQueue[e].src=this.lexer.inlineQueue[e].src.replace(this.rules.other.listReplaceTask,``);break}let n=this.rules.other.listTaskCheckbox.exec(e.raw);if(n){let t={type:`checkbox`,raw:n[0]+` `,checked:n[0]!==`[ ]`};e.checked=t.checked,i.loose?e.tokens[0]&&[`paragraph`,`text`].includes(e.tokens[0].type)&&`tokens`in e.tokens[0]&&e.tokens[0].tokens?(e.tokens[0].raw=t.raw+e.tokens[0].raw,e.tokens[0].text=t.raw+e.tokens[0].text,e.tokens[0].tokens.unshift(t)):e.tokens.unshift({type:`paragraph`,raw:t.raw,text:t.raw,tokens:[t]}):e.tokens.unshift(t)}}else e.task&&=!1;if(!i.loose){let t=e.tokens.filter(e=>e.type===`space`);i.loose=t.length>0&&t.some(e=>this.rules.other.anyLine.test(e.raw))}}if(i.loose)for(let e of i.items){e.loose=!0;for(let t of e.tokens)t.type===`text`&&(t.type=`paragraph`)}return i}}html(e){let t=this.rules.block.html.exec(e);if(t){let e=sa(t[0]);return{type:`html`,block:!0,raw:e,pre:t[1]===`pre`||t[1]===`script`||t[1]===`style`,text:e}}}def(e){let t=this.rules.block.def.exec(e);if(t){let e=t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal,` `),n=t[2]?t[2].replace(this.rules.other.hrefBrackets,`$1`).replace(this.rules.inline.anyPunctuation,`$1`):``,r=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,`$1`):t[3];return{type:`def`,tag:e,raw:oa(t[0],`
31
+ `),href:n,title:r}}}table(e){let t=this.rules.block.table.exec(e);if(!t||!this.rules.other.tableDelimiter.test(t[2]))return;let n=aa(t[1]),r=t[2].replace(this.rules.other.tableAlignChars,``).split(`|`),i=t[3]?.trim()?t[3].replace(this.rules.other.tableRowBlankLine,``).split(`
32
+ `):[],a={type:`table`,raw:oa(t[0],`
33
+ `),header:[],align:[],rows:[]};if(n.length===r.length){for(let e of r)this.rules.other.tableAlignRight.test(e)?a.align.push(`right`):this.rules.other.tableAlignCenter.test(e)?a.align.push(`center`):this.rules.other.tableAlignLeft.test(e)?a.align.push(`left`):a.align.push(null);for(let e=0;e<n.length;e++)a.header.push({text:n[e],tokens:this.lexer.inline(n[e]),header:!0,align:a.align[e]});for(let e of i)a.rows.push(aa(e,a.header.length).map((e,t)=>({text:e,tokens:this.lexer.inline(e),header:!1,align:a.align[t]})));return a}}lheading(e){let t=this.rules.block.lheading.exec(e);if(t){let e=t[1].trim();return{type:`heading`,raw:oa(t[0],`
34
+ `),depth:t[2].charAt(0)===`=`?1:2,text:e,tokens:this.lexer.inline(e)}}}paragraph(e){let t=this.rules.block.paragraph.exec(e);if(t){let e=t[1].charAt(t[1].length-1)===`
35
+ `?t[1].slice(0,-1):t[1];return{type:`paragraph`,raw:t[0],text:e,tokens:this.lexer.inline(e)}}}text(e){let t=this.rules.block.text.exec(e);if(t)return{type:`text`,raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}escape(e){let t=this.rules.inline.escape.exec(e);if(t)return{type:`escape`,raw:t[0],text:t[1]}}tag(e){let t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&this.rules.other.startATag.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(t[0])&&(this.lexer.state.inRawBlock=!1),{type:`html`,raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:t[0]}}link(e){let t=this.rules.inline.link.exec(e);if(t){let e=t[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(e)){if(!this.rules.other.endAngleBracket.test(e))return;let t=oa(e.slice(0,-1),`\\`);if((e.length-t.length)%2==0)return}else{let e=ca(t[2],`()`);if(e===-2)return;if(e>-1){let n=(t[0].indexOf(`!`)===0?5:4)+t[1].length+e;t[2]=t[2].substring(0,e),t[0]=t[0].substring(0,n).trim(),t[3]=``}}let n=t[2],r=``;if(this.options.pedantic){let e=this.rules.other.pedanticHrefTitle.exec(n);e&&(n=e[1],r=e[3])}else r=t[3]?t[3].slice(1,-1):``;return n=n.trim(),this.rules.other.startAngleBracket.test(n)&&(n=this.options.pedantic&&!this.rules.other.endAngleBracket.test(e)?n.slice(1):n.slice(1,-1)),ua(t,{href:n&&n.replace(this.rules.inline.anyPunctuation,`$1`),title:r&&r.replace(this.rules.inline.anyPunctuation,`$1`)},t[0],this.lexer,this.rules)}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){let e=t[(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal,` `).toLowerCase()];if(!e){let e=n[0].charAt(0);return{type:`text`,raw:e,text:e}}return ua(n,e,n[0],this.lexer,this.rules)}}emStrong(e,t,n=``){let r=this.rules.inline.emStrongLDelim.exec(e);if(!(!r||!r[1]&&!r[2]&&!r[3]&&!r[4]||r[4]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!(r[1]||r[3])||!n||this.rules.inline.punctuation.exec(n))){let n=[...r[0]].length-1,i,a,o=n,s=0,c=r[0][0]===`*`?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(c.lastIndex=0,t=t.slice(-1*e.length+n);(r=c.exec(t))!==null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i)continue;if(a=[...i].length,r[3]||r[4]){o+=a;continue}else if((r[5]||r[6])&&n%3&&!((n+a)%3)){s+=a;continue}if(o-=a,o>0)continue;a=Math.min(a,a+o+s);let t=[...r[0]][0].length,c=e.slice(0,n+r.index+t+a);if(Math.min(n,a)%2){let e=c.slice(1,-1);return{type:`em`,raw:c,text:e,tokens:this.lexer.inlineTokens(e)}}let l=c.slice(2,-2);return{type:`strong`,raw:c,text:l,tokens:this.lexer.inlineTokens(l)}}}}codespan(e){let t=this.rules.inline.code.exec(e);if(t){let e=t[2].replace(this.rules.other.newLineCharGlobal,` `),n=this.rules.other.nonSpaceChar.test(e),r=this.rules.other.startingSpaceChar.test(e)&&this.rules.other.endingSpaceChar.test(e);return n&&r&&(e=e.substring(1,e.length-1)),{type:`codespan`,raw:t[0],text:e}}}br(e){let t=this.rules.inline.br.exec(e);if(t)return{type:`br`,raw:t[0]}}del(e,t,n=``){let r=this.rules.inline.delLDelim.exec(e);if(r&&(!r[1]||!n||this.rules.inline.punctuation.exec(n))){let n=[...r[0]].length-1,i,a,o=n,s=this.rules.inline.delRDelim;for(s.lastIndex=0,t=t.slice(-1*e.length+n);(r=s.exec(t))!==null;){if(i=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!i||(a=[...i].length,a!==n))continue;if(r[3]||r[4]){o+=a;continue}if(o-=a,o>0)continue;a=Math.min(a,a+o);let t=[...r[0]][0].length,s=e.slice(0,n+r.index+t+a),c=s.slice(n,-n);return{type:`del`,raw:s,text:c,tokens:this.lexer.inlineTokens(c)}}}}autolink(e){let t=this.rules.inline.autolink.exec(e);if(t){let e,n;return t[2]===`@`?(e=t[1],n=`mailto:`+e):(e=t[1],n=e),{type:`link`,raw:t[0],text:e,href:n,tokens:[{type:`text`,raw:e,text:e}]}}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let e,n;if(t[2]===`@`)e=t[0],n=`mailto:`+e;else{let r;do r=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??``;while(r!==t[0]);e=t[0],n=t[1]===`www.`?`http://`+t[0]:t[0]}return{type:`link`,raw:t[0],text:e,href:n,tokens:[{type:`text`,raw:e,text:e}]}}}inlineText(e){let t=this.rules.inline.text.exec(e);if(t){let e=this.lexer.state.inRawBlock;return{type:`text`,raw:t[0],text:t[0],escaped:e}}}},pa=class e{tokens;options;state;inlineQueue;tokenizer;constructor(e){this.tokens=[],this.tokens.links=Object.create(null),this.options=e||Wr,this.options.tokenizer=this.options.tokenizer||new fa,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let t={other:Yr,block:$i.normal,inline:ea.normal};this.options.pedantic?(t.block=$i.pedantic,t.inline=ea.pedantic):this.options.gfm&&(t.block=$i.gfm,this.options.breaks?t.inline=ea.breaks:t.inline=ea.gfm),this.tokenizer.rules=t}static get rules(){return{block:$i,inline:ea}}static lex(t,n){return new e(n).lex(t)}static lexInline(t,n){return new e(n).inlineTokens(t)}lex(e){e=e.replace(Yr.carriageReturn,`
36
+ `),this.blockTokens(e,this.tokens);for(let e=0;e<this.inlineQueue.length;e++){let t=this.inlineQueue[e];this.inlineTokens(t.src,t.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,t=[],n=!1){this.tokenizer.lexer=this,this.options.pedantic&&(e=e.replace(Yr.tabCharGlobal,` `).replace(Yr.spaceLine,``));let r=1/0;for(;e;){if(e.length<r)r=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}let i;if(this.options.extensions?.block?.some(n=>(i=n.call({lexer:this},e,t))?(e=e.substring(i.raw.length),t.push(i),!0):!1))continue;if(i=this.tokenizer.space(e)){e=e.substring(i.raw.length);let n=t.at(-1);i.raw.length===1&&n!==void 0?n.raw+=`
37
+ `:t.push(i);continue}if(i=this.tokenizer.code(e)){e=e.substring(i.raw.length);let n=t.at(-1);n?.type===`paragraph`||n?.type===`text`?(n.raw+=(n.raw.endsWith(`
38
+ `)?``:`
39
+ `)+i.raw,n.text+=`
40
+ `+i.text,this.inlineQueue.at(-1).src=n.text):t.push(i);continue}if(i=this.tokenizer.fences(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.heading(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.hr(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.blockquote(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.list(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.html(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.def(e)){e=e.substring(i.raw.length);let n=t.at(-1);n?.type===`paragraph`||n?.type===`text`?(n.raw+=(n.raw.endsWith(`
41
+ `)?``:`
42
+ `)+i.raw,n.text+=`
43
+ `+i.raw,this.inlineQueue.at(-1).src=n.text):this.tokens.links[i.tag]||(this.tokens.links[i.tag]={href:i.href,title:i.title},t.push(i));continue}if(i=this.tokenizer.table(e)){e=e.substring(i.raw.length),t.push(i);continue}if(i=this.tokenizer.lheading(e)){e=e.substring(i.raw.length),t.push(i);continue}let a=e;if(this.options.extensions?.startBlock){let t=1/0,n=e.slice(1),r;this.options.extensions.startBlock.forEach(e=>{r=e.call({lexer:this},n),typeof r==`number`&&r>=0&&(t=Math.min(t,r))}),t<1/0&&t>=0&&(a=e.substring(0,t+1))}if(this.state.top&&(i=this.tokenizer.paragraph(a))){let r=t.at(-1);n&&r?.type===`paragraph`?(r.raw+=(r.raw.endsWith(`
44
+ `)?``:`
45
+ `)+i.raw,r.text+=`
46
+ `+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=r.text):t.push(i),n=a.length!==e.length,e=e.substring(i.raw.length);continue}if(i=this.tokenizer.text(e)){e=e.substring(i.raw.length);let n=t.at(-1);n?.type===`text`?(n.raw+=(n.raw.endsWith(`
47
+ `)?``:`
48
+ `)+i.raw,n.text+=`
49
+ `+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=n.text):t.push(i);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return this.state.top=!0,t}inline(e,t=[]){return this.inlineQueue.push({src:e,tokens:t}),t}inlineTokens(e,t=[]){this.tokenizer.lexer=this;let n=e,r=null;if(this.tokens.links){let e=Object.keys(this.tokens.links);if(e.length>0)for(;(r=this.tokenizer.rules.inline.reflinkSearch.exec(n))!==null;)e.includes(r[0].slice(r[0].lastIndexOf(`[`)+1,-1))&&(n=n.slice(0,r.index)+`[`+`a`.repeat(r[0].length-2)+`]`+n.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(r=this.tokenizer.rules.inline.anyPunctuation.exec(n))!==null;)n=n.slice(0,r.index)+`++`+n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let i;for(;(r=this.tokenizer.rules.inline.blockSkip.exec(n))!==null;)i=r[2]?r[2].length:0,n=n.slice(0,r.index+i)+`[`+`a`.repeat(r[0].length-i-2)+`]`+n.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);n=this.options.hooks?.emStrongMask?.call({lexer:this},n)??n;let a=!1,o=``,s=1/0;for(;e;){if(e.length<s)s=e.length;else{this.infiniteLoopError(e.charCodeAt(0));break}a||(o=``),a=!1;let r;if(this.options.extensions?.inline?.some(n=>(r=n.call({lexer:this},e,t))?(e=e.substring(r.raw.length),t.push(r),!0):!1))continue;if(r=this.tokenizer.escape(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.tag(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.link(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(r.raw.length);let n=t.at(-1);r.type===`text`&&n?.type===`text`?(n.raw+=r.raw,n.text+=r.text):t.push(r);continue}if(r=this.tokenizer.emStrong(e,n,o)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.codespan(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.br(e)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.del(e,n,o)){e=e.substring(r.raw.length),t.push(r);continue}if(r=this.tokenizer.autolink(e)){e=e.substring(r.raw.length),t.push(r);continue}if(!this.state.inLink&&(r=this.tokenizer.url(e))){e=e.substring(r.raw.length),t.push(r);continue}let i=e;if(this.options.extensions?.startInline){let t=1/0,n=e.slice(1),r;this.options.extensions.startInline.forEach(e=>{r=e.call({lexer:this},n),typeof r==`number`&&r>=0&&(t=Math.min(t,r))}),t<1/0&&t>=0&&(i=e.substring(0,t+1))}if(r=this.tokenizer.inlineText(i)){e=e.substring(r.raw.length),r.raw.slice(-1)!==`_`&&(o=r.raw.slice(-1)),a=!0;let n=t.at(-1);n?.type===`text`?(n.raw+=r.raw,n.text+=r.text):t.push(r);continue}if(e){this.infiniteLoopError(e.charCodeAt(0));break}}return t}infiniteLoopError(e){let t=`Infinite loop on byte: `+e;if(this.options.silent)console.error(t);else throw Error(t)}},ma=class{options;parser;constructor(e){this.options=e||Wr}space(e){return``}code({text:e,lang:t,escaped:n}){let r=(t||``).match(Yr.notSpaceStart)?.[0],i=e.replace(Yr.endingNewline,``)+`
50
+ `;return r?`<pre><code class="language-`+ra(r)+`">`+(n?i:ra(i,!0))+`</code></pre>
51
+ `:`<pre><code>`+(n?i:ra(i,!0))+`</code></pre>
52
+ `}blockquote({tokens:e}){return`<blockquote>
53
+ ${this.parser.parse(e)}</blockquote>
54
+ `}html({text:e}){return e}def(e){return``}heading({tokens:e,depth:t}){return`<h${t}>${this.parser.parseInline(e)}</h${t}>
55
+ `}hr(e){return`<hr>
56
+ `}list(e){let t=e.ordered,n=e.start,r=``;for(let t=0;t<e.items.length;t++){let n=e.items[t];r+=this.listitem(n)}let i=t?`ol`:`ul`,a=t&&n!==1?` start="`+n+`"`:``;return`<`+i+a+`>
57
+ `+r+`</`+i+`>
58
+ `}listitem(e){return`<li>${this.parser.parse(e.tokens)}</li>
59
+ `}checkbox({checked:e}){return`<input `+(e?`checked="" `:``)+`disabled="" type="checkbox"> `}paragraph({tokens:e}){return`<p>${this.parser.parseInline(e)}</p>
60
+ `}table(e){let t=``,n=``;for(let t=0;t<e.header.length;t++)n+=this.tablecell(e.header[t]);t+=this.tablerow({text:n});let r=``;for(let t=0;t<e.rows.length;t++){let i=e.rows[t];n=``;for(let e=0;e<i.length;e++)n+=this.tablecell(i[e]);r+=this.tablerow({text:n})}return r&&=`<tbody>${r}</tbody>`,`<table>
61
+ <thead>
62
+ `+t+`</thead>
63
+ `+r+`</table>
64
+ `}tablerow({text:e}){return`<tr>
65
+ ${e}</tr>
66
+ `}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?`th`:`td`;return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>
67
+ `}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${ra(e,!0)}</code>`}br(e){return`<br>`}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,tokens:n}){let r=this.parser.parseInline(n),i=ia(e);if(i===null)return r;e=i;let a=`<a href="`+e+`"`;return t&&(a+=` title="`+ra(t)+`"`),a+=`>`+r+`</a>`,a}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let i=ia(e);if(i===null)return ra(n);e=i;let a=`<img src="${e}" alt="${ra(n)}"`;return t&&(a+=` title="${ra(t)}"`),a+=`>`,a}text(e){return`tokens`in e&&e.tokens?this.parser.parseInline(e.tokens):`escaped`in e&&e.escaped?e.text:ra(e.text)}},ha=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return``+e}image({text:e}){return``+e}br(){return``}checkbox({raw:e}){return e}},ga=class e{options;renderer;textRenderer;constructor(e){this.options=e||Wr,this.options.renderer=this.options.renderer||new ma,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new ha}static parse(t,n){return new e(n).parse(t)}static parseInline(t,n){return new e(n).parseInline(t)}parse(e){this.renderer.parser=this;let t=``;for(let n=0;n<e.length;n++){let r=e[n];if(this.options.extensions?.renderers?.[r.type]){let e=r,n=this.options.extensions.renderers[e.type].call({parser:this},e);if(n!==!1||![`space`,`hr`,`heading`,`code`,`table`,`blockquote`,`list`,`html`,`def`,`paragraph`,`text`].includes(e.type)){t+=n||``;continue}}let i=r;switch(i.type){case`space`:t+=this.renderer.space(i);break;case`hr`:t+=this.renderer.hr(i);break;case`heading`:t+=this.renderer.heading(i);break;case`code`:t+=this.renderer.code(i);break;case`table`:t+=this.renderer.table(i);break;case`blockquote`:t+=this.renderer.blockquote(i);break;case`list`:t+=this.renderer.list(i);break;case`checkbox`:t+=this.renderer.checkbox(i);break;case`html`:t+=this.renderer.html(i);break;case`def`:t+=this.renderer.def(i);break;case`paragraph`:t+=this.renderer.paragraph(i);break;case`text`:t+=this.renderer.text(i);break;default:{let e=`Token with "`+i.type+`" type was not found.`;if(this.options.silent)return console.error(e),``;throw Error(e)}}}return t}parseInline(e,t=this.renderer){this.renderer.parser=this;let n=``;for(let r=0;r<e.length;r++){let i=e[r];if(this.options.extensions?.renderers?.[i.type]){let e=this.options.extensions.renderers[i.type].call({parser:this},i);if(e!==!1||![`escape`,`html`,`link`,`image`,`strong`,`em`,`codespan`,`br`,`del`,`text`].includes(i.type)){n+=e||``;continue}}let a=i;switch(a.type){case`escape`:n+=t.text(a);break;case`html`:n+=t.html(a);break;case`link`:n+=t.link(a);break;case`image`:n+=t.image(a);break;case`checkbox`:n+=t.checkbox(a);break;case`strong`:n+=t.strong(a);break;case`em`:n+=t.em(a);break;case`codespan`:n+=t.codespan(a);break;case`br`:n+=t.br(a);break;case`del`:n+=t.del(a);break;case`text`:n+=t.text(a);break;default:{let e=`Token with "`+a.type+`" type was not found.`;if(this.options.silent)return console.error(e),``;throw Error(e)}}}return n}},_a=class{options;block;constructor(e){this.options=e||Wr}static passThroughHooks=new Set([`preprocess`,`postprocess`,`processAllTokens`,`emStrongMask`]);static passThroughHooksRespectAsync=new Set([`preprocess`,`postprocess`,`processAllTokens`]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}emStrongMask(e){return e}provideLexer(e=this.block){return e?pa.lex:pa.lexInline}provideParser(e=this.block){return e?ga.parse:ga.parseInline}},va=new class{defaults=Ur();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=ga;Renderer=ma;TextRenderer=ha;Lexer=pa;Tokenizer=fa;Hooks=_a;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(let r of e)switch(n=n.concat(t.call(this,r)),r.type){case`table`:{let e=r;for(let r of e.header)n=n.concat(this.walkTokens(r.tokens,t));for(let r of e.rows)for(let e of r)n=n.concat(this.walkTokens(e.tokens,t));break}case`list`:{let e=r;n=n.concat(this.walkTokens(e.items,t));break}default:{let e=r;this.defaults.extensions?.childTokens?.[e.type]?this.defaults.extensions.childTokens[e.type].forEach(r=>{let i=e[r].flat(1/0);n=n.concat(this.walkTokens(i,t))}):e.tokens&&(n=n.concat(this.walkTokens(e.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(e=>{let n={...e};if(n.async=this.defaults.async||n.async||!1,e.extensions&&(e.extensions.forEach(e=>{if(!e.name)throw Error(`extension name required`);if(`renderer`in e){let n=t.renderers[e.name];n?t.renderers[e.name]=function(...t){let r=e.renderer.apply(this,t);return r===!1&&(r=n.apply(this,t)),r}:t.renderers[e.name]=e.renderer}if(`tokenizer`in e){if(!e.level||e.level!==`block`&&e.level!==`inline`)throw Error(`extension level must be 'block' or 'inline'`);let n=t[e.level];n?n.unshift(e.tokenizer):t[e.level]=[e.tokenizer],e.start&&(e.level===`block`?t.startBlock?t.startBlock.push(e.start):t.startBlock=[e.start]:e.level===`inline`&&(t.startInline?t.startInline.push(e.start):t.startInline=[e.start]))}`childTokens`in e&&e.childTokens&&(t.childTokens[e.name]=e.childTokens)}),n.extensions=t),e.renderer){let t=this.defaults.renderer||new ma(this.defaults);for(let n in e.renderer){if(!(n in t))throw Error(`renderer '${n}' does not exist`);if([`options`,`parser`].includes(n))continue;let r=n,i=e.renderer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n||``}}n.renderer=t}if(e.tokenizer){let t=this.defaults.tokenizer||new fa(this.defaults);for(let n in e.tokenizer){if(!(n in t))throw Error(`tokenizer '${n}' does not exist`);if([`options`,`rules`,`lexer`].includes(n))continue;let r=n,i=e.tokenizer[r],a=t[r];t[r]=(...e)=>{let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.tokenizer=t}if(e.hooks){let t=this.defaults.hooks||new _a;for(let n in e.hooks){if(!(n in t))throw Error(`hook '${n}' does not exist`);if([`options`,`block`].includes(n))continue;let r=n,i=e.hooks[r],a=t[r];_a.passThroughHooks.has(n)?t[r]=e=>{if(this.defaults.async&&_a.passThroughHooksRespectAsync.has(n))return(async()=>{let n=await i.call(t,e);return a.call(t,n)})();let r=i.call(t,e);return a.call(t,r)}:t[r]=(...e)=>{if(this.defaults.async)return(async()=>{let n=await i.apply(t,e);return n===!1&&(n=await a.apply(t,e)),n})();let n=i.apply(t,e);return n===!1&&(n=a.apply(t,e)),n}}n.hooks=t}if(e.walkTokens){let t=this.defaults.walkTokens,r=e.walkTokens;n.walkTokens=function(e){let n=[];return n.push(r.call(this,e)),t&&(n=n.concat(t.call(this,e))),n}}this.defaults={...this.defaults,...n}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return pa.lex(e,t??this.defaults)}parser(e,t){return ga.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let r={...n},i={...this.defaults,...r},a=this.onError(!!i.silent,!!i.async);if(this.defaults.async===!0&&r.async===!1)return a(Error(`marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise.`));if(typeof t>`u`||t===null)return a(Error(`marked(): input parameter is undefined or null`));if(typeof t!=`string`)return a(Error(`marked(): input parameter is of type `+Object.prototype.toString.call(t)+`, string expected`));if(i.hooks&&(i.hooks.options=i,i.hooks.block=e),i.async)return(async()=>{let n=i.hooks?await i.hooks.preprocess(t):t,r=await(i.hooks?await i.hooks.provideLexer(e):e?pa.lex:pa.lexInline)(n,i),a=i.hooks?await i.hooks.processAllTokens(r):r;i.walkTokens&&await Promise.all(this.walkTokens(a,i.walkTokens));let o=await(i.hooks?await i.hooks.provideParser(e):e?ga.parse:ga.parseInline)(a,i);return i.hooks?await i.hooks.postprocess(o):o})().catch(a);try{i.hooks&&(t=i.hooks.preprocess(t));let n=(i.hooks?i.hooks.provideLexer(e):e?pa.lex:pa.lexInline)(t,i);i.hooks&&(n=i.hooks.processAllTokens(n)),i.walkTokens&&this.walkTokens(n,i.walkTokens);let r=(i.hooks?i.hooks.provideParser(e):e?ga.parse:ga.parseInline)(n,i);return i.hooks&&(r=i.hooks.postprocess(r)),r}catch(e){return a(e)}}}onError(e,t){return n=>{if(n.message+=`
68
+ Please report this to https://github.com/markedjs/marked.`,e){let e=`<p>An error occurred:</p><pre>`+ra(n.message+``,!0)+`</pre>`;return t?Promise.resolve(e):e}if(t)return Promise.reject(n);throw n}}};function Q(e,t){return va.parse(e,t)}Q.options=Q.setOptions=function(e){return va.setOptions(e),Q.defaults=va.defaults,Gr(Q.defaults),Q},Q.getDefaults=Ur,Q.defaults=Wr,Q.use=function(...e){return va.use(...e),Q.defaults=va.defaults,Gr(Q.defaults),Q},Q.walkTokens=function(e,t){return va.walkTokens(e,t)},Q.parseInline=va.parseInline,Q.Parser=ga,Q.parser=ga.parse,Q.Renderer=ma,Q.TextRenderer=ha,Q.Lexer=pa,Q.lexer=pa.lex,Q.Tokenizer=fa,Q.Hooks=_a,Q.parse=Q,Q.options,Q.setOptions,Q.use,Q.walkTokens,Q.parseInline,ga.parse,pa.lex;var ya=!1;function ba(){ya||=(Q.setOptions({breaks:!0,gfm:!0}),Hr.addHook(`afterSanitizeAttributes`,e=>{e.nodeName===`A`&&(e.setAttribute(`target`,`_blank`),e.setAttribute(`rel`,`noopener noreferrer`))}),!0)}function xa(e,t){if(!e)return``;if(!t||typeof window>`u`)return Sa(e);try{ba();let t=Q.parse(e,{async:!1});return Hr.sanitize(t)}catch{return Sa(e)}}function Sa(e){return String(e).replaceAll(`&`,`&amp;`).replaceAll(`<`,`&lt;`).replaceAll(`>`,`&gt;`)}var $=a(),Ca=e=>e?e.slice(0,7):`no commit`;function wa({changes:e,base:t,loading:n,onBase:r,onRefresh:i}){let[a,o]=(0,G.useState)(!1),[s,c]=(0,G.useState)(t),l=e?.identity,u=l?l.headState===`detached`?`detached at ${Ca(l.head)}`:l.branch??`unknown branch`:``;return a?(0,$.jsxs)(`form`,{className:`flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),r(s.trim()),o(!1)},children:[(0,$.jsx)(`input`,{autoFocus:!0,"aria-label":`Comparison base`,placeholder:`HEAD, main, HEAD~1, a commit…`,value:s,onChange:e=>c(e.target.value),className:`min-h-9 min-w-0 flex-1 basis-40 py-1.5 font-mono text-xs`}),(0,$.jsx)(g,{variant:`primary`,type:`submit`,className:`min-h-9 px-3 py-1 text-xs`,children:`Compare`}),(0,$.jsx)(g,{variant:`ghost`,className:`min-h-9 px-3 py-1 text-xs`,onClick:()=>o(!1),children:`Cancel`}),(0,$.jsx)(`p`,{className:`m-0 basis-full text-xs text-muted-foreground`,children:`A branch name is pinned to its commit when the review loads. Empty means HEAD: what is not committed yet.`})]}):(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2 text-xs`,children:[(0,$.jsx)(Qt,{className:`size-3.5 shrink-0 text-mocha`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`min-w-0 truncate font-mono text-foreground`,title:u,children:u||`…`}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>{c(t),o(!0)},title:`Change the comparison base`,className:`unstyled shrink-0 rounded-full border border-border bg-card px-2 py-0.5 font-mono text-mocha hover:border-sapphire-light hover:text-sapphire`,children:[`since `,e?e.base.requestedRef:t||`HEAD`,e?` (${Ca(e.base.resolvedOid)})`:``]}),(0,$.jsx)(`button`,{type:`button`,onClick:i,"aria-label":`Refresh the changes`,title:`Refresh`,className:`unstyled ml-auto flex size-7 shrink-0 items-center justify-center rounded-lg text-mocha hover:bg-muted hover:text-sapphire`,children:(0,$.jsx)(mn,{className:`size-3.5 ${n?`animate-spin`:``}`,"aria-hidden":`true`})})]})}var Ta=1500,Ea=`select-none px-2 text-right text-xs leading-[1.6] text-muted-foreground tabular-nums`,Da=`whitespace-pre-wrap px-2 leading-[1.6] [overflow-wrap:anywhere]`;function Oa({line:e,active:t,onClick:n}){return n?(0,$.jsxs)(`button`,{type:`button`,onClick:n,title:`Comment on line ${e}`,"aria-label":`Comment on line ${e}`,className:`unstyled group/line relative ${Ea} hover:bg-primary hover:text-primary-foreground ${t?`bg-primary text-primary-foreground`:``}`,children:[(0,$.jsx)(`span`,{className:`group-hover/line:invisible`,children:e}),(0,$.jsx)(Qe,{className:`invisible absolute right-1.5 top-1/2 size-3.5 -translate-y-1/2 group-hover/line:visible`,"aria-hidden":`true`})]}):(0,$.jsx)(`span`,{className:Ea,children:e})}function ka({line:e,onAdd:t,onCancel:n}){let[r,i]=(0,G.useState)(``),a=()=>{r.trim()&&t(r.trim())};return(0,$.jsxs)(`div`,{className:`border-y border-primary/30 bg-accent/40 px-3 py-2.5 font-body`,children:[(0,$.jsx)(`textarea`,{autoFocus:!0,"aria-label":`Comment on line ${e}`,placeholder:`What should change on line ${e}?`,rows:2,maxLength:2e3,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Escape`&&n(),e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&a()},className:`min-h-16 text-sm`}),(0,$.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(g,{variant:`primary`,className:`min-h-8 px-3 py-1 text-xs`,disabled:!r.trim(),onClick:a,children:`Add to the review`}),(0,$.jsx)(g,{variant:`ghost`,className:`min-h-8 px-3 py-1 text-xs`,onClick:n,children:`Cancel`})]})]})}function Aa({comments:e,onRemove:t}){return(0,$.jsx)(`div`,{className:`space-y-1.5 border-y border-primary/25 bg-accent/30 px-3 py-2 font-body`,children:e.map(e=>(0,$.jsxs)(`div`,{className:`flex items-start gap-2 rounded-[10px] border border-border bg-card px-2.5 py-1.5 text-sm`,children:[(0,$.jsx)(`p`,{className:`m-0 min-w-0 flex-1 whitespace-pre-wrap break-words text-chocolate`,children:e.note}),t&&(0,$.jsx)(`button`,{type:`button`,"aria-label":`Remove this comment`,onClick:()=>t(e.id),className:`unstyled flex size-6 shrink-0 items-center justify-center rounded-md text-mocha hover:bg-muted hover:text-danger`,children:(0,$.jsx)(y,{className:`size-3.5`,"aria-hidden":`true`})})]},e.id))})}function ja({comments:e,onAddComment:t,onRemoveComment:n}){let[r,i]=(0,G.useState)(null),a=(0,G.useMemo)(()=>{let t=new Map;for(let n of e)n.line!==void 0&&t.set(n.line,[...t.get(n.line)??[],n]);return t},[e]);return{composing:r,under:e=>{if(e===void 0)return null;let o=a.get(e);return!o&&r!==e?null:(0,$.jsxs)(`div`,{className:`col-span-full`,children:[o&&(0,$.jsx)(Aa,{comments:o,onRemove:n}),r===e&&t&&(0,$.jsx)(ka,{line:e,onAdd:n=>{t(e,n),i(null)},onCancel:()=>i(null)})]})},startOn:t?e=>()=>i(t=>t===e?null:e):()=>void 0}}function Ma({hidden:e,onShow:t}){return e<=0?null:(0,$.jsx)(`div`,{className:`col-span-full border-t border-frost/70 px-3 py-2 font-body`,children:(0,$.jsxs)(g,{variant:`ghost`,className:`min-h-8 px-3 py-1 text-xs`,onClick:t,children:[`Show `,e.toLocaleString(),` more line`,e===1?``:`s`]})})}var Na=`col-span-full bg-accent/50 px-3 py-0.5 text-xs text-accent-foreground`,Pa=`col-span-full px-3 py-0.5 font-body text-xs italic text-mocha-light`;function Fa(e){let t=(0,G.useMemo)(()=>bn(e.patch).lines,[e.patch]),[n,r]=(0,G.useState)(!1),{composing:i,under:a,startOn:o}=ja(e),s=n?t:t.slice(0,Ta);return(0,$.jsxs)(`div`,{className:`grid grid-cols-[2.6rem_2.6rem_minmax(0,1fr)] font-mono text-xs text-chocolate`,children:[s.map((e,t)=>{if(e.kind===`hunk`)return(0,$.jsx)(`div`,{className:Na,children:e.text},t);if(e.kind===`note`)return(0,$.jsx)(`div`,{className:Pa,children:e.text},t);let n=e.kind===`add`?`bg-success/[0.13]`:e.kind===`remove`?`bg-danger/[0.13]`:``,r=e.kind===`add`?`bg-success/20`:e.kind===`remove`?`bg-danger/20`:`bg-muted/60`,s=e.kind===`remove`?void 0:e.newLine;return(0,$.jsxs)(G.Fragment,{children:[(0,$.jsx)(`span`,{className:`${Ea} ${r}`,children:e.kind===`add`?``:e.oldLine}),s===void 0?(0,$.jsx)(`span`,{className:`${Ea} ${r}`}):(0,$.jsx)(`span`,{className:`grid ${r}`,children:(0,$.jsx)(Oa,{line:s,active:i===s,onClick:o(s)})}),(0,$.jsxs)(`span`,{className:`${Da} ${n}`,children:[(0,$.jsx)(`span`,{className:`select-none text-mocha-light`,children:e.kind===`add`?`+`:e.kind===`remove`?`−`:` `}),e.text]}),a(s)]},t)}),(0,$.jsx)(Ma,{hidden:t.length-s.length,onShow:()=>r(!0)})]})}function Ia(e){let t=(0,G.useMemo)(()=>xn(bn(e.patch).lines),[e.patch]),[n,r]=(0,G.useState)(!1),{composing:i,under:a,startOn:o}=ja(e),s=n?t:t.slice(0,Ta);return(0,$.jsxs)(`div`,{className:`grid grid-cols-[2.8rem_minmax(0,1fr)_2.8rem_minmax(0,1fr)] font-mono text-xs text-chocolate`,children:[s.map((e,t)=>{if(e.kind===`hunk`)return(0,$.jsx)(`div`,{className:Na,children:e.text},t);if(e.kind===`note`)return(0,$.jsx)(`div`,{className:Pa,children:e.text},t);let{left:n,right:r}=e,s=n?.changed?`bg-danger/[0.13]`:n?``:`bg-muted/50`,c=r?.changed?`bg-success/[0.13]`:r?``:`bg-muted/50`;return(0,$.jsxs)(G.Fragment,{children:[(0,$.jsx)(`span`,{className:`${Ea} ${n?.changed?`bg-danger/20`:`bg-muted/60`}`,children:n?.line}),(0,$.jsx)(`span`,{className:`${Da} border-r border-frost/70 ${s}`,children:n?.text}),r?(0,$.jsx)(`span`,{className:`grid ${r.changed?`bg-success/20`:`bg-muted/60`}`,children:(0,$.jsx)(Oa,{line:r.line,active:i===r.line,onClick:o(r.line)})}):(0,$.jsx)(`span`,{className:`${Ea} bg-muted/60`}),(0,$.jsx)(`span`,{className:`${Da} ${c}`,children:r?.text}),a(r?.line)]},t)}),(0,$.jsx)(Ma,{hidden:t.length-s.length,onShow:()=>r(!0)})]})}var La={base:``,comments:[],note:``},Ra=(0,G.createContext)(null);function za({children:e}){let[t,n]=(0,G.useState)({}),r=(0,G.useRef)(0),i=(0,G.useCallback)((e,t)=>{n(n=>({...n,[e]:t(n[e]??La)}))},[]),a=(0,G.useCallback)(()=>++r.current,[]),o=(0,G.useMemo)(()=>({sessions:t,update:i,nextId:a}),[t,i,a]);return(0,$.jsx)(Ra.Provider,{value:o,children:e})}function Ba(e){let t=(0,G.useContext)(Ra);if(!t)throw Error(`useReviewSession needs a ReviewProvider`);let{sessions:n,update:r,nextId:i}=t,a=n[e]??La;return(0,G.useMemo)(()=>({...a,setBase:t=>r(e,e=>({...e,base:t})),setNote:t=>r(e,e=>({...e,note:t})),addComment:t=>r(e,e=>({...e,comments:[...e.comments,{...t,id:i()}]})),removeComment:t=>r(e,e=>({...e,comments:e.comments.filter(e=>e.id!==t)})),clear:()=>r(e,e=>({...e,comments:[],note:``}))}),[a,e,r,i])}function Va(e,t){let n=new URLSearchParams(t).toString();return`/api/teams/${encodeURIComponent(e)}/review${n?`?${n}`:``}`}function Ha(e,t){let{turnsEnded:r}=U();return W(async r=>{try{let i=await n(Va(e,{authors:`1`,...t?{base:t}:{}}),{signal:r});return`unavailable`in i?{review:null,unavailable:i.unavailable}:{review:i,unavailable:null}}catch(e){if(!(e instanceof o)||r.aborted)throw e;return{review:null,unavailable:{code:e.code,message:l(e)}}}},[e,t],{refreshOn:r})}function Ua(e,t,r,i){return W(async i=>{if(!r)return null;let a=await n(Va(e,{patches:`1`,path:r,...t?{base:t}:{}}),{signal:i});if(`unavailable`in a)throw Error(a.unavailable.message);let o=a.changes.changes.find(e=>e.path===r);return{path:r,patch:o?.patch??null,truncated:o?.patchTruncated??!1,omitted:o?.contentOmitted??null}},[e,t,r],{refreshOn:i})}var Wa={added:`A`,modified:`M`,deleted:`D`,renamed:`R`,copied:`C`,type_changed:`T`,unmerged:`U`,untracked:`N`,unknown:`?`},Ga={added:`bg-success/15 text-success`,untracked:`bg-success/15 text-success`,copied:`bg-success/15 text-success`,modified:`bg-accent text-accent-foreground`,renamed:`bg-accent text-accent-foreground`,type_changed:`bg-accent text-accent-foreground`,deleted:`bg-danger/15 text-danger`,unmerged:`bg-warning/15 text-warning`,unknown:`bg-frost text-foreground`};function Ka({status:e}){return(0,$.jsx)(`span`,{className:`inline-flex size-[18px] shrink-0 items-center justify-center rounded font-mono text-xs font-semibold ${Ga[e]}`,"aria-hidden":`true`,children:Wa[e]})}function qa(e){let t=e.lastIndexOf(`/`);return t<0?{dir:``,name:e}:{dir:e.slice(0,t+1),name:e.slice(t+1)}}function Ja(e){return e.excludedReason?(0,$.jsx)(`span`,{className:`text-xs text-mocha`,children:`withheld`}):e.binary?(0,$.jsx)(`span`,{className:`text-xs text-mocha`,children:`binary`}):(0,$.jsxs)(`span`,{className:`flex shrink-0 gap-1.5 font-mono text-xs font-medium`,children:[e.addedLines?(0,$.jsxs)(`span`,{className:`text-success`,children:[`+`,e.addedLines]}):null,e.deletedLines?(0,$.jsxs)(`span`,{className:`text-danger`,children:[`−`,e.deletedLines]}):null]})}function Ya({changes:e,authors:t,comments:n,selected:r,onSelect:i}){let{agentById:a}=z();return e.changes.length===0?(0,$.jsx)(`p`,{className:`m-0 rounded-2xl border border-dashed border-border bg-muted/40 px-3 py-4 text-sm text-muted-foreground`,children:`Nothing changed since this base.`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`ul`,{className:`m-0 list-none divide-y divide-frost/70 overflow-hidden rounded-2xl border border-border p-0`,children:e.changes.map(e=>{let{dir:o,name:s}=qa(e.path),c=t[e.path],l=n.filter(t=>t.path===e.path).length,u=e.path===r;return(0,$.jsx)(`li`,{children:(0,$.jsxs)(`button`,{type:`button`,"aria-current":u?`true`:void 0,onClick:()=>i(e.path),title:`${e.previousPath?`${e.previousPath} → `:``}${e.path} · ${Cn(e)}`,className:`unstyled flex min-h-10 w-full items-center gap-2 px-2.5 py-1.5 text-left hover:bg-accent/50 ${u?`bg-accent/60`:``}`,children:[(0,$.jsx)(Ka,{status:e.status}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs`,children:[(0,$.jsx)(`span`,{className:`text-mocha-light`,children:o}),(0,$.jsx)(`span`,{className:`font-medium text-foreground`,children:s})]}),l>0&&(0,$.jsxs)(`span`,{className:`flex shrink-0 items-center gap-0.5 text-xs font-semibold text-accent-foreground`,children:[(0,$.jsx)(ke,{className:`size-3`,"aria-hidden":`true`}),l]}),Ja(e),c&&(0,$.jsxs)(`span`,{title:`Last written by ${c.agentName}`,className:`shrink-0`,children:[(0,$.jsx)(H,{identity:a(c.agentId)?.identity,size:18}),(0,$.jsxs)(`span`,{className:`sr-only`,children:[`Last written by `,c.agentName]})]})]})},`${e.status}:${e.path}`)})}),e.truncated&&(0,$.jsx)(`p`,{className:`m-0 mt-2 text-xs text-warning`,children:`This list is incomplete: more files changed than a review shows.`}),(e.withheld.excluded>0||e.withheld.untracked>0)&&(0,$.jsxs)(`p`,{className:`m-0 mt-2 text-xs text-muted-foreground`,children:[`Not shown: `,e.withheld.excluded,` excluded and `,e.withheld.untracked,` untracked path`,e.withheld.excluded+e.withheld.untracked===1?``:`s`,`.`]}),e.issues.map(e=>(0,$.jsx)(`p`,{className:`m-0 mt-2 text-xs text-muted-foreground`,children:e.message},`${e.code}:${e.message}`))]})}var Xa=20;function Za(e,t,n,r){let i=new Map;for(let n of e.comments){let e=t[n.path]?.agentId;e&&i.set(e,(i.get(e)??0)+1)}let a=[...i].sort((e,t)=>t[1]-e[1])[0]?.[0],o=e=>n.some(t=>t.id===e);return o(a)?a:o(r)?r:n[0]?.id??``}function Qa({teamId:e,session:t,authors:i,onOpenFile:a}){let{agents:s,agent:c,to:u}=z(),d=U(),f=s.filter(t=>t.teamId===e),[p,m]=(0,G.useState)(null),h=(0,G.useId)(),[_,v]=(0,G.useState)(!1),[b,x]=(0,G.useState)(``),[S,C]=(0,G.useState)(null),w=Za(t,i,f,c?.agent.id),T=p&&f.some(e=>e.id===p)?p:w,E=t.comments.length;async function D(){v(!0),x(``);try{let r={agentId:T,comments:t.comments.map(({path:e,line:t,note:n})=>({path:e,...t===void 0?{}:{line:t},...n?{note:n}:{}})),...t.note.trim()?{note:t.note.trim()}:{},...t.base?{base:t.base}:{}};C({agentId:T,message:(await n(`/api/teams/${encodeURIComponent(e)}/review/feedback`,{body:r})).message}),t.clear(),d.refresh()}catch(e){x(wn(e instanceof o?e.code:void 0,l(e)))}finally{v(!1)}}if(E===0){let e=S?f.find(e=>e.id===S.agentId):void 0;return S?(0,$.jsxs)(`div`,{role:`status`,className:`rounded-2xl border border-success/30 bg-success/[0.08] px-3 py-2.5 text-sm`,children:[(0,$.jsxs)(`p`,{className:`m-0 font-semibold text-foreground`,children:[`Sent to `,e?.name??`the Agent`,`. It runs the review as its next turn.`]}),(0,$.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[e&&(0,$.jsx)(r,{to:`/`,search:u({agent:e.id,view:void 0,file:void 0}),className:`ghost-btn min-h-8 px-3 py-1 text-xs`,children:`Open the conversation`}),(0,$.jsx)(g,{variant:`ghost`,className:`min-h-8 px-3 py-1 text-xs`,onClick:()=>C(null),children:`Dismiss`})]}),(0,$.jsxs)(`details`,{className:`mt-2`,children:[(0,$.jsx)(`summary`,{className:`cursor-pointer text-xs text-mocha`,children:`The message it received`}),(0,$.jsx)(`pre`,{className:`m-0 mt-1.5 max-h-56 overflow-auto whitespace-pre-wrap break-words rounded-[10px] bg-card p-2.5 font-mono text-xs`,children:S.message})]})]}):(0,$.jsx)(`p`,{className:`m-0 rounded-2xl border border-dashed border-border bg-muted/40 px-3 py-3 text-sm text-muted-foreground`,children:`No comments yet. Click a line number in a diff, or comment on a whole file. The comments go to one Agent together.`})}return(0,$.jsxs)(`div`,{className:`rounded-2xl border border-primary/25 bg-accent/25 p-3`,children:[(0,$.jsxs)(`p`,{className:`m-0 text-sm font-semibold text-foreground`,children:[`Your review · `,E,` comment`,E===1?``:`s`]}),(0,$.jsx)(`ul`,{className:`m-0 mt-2 list-none space-y-1.5 p-0`,children:t.comments.map(e=>{let{name:n}=qa(e.path);return(0,$.jsxs)(`li`,{className:`flex items-start gap-2 rounded-[10px] border border-border bg-card px-2.5 py-1.5`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`button`,{type:`button`,onClick:()=>a?.(e.path),title:e.path,className:`unstyled block max-w-full truncate font-mono text-xs font-medium text-accent-foreground hover:underline`,children:[n,e.line===void 0?``:`:${e.line}`]}),(0,$.jsx)(`p`,{className:`m-0 mt-0.5 line-clamp-3 whitespace-pre-wrap break-words text-xs text-chocolate`,children:e.note||`No note: the Agent gets the file and its diff.`})]}),(0,$.jsx)(`button`,{type:`button`,"aria-label":`Remove this comment`,onClick:()=>t.removeComment(e.id),className:`unstyled flex size-6 shrink-0 items-center justify-center rounded-md text-mocha hover:bg-muted hover:text-danger`,children:(0,$.jsx)(y,{className:`size-3.5`,"aria-hidden":`true`})})]},e.id)})}),(0,$.jsxs)(`label`,{className:`mb-0 mt-2.5 text-xs`,children:[`About the review as a whole (optional)`,(0,$.jsx)(`textarea`,{rows:2,maxLength:2e3,value:t.note,onChange:e=>t.setNote(e.target.value),className:`min-h-14 text-sm`})]}),(0,$.jsxs)(`div`,{className:`mt-2.5 flex flex-wrap items-end gap-2`,children:[(0,$.jsxs)(`div`,{className:`m-0 min-w-0 flex-1 basis-40 text-xs`,children:[(0,$.jsx)(`span`,{id:h,className:`mb-1 block`,children:`Send to`}),(0,$.jsx)(pt,{labelledBy:h,value:T,options:f.map(e=>({value:e.id,label:e.name,hint:e.id===w&&t.comments.some(t=>i[t.path]?.agentId===e.id)?`wrote these files`:void 0})),onChange:m})]}),(0,$.jsx)(g,{variant:`primary`,disabled:_||!T||E>Xa,onClick:()=>void D(),children:_?`Sending…`:`Send review`})]}),E>Xa&&(0,$.jsxs)(`p`,{className:`m-0 mt-2 text-xs text-danger`,children:[`A review takes `,Xa,` comments at most: remove `,E-Xa,`.`]}),f.length===0&&(0,$.jsx)(`p`,{className:`m-0 mt-2 text-xs text-danger`,children:`This Team has no Agent to send a review to.`}),b&&(0,$.jsx)(`p`,{role:`alert`,className:`m-0 mt-2 text-xs text-danger`,children:b})]})}function $a({agent:e}){let t=i(),r=W(e=>n(et,{signal:e}),[]),[a,o]=(0,G.useState)({model:e.agent.modelOverride??``,reasoning:e.reasoningLevel}),[s,c]=(0,G.useState)(!1),[u,d]=(0,G.useState)(null),[f,p]=(0,G.useState)(null);async function m(r,i){let s=a;o(r),c(!0),p(null);try{await n(`/api/agents/${encodeURIComponent(e.agent.id)}`,{method:`PATCH`,body:{modelOverride:r.model||null,reasoningLevel:r.reasoning}}),await t.invalidate({sync:!0}),d(i?{before:s,what:i}:null)}catch(e){o(s),p(l(e))}finally{c(!1)}}let h=e=>{if(e===``)return`the template’s model`;let t=r.data?.chat.find(t=>t.value===e);return t?qe(t):e};return(0,$.jsxs)(`div`,{className:`grid gap-3`,children:[(0,$.jsx)(Ge,{kit:!0,disabled:s,label:`Model`,value:a.model,onChange:e=>{e!==a.model&&m({...a,model:e},`Model set to ${h(e)}`)},models:r.data?.chat??[],inherited:{label:`The template’s model`,model:e.profile.defaultModel}}),(0,$.jsx)(V,{label:`Reasoning`,value:a.reasoning,options:Et.map(e=>({value:e,label:e})),disabled:s,className:`max-w-none`,onChange:e=>{e!==a.reasoning&&m({...a,reasoning:e},`Reasoning set to ${e}`)}}),(0,$.jsx)(`p`,{role:`status`,className:`m-0 flex min-h-8 flex-wrap items-center gap-x-2 text-sm ${f?`text-warning`:`text-success`}`,children:f?`Not saved: ${f}`:s?(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:`Saving…`}):u?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`span`,{children:[u.what,`. It applies from the next turn.`]}),(0,$.jsx)(g,{variant:`ghost`,onClick:()=>void m(u.before,null),children:`Undo`})]}):(0,$.jsx)(`span`,{className:`text-muted-foreground`,children:`Changes apply from the next turn.`})}),r.error&&(0,$.jsxs)(`p`,{role:`alert`,className:`m-0 text-sm text-warning`,children:[`The models could not be loaded: `,r.error]})]})}function eo({agent:e,onClose:t,onRenamed:n}){let[r,i]=(0,G.useState)(e.name),[a,o]=(0,G.useState)(!1),[s,c]=(0,G.useState)(null),u=!r.trim()||r.trim()===e.name;async function d(i){if(i.preventDefault(),!u){o(!0),c(null);try{await zt(e.id,r.trim()),await n(),t()}catch(e){c(l(e)),o(!1)}}}return(0,$.jsx)(Ye,{title:`Rename ${e.name}`,description:`This changes the display name only; the Agent ID and history stay the same.`,busy:a,onClose:t,className:`max-w-md`,children:(0,$.jsxs)(`form`,{onSubmit:e=>void d(e),children:[(0,$.jsxs)(`label`,{children:[`Agent name`,(0,$.jsx)(`input`,{autoFocus:!0,value:r,onChange:e=>i(e.target.value),maxLength:120})]}),s&&(0,$.jsx)(`p`,{role:`alert`,className:`mt-3 text-sm text-danger`,children:s}),(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsxs)(_t,{children:[(0,$.jsx)(g,{variant:`ghost`,disabled:a,onClick:t,children:`Cancel`}),(0,$.jsx)(g,{variant:`primary`,type:`submit`,disabled:a||u,children:a?`Renaming…`:`Rename agent`})]})})]})})}function to({value:e,className:t,ariaLabel:n=`Copy to clipboard`,title:r=`Copy to clipboard`}){let[i,a]=(0,G.useState)(!1);async function o(){if(!e)return;let t=!1;try{navigator.clipboard?.writeText&&(await navigator.clipboard.writeText(e),t=!0)}catch{}if(!t){let n=document.createElement(`textarea`);n.value=e,n.setAttribute(`readonly`,``),n.style.position=`fixed`,n.style.opacity=`0`,document.body.appendChild(n),n.select();try{t=document.execCommand(`copy`)}catch{}n.remove()}t&&(a(!0),setTimeout(()=>a(!1),1e3))}return(0,$.jsx)(`button`,{type:`button`,onClick:o,title:r,"aria-label":n,className:`inline-flex h-[1.3rem] w-[1.6rem] items-center justify-center rounded-sm border border-transparent text-mocha-light transition-colors hover:border-frost hover:bg-snow hover:text-mocha ${i?`border-[#bcd9bc] bg-[#eef7ee] text-[#3b7a3b] hover:border-[#bcd9bc] hover:bg-[#eef7ee] hover:text-[#3b7a3b]`:``} ${t??``}`,children:i?`✓`:`⧉`})}var no=(e,t,n=`${t}s`)=>`${e} ${e===1?t:n}`;function ro({agent:e}){let{agent:t}=e,{teams:a,to:o,search:s}=z(),c=U(),u=i(),d=Pt(),[f,p]=(0,G.useState)(!1),m=rt(t);async function h(){if(m){b(null);try{await zt(t.id,m),await u.invalidate()}catch(e){b(l(e))}}}let[_,v]=(0,G.useState)(null),[y,b]=(0,G.useState)(null),x=t.status===`archived`,S=`/api/agents/${encodeURIComponent(t.id)}`,C=c.stateOf(t.id),w=c.byAgent.get(t.id)?.lastActivityAt??null,T=W(async e=>{let[t,r,i]=await Promise.all([n(`${S}/triggers`,{signal:e}),n(`${S}/lesson-proposals`,{signal:e}),n(`${S}/messages?unread=1`,{signal:e})]);return{schedules:t.triggers.filter(e=>e.enabled).length,schedulesOff:t.triggers.filter(e=>!e.enabled).length,proposals:r.proposals.filter(e=>e.status===`pending`).length,unread:i.messages.length}},[S,s.section],{refreshOn:c.turnsEnded}),E=W(e=>n(`/api/config/telegram`,{signal:e}).catch(()=>({configured:!1})),[]);async function D(){b(null);try{await Lt(t.id),await u.invalidate()}catch(e){b(l(e))}}let k=T.data,A=[{section:`schedules`,icon:qt,label:`Schedules`,detail:k?k.schedules+k.schedulesOff===0?`None`:`${k.schedules} on${k.schedulesOff?`, ${k.schedulesOff} off`:``}`:``},{section:`learning`,icon:Gt,label:`Learning`,detail:k?.proposals?`${no(k.proposals,`lesson`)} to review`:e.privateLessons.length?`${no(e.privateLessons.length,`lesson`)} applied`:t.reviewEnabled?`Reviews every ${t.reviewEveryNTurns} turns`:`Periodic review off`},{section:`mailbox`,icon:nn,label:`Mailbox`,detail:k?k.unread?`${k.unread} unread`:`Nothing unread`:``},{section:`skills`,icon:Pe,label:`Skills`,detail:e.profile.skillsMode===`all`&&e.skills.length===0?`From the template`:`${e.skills.length} attached`},...E.data?.configured?[{section:`telegram`,icon:hn,label:`Telegram`,detail:t.telegramTopicId===null?`Not bound`:`Topic #${t.telegramTopicId}`}]:[],{section:`browser`,icon:$t,label:`Browser`,detail:`Session and saved profile`}];return(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,$.jsx)(H,{identity:t.identity,size:44}),(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`min-w-0 truncate text-base font-semibold text-foreground`,children:t.name}),x&&(0,$.jsx)(O,{variant:`warning`,children:`Archived`})]}),(t.identity?.creature||t.identity?.vibe)&&(0,$.jsx)(`p`,{className:`m-0 truncate text-xs text-muted-foreground`,children:[t.identity?.creature,t.identity?.vibe].filter(Boolean).join(` · `)}),m&&(0,$.jsxs)(`p`,{className:`m-0 mt-0.5 flex min-w-0 flex-wrap items-center gap-x-1.5 text-xs text-mocha`,children:[(0,$.jsxs)(`span`,{children:[`It calls itself `,m,`.`]}),(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void h(),className:`unstyled font-semibold text-sapphire underline underline-offset-2 hover:text-sapphire-deep`,children:[`Use `,m,` as its name`]})]}),(0,$.jsxs)(`p`,{className:`m-0 mt-0.5 flex min-w-0 items-center gap-1.5 text-xs text-mocha`,children:[(0,$.jsx)(`span`,{className:`size-[7px] shrink-0 rounded-full ${xe[C.kind]}`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:C.text}),d&&w!==null&&C.kind!==`working`&&(0,$.jsxs)(`span`,{className:`shrink-0 text-muted-foreground`,children:[`· last active `,dt(w)]})]})]})]}),y&&(0,$.jsx)(`p`,{role:`alert`,className:`err mt-3`,children:y}),x&&(0,$.jsxs)(`div`,{className:`mt-3 rounded-[10px] border border-warning/30 bg-warning/[0.07] px-3 py-2 text-sm text-chocolate`,children:[`This Agent is archived: it is hidden from the list and receives no work.`,(0,$.jsx)(`div`,{className:`mt-2`,children:(0,$.jsx)(g,{variant:`ghost`,onClick:()=>void D(),children:`Restore`})})]}),(0,$.jsx)(Vo,{children:`Model`}),(0,$.jsx)($a,{agent:e}),(0,$.jsx)(Vo,{children:`More about this Agent`}),(0,$.jsx)(Ho,{children:A.map(({section:e,icon:t,label:n,detail:i})=>(0,$.jsxs)(r,{to:`/`,search:o({panel:`agent`,section:e}),className:`flex min-h-11 items-center gap-2.5 px-3 py-2 text-foreground hover:bg-accent/50`,children:[(0,$.jsx)(t,{className:`size-4 shrink-0 text-mocha`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`shrink-0 text-sm font-semibold`,children:n}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-right text-xs ${e===`learning`&&k?.proposals||e===`mailbox`&&k?.unread?`font-semibold text-warning`:`text-muted-foreground`}`,children:i}),(0,$.jsx)(me,{className:`size-3.5 shrink-0 text-muted-foreground`,"aria-hidden":`true`})]},e))}),(0,$.jsx)(Vo,{children:`Team`}),(0,$.jsx)(io,{agentId:t.id,teamId:e.team.id,teams:a},e.team.id),(0,$.jsx)(Vo,{children:`Details`}),(0,$.jsxs)(`dl`,{className:`m-0 grid grid-cols-[max-content_minmax(0,1fr)] gap-x-3 gap-y-1.5 text-xs`,children:[(0,$.jsx)(`dt`,{className:`text-muted-foreground`,children:`Template`}),(0,$.jsx)(`dd`,{className:`m-0 min-w-0 truncate`,children:(0,$.jsx)(`a`,{href:`/templates/agents/${encodeURIComponent(e.profile.id)}`,children:e.profile.name||e.profile.id})}),(0,$.jsx)(`dt`,{className:`text-muted-foreground`,children:`ID`}),(0,$.jsxs)(`dd`,{className:`m-0 flex min-w-0 items-center gap-1`,children:[(0,$.jsx)(`span`,{className:`min-w-0 select-all truncate font-mono text-mocha`,children:t.id}),(0,$.jsx)(to,{value:t.id,ariaLabel:`Copy the Agent's ID`,title:`Copy the ID`})]}),(0,$.jsx)(`dt`,{className:`text-muted-foreground`,children:`Files`}),(0,$.jsx)(`dd`,{className:`m-0 min-w-0 truncate font-mono text-mocha`,title:t.dir,children:t.dir})]}),(0,$.jsxs)(`div`,{className:`mt-5 flex flex-wrap gap-2`,children:[(0,$.jsx)(g,{variant:`ghost`,onClick:()=>p(!0),children:`Rename`}),!x&&(0,$.jsx)(g,{variant:`ghost`,onClick:()=>v(`archive`),children:`Archive`}),(0,$.jsx)(g,{variant:`danger`,onClick:()=>v(`delete`),children:`Delete`})]}),f&&(0,$.jsx)(eo,{agent:t,onClose:()=>p(!1),onRenamed:()=>u.invalidate()}),(0,$.jsx)(Ft,{open:_!==null,onOpenChange:e=>{e||v(null)},title:_===`delete`?`Delete ${t.name} permanently?`:`Archive ${t.name}?`,description:_===`delete`?(0,$.jsx)(`p`,{children:`This removes its conversations, messages, schedules, skill attachments and private files. Files it saved for the Team stay. This cannot be undone.`}):(0,$.jsx)(`p`,{children:`The Agent leaves the list and receives no work. Restore it later under Manage, Agents, with “Show archived”.`}),confirmLabel:_===`delete`?`Delete permanently`:`Archive agent`,confirmVariant:_===`delete`?`danger`:`primary`,onConfirm:async()=>{_===`delete`?await Rt(t.id):await Bt(t.id),await u.navigate({to:`/`,search:{team:e.team.id}}),await u.invalidate()}})]})}function io({agentId:e,teamId:t,teams:r}){let a=i(),[o,s]=(0,G.useState)(t),[c,u]=(0,G.useState)(!1),[d,f]=(0,G.useState)(null);async function p(t){t.preventDefault(),u(!0),f(null);try{await n(`/api/agents/${encodeURIComponent(e)}/team`,{method:`PATCH`,body:{teamId:o}}),await a.invalidate({sync:!0})}catch(e){f(l(e))}finally{u(!1)}}return(0,$.jsxs)(`form`,{onSubmit:e=>void p(e),children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(pt,{ariaLabel:`Team`,value:o,options:r.map(e=>({value:e.id,label:e.name,hint:e.id===t?`now`:void 0})),onChange:s,className:`min-w-0 flex-1`}),(0,$.jsx)(g,{variant:`primary`,type:`submit`,disabled:c||o===t,children:c?`Moving…`:`Move`})]}),o!==t&&(0,$.jsx)(`p`,{className:`m-0 mt-1.5 text-xs text-muted-foreground`,children:`Moving leaves this Agent's connections behind; it joins the other Team with none.`}),d&&(0,$.jsx)(`p`,{role:`alert`,className:`m-0 mt-1.5 text-xs text-danger`,children:d})]})}function ao({team:e}){let{to:t,search:i,agentById:a}=z(),{turnsEnded:o}=U(),s=W(t=>n(`/api/teams/${encodeURIComponent(e.id)}/policy`,{signal:t}),[e.id,i.view],{refreshOn:o}),c=be(e.id);if(s.error)return(0,$.jsx)(`p`,{role:`alert`,className:`err`,children:s.error});if(!s.data)return(0,$.jsx)(`p`,{role:`status`,className:`m-0 text-sm text-muted-foreground`,children:`Loading the connections…`});let{mode:l,edges:u}=s.data,d=s.data.members.filter(e=>e.status!==`archived`),f=he(c.data??[]),p=(e,t)=>u.some(n=>n.from===e&&n.to===t),m=new Set(d.map(e=>e.id)),h=u.filter(e=>m.has(e.from)&&m.has(e.to)).length;return(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`rounded-2xl border border-border bg-muted/50 px-3 py-2.5`,children:[(0,$.jsx)(`p`,{className:`m-0 text-sm font-semibold text-foreground`,children:kt[l]}),(0,$.jsxs)(`p`,{className:`m-0 mt-0.5 text-xs leading-relaxed text-mocha`,children:[l===`open`?`Every member can message every other member, with no connections needed. Connections here only matter for messages to and from other Teams, or if you switch the Team to Connections only.${h>0?` ${h} ${h===1?`connection between teammates is`:`connections between teammates are`} saved; ${h===1?`it applies`:`they apply`} then.`:``}`:`A member can message a teammate only along a connection.`,` `,`You can always talk to every Agent.`]}),(0,$.jsxs)(r,{to:`/`,search:t({view:`connections`,section:void 0}),className:`btn-primary mt-2.5 min-h-9 w-full py-1.5 text-sm no-underline`,children:[(0,$.jsx)(Me,{className:`size-4`,"aria-hidden":`true`}),`Open the map`]})]}),(0,$.jsx)(Vo,{children:`Who can message whom`}),d.length===0?(0,$.jsx)(`p`,{className:`m-0 text-sm text-muted-foreground`,children:`This Team has no members yet.`}):(0,$.jsx)(Ho,{children:d.map(e=>{let t=[...d.filter(t=>t.id!==e.id),null].flatMap(t=>{let n=t?.id??`outside`,r=p(e.id,n),i=p(n,e.id);return l===`open`&&t||!r&&!i?[]:[{id:n,name:t?.name??`Other teams`,out:r,back:i}]}),n=d.reduce((t,n)=>{if(n.id===e.id)return t;let r=f.get(ve(e.id,n.id));return r?t+(e.id<n.id?r.forward:r.back):t},0);return(0,$.jsxs)(`div`,{className:`px-3 py-2.5`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(H,{identity:a(e.id)?.identity,size:22}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm font-semibold text-foreground`,children:e.name}),n>0&&(0,$.jsxs)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:[n,` sent`]})]}),(0,$.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap gap-1.5 pl-[30px]`,children:[l===`open`&&(0,$.jsx)(`span`,{className:`rounded-full bg-frost px-2 py-0.5 text-xs text-chocolate`,children:`Everyone in the Team`}),t.map(t=>(0,$.jsxs)(`span`,{title:t.out&&t.back?`${e.name} and ${t.name} can message each other`:t.out?`${e.name} can message ${t.name}`:`${t.name} can message ${e.name}`,className:`inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs ${t.out?`bg-accent text-accent-foreground`:`bg-frost text-foreground`}`,children:[t.out&&t.back?(0,$.jsx)(Ut,{className:`size-3`,"aria-hidden":`true`}):t.out?(0,$.jsx)(R,{className:`size-3`,"aria-hidden":`true`}):(0,$.jsx)(R,{className:`size-3 rotate-180`,"aria-hidden":`true`}),t.name]},t.id)),l===`restricted`&&t.length===0&&(0,$.jsx)(`span`,{className:`rounded-full bg-warning/15 px-2 py-0.5 text-xs font-semibold text-warning`,children:`No connections: it can only talk to you`})]})]},e.id)})}),(0,$.jsx)(Vo,{children:`Recent messages`}),c.error?(0,$.jsx)(`p`,{role:`alert`,className:`m-0 text-xs text-danger`,children:c.error}):(0,$.jsx)(Te,{messages:c.data??[],limit:12})]})}var oo=[{id:`all`,label:`All`},{id:`pictures`,label:`Pictures`},{id:`documents`,label:`Documents`}],so=e=>e.mimeType.startsWith(`image/`);function co(e){let{agents:t,agent:n,conversationId:r}=z(),[i,a]=(0,G.useState)(`all`),[o,s]=(0,G.useState)(`team`),c=n&&n.team.id===e.id?n.agent:null,l=[{value:`team`,label:`Everyone in ${e.name}`},...t.filter(t=>t.teamId===e.id).map(e=>({value:`agent:${e.id}`,label:e.name})),...c&&r?[{value:`conversation`,label:`This conversation`,hint:c.name}]:[]],u=l.some(e=>e.value===o)?o:`team`;return{kind:i,setKind:a,who:u,setWho:s,options:l,filter:u.startsWith(`agent:`)?{agentId:u.slice(6)}:u===`conversation`&&r?{sessionId:r}:{},narrowed:u!==`team`,matches:e=>i===`all`||i===`pictures`===so(e)}}function lo({state:e}){return(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,$.jsx)(It,{label:`Kind of file`,value:e.kind,options:oo,onChange:e.setKind}),(0,$.jsx)(wt,{label:`Whose files`,value:e.who,options:e.options,onChange:e.setWho})]})}var uo=[`image/png`,`image/jpeg`,`image/gif`,`image/webp`];function fo(e){return uo.includes(e.mimeType)&&e.byteLength<=10*1024*1024}function po(e){return ut(e)}var mo=1200;function ho(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(+(e<10*1024))} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function go(e,t){if(e.startsWith(`image/`))return`${e.slice(6).toUpperCase()} image`;if(e===`text/markdown`)return`Markdown`;if(e===`text/plain`)return`Text`;if(e===`application/pdf`)return`PDF`;let n=/\.([a-z0-9]{1,6})$/i.exec(t)?.[1];return n?n.toUpperCase():e}var _o=(e,t)=>`/api/results/${encodeURIComponent(e)}${t?`/${t}`:``}`,vo=e=>`${_o(e,`preview`)}?bytes=${mo}`;function yo(e){let t=new URLSearchParams;for(let[n,r]of Object.entries(e))r&&t.set(n,r);return`/api/results/archive?${t}`}function bo({resultId:e,result:t,detail:i,open:a,selected:c=!1,compact:u=!1,onPick:d}){let[f,p]=(0,G.useState)(t??null),[m,h]=(0,G.useState)(``),[_,v]=(0,G.useState)(null);(0,G.useEffect)(()=>{if(t){p(t);return}let r=new AbortController;return n(_o(e),{signal:r.signal}).then(e=>p(e.result)).catch(e=>{r.signal.aborted||h(e instanceof o&&e.status===404?`This saved file is unavailable (it may have been deleted).`:l(e))}),()=>r.abort()},[e,t]);async function y(){if(_!==null)return v(null);h(``);try{v(await(await s(_o(e,`preview`))).text())}catch(e){h(l(e))}}if(!f)return(0,$.jsx)(`div`,{className:`rounded-[10px] border border-border bg-muted p-3 text-sm text-muted-foreground`,children:m?(0,$.jsx)(`span`,{role:`alert`,children:m}):(0,$.jsx)(`span`,{role:`status`,children:`Loading saved file…`})});let b=[ho(f.byteLength),go(f.mimeType,f.name),f.imageModel?`made with ${f.imageModel}`:null].filter(Boolean).join(` · `),x=(0,$.jsx)(`a`,{href:_o(f.id,`download`),download:f.name,"aria-label":`Download ${f.name}`,title:`Download`,className:`flex size-8 shrink-0 items-center justify-center rounded-[10px] border border-border bg-card text-foreground hover:border-sapphire-light hover:text-sapphire`,children:(0,$.jsx)(ue,{className:`size-[15px]`,"aria-hidden":`true`})}),S=`min-w-0 overflow-hidden rounded-[10px] border bg-muted ${c?`border-primary ring-1 ring-primary`:`border-border`}`;if(u){let e=fo(f)?(0,$.jsx)(`img`,{src:_o(f.id,`preview`),alt:``,loading:`lazy`,className:`block aspect-[4/3] w-full bg-card object-contain p-1.5`}):po(f)?(0,$.jsx)(So,{result:f}):(0,$.jsx)(xo,{result:f});return(0,$.jsxs)(`figure`,{className:`m-0 ${S}`,children:[d?(0,$.jsxs)(`button`,{type:`button`,onClick:d,"aria-pressed":c,className:`unstyled block w-full`,children:[(0,$.jsxs)(`span`,{className:`sr-only`,children:[`Choose `,f.name]}),e]}):a?(0,$.jsxs)(r,{to:`/`,search:a,"aria-current":c?`true`:void 0,className:`block`,children:[(0,$.jsxs)(`span`,{className:`sr-only`,children:[`Open `,f.name]}),e]}):e,(0,$.jsxs)(`figcaption`,{className:`flex items-center gap-1.5 py-1.5 pl-2.5 pr-1.5`,children:[(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate text-sm font-semibold text-foreground`,title:f.name,children:f.name}),(0,$.jsx)(`span`,{className:`block truncate text-xs text-mocha`,children:i??b})]}),x]})]})}if(fo(f)){let e=(0,$.jsx)(`img`,{src:_o(f.id,`preview`),alt:f.name,loading:`lazy`,className:`block max-h-80 w-full bg-card object-contain`});return(0,$.jsxs)(`figure`,{className:`m-0 ${S}`,children:[a?(0,$.jsx)(r,{to:`/`,search:a,"aria-label":`Open ${f.name} in Files`,className:`block`,children:e}):e,(0,$.jsxs)(`figcaption`,{className:`flex items-center gap-2 py-1.5 pl-2.5 pr-1.5`,children:[(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate text-sm font-semibold text-foreground`,children:f.name}),(0,$.jsx)(`span`,{className:`block truncate text-xs text-mocha`,children:i??b})]}),x]})]})}return(0,$.jsxs)(`div`,{className:S,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-2.5 py-2 pl-2.5 pr-1.5`,children:[(0,$.jsx)(De,{className:`size-[18px] shrink-0 text-mocha`,"aria-hidden":`true`}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[a?(0,$.jsx)(r,{to:`/`,search:a,className:`block truncate text-sm font-semibold text-foreground hover:text-sapphire`,children:f.name}):(0,$.jsx)(`span`,{className:`block truncate text-sm font-semibold text-foreground`,children:f.name}),(0,$.jsx)(`span`,{className:`block truncate text-xs text-mocha`,children:i??b})]}),po(f)&&(0,$.jsx)(g,{variant:`ghost`,className:`min-h-8 px-2.5 py-1 text-xs`,onClick:()=>void y(),children:_===null?`Preview`:`Hide`}),x]}),_!==null&&(0,$.jsx)(`pre`,{className:`m-0 max-h-80 overflow-auto whitespace-pre-wrap break-words border-t border-border bg-card p-3 text-xs`,children:_}),m&&(0,$.jsx)(`p`,{role:`alert`,className:`m-0 border-t border-border px-3 py-2 text-xs text-danger`,children:m})]})}function xo({result:e}){return(0,$.jsxs)(`span`,{"aria-hidden":`true`,className:`flex aspect-[4/3] w-full flex-col items-center justify-center gap-1.5 bg-card text-mocha`,children:[(0,$.jsx)(De,{className:`size-7`}),(0,$.jsx)(`span`,{className:`max-w-full truncate px-2 font-mono text-xs font-medium uppercase tracking-wide`,children:go(e.mimeType,e.name)})]})}function So({result:e}){let[t,n]=(0,G.useState)(null);return(0,G.useEffect)(()=>{let t=new AbortController;return s(vo(e.id),{signal:t.signal}).then(e=>e.text()).then(e=>n(e.trim()?e:null)).catch(()=>n(null)),()=>t.abort()},[e.id]),t===null?(0,$.jsx)(xo,{result:e}):(0,$.jsxs)(`span`,{"aria-hidden":`true`,className:`relative block aspect-[4/3] w-full overflow-hidden bg-card text-left`,children:[(0,$.jsx)(`pre`,{className:`m-0 h-full overflow-hidden whitespace-pre-wrap break-words p-2.5 font-mono text-[10px] leading-[1.45] text-mocha`,children:t}),(0,$.jsx)(`span`,{className:`pointer-events-none absolute inset-x-0 bottom-0 h-10 bg-gradient-to-t from-card to-transparent`}),(0,$.jsx)(`span`,{className:`absolute bottom-1.5 right-2 rounded bg-muted px-1.5 py-0.5 font-mono text-[10px] font-medium uppercase tracking-wide text-mocha`,children:go(e.mimeType,e.name)})]})}var Co=100;function wo(e,t,r=24){let{turnsEnded:i}=U(),[a,o]=(0,G.useState)(r),s=`${e}|${t.agentId??``}|${t.sessionId??``}`;(0,G.useEffect)(()=>o(r),[s,r]);let c=W(async r=>{let i=[],o=0;for(let s=0;s<a;s+=Co){let c=new URLSearchParams({limit:String(Math.min(Co,a-s)),offset:String(s)});e&&c.set(`teamId`,e),t.agentId&&c.set(`agentId`,t.agentId),t.sessionId&&c.set(`sessionId`,t.sessionId);let l=await n(`/api/results?${c}`,{signal:r});if(i.push(...l.results),o=l.total,i.length>=o)break}return{results:i,total:o}},[s,a],{refreshOn:i}),l=c.data?.results??[],u=c.data?.total??0;return{results:l,total:u,loading:c.loading,error:c.error,hasMore:l.length<u,more:()=>o(e=>e+r),reload:c.reload}}var To=`inline-flex h-7 items-center gap-1 rounded-[10px] border border-border bg-card px-2 text-xs font-semibold text-foreground hover:border-sapphire-light hover:text-sapphire`;function Eo({team:e}){let{agentById:t,to:n}=z(),i=Pt(),a=co(e),{filter:o}=a,s=wo(e.id,o,12),c=s.results.filter(a.matches);return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`div`,{className:`mb-3`,children:(0,$.jsx)(lo,{state:a})}),(0,$.jsxs)(`div`,{className:`mb-2 flex items-center justify-between gap-2`,children:[(0,$.jsx)(`p`,{className:`m-0 text-xs text-muted-foreground`,children:s.loading&&s.results.length===0?`Loading…`:a.kind===`all`?`${s.total} saved file${s.total===1?``:`s`}`:`${c.length} of the ${s.results.length} loaded`}),(0,$.jsxs)(`div`,{className:`flex gap-1.5`,children:[s.total>0&&a.kind===`all`&&(0,$.jsxs)(`a`,{href:yo({teamId:e.id,...o}),download:!0,className:To,title:`Download these files as one zip`,children:[(0,$.jsx)(ue,{className:`size-3.5`,"aria-hidden":`true`}),`All (.zip)`]}),(0,$.jsxs)(r,{to:`/`,search:n({view:`files`,section:void 0}),className:To,children:[(0,$.jsx)(de,{className:`size-3.5`,"aria-hidden":`true`}),`Gallery`]})]})]}),s.error&&(0,$.jsx)(`p`,{role:`alert`,className:`err`,children:s.error}),!s.loading&&!s.error&&s.total===0&&(0,$.jsxs)(`p`,{className:`m-0 rounded-2xl border border-dashed border-border bg-muted/40 px-3 py-4 text-sm text-muted-foreground`,children:[`Nothing saved `,a.narrowed?`here`:`in this Team`,` yet. Files an Agent delivers or pictures it generates are kept here with their original contents.`]}),!s.loading&&s.total>0&&c.length===0&&(0,$.jsxs)(`p`,{className:`m-0 rounded-2xl border border-dashed border-border bg-muted/40 px-3 py-4 text-sm text-muted-foreground`,children:[`No `,a.kind===`pictures`?`pictures`:`documents`,` among the files loaded`,s.hasMore?`; Show more loads older ones.`:`.`]}),(0,$.jsx)(`div`,{className:`grid grid-cols-2 gap-2.5`,children:c.map(e=>{let r=t(e.agentId)?.name;return(0,$.jsx)(bo,{resultId:e.id,result:e,compact:!0,detail:[r,i?dt(e.createdAt):null].filter(Boolean).join(` · `),open:n({view:`files`,result:e.id,section:void 0})},e.id)})}),s.hasMore&&(0,$.jsx)(`div`,{className:`mt-3`,children:(0,$.jsx)(g,{variant:`ghost`,className:`w-full`,disabled:s.loading,onClick:s.more,children:s.loading?`Loading…`:`Show more (${s.total-s.results.length} left)`})})]})}function Do(e){return e.replace(/^\s{0,3}#{1,6}\s+/,``).replace(/^\s*>\s?/,``).replace(/^\s*(?:[-*+]|\d+[.)])\s+(?:\[[ xX]\]\s+)?/,``)}function Oo(e){return e.replace(/!\[([^\]]*)\]\([^)]*\)/g,`$1`).replace(/\[([^\]]+)\]\([^)]*\)/g,`$1`).replace(/`([^`]*)`/g,`$1`).replace(/(^|[^\w*])\*\*([^*\s](?:.*?[^*\s])?)\*\*(?![\w*])/g,`$1$2`).replace(/(^|[^\w_])__([^_\s](?:.*?[^_\s])?)__(?![\w_.])/g,`$1$2`).replace(/(^|[^\w*])\*([^*\s](?:[^*]*?[^*\s])?)\*(?![\w*])/g,`$1$2`).replace(/(^|[^\w_])_([^_\s](?:[^_]*?[^_\s])?)_(?![\w_])/g,`$1$2`).replace(/~~(\S(?:.*?\S)?)~~/g,`$1`)}var ko=e=>/^\s*([-*_])(\s*\1){2,}\s*$/.test(e),Ao=e=>/^\s{0,3}#{1,6}\s/.test(e),jo=e=>/^\s*(`{3,}|~{3,})/.exec(e)?.[1]??null,Mo=/^\s*@@[^@]*@@\s*/;function No(e){for(let t of e.split(`
69
+ `)){let e=t.replace(Mo,``);if(!e.trim())continue;let n=/^\s{0,3}#{1,6}\s+(.+)$/.exec(e);return n?.[1]&&Oo(n[1]).trim()||null}return null}function Po(e,t=140){let n=[],r=[],i=null,a=()=>{r.length&&n.push(Oo(r.join(` `))),r=[]};for(let o of e.split(`
70
+ `)){let e=o.replace(Mo,``),s=jo(e);if(i){s&&s[0]===i[0]&&s.length>=i.length&&(i=null);continue}if(s){a(),i=s;continue}if(!e.trim()||ko(e)||Ao(e)){a();continue}if(/^\s*(?:[-*+]|\d+[.)])\s+/.test(e)&&a(),r.push(Do(e).trim()),n.join(` `).length>t)break}a();let o=n.join(` `).replace(/\s+/g,` `).trim();if(o.length<=t)return o;let s=o.slice(0,t),c=s.lastIndexOf(` `);return`${(c>t*.6?s.slice(0,c):s).replace(/[\s,;:.–-]+$/,``)}…`}var Fo=`inline-flex h-7 items-center gap-1 rounded-[10px] border border-border bg-card px-2 text-xs font-semibold text-foreground hover:border-sapphire-light hover:text-sapphire`;function Io({team:e}){let{agents:t,profiles:a,teams:o,teamTemplates:s,agent:c,to:l,search:u}=z(),{turnsEnded:d}=U(),f=W(t=>n(`/api/teams/${encodeURIComponent(e.id)}`,{signal:t}),[e.id,u.section],{refreshOn:d}),p=f.data?.id===e.id?f.data.userMd:e.userMd,m=U(),h=i(),[g,_]=(0,G.useState)(!1),[v,y]=(0,G.useState)(!1),[b,x]=(0,G.useState)(null),S=t.filter(t=>t.teamId===e.id),C=s.filter(e=>e.slots.length>0),w=C.find(e=>e.id===b);return(0,$.jsxs)(`div`,{children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`div`,{className:`truncate text-base font-semibold text-foreground`,children:e.name}),(0,$.jsxs)(`div`,{className:`mt-0.5 flex flex-wrap items-center gap-x-3 gap-y-0.5 text-xs`,children:[(0,$.jsx)(r,{to:`/`,search:{team:e.id},className:`font-semibold text-sapphire hover:text-sapphire-deep`,children:`Its day so far`}),!v&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>y(!0),className:`unstyled text-muted-foreground underline underline-offset-2 hover:text-sapphire`,children:`Show the folder`})]}),v&&(0,$.jsxs)(`p`,{className:`m-0 mt-0.5 flex min-w-0 items-center gap-1 font-mono text-xs text-muted-foreground`,children:[(0,$.jsx)(`span`,{className:`min-w-0 truncate`,title:e.path,children:e.path}),(0,$.jsx)(to,{value:e.path,ariaLabel:`Copy the folder's path`})]})]}),(0,$.jsx)(r,{to:`/`,search:l({panel:`connections`,section:void 0}),title:kt[e.policyMode],className:`shrink-0 rounded-full border border-border bg-muted px-2 py-0.5 text-xs font-semibold text-mocha hover:border-sapphire-light hover:text-sapphire`,children:Ot[e.policyMode]})]}),(c||S.length===0&&C.length>0)&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`mt-5 flex items-center justify-between gap-2`,children:[(0,$.jsxs)(Vo,{children:[S.length,` member`,S.length===1?``:`s`]}),(0,$.jsxs)(`button`,{type:`button`,className:`unstyled ${Fo}`,onClick:()=>_(!0),children:[(0,$.jsx)(B,{className:`size-3.5`,"aria-hidden":`true`}),`Add an Agent`]})]}),S.length===0?(0,$.jsxs)(`div`,{className:`rounded-2xl border border-dashed border-border bg-muted/40 px-3 py-4 text-sm text-muted-foreground`,children:[(0,$.jsx)(`p`,{className:`m-0`,children:`No Agents in this Team yet.`}),C.length>0&&(0,$.jsxs)(`div`,{className:`mt-3`,children:[(0,$.jsx)(`span`,{className:`mb-1.5 block text-xs`,children:`Or start it from a Team template`}),(0,$.jsx)(pt,{ariaLabel:`Start from a Team template`,value:``,placeholder:`Choose a Team template…`,options:C.map(e=>({value:e.id,label:e.name,hint:`${e.slots.length} member${e.slots.length===1?``:`s`}`})),onChange:e=>x(e||null)})]})]}):(0,$.jsx)(Ho,{children:S.map(e=>{let t=m.stateOf(e.id),n=e.id===c?.agent.id;return(0,$.jsxs)(r,{to:`/`,search:{agent:e.id,panel:`team`},"aria-current":n?`true`:void 0,className:`flex min-h-12 items-center gap-2.5 px-3 py-2 text-foreground hover:bg-accent/50 ${n?`bg-accent/40`:``}`,children:[(0,$.jsx)(H,{identity:e.identity,size:28}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate text-sm font-semibold`,children:e.name}),(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5 text-xs text-mocha`,children:[(0,$.jsx)(`span`,{className:`size-[7px] shrink-0 rounded-full ${xe[t.kind]}`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:t.text})]})]}),!n&&(0,$.jsx)(me,{className:`size-3.5 shrink-0 text-muted-foreground`,"aria-hidden":`true`})]},e.id)})})]}),(0,$.jsxs)(`div`,{className:`mt-5 flex items-center justify-between gap-2`,children:[(0,$.jsx)(Vo,{children:`About you · USER.md`}),(0,$.jsx)(r,{to:`/`,search:l({panel:`team`,section:`user-md`}),className:Fo,children:`Edit`})]}),p.trim()?(0,$.jsx)(r,{to:`/`,search:l({panel:`team`,section:`user-md`}),className:`block rounded-2xl border border-border bg-muted/50 px-3 py-2.5 hover:border-sapphire-light`,children:(0,$.jsx)(`span`,{className:`line-clamp-4 break-words text-sm leading-relaxed text-chocolate`,children:Po(p,320)||p.trim()})}):(0,$.jsxs)(`div`,{className:`rounded-2xl border border-dashed border-border bg-muted/40 px-3 py-3 text-sm text-muted-foreground`,children:[(0,$.jsx)(`p`,{className:`m-0`,children:`Tell this Team’s Agents who you are and how you like to work. Every member reads it on every turn, and fills it in as it learns about you.`}),(0,$.jsx)(r,{to:`/`,search:l({panel:`team`,section:`user-md`}),className:`mt-2.5 ${Fo}`,children:`Write it`})]}),(0,$.jsx)(Ro,{team:e},`${e.id}:${u.section??``}`),(0,$.jsx)(Vo,{children:`Settings`}),(0,$.jsx)(Ho,{children:(0,$.jsxs)(r,{to:`/`,search:l({panel:`team`,section:`settings`}),className:`flex min-h-11 items-center gap-2.5 px-3 py-2 text-foreground hover:bg-accent/50`,children:[(0,$.jsx)(Be,{className:`size-4 shrink-0 text-mocha`,"aria-hidden":`true`}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block text-sm font-semibold`,children:`Workspace and templates`}),(0,$.jsx)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:`Sandbox defaults, Telegram topic names, save as a template`})]}),(0,$.jsx)(me,{className:`size-3.5 shrink-0 text-muted-foreground`,"aria-hidden":`true`})]})}),g&&(0,$.jsx)(Tt,{profiles:a,teams:o,teamId:e.id,onClose:()=>_(!1)}),w&&(0,$.jsx)(Vt,{template:w,teams:[e],initialTeamId:e.id,onClose:()=>x(null),onSpawned:()=>{x(null),h.invalidate()}})]})}var Lo=(e,t)=>({key:e,title:No(t)??e.split(`/`).pop()?.replace(/\.md$/,``)??e,preview:Po(t,120)});function Ro({team:e}){let{to:t}=z(),{turnsEnded:i}=U(),a=`/api/teams/${encodeURIComponent(e.id)}/memory`,[o,s]=(0,G.useState)(``),[c,l]=(0,G.useState)(``);(0,G.useEffect)(()=>{let e=setTimeout(()=>l(o.trim()),200);return()=>clearTimeout(e)},[o]);let u=W(async e=>{if(c)return{rows:(await n(`${a}/search?q=${encodeURIComponent(c)}&limit=8`,{signal:e})).map(e=>Lo(e.key,e.snippet)),total:null};let t=await n(a,{signal:e});return{rows:[...t].sort((e,t)=>t.updatedAt-e.updatedAt).slice(0,5).map(e=>Lo(e.key,e.content)),total:t.length}},[a,c],{refreshOn:i}),d=u.data?.total;return(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`mt-5 flex items-center justify-between gap-2`,children:[(0,$.jsxs)(Vo,{children:[`Shared memory`,typeof d==`number`?` · ${d} note${d===1?``:`s`}`:``]}),(0,$.jsx)(r,{to:`/`,search:t({panel:`team`,section:`memory`,note:void 0}),className:Fo,children:`Open`})]}),(0,$.jsx)(le,{label:`Search the Team's memory`,placeholder:`Search the notes`,value:o,onChange:s,className:`mb-2`}),u.error?(0,$.jsx)(`p`,{role:`alert`,className:`m-0 text-xs text-danger`,children:u.error}):u.data?u.data.rows.length===0?(0,$.jsx)(`p`,{className:`m-0 text-sm text-muted-foreground`,children:c?`No note matches.`:`No notes yet. Agents write here what the whole Team should remember.`}):(0,$.jsx)(Ho,{children:u.data.rows.map(e=>(0,$.jsxs)(r,{to:`/`,search:t({panel:`team`,section:`memory`,note:e.key}),className:`block px-3 py-2 hover:bg-accent/50`,children:[(0,$.jsx)(`span`,{className:`block truncate text-sm font-semibold text-foreground`,children:e.title}),(0,$.jsx)(`span`,{className:`block truncate font-mono text-xs text-muted-foreground`,children:e.key}),e.preview&&(0,$.jsx)(`span`,{className:`mt-0.5 line-clamp-2 break-words text-xs leading-snug text-mocha`,children:e.preview})]},e.key))}):(0,$.jsx)(`p`,{role:`status`,className:`m-0 text-xs text-muted-foreground`,children:`Loading…`})]})}function zo({tab:e}){let{agent:t,team:n,to:i}=z(),a=ye(n?.id),o=Re.filter(e=>e!==`changes`||a.repository!==!1),s=o.includes(e)?e:`team`,c=(0,G.useRef)(null);(0,G.useEffect)(()=>_(c.current,`[aria-selected="true"]`),[s]);let l={changes:a.changes,files:a.files};return(0,$.jsxs)(`aside`,{"aria-label":`About the work`,className:`flex h-full flex-col overflow-hidden rounded-[16px] border border-border bg-card shadow-baziu-sm`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-1 border-b border-border bg-muted/60 p-2`,children:[(0,$.jsx)(`div`,{ref:c,role:`tablist`,"aria-label":`Side panel`,className:`flex min-w-0 flex-1 items-center gap-1 overflow-x-auto [scrollbar-width:none]`,children:o.map(e=>{let t=e===s,n=l[e];return(0,$.jsxs)(r,{to:`/`,search:i({panel:e,section:void 0}),role:`tab`,"aria-selected":t,className:`inline-flex h-8 shrink-0 items-center gap-1.5 rounded-[10px] border px-2 text-sm font-semibold ${t?`border-border bg-card text-foreground shadow-baziu-sm`:`border-transparent text-mocha hover:bg-card/70 hover:text-foreground`}`,children:[nt[e],typeof n==`number`&&n>0&&(0,$.jsx)(`span`,{className:`rounded-full bg-frost px-1.5 font-mono text-xs font-medium text-chocolate`,children:n})]},e)})}),(0,$.jsx)(r,{to:`/`,search:i({panel:`none`,section:void 0}),"aria-label":`Close the side panel`,className:`flex size-8 shrink-0 items-center justify-center rounded-[10px] text-mocha hover:bg-card hover:text-foreground xl:hidden`,children:(0,$.jsx)(y,{className:`size-4`,"aria-hidden":`true`})})]}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto px-4 pb-5 pt-3.5`,children:s===`agent`?t?(0,$.jsx)(ro,{agent:t},t.agent.id):(0,$.jsx)(Bo,{children:`Open an Agent's conversation to see its settings here.`}):n?s===`team`?(0,$.jsx)(Io,{team:n},n.id):s===`connections`?(0,$.jsx)(ao,{team:n},n.id):s===`changes`?(0,$.jsx)(Uo,{team:n},n.id):(0,$.jsx)(Eo,{team:n},n.id):(0,$.jsx)(Bo,{children:`Pick an Agent or a Team on the left.`})})]})}function Bo({children:e}){return(0,$.jsx)(`p`,{className:`m-0 py-10 text-center text-sm text-muted-foreground`,children:e})}function Vo({children:e}){return(0,$.jsx)(`h2`,{className:`m-0 mb-1.5 mt-5 font-body text-xs font-bold uppercase tracking-[0.08em] text-muted-foreground first:mt-0`,children:e})}function Ho({children:e}){return(0,$.jsx)(`div`,{className:`divide-y divide-frost/70 overflow-hidden rounded-2xl border border-border`,children:e})}function Uo({team:e}){let{search:t,to:n}=z(),a=i(),o=Ba(e.id),s=Ha(e.id,o.base),c=s.data?.review?.changes??null,l=s.data?.review?.authors??{},u=c?.changes.find(e=>e.path===t.file)?.path??null,d=Ua(e.id,o.base,u,s.data),f=e=>void a.navigate({to:`/`,search:n({file:e}),replace:!0});return(0,$.jsxs)(`div`,{children:[(0,$.jsx)(wa,{changes:c,base:o.base,loading:s.loading,onBase:o.setBase,onRefresh:()=>void s.reload()}),s.error&&(0,$.jsx)(`p`,{role:`alert`,className:`err mt-3`,children:s.error}),s.data?.unavailable&&(0,$.jsx)(`p`,{role:`alert`,className:`m-0 mt-3 rounded-2xl border border-border bg-muted/50 px-3 py-3 text-sm`,children:wn(s.data.unavailable.code,s.data.unavailable.message)}),!s.data&&!s.error&&(0,$.jsx)(`p`,{role:`status`,className:`m-0 mt-3 text-sm text-muted-foreground`,children:`Loading the changes…`}),c&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`mt-3 flex items-center justify-between gap-2`,children:[(0,$.jsxs)(Vo,{children:[c.changes.length,` changed file`,c.changes.length===1?``:`s`]}),c.changes.length>0&&(0,$.jsxs)(r,{to:`/`,search:n({view:`changes`,file:u??c.changes[0]?.path}),className:`inline-flex h-7 items-center gap-1 rounded-[10px] border border-border bg-card px-2 text-xs font-semibold text-foreground hover:border-sapphire-light hover:text-sapphire`,children:[(0,$.jsx)(Yt,{className:`size-3.5`,"aria-hidden":`true`}),`Side by side`]})]}),(0,$.jsx)(Ya,{changes:c,authors:l,comments:o.comments,selected:u,onSelect:e=>f(e===u?void 0:e)})]}),u&&(0,$.jsxs)(`section`,{"aria-label":`Diff of ${u}`,className:`mt-4`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,$.jsx)(`h3`,{className:`m-0 min-w-0 flex-1 truncate font-mono text-xs font-medium text-foreground`,title:u,children:qa(u).name}),(0,$.jsx)(Wo,{onAdd:e=>o.addComment({path:u,note:e})})]}),(0,$.jsx)(`div`,{className:`mt-2 max-h-[55vh] overflow-auto rounded-2xl border border-border bg-card`,children:d.error?(0,$.jsx)(`p`,{role:`alert`,className:`m-0 p-3 text-sm text-danger`,children:d.error}):d.data?d.data.patch===null?(0,$.jsxs)(`p`,{className:`m-0 p-3 text-sm text-muted-foreground`,children:[`No diff text for this file`,d.data.omitted?` (${d.data.omitted.replaceAll(`_`,` `)})`:``,`.`]}):(0,$.jsx)(Fa,{patch:d.data.patch,comments:o.comments.filter(e=>e.path===u),onAddComment:(e,t)=>o.addComment({path:u,line:e,note:t}),onRemoveComment:o.removeComment}):(0,$.jsx)(`p`,{role:`status`,className:`m-0 p-3 text-sm text-muted-foreground`,children:`Loading the diff…`})}),d.data?.truncated&&(0,$.jsx)(`p`,{className:`m-0 mt-1.5 text-xs text-warning`,children:`This diff was cut: the file changed more.`})]}),c&&c.changes.length>0&&(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsx)(Qa,{teamId:e.id,session:o,authors:l,onOpenFile:e=>f(e)})})]})}function Wo({onAdd:e}){let[t,n]=(0,G.useState)(!1),[r,i]=(0,G.useState)(``);if(!t)return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>n(!0),className:`unstyled inline-flex h-7 shrink-0 items-center gap-1 rounded-[10px] border border-border bg-card px-2 text-xs font-semibold text-foreground hover:border-sapphire-light hover:text-sapphire`,children:[(0,$.jsx)(Qe,{className:`size-3.5`,"aria-hidden":`true`}),`Comment on the file`]});let a=()=>{e(r.trim()),i(``),n(!1)};return(0,$.jsxs)(`div`,{className:`basis-full rounded-[10px] border border-primary/30 bg-accent/40 p-2.5`,children:[(0,$.jsx)(`textarea`,{autoFocus:!0,"aria-label":`Comment on the file`,placeholder:`What should change in this file? (optional: the Agent gets the diff either way)`,rows:2,maxLength:2e3,value:r,onChange:e=>i(e.target.value),onKeyDown:e=>{e.key===`Escape`&&n(!1),e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&a()},className:`min-h-16 text-sm`}),(0,$.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:[(0,$.jsx)(g,{variant:`primary`,className:`min-h-8 px-3 py-1 text-xs`,onClick:a,children:`Add to the review`}),(0,$.jsx)(g,{variant:`ghost`,className:`min-h-8 px-3 py-1 text-xs`,onClick:()=>n(!1),children:`Cancel`})]})]})}var Go=`bz_diff_layout`;function Ko({team:e}){let{search:t,to:n,agentById:a}=z(),o=i(),s=Pt(),c=Ba(e.id),l=Ha(e.id,c.base),u=l.data?.review?.changes??null,d=l.data?.review?.authors??{},f=u?.changes.find(e=>e.path===t.file)??u?.changes[0]??null,p=f?.path??null,m=Ua(e.id,c.base,p,l.data),h=p?d[p]:void 0,[g,_]=(0,G.useState)(`split`);(0,G.useEffect)(()=>{try{window.localStorage.getItem(Go)===`unified`&&_(`unified`)}catch{}},[]);let v=e=>{_(e);try{window.localStorage.setItem(Go,e)}catch{}},y=e=>void o.navigate({to:`/`,search:n({file:e}),replace:!0}),b=Nt(`(min-width: 768px)`),x=f!==null&&[`added`,`deleted`,`untracked`].includes(f.status),S=g===`split`&&b&&!x?Ia:Fa,[C,w]=(0,G.useState)(!1);(0,G.useEffect)(()=>w(!1),[p]);let T=(f?.status===`added`||f?.status===`untracked`)&&/\.(md|markdown)$/i.test(f.path)&&m.data?.patch?bn(m.data.patch).lines.filter(e=>e.kind===`add`).map(e=>e.text).join(`
71
+ `):null;return(0,$.jsx)(ge,{view:`changes`,actions:b&&(0,$.jsx)(It,{label:`Diff layout`,value:g,options:[{id:`split`,label:`Side by side`},{id:`unified`,label:`One column`}],onChange:v}),children:(0,$.jsxs)(`div`,{className:`grid h-full min-h-0 grid-cols-1 lg:grid-cols-[21rem_minmax(0,1fr)]`,children:[(0,$.jsxs)(`div`,{className:`min-h-0 space-y-3 overflow-y-auto border-border p-3 max-lg:max-h-[42vh] max-lg:border-b lg:border-r`,children:[(0,$.jsx)(wa,{changes:u,base:c.base,loading:l.loading,onBase:c.setBase,onRefresh:()=>void l.reload()}),l.error&&(0,$.jsx)(`p`,{role:`alert`,className:`err`,children:l.error}),l.data?.unavailable&&(0,$.jsx)(`p`,{role:`alert`,className:`m-0 rounded-2xl border border-border bg-muted/50 px-3 py-3 text-sm`,children:wn(l.data.unavailable.code,l.data.unavailable.message)}),!l.data&&!l.error&&(0,$.jsx)(`p`,{role:`status`,className:`m-0 text-sm text-muted-foreground`,children:`Loading the changes…`}),u&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Ya,{changes:u,authors:d,comments:c.comments,selected:p,onSelect:y}),u.changes.length>0&&(0,$.jsx)(Qa,{teamId:e.id,session:c,authors:d,onOpenFile:y})]})]}),(0,$.jsx)(`div`,{className:`flex min-h-0 min-w-0 flex-col`,children:f&&p?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-2 border-b border-border px-3 py-2`,children:[(0,$.jsx)(Ka,{status:f.status}),(0,$.jsxs)(`h2`,{className:`m-0 min-w-0 flex-1 basis-48 break-all font-mono text-sm font-medium leading-snug text-foreground`,children:[f.previousPath?`${f.previousPath} → `:``,f.path]}),(0,$.jsx)(`span`,{className:`shrink-0 text-xs text-mocha`,children:Cn(f)}),h&&(0,$.jsxs)(r,{to:`/`,search:{agent:h.agentId,conversation:h.conversationId,panel:`changes`,file:p},title:`Open the conversation this was written in`,className:`inline-flex h-7 shrink-0 items-center gap-1.5 rounded-full border border-border bg-muted px-2 text-xs font-semibold text-mocha hover:border-sapphire-light hover:text-sapphire`,children:[(0,$.jsx)(H,{identity:a(h.agentId)?.identity,size:16}),h.agentName,s&&(0,$.jsx)(`span`,{className:`font-normal text-muted-foreground`,children:dt(h.at)})]}),T!==null&&(0,$.jsx)(It,{label:`Show the file as`,value:C?`preview`:`text`,options:[{id:`text`,label:`Text`},{id:`preview`,label:`Preview`}],onChange:e=>w(e===`preview`)}),(0,$.jsx)(Wo,{onAdd:e=>c.addComment({path:p,note:e})})]}),(0,$.jsxs)(`div`,{className:`min-h-0 flex-1 overflow-auto`,children:[m.error?(0,$.jsx)(`p`,{role:`alert`,className:`m-0 p-4 text-sm text-danger`,children:m.error}):m.data?m.data.patch===null?(0,$.jsxs)(`p`,{className:`m-0 p-4 text-sm text-muted-foreground`,children:[`No diff text for this file`,m.data.omitted?` (${m.data.omitted.replaceAll(`_`,` `)})`:``,`. A comment on the file still reaches the Agent.`]}):C&&T!==null?(0,$.jsx)(`div`,{className:`md-content mx-auto max-w-[50rem] px-5 py-4 leading-[1.6] text-chocolate`,dangerouslySetInnerHTML:{__html:xa(T,s)}}):(0,$.jsx)(S,{patch:m.data.patch,comments:c.comments.filter(e=>e.path===p),onAddComment:(e,t)=>c.addComment({path:p,line:e,note:t}),onRemoveComment:c.removeComment}):(0,$.jsx)(`p`,{role:`status`,className:`m-0 p-4 text-sm text-muted-foreground`,children:`Loading the diff…`}),m.data?.truncated&&(0,$.jsx)(`p`,{className:`m-0 border-t border-border px-4 py-2 text-xs text-warning`,children:`This diff was cut: the file changed more than a review shows.`})]})]}):(0,$.jsx)(`div`,{className:`flex min-h-40 flex-1 items-center justify-center px-6 text-center text-sm text-muted-foreground`,children:u?`Nothing changed since this base.`:l.data?.unavailable?`There is nothing to compare.`:``})})]})})}var qo=8e3,Jo=2500;function Yo(e,t,n=0){let r=t.toLowerCase().split(/\s+/).filter(Boolean);if(r.length===0)return null;let i=[];for(let t of e.querySelectorAll(`[data-message]`)){let e=(t.textContent??``).toLowerCase();r.every(t=>e.includes(t))&&i.push(t)}return i[Math.min(n,i.length-1)]??null}function Xo(e,t,n,r){let i=(0,G.useRef)(r);i.current=r,(0,G.useEffect)(()=>{let r=e.current;if(!t||!r)return;let a=!1,o=()=>{a=!0,c.disconnect(),window.clearTimeout(l),i.current()},s=()=>{if(a)return;let e=Yo(r,t,n);e&&(e.scrollIntoView({block:`center`}),e.classList.add(`found-message`),window.setTimeout(()=>e.classList.remove(`found-message`),Jo),o())},c=new MutationObserver(s);c.observe(r,{childList:!0,subtree:!0});let l=window.setTimeout(o,qo);return s(),()=>{a=!0,c.disconnect(),window.clearTimeout(l)}},[t,n])}var Zo=`[data-message]`,Qo=200,$o=new Map;function es(e,t){return`${e}:${t??``}`}function ts(e){return e.scrollHeight-e.scrollTop-e.clientHeight<40}function ns(e){if(ts(e))return{atEnd:!0};let t=e.getBoundingClientRect().top,n=e.querySelectorAll(Zo);for(let e=0;e<n.length;e++){let r=n[e]?.getBoundingClientRect();if(r&&r.bottom>t)return{atEnd:!1,index:e,offset:r.top-t}}return{atEnd:!0}}function rs(e,t){if(t.atEnd)return e.scrollTop=e.scrollHeight,!0;let n=e.querySelectorAll(Zo)[t.index];if(!n)return!1;let r=e.getBoundingClientRect().top;return e.scrollTop+=n.getBoundingClientRect().top-r-t.offset,!0}function is(e,t){if($o.delete(e),$o.set(e,t),$o.size>Qo){let e=$o.keys().next().value;e!==void 0&&$o.delete(e)}}function as(e){return $o.get(e)}function os(e,t,{ready:n,skip:r,onRestored:i}){let a=(0,G.useRef)(t);a.current=t;let o=(0,G.useRef)(!1);(0,G.useLayoutEffect)(()=>{let t=e.current;if(o.current||!n||!t||(o.current=!0,r))return;let s=as(a.current());s&&rs(t,s)&&!s.atEnd&&i?.()});let s=(0,G.useRef)(0),c=(0,G.useRef)(()=>{});(0,G.useEffect)(()=>{let t=e.current;if(!t)return;c.current=()=>{s.current=0,t.isConnected&&is(a.current(),ns(t))};let n=()=>{o.current&&(s.current||=window.requestAnimationFrame(()=>c.current()))};return t.addEventListener(`scroll`,n,{passive:!0}),()=>t.removeEventListener(`scroll`,n)},[]),(0,G.useLayoutEffect)(()=>()=>{s.current&&(window.cancelAnimationFrame(s.current),c.current())},[])}function ss({agentId:e,agentName:t,refreshKey:r}){let[i,a]=(0,G.useState)([]);return(0,G.useEffect)(()=>{let t=new AbortController;return n(`/api/agents/${encodeURIComponent(e)}/questions`,{signal:t.signal}).then(e=>a(e.questions)).catch(()=>{}),()=>t.abort()},[e,r,yt()?.byAgent.get(e)?.questions??0]),i.length?(0,$.jsx)(`section`,{"aria-label":`Agent questions`,className:`max-h-[45vh] min-w-0 shrink-0 space-y-3 overflow-y-auto border-t border-frost px-5 py-3`,children:i.map(e=>(0,$.jsx)(cs,{item:e,agentName:t},e.id))}):null}function cs({item:e,agentName:t}){let r=yt(),i=Pt(),[a,s]=(0,G.useState)(``),[c,u]=(0,G.useState)(!1),[d,f]=(0,G.useState)(null),[p,m]=(0,G.useState)(``);async function h(t,i){u(!0),m(``);try{await n(`/api/agents/${encodeURIComponent(e.agentId)}/questions/${encodeURIComponent(e.id)}/answer`,{body:{answer:t}}),f(i),r?.refresh()}catch(e){m(e instanceof o&&e.status===404?`This question is no longer open.`:l(e))}finally{u(!1)}}return d===null?(0,$.jsxs)(`article`,{className:`min-w-0 rounded-2xl border border-warning/35 bg-warning/[0.07] px-4 py-3.5`,children:[(0,$.jsxs)(`p`,{className:`m-0 flex items-center gap-2 text-xs font-bold uppercase tracking-[0.08em] text-warning`,children:[(0,$.jsx)(`span`,{className:`size-[7px] shrink-0 rounded-full bg-warning`,"aria-hidden":`true`}),t,` is waiting for you`]}),(0,$.jsx)(`p`,{className:`m-0 mt-1.5 break-words text-base font-semibold text-charcoal`,children:e.question.prompt}),(0,$.jsxs)(`fieldset`,{disabled:c,className:`m-0 mt-3 min-w-0 border-0 p-0`,children:[(0,$.jsx)(`legend`,{className:`sr-only`,children:`Answer this question`}),(0,$.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:e.question.choices.map((t,n)=>{let r=e.question.recommendedIndex===n;return(0,$.jsxs)(`button`,{type:`button`,onClick:()=>void h({kind:`choice`,index:n},t.label),className:`unstyled min-h-[3.25rem] min-w-0 flex-1 basis-56 rounded-[10px] bg-card px-3 py-2 text-left transition-colors hover:bg-accent/60 disabled:opacity-60 ${r?`border-[1.5px] border-primary`:`border border-border`}`,children:[(0,$.jsxs)(`span`,{className:`flex flex-wrap items-center gap-2 text-sm font-bold ${r?`text-accent-foreground`:`text-foreground`}`,children:[(0,$.jsx)(`span`,{className:`min-w-0 break-words [overflow-wrap:anywhere]`,children:t.label}),r&&(0,$.jsx)(`span`,{className:`rounded-full bg-accent px-1.5 text-xs font-semibold`,children:`Suggested`})]}),t.description&&(0,$.jsx)(`span`,{className:`mt-0.5 block break-words text-sm text-mocha`,children:t.description})]},t.label)})}),(0,$.jsxs)(`form`,{className:`mt-2.5 flex flex-wrap items-center gap-2`,onSubmit:e=>{e.preventDefault(),a.trim()&&h({kind:`text`,text:a},a.trim())},children:[(0,$.jsx)(`input`,{"aria-label":`Answer in your own words`,placeholder:`Or answer in your own words`,value:a,maxLength:4096,onChange:e=>s(e.target.value),className:`min-h-10 min-w-0 flex-1 basis-48 text-sm`}),a.trim()&&(0,$.jsx)(g,{variant:`primary`,type:`submit`,className:`min-h-10`,children:`Send answer`}),(0,$.jsx)(g,{variant:`ghost`,className:`min-h-10`,onClick:()=>void h({kind:`skip`},`Skipped`),children:`Skip`})]})]}),(0,$.jsxs)(`p`,{className:`m-0 mt-2 text-xs text-mocha`,children:[i?`Waiting until ${new Date(e.expiresAt).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`})}. `:``,`An answer is information only; it grants no permission.`]}),p&&(0,$.jsx)(`p`,{role:`alert`,className:`m-0 mt-2 text-sm text-danger`,children:p})]}):(0,$.jsxs)(`p`,{role:`status`,className:`m-0 flex flex-wrap items-center gap-2 rounded-[10px] border border-border bg-muted px-3 py-2 text-sm`,children:[(0,$.jsx)(`span`,{className:`text-mocha`,children:e.question.prompt}),(0,$.jsx)(`span`,{className:`font-semibold text-foreground`,children:d})]})}function ls(e,t){return{message:e,attachments:t,bashApprovalMode:`interactive`,questionMode:`web`}}function us(e){return`/api/shell-approvals?agentId=${encodeURIComponent(e)}`}var ds=e=>e.startsWith(`image/`);function fs(e,t){let n=t.filter(e=>ds(e.mimeType)),r=t.filter(e=>!ds(e.mimeType)).map(e=>({name:e.name??`file`}));return{type:`user`,content:e,...n.length>0?{images:n}:{},...r.length>0?{files:r}:{}}}function ps(e){let t=[],n=null,r=()=>(n||(n={type:`tool`,items:[]},t.push(n)),n);for(let i of e)if(i.role===`user`)n=null,t.push({type:`user`,content:i.content,...i.images?.length?{images:i.images}:{}});else if(i.role===`assistant`){i.content&&(n=null,t.push({type:`assistant`,content:i.content}));for(let e of i.toolCalls??[])r().items.push({kind:`call`,id:e.id,name:e.name,body:e.arguments});i.stopped&&(n=null,t.push({type:`stopped`,reason:i.stopped}))}else if(i.role===`tool`){r().items.push({kind:/^error:/i.test(i.content)?`error`:`result`,id:i.toolCallId??``,name:i.toolName??``,body:i.content});for(let e of i.results??[])t.push({type:`result`,resultId:e.resultId}),n=null;i.images?.length&&(t.push({type:`images`,images:i.images}),n=null)}return t}function ms(e){let t=[],n=new Map;for(let r of e){let e=n.get(r.id);if(r.kind===`call`){let e={id:r.id,name:r.name,args:r.body,status:`running`,output:``};t.push(e),n.set(r.id,e)}else e?(r.kind===`progress`||(e.status=r.kind===`error`?`failed`:`done`),e.output=r.body):r.kind!==`progress`&&t.push({id:r.id,name:r.name,args:``,status:r.kind===`error`?`failed`:`done`,output:r.body})}return t}function hs(e){let t=[],n=null;return e.forEach((e,r)=>{if(e.type===`tool`||e.type===`result`){n||(n={type:`work`,index:r,items:[],resultIds:[]},t.push(n)),e.type===`tool`?n.items.push(...e.items):n.resultIds.push(e.resultId);return}n=null,t.push({type:`entry`,index:r,entry:e})}),t}function gs(e,t){let n=e.findIndex(e=>e.type===`command_approval`&&e.approval.id===t.id);if(n===-1)return[...e,{type:`command_approval`,approval:t}];let r=[...e];return r[n]={type:`command_approval`,approval:t},r}function _s(e,t){let n={kind:`progress`,id:t.id,name:t.name,body:t.output};for(let r=e.length-1;r>=0;r--){let i=e[r];if(i?.type!==`tool`)continue;let a=i.items.findIndex(e=>e.id===t.id);if(a<0)continue;let o=[...i.items],s=o.findIndex(e=>e.kind===`progress`&&e.id===t.id);s>=0?o[s]=n:o.splice(a+1,0,n);let c=[...e];return c[r]={type:`tool`,items:o},c}return vs(e,n)}function vs(e,t){let n=e[e.length-1];return n?.type===`tool`?[...e.slice(0,-1),{type:`tool`,items:[...n.items,t]}]:[...e,{type:`tool`,items:[t]}]}function ys(e,t){let n=e[e.length-1];return n?.type===`assistant`?[...e.slice(0,-1),{type:`assistant`,content:t(n.content)}]:[...e,{type:`assistant`,content:t(``)}]}function bs(e,t){switch(t.type){case`assistant_delta`:return ys(e,e=>e+t.delta);case`assistant_message`:return ys(e,()=>t.text);case`command_approval`:return gs(e,t.approval);case`tool_progress`:return _s(e,t);case`tool_call`:return vs(e,{kind:`call`,id:t.id,name:t.name,body:t.arguments});case`tool_result`:case`tool_error`:{let n=vs(e.map(e=>e.type===`tool`?{...e,items:e.items.filter(e=>!(e.kind===`progress`&&e.id===t.id))}:e),t.type===`tool_result`?{kind:`result`,id:t.id,name:t.name,body:t.result}:{kind:`error`,id:t.id,name:t.name,body:t.error});return t.type===`tool_result`&&t.images?.length?[...n,{type:`images`,images:t.images}]:n}case`file`:return[...e,{type:`result`,resultId:t.result.resultId}];case`error`:return t.error===`cancelled`?[...e,{type:`stopped`,reason:`cancelled`}]:[...e,{type:`error`,content:`[error] ${t.error}`}];default:return e}}function xs(e){return e.map(e=>e.type===`command_approval`&&e.approval.status===`pending`?{type:`command_approval`,approval:{...e.approval,status:`cancelled`}}:e)}async function*Ss(e){let t=e.getReader(),n=new TextDecoder,r=``;for(;;){let{done:e,value:i}=await t.read();r+=e?n.decode():n.decode(i,{stream:!0});let a=r.split(`
72
+ `);r=e?``:a.pop()??``;for(let e of a)if(e.trim())try{yield JSON.parse(e)}catch{}if(e)return}}var Cs=200;function ws(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>{let n=String(r.result);t({name:e.name,data:n.slice(n.indexOf(`,`)+1),mimeType:e.type||`application/octet-stream`})},r.onerror=()=>n(r.error),r.readAsDataURL(e)})}function Ts(e){return Promise.all(Array.from(e).map(ws))}function Es({agentName:e,value:t,onChange:n,onSubmit:r,attachments:i,onAddFiles:a,onRemoveAttachment:o,editing:s,onCancelEdit:c,agentBusy:l,onStop:u,inputRef:d}){let f=(0,G.useRef)(null);return(0,G.useLayoutEffect)(()=>{let e=d.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,Cs)}px`)},[t,e]),(0,$.jsxs)($.Fragment,{children:[s&&(0,$.jsxs)(`div`,{className:`flex items-center gap-2 border-t border-frost bg-sapphire-glow px-5 py-2 text-[0.85em] text-sapphire-deep`,children:[(0,$.jsx)(`span`,{children:`Editing your last message: send to replace it.`}),(0,$.jsx)(`button`,{type:`button`,onClick:c,className:`ml-auto rounded-sm border border-sapphire-light bg-transparent px-2 py-0.5 text-[0.92em] text-sapphire-deep hover:bg-snow`,children:`Cancel`})]}),i.length>0&&(0,$.jsx)(`div`,{className:`flex max-h-24 shrink-0 flex-wrap gap-2 overflow-y-auto border-t border-frost bg-ivory px-5 pt-3`,children:i.map((e,t)=>ds(e.mimeType)?(0,$.jsxs)(`div`,{className:`relative`,children:[(0,$.jsx)(`img`,{src:`data:${e.mimeType};base64,${e.data}`,alt:`pending attachment`,className:`h-16 w-16 rounded-md border border-frost object-cover`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>o(t),className:`absolute -right-1.5 -top-1.5 flex h-5 w-5 items-center justify-center rounded-full border border-frost bg-snow text-[0.7em] text-mocha hover:border-sapphire hover:text-sapphire`,"aria-label":`remove attachment`,children:`✕`})]},t):(0,$.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded-md border border-frost bg-snow px-2 py-1 text-[0.82em] text-mocha`,children:[(0,$.jsx)(De,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`max-w-[160px] truncate`,children:e.name??`file`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>o(t),className:`text-[0.85em] text-mocha hover:text-sapphire`,"aria-label":`remove attachment`,children:`✕`})]},t))}),(0,$.jsxs)(`form`,{className:`grid shrink-0 grid-cols-[auto_minmax(0,1fr)] items-end gap-2 border-t border-frost bg-ivory px-3 py-3 sm:grid-cols-[auto_minmax(0,1fr)_auto] sm:px-5`,onSubmit:e=>{e.preventDefault(),r()},children:[(0,$.jsx)(`input`,{ref:f,type:`file`,multiple:!0,className:`hidden`,onChange:e=>{e.target.files&&a(e.target.files),e.target.value=``}}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>f.current?.click(),title:`attach images or files`,"aria-label":`attach files`,className:`flex h-11 items-center justify-center rounded-md border-[1.5px] border-frost bg-snow px-3 py-2 text-[1em] text-mocha transition-colors hover:border-sapphire hover:text-sapphire`,children:(0,$.jsx)(dn,{className:`size-[18px]`,"aria-hidden":`true`})}),(0,$.jsx)(`textarea`,{ref:d,"data-composer":`true`,rows:1,value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&!e.nativeEvent.isComposing&&(e.preventDefault(),r())},onPaste:e=>{let t=Array.from(e.clipboardData.files);t.some(e=>ds(e.type))&&(e.preventDefault(),a(t))},placeholder:`Message ${e}`,title:`Shift+Enter for a new line. Paste or attach files with the paperclip.`,autoComplete:`off`,"aria-label":`Message ${e}`,className:`max-h-[200px] min-h-11 min-w-0 flex-1 resize-none overflow-y-auto rounded-md border-[1.5px] border-frost bg-snow px-3 py-2 text-[0.93em] leading-[1.45] text-chocolate outline-none transition-colors focus:border-sapphire focus:shadow-[0_0_0_3px_var(--color-sapphire-glow)]`}),(0,$.jsxs)(`div`,{className:`col-span-2 flex flex-wrap justify-end gap-2 sm:col-span-1`,children:[(0,$.jsx)(g,{variant:`primary`,type:`submit`,className:`min-h-11 whitespace-normal text-center`,disabled:!t.trim()&&i.length===0,children:l?`Queue follow-up`:`Send`}),l&&(0,$.jsx)(g,{variant:`danger`,className:`min-h-11`,onClick:u,"aria-label":`Stop response`,children:`Stop`})]}),(0,$.jsx)(`p`,{className:`col-span-full m-0 hidden text-xs text-mocha-light sm:block`,children:`Enter sends · Shift+Enter adds a line · /help lists commands`})]})]})}function Ds({agentId:e,queue:t,onChanged:r,onViewConversation:i,conversationId:a}){let[o,s]=(0,G.useState)(null),[c,u]=(0,G.useState)(!1),[d,f]=(0,G.useState)(``);if(!t||t.items.length===0&&!t.paused)return null;let p=`/api/agents/${encodeURIComponent(e)}/queue`;async function m(e,t){u(!0),f(``);try{await n(`${p}${e}`,t),s(null)}catch(e){f(l(e))}finally{u(!1),r()}}let h=t.items.some(e=>e.status===`pending`);return(0,$.jsxs)(`section`,{"aria-label":`Follow-up queue`,className:`max-h-[35%] min-w-0 shrink-0 space-y-3 overflow-y-auto border-t border-frost px-5 py-3 text-sm`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,$.jsxs)(`strong`,{children:[`Follow-ups`,t.paused?` · paused`:``]}),(t.paused||h)&&(0,$.jsx)(g,{variant:`ghost`,disabled:c,onClick:()=>void m(`/control`,{body:{paused:!t.paused}}),children:t.paused?`Resume queue`:`Pause queue`})]}),d&&(0,$.jsx)(`p`,{role:`alert`,className:`m-0 break-words text-danger`,children:d}),t.items.map(e=>(0,$.jsxs)(`article`,{className:`flex min-w-0 flex-col gap-2 rounded-lg border border-frost bg-ivory p-3`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(`strong`,{className:`rounded-full bg-frost px-2 py-0.5 text-xs capitalize`,children:e.status}),(0,$.jsx)(`span`,{className:`text-xs text-mocha`,children:e.source===`telegram`?`Telegram`:`Web / API`}),e.conversationId!==a&&(0,$.jsx)(g,{variant:`ghost`,className:`ml-auto`,onClick:()=>i(e.conversationId),children:`View its conversation`})]}),o?.id===e.id?(0,$.jsxs)(`form`,{className:`flex min-w-0 flex-col gap-2`,onSubmit:t=>{t.preventDefault(),m(`/${encodeURIComponent(e.id)}`,{method:`PATCH`,body:{message:o.text}})},children:[(0,$.jsx)(`textarea`,{"aria-label":`Edit follow-up`,rows:3,className:`w-full resize-y`,value:o.text,onChange:t=>s({id:e.id,text:t.target.value})}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,$.jsx)(g,{variant:`primary`,type:`submit`,disabled:c,children:`Save`}),(0,$.jsx)(g,{variant:`ghost`,onClick:()=>s(null),children:`Cancel`})]})]}):(0,$.jsx)(`p`,{className:`m-0 whitespace-pre-wrap break-words [overflow-wrap:anywhere]`,children:e.text}),e.attachments.map((e,t)=>(0,$.jsxs)(`p`,{className:`m-0 break-all text-xs text-mocha`,children:[e.name??`Attachment`,` · `,e.byteLength,` bytes`]},t)),e.diagnostic&&(0,$.jsx)(`p`,{className:`m-0 break-words`,children:e.diagnostic}),e.status!==`running`&&o?.id!==e.id&&(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[e.status===`pending`&&(0,$.jsx)(g,{variant:`ghost`,disabled:c,onClick:()=>s({id:e.id,text:e.text}),children:`Edit`}),(0,$.jsx)(g,{variant:`danger`,disabled:c,onClick:()=>void m(`/${encodeURIComponent(e.id)}`,{method:`DELETE`}),children:`Remove`})]})]},e.id))]})}function Os(e){let t=e.split(`
73
+ `).find(e=>e.startsWith(`--- from `));if(!t)return`Teammate update received`;let n=/^--- from (.+?) \(message [0-9a-f-]+(?:, reply to [0-9a-f-]+)?\) ---$/.exec(t);if(!n)return`Teammate update received`;let r=n[1]?.replace(/ \([0-9a-f-]{36}\)$/,``).trim();return!r||/^[0-9a-f-]{36}$/.test(r)?`Teammate update received`:`Update from ${r.slice(0,100)}`}var ks={pending:`Waiting for a decision.`,allowed:`Allowed once — the command may run for this tool call only.`,denied:`Denied — the command was not run.`,auto_denied:`Automatically denied — no interactive approval path was available.`,expired:`Expired — the command was not run.`,cancelled:`Cancelled — the command was not run.`},As={pending:`Waiting for a decision.`,allowed:`Allowed once — for this call only.`,denied:`Denied — nothing was sent.`,auto_denied:`Denied — nobody could approve it in this turn, so nothing was sent.`,expired:`Expired — nothing was sent.`,cancelled:`Cancelled — nothing was sent.`};function js({approval:e,busy:t=!1,error:n,onDecision:r}){let i=e.status===`pending`;return(0,$.jsxs)(`section`,{className:`my-3 rounded-lg border border-danger/50 bg-danger/5 p-4 text-chocolate`,"aria-label":e.tool?`Approval before it goes out`:`Shell command approval`,children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-start justify-between gap-2`,children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`p`,{className:`m-0 text-[0.72em] font-semibold uppercase tracking-wider text-danger`,children:e.tool?`Before it goes out`:`Shell command approval`}),(0,$.jsx)(`h2`,{className:`m-0 mt-1 font-body text-[0.95em] font-semibold`,children:e.tool?i?`It wants to use ${e.tool}`:`Decision recorded`:i?`A risky command is waiting for you`:`Command decision recorded`})]}),(0,$.jsx)(`span`,{className:`rounded-full border border-danger/30 px-2 py-0.5 text-[0.75em] font-semibold uppercase tracking-wide text-danger`,children:e.status.replaceAll(`_`,` `)})]}),(0,$.jsx)(`pre`,{className:`mt-3 max-h-48 overflow-auto whitespace-pre-wrap break-words rounded-md border border-fawn bg-snow p-3 font-mono text-[0.82em] leading-[1.45] text-charcoal`,children:e.command}),(0,$.jsx)(`ul`,{className:`mt-3 space-y-1.5 pl-5 text-[0.84em] leading-[1.4] text-mocha`,children:e.risks.map(e=>(0,$.jsxs)(`li`,{children:[(0,$.jsx)(`span`,{className:`font-medium text-chocolate`,children:e.message}),` `,(0,$.jsx)(`code`,{className:`text-[0.9em]`,children:e.code})]},`${e.code}:${e.span.start}:${e.span.end}`))}),i?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`p`,{className:`mt-3 text-[0.78em] text-mocha-light`,children:[`This approval expires`,` `,(0,$.jsx)(`time`,{dateTime:new Date(e.expiresAt).toISOString(),children:new Date(e.expiresAt).toLocaleString()}),`. Deny blocks only this `,e.tool?`call`:`command`,`; Stop ends the whole turn.`]}),n&&(0,$.jsx)(`p`,{role:`alert`,className:`mt-2 rounded-md bg-danger/10 px-3 py-2 text-[0.82em] text-danger`,children:n}),r&&(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,$.jsx)(g,{variant:`primary`,disabled:t,onClick:()=>r(e,`deny`),children:`Deny`}),(0,$.jsx)(g,{variant:`danger`,disabled:t,onClick:()=>r(e,`allow`),children:`Allow once`})]})]}):(0,$.jsx)(`p`,{role:`status`,className:`mt-3 text-[0.84em] font-medium text-mocha`,children:e.tool?As[e.status]:ks[e.status]})]})}var Ms={terminal:_n,read:Kt,write:fn,search:S,web:$t,message:ke,file:De,image:tn,note:gn,question:Jt,tool:je},Ns=6,Ps=40,Fs=6e3,Is=`rounded-md bg-frost px-1.5 py-px font-mono text-[0.86em] text-chocolate [overflow-wrap:anywhere]`;function Ls({items:e,dimmed:t=!1}){let n=ms(e),r=n.filter(e=>e.name===`send_message`),i=n.filter(e=>e.name!==`send_message`),a=[...new Set(i.filter(e=>e.status===`done`&&(e.name===`write`||e.name===`edit`)).map(e=>xt(e.args)?.path).filter(e=>typeof e==`string`))];return(0,$.jsxs)(`div`,{className:t?`opacity-40`:void 0,children:[i.length>0&&(0,$.jsx)(zs,{steps:i}),r.length>0&&(0,$.jsx)(Gs,{steps:r}),a.length>0&&(0,$.jsx)(Ks,{paths:a})]})}function Rs(){let e=_e(),t=yt(),n=e?.agent?.agent.id,r=n!==void 0&&t?.stateOf(n).kind===`needs`;return e=>r&&e.status===`running`&&(e.name===`ask_user`||e.name===`bash`)}function zs({steps:e}){let t=Rs(),n=e.some(t),r=e.some(e=>e.status===`running`),i=e.some(e=>e.status===`failed`),[a,o]=(0,G.useState)(null),s=a??(r||i||e.length<=Ns),c=e.map(e=>st(e.name,xt(e.args)));return(0,$.jsxs)(`div`,{className:`my-3 overflow-hidden rounded-[10px] border border-border bg-muted text-sm`,children:[(0,$.jsxs)(`button`,{type:`button`,"aria-expanded":s,onClick:()=>o(!s),className:`unstyled flex min-h-9 w-full items-center gap-2 px-3 py-1.5 text-left text-mocha hover:bg-accent/50`,children:[(0,$.jsx)(Oe,{className:`size-[15px] shrink-0`,"aria-hidden":`true`}),(0,$.jsxs)(`span`,{className:`shrink-0 font-semibold text-foreground`,children:[e.length,` step`,e.length===1?``:`s`]}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1 truncate`,children:[ct(c.map(e=>e.kind)),n?` · waiting for you`:r?` · running`:``]}),(0,$.jsx)(`span`,{className:`shrink-0 text-xs font-semibold text-accent-foreground`,children:s?`Hide`:`Show`})]}),s&&(0,$.jsx)(`ul`,{className:`m-0 list-none p-0`,children:e.map((e,n)=>(0,$.jsx)(Bs,{step:e,waiting:t(e)},n))})]})}function Bs({step:e,waiting:t}){let[n,r]=(0,G.useState)(!1),i=xt(e.args),a=st(e.name,i),o=Ms[a.icon],s=e.status===`done`?mt(e.name,i):null,c=e.status===`running`;return(0,$.jsxs)(`li`,{className:`border-t border-frost/70`,children:[(0,$.jsxs)(`button`,{type:`button`,"aria-expanded":n,onClick:()=>r(!n),className:`unstyled flex min-h-8 w-full items-center gap-2.5 px-3 py-1 text-left hover:bg-accent/40`,children:[(0,$.jsx)(o,{className:`size-[15px] shrink-0 text-mocha`,"aria-hidden":`true`}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1 truncate text-foreground`,children:[a.verb,a.target&&(0,$.jsxs)($.Fragment,{children:[` `,(0,$.jsx)(`code`,{className:Is,children:a.target})]})]}),s&&s.added>0&&(0,$.jsxs)(`span`,{className:`shrink-0 font-mono text-xs font-medium text-success`,children:[`+`,s.added]}),s&&s.removed>0&&(0,$.jsxs)(`span`,{className:`shrink-0 font-mono text-xs font-medium text-danger`,children:[`−`,s.removed]}),c&&(t?(0,$.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1.5 text-xs text-warning`,children:[(0,$.jsx)(`span`,{className:`size-[7px] rounded-full bg-warning`,"aria-hidden":`true`}),`waiting for you`]}):(0,$.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1.5 text-xs text-success`,children:[(0,$.jsx)(`span`,{className:`size-[7px] animate-pulse rounded-full bg-success`,"aria-hidden":`true`}),`running`]})),e.status===`failed`&&(0,$.jsx)(`span`,{className:`shrink-0 text-xs font-semibold text-danger`,children:`failed`}),(0,$.jsx)(me,{className:`size-3.5 shrink-0 text-muted-foreground transition-transform ${n?`rotate-90`:``}`,"aria-hidden":`true`})]}),c&&e.output&&!n&&(0,$.jsx)(Ws,{output:e.output}),n&&(0,$.jsx)(Us,{step:e,args:i})]})}function Vs(e,t=Ps){let n=e.replace(/\n$/,``).split(`
74
+ `);return{lines:n.slice(0,t),more:Math.max(0,n.length-t)}}function Hs({text:e,sign:t}){let{lines:n,more:r}=Vs(e),i=t===`+`?`bg-success/15`:`bg-danger/15`;return(0,$.jsxs)($.Fragment,{children:[n.map((e,n)=>(0,$.jsxs)(`div`,{className:`whitespace-pre px-3 ${i}`,children:[t===`+`?`+`:`−`,e]},n)),r>0&&(0,$.jsxs)(`div`,{className:`px-3 text-mocha`,children:[` `,r,` more line`,r===1?``:`s`]})]})}function Us({step:e,args:t}){let n=e.output.length>Fs?`${e.output.slice(0,Fs)}\n…`:e.output,r=`overflow-x-auto border-t border-frost/70 bg-card font-mono text-xs leading-[1.55]`;if(e.status!==`failed`&&e.name===`write`&&typeof t?.content==`string`)return(0,$.jsx)(`div`,{className:r,children:(0,$.jsx)(Hs,{text:t.content,sign:`+`})});if(e.status!==`failed`&&e.name===`edit`&&Array.isArray(t?.edits))return(0,$.jsx)(`div`,{className:r,children:t.edits.map((e,t)=>(0,$.jsxs)(`div`,{className:t>0?`border-t border-frost/70`:void 0,children:[typeof e?.oldText==`string`&&(0,$.jsx)(Hs,{text:e.oldText,sign:`-`}),typeof e?.newText==`string`&&(0,$.jsx)(Hs,{text:e.newText,sign:`+`})]},t))});let i=e.name===`bash`&&typeof t?.command==`string`?t.command:t?JSON.stringify(t,null,2):e.args;return(0,$.jsxs)(`div`,{className:`${r} max-h-72 overflow-y-auto`,children:[i&&(0,$.jsx)(`pre`,{className:`m-0 whitespace-pre-wrap break-words px-3 py-1.5 text-mocha`,children:i}),n&&(0,$.jsx)(`pre`,{className:`m-0 whitespace-pre-wrap break-words border-t border-frost/70 px-3 py-1.5 ${e.status===`failed`?`text-danger`:`text-chocolate`}`,children:n})]})}function Ws({output:e}){let t=(0,G.useRef)(null);return(0,G.useLayoutEffect)(()=>{t.current&&(t.current.scrollTop=t.current.scrollHeight)},[e]),(0,$.jsx)(`pre`,{ref:t,className:`m-0 max-h-48 overflow-auto whitespace-pre-wrap break-words border-t border-frost/70 bg-card px-3 py-1.5 font-mono text-xs text-mocha`,children:e})}function Gs({steps:e}){let t=_e(),n=yt();return(0,$.jsxs)(`div`,{className:`my-3 overflow-hidden rounded-[10px] border border-border bg-muted text-sm`,children:[(0,$.jsxs)(`div`,{className:`flex min-h-9 items-center gap-2 px-3 py-1.5 text-mocha`,children:[(0,$.jsx)(Ut,{className:`size-[15px] shrink-0`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`font-semibold text-foreground`,children:e.length===1?`Handed off to a teammate`:`Handed off to ${e.length} teammates`}),t?.team&&(0,$.jsx)(r,{to:`/`,search:t.to({panel:`connections`}),className:`ml-auto text-xs font-semibold`,children:`See connections`})]}),e.map((e,i)=>{let a=xt(e.args),o=typeof a?.to==`string`?a.to:``,s=t?.agentById(o),c=typeof a?.text==`string`?a.text:``,l=s?n?.stateOf(s.id):void 0;return(0,$.jsxs)(`div`,{className:`relative border-t border-frost/70`,children:[(0,$.jsxs)(`details`,{className:`group`,children:[(0,$.jsxs)(`summary`,{className:`flex min-h-11 cursor-pointer list-none items-center gap-2.5 py-1.5 pl-3 [&::-webkit-details-marker]:hidden ${t&&s?`pr-[4.5rem]`:`pr-3`}`,children:[(0,$.jsx)(H,{identity:s?.identity,size:24}),(0,$.jsx)(`span`,{className:`shrink-0 font-semibold text-foreground`,children:s?.name??(o?o.slice(0,8):`Teammate`)}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-mocha group-open:invisible`,children:c}),e.status===`failed`?(0,$.jsx)(`span`,{className:`shrink-0 text-xs font-semibold text-danger`,children:`not sent`}):e.status===`running`?(0,$.jsx)(`span`,{className:`shrink-0 text-xs text-mocha`,children:`sending…`}):l&&(0,$.jsx)(`span`,{className:`shrink-0 text-xs text-mocha`,children:l.text})]}),(0,$.jsx)(`p`,{className:`m-0 whitespace-pre-wrap break-words px-3 pb-2.5 pl-[3.1rem] text-chocolate`,children:c}),e.status===`failed`&&(0,$.jsx)(`p`,{className:`m-0 break-words px-3 pb-2.5 pl-[3.1rem] text-xs text-danger`,children:e.output})]}),t&&s&&(0,$.jsxs)(r,{to:`/`,search:{agent:s.id,...t.search.panel?{panel:t.search.panel}:{}},className:`absolute right-3 top-2 flex h-7 items-center rounded-[10px] border border-border bg-card px-2.5 text-xs font-semibold text-foreground hover:border-sapphire-light hover:text-sapphire`,children:[`Open`,(0,$.jsxs)(`span`,{className:`sr-only`,children:[` `,s.name]})]})]},i)})]})}function Ks({paths:e}){let t=_e(),n=`${e.length} file${e.length===1?``:`s`} written`,i=e.map(e=>e.split(`/`).pop()??e).join(`, `),a=(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Se,{className:`size-4 shrink-0 text-primary`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`shrink-0 font-semibold text-foreground`,children:n}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs text-mocha`,children:i})]}),o=`my-3 flex min-h-11 w-full items-center gap-2.5 rounded-[10px] border border-border bg-card px-3 py-2 text-sm`;return t?.team?(0,$.jsxs)(r,{to:`/`,search:t.to({panel:`changes`,file:e[0]}),className:`${o} text-foreground hover:border-sapphire-light`,children:[a,(0,$.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1.5 font-semibold text-accent-foreground`,children:[`Review changes`,(0,$.jsx)(R,{className:`size-3.5`,"aria-hidden":`true`})]})]}):(0,$.jsx)(`div`,{className:o,children:a})}var qs=`[[bazilion:inbox-wake]]
75
+ `,Js=`[conversation summary]`,Ys=()=>()=>{};function Xs(){return(0,G.useSyncExternalStore)(Ys,()=>!0,()=>!1)}function Zs({entry:e,markdownReady:t,onEdit:n,dropped:r=!1,approvals:i}){let a=r?`opacity-40 [&_.bubble-content]:line-through`:``;switch(e.type){case`user`:if(e.content.startsWith(qs)){let t=e.content.slice(24);return(0,$.jsxs)(`details`,{"data-message":``,className:`my-3 rounded-lg border border-fawn bg-ivory px-3 py-2 text-sm text-mocha ${a}`,"aria-label":`Teammate update`,children:[(0,$.jsx)(`summary`,{className:`cursor-pointer font-medium`,children:Os(t)}),(0,$.jsx)(`p`,{className:`mt-2 text-xs`,children:`Original message and Agent instructions`}),(0,$.jsx)(`pre`,{className:`mt-1 max-h-64 overflow-auto whitespace-pre-wrap break-words text-xs`,children:t})]})}return(0,$.jsxs)(`div`,{"data-message":``,className:`group relative my-4 flex flex-col items-end ${a}`,children:[(0,$.jsx)(`span`,{className:`sr-only`,children:`you`}),e.images&&e.images.length>0&&(0,$.jsx)(`div`,{className:`mb-1 flex max-w-[85%] flex-wrap justify-end gap-1`,children:e.images.map((e,t)=>(0,$.jsx)(`img`,{src:`data:${e.mimeType};base64,${e.data}`,alt:`attachment`,className:`max-h-48 rounded-lg border border-sapphire-light`},t))}),e.files&&e.files.length>0&&(0,$.jsx)(`div`,{className:`mb-1 flex max-w-[85%] flex-wrap justify-end gap-1`,children:e.files.map((e,t)=>(0,$.jsxs)(`span`,{className:`flex items-center gap-1 rounded-md border border-sapphire-light bg-sapphire-glow px-2 py-1 text-[0.8em] text-chocolate`,children:[(0,$.jsx)(De,{className:`size-3.5 shrink-0`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`max-w-[180px] truncate`,children:e.name})]},t))}),e.content&&(0,$.jsx)(tc,{content:e.content}),n&&(0,$.jsx)(`button`,{type:`button`,onClick:n,title:`Edit and resend: replaces the last turn`,className:`mt-1 rounded-md px-2 py-0.5 text-xs font-semibold text-mocha opacity-0 transition hover:bg-sapphire-glow hover:text-sapphire focus-visible:opacity-100 group-hover:opacity-100 group-focus-within:opacity-100 [@media(hover:none)]:opacity-100`,children:`Edit`})]});case`assistant`:if(e.content.startsWith(Js)){let n=e.content.slice(22).trim();return(0,$.jsx)(`div`,{className:`my-3 border-y border-dashed border-frost py-2 text-[0.85em] italic text-mocha-light ${a}`,children:(0,$.jsxs)(`details`,{children:[(0,$.jsx)(`summary`,{className:`cursor-pointer select-none text-center [&::-webkit-details-marker]:hidden`,children:`— conversation summary (click to expand) —`}),(0,$.jsx)(`div`,{className:`md-content mt-2 rounded-sm bg-frost/40 p-2 not-italic`,dangerouslySetInnerHTML:{__html:xa(n,t)}})]})})}return(0,$.jsxs)(`div`,{"data-message":``,className:`my-4 flex flex-col items-start ${a}`,children:[(0,$.jsx)(`span`,{className:`sr-only`,children:`agent`}),(0,$.jsx)(`div`,{className:`md-content bubble-content w-full leading-[1.55] text-chocolate`,dangerouslySetInnerHTML:{__html:xa(e.content,t)}})]});case`images`:return(0,$.jsx)(`div`,{className:`my-2 space-y-2 ${a}`,children:e.images.map((e,t)=>(0,$.jsx)(`img`,{src:`data:${e.mimeType};base64,${e.data}`,alt:`screenshot`,className:`block max-w-full rounded-lg border border-fawn`},t))});case`command_approval`:return(0,$.jsx)(js,{approval:e.approval,busy:i?.busy[e.approval.id]??!1,error:i?.errors[e.approval.id],onDecision:i?.decide});case`system`:return(0,$.jsxs)(`div`,{className:`my-3 rounded-r-sm border-l-[3px] border-sapphire bg-sapphire-glow px-3 py-1 font-mono text-[0.88em] text-sapphire-deep`,children:[(0,$.jsx)(`span`,{className:`mr-2 font-semibold uppercase tracking-wider opacity-80`,children:`system`}),(0,$.jsx)(`span`,{className:`whitespace-pre-wrap`,children:e.content})]});case`stopped`:return(0,$.jsx)(`p`,{className:`my-2 px-1 text-[0.85em] italic text-muted-foreground`,children:e.reason===`cancelled`?`Stopped.`:`This reply failed.`});case`error`:return(0,$.jsx)(`div`,{className:`my-3 rounded-r-sm border-l-[3px] border-danger bg-danger/10 px-3 py-1 text-[0.92em] text-danger`,children:e.content})}}var Qs=14,$s=1400,ec=8;function tc({content:e}){let[t,n]=(0,G.useState)(!1),r=e.split(`
76
+ `),i=r.length>Qs||e.length>$s;return(0,$.jsxs)(`div`,{className:`bubble-content max-w-[85%] rounded-[14px_14px_4px_14px] border border-sapphire-light bg-sapphire-glow px-3 py-2 text-chocolate`,children:[(0,$.jsxs)(`div`,{className:`whitespace-pre-wrap break-words`,children:[!i||t?e:r.slice(0,ec).join(`
77
+ `).slice(0,$s/2),i&&!t?`…`:``]}),i&&(0,$.jsx)(`button`,{type:`button`,"aria-expanded":t,onClick:()=>n(!t),className:`unstyled mt-1.5 text-[0.82em] font-semibold text-sapphire-deep hover:underline`,children:t?`Show less`:`Show the whole message (${r.length} lines)`})]})}function nc({block:e,dropped:t}){let n=_e();return(0,$.jsxs)($.Fragment,{children:[e.items.length>0&&(0,$.jsx)(Ls,{items:e.items,dimmed:t}),e.resultIds.length>0&&(0,$.jsx)(`div`,{className:`my-3 grid grid-cols-[repeat(auto-fit,minmax(min(15rem,100%),1fr))] gap-3 ${t?`opacity-40`:``}`,children:e.resultIds.map(e=>(0,$.jsx)(bo,{resultId:e,...n?.team?{open:n.to({view:`files`,result:e})}:{}},e))})]})}function rc({entries:e,notes:t=[],markdownReady:n,editableEntry:r=-1,replacedFrom:i=-1,onEdit:a,approvals:o}){let s=[],c=0,l=e=>{for(;c<t.length&&(t[c]?.afterIndex??0)<=e;){let e=t[c];s.push((0,$.jsx)(Zs,{entry:{type:`system`,content:e.content},markdownReady:n},`note-${e.id}`)),c++}};for(let t of hs(e)){l(t.index);let e=i>=0&&t.index>=i;s.push(t.type===`work`?(0,$.jsx)(nc,{block:t,dropped:e},t.index):(0,$.jsx)(Zs,{entry:t.entry,markdownReady:n,dropped:e,onEdit:t.index===r?a:void 0,approvals:o},t.index))}return l(1/0),(0,$.jsx)($.Fragment,{children:s})}function ic({messages:e}){let t=Xs();return(0,$.jsx)(`section`,{"aria-label":`Conversation history`,children:(0,$.jsx)(rc,{entries:ps(e),markdownReady:t})})}var ac=[`slash commands:`,` /context — context breakdown (system prompt, tools, skills, history)`,` /compact [N] — summarize the head; keep the last N messages verbatim (default 10)`,` /new — open the list of conversations to start a new one`,` /help — show this list`].join(`
78
+ `);function oc(e){let t=e.trim();if(!t.startsWith(`/`))return null;let[n=``,...r]=t.split(/\s+/);return{command:n.toLowerCase(),rest:r.join(` `)}}function sc(e){let t=Number(e.trim());return e.trim()&&Number.isFinite(t)&&t>=0?Math.floor(t):void 0}function cc(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KiB`:`${(e/(1024*1024)).toFixed(2)} MiB`}function lc(e){let t=(e,t)=>`${e.toLocaleString()} chars (~${t.toLocaleString()} tok)`,n=[`context for ${e.agentId}`,`model: ${e.model}`,``,`system prompt: ${t(e.systemPrompt.chars,e.systemPrompt.tokens)}`,...e.systemPrompt.files.map(e=>` - ${e.name}: ${e.chars.toLocaleString()} chars`),``,`tools: ${e.tools.count} (${e.tools.schemaChars.toLocaleString()} chars of schema)`,...e.tools.entries.slice(0,5).map(e=>` - ${e.name}: ${e.schemaChars.toLocaleString()} chars`)];if(e.skills.count>0){n.push(``,`skills: ${e.skills.count}`);for(let t of e.skills.entries.slice(0,10))n.push(` - ${t.name}: ${t.blockChars.toLocaleString()} chars`)}return n.push(``,`history: ${e.history.messageEntries} messages / ${e.history.compactionEntries} compactions`,` ${t(e.history.chars,e.history.tokensEstimate)}`,` bytes on disk: ${cc(e.history.bytes)}`,``,`TOTAL: ${t(e.totals.chars,e.totals.tokens)}`),n.join(`
79
+ `)}function uc(e){return`/compact: ${e.before} → ${e.after} entries (${e.summarized} summarized, ${e.keptTail} kept verbatim; ~${e.tokensBefore.toLocaleString()} → ~${e.tokensAfter.toLocaleString()} tok). reloading…`}async function dc(e,t){if(t.messageCount<2){t.pushNote(`/compact: need ≥2 messages to compact`);return}t.setCompacting(!0);try{let r=await n(`${t.base}/chat/compact`,{body:{keepTail:sc(e)}});t.pushNote(uc(r)),setTimeout(()=>window.location.reload(),400)}catch(e){t.pushNote(`/compact failed: ${l(e)}`)}finally{t.setCompacting(!1)}}async function fc(e,t,r){switch(e){case`/help`:return r.pushNote(ac),!0;case`/context`:try{r.pushNote(lc(await n(`${r.base}/chat/context`)))}catch(e){r.pushNote(`/context failed: ${l(e)}`)}return!0;case`/new`:return r.onOpenLibrary(),!0;case`/compact`:return await dc(t,r),!0;default:return!1}}function pc({agentId:e,setLive:t}){let[r,i]=(0,G.useState)(!1),[a,o]=(0,G.useState)({}),[s,c]=(0,G.useState)({}),u=(0,G.useRef)(!1);(0,G.useEffect)(()=>{let r=new AbortController;return n(us(e),{signal:r.signal}).then(({approvals:n})=>{let r=n.filter(t=>t.agentId===e&&t.status===`pending`);r.length!==0&&(u.current=!0,t(e=>r.reduce(gs,e)),i(!0))}).catch(()=>{}),()=>r.abort()},[e,t]);async function d(r){try{let{approvals:i}=await n(us(e)),a=i.find(t=>t.id===r&&t.agentId===e);return a&&t(e=>gs(e,a)),a??null}catch{return null}}async function f(r,i){if(!(r.agentId!==e||r.status!==`pending`)){o(e=>({...e,[r.id]:!0})),c(({[r.id]:e,...t})=>t);try{let a=await n(`/api/shell-approvals/${encodeURIComponent(r.id)}`,{body:{decision:i}});a.approval.agentId===e&&t(e=>gs(e,a.approval))}catch(e){let t=await d(r.id);(!t||t.status===`pending`)&&c(t=>({...t,[r.id]:l(e)}))}finally{o(e=>({...e,[r.id]:!1}))}}}return{recoveredTurn:r,setRecoveredTurn:i,approvalTurnRef:u,approvalBusy:a,approvalErrors:s,decide:f,resetApprovals:()=>{o({}),c({})}}}var mc={file:null,size:0,conversationId:null};function hc(e){return e?.items.filter(e=>e.status===`pending`||e.status===`running`).length??0}function gc(e){return e?.turnActive||e?.items.some(t=>t.status===`running`||t.status===`pending`&&!e.paused)}function _c(e,t){return!!e.unavailable!=!!t.unavailable||e.file!==t.file||e.size!==t.size}function vc(e,t){return e?t.working!==e.working||t.queuePaused!==e.queuePaused||t.followUps!==e.followUps?e.working&&!t.working?`queue-then-head`:`queue`:!t.working&&t.lastActivityAt!==e.lastActivityAt?`head`:null:`head`}var yc=1e4,bc=5e3;function xc({agentId:e,base:t,initialSessionHead:r,onConversation:i,streamingRef:a,pushNote:o,onHistory:s}){let[u,d]=(0,G.useState)(!1),[f,p]=(0,G.useState)(r?.unavailable??!1),[m,h]=(0,G.useState)(null),g=(0,G.useRef)(r??mc),_=(0,G.useRef)(null),v=(0,G.useRef)(u);v.current=u;let y=(0,G.useRef)(null),b=c(),x=gc(m);function S(e){e.conversationId!==g.current.conversationId&&i?.(e.conversationId),g.current=e}async function C(){if(!a.current)try{let e=await n(`${t}/sessions/messages`);p(e.head.unavailable??!1),s(e.messages),S(e.head),d(!1)}catch{o(`Conversation history is unavailable. Your draft is preserved.`)}}async function w(){try{let e=await n(`${t}/sessions/head`),r=g.current.conversationId;if(r&&r!==e.conversationId){d(!0);return}p(e.unavailable??!1),S(e)}catch{}}async function T(){try{let e=await n(`${t}/queue`),r=hc(e)<hc(_.current)&&!a.current;return r&&C(),_.current=e,h(e),r}catch{return!1}}async function E(){if(!(!r||v.current||a.current))try{_c(await n(`${t}/sessions/head`),g.current)&&(d(!0),T())}catch{}}async function D(e){try{return await n(`${t}/queue`,{body:{message:e.text,attachments:e.attachments}}),T(),null}catch(t){return o(`The follow-up was not queued: ${l(t)}. Your draft is kept.`),e}}return(0,G.useEffect)(()=>{T()},[]),(0,G.useEffect)(()=>b.subscribe(`activity`,t=>{let n=t.agents.find(t=>t.agentId===e)??null,r=y.current;if(y.current=n,!n||a.current)return;let i=vc(r,n);i===`head`?E():i!==null&&T().then(e=>{i===`queue-then-head`&&!e&&E()})}),[b.subscribe,e]),(0,G.useEffect)(()=>{if(!x||b.connected)return;let e=setInterval(()=>{document.hidden||T()},bc);return()=>clearInterval(e)},[x,b.connected]),(0,G.useEffect)(()=>{if(!r||u||b.connected)return;let e=setInterval(()=>{document.hidden||E()},yc);return()=>clearInterval(e)},[t,r,u,b.connected]),{stale:u,dismissStale:()=>d(!1),historyUnavailable:f,queue:m,knownConversationId:()=>g.current.conversationId,refreshHistory:C,refreshKnownHead:w,refreshQueue:T,enqueue:D}}function Sc({agentId:e,initialMessages:t,initialSessionHead:r,onOpenLibrary:i,onConversation:a}){let c=`/api/agents/${encodeURIComponent(e)}`,[u,d]=(0,G.useState)(t),[f,p]=(0,G.useState)([]),[m,h]=(0,G.useState)([]),[g,_]=(0,G.useState)(!1),[v,y]=(0,G.useState)(!1),[b,x]=(0,G.useState)(!1),[S,C]=(0,G.useState)(0),w=(0,G.useRef)(null),T=(0,G.useRef)(0),E=(0,G.useRef)(0),D=(0,G.useRef)(!1);D.current=v;function O(e){let t={id:T.current++,content:e,afterIndex:E.current};h(e=>[...e,t])}(0,G.useEffect)(()=>()=>w.current?.abort(),[]);let k=xc({agentId:e,base:c,initialSessionHead:r,onConversation:a,streamingRef:D,pushNote:O,onHistory:e=>{d(e),p([]),x(!1)}}),{recoveredTurn:A,setRecoveredTurn:j,approvalTurnRef:ee,approvalBusy:M,approvalErrors:te,decide:N,resetApprovals:P}=pc({agentId:e,setLive:p}),ne=v||A,re=ne||!!k.queue?.turnActive;function ie(){return u.findLastIndex(e=>e.role===`user`)}function ae(t){if(t.kind===`fatal`){ee.current=!1,p(e=>[...xs(e),{type:`error`,content:`[fatal] ${t.error}`}]),j(!1);return}if(t.kind===`done`){ee.current=!1,d(t.messages),p([]),j(!1),P();return}let n=t.event;if(n.type===`command_approval`){if(n.approval.agentId!==e)return;ee.current=!0,_(n.approval.status!==`pending`&&n.approval.status!==`cancelled`)}else n.type===`agent_question`?C(e=>e+1):n.type===`assistant_delta`||n.type===`assistant_message`||n.type===`tool_call`?_(!1):(n.type===`tool_result`||n.type===`tool_error`)&&_(!0);p(e=>bs(e,n))}async function oe(e){let t=oc(e.text);if(t&&await fc(t.command,t.rest,{base:c,messageCount:u.length,pushNote:O,onOpenLibrary:i,setCompacting:e=>{e&&x(!1),y(e),_(e)}}))return e.attachments.length>0?{text:``,attachments:e.attachments}:null;if(ne)return b?(O(`Wait for the current turn to finish before replacing the last message.`),e):k.enqueue(e);if(b){let t=ie();try{await n(`${c}/chat/truncate`,{body:{keepCount:t,conversationId:k.knownConversationId()??void 0}})}catch(t){return O(`Could not replace the last turn: ${l(t)}`),e}d(e=>e.slice(0,t)),x(!1)}p([fs(e.text,e.attachments)]),j(!1),P(),ee.current=!1;let r=new AbortController;w.current=r,y(!0),_(!0);let a=!1,f=null;try{let t=await s(`${c}/chat`,{body:ls(e.text,e.attachments),signal:r.signal});if(!t.body)throw Error(`the chat response has no body`);for await(let e of Ss(t.body))e.kind!==`event`&&(a=!0),ae(e);await k.refreshKnownHead()}catch(t){t instanceof o?t.code===`agent_turn_active`?(p([]),f=await k.enqueue(e)):(p([{type:`error`,content:`[error] ${t.message}`}]),f=e):t.name!==`AbortError`&&p(e=>[...e,{type:`error`,content:`[network error] ${l(t)}`}])}finally{w.current===r&&(!a&&ee.current&&j(!0),_(!1),y(!1),w.current=null,k.refreshQueue(),C(e=>e+1))}return f}async function se(){try{(await n(`${c}/cancel`,{method:`POST`})).queuePaused&&O(`The follow-ups waiting behind this turn are paused too. Resume them under Follow-ups when you are ready.`)}catch(e){e instanceof o&&e.status===409||O(`Stop was not confirmed; the response may still be running.`)}k.refreshQueue()}function ce(){if(f.length>0||ne)return null;let e=ie();return e<0?null:(x(!0),u[e]?.content??null)}let le=ps(u),F=[...le,...f];E.current=F.length;let I=le.findLastIndex(e=>e.type===`user`);return{entries:F,notes:m,replacedFrom:b?I:-1,editableEntry:!b&&f.length===0&&!ne?I:-1,thinking:g,turnBusy:ne,agentBusy:re,editing:b,stale:k.stale,recoveredTurn:A,historyUnavailable:k.historyUnavailable,queue:k.queue,questionsKey:S,approvals:{busy:M,errors:te,decide:N},send:oe,stop:se,startEdit:ce,cancelEdit:()=>x(!1),refreshHistory:k.refreshHistory,refreshQueue:k.refreshQueue,dismissStale:k.dismissStale,conversationId:k.knownConversationId}}var Cc=new Map,wc=`relative flex h-full flex-col overflow-hidden rounded-[16px] border border-frost bg-snow shadow-baziu-sm`;function Tc(e){return(0,$.jsx)(Ec,{...e},e.agentId)}function Ec({agentId:e,agentName:t,initialMessages:n,initialSessionHead:r,header:i,onViewConversation:a,onConversationChange:o}){let s=Xs(),c=yt(),[l,u]=(0,G.useState)(!1),d=Sc({agentId:e,initialMessages:n,initialSessionHead:r,onOpenLibrary:()=>u(!0),onConversation:o}),[f,p]=(0,G.useState)(()=>Cc.get(e)??``),h=(0,G.useRef)(``),g=(0,G.useRef)(!1);(0,G.useEffect)(()=>{d.editing||(g.current=!1)},[d.editing]);let _=t=>p(n=>{let r=typeof t==`function`?t(n):t,i=g.current?h.current:r;return i?Cc.set(e,i):Cc.delete(e),r}),[v,y]=(0,G.useState)([]),[b,x]=(0,G.useState)(!1),S=(0,G.useRef)(null),C=(0,G.useRef)(null),w=(0,G.useRef)(!0),T=_e(),E=m();Xo(C,T?.search.find,T?.search.match,()=>{w.current=!1,T&&E({to:`/`,search:T.to({find:void 0,match:void 0}),replace:!0})}),os(C,()=>es(e,d.conversationId()),{ready:!0,skip:!!T?.search.find,onRestored:()=>{w.current=!1}}),(0,G.useLayoutEffect)(()=>{let e=C.current;e&&w.current&&(e.scrollTop=e.scrollHeight)});async function D(e){let t=await Ts(e);y(e=>[...e,...t].slice(0,16))}async function O(){let e={text:f,attachments:v};if(!e.text.trim()&&e.attachments.length===0)return;let t=g.current?h.current:``;g.current=!1,h.current=``,_(t),y([]);let n=await d.send(e);c?.refresh(),n&&(_(e=>e&&e!==t?e:n.text),y(e=>e.length>0?e:n.attachments))}function k(){let e=d.startEdit();e!==null&&(h.current=f,g.current=!0,_(e),S.current?.focus())}let A=!d.historyUnavailable&&d.entries.length===0&&d.notes.length===0,j=d.agentBusy&&!d.turnBusy,ee=c?.stateOf(e),M=ee?.kind===`working`?ee.text.replace(/^Working:?\s*/,``):``,te=ee?.kind===`needs`;return(0,$.jsxs)(`section`,{"aria-label":`Chat with ${t}`,className:wc,onDragOver:e=>{Array.from(e.dataTransfer.types).includes(`Files`)&&(e.preventDefault(),x(!0))},onDragLeave:e=>{e.currentTarget===e.target&&x(!1)},onDrop:e=>{e.dataTransfer.files.length!==0&&(e.preventDefault(),x(!1),D(e.dataTransfer.files))},children:[b&&(0,$.jsx)(`div`,{className:`pointer-events-none absolute inset-0 z-10 flex items-center justify-center rounded-[16px] border-2 border-dashed border-sapphire bg-sapphire-glow/80 text-[0.95em] font-medium text-sapphire-deep`,children:`drop images or files to attach`}),i?i({agentBusy:d.agentBusy,reload:d.refreshHistory,conversationsOpen:l,setConversationsOpen:u}):(0,$.jsx)(`div`,{className:`border-b border-frost px-4 py-2.5`,children:(0,$.jsx)(`h1`,{className:`m-0 truncate font-display text-xl text-charcoal`,children:t})}),d.historyUnavailable&&(0,$.jsx)(`p`,{role:`alert`,className:`mx-5 mt-2 text-sm`,children:`This conversation's history is unavailable. Start a new conversation from the list above; earlier conversations and their files stay listed.`}),d.stale&&(0,$.jsxs)(`div`,{role:`status`,"aria-live":`polite`,"aria-atomic":`true`,className:`mx-5 mt-2 flex items-center gap-2 rounded-[10px] border border-sapphire-light bg-sapphire-glow px-3 py-2 text-[0.86em] text-sapphire-deep`,children:[(0,$.jsx)(`span`,{className:`h-2 w-2 flex-none rounded-full bg-sapphire`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`flex-1`,children:d.recoveredTurn?`The recovered turn has new activity.`:`There is new activity from elsewhere (the terminal, a follow-up, Telegram or a schedule).`}),(0,$.jsx)(`button`,{type:`button`,onClick:()=>void d.refreshHistory(),className:`unstyled rounded-md bg-sapphire px-3 py-1 text-[0.92em] font-semibold text-snow hover:bg-sapphire-deep`,children:`Show it`}),(0,$.jsx)(`button`,{type:`button`,onClick:d.dismissStale,className:`unstyled px-1 text-sapphire-deep hover:opacity-70`,"aria-label":`Dismiss`,children:`×`})]}),(0,$.jsx)(`div`,{ref:C,onScroll:e=>{w.current=ts(e.currentTarget)},role:`log`,"aria-label":`Conversation with ${t}`,"aria-live":`polite`,"aria-relevant":`additions`,"aria-busy":d.turnBusy,className:`min-h-0 flex-1 overflow-y-auto px-5 py-4`,children:(0,$.jsxs)(`div`,{className:`mx-auto max-w-[50rem]`,children:[A&&(0,$.jsxs)(`p`,{className:`py-12 text-center italic text-mocha-light`,children:[`Say what you need. `,t,` keeps this conversation between turns.`]}),(0,$.jsx)(rc,{entries:d.entries,notes:d.notes,markdownReady:s,editableEntry:d.editableEntry,replacedFrom:d.replacedFrom,onEdit:k,approvals:d.approvals}),(d.thinking||j)&&(0,$.jsxs)(`div`,{role:`status`,className:`flex items-center gap-2 px-1 py-1.5 text-[0.85em] ${te?`text-warning`:`text-success`}`,children:[(0,$.jsx)(`span`,{className:`size-[7px] rounded-full ${te?`bg-warning`:`animate-pulse bg-success`}`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{children:te?`${t} is waiting for you`:`${t} is working${M?`: ${M}`:``}`})]})]})}),(0,$.jsx)(`p`,{className:`sr-only`,role:`status`,"aria-live":`polite`,"aria-atomic":`true`,children:d.turnBusy?`${t} is responding.`:`Conversation ready.`}),(0,$.jsx)(Ds,{agentId:e,queue:d.queue,onChanged:()=>void d.refreshQueue(),onViewConversation:e=>a?.(e),conversationId:d.conversationId()}),(0,$.jsx)(ss,{agentId:e,agentName:t,refreshKey:d.questionsKey}),(0,$.jsx)(Es,{agentName:t,value:f,onChange:_,onSubmit:()=>void O(),attachments:v,onAddFiles:e=>void D(e),onRemoveAttachment:e=>y(t=>t.filter((t,n)=>n!==e)),editing:d.editing,onCancelEdit:()=>{d.cancelEdit(),g.current=!1,_(h.current),h.current=``},agentBusy:d.agentBusy,onStop:()=>void d.stop(),inputRef:S})]})}function Dc({team:e}){let{agentById:t,search:a,to:s}=z(),c=i(),l=Pt(),u=co(e),[d,f]=(0,G.useState)(!1),[p,m]=(0,G.useState)(null),[h,_]=(0,G.useState)(null),v=wo(e.id,u.filter,48),b=v.results.filter(u.matches),x=a.result??null,S=v.results.find(e=>e.id===x),C=W(async e=>{if(!x||S)return null;try{return(await n(_o(x),{signal:e})).result}catch(e){if(e instanceof o&&e.status===404)return null;throw e}},[x,!!S]),w=S??C.data??null,T=v.results.find(e=>e.id===p)??null,E=e=>void c.navigate({to:`/`,search:s({result:e}),replace:!0}),D=()=>{f(!1),m(null)};(0,G.useEffect)(D,[x]);let O=e=>t(e.agentId)?.name,k=u.filter;return(0,$.jsxs)(ge,{view:`files`,actions:v.total>0&&u.kind===`all`&&(0,$.jsxs)(`a`,{href:yo({teamId:e.id,...k}),download:!0,className:`ghost-btn min-h-8 px-3 py-1 text-xs`,children:[(0,$.jsx)(ue,{className:`size-3.5`,"aria-hidden":`true`}),`Download `,u.narrowed?`these`:`all`,` `,v.total,` (.zip)`]}),children:[(0,$.jsxs)(`div`,{className:`grid h-full min-h-0 grid-cols-1 ${w?`lg:grid-cols-[minmax(0,1fr)_minmax(20rem,26rem)]`:``}`,children:[w&&T?(0,$.jsxs)(`div`,{className:`min-h-0 overflow-y-auto p-3 sm:p-4`,children:[(0,$.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(Yt,{className:`size-4 shrink-0 text-accent-foreground`,"aria-hidden":`true`}),(0,$.jsx)(`h2`,{className:`m-0 min-w-0 flex-1 font-body text-sm font-semibold text-foreground`,children:`Side by side`}),(0,$.jsx)(g,{variant:`ghost`,className:`min-h-8 px-3 py-1 text-xs`,onClick:D,children:`Stop comparing`})]}),(0,$.jsx)(`div`,{className:`grid grid-cols-1 gap-3 md:grid-cols-2`,children:[w,T].map(e=>(0,$.jsxs)(`figure`,{className:`m-0 min-w-0`,children:[(0,$.jsx)(Oc,{result:e}),(0,$.jsxs)(`figcaption`,{className:`mt-1.5 flex items-center gap-2 text-xs text-mocha`,children:[(0,$.jsxs)(`span`,{className:`min-w-0 flex-1 truncate`,title:e.name,children:[(0,$.jsx)(`strong`,{className:`text-foreground`,children:e.name}),` ·`,` `,ho(e.byteLength),O(e)?` · ${O(e)}`:``]}),(0,$.jsx)(`a`,{href:_o(e.id,`download`),download:e.name,className:`shrink-0 font-semibold`,children:`Download`})]})]},e.id))})]}):(0,$.jsxs)(`div`,{className:`min-h-0 overflow-y-auto p-3 sm:p-4 ${w?`hidden lg:block`:``}`,children:[(0,$.jsxs)(`div`,{className:`mb-3 flex flex-wrap items-center gap-2`,children:[(0,$.jsx)(lo,{state:u}),(0,$.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:v.loading&&v.results.length===0?`Loading…`:u.kind===`all`?`${v.total} file${v.total===1?``:`s`}`:`${b.length} of the ${v.results.length} loaded`})]}),d&&(0,$.jsxs)(`p`,{role:`status`,className:`mb-3 flex flex-wrap items-center gap-2 rounded-[10px] border border-primary/30 bg-accent/40 px-3 py-2 text-sm text-foreground`,children:[(0,$.jsx)(Yt,{className:`size-4 shrink-0 text-accent-foreground`,"aria-hidden":`true`}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[`Choose the file to put beside `,(0,$.jsx)(`strong`,{children:w?.name}),`.`]}),(0,$.jsx)(g,{variant:`ghost`,className:`min-h-8 px-3 py-1 text-xs`,onClick:D,children:`Stop comparing`})]}),v.error&&(0,$.jsx)(`p`,{role:`alert`,className:`err`,children:v.error}),!v.loading&&!v.error&&b.length===0&&(0,$.jsx)(`p`,{className:`m-0 rounded-2xl border border-dashed border-border bg-muted/40 px-4 py-10 text-center text-sm text-muted-foreground`,children:v.total===0?`Nothing saved yet. Files an Agent delivers and pictures it generates are kept here with their original contents.`:`No file of this kind among the ones loaded.`}),(0,$.jsx)(`div`,{className:`grid grid-cols-[repeat(auto-fill,minmax(14rem,1fr))] gap-3`,children:b.map(e=>(0,$.jsx)(bo,{resultId:e.id,result:e,compact:!0,selected:e.id===x||e.id===p,detail:[O(e),l?dt(e.createdAt):null].filter(Boolean).join(` · `),open:s({result:e.id}),...d&&e.id!==x?{onPick:()=>m(e.id)}:{}},e.id))}),v.hasMore&&(0,$.jsx)(`div`,{className:`mt-4 text-center`,children:(0,$.jsx)(g,{variant:`ghost`,disabled:v.loading,onClick:v.more,children:v.loading?`Loading…`:`Show more (${v.total-v.results.length} left)`})})]}),w&&(0,$.jsxs)(`aside`,{"aria-label":`Details of ${w.name}`,className:`min-h-0 overflow-y-auto border-border p-3 sm:p-4 lg:border-l`,children:[(0,$.jsxs)(`div`,{className:`mb-3 flex items-start gap-2`,children:[(0,$.jsx)(`h2`,{className:`m-0 min-w-0 flex-1 break-words font-body text-base font-semibold leading-snug text-foreground`,children:w.name}),(0,$.jsx)(`button`,{type:`button`,"aria-label":`Close the details`,onClick:()=>E(void 0),className:`unstyled flex size-8 shrink-0 items-center justify-center rounded-[10px] text-mocha hover:bg-muted hover:text-foreground`,children:(0,$.jsx)(y,{className:`size-4`,"aria-hidden":`true`})})]}),(0,$.jsx)(Oc,{result:w}),(0,$.jsxs)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:[(0,$.jsxs)(`a`,{href:_o(w.id,`download`),download:w.name,className:`btn-primary min-h-9 px-3 py-1.5 text-sm no-underline`,children:[(0,$.jsx)(ue,{className:`size-4`,"aria-hidden":`true`}),`Download`]}),T?(0,$.jsx)(g,{variant:`ghost`,className:`min-h-9`,onClick:D,children:`Stop comparing`}):(0,$.jsxs)(g,{variant:`ghost`,className:`min-h-9`,disabled:v.results.length<2,onClick:()=>f(!0),children:[(0,$.jsx)(Yt,{className:`size-4`,"aria-hidden":`true`}),`Compare`]}),(0,$.jsxs)(g,{variant:`danger`,className:`min-h-9`,onClick:()=>_(w),children:[(0,$.jsx)(vn,{className:`size-4`,"aria-hidden":`true`}),`Delete`]})]}),(0,$.jsxs)(`dl`,{className:`m-0 mt-4 grid grid-cols-[max-content_minmax(0,1fr)] gap-x-3 gap-y-2 text-sm`,children:[(0,$.jsx)(`dt`,{className:`text-muted-foreground`,children:`Delivered by`}),(0,$.jsxs)(`dd`,{className:`m-0 flex min-w-0 items-center gap-1.5`,children:[(0,$.jsx)(H,{identity:t(w.agentId)?.identity,size:18}),(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:O(w)??`An Agent that was deleted`})]}),(0,$.jsx)(`dt`,{className:`text-muted-foreground`,children:`Saved`}),(0,$.jsx)(`dd`,{className:`m-0`,children:l?new Date(w.createdAt).toLocaleString():``}),(0,$.jsx)(`dt`,{className:`text-muted-foreground`,children:`Kind`}),(0,$.jsxs)(`dd`,{className:`m-0`,children:[go(w.mimeType,w.name),` · `,ho(w.byteLength)]}),w.imageModel&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`dt`,{className:`text-muted-foreground`,children:`Made with`}),(0,$.jsx)(`dd`,{className:`m-0 break-all font-mono text-xs`,children:w.imageModel})]}),(0,$.jsx)(`dt`,{className:`text-muted-foreground`,children:`SHA-256`}),(0,$.jsxs)(`dd`,{className:`m-0 flex min-w-0 items-center gap-1`,children:[(0,$.jsx)(`span`,{className:`min-w-0 truncate font-mono text-xs text-mocha`,children:w.sha256}),(0,$.jsx)(to,{value:w.sha256,ariaLabel:`Copy the checksum`,title:`Copy`})]})]}),O(w)&&(0,$.jsxs)(r,{to:`/`,search:{agent:w.agentId,conversation:w.sessionId,panel:`files`},className:`ghost-btn mt-4 min-h-9 w-full text-sm`,children:[(0,$.jsx)(ke,{className:`size-4`,"aria-hidden":`true`}),`Open the conversation it came from`]})]}),x&&!w&&!C.loading&&(0,$.jsx)(`p`,{role:`alert`,className:`m-0 p-4 text-sm text-muted-foreground`,children:`That saved file is not available any more.`})]}),(0,$.jsx)(Ft,{open:h!==null,title:`Delete ${h?.name??`this file`}?`,description:(0,$.jsx)(`p`,{children:`The saved copy is removed for good, and the conversation shows it as unavailable. A file of the same name in the Team's workspace, if there is one, is not touched.`}),confirmLabel:`Delete saved file`,onOpenChange:e=>{e||_(null)},onConfirm:async()=>{h&&(await n(_o(h.id),{method:`DELETE`}),E(void 0),await v.reload())}})]})}function Oc({result:e}){let t=W(async t=>po(e)?(await s(_o(e.id,`preview`),{signal:t})).text():null,[e.id]);return fo(e)?(0,$.jsx)(`a`,{href:_o(e.id,`preview`),target:`_blank`,rel:`noreferrer`,title:`Open at full size`,children:(0,$.jsx)(`img`,{src:_o(e.id,`preview`),alt:e.name,className:`block max-h-[60vh] w-full rounded-[10px] border border-border bg-muted object-contain`})}):po(e)?(0,$.jsx)(`pre`,{className:`m-0 max-h-[60vh] overflow-auto whitespace-pre-wrap break-words rounded-[10px] border border-border bg-muted p-3 font-mono text-xs leading-relaxed`,children:t.error?l(t.error):t.data??`Loading…`}):(0,$.jsxs)(`p`,{className:`m-0 rounded-[10px] border border-dashed border-border bg-muted/50 px-3 py-8 text-center text-sm text-muted-foreground`,children:[`No preview for `,go(e.mimeType,e.name),` files. Download it to open it.`]})}var kc=`inline-flex h-[26px] min-w-0 max-w-[11rem] shrink items-center gap-1 rounded-full border border-border bg-muted px-2.5 text-xs font-semibold text-mocha hover:border-sapphire-light hover:text-sapphire`,Ac=`flex min-h-10 w-full cursor-pointer items-center gap-2 rounded-lg px-2.5 py-1.5 text-left text-sm text-foreground outline-none data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground data-[disabled]:cursor-not-allowed data-[disabled]:opacity-50`;function jc(e){let t=e.indexOf(`:`);return t>0?e.slice(t+1):e}function Mc({agent:e,chat:t,panel:n,lastPanel:i}){let{to:a}=z();return(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2.5 gap-y-2 border-b border-frost px-3 py-2.5 sm:flex-nowrap sm:px-4`,children:[(0,$.jsx)(r,{to:`/`,search:{},"aria-label":`Back to the list of agents`,className:`flex size-8 shrink-0 items-center justify-center rounded-[10px] border border-border text-mocha lg:hidden`,children:(0,$.jsx)(L,{className:`size-4`,"aria-hidden":`true`})}),(0,$.jsx)(H,{identity:e.agent.identity,size:32}),(0,$.jsxs)(`h1`,{title:e.agent.name,className:`m-0 min-w-0 max-w-[14rem] shrink-0 truncate font-display text-xl leading-tight text-charcoal`,children:[e.agent.name,rt(e.agent)&&(0,$.jsxs)(`span`,{className:`font-body text-sm text-muted-foreground`,children:[` `,`· `,rt(e.agent)]})]}),(0,$.jsx)(r,{to:`/`,search:a({panel:`team`,section:void 0}),title:e.team.name,className:v(kc,e.team.name.length<=16&&`shrink-0`),children:(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:e.team.name})}),(0,$.jsxs)(r,{to:`/`,search:a({panel:`agent`,section:void 0}),title:`Model: ${e.model}`,className:v(kc,`hidden min-w-[4.5rem] shrink-[4] font-mono font-normal sm:inline-flex`),children:[(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:jc(e.model)}),(0,$.jsx)(tt,{className:`size-[11px] shrink-0`,"aria-hidden":`true`})]}),(0,$.jsxs)(`div`,{className:`ml-auto flex min-w-[7.75rem] shrink-[20] items-center justify-end gap-1.5`,children:[(0,$.jsx)(Nc,{agentId:e.agent.id,chat:t}),(0,$.jsx)(r,{to:`/`,search:a({panel:n===`none`?i:`none`,section:void 0}),"aria-label":n===`none`?`Show the side panel`:`Hide the side panel`,title:n===`none`?`Show the side panel`:`Hide the side panel`,className:`flex size-8 shrink-0 items-center justify-center rounded-[10px] border ${n===`none`?`border-border bg-card text-mocha hover:text-sapphire`:`border-primary/25 bg-accent text-accent-foreground`}`,children:(0,$.jsx)(un,{className:`size-4`,"aria-hidden":`true`})})]})]})}function Nc({agentId:e,chat:t}){let{search:a,to:o}=z(),{turnsEnded:s}=U(),c=i(),u=Pt(),d=`/api/agents/${encodeURIComponent(e)}/conversations`,[f,p]=(0,G.useState)(!1),[m,h]=(0,G.useState)(null),[g,_]=(0,G.useState)(``),v=W(e=>n(`${d}?limit=20`,{signal:e}),[d],{refreshOn:s}),y=t?t.conversationsOpen:f,S=t?t.setConversationsOpen:p,D=v.data?.conversations??[],O=v.data?.selectedId??null,k=a.conversation??O,A=D.find(e=>e.id===k);async function j(){_(``);try{await n(d,{body:{}}),t?await t.reload():(await c.invalidate({sync:!0}),await c.navigate({to:`/`,search:o({conversation:void 0})})),await v.reload()}catch(e){_(l(e)),S(!0)}}let ee=(0,G.useRef)(()=>{});return ee.current=()=>{if(t?.agentBusy){_(`Wait for the turn to end, or stop it, before starting a new conversation.`),S(!0);return}j()},(0,G.useEffect)(()=>{let t=t=>{t.detail?.agentId===e&&ee.current()};return window.addEventListener(it,t),()=>window.removeEventListener(it,t)},[e]),(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(ie,{open:y,onOpenChange:e=>{S(e),e&&v.reload()},children:[(0,$.jsx)(re,{asChild:!0,children:(0,$.jsxs)(`button`,{type:`button`,"aria-label":A?`${A.title}: conversations`:`Conversations`,className:`unstyled inline-flex h-8 min-w-0 max-w-[15rem] items-center gap-1.5 rounded-[10px] border border-border bg-card px-2.5 text-sm font-semibold text-foreground hover:border-sapphire-light`,children:[(0,$.jsx)(ke,{className:`size-[15px] shrink-0 text-mocha`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:A?.title??`Conversations`}),(0,$.jsx)(tt,{className:`size-3 shrink-0 text-mocha`,"aria-hidden":`true`})]})}),(0,$.jsx)(w,{children:(0,$.jsxs)(T,{align:`end`,sideOffset:6,collisionPadding:12,className:`z-50 max-h-[70vh] w-[min(22rem,calc(100vw-1.5rem))] overflow-y-auto rounded-xl border border-border bg-popover p-1.5 text-popover-foreground shadow-baziu-lg outline-none`,children:[(0,$.jsx)(E,{className:`px-2.5 pb-1 pt-1.5 text-xs font-bold uppercase tracking-[0.08em] text-muted-foreground`,children:`Conversations`}),v.error&&(0,$.jsx)(`p`,{role:`alert`,className:`m-0 px-2.5 py-1.5 text-xs text-danger`,children:v.error}),g&&(0,$.jsx)(`p`,{role:`alert`,className:`m-0 px-2.5 py-1.5 text-xs text-danger`,children:g}),!v.data&&!v.error&&(0,$.jsx)(`p`,{role:`status`,className:`m-0 px-2.5 py-2 text-sm text-muted-foreground`,children:`Loading…`}),v.data&&D.length===0&&(0,$.jsx)(`p`,{className:`m-0 px-2.5 py-2 text-sm text-muted-foreground`,children:`The first message starts the first conversation.`}),D.map(e=>{let t=e.id===O,n=e.id===k,i=v.data?.usage[e.id];return(0,$.jsx)(C,{asChild:!0,className:Ac,children:(0,$.jsxs)(r,{to:`/`,search:o({conversation:t?void 0:e.id}),"aria-current":n?`true`:void 0,className:n?`bg-accent/70 text-accent-foreground`:``,children:[(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate font-medium`,children:e.title}),i&&(0,$.jsx)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:ht(i)})]}),t?(0,$.jsxs)(`span`,{className:`flex shrink-0 items-center gap-1 text-xs font-semibold text-success`,children:[(0,$.jsx)(b,{className:`size-3`,"aria-hidden":`true`}),`Active`]}):u&&(0,$.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:dt(e.createdAt)})]})},e.id)}),v.data&&v.data.total>D.length&&(0,$.jsxs)(`p`,{className:`m-0 px-2.5 py-1.5 text-xs text-muted-foreground`,children:[`The newest `,D.length,` of `,v.data.total,`.`,` `,(0,$.jsx)(`code`,{children:`bazilion conversation list`}),` shows them all.`]}),(0,$.jsx)(x,{className:`my-1.5 h-px bg-border`}),(0,$.jsxs)(C,{className:`${Ac} font-semibold`,disabled:t?.agentBusy??!1,onSelect:()=>void j(),children:[(0,$.jsx)(B,{className:`size-3.5`,"aria-hidden":`true`}),`New conversation`,t?.agentBusy&&(0,$.jsx)(`span`,{className:`ml-auto text-xs font-normal`,children:`after this turn`})]}),A&&(0,$.jsxs)(C,{className:Ac,onSelect:()=>h(A),children:[(0,$.jsx)(pn,{className:`size-3.5`,"aria-hidden":`true`}),`Rename “`,A.title.length>24?`${A.title.slice(0,24)}…`:A.title,`”`]}),(0,$.jsx)(C,{asChild:!0,className:Ac,children:(0,$.jsxs)(r,{to:`/usage`,search:{agent:e},children:[(0,$.jsx)(pe,{className:`size-3.5`,"aria-hidden":`true`}),`This Agent's usage`]})})]})})]}),m&&(0,$.jsx)(Pc,{base:d,conversation:m,onClose:()=>h(null),onRenamed:()=>v.reload()})]})}function Pc({base:e,conversation:t,onClose:r,onRenamed:i}){let[a,o]=(0,G.useState)(t.title),[s,c]=(0,G.useState)(!1),[u,d]=(0,G.useState)(``),f=!a.trim()||a.trim()===t.title;async function p(o){if(o.preventDefault(),!f){c(!0),d(``);try{await n(`${e}/${encodeURIComponent(t.id)}`,{method:`PATCH`,body:{title:a.trim()}}),await i(),r()}catch(e){d(l(e)),c(!1)}}}return(0,$.jsx)(Ye,{title:`Rename the conversation`,busy:s,onClose:r,className:`max-w-md`,children:(0,$.jsxs)(`form`,{onSubmit:e=>void p(e),children:[(0,$.jsxs)(`label`,{children:[`Title`,(0,$.jsx)(`input`,{autoFocus:!0,value:a,maxLength:200,onChange:e=>o(e.target.value)})]}),u&&(0,$.jsx)(`p`,{role:`alert`,className:`mt-3 text-sm text-danger`,children:u}),(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsxs)(_t,{children:[(0,$.jsx)(g,{variant:`ghost`,disabled:s,onClick:r,children:`Cancel`}),(0,$.jsx)(g,{variant:`primary`,type:`submit`,disabled:s||f,children:s?`Renaming…`:`Rename`})]})})]})})}function Fc({agentId:e,agentName:t,conversationId:a,header:s}){let{search:c,to:u}=z(),d=i(),f=m(),p=(0,G.useRef)(null);Xo(p,c.find,c.match,()=>{f({to:`/`,search:u({find:void 0,match:void 0}),replace:!0})});let h=`/api/agents/${encodeURIComponent(e)}/conversations/${encodeURIComponent(a)}`,[_,v]=(0,G.useState)(!1),[y,b]=(0,G.useState)(``),x=W(async e=>{try{return await n(h,{signal:e})}catch(e){if(e instanceof o&&e.status===409)return{conversation:e.body.conversation??null,messages:null};throw e}},[h]);os(p,()=>es(e,a),{ready:x.data!==void 0,skip:!!c.find});async function S(){v(!0),b(``);try{await n(`${h}/select`,{method:`POST`}),await d.invalidate({sync:!0}),await d.navigate({to:`/`,search:u({conversation:void 0})})}catch(e){b(l(e)),v(!1)}}let C=x.data?.conversation?.title;return(0,$.jsxs)(`section`,{"aria-label":`An earlier conversation with ${t}`,className:wc,children:[s,(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 border-b border-frost bg-muted px-4 py-2 text-sm`,children:[(0,$.jsxs)(`span`,{className:`min-w-0 flex-1 basis-56 text-mocha`,children:[`You are reading`,` `,C?(0,$.jsx)(`strong`,{className:`text-foreground`,children:C.replace(/\.+$/,``)}):`an earlier conversation`,`. New messages go to the active conversation.`]}),(0,$.jsx)(g,{variant:`primary`,className:`min-h-9`,disabled:_||!x.data?.messages,onClick:()=>void S(),children:_?`Switching…`:`Continue this conversation`}),(0,$.jsx)(r,{to:`/`,search:u({conversation:void 0}),className:`ghost-btn min-h-9`,children:`Back to the active one`})]}),y&&(0,$.jsx)(`p`,{role:`alert`,className:`m-0 px-5 pt-3 text-sm text-danger`,children:y}),(0,$.jsx)(`div`,{ref:p,className:`min-h-0 flex-1 overflow-y-auto px-5 py-4`,children:(0,$.jsxs)(`div`,{className:`mx-auto max-w-[50rem]`,children:[x.error&&(0,$.jsx)(`p`,{role:`alert`,className:`text-sm text-danger`,children:x.error}),!x.data&&!x.error&&(0,$.jsx)(`p`,{role:`status`,className:`text-sm text-mocha`,children:`Loading the conversation…`}),x.data&&(x.data.messages===null?(0,$.jsx)(`p`,{role:`alert`,className:`text-sm`,children:`This conversation's history is unavailable, so it cannot be read or continued.`}):x.data.messages.length>0?(0,$.jsx)(ic,{messages:x.data.messages}):(0,$.jsx)(`p`,{className:`py-12 text-center italic text-mocha-light`,children:`This conversation is empty.`}))]})})]})}var Ic=`m-0 mb-2 mt-7 font-body text-xs font-bold uppercase tracking-[0.08em] text-muted-foreground`,Lc=`flex min-h-14 items-center gap-3 rounded-2xl border border-border bg-card px-3.5 py-2 text-foreground shadow-baziu-sm hover:border-sapphire-light hover:bg-accent/30`,Rc=5,zc=(e,t,n=`${t}s`)=>`${e} ${e===1?t:n}`;function Bc(){let{agents:e,teams:t,profiles:n,search:i}=z(),a=U(),o=d(),[s,c]=(0,G.useState)(!1),l=Pt(),u=wo(``,{},4),f=new Map(t.map(e=>[e.id,e.name])),p=new Map(e.map(e=>[e.id,a.stateOf(e.id)])),m=e=>p.get(e.id)??{kind:`idle`,text:``},h=e.filter(e=>m(e).kind===`needs`),_=e.filter(e=>m(e).kind===`working`),v=new Set([...h,..._].map(e=>e.id)),y=e.filter(e=>!v.has(e.id)).map(e=>({agent:e,at:a.byAgent.get(e.id)?.lastActivityAt??null})).filter(e=>e.at!==null).sort((e,t)=>t.at-e.at).slice(0,Rc),b=Math.max(o.open-o.agentWaits,0),x=ot([...p.values()]),S=(e,t)=>{let n=m(e);return(0,$.jsx)(`li`,{children:(0,$.jsxs)(r,{to:`/`,search:{agent:e.id,...i.panel?{panel:i.panel}:{}},className:Lc,children:[(0,$.jsx)(H,{identity:e.identity,size:36}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`span`,{className:`block truncate text-base font-semibold`,children:[e.name,(0,$.jsxs)(`span`,{className:`font-normal text-mocha`,children:[` · `,f.get(e.teamId)]})]}),(0,$.jsxs)(`span`,{className:`mt-0.5 flex min-w-0 items-center gap-1.5 text-xs ${we[n.kind]}`,children:[(0,$.jsx)(`span`,{className:`size-[7px] shrink-0 rounded-full ${xe[n.kind]}`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:n.text})]})]}),t&&(0,$.jsx)(`span`,{className:`shrink-0 text-xs text-mocha`,children:t}),(0,$.jsx)(`span`,{className:`shrink-0 text-xs font-semibold text-accent-foreground`,children:`Open`})]})},e.id)};return(0,$.jsxs)(`section`,{"aria-label":`Overview`,className:`flex h-full flex-col overflow-y-auto rounded-[16px] border border-border bg-card px-4 py-5 shadow-baziu-sm sm:px-8 sm:py-8`,children:[(0,$.jsxs)(`div`,{className:`mx-auto w-full max-w-2xl`,children:[(0,$.jsx)(`h1`,{className:`m-0 font-display text-[1.9rem] leading-tight text-charcoal`,children:`Overview`}),(0,$.jsxs)(`p`,{className:`m-0 mt-1 text-sm text-mocha`,children:[zc(e.length,`Agent`),` in `,zc(t.length,`Team`),x?` · ${x}`:``]}),(0,$.jsx)(`h2`,{className:Ic,children:`Waiting for you`}),h.length>0?(0,$.jsx)(`ul`,{className:`m-0 list-none space-y-2 p-0`,children:h.map(e=>S(e))}):(0,$.jsx)(`p`,{className:`m-0 rounded-2xl border border-dashed border-border bg-muted/40 px-4 py-3 text-sm text-muted-foreground`,children:`No Agent is waiting for you.`}),b>0&&(0,$.jsxs)(r,{to:`/attention`,className:`mt-2 inline-flex items-center gap-1.5 text-sm font-semibold`,children:[(0,$.jsx)(Ke,{className:`size-3.5`,"aria-hidden":`true`}),zc(b,`more item`),` in Attention`]}),_.length>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`h2`,{className:Ic,children:`Working now`}),(0,$.jsx)(`ul`,{className:`m-0 list-none space-y-2 p-0`,children:_.map(e=>S(e))})]}),(0,$.jsx)(`h2`,{className:Ic,children:`Teams`}),(0,$.jsx)(`ul`,{className:`m-0 grid list-none grid-cols-1 gap-2 p-0 sm:grid-cols-2`,children:t.map(t=>(0,$.jsx)(Vc,{team:t,members:e.filter(e=>e.teamId===t.id),summary:ot(e.filter(e=>e.teamId===t.id).map(m))},t.id))}),e.length===0&&(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsxs)(g,{variant:`primary`,onClick:()=>c(!0),children:[(0,$.jsx)(B,{className:`size-4`,"aria-hidden":`true`}),`Add your first Agent`]})}),u.results.length>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`h2`,{className:Ic,children:`Latest files`}),(0,$.jsx)(`div`,{className:`grid grid-cols-2 gap-2.5 sm:grid-cols-4`,children:u.results.map(t=>(0,$.jsx)(bo,{resultId:t.id,result:t,compact:!0,detail:e.find(e=>e.id===t.agentId)?.name,open:{team:t.teamId,view:`files`,result:t.id}},t.id))})]}),y.length>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`h2`,{className:Ic,children:`Recently active`}),(0,$.jsx)(`ul`,{className:`m-0 list-none space-y-2 p-0`,children:y.map(({agent:e,at:t})=>S(e,l?dt(t):void 0))})]})]}),s&&(0,$.jsx)(Tt,{profiles:n,teams:t,teamId:t[0]?.id??`default`,onClose:()=>c(!1)})]})}function Vc({team:e,members:t,summary:n}){return(0,$.jsx)(`li`,{children:(0,$.jsxs)(r,{to:`/`,search:{team:e.id},className:`flex h-full min-h-16 items-center gap-3 rounded-2xl border border-border bg-muted/40 px-3.5 py-2.5 text-foreground hover:border-sapphire-light hover:bg-accent/30`,children:[(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate text-base font-semibold`,children:e.name}),(0,$.jsxs)(`span`,{className:`block truncate text-xs text-mocha`,children:[zc(t.length,`member`),n?` · ${n}`:``]})]}),(0,$.jsx)(`span`,{className:`flex shrink-0 -space-x-2`,"aria-hidden":`true`,children:t.slice(0,4).map(e=>(0,$.jsx)(`span`,{className:`rounded-full ring-2 ring-card`,children:(0,$.jsx)(H,{identity:e.identity,size:26})},e.id))})]})})}var Hc=`flex min-h-8 w-full cursor-pointer items-center gap-2 rounded-lg px-2.5 py-1.5 text-left text-sm text-foreground outline-none transition-colors data-[highlighted]:bg-accent data-[highlighted]:text-accent-foreground data-[disabled]:cursor-not-allowed data-[disabled]:opacity-50`,Uc=`flex items-center gap-1.5 px-2.5 pb-1 pt-1 text-xs font-semibold uppercase tracking-[0.08em] text-muted-foreground`;function Wc({buttonRef:e,profiles:t,teamTemplates:n,onSpawnAgent:r,onSpawnTeam:i,onCreateTeam:a}){return(0,$.jsxs)(ie,{modal:!1,children:[(0,$.jsx)(re,{asChild:!0,children:(0,$.jsxs)(`button`,{ref:e,type:`button`,"aria-label":`Create a new Agent or Team`,className:`unstyled group inline-flex h-8 items-center gap-1 rounded-lg border border-border bg-card px-2.5 text-xs font-semibold text-foreground shadow-baziu-sm transition-colors hover:border-primary/30 hover:bg-accent hover:text-accent-foreground`,children:[(0,$.jsx)(B,{className:`size-3.5`,"aria-hidden":`true`}),`New`,(0,$.jsx)(tt,{className:`size-3.5 text-muted-foreground transition-transform group-data-[state=open]:rotate-180`,"aria-hidden":`true`})]})}),(0,$.jsx)(w,{children:(0,$.jsxs)(T,{align:`end`,sideOffset:6,className:`z-50 w-60 rounded-xl border border-border bg-popover p-1.5 text-popover-foreground shadow-baziu-lg outline-none`,children:[(0,$.jsxs)(E,{className:Uc,children:[(0,$.jsx)(fe,{className:`size-3`,"aria-hidden":`true`}),`Agent templates`]}),t.length===0?(0,$.jsx)(C,{asChild:!0,className:Hc,children:(0,$.jsx)(`a`,{href:`/templates/agents?new=1`,children:`Create an Agent template`})}):t.map(e=>(0,$.jsxs)(C,{className:Hc,onSelect:()=>r(e.id),children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.name||e.id}),e.id==="default"&&(0,$.jsx)(`span`,{className:`rounded-full border border-border bg-muted px-1.5 py-0.5 text-xs font-semibold text-muted-foreground`,children:`Default`})]},e.id)),(0,$.jsx)(x,{className:`my-1.5 h-px bg-border`}),(0,$.jsxs)(E,{className:Uc,children:[(0,$.jsx)(Le,{className:`size-3`,"aria-hidden":`true`}),`Team templates`]}),n.length===0?(0,$.jsx)(C,{asChild:!0,className:Hc,children:(0,$.jsx)(`a`,{href:`/templates/teams?new=1`,children:`Create a Team template`})}):n.map(e=>(0,$.jsxs)(C,{className:Hc,disabled:e.slots.length===0,title:e.slots.length===0?`Add at least one member before spawning`:void 0,onSelect:()=>i(e.id),children:[(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.name||e.id}),(0,$.jsx)(`span`,{className:`inline-flex min-w-6 items-center justify-center rounded-full bg-muted px-1.5 font-mono text-xs text-muted-foreground`,children:e.slots.length})]},e.id)),(0,$.jsx)(x,{className:`my-1.5 h-px bg-border`}),(0,$.jsxs)(C,{className:Hc,onSelect:a,children:[(0,$.jsx)(B,{className:`size-3.5`,"aria-hidden":`true`}),`Create a Team`]})]})})]})}var Gc=`bz_sidebar_open_groups`;function Kc(e){document.cookie=`${Gc}=${encodeURIComponent(JSON.stringify(e))}; Path=/; Max-Age=31536000; SameSite=Lax`}function qc(e,t,n){return e[t]??(n||t==="default")}function Jc(e){return[...e].sort((e,t)=>Number(t.id===Dt)-Number(e.id===Dt))}function Yc(e){return[...e].sort((e,t)=>Number(t.id===Ct)-Number(e.id===Ct))}function Xc(e,t,n){let r=Jc(e).filter(e=>t.some(t=>t.teamId===e.id));return r.sort((e,t)=>Number(t.id===n)-Number(e.id===n)),r}function Zc({agent:e,selected:t,state:n,lastActivityAt:i,panel:a,onRename:o,onArchive:s}){let c=Pt();return(0,$.jsxs)(`div`,{className:`group/row relative rounded-2xl`,children:[(0,$.jsxs)(r,{to:`/`,search:{agent:e.id,...a?{panel:a}:{}},"aria-current":t?`page`:void 0,className:`flex min-h-[3.1rem] items-center gap-2.5 rounded-2xl border py-1.5 pl-2 pr-9 transition-colors hover:bg-accent/60 ${t?`border-primary/20 bg-accent shadow-baziu-sm`:`border-transparent`}`,children:[(0,$.jsx)(H,{identity:e.identity,size:30}),(0,$.jsxs)(`span`,{className:`block min-w-0 flex-1`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,$.jsxs)(`span`,{className:`min-w-0 truncate text-sm font-semibold leading-tight ${t?`text-accent-foreground`:`text-foreground`}`,children:[e.name,rt(e)&&(0,$.jsxs)(`span`,{className:`font-normal text-muted-foreground`,children:[` · `,rt(e)]})]}),e.telegramTopicId!==null&&(0,$.jsx)(`span`,{className:`shrink-0 text-primary`,title:`Telegram topic #${e.telegramTopicId}`,role:`img`,"aria-label":`Bound to Telegram topic ${e.telegramTopicId}`,children:(0,$.jsx)(hn,{className:`size-3`,"aria-hidden":`true`})}),c&&i!==null&&(0,$.jsx)(`time`,{dateTime:new Date(i).toISOString(),className:`ml-auto shrink-0 text-xs font-normal text-muted-foreground`,children:dt(i)})]}),(0,$.jsxs)(`span`,{className:`mt-0.5 flex items-center gap-1.5 text-xs leading-snug ${we[n.kind]}`,children:[(0,$.jsx)(`span`,{className:`size-[7px] shrink-0 rounded-full ${xe[n.kind]}`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:n.text})]})]})]}),(0,$.jsxs)(ie,{modal:!1,children:[(0,$.jsx)(re,{asChild:!0,children:(0,$.jsx)(`button`,{type:`button`,"aria-label":`More for ${e.name}`,className:`unstyled absolute right-1 top-1/2 flex size-7 -translate-y-1/2 items-center justify-center rounded-lg text-muted-foreground opacity-0 transition-opacity hover:bg-card hover:text-primary focus-visible:opacity-100 group-hover/row:opacity-100 data-[state=open]:opacity-100 [@media(hover:none)]:opacity-100`,children:(0,$.jsx)(D,{className:`size-4`,"aria-hidden":`true`})})}),(0,$.jsx)(w,{children:(0,$.jsxs)(T,{align:`start`,sideOffset:4,className:`z-50 w-48 rounded-xl border border-border bg-popover p-1.5 text-popover-foreground shadow-baziu-lg outline-none`,children:[(0,$.jsx)(C,{asChild:!0,className:Hc,children:(0,$.jsxs)(r,{to:`/`,search:{agent:e.id,panel:`agent`},children:[(0,$.jsx)(Be,{className:`size-3.5`,"aria-hidden":`true`}),`Agent settings`]})}),(0,$.jsxs)(C,{className:Hc,onSelect:o,children:[(0,$.jsx)(pn,{className:`size-3.5`,"aria-hidden":`true`}),`Rename`]}),(0,$.jsxs)(C,{className:Hc,onSelect:s,children:[(0,$.jsx)(I,{className:`size-3.5`,"aria-hidden":`true`}),`Archive`]})]})})]})]})}function Qc({team:e,members:t,current:n,isOpen:i,onOpenChange:a,openAgentId:o,selectedId:s,activity:c,panel:l,onRename:u,onArchive:d}){let f=ot(t.map(e=>c.stateOf(e.id)));return(0,$.jsxs)(`div`,{className:`relative mb-1 last:mb-0`,children:[(0,$.jsxs)(`details`,{open:i,onToggle:e=>{let t=e.currentTarget.open;t!==i&&a(t)},className:`group/details`,children:[(0,$.jsxs)(`summary`,{className:`flex min-h-9 cursor-pointer list-none items-center gap-1.5 rounded-lg py-1 pl-2 pr-9 text-sm transition-colors hover:bg-accent/60 [&::-webkit-details-marker]:hidden ${n?`bg-muted text-foreground`:`text-mocha`}`,children:[(0,$.jsx)(me,{className:`size-3.5 shrink-0 text-muted-foreground transition-transform group-open/details:rotate-90`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-semibold`,children:e.name}),(0,$.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:f||t.length})]}),t.length===0?(0,$.jsx)(`div`,{className:`py-2 pl-7 pr-2 text-xs text-muted-foreground`,children:`No agents in this team`}):(0,$.jsx)(`div`,{className:`space-y-0.5 py-1 pl-1.5`,children:t.map(e=>(0,$.jsx)(Zc,{agent:e,selected:e.id===s,state:c.stateOf(e.id),lastActivityAt:c.byAgent.get(e.id)?.lastActivityAt??null,panel:l,onRename:()=>u(e),onArchive:()=>d(e)},e.id))})]}),(0,$.jsx)(r,{to:`/`,search:{...o===null?{}:{agent:o},team:e.id,panel:`team`},"aria-label":`Open ${e.name}: members, USER.md, memory`,title:`Open the Team`,className:`absolute right-1 top-1 flex size-7 items-center justify-center rounded-lg text-muted-foreground hover:bg-card hover:text-primary`,children:(0,$.jsx)(un,{className:`size-3.5`,"aria-hidden":`true`})})]})}function $c({initialOpenGroups:e}){let{agents:t,teams:n,profiles:r,teamTemplates:a,agent:o,team:s,search:c}=z(),l=U(),u=i(),[d,f]=(0,G.useState)(null),[p,m]=(0,G.useState)(void 0),[h,_]=(0,G.useState)(null),[v,y]=(0,G.useState)(!1),[b,x]=(0,G.useState)(!1),[S,C]=(0,G.useState)(null),[w,T]=(0,G.useState)(null),[E,D]=(0,G.useState)(e),O=(0,G.useRef)(null),k=()=>window.requestAnimationFrame(()=>O.current?.focus()),A=Yc(r),j=Jc(n),ee=a.find(e=>e.id===h),M=o?.agent.id??null;return(0,$.jsxs)(`aside`,{className:`flex h-full flex-col overflow-hidden rounded-2xl border border-border bg-card shadow-baziu-sm`,children:[(0,$.jsxs)(`header`,{className:`flex items-center justify-between gap-3 border-b border-border bg-muted/60 px-3 py-2.5`,children:[(0,$.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`flex size-7 shrink-0 items-center justify-center rounded-[10px] bg-accent text-accent-foreground`,children:(0,$.jsx)(Le,{className:`size-4`,"aria-hidden":`true`})}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`div`,{className:`text-sm font-semibold leading-tight text-foreground`,children:`Teams`}),(0,$.jsxs)(`p`,{className:`m-0 truncate text-xs leading-snug text-muted-foreground`,children:[t.length,` agent`,t.length===1?``:`s`,` in `,n.length,` team`,n.length===1?``:`s`]})]})]}),(0,$.jsx)(Wc,{buttonRef:O,profiles:A,teamTemplates:a,onSpawnAgent:e=>{m(s?.id),f(e)},onSpawnTeam:e=>_(e),onCreateTeam:()=>y(!0)})]}),(0,$.jsxs)(`nav`,{className:`flex-1 overflow-y-auto p-1.5`,"aria-label":`Teams and agents`,children:[t.length===0&&(0,$.jsxs)(`div`,{className:`m-1 mb-2 flex flex-col items-center rounded-xl border border-dashed border-border bg-muted/30 px-4 py-6 text-center`,children:[(0,$.jsx)(`p`,{className:`m-0 text-sm font-semibold text-foreground`,children:`No agents yet`}),(0,$.jsx)(`p`,{className:`mt-1 text-xs leading-5 text-muted-foreground`,children:`Your default Team is ready. Add the first Agent to start a conversation.`}),A[0]?(0,$.jsx)(g,{variant:`primary`,className:`mt-3`,onClick:()=>f(A[0]?.id??`default`),children:`Add the first Agent`}):(0,$.jsx)(`a`,{href:`/templates/agents?new=1`,className:`mt-3 text-xs font-semibold`,children:`Create an Agent template`})]}),j.map(e=>{let n=s?.id===e.id;return(0,$.jsx)(Qc,{team:e,members:t.filter(t=>t.teamId===e.id),current:n,isOpen:qc(E,e.id,n),onOpenChange:t=>{let n={...E,[e.id]:t};Kc(n),D(n)},openAgentId:o?.team.id===e.id?o.agent.id:null,selectedId:M,activity:l,panel:c.panel,onRename:e=>C(e),onArchive:e=>T(e)},e.id)})]}),d&&(0,$.jsx)(Tt,{profiles:A,teams:j,profileId:d,teamId:p,onClose:()=>{f(null),k()}}),ee&&(0,$.jsx)(Vt,{template:ee,teams:j,onClose:()=>{_(null),k()},onSpawned:e=>{_(null),u.navigate({to:`/`,search:{team:e,panel:`team`}})}}),v&&(0,$.jsx)(Ye,{title:`Create a Team`,description:`A Team is one workspace: its folder, its Agents, its USER.md and shared memory, and who may message whom.`,busy:b,onClose:()=>{y(!1),k()},children:(0,$.jsx)(Ht,{taken:n.map(e=>e.id),onBusyChange:x,onCreated:async e=>{y(!1),await u.navigate({to:`/`,search:{team:e.id,panel:`team`}})},extraActions:e=>(0,$.jsx)(g,{variant:`ghost`,disabled:e,onClick:()=>y(!1),children:`Cancel`})})}),S&&(0,$.jsx)(eo,{agent:S,onClose:()=>C(null),onRenamed:()=>u.invalidate()}),(0,$.jsx)(Ft,{open:w!==null,onOpenChange:e=>{e||T(null)},title:`Archive ${w?.name??`agent`}?`,description:(0,$.jsx)(`p`,{children:`The Agent leaves this list and receives no work. Restore it later under Manage → Agents, in Archived.`}),confirmLabel:`Archive agent`,confirmVariant:`primary`,onConfirm:async()=>{w&&(await Bt(w.id),w.id===M?await u.navigate({to:`/`,search:{}}):await u.invalidate())}})]})}function el(){let{agents:e,teams:t,agent:n,team:i,search:a}=z(),o=U(),s=Xc(t,e,i?.id);return(0,$.jsxs)(`nav`,{"aria-label":`Agents`,className:`flex h-full w-16 flex-col items-center gap-2 overflow-y-auto rounded-xl border border-border bg-card py-2.5 shadow-baziu-sm`,children:[(0,$.jsx)(r,{to:`/`,search:{...a,view:void 0,file:void 0,result:void 0},"aria-label":`Back to the conversation and the full list`,title:`Back to the conversation`,className:`flex size-10 shrink-0 items-center justify-center rounded-xl text-mocha hover:bg-accent hover:text-accent-foreground`,children:(0,$.jsx)(ln,{className:`size-[18px]`,"aria-hidden":`true`})}),s.map(t=>(0,$.jsxs)(`div`,{className:`flex w-full flex-col items-center gap-2`,children:[(0,$.jsx)(`div`,{className:`h-px w-8 bg-border`}),(0,$.jsx)(`span`,{className:`max-w-14 truncate text-xs font-bold uppercase tracking-[0.06em] ${t.id===i?.id?`text-accent-foreground`:`text-muted-foreground`}`,title:t.name,children:t.name}),e.filter(e=>e.teamId===t.id).map(e=>{let t=o.stateOf(e.id);return(0,$.jsxs)(r,{to:`/`,search:{agent:e.id,...a.panel?{panel:a.panel}:{}},"aria-label":`${e.name}: ${t.text}`,title:`${e.name}: ${t.text}`,className:`relative flex size-10 shrink-0 items-center justify-center rounded-full ${e.id===n?.agent.id?`ring-2 ring-primary ring-offset-2 ring-offset-card`:``}`,children:[(0,$.jsx)(H,{identity:e.identity,size:40}),(0,$.jsx)(`span`,{className:`absolute -bottom-px -right-px size-3 rounded-full border-2 border-card ${xe[t.kind]}`,"aria-hidden":`true`})]},e.id)})]},t.id))]})}var tl={headless:`without a window`,headed:`in a window`,attached:`your own, attached`};function nl({agentId:e,agentName:t=`This Agent`}){let r=`/api/agents/${encodeURIComponent(e)}/browser`,[i,a]=(0,G.useState)(null),[o,s]=(0,G.useState)(!0),[c,u]=(0,G.useState)(null),[d,f]=(0,G.useState)(null),[p,m]=(0,G.useState)(!1),h=(0,G.useCallback)(async()=>{s(!0);try{a(await n(r))}catch(e){f(l(e))}finally{s(!1)}},[r]),_=(0,G.useCallback)(()=>{f(null),h()},[h]);(0,G.useEffect)(()=>{_()},[_]);async function v(e){u(e),f(null);try{e===`stop`?await n(`${r}/stop`,{method:`POST`}):await n(`${r}/profile`,{method:`DELETE`})}catch(e){f(l(e))}finally{await h(),u(null)}}let y=c!==null||o;return(0,$.jsxs)(F,{labelledBy:`agent-browser`,icon:(0,$.jsx)($t,{className:`size-5`}),title:`Browser`,description:`${t}’s own browser for pages that need one. It keeps its sign-ins between turns.`,action:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[i&&(i.running?(0,$.jsx)(M,{tone:`success`,children:`Running`}):(0,$.jsx)(M,{tone:`neutral`,children:`Stopped`})),(0,$.jsx)(g,{variant:`ghost`,disabled:y,onClick:_,children:o?`Checking…`:`Check again`})]}),children:[o&&!i&&(0,$.jsx)(ce,{children:(0,$.jsx)(`p`,{role:`status`,className:`m-0 text-sm text-muted-foreground`,children:`Checking the browser…`})}),i&&(0,$.jsxs)(se,{children:[(0,$.jsx)(te,{label:`Browser tools`,tone:i.enabled?void 0:`warning`,children:i.enabled?`On`:`Off in Setup → Tools`}),(0,$.jsx)(te,{label:`Saved sign-ins`,children:i.profilePresent?`Kept: cookies and sign-ins`:`None yet`}),(0,$.jsx)(te,{label:`Browser`,tone:i.browser?void 0:`warning`,children:i.browser?`${i.browser.name}, ${tl[i.browser.mode]}`:`None found`})]}),(0,$.jsxs)(ce,{children:[i?.error&&(0,$.jsx)(N,{title:`The browser cannot run.`,children:(0,$.jsx)(`span`,{className:`whitespace-pre-wrap`,children:i.error})}),d&&(0,$.jsx)(N,{role:`alert`,title:`That did not work.`,children:d}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,$.jsx)(g,{variant:`ghost`,disabled:y||!i?.running,onClick:()=>void v(`stop`),children:c===`stop`?`Stopping…`:`Stop it`}),(0,$.jsx)(g,{variant:`ghost`,disabled:y||!i?.profilePresent&&!i?.running,onClick:()=>m(!0),children:`Forget its sign-ins…`})]}),(0,$.jsx)(`p`,{className:`m-0 text-xs leading-5 text-muted-foreground`,children:`Stopping it, archiving the Agent or moving it to another Team keeps the sign-ins; forgetting them or deleting the Agent removes them. Backups leave them out.`})]}),(0,$.jsx)(Ft,{open:p,onOpenChange:m,title:`Forget ${t}’s sign-ins?`,description:(0,$.jsx)(`p`,{className:`m-0`,children:`The browser stops, and its cookies and sign-ins are deleted. The next page it opens starts signed out.`}),confirmLabel:`Forget the sign-ins`,onConfirm:()=>v(`reset`)})]})}function rl({agentId:e,agentName:t,attached:r}){let i=W(e=>n(`/api/skills`,{signal:e}),[]);return i.data?(0,$.jsx)(il,{agentId:e,agentName:t,attached:new Set(r),all:i.data}):i.error?(0,$.jsx)(N,{role:`alert`,title:`The skills could not be loaded.`,children:i.error}):(0,$.jsx)(`p`,{role:`status`,className:`m-0 text-sm text-muted-foreground`,children:`Loading the skills…`})}function il({agentId:e,agentName:t=`this Agent`,attached:r,all:a}){let o=i(),[s,c]=(0,G.useState)(null),[u,d]=(0,G.useState)(null),[f,p]=(0,G.useState)(null),[m,h]=(0,G.useState)(null),g=`/api/agents/${encodeURIComponent(e)}/skills`,_=a.filter(e=>r.has(e.name)).length;async function v(e,t){c(e),d(null);try{await t(),await o.invalidate()}catch(e){throw d(l(e)),e}finally{c(null)}}let y=e=>v(e.name,()=>n(g,{body:{skill:e.name,allowFindings:(e.scanFindings??[]).length>0}})),b=e=>v(e,()=>n(`${g}/${encodeURIComponent(e)}`,{method:`DELETE`}));return(0,$.jsxs)(F,{labelledBy:`agent-skills`,icon:(0,$.jsx)(Pe,{className:`size-5`}),title:`Skills`,description:(0,$.jsxs)($.Fragment,{children:[`Instructions `,t,` follows on every turn. Install and remove skills under`,` `,(0,$.jsx)(`a`,{href:`/skills`,children:`Manage → Skills`}),`.`]}),action:(0,$.jsxs)(M,{tone:_>0?`success`:`neutral`,children:[_,` on`]}),children:[u&&(0,$.jsx)(`div`,{className:`border-t border-border px-4 py-3 sm:px-5`,children:(0,$.jsx)(N,{role:`alert`,title:`That did not work.`,children:u})}),a.length===0?(0,$.jsx)(ne,{icon:(0,$.jsx)(Pe,{className:`size-5`}),title:`No skills are installed`,children:`Import some under Manage → Skills, then switch them on here.`}):(0,$.jsx)(oe,{children:a.map(e=>{let t=r.has(e.name),n=e.scanFindings??[],i=jt(e);return(0,$.jsx)(P,{inline:!0,title:(0,$.jsx)(`span`,{className:`font-mono text-[0.92em]`,children:e.name}),chip:i&&(0,$.jsx)(M,{tone:i.tone,children:i.label}),meta:(0,$.jsx)(`span`,{children:e.description||`No description.`}),actions:(0,$.jsx)(j,{label:`${e.name}: ${t?`on`:`off`}`,checked:t,disabled:s===e.name||!!e.parseError&&!t,onChange:()=>{t?h(e.name):n.length>0?p(e):y(e).catch(()=>{})}}),children:n.length>0&&(0,$.jsx)(Fe,{findings:n})},e.name)})}),(0,$.jsx)(Ft,{open:f!==null,onOpenChange:e=>{e||p(null)},title:`Switch on ${f?.name??`the skill`}?`,description:(0,$.jsxs)(`div`,{className:`grid gap-2`,children:[(0,$.jsxs)(`p`,{className:`m-0`,children:[`The scan found something in it. Its text goes into `,t,`’s instructions, so read what was found first.`]}),(0,$.jsx)(`div`,{className:`text-sm`,children:(0,$.jsx)(Ie,{findings:f?.scanFindings??[]})})]}),confirmLabel:`Switch it on anyway`,onConfirm:async()=>{f&&await y(f)}}),(0,$.jsx)(Ft,{open:m!==null,onOpenChange:e=>{e||h(null)},title:`Switch off ${m??`the skill`}?`,description:(0,$.jsxs)(`p`,{className:`m-0`,children:[t,` stops following it from the next turn. The skill stays installed, and you can switch it on again.`]}),confirmVariant:`primary`,confirmLabel:`Switch it off`,onConfirm:async()=>{m&&await b(m)}})]})}var al=[{value:`minimal`,label:`Its replies`},{value:`verbose`,label:`Its replies and every tool it uses`}];function ol({agent:e}){let t=i(),[r,a]=(0,G.useState)(!1),[o,s]=(0,G.useState)(null),[c,u]=(0,G.useState)(e.telegramMirrorMode),[d,f]=(0,G.useState)(e.telegramIconEmoji??``),[p,m]=(0,G.useState)(!1),[h,_]=(0,G.useState)(!1),v=`/api/agents/${encodeURIComponent(e.id)}`,y=e.telegramTopicId!==null,b=d!==(e.telegramIconEmoji??``);async function x(e){a(!0),s(null);try{await e(),await t.invalidate()}catch(e){throw s(l(e)),e}finally{a(!1)}}async function S(){await x(async()=>{let{deepLink:e}=await n(`${v}/telegram/bind`,{method:`POST`});window.open(e,`_blank`,`noopener`)}).catch(()=>{})}async function C(t){u(t),await x(()=>n(v,{method:`PATCH`,body:{telegramMirrorMode:t}})).catch(()=>u(e.telegramMirrorMode))}async function w(e){e.preventDefault(),await x(()=>n(v,{method:`PATCH`,body:{telegramIconEmoji:d.trim()||null}})).then(()=>m(!0)).catch(()=>{})}return(0,$.jsxs)(F,{labelledBy:`agent-telegram`,icon:(0,$.jsx)(Ae,{className:`size-5`}),title:`Telegram topic`,description:`${e.name}’s own topic in the Telegram group: its turns show there, and a message there starts one.`,action:(0,$.jsxs)(`div`,{className:`flex items-center gap-2`,children:[y?(0,$.jsx)(M,{tone:`success`,children:`Has a topic`}):(0,$.jsx)(M,{tone:`neutral`,children:`No topic`}),y&&(0,$.jsx)(k,{label:`More for ${e.name}’s topic`,disabled:r,items:[{label:`Unbind…`,danger:!0,onSelect:()=>_(!0)}]})]}),children:[o&&(0,$.jsx)(`div`,{className:`border-t border-border px-4 py-3 sm:px-5`,children:(0,$.jsx)(N,{role:`alert`,title:`That did not work.`,children:o})}),(0,$.jsx)(se,{children:(0,$.jsx)(te,{label:`Topic`,children:(0,$.jsxs)(`span`,{className:`flex flex-wrap items-center gap-3`,children:[(0,$.jsx)(`span`,{children:y?`Topic ${e.telegramTopicId}`:`None yet`}),(0,$.jsx)(g,{variant:`ghost`,onClick:()=>void S(),disabled:r,children:y?`Open in Telegram`:r?`Making it…`:`Make its topic`})]})})}),(0,$.jsxs)(A,{onSubmit:e=>void w(e),children:[(0,$.jsx)(V,{label:`What shows in the topic`,value:c,options:al,disabled:r,hint:`Changed at once.`,onChange:e=>void C(e)}),(0,$.jsx)(Xe,{label:`Topic icon`,value:d,disabled:r,placeholder:`🦉`,hint:`An emoji; empty takes the template’s.`,className:`max-w-40`,onChange:e=>{f(e.slice(0,8)),m(!1)}}),(0,$.jsx)(Ue,{busy:r,disabled:!b,label:`Save the icon`,status:Ze({dirty:b,saved:p,footnote:`On iOS, Telegram opens the list of topics rather than the topic.`})})]}),(0,$.jsx)(Ft,{open:h,onOpenChange:_,title:`Unbind ${e.name} from its topic?`,description:(0,$.jsx)(`p`,{className:`m-0`,children:`Its turns stop showing in the topic, and messages there no longer reach it. The topic stays in Telegram until you delete it there.`}),confirmLabel:`Unbind the topic`,onConfirm:()=>x(()=>n(`${v}/telegram/binding`,{method:`DELETE`}))})]})}function sl({agent:e}){let t=`/api/agents/${encodeURIComponent(e.id)}`,r=W(async e=>{let[r,i,a]=await Promise.all([n(`${t}/review-config`,{signal:e}),n(`${t}/reviews`,{signal:e}),n(`${t}/lesson-proposals`,{signal:e})]);return{config:r,reviews:i.reviews,proposals:a.proposals}},[t]),[i,a]=(0,G.useState)(null),[o,s]=(0,G.useState)(!1),c=Pt(),u=e=>c?new Date(e).toLocaleString():`…`,d=async(e,t)=>{a(null),s(!0);try{await n(e,t),await r.reload()}catch(e){throw a(l(e)),e}finally{s(!1)}};if(!r.data)return r.error?(0,$.jsx)(N,{role:`alert`,title:`Reviewed learning could not be loaded.`,children:r.error}):(0,$.jsx)(`p`,{role:`status`,className:`m-0 text-sm text-muted-foreground`,children:`Loading reviewed learning…`});let{config:f,reviews:p,proposals:m}=r.data,h=m.filter(e=>e.status===`pending`),_=m.filter(e=>e.status!==`pending`);return(0,$.jsxs)(`div`,{className:`grid gap-5`,children:[i&&(0,$.jsx)(N,{role:`alert`,title:`That did not work.`,children:i}),(0,$.jsx)(F,{labelledBy:`agent-reviews`,icon:(0,$.jsx)(Gt,{className:`size-5`}),title:`Reviews`,description:`A review reads ${e.name}'s recent turns and proposes up to five lessons.`,action:(0,$.jsx)(g,{variant:`ghost`,disabled:o||e.status===`archived`,onClick:()=>void d(`${t}/reviews`,{method:`POST`}).catch(()=>{}),children:`Review now`}),children:(0,$.jsx)(cl,{config:f,disabled:o,onSave:async e=>{await n(`${t}/review-config`,{method:`PATCH`,body:e}),await r.reload()}})}),(0,$.jsx)(F,{labelledBy:`agent-lessons`,icon:(0,$.jsx)(an,{className:`size-5`}),title:`Lessons`,description:`What reviews proposed. A lesson applies only once you approve it.`,action:h.length>0&&(0,$.jsx)(M,{tone:`warning`,children:h.length===1?`1 to decide`:`${h.length} to decide`}),children:m.length===0?(0,$.jsx)(ne,{icon:(0,$.jsx)(an,{className:`size-5`}),title:`No lessons yet`,children:`A review proposes lessons when it finds something worth keeping; it may also find nothing.`}):(0,$.jsxs)($.Fragment,{children:[h.map(e=>(0,$.jsx)(pl,{proposal:e,base:`${t}/lesson-proposals/${encodeURIComponent(e.id)}`,busy:o,act:d},`${e.id}:${e.version}`)),_.length>0&&(0,$.jsx)(oe,{children:_.map(e=>(0,$.jsx)(hl,{proposal:e,base:`${t}/lesson-proposals/${encodeURIComponent(e.id)}`,busy:o,act:d},e.id))})]})}),(0,$.jsx)(F,{labelledBy:`agent-review-history`,icon:(0,$.jsx)(en,{className:`size-5`}),title:`Reviews so far`,description:`Each review, what started it, and what it found.`,children:p.length===0?(0,$.jsx)(ne,{title:`No review has run yet`}):(0,$.jsx)(oe,{children:p.map(e=>(0,$.jsx)(ul,{review:e,when:u(e.createdAt)},e.id))})})]})}function cl({config:e,disabled:t,onSave:r}){let i=W(e=>n(et,{signal:e}),[]),[a,o]=(0,G.useState)(e.enabled),[s,c]=(0,G.useState)(String(e.everyNTurns)),[u,d]=(0,G.useState)(e.model??``),[f,p]=(0,G.useState)(e.reasoningLevel),[m,h]=(0,G.useState)(!1),[g,_]=(0,G.useState)(!1),[v,y]=(0,G.useState)(null),b=Number(s),x=s!==``&&Number.isInteger(b)&&b>=1&&b<=100,S=a&&!x?`From 1 to 100 turns.`:void 0,C=x?b:e.everyNTurns,w=a!==e.enabled||C!==e.everyNTurns||u!==(e.model??``)||f!==e.reasoningLevel;async function T(e){if(e.preventDefault(),!S){h(!0),y(null);try{await r({enabled:a,everyNTurns:C,model:u||null,reasoningLevel:f}),_(!0)}catch(e){y(l(e))}finally{h(!1)}}}return(0,$.jsxs)(A,{onSubmit:e=>void T(e),children:[(0,$.jsx)(ze,{label:`Review on its own`,description:a?`After every ${x?b:`…`} successful turns, reading at most the last 8 and 40,000 characters.`:`Off: a review runs only when you press Review now.`,checked:a,disabled:t,onChange:e=>{o(e),_(!1)}}),a&&(0,$.jsx)(Xe,{label:`Every how many turns`,value:s,inputMode:`numeric`,disabled:t,problem:S,className:`max-w-32`,onChange:e=>{c(e.replace(/\D/g,``)),_(!1)}}),(0,$.jsxs)(`div`,{className:`grid items-start gap-x-3 gap-y-4 sm:grid-cols-2`,children:[(0,$.jsx)(Ge,{kit:!0,disabled:t||m,label:`Model for reviews`,value:u,onChange:e=>{d(e),_(!1)},models:i.data?.chat??[],inherited:{label:`The Agent’s own model`}}),(0,$.jsx)(V,{label:`Reasoning`,value:f,options:Et.map(e=>({value:e,label:e})),disabled:t,className:`max-w-none`,onChange:e=>{p(e),_(!1)}})]}),(0,$.jsx)(Ue,{busy:m,disabled:!w||t||!!S,status:Ze({error:v,dirty:w,saved:g,footnote:`${e.turnsSinceLast} successful turn${e.turnsSinceLast===1?``:`s`} since the last review.`})})]})}var ll={pending:{label:`Queued`,tone:`neutral`},running:{label:`Running`,tone:`success`},completed:{label:`Done`,tone:`success`},failed:{label:`Failed`,tone:`warning`},cancelled:{label:`Cancelled`,tone:`neutral`}};function ul({review:e,when:t}){let n=ll[e.status];return(0,$.jsx)(P,{inline:!0,title:t,chip:(0,$.jsx)(M,{tone:n.tone,children:n.label}),meta:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{children:e.trigger===`manual`?`Started by you`:`Ran on its own`}),(0,$.jsxs)(`span`,{children:[e.turnsReviewed,` turn`,e.turnsReviewed===1?``:`s`,` read`]}),(0,$.jsx)(`span`,{children:e.proposalCount===0?`no lessons`:`${e.proposalCount} lesson${e.proposalCount===1?``:`s`} proposed`})]}),children:e.lastError&&(0,$.jsx)(`p`,{className:`m-0 break-words text-sm text-danger`,children:e.lastError})})}function dl({proposal:e}){let t=e.evidence.filter(e=>e.excerpt);return t.length===0?null:(0,$.jsxs)(`details`,{className:`text-sm`,children:[(0,$.jsxs)(`summary`,{className:`cursor-pointer font-semibold text-accent-foreground`,children:[`What it is based on (`,t.length,`)`]}),(0,$.jsx)(`ul`,{className:`m-0 mt-2 grid list-none gap-2 p-0`,children:t.map(e=>(0,$.jsx)(`li`,{className:`whitespace-pre-wrap break-words rounded-lg border-l-2 border-border bg-muted/40 px-3 py-2 text-muted-foreground`,children:e.excerpt},`${e.sessionId}:${e.entryOrdinal}`))})]})}var fl=[{value:`private`,label:`This Agent only`,hint:`Added to its own instructions, for its future turns.`},{value:`shared`,label:`The whole Team`,hint:`Kept in the Team’s shared memory, where every member can find it.`}];function pl({proposal:e,base:t,busy:n,act:r}){let[i,a]=(0,G.useState)(e.text),[o,s]=(0,G.useState)(e.scope),[c,l]=(0,G.useState)(!1),u={version:e.version},d=i!==e.text||o!==e.scope;async function f(){d?await r(t,{method:`PATCH`,body:{...u,text:i,scope:o}}):await r(`${t}/approve`,{body:u})}return(0,$.jsxs)(ce,{children:[(0,$.jsx)(ft,{label:`Proposed lesson`,value:i,rows:3,disabled:n,onChange:a}),(0,$.jsx)(Ve,{legend:`If you approve it, it applies to`,name:`lesson-scope-${e.id}`,value:o,options:fl,disabled:n,onChange:s,notes:o===`shared`&&(0,$.jsx)(`span`,{className:`mt-1.5 block text-xs text-muted-foreground`,children:`Facts about you belong in the Team’s USER.md instead.`})}),(0,$.jsx)(dl,{proposal:e}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,$.jsx)(g,{variant:`primary`,disabled:n,onClick:()=>void f().catch(()=>{}),children:d?`Save the edit`:`Approve`}),(0,$.jsx)(g,{variant:`ghost`,disabled:n,onClick:()=>l(!0),children:`Reject`}),d&&(0,$.jsx)(`span`,{className:`self-center text-sm text-warning`,children:`Edited: save it, then approve it.`})]}),c&&(0,$.jsx)(Ft,{open:!0,title:`Reject this lesson?`,description:(0,$.jsx)(`p`,{className:`m-0`,children:`It never reaches the Agent’s instructions or the Team’s memory, and it cannot be approved later. Unsaved edits are discarded.`}),confirmLabel:`Reject the lesson`,onOpenChange:e=>{e||l(!1)},onConfirm:()=>r(`${t}/reject`,{body:u})})]})}var ml={approved:{label:`Approved`,tone:`success`},rejected:{label:`Rejected`,tone:`neutral`},revoked:{label:`Revoked`,tone:`neutral`}};function hl({proposal:e,base:t,busy:n,act:r}){let[i,a]=(0,G.useState)(!1),o=ml[e.status];return(0,$.jsxs)(P,{inline:!0,title:(0,$.jsx)(`span`,{className:`font-normal`,children:e.text}),chip:(0,$.jsx)(M,{tone:o.tone,children:o.label}),meta:(0,$.jsx)(`span`,{children:e.scope===`shared`?`The whole Team`:`This Agent only`}),actions:e.status===`approved`&&(0,$.jsx)(k,{label:`More for this lesson`,disabled:n,items:[{label:`Revoke…`,danger:!0,onSelect:()=>a(!0)}]}),children:[(0,$.jsx)(dl,{proposal:e}),i&&(0,$.jsx)(Ft,{open:!0,title:`Revoke this lesson?`,description:(0,$.jsxs)(`p`,{className:`m-0`,children:[e.scope===`shared`?`Its note leaves the Team’s shared memory, so searches no longer find it.`:`It leaves the Agent’s instructions from the next turn; past conversations stay as they were.`,` `,`It stays listed here as revoked.`]}),confirmLabel:`Revoke the lesson`,onOpenChange:e=>{e||a(!1)},onConfirm:()=>r(`${t}/revoke`,{body:{version:e.version}})})]})}function gl({agent:e,agents:t}){let r=`/api/agents/${encodeURIComponent(e.id)}`,i=W(async e=>{let[i,a,o]=await Promise.all([n(`${r}/messages`,{signal:e}),n(`${r}/loop-breaks?limit=10`,{signal:e}),n(`/api/agents?includeArchived=true`,{signal:e}).catch(()=>t)]);return{messages:[...i.messages].reverse(),loopBreaks:a.events,agents:o}},[r]);return i.data?(0,$.jsx)(yl,{agent:e,...i.data,onChanged:i.reload}):i.error?(0,$.jsx)(N,{role:`alert`,title:`The mailbox could not be loaded.`,children:i.error}):(0,$.jsx)(`p`,{role:`status`,className:`m-0 text-sm text-muted-foreground`,children:`Loading the mailbox…`})}function _l(e){let t=new Map(e.map(e=>[e.id,e])),n=new Map;for(let t of e)n.set(t.name,(n.get(t.name)??0)+1);return e=>{let r=t.get(e);if(!r)return`A deleted Agent`;let i=(n.get(r.name)??0)>1?`${r.name} (${e.slice(0,8)})`:r.name;return r.status===`archived`?`${i} (archived)`:i}}function vl(e,t){let n=_l(t);return t.filter(t=>t.status!==`archived`&&t.id!==e).map(e=>({value:e.id,label:n(e.id)}))}function yl({agent:e,agents:t,messages:r,loopBreaks:i,onChanged:a}){let[o,s]=(0,G.useState)(`all`),[c,u]=(0,G.useState)(null),[d,f]=(0,G.useState)(null),p=Pt(),m=e=>p?new Date(e).toLocaleString():``,h=r.filter(e=>e.readAt===null),_=o===`unread`?h:r,v=new Map(t.map(e=>[e.id,e])),y=_l(t),b=vl(e.id,t);async function x(e){u(e.id),f(null);try{await n(`/api/messages/${encodeURIComponent(e.id)}`,{method:`PATCH`,body:{read:!0}}),await a()}catch(e){f(l(e))}finally{u(null)}}return(0,$.jsxs)(`div`,{className:`grid gap-5`,children:[(0,$.jsxs)(F,{labelledBy:`agent-mailbox`,icon:(0,$.jsx)(nn,{className:`size-5`}),title:`Messages`,description:`What other Agents sent ${e.name}. It reads the unread ones when it is next free.`,action:h.length>0?(0,$.jsxs)(M,{tone:`warning`,children:[h.length,` unread`]}):(0,$.jsx)(M,{tone:`neutral`,children:`0 unread`}),children:[r.length>0&&(0,$.jsx)(ee,{children:(0,$.jsx)(It,{label:`Which messages`,value:o,onChange:s,options:[{id:`all`,label:`All ${r.length}`},{id:`unread`,label:`Unread ${h.length}`}]})}),d&&(0,$.jsx)(`div`,{className:`border-t border-border px-4 py-3 sm:px-5`,children:(0,$.jsx)(N,{role:`alert`,title:`It could not be marked read.`,children:d})}),_.length===0?(0,$.jsx)(ne,{icon:(0,$.jsx)(nn,{className:`size-5`}),title:r.length===0?`No messages yet`:`Nothing unread`,children:r.length===0&&`Teammates write here with their messaging tool.`}):(0,$.jsx)(oe,{children:_.map(e=>{let t=v.get(e.fromAgentId),n=e.readAt===null;return(0,$.jsx)(P,{inline:!0,leading:(0,$.jsx)(H,{identity:t?.identity,size:32}),title:`From ${y(e.fromAgentId)}`,chip:n&&(0,$.jsx)(M,{tone:`warning`,children:`Unread`}),meta:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{children:m(e.createdAt)}),e.replyTo&&(0,$.jsx)(`span`,{children:`A reply`})]}),actions:n&&(0,$.jsx)(g,{variant:`ghost`,disabled:c===e.id,"aria-label":`Mark the message from ${y(e.fromAgentId)} read`,onClick:()=>void x(e),children:`Mark read`}),children:(0,$.jsx)(`p`,{className:`m-0 whitespace-pre-wrap break-words rounded-xl bg-muted/50 px-3 py-2 text-sm text-foreground`,children:Ce(e.payload)})},e.id)})})]}),(0,$.jsx)(F,{labelledBy:`agent-loop-breaks`,icon:(0,$.jsx)(cn,{className:`size-5`}),title:`Stopped chains`,description:`When Agents keep answering each other past the limit, the chain stops and shows here.`,children:i.length===0?(0,$.jsx)(ne,{title:`No chain has been stopped`}):(0,$.jsx)(oe,{children:i.map(e=>(0,$.jsx)(P,{inline:!0,title:`${y(e.fromAgentId)} → ${y(e.toAgentId)}`,meta:(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`span`,{children:[`Stopped at message `,e.attemptedHop,`; the limit is `,e.maxHops]}),(0,$.jsx)(`span`,{children:m(e.createdAt)})]})},e.id))})}),b.length>0&&(0,$.jsx)(bl,{agent:e,senders:b,onSent:()=>void a()})]})}function bl({agent:e,senders:t,onSent:r}){let[i,a]=(0,G.useState)(t[0]?.value??``),[o,s]=(0,G.useState)(``),[c,u]=(0,G.useState)(null),[d,f]=(0,G.useState)(!1),[p,m]=(0,G.useState)(!1),[h,_]=(0,G.useState)(!1);async function v(t){if(t.preventDefault(),o.trim()){u(null),m(!0);try{let t={from:i,payload:{text:o}};await n(`/api/agents/${encodeURIComponent(e.id)}/messages`,{body:t}),s(``),f(!0),r()}catch(e){u(l(e))}finally{m(!1)}}}return(0,$.jsx)(F,{labelledBy:`agent-mailbox-send`,icon:(0,$.jsx)(hn,{className:`size-5`}),title:`Try a message from a teammate`,description:`Write to ${e.name} as one of its teammates, to see how it handles mail.`,action:!h&&(0,$.jsx)(g,{variant:`ghost`,onClick:()=>_(!0),children:`Try it`}),children:h&&(0,$.jsxs)(A,{onSubmit:e=>void v(e),children:[(0,$.jsx)(V,{label:`From`,value:i,options:t,disabled:p,onChange:a}),(0,$.jsx)(ft,{label:`Message`,value:o,rows:3,disabled:p,onChange:e=>{s(e),f(!1)}}),(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2`,children:[(0,$.jsx)(g,{variant:`primary`,type:`submit`,disabled:p||!o.trim(),children:p?`Sending…`:`Send`}),(0,$.jsx)(`p`,{role:`status`,className:`m-0 text-sm font-medium ${c?`text-warning`:`text-success`}`,children:c?`Not sent: ${c}`:d?`Sent. ${e.name} reads it when it is free.`:``})]})]})})}var xl=[`Sunday`,`Monday`,`Tuesday`,`Wednesday`,`Thursday`,`Friday`,`Saturday`],Sl=(e,t)=>`${e} ${t}${e===1?``:`s`}`;function Cl(e){return e%86400==0?e===86400?`Every day`:`Every ${Sl(e/86400,`day`)}`:e%3600==0?e===3600?`Every hour`:`Every ${Sl(e/3600,`hour`)}`:e%60==0?e===60?`Every minute`:`Every ${Sl(e/60,`minute`)}`:`Every ${Sl(e,`second`)}`}var wl=e=>/^\d+$/.test(e)?Number(e):null,Tl=(e,t)=>`${String(e).padStart(2,`0`)}:${String(t).padStart(2,`0`)}`;function El(e){let t=e.trim().split(/\s+/);if(t.length!==5)return null;let[n=``,r=``,i=``,a=``,o=``]=t;if(i!==`*`||a!==`*`)return null;let s=/^\*\/(\d+)$/.exec(n);if(s&&r===`*`&&o===`*`)return Cl(Number(s[1])*60);if(n===`*`&&r===`*`&&o===`*`)return`Every minute`;let c=wl(n);if(c===null||c>59)return null;if(r===`*`&&o===`*`)return c===0?`Every hour`:`Every hour at :${Tl(0,c).slice(3)}`;let l=wl(r);if(l===null||l>23)return null;let u=Tl(l,c);if(o===`*`)return`Every day at ${u}`;if(o===`1-5`)return`Weekdays at ${u}`;if(o===`0,6`||o===`6,0`)return`Weekends at ${u}`;let d=wl(o);return d!==null&&d<=7?`Every ${xl[d%7]} at ${u}`:null}function Dl(e){if(e.kind===`interval`)return{text:Cl(e.intervalSec??0),raw:!1};let t=e.cronExpr??``,n=El(t);return n?{text:n,raw:!1}:{text:t,raw:!0}}var Ol=[{value:`minutes`,label:`Every few minutes`},{value:`hourly`,label:`Every hour`},{value:`daily`,label:`Every day`},{value:`weekdays`,label:`Every weekday`},{value:`weekly`,label:`Once a week`},{value:`cron`,label:`A cron expression`}],kl=[1,2,3,4,5,6,0].map(e=>({value:String(e),label:xl[e]??``})),Al={repeat:`weekdays`,minutes:`30`,time:`09:00`,day:`1`,cron:``,message:``};function jl(e){let t=e.message.trim(),n=(e,t)=>({request:null,problem:t,field:e}),r=e=>t?{request:{...e,message:t},problem:null,field:null}:n(`message`,`Write the message the Agent gets.`),i=/^(\d{1,2}):(\d{2})$/.exec(e.time),a=i?Number(i[1]):NaN,o=i?Number(i[2]):NaN,s=a>=0&&a<=23&&o>=0&&o<=59;switch(e.repeat){case`minutes`:{let t=Number(e.minutes);return!Number.isInteger(t)||t<1?n(`minutes`,`Give a whole number of minutes.`):r({kind:`interval`,intervalSec:t*60})}case`hourly`:return r({kind:`cron`,cronExpr:`0 * * * *`});case`daily`:case`weekdays`:case`weekly`:return s?r({kind:`cron`,cronExpr:`${o} ${a} * * ${e.repeat===`daily`?`*`:e.repeat===`weekdays`?`1-5`:e.day}`}):n(`time`,`Give a time of day, such as 09:00.`);case`cron`:{let t=e.cron.trim().replace(/\s+/g,` `);return t.split(` `).length===5?r({kind:`cron`,cronExpr:t}):n(`cron`,`A cron expression has five fields: minute, hour, day, month, weekday.`)}}}function Ml({agent:e}){let t=`/api/agents/${encodeURIComponent(e.id)}/triggers`,r=W(e=>n(t,{signal:e}),[t]);return r.data?(0,$.jsx)(Fl,{agentId:e.id,agentName:e.name,...r.data,onChanged:r.reload}):r.error?(0,$.jsx)(N,{role:`alert`,title:`The schedules could not be loaded.`,children:r.error}):(0,$.jsx)(`p`,{role:`status`,className:`m-0 text-sm text-muted-foreground`,children:`Loading the schedules…`})}function Nl(e,t){let n=e-t;return n<6e4?`Next run now`:n<36e5?`Next run in ${Math.round(n/6e4)} min`:`Next run ${new Date(e).toLocaleString(void 0,{weekday:`short`,day:`numeric`,month:`short`,hour:`2-digit`,minute:`2-digit`})}`}var Pl={pending:{label:`Waiting for the Agent`,tone:`neutral`},running:{label:`Running`,tone:`success`},succeeded:{label:`Done`,tone:`success`},failed:{label:`Failed`,tone:`warning`},cancelled:{label:`Cancelled`,tone:`neutral`}};function Fl({agentId:e,agentName:t=`The Agent`,triggers:r,dispatches:i,nextRuns:a,schedulerOff:o,onChanged:s}){let[c,u]=(0,G.useState)(!1),[d,f]=(0,G.useState)(null),[p,m]=(0,G.useState)(null),[h,_]=(0,G.useState)(null),v=Pt(),y=e=>v?new Date(e).toLocaleString():``,b=new Map(r.map(e=>[e.id,e]));async function x(e){_(e.id),m(null);try{await n(`/api/triggers/${encodeURIComponent(e.id)}`,{method:`PATCH`,body:{enabled:!e.enabled}}),await s()}catch(e){m(l(e))}finally{_(null)}}return(0,$.jsxs)(`div`,{className:`grid gap-5`,children:[(0,$.jsxs)(F,{labelledBy:`agent-schedules`,icon:(0,$.jsx)(qt,{className:`size-5`}),title:`Schedules`,description:`Each one sends ${t} its message at the times it says.`,action:r.length>0&&(0,$.jsxs)(g,{variant:`primary`,onClick:()=>u(!0),children:[(0,$.jsx)(B,{className:`size-4`,"aria-hidden":`true`}),`Add a schedule`]}),children:[p&&(0,$.jsx)(`div`,{className:`border-t border-border px-4 py-3 sm:px-5`,children:(0,$.jsx)(N,{role:`alert`,title:`That did not work.`,children:p})}),o&&r.length>0&&(0,$.jsx)(`div`,{className:`border-t border-border px-4 py-3 sm:px-5`,children:(0,$.jsxs)(N,{title:`No schedule runs on this daemon`,children:[`It was started with `,(0,$.jsx)(`code`,{children:`BAZILION_SCHEDULER=off`}),`.`]})}),r.length===0?(0,$.jsxs)(ne,{icon:(0,$.jsx)(qt,{className:`size-5`}),title:`No schedules yet`,action:(0,$.jsxs)(g,{variant:`primary`,onClick:()=>u(!0),children:[(0,$.jsx)(B,{className:`size-4`,"aria-hidden":`true`}),`Add a schedule`]}),children:[`A schedule gives `,t,` a message at set times: a morning check, a weekly summary.`]}):(0,$.jsx)(oe,{children:r.map(e=>{let t=Dl(e);return(0,$.jsx)(P,{inline:!0,title:t.raw?(0,$.jsx)(`code`,{className:`font-mono text-[0.92em]`,children:t.text}):t.text,chip:e.enabled?(0,$.jsx)(M,{tone:`success`,children:`On`}):(0,$.jsx)(M,{tone:`neutral`,children:`Paused`}),meta:(0,$.jsxs)($.Fragment,{children:[v&&typeof a[e.id]==`number`&&(0,$.jsx)(`span`,{children:Nl(a[e.id],Date.now())}),(0,$.jsx)(`span`,{children:e.lastFiredAt?`Last ran ${y(e.lastFiredAt)}`:`Has not run yet`})]}),actions:(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(j,{label:`${t.text}: ${e.enabled?`on`:`paused`}`,checked:e.enabled,disabled:h===e.id,onChange:()=>void x(e)}),(0,$.jsx)(k,{label:`More for ${t.text}`,items:[{label:`Delete…`,danger:!0,onSelect:()=>f(e)}]})]}),children:(0,$.jsx)(`p`,{className:`m-0 whitespace-pre-wrap break-words rounded-xl bg-muted/50 px-3 py-2 text-sm text-foreground`,children:e.message})},e.id)})})]}),(0,$.jsx)(F,{labelledBy:`agent-schedule-runs`,icon:(0,$.jsx)(en,{className:`size-5`}),title:`Recent runs`,description:`Each time a schedule came due, and how it went.`,children:i.length===0?(0,$.jsx)(ne,{title:`Nothing has run yet`,children:`A schedule's first run shows here once its time comes.`}):(0,$.jsx)(oe,{children:i.map(e=>{let t=Pl[e.status],n=b.get(e.triggerId);return(0,$.jsx)(P,{inline:!0,title:y(e.scheduledAt)||`…`,chip:(0,$.jsx)(M,{tone:t.tone,children:t.label}),meta:(0,$.jsx)(`span`,{children:n?Dl(n).text:`A deleted schedule`}),children:e.error&&(0,$.jsx)(`p`,{className:`m-0 break-words text-sm text-danger`,children:e.error})},e.id)})})}),c&&(0,$.jsx)(Il,{agentId:e,agentName:t,onClose:()=>u(!1),onAdded:async()=>{u(!1),await s()}}),(0,$.jsx)(Ft,{open:d!==null,title:`Delete this schedule?`,description:(0,$.jsxs)(`p`,{className:`m-0`,children:[d?Dl(d).text:`The schedule`,` stops, and its run history goes with it. `,t,` and its conversations stay.`]}),confirmLabel:`Delete the schedule`,onConfirm:async()=>{d&&(await n(`/api/triggers/${encodeURIComponent(d.id)}`,{method:`DELETE`}),await s())},onOpenChange:e=>{e||f(null)}})]})}function Il({agentId:e,agentName:t,onClose:r,onAdded:i}){let[a,o]=(0,G.useState)(Al),[s,c]=(0,G.useState)(!1),[u,d]=(0,G.useState)(!1),[f,p]=(0,G.useState)(null),m=(e,t)=>{o(n=>({...n,[e]:t})),p(null)},h=jl(a),_=jl({...a,message:a.message.trim()||`…`}),v=_.request?Dl(_.request):null,y=e=>s&&h.field===e?h.problem:void 0;async function b(t){if(t.preventDefault(),c(!0),h.request){d(!0);try{await n(`/api/agents/${encodeURIComponent(e)}/triggers`,{body:h.request}),await i()}catch(e){p(l(e)),d(!1)}}}return(0,$.jsx)(Ye,{title:`Add a schedule`,description:`${t} gets the message at these times, as if you had written it.`,busy:u,onClose:r,children:(0,$.jsxs)(`form`,{onSubmit:e=>void b(e),className:`grid gap-4`,children:[(0,$.jsxs)(`div`,{className:`grid items-start gap-x-3 gap-y-4 sm:grid-cols-2`,children:[(0,$.jsx)(V,{label:`Repeat`,value:a.repeat,options:Ol,disabled:u,onChange:e=>m(`repeat`,e),className:`max-w-none`}),a.repeat===`minutes`&&(0,$.jsx)(Xe,{label:`Every how many minutes`,value:a.minutes,inputMode:`numeric`,disabled:u,problem:y(`minutes`),className:`max-w-none`,onChange:e=>m(`minutes`,e.replace(/\D/g,``))}),(a.repeat===`daily`||a.repeat===`weekdays`)&&(0,$.jsx)(Xe,{label:`At`,type:`time`,value:a.time,problem:y(`time`),disabled:u,className:`max-w-none`,onChange:e=>m(`time`,e)}),a.repeat===`cron`&&(0,$.jsx)(Xe,{label:`Cron expression`,value:a.cron,problem:y(`cron`),mono:!0,placeholder:`*/15 9-17 * * 1-5`,disabled:u,className:`max-w-none`,hint:`Minute, hour, day of the month, month, day of the week.`,onChange:e=>m(`cron`,e)})]}),a.repeat===`weekly`&&(0,$.jsxs)(`div`,{className:`grid items-start gap-x-3 gap-y-4 sm:grid-cols-2`,children:[(0,$.jsx)(V,{label:`On`,value:a.day,options:kl,disabled:u,onChange:e=>m(`day`,e),className:`max-w-none`}),(0,$.jsx)(Xe,{label:`At`,type:`time`,value:a.time,problem:y(`time`),disabled:u,className:`max-w-none`,onChange:e=>m(`time`,e)})]}),(0,$.jsx)(ft,{label:`Message`,value:a.message,rows:3,disabled:u,placeholder:`Morning check: what is blocked, what ships today?`,problem:y(`message`),onChange:e=>m(`message`,e)}),v&&(0,$.jsx)(`p`,{className:`m-0 text-sm text-muted-foreground`,children:v.raw?(0,$.jsxs)($.Fragment,{children:[t,` gets it when `,(0,$.jsx)(`code`,{children:v.text}),` matches, on this computer's clock.`]}):(0,$.jsxs)($.Fragment,{children:[t,` gets it: `,v.text.charAt(0).toLowerCase()+v.text.slice(1),`, on this computer's clock.`]})}),f&&(0,$.jsx)(N,{role:`alert`,title:`The schedule was not added.`,children:f}),(0,$.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,$.jsx)(g,{variant:`primary`,type:`submit`,disabled:u,children:u?`Adding…`:`Add the schedule`}),(0,$.jsx)(g,{variant:`ghost`,disabled:u,onClick:r,children:`Cancel`})]})]})})}function Ll(e){let t=e.trim().replace(/^(\.\/)+/,``);return t?t.startsWith(`/`)||t.includes(`\\`)?{error:`A name is a path inside the memory folder, such as people/sam.md.`}:t.split(`/`).some(e=>e===``||e===`.`||e===`..`)?{error:`A name cannot have empty parts, “.” or “..” in its path.`}:(t=`${t.replace(/\.md$/i,``)}.md`,{key:t}):{error:`Give the note a name.`}}function Rl(e,t){return{key:e,title:No(t)??e.split(`/`).pop()?.replace(/\.md$/,``)??e,preview:Po(t,110)}}function zl({team:e,openKey:t}){let r=`/api/teams/${encodeURIComponent(e.id)}/memory`,i=e=>`${r}/${e.split(`/`).map(encodeURIComponent).join(`/`)}`,a=Pt(),[o,s]=(0,G.useState)([]),[c,u]=(0,G.useState)(0),[d,f]=(0,G.useState)(!1),[p,m]=(0,G.useState)(``),[_,y]=(0,G.useState)({mode:`none`}),[b,x]=(0,G.useState)(!1),[S,C]=(0,G.useState)(!1),[w,T]=(0,G.useState)(null),[E,D]=(0,G.useState)(null),[O,j]=(0,G.useState)(null),[M,te]=(0,G.useState)(null),P=_.mode===`edit`&&_.draft!==_.content||_.mode===`new`&&(_.key.trim()!==``||_.draft!==``),re=_.mode===`read`||_.mode===`edit`?_.key:null;async function ie(e){try{if(e.trim())s((await n(`${r}/search?q=${encodeURIComponent(e)}&limit=50`)).map(e=>Rl(e.key,e.snippet))),f(!0);else{let e=await n(r);s(e.map(e=>Rl(e.key,e.content))),u(e.length),f(!1)}}catch(e){T(l(e))}}(0,G.useEffect)(()=>{let e=setTimeout(()=>void ie(p),200);return()=>clearTimeout(e)},[p]),(0,G.useEffect)(()=>{t&&se(t)},[t]);function oe(e){P?D(()=>e):e()}async function se(e){T(null),C(!1),te(e);try{let t=await n(i(e));y({mode:`read`,key:t.key,content:t.content??``})}catch(e){T(l(e))}finally{te(null)}}async function ce(e){if(e.preventDefault(),_.mode!==`edit`&&_.mode!==`new`)return;let t=_.mode===`new`?Ll(_.key):{key:_.key};if(`error`in t){T(t.error);return}let{key:r}=t;x(!0),T(null);try{await n(i(r),{method:`PUT`,body:{content:_.draft}}),y({mode:`read`,key:r,content:_.draft}),C(!0),await ie(p)}catch(e){T(l(e))}finally{x(!1)}}let I=_.mode===`none`?null:_,ue=I===null?``:I.mode===`new`?`A new note`:Rl(I.key,I.mode===`edit`?I.draft:I.content).title;return(0,$.jsxs)(`div`,{className:`grid items-start gap-5 lg:grid-cols-[minmax(0,21rem)_minmax(0,1fr)]`,children:[(0,$.jsx)(h,{when:P,subject:`note`}),(0,$.jsxs)(F,{labelledBy:`team-notes`,icon:(0,$.jsx)(sn,{className:`size-5`}),title:`Notes`,description:c===1?`1 note`:`${c} notes`,action:(0,$.jsxs)(g,{variant:`ghost`,onClick:()=>oe(()=>{C(!1),y({mode:`new`,key:``,draft:``})}),children:[(0,$.jsx)(B,{className:`size-4`,"aria-hidden":`true`}),`New note`]}),children:[(0,$.jsx)(ee,{children:(0,$.jsx)(le,{label:`Search the notes`,placeholder:`Search the notes`,value:p,onChange:m,className:`flex-1`})}),o.length===0?(0,$.jsx)(ne,{title:d?`No note matches`:`No notes yet`,children:d?`Try another word.`:`Agents keep here what the whole Team should remember; you can write notes too.`}):(0,$.jsx)(`ul`,{className:`m-0 max-h-[56dvh] list-none overflow-y-auto p-0`,children:o.map(e=>(0,$.jsx)(`li`,{children:(0,$.jsxs)(`button`,{type:`button`,"aria-current":e.key===re?`true`:void 0,onClick:()=>{e.key!==re&&oe(()=>void se(e.key))},className:v(ae,`unstyled block w-full py-2.5 text-left transition-colors hover:bg-accent/30`,e.key===re&&`bg-accent/50`),children:[(0,$.jsx)(`span`,{className:`block w-full truncate text-sm font-semibold text-foreground`,children:e.title}),(0,$.jsx)(`span`,{className:`block w-full truncate font-mono text-xs text-muted-foreground`,children:e.key}),e.preview&&(0,$.jsx)(`span`,{className:`mt-0.5 line-clamp-2 block w-full text-sm text-muted-foreground`,children:e.preview})]})},e.key))})]}),(0,$.jsxs)(`section`,{"aria-label":ue||`Note`,className:`min-w-0 overflow-hidden rounded-2xl border border-border bg-card shadow-baziu-sm`,children:[w&&(0,$.jsx)(`div`,{className:`px-4 pt-4 sm:px-5`,children:(0,$.jsx)(N,{role:`alert`,title:`That did not work.`,children:w})}),M===null?I===null?(0,$.jsx)(ne,{icon:(0,$.jsx)(sn,{className:`size-5`}),title:`Pick a note to read it`,children:`Or write a new one with New note.`}):I.mode===`read`?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-2 px-4 py-4 sm:px-5`,children:[(0,$.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`h3`,{className:`m-0 font-body text-lg font-semibold text-foreground`,children:ue}),(0,$.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground`,children:I.key})]}),S&&(0,$.jsx)(`span`,{role:`status`,className:`text-sm font-medium text-success`,children:`Saved.`}),(0,$.jsx)(g,{variant:`ghost`,onClick:()=>{C(!1),y({...I,mode:`edit`,draft:I.content})},children:`Edit`}),(0,$.jsx)(k,{label:`More for ${ue}`,items:[{label:`Delete…`,danger:!0,onSelect:()=>j(I.key)}]})]}),(0,$.jsx)(`div`,{className:`md-content max-h-[60dvh] overflow-y-auto border-t border-border px-4 py-4 text-base leading-[1.6] text-chocolate sm:px-5`,dangerouslySetInnerHTML:{__html:xa(I.content,a)}})]}):(0,$.jsxs)(A,{onSubmit:e=>void ce(e),className:`border-t-0`,children:[I.mode===`new`?(0,$.jsx)(Xe,{label:`Name`,value:I.key,mono:!0,disabled:b,placeholder:`decisions/launch-date.md`,hint:`A path: folders group notes, such as people/sam. It ends in .md, added when left out.`,onChange:e=>y({...I,key:e})}):(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`m-0 font-body text-lg font-semibold text-foreground`,children:ue}),(0,$.jsx)(`span`,{className:`font-mono text-xs text-muted-foreground`,children:I.key})]}),(0,$.jsx)(ft,{label:`Text`,value:I.draft,rows:14,mono:!0,disabled:b,hint:`Markdown. A first line such as “# Launch date” names the note.`,onChange:e=>y({...I,draft:e})}),(0,$.jsx)(Ue,{busy:b,disabled:!P||!I.key.trim(),status:Ze({dirty:P,saved:!1}),extra:(0,$.jsx)(g,{variant:`ghost`,disabled:b,onClick:()=>oe(()=>I.mode===`edit`?y({mode:`read`,key:I.key,content:I.content}):y({mode:`none`})),children:`Cancel`})})]}):(0,$.jsxs)(`p`,{role:`status`,className:`m-0 px-4 py-6 text-sm text-muted-foreground sm:px-5`,children:[`Opening `,M,`…`]})]}),(0,$.jsx)(Ft,{open:E!==null,title:`Discard your unsaved edit?`,description:(0,$.jsx)(`p`,{className:`m-0`,children:`What you changed in this note is lost.`}),confirmLabel:`Discard the edit`,onConfirm:()=>{let e=E;D(null),e?.()},onOpenChange:e=>{e||D(null)}}),(0,$.jsx)(Ft,{open:O!==null,title:`Delete this note?`,description:(0,$.jsxs)(`p`,{className:`m-0`,children:[(0,$.jsx)(`code`,{className:`font-mono`,children:O}),` leaves the Team’s shared memory, and searches no longer find it.`]}),confirmLabel:`Delete the note`,onConfirm:async()=>{O&&(await n(i(O),{method:`DELETE`}),y({mode:`none`}),await ie(p))},onOpenChange:e=>{e||j(null)}})]})}function Bl(e,t){return{image:e.trim()||null,cwd:t.trim()||`.`}}function Vl({teamId:e}){let[t,r]=(0,G.useState)(null),[i,a]=(0,G.useState)(``),[o,s]=(0,G.useState)(`.`),[c,u]=(0,G.useState)(``),[d,f]=(0,G.useState)(!1),[p,m]=(0,G.useState)(!1),h=`/api/teams/${encodeURIComponent(e)}/coding-environment`,g=t!==null&&(i!==(t.image??``)||o!==t.cwd);function _(e){r(e),a(e.image??``),s(e.cwd)}(0,G.useEffect)(()=>{let e=new AbortController;return n(h,{signal:e.signal}).then(_).catch(t=>{e.signal.aborted||u(l(t))}),()=>e.abort()},[h]);async function v(e){e.preventDefault(),m(!0),u(``),f(!1);try{_(await n(h,{method:`PUT`,body:Bl(i,o)})),f(!0)}catch(e){u(l(e))}finally{m(!1)}}return t?(0,$.jsxs)(A,{onSubmit:e=>void v(e),children:[(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`h3`,{className:`m-0 font-body text-sm font-semibold text-foreground`,children:`Commands in Docker`}),(0,$.jsxs)(`p`,{className:`m-0 text-sm text-muted-foreground`,children:[t.sandboxMode===`docker`?`Commands run in Docker now. `:`Commands run on this computer now; these apply once Setup → Tools runs them in Docker. `,`The image must already be on this computer: Bazilion never downloads one.`]})]}),(0,$.jsxs)(`div`,{className:`grid items-start gap-x-3 gap-y-4 sm:grid-cols-2`,children:[(0,$.jsx)(Xe,{label:`Image`,value:i,mono:!0,disabled:p,placeholder:t.defaultImage,hint:`Empty: the installation’s own.`,className:`max-w-none`,onChange:e=>{a(e),f(!1)}}),(0,$.jsx)(Xe,{label:`Folder they start in`,value:o,mono:!0,disabled:p,hint:`Inside the Team’s folder; “.” is the folder itself.`,className:`max-w-none`,onChange:e=>{s(e),f(!1)}})]}),(0,$.jsx)(Ue,{busy:p,disabled:!g,status:Ze({error:c||null,dirty:g,saved:d})})]}):c?(0,$.jsx)(`div`,{className:`border-t border-border px-4 py-4 sm:px-5`,children:(0,$.jsx)(N,{role:`alert`,title:`The Docker defaults could not be loaded.`,children:c})}):null}function Hl({team:e,sampleAgent:t}){return(0,$.jsxs)(`div`,{className:`grid gap-5`,children:[(0,$.jsxs)(F,{labelledBy:`team-workspace`,icon:(0,$.jsx)(Zt,{className:`size-5`}),title:`Workspace`,description:`Where this Team’s Agents read and write files.`,children:[(0,$.jsx)(se,{children:(0,$.jsx)(te,{label:`Folder`,children:(0,$.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,$.jsx)(`code`,{className:`min-w-0 break-all font-mono text-sm`,children:e.path}),(0,$.jsx)(to,{value:e.path,ariaLabel:`Copy the folder`,title:`Copy the folder`})]})})}),(0,$.jsx)(Vl,{teamId:e.id})]}),(0,$.jsx)(Ul,{team:e,sampleAgent:t}),(0,$.jsx)(Wl,{team:e})]})}function Ul({team:e,sampleAgent:t}){let r=i(),[a,o]=(0,G.useState)(e.telegramTopicNameFormat??``),[s,c]=(0,G.useState)(!1),[u,d]=(0,G.useState)(null),[f,p]=(0,G.useState)(!1),m=a.trim(),_=(e.telegramTopicNameFormat??``)!==a,v=m&&!m.includes(`{agent.name}`)?`Put {agent.name} in it, so each member’s topic has its own name.`:void 0,y=m?m.replaceAll(`{agent.name}`,t).replaceAll(`{team.name}`,e.name).replaceAll(`{team.slug}`,e.id):e.id==="default"?t:`${e.id} › ${t}`;async function b(t){c(!0),d(null);try{await n(`/api/teams/${encodeURIComponent(e.id)}/topic-format`,{method:`PUT`,body:{format:t?null:a}}),t&&o(``),await r.invalidate({sync:!0}),p(!0)}catch(e){d(l(e))}finally{c(!1)}}return(0,$.jsxs)(F,{labelledBy:`team-topic-names`,icon:(0,$.jsx)(Ae,{className:`size-5`}),title:`Telegram topic names`,description:`What each member’s forum topic is called in the Telegram group.`,children:[(0,$.jsx)(h,{when:_,subject:`topic name changes`}),(0,$.jsxs)(A,{onSubmit:e=>{e.preventDefault(),b(!1)},children:[(0,$.jsx)(Xe,{label:`Topic name`,value:a,mono:!0,disabled:s,placeholder:`{team.name} / {agent.name}`,problem:v,hint:(0,$.jsxs)($.Fragment,{children:[`Empty: the built-in name. Use `,(0,$.jsx)(`code`,{children:`{agent.name}`}),`,`,` `,(0,$.jsx)(`code`,{children:`{team.name}`}),` and `,(0,$.jsx)(`code`,{children:`{team.slug}`}),`. Saving renames the topics you have not renamed in Telegram yourself.`]}),onChange:e=>{o(e),p(!1)}}),(0,$.jsxs)(`p`,{className:`m-0 text-sm text-muted-foreground`,children:[t,`’s topic would read`,` `,(0,$.jsx)(`span`,{className:`font-semibold text-foreground`,children:y}),`.`]}),(0,$.jsx)(Ue,{busy:s,disabled:!_||m.length===0||!!v,status:Ze({error:u,dirty:_,saved:f}),extra:e.telegramTopicNameFormat&&(0,$.jsx)(g,{variant:`ghost`,onClick:()=>void b(!0),disabled:s,children:`Use the built-in name`})})]})]})}function Wl({team:e}){let[t,r]=(0,G.useState)(`${e.name} template`),[i,a]=(0,G.useState)(``),[o,s]=(0,G.useState)(!1),[c,u]=(0,G.useState)(!1),[d,f]=(0,G.useState)(null),p=o?i:At(t),m=p?Mt(p):null;async function h(r){r.preventDefault(),u(!0),f(null);try{let r=await n(`/api/teams/${encodeURIComponent(e.id)}/policy/save-as-template`,{body:{id:p,name:t.trim()}});window.location.assign(`/templates/teams/${encodeURIComponent(r.id)}`)}catch(e){f(l(e)),u(!1)}}return(0,$.jsx)(F,{labelledBy:`team-save-template`,icon:(0,$.jsx)(rn,{className:`size-5`}),title:`Save as a Team template`,description:`Its members, who may message whom, and USER.md, ready to start another Team.`,children:(0,$.jsxs)(A,{onSubmit:e=>void h(e),children:[(0,$.jsxs)(`div`,{className:`grid items-start gap-x-3 gap-y-4 sm:grid-cols-2`,children:[(0,$.jsx)(Xe,{label:`Template name`,value:t,disabled:c,className:`max-w-none`,onChange:r}),(0,$.jsx)(Xe,{label:`ID`,value:p,mono:!0,disabled:c,className:`max-w-none`,hint:`Used in commands; it cannot change later.`,problem:m??void 0,onChange:e=>{s(!0),a(e)}})]}),(0,$.jsx)(Ue,{busy:c,disabled:!t.trim()||!p||!!m,label:`Save as a template`,busyLabel:`Saving…`,status:Ze({error:d,dirty:!1,saved:!1})})]})})}var Gl=12e3,Kl=e=>new TextEncoder().encode(e).length;function ql({team:e}){let t=i(),r=`/api/teams/${encodeURIComponent(e.id)}`,[a,s]=(0,G.useState)(null),[c,u]=(0,G.useState)(``),[d,f]=(0,G.useState)(!1),[p,m]=(0,G.useState)(null),[_,v]=(0,G.useState)(null),[y,b]=(0,G.useState)(!1),x=a!==null&&c!==a,S=Kl(c),C=S>Gl;async function w(){return(await n(r)).userMd}(0,G.useEffect)(()=>{let e=!0;return w().then(t=>{e&&(s(t),u(t))}).catch(t=>e&&m(l(t))),()=>{e=!1}},[r]);async function T(e){if(e.preventDefault(),a!==null){f(!0),m(null),v(null);try{let e={userMd:c,expected:a};await n(`${r}/user-md`,{method:`PUT`,body:e}),s(c),b(!0),await t.invalidate({sync:!0})}catch(e){e instanceof o&&e.code===`user_md_changed`?v(await w().catch(()=>null)):m(l(e))}finally{f(!1)}}}return(0,$.jsxs)(F,{labelledBy:`team-user-md`,icon:(0,$.jsx)($e,{className:`size-5`}),title:`About you`,description:`Who you are, how you like to work, what this Team is for. Its Agents add to it as they learn about you.`,children:[(0,$.jsx)(h,{when:x,subject:`USER.md changes`}),a===null?(0,$.jsx)(ce,{children:p?(0,$.jsx)(N,{role:`alert`,title:`USER.md could not be loaded.`,children:p}):(0,$.jsx)(`p`,{role:`status`,className:`m-0 text-sm text-muted-foreground`,children:`Loading USER.md…`})}):(0,$.jsxs)(A,{onSubmit:e=>void T(e),children:[_!==null&&(0,$.jsx)(N,{role:`alert`,title:`An Agent changed USER.md since you opened it.`,actions:(0,$.jsx)(g,{variant:`ghost`,onClick:()=>{s(_),u(_),v(null)},children:`Load their version (drops your edit)`}),children:`Nothing was saved. Copy what you wrote if you want to keep it, then load their version and add it back.`}),(0,$.jsx)(ft,{label:`USER.md`,value:c,rows:16,mono:!0,disabled:d,placeholder:`# About me
80
+
81
+ I run a small note-taking app. I like short answers.
82
+
83
+ # This Team
84
+
85
+ We ship version 2 on Friday.`,problem:C?`Keep it under ${Gl.toLocaleString()} bytes; it is ${S.toLocaleString()}.`:void 0,hint:`${S.toLocaleString()} of ${Gl.toLocaleString()} bytes. Markdown.`,onChange:e=>{u(e),b(!1)}}),(0,$.jsx)(Ue,{busy:d,disabled:!x||C,status:Ze({error:p,dirty:x,saved:y,savedText:`Saved. Members read it from their next turn.`})})]})]})}function Jl({title:e,description:t,onClose:n,busy:r=!1,children:i}){return(0,$.jsx)(Ye,{title:e,description:t,onClose:n,busy:r,className:`top-[4dvh] max-h-[92dvh] max-w-5xl translate-y-0 content-start`,children:(0,$.jsx)(`div`,{className:`min-w-0`,children:i})})}function Yl(){let{agent:e,team:t,agents:n,search:r,to:a}=z(),o=i(),s=r.section;if(!s)return null;let c=()=>void o.navigate({to:`/`,search:a({section:void 0,note:void 0})}),l,u;if(lt(s)){if(!e)return null;let{name:t,id:r}=e.agent;switch(s){case`schedules`:l=`${t}’s schedules`,u=(0,$.jsx)(Ml,{agent:e.agent},r);break;case`learning`:l=`What ${t} has learned`,u=(0,$.jsx)(sl,{agent:e.agent},r);break;case`mailbox`:l=`${t}’s mailbox`,u=(0,$.jsx)(gl,{agent:e.agent,agents:n},r);break;case`skills`:l=`${t}’s skills`,u=(0,$.jsx)(rl,{agentId:r,agentName:t,attached:e.skills},r);break;case`telegram`:l=`${t} on Telegram`,u=(0,$.jsx)(ol,{agent:e.agent},r);break;case`browser`:l=`${t}’s browser`,u=(0,$.jsx)(nl,{agentId:r,agentName:t},r);break}}else if(bt(s)){if(!t)return null;switch(s){case`user-md`:l=`${t.name}: about you`,u=(0,$.jsx)(ql,{team:t},t.id);break;case`memory`:l=`${t.name}: shared memory`,u=(0,$.jsx)(zl,{team:t,openKey:r.note},t.id);break;case`settings`:l=`${t.name}: settings`,u=(0,$.jsx)(Hl,{team:t,sampleAgent:n.find(e=>e.teamId===t.id)?.name??`Researcher`},t.id);break}}else return null;return(0,$.jsx)(Jl,{title:l,onClose:c,children:u})}var Xl=12,Zl={handoff:{icon:Wt,verb:`handed off to`,tone:`text-sapphire`},reply:{icon:Xt,verb:`replied to`,tone:`text-sapphire`},file:{icon:De,verb:`delivered`,tone:`text-success`},worked:{icon:ke,verb:`worked in`,tone:`text-mocha`},question:{icon:on,verb:`asks you`,tone:`text-warning`},approval:{icon:Ne,verb:`waits for your approval`,tone:`text-warning`}};function Ql(e,t){return t.kind===`file`&&t.resultId?{team:e,view:`files`,result:t.resultId}:t.kind===`handoff`&&t.otherAgentId?{agent:t.otherAgentId}:{agent:t.agentId,...t.kind===`worked`&&t.conversationId?{conversation:t.conversationId}:{}}}function $l({teamId:e}){let{turnsEnded:t}=U(),i=Pt(),[a,o]=(0,G.useState)(!1),s=W(t=>{let r=new Date;return r.setHours(0,0,0,0),n(`/api/teams/${encodeURIComponent(e)}/today?since=${r.getTime()}`,{signal:t})},[e],{refreshOn:t}),c=s.data?.events??[];return!i||s.error||c.length===0?(0,$.jsx)(`p`,{className:`m-0 text-sm text-muted-foreground`,children:s.error??(s.data?`Nothing yet today.`:`Loading…`)}):(0,$.jsxs)(`div`,{children:[(0,$.jsx)(`ol`,{className:`m-0 list-none divide-y divide-border rounded-2xl border border-border bg-card p-0`,children:(a?c:c.slice(0,Xl)).map(t=>{let n=Zl[t.kind],i=n.icon;return(0,$.jsx)(`li`,{children:(0,$.jsxs)(r,{to:`/`,search:Ql(e,t),className:`flex min-w-0 items-start gap-2.5 px-3 py-2 text-foreground no-underline hover:bg-accent/30`,children:[(0,$.jsx)(i,{className:`mt-0.5 size-4 shrink-0 ${n.tone}`,"aria-hidden":`true`}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`span`,{className:`block text-sm`,children:[(0,$.jsx)(`strong`,{className:`font-semibold`,children:t.agentName}),` `,n.verb,t.otherAgentName&&(0,$.jsxs)($.Fragment,{children:[` `,(0,$.jsx)(`strong`,{className:`font-semibold`,children:t.otherAgentName})]})]}),(0,$.jsx)(`span`,{className:`block truncate text-xs text-mocha`,children:t.text})]}),(0,$.jsx)(`span`,{className:`shrink-0 text-xs text-muted-foreground`,children:dt(t.at)})]})},`${t.kind}:${t.at}:${t.agentId}:${t.resultId??t.conversationId??t.text}`)})}),(c.length>Xl||s.data?.truncated)&&!a&&(0,$.jsxs)(`button`,{type:`button`,onClick:()=>o(!0),className:`unstyled mt-2 text-sm font-semibold text-sapphire hover:text-sapphire-deep`,children:[`Show all `,c.length,s.data?.truncated?`+`:``]})]})}var eu=[{view:`connections`,label:`Connections`,icon:Me},{view:`changes`,label:`Changes`,icon:Se},{view:`files`,label:`Files`,icon:de}],tu=`m-0 mb-2 mt-7 font-body text-xs font-bold uppercase tracking-[0.08em] text-muted-foreground`;function nu({team:e}){let{agents:t,profiles:n,teams:i,search:a}=z(),o=U(),[s,c]=(0,G.useState)(!1),l=t.filter(t=>t.teamId===e.id),u=ot(l.map(e=>o.stateOf(e.id))),d=ye(e.id),f=wo(e.id,{},4),p=be(e.id,50);return(0,$.jsxs)(`section`,{"aria-label":e.name,className:`flex h-full flex-col overflow-y-auto rounded-[16px] border border-border bg-card px-4 py-5 shadow-baziu-sm sm:px-8 sm:py-8`,children:[(0,$.jsxs)(`div`,{className:`mx-auto w-full max-w-2xl`,children:[(0,$.jsxs)(r,{to:`/`,search:{},className:`mb-4 inline-flex items-center gap-1.5 text-sm font-semibold lg:hidden`,children:[(0,$.jsx)(L,{className:`size-3.5`,"aria-hidden":`true`}),`All teams`]}),(0,$.jsx)(`h1`,{className:`m-0 font-display text-[1.9rem] leading-tight text-charcoal`,children:e.name}),(0,$.jsxs)(`p`,{className:`m-0 mt-1 text-sm text-mocha`,children:[l.length,` member`,l.length===1?``:`s`,u?` · ${u}`:``]}),l.length===0?(0,$.jsxs)(`div`,{className:`mt-6 rounded-2xl border border-dashed border-border bg-muted/40 px-5 py-8 text-center`,children:[(0,$.jsx)(`p`,{className:`m-0 text-sm font-semibold text-foreground`,children:`No Agents in this Team yet`}),(0,$.jsx)(`p`,{className:`m-0 mt-1 text-sm text-muted-foreground`,children:`Add the first one to start a conversation.`}),(0,$.jsxs)(g,{variant:`primary`,className:`mt-4`,onClick:()=>c(!0),children:[(0,$.jsx)(B,{className:`size-4`,"aria-hidden":`true`}),`Add an Agent`]})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`ul`,{className:`m-0 mt-5 list-none space-y-2 p-0`,children:l.map(e=>{let t=o.stateOf(e.id);return(0,$.jsx)(`li`,{children:(0,$.jsxs)(r,{to:`/`,search:{agent:e.id,...a.panel?{panel:a.panel}:{}},className:`flex min-h-16 items-center gap-3 rounded-2xl border border-border bg-card px-3.5 py-2.5 text-foreground shadow-baziu-sm hover:border-sapphire-light hover:bg-accent/30`,children:[(0,$.jsx)(H,{identity:e.identity,size:40}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsx)(`span`,{className:`block truncate text-base font-semibold`,children:e.name}),(0,$.jsxs)(`span`,{className:`mt-0.5 flex min-w-0 items-center gap-1.5 text-xs text-mocha`,children:[(0,$.jsx)(`span`,{className:`size-[7px] shrink-0 rounded-full ${xe[t.kind]}`,"aria-hidden":`true`}),(0,$.jsx)(`span`,{className:`min-w-0 truncate`,children:t.text})]})]}),(0,$.jsx)(`span`,{className:`shrink-0 text-xs font-semibold text-accent-foreground`,children:`Open`})]})},e.id)})}),(0,$.jsx)(`div`,{className:`mt-4`,children:(0,$.jsxs)(g,{variant:`ghost`,onClick:()=>c(!0),children:[(0,$.jsx)(B,{className:`size-4`,"aria-hidden":`true`}),`Add an Agent`]})})]}),l.length>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`h2`,{className:tu,children:`Today`}),(0,$.jsx)($l,{teamId:e.id})]}),(0,$.jsx)(`div`,{className:`mt-8 grid grid-cols-1 gap-2 sm:grid-cols-3`,children:eu.filter(({view:e})=>e!==`changes`||d.repository!==!1).map(({view:t,label:n,icon:i})=>(0,$.jsxs)(r,{to:`/`,search:{team:e.id,view:t},className:`flex min-h-16 items-center gap-2.5 rounded-2xl border border-border bg-muted/50 px-3 py-2.5 text-foreground hover:border-sapphire-light hover:bg-accent/30`,children:[(0,$.jsx)(i,{className:`size-[18px] shrink-0 text-mocha`,"aria-hidden":`true`}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`block text-sm font-semibold`,children:n}),(0,$.jsx)(`span`,{className:`block truncate text-xs text-mocha`,children:t===`connections`?`${Ot[e.policyMode]} · ${p.data?.length?`${p.data.length} message${p.data.length===1?``:`s`}`:`no messages yet`}`:t===`changes`?d.changes===null?`Not readable`:`${d.changes} changed file${d.changes===1?``:`s`}`:`${d.files??0} saved file${d.files===1?``:`s`}`})]})]},t))}),f.results.length>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`h2`,{className:tu,children:`Latest files`}),(0,$.jsx)(`div`,{className:`grid grid-cols-2 gap-2.5 sm:grid-cols-4`,children:f.results.map(n=>(0,$.jsx)(bo,{resultId:n.id,result:n,compact:!0,detail:t.find(e=>e.id===n.agentId)?.name,open:{team:e.id,view:`files`,result:n.id}},n.id))})]}),(p.data?.length??0)>0&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`h2`,{className:tu,children:`Lately between its Agents`}),(0,$.jsx)(Te,{messages:p.data??[],limit:4})]})]}),s&&(0,$.jsx)(Tt,{profiles:n,teams:i,teamId:e.id,onClose:()=>c(!1)})]})}var ru=3;function iu({className:e=``}){let{agents:t,teams:n}=z(),i=U(),a=t.map(e=>({agent:e,state:i.stateOf(e.id)})).filter(e=>e.state.kind===`needs`);if(a.length===0)return null;let o=new Map(n.map(e=>[e.id,e.name])),s=a.length-ru;return(0,$.jsxs)(`section`,{"aria-label":`Waiting for you`,className:`rounded-2xl border border-warning/40 bg-warning/10 px-3 py-2.5 shadow-baziu-sm ${e}`,children:[(0,$.jsxs)(`h2`,{className:`m-0 mb-1.5 flex items-center gap-1.5 font-body text-xs font-bold uppercase tracking-[0.08em] text-warning`,children:[(0,$.jsx)(Ke,{className:`size-3.5`,"aria-hidden":`true`}),`Waiting for you`]}),(0,$.jsx)(`ul`,{className:`m-0 flex list-none flex-col gap-1 p-0`,children:a.slice(0,ru).map(({agent:e,state:t})=>(0,$.jsx)(`li`,{children:(0,$.jsx)(au,{agent:e,team:o.get(e.teamId),text:t.text})},e.id))}),s>0&&(0,$.jsxs)(r,{to:`/attention`,className:`mt-1.5 inline-block text-sm font-semibold`,children:[s,` more in Attention`]})]})}function au({agent:e,team:t,text:n}){return(0,$.jsxs)(r,{to:`/`,search:{agent:e.id},className:`flex min-h-11 items-center gap-2.5 rounded-xl px-1.5 py-1 text-foreground hover:bg-card/70`,children:[(0,$.jsx)(H,{identity:e.identity,size:28}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`span`,{className:`block truncate text-sm font-semibold`,children:[e.name,t&&(0,$.jsxs)(`span`,{className:`font-normal text-mocha`,children:[` · `,t]})]}),(0,$.jsx)(`span`,{className:`block truncate text-xs text-warning`,children:n})]}),(0,$.jsx)(`span`,{className:`shrink-0 text-xs font-semibold text-accent-foreground`,children:`Open`})]})}var ou=(0,G.lazy)(()=>p(()=>import(`./ConnectionsView-BUZcfBHw.js`).then(e=>({default:e.ConnectionsView})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19])));function su(){let e=St.useLoaderData(),t=St.useSearch(),n=i(),{agents:a,teams:o,selected:s}=e,c=s?.resolved??null,l=c?.team??o.find(e=>e.id===t.team)??null,u=l?t.view:void 0,d=(0,G.useMemo)(()=>new Map(a.map(e=>[e.id,e.name])),[a]);f(u&&l?`${nt[u]} · ${l.name}`:c?[c.agent.name,l?.name].filter(Boolean).join(` · `):l?l.name:`Overview`);let[p,m]=(0,G.useState)(e.panel);(0,G.useEffect)(()=>{t.panel&&m(e=>{let n=t.panel===`none`?{open:!1,tab:e.tab}:{open:!0,tab:t.panel};return n.open===e.open&&n.tab===e.tab?e:(gt(n),n)})},[t.panel]);let h=t.panel??(p.open&&(c||l)?p.tab:`none`);(0,G.useEffect)(()=>{let e=e=>{if(e.defaultPrevented||document.querySelector(`[role="dialog"]`))return;let r=e.metaKey||e.ctrlKey;if(r&&e.key===`.`){e.preventDefault();let r=h!==`none`&&(g||window.matchMedia(`(min-width: 1280px)`).matches);n.navigate({to:`/`,search:{...t,panel:r?`none`:p.tab,section:void 0}});return}if(!(We(e.target)||r)){if(e.key===`/`&&!e.altKey){let t=document.querySelector(`[data-composer]`);if(!t)return;e.preventDefault(),t.focus();return}if(e.altKey&&(e.key===`ArrowDown`||e.key===`ArrowUp`)){let r=He(o.flatMap(e=>a.filter(t=>t.teamId===e.id)),c?.agent.id,e.key===`ArrowDown`?1:-1);if(!r)return;e.preventDefault(),n.navigate({to:`/`,search:{agent:r.id,...t.panel?{panel:t.panel}:{}}})}}};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)});let g=t.panel!==void 0&&t.panel!==`none`,_=Nt(`(min-width: 1280px)`),v=h!==`none`&&(g||_)?h:`none`,y=v!==`none`&&!_,b=(0,G.useRef)(null),x=(0,G.useRef)(null);(0,G.useLayoutEffect)(()=>{if(y)return x.current=Je(document),b.current?.querySelector(`[role="tab"][aria-selected="true"]`)?.focus(),()=>{let e=x.current;x.current=null,window.requestAnimationFrame(()=>at(e,document))}},[y]),(0,G.useEffect)(()=>{if(!y)return;let e=e=>{e.key!==`Escape`||e.defaultPrevented||document.querySelector(`[role="dialog"], [role="alertdialog"], [role="menu"]`)||(e.preventDefault(),n.navigate({to:`/`,search:{...t,panel:`none`,section:void 0}}))};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[y,n,t]);let[S,C]=(0,G.useState)(null),w=s?.head.conversationId??null,T=c&&S?.agentId===c.agent.id&&S.loaded===w?S.id:w,E=c&&t.conversation&&t.conversation!==T?t.conversation:null,D=c?E??T:null,k=(0,G.useMemo)(()=>({agents:a,teams:o,profiles:e.profiles,teamTemplates:e.teamTemplates,agent:c,team:l,conversationId:D,search:t}),[a,o,e.profiles,e.teamTemplates,c,l,D,t]),A=e=>c&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(Mc,{agent:c,chat:e,panel:v,lastPanel:p.tab}),c.agent.status===`archived`&&(0,$.jsxs)(`p`,{className:`m-0 flex flex-wrap items-center gap-2 border-b border-frost bg-warning/[0.07] px-4 py-2 text-sm text-chocolate`,children:[(0,$.jsx)(O,{variant:`warning`,children:`Archived`}),`This Agent receives no work. Restore it from its settings to talk to it again.`,(0,$.jsx)(r,{to:`/`,search:{...t,panel:`agent`},className:`font-semibold`,children:`Agent settings`})]})]});return(0,$.jsx)(vt,{initial:e.activity,openAgentId:u?null:c?.agent.id??null,names:d,children:(0,$.jsx)(Ee,{value:k,children:(0,$.jsxs)(za,{children:[u&&l?(0,$.jsxs)(`div`,{className:`grid h-full min-h-0 grid-cols-1 gap-3 py-3 sm:grid-cols-[4rem_minmax(0,1fr)]`,children:[(0,$.jsx)(`div`,{className:`hidden min-h-0 sm:block`,children:(0,$.jsx)(el,{})}),(0,$.jsx)(`div`,{className:`min-h-0 min-w-0`,children:u===`connections`?(0,$.jsx)(G.Suspense,{fallback:(0,$.jsx)(ge,{view:`connections`,children:(0,$.jsx)(`p`,{role:`status`,className:`m-4 text-sm text-muted-foreground`,children:`Loading the map…`})}),children:(0,$.jsx)(ou,{team:l},l.id)}):u===`changes`?(0,$.jsx)(Ko,{team:l},l.id):(0,$.jsx)(Dc,{team:l},l.id)})]}):(0,$.jsxs)(`div`,{className:`grid h-full min-h-0 grid-cols-1 gap-3 py-3 lg:grid-cols-[18rem_minmax(0,1fr)] ${h===`none`?``:`xl:grid-cols-[18rem_minmax(0,1fr)_minmax(22rem,27rem)]`}`,children:[(0,$.jsxs)(`div`,{inert:y||void 0,className:`flex min-h-0 flex-col gap-3 ${c||l?`hidden lg:flex`:``}`,children:[(0,$.jsx)(iu,{className:`lg:hidden`}),(0,$.jsx)(`div`,{className:`min-h-0 flex-1`,children:(0,$.jsx)($c,{initialOpenGroups:e.openGroups})})]}),(0,$.jsx)(`div`,{inert:y||void 0,className:`min-h-0 min-w-0 ${c||l?``:`hidden lg:block`}`,children:c&&s?E?(0,$.jsx)(Fc,{agentId:c.agent.id,agentName:c.agent.name,conversationId:E,header:A()},`${c.agent.id}:${E}`):(0,$.jsx)(Tc,{agentId:c.agent.id,agentName:c.agent.name,initialMessages:s.messages,initialSessionHead:s.head,header:A,onViewConversation:e=>void n.navigate({to:`/`,search:{...t,conversation:e}}),onConversationChange:e=>C({agentId:c.agent.id,loaded:w,id:e})}):l?(0,$.jsx)(nu,{team:l}):(0,$.jsx)(Bc,{})}),h!==`none`&&(0,$.jsxs)($.Fragment,{children:[g&&(0,$.jsx)(r,{to:`/`,search:{...t,panel:`none`,section:void 0},"aria-label":`Close the side panel`,className:`fixed inset-0 z-30 bg-chocolate/30 xl:hidden`}),(0,$.jsx)(`div`,{ref:b,className:g?`fixed inset-y-0 right-0 z-40 w-[min(27rem,100vw)] p-2 xl:static xl:z-auto xl:min-h-0 xl:w-auto xl:min-w-0 xl:p-0`:`hidden min-h-0 min-w-0 xl:block`,children:(0,$.jsx)(zo,{tab:h})})]})]}),(0,$.jsx)(Yl,{})]})})})}export{su as component};