@markus-global/cli 0.10.0-rc.0 → 0.10.0

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 (64) hide show
  1. package/dist/web-ui/assets/{CommentInput-DVEZsFdH.js → CommentInput-BqMnooel.js} +1 -1
  2. package/dist/web-ui/assets/{ContentRenderer-D7liy5Ei.js → ContentRenderer-DL45IlDu.js} +2 -2
  3. package/dist/web-ui/assets/{DeliverableShareModal-3Z6n5SPB.js → DeliverableShareModal-2BWwrD0B.js} +1 -1
  4. package/dist/web-ui/assets/{Deliverables-pJ0mZrCG.js → Deliverables-ZRYTt61i.js} +1 -1
  5. package/dist/web-ui/assets/{Notifications-B7m8KM5F.js → Notifications-DTWB_mkr.js} +1 -1
  6. package/dist/web-ui/assets/{Search-Dg1QnxMv.js → Search-CJotdd_7.js} +1 -1
  7. package/dist/web-ui/assets/{Settings-KeOQ8NBT.js → Settings-hOETMz7R.js} +1 -1
  8. package/dist/web-ui/assets/{Store-znN3kITL.js → Store-BA0EkZGV.js} +1 -1
  9. package/dist/web-ui/assets/{Team-B3HjBTMx.js → Team-D2FwZz_o.js} +4 -4
  10. package/dist/web-ui/assets/{Work-CLAetrCe.js → Work-DJOaN4GX.js} +1 -1
  11. package/dist/web-ui/assets/{arc-DLJKkSLU.js → arc-DHkGrr0f.js} +1 -1
  12. package/dist/web-ui/assets/{architectureDiagram-3BPJPVTR-CErxJL8z.js → architectureDiagram-3BPJPVTR-SV9bE7r9.js} +1 -1
  13. package/dist/web-ui/assets/{blockDiagram-GPEHLZMM-DhnC1GHJ.js → blockDiagram-GPEHLZMM-Bb1vRq1C.js} +1 -1
  14. package/dist/web-ui/assets/{c4Diagram-AAUBKEIU-CWcg6zCh.js → c4Diagram-AAUBKEIU-tcZyAXyl.js} +1 -1
  15. package/dist/web-ui/assets/channel-N52kezHF.js +1 -0
  16. package/dist/web-ui/assets/{chunk-2J33WTMH-BOcDAFHW.js → chunk-2J33WTMH-CJwLLa3C.js} +1 -1
  17. package/dist/web-ui/assets/{chunk-4BX2VUAB-Dc8q34rQ.js → chunk-4BX2VUAB-BOtdLqQJ.js} +1 -1
  18. package/dist/web-ui/assets/{chunk-55IACEB6-CjeuFc0_.js → chunk-55IACEB6-NQr5uRBA.js} +1 -1
  19. package/dist/web-ui/assets/{chunk-727SXJPM-DsyO9cPr.js → chunk-727SXJPM-B5zAoAuj.js} +1 -1
  20. package/dist/web-ui/assets/{chunk-AQP2D5EJ-DOhY_Zn6.js → chunk-AQP2D5EJ-D6ckRpUW.js} +1 -1
  21. package/dist/web-ui/assets/{chunk-FMBD7UC4-C4wQwaKj.js → chunk-FMBD7UC4-uWIbAJn7.js} +1 -1
  22. package/dist/web-ui/assets/{chunk-ND2GUHAM-DAxE9n6p.js → chunk-ND2GUHAM-DRoYVcWH.js} +1 -1
  23. package/dist/web-ui/assets/{chunk-QZHKN3VN-BqskBLc5.js → chunk-QZHKN3VN-TwjLbnMx.js} +1 -1
  24. package/dist/web-ui/assets/classDiagram-4FO5ZUOK-XkibfmWR.js +1 -0
  25. package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-XkibfmWR.js +1 -0
  26. package/dist/web-ui/assets/{cose-bilkent-S5V4N54A-q7ZrVkOv.js → cose-bilkent-S5V4N54A-BfQ_0liP.js} +1 -1
  27. package/dist/web-ui/assets/{dagre-BM42HDAG-CzpG9RNW.js → dagre-BM42HDAG-CU3dMbrI.js} +1 -1
  28. package/dist/web-ui/assets/{diagram-2AECGRRQ-Cq3sRUJD.js → diagram-2AECGRRQ-DYleVZiW.js} +1 -1
  29. package/dist/web-ui/assets/{diagram-5GNKFQAL-BZlWfVNc.js → diagram-5GNKFQAL-DykVmK0r.js} +1 -1
  30. package/dist/web-ui/assets/{diagram-KO2AKTUF-BR3FEkPK.js → diagram-KO2AKTUF-BIlHPMdB.js} +1 -1
  31. package/dist/web-ui/assets/{diagram-LMA3HP47-BhgVodCu.js → diagram-LMA3HP47-D70tKzYv.js} +1 -1
  32. package/dist/web-ui/assets/{diagram-OG6HWLK6-aEqNtQM7.js → diagram-OG6HWLK6-CV2Nu6ik.js} +1 -1
  33. package/dist/web-ui/assets/{docx-preview-BCUdrB1J.js → docx-preview-DL_6q0h-.js} +1 -1
  34. package/dist/web-ui/assets/{erDiagram-TEJ5UH35-CmKuqvTk.js → erDiagram-TEJ5UH35-Dzq3Vw8P.js} +1 -1
  35. package/dist/web-ui/assets/{flowDiagram-I6XJVG4X-B9PwU7vi.js → flowDiagram-I6XJVG4X-DGkcoQ60.js} +1 -1
  36. package/dist/web-ui/assets/{ganttDiagram-6RSMTGT7-D4eRLO6n.js → ganttDiagram-6RSMTGT7-BLQ3H0r3.js} +1 -1
  37. package/dist/web-ui/assets/{gitGraphDiagram-PVQCEYII-BX5vzMBG.js → gitGraphDiagram-PVQCEYII-DUmAstFU.js} +1 -1
  38. package/dist/web-ui/assets/index-B6fl84HP.js +882 -0
  39. package/dist/web-ui/assets/{infoDiagram-5YYISTIA-isLK7RCT.js → infoDiagram-5YYISTIA-CsXOZLwT.js} +1 -1
  40. package/dist/web-ui/assets/{ishikawaDiagram-YF4QCWOH-D_KwMIC_.js → ishikawaDiagram-YF4QCWOH-FxKhYmDc.js} +1 -1
  41. package/dist/web-ui/assets/{journeyDiagram-JHISSGLW-BERHrAd2.js → journeyDiagram-JHISSGLW-BlhEY13x.js} +1 -1
  42. package/dist/web-ui/assets/{kanban-definition-UN3LZRKU-iWhVeCEA.js → kanban-definition-UN3LZRKU-CBPhJXrD.js} +1 -1
  43. package/dist/web-ui/assets/{mermaid.core-DBb2SvbA.js → mermaid.core-DHGX5lHc.js} +5 -5
  44. package/dist/web-ui/assets/{mindmap-definition-RKZ34NQL-B1e7ShjO.js → mindmap-definition-RKZ34NQL-DBuFrFuP.js} +1 -1
  45. package/dist/web-ui/assets/{pieDiagram-4H26LBE5-CINLSMM2.js → pieDiagram-4H26LBE5-mWrxRhxJ.js} +1 -1
  46. package/dist/web-ui/assets/{quadrantDiagram-W4KKPZXB-5OsDJzw-.js → quadrantDiagram-W4KKPZXB-JFaiGibg.js} +1 -1
  47. package/dist/web-ui/assets/{requirementDiagram-4Y6WPE33-TckyECvk.js → requirementDiagram-4Y6WPE33-CVHcioJN.js} +1 -1
  48. package/dist/web-ui/assets/{sankeyDiagram-5OEKKPKP-BBUaDX49.js → sankeyDiagram-5OEKKPKP-BI8QYkQZ.js} +1 -1
  49. package/dist/web-ui/assets/{sequenceDiagram-3UESZ5HK-CDvlRmkY.js → sequenceDiagram-3UESZ5HK-DloeuaaF.js} +1 -1
  50. package/dist/web-ui/assets/{stateDiagram-AJRCARHV-KuO58ZEJ.js → stateDiagram-AJRCARHV-u1GtjbZs.js} +1 -1
  51. package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-DligGfEm.js +1 -0
  52. package/dist/web-ui/assets/{timeline-definition-PNZ67QCA-De3GteSx.js → timeline-definition-PNZ67QCA-CbhjCcpj.js} +1 -1
  53. package/dist/web-ui/assets/{vennDiagram-CIIHVFJN-B-XEM6Hx.js → vennDiagram-CIIHVFJN-CUKEb9oX.js} +1 -1
  54. package/dist/web-ui/assets/{wardley-L42UT6IY-DX7ioE-0.js → wardley-L42UT6IY-D64zeLnz.js} +1 -1
  55. package/dist/web-ui/assets/{wardleyDiagram-YWT4CUSO-BrOYIz-Z.js → wardleyDiagram-YWT4CUSO-BpbJymuq.js} +1 -1
  56. package/dist/web-ui/assets/{xychartDiagram-2RQKCTM6-CQANrcat.js → xychartDiagram-2RQKCTM6-Dt54kL4V.js} +1 -1
  57. package/dist/web-ui/index.html +1 -1
  58. package/package.json +1 -1
  59. package/templates/roles/data-analyst/ROLE.md +184 -0
  60. package/dist/web-ui/assets/channel-DXLppOOi.js +0 -1
  61. package/dist/web-ui/assets/classDiagram-4FO5ZUOK-Ugc4ArHR.js +0 -1
  62. package/dist/web-ui/assets/classDiagram-v2-Q7XG4LA2-Ugc4ArHR.js +0 -1
  63. package/dist/web-ui/assets/index-BrU2YO3p.js +0 -713
  64. package/dist/web-ui/assets/stateDiagram-v2-BHNVJYJU-DxZVvQnr.js +0 -1
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-BrU2YO3p.js","assets/index-CT8Kx3sa.css"])))=>i.map(i=>d[i]);
2
- import{r as _,k as zb,u as Qt,B as zw,j as c,q as ja,a2 as qw,a as Om,b as xm,P as Gt,c as kh,l as re,w as bt,M as Zw,A as Qs,n as yr,F as Po,i as bm,a3 as Vw,a4 as Fw,a5 as Uw,a6 as Hw,a7 as Yw,a8 as Ig,a9 as Vl,o as Bg,O as Gw,D as Kw,h as vm,d as qb,aa as Zb,ab as zc,ac as Jw,ad as Wg,ae as ek,W as tk,Y as Vb,X as Fb,H as sk,af as rk,ag as ik,_ as Ub,ah as nk,ai as ef,aj as Xg,ak as ok,al as zg,am as qg,an as Zg,ao as Vg,ap as Fg,aq as _n,ar as wc,as as kc,at as Ug,au as ak,av as lk,aw as ck,ax as hk,m as Hg,ay as Yg,az as dk,aA as uk,aB as Wd,aC as Gg,aD as Xd,aE as zd,aF as fk,C as Kg,aG as qd,aH as Fl,aI as Jg,aJ as mk,aK as pk,aL as gk,aM as eO,aN as Ok,aO as xk,aP as bk,aQ as vk,aR as yk,aS as Sk,aT as _k,aU as wk,aV as tO,aW as kk,aX as Ck,p as Pk,aY as Tk,aZ as Qk,a_ as $k,a$ as jk}from"./index-BrU2YO3p.js";import{p as Ek,r as sO}from"./CommentInput-DVEZsFdH.js";import{ContentRenderer as tf,resolveFormat as Rk}from"./ContentRenderer-D7liy5Ei.js";import{a as Ak,c as Mk,D as Lk}from"./DeliverableShareModal-3Z6n5SPB.js";function Yn(s,e,t){let r=t.initialDeps??[],i,n=!0;function a(){var o,l,h;let d;t.key&&((o=t.debug)!=null&&o.call(t))&&(d=Date.now());const u=s();if(!(u.length!==r.length||u.some((b,v)=>r[v]!==b)))return i;r=u;let p;if(t.key&&((l=t.debug)!=null&&l.call(t))&&(p=Date.now()),i=e(...u),t.key&&((h=t.debug)!=null&&h.call(t))){const b=Math.round((Date.now()-d)*100)/100,v=Math.round((Date.now()-p)*100)/100,g=v/16,O=(m,x)=>{for(m=String(m);m.length<x;)m=" "+m;return m};console.info(`%c⏱ ${O(v,5)} /${O(b,5)} ms`,`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-B6fl84HP.js","assets/index-CT8Kx3sa.css"])))=>i.map(i=>d[i]);
2
+ import{r as _,k as zb,u as Qt,B as zw,j as c,q as ja,a2 as qw,a as Om,b as xm,P as Gt,c as kh,l as re,w as bt,M as Zw,A as Qs,n as yr,F as Po,i as bm,a3 as Vw,a4 as Fw,a5 as Uw,a6 as Hw,a7 as Yw,a8 as Ig,a9 as Vl,o as Bg,O as Gw,D as Kw,h as vm,d as qb,aa as Zb,ab as zc,ac as Jw,ad as Wg,ae as ek,W as tk,Y as Vb,X as Fb,H as sk,af as rk,ag as ik,_ as Ub,ah as nk,ai as ef,aj as Xg,ak as ok,al as zg,am as qg,an as Zg,ao as Vg,ap as Fg,aq as _n,ar as wc,as as kc,at as Ug,au as ak,av as lk,aw as ck,ax as hk,m as Hg,ay as Yg,az as dk,aA as uk,aB as Wd,aC as Gg,aD as Xd,aE as zd,aF as fk,C as Kg,aG as qd,aH as Fl,aI as Jg,aJ as mk,aK as pk,aL as gk,aM as eO,aN as Ok,aO as xk,aP as bk,aQ as vk,aR as yk,aS as Sk,aT as _k,aU as wk,aV as tO,aW as kk,aX as Ck,p as Pk,aY as Tk,aZ as Qk,a_ as $k,a$ as jk}from"./index-B6fl84HP.js";import{p as Ek,r as sO}from"./CommentInput-BqMnooel.js";import{ContentRenderer as tf,resolveFormat as Rk}from"./ContentRenderer-DL45IlDu.js";import{a as Ak,c as Mk,D as Lk}from"./DeliverableShareModal-2BWwrD0B.js";function Yn(s,e,t){let r=t.initialDeps??[],i,n=!0;function a(){var o,l,h;let d;t.key&&((o=t.debug)!=null&&o.call(t))&&(d=Date.now());const u=s();if(!(u.length!==r.length||u.some((b,v)=>r[v]!==b)))return i;r=u;let p;if(t.key&&((l=t.debug)!=null&&l.call(t))&&(p=Date.now()),i=e(...u),t.key&&((h=t.debug)!=null&&h.call(t))){const b=Math.round((Date.now()-d)*100)/100,v=Math.round((Date.now()-p)*100)/100,g=v/16,O=(m,x)=>{for(m=String(m);m.length<x;)m=" "+m;return m};console.info(`%c⏱ ${O(v,5)} /${O(b,5)} ms`,`
3
3
  font-size: .6rem;
4
4
  font-weight: bold;
5
5
  color: hsl(${Math.max(0,Math.min(120-120*g,120))}deg 100% 31%);`,t?.key)}return t?.onChange&&!(n&&t.skipInitialOnChange)&&t.onChange(i),n=!1,i}return a.updateDeps=o=>{r=o},a}function rO(s,e){if(s===void 0)throw new Error("Unexpected undefined");return s}const Nk=(s,e)=>Math.abs(s-e)<1.01,Dk=(s,e,t)=>{let r;return function(...i){s.clearTimeout(r),r=s.setTimeout(()=>e.apply(this,i),t)}},iO=s=>{const{offsetWidth:e,offsetHeight:t}=s;return{width:e,height:t}},Ik=s=>s,Bk=s=>{const e=Math.max(s.startIndex-s.overscan,0),t=Math.min(s.endIndex+s.overscan,s.count-1),r=[];for(let i=e;i<=t;i++)r.push(i);return r},Wk=(s,e)=>{const t=s.scrollElement;if(!t)return;const r=s.targetWindow;if(!r)return;const i=a=>{const{width:o,height:l}=a;e({width:Math.round(o),height:Math.round(l)})};if(i(iO(t)),!r.ResizeObserver)return()=>{};const n=new r.ResizeObserver(a=>{const o=()=>{const l=a[0];if(l?.borderBoxSize){const h=l.borderBoxSize[0];if(h){i({width:h.inlineSize,height:h.blockSize});return}}i(iO(t))};s.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(o):o()});return n.observe(t,{box:"border-box"}),()=>{n.unobserve(t)}},nO={passive:!0},oO=typeof window>"u"?!0:"onscrollend"in window,Xk=(s,e)=>{const t=s.scrollElement;if(!t)return;const r=s.targetWindow;if(!r)return;let i=0;const n=s.options.useScrollendEvent&&oO?()=>{}:Dk(r,()=>{e(i,!1)},s.options.isScrollingResetDelay),a=d=>()=>{const{horizontal:u,isRtl:f}=s.options;i=u?t.scrollLeft*(f&&-1||1):t.scrollTop,n(),e(i,d)},o=a(!0),l=a(!1);t.addEventListener("scroll",o,nO);const h=s.options.useScrollendEvent&&oO;return h&&t.addEventListener("scrollend",l,nO),()=>{t.removeEventListener("scroll",o),h&&t.removeEventListener("scrollend",l)}},zk=(s,e,t)=>{if(e?.borderBoxSize){const r=e.borderBoxSize[0];if(r)return Math.round(r[t.options.horizontal?"inlineSize":"blockSize"])}return s[t.options.horizontal?"offsetWidth":"offsetHeight"]},qk=(s,{adjustments:e=0,behavior:t},r)=>{var i,n;const a=s+e;(n=(i=r.scrollElement)==null?void 0:i.scrollTo)==null||n.call(i,{[r.options.horizontal?"left":"top"]:a,behavior:t})};class Zk{constructor(e){this.unsubs=[],this.scrollElement=null,this.targetWindow=null,this.isScrolling=!1,this.scrollState=null,this.measurementsCache=[],this.itemSizeCache=new Map,this.laneAssignments=new Map,this.pendingMeasuredCacheIndexes=[],this.prevLanes=void 0,this.lanesChangedFlag=!1,this.lanesSettling=!1,this.scrollRect=null,this.scrollOffset=null,this.scrollDirection=null,this.scrollAdjustments=0,this.elementsCache=new Map,this.now=()=>{var t,r,i;return((i=(r=(t=this.targetWindow)==null?void 0:t.performance)==null?void 0:r.now)==null?void 0:i.call(r))??Date.now()},this.observer=(()=>{let t=null;const r=()=>t||(!this.targetWindow||!this.targetWindow.ResizeObserver?null:t=new this.targetWindow.ResizeObserver(i=>{i.forEach(n=>{const a=()=>{const o=n.target,l=this.indexFromElement(o);if(!o.isConnected){this.observer.unobserve(o);return}this.shouldMeasureDuringScroll(l)&&this.resizeItem(l,this.options.measureElement(o,n,this))};this.options.useAnimationFrameWithResizeObserver?requestAnimationFrame(a):a()})}));return{disconnect:()=>{var i;(i=r())==null||i.disconnect(),t=null},observe:i=>{var n;return(n=r())==null?void 0:n.observe(i,{box:"border-box"})},unobserve:i=>{var n;return(n=r())==null?void 0:n.unobserve(i)}}})(),this.range=null,this.setOptions=t=>{Object.entries(t).forEach(([r,i])=>{typeof i>"u"&&delete t[r]}),this.options={debug:!1,initialOffset:0,overscan:1,paddingStart:0,paddingEnd:0,scrollPaddingStart:0,scrollPaddingEnd:0,horizontal:!1,getItemKey:Ik,rangeExtractor:Bk,onChange:()=>{},measureElement:zk,initialRect:{width:0,height:0},scrollMargin:0,gap:0,indexAttribute:"data-index",initialMeasurementsCache:[],lanes:1,isScrollingResetDelay:150,enabled:!0,isRtl:!1,useScrollendEvent:!1,useAnimationFrameWithResizeObserver:!1,laneAssignmentMode:"estimate",...t}},this.notify=t=>{var r,i;(i=(r=this.options).onChange)==null||i.call(r,this,t)},this.maybeNotify=Yn(()=>(this.calculateRange(),[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]),t=>{this.notify(t)},{key:!1,debug:()=>this.options.debug,initialDeps:[this.isScrolling,this.range?this.range.startIndex:null,this.range?this.range.endIndex:null]}),this.cleanup=()=>{this.unsubs.filter(Boolean).forEach(t=>t()),this.unsubs=[],this.observer.disconnect(),this.rafId!=null&&this.targetWindow&&(this.targetWindow.cancelAnimationFrame(this.rafId),this.rafId=null),this.scrollState=null,this.scrollElement=null,this.targetWindow=null},this._didMount=()=>()=>{this.cleanup()},this._willUpdate=()=>{var t;const r=this.options.enabled?this.options.getScrollElement():null;if(this.scrollElement!==r){if(this.cleanup(),!r){this.maybeNotify();return}this.scrollElement=r,this.scrollElement&&"ownerDocument"in this.scrollElement?this.targetWindow=this.scrollElement.ownerDocument.defaultView:this.targetWindow=((t=this.scrollElement)==null?void 0:t.window)??null,this.elementsCache.forEach(i=>{this.observer.observe(i)}),this.unsubs.push(this.options.observeElementRect(this,i=>{this.scrollRect=i,this.maybeNotify()})),this.unsubs.push(this.options.observeElementOffset(this,(i,n)=>{this.scrollAdjustments=0,this.scrollDirection=n?this.getScrollOffset()<i?"forward":"backward":null,this.scrollOffset=i,this.isScrolling=n,this.scrollState&&this.scheduleScrollReconcile(),this.maybeNotify()})),this._scrollToOffset(this.getScrollOffset(),{adjustments:void 0,behavior:void 0})}},this.rafId=null,this.getSize=()=>this.options.enabled?(this.scrollRect=this.scrollRect??this.options.initialRect,this.scrollRect[this.options.horizontal?"width":"height"]):(this.scrollRect=null,0),this.getScrollOffset=()=>this.options.enabled?(this.scrollOffset=this.scrollOffset??(typeof this.options.initialOffset=="function"?this.options.initialOffset():this.options.initialOffset),this.scrollOffset):(this.scrollOffset=null,0),this.getFurthestMeasurement=(t,r)=>{const i=new Map,n=new Map;for(let a=r-1;a>=0;a--){const o=t[a];if(i.has(o.lane))continue;const l=n.get(o.lane);if(l==null||o.end>l.end?n.set(o.lane,o):o.end<l.end&&i.set(o.lane,!0),i.size===this.options.lanes)break}return n.size===this.options.lanes?Array.from(n.values()).sort((a,o)=>a.end===o.end?a.index-o.index:a.end-o.end)[0]:void 0},this.getMeasurementOptions=Yn(()=>[this.options.count,this.options.paddingStart,this.options.scrollMargin,this.options.getItemKey,this.options.enabled,this.options.lanes,this.options.laneAssignmentMode],(t,r,i,n,a,o,l)=>(this.prevLanes!==void 0&&this.prevLanes!==o&&(this.lanesChangedFlag=!0),this.prevLanes=o,this.pendingMeasuredCacheIndexes=[],{count:t,paddingStart:r,scrollMargin:i,getItemKey:n,enabled:a,lanes:o,laneAssignmentMode:l}),{key:!1}),this.getMeasurements=Yn(()=>[this.getMeasurementOptions(),this.itemSizeCache],({count:t,paddingStart:r,scrollMargin:i,getItemKey:n,enabled:a,lanes:o,laneAssignmentMode:l},h)=>{if(!a)return this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),[];if(this.laneAssignments.size>t)for(const p of this.laneAssignments.keys())p>=t&&this.laneAssignments.delete(p);this.lanesChangedFlag&&(this.lanesChangedFlag=!1,this.lanesSettling=!0,this.measurementsCache=[],this.itemSizeCache.clear(),this.laneAssignments.clear(),this.pendingMeasuredCacheIndexes=[]),this.measurementsCache.length===0&&!this.lanesSettling&&(this.measurementsCache=this.options.initialMeasurementsCache,this.measurementsCache.forEach(p=>{this.itemSizeCache.set(p.key,p.size)}));const d=this.lanesSettling?0:this.pendingMeasuredCacheIndexes.length>0?Math.min(...this.pendingMeasuredCacheIndexes):0;this.pendingMeasuredCacheIndexes=[],this.lanesSettling&&this.measurementsCache.length===t&&(this.lanesSettling=!1);const u=this.measurementsCache.slice(0,d),f=new Array(o).fill(void 0);for(let p=0;p<d;p++){const b=u[p];b&&(f[b.lane]=p)}for(let p=d;p<t;p++){const b=n(p),v=this.laneAssignments.get(p);let g,O;const m=l==="estimate"||h.has(b);if(v!==void 0&&this.options.lanes>1){g=v;const C=f[g],P=C!==void 0?u[C]:void 0;O=P?P.end+this.options.gap:r+i}else{const C=this.options.lanes===1?u[p-1]:this.getFurthestMeasurement(u,p);O=C?C.end+this.options.gap:r+i,g=C?C.lane:p%this.options.lanes,this.options.lanes>1&&m&&this.laneAssignments.set(p,g)}const x=h.get(b),y=typeof x=="number"?x:this.options.estimateSize(p),w=O+y;u[p]={index:p,start:O,size:y,end:w,key:b,lane:g},f[g]=p}return this.measurementsCache=u,u},{key:!1,debug:()=>this.options.debug}),this.calculateRange=Yn(()=>[this.getMeasurements(),this.getSize(),this.getScrollOffset(),this.options.lanes],(t,r,i,n)=>this.range=t.length>0&&r>0?Vk({measurements:t,outerSize:r,scrollOffset:i,lanes:n}):null,{key:!1,debug:()=>this.options.debug}),this.getVirtualIndexes=Yn(()=>{let t=null,r=null;const i=this.calculateRange();return i&&(t=i.startIndex,r=i.endIndex),this.maybeNotify.updateDeps([this.isScrolling,t,r]),[this.options.rangeExtractor,this.options.overscan,this.options.count,t,r]},(t,r,i,n,a)=>n===null||a===null?[]:t({startIndex:n,endIndex:a,overscan:r,count:i}),{key:!1,debug:()=>this.options.debug}),this.indexFromElement=t=>{const r=this.options.indexAttribute,i=t.getAttribute(r);return i?parseInt(i,10):(console.warn(`Missing attribute name '${r}={index}' on measured element.`),-1)},this.shouldMeasureDuringScroll=t=>{var r;if(!this.scrollState||this.scrollState.behavior!=="smooth")return!0;const i=this.scrollState.index??((r=this.getVirtualItemForOffset(this.scrollState.lastTargetOffset))==null?void 0:r.index);if(i!==void 0&&this.range){const n=Math.max(this.options.overscan,Math.ceil((this.range.endIndex-this.range.startIndex)/2)),a=Math.max(0,i-n),o=Math.min(this.options.count-1,i+n);return t>=a&&t<=o}return!0},this.measureElement=t=>{if(!t){this.elementsCache.forEach((a,o)=>{a.isConnected||(this.observer.unobserve(a),this.elementsCache.delete(o))});return}const r=this.indexFromElement(t),i=this.options.getItemKey(r),n=this.elementsCache.get(i);n!==t&&(n&&this.observer.unobserve(n),this.observer.observe(t),this.elementsCache.set(i,t)),(!this.isScrolling||this.scrollState)&&this.shouldMeasureDuringScroll(r)&&this.resizeItem(r,this.options.measureElement(t,void 0,this))},this.resizeItem=(t,r)=>{var i;const n=this.measurementsCache[t];if(!n)return;const a=this.itemSizeCache.get(n.key)??n.size,o=r-a;o!==0&&(((i=this.scrollState)==null?void 0:i.behavior)!=="smooth"&&(this.shouldAdjustScrollPositionOnItemSizeChange!==void 0?this.shouldAdjustScrollPositionOnItemSizeChange(n,o,this):n.start<this.getScrollOffset()+this.scrollAdjustments)&&this._scrollToOffset(this.getScrollOffset(),{adjustments:this.scrollAdjustments+=o,behavior:void 0}),this.pendingMeasuredCacheIndexes.push(n.index),this.itemSizeCache=new Map(this.itemSizeCache.set(n.key,r)),this.notify(!1))},this.getVirtualItems=Yn(()=>[this.getVirtualIndexes(),this.getMeasurements()],(t,r)=>{const i=[];for(let n=0,a=t.length;n<a;n++){const o=t[n],l=r[o];i.push(l)}return i},{key:!1,debug:()=>this.options.debug}),this.getVirtualItemForOffset=t=>{const r=this.getMeasurements();if(r.length!==0)return rO(r[Hb(0,r.length-1,i=>rO(r[i]).start,t)])},this.getMaxScrollOffset=()=>{if(!this.scrollElement)return 0;if("scrollHeight"in this.scrollElement)return this.options.horizontal?this.scrollElement.scrollWidth-this.scrollElement.clientWidth:this.scrollElement.scrollHeight-this.scrollElement.clientHeight;{const t=this.scrollElement.document.documentElement;return this.options.horizontal?t.scrollWidth-this.scrollElement.innerWidth:t.scrollHeight-this.scrollElement.innerHeight}},this.getOffsetForAlignment=(t,r,i=0)=>{if(!this.scrollElement)return 0;const n=this.getSize(),a=this.getScrollOffset();r==="auto"&&(r=t>=a+n?"end":"start"),r==="center"?t+=(i-n)/2:r==="end"&&(t-=n);const o=this.getMaxScrollOffset();return Math.max(Math.min(o,t),0)},this.getOffsetForIndex=(t,r="auto")=>{t=Math.max(0,Math.min(t,this.options.count-1));const i=this.getSize(),n=this.getScrollOffset(),a=this.measurementsCache[t];if(!a)return;if(r==="auto")if(a.end>=n+i-this.options.scrollPaddingEnd)r="end";else if(a.start<=n+this.options.scrollPaddingStart)r="start";else return[n,r];if(r==="end"&&t===this.options.count-1)return[this.getMaxScrollOffset(),r];const o=r==="end"?a.end+this.options.scrollPaddingEnd:a.start-this.options.scrollPaddingStart;return[this.getOffsetForAlignment(o,r,a.size),r]},this.scrollToOffset=(t,{align:r="start",behavior:i="auto"}={})=>{const n=this.getOffsetForAlignment(t,r),a=this.now();this.scrollState={index:null,align:r,behavior:i,startedAt:a,lastTargetOffset:n,stableFrames:0},this._scrollToOffset(n,{adjustments:void 0,behavior:i}),this.scheduleScrollReconcile()},this.scrollToIndex=(t,{align:r="auto",behavior:i="auto"}={})=>{t=Math.max(0,Math.min(t,this.options.count-1));const n=this.getOffsetForIndex(t,r);if(!n)return;const[a,o]=n,l=this.now();this.scrollState={index:t,align:o,behavior:i,startedAt:l,lastTargetOffset:a,stableFrames:0},this._scrollToOffset(a,{adjustments:void 0,behavior:i}),this.scheduleScrollReconcile()},this.scrollBy=(t,{behavior:r="auto"}={})=>{const i=this.getScrollOffset()+t,n=this.now();this.scrollState={index:null,align:"start",behavior:r,startedAt:n,lastTargetOffset:i,stableFrames:0},this._scrollToOffset(i,{adjustments:void 0,behavior:r}),this.scheduleScrollReconcile()},this.getTotalSize=()=>{var t;const r=this.getMeasurements();let i;if(r.length===0)i=this.options.paddingStart;else if(this.options.lanes===1)i=((t=r[r.length-1])==null?void 0:t.end)??0;else{const n=Array(this.options.lanes).fill(null);let a=r.length-1;for(;a>=0&&n.some(o=>o===null);){const o=r[a];n[o.lane]===null&&(n[o.lane]=o.end),a--}i=Math.max(...n.filter(o=>o!==null))}return Math.max(i-this.options.scrollMargin+this.options.paddingEnd,0)},this._scrollToOffset=(t,{adjustments:r,behavior:i})=>{this.options.scrollToFn(t,{behavior:i,adjustments:r},this)},this.measure=()=>{this.itemSizeCache=new Map,this.laneAssignments=new Map,this.notify(!1)},this.setOptions(e)}scheduleScrollReconcile(){if(!this.targetWindow){this.scrollState=null;return}this.rafId==null&&(this.rafId=this.targetWindow.requestAnimationFrame(()=>{this.rafId=null,this.reconcileScroll()}))}reconcileScroll(){if(!this.scrollState||!this.scrollElement)return;if(this.now()-this.scrollState.startedAt>5e3){this.scrollState=null;return}const r=this.scrollState.index!=null?this.getOffsetForIndex(this.scrollState.index,this.scrollState.align):void 0,i=r?r[0]:this.scrollState.lastTargetOffset,n=1,a=i!==this.scrollState.lastTargetOffset;if(!a&&Nk(i,this.getScrollOffset())){if(this.scrollState.stableFrames++,this.scrollState.stableFrames>=n){this.scrollState=null;return}}else this.scrollState.stableFrames=0,a&&(this.scrollState.lastTargetOffset=i,this.scrollState.behavior="auto",this._scrollToOffset(i,{adjustments:void 0,behavior:"auto"}));this.scheduleScrollReconcile()}}const Hb=(s,e,t,r)=>{for(;s<=e;){const i=(s+e)/2|0,n=t(i);if(n<r)s=i+1;else if(n>r)e=i-1;else return i}return s>0?s-1:0};function Vk({measurements:s,outerSize:e,scrollOffset:t,lanes:r}){const i=s.length-1,n=l=>s[l].start;if(s.length<=r)return{startIndex:0,endIndex:i};let a=Hb(0,i,n,t),o=a;if(r===1)for(;o<i&&s[o].end<t+e;)o++;else if(r>1){const l=Array(r).fill(0);for(;o<i&&l.some(d=>d<t+e);){const d=s[o];l[d.lane]=d.end,o++}const h=Array(r).fill(t+e);for(;a>=0&&h.some(d=>d>=t);){const d=s[a];h[d.lane]=d.start,a--}a=Math.max(0,a-a%r),o=Math.min(i,o+(r-1-o%r))}return{startIndex:a,endIndex:o}}const aO=typeof document<"u"?_.useLayoutEffect:_.useEffect;function Fk({useFlushSync:s=!0,...e}){const t=_.useReducer(()=>({}),{})[1],r={...e,onChange:(n,a)=>{var o;s&&a?zb.flushSync(t):t(),(o=e.onChange)==null||o.call(e,n,a)}},[i]=_.useState(()=>new Zk(r));return i.setOptions(r),aO(()=>i._didMount(),[]),aO(()=>i._willUpdate()),i}function Uk(s){return Fk({observeElementRect:Wk,observeElementOffset:Xk,scrollToFn:qk,...s})}const lO={urgent:"bg-red-500/15 text-red-500",high:"bg-amber-500/15 text-amber-600",normal:"bg-blue-500/15 text-blue-500",low:"bg-surface-overlay text-fg-tertiary"};function Hk({notification:s,agentName:e,acknowledging:t,onClose:r,onAcknowledge:i}){const{t:n}=Qt(["team","common"]);zw(!0);const a=s.priority||"normal",o=s.metadata??{},l=e||(typeof o.agentName=="string"?o.agentName:void 0);return zb.createPortal(c.jsx("div",{className:"fixed inset-0 z-[10000] flex items-center justify-center p-4 bg-black/50 backdrop-blur-sm",onMouseDown:h=>{h.target===h.currentTarget&&r()},children:c.jsxs("div",{className:"w-full max-w-2xl max-h-[85vh] flex flex-col bg-surface-secondary border border-border-default rounded-2xl shadow-2xl overflow-hidden",children:[c.jsxs("div",{className:"flex items-start gap-3 px-6 py-4 border-b border-border-default shrink-0",children:[c.jsx("div",{className:"w-9 h-9 rounded-lg bg-blue-500/15 text-blue-500 flex items-center justify-center shrink-0",children:c.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"}),c.jsx("path",{d:"M13.73 21a2 2 0 0 1-3.46 0"})]})}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsx("h2",{className:"text-base font-semibold text-fg-primary leading-snug",children:s.title}),c.jsxs("div",{className:"flex items-center gap-2 mt-0.5 flex-wrap",children:[l&&c.jsx("p",{className:"text-xs text-fg-tertiary",children:l}),a!=="normal"&&c.jsx("span",{className:`inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-medium ${lO[a]??lO.normal}`,children:a})]})]}),c.jsx("button",{onClick:r,className:"p-1.5 text-fg-tertiary hover:text-fg-primary rounded-md hover:bg-surface-overlay transition-colors shrink-0",title:n("common:close"),children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M18 6L6 18"}),c.jsx("path",{d:"M6 6l12 12"})]})})]}),c.jsx("div",{className:"flex-1 overflow-y-auto px-6 py-5",children:c.jsx("div",{className:"text-sm text-fg-primary leading-relaxed",children:c.jsx(ja,{content:s.body||""})})}),c.jsxs("div",{className:"flex items-center justify-end gap-2 px-6 py-4 border-t border-border-default shrink-0",children:[c.jsx("button",{onClick:r,className:"px-3.5 py-2 text-sm text-fg-secondary hover:text-fg-primary rounded-lg hover:bg-surface-overlay transition-colors",children:n("common:close")}),c.jsx("button",{onClick:()=>{i()},disabled:t,className:"px-4 py-2 text-sm font-medium text-white bg-blue-600 hover:bg-blue-500 disabled:opacity-50 rounded-lg transition-colors",children:t?n("common:loading"):n("page.notifyUserGotIt",{ns:"team",defaultValue:"Got it"})})]})]})}),document.body)}const Yb=12,Zd=400,Yk=4,Gk=350;function Gb(s){return Math.max(0,s.scrollHeight-s.clientHeight)}function cO(s){return Gb(s)>1}function sf(s){return Gb(s)-s.scrollTop}function Kk(s){return sf(s)<=Yb}function Jk(s,e){return Math.abs(e)<=Math.abs(s)?"none":e<0?"up":e>0?"down":"none"}const eC=new Set(["ArrowUp","PageUp","Home"]),tC=new Set(["ArrowDown","PageDown","End"]);function sC(s){return eC.has(s)?"up":tC.has(s)?"down":"none"}function rC(s,e){return s==null?"none":e>s+1?"up":e<s-1?"down":"none"}function iC(s){return s.scrollable?s.takeover?s.gestureDirection==="up"?"hold":s.distance<=Yb?"resume":"hold":s.gestureDirection==="up"&&s.gestureActive||!s.programmatic&&s.deltaScrollTop<-4?"handover":"follow":s.takeover?"resume":"follow"}function nC(s){return!s.takeover&&!s.gestureActive}function oC(s,e){return e&&s==="up"}function Gn(s,e){return`${s||"_"}::${e??""}`}function aC(s,e){let t=null;for(const r of s)r.start>e+1||(!t||r.start>t.start)&&(t=r);return t??s[0]??null}function lC(s,e){if(Kk(e))return{kind:"bottom"};const t=aC(s,e.scrollTop);return t?{kind:"row",id:t.id,delta:e.scrollTop-t.start}:{kind:"bottom"}}function cC(s,e){return s+e}function hC(s){const e=s.getBoundingClientRect().top,t=s.scrollTop,r=[];for(const i of Array.from(s.querySelectorAll("[data-index]"))){const a=i.querySelector('[id^="msg-"]')?.id?.slice(4);a&&r.push({id:a,start:t+(i.getBoundingClientRect().top-e)})}return r.sort((i,n)=>i.start-n.start),r}function dC(s,e){const t=s.getBoundingClientRect().top,r=`msg-${e}`;for(const i of Array.from(s.querySelectorAll('[id^="msg-"]')))if(i.id===r)return i.getBoundingClientRect().top-t;return null}class uC{constructor(e=120){this.capacity=e}entries=new Map;save(e,t){if(e)for(this.entries.delete(e),this.entries.set(e,t);this.entries.size>this.capacity;){const r=this.entries.keys().next();if(r.done)break;this.entries.delete(r.value)}}get(e){if(!e)return null;const t=this.entries.get(e);return t?(this.entries.delete(e),this.entries.set(e,t),t):null}delete(e){this.entries.delete(e)}clear(){this.entries.clear()}get size(){return this.entries.size}}const hO=new uC,fC=1e4;function mC(s,e){return e-s>fC}function Ea({children:s,onClose:e,title:t,width:r="w-[440px]"}){return c.jsx("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-50",onClick:e,children:c.jsxs("div",{className:`bg-surface-secondary border border-border-default rounded-xl p-6 ${r} shadow-2xl max-h-[90vh] overflow-y-auto`,onClick:i=>i.stopPropagation(),children:[c.jsx("h3",{className:"text-base font-semibold mb-5",children:t}),s]})})}function oo({label:s,children:e}){return c.jsxs("div",{children:[c.jsx("label",{className:"block text-xs text-fg-secondary mb-1.5 font-medium",children:s}),e]})}function pC({onClose:s,onCreate:e}){const{t}=Qt(["team","common"]),[r,i]=_.useState(""),[n,a]=_.useState("");return c.jsx(Ea,{onClose:s,title:t("team:modals.createTeam.title"),children:c.jsxs("div",{className:"space-y-4",children:[c.jsx(oo,{label:t("team:modals.createTeam.teamName"),children:c.jsx("input",{value:r,onChange:o=>i(o.target.value),placeholder:t("team:modals.createTeam.teamNamePlaceholder"),className:"input",autoFocus:!0,onKeyDown:o=>{o.key==="Enter"&&r.trim()&&e(r.trim(),n.trim()||void 0)}})}),c.jsx(oo,{label:t("team:modals.createTeam.description"),children:c.jsx("textarea",{value:n,onChange:o=>a(o.target.value),placeholder:t("team:modals.createTeam.descriptionPlaceholder"),className:"input",rows:2})}),c.jsx("div",{className:"text-xs text-fg-tertiary",children:t("team:modals.createTeam.hint")}),c.jsx("div",{className:"text-xs text-fg-tertiary bg-brand-500/5 border border-brand-500/20 rounded-lg px-3 py-2",children:c.jsx(qw,{i18nKey:"modals.createTeam.tipTrans",ns:"team",components:{0:c.jsx("span",{className:"text-brand-400 font-medium"}),1:c.jsx("span",{className:"text-brand-400"})}})}),c.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[c.jsx("button",{onClick:s,className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated",children:t("common:cancel")}),c.jsx("button",{onClick:()=>r.trim()&&e(r.trim(),n.trim()||void 0),disabled:!r.trim(),className:"px-4 py-2 text-sm bg-brand-600 hover:bg-brand-500 disabled:opacity-40 rounded-lg text-white",children:t("team:modals.createTeam.createTeam")})]})]})})}function gC({onClose:s,onAdd:e}){const{t}=Qt(["team","common"]),[r,i]=_.useState(""),[n,a]=_.useState("member"),[o,l]=_.useState(""),[h,d]=_.useState(""),[u,f]=_.useState(!1),[p,b]=_.useState(null),[v,g]=_.useState(!1),O=p?.inviteToken?`${window.location.origin}/#invite?token=${p.inviteToken}`:null,m=async()=>{if(d(""),!r.trim()){d(t("team:modals.addHuman.nameRequired"));return}if(!o.trim()){d(t("team:modals.addHuman.emailRequired"));return}if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(o.trim())){d(t("team:modals.addHuman.invalidEmail"));return}f(!0);try{const y=await e(r.trim(),n,o.trim());b({...y,userName:r.trim()})}catch(y){d(y instanceof Error?y.message:String(y))}finally{f(!1)}},x=()=>{O&&(navigator.clipboard.writeText(O),g(!0),setTimeout(()=>g(!1),2e3))};return p?c.jsxs(Ea,{onClose:s,title:t("team:modals.addHuman.title"),width:"w-[460px]",children:[c.jsxs("div",{className:"text-center py-4",children:[c.jsx("div",{className:"w-12 h-12 rounded-full bg-green-600/20 flex items-center justify-center mx-auto mb-3",children:c.jsx("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-green-500",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})})}),c.jsx("div",{className:"text-base font-medium mb-1",children:t("team:modals.addHuman.memberCreated",{name:p.userName})}),O?c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"text-xs text-fg-secondary mt-1 mb-4",children:t("team:modals.addHuman.inviteHint")}),c.jsxs("div",{className:"bg-surface-primary border border-border-default rounded-lg p-3 text-left mb-3",children:[c.jsx("div",{className:"text-[10px] text-fg-tertiary uppercase mb-1.5",children:t("team:modals.addHuman.inviteLink")}),c.jsx("div",{className:"text-xs text-fg-primary break-all font-mono select-all",children:O})]}),c.jsx("button",{onClick:x,className:`w-full py-2.5 text-sm font-medium rounded-lg transition-colors ${v?"bg-green-600 text-white":"bg-brand-700 hover:bg-brand-600 text-white"}`,children:t(v?"common:copied":"team:modals.addHuman.copyInviteLink")})]}):c.jsx("div",{className:"text-xs text-fg-secondary mt-1",children:t("team:modals.addHuman.memberCreatedNoInvite")})]}),c.jsx("div",{className:"flex justify-end pt-3",children:c.jsx("button",{onClick:s,className:"px-5 py-2 text-sm bg-surface-elevated hover:bg-surface-overlay rounded-lg text-fg-secondary border border-border-default",children:t("common:done")})})]}):c.jsx(Ea,{onClose:s,title:t("team:modals.addHuman.title"),width:"w-[460px]",children:c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"text-xs text-fg-secondary bg-surface-primary border border-border-default rounded-lg px-3 py-2.5 leading-relaxed",children:[c.jsx("div",{className:"font-semibold text-fg-primary mb-1",children:t("team:modals.addHuman.sharedInstanceTitle")}),t("team:modals.addHuman.sharedInstanceDesc"),c.jsxs("div",{className:"mt-1.5 text-fg-tertiary",children:[t("team:modals.addHuman.orgHint")," ",c.jsx("a",{href:"#settings/organization",className:"text-brand-500 hover:text-brand-400 underline",children:t("team:modals.addHuman.orgLink")})]})]}),c.jsx(oo,{label:t("team:modals.addHuman.name"),children:c.jsx("input",{value:r,onChange:y=>i(y.target.value),placeholder:t("team:modals.addHuman.namePlaceholder"),className:"input",autoFocus:!0})}),c.jsx(oo,{label:t("team:modals.addHuman.role"),children:c.jsxs("select",{value:n,onChange:y=>a(y.target.value),className:"input",children:[c.jsx("option",{value:"owner",children:t("common:role.owner")}),c.jsx("option",{value:"admin",children:t("common:role.admin")}),c.jsx("option",{value:"member",children:t("common:role.member")}),c.jsx("option",{value:"guest",children:t("common:role.guest")})]})}),c.jsx(oo,{label:t("team:modals.addHuman.emailRequired"),children:c.jsx("input",{value:o,onChange:y=>l(y.target.value),type:"email",placeholder:t("team:modals.addHuman.emailPlaceholder"),className:"input"})}),c.jsx("div",{className:"text-xs text-fg-tertiary bg-brand-500/5 border border-brand-500/20 rounded-lg px-3 py-2",children:t("team:modals.addHuman.inviteFlowHint")}),h&&c.jsx("div",{className:"text-xs text-red-500 bg-red-500/10 border border-red-500/30 rounded-lg px-3 py-2",children:h}),c.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[c.jsx("button",{onClick:s,className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated",children:t("common:cancel")}),c.jsx("button",{onClick:m,disabled:u,className:"px-4 py-2 text-sm bg-green-700 hover:bg-green-600 disabled:opacity-50 rounded-lg text-white",children:t(u?"common:saving":"team:modals.addHuman.addMember")})]})]})})}function OC({teamId:s,ungrouped:e,onClose:t,onAdd:r}){const{t:i}=Qt(["team","common"]);return c.jsx(Ea,{onClose:t,title:i("team:modals.addExisting.title"),children:c.jsxs("div",{className:"space-y-3",children:[c.jsx("div",{className:"text-xs text-fg-tertiary",children:i("team:modals.addExisting.hint")}),e.length===0?c.jsx("div",{className:"text-center py-8 text-sm text-fg-tertiary",children:i("team:modals.addExisting.allInTeam")}):c.jsx("div",{className:"space-y-2 max-h-72 overflow-y-auto",children:e.map(n=>c.jsxs("button",{onClick:()=>r(n.id,n.type),className:"w-full flex items-center gap-3 px-4 py-3 rounded-lg border border-border-default hover:border-brand-500 hover:bg-brand-500/10 text-left transition-all",children:[c.jsx("div",{className:`w-8 h-8 rounded-lg flex items-center justify-center text-xs font-bold text-white ${n.type==="agent"?"bg-brand-600":"bg-green-600"}`,children:n.name.charAt(0)}),c.jsxs("div",{className:"flex-1",children:[c.jsx("div",{className:"font-medium text-sm",children:n.name}),c.jsxs("div",{className:"text-xs text-fg-tertiary",children:[n.role," · ",n.type==="agent"?i("team:modals.addExisting.typeAgent"):i("team:modals.addExisting.typeHuman")]})]}),n.status&&c.jsx("span",{className:`w-2 h-2 rounded-full ${n.status==="idle"?"bg-green-400":n.status==="working"?"bg-blue-400":"bg-gray-600"}`})]},n.id))}),c.jsx("div",{className:"flex justify-end pt-2",children:c.jsx("button",{onClick:t,className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated",children:i("common:close")})})]})})}function xC({onClose:s,onConnected:e}){const{t}=Qt(["team","common"]),[r,i]=_.useState(""),[n,a]=_.useState(""),[o,l]=_.useState(!1),[h,d]=_.useState(null),[u,f]=_.useState(null),p=async()=>{if(!r.trim()){a(t("team:modals.openClaw.agentNameRequired"));return}const v=r.trim().toLowerCase().replace(/\s+/g,"-");l(!0),a("");try{const g=await fetch("/api/external-agents/register",{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify({externalAgentId:v,agentName:r.trim(),orgId:"default",capabilities:["general"]})});if(!g.ok){const m=await g.json().catch(()=>({}));throw new Error(m.error??`HTTP ${g.status}`)}const O=await g.json();d({externalAgentId:v,markusAgentId:O.registration?.markusAgentId,token:O.token,gatewayUrl:O.gatewayUrl})}catch(g){a(String(g))}l(!1)},b=(v,g)=>{navigator.clipboard.writeText(v),f(g),setTimeout(()=>f(null),2e3)};return c.jsx(Ea,{onClose:s,title:t("team:modals.openClaw.title"),width:"w-[560px]",children:h?(()=>{const v=h.gatewayUrl??`${window.location.origin}/api/gateway`,g=h.token?t("team:modals.openClaw.bearerTokenLine",{token:h.token}):"",O=t("team:modals.openClaw.connectionPromptBody",{gwUrl:v,externalAgentId:h.externalAgentId,tokenSection:g});return c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"text-center py-6",children:[c.jsx("div",{className:"text-3xl mb-3 text-green-600",children:"✓"}),c.jsx("div",{className:"text-base text-green-600 font-medium mb-1",children:t("team:modals.openClaw.agentRegistered")}),c.jsx("div",{className:"text-sm text-fg-secondary mt-1",children:c.jsx("strong",{children:r})})]}),c.jsxs("div",{className:"bg-brand-500/10 border border-brand-500/30 rounded-xl p-4",children:[c.jsx("div",{className:"text-xs text-fg-secondary mb-3",children:t("team:modals.openClaw.copyInstruction")}),c.jsx("button",{onClick:()=>b(O,"prompt"),className:`w-full py-2.5 text-sm font-medium rounded-lg transition-colors ${u==="prompt"?"bg-green-600 text-white":"bg-brand-700 hover:bg-brand-600 text-white"}`,children:t(u==="prompt"?"common:copied":"team:modals.openClaw.copyPrompt")})]}),c.jsx("div",{className:"flex justify-end pt-5",children:c.jsx("button",{onClick:()=>{e()},className:"px-5 py-2 text-sm bg-surface-elevated hover:bg-surface-overlay rounded-lg text-fg-secondary border border-border-default",children:t("team:modals.openClaw.done")})})]})})():c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"text-xs text-fg-secondary mb-4",children:t("team:modals.openClaw.description")}),c.jsxs("div",{className:"space-y-4",children:[c.jsx(oo,{label:t("team:modals.openClaw.agentName"),children:c.jsx("input",{className:"input",placeholder:t("team:modals.openClaw.agentNamePlaceholder"),value:r,onChange:v=>i(v.target.value),autoFocus:!0})}),n&&c.jsx("div",{className:"text-xs text-red-500 bg-red-500/10 border border-red-500/30 rounded-lg px-3 py-2",children:n}),c.jsxs("div",{className:"flex justify-end gap-3 pt-2",children:[c.jsx("button",{onClick:s,className:"px-4 py-2 text-sm border border-border-default rounded-lg hover:bg-surface-elevated",children:t("common:cancel")}),c.jsx("button",{onClick:p,disabled:o,className:"px-4 py-2 text-sm bg-brand-700 hover:bg-brand-600 rounded-lg text-white disabled:opacity-50",children:t(o?"team:modals.openClaw.connecting":"team:modals.openClaw.importAgent")})]})]})]})})}function Kb(s){return`group:${s}`}function bC(s){const{chatMode:e,agentTeamId:t,channelTeamId:r,knownTeamIds:i}=s,n=e==="direct"?t:e==="channel"?r:null;return n&&(i instanceof Set?i.has(n):Array.from(i).includes(n))?`team/t/${n}`:"team"}class vC{listeners=new Set;streamingAgents=new Set;streamingVersion=0;markAgentStreaming(e,t){if(!e)return;const r=this.streamingAgents.has(e);t&&!r?(this.streamingAgents.add(e),this.streamingVersion++,this.emit()):!t&&r&&(this.streamingAgents.delete(e),this.streamingVersion++,this.emit())}clearAgentStreaming(e){e&&this.streamingAgents.delete(e)&&(this.streamingVersion++,this.emit())}getStreamingAgents(){return this.streamingAgents}isAgentStreaming(e){return!!e&&this.streamingAgents.has(e)}getStreamingVersion(){return this.streamingVersion}emit(){for(const e of this.listeners)e()}subscribe=e=>(this.listeners.add(e),()=>this.listeners.delete(e))}const sr=new vC;function ym(s){const e=s??(t=>t);return _.useSyncExternalStore(sr.subscribe,()=>e(sr.getStreamingVersion()))}function yC(s){return ym(()=>sr.isAgentStreaming(s))}function SC(s,e){return s&&typeof s.tokensUsedToday=="number"&&Number.isFinite(s.tokensUsedToday)?s.tokensUsedToday:typeof e=="number"&&Number.isFinite(e)?e:0}function _C(s){return s?s.filter(e=>e&&typeof e.size=="number"&&e.size>0).slice().sort((e,t)=>t.size-e.size||e.name.localeCompare(t.name)):[]}const wC=new Set(["workspace","sessions","tool-outputs","daily-logs","role","subagent-logs","worktrees"]);function kC(s){return wC.has(s)?`agent:profilePage.overview.storageBuckets.${s}`:null}const rf={idle:{tone:"ok",dotClass:"bg-green-400",running:!0,chipClass:"bg-green-500/10 border border-green-500/20",textClass:"text-green-600",labelKey:"common:status.idle"},working:{tone:"busy",dotClass:"bg-blue-400 animate-pulse",running:!0,chipClass:"bg-blue-500/10 border border-blue-500/20",textClass:"text-blue-500",labelKey:"common:status.working"},error:{tone:"danger",dotClass:"bg-red-400 animate-pulse",running:!0,chipClass:"bg-red-500/10 border border-red-500/20",textClass:"text-red-500",labelKey:"common:status.error"},paused:{tone:"warn",dotClass:"bg-amber-400",running:!1,chipClass:"bg-amber-500/10 border border-amber-500/20",textClass:"text-amber-600",labelKey:"common:status.paused"},offline:{tone:"muted",dotClass:"bg-gray-400",running:!1,chipClass:"bg-gray-500/10 border border-border-default",textClass:"text-fg-tertiary",labelKey:"common:status.offline"}};function Ch(s){const e=s?rf[s]:void 0;return e||{...rf.offline,labelKey:null}}const CC=rf.working;function Ph(s,e){const t=Ch(s);return!e||!t.running||t.tone==="danger"||t.tone==="busy"?t:CC}const PC=5;function dO(s,e=PC){const t=Array.isArray(s)?s:[];return{shown:t.slice().sort((i,n)=>Date.parse(n.startedAt)-Date.parse(i.startedAt)).slice(0,Math.max(0,e)),total:t.length}}const TC=100;function QC(s){const e=Array.isArray(s)?s:[];return{heartbeats:e.filter(t=>t.type==="heartbeat"),comms:e.filter(t=>t.type==="a2a")}}const Sm=["files","mind","recent","tools","memory","usage"],$C=Sm[0];function uO(s,e){return e?"mind":Sm.find(r=>r===s)??$C}function jC(s){return s?"right-panel":"page"}let Ul=new Map;function EC({agents:s,humans:e,authUser:t,onClose:r,onCreate:i}){const{t:n}=Qt(["team","common"]),[a,o]=_.useState(""),[l,h]=_.useState(new Set),[d,u]=_.useState(""),[f,p]=_.useState(!1),b=_.useMemo(()=>{const m=[];for(const x of s)m.push({id:x.id,name:x.name,type:"agent",subtitle:x.role||"Agent"});for(const x of e)x.id!==t?.id&&m.push({id:x.id,name:x.name,type:"human",subtitle:x.email||x.role||"Human"});return m},[s,e,t]),v=_.useMemo(()=>{if(!d)return b;const m=d.toLowerCase();return b.filter(x=>x.name.toLowerCase().includes(m)||x.subtitle.toLowerCase().includes(m))},[b,d]),g=m=>{h(x=>{const y=new Set(x);return y.has(m)?y.delete(m):y.add(m),y})},O=async()=>{if(!a.trim()||l.size===0)return;p(!0);const m=[...l],x={},y={};for(const w of m){const C=b.find(P=>P.id===w);C&&(x[w]=C.type,y[w]=C.name)}await i(a.trim(),m,x,y),p(!1)};return c.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",onClick:r,children:c.jsxs("div",{className:"bg-surface-elevated rounded-xl border border-border-default shadow-2xl w-[400px] max-w-[90vw] max-h-[80vh] flex flex-col",onClick:m=>m.stopPropagation(),children:[c.jsxs("div",{className:"px-5 py-4 border-b border-border-default",children:[c.jsx("h3",{className:"text-sm font-semibold",children:n("modals.createGroupChat.title")}),c.jsx("p",{className:"text-[11px] text-fg-tertiary mt-0.5",children:n("modals.createGroupChat.subtitle")})]}),c.jsx("div",{className:"px-5 py-3 border-b border-border-default",children:c.jsx("input",{value:a,onChange:m=>o(m.target.value),placeholder:n("modals.createGroupChat.groupNamePlaceholder"),className:"w-full bg-surface-primary border border-border-default rounded-lg px-3 py-2 text-sm text-fg-primary placeholder:text-fg-muted outline-none focus:ring-1 focus:ring-brand-500/50",autoFocus:!0})}),c.jsx("div",{className:"px-5 py-2 border-b border-border-default",children:c.jsx("input",{value:d,onChange:m=>u(m.target.value),placeholder:n("modals.createGroupChat.searchPlaceholder"),className:"w-full bg-surface-primary border border-border-default rounded-lg px-3 py-1.5 text-xs text-fg-primary placeholder:text-fg-muted outline-none focus:ring-1 focus:ring-brand-500/50"})}),c.jsxs("div",{className:"flex-1 overflow-y-auto px-3 py-2 min-h-0 max-h-[300px]",children:[v.length===0&&c.jsx("p",{className:"text-xs text-fg-tertiary px-2 py-4 text-center",children:n("modals.createGroupChat.noMembersFound")}),v.map(m=>c.jsxs("button",{onClick:()=>g(m.id),className:`w-full flex items-center gap-2.5 px-2 py-1.5 rounded-lg text-xs mb-0.5 transition-colors ${l.has(m.id)?"bg-brand-500/10 text-brand-500":"text-fg-secondary hover:bg-surface-overlay"}`,children:[c.jsx("div",{className:`w-4 h-4 rounded border flex items-center justify-center shrink-0 transition-colors ${l.has(m.id)?"bg-brand-500 border-brand-500":"border-border-default"}`,children:l.has(m.id)&&c.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})})}),c.jsx(Qs,{name:m.name,size:20,bgClass:m.type==="agent"?"bg-brand-500/15 text-brand-500":"bg-green-500/15 text-green-600"}),c.jsxs("div",{className:"flex-1 min-w-0 text-left",children:[c.jsx("span",{className:"truncate text-[11px] font-medium block",children:m.name}),c.jsx("span",{className:"text-[9px] text-fg-tertiary",children:m.subtitle})]}),c.jsx("span",{className:`text-[8px] px-1.5 py-0.5 rounded-full font-medium ${m.type==="agent"?"bg-brand-500/10 text-brand-500":"bg-green-500/10 text-green-600"}`,children:m.type==="agent"?n("modals.addExisting.typeAgent"):n("modals.addExisting.typeHuman")})]},m.id))]}),c.jsxs("div",{className:"px-5 py-3 border-t border-border-default flex items-center justify-between",children:[c.jsx("span",{className:"text-[10px] text-fg-tertiary",children:n("modals.createGroupChat.selected",{count:l.size})}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx("button",{onClick:r,className:"px-3 py-1.5 text-xs text-fg-secondary hover:text-fg-primary rounded-lg hover:bg-surface-overlay transition-colors",children:n("common:cancel")}),c.jsx("button",{onClick:O,disabled:!a.trim()||l.size===0||f,className:"px-4 py-1.5 text-xs font-medium text-white bg-brand-600 hover:bg-brand-500 rounded-lg transition-colors disabled:opacity-50 disabled:pointer-events-none",children:n(f?"modals.createGroupChat.creating":"modals.createGroupChat.create")})]})]})]})})}const RC=_.memo(function({authUser:e,agents:t,teams:r,humans:i,tasks:n,externalAgents:a,groupChats:o,chatMode:l,selectedAgent:h,activeChannel:d,activeDmUserId:u,onSelectAgent:f,onSelectChannel:p,onSelectDm:b,onSelectTeam:v,selectedTeamId:g,onRefreshTeams:O,onRefreshAgents:m,onRefreshHumans:x,onRefreshGroupChats:y,onViewProfile:w,onManageGroupMembers:C,unreadByAgent:P,unreadByChannel:S,width:T,onResizeStart:j,hidden:M,onCollapse:L,initialLoading:E,previewMode:B,focused:U,l2Available:Z}){const{t:I}=Qt(["team","common"]),ie=Om(),Q=xm(Gt.TEAM),W=kh(),A=e?.role==="owner"||e?.role==="admin",X=_.useMemo(()=>new Set(a.map(q=>q.markusAgentId).filter(Boolean)),[a]);ym(()=>sr.getStreamingVersion());const Y=sr.getStreamingAgents(),[se,ee]=_.useState([]),[me,V]=_.useState(new Set),[N,ne]=_.useState(!1),[H,te]=_.useState(!1),[J,ge]=_.useState(null),[Qe,_e]=_.useState(!1),[pe,be]=_.useState(!1),[Ae,ke]=_.useState(null),[oe,dt]=_.useState(null),[Ge,Ke]=_.useState(null),[Ot,rt]=_.useState(!1),[qt,$e]=_.useState(""),[ut,as]=_.useState(null),[mt,wt]=_.useState(null),[De,Nt]=_.useState(null),[et,ct]=_.useState(!1),kt=_.useRef(null),[Me,Ne]=_.useState(null),Ce=_.useRef(null),Ve=_.useRef(null),[G,K]=_.useState(null),fe=(q,ue="success")=>{K({message:q,type:ue}),setTimeout(()=>K(null),3e3)},[Pe,ze]=_.useState(null),[xt,ae]=_.useState(!1),Ze=_.useRef(!1);_.useEffect(()=>{if(B)return;re.governance.getSystemStatus().then(Oe=>{Ze.current=!0,ze(Oe.globalPaused)}).catch(()=>{Ze.current=!0,ze(!1)});const q=bt.on("system:pause-all",()=>{Ze.current&&ze(!0)}),ue=bt.on("system:resume-all",()=>{Ze.current&&ze(!1)});return()=>{q(),ue()}},[]),_.useEffect(()=>{if(!B)return;const q=setTimeout(()=>{const ue=Ve.current,Oe=Ce.current;ue&&Oe&&Oe.scrollTo({top:ue.offsetTop-Oe.offsetTop-8,behavior:"instant"})},100);return()=>clearTimeout(q)},[B]);const Te=_.useCallback(()=>{Pe!==null&&Se({title:I(Pe?"modals.resumeAll.title":"modals.pauseAll.title"),message:I(Pe?"modals.resumeAll.message":"modals.pauseAll.message"),confirmLabel:I(Pe?"chat.resume":"chat.pause"),onConfirm:async()=>{ae(!0);try{Pe?(await re.governance.resumeAll(),ze(!1)):(await re.governance.pauseAll(),ze(!0))}catch{}ae(!1)}})},[Pe]),[ve,Se]=_.useState(null),Ie=(q,ue,Oe,We,Je)=>{Se({title:q,message:ue,onConfirm:Oe,confirmLabel:We,checkboxes:Je})},[Ue,$t]=_.useState(null),[ht,ft]=_.useState(null),jt=_.useRef(null),Hr=_.useRef(null),[Us,ir]=_.useState(!1),[ul,Hi]=_.useState(null),[he,yt]=_.useState(""),ye=_.useCallback((q,ue=176,Oe=220)=>{const We=window.innerWidth,Je=window.innerHeight,st=8;let Ct=q.clientX,Tt=q.clientY;return Ct+ue>We-st&&(Ct=Math.max(st,We-ue-st)),Tt+Oe>Je-st&&(Tt=Math.max(st,Je-Oe-st)),Ct=Math.max(st,Math.min(Ct,We-ue-st)),Tt=Math.max(st,Math.min(Tt,Je-Oe-st)),{x:Ct,y:Tt}},[]),[gs,lt]=_.useState(Ul),Es=_.useMemo(()=>t.map(q=>q.id).sort().join(","),[t]);_.useEffect(()=>{if(!t.length||!Q)return;let q=!1;(async()=>{const Tt=[];await Promise.allSettled(t.map(async it=>{if(!Ul.has(it.id))try{const{sessions:is}=await re.sessions.listByAgent(it.id,1);if(!is.length)return;const{messages:us}=await re.sessions.getMessages(is[0].id,1);if(us.length){const As=us[0],Qr=As.metadata?.segments;let Vt=As.content;if(Qr&&Qr.length>0){const Ft=[...Qr].reverse().find(or=>or.type==="text");Ft&&Ft.type==="text"&&(Vt=Ft.content)}const Os=Vt.replace(/<think>[\s\S]*?(<\/think>|$)/g,"").replace(/<(invoke|function_calls|antml:\w+)\b[\s\S]*?(<\/\1>|$)/g,"").replace(/\n+/g," ").trim().slice(0,80);Os&&Tt.push([it.id,Os])}}catch{}})),!q&&Tt.length&&lt(it=>{const is=new Map(it);for(const[us,As]of Tt)is.set(us,As);return Ul=is,is})})();const Oe=new Set(t.map(Tt=>Tt.id)),We=Tt=>Vw(Tt).replace(/<(invoke|function_calls|antml:\w+)\b[\s\S]*?(<\/\1>|$)/g,"").replace(/\n+/g," ").trim().slice(0,80),Je=(Tt,it)=>{if(!Tt||!it||!Oe.has(Tt))return;const is=We(it);is&&lt(us=>{const As=new Map(us);return As.set(Tt,is),Ul=As,As})},st=bt.on("chat:proactive_message",Tt=>{const it=Tt.payload;Je(it.agentId??"",it.message??"")}),Ct=bt.on("chat:message",Tt=>{const it=Tt.payload,is=it.senderId??it.agentId??"",us=it.text??it.message??"";Je(is,us)});return()=>{q=!0,st(),Ct()}},[Es,Q]);const St=_.useCallback(()=>{B||re.teams.list().then(q=>ee(q.ungrouped)).catch(()=>{})},[B]);_.useEffect(()=>{St()},[St]),_.useEffect(()=>{if(!Q)return;const q=bt.on("team:update",St),ue=bt.on("agent:removed",St);return()=>{q(),ue()}},[St,Q]),_.useEffect(()=>{if(!oe&&!Ge&&!ut&&!et&&!De)return;const q=()=>{dt(null),Ke(null),as(null),Nt(null),ct(!1)},ue=setTimeout(()=>document.addEventListener("click",q),0);return()=>{clearTimeout(ue),document.removeEventListener("click",q)}},[oe,Ge,ut,et,De]);const Yi=(q,ue)=>{Ie(`${I("common:delete")} "${ue}"?`,I("modals.deleteTeam.message"),async Oe=>{const We=Oe?.deleteMembers??!0,Je=Oe?.purgeFiles??!1;await re.teams.delete(q,We,{purgeFiles:Je}),O(),St(),window.dispatchEvent(new CustomEvent("markus:data-changed"))},I("contextMenu.deleteTeam"),[{id:"deleteMembers",label:I("modals.deleteTeam.deleteMembers"),defaultChecked:!0},{id:"purgeFiles",label:I("modals.deleteTeam.purgeFiles"),defaultChecked:!1}])},Ro=async(q,ue)=>{try{const We=await(ue==="start"?re.teams.startAll:re.teams.stopAll)(q),Je=We.success?.length??0,st=We.failed?.length??0;st>0?fe(I("batchAction.failed",{action:I(`batchAction.operation.${ue}`),ok:Je,fail:st}),"error"):Je>0&&fe(I("batchAction.succeeded",{count:Je,action:I(`batchAction.past.${ue}`)}),"success"),m()}catch(Oe){fe(I("batchAction.failedToRun",{action:I(`batchAction.operation.${ue}`),error:Oe instanceof Error?Oe.message:String(Oe)}),"error")}},Gi=async(q,ue,Oe)=>{await re.teams.update(q,{managerId:ue,managerType:Oe}),O()},fl=async q=>{if(!he.trim()){Hi(null);return}await re.teams.update(q,{name:he.trim()}),Hi(null),O()},ml=async(q,ue)=>{ue==="offline"?await re.agents.start(q):await re.agents.stop(q),m()},An=(q,ue)=>{Ie(I("modals.removeFromTeam.title"),I("modals.removeFromTeam.message"),async()=>{await re.teams.removeMember(q,ue),O(),St()},I("common:remove"))},Ht=(q,ue,Oe,We)=>{Ie(`${I("common:remove")} "${ue}"?`,I(Oe==="agent"?"modals.removeAgent.message":"modals.removeHuman.message"),async Je=>{if(Oe==="agent"&&We){const st=o.find(Ct=>Ct.type==="team"&&Ct.teamId===We);st?.channelKey&&localStorage.setItem("markus_nav_after_remove","channel:"+st.channelKey)}if(Oe==="agent"){const st=Je?.purgeFiles??!1;await re.agents.remove(q,{purgeFiles:st})}else await re.users.remove(q);m(),O(),x?.(),St(),window.dispatchEvent(new CustomEvent("markus:data-changed"))},I("common:remove"),Oe==="agent"?[{id:"purgeFiles",label:I("modals.removeAgent.purgeFiles"),defaultChecked:!1}]:void 0)},ds=q=>{if(q.isOrgSecretary||q.protected)return!0;if(q.teamId)return!1;const ue=(q.role??"").toLowerCase().trim(),Oe=(q.name??"").trim();return Oe==="Secretary"||Oe==="秘书"||ue==="secretary"||ue.startsWith("secretary")},Is=(q,ue,Oe)=>{const We=t.find(Je=>Je.id===ue);We&&ds(We)||(Hr.current={x:q.clientX,y:q.clientY},jt.current=setTimeout(()=>{$t({agentId:ue,fromTeamId:Oe}),ir(!0)},200))},Ao=q=>{if(!Hr.current||!jt.current)return;const ue=Math.abs(q.clientX-Hr.current.x),Oe=Math.abs(q.clientY-Hr.current.y);(ue>5||Oe>5)&&(Us||(clearTimeout(jt.current),jt.current=null))},pl=async()=>{if(jt.current&&(clearTimeout(jt.current),jt.current=null),Hr.current=null,Us&&Ue&&ht){const q=ht==="_ungrouped"?void 0:ht;try{if(Ue.fromTeamId&&Ue.fromTeamId!==q&&await re.teams.removeMember(Ue.fromTeamId,Ue.agentId),q&&q!==Ue.fromTeamId){const ue=t.find(Oe=>Oe.id===Ue.agentId);await re.teams.addMember(q,Ue.agentId,"agent")}O(),m(),St()}catch(ue){fe(I("batchAction.moveFailed",{error:ue instanceof Error?ue.message:String(ue)}),"error")}}$t(null),ft(null),ir(!1)},Tr=_.useMemo(()=>new Map(r.map(q=>[q.id,q])),[r]),rs=_.useMemo(()=>{const q=new Map,ue=[];for(const Oe of t)if(Oe.teamId&&Tr.has(Oe.teamId)){const We=q.get(Oe.teamId)??[];We.push(Oe),q.set(Oe.teamId,We)}else ue.push(Oe);return{byTeam:q,ungrouped:ue}},[t,Tr]),gl=(q,ue)=>{const Oe=l==="direct"&&h===q.id,We=X.has(q.id),Je=q.status==="offline",st=Ph(q.status,!Je&&Y.has(q.id)),Ct=st.tone==="busy",Tt=st.dotClass,is=(void 0)?.managerId===q.id,us=q.role?.toLowerCase().replace(/[-_]/g," ").trim(),As=q.name.toLowerCase().trim(),Qr=us&&us!==As,Vt=gs.get(q.id)||q.currentActivity?.label?.slice(0,60)||"",Os=Ct?I("common:status.working"):q.status==="error"?I("common:status.error"):I(Je?"common:status.offline":"common:status.online");return c.jsx("div",{className:`relative mb-0.5 ${Us&&Ue?.agentId===q.id?"opacity-40":""}`,onPointerDown:Ft=>Is(Ft,q.id,ue),onPointerMove:Ao,onPointerUp:pl,children:c.jsxs("button",{"data-l1-nav-id":`agent:${q.id}`,onClick:()=>{Us||f(q.id)},onContextMenu:Ft=>{if(!A)return;Ft.preventDefault();const or=ye(Ft);rt(!1),$e(""),Ke({agentId:q.id,teamId:ue,...or})},className:`w-full flex items-center gap-2.5 px-2.5 py-2 rounded-lg text-xs transition-colors select-none ${ie?"":"touch-none"} ${Je?"opacity-50 text-fg-tertiary":"text-fg-primary"} ${vi(Oe)}`,children:[c.jsx(Qs,{name:q.name,avatarUrl:q.avatarUrl,size:28,bgClass:Je?"bg-surface-overlay/60 text-fg-tertiary":"bg-surface-overlay text-fg-primary"}),c.jsxs("div",{className:"flex-1 min-w-0 text-left",children:[c.jsxs("div",{className:"flex items-center gap-1",children:[c.jsx("span",{className:"truncate font-medium text-[12px] leading-tight",children:q.name}),Qr&&c.jsxs("span",{className:"text-[9px] text-fg-secondary shrink-0 truncate max-w-[80px]",children:["(",q.role,")"]}),is&&c.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"currentColor",className:"text-amber-500 shrink-0",children:c.jsx("polygon",{points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"})}),We&&c.jsx("span",{className:"text-[8px] px-1 py-0 rounded bg-brand-500/20 text-brand-400 font-medium shrink-0 leading-relaxed",children:"EXT"}),Je&&c.jsx("span",{className:"text-[8px] px-1 py-0 rounded bg-gray-500/20 text-gray-400 font-medium shrink-0 leading-relaxed",children:I("common:status.offline")})]}),c.jsx("div",{className:"truncate text-[10px] leading-tight mt-0.5 text-fg-secondary",children:Vt||" "})]}),c.jsxs("span",{className:"flex items-center gap-1.5 shrink-0",children:[(P?.get(q.id)??0)>0&&c.jsx("span",{className:"min-w-[16px] h-[16px] flex items-center justify-center text-[9px] font-semibold text-white bg-red-500 rounded-full px-1 leading-none",children:P.get(q.id)}),q.mailboxDepth!=null&&q.mailboxDepth>0&&c.jsx("span",{className:"text-[8px] text-fg-tertiary bg-surface-overlay rounded-full px-1 leading-relaxed",children:q.mailboxDepth}),c.jsx("span",{title:Os,onClick:Ft=>{Ft.stopPropagation(),w(q.id)},className:`w-2 h-2 rounded-full cursor-pointer transition-transform duration-150 hover:scale-[2] ${Tt}`}),ie&&A&&c.jsx("span",{role:"button",tabIndex:0,onClick:Ft=>{if(Ft.stopPropagation(),Ge?.agentId===q.id)Ke(null);else{const or=ye(Ft);rt(!1),$e(""),Ke({agentId:q.id,teamId:ue,...or})}},className:"w-5 h-5 flex items-center justify-center text-fg-tertiary hover:text-fg-secondary rounded transition-colors",title:I("chat.moreOptions"),children:c.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"12",cy:"12",r:"1"}),c.jsx("circle",{cx:"12",cy:"5",r:"1"}),c.jsx("circle",{cx:"12",cy:"19",r:"1"})]})})]})]})},q.id)},Ki=(q,ue,Oe,We)=>{const Je=Us&&ht===q&&Ue?.fromTeamId!==q,st=Me===q,Ct=g===q,Tt=P?(rs.byTeam.get(q)??[]).reduce((Bt,yi)=>Bt+(P.get(yi.id)??0),0):0,is=o.find(Bt=>Bt.type==="team"&&Bt.teamId===q)?.channelKey??Kb(q),us=S?S[is]??0:0,As=Tt+us,Qr=rs.byTeam.get(q)??[],Vt=Qr.filter(Bt=>Bt.status==="offline").length,Os=Qr.length,Ft=Os>0&&Vt===Os,or=Vt>0&&!Ft,Mo=Ft?"bg-gray-500":or?"bg-amber-500":"bg-green-500";return c.jsxs("div",{"data-team-id":q,className:`mb-0.5 rounded-lg transition-all duration-500 ${Je?"ring-1 ring-brand-500/50 bg-brand-500/5":""} ${st?"ring-2 ring-brand-500 bg-brand-500/10":""}`,onPointerEnter:()=>{Us&&ft(q)},onPointerLeave:()=>{Us&&ht===q&&ft(null)},children:[c.jsxs("div",{className:"group/teamhdr flex items-center gap-0.5",children:[c.jsxs("button",{"data-l1-nav-id":`team:${q}`,onClick:()=>{v&&q!=="_ungrouped"&&v(q)},onContextMenu:Bt=>{if(!A||!ue)return;Bt.preventDefault();const yi=ye(Bt);dt({teamId:q,...yi})},className:`flex-1 flex items-center gap-2.5 px-2.5 py-2 rounded-lg text-xs transition-colors min-w-0 ${Ft?"opacity-50 text-fg-tertiary":"text-fg-primary"} ${vi(Ct)}`,children:[c.jsxs("div",{className:`w-7 h-7 rounded-full flex items-center justify-center shrink-0 relative ${Ft?"bg-surface-overlay/60 text-fg-tertiary":"bg-surface-overlay text-fg-primary"}`,children:[ue?.avatarUrl?c.jsx("img",{src:ue.avatarUrl,alt:We,className:"w-full h-full rounded-full object-cover",onError:Bt=>{Bt.target.style.display="none",Bt.target.nextElementSibling?.classList.remove("hidden")}}):null,c.jsxs("svg",{className:`w-3 h-3 ${ue?.avatarUrl?"hidden":""}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),c.jsx("circle",{cx:"9",cy:"7",r:"4"}),c.jsx("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),c.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]}),Os>0&&c.jsx("span",{className:`absolute -bottom-0.5 -right-0.5 w-2.5 h-2.5 rounded-full border-2 border-surface-primary ${Mo}`})]}),c.jsxs("div",{className:"flex-1 min-w-0 text-left",children:[ul===q?c.jsx("input",{className:"bg-transparent border-b border-brand-500 text-fg-primary text-[12px] font-medium outline-none w-full",value:he,onChange:Bt=>yt(Bt.target.value),onBlur:()=>fl(q),onKeyDown:Bt=>{Bt.key==="Enter"&&fl(q),Bt.key==="Escape"&&Hi(null)},onClick:Bt=>Bt.stopPropagation(),autoFocus:!0}):c.jsx("span",{className:"truncate font-medium text-[12px] leading-tight block",children:We}),c.jsxs("div",{className:"text-[10px] text-fg-secondary leading-tight mt-0.5 flex items-center gap-1.5",children:[I("chat.members_other",{count:Oe}),Ft&&c.jsx("span",{className:"text-[8px] px-1 py-0 rounded bg-gray-500/20 text-gray-400 font-medium leading-relaxed",children:I("common:status.offline")}),or&&c.jsxs("span",{className:"text-[8px] px-1 py-0 rounded bg-amber-500/20 text-amber-500 font-medium leading-relaxed",children:[Vt,"/",Os]})]})]}),As>0&&c.jsx("span",{className:"min-w-[16px] h-[16px] flex items-center justify-center text-[9px] font-semibold text-white bg-red-500 rounded-full px-1 leading-none shrink-0",children:As}),c.jsx("svg",{className:"w-3.5 h-3.5 text-fg-muted shrink-0",fill:"currentColor",viewBox:"0 0 20 20",children:c.jsx("path",{fillRule:"evenodd",d:"M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z",clipRule:"evenodd"})})]}),A&&ue&&c.jsx("button",{onClick:Bt=>{if(Bt.stopPropagation(),oe?.teamId===q)dt(null);else{const yi=ye(Bt);dt({teamId:q,...yi})}},className:"w-7 h-7 flex items-center justify-center text-fg-muted hover:text-fg-primary rounded-md hover:bg-white/[0.08] transition-colors shrink-0",title:I("chat.moreOptions"),children:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"12",cy:"12",r:"1"}),c.jsx("circle",{cx:"12",cy:"5",r:"1"}),c.jsx("circle",{cx:"12",cy:"19",r:"1"})]})})]}),Je&&Us&&c.jsx("div",{className:"text-[9px] text-brand-500 px-4 py-0.5 animate-pulse",children:I("chat.dropHere")})]},q)},Rs=_.useMemo(()=>{const q=new Map,ue=[],Oe=[],We=[];for(const Je of o)if(Je.channelKey.startsWith("dm:a2a:"))We.push(Je);else if(Je.type==="custom")Oe.push(Je);else if(Je.teamId){const st=q.get(Je.teamId)??[];st.push(Je),q.set(Je.teamId,st)}else{const st=r.find(Ct=>Je.name.toLowerCase().includes(Ct.name.toLowerCase())||Ct.name.toLowerCase().includes(Je.name.toLowerCase()));if(st){const Ct=q.get(st.id)??[];Ct.push(Je),q.set(st.id,Ct)}else ue.push(Je)}return{byTeam:q,unmatched:ue,custom:Oe,dmChannels:We}},[o,r]),[Ji,Ol]=_.useState(!1),Mt=l==="channel"&&Rs.dmChannels.some(q=>q.channelKey===d);_.useEffect(()=>{Mt&&Ol(!0)},[Mt]);const nr=_.useMemo(()=>{const q=[];e&&q.push({kind:"dm",id:`dm:${e.id}`,userId:e.id});for(const Oe of i)Oe.id!==e?.id&&q.push({kind:"dm",id:`dm:${Oe.id}`,userId:Oe.id});for(const Oe of Rs.custom)q.push({kind:"channel",id:`channel:${Oe.channelKey}`,channelKey:Oe.channelKey});for(const Oe of Rs.unmatched)q.push({kind:"channel",id:`channel:${Oe.channelKey}`,channelKey:Oe.channelKey});const ue=rs.ungrouped.length>0?rs.ungrouped:r.length===0?t:[];for(const Oe of ue)q.push({kind:"agent",id:`agent:${Oe.id}`,agentId:Oe.id});for(const Oe of r)q.push({kind:"team",id:`team:${Oe.id}`,teamId:Oe.id});if(Ji)for(const Oe of Rs.dmChannels)q.push({kind:"channel",id:`channel:${Oe.channelKey}`,channelKey:Oe.channelKey});return q},[e,i,Rs,rs,r,t,Ji]),xl=_.useRef(nr);xl.current=nr;const bl=_.useCallback(q=>{q.kind==="dm"?b(q.userId):q.kind==="channel"?p(q.channelKey):q.kind==="agent"?f(q.agentId):q.kind==="team"&&v?.(q.teamId),requestAnimationFrame(()=>{document.querySelector(`[data-l1-nav-id="${q.id}"]`)?.scrollIntoView({block:"nearest"})})},[b,p,f,v]);_.useEffect(()=>{if(B||ie||!Q||M)return;const q=ue=>{const Oe=W?.keyboardPane??"content";if(Oe==="l0"||Oe==="l2"||ue.metaKey||ue.ctrlKey||ue.altKey||bm(ue.target))return;const We=ue.key.length===1?ue.key.toLowerCase():ue.key;if(We==="h"||We==="ArrowLeft"){if(Oe!=="l1")return;ue.preventDefault(),ue.stopPropagation(),W?.setL0FocusPageId(Gt.TEAM),W?.setLeftCollapsed(!1),W?.setKeyboardPane("l0");return}if(We==="l"||We==="ArrowRight"){if(Oe!=="l1")return;ue.preventDefault(),ue.stopPropagation(),Z&&W?.setKeyboardPane("l2");return}if(Oe!=="l1"&&!(U&&(We==="j"||We==="k"||We==="ArrowDown"||We==="ArrowUp")))return;const Je=We==="j"||We==="ArrowDown"?1:We==="k"||We==="ArrowUp"?-1:0;if(!Je)return;ue.preventDefault(),ue.stopPropagation(),W?.setKeyboardPane("l1");const st=xl.current;if(st.length===0)return;let Ct=-1;if(l==="dm"){const it=u||e?.id;it&&(Ct=st.findIndex(is=>is.kind==="dm"&&is.userId===it))}else l==="direct"?Ct=st.findIndex(it=>it.kind==="agent"&&it.agentId===h):l==="channel"&&(Ct=st.findIndex(it=>it.kind==="channel"&&it.channelKey===d),Ct<0&&g&&(Ct=st.findIndex(it=>it.kind==="team"&&it.teamId===g)));Ct<0&&(Ct=Je>0?-1:0);const Tt=Math.max(0,Math.min(st.length-1,Ct+Je));bl(st[Tt])};return document.addEventListener("keydown",q,!0),()=>document.removeEventListener("keydown",q,!0)},[B,ie,Q,M,W,U,Z,l,u,e?.id,h,d,g,bl]);const vi=q=>q?U?"bg-brand-500/25 ring-1 ring-inset ring-brand-500/40":"bg-surface-overlay":"hover:bg-surface-overlay/60";return c.jsxs(c.Fragment,{children:[c.jsxs("div",{"data-keyboard-pane":"l1",className:`bg-surface-primary flex flex-col ${T!=null?"shrink-0":"flex-1 min-w-0"} ${U?"ring-1 ring-inset ring-brand-500/30":""}`,style:M?{display:"none"}:T!=null?{width:T}:void 0,children:[c.jsxs("div",{"data-electron-drag":!0,className:"px-4 h-14 flex items-center shrink-0 gap-2",children:[ie&&c.jsx(Zw,{}),!ie&&L&&c.jsx("button",{onClick:L,className:"w-8 h-8 flex items-center justify-center rounded-lg transition-colors shrink-0 bg-brand-500/15 text-brand-500 hover:bg-brand-500/25",children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),c.jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]})}),c.jsx("h2",{className:"text-lg font-semibold",children:I("chat.title")}),A&&c.jsxs("div",{"data-no-drag":!0,className:"ml-auto relative",ref:kt,children:[c.jsxs("button",{onClick:()=>ct(!et),className:"flex items-center gap-1 px-2.5 py-1 text-xs font-medium text-fg-secondary hover:text-fg-primary bg-surface-elevated/60 hover:bg-surface-elevated rounded-md transition-colors",children:[c.jsx("span",{className:"text-brand-500",children:"+"})," ",I("chat.manage"),c.jsx("svg",{className:`w-2.5 h-2.5 transition-transform ${et?"rotate-180":""}`,fill:"currentColor",viewBox:"0 0 20 20",children:c.jsx("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})})]}),et&&c.jsxs("div",{ref:q=>{if(!q)return;const ue=q.getBoundingClientRect(),Oe=window.innerWidth,We=8;ue.right>Oe-We&&(q.style.left="auto",q.style.right="0"),ue.left<We&&(q.style.left="0",q.style.right="auto")},className:"absolute right-0 top-full mt-1 w-48 max-w-[calc(100vw-1rem)] bg-surface-elevated border border-border-default rounded-lg shadow-xl z-50 overflow-hidden",children:[c.jsxs("button",{onClick:()=>{ct(!1),ke("agent")},className:"w-full text-left px-4 py-2.5 text-xs text-fg-secondary hover:bg-surface-elevated transition-colors",children:[c.jsxs("div",{className:"font-medium flex items-center gap-1.5",children:[c.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("rect",{x:"3",y:"11",width:"18",height:"10",rx:"2"}),c.jsx("circle",{cx:"12",cy:"5",r:"2"}),c.jsx("path",{d:"M12 7v4"}),c.jsx("circle",{cx:"9",cy:"16",r:"1",fill:"currentColor",stroke:"none"}),c.jsx("circle",{cx:"15",cy:"16",r:"1",fill:"currentColor",stroke:"none"})]}),I("chat.addAgent")]}),c.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5 pl-[18px]",children:I("chat.addAgentDesc")})]}),c.jsxs("button",{onClick:()=>{ct(!1),ke("team")},className:"w-full text-left px-4 py-2.5 text-xs text-fg-secondary hover:bg-surface-elevated border-t border-border-default transition-colors",children:[c.jsxs("div",{className:"font-medium flex items-center gap-1.5",children:[c.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"}),c.jsx("circle",{cx:"9",cy:"7",r:"4"}),c.jsx("line",{x1:"19",y1:"8",x2:"19",y2:"14"}),c.jsx("line",{x1:"22",y1:"11",x2:"16",y2:"11"})]}),I("chat.newTeam")]}),c.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5 pl-[18px]",children:I("chat.newTeamDesc")})]}),c.jsxs("button",{onClick:()=>{ct(!1),te(!0)},className:"w-full text-left px-4 py-2.5 text-xs text-green-600 hover:bg-surface-elevated border-t border-border-default transition-colors",children:[c.jsxs("div",{className:"font-medium flex items-center gap-1.5",children:[c.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"}),c.jsx("circle",{cx:"9",cy:"7",r:"4"}),c.jsx("path",{d:"M20 8v6"}),c.jsx("path",{d:"M23 11h-6"})]}),I("chat.addHuman")]}),c.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5 pl-[18px]",children:I("chat.addHumanDesc")})]}),c.jsxs("button",{onClick:()=>{ct(!1),be(!0)},className:"w-full text-left px-4 py-2.5 text-xs text-fg-secondary hover:bg-surface-elevated border-t border-border-default transition-colors",children:[c.jsxs("div",{className:"font-medium flex items-center gap-1.5",children:[c.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M14 9a2 2 0 0 1-2 2H6l-4 4V4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2z"}),c.jsx("path",{d:"M18 9h2a2 2 0 0 1 2 2v11l-4-4h-6a2 2 0 0 1-2-2v-1"})]}),I("chat.newGroupChat")]}),c.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5 pl-[18px]",children:I("chat.newGroupChatDesc")})]}),Pe!==null&&c.jsxs("button",{onClick:()=>{ct(!1),Te()},disabled:xt,className:`w-full text-left px-4 py-2.5 text-xs hover:bg-surface-elevated border-t border-border-default transition-colors disabled:opacity-50 ${Pe?"text-green-600":"text-red-500"}`,children:[c.jsx("div",{className:"font-medium flex items-center gap-1.5",children:Pe?c.jsxs(c.Fragment,{children:[c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:c.jsx("polygon",{points:"5 3 19 12 5 21 5 3"})})," ",I("chat.resume")]}):c.jsxs(c.Fragment,{children:[c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:c.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"})})," ",I("contextMenu.stopAll")]})}),c.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5 pl-[18px]",children:I(Pe?"modals.resumeAll.title":"modals.pauseAll.title")})]})]})]})]}),c.jsxs("div",{ref:Ce,className:"flex-1 overflow-y-auto px-3 py-2 flex flex-col",children:[c.jsxs("div",{className:"mb-2",children:[c.jsx("p",{className:"text-[10px] font-semibold text-fg-muted uppercase tracking-wider mb-1.5 px-2.5",children:I("chat.people")}),e&&c.jsxs("button",{"data-l1-nav-id":`dm:${e.id}`,onClick:()=>b(e.id),className:`w-full flex items-center gap-2.5 px-2.5 py-2 rounded-lg text-xs mb-0.5 transition-colors text-fg-primary ${vi(l==="dm"&&(u===e.id||!u))}`,children:[c.jsx(Qs,{name:e.name,avatarUrl:e.avatarUrl,size:28,bgClass:"bg-brand-500/15 text-brand-400"}),c.jsxs("div",{className:"flex-1 min-w-0 text-left",children:[c.jsx("div",{className:"truncate font-medium text-[12px] leading-tight",children:e.name}),c.jsx("div",{className:"text-fg-secondary truncate text-[10px] leading-tight mt-0.5",children:I("chat.myNotes")})]}),c.jsx("span",{className:"text-fg-secondary shrink-0",children:c.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),c.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})})]}),i.filter(q=>q.id!==e?.id).map(q=>{const ue=e?.id?`dm:${[e.id,q.id].sort().join(":")}`:"",Oe=ue&&S?S[ue]??0:0;return c.jsxs("button",{"data-l1-nav-id":`dm:${q.id}`,onClick:()=>b(q.id),onContextMenu:We=>{if(!A||q.id===e?.id)return;We.preventDefault();const Je=ye(We);as({userId:q.id,...Je})},className:`w-full flex items-center gap-2.5 px-2.5 py-2 rounded-lg text-xs mb-0.5 transition-colors text-fg-primary ${l==="dm"&&u===q.id?U?"bg-brand-500/25 ring-1 ring-inset ring-brand-500/40":"bg-green-500/15":"hover:bg-surface-overlay/60"}`,children:[c.jsx(Qs,{name:q.name,avatarUrl:q.avatarUrl,size:28,bgClass:"bg-green-500/10 text-green-500"}),c.jsxs("div",{className:"flex-1 min-w-0 text-left",children:[c.jsx("div",{className:"truncate font-medium text-[12px] leading-tight",children:q.name}),c.jsx("div",{className:"text-fg-secondary truncate text-[10px] leading-tight mt-0.5",children:q.email||q.role})]}),Oe>0?c.jsx("span",{className:"min-w-[16px] h-[16px] flex items-center justify-center text-[9px] font-semibold text-white bg-red-500 rounded-full px-1 leading-none shrink-0",children:Oe}):c.jsx("span",{className:"w-2 h-2 rounded-full bg-green-500 shrink-0"})]},q.id)})]}),Rs.custom.length>0&&c.jsxs("div",{className:"mb-2",children:[c.jsx("p",{className:"text-[10px] font-semibold text-fg-muted uppercase tracking-wider mb-1 px-2.5",children:I("chat.groups")}),Rs.custom.map(q=>{const ue=l==="channel"&&d===q.channelKey;return c.jsxs("button",{"data-l1-nav-id":`channel:${q.channelKey}`,onClick:()=>p(q.channelKey),onContextMenu:Oe=>{Oe.preventDefault();const We=ye(Oe);Nt({gcId:q.id,...We})},className:`w-full flex items-center gap-2.5 px-2.5 py-2 rounded-lg text-xs mb-0.5 transition-colors text-fg-primary ${vi(ue)}`,children:[c.jsx("div",{className:"w-7 h-7 rounded-lg flex items-center justify-center shrink-0 bg-surface-overlay text-fg-primary",children:c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),c.jsxs("div",{className:"flex-1 min-w-0 text-left",children:[c.jsx("span",{className:"truncate font-medium text-[12px] leading-tight block",children:q.name}),c.jsx("div",{className:"text-[10px] text-fg-secondary leading-tight mt-0.5",children:I("chat.members_other",{count:q.memberCount??0})})]})]},q.id)})]}),E?c.jsx("div",{className:"space-y-3 px-1 mb-2",children:[...Array(6)].map((q,ue)=>c.jsxs("div",{className:"flex items-center gap-2.5 animate-pulse",children:[c.jsx("div",{className:"w-6 h-6 rounded-lg bg-surface-overlay shrink-0"}),c.jsxs("div",{className:"flex-1 space-y-1.5",children:[c.jsx("div",{className:"h-2.5 bg-surface-overlay rounded w-24"}),c.jsx("div",{className:"h-2 bg-surface-overlay rounded w-36"})]}),c.jsx("div",{className:"w-2 h-2 rounded-full bg-surface-overlay shrink-0"})]},ue))}):t.length===0&&r.length===0?c.jsx("p",{className:"text-xs text-fg-tertiary px-1 mb-2",children:I("chat.noAgentsYet")}):null,Rs.unmatched.map(q=>{const ue=S?.[q.channelKey]??0;return c.jsxs("button",{"data-l1-nav-id":`channel:${q.channelKey}`,onClick:()=>p(q.channelKey),className:`w-full flex items-center gap-2.5 px-2.5 py-2 rounded-lg text-xs mb-0.5 transition-colors text-fg-primary ${vi(l==="channel"&&d===q.channelKey)}`,children:[c.jsx("div",{className:"w-7 h-7 rounded-full flex items-center justify-center shrink-0 bg-surface-overlay text-fg-primary",children:c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),c.jsxs("div",{className:"flex-1 min-w-0 text-left",children:[c.jsx("span",{className:"truncate font-medium text-[12px] leading-tight block",children:q.name}),c.jsx("div",{className:"text-[10px] text-fg-secondary leading-tight mt-0.5",children:I("chat.groupChat")})]}),ue>0?c.jsx("span",{className:"min-w-[16px] h-[16px] flex items-center justify-center text-[9px] font-semibold text-white bg-red-500 rounded-full px-1 leading-none",children:ue}):q.memberCount!==void 0&&q.memberCount>0?c.jsx("span",{className:"text-[9px] text-fg-secondary shrink-0",children:q.memberCount}):null]},q.id)}),rs.ungrouped.length>0&&c.jsxs("div",{className:"mb-2",children:[c.jsx("p",{className:"text-[10px] font-semibold text-fg-muted uppercase tracking-wider mb-1.5 px-2.5",children:I("chat.agents")}),rs.ungrouped.map(q=>gl(q))]}),r.length>0&&c.jsxs("div",{className:"mb-2",ref:Ve,children:[c.jsx("p",{className:"text-[10px] font-semibold text-fg-muted uppercase tracking-wider mb-1.5 px-2.5",children:I("chat.teams")}),r.map(q=>{const ue=rs.byTeam.get(q.id)??[],Oe=q.members?.length||ue.length;return Ki(q.id,q,Oe,q.name)})]}),r.length===0&&rs.ungrouped.length===0&&t.length>0&&t.map(q=>gl(q)),Rs.dmChannels.length>0&&c.jsxs("div",{className:"mb-2",children:[c.jsxs("button",{onClick:()=>Ol(q=>!q),className:"w-full flex items-center gap-1.5 px-2.5 py-1 text-[10px] font-semibold text-fg-muted uppercase tracking-wider hover:text-fg-secondary transition-colors",children:[c.jsx("svg",{className:`w-2.5 h-2.5 transition-transform ${Ji?"rotate-90":""}`,fill:"currentColor",viewBox:"0 0 20 20",children:c.jsx("path",{fillRule:"evenodd",d:"M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z",clipRule:"evenodd"})}),I("chat.agentDMs"),c.jsx("span",{className:"ml-auto text-[9px] font-normal text-fg-tertiary",children:Rs.dmChannels.length})]}),Ji&&Rs.dmChannels.map(q=>{const ue=l==="channel"&&d===q.channelKey,Oe=S?.[q.channelKey]??0,We=q.name.replace(/^DM:\s*/,"");return c.jsxs("button",{"data-l1-nav-id":`channel:${q.channelKey}`,onClick:()=>p(q.channelKey),className:`w-full flex items-center gap-2.5 px-2.5 pl-5 py-1.5 rounded-lg text-xs mb-0.5 transition-colors text-fg-primary ${vi(ue)}`,children:[c.jsx("div",{className:"w-5 h-5 rounded-full flex items-center justify-center shrink-0 bg-surface-overlay/60 text-fg-tertiary text-[9px]",children:c.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),c.jsx("span",{className:"flex-1 min-w-0 text-left truncate text-[11px] text-fg-secondary",children:We}),Oe>0&&c.jsx("span",{className:"min-w-[14px] h-[14px] flex items-center justify-center text-[8px] font-semibold text-white bg-red-500 rounded-full px-0.5 leading-none",children:Oe})]},q.id)})]})]})]}),j&&c.jsx("div",{className:"w-1.5 cursor-col-resize shrink-0 group relative flex items-center justify-center",onMouseDown:j,children:c.jsx("div",{className:"w-px h-2/3 border-l border-dashed border-transparent group-hover:border-border-default group-active:border-fg-tertiary transition-colors"})}),oe&&(()=>{const q=rs.byTeam.get(oe.teamId)??[],ue=q.some(We=>We.status==="offline"),Oe=q.some(We=>We.status!=="offline");return c.jsxs("div",{className:"fixed bg-surface-elevated border border-border-default rounded-lg shadow-xl py-1 z-50 w-44 max-w-[calc(100vw-1rem)] max-h-[calc(100vh-1rem)] overflow-y-auto",style:{left:oe.x,top:oe.y},onClick:We=>We.stopPropagation(),children:[c.jsxs("button",{onClick:()=>{const We=Tr.get(oe.teamId);We&&(Hi(oe.teamId),yt(We.name)),dt(null)},className:"w-full text-left px-3 py-2 text-xs hover:bg-surface-overlay text-fg-secondary flex items-center gap-2",children:[c.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),c.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]}),I("contextMenu.renameTeam")]}),ue&&c.jsxs("button",{onClick:()=>{Ro(oe.teamId,"start"),dt(null)},className:"w-full text-left px-3 py-2 text-xs hover:bg-surface-overlay text-green-600 flex items-center gap-2",children:[c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:c.jsx("polygon",{points:"5 3 19 12 5 21 5 3"})}),I("contextMenu.startAll")]}),Oe&&c.jsxs("button",{onClick:()=>{Ro(oe.teamId,"stop"),dt(null)},className:"w-full text-left px-3 py-2 text-xs hover:bg-surface-overlay text-red-500 flex items-center gap-2",children:[c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:c.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"})}),I("contextMenu.stopAll")]}),c.jsx("div",{className:"border-t border-border-default/50 my-1"}),c.jsxs("button",{onClick:()=>{dt(null),yr.navigate(Gt.STORE)},className:"w-full text-left px-3 py-2 text-xs hover:bg-surface-overlay text-brand-500 flex items-center gap-2",children:[c.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),c.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),I("chat.addAgent")]}),se.length>0&&c.jsxs("button",{onClick:()=>{dt(null),ge(oe.teamId)},className:"w-full text-left px-3 py-2 text-xs hover:bg-surface-overlay text-fg-secondary flex items-center gap-2",children:[c.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M16 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),c.jsx("circle",{cx:"8.5",cy:"7",r:"4"}),c.jsx("polyline",{points:"17 11 19 13 23 9"})]}),I("contextMenu.addExisting")]}),c.jsx("div",{className:"border-t border-border-default/50 my-1"}),c.jsxs("button",{onClick:()=>{const We=Tr.get(oe.teamId);We&&Yi(oe.teamId,We.name),dt(null)},className:"w-full text-left px-3 py-2 text-xs hover:bg-surface-overlay text-red-500 flex items-center gap-2",children:[c.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("polyline",{points:"3 6 5 6 21 6"}),c.jsx("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]}),I("contextMenu.deleteTeam")]})]})})(),Ge&&(()=>{const q=t.find(st=>st.id===Ge.agentId);if(!q||!A)return null;const Oe=(Ge.teamId?Tr.get(Ge.teamId):void 0)?.managerId===q.id,We=q.id===e?.id,Je=ds(q);return c.jsxs("div",{className:"fixed bg-surface-elevated border border-border-default rounded-lg shadow-xl py-1 z-50 w-48 max-w-[calc(100vw-1rem)] overflow-y-auto",style:{left:Ge.x,top:Ge.y,maxHeight:Math.max(160,window.innerHeight-Ge.y-8)},onClick:st=>st.stopPropagation(),children:[Je&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"px-3 py-2 text-[10px] leading-snug text-fg-secondary font-medium",children:I("contextMenu.orgSecretaryProtected")}),c.jsx("div",{className:"border-t border-border-default/50 my-1"})]}),c.jsxs("button",{onClick:()=>{Ke(null),w(q.id)},className:"w-full text-left px-3 py-2 text-xs hover:bg-surface-overlay text-brand-500 flex items-center gap-2",children:[c.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"}),c.jsx("circle",{cx:"12",cy:"7",r:"4"})]}),I("contextMenu.viewProfile")]}),q.status==="offline"?c.jsxs("button",{onClick:()=>{ml(q.id,"offline"),Ke(null)},className:"w-full text-left px-3 py-2 text-xs hover:bg-surface-overlay text-green-600 flex items-center gap-2",children:[c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:c.jsx("polygon",{points:"5 3 19 12 5 21 5 3"})}),I("contextMenu.start")]}):c.jsxs("button",{onClick:()=>{ml(q.id,q.status??"idle"),Ke(null)},className:"w-full text-left px-3 py-2 text-xs hover:bg-surface-overlay text-red-500 flex items-center gap-2",children:[c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:c.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"})}),I("contextMenu.stop")]}),!Je&&Ge.teamId&&!Oe&&c.jsxs("button",{onClick:()=>{Gi(Ge.teamId,q.id,"agent"),Ke(null)},className:"w-full text-left px-3 py-2 text-xs hover:bg-surface-overlay text-amber-600 flex items-center gap-2",children:[c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:c.jsx("polygon",{points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"})}),I("contextMenu.setAsManager")]}),!Je&&Ge.teamId&&c.jsxs("button",{onClick:()=>{An(Ge.teamId,q.id),Ke(null)},className:"w-full text-left px-3 py-2 text-xs hover:bg-surface-overlay text-fg-secondary flex items-center gap-2",children:[c.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("polyline",{points:"9 14 4 9 9 4"}),c.jsx("path",{d:"M20 20v-7a4 4 0 0 0-4-4H4"})]}),I("contextMenu.removeFromTeam")]}),!Je&&(()=>{const st=r.filter(it=>it.id!==Ge.teamId);if(st.length===0)return null;const Ct=qt.trim().toLowerCase(),Tt=Ct?st.filter(it=>it.name.toLowerCase().includes(Ct)):st;return c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"border-t border-border-default/50 my-1"}),c.jsxs("button",{type:"button",onClick:()=>rt(it=>!it),className:"w-full text-left px-3 py-2 text-xs hover:bg-surface-overlay text-fg-secondary flex items-center gap-2",children:[c.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M5 12h14"}),c.jsx("path",{d:"M12 5l7 7-7 7"})]}),c.jsx("span",{className:"flex-1",children:I("contextMenu.moveTo")}),c.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:`shrink-0 text-fg-tertiary transition-transform ${Ot?"rotate-180":""}`,children:c.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),Ot&&c.jsxs("div",{className:"px-2 pb-1.5",onClick:it=>it.stopPropagation(),children:[c.jsx("input",{autoFocus:!0,value:qt,onChange:it=>$e(it.target.value),onKeyDown:it=>it.stopPropagation(),placeholder:I("contextMenu.moveToSearch"),className:"w-full mb-1 px-2 py-1.5 text-xs rounded-md bg-surface-overlay border border-border-default text-fg-primary placeholder:text-fg-tertiary outline-none focus:border-brand-500/50"}),c.jsx("div",{className:"max-h-36 overflow-y-auto rounded-md",children:Tt.length===0?c.jsx("div",{className:"px-2 py-2 text-[10px] text-fg-tertiary",children:I("contextMenu.moveToEmpty")}):Tt.map(it=>c.jsx("button",{type:"button",onClick:async()=>{Ge.teamId&&await re.teams.removeMember(Ge.teamId,q.id),await re.teams.addMember(it.id,q.id,"agent"),O(),m(),St(),Ke(null)},className:"w-full text-left px-2 py-1.5 text-xs hover:bg-surface-overlay text-fg-secondary rounded truncate",title:it.name,children:it.name},it.id))})]})]})})(),!Je&&!We&&c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"border-t border-border-default/50 my-1"}),c.jsxs("button",{onClick:()=>{Ht(q.id,q.name,"agent",Ge.teamId),Ke(null)},className:"w-full text-left px-3 py-2 text-xs hover:bg-surface-overlay text-red-500 flex items-center gap-2",children:[c.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("polyline",{points:"3 6 5 6 21 6"}),c.jsx("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]}),I("contextMenu.removeFromOrg")]})]})]})})(),ut&&(()=>{const q=i.find(ue=>ue.id===ut.userId);return!q||!A?null:c.jsx("div",{className:"fixed bg-surface-elevated border border-border-default rounded-lg shadow-xl py-1 z-50 w-44 max-w-[calc(100vw-1rem)] max-h-[calc(100vh-1rem)] overflow-y-auto",style:{left:ut.x,top:ut.y},onClick:ue=>ue.stopPropagation(),children:c.jsxs("button",{onClick:()=>{Ht(q.id,q.name,"human"),as(null)},className:"w-full text-left px-3 py-2 text-xs hover:bg-surface-overlay text-red-500 flex items-center gap-2",children:[c.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("polyline",{points:"3 6 5 6 21 6"}),c.jsx("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]}),I("contextMenu.removeFromOrg")]})})})(),N&&c.jsx(pC,{onClose:()=>ne(!1),onCreate:async(q,ue)=>{try{const{team:Oe}=await re.teams.create(q,ue);ne(!1),O(),Ne(Oe.id),setTimeout(()=>{document.querySelector(`[data-team-id="${Oe.id}"]`)?.scrollIntoView({behavior:"smooth",block:"center"})},300),setTimeout(()=>Ne(null),3e3)}catch(Oe){fe(I("chat.failedToCreateTeam",{message:Oe instanceof Error?Oe.message:String(Oe)}),"error")}}}),H&&c.jsx(gC,{onClose:()=>{te(!1),x?.()},onAdd:async(q,ue,Oe)=>{const{inviteToken:We}=await re.users.create(q,ue,void 0,Oe);return x?.(),{inviteToken:We}}}),J!==null&&c.jsx(OC,{teamId:J,ungrouped:se,onClose:()=>ge(null),onAdd:async(q,ue)=>{await re.teams.addMember(J,q,ue),ge(null),O(),St()}}),Qe&&c.jsx(xC,{onClose:()=>_e(!1),onConnected:()=>{_e(!1),m(),O()}}),De&&(()=>{const q=o.find(ue=>ue.id===De.gcId);return q?c.jsxs("div",{className:"fixed bg-surface-elevated border border-border-default rounded-lg shadow-xl py-1 z-50 w-44 max-w-[calc(100vw-1rem)] max-h-[calc(100vh-1rem)] overflow-y-auto",style:{left:De.x,top:De.y},onClick:ue=>ue.stopPropagation(),children:[q.type==="custom"&&c.jsxs("button",{onClick:()=>{Nt(null),C?C(q.channelKey):p(q.channelKey)},className:"w-full text-left px-3 py-2 text-xs hover:bg-surface-overlay text-fg-secondary flex items-center gap-2",children:[c.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),c.jsx("circle",{cx:"9",cy:"7",r:"4"}),c.jsx("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),c.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]}),I("contextMenu.manageMembers")]}),c.jsxs("button",{onClick:async()=>{Nt(null),Ie(I("modals.deleteGroupChat.title"),I("modals.deleteGroupChat.message",{name:q.name}),async()=>{await re.groupChats.delete(q.id),y()},I("modals.deleteGroupChat.confirm"))},className:"w-full text-left px-3 py-2 text-xs hover:bg-surface-overlay text-red-500 flex items-center gap-2",children:[c.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("polyline",{points:"3 6 5 6 21 6"}),c.jsx("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]}),I("modals.deleteGroupChat.menuLabel")]})]}):null})(),pe&&c.jsx(EC,{agents:t,humans:i,authUser:e,onClose:()=>be(!1),onCreate:async(q,ue,Oe,We)=>{await re.groupChats.create({name:q,memberIds:ue,memberTypes:Oe,memberNames:We,creatorId:e?.id,creatorName:e?.name}),be(!1),y()}}),Ae&&c.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",onClick:()=>ke(null),children:c.jsxs("div",{className:"bg-surface-elevated rounded-xl border border-border-default shadow-2xl w-[340px] max-w-[90vw] overflow-hidden",onClick:q=>q.stopPropagation(),children:[c.jsxs("div",{className:"px-5 py-4 border-b border-border-default",children:[c.jsx("h3",{className:"text-sm font-semibold",children:I(Ae==="agent"?"chat.addAgent":"chat.newTeam")}),c.jsx("p",{className:"text-[11px] text-fg-tertiary mt-0.5",children:I("chat.methodChoiceSubtitle")})]}),c.jsxs("div",{className:"p-3 space-y-2",children:[c.jsxs("button",{onClick:()=>{const q=Ae;ke(null);const ue=t.find(Oe=>Oe.role==="secretary")??t.find(Oe=>Oe.name?.toLowerCase().includes("secretary"));ue?(f(ue.id),yr.navigate(Gt.TEAM,{agentId:ue.id,prefillMessage:I(q==="agent"?"chat.addAgentPrefill":"chat.newTeamPrefill")})):q==="agent"?yr.navigate(Gt.STORE):ne(!0)},className:"w-full flex items-center gap-3 px-4 py-3 rounded-lg border border-brand-500/30 bg-brand-500/5 hover:bg-brand-500/10 transition-colors text-left",children:[c.jsx("div",{className:"w-8 h-8 rounded-full bg-brand-500/15 flex items-center justify-center shrink-0",children:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",className:"text-brand-500",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M9.937 15.5A2 2 0 0 0 8.5 14.063l-6.135-1.582a.5.5 0 0 1 0-.962L8.5 9.936A2 2 0 0 0 9.937 8.5l1.582-6.135a.5.5 0 0 1 .963 0L14.063 8.5A2 2 0 0 0 15.5 9.937l6.135 1.581a.5.5 0 0 1 0 .964L15.5 14.063a2 2 0 0 0-1.437 1.437l-1.582 6.135a.5.5 0 0 1-.963 0z"}),c.jsx("path",{d:"M20 3v4"}),c.jsx("path",{d:"M22 5h-4"})]})}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsx("div",{className:"text-xs font-medium text-brand-500",children:I("chat.methodSecretary")}),c.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:I("chat.methodSecretaryDesc")})]}),c.jsx("span",{className:"text-[9px] px-1.5 py-0.5 rounded-full bg-brand-500/10 text-brand-500 font-medium shrink-0",children:I("chat.recommended")})]}),c.jsxs("button",{onClick:()=>{const q=Ae;ke(null),q==="agent"?yr.navigate(Gt.STORE):ne(!0)},className:"w-full flex items-center gap-3 px-4 py-3 rounded-lg border border-border-default hover:bg-surface-overlay transition-colors text-left",children:[c.jsx("div",{className:"w-8 h-8 rounded-full bg-surface-overlay flex items-center justify-center shrink-0",children:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",className:"text-fg-secondary",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7z"}),c.jsx("circle",{cx:"12",cy:"12",r:"3"})]})}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsx("div",{className:"text-xs font-medium text-fg-secondary",children:I("chat.methodManual")}),c.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:I(Ae==="agent"?"chat.methodManualAgentDesc":"chat.methodManualTeamDesc")})]})]})]}),c.jsx("div",{className:"px-5 py-3 border-t border-border-default flex justify-end",children:c.jsx("button",{onClick:()=>ke(null),className:"px-3 py-1.5 text-xs text-fg-secondary hover:text-fg-primary rounded-lg hover:bg-surface-overlay transition-colors",children:I("common:cancel")})})]})}),ve&&c.jsx(Po,{title:ve.title,message:ve.message,confirmLabel:ve.confirmLabel,checkboxes:ve.checkboxes,onConfirm:q=>{ve.onConfirm(q),Se(null)},onCancel:()=>Se(null)}),G&&c.jsx("div",{className:`fixed bottom-6 left-1/2 -translate-x-1/2 z-50 px-4 py-2.5 rounded-lg shadow-xl text-sm font-medium ${G.type==="error"?"bg-red-500/10 text-red-500 border border-red-500/30":"bg-surface-elevated/95 text-fg-primary border border-border-default/50"}`,children:G.message})]})});function fO({team:s,agents:e,humans:t,authUser:r,groupChat:i,chatMode:n,selectedAgent:a,activeChannel:o,activeDmUserId:l,teams:h,onSelectAgent:d,onSelectChannel:u,onSelectDm:f,onBack:p,onViewProfile:b,onRefreshAgents:v,onRefreshTeams:g,unreadByAgent:O,width:m,onResizeStart:x,focused:y}){const{t:w}=Qt(["team","common"]),C=kh(),P=xm(Gt.TEAM),S=r?.role==="owner"||r?.role==="admin",T=_.useMemo(()=>e.filter(H=>H.teamId===s.id),[e,s.id]),j=_.useMemo(()=>{const H=new Set((s.members??[]).filter(te=>te.type==="human").map(te=>te.id));return t.filter(te=>H.has(te.id))},[s.members,t]),M=i&&n==="channel"&&o===i.channelKey,L=_.useMemo(()=>{const H=[];i&&H.push({kind:"channel",id:`channel:${i.channelKey}`,channelKey:i.channelKey});for(const te of T)H.push({kind:"agent",id:`agent:${te.id}`,agentId:te.id});for(const te of j)H.push({kind:"dm",id:`dm:${te.id}`,userId:te.id});return H},[i,T,j]),E=_.useRef(L);E.current=L;const B=_.useCallback(H=>{H.kind==="channel"?u(H.channelKey):H.kind==="agent"?d(H.agentId):f(H.userId),requestAnimationFrame(()=>{document.querySelector(`[data-l2-nav-id="${H.id}"]`)?.scrollIntoView({block:"nearest"})})},[u,d,f]);_.useEffect(()=>{if(!P)return;const H=te=>{if((C?.keyboardPane??"content")!=="l2"||te.metaKey||te.ctrlKey||te.altKey||bm(te.target))return;const ge=te.key.length===1?te.key.toLowerCase():te.key;if(ge==="h"||ge==="ArrowLeft"){te.preventDefault(),te.stopPropagation(),C?.setKeyboardPane("l1");return}if(ge==="l"||ge==="ArrowRight"){te.preventDefault(),te.stopPropagation();return}const Qe=ge==="j"||ge==="ArrowDown"?1:ge==="k"||ge==="ArrowUp"?-1:0;if(!Qe)return;te.preventDefault(),te.stopPropagation();const _e=E.current;if(_e.length===0)return;let pe=-1;n==="channel"?pe=_e.findIndex(Ae=>Ae.kind==="channel"&&Ae.channelKey===o):n==="direct"?pe=_e.findIndex(Ae=>Ae.kind==="agent"&&Ae.agentId===a):n==="dm"&&l&&(pe=_e.findIndex(Ae=>Ae.kind==="dm"&&Ae.userId===l)),pe<0&&(pe=Qe>0?-1:0);const be=Math.max(0,Math.min(_e.length-1,pe+Qe));B(_e[be])};return document.addEventListener("keydown",H,!0),()=>document.removeEventListener("keydown",H,!0)},[P,C,n,o,a,l,B]);const U=H=>H?y?"bg-brand-500/25 ring-1 ring-inset ring-brand-500/40":"bg-surface-overlay":"hover:bg-surface-overlay/60",[Z,I]=_.useState(null),[ie,Q]=_.useState(!1),[W,A]=_.useState(""),[X,Y]=_.useState(null),se=(H,te,J,ge,Qe)=>{Y({title:H,message:te,onConfirm:J,confirmLabel:ge,checkboxes:Qe})},ee=_.useCallback((H,te=176,J=220)=>{const ge=window.innerWidth,Qe=window.innerHeight,_e=8;let pe=H.clientX,be=H.clientY;return pe+te>ge-_e&&(pe=Math.max(_e,ge-te-_e)),be+J>Qe-_e&&(be=Math.max(_e,Qe-J-_e)),pe=Math.max(_e,Math.min(pe,ge-te-_e)),be=Math.max(_e,Math.min(be,Qe-J-_e)),{x:pe,y:be}},[]);_.useEffect(()=>{if(!Z)return;const H=()=>I(null),te=setTimeout(()=>document.addEventListener("click",H),0);return()=>{clearTimeout(te),document.removeEventListener("click",H)}},[Z]);const me=_.useCallback(async(H,te)=>{te==="offline"?await re.agents.start(H):await re.agents.stop(H),v()},[v]),V=_.useCallback(async H=>{await re.teams.update(s.id,{managerId:H,managerType:"agent"}),g()},[s.id,g]),N=_.useCallback(async H=>{await re.teams.removeMember(s.id,H),g(),v()},[s.id,g,v]),ne=_.useCallback(async(H,te)=>{await re.teams.removeMember(s.id,H),await re.teams.addMember(te,H,"agent"),g(),v()},[s.id,g,v]);return c.jsxs(c.Fragment,{children:[c.jsxs("div",{"data-keyboard-pane":"l2",className:`bg-surface-primary flex flex-col shrink-0 ${y?"ring-1 ring-inset ring-brand-500/30":""}`,style:m!=null?{width:m}:{width:260},children:[c.jsxs("div",{className:"px-3 h-14 flex items-center gap-2 shrink-0",children:[c.jsx("button",{onClick:p,className:"w-8 h-8 flex items-center justify-center rounded-lg bg-brand-500/15 text-brand-500 transition-colors shrink-0",title:w("common:back",{defaultValue:"Back"}),children:c.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),c.jsx("line",{x1:"9",y1:"3",x2:"9",y2:"21"})]})}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsx("div",{className:"truncate font-semibold text-sm",children:s.name}),s.description&&c.jsx("div",{className:"truncate text-[10px] text-fg-tertiary",children:s.description})]})]}),c.jsxs("div",{className:"flex-1 overflow-y-auto px-3 py-2 flex flex-col",children:[i&&c.jsxs("div",{className:"mb-3",children:[c.jsx("p",{className:"text-[10px] font-semibold text-fg-muted uppercase tracking-wider mb-1.5 px-2.5",children:w("chat.groupChat",{defaultValue:"Group Chat"})}),c.jsxs("button",{"data-l2-nav-id":`channel:${i.channelKey}`,onClick:()=>u(i.channelKey),className:`w-full flex items-center gap-2.5 px-2.5 py-2 rounded-lg text-xs transition-colors text-fg-primary ${U(!!M)}`,children:[c.jsx("div",{className:"w-7 h-7 rounded-lg flex items-center justify-center shrink-0 bg-surface-overlay text-fg-primary",children:c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),c.jsxs("div",{className:"flex-1 min-w-0 text-left",children:[c.jsx("span",{className:"truncate font-medium text-[12px] leading-tight block",children:s.name}),c.jsx("div",{className:"text-[10px] text-fg-secondary leading-tight mt-0.5",children:w("chat.members_other",{count:i.memberCount||T.length+j.length})})]})]})]}),T.length>0&&c.jsxs("div",{className:"mb-3",children:[c.jsxs("p",{className:"text-[10px] font-semibold text-fg-muted uppercase tracking-wider mb-1.5 px-2.5",children:[w("chat.agents",{defaultValue:"Agents"}),c.jsx("span",{className:"ml-1 text-fg-tertiary font-normal",children:T.length})]}),T.map(H=>{const te=n==="direct"&&a===H.id,J=s.managerId===H.id,ge=H.status==="offline",Qe=Ph(H.status,sr.isAgentStreaming(H.id)).dotClass;return c.jsxs("button",{"data-l2-nav-id":`agent:${H.id}`,onClick:()=>d(H.id),onContextMenu:_e=>{if(!S)return;_e.preventDefault();const pe=ee(_e);Q(!1),A(""),I({agentId:H.id,...pe})},className:`w-full flex items-center gap-2.5 px-2.5 py-2 rounded-lg text-xs mb-0.5 transition-colors ${ge?"opacity-50 text-fg-tertiary":"text-fg-primary"} ${U(te)}`,children:[c.jsx(Qs,{name:H.name,avatarUrl:H.avatarUrl,size:28,bgClass:ge?"bg-surface-overlay/60 text-fg-tertiary":"bg-surface-overlay text-fg-primary"}),c.jsxs("div",{className:"flex-1 min-w-0 text-left",children:[c.jsxs("div",{className:"flex items-center gap-1",children:[c.jsx("span",{className:"truncate font-medium text-[12px] leading-tight",children:H.name}),J&&c.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"currentColor",className:"text-amber-500 shrink-0",children:c.jsx("polygon",{points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"})}),ge&&c.jsx("span",{className:"text-[8px] px-1 py-0 rounded bg-gray-500/20 text-gray-400 font-medium shrink-0 leading-relaxed",children:w("common:status.offline")})]}),c.jsx("div",{className:"truncate text-[10px] leading-tight mt-0.5 text-fg-secondary",children:H.role||" "})]}),(O?.get(H.id)??0)>0&&c.jsx("span",{className:"min-w-[16px] h-[16px] flex items-center justify-center text-[9px] font-semibold text-white bg-red-500 rounded-full px-1 leading-none shrink-0",children:O.get(H.id)}),c.jsx("span",{title:H.status,onClick:_e=>{_e.stopPropagation(),b(H.id)},className:`w-2 h-2 rounded-full cursor-pointer transition-transform duration-150 hover:scale-[2] shrink-0 ${Qe}`})]},H.id)})]}),j.length>0&&c.jsxs("div",{className:"mb-3",children:[c.jsxs("p",{className:"text-[10px] font-semibold text-fg-muted uppercase tracking-wider mb-1.5 px-2.5",children:[w("chat.people"),c.jsx("span",{className:"ml-1 text-fg-tertiary font-normal",children:j.length})]}),j.map(H=>{const te=H.id===r?.id,J=n==="dm"&&l===H.id;return c.jsxs("button",{"data-l2-nav-id":`dm:${H.id}`,onClick:()=>f(H.id),className:`w-full flex items-center gap-2.5 px-2.5 py-2 rounded-lg text-xs mb-0.5 transition-colors text-fg-primary ${U(J)}`,children:[c.jsx(Qs,{name:H.name,avatarUrl:H.avatarUrl,size:28,bgClass:"bg-green-500/10 text-green-500"}),c.jsxs("div",{className:"flex-1 min-w-0 text-left",children:[c.jsxs("div",{className:"truncate font-medium text-[12px] leading-tight",children:[H.name,te?` (${w("chat.you",{defaultValue:"You"})})`:""]}),c.jsx("div",{className:"text-fg-secondary truncate text-[10px] leading-tight mt-0.5",children:H.email||H.role})]}),c.jsx("span",{className:"w-2 h-2 rounded-full bg-green-500 shrink-0"})]},H.id)})]}),T.length===0&&j.length===0&&c.jsx("div",{className:"text-xs text-fg-tertiary text-center py-6 px-2",children:w("chat.noMembers",{defaultValue:"No members in this team yet."})})]})]}),x&&c.jsx("div",{className:"w-1.5 cursor-col-resize shrink-0 group relative flex items-center justify-center",onMouseDown:x,children:c.jsx("div",{className:"w-px h-2/3 border-l border-dashed border-transparent group-hover:border-border-default group-active:border-fg-tertiary transition-colors"})}),Z&&(()=>{const H=T.find(J=>J.id===Z.agentId);if(!H||!S)return null;const te=s.managerId===H.id;return c.jsxs("div",{className:"fixed bg-surface-elevated border border-border-default rounded-lg shadow-xl py-1 z-50 w-48 max-w-[calc(100vw-1rem)] overflow-y-auto",style:{left:Z.x,top:Z.y,maxHeight:Math.max(160,window.innerHeight-Z.y-8)},onClick:J=>J.stopPropagation(),children:[c.jsxs("button",{onClick:()=>{I(null),b(H.id)},className:"w-full text-left px-3 py-2 text-xs hover:bg-surface-overlay text-brand-500 flex items-center gap-2",children:[c.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"}),c.jsx("circle",{cx:"12",cy:"7",r:"4"})]}),w("contextMenu.viewProfile")]}),H.status==="offline"?c.jsxs("button",{onClick:()=>{me(H.id,"offline"),I(null)},className:"w-full text-left px-3 py-2 text-xs hover:bg-surface-overlay text-green-600 flex items-center gap-2",children:[c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:c.jsx("polygon",{points:"5 3 19 12 5 21 5 3"})}),w("contextMenu.start")]}):c.jsxs("button",{onClick:()=>{me(H.id,H.status??"idle"),I(null)},className:"w-full text-left px-3 py-2 text-xs hover:bg-surface-overlay text-red-500 flex items-center gap-2",children:[c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:c.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"})}),w("contextMenu.stop")]}),!te&&c.jsxs("button",{onClick:()=>{V(H.id),I(null)},className:"w-full text-left px-3 py-2 text-xs hover:bg-surface-overlay text-amber-600 flex items-center gap-2",children:[c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"currentColor",children:c.jsx("polygon",{points:"12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"})}),w("contextMenu.setAsManager")]}),c.jsxs("button",{onClick:()=>{N(H.id),I(null)},className:"w-full text-left px-3 py-2 text-xs hover:bg-surface-overlay text-fg-secondary flex items-center gap-2",children:[c.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("polyline",{points:"9 14 4 9 9 4"}),c.jsx("path",{d:"M20 20v-7a4 4 0 0 0-4-4H4"})]}),w("contextMenu.removeFromTeam")]}),(()=>{const J=h.filter(_e=>_e.id!==s.id);if(J.length===0)return null;const ge=W.trim().toLowerCase(),Qe=ge?J.filter(_e=>_e.name.toLowerCase().includes(ge)):J;return c.jsxs(c.Fragment,{children:[c.jsx("div",{className:"border-t border-border-default/50 my-1"}),c.jsxs("button",{type:"button",onClick:()=>Q(_e=>!_e),className:"w-full text-left px-3 py-2 text-xs hover:bg-surface-overlay text-fg-secondary flex items-center gap-2",children:[c.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M5 12h14"}),c.jsx("path",{d:"M12 5l7 7-7 7"})]}),c.jsx("span",{className:"flex-1",children:w("contextMenu.moveTo")}),c.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:`shrink-0 text-fg-tertiary transition-transform ${ie?"rotate-180":""}`,children:c.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),ie&&c.jsxs("div",{className:"px-2 pb-1.5",onClick:_e=>_e.stopPropagation(),children:[c.jsx("input",{autoFocus:!0,value:W,onChange:_e=>A(_e.target.value),onKeyDown:_e=>_e.stopPropagation(),placeholder:w("contextMenu.moveToSearch"),className:"w-full mb-1 px-2 py-1.5 text-xs rounded-md bg-surface-overlay border border-border-default text-fg-primary placeholder:text-fg-tertiary outline-none focus:border-brand-500/50"}),c.jsx("div",{className:"max-h-36 overflow-y-auto rounded-md",children:Qe.length===0?c.jsx("div",{className:"px-2 py-2 text-[10px] text-fg-tertiary",children:w("contextMenu.moveToEmpty")}):Qe.map(_e=>c.jsx("button",{type:"button",onClick:()=>{ne(H.id,_e.id),I(null)},className:"w-full text-left px-2 py-1.5 text-xs hover:bg-surface-overlay text-fg-secondary rounded truncate",title:_e.name,children:_e.name},_e.id))})]})]})})(),c.jsx("div",{className:"border-t border-border-default/50 my-1"}),c.jsxs("button",{onClick:()=>{se(`${w("common:remove")} "${H.name}"?`,w("modals.removeAgent.message"),async J=>{const ge=J?.purgeFiles??!1;i?.channelKey&&localStorage.setItem("markus_nav_after_remove","channel:"+i.channelKey),await re.agents.remove(H.id,{purgeFiles:ge}),v(),I(null)},w("common:remove"),[{id:"purgeFiles",label:w("modals.removeAgent.purgeFiles"),defaultChecked:!1}])},className:"w-full text-left px-3 py-2 text-xs hover:bg-surface-overlay text-red-500 flex items-center gap-2",children:[c.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("polyline",{points:"3 6 5 6 21 6"}),c.jsx("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})]}),w("contextMenu.removeFromOrg")]})]})})(),X&&c.jsx(Po,{title:X.title,message:X.message,confirmLabel:X.confirmLabel,checkboxes:X.checkboxes,onConfirm:H=>{X.onConfirm(H),Y(null)},onCancel:()=>Y(null)})]})}function nf(){return nf=Object.assign?Object.assign.bind():function(s){for(var e=1;e<arguments.length;e++){var t=arguments[e];for(var r in t)({}).hasOwnProperty.call(t,r)&&(s[r]=t[r])}return s},nf.apply(null,arguments)}function AC(s,e){if(s==null)return{};var t={};for(var r in s)if({}.hasOwnProperty.call(s,r)){if(e.indexOf(r)!==-1)continue;t[r]=s[r]}return t}let of=[],Jb=[];(()=>{let s="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map(e=>e?parseInt(e,36):1);for(let e=0,t=0;e<s.length;e++)(e%2?Jb:of).push(t=t+s[e])})();function MC(s){if(s<768)return!1;for(let e=0,t=of.length;;){let r=e+t>>1;if(s<of[r])t=r;else if(s>=Jb[r])e=r+1;else return!0;if(e==t)return!1}}function mO(s){return s>=127462&&s<=127487}const pO=8205;function LC(s,e,t=!0,r=!0){return(t?ev:NC)(s,e,r)}function ev(s,e,t){if(e==s.length)return e;e&&tv(s.charCodeAt(e))&&sv(s.charCodeAt(e-1))&&e--;let r=Vd(s,e);for(e+=gO(r);e<s.length;){let i=Vd(s,e);if(r==pO||i==pO||t&&MC(i))e+=gO(i),r=i;else if(mO(i)){let n=0,a=e-2;for(;a>=0&&mO(Vd(s,a));)n++,a-=2;if(n%2==0)break;e+=2}else break}return e}function NC(s,e,t){for(;e>1;){let r=ev(s,e-2,t);if(r<e)return r;e--}return 0}function Vd(s,e){let t=s.charCodeAt(e);if(!sv(t)||e+1==s.length)return t;let r=s.charCodeAt(e+1);return tv(r)?(t-55296<<10)+(r-56320)+65536:t}function tv(s){return s>=56320&&s<57344}function sv(s){return s>=55296&&s<56320}function gO(s){return s<65536?1:2}let Et=class rv{lineAt(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,r){[e,t]=Oo(this,e,t);let i=[];return this.decompose(0,e,i,2),r.length&&r.decompose(0,r.length,i,3),this.decompose(t,this.length,i,1),Dr.from(i,this.length-(t-e)+r.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=Oo(this,e,t);let r=[];return this.decompose(e,t,r,0),Dr.from(r,t-e)}eq(e){if(e==this)return!0;if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),r=this.length-this.scanIdentical(e,-1),i=new Sa(this),n=new Sa(e);for(let a=t,o=t;;){if(i.next(a),n.next(a),a=0,i.lineBreak!=n.lineBreak||i.done!=n.done||i.value!=n.value)return!1;if(o+=i.value.length,i.done||o>=r)return!0}}iter(e=1){return new Sa(this,e)}iterRange(e,t=this.length){return new iv(this,e,t)}iterLines(e,t){let r;if(e==null)r=this.iter();else{t==null&&(t=this.lines+1);let i=this.line(e).from;r=this.iterRange(i,Math.max(i,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new nv(r)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?rv.empty:e.length<=32?new ss(e):Dr.from(ss.split(e,[]))}};class ss extends Et{constructor(e,t=DC(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,r,i){for(let n=0;;n++){let a=this.text[n],o=i+a.length;if((t?r:o)>=e)return new IC(i,o,r,a);i=o+1,r++}}decompose(e,t,r,i){let n=e<=0&&t>=this.length?this:new ss(OO(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(i&1){let a=r.pop(),o=Cc(n.text,a.text.slice(),0,n.length);if(o.length<=32)r.push(new ss(o,a.length+n.length));else{let l=o.length>>1;r.push(new ss(o.slice(0,l)),new ss(o.slice(l)))}}else r.push(n)}replace(e,t,r){if(!(r instanceof ss))return super.replace(e,t,r);[e,t]=Oo(this,e,t);let i=Cc(this.text,Cc(r.text,OO(this.text,0,e)),t),n=this.length+r.length-(t-e);return i.length<=32?new ss(i,n):Dr.from(ss.split(i,[]),n)}sliceString(e,t=this.length,r=`
@@ -55,7 +55,7 @@ ${G}
55
55
  `)})},[i,s]);_.useEffect(()=>{if(s.kind!=="terminal"||!i)return;const G=navigator.platform.toUpperCase().includes("MAC"),K=fe=>{if(!(G?fe.metaKey&&!fe.ctrlKey:fe.ctrlKey&&!fe.metaKey)||!fe.shiftKey||fe.altKey||fe.key.toLowerCase()!=="a")return;const ze=ne.current?.getSelection()?.trim();ze&&(fe.preventDefault(),Ge(ze))};return window.addEventListener("keydown",K),()=>window.removeEventListener("keydown",K)},[s.kind,i,Ge]);const Ot=_.useCallback(G=>{if(!G.text.trim()||!i)return;const K=me.current?.querySelector("iframe")?.getBoundingClientRect(),fe=(K?.left??0)+G.rect.x+G.rect.width/2,Pe=(K?.top??0)+G.rect.y;B({x:fe,y:Pe,text:G.text,htmlMeta:{xpath:G.xpath,cssSelector:G.cssSelector}})},[i]);_.useEffect(()=>{const G=me.current;if(!G||!i)return;const K=()=>{requestAnimationFrame(()=>{const Pe=window.getSelection(),ze=Pe?.toString().trim();if(!ze||!Pe?.rangeCount){B(null);return}const xt=Pe.getRangeAt(0);if(!G.contains(xt.commonAncestorContainer)){B(null);return}const ae=xt.getBoundingClientRect();B({x:ae.left+ae.width/2,y:ae.top,text:ze})})},fe=Pe=>{const ze=document.getElementById("right-panel-selection-toolbar");ze&&ze.contains(Pe.target)||B(null)};return G.addEventListener("mouseup",K),document.addEventListener("mousedown",fe),()=>{G.removeEventListener("mouseup",K),document.removeEventListener("mousedown",fe)}},[i,x.mode]);const rt=()=>{re.files.reveal(Qe||J).catch(()=>{})},qt=()=>{navigator.clipboard?.writeText(Qe||J).then(()=>{S(!0),setTimeout(()=>S(!1),1500)}).catch(()=>{})},$e=_.useMemo(()=>{if(!i)return null;const G=Qe||J;if(s.kind==="deliverable"){const K=s.deliverable;if(!K.id&&!K.reference)return null;const fe=ge||K.title||K.reference||K.id;return{label:`📄 ${fe.length>40?`${fe.slice(0,24)}…${fe.slice(-12)}`:fe}`,content:["[deliverable]",K.id?`ID: ${K.id}`:"",K.title?`Title: ${K.title}`:"",K.reference?`Reference: ${K.reference}`:"",K.taskId?`Task: ${K.taskId}`:"",K.projectId?`Project: ${K.projectId}`:""].filter(Boolean).join(`
56
56
  `)}}if(s.kind==="file"){if(!G||Kn(G))return null;const K=ge||G.split(/[/\\]/).pop()||G;return{label:`📄 ${K.length>40?`${K.slice(0,24)}…${K.slice(-12)}`:K}`,content:["[file]",`Path: ${G}`,x.mode==="content"&&x.format?`Format: ${x.format}`:""].filter(Boolean).join(`
57
57
  `)}}return null},[i,s,Qe,J,ge,x]),[ut,as]=_.useState(!1),mt=_.useCallback(()=>{$e&&(i?.($e),as(!0),setTimeout(()=>as(!1),1200))},[$e,i]),wt=_.useCallback(async()=>{if(s.kind==="deliverable"){yr.navigate(Gt.DELIVERABLES,{openDeliverable:s.deliverable.id});return}if(s.kind==="url"){let K=s.url;if(s.browserId&&window.markusDesktop?.browser)try{const fe=await window.markusDesktop.browser.getState(s.browserId);if(fe.ok){if(fe.directoryPath){await re.system.openPath(fe.directoryPath).catch(()=>re.files.reveal(fe.directoryPath));return}fe.url&&fe.url!=="about:blank"&&(K=fe.url)}}catch{}if(!K||K==="about:blank")return;if(/^https?:\/\//i.test(K)||/^file:\/\//i.test(K)){Vl(K);return}await re.system.openPath(K).catch(()=>Vl(Sb(K)));return}if(s.kind!=="file")return;const G=s.path;if(G){if(/^https?:\/\//i.test(G)||/^file:\/\//i.test(G)){Vl(G);return}await re.system.openPath(G).catch(()=>Vl(Sb(G)))}},[s]),De=s.kind==="deliverable"?!!s.deliverable.id:s.kind==="url"?!!(s.url&&s.url!=="about:blank")||!!s.browserId:s.kind==="file"?!!s.path:!1,Nt=s.kind==="deliverable"?m("agent:deliverables.openInPage",{defaultValue:"Open in Output"}):m("common:openInSystemBrowser"),et=!!J&&!Kn(J)&&(s.kind==="file"||s.kind==="deliverable"),ct=s.kind==="deliverable"&&s.deliverable.type==="file"&&!!J&&!Kn(J)&&!s.deliverable.artifactType&&Ak(s.deliverable.format),kt=s.kind==="deliverable"?{...s.deliverable,hubShareId:M?.id??s.deliverable.hubShareId??null,shareStatus:M?.status??s.deliverable.shareStatus??null,shareUrl:M?.url??s.deliverable.shareUrl??null,shareVisibility:M?.visibility??s.deliverable.shareVisibility??null}:null,Me=_.useCallback(G=>{L(G)},[]),Ne=_.useMemo(()=>Mk(Bg,vm.getUrl()),[]),Ce=s.kind==="deliverable"?s.deliverable.id:null;_.useEffect(()=>{if(!Ce||!Bg())return;let G=!1;const K=async()=>{try{const Pe=await Ne.listMine();if(G)return;const ze=s.kind==="deliverable"?s.deliverable:null;if(!ze)return;const xt=ze.hubShareId&&Pe.find(Te=>Te.id===ze.hubShareId)||Pe.find(Te=>Te.localId===ze.id);if(!xt)return;L(Te=>Te&&Te.id===xt.id&&Te.status===xt.status?Te:xt);const ae={hubShareId:ze.hubShareId??xt.id??null,shareStatus:xt.status??null,shareUrl:xt.url??null,shareVisibility:ze.shareVisibility??xt.visibility??null};(ze.shareStatus!==ae.shareStatus||ze.hubShareId!==ae.hubShareId||ze.shareUrl!==ae.shareUrl||ze.shareVisibility!==ae.shareVisibility)&&ze.id&&re.deliverables.update(ze.id,ae).catch(Te=>{console.warn("[right-panel] Hub 分享状态本地持久化失败:",Te)})}catch{}};K();const fe=setInterval(K,3e4);return()=>{G=!0,clearInterval(fe)}},[Ne,Ce,s]);const Ve=kt?.shareStatus??null;return c.jsxs(c.Fragment,{children:[!d&&c.jsx("div",{className:"w-1.5 cursor-col-resize shrink-0 group relative z-10 flex items-center justify-center",onMouseDown:r,children:c.jsx("div",{className:"w-px h-2/3 border-l border-dashed border-transparent group-hover:border-border-default group-active:border-fg-tertiary transition-colors"})}),c.jsxs("div",{className:`bg-surface-primary flex flex-col overflow-hidden ${d?"flex-1 min-w-0":"shrink-0"}`,style:d?void 0:{width:t},"data-right-panel":!0,children:[c.jsxs("header",{"data-electron-drag":!0,className:"relative z-20 h-10 shrink-0 flex items-center gap-1 pl-1.5 pr-1.5 border-b border-border-default bg-surface-primary",children:[b&&c.jsxs("div",{"data-no-drag":!0,className:"shrink-0 flex items-center gap-0.5 pr-1 border-r border-border-default/60",children:[c.jsx("button",{type:"button",onClick:()=>b("browser"),title:m("common:browserMode",{defaultValue:"Browser"}),"aria-label":m("common:browserMode",{defaultValue:"Browser"}),"aria-pressed":p==="browser",className:`w-7 h-7 flex items-center justify-center rounded-md transition-colors ${p==="browser"?"bg-brand-500/15 text-brand-500":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,children:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"12",cy:"12",r:"10"}),c.jsx("line",{x1:"2",y1:"12",x2:"22",y2:"12"}),c.jsx("path",{d:"M12 2a15.3 15.3 0 0 1 4 10 15.3 15.3 0 0 1-4 10 15.3 15.3 0 0 1-4-10 15.3 15.3 0 0 1 4-10z"})]})}),c.jsx("button",{type:"button",onClick:()=>b("terminal"),title:m("common:terminalMode",{defaultValue:"Terminal"}),"aria-label":m("common:terminalMode",{defaultValue:"Terminal"}),"aria-pressed":p==="terminal",className:`w-7 h-7 flex items-center justify-center rounded-md transition-colors ${p==="terminal"?"bg-brand-500/15 text-brand-500":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,children:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("polyline",{points:"4 17 10 11 4 5"}),c.jsx("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]})})]}),_e||h?c.jsxs("div",{"data-no-drag":!0,ref:V,role:"tablist",className:"flex-1 min-w-0 flex flex-nowrap items-center gap-0.5 overflow-x-auto overflow-y-hidden overscroll-x-contain scrollbar-thin",onWheel:G=>{const K=G.currentTarget;K.scrollWidth<=K.clientWidth||Math.abs(G.deltaY)<=Math.abs(G.deltaX)||(K.scrollLeft+=G.deltaY,G.preventDefault())},children:[n?.map(G=>{const K=G.id===a,fe=G.payload.kind==="url"?G.payload.pageId:void 0,Pe=G.payload.kind==="terminal"?G.payload.terminalId:void 0,ze=fe!=null?U[fe]:Pe?I[Pe]:void 0,xt=ze?`${G.title} — ${m("common:browserTabControlledBy",{name:ze.agentName})}`:G.title;return c.jsxs("div",{className:`group shrink-0 flex items-center max-w-[200px] rounded-md text-[11px] border transition-colors ${K?ze?"bg-brand-500/10 border-brand-500/35 text-fg-primary":"bg-surface-elevated border-border-default text-fg-primary":ze?"border-brand-500/25 text-fg-secondary hover:bg-brand-500/8":"border-transparent text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated/50"}`,children:[c.jsxs("button",{type:"button",role:"tab","aria-selected":K,ref:K?N:void 0,className:"min-w-0 flex-1 truncate pl-2.5 pr-1 py-1 text-left cursor-pointer flex items-center gap-1",title:xt,onPointerDown:ae=>{ae.button===0&&(G.id!==a&&!te()||o?.(G.id))},onClick:()=>{G.id!==a&&!te()||o?.(G.id)},children:[ze&&c.jsxs("span",{className:"shrink-0 inline-flex items-center gap-0.5 max-w-[72px] px-1 py-px rounded text-[9px] font-semibold tracking-wide bg-brand-500/20 text-brand-500",title:m("common:browserTabControlledBy",{name:ze.agentName}),children:[c.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-500 animate-pulse shrink-0","aria-hidden":!0}),c.jsx("span",{className:"truncate",children:ze.agentName})]}),c.jsx("span",{className:"truncate min-w-0",children:G.title})]}),l&&c.jsx("button",{type:"button",onPointerDown:ae=>{ae.button===0&&(ae.preventDefault(),ae.stopPropagation(),!(G.id===a&&!te())&&l(G.id))},onClick:ae=>{ae.preventDefault(),ae.stopPropagation(),!(G.id===a&&!te())&&l(G.id)},className:`shrink-0 mr-1 p-0.5 rounded hover:bg-surface-overlay transition-colors ${K?"text-fg-tertiary hover:text-fg-secondary":"text-fg-muted hover:text-fg-secondary opacity-70 group-hover:opacity-100"}`,title:m("common:closeTab",{defaultValue:"Close tab"}),"aria-label":m("common:closeTab",{defaultValue:"Close tab"}),children:c.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[c.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),c.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},G.id)}),h&&c.jsx("button",{type:"button",onClick:h,className:"shrink-0 w-7 h-7 flex items-center justify-center rounded-md text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated/60 transition-colors",title:m("common:newTab",{defaultValue:"New Tab"}),"aria-label":m("common:newTab",{defaultValue:"New Tab"}),children:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),c.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})})]}):c.jsx("span",{className:"text-sm font-semibold text-fg-primary truncate flex-1 min-w-0 px-1.5",title:J||ge,children:ge}),c.jsxs("div",{"data-no-drag":!0,className:"shrink-0 flex items-center gap-0.5 pl-1 border-l border-border-default/60",children:[be&&c.jsx("button",{type:"button",onClick:ke,title:m("common:refreshPreview",{defaultValue:"刷新"}),"aria-label":m("common:refreshPreview",{defaultValue:"刷新"}),className:"w-7 h-7 flex items-center justify-center rounded-md transition-colors text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated",children:c.jsxs("svg",{className:x.mode==="loading"?"animate-spin":"",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("polyline",{points:"23 4 23 10 17 10"}),c.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}),be&&c.jsx("button",{type:"button",onClick:()=>se(G=>!G),"aria-pressed":Y,title:Y?m("common:autoRefreshOn",{defaultValue:"自动刷新:已开启"}):m("common:autoRefreshOff",{defaultValue:"自动刷新:已关闭"}),"aria-label":Y?m("common:autoRefreshOn",{defaultValue:"自动刷新:已开启"}):m("common:autoRefreshOff",{defaultValue:"自动刷新:已关闭"}),className:`w-7 h-7 flex items-center justify-center rounded-md transition-colors ${Y?"text-brand-500 bg-brand-500/10":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,children:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"12",cy:"12",r:"9"}),c.jsx("circle",{cx:"12",cy:"12",r:"3",fill:"currentColor",stroke:"none"})]})}),s.kind==="terminal"&&i&&c.jsx("button",{type:"button",onClick:()=>{Ke()},title:m("common:addRecentOutput",{defaultValue:"Add recent output to chat"}),"aria-label":m("common:addRecentOutput",{defaultValue:"Add recent output to chat"}),className:"w-7 h-7 flex items-center justify-center rounded-md transition-colors text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated",children:c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})})}),$e&&c.jsx("button",{type:"button",onClick:mt,title:ut?m("common:addedToChat",{defaultValue:"Added to chat"}):s.kind==="deliverable"?m("common:addDeliverableToChat",{defaultValue:"Add deliverable to chat"}):m("common:addFilePathToChat",{defaultValue:"Add file path to chat"}),"aria-label":s.kind==="deliverable"?m("common:addDeliverableToChat",{defaultValue:"Add deliverable to chat"}):m("common:addFilePathToChat",{defaultValue:"Add file path to chat"}),className:`w-7 h-7 flex items-center justify-center rounded-md transition-colors ${ut?"text-green-500 bg-green-500/10":"text-fg-tertiary hover:text-brand-500 hover:bg-brand-500/10"}`,children:ut?c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})}):c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h6"}),c.jsx("line",{x1:"17",y1:"3",x2:"17",y2:"9"}),c.jsx("line",{x1:"14",y1:"6",x2:"20",y2:"6"})]})}),ct&&c.jsxs("button",{type:"button",onClick:()=>j(!0),title:m("deliverables:share.title",{defaultValue:"分享到 Markus Hub"}),"aria-label":m("deliverables:share.title",{defaultValue:"分享到 Markus Hub"}),className:`relative w-7 h-7 flex items-center justify-center rounded-md transition-colors ${Ve==="published"?"text-green-500 hover:text-green-400":Ve==="pending_review"?"text-amber-500 hover:text-amber-400":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,children:[c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("circle",{cx:"18",cy:"5",r:"3"}),c.jsx("circle",{cx:"6",cy:"12",r:"3"}),c.jsx("circle",{cx:"18",cy:"19",r:"3"}),c.jsx("line",{x1:"8.59",y1:"13.51",x2:"15.42",y2:"17.49"}),c.jsx("line",{x1:"15.41",y1:"6.51",x2:"8.59",y2:"10.49"})]}),(Ve==="published"||Ve==="pending_review"||Ve==="rejected")&&c.jsx("span",{className:`absolute -top-0.5 -right-0.5 w-2 h-2 rounded-full border border-surface-primary ${Ve==="published"?"bg-green-500":Ve==="pending_review"?"bg-amber-500":"bg-red-500"}`,"aria-hidden":!0})]}),De&&c.jsx("button",{type:"button",onClick:()=>{wt()},title:Nt,"aria-label":Nt,className:"w-7 h-7 flex items-center justify-center rounded-md transition-colors text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated",children:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),c.jsx("polyline",{points:"15 3 21 3 21 9"}),c.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]})}),et&&c.jsx("button",{onClick:qt,title:P?m("common:copied",{defaultValue:"Copied"}):m("common:copyPath",{defaultValue:"复制路径"}),"aria-label":m("common:copyPath",{defaultValue:"复制路径"}),className:`w-7 h-7 flex items-center justify-center rounded-md transition-colors ${P?"text-green-500":"text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated"}`,children:P?c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"20 6 9 17 4 12"})}):c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),c.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})}),et&&c.jsx("button",{onClick:rt,title:m("detail.openInFileBrowser",{defaultValue:"Reveal in file browser"}),"aria-label":m("detail.openInFileBrowser",{defaultValue:"Reveal in file browser"}),className:"w-7 h-7 flex items-center justify-center rounded-md transition-colors text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated",children:c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"})})}),u&&c.jsx("button",{onClick:u,title:d?m("common:exitFullscreen",{defaultValue:"Exit fullscreen"}):m("common:fullscreen",{defaultValue:"Fullscreen"}),className:"w-7 h-7 flex items-center justify-center rounded-md transition-colors text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated",children:d?c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("polyline",{points:"4 14 10 14 10 20"}),c.jsx("polyline",{points:"20 10 14 10 14 4"}),c.jsx("line",{x1:"14",y1:"10",x2:"21",y2:"3"}),c.jsx("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]}):c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("polyline",{points:"15 3 21 3 21 9"}),c.jsx("polyline",{points:"9 21 3 21 3 15"}),c.jsx("line",{x1:"21",y1:"3",x2:"14",y2:"10"}),c.jsx("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]})}),c.jsx("button",{onClick:()=>{te()&&e()},title:m("common:collapsePanel",{defaultValue:"Hide panel"}),"aria-label":m("common:collapsePanel",{defaultValue:"Hide panel"}),className:"w-7 h-7 flex items-center justify-center rounded-md transition-colors text-fg-tertiary hover:text-fg-secondary hover:bg-surface-elevated",children:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),c.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),c.jsxs("div",{className:`flex-1 min-w-0 min-h-0 ${x.mode==="url"||x.mode==="terminal"||x.mode==="office"||x.mode==="directory"||x.mode==="content"&&["code","json","text","markdown","html"].includes(x.format)?"overflow-hidden p-2 flex flex-col":"overflow-auto p-4"}`,children:[w&&x.mode!=="directory"&&x.mode!=="loading"&&c.jsx("div",{className:"shrink-0 mb-2",children:c.jsxs("button",{className:"inline-flex items-center gap-1 text-xs text-fg-secondary hover:text-brand-500 transition-colors cursor-pointer",onClick:()=>C(JN(Qe)),children:[c.jsx("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 20 20",fill:"currentColor",children:c.jsx("path",{fillRule:"evenodd",d:"M17 10a.75.75 0 01-.75.75H5.612l4.158 3.96a.75.75 0 11-1.04 1.08l-5.5-5.25a.75.75 0 010-1.08l5.5-5.25a.75.75 0 111.04 1.08L5.612 9.25H16.25A.75.75 0 0117 10z",clipRule:"evenodd"})}),"返回上级目录"]})}),x.mode==="loading"&&c.jsxs("div",{className:"animate-pulse space-y-3",children:[c.jsx("div",{className:"h-4 bg-surface-overlay/60 rounded w-full"}),c.jsx("div",{className:"h-4 bg-surface-overlay/60 rounded w-5/6"}),c.jsx("div",{className:"h-32 bg-surface-overlay/40 rounded-lg w-full mt-2"}),c.jsx("div",{className:"h-4 bg-surface-overlay/60 rounded w-3/4"})]}),x.mode==="image"&&c.jsxs("div",{className:"flex flex-col items-center gap-2",children:[c.jsx("img",{src:x.src,alt:x.name,className:"max-w-full rounded-lg object-contain"}),c.jsx("span",{className:"text-xs text-fg-tertiary",children:x.name})]}),x.mode==="audio"&&c.jsxs("div",{className:"flex flex-col items-stretch gap-3 py-6",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:"w-12 h-12 rounded-xl bg-brand-500/15 text-brand-500 flex items-center justify-center shrink-0",children:c.jsxs("svg",{width:"22",height:"22",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M9 18V5l12-2v13"}),c.jsx("circle",{cx:"6",cy:"18",r:"3"}),c.jsx("circle",{cx:"18",cy:"16",r:"3"})]})}),c.jsxs("div",{className:"min-w-0",children:[c.jsx("div",{className:"text-sm font-medium text-fg-primary truncate",children:x.name}),c.jsxs("div",{className:"text-[11px] text-fg-tertiary mt-0.5",children:[x.mimeType,x.size!=null?` · ${Ku(x.size)}`:""]})]})]}),c.jsx("audio",{controls:!0,preload:"metadata",src:x.src,className:"w-full"})]}),x.mode==="video"&&c.jsxs("div",{className:"flex flex-col items-stretch gap-3",children:[c.jsx("video",{controls:!0,preload:"metadata",src:x.src,className:"w-full max-h-[70vh] rounded-lg bg-black"}),c.jsxs("span",{className:"text-xs text-fg-tertiary",children:[x.name,x.size!=null?` · ${Ku(x.size)}`:""]})]}),x.mode==="binary"&&c.jsxs("div",{className:"space-y-4 py-4",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:"w-12 h-12 rounded-xl bg-surface-elevated text-fg-tertiary flex items-center justify-center shrink-0 text-xs font-mono uppercase",children:(x.extension||"file").replace(/^\./,"")||"file"}),c.jsxs("div",{className:"min-w-0",children:[c.jsx("div",{className:"text-sm font-medium text-fg-primary truncate",children:x.name}),c.jsxs("div",{className:"text-[11px] text-fg-tertiary mt-0.5",children:[m("detail.cannotPreview",{type:"file",defaultValue:"This file type cannot be previewed."}),x.size!=null?` · ${Ku(x.size)}`:""]})]})]}),x.reference&&c.jsx("div",{className:"flex items-center gap-2",children:c.jsx("button",{onClick:()=>{re.files.reveal(x.reference)},className:"px-3 py-2 text-xs rounded-lg bg-brand-600/20 text-brand-500 hover:bg-brand-600/30 transition-colors",children:m("detail.openInFileBrowser",{defaultValue:"Reveal in file browser"})})})]}),x.mode==="office"&&c.jsx("div",{ref:me,className:"flex-1 min-h-0 min-w-0 w-full",children:c.jsx(Gw,{data:{format:x.format,streamUrl:x.streamUrl,name:x.name,size:x.size},reference:x.reference,onFallback:x.reference?()=>{re.files.reveal(x.reference)}:void 0})}),x.mode==="content"&&(()=>{const G=J?J.replace(/[/\\][^/\\]+$/,""):void 0,K=J&&!Kn(J)?J:"",fe=x.format;return K&&(fe==="code"||fe==="json"||fe==="text")?c.jsx("div",{ref:me,className:"flex-1 min-h-0 min-w-0 w-full flex flex-col",children:c.jsx(y_,{path:K,initialContent:x.content,language:Qp(K,fe),onDirtyChange:W})}):K&&(fe==="markdown"||fe==="html")?c.jsx("div",{ref:me,className:"flex-1 min-h-0 min-w-0 w-full flex flex-col",children:c.jsx(yN,{path:K,content:x.content,format:fe,basePath:G,onHtmlSelection:Ot,onDirtyChange:W})}):c.jsx("div",{ref:me,className:"min-w-0 max-w-full overflow-auto break-words [&_pre]:max-w-full [&_pre]:overflow-x-auto [&_table]:block [&_table]:max-w-full [&_table]:overflow-x-auto [&_img]:max-w-full",children:c.jsx(tf,{content:x.content,format:fe,className:"text-fg-secondary text-sm",onHtmlSelection:Ot,basePath:G})})})(),x.mode==="artifact"&&c.jsx("div",{ref:me,className:"min-w-0 max-w-full break-words [&_pre]:max-w-full [&_pre]:overflow-x-auto [&_table]:block [&_table]:max-w-full [&_table]:overflow-x-auto [&_img]:max-w-full",children:c.jsx(tf,{content:x.summary,format:"markdown",className:"text-fg-secondary text-sm"})}),x.mode==="url"&&c.jsx("div",{className:"flex-1 min-h-0 min-w-0 w-full flex flex-col",children:c.jsx(IN,{url:x.url,browserId:x.browserId,className:"flex-1 min-h-0",onMeta:x.browserId&&f?G=>f(x.browserId,G):void 0},x.browserId||x.url)}),x.mode==="terminal"&&c.jsx("div",{className:"flex-1 min-h-0 min-w-0 w-full flex flex-col",children:c.jsx(HN,{terminalId:x.terminalId,title:x.title,cwd:x.cwd,active:!0,apiRef:ne,onMeta:v,onOpenUrl:g,onOpenPath:O,onSelection:G=>{if(!G||!i){B(null);return}B({x:G.x,y:G.y,text:G.text})}},x.terminalId)}),x.mode==="directory"&&c.jsx(Kw,{path:x.path,entries:x.entries,onNavigate:G=>C(G),onOpenFile:G=>C(G),onReveal:rt,onCopyPath:qt}),x.mode==="unpreviewable"&&c.jsxs("div",{className:"space-y-3",children:[c.jsx("p",{className:"text-sm text-fg-secondary",children:x.isDirectory?m("detail.cannotPreview",{type:"directory",defaultValue:"This item cannot be previewed here."}):m("detail.cannotPreview",{type:"file",defaultValue:"This file cannot be previewed here."})}),x.reference&&c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("button",{onClick:rt,className:"text-xs bg-surface-elevated px-3 py-2 rounded text-brand-500 hover:underline flex-1 truncate text-left cursor-pointer font-mono",title:m("detail.openInFileBrowser",{defaultValue:"Reveal in file browser"}),children:x.reference}),c.jsx("button",{onClick:rt,className:"px-3 py-2 text-xs rounded-lg bg-brand-600/20 text-brand-500 hover:bg-brand-600/30 transition-colors shrink-0",children:m("common:open",{defaultValue:"Open"})}),c.jsx("button",{onClick:qt,className:`px-3 py-2 text-xs rounded-lg transition-colors shrink-0 ${P?"bg-green-500/20 text-green-600":"bg-surface-overlay/50 text-fg-secondary hover:bg-surface-overlay"}`,children:P?m("common:copied",{defaultValue:"Copied"}):m("common:copy",{defaultValue:"Copy"})})]})]})]},`${pe}#${A}`)]}),E&&i&&c.jsx("div",{id:"right-panel-selection-toolbar",className:"fixed z-50 -translate-x-1/2 -translate-y-full rounded-lg shadow-xl overflow-hidden border border-brand-400/40 bg-brand-600",style:{left:E.x,top:E.y-8},children:c.jsxs("button",{onMouseDown:G=>{G.preventDefault(),G.stopPropagation(),Ge(E.text,E.htmlMeta)},className:"px-3 py-1.5 text-xs font-medium text-white hover:bg-brand-500 transition-colors flex items-center gap-1.5 whitespace-nowrap",children:[c.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"})}),m("deliverables:contextMenu.addToConversation",{defaultValue:"Add to conversation"})]})}),T&&kt&&c.jsx(Lk,{item:kt,onClose:()=>j(!1),onShared:Me})]})}function t4({searchQuery:s,searchLoading:e,searchResults:t,onInputChange:r,onResultClick:i,onClose:n}){const{t:a}=Qt(["team","common"]);return c.jsxs("div",{className:"border-b border-border-default bg-surface-secondary/50 px-4 py-2 space-y-2 animate-in slide-in-from-top-2 duration-200",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsxs("div",{className:"flex-1 relative",children:[c.jsx("svg",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-fg-tertiary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:c.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607z"})}),c.jsx("input",{autoFocus:!0,value:s,onChange:o=>r(o.target.value),onKeyDown:o=>{o.key==="Escape"&&n()},placeholder:a("page.searchPlaceholder"),className:"w-full pl-8 pr-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg outline-none focus:border-brand-500/50 transition-colors"})]}),c.jsx("button",{onClick:n,className:"text-fg-tertiary hover:text-fg-secondary text-xs px-1",children:"✕"})]}),e&&c.jsxs("div",{className:"flex items-center gap-2 text-xs text-fg-tertiary py-1",children:[c.jsxs("svg",{className:"animate-spin h-3 w-3",viewBox:"0 0 24 24",fill:"none",children:[c.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),c.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),a("page.searching")]}),!e&&s.length>=2&&t.length===0&&c.jsx("div",{className:"text-xs text-fg-tertiary py-1",children:a("page.noSearchResults")}),t.length>0&&c.jsx("div",{className:"max-h-60 overflow-y-auto space-y-0.5",children:t.map(o=>c.jsxs("button",{onClick:()=>i(o),className:"w-full text-left px-3 py-2 rounded-lg hover:bg-surface-elevated transition-colors group",children:[c.jsxs("div",{className:"flex items-center gap-2 text-[11px] text-fg-tertiary mb-0.5",children:[c.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-medium ${o.source==="channel"?"bg-blue-500/10 text-blue-500":"bg-emerald-500/10 text-emerald-500"}`,children:o.source==="channel"?"#":"1:1"}),o.senderName&&c.jsx("span",{children:o.senderName}),c.jsx("span",{children:new Date(o.createdAt).toLocaleDateString(void 0,{month:"short",day:"numeric"})})]}),c.jsx("div",{className:"text-xs text-fg-secondary line-clamp-2 group-hover:text-fg-primary transition-colors",children:o.text.length>200?o.text.slice(0,200)+"…":o.text})]},o.id))})]})}function s4({members:s,candidates:e,currentUserId:t,memberCount:r,onClose:i,onRemoveMember:n,onAddMember:a}){const{t:o}=Qt(["team","common"]);return c.jsxs("div",{className:"bg-surface-secondary/80 px-4 py-3 flex flex-col gap-2",children:[c.jsxs("div",{className:"flex items-center justify-between",children:[c.jsxs("span",{className:"text-xs font-semibold text-fg-secondary",children:[o("page.members")," (",r,")"]}),c.jsx("button",{onClick:i,className:"text-fg-tertiary hover:text-fg-secondary text-xs",children:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),c.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),c.jsx("div",{className:"flex flex-wrap gap-1.5",children:s.map(l=>c.jsxs("span",{className:`inline-flex items-center gap-1.5 px-2 py-1 rounded-full text-[11px] font-medium ${l.type==="agent"?"bg-brand-500/10 text-brand-500":"bg-green-500/10 text-green-600"}`,children:[c.jsx(Qs,{name:l.name,size:16,bgClass:l.type==="agent"?"bg-brand-500/15 text-brand-500":"bg-green-500/15 text-green-600"}),l.name,l.id!==t&&c.jsx("button",{onClick:()=>n(l.id),className:"ml-0.5 hover:text-red-500 transition-colors",title:o("common:remove"),children:c.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),c.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},l.id))}),e.length>0&&c.jsx("div",{className:"mt-1",children:c.jsxs("select",{className:"w-full bg-surface-primary border border-border-default rounded-lg px-2.5 py-1.5 text-xs text-fg-primary outline-none focus:ring-1 focus:ring-brand-500/50",value:"",onChange:l=>{l.target.value&&a(l.target.value)},children:[c.jsx("option",{value:"",children:o("page.addMemberPlaceholder")}),e.map(l=>c.jsxs("option",{value:l.id,children:["[",l.type==="agent"?"Agent":"Human","] ",l.name]},l.id))]})})]})}const r4={text:"page.findFieldText",thinking:"page.findFieldThinking",tool:"page.findFieldTool"},i4={text:"bg-brand-500/10 text-brand-500",thinking:"bg-amber-500/10 text-amber-600",tool:"bg-sky-500/10 text-sky-600"};function n4({match:s}){const e=s.snippet.slice(0,s.snippetMatchStart),t=s.snippet.slice(s.snippetMatchStart,s.snippetMatchStart+s.snippetMatchLength),r=s.snippet.slice(s.snippetMatchStart+s.snippetMatchLength);return c.jsxs("span",{className:"text-xs text-fg-secondary",children:[e,c.jsx("mark",{className:"bg-yellow-500/30 text-fg-primary rounded-[3px] px-0.5",children:t}),r]})}function o4({query:s,onQueryChange:e,matches:t,cursor:r,scanned:i,hasMore:n,loadingMore:a,truncated:o,onLoadEarlier:l,onJump:h,onClose:d,labelFor:u}){const{t:f}=Qt(["team","common"]),p=_.useRef(null),b=_.useRef(null);_.useEffect(()=>{p.current?.focus()},[]),_.useEffect(()=>{if(r<0)return;b.current?.querySelector(`[data-find-idx="${r}"]`)?.scrollIntoView({block:"nearest"})},[r]);const v=O=>{if(t.length===0)return;const x=(((r<0?O>=0?-1:0:r)+O)%t.length+t.length)%t.length;h(x)},g=s.trim().length>0;return c.jsxs("div",{className:"border-b border-border-default bg-surface-secondary/60 px-4 py-2 space-y-1.5 shrink-0",children:[c.jsxs("div",{className:"flex items-center gap-1.5",children:[c.jsxs("div",{className:"flex-1 relative",children:[c.jsx("svg",{className:"absolute left-2.5 top-1/2 -translate-y-1/2 w-3.5 h-3.5 text-fg-tertiary",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:c.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M21 21l-5.197-5.197m0 0A7.5 7.5 0 105.196 5.196a7.5 7.5 0 0010.607 10.607z"})}),c.jsx("input",{ref:p,value:s,onChange:O=>e(O.target.value),onKeyDown:O=>{O.key==="Escape"?(O.preventDefault(),d()):O.key==="Enter"?(O.preventDefault(),v(O.shiftKey?-1:1)):O.key==="ArrowDown"?(O.preventDefault(),v(1)):O.key==="ArrowUp"&&(O.preventDefault(),v(-1))},placeholder:f("page.findPlaceholder"),className:"w-full pl-8 pr-3 py-1.5 text-xs bg-surface-primary border border-border-default rounded-lg outline-none focus:border-brand-500/50 transition-colors"})]}),c.jsx("span",{className:"text-[11px] text-fg-tertiary tabular-nums shrink-0 min-w-[44px] text-center",children:g&&t.length>0?f("page.findMatchCount",{current:(r<0?0:r)+1,total:t.length}):g?"0/0":""}),c.jsx("button",{onClick:()=>v(-1),disabled:t.length===0,title:f("page.findPrev"),className:"p-1 rounded-md text-fg-tertiary hover:text-fg-primary hover:bg-surface-elevated disabled:opacity-40 disabled:hover:bg-transparent transition-colors",children:c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"18 15 12 9 6 15"})})}),c.jsx("button",{onClick:()=>v(1),disabled:t.length===0,title:f("page.findNext"),className:"p-1 rounded-md text-fg-tertiary hover:text-fg-primary hover:bg-surface-elevated disabled:opacity-40 disabled:hover:bg-transparent transition-colors",children:c.jsx("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"6 9 12 15 18 9"})})}),c.jsx("button",{onClick:d,title:f("page.findClose"),className:"p-1 rounded-md text-fg-tertiary hover:text-fg-primary hover:bg-surface-elevated transition-colors",children:c.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),c.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),g&&c.jsxs("div",{className:"flex items-center gap-2 text-[10px] text-fg-tertiary",children:[c.jsx("span",{children:f("page.findScopeLoaded",{count:i})}),o&&c.jsx("span",{className:"text-amber-600",children:f("page.findTruncated",{count:t.length})}),t.length===0&&!n&&c.jsx("span",{className:"text-fg-secondary",children:f("page.findNoMatches")}),n&&c.jsx("button",{onClick:l,disabled:a,className:"ml-auto text-brand-500 hover:text-brand-500 disabled:opacity-50 underline decoration-dotted",children:f(a?"page.findLoadingEarlier":"page.findLoadEarlier")})]}),g&&t.length>0&&c.jsx("div",{ref:b,className:"max-h-52 overflow-y-auto scrollbar-thin space-y-0.5",children:t.map((O,m)=>c.jsxs("button",{"data-find-idx":m,onClick:()=>h(m),className:`w-full text-left px-2.5 py-1.5 rounded-lg transition-colors ${m===r?"bg-brand-500/15 ring-1 ring-brand-500/40":"hover:bg-surface-elevated"}`,children:[c.jsxs("div",{className:"flex items-center gap-1.5 mb-0.5",children:[c.jsx("span",{className:`px-1.5 py-0 rounded text-[9px] font-medium shrink-0 ${i4[O.field]}`,children:f(r4[O.field])}),u&&c.jsx("span",{className:"text-[10px] text-fg-tertiary truncate",children:u(O)})]}),c.jsx("div",{className:"line-clamp-2 break-words",children:c.jsx(n4,{match:O})})]},`${O.messageId}-${O.field}-${m}`))})]})}const a4=300,l4=48;function c4(s){const e=[];if(s.segments&&s.segments.length>0){for(const t of s.segments)if(t.type==="text")t.thinking&&e.push({field:"thinking",value:t.thinking}),t.content&&e.push({field:"text",value:t.content});else if(t.type==="tool"){const r=[t.tool,t.result,t.error].filter(i=>!!i);r.length>0&&e.push({field:"tool",value:r.join(`
58
- `)})}if(e.length>0)return e}return s.text&&e.push({field:"text",value:s.text}),e}function h4(s,e,t,r=l4){const i=Math.max(0,e-r),n=Math.min(s.length,e+t+r),a=i>0?"…":"",o=n<s.length?"…":"",l=s.slice(i,e).replace(/\s+/g," "),h=s.slice(e,e+t).replace(/\s+/g," "),d=s.slice(e+t,n).replace(/\s+/g," ");return{text:`${a}${l}${h}${d}${o}`,matchStart:a.length+l.length,matchLength:h.length}}function d4(s,e,t={}){const r=t.limit??a4,i=e.trim().toLocaleLowerCase();if(i.length===0)return{matches:[],scanned:s.length,truncated:!1};const n=[];for(let a=0;a<s.length;a+=1){const o=s[a];for(const{field:l,value:h}of c4(o)){const d=h.toLocaleLowerCase();let u=0;for(;;){const f=d.indexOf(i,u);if(f===-1)break;const p=h4(h,f,i.length);if(n.push({messageIndex:a,messageId:o.id,field:l,snippet:p.text,snippetMatchStart:p.matchStart,snippetMatchLength:p.matchLength}),n.length>=r)return{matches:n,scanned:s.length,truncated:!0};u=f+i.length}}}return{matches:n,scanned:s.length,truncated:!1}}const u4=[{id:"files",prefixes:["file_read","file_write","file_edit","apply_patch"]},{id:"search",prefixes:["grep_search","glob_find","list_directory"]},{id:"runtime",prefixes:["shell_execute","background_exec","process"]},{id:"terminal",prefixes:["terminal__","list_terminals","new_terminal","select_terminal","close_terminal","read_terminal","write_terminal","exec_terminal"]},{id:"web",prefixes:["web_search","web_fetch","web_extract"]},{id:"multimodal",prefixes:["generate_image","text_to_speech","speech_to_text","generate_video","describe_image","upload_reference"]},{id:"browser",prefixes:["navigate_page","new_page","close_page","select_page","list_pages","open_page","resize_page","click","hover","fill","fill_form","type_text","press_key","take_screenshot","take_snapshot","evaluate_script","wait_for","list_console_messages","list_network_requests","get_console_message","get_network_request","lighthouse_audit","drag","upload_file","emulate","handle_dialog"]},{id:"tasks",prefixes:["task_create","task_list","task_update","task_get","task_assign","task_note","task_comment","task_submit_review","subtask_create","subtask_complete","subtask_cancel","subtask_list","task_check_duplicates","task_cleanup_duplicates","task_board_health","create_task","update_task","add_task_note","create_subtask"]},{id:"requirements",prefixes:["requirement_propose","requirement_list","requirement_get","requirement_update","requirement_update_status","requirement_resubmit","requirement_comment"]},{id:"projects",prefixes:["list_projects","get_project","create_project","update_project","delete_project","project_stats","project_structure","code_stats","git_"]},{id:"deliverables",prefixes:["deliverable_create","deliverable_search","deliverable_list","deliverable_update"]},{id:"packages",prefixes:["package_list","package_install","hub_search","hub_install","builder_list","builder_install","markus-hub__"]},{id:"communication",prefixes:["agent_send_message","agent_list_colleagues","agent_send_group_message","agent_create_group_chat","agent_list_group_chats","agent_broadcast_status","agent_delegate_task","feishu_"]},{id:"memory",prefixes:["memory_save","memory_search","memory_list","memory_update","memory_update_longterm","memory_delete","recall_context","recall_activity","update_working_memory","clear_working_memory","update_notebook","clear_notebook","session"]},{id:"mailbox",prefixes:["check_mailbox","defer_mailbox_item","drop_mailbox_item","prioritize_mailbox_item","delegate_message"]},{id:"planning",prefixes:["goal_create","goal_update","goal_status","workflow_"]},{id:"teamManager",prefixes:["team_list","team_status","team_update","team_start","team_stop","agent_update","agent_start","agent_stop","list_teams"]},{id:"subagents",prefixes:["spawn_subagent","spawn_subagents","invoke_coding_tool","coding_tool_apply"]},{id:"system",prefixes:["discover_tools","notify_user","request_user_input","request_user_approval","schedule_wakeup","cancel_wakeup","set_heartbeat_interval"]},{id:"llm",prefixes:["llm_","agent_model_"]}];function f4(s,e){const t=new Map,r=new Set;for(const{id:a,prefixes:o}of u4){const l=e(`agent:toolCategories.${a}`),h=s.filter(d=>!r.has(d.name)&&o.some(u=>d.name.startsWith(u)));h.length>0&&(t.set(l,h),h.forEach(d=>r.add(d.name)))}const i=s.filter(a=>!r.has(a.name));for(const a of i){const o=a.name.indexOf("__");if(o>0){const l=a.name.slice(0,o),h=e("agent:toolCategories.mcp",{server:l});t.has(h)||t.set(h,[]),t.get(h).push(a),r.add(a.name)}}const n=s.filter(a=>!r.has(a.name));return n.length>0&&t.set(e("agent:toolCategories.other"),n),[...t.entries()].map(([a,o])=>({category:a,tools:o}))}const R_=16;function m4(s,e,t=R_){const r=s??[];return r.length<=t?{visible:[...r],hiddenCount:0,collapsible:!1}:e?{visible:[...r],hiddenCount:0,collapsible:!0}:{visible:r.slice(0,t),hiddenCount:r.length-t,collapsible:!0}}function p4(s,e=Date.now()){const t=Math.max(0,e-(Number.isFinite(s)?s:e));return t<6e4?{unit:"seconds",count:Math.round(t/1e3)}:t<36e5?{unit:"minutes",count:Math.round(t/6e4)}:{unit:"hours",count:Math.round(t/36e5*10)/10}}const g4=_.lazy(()=>Ub(()=>import("./index-BrU2YO3p.js").then(s=>s.b1),__vite__mapDeps([0,1])).then(s=>({default:s.MarkdownMessage}))),Xc={mind:"mind",files:"files",tools:"tools",memory:"memory"},Mp=[{key:"overview",icon:"▦"},{key:"deliverables",icon:"📦"}];function fm(s,e){return e(`agent:profilePage.taskStatus.${s}`,{defaultValue:s.replace(/_/g," ")})}function O4(s,e){const{labelKey:t}=Ch(s);return t?e(t):s}function mm(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function _b({agentId:s,onBack:e,inline:t,defaultTab:r,onSwipeBack:i,highlightMailboxId:n,authUser:a,headless:o,activeTab:l,initialSection:h}){const{t:d}=Qt(["agent","common"]),u=Om(),[f,p]=_.useState(null),[b,v]=_.useState(null),[g,O]=_.useState(r??"overview"),m=o&&l?l:g,[x,y]=_.useState(null),w=_.useMemo(()=>Mp.map(Z=>({...Z,label:d(`agent:tabs.${Z.key}`)})),[d]),C=_.useMemo(()=>w.map(Z=>({id:Z.key})),[w]),P=_.useMemo(()=>({onSwipeOutLeft:i}),[i]),S=qb(C,g,O,P),T=_.useRef(null);_.useEffect(()=>{const Z=T.current;if(!Z)return;Z.querySelector('[data-active="true"]')?.scrollIntoView({behavior:"smooth",block:"nearest",inline:"center"})},[g]);const j=_.useCallback(()=>{re.agents.get(s).then(p).catch(()=>{})},[s]);if(_.useEffect(()=>(O(r??"overview"),y(null),j(),re.externalAgents.list().then(I=>{const ie=I.agents.find(Q=>Q.markusAgentId===s);y(ie??null)}).catch(()=>{}),bt.on("agent:update",I=>{I.payload.agentId===s&&j()})),[s,j]),!f)return c.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary text-sm",children:d("agent:profilePage.loadingAgent")});const M=Ch(f.state.status).dotClass,L=a?.role==="owner"||a?.role==="admin",E=Z=>h??Xc[Z],B=Z=>x||Xc[Z]?"overview":Z,U=Xc[g];return o?c.jsx("div",{className:"flex-1 overflow-y-auto bg-surface-primary",children:c.jsxs("div",{className:"p-5",children:[B(m)==="overview"&&c.jsx(kb,{agent:f,onUpdate:j,externalInfo:x,t:d,canManageAgents:L,highlightMailboxId:n,initialSection:E(m)}),B(m)==="deliverables"&&c.jsx(Mb,{agentId:s})]})}):c.jsxs("div",{className:"flex-1 overflow-y-auto bg-surface-primary",children:[c.jsxs("div",{className:"px-5 py-3.5 bg-surface-secondary sticky top-0 z-10",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx(Qs,{name:f.name,avatarUrl:f.avatarUrl,size:40,className:"rounded-xl"}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[c.jsx("h2",{className:"text-base font-semibold",children:f.name}),c.jsx("span",{className:`w-2 h-2 rounded-full ${M}`}),c.jsx("span",{className:"text-xs text-fg-tertiary",children:O4(f.state.status,d)}),x&&c.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-brand-500/15 text-brand-500 rounded font-medium",children:d("agent:profilePage.badges.external")}),f.agentRole==="manager"&&c.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-amber-500/15 text-amber-600 rounded font-medium",children:d("agent:profilePage.badges.manager")})]}),c.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[f.role,f.roleDescription?` — ${f.roleDescription}`:""]})]}),c.jsxs("div",{className:"flex gap-1.5 shrink-0",children:[!t&&c.jsxs("button",{onClick:()=>yr.navigate(Gt.TEAM,{agentId:s}),className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 text-white rounded-lg transition-colors flex items-center gap-1",children:[c.jsx("span",{children:"◈"})," ",d("agent:profilePage.chat")]}),L&&c.jsxs("button",{onClick:async()=>{if(f)try{const{filesMap:Z}=await re.agents.getFilesMap(s),I={type:"agent",name:Zb(f.name,f.name),displayName:f.name,version:"1.0.0",description:f.roleDescription??f.role,author:"",category:"general",tags:[],agent:{roleName:f.role,agentRole:f.agentRole},dependencies:{skills:f.skills??[]}};await vm.publishViaProxy({itemType:"agent",name:f.name,description:I.description,category:"general",config:I,files:Z}),v({title:d("agent:profilePage.hub"),message:d("agent:profilePage.publishSuccess",{name:f.name}),variant:"primary"})}catch(Z){v({title:d("agent:profilePage.hub"),message:d("agent:profilePage.publishFailed",{error:String(Z)}),variant:"danger"})}},className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 text-white rounded-lg transition-colors flex items-center gap-1",title:d("agent:profilePage.publishTitle"),children:[c.jsx("span",{children:"↑"})," ",d("agent:profilePage.hub")]}),t&&c.jsx("button",{onClick:e,className:"p-1.5 text-fg-tertiary hover:text-fg-secondary text-lg leading-none",children:"×"})]})]}),c.jsx("div",{ref:T,className:"flex gap-1 mt-3 -mb-[1px] overflow-x-auto scrollbar-hide",children:w.filter(Z=>!x||Z.key==="overview").map(Z=>c.jsxs("button",{onClick:()=>O(Z.key),"data-active":g===Z.key,className:`px-3 py-1.5 text-xs rounded-t-lg border border-b-0 transition-colors whitespace-nowrap ${g===Z.key?"bg-surface-primary text-fg-primary border-border-default":"text-fg-tertiary border-transparent hover:text-fg-secondary hover:bg-surface-elevated/50"}`,children:[c.jsx("span",{className:"mr-1",children:Z.icon}),Z.label]},Z.key))})]}),c.jsxs("div",{className:"p-5",onTouchStart:u?S.onTouchStart:void 0,onTouchEnd:u?S.onTouchEnd:void 0,children:[B(g)==="overview"&&c.jsx(kb,{agent:f,onUpdate:j,externalInfo:x,t:d,canManageAgents:L,highlightMailboxId:n,initialSection:h??U}),B(g)==="deliverables"&&c.jsx(Mb,{agentId:s})]}),b&&c.jsx(Po,{alertOnly:!0,variant:b.variant??"primary",title:b.title,message:b.message,onConfirm:()=>v(null),onCancel:()=>v(null)})]})}function x4({section:s,onChange:e,t}){return c.jsx("div",{role:"tablist",className:"flex border-b border-border-default overflow-x-auto scrollbar-hide",onTouchStart:r=>r.stopPropagation(),onTouchEnd:r=>r.stopPropagation(),children:Sm.map(r=>{const i=r===s,n=t(`agent:profilePage.overview.sections.${r}.hint`,{defaultValue:""});return c.jsx("button",{type:"button",role:"tab","aria-selected":i,title:n||void 0,onClick:()=>e(r),className:`px-3 py-2 text-xs whitespace-nowrap border-b-2 transition-colors cursor-pointer ${i?"border-brand-500 text-fg-primary font-medium":"border-transparent text-fg-tertiary hover:text-fg-secondary"}`,children:t(`agent:profilePage.overview.sections.${r}.title`)},r)})})}function Jn({children:s}){return c.jsx("div",{role:"tabpanel",className:"border border-border-default rounded-xl bg-surface-elevated/30 p-4",children:s})}function wb({agentId:s,act:e,dotClass:t,expanded:r,onToggle:i}){return c.jsxs("div",{children:[c.jsxs("button",{onClick:i,className:"w-full flex items-center gap-2.5 px-3 py-2 text-left transition-colors hover:bg-surface-elevated/40 cursor-pointer",children:[c.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${t}`}),c.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:e.label}),c.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:new Date(e.startedAt).toLocaleString()}),c.jsx("span",{className:"text-fg-tertiary text-[10px]",children:r?"▲":"▼"})]}),r&&c.jsx("div",{className:"border-t border-border-default/60 bg-surface-primary/40",children:c.jsx(_h,{agentId:s,activityId:e.id})})]})}function kb({agent:s,onUpdate:e,externalInfo:t,t:r,canManageAgents:i,highlightMailboxId:n,initialSection:a}){const[o,l]=_.useState(null),[h,d]=_.useState([]),[u,f]=_.useState(null),[p,b]=_.useState(null),[v,g]=_.useState(""),[O,m]=_.useState([]),[x,y]=_.useState(0),[w,C]=_.useState(()=>uO(a,n));_.useEffect(()=>{C(uO(a,n))},[a,n]);const P=(s.state.activeTaskIds??[]).join(",");_.useEffect(()=>{re.usage.agents().then(I=>{const ie=I.agents.find(Q=>Q.agentId===s.id);ie&&l(ie)}).catch(()=>{}),re.agents.getActivities(s.id,{limit:TC}).then(I=>d(I.activities)).catch(()=>{}),re.system.storage().then(I=>{g(I.dataDir+"/agents/"+s.id);const ie=I.agents.find(Q=>Q.id===s.id);ie&&b(ie)}).catch(()=>{}),s.state.activeTaskIds?.length&&re.tasks.list({assignedAgentId:s.id}).then(I=>{m(I.tasks.filter(ie=>s.state.activeTaskIds?.includes(ie.id)))}).catch(()=>{}),re.agents.getMailbox(s.id,{limit:1}).then(I=>{y(I.queued?.length??0)}).catch(()=>{})},[s.id,P,s.state.status]);const S=()=>{s.state.status==="offline"?re.agents.start(s.id).then(e):re.agents.stop(s.id).then(e)},T=_.useMemo(()=>[{method:"POST",path:"/api/gateway/sync",desc:r("agent:profilePage.gateway.sync")},{method:"GET",path:"/api/gateway/manual",desc:r("agent:profilePage.gateway.manual")},{method:"GET",path:"/api/gateway/team",desc:r("agent:profilePage.gateway.team")},{method:"GET",path:"/api/gateway/projects",desc:r("agent:profilePage.gateway.projects")},{method:"GET",path:"/api/gateway/requirements",desc:r("agent:profilePage.gateway.requirements")}],[r]),j=_.useMemo(()=>[{field:"assignedTasks",desc:r("agent:profilePage.syncContext.assignedTasks")},{field:"inboxMessages",desc:r("agent:profilePage.syncContext.inboxMessages")},{field:"teamContext",desc:r("agent:profilePage.syncContext.teamContext")},{field:"projectContext",desc:r("agent:profilePage.syncContext.projectContext")}],[r]);if(t)return c.jsxs("div",{className:"space-y-4",children:[c.jsx(fs,{title:r("agent:profilePage.overview.identity"),children:c.jsxs("div",{className:"grid grid-cols-2 gap-x-6 gap-y-3",children:[c.jsx(Ms,{label:r("agent:profilePage.overview.labels.name"),children:s.name}),c.jsx(Ms,{label:r("agent:profilePage.overview.labels.agentRole"),children:c.jsx("span",{className:s.agentRole==="manager"?"text-amber-600":"text-blue-600",children:s.agentRole==="manager"?r("agent:profilePage.roles.managerDisplay"):r("agent:profilePage.roles.workerDisplay")})}),c.jsx(Ms,{label:r("agent:profilePage.overview.labels.roleTemplate"),children:s.role}),c.jsx(Ms,{label:r("agent:profilePage.overview.labels.markusAgentId"),mono:!0,children:s.id}),c.jsx(Ms,{label:r("agent:profilePage.overview.labels.organization"),children:s.config?.orgId??"default"}),c.jsx(Ms,{label:r("agent:profilePage.overview.labels.created"),children:s.config?.createdAt?new Date(s.config.createdAt).toLocaleDateString():r("agent:profilePage.emDash")})]})}),c.jsx(fs,{title:r("agent:profilePage.overview.connectionStatus"),children:c.jsxs("div",{className:"flex flex-wrap items-center gap-x-5 gap-y-1.5",children:[c.jsx(Xs,{label:r("agent:profilePage.overview.labels.connection"),value:t.connected?r("common:status.online"):r("common:status.offline"),color:t.connected?"green":"gray"}),c.jsx(Xs,{label:r("agent:profilePage.overview.labels.platform"),value:r("agent:profilePage.overview.openClaw")}),c.jsx(Xs,{label:r("agent:profilePage.overview.labels.activeTasks"),value:String(s.state.activeTaskIds?.length??0)}),c.jsx(Xs,{label:r("agent:profilePage.overview.labels.lastSync"),value:t.lastHeartbeat?new Date(t.lastHeartbeat).toLocaleTimeString():r("agent:profilePage.never")})]})}),c.jsx(fs,{title:r("agent:profilePage.overview.externalAgentDetails"),children:c.jsxs("div",{className:"grid grid-cols-2 gap-x-6 gap-y-3",children:[c.jsx(Ms,{label:r("agent:profilePage.overview.labels.externalAgentId"),mono:!0,children:t.externalAgentId}),c.jsx(Ms,{label:r("agent:profilePage.overview.labels.registered"),children:new Date(t.registeredAt).toLocaleString()}),c.jsx(Ms,{label:r("agent:profilePage.overview.labels.capabilities"),children:t.capabilities.length>0?t.capabilities.join(", "):r("agent:profilePage.overview.noneDeclared")}),c.jsx(Ms,{label:r("agent:profilePage.overview.labels.lastHeartbeat"),children:t.lastHeartbeat?new Date(t.lastHeartbeat).toLocaleString():r("agent:profilePage.never")})]})}),c.jsx(fs,{title:r("agent:profilePage.overview.syncContextTitle"),children:c.jsx("div",{className:"space-y-1.5",children:j.map(I=>c.jsxs("div",{className:"flex items-start gap-2.5 px-3 py-2 rounded-lg bg-surface-elevated",children:[c.jsx("span",{className:"font-mono text-[10px] text-brand-500 shrink-0 pt-0.5",children:I.field}),c.jsx("span",{className:"text-[10px] text-fg-tertiary",children:I.desc})]},I.field))})}),c.jsx(fs,{title:r("agent:profilePage.overview.gatewayEndpoints"),children:c.jsx("div",{className:"space-y-1.5",children:T.map(I=>c.jsxs("div",{className:"flex items-start gap-2.5 px-3 py-2 rounded-lg bg-surface-elevated",children:[c.jsx("span",{className:`text-[10px] font-semibold shrink-0 pt-0.5 ${I.method==="POST"?"text-amber-600":"text-green-600"}`,children:I.method}),c.jsx("span",{className:"font-mono text-[10px] text-fg-secondary shrink-0 pt-0.5",children:I.path}),c.jsx("span",{className:"text-[10px] text-fg-tertiary ml-auto",children:I.desc})]},I.path))})})]});const{heartbeats:M,comms:L}=QC(h),E=dO(M),B=dO(L),U=s.state.activeTaskIds?.length??0,Z=[h.length>0?r("agent:profilePage.overview.recentWindow",{count:h.length}):null,E.total>0?r("agent:profilePage.overview.heartbeatRuns",{count:E.total}):null,B.total>0?r("agent:profilePage.overview.a2aRuns",{count:B.total}):null].filter(Boolean).join(" · ");return c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"bg-surface-elevated rounded-xl px-4 py-3 flex flex-wrap items-center gap-x-5 gap-y-1.5",children:[c.jsx(Ms,{label:r("agent:profilePage.overview.labels.roleTemplate"),children:s.role}),c.jsx(Ms,{label:r("agent:profilePage.overview.labels.agentRole"),children:c.jsx("span",{className:s.agentRole==="manager"?"text-amber-600":"text-blue-600",children:s.agentRole==="manager"?r("agent:profilePage.roles.managerDisplay"):r("agent:profilePage.roles.workerDisplay")})}),c.jsx(Ms,{label:r("agent:profilePage.overview.labels.agentId"),mono:!0,children:s.id}),c.jsx(Ms,{label:r("agent:profilePage.overview.labels.model"),children:s.effectiveModel?.model?c.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[c.jsx("span",{className:"font-mono",children:s.effectiveModel.model}),s.config?.llmConfig?.modelMode==="custom"&&s.effectiveModel.source!=="override"?c.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-brand-500/15 text-brand-500 rounded font-medium",children:r("agent:profilePage.overview.labels.badgeAgentModel")}):s.effectiveModel.source==="override"?c.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-amber-500/15 text-amber-600 rounded font-medium",children:r("agent:profilePage.overview.labels.badgeSessionModel")}):null]}):c.jsx("span",{className:"text-fg-tertiary",children:r("agent:profilePage.overview.labels.followsGlobal")})}),c.jsx(Ms,{label:r("agent:profilePage.overview.labels.created"),children:s.config?.createdAt?new Date(s.config.createdAt).toLocaleDateString():r("agent:profilePage.emDash")})]}),c.jsxs("div",{className:"bg-surface-elevated rounded-xl px-4 py-3 space-y-3",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-x-5 gap-y-1.5",children:[c.jsx(Xs,{label:r("agent:profilePage.overview.labels.tokensToday"),value:mm(SC(o,s.state.tokensUsedToday))}),c.jsx(Xs,{label:r("agent:profilePage.overview.labels.activeTasks"),value:String(U),color:U>0?"blue":void 0}),i&&c.jsx("button",{onClick:S,className:"ml-auto px-3 py-1 text-xs border border-border-default rounded-lg hover:border-brand-500 transition-colors shrink-0",children:s.state.status==="offline"?r("agent:profilePage.overview.startAgent"):r("agent:profilePage.overview.stopAgent")})]}),s.state.status==="error"&&c.jsxs("div",{className:"bg-red-500/10 border border-red-500/20 rounded-lg p-3",children:[c.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[c.jsx("span",{className:"text-xs font-medium text-red-500",children:r("agent:profilePage.overview.errorDetails")}),s.state.lastErrorAt&&c.jsx("span",{className:"text-[10px] text-red-500/50 ml-auto",children:new Date(s.state.lastErrorAt).toLocaleString()})]}),c.jsx("pre",{className:"text-[11px] text-red-500/80 leading-relaxed whitespace-pre-wrap break-all font-mono bg-red-500/5 rounded p-2",children:zc(s.state.lastError,r)||s.state.lastError||r("agent:profilePage.overview.errorFallback")})]}),s.state.status==="working"&&(U>0||x>0||s.runtime?.activityLabel)&&c.jsx("div",{className:"bg-brand-500/10 border border-brand-500/20 rounded-lg p-2.5",children:c.jsxs("div",{className:"space-y-1.5",children:[s.runtime?.activityLabel&&c.jsxs("div",{className:"flex items-center gap-2 text-[11px]",children:[c.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-400 animate-pulse shrink-0"}),c.jsx("span",{className:"text-fg-secondary truncate flex-1",children:s.runtime.activityLabel}),s.runtime.activityType&&c.jsx("span",{className:"text-fg-tertiary capitalize shrink-0",children:s.runtime.activityType})]}),O.map(I=>c.jsxs("div",{className:"flex items-center gap-2 text-[11px]",children:[c.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-400 animate-pulse shrink-0"}),c.jsx("span",{className:"text-fg-secondary truncate flex-1",children:I.title}),c.jsx("span",{className:"text-fg-tertiary capitalize shrink-0",children:fm(I.status,r)})]},I.id)),x>0&&c.jsxs("div",{className:"flex items-center gap-2 text-[11px]",children:[c.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-amber-400 shrink-0"}),c.jsx("span",{className:"text-fg-secondary flex-1",children:r("agent:profilePage.overview.mailboxQueued",{count:x})})]})]})})]}),c.jsx(x4,{section:w,onChange:C,t:r}),w==="usage"&&c.jsx(Jn,{children:o||p?c.jsxs("div",{className:"space-y-2",children:[o&&c.jsxs("div",{className:"space-y-1",children:[c.jsx("p",{className:"text-[10px] text-fg-tertiary",children:r("agent:profilePage.overview.lifetimeCaption")}),c.jsxs("div",{className:"flex flex-wrap items-center gap-x-5 gap-y-1.5",children:[c.jsx(Xs,{label:r("agent:profilePage.overview.labels.totalTokens"),value:mm(o.totalTokens)}),c.jsx(Xs,{label:r("agent:profilePage.overview.labels.requests"),value:String(o.requestCount)}),c.jsx(Xs,{label:r("agent:profilePage.overview.labels.toolCalls"),value:String(o.toolCalls)})]})]}),p&&c.jsxs("div",{className:"space-y-1",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-x-5 gap-y-1.5",children:[c.jsx(Xs,{label:r("agent:profilePage.overview.storage"),value:jb(p.size)}),_C(p.subItems).map(I=>{const ie=kC(I.name);return c.jsx(Xs,{label:ie?r(ie):I.name,value:jb(I.size)},I.name)}),c.jsxs("button",{onClick:()=>{re.system.openPath(v)},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary ml-auto",children:[r("agent:profilePage.overview.openFolder")," →"]})]}),p.depthLimited&&c.jsx("p",{className:"text-[10px] text-fg-tertiary",children:r("agent:profilePage.overview.storageDepthLimited")})]})]}):c.jsx("p",{className:"text-xs text-fg-tertiary",children:r("agent:profilePage.overview.sections.usage.empty")})}),w==="recent"&&c.jsxs(Jn,{children:[Z&&c.jsx("p",{className:"text-[10px] text-fg-tertiary mb-2",children:Z}),E.total>0&&c.jsxs("div",{children:[c.jsx("h4",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider mb-1",children:r("agent:profilePage.overview.recentHeartbeats")}),c.jsx("div",{className:"divide-y divide-gray-800/50",children:E.shown.map(I=>c.jsx(wb,{agentId:s.id,act:I,dotClass:"bg-green-400",expanded:u===I.id,onToggle:()=>f(u===I.id?null:I.id)},I.id))})]}),B.total>0&&c.jsxs("div",{className:"mt-3",children:[c.jsx("h4",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider mb-1",children:r("agent:profilePage.overview.recentA2A")}),c.jsx("div",{className:"divide-y divide-gray-800/50",children:B.shown.map(I=>c.jsx(wb,{agentId:s.id,act:I,dotClass:"bg-blue-400",expanded:u===I.id,onToggle:()=>f(u===I.id?null:I.id)},I.id))})]}),E.total===0&&B.total===0&&c.jsx("p",{className:"text-xs text-fg-tertiary",children:r("agent:profilePage.overview.sections.recent.empty")})]}),w==="mind"&&c.jsx(Jn,{children:c.jsx(D4,{agentId:s.id,highlightId:n,agentStatus:s.state.status,canManageAgents:i})}),w==="files"&&c.jsx(Jn,{children:c.jsx(S4,{agentId:s.id})}),w==="tools"&&c.jsx(Jn,{children:c.jsx(P4,{tools:s.tools??[],agent:s})}),w==="memory"&&c.jsxs(Jn,{children:[c.jsx(Q4,{agentId:s.id,initialData:s.heartbeat}),c.jsx("div",{className:"mt-6",children:c.jsx(T4,{agentId:s.id})})]})]})}function b4(s,e){const t=s.split(`
58
+ `)})}if(e.length>0)return e}return s.text&&e.push({field:"text",value:s.text}),e}function h4(s,e,t,r=l4){const i=Math.max(0,e-r),n=Math.min(s.length,e+t+r),a=i>0?"…":"",o=n<s.length?"…":"",l=s.slice(i,e).replace(/\s+/g," "),h=s.slice(e,e+t).replace(/\s+/g," "),d=s.slice(e+t,n).replace(/\s+/g," ");return{text:`${a}${l}${h}${d}${o}`,matchStart:a.length+l.length,matchLength:h.length}}function d4(s,e,t={}){const r=t.limit??a4,i=e.trim().toLocaleLowerCase();if(i.length===0)return{matches:[],scanned:s.length,truncated:!1};const n=[];for(let a=0;a<s.length;a+=1){const o=s[a];for(const{field:l,value:h}of c4(o)){const d=h.toLocaleLowerCase();let u=0;for(;;){const f=d.indexOf(i,u);if(f===-1)break;const p=h4(h,f,i.length);if(n.push({messageIndex:a,messageId:o.id,field:l,snippet:p.text,snippetMatchStart:p.matchStart,snippetMatchLength:p.matchLength}),n.length>=r)return{matches:n,scanned:s.length,truncated:!0};u=f+i.length}}}return{matches:n,scanned:s.length,truncated:!1}}const u4=[{id:"files",prefixes:["file_read","file_write","file_edit","apply_patch"]},{id:"search",prefixes:["grep_search","glob_find","list_directory"]},{id:"runtime",prefixes:["shell_execute","background_exec","process"]},{id:"terminal",prefixes:["terminal__","list_terminals","new_terminal","select_terminal","close_terminal","read_terminal","write_terminal","exec_terminal"]},{id:"web",prefixes:["web_search","web_fetch","web_extract"]},{id:"multimodal",prefixes:["generate_image","text_to_speech","speech_to_text","generate_video","describe_image","upload_reference"]},{id:"browser",prefixes:["navigate_page","new_page","close_page","select_page","list_pages","open_page","resize_page","click","hover","fill","fill_form","type_text","press_key","take_screenshot","take_snapshot","evaluate_script","wait_for","list_console_messages","list_network_requests","get_console_message","get_network_request","lighthouse_audit","drag","upload_file","emulate","handle_dialog"]},{id:"tasks",prefixes:["task_create","task_list","task_update","task_get","task_assign","task_note","task_comment","task_submit_review","subtask_create","subtask_complete","subtask_cancel","subtask_list","task_check_duplicates","task_cleanup_duplicates","task_board_health","create_task","update_task","add_task_note","create_subtask"]},{id:"requirements",prefixes:["requirement_propose","requirement_list","requirement_get","requirement_update","requirement_update_status","requirement_resubmit","requirement_comment"]},{id:"projects",prefixes:["list_projects","get_project","create_project","update_project","delete_project","project_stats","project_structure","code_stats","git_"]},{id:"deliverables",prefixes:["deliverable_create","deliverable_search","deliverable_list","deliverable_update"]},{id:"packages",prefixes:["package_list","package_install","hub_search","hub_install","builder_list","builder_install","markus-hub__"]},{id:"communication",prefixes:["agent_send_message","agent_list_colleagues","agent_send_group_message","agent_create_group_chat","agent_list_group_chats","agent_broadcast_status","agent_delegate_task","feishu_"]},{id:"memory",prefixes:["memory_save","memory_search","memory_list","memory_update","memory_update_longterm","memory_delete","recall_context","recall_activity","update_working_memory","clear_working_memory","update_notebook","clear_notebook","session"]},{id:"mailbox",prefixes:["check_mailbox","defer_mailbox_item","drop_mailbox_item","prioritize_mailbox_item","delegate_message"]},{id:"planning",prefixes:["goal_create","goal_update","goal_status","workflow_"]},{id:"teamManager",prefixes:["team_list","team_status","team_update","team_start","team_stop","agent_update","agent_start","agent_stop","list_teams"]},{id:"subagents",prefixes:["spawn_subagent","spawn_subagents","invoke_coding_tool","coding_tool_apply"]},{id:"system",prefixes:["discover_tools","notify_user","request_user_input","request_user_approval","schedule_wakeup","cancel_wakeup","set_heartbeat_interval"]},{id:"llm",prefixes:["llm_","agent_model_"]}];function f4(s,e){const t=new Map,r=new Set;for(const{id:a,prefixes:o}of u4){const l=e(`agent:toolCategories.${a}`),h=s.filter(d=>!r.has(d.name)&&o.some(u=>d.name.startsWith(u)));h.length>0&&(t.set(l,h),h.forEach(d=>r.add(d.name)))}const i=s.filter(a=>!r.has(a.name));for(const a of i){const o=a.name.indexOf("__");if(o>0){const l=a.name.slice(0,o),h=e("agent:toolCategories.mcp",{server:l});t.has(h)||t.set(h,[]),t.get(h).push(a),r.add(a.name)}}const n=s.filter(a=>!r.has(a.name));return n.length>0&&t.set(e("agent:toolCategories.other"),n),[...t.entries()].map(([a,o])=>({category:a,tools:o}))}const R_=16;function m4(s,e,t=R_){const r=s??[];return r.length<=t?{visible:[...r],hiddenCount:0,collapsible:!1}:e?{visible:[...r],hiddenCount:0,collapsible:!0}:{visible:r.slice(0,t),hiddenCount:r.length-t,collapsible:!0}}function p4(s,e=Date.now()){const t=Math.max(0,e-(Number.isFinite(s)?s:e));return t<6e4?{unit:"seconds",count:Math.round(t/1e3)}:t<36e5?{unit:"minutes",count:Math.round(t/6e4)}:{unit:"hours",count:Math.round(t/36e5*10)/10}}const g4=_.lazy(()=>Ub(()=>import("./index-B6fl84HP.js").then(s=>s.b1),__vite__mapDeps([0,1])).then(s=>({default:s.MarkdownMessage}))),Xc={mind:"mind",files:"files",tools:"tools",memory:"memory"},Mp=[{key:"overview",icon:"▦"},{key:"deliverables",icon:"📦"}];function fm(s,e){return e(`agent:profilePage.taskStatus.${s}`,{defaultValue:s.replace(/_/g," ")})}function O4(s,e){const{labelKey:t}=Ch(s);return t?e(t):s}function mm(s){return s>=1e6?`${(s/1e6).toFixed(1)}M`:s>=1e3?`${(s/1e3).toFixed(1)}K`:s.toLocaleString()}function _b({agentId:s,onBack:e,inline:t,defaultTab:r,onSwipeBack:i,highlightMailboxId:n,authUser:a,headless:o,activeTab:l,initialSection:h}){const{t:d}=Qt(["agent","common"]),u=Om(),[f,p]=_.useState(null),[b,v]=_.useState(null),[g,O]=_.useState(r??"overview"),m=o&&l?l:g,[x,y]=_.useState(null),w=_.useMemo(()=>Mp.map(Z=>({...Z,label:d(`agent:tabs.${Z.key}`)})),[d]),C=_.useMemo(()=>w.map(Z=>({id:Z.key})),[w]),P=_.useMemo(()=>({onSwipeOutLeft:i}),[i]),S=qb(C,g,O,P),T=_.useRef(null);_.useEffect(()=>{const Z=T.current;if(!Z)return;Z.querySelector('[data-active="true"]')?.scrollIntoView({behavior:"smooth",block:"nearest",inline:"center"})},[g]);const j=_.useCallback(()=>{re.agents.get(s).then(p).catch(()=>{})},[s]);if(_.useEffect(()=>(O(r??"overview"),y(null),j(),re.externalAgents.list().then(I=>{const ie=I.agents.find(Q=>Q.markusAgentId===s);y(ie??null)}).catch(()=>{}),bt.on("agent:update",I=>{I.payload.agentId===s&&j()})),[s,j]),!f)return c.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary text-sm",children:d("agent:profilePage.loadingAgent")});const M=Ch(f.state.status).dotClass,L=a?.role==="owner"||a?.role==="admin",E=Z=>h??Xc[Z],B=Z=>x||Xc[Z]?"overview":Z,U=Xc[g];return o?c.jsx("div",{className:"flex-1 overflow-y-auto bg-surface-primary",children:c.jsxs("div",{className:"p-5",children:[B(m)==="overview"&&c.jsx(kb,{agent:f,onUpdate:j,externalInfo:x,t:d,canManageAgents:L,highlightMailboxId:n,initialSection:E(m)}),B(m)==="deliverables"&&c.jsx(Mb,{agentId:s})]})}):c.jsxs("div",{className:"flex-1 overflow-y-auto bg-surface-primary",children:[c.jsxs("div",{className:"px-5 py-3.5 bg-surface-secondary sticky top-0 z-10",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx(Qs,{name:f.name,avatarUrl:f.avatarUrl,size:40,className:"rounded-xl"}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[c.jsx("h2",{className:"text-base font-semibold",children:f.name}),c.jsx("span",{className:`w-2 h-2 rounded-full ${M}`}),c.jsx("span",{className:"text-xs text-fg-tertiary",children:O4(f.state.status,d)}),x&&c.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-brand-500/15 text-brand-500 rounded font-medium",children:d("agent:profilePage.badges.external")}),f.agentRole==="manager"&&c.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-amber-500/15 text-amber-600 rounded font-medium",children:d("agent:profilePage.badges.manager")})]}),c.jsxs("div",{className:"text-xs text-fg-tertiary truncate",children:[f.role,f.roleDescription?` — ${f.roleDescription}`:""]})]}),c.jsxs("div",{className:"flex gap-1.5 shrink-0",children:[!t&&c.jsxs("button",{onClick:()=>yr.navigate(Gt.TEAM,{agentId:s}),className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 text-white rounded-lg transition-colors flex items-center gap-1",children:[c.jsx("span",{children:"◈"})," ",d("agent:profilePage.chat")]}),L&&c.jsxs("button",{onClick:async()=>{if(f)try{const{filesMap:Z}=await re.agents.getFilesMap(s),I={type:"agent",name:Zb(f.name,f.name),displayName:f.name,version:"1.0.0",description:f.roleDescription??f.role,author:"",category:"general",tags:[],agent:{roleName:f.role,agentRole:f.agentRole},dependencies:{skills:f.skills??[]}};await vm.publishViaProxy({itemType:"agent",name:f.name,description:I.description,category:"general",config:I,files:Z}),v({title:d("agent:profilePage.hub"),message:d("agent:profilePage.publishSuccess",{name:f.name}),variant:"primary"})}catch(Z){v({title:d("agent:profilePage.hub"),message:d("agent:profilePage.publishFailed",{error:String(Z)}),variant:"danger"})}},className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 text-white rounded-lg transition-colors flex items-center gap-1",title:d("agent:profilePage.publishTitle"),children:[c.jsx("span",{children:"↑"})," ",d("agent:profilePage.hub")]}),t&&c.jsx("button",{onClick:e,className:"p-1.5 text-fg-tertiary hover:text-fg-secondary text-lg leading-none",children:"×"})]})]}),c.jsx("div",{ref:T,className:"flex gap-1 mt-3 -mb-[1px] overflow-x-auto scrollbar-hide",children:w.filter(Z=>!x||Z.key==="overview").map(Z=>c.jsxs("button",{onClick:()=>O(Z.key),"data-active":g===Z.key,className:`px-3 py-1.5 text-xs rounded-t-lg border border-b-0 transition-colors whitespace-nowrap ${g===Z.key?"bg-surface-primary text-fg-primary border-border-default":"text-fg-tertiary border-transparent hover:text-fg-secondary hover:bg-surface-elevated/50"}`,children:[c.jsx("span",{className:"mr-1",children:Z.icon}),Z.label]},Z.key))})]}),c.jsxs("div",{className:"p-5",onTouchStart:u?S.onTouchStart:void 0,onTouchEnd:u?S.onTouchEnd:void 0,children:[B(g)==="overview"&&c.jsx(kb,{agent:f,onUpdate:j,externalInfo:x,t:d,canManageAgents:L,highlightMailboxId:n,initialSection:h??U}),B(g)==="deliverables"&&c.jsx(Mb,{agentId:s})]}),b&&c.jsx(Po,{alertOnly:!0,variant:b.variant??"primary",title:b.title,message:b.message,onConfirm:()=>v(null),onCancel:()=>v(null)})]})}function x4({section:s,onChange:e,t}){return c.jsx("div",{role:"tablist",className:"flex border-b border-border-default overflow-x-auto scrollbar-hide",onTouchStart:r=>r.stopPropagation(),onTouchEnd:r=>r.stopPropagation(),children:Sm.map(r=>{const i=r===s,n=t(`agent:profilePage.overview.sections.${r}.hint`,{defaultValue:""});return c.jsx("button",{type:"button",role:"tab","aria-selected":i,title:n||void 0,onClick:()=>e(r),className:`px-3 py-2 text-xs whitespace-nowrap border-b-2 transition-colors cursor-pointer ${i?"border-brand-500 text-fg-primary font-medium":"border-transparent text-fg-tertiary hover:text-fg-secondary"}`,children:t(`agent:profilePage.overview.sections.${r}.title`)},r)})})}function Jn({children:s}){return c.jsx("div",{role:"tabpanel",className:"border border-border-default rounded-xl bg-surface-elevated/30 p-4",children:s})}function wb({agentId:s,act:e,dotClass:t,expanded:r,onToggle:i}){return c.jsxs("div",{children:[c.jsxs("button",{onClick:i,className:"w-full flex items-center gap-2.5 px-3 py-2 text-left transition-colors hover:bg-surface-elevated/40 cursor-pointer",children:[c.jsx("span",{className:`w-2 h-2 rounded-full shrink-0 ${t}`}),c.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:e.label}),c.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:new Date(e.startedAt).toLocaleString()}),c.jsx("span",{className:"text-fg-tertiary text-[10px]",children:r?"▲":"▼"})]}),r&&c.jsx("div",{className:"border-t border-border-default/60 bg-surface-primary/40",children:c.jsx(_h,{agentId:s,activityId:e.id})})]})}function kb({agent:s,onUpdate:e,externalInfo:t,t:r,canManageAgents:i,highlightMailboxId:n,initialSection:a}){const[o,l]=_.useState(null),[h,d]=_.useState([]),[u,f]=_.useState(null),[p,b]=_.useState(null),[v,g]=_.useState(""),[O,m]=_.useState([]),[x,y]=_.useState(0),[w,C]=_.useState(()=>uO(a,n));_.useEffect(()=>{C(uO(a,n))},[a,n]);const P=(s.state.activeTaskIds??[]).join(",");_.useEffect(()=>{re.usage.agents().then(I=>{const ie=I.agents.find(Q=>Q.agentId===s.id);ie&&l(ie)}).catch(()=>{}),re.agents.getActivities(s.id,{limit:TC}).then(I=>d(I.activities)).catch(()=>{}),re.system.storage().then(I=>{g(I.dataDir+"/agents/"+s.id);const ie=I.agents.find(Q=>Q.id===s.id);ie&&b(ie)}).catch(()=>{}),s.state.activeTaskIds?.length&&re.tasks.list({assignedAgentId:s.id}).then(I=>{m(I.tasks.filter(ie=>s.state.activeTaskIds?.includes(ie.id)))}).catch(()=>{}),re.agents.getMailbox(s.id,{limit:1}).then(I=>{y(I.queued?.length??0)}).catch(()=>{})},[s.id,P,s.state.status]);const S=()=>{s.state.status==="offline"?re.agents.start(s.id).then(e):re.agents.stop(s.id).then(e)},T=_.useMemo(()=>[{method:"POST",path:"/api/gateway/sync",desc:r("agent:profilePage.gateway.sync")},{method:"GET",path:"/api/gateway/manual",desc:r("agent:profilePage.gateway.manual")},{method:"GET",path:"/api/gateway/team",desc:r("agent:profilePage.gateway.team")},{method:"GET",path:"/api/gateway/projects",desc:r("agent:profilePage.gateway.projects")},{method:"GET",path:"/api/gateway/requirements",desc:r("agent:profilePage.gateway.requirements")}],[r]),j=_.useMemo(()=>[{field:"assignedTasks",desc:r("agent:profilePage.syncContext.assignedTasks")},{field:"inboxMessages",desc:r("agent:profilePage.syncContext.inboxMessages")},{field:"teamContext",desc:r("agent:profilePage.syncContext.teamContext")},{field:"projectContext",desc:r("agent:profilePage.syncContext.projectContext")}],[r]);if(t)return c.jsxs("div",{className:"space-y-4",children:[c.jsx(fs,{title:r("agent:profilePage.overview.identity"),children:c.jsxs("div",{className:"grid grid-cols-2 gap-x-6 gap-y-3",children:[c.jsx(Ms,{label:r("agent:profilePage.overview.labels.name"),children:s.name}),c.jsx(Ms,{label:r("agent:profilePage.overview.labels.agentRole"),children:c.jsx("span",{className:s.agentRole==="manager"?"text-amber-600":"text-blue-600",children:s.agentRole==="manager"?r("agent:profilePage.roles.managerDisplay"):r("agent:profilePage.roles.workerDisplay")})}),c.jsx(Ms,{label:r("agent:profilePage.overview.labels.roleTemplate"),children:s.role}),c.jsx(Ms,{label:r("agent:profilePage.overview.labels.markusAgentId"),mono:!0,children:s.id}),c.jsx(Ms,{label:r("agent:profilePage.overview.labels.organization"),children:s.config?.orgId??"default"}),c.jsx(Ms,{label:r("agent:profilePage.overview.labels.created"),children:s.config?.createdAt?new Date(s.config.createdAt).toLocaleDateString():r("agent:profilePage.emDash")})]})}),c.jsx(fs,{title:r("agent:profilePage.overview.connectionStatus"),children:c.jsxs("div",{className:"flex flex-wrap items-center gap-x-5 gap-y-1.5",children:[c.jsx(Xs,{label:r("agent:profilePage.overview.labels.connection"),value:t.connected?r("common:status.online"):r("common:status.offline"),color:t.connected?"green":"gray"}),c.jsx(Xs,{label:r("agent:profilePage.overview.labels.platform"),value:r("agent:profilePage.overview.openClaw")}),c.jsx(Xs,{label:r("agent:profilePage.overview.labels.activeTasks"),value:String(s.state.activeTaskIds?.length??0)}),c.jsx(Xs,{label:r("agent:profilePage.overview.labels.lastSync"),value:t.lastHeartbeat?new Date(t.lastHeartbeat).toLocaleTimeString():r("agent:profilePage.never")})]})}),c.jsx(fs,{title:r("agent:profilePage.overview.externalAgentDetails"),children:c.jsxs("div",{className:"grid grid-cols-2 gap-x-6 gap-y-3",children:[c.jsx(Ms,{label:r("agent:profilePage.overview.labels.externalAgentId"),mono:!0,children:t.externalAgentId}),c.jsx(Ms,{label:r("agent:profilePage.overview.labels.registered"),children:new Date(t.registeredAt).toLocaleString()}),c.jsx(Ms,{label:r("agent:profilePage.overview.labels.capabilities"),children:t.capabilities.length>0?t.capabilities.join(", "):r("agent:profilePage.overview.noneDeclared")}),c.jsx(Ms,{label:r("agent:profilePage.overview.labels.lastHeartbeat"),children:t.lastHeartbeat?new Date(t.lastHeartbeat).toLocaleString():r("agent:profilePage.never")})]})}),c.jsx(fs,{title:r("agent:profilePage.overview.syncContextTitle"),children:c.jsx("div",{className:"space-y-1.5",children:j.map(I=>c.jsxs("div",{className:"flex items-start gap-2.5 px-3 py-2 rounded-lg bg-surface-elevated",children:[c.jsx("span",{className:"font-mono text-[10px] text-brand-500 shrink-0 pt-0.5",children:I.field}),c.jsx("span",{className:"text-[10px] text-fg-tertiary",children:I.desc})]},I.field))})}),c.jsx(fs,{title:r("agent:profilePage.overview.gatewayEndpoints"),children:c.jsx("div",{className:"space-y-1.5",children:T.map(I=>c.jsxs("div",{className:"flex items-start gap-2.5 px-3 py-2 rounded-lg bg-surface-elevated",children:[c.jsx("span",{className:`text-[10px] font-semibold shrink-0 pt-0.5 ${I.method==="POST"?"text-amber-600":"text-green-600"}`,children:I.method}),c.jsx("span",{className:"font-mono text-[10px] text-fg-secondary shrink-0 pt-0.5",children:I.path}),c.jsx("span",{className:"text-[10px] text-fg-tertiary ml-auto",children:I.desc})]},I.path))})})]});const{heartbeats:M,comms:L}=QC(h),E=dO(M),B=dO(L),U=s.state.activeTaskIds?.length??0,Z=[h.length>0?r("agent:profilePage.overview.recentWindow",{count:h.length}):null,E.total>0?r("agent:profilePage.overview.heartbeatRuns",{count:E.total}):null,B.total>0?r("agent:profilePage.overview.a2aRuns",{count:B.total}):null].filter(Boolean).join(" · ");return c.jsxs("div",{className:"space-y-4",children:[c.jsxs("div",{className:"bg-surface-elevated rounded-xl px-4 py-3 flex flex-wrap items-center gap-x-5 gap-y-1.5",children:[c.jsx(Ms,{label:r("agent:profilePage.overview.labels.roleTemplate"),children:s.role}),c.jsx(Ms,{label:r("agent:profilePage.overview.labels.agentRole"),children:c.jsx("span",{className:s.agentRole==="manager"?"text-amber-600":"text-blue-600",children:s.agentRole==="manager"?r("agent:profilePage.roles.managerDisplay"):r("agent:profilePage.roles.workerDisplay")})}),c.jsx(Ms,{label:r("agent:profilePage.overview.labels.agentId"),mono:!0,children:s.id}),c.jsx(Ms,{label:r("agent:profilePage.overview.labels.model"),children:s.effectiveModel?.model?c.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[c.jsx("span",{className:"font-mono",children:s.effectiveModel.model}),s.config?.llmConfig?.modelMode==="custom"&&s.effectiveModel.source!=="override"?c.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-brand-500/15 text-brand-500 rounded font-medium",children:r("agent:profilePage.overview.labels.badgeAgentModel")}):s.effectiveModel.source==="override"?c.jsx("span",{className:"px-1.5 py-0.5 text-[10px] bg-amber-500/15 text-amber-600 rounded font-medium",children:r("agent:profilePage.overview.labels.badgeSessionModel")}):null]}):c.jsx("span",{className:"text-fg-tertiary",children:r("agent:profilePage.overview.labels.followsGlobal")})}),c.jsx(Ms,{label:r("agent:profilePage.overview.labels.created"),children:s.config?.createdAt?new Date(s.config.createdAt).toLocaleDateString():r("agent:profilePage.emDash")})]}),c.jsxs("div",{className:"bg-surface-elevated rounded-xl px-4 py-3 space-y-3",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-x-5 gap-y-1.5",children:[c.jsx(Xs,{label:r("agent:profilePage.overview.labels.tokensToday"),value:mm(SC(o,s.state.tokensUsedToday))}),c.jsx(Xs,{label:r("agent:profilePage.overview.labels.activeTasks"),value:String(U),color:U>0?"blue":void 0}),i&&c.jsx("button",{onClick:S,className:"ml-auto px-3 py-1 text-xs border border-border-default rounded-lg hover:border-brand-500 transition-colors shrink-0",children:s.state.status==="offline"?r("agent:profilePage.overview.startAgent"):r("agent:profilePage.overview.stopAgent")})]}),s.state.status==="error"&&c.jsxs("div",{className:"bg-red-500/10 border border-red-500/20 rounded-lg p-3",children:[c.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[c.jsx("span",{className:"text-xs font-medium text-red-500",children:r("agent:profilePage.overview.errorDetails")}),s.state.lastErrorAt&&c.jsx("span",{className:"text-[10px] text-red-500/50 ml-auto",children:new Date(s.state.lastErrorAt).toLocaleString()})]}),c.jsx("pre",{className:"text-[11px] text-red-500/80 leading-relaxed whitespace-pre-wrap break-all font-mono bg-red-500/5 rounded p-2",children:zc(s.state.lastError,r)||s.state.lastError||r("agent:profilePage.overview.errorFallback")})]}),s.state.status==="working"&&(U>0||x>0||s.runtime?.activityLabel)&&c.jsx("div",{className:"bg-brand-500/10 border border-brand-500/20 rounded-lg p-2.5",children:c.jsxs("div",{className:"space-y-1.5",children:[s.runtime?.activityLabel&&c.jsxs("div",{className:"flex items-center gap-2 text-[11px]",children:[c.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-400 animate-pulse shrink-0"}),c.jsx("span",{className:"text-fg-secondary truncate flex-1",children:s.runtime.activityLabel}),s.runtime.activityType&&c.jsx("span",{className:"text-fg-tertiary capitalize shrink-0",children:s.runtime.activityType})]}),O.map(I=>c.jsxs("div",{className:"flex items-center gap-2 text-[11px]",children:[c.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-brand-400 animate-pulse shrink-0"}),c.jsx("span",{className:"text-fg-secondary truncate flex-1",children:I.title}),c.jsx("span",{className:"text-fg-tertiary capitalize shrink-0",children:fm(I.status,r)})]},I.id)),x>0&&c.jsxs("div",{className:"flex items-center gap-2 text-[11px]",children:[c.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-amber-400 shrink-0"}),c.jsx("span",{className:"text-fg-secondary flex-1",children:r("agent:profilePage.overview.mailboxQueued",{count:x})})]})]})})]}),c.jsx(x4,{section:w,onChange:C,t:r}),w==="usage"&&c.jsx(Jn,{children:o||p?c.jsxs("div",{className:"space-y-2",children:[o&&c.jsxs("div",{className:"space-y-1",children:[c.jsx("p",{className:"text-[10px] text-fg-tertiary",children:r("agent:profilePage.overview.lifetimeCaption")}),c.jsxs("div",{className:"flex flex-wrap items-center gap-x-5 gap-y-1.5",children:[c.jsx(Xs,{label:r("agent:profilePage.overview.labels.totalTokens"),value:mm(o.totalTokens)}),c.jsx(Xs,{label:r("agent:profilePage.overview.labels.requests"),value:String(o.requestCount)}),c.jsx(Xs,{label:r("agent:profilePage.overview.labels.toolCalls"),value:String(o.toolCalls)})]})]}),p&&c.jsxs("div",{className:"space-y-1",children:[c.jsxs("div",{className:"flex flex-wrap items-center gap-x-5 gap-y-1.5",children:[c.jsx(Xs,{label:r("agent:profilePage.overview.storage"),value:jb(p.size)}),_C(p.subItems).map(I=>{const ie=kC(I.name);return c.jsx(Xs,{label:ie?r(ie):I.name,value:jb(I.size)},I.name)}),c.jsxs("button",{onClick:()=>{re.system.openPath(v)},className:"text-[10px] text-fg-tertiary hover:text-fg-secondary ml-auto",children:[r("agent:profilePage.overview.openFolder")," →"]})]}),p.depthLimited&&c.jsx("p",{className:"text-[10px] text-fg-tertiary",children:r("agent:profilePage.overview.storageDepthLimited")})]})]}):c.jsx("p",{className:"text-xs text-fg-tertiary",children:r("agent:profilePage.overview.sections.usage.empty")})}),w==="recent"&&c.jsxs(Jn,{children:[Z&&c.jsx("p",{className:"text-[10px] text-fg-tertiary mb-2",children:Z}),E.total>0&&c.jsxs("div",{children:[c.jsx("h4",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider mb-1",children:r("agent:profilePage.overview.recentHeartbeats")}),c.jsx("div",{className:"divide-y divide-gray-800/50",children:E.shown.map(I=>c.jsx(wb,{agentId:s.id,act:I,dotClass:"bg-green-400",expanded:u===I.id,onToggle:()=>f(u===I.id?null:I.id)},I.id))})]}),B.total>0&&c.jsxs("div",{className:"mt-3",children:[c.jsx("h4",{className:"text-[10px] text-fg-tertiary uppercase tracking-wider mb-1",children:r("agent:profilePage.overview.recentA2A")}),c.jsx("div",{className:"divide-y divide-gray-800/50",children:B.shown.map(I=>c.jsx(wb,{agentId:s.id,act:I,dotClass:"bg-blue-400",expanded:u===I.id,onToggle:()=>f(u===I.id?null:I.id)},I.id))})]}),E.total===0&&B.total===0&&c.jsx("p",{className:"text-xs text-fg-tertiary",children:r("agent:profilePage.overview.sections.recent.empty")})]}),w==="mind"&&c.jsx(Jn,{children:c.jsx(D4,{agentId:s.id,highlightId:n,agentStatus:s.state.status,canManageAgents:i})}),w==="files"&&c.jsx(Jn,{children:c.jsx(S4,{agentId:s.id})}),w==="tools"&&c.jsx(Jn,{children:c.jsx(P4,{tools:s.tools??[],agent:s})}),w==="memory"&&c.jsxs(Jn,{children:[c.jsx(Q4,{agentId:s.id,initialData:s.heartbeat}),c.jsx("div",{className:"mt-6",children:c.jsx(T4,{agentId:s.id})})]})]})}function b4(s,e){const t=s.split(`
59
59
  `),r=e.split(`
60
60
  `),i=t.length,n=r.length,a=Array.from({length:i+1},()=>new Array(n+1).fill(0));for(let f=i-1;f>=0;f--)for(let p=n-1;p>=0;p--)a[f][p]=t[f]===r[p]?a[f+1][p+1]+1:Math.max(a[f+1][p],a[f][p+1]);const o=[];let l=0,h=0,d=1,u=1;for(;l<i||h<n;)l<i&&h<n&&t[l]===r[h]?(o.push({type:"equal",content:t[l],oldLineNum:d++,lineNum:u++}),l++,h++):h<n&&(l>=i||a[l][h+1]>=a[l+1][h])?(o.push({type:"add",content:r[h],lineNum:u++}),h++):(o.push({type:"remove",content:t[l],oldLineNum:d++}),l++);return o}function Cb(s){return s.match(/\S+|\s+/g)??[""]}function Pb({oldText:s,newText:e,mode:t}){const r=Cb(s),i=Cb(e),n=r.length,a=i.length,o=Array.from({length:n+1},()=>new Array(a+1).fill(0));for(let u=n-1;u>=0;u--)for(let f=a-1;f>=0;f--)o[u][f]=r[u]===i[f]?o[u+1][f+1]+1:Math.max(o[u+1][f],o[u][f+1]);const l=[];let h=0,d=0;for(;h<n||d<a;)h<n&&d<a&&r[h]===i[d]?(l.push({text:t==="remove"?r[h]:i[d],changed:!1}),h++,d++):d<a&&(h>=n||o[h][d+1]>=o[h+1][d])?(t==="add"&&l.push({text:i[d],changed:!0}),d++):(t==="remove"&&l.push({text:r[h],changed:!0}),h++);return c.jsx("span",{children:l.map((u,f)=>u.changed?c.jsx("span",{className:t==="add"?"bg-green-500/30 rounded-sm":"bg-red-500/30 rounded-sm",children:u.text},f):c.jsx("span",{children:u.text},f))})}function v4({agent:s,template:e,templateId:t}){const{t:r}=Qt(["agent","common"]),i=_.useMemo(()=>b4(s,e),[s,e]),[n,a]=_.useState(!0),o=3,l=_.useMemo(()=>{const p=i.map((O,m)=>O.type!=="equal"?m:-1).filter(O=>O>=0);if(p.length===0)return[];const b=[];let v=Math.max(0,p[0]-o),g=Math.min(i.length-1,p[0]+o);for(let O=1;O<p.length;O++){const m=Math.max(0,p[O]-o),x=Math.min(i.length-1,p[O]+o);m<=g+1||(b.push({start:v,end:g}),v=m),g=x}return b.push({start:v,end:g}),b},[i]),h=(p,b,v)=>{const g=p.type==="add"?"+":p.type==="remove"?"-":" ",O=p.type==="add"?"bg-green-500/8":p.type==="remove"?"bg-red-500/8":"",m=p.type==="add"?"text-green-600/90":p.type==="remove"?"text-red-500/80":"text-fg-tertiary",x=p.type==="add"?"text-green-500":p.type==="remove"?"text-red-500":"text-fg-muted",y=p.type==="remove"?p.oldLineNum:p.lineNum;let w=null;return p.type==="remove"&&b+1<v.length&&v[b+1].type==="add"?w=c.jsx(Pb,{oldText:p.content,newText:v[b+1].content,mode:"remove"}):p.type==="add"&&b>0&&v[b-1].type==="remove"&&(w=c.jsx(Pb,{oldText:v[b-1].content,newText:p.content,mode:"add"})),c.jsxs("div",{className:`flex ${O} hover:brightness-95 transition-colors`,children:[c.jsx("span",{className:"w-10 shrink-0 text-right pr-2 text-[10px] text-fg-muted/50 select-none leading-[20px]",children:y??""}),c.jsx("span",{className:`w-4 shrink-0 text-center text-[11px] font-mono ${x} select-none leading-[20px]`,children:g}),c.jsxs("span",{className:`flex-1 text-[11px] font-mono ${m} whitespace-pre-wrap break-words leading-[20px]`,children:[w??p.content,p.content===""&&" "]})]},b)},d=i.filter(p=>p.type==="add").length,u=i.filter(p=>p.type==="remove").length,f=n?l.flatMap(p=>{const b=[];for(let v=p.start;v<=p.end;v++)b.push({...i[v],_idx:v});return b}):i.map((p,b)=>({...p,_idx:b}));return c.jsxs("div",{className:"mb-3 bg-surface-elevated rounded-lg overflow-hidden",children:[c.jsxs("div",{className:"flex items-center justify-between px-3 py-1.5 bg-surface-elevated",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("span",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider",children:r("agent:profilePage.diff.title",{templateId:t})}),c.jsxs("span",{className:"text-[10px] text-green-500 font-mono",children:["+",d]}),c.jsxs("span",{className:"text-[10px] text-red-500 font-mono",children:["-",u]})]}),c.jsx("button",{onClick:()=>a(p=>!p),className:"text-[10px] text-brand-500 hover:text-brand-400 transition-colors",children:r(n?"agent:profilePage.diff.showFullFile":"agent:profilePage.diff.showChangesOnly")})]}),c.jsxs("div",{className:"max-h-72 overflow-y-auto bg-surface-primary/50",children:[n&&l.length>0&&l[0].start>0&&c.jsx("div",{className:"text-[10px] text-fg-muted/50 text-center py-0.5 bg-surface-elevated/40 border-b border-border-default/30",children:r("agent:profilePage.diff.linesHidden",{count:l[0].start})}),f.map((p,b)=>{const v=b>0?f[b-1]:null,g=n&&v&&p._idx-v._idx>1;return c.jsxs("div",{children:[g&&c.jsx("div",{className:"text-[10px] text-fg-muted/50 text-center py-0.5 bg-surface-elevated/40 border-y border-border-default/30",children:"···"}),h(p,p._idx,i)]},b)}),n&&l.length>0&&l[l.length-1].end<i.length-1&&c.jsx("div",{className:"text-[10px] text-fg-muted/50 text-center py-0.5 bg-surface-elevated/40 border-t border-border-default/30",children:r("agent:profilePage.diff.linesHidden",{count:i.length-1-l[l.length-1].end})}),l.length===0&&c.jsx("div",{className:"text-xs text-fg-tertiary text-center py-4",children:r("agent:profilePage.diff.identical")})]})]})}function y4(s,e){const t=s.split(`
61
61
  `),r=e.split(`
@@ -72,7 +72,7 @@ ${G}
72
72
  `+ie.join(`
73
73
  ---
74
74
 
75
- `)+"\nPlease review each change and update your files if appropriate. You can use the `update_file` tool or ask me to apply the changes.";yr.navigate(Gt.TEAM,{agentId:s,prefillMessage:Q})},M=async Z=>{if(y?.file===Z){w(null);return}try{const I=await re.agents.roleDiff(s,Z);I.agentContent!=null&&I.templateContent!=null&&w({file:Z,agent:I.agentContent,template:I.templateContent})}catch{}};if(i)return c.jsx("div",{className:"text-xs text-fg-tertiary py-8 text-center",children:e("agent:profilePage.filesTab.loading")});const L={"ROLE.md":"roleMd","HEARTBEAT.md":"heartbeatMd","POLICIES.md":"policiesMd","CONTEXT.md":"contextMd"},E=Z=>{const I=L[Z];return I?e(`agent:profilePage.filesTab.fileLabels.${I}`):Z},B=m?.hasTemplate&&!m.isUpToDate,U=a?T.some(Z=>Z.file===a):!1;return c.jsxs("div",{className:"space-y-4",children:[B&&c.jsxs("div",{className:"bg-amber-500/8 border border-amber-500/25 rounded-xl p-4 flex items-start gap-3",children:[c.jsx("span",{className:"text-amber-600 text-sm mt-0.5",children:"↻"}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsx("div",{className:"text-xs text-amber-600 font-medium",children:e("agent:profilePage.filesTab.templateUpdateAvailable")}),c.jsxs("div",{className:"text-[11px] text-amber-600/70 mt-0.5",children:[e("agent:profilePage.filesTab.filesDiffer",{count:T.length,templateId:m.templateId})," ",T.map(Z=>Z.file).join(", ")]})]}),c.jsx("button",{onClick:()=>j(),className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 text-white rounded-lg transition-colors shrink-0",children:e("agent:profilePage.filesTab.sendToAgent")})]}),c.jsxs(fs,{title:e("agent:profilePage.filesTab.agentConfigFiles"),action:m?.hasTemplate?c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:`inline-block w-1.5 h-1.5 rounded-full ${m.isUpToDate?"bg-green-400":"bg-amber-400"}`}),c.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:[e("agent:profilePage.filesTab.templateLabel")," ",c.jsx("span",{className:"text-fg-secondary",children:m.templateId}),m.isUpToDate?e("agent:profilePage.filesTab.upToDate"):e("agent:profilePage.filesTab.updatesAvailable")]})]}):c.jsx("div",{className:"text-[10px] text-fg-tertiary",children:e("agent:profilePage.filesTab.customAgentNoTemplate")}),children:[c.jsx("div",{className:"flex gap-2 mb-4 flex-wrap",children:t.map(Z=>{const I=T.some(ie=>ie.file===Z.name);return c.jsxs("button",{onClick:()=>P(Z.name),className:`px-3 py-1.5 text-xs rounded-lg border transition-colors relative ${a===Z.name?"bg-brand-600/15 border-brand-500/40 text-brand-500":"border-border-default text-fg-tertiary hover:text-fg-secondary"}`,children:[Z.name,I&&c.jsx("span",{className:"absolute -top-1 -right-1 w-2 h-2 bg-amber-400 rounded-full"})]},Z.name)})}),a&&c.jsxs("div",{children:[c.jsxs("div",{className:"flex items-center justify-between mb-1",children:[c.jsx("div",{className:"text-xs text-fg-secondary",children:E(a)}),c.jsxs("div",{className:"flex gap-2 items-center",children:[U&&c.jsxs(c.Fragment,{children:[c.jsx("button",{onClick:()=>M(a),className:"px-2.5 py-1 text-[11px] text-amber-600 hover:text-amber-600 border border-amber-500/30 hover:border-amber-500/50 rounded-lg transition-colors",children:y?.file===a?e("agent:profilePage.filesTab.hideDiff"):e("agent:profilePage.filesTab.viewDiff")}),c.jsx("button",{onClick:()=>j(a),className:"px-2.5 py-1 text-[11px] bg-brand-600 hover:bg-brand-500 text-white rounded-lg transition-colors",title:e("agent:profilePage.filesTab.sendToAgentTitle"),children:e("agent:profilePage.filesTab.sendToAgent")})]}),b&&c.jsx("span",{className:"text-[10px] text-fg-tertiary",children:e("common:saving")})]})]}),d&&c.jsxs("div",{className:"flex items-center gap-2 mb-3 bg-surface-elevated/40 rounded-lg px-3 py-2",children:[c.jsxs("code",{className:"text-[10px] text-fg-tertiary font-mono flex-1 truncate select-all",title:`${d}/${a}`,children:[d,"/",a]}),c.jsx("button",{onClick:()=>{navigator.clipboard.writeText(`${d}/${a}`),p(!0),setTimeout(()=>p(!1),2e3)},className:"shrink-0 px-2 py-1 text-[10px] text-fg-tertiary hover:text-fg-secondary border border-border-default hover:border-border-hover rounded-md transition-colors",title:e("agent:profilePage.filesTab.copyPath"),children:e(f?"agent:profilePage.filesTab.pathCopied":"agent:profilePage.filesTab.copyPath")}),c.jsx("button",{onClick:()=>{re.system.openPath(d)},className:"shrink-0 px-2 py-1 text-[10px] text-fg-tertiary hover:text-fg-secondary border border-border-default hover:border-border-hover rounded-md transition-colors",title:e("agent:profilePage.filesTab.openInFinder"),children:e("agent:profilePage.filesTab.openInFinder")})]}),y?.file===a&&c.jsx(v4,{agent:y.agent,template:y.template,templateId:m?.templateId??""}),c.jsx(_4,{content:t.find(Z=>Z.name===a)?.content??"",editContent:l,setEditContent:Z=>{h(Z),O(!0)},dirty:g,onSave:S}),a==="ROLE.md"&&c.jsx("div",{className:"text-[10px] text-fg-tertiary mt-2",children:e("agent:profilePage.filesTab.roleMdHint")})]}),t.length===0&&c.jsx(wh,{text:e("agent:profilePage.filesTab.noConfigFiles")})]})]})}function _4({content:s,editContent:e,setEditContent:t,dirty:r,onSave:i}){const[n,a]=_.useState(!1),o=_.useRef(null);return _.useEffect(()=>{n&&o.current?.focus()},[n]),_.useEffect(()=>{a(!1)},[s]),n||r?c.jsx("textarea",{ref:o,value:e,onChange:l=>t(l.target.value),onBlur:()=>{e!==s&&i(),a(!1)},onKeyDown:l=>{l.key==="Escape"&&(l.preventDefault(),t(s),a(!1))},className:"w-full min-h-[60vh] bg-surface-elevated/60 border border-border-default rounded-lg p-4 text-xs font-mono text-fg-secondary leading-relaxed resize-y focus:border-brand-500 outline-none",spellCheck:!1}):c.jsxs("div",{className:"group relative cursor-pointer rounded-lg px-4 py-3 bg-surface-elevated hover:bg-surface-overlay transition-colors min-h-[200px]",onClick:()=>a(!0),role:"button",tabIndex:0,onKeyDown:l=>{l.key==="Enter"&&a(!0)},children:[c.jsx("div",{className:"absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity text-[10px] text-fg-tertiary bg-surface-secondary/80 px-2 py-0.5 rounded",children:"Click to edit"}),e.trim()?c.jsx(_.Suspense,{fallback:c.jsx("div",{className:"text-xs text-fg-tertiary",children:"Loading…"}),children:c.jsx(g4,{content:e,className:"text-sm text-fg-secondary leading-relaxed"})}):c.jsx("div",{className:"text-sm text-fg-tertiary italic py-4 text-center",children:"Empty"})]})}function w4(s){return s.replace(/^\[MCP:[^\]]*\]\s*/i,"")}function k4({tools:s}){const{t:e}=Qt(["agent","common"]),t=f4(s,e);return c.jsxs("div",{className:"space-y-4",children:[c.jsx("div",{className:"text-xs text-fg-tertiary",children:e("agent:profilePage.toolsTab.registeredCount",{count:s.length})}),t.map(r=>c.jsx(fs,{title:`${r.category} (${r.tools.length})`,children:c.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:r.tools.map(i=>{const n=rk(i.name),a=e(`common:execution.tools.${n.key}`,{defaultValue:n.label}),o=i.name.includes("__"),l=o?i.name.split("__").pop():i.name,h=w4(i.description||"");return c.jsxs("div",{className:"flex items-start gap-2.5 px-3 py-2.5 rounded-lg bg-surface-elevated min-w-0",children:[c.jsx(ik,{name:n.iconName,size:15,className:"shrink-0 mt-0.5 text-fg-secondary"}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[c.jsx("span",{className:"text-xs font-medium text-fg-primary truncate",children:a}),o&&c.jsx("span",{className:"text-[9px] px-1 py-px rounded bg-surface-secondary text-fg-tertiary border border-border-default/40 shrink-0",children:"MCP"})]}),l!==a&&c.jsx("div",{className:"text-[10px] font-mono text-fg-tertiary/70 truncate",children:l}),h&&c.jsx("div",{className:"text-[10px] text-fg-tertiary truncate mt-0.5",title:h,children:h})]})]},i.name)})})},r.category)),s.length===0&&c.jsx("div",{className:"text-center py-12 text-fg-tertiary text-sm",children:e("agent:profilePage.toolsTab.noToolsRegistered")})]})}function C4({agent:s}){const{t:e}=Qt(["agent","common"]),t=s.proficiency??{},[r,i]=_.useState(null),[n,a]=_.useState(null),[o,l]=_.useState(!1),h=s.availableSkills??[],d=new Map;for(const g of h){const O=g.category||"custom";d.has(O)||d.set(O,[]),d.get(O).push(g)}const u=async g=>{if(r===g){i(null),a(null);return}i(g),l(!0);try{const O=await fetch(`/api/skills/${encodeURIComponent(g)}`);if(O.ok){const m=await O.json();a(m.skill)}else a(null)}catch{a(null)}l(!1)},f={development:"bg-blue-500/15 text-blue-600",devops:"bg-amber-500/15 text-amber-600",communication:"bg-green-500/15 text-green-600",data:"bg-brand-500/15 text-brand-500",productivity:"bg-amber-500/15 text-amber-600",browser:"bg-blue-500/15 text-blue-600",custom:"bg-gray-500/15 text-fg-secondary",platform:"bg-purple-500/15 text-purple-500"},p=g=>{const O=t[g.name],m=O&&O.uses>0?Math.round(O.successes/O.uses*100):null,x=O&&c.jsxs("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:[e("agent:profilePage.skillsTab.usesStats",{uses:O.uses,successes:O.successes}),O.lastUsed&&e("agent:profilePage.skillsTab.lastUsed",{date:new Date(O.lastUsed).toLocaleDateString()})]}),y=r===g.name;return c.jsxs("div",{children:[c.jsxs("div",{className:`flex items-center gap-3 px-4 py-2.5 rounded-lg border cursor-pointer transition-all ${y?"bg-brand-500/10 border-brand-500/40":"bg-surface-elevated/30 border-border-default/30 hover:border-gray-600/50"}`,onClick:()=>u(g.name),children:[c.jsx("span",{className:`text-sm transition-transform ${y?"rotate-90":""}`,children:"▶"}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-sm font-medium",children:g.name}),g.alwaysOn&&c.jsx("span",{className:"px-1.5 py-0.5 rounded text-[9px] font-medium bg-green-500/15 text-green-500",children:e("agent:profilePage.skillsTab.alwaysOn")}),g.builtIn&&!g.alwaysOn&&c.jsx("span",{className:"px-1.5 py-0.5 rounded text-[9px] font-medium bg-surface-overlay/40 text-fg-tertiary",children:e("agent:profilePage.skillsTab.builtIn")}),!g.builtIn&&c.jsx("span",{className:"px-1.5 py-0.5 rounded text-[9px] font-medium bg-brand-500/15 text-brand-400",children:e("agent:profilePage.skillsTab.installed")})]}),c.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5 truncate",children:g.description}),x]}),m!==null&&c.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[c.jsx("div",{className:"w-16 h-1.5 bg-surface-overlay rounded-full overflow-hidden",children:c.jsx("div",{className:`h-full rounded-full ${m>=80?"bg-green-400":m>=50?"bg-amber-400":"bg-red-400"}`,style:{width:`${m}%`}})}),c.jsxs("span",{className:"text-[10px] text-fg-tertiary w-8 text-right",children:[m,"%"]})]})]}),y&&c.jsx("div",{className:"ml-6 mt-1 mb-2 p-4 bg-surface-elevated/30 rounded-lg border border-border-default/20 space-y-3",children:o?c.jsx("div",{className:"text-[10px] text-fg-tertiary py-3 text-center",children:e("agent:profilePage.skillsTab.loadingDetails")}):n?c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[c.jsx("span",{className:`px-2 py-0.5 rounded text-[10px] font-medium ${f[n.category]??f.custom}`,children:n.category}),c.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["v",n.version]}),n.author&&c.jsx("span",{className:"text-[10px] text-fg-tertiary",children:e("agent:profilePage.skillsTab.byAuthor",{author:n.author})}),n.requiredPermissions?.map(w=>c.jsx("span",{className:"px-1.5 py-0.5 bg-amber-500/10 text-amber-600 text-[10px] rounded",children:w},w))]}),n.description&&c.jsx("p",{className:"text-xs text-fg-secondary leading-relaxed",children:n.description}),n.tags&&n.tags.length>0&&c.jsx("div",{className:"flex gap-1 flex-wrap",children:n.tags.map(w=>c.jsxs("span",{className:"px-1.5 py-0.5 bg-surface-overlay/40 text-fg-tertiary text-[10px] rounded",children:["#",w]},w))}),(n.toolDetails??n.tools??[]).length>0&&c.jsxs("div",{children:[c.jsx("div",{className:"text-[10px] text-fg-tertiary font-semibold uppercase tracking-wider mb-2",children:e("agent:profilePage.skillsTab.toolsHeading",{count:(n.toolDetails??n.tools??[]).length})}),c.jsx("div",{className:"space-y-1.5",children:(n.toolDetails??n.tools??[]).map(w=>c.jsxs("div",{className:"px-3 py-2 bg-surface-secondary/50 rounded border border-border-default/20",children:[c.jsx("div",{className:"text-xs font-medium text-brand-500",children:w.name}),w.description&&c.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:w.description})]},w.name))})]})]}):c.jsx("div",{className:"text-[10px] text-fg-tertiary py-3 text-center",children:e("agent:profilePage.skillsTab.detailsUnavailable")})})]},g.name)},b=["development","productivity","browser","communication","devops","data","platform","custom"],v=[...d.entries()].sort((g,O)=>{const m=b.indexOf(g[0]),x=b.indexOf(O[0]);return(m===-1?999:m)-(x===-1?999:x)});return c.jsxs("div",{className:"space-y-4",children:[c.jsx("div",{className:"flex items-center justify-between",children:c.jsx("div",{className:"text-xs text-fg-tertiary",children:e("agent:profilePage.skillsTab.installedCount",{count:h.length})})}),v.map(([g,O])=>c.jsx(fs,{title:c.jsxs("span",{className:"capitalize",children:[g," ",c.jsxs("span",{className:"text-fg-tertiary font-normal",children:["(",O.length,")"]})]}),children:c.jsx("div",{className:"space-y-2",children:O.map(m=>p(m))})},g)),h.length===0&&c.jsx(wh,{text:e("agent:profilePage.skillsTab.noSkills")})]})}function P4({tools:s,agent:e}){const{t}=Qt(["agent","common"]),[r,i]=_.useState("tools");return c.jsxs("div",{className:"space-y-4",children:[c.jsx("div",{className:"flex items-center gap-2 mb-2",children:["tools","skills"].map(n=>c.jsx("button",{onClick:()=>i(n),className:`px-3 py-1.5 text-xs rounded-lg border transition-colors ${r===n?"bg-brand-600/15 border-brand-500/40 text-brand-500":"border-border-default text-fg-tertiary hover:text-fg-secondary"}`,children:n==="tools"?`${t("agent:profilePage.toolsTab.title",{defaultValue:"Tools"})} (${s.length})`:`${t("agent:tabs.skills")} (${e.availableSkills?.length??0})`},n))}),r==="tools"?c.jsx(k4,{tools:s}):c.jsx(C4,{agent:e})]})}function T4({agentId:s}){const{t:e}=Qt(["agent","common"]),[t,r]=_.useState(null),[i,n]=_.useState(!0),[a,o]=_.useState("longterm"),[l,h]=_.useState(""),[d,u]=_.useState(""),[f,p]=_.useState(!1),[b,v]=_.useState(null),[g,O]=_.useState(null),[m,x]=_.useState([]),[y,w]=_.useState(!1),C=_.useCallback(()=>{n(!0),re.agents.getMemory(s).then(L=>{r(L),h(L.recentDailyLogs??""),u(L.longTermMemory??"")}).catch(()=>{}).finally(()=>n(!1))},[s]);_.useEffect(()=>{C()},[C]);const P=async()=>{p(!0),await re.agents.updateDailyMemory(s,l).catch(()=>{}),p(!1),C()},S=async()=>{p(!0),await re.agents.updateLongTermMemory(s,e("agent:profilePage.memoryTab.userEditedSource"),d).catch(()=>{}),p(!1),C()},T=l!==(t?.recentDailyLogs??""),j=d!==(t?.longTermMemory??"");if(i)return c.jsx("div",{className:"text-xs text-fg-tertiary py-8 text-center",children:e("agent:profilePage.memoryTab.loading")});if(!t)return c.jsx("div",{className:"text-xs text-fg-tertiary py-8 text-center",children:e("agent:profilePage.memoryTab.loadFailed")});const M=[{key:"longterm",label:"MEMORY.md"},{key:"entries",label:`Observations (${t.entries.length})`},{key:"sessions",label:e("agent:profilePage.memoryTab.sessions",{count:t.sessions.length})},{key:"daily",label:e("agent:profilePage.memoryTab.dailyLogs")}];return c.jsxs("div",{className:"space-y-4",children:[c.jsx("div",{className:"flex gap-2",children:M.map(L=>c.jsx("button",{onClick:()=>o(L.key),className:`px-3 py-1.5 text-xs rounded-lg border transition-colors ${a===L.key?"bg-brand-600/15 border-brand-500/40 text-brand-500":"border-border-default text-fg-tertiary hover:text-fg-secondary"}`,children:L.label},L.key))}),a==="entries"&&c.jsx(fs,{title:e("agent:profilePage.memoryTab.recentEntries"),children:t.entries.length===0?c.jsx(wh,{text:e("agent:profilePage.memoryTab.noEntries")}):c.jsx("div",{className:"space-y-1.5 max-h-[600px] overflow-y-auto",children:t.entries.map((L,E)=>{const B=b===E;return c.jsxs("div",{children:[c.jsxs("button",{onClick:()=>v(B?null:E),className:"w-full flex gap-2 px-3 py-2 rounded-lg bg-surface-elevated/20 text-xs text-left hover:bg-surface-elevated/40 transition-colors cursor-pointer",children:[c.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-medium shrink-0 ${L.type==="fact"?"bg-blue-500/15 text-blue-600":L.type==="task"?"bg-green-500/15 text-green-600":L.type==="note"?"bg-brand-500/15 text-brand-500":"bg-surface-overlay text-fg-secondary"}`,children:L.type}),c.jsx("span",{className:`text-fg-secondary flex-1 min-w-0 ${B?"":"line-clamp-2"}`,children:L.content}),c.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[L.importance!=null&&c.jsxs("span",{className:`px-1 py-0.5 rounded text-[9px] font-medium ${L.importance>=7?"bg-red-500/15 text-red-500":L.importance>=4?"bg-amber-500/15 text-amber-600":"bg-surface-overlay text-fg-tertiary"}`,children:["P",L.importance]}),c.jsx("span",{className:"text-fg-tertiary text-[10px]",children:new Date(L.timestamp).toLocaleTimeString()}),c.jsx("span",{className:"text-fg-tertiary text-[10px]",children:B?"▲":"▼"})]})]}),B&&c.jsxs("div",{className:"mx-3 mt-1 mb-2 p-3 bg-surface-elevated/30 rounded-lg border border-border-default/20",children:[c.jsx("pre",{className:"text-xs text-fg-secondary whitespace-pre-wrap font-mono leading-relaxed break-words",children:L.content}),c.jsxs("div",{className:"flex gap-3 mt-2 pt-2 border-t border-border-default/30 text-[10px] text-fg-tertiary",children:[c.jsxs("span",{children:[e("agent:profilePage.overview.labels.type"),": ",L.type]}),L.importance!=null&&c.jsxs("span",{children:[e("agent:profilePage.overview.labels.importance"),": ",L.importance]}),c.jsx("span",{children:new Date(L.timestamp).toLocaleString()})]})]})]},E)})})}),a==="sessions"&&c.jsx(fs,{title:e("agent:profilePage.memoryTab.chatSessions"),children:t.sessions.length===0?c.jsx(wh,{text:e("agent:profilePage.memoryTab.noSessions")}):c.jsx("div",{className:"space-y-1.5 max-h-[600px] overflow-y-auto",children:t.sessions.map(L=>{const E=g===L.id,B=async()=>{if(E){O(null),x([]);return}O(L.id),w(!0);try{const U=await re.agents.getMemorySession(s,L.id);x(U.messages)}catch{x([])}w(!1)};return c.jsxs("div",{children:[c.jsxs("button",{onClick:B,className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-lg bg-surface-elevated/20 hover:bg-surface-elevated/40 transition-colors cursor-pointer text-left",children:[c.jsx("div",{className:"text-xs text-fg-secondary font-mono flex-1 truncate",children:L.id}),c.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:[L.messageCount," ",e("agent:profilePage.memoryTab.msgs")]}),c.jsx("span",{className:"text-[10px] text-fg-tertiary",children:new Date(L.updatedAt).toLocaleDateString()}),c.jsx("span",{className:"text-fg-tertiary text-[10px]",children:E?"▲":"▼"})]}),E&&c.jsx("div",{className:"mx-3 mt-1 mb-2 bg-surface-elevated/30 rounded-lg border border-border-default/20 max-h-96 overflow-y-auto",children:y?c.jsx("div",{className:"text-[10px] text-fg-tertiary py-3 text-center",children:e("agent:profilePage.memoryTab.loadingMessages")}):m.length===0?c.jsx("div",{className:"text-[10px] text-fg-tertiary py-3 text-center",children:e("agent:profilePage.memoryTab.noMessagesInSession")}):(()=>{const U=new Map;for(const Z of m)Z.role==="tool"&&Z.toolCallId&&U.set(Z.toolCallId,Z.content);return c.jsx("div",{className:"divide-y divide-gray-700/30",children:m.filter(Z=>Z.role!=="tool").map((Z,I)=>c.jsxs("div",{className:"px-3 py-2",children:[(Z.role==="user"||Z.role==="system")&&c.jsxs("div",{children:[c.jsx("span",{className:`inline-block px-1.5 py-0.5 rounded text-[10px] font-medium mb-1 ${Z.role==="user"?"bg-blue-500/15 text-blue-600":"bg-surface-overlay text-fg-secondary"}`,children:e(`agent:profilePage.memoryTab.roles.${Z.role}`,{defaultValue:Z.role})}),c.jsx("div",{className:"text-xs text-fg-secondary",children:c.jsx(ja,{content:Z.content,className:"text-xs text-fg-secondary"})})]}),Z.role==="assistant"&&c.jsxs("div",{className:"space-y-1",children:[Z.content&&c.jsxs("div",{children:[c.jsx("span",{className:"inline-block px-1.5 py-0.5 rounded text-[10px] font-medium mb-1 bg-green-500/15 text-green-600",children:e("agent:profilePage.memoryTab.roles.assistant")}),c.jsx("div",{className:"text-xs text-fg-secondary",children:c.jsx(ja,{content:Z.content,className:"text-xs text-fg-secondary"})})]}),Z.toolCalls&&Z.toolCalls.length>0&&c.jsx("div",{className:"space-y-0.5",children:Z.toolCalls.map(ie=>{let Q;try{Q=JSON.parse(ie.arguments)}catch{}const W={tool:ie.name,status:"done",args:Q,result:U.get(ie.id)};return c.jsx(ek,{entry:{type:"tool",info:W}},ie.id)})})]})]},I))})})()})]},L.id)})})}),a==="daily"&&c.jsx(fs,{title:e("agent:profilePage.memoryTab.dailyLogs"),action:T?c.jsxs("div",{className:"flex gap-2",children:[c.jsx("button",{onClick:()=>h(t?.recentDailyLogs??""),className:"text-xs text-fg-tertiary hover:text-fg-secondary",children:e("common:cancel")}),c.jsx("button",{onClick:P,disabled:f,className:"text-xs text-brand-500",children:e(f?"common:saving":"common:save")})]}):null,children:c.jsx("textarea",{value:l,onChange:L=>h(L.target.value),placeholder:e("agent:profilePage.memoryTab.noDailyLogs"),className:"w-full min-h-[50vh] bg-surface-elevated/30 border border-border-default/50 hover:border-border-default focus:border-brand-500 rounded-lg p-4 text-xs font-mono text-fg-secondary leading-relaxed resize-y outline-none transition-colors"})}),a==="longterm"&&c.jsx(fs,{title:e("agent:profilePage.memoryTab.longTermTitle"),action:j?c.jsxs("div",{className:"flex gap-2",children:[c.jsx("button",{onClick:()=>u(t?.longTermMemory??""),className:"text-xs text-fg-tertiary hover:text-fg-secondary",children:e("common:cancel")}),c.jsx("button",{onClick:S,disabled:f,className:"text-xs text-brand-500",children:e(f?"common:saving":"common:save")})]}):null,children:c.jsx("textarea",{value:d,onChange:L=>u(L.target.value),placeholder:e("agent:profilePage.memoryTab.noLongTerm"),className:"w-full min-h-[50vh] bg-surface-elevated/30 border border-border-default/50 hover:border-border-default focus:border-brand-500 rounded-lg p-4 text-xs font-mono text-fg-secondary leading-relaxed resize-y outline-none transition-colors"})})]})}function Q4({agentId:s,initialData:e}){const{t}=Qt(["agent","common"]),[r,i]=_.useState(e??null),[n,a]=_.useState(!e),[o,l]=_.useState([]),[h,d]=_.useState(null),[u,f]=_.useState(!1),[p,b]=_.useState(null),[v,g]=_.useState(null),O=_.useRef(null);_.useEffect(()=>()=>{O.current!==null&&window.clearTimeout(O.current)},[]);const m=_.useCallback(()=>Promise.all([re.agents.getHeartbeat(s).then(i).catch(()=>{}),re.agents.getRecentActivities(s).then(P=>{l(P.activities.filter(S=>S.type==="heartbeat"))}).catch(()=>{})]),[s]);_.useEffect(()=>{a(!0),m().finally(()=>a(!1))},[m]),_.useEffect(()=>bt.on("agent:update",S=>{S.payload?.agentId===s&&m()}),[s,m]);const x=async()=>{f(!0),b(null);try{const P=await re.agents.triggerHeartbeat(s);b(P.message),setTimeout(()=>b(null),4e3),setTimeout(m,2e3)}catch(P){b(String(P).replace("Error: ",""))}f(!1)},y=async P=>{O.current!==null&&window.clearTimeout(O.current),g(null);try{await re.agents.cancelWakeup(s,P),g({kind:"ok",text:t("agent:profilePage.heartbeatTab.cancelWakeupOk")}),O.current=window.setTimeout(()=>g(null),4e3)}catch(S){const T=S instanceof Error?S.message:String(S),j=!T||/no scheduled wakeup|404/i.test(T);g({kind:"error",text:j?t("agent:profilePage.heartbeatTab.cancelWakeupGone"):`${t("agent:profilePage.heartbeatTab.cancelWakeupFailed")}: ${T}`})}m()};if(n)return c.jsx("div",{className:"text-xs text-fg-tertiary py-8 text-center",children:t("agent:profilePage.heartbeatTab.loading")});if(!r)return c.jsx("div",{className:"text-xs text-fg-tertiary py-8 text-center",children:t("agent:profilePage.heartbeatTab.noData")});const w=P=>P?P<1e3?`${P}ms`:P<6e4?`${(P/1e3).toFixed(1)}s`:`${(P/6e4).toFixed(1)}m`:null,C=P=>{if(!P)return null;const S=Date.now()-new Date(P).getTime();if(S<0){const T=Math.abs(S);return T<6e4?t("agent:profilePage.relative.inSeconds",{count:Math.ceil(T/1e3)}):T<36e5?t("agent:profilePage.relative.inMinutes",{count:Math.ceil(T/6e4)}):t("agent:profilePage.relative.inHours",{hours:(T/36e5).toFixed(1)})}return S<6e4?t("agent:profilePage.relative.secondsAgo",{count:Math.floor(S/1e3)}):S<36e5?t("agent:profilePage.relative.minutesAgo",{count:Math.floor(S/6e4)}):t("agent:profilePage.relative.hoursAgo",{hours:(S/36e5).toFixed(1)})};return c.jsxs("div",{className:"space-y-4",children:[c.jsxs(fs,{title:t("agent:profilePage.heartbeatTab.scheduler"),action:c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("button",{onClick:m,className:"text-[10px] text-fg-tertiary hover:text-fg-secondary transition-colors",children:t("common:refresh")}),c.jsx("button",{onClick:x,disabled:u||!r.running,className:"text-[10px] px-2.5 py-1 rounded-md bg-blue-600/20 text-blue-600 hover:bg-blue-600/30 border border-blue-500/30 transition-colors disabled:opacity-40",children:t(u?"agent:profilePage.heartbeatTab.triggering":"agent:profilePage.heartbeatTab.triggerNow")})]}),children:[c.jsxs("div",{className:"grid grid-cols-4 gap-4",children:[c.jsx(Xs,{label:t("agent:profilePage.overview.labels.status"),value:r.running?t("agent:profilePage.heartbeatTab.running"):t("agent:profilePage.heartbeatTab.stopped"),color:r.running?"green":"gray"}),c.jsx(j4,{agentId:s,intervalMs:r.intervalMs,onChanged:m}),c.jsx(Xs,{label:t("agent:profilePage.heartbeatTab.lastRun"),value:r.lastHeartbeat?C(r.lastHeartbeat)??t("agent:profilePage.emDash"):t("agent:profilePage.never")}),c.jsx(Xs,{label:t("agent:profilePage.heartbeatTab.nextWake"),value:r.nextWakeAt?C(r.nextWakeAt)??t("agent:profilePage.emDash"):r.running?t("agent:profilePage.heartbeatTab.pending"):t("agent:profilePage.emDash")})]}),c.jsx("p",{className:"mt-2 text-[10px] text-fg-tertiary leading-relaxed",children:t("agent:profilePage.heartbeatTab.rhythmHint")}),p&&c.jsx("div",{className:"mt-3 text-[11px] text-blue-600 bg-blue-500/10 border border-blue-500/20 rounded-lg px-3 py-2",children:p})]}),v&&c.jsx("div",{className:`text-[11px] rounded-lg px-3 py-2 border ${v.kind==="ok"?"text-green-600 bg-green-500/10 border-green-500/20":"text-red-500 bg-red-500/10 border-red-500/20"}`,children:v.text}),r.wakeups&&r.wakeups.length>0&&c.jsx(fs,{title:t("agent:profilePage.heartbeatTab.wakeupsTitle"),action:c.jsx("span",{className:"text-[10px] text-fg-tertiary",children:t("agent:profilePage.heartbeatTab.wakeupsCount",{count:r.wakeups.length})}),children:c.jsx("div",{className:"divide-y divide-gray-800/50 -mx-5",children:r.wakeups.map(P=>c.jsxs("div",{className:"flex items-center gap-2.5 px-5 py-2.5",children:[c.jsx("span",{className:"text-sm shrink-0 opacity-60",children:"⏰"}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsx("div",{className:"text-xs text-fg-secondary truncate",children:P.note||t("agent:profilePage.heartbeatTab.wakeupNoNote")}),c.jsxs("div",{className:"text-[10px] text-fg-tertiary",children:[C(P.wakeAt)??new Date(P.wakeAt).toLocaleString(),P.recurringMs?` · ${t("agent:profilePage.heartbeatTab.recurring")}`:"",` · ${P.deliveryMode==="in_session"?t("agent:profilePage.heartbeatTab.deliveryInSession"):t("agent:profilePage.heartbeatTab.deliveryMailbox")}`]})]}),c.jsx("button",{onClick:()=>y(P.id),className:"text-[10px] px-2 py-0.5 rounded text-fg-tertiary hover:text-red-500 hover:bg-red-500/10 transition-colors shrink-0",children:t("agent:profilePage.heartbeatTab.cancelWakeup")})]},P.id))})}),r.pendingCallbacks&&r.pendingCallbacks.length>0&&c.jsx(fs,{title:t("agent:profilePage.heartbeatTab.pendingOpsTitle"),action:c.jsx("span",{className:"text-[10px] text-fg-tertiary",children:t("agent:profilePage.heartbeatTab.pendingOpsCount",{count:r.pendingCallbacks.length})}),children:c.jsx("div",{className:"divide-y divide-gray-800/50 -mx-5",children:r.pendingCallbacks.map(P=>c.jsxs("div",{className:"flex items-center gap-2.5 px-5 py-2.5",children:[c.jsx("span",{className:"text-sm shrink-0 opacity-60",children:P.type==="background_exec"?"⚙":"↔"}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsx("div",{className:"text-xs text-fg-secondary truncate font-mono",children:P.label}),c.jsxs("div",{className:"text-[10px] text-fg-tertiary",children:[t(`agent:profilePage.heartbeatTab.callbackType.${P.type}`),` · ${t("agent:profilePage.heartbeatTab.timesOut")} ${C(P.timeoutAt)??new Date(P.timeoutAt).toLocaleString()}`]})]})]},P.id))})}),r.lastSummary&&c.jsx(fs,{title:t("agent:profilePage.heartbeatTab.lastSummary"),action:r.lastSummaryAt?c.jsx("span",{className:"text-[10px] text-fg-tertiary",children:new Date(r.lastSummaryAt).toLocaleString()}):void 0,children:c.jsx("div",{className:"bg-surface-primary/50 rounded-lg px-4 py-3",children:c.jsx(ja,{content:r.lastSummary,className:"text-xs text-fg-secondary leading-relaxed"})})}),o.length>0?c.jsx(fs,{title:t("agent:profilePage.heartbeatTab.recentRuns"),action:c.jsx("span",{className:"text-[10px] text-fg-tertiary",children:t("agent:profilePage.heartbeatTab.runsThisSession",{count:o.length})}),children:c.jsx("div",{className:"divide-y divide-gray-800/50 -mx-5",children:[...o].reverse().map(P=>{const S=h===P.id;return c.jsxs("div",{children:[c.jsxs("button",{onClick:()=>d(S?null:P.id),className:"w-full flex items-center gap-2.5 px-5 py-2.5 text-left transition-colors hover:bg-surface-elevated/40 cursor-pointer",children:[c.jsx("span",{className:"w-2 h-2 rounded-full shrink-0 bg-blue-400"}),c.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:P.label}),c.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:t("agent:profilePage.heartbeatTab.actionsCount",{count:P.logCount})}),c.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:new Date(P.startedAt).toLocaleString()}),c.jsx("svg",{className:`w-3 h-3 text-fg-tertiary shrink-0 transition-transform ${S?"rotate-180":""}`,viewBox:"0 0 12 12",fill:"currentColor",children:c.jsx("path",{d:"M3 4.5l3 3 3-3",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})]}),S&&c.jsx("div",{className:"border-t border-border-default/60 bg-surface-primary/40",children:c.jsx(_h,{agentId:s,activityId:P.id})})]},P.id)})})}):r.lastHeartbeat?null:c.jsx(fs,{title:t("agent:profilePage.heartbeatTab.recentRuns"),children:c.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[c.jsx("div",{className:"text-xl mb-2 opacity-40",children:"♡"}),c.jsx("p",{className:"text-xs text-fg-tertiary",children:t("agent:profilePage.heartbeatTab.noRunsYet")}),c.jsx("p",{className:"text-[10px] text-fg-tertiary mt-1",children:r.running?t("agent:profilePage.heartbeatTab.firstHeartbeatSoon",{when:w(r.intervalMs-r.uptimeMs%r.intervalMs)??t("agent:profilePage.heartbeatTab.soon")}):t("agent:profilePage.heartbeatTab.schedulerStopped")}),r.running&&c.jsx("button",{onClick:x,disabled:u,className:"mt-3 text-[10px] px-3 py-1.5 rounded-md bg-blue-600/15 text-blue-600 hover:bg-blue-600/25 border border-blue-500/25 transition-colors disabled:opacity-40",children:t(u?"agent:profilePage.heartbeatTab.triggering":"agent:profilePage.heartbeatTab.runFirstNow")})]})})]})}function $4({taskId:s,isLive:e}){const{t}=Qt("agent"),[r,i]=_.useState([]),[n,a]=_.useState(""),[o,l]=_.useState(!0),[h,d]=_.useState("compact");if(_.useEffect(()=>{l(!0),a(""),re.tasks.getLogs(s).then(p=>{i(p.logs),l(!1)}).catch(()=>l(!1))},[s]),_.useEffect(()=>{if(!e)return;const p=bt.on("task:log",v=>{const g=v.payload;if(g.taskId!==s)return;const O={id:g.id,taskId:g.taskId,agentId:g.agentId,seq:g.seq,type:g.logType,content:g.content,metadata:g.metadata,createdAt:g.createdAt};i(m=>O.id&&m.some(x=>x.id===O.id)?m:[...m,O]),O.type==="text"&&a("")}),b=bt.on("task:log:delta",v=>{const g=v.payload;g.taskId===s&&a(O=>O+g.text)});return()=>{p(),b()}},[s,e]),o)return c.jsx("div",{className:"px-4 py-3 text-xs text-fg-tertiary",children:t("profilePage.taskLog.loading")});if(r.length===0&&!n)return c.jsx("div",{className:"px-4 py-3 text-xs text-fg-tertiary",children:t("profilePage.taskLog.noLogs")});const u=r.map(p=>sk(p)),f=new Set(u.filter(p=>p.executionRound!=null).map(p=>p.executionRound)).size>1;return c.jsx("div",{className:"px-3 py-2",children:h==="compact"?c.jsx(Vb,{entries:u,streamingText:n,isActive:e,onExpand:()=>d("full"),showRounds:f}):c.jsx(Fb,{entries:u,streamingText:n,isActive:e,onCollapse:()=>d("compact"),showRounds:f})})}function _h({agentId:s,activityId:e,isLive:t=!1}){const{t:r}=Qt("agent"),[i,n]=_.useState([]),[a,o]=_.useState(!0),[l,h]=_.useState("compact");if(_.useEffect(()=>{o(!0),re.agents.getActivityLogs(s,e).then(u=>{n(u.logs),o(!1)}).catch(()=>o(!1))},[s,e]),_.useEffect(()=>t?bt.on("agent:activity_log",f=>{const p=f.payload;if(p.agentId!==s||p.activityId!==e)return;const b={seq:p.seq,type:p.type,content:p.content,metadata:p.metadata,createdAt:p.createdAt};n(v=>v.some(g=>g.seq===b.seq)?v:[...v,b])}):void 0,[s,e,t]),a)return c.jsx("div",{className:"px-4 py-3 text-xs text-fg-tertiary",children:r("profilePage.activityLog.loading")});if(i.length===0)return c.jsx("div",{className:"px-4 py-3 text-xs text-fg-tertiary",children:r("profilePage.activityLog.noLogs")});const d=i.map(u=>tk(u,e,s)).filter(u=>u!==null);return c.jsx("div",{className:"px-3 py-2",children:l==="compact"?c.jsx(Vb,{entries:d,isActive:t,onExpand:()=>h("full")}):c.jsx(Fb,{entries:d,isActive:t,onCollapse:()=>h("compact")})})}function fs({title:s,action:e,children:t}){return c.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5",children:[c.jsxs("div",{className:"flex items-center justify-between mb-3",children:[c.jsx("h3",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider",children:s}),e]}),t]})}function Ms({label:s,mono:e,children:t}){return c.jsxs("div",{className:"flex flex-col gap-0.5",children:[c.jsx("span",{className:"text-[10px] text-fg-tertiary",children:s}),c.jsx("span",{className:`text-xs text-fg-secondary ${e?"font-mono text-[10px]":""}`,children:t})]})}function Xs({label:s,value:e,color:t}){const r=t==="green"?"text-green-500":t==="blue"?"text-blue-400":t==="indigo"?"text-brand-500":t==="red"?"text-red-400":"text-fg-secondary";return c.jsxs("div",{className:"flex items-baseline gap-1.5",children:[c.jsx("span",{className:`text-sm font-semibold ${r}`,children:e}),c.jsx("span",{className:"text-[10px] text-fg-tertiary",children:s})]})}const Tb=[1800*1e3,3600*1e3,10800*1e3,360*60*1e3,720*60*1e3,1440*60*1e3],Qb=5,$b=1440;function j4({agentId:s,intervalMs:e,onChanged:t}){const{t:r}=Qt(["agent","common"]),[i,n]=_.useState(!1),[a,o]=_.useState(null),[l,h]=_.useState(!1),[d,u]=_.useState(String(Math.round(e/6e4))),f=m=>m%(3600*1e3)===0?r("agent:profilePage.heartbeatTab.intervalHours",{count:m/(3600*1e3)}):r("agent:profilePage.heartbeatTab.intervalMinutes",{count:Math.round(m/6e4)}),p=async m=>{n(!0),o(null);try{await re.agents.updateConfig(s,{heartbeatIntervalMs:m}),t()}catch(x){o(String(x).replace("Error: ",""))}n(!1)},b=m=>{if(m.target.value==="custom"){h(!0);return}h(!1),p(Number(m.target.value))},v=()=>{const m=Math.round(Number(d));if(!Number.isFinite(m)||m<Qb||m>$b){o(r("agent:profilePage.heartbeatTab.intervalRangeHint"));return}p(m*60*1e3)},g=Tb.includes(e),O=l||!g?"custom":String(e);return c.jsxs("div",{className:"flex flex-col gap-1",children:[c.jsx("span",{className:"text-[10px] text-fg-tertiary",children:r("agent:profilePage.heartbeatTab.safetyNetInterval")}),c.jsxs("select",{value:O,onChange:b,disabled:i,className:"text-xs bg-bg-secondary border border-gray-700/50 rounded-md px-1.5 py-1 text-fg-secondary focus:outline-none focus:border-blue-500/50 disabled:opacity-40",children:[!g&&c.jsx("option",{value:String(e),children:f(e)}),Tb.map(m=>c.jsx("option",{value:String(m),children:f(m)},m)),c.jsx("option",{value:"custom",children:r("agent:profilePage.heartbeatTab.intervalCustom")})]}),(l||!g)&&c.jsxs("div",{className:"flex items-center gap-1.5 mt-1",children:[c.jsx("input",{type:"number",min:Qb,max:$b,value:d,onChange:m=>u(m.target.value),disabled:i,className:"w-16 text-xs bg-bg-secondary border border-gray-700/50 rounded-md px-1.5 py-1 text-fg-secondary focus:outline-none focus:border-blue-500/50 disabled:opacity-40"}),c.jsx("span",{className:"text-[10px] text-fg-tertiary",children:r("agent:profilePage.heartbeatTab.intervalCustomUnit")}),c.jsx("button",{onClick:v,disabled:i,className:"text-[10px] px-2 py-1 rounded-md bg-blue-600/20 text-blue-600 hover:bg-blue-600/30 border border-blue-500/30 transition-colors disabled:opacity-40",children:r(i?"agent:profilePage.heartbeatTab.intervalSaving":"agent:profilePage.heartbeatTab.intervalSave")})]}),a&&c.jsx("span",{className:"text-[10px] text-red-400",children:a})]})}function wh({text:s}){return c.jsx("div",{className:"text-xs text-fg-tertiary py-6 text-center",children:s})}function jb(s){if(s===0)return"0 B";const e=["B","KB","MB","GB"],t=Math.min(Math.floor(Math.log(s)/Math.log(1024)),e.length-1),r=s/Math.pow(1024,t);return`${r<10?r.toFixed(1):Math.round(r)} ${e[t]}`}const Eb={0:"0",1:"1",2:"2",3:"3",4:"4"},Rb={0:"text-red-500",1:"text-amber-500",2:"text-fg-secondary",3:"text-fg-tertiary",4:"text-fg-tertiary/60"},E4={pick:"bg-brand-500/20 text-brand-500",continue:"bg-gray-500/20 text-gray-500",preempt:"bg-amber-500/20 text-amber-500",merge:"bg-blue-500/20 text-blue-500",defer:"bg-purple-500/20 text-purple-500",delegate:"bg-green-500/20 text-green-500",drop:"bg-red-500/20 text-red-500"},R4={idle:"bg-green-500/20 text-green-500",focused:"bg-brand-500/20 text-brand-500",deciding:"bg-amber-500/20 text-amber-500"},yc={system_event:"⚙",human_chat:"💬",task_comment:"💬",mention:"@",session_reply:"↩",task_status_update:"📋",a2a_message:"🔗",review_request:"👀",requirement_update:"📝",requirement_comment:"💬",daily_report:"📊",heartbeat:"♡",memory_consolidation:"🧠"},A4=["all","interaction","task","notification","system"],M4={interaction:["human_chat","a2a_message","mention"],task:["task_status_update","task_comment","requirement_comment","review_request","session_reply"],notification:["requirement_update"],system:["system_event","heartbeat","daily_report","memory_consolidation"]},L4={completed:"bg-green-500",processing:"bg-blue-400 animate-pulse",deferred:"bg-purple-400",merged:"bg-brand-400",queued:"bg-amber-400",dropped:"bg-red-500"},N4={pending:"text-gray-400",assigned:"text-blue-400",in_progress:"text-brand-400",completed:"text-green-400",failed:"text-red-400",cancelled:"text-gray-500",review:"text-amber-400",approved:"text-green-500",rejected:"text-red-500",draft:"text-gray-400"};function Ju(s){const e=s.match(/Comment from .+?:\s*(.+?)(?:\n\n\*\*MANDATORY|\n\n---|\n\n\[|$)/s);if(e?.[1]){const t=e[1].trim().replace(/\n/g," ");return t.length>80?t.slice(0,80)+"…":t}}function Ab(s,e){const t=s.payload,r=t?.summary??"",i=t?.content??"",n=s.metadata?.senderName;switch(s.sourceType){case"task_status_update":{const a=r.match(/^Task "(.+?)" status:/),o=r.match(/status:\s*(\S+)\s*→\s*(\S+)/),l=a?.[1]??r;if(o){const d=o[1],u=o[2],f=fm(d,e),p=fm(u,e),b=N4[u]??"text-fg-secondary";return{title:l,subtitle:e("agent:profilePage.mind.mailbox.statusArrow",{from:f,to:p}),badge:{label:p,color:b}}}const h=r.match(/^Task:\s*(.+)/);return h?{title:h[1]}:{title:l}}case"task_comment":{const a=r.match(/^Comment on task "(.+?)" from (.+?)(\s*\(\+\d+\))?$/),o=Ju(i);if(a){const l=o?e("agent:profilePage.mind.mailbox.commentFromAuthor",{author:a[2],text:o}):e("agent:profilePage.mind.mailbox.commentFrom",{name:a[2]});return{title:a[1],subtitle:l}}return{title:r}}case"requirement_update":{const a=r.match(/^Requirement "(.+?)"\s+(.*)/);return a?{title:a[1],subtitle:a[2]}:{title:r}}case"requirement_comment":{const a=r.match(/^Comment on requirement "(.+?)" from (.+?)(\s*\(\+\d+\))?$/),o=Ju(i);if(a){const l=o?e("agent:profilePage.mind.mailbox.commentFromAuthor",{author:a[2],text:o}):e("agent:profilePage.mind.mailbox.commentFrom",{name:a[2]});return{title:a[1],subtitle:l}}return{title:r}}case"human_chat":{const a=i.slice(0,120).replace(/\n/g," ");return{title:n?e("agent:profilePage.mind.mailbox.chatFrom",{sender:n}):e("agent:profilePage.mind.mailbox.humanChat"),subtitle:a+(i.length>120?"…":"")}}case"a2a_message":{const a=i.slice(0,120).replace(/\n/g," ");return{title:n?e("agent:profilePage.mind.mailbox.messageFrom",{sender:n}):e("agent:profilePage.mind.mailbox.agentMessage"),subtitle:a+(i.length>120?"…":"")}}case"mention":{const a=r.match(/from (.+)$/),o=Ju(i);return{title:a?e("agent:profilePage.mind.mailbox.mentionedBy",{name:a[1]}):e("agent:profilePage.mind.mailbox.mention"),subtitle:o||void 0}}case"review_request":{const a=i.slice(0,120).replace(/\n/g," ");return{title:n?e("agent:profilePage.mind.mailbox.reviewRequestFrom",{sender:n}):e("agent:profilePage.mind.mailbox.reviewRequest"),subtitle:a+(i.length>120?"…":"")}}case"session_reply":{const a=i.slice(0,120).replace(/\n/g," ");return{title:n?e("agent:profilePage.mind.mailbox.replyInSession",{sender:n}):e("agent:profilePage.mind.mailbox.sessionReply"),subtitle:a+(i.length>120?"…":"")}}case"heartbeat":return{title:e("agent:profilePage.mind.mailbox.scheduledHeartbeat")};case"daily_report":return{title:e("agent:profilePage.mind.mailbox.dailyReport")};case"memory_consolidation":return{title:e("agent:profilePage.mind.mailbox.memoryConsolidation")};case"system_event":{const a=r.match(/^\[Announcement]\s*(.+)/);return a?{title:a[1],subtitle:e("agent:profilePage.mind.mailbox.systemAnnouncement")}:{title:r||e("agent:profilePage.mind.mailbox.systemEvent")}}default:return{title:r||s.sourceType}}}function D4({agentId:s,highlightId:e,agentStatus:t,canManageAgents:r}){const{t:i}=Qt(["agent","common","team"]),[n,a]=_.useState(null),[o,l]=_.useState(null),[h,d]=_.useState(!0),[u,f]=_.useState("all"),[p,b]=_.useState("all"),[v,g]=_.useState(e??null),[O,m]=_.useState(e??null),[x,y]=_.useState(!1),[w,C]=_.useState(!1),[P,S]=_.useState(!0),[T,j]=_.useState(null),M=50,L=3,E=_.useCallback(async(A=!0)=>{A&&d(!0);try{const X=u==="all"?void 0:u,Y=p==="all"?void 0:p,[se,ee]=await Promise.all([re.agents.getMindState(s),re.agents.getMailbox(s,{limit:M,category:X,status:Y})]);a(se),l(ee),S((ee.history?.length??0)>=M)}catch{}d(!1)},[s,u,p]),B=_.useCallback(async()=>{if(!o)return;const A=u==="all"?void 0:u,X=p==="all"?void 0:p;try{const Y=await re.agents.getMailbox(s,{limit:M,offset:o.history.length,category:A,status:X});l(se=>se?{...se,history:[...se.history,...Y.history]}:Y),S((Y.history?.length??0)>=M)}catch{}},[s,o,u,p]);_.useEffect(()=>{g(e??null),m(e??null),E()},[E,e]);const U=_.useRef(!1);if(_.useEffect(()=>{if(!O||h)return;if(o?.history?.some(X=>X.id===O)){U.current=!1;const X=document.getElementById(`mbx-${O}`);if(X){setTimeout(()=>X.scrollIntoView({behavior:"smooth",block:"center"}),100);const Y=setTimeout(()=>m(null),3e3);return()=>clearTimeout(Y)}}else P&&!U.current&&(U.current=!0,(async()=>{let X=o?.history??[],Y=P;for(;Y;)try{const se=await re.agents.getMailbox(s,{limit:M,offset:X.length}),ee=[...X,...se.history];X=ee,Y=(se.history?.length??0)>=M;const me=se.history.some(V=>V.id===O);if(l(V=>V?{...V,history:ee}:se),S(Y),me||!Y)break}catch{break}U.current=!1})())},[O,h,o,P,s]),_.useEffect(()=>{let A=null;const X=se=>{se.payload?.agentId===s&&(A&&clearTimeout(A),A=setTimeout(()=>{A=null,E(!1)},500))},Y=[bt.on("agent:mailbox",X),bt.on("agent:decision",X),bt.on("agent:attention",X),bt.on("agent:focus",X),bt.on("agent:update",X),bt.on("agent:triage",X)];return()=>{A&&clearTimeout(A),Y.forEach(se=>se())}},[s,E]),h&&!n)return c.jsx("div",{className:"text-fg-tertiary text-sm animate-pulse",children:i("agent:profilePage.mind.loading")});const Z=n?.mailboxDepth??n?.queuedItems?.length??0,I=Ch(t).running,ie=(()=>{const A=n?.attentionState??"idle";return A==="deciding"||A==="idle"&&Z>0?"deciding":A!=="idle"&&!n?.currentFocus?"idle":A})(),Q=ie==="idle"&&o?.history?.some(A=>A.status==="processing"),W=(n?.attentionState??"idle")==="idle"&&Z>0;return c.jsxs("div",{className:"space-y-4",children:[c.jsxs("section",{children:[c.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[I?c.jsx("span",{className:`px-2.5 py-1 text-xs font-medium rounded-full ${R4[ie]??"bg-gray-500/20 text-gray-500"}`,children:i(`agent:profilePage.mind.attention.${ie}`)}):c.jsx("span",{className:"px-2.5 py-1 text-xs font-medium rounded-full bg-gray-500/20 text-fg-tertiary",children:i("agent:profilePage.mind.agentStopped")}),I?n?.currentFocus?(()=>{const A=Ab({id:n.currentFocus.mailboxItemId,sourceType:n.currentFocus.type,payload:{summary:n.currentFocus.label,taskId:n.currentFocus.taskId},metadata:{},queuedAt:n.currentFocus.startedAt},i);return c.jsxs("span",{className:"text-sm text-fg-secondary inline-flex items-center gap-2",children:[c.jsxs("span",{children:[yc[n.currentFocus.type]??"●"," ",c.jsx("span",{className:"text-fg-primary font-medium",children:A.title}),A.subtitle&&c.jsx("span",{className:"text-fg-tertiary ml-1.5 text-xs",children:A.subtitle}),c.jsx("span",{className:"text-fg-tertiary ml-2 text-xs",children:i("agent:profilePage.mind.since",{time:new Date(n.currentFocus.startedAt).toLocaleTimeString()})})]}),r&&c.jsxs("button",{onClick:()=>j(n.currentFocus.mailboxItemId),className:"px-2 py-0.5 text-[10px] font-medium rounded-md bg-red-500/15 text-red-500 hover:bg-red-500/25 transition-colors shrink-0",children:["✕ ",i("agent:profilePage.mind.cancelCurrentBtn")]})]})})():W?c.jsx("span",{className:"text-sm text-amber-500",children:i("agent:profilePage.mind.queuedButIdle",{count:Z,defaultValue:"Queue has {{count}} item(s) — attention loop should pick them up…"})}):ie==="deciding"?c.jsx("span",{className:"text-sm text-amber-500",children:i("agent:profilePage.mind.decidingWaiting",{count:Z})}):c.jsx("span",{className:"text-sm text-fg-tertiary",children:i("agent:profilePage.mind.idleWaiting")}):c.jsx("span",{className:"text-sm text-fg-tertiary",children:i("agent:profilePage.mind.stoppedHint")}),c.jsx("div",{className:"ml-auto flex items-center gap-2",children:c.jsx("button",{onClick:()=>{E()},className:"text-xs text-fg-tertiary hover:text-fg-secondary active:text-fg-primary transition-colors",children:i("agent:profilePage.mind.refresh")})})]}),I&&Q&&c.jsxs("div",{className:"mb-3 px-3 py-2 rounded-lg bg-amber-500/10 border border-amber-500/30 flex items-center gap-2",children:[c.jsx("span",{className:"text-amber-500 text-sm",children:"⚠"}),c.jsx("span",{className:"text-[11px] text-amber-600",children:i("agent:profilePage.mind.staleProcessingWarning")})]}),(n?.queuedItems?.length??0)>0&&(()=>{const A=n.queuedItems,X=A.length>L,Y=X&&!x?A.slice(0,L):A,se=A.reduce((ee,me)=>(ee[me.sourceType]=(ee[me.sourceType]??0)+1,ee),{});return c.jsxs("div",{className:"mb-3",children:[c.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[c.jsx("h4",{className:"text-xs font-medium text-amber-500 uppercase tracking-wider",children:i("agent:profilePage.mind.queue",{count:A.length})}),c.jsx("div",{className:"flex gap-1.5 flex-wrap",children:Object.entries(se).map(([ee,me])=>c.jsxs("span",{className:"text-[10px] text-fg-tertiary bg-amber-500/10 px-1.5 py-0.5 rounded",children:[yc[ee]??"●"," ",me]},ee))})]}),c.jsxs("div",{className:"space-y-1",children:[Y.map((ee,me)=>c.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded bg-amber-500/5 border border-amber-500/20 text-sm",children:[c.jsx("span",{className:"text-fg-tertiary w-4 text-right text-xs",children:me+1}),c.jsx("span",{className:"text-sm",children:yc[ee.sourceType]??"●"}),c.jsx("span",{className:`text-[10px] ${Rb[ee.priority]??"text-fg-tertiary"}`,children:i(`agent:profilePage.mind.priority.${Eb[ee.priority]??ee.priority}`,{defaultValue:`P${ee.priority}`})}),c.jsx("span",{className:"text-fg-secondary truncate flex-1 text-xs",children:ee.summary}),c.jsx("span",{className:"text-[10px] text-fg-tertiary",children:new Date(ee.queuedAt).toLocaleTimeString()})]},ee.id)),X&&c.jsx("button",{onClick:()=>y(!x),className:"w-full text-center text-[11px] text-amber-500 hover:text-amber-400 py-1 transition-colors",children:x?i("agent:profilePage.mind.collapseQueue"):i("agent:profilePage.mind.expandQueue",{count:A.length-L})})]})]})})()]}),(n?.notebook?.length??0)>0&&(()=>{const A=m4(n.notebook,w);return c.jsx("section",{className:"bg-surface-2 rounded-lg border border-border-subtle p-3",children:c.jsxs("details",{children:[c.jsxs("summary",{className:"flex items-center gap-2 cursor-pointer list-none",children:[c.jsx("span",{className:"text-sm",children:"📓"}),c.jsx("h4",{className:"text-xs font-medium text-fg-secondary uppercase tracking-wider",children:i("agent:profilePage.mind.notebook")}),c.jsx("span",{className:"text-[10px] text-fg-quaternary ml-auto",children:i("agent:profilePage.mind.notebookEntries",{count:n.notebook.length})})]}),c.jsx("p",{className:"mt-2 text-[10px] text-fg-quaternary leading-relaxed",children:i("agent:profilePage.mind.notebookHint",{count:R_})}),c.jsxs("div",{className:"mt-2 space-y-2",children:[A.visible.map(X=>{const Y=p4(X.updatedAt),se=i(`agent:profilePage.relative.${Y.unit==="seconds"?"secondsAgo":Y.unit==="minutes"?"minutesAgo":"hoursAgo"}`,{count:Y.count,hours:Y.count}),ee=X.managed==="system"?"text-blue-400":X.managed==="cpp"?"text-purple-400":"text-emerald-400";return c.jsxs("div",{className:"px-3 py-2 rounded bg-surface-3 border border-border-subtle",children:[c.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[c.jsx("span",{className:"text-xs font-medium text-fg-primary",children:X.key}),c.jsxs("span",{className:`text-[10px] ${ee}`,children:["[",X.managed,"]"]}),c.jsx("span",{className:"text-[10px] text-fg-quaternary ml-auto",children:se})]}),c.jsx("pre",{className:"text-[11px] text-fg-secondary whitespace-pre-wrap break-words leading-relaxed max-h-32 overflow-y-auto",children:X.text.length>500?X.text.slice(0,500)+"…":X.text})]},X.key)}),A.collapsible&&c.jsx("button",{onClick:()=>C(!w),className:"w-full text-center text-[11px] text-accent-primary hover:opacity-80 py-1 transition-colors",children:w?i("agent:profilePage.mind.collapseQueue"):i("agent:profilePage.mind.expandNotebook",{count:A.hiddenCount})})]})]})})})(),n?.deliberationActivity&&c.jsxs("section",{className:"bg-surface-2 rounded-lg border border-amber-500/20 p-3",children:[c.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[c.jsx("span",{className:"text-sm",children:"🧠"}),c.jsx("h4",{className:"text-xs font-medium text-amber-500 uppercase tracking-wider",children:i("agent:profilePage.mind.deliberationInProgress")}),c.jsx("span",{className:"text-[10px] text-fg-quaternary ml-auto",children:i("agent:profilePage.mind.since",{time:new Date(n.deliberationActivity.startedAt).toLocaleTimeString()})})]}),c.jsx(_h,{agentId:s,activityId:n.deliberationActivity.activityId,isLive:!0})]}),n?.lastTriage&&(()=>{const X=Date.now()-new Date(n.lastTriage.timestamp).getTime()>6e4;return c.jsx("section",{className:`bg-surface-2 rounded-lg border p-3 transition-opacity ${X?"border-border-subtle opacity-60":"border-indigo-500/20"}`,children:c.jsxs("details",{open:!X,children:[c.jsxs("summary",{className:"flex items-center gap-2 cursor-pointer list-none",children:[c.jsx("span",{className:"text-sm",children:"🧠"}),c.jsx("h4",{className:"text-xs font-medium text-indigo-400 uppercase tracking-wider",children:i("agent:profilePage.mind.triageDecision")}),c.jsx("span",{className:"text-[10px] text-fg-quaternary ml-auto",children:new Date(n.lastTriage.timestamp).toLocaleTimeString()})]}),c.jsx("p",{className:"text-xs text-fg-secondary leading-relaxed mt-2",children:n.lastTriage.reasoning}),c.jsxs("div",{className:"flex flex-wrap gap-2 mt-2 text-[10px]",children:[c.jsx("span",{className:"px-1.5 py-0.5 rounded bg-green-500/10 text-green-400",children:i("agent:profilePage.mind.processingItem",{id:n.lastTriage.processedItemId.slice(0,12)})}),n.lastTriage.deferredItemIds.length>0&&c.jsx("span",{className:"px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-400",children:i("agent:profilePage.mind.deferred",{count:n.lastTriage.deferredItemIds.length})}),n.lastTriage.droppedItemIds.length>0&&c.jsx("span",{className:"px-1.5 py-0.5 rounded bg-red-500/10 text-red-400",children:i("agent:profilePage.mind.dropped",{count:n.lastTriage.droppedItemIds.length})}),(n.lastTriage.inlineCompletedIds?.length??0)>0&&c.jsx("span",{className:"px-1.5 py-0.5 rounded bg-blue-500/10 text-blue-400",children:i("agent:profilePage.mind.inlineCompleted",{count:n.lastTriage.inlineCompletedIds.length})})]})]})})})(),c.jsxs("section",{children:[c.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[c.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase tracking-wider",children:i("agent:profilePage.mind.mailboxHistory")}),c.jsx("div",{className:"flex gap-1 ml-auto flex-wrap",children:A4.map(A=>{const X=o?.sourceTypeCounts,Y=A==="all"?X?Object.values(X).reduce((se,ee)=>se+ee,0):void 0:X?(M4[A]??[]).reduce((se,ee)=>se+(X[ee]??0),0):void 0;return c.jsxs("button",{onClick:()=>f(A),className:`px-2 py-0.5 text-[10px] rounded-md border transition-colors ${u===A?"bg-brand-500/20 border-brand-500/40 text-brand-300":"bg-surface-2 border-border-subtle text-fg-secondary hover:bg-surface-3"}`,children:[i(`agent:profilePage.mind.categoryFilters.${A}`),Y!=null&&Y>0&&c.jsx("span",{className:"ml-1 opacity-60",children:Y})]},A)})})]}),c.jsx("div",{className:"flex gap-1 mb-2 flex-wrap",children:[{key:"all",dot:""},{key:"queued",dot:"bg-amber-400"},{key:"processing",dot:"bg-blue-400"},{key:"completed",dot:"bg-green-500"},{key:"merged",dot:"bg-brand-400"},{key:"deferred",dot:"bg-purple-400"},{key:"dropped",dot:"bg-red-500"}].map(A=>{const X=o?.statusCounts,Y=A.key==="all"?X?Object.values(X).reduce((se,ee)=>se+ee,0):void 0:X?.[A.key];return c.jsxs("button",{onClick:()=>b(A.key),className:`px-2 py-0.5 text-[10px] rounded-md border transition-colors flex items-center gap-1 ${p===A.key?"bg-brand-500/20 border-brand-500/40 text-brand-300":"bg-surface-2 border-border-subtle text-fg-secondary hover:bg-surface-3"}`,children:[A.dot&&c.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${A.dot}`}),i(`agent:profilePage.mind.statusFilters.${A.key}`),Y!=null&&Y>0&&c.jsx("span",{className:"ml-1 opacity-60",children:Y})]},A.key)})}),(!o?.history||o.history.length===0)&&!h&&c.jsx("div",{className:"text-center text-fg-tertiary text-sm py-8",children:i("agent:profilePage.mind.noHistory")}),c.jsx("div",{className:"space-y-1",children:o?.history?.map(A=>{const X=v===A.id,Y=yc[A.sourceType]??"●",se=Ab(A,i),ee=A.metadata?.senderName,me=A.metadata?.senderRole,V=O===A.id;return c.jsxs("div",{id:`mbx-${A.id}`,className:`bg-surface-2 rounded-lg border transition-colors duration-1000 ${V?"border-brand-500 ring-1 ring-brand-500/40":"border-border-subtle"}`,children:[c.jsxs("button",{className:"w-full px-3 py-2.5 flex items-start gap-2 text-left hover:bg-surface-3/50 transition-colors rounded-lg",onClick:()=>g(X?null:A.id),children:[c.jsx("span",{className:"text-xs mt-0.5 text-fg-tertiary",children:X?"▾":"▸"}),c.jsx("span",{className:`w-2 h-2 mt-1.5 rounded-full shrink-0 ${L4[A.status]??"bg-gray-400"}`}),c.jsx("span",{className:"text-sm",children:Y}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:`text-xs font-medium text-fg-primary ${X?"":"truncate"}`,children:se.title}),se.badge&&c.jsx("span",{className:`text-[10px] font-medium shrink-0 ${se.badge.color}`,children:se.badge.label}),c.jsx("span",{className:`text-[10px] shrink-0 ${Rb[A.priority]??"text-fg-tertiary"}`,children:i(`agent:profilePage.mind.priority.${Eb[A.priority]??A.priority}`,{defaultValue:""})})]}),se.subtitle&&c.jsx("div",{className:`text-[11px] text-fg-secondary mt-0.5 ${X?"":"truncate"}`,children:se.subtitle}),c.jsxs("div",{className:"text-[10px] text-fg-tertiary mt-0.5 flex gap-2 flex-wrap",children:[c.jsx("span",{children:new Date(A.queuedAt).toLocaleString()}),A.completedAt&&c.jsxs("span",{children:["→ ",new Date(A.completedAt).toLocaleTimeString()]}),A.activity&&c.jsxs(c.Fragment,{children:[A.activity.totalTokens>0&&c.jsx("span",{children:i("agent:profilePage.mind.tokensCount",{count:mm(A.activity.totalTokens)})}),A.activity.totalTools>0&&c.jsx("span",{children:i("agent:profilePage.mind.toolsCount",{count:A.activity.totalTools})})]})]})]}),c.jsx("span",{className:"text-[10px] text-fg-tertiary bg-surface-3 px-1.5 py-0.5 rounded shrink-0",children:A.sourceType}),r&&A.status==="processing"&&c.jsxs("button",{onClick:N=>{N.stopPropagation(),j(A.id)},className:"px-2 py-0.5 text-[10px] font-medium rounded-md bg-red-500/15 text-red-500 hover:bg-red-500/25 transition-colors shrink-0",children:["✕ ",i("agent:profilePage.mind.cancelCurrentBtn")]})]}),X&&c.jsxs("div",{className:"border-t border-border-subtle px-3 py-3 space-y-3",children:[ee&&c.jsxs("div",{className:"text-[10px] text-fg-tertiary",children:[i("agent:profilePage.mind.from")," ",c.jsx("span",{className:"text-fg-secondary",children:ee}),me&&c.jsxs("span",{className:"text-fg-tertiary",children:[" (",me,")"]})]}),A.payload?.content&&["human_chat","a2a_message","task_comment","requirement_comment","review_request","session_reply","mention"].includes(A.sourceType)&&c.jsx("div",{className:"text-xs text-fg-secondary bg-surface-primary/50 rounded-md p-2.5 whitespace-pre-wrap break-words max-h-60 overflow-y-auto",children:A.payload.content}),A.decisions&&A.decisions.length>0&&c.jsxs("div",{children:[c.jsx("h5",{className:"text-[10px] font-medium text-fg-tertiary uppercase tracking-wider mb-1",children:i("agent:profilePage.mind.decisions")}),c.jsx("div",{className:"space-y-1",children:A.decisions.map(N=>c.jsxs("div",{className:"flex items-start gap-2 text-xs",children:[c.jsx("span",{className:`px-1.5 py-0.5 rounded shrink-0 ${E4[N.decisionType]??"bg-gray-500/20 text-gray-500"}`,children:N.decisionType}),c.jsx("span",{className:"text-fg-secondary flex-1",children:N.reasoning}),c.jsx("span",{className:"text-fg-tertiary shrink-0",children:new Date(N.createdAt).toLocaleTimeString()})]},N.id))})]}),A.activity?c.jsxs("div",{children:[c.jsxs("h5",{className:"text-[10px] font-medium text-fg-tertiary uppercase tracking-wider mb-1",children:[i("agent:profilePage.mind.activityHeading",{label:A.activity.label}),c.jsx("span",{className:`ml-2 inline-block px-1 py-0 rounded text-[9px] ${A.activity.success?"bg-green-500/15 text-green-500":"bg-red-500/15 text-red-500"}`,children:A.activity.success?i("agent:profilePage.mind.success"):i("agent:profilePage.mind.failed")})]}),A.activity.type==="task"&&A.payload?.taskId?c.jsx($4,{taskId:A.payload.taskId,isLive:!A.activity.endedAt}):c.jsx(_h,{agentId:s,activityId:A.activity.id,isLive:!A.activity.endedAt})]}):A.status==="processing"?c.jsx("div",{className:"text-xs text-fg-tertiary text-center py-2 animate-pulse",children:i("agent:profilePage.mind.processing")}):A.status==="completed"?c.jsx("div",{className:"text-xs text-fg-tertiary text-center py-2",children:i("agent:profilePage.mind.noActivityLog")}):null]})]},A.id)})}),P&&(o?.history?.length??0)>0&&c.jsx("div",{className:"text-center mt-3",children:c.jsx("button",{onClick:B,className:"text-xs text-brand-400 hover:text-brand-300 transition-colors",children:i("agent:profilePage.mind.loadEarlier")})})]}),T&&c.jsx(Po,{title:i("agent:profilePage.mind.cancelConfirmTitle"),message:i("agent:profilePage.mind.cancelConfirmMessage"),confirmLabel:i("agent:profilePage.mind.cancelCurrentBtn"),onConfirm:()=>{const A=T;j(null),re.agents.cancelProcessing(s,{itemId:A}).then(()=>{let X=0;const Y=()=>{X+=1,E(),X<8&&window.setTimeout(Y,750)};Y()}).catch(()=>{E()})},onCancel:()=>j(null)})]})}function Mb({agentId:s}){const{t:e}=Qt(["agent","common"]),t=kh(),[r,i]=_.useState([]),[n,a]=_.useState(!0),o=_.useCallback(h=>{if(jC(t?.hostAvailable)==="right-panel"){t?.openRightPanel({kind:"deliverable",deliverable:h});return}yr.navigate(Gt.DELIVERABLES,{openDeliverable:h.id})},[t]),l=_.useCallback(async()=>{a(!0);try{const{results:h}=await re.deliverables.search({agentId:s,limit:200});i(h)}catch{i([])}a(!1)},[s]);return _.useEffect(()=>{l()},[l]),_.useEffect(()=>{const h=bt.on("deliverable:created",()=>l()),d=bt.on("deliverable:updated",()=>l()),u=bt.on("deliverable:removed",()=>l());return()=>{h(),d(),u()}},[l]),n?c.jsx("div",{className:"space-y-3 py-4",children:[1,2,3].map(h=>c.jsxs("div",{className:"animate-pulse space-y-2",children:[c.jsx("div",{className:"h-4 bg-surface-elevated rounded w-3/4"}),c.jsx("div",{className:"h-3 bg-surface-elevated rounded w-1/2"})]},h))}):r.length===0?c.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[c.jsx("span",{className:"text-3xl mb-3",children:"📦"}),c.jsx("p",{className:"text-sm text-fg-secondary",children:e("agent:deliverables.empty")}),c.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:e("agent:deliverables.emptyHint")})]}):c.jsx(c.Fragment,{children:c.jsxs("div",{className:"space-y-2",children:[c.jsx("div",{className:"text-xs text-fg-tertiary mb-3",children:e("agent:deliverables.count",{count:r.length})}),r.map(h=>{const d=Jw[h.type]??{icon:"📎",color:"bg-surface-elevated text-fg-secondary"},u=Wg[h.status]??Wg.active;return c.jsxs("button",{onClick:()=>o(h),className:"w-full text-left rounded-xl border border-border-default bg-surface-elevated/30 overflow-hidden transition-colors hover:border-brand-500/40 hover:bg-surface-elevated/50 px-4 py-3 flex items-start gap-3",children:[c.jsx("span",{className:`inline-flex items-center justify-center w-8 h-8 rounded-lg text-sm shrink-0 ${d.color}`,children:d.icon}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[c.jsx("span",{className:"text-sm font-medium text-fg-primary truncate",children:h.title}),c.jsx("span",{className:`px-1.5 py-0.5 text-[10px] rounded font-medium ${u.color}`,children:h.status})]}),h.summary&&c.jsx("p",{className:"text-xs text-fg-tertiary mt-0.5 line-clamp-1",children:h.summary}),c.jsxs("div",{className:"flex items-center gap-3 mt-1 text-[10px] text-fg-tertiary",children:[c.jsx("span",{children:new Date(h.createdAt).toLocaleDateString()}),h.tags.length>0&&c.jsx("span",{children:h.tags.slice(0,3).join(", ")})]})]}),c.jsx("svg",{className:"w-4 h-4 text-fg-tertiary shrink-0 mt-1",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:c.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})})]},h.id)})]})})}const I4=_.lazy(()=>Ub(()=>import("./index-BrU2YO3p.js").then(s=>s.b1),__vite__mapDeps([0,1])).then(s=>({default:s.MarkdownMessage}))),Lp=[{key:"overview",labelKey:"teamProfile.overview",icon:"▦"},{key:"announcements",labelKey:"teamProfile.announcements",icon:"◈"},{key:"norms",labelKey:"teamProfile.norms",icon:"☰"},{key:"settings",labelKey:"teamProfile.settings",icon:"⚙"}],Lb={idle:"bg-green-400",working:"bg-blue-400 animate-pulse",offline:"bg-gray-500",error:"bg-red-400"};function Nb({teamId:s,onBack:e,inline:t,headless:r,activeTab:i,onSelectAgent:n}){const{t:a}=Qt("team"),[o,l]=_.useState(null),[h,d]=_.useState(null),[u,f]=_.useState("overview"),p=r&&i?i:u,[b,v]=_.useState(""),[g,O]=_.useState(""),[m,x]=_.useState(!1),[y,w]=_.useState(!1),[C,P]=_.useState(""),[S,T]=_.useState(""),j=_.useRef(null),M=_.useRef(null),L=_.useRef(null),E=_.useRef(null),[B,U]=_.useState(!1),[Z,I]=_.useState(!1),[ie,Q]=_.useState(""),[W,A]=_.useState(""),[X,Y]=_.useState(!1),[se,ee]=_.useState([]),me=_.useRef(null),V=_.useCallback(async()=>{try{const be=(await re.teams.list()).teams.find(ke=>ke.id===s);be&&l(be);const Ae=await re.teams.status(s);ee(Ae.agents)}catch{}},[s]),N=_.useCallback(async()=>{try{const pe=await re.teams.getFile(s,"ANNOUNCEMENT.md");v(pe.content)}catch{v("")}try{const pe=await re.teams.getFile(s,"NORMS.md");O(pe.content)}catch{O("")}},[s]);_.useEffect(()=>{f("overview"),V(),N()},[s,V,N]),_.useEffect(()=>{m&&M.current&&M.current.focus()},[m]),_.useEffect(()=>{y&&E.current&&E.current.focus()},[y]);const ne=async(pe,be)=>{U(!0);try{await re.teams.updateFile(s,pe,be),pe==="ANNOUNCEMENT.md"?(v(be),x(!1)):(O(be),w(!1))}catch{}U(!1)},H=async()=>{ie.trim()&&(await re.teams.update(s,{name:ie.trim()}),I(!1),V())},te=async()=>{await re.teams.update(s,{description:W}),Y(!1),V()};if(!o)return c.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary text-sm",children:"Loading team..."});const J=o.members.find(pe=>pe.agentRole==="manager"),ge=se.filter(pe=>pe.status!=="offline").length,Qe=p==="announcements"&&m||p==="norms"&&y;if(r)return c.jsx("div",{className:`flex-1 bg-surface-primary ${Qe?"flex flex-col overflow-hidden":"overflow-y-auto"}`,children:c.jsxs("div",{className:`${Qe?"flex-1 flex flex-col min-h-0 p-5":"p-5"}`,children:[p==="overview"&&c.jsxs("div",{className:"space-y-5",children:[c.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[c.jsxs("div",{className:"p-4 bg-surface-secondary rounded-xl border border-border-default",children:[c.jsx("div",{className:"text-xs text-fg-tertiary mb-1",children:"Manager"}),c.jsx("div",{className:"text-sm font-medium",children:J?.name??o.managerName??"None"})]}),c.jsxs("div",{className:"p-4 bg-surface-secondary rounded-xl border border-border-default",children:[c.jsx("div",{className:"text-xs text-fg-tertiary mb-1",children:"Team ID"}),c.jsx("div",{className:"text-sm font-mono text-fg-secondary truncate",children:o.id})]})]}),c.jsxs("div",{className:"space-y-3",children:[c.jsx("div",{className:"text-xs text-fg-tertiary font-medium px-1",children:"Members"}),o.members.map(pe=>{const be=se.find(oe=>oe.id===pe.id),Ae=Lb[be?.status??"offline"]??"bg-gray-500",ke=pe.type==="agent";return c.jsxs("div",{onClick:()=>ke&&n?.(pe.id),className:`p-3 bg-surface-secondary rounded-xl border border-border-default flex items-center gap-3${ke&&n?" cursor-pointer hover:border-brand-500/40 transition-colors":""}`,children:[c.jsx(Qs,{name:pe.name,avatarUrl:pe.avatarUrl,size:32,className:"rounded-lg"}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-sm font-medium",children:pe.name}),c.jsx("span",{className:`w-2 h-2 rounded-full ${Ae}`}),c.jsx("span",{className:"text-xs text-fg-tertiary",children:be?.status??"offline"}),pe.agentRole==="manager"&&c.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-amber-500/15 text-amber-600 rounded font-medium",children:"Manager"})]}),c.jsxs("div",{className:"text-xs text-fg-tertiary",children:[pe.role," · ",pe.type]})]}),ke&&n&&c.jsx("svg",{className:"w-4 h-4 text-fg-tertiary shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"9 18 15 12 9 6"})})]},pe.id)}),o.members.length===0&&c.jsx("div",{className:"text-sm text-fg-tertiary text-center py-8",children:"No members"})]})]}),p==="announcements"&&c.jsx(Sc,{content:b,draft:C,setDraft:P,editing:m,setEditing:x,textareaRef:M,contentRef:j,saving:B,onSave:()=>ne("ANNOUNCEMENT.md",C),placeholder:a("teamProfile.annPlaceholder"),emptyText:a("teamProfile.noAnnouncements")}),p==="norms"&&c.jsx(Sc,{content:g,draft:S,setDraft:T,editing:y,setEditing:w,textareaRef:E,contentRef:L,saving:B,onSave:()=>ne("NORMS.md",S),placeholder:a("teamProfile.normsPlaceholder"),emptyText:a("teamProfile.noNorms")}),p==="settings"&&c.jsxs("div",{className:"space-y-5",children:[c.jsxs("div",{className:"p-4 bg-surface-secondary rounded-xl border border-border-default space-y-4",children:[c.jsxs("div",{children:[c.jsx("div",{className:"text-xs text-fg-tertiary mb-1",children:"Team Name"}),Z?c.jsxs("div",{className:"flex gap-2 items-center",children:[c.jsx("input",{ref:me,value:ie,onChange:pe=>Q(pe.target.value),onKeyDown:pe=>pe.key==="Enter"&&H(),className:"flex-1 bg-surface-elevated border border-border-default rounded-lg px-3 py-1.5 text-sm text-fg-primary focus:outline-none focus:border-brand-500",autoFocus:!0}),c.jsx("button",{onClick:H,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-white",children:"Save"}),c.jsx("button",{onClick:()=>I(!1),className:"px-3 py-1.5 text-xs bg-surface-elevated hover:bg-surface-overlay rounded-lg text-fg-secondary",children:"Cancel"})]}):c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-sm",children:o.name}),c.jsx("button",{onClick:()=>{Q(o.name),I(!0)},className:"text-xs text-fg-tertiary hover:text-fg-secondary",children:"Edit"})]})]}),c.jsxs("div",{children:[c.jsx("div",{className:"text-xs text-fg-tertiary mb-1",children:"Description"}),X?c.jsxs("div",{className:"space-y-2",children:[c.jsx("textarea",{value:W,onChange:pe=>A(pe.target.value),className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-1.5 text-sm text-fg-primary resize-y focus:outline-none focus:border-brand-500",rows:3,autoFocus:!0}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx("button",{onClick:te,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-white",children:"Save"}),c.jsx("button",{onClick:()=>Y(!1),className:"px-3 py-1.5 text-xs bg-surface-elevated hover:bg-surface-overlay rounded-lg text-fg-secondary",children:"Cancel"})]})]}):c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-sm text-fg-secondary",children:o.description||"No description"}),c.jsx("button",{onClick:()=>{A(o.description??""),Y(!0)},className:"text-xs text-fg-tertiary hover:text-fg-secondary",children:"Edit"})]})]})]}),c.jsx(Db,{teamId:s,teamName:o.name,onDeleted:e})]})]})});const _e=u==="announcements"&&m||u==="norms"&&y;return c.jsxs("div",{className:`flex-1 bg-surface-primary ${_e?"flex flex-col overflow-hidden":"overflow-y-auto"}`,children:[c.jsxs("div",{className:"px-5 py-3.5 bg-surface-secondary sticky top-0 z-10 shrink-0",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:"w-10 h-10 rounded-xl bg-brand-600 text-white flex items-center justify-center text-lg font-bold shrink-0",children:c.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),c.jsx("circle",{cx:"9",cy:"7",r:"4"}),c.jsx("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),c.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]})}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[c.jsx("h2",{className:"text-base font-semibold",children:o.name}),c.jsxs("span",{className:"px-1.5 py-0.5 text-[10px] bg-brand-500/15 text-brand-500 rounded font-medium",children:[o.members.length," members"]}),c.jsxs("span",{className:"px-1.5 py-0.5 text-[10px] bg-green-500/15 text-green-600 rounded font-medium",children:[ge," online"]})]}),c.jsx("div",{className:"text-xs text-fg-tertiary truncate",children:o.description||"No description"})]}),c.jsxs("button",{onClick:async()=>{if(o)try{const{files:pe}=await re.teams.getFilesMap(o.id),be=o.members.filter(ke=>ke.type==="agent"),Ae={type:"team",name:Zb(o.name,o.name),displayName:o.name,version:"1.0.0",description:o.description??"",author:"",category:"general",tags:[],team:{members:be.map(ke=>({name:ke.name,roleName:ke.role,role:ke.agentRole??"worker",count:1,skills:[]}))}};await vm.publishViaProxy({itemType:"team",name:o.name,description:o.description??"",category:"general",config:Ae,files:pe}),d({title:"Hub",message:`Published "${o.name}" to Markus Hub`,variant:"primary"})}catch(pe){d({title:"Hub",message:`Failed to publish: ${pe}`,variant:"danger"})}},className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 text-white rounded-lg transition-colors flex items-center gap-1",title:"Publish to Markus Hub",children:[c.jsx("span",{children:"↑"})," Hub"]}),t&&c.jsx("button",{onClick:e,className:"p-1.5 text-fg-tertiary hover:text-fg-secondary text-lg leading-none",children:"×"})]}),c.jsx("div",{className:"flex gap-1 mt-3 -mb-[1px] overflow-x-auto",children:Lp.map(pe=>c.jsxs("button",{onClick:()=>f(pe.key),className:`px-3 py-1.5 text-xs rounded-t-lg whitespace-nowrap transition-colors ${u===pe.key?"bg-surface-primary text-fg-primary border border-border-default border-b-gray-950":"text-fg-tertiary hover:text-fg-secondary"}`,children:[pe.icon," ",a(pe.labelKey)]},pe.key))})]}),c.jsxs("div",{className:`${_e?"flex-1 flex flex-col min-h-0 p-5":"p-5"}`,children:[u==="overview"&&c.jsxs("div",{className:"space-y-5",children:[c.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[c.jsxs("div",{className:"p-4 bg-surface-secondary rounded-xl border border-border-default",children:[c.jsx("div",{className:"text-xs text-fg-tertiary mb-1",children:"Manager"}),c.jsx("div",{className:"text-sm font-medium",children:J?.name??o.managerName??"None"})]}),c.jsxs("div",{className:"p-4 bg-surface-secondary rounded-xl border border-border-default",children:[c.jsx("div",{className:"text-xs text-fg-tertiary mb-1",children:"Team ID"}),c.jsx("div",{className:"text-sm font-mono text-fg-secondary truncate",children:o.id})]})]}),c.jsxs("div",{className:"space-y-3",children:[c.jsx("div",{className:"text-xs text-fg-tertiary font-medium px-1",children:"Members"}),o.members.map(pe=>{const be=se.find(oe=>oe.id===pe.id),Ae=Lb[be?.status??"offline"]??"bg-gray-500",ke=pe.type==="agent";return c.jsxs("div",{onClick:()=>ke&&n?.(pe.id),className:`p-3 bg-surface-secondary rounded-xl border border-border-default flex items-center gap-3${ke&&n?" cursor-pointer hover:border-brand-500/40 transition-colors":""}`,children:[c.jsx(Qs,{name:pe.name,avatarUrl:pe.avatarUrl,size:32,className:"rounded-lg"}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-sm font-medium",children:pe.name}),c.jsx("span",{className:`w-2 h-2 rounded-full ${Ae}`}),c.jsx("span",{className:"text-xs text-fg-tertiary",children:be?.status??"offline"}),pe.agentRole==="manager"&&c.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-amber-500/15 text-amber-600 rounded font-medium",children:"Manager"})]}),c.jsxs("div",{className:"text-xs text-fg-tertiary",children:[pe.role," · ",pe.type]})]}),ke&&n&&c.jsx("svg",{className:"w-4 h-4 text-fg-tertiary shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"9 18 15 12 9 6"})})]},pe.id)}),o.members.length===0&&c.jsx("div",{className:"text-sm text-fg-tertiary text-center py-8",children:"No members"})]})]}),u==="announcements"&&c.jsx(Sc,{content:b,draft:C,setDraft:P,editing:m,setEditing:x,textareaRef:M,contentRef:j,saving:B,onSave:()=>ne("ANNOUNCEMENT.md",C),placeholder:a("teamProfile.annPlaceholder"),emptyText:a("teamProfile.noAnnouncements")}),u==="norms"&&c.jsx(Sc,{content:g,draft:S,setDraft:T,editing:y,setEditing:w,textareaRef:E,contentRef:L,saving:B,onSave:()=>ne("NORMS.md",S),placeholder:a("teamProfile.normsPlaceholder"),emptyText:a("teamProfile.noNorms")}),u==="settings"&&c.jsxs("div",{className:"space-y-5",children:[c.jsxs("div",{className:"p-4 bg-surface-secondary rounded-xl border border-border-default space-y-4",children:[c.jsxs("div",{children:[c.jsx("div",{className:"text-xs text-fg-tertiary mb-1",children:"Team Name"}),Z?c.jsxs("div",{className:"flex gap-2 items-center",children:[c.jsx("input",{ref:me,value:ie,onChange:pe=>Q(pe.target.value),onKeyDown:pe=>pe.key==="Enter"&&H(),className:"flex-1 bg-surface-elevated border border-border-default rounded-lg px-3 py-1.5 text-sm text-fg-primary focus:outline-none focus:border-brand-500",autoFocus:!0}),c.jsx("button",{onClick:H,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-white",children:"Save"}),c.jsx("button",{onClick:()=>I(!1),className:"px-3 py-1.5 text-xs bg-surface-elevated hover:bg-surface-overlay rounded-lg text-fg-secondary",children:"Cancel"})]}):c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-sm",children:o.name}),c.jsx("button",{onClick:()=>{Q(o.name),I(!0)},className:"text-xs text-fg-tertiary hover:text-fg-secondary",children:"Edit"})]})]}),c.jsxs("div",{children:[c.jsx("div",{className:"text-xs text-fg-tertiary mb-1",children:"Description"}),X?c.jsxs("div",{className:"space-y-2",children:[c.jsx("textarea",{value:W,onChange:pe=>A(pe.target.value),className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-1.5 text-sm text-fg-primary resize-y focus:outline-none focus:border-brand-500",rows:3,autoFocus:!0}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx("button",{onClick:te,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-white",children:"Save"}),c.jsx("button",{onClick:()=>Y(!1),className:"px-3 py-1.5 text-xs bg-surface-elevated hover:bg-surface-overlay rounded-lg text-fg-secondary",children:"Cancel"})]})]}):c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-sm text-fg-secondary",children:o.description||"No description"}),c.jsx("button",{onClick:()=>{A(o.description??""),Y(!0)},className:"text-xs text-fg-tertiary hover:text-fg-secondary",children:"Edit"})]})]})]}),c.jsx(Db,{teamId:s,teamName:o.name,onDeleted:e})]})]}),h&&c.jsx(Po,{alertOnly:!0,variant:h.variant??"primary",title:h.title,message:h.message,onConfirm:()=>d(null),onCancel:()=>d(null)})]})}function Sc({content:s,draft:e,setDraft:t,editing:r,setEditing:i,textareaRef:n,contentRef:a,saving:o,onSave:l,placeholder:h,emptyText:d}){return r?c.jsxs("div",{className:"flex flex-col h-full min-h-0",children:[c.jsx("textarea",{ref:n,value:e,onChange:u=>t(u.target.value),onBlur:()=>{e!==s?l():i(!1)},onKeyDown:u=>{u.key==="Escape"&&(u.preventDefault(),t(s),i(!1))},className:"flex-1 w-full bg-transparent border border-brand-500/30 rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none resize-none px-3 py-2 font-mono",placeholder:h}),o&&c.jsx("div",{className:"text-xs text-fg-tertiary mt-1 shrink-0",children:"Saving..."})]}):c.jsx("div",{ref:a,className:"group relative cursor-pointer rounded-lg px-1 py-1 hover:bg-surface-elevated/50 transition-colors min-h-[80px]",onClick:()=>{t(s),i(!0)},role:"button",tabIndex:0,onKeyDown:u=>{u.key==="Enter"&&(t(s),i(!0))},children:s.trim()?c.jsx(_.Suspense,{fallback:c.jsx("div",{className:"text-xs text-fg-tertiary",children:"Loading…"}),children:c.jsx(I4,{content:s,className:"text-sm text-fg-secondary leading-relaxed"})}):c.jsx("div",{className:"text-sm text-fg-tertiary italic",children:d})})}function Db({teamId:s,teamName:e,onDeleted:t}){const[r,i]=_.useState(!1),[n,a]=_.useState(!1),[o,l]=_.useState(!1),[h,d]=_.useState(!1);return c.jsxs("div",{className:"p-4 bg-surface-secondary rounded-xl border border-red-900/30 space-y-3",children:[c.jsx("div",{className:"text-sm font-medium text-red-500",children:"Danger Zone"}),r?c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"text-xs text-fg-secondary",children:['Delete team "',e,'"? This removes the team record from the database.']}),c.jsxs("label",{className:"flex items-center gap-2 text-xs text-fg-secondary cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:o,onChange:u=>l(u.target.checked),className:"rounded"}),"Also delete all members in this team"]}),c.jsxs("label",{className:"flex items-center gap-2 text-xs text-fg-secondary cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:n,onChange:u=>a(u.target.checked),className:"rounded"}),"Also delete disk files (workspace, memory, logs)"]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx("button",{disabled:h,onClick:async()=>{d(!0);try{await re.teams.delete(s,o,{purgeFiles:n}),window.dispatchEvent(new CustomEvent("markus:data-changed")),t()}catch{d(!1)}},className:"px-4 py-1.5 text-xs bg-red-600 hover:bg-red-700 text-white rounded-lg transition-colors disabled:opacity-50",children:h?"Deleting...":"Confirm Delete"}),c.jsx("button",{onClick:()=>i(!1),className:"px-4 py-1.5 text-xs bg-surface-elevated hover:bg-surface-overlay text-fg-secondary rounded-lg transition-colors border border-border-default",children:"Cancel"})]})]}):c.jsx("button",{onClick:()=>i(!0),className:"px-4 py-1.5 text-xs bg-red-600/20 hover:bg-red-600/30 text-red-500 rounded-lg transition-colors border border-red-500/30",children:"Delete Team"})]})}const B4=["chat","overview","deliverables"],W4=["chat","overview","announcements","norms","settings"];function X4(s,e){if(s==="chat")return e("page.chatTitle");if(Mp.find(i=>i.key===s))return e(`agent:tabs.${s}`);const r=Lp.find(i=>i.key===s);return r?e(r.labelKey):s}function z4(s){if(s==="chat")return"💬";const e=Mp.find(r=>r.key===s);if(e)return e.icon;const t=Lp.find(r=>r.key===s);return t?t.icon:""}function ri(s){return s!=="chat"}function Oa(s,e,t,r){return s==="channel"?`ch:${t}`:s==="dm"?`dm:${r??""}`:e||"_direct"}class Nr{currentConvKey="";loadingSession=null;msgBuffers=new Map;sessionMsgCache=new Map;activeSession=new Map;actBuffers=new Map;sessionTabs=new Map;phase=new Map;sendCount=new Map;streamingSessions=new Map;sessionCacheOrder=[];static MAX_MESSAGES=500;static MAX_CONVERSATIONS=20;static MAX_SESSION_CACHE=30;static NEW_CHAT_ID="__new_chat__";getPhase(e){return this.phase.get(e)??"idle"}beginLoad(e){this.getPhase(e)!=="streaming"&&this.phase.set(e,"loading")}completeLoad(e){this.getPhase(e)==="loading"&&this.phase.set(e,"ready")}beginStream(e){this.phase.set(e,"streaming")}endStream(e){this.getPhase(e)==="streaming"&&this.phase.set(e,"ready")}resetConv(e,t){this.phase.set(e,"idle"),this.activeSession.delete(e),t&&this.activeSession.set(e,t)}updateMessages(e,t,r){const i=this.activeSession.get(e),n=this.isDisplayRoute(e,i,r),a=n?this.msgBuffers.get(e)??[]:this.sessionMsgCache.get(r)??[];let o=t(a);o.length>Nr.MAX_MESSAGES&&(o=o.slice(-500));let l=!1;return n&&(this.msgBuffers.set(e,o),this.evictIfNeeded(e),l=this.currentConvKey===e),r&&r!==Nr.NEW_CHAT_ID&&(this.sessionMsgCache.set(r,o),this.touchSessionCache(r)),{displayChanged:l,newMessages:l?o:void 0}}isDisplayRoute(e,t,r){if(!r)return!0;if(t!==void 0&&t!==Nr.NEW_CHAT_ID)return t===r;const i=this.msgBuffers.get(e)??[];for(let n=i.length-1;n>=Math.max(0,i.length-3);n--){const a=i[n];if(a?.sender==="agent"&&a.isStreaming&&!a.isStopped)return!0}return!1}applyLoadResult(e,t,r){const i=this.sessionMsgCache.get(t),n=this.isCacheFresher(t,r);n||(this.sessionMsgCache.set(t,r),this.touchSessionCache(t));const o=this.getPhase(e)==="streaming",l=this.streamingSessions.get(e),h=o&&(l?.size??0)>0&&!l.has(t),d=this.activeSession.get(e);if(this.currentConvKey===e&&(this.loadingSession===t||d===t)&&(!o||h)){const f=this.mergeDbWithCache(r,n?i:void 0);return this.msgBuffers.set(e,f),this.loadingSession=t,this.completeLoad(e),{displayChanged:!0,newMessages:f}}return{displayChanged:!1}}mergeDbWithCache(e,t){if(!t||t.length===0)return[...e];const r=new Set,i=[];for(const o of e)r.add(o.id),i.push(o);const n=[],a=[];for(const o of t)r.has(o.id)||(o.sender==="agent"&&o.isStreaming?(n.push(o),r.add(o.id)):a.push(o));for(const o of a){if(r.has(o.id))continue;const l=o.rawCreatedAt?Date.parse(o.rawCreatedAt):NaN;let h=i.length;for(;h>0&&i[h-1].rawCreatedAt&&Number.isFinite(l);){const d=Date.parse(i[h-1].rawCreatedAt);if(!Number.isFinite(d)||d<=l)break;h--}i.splice(h,0,o),r.add(o.id)}for(const o of n)i.push(o);return i}appendActivity(e,t,r){const i=r??e,n=[...this.actBuffers.get(i)??[],t];if(this.actBuffers.set(i,n),this.currentConvKey!==e)return{displayChanged:!1};const a=this.activeSession.get(e);return!r||!a||a===r?{displayChanged:!0,newActivities:n}:{displayChanged:!1}}getActiveSession(e){return this.activeSession.get(e)}setActiveSession(e,t){this.activeSession.set(e,t)}clearActiveSession(e){this.activeSession.delete(e)}saveToCache(e,t){if(!t||t===Nr.NEW_CHAT_ID)return;const r=this.msgBuffers.get(e);r&&r.length>0&&(this.sessionMsgCache.set(t,r),this.touchSessionCache(t))}restoreFromCache(e,t){const r=this.sessionMsgCache.get(t);if(r&&r.length>0)return this.msgBuffers.set(e,r),r;this.msgBuffers.delete(e)}isCacheFresher(e,t){const r=this.sessionMsgCache.get(e);if(!r||r.length===0)return!1;if(r.length>t.length)return!0;const i=r.reduce((l,h)=>l+h.text.length,0),n=t.reduce((l,h)=>l+h.text.length,0);if(i>n)return!0;const a=r.reduce((l,h)=>l+(h.segments?.length??0),0),o=t.reduce((l,h)=>l+(h.segments?.length??0),0);return a>o}incrementSend(e){this.sendCount.set(e,(this.sendCount.get(e)??0)+1)}decrementSend(e){const t=Math.max(0,(this.sendCount.get(e)??1)-1);return this.sendCount.set(e,t),t}resetSend(e){this.sendCount.set(e,0)}isSending(e){return(this.sendCount.get(e)??0)>0}addStreamSession(e,t){const r=this.streamingSessions.get(e)??new Set;return r.has(t)?(this.streamingSessions.set(e,r),!1):(r.add(t),this.streamingSessions.set(e,r),!0)}removeStreamSession(e,t){if(t){const r=this.streamingSessions.get(e);return!r||!r.has(t)?!1:(r.delete(t),r.size===0&&this.streamingSessions.delete(e),!0)}return this.streamingSessions.delete(e)}getStreamSessions(e){return this.streamingSessions.get(e)}abortStream(e,t){let r=!1;(this.sendCount.get(e)??0)>0&&(this.sendCount.set(e,0),r=!0);const i=t??e;if(this.actBuffers.delete(i)&&(r=!0),this.getPhase(e)==="streaming"&&(this.phase.set(e,"ready"),r=!0),t){const n=this.streamingSessions.get(e)?.has(t)??!1;this.removeStreamSession(e,t),n&&(r=!0)}else this.streamingSessions.delete(e)&&(r=!0);return r}getMessages(e){return this.msgBuffers.get(e)}getActivities(e){return this.actBuffers.get(e)??[]}deleteBuffer(e){this.msgBuffers.delete(e)}evictIfNeeded(e){if(this.msgBuffers.size<=Nr.MAX_CONVERSATIONS)return;const t=[...this.msgBuffers.keys()],r=t.filter(i=>i!==e&&i!==this.currentConvKey).slice(0,t.length-Nr.MAX_CONVERSATIONS);for(const i of r)this.msgBuffers.delete(i),this.actBuffers.delete(i),this.sessionTabs.delete(i),this.activeSession.delete(i)}touchSessionCache(e){const t=this.sessionCacheOrder.indexOf(e);for(t!==-1&&this.sessionCacheOrder.splice(t,1),this.sessionCacheOrder.push(e);this.sessionCacheOrder.length>Nr.MAX_SESSION_CACHE;){const r=this.sessionCacheOrder.shift();if(new Set(this.activeSession.values()).has(r)){this.sessionCacheOrder.push(r);break}this.sessionMsgCache.delete(r)}}}const pt=Nr.NEW_CHAT_ID,_c=s=>!!s&&!s.startsWith("ch:")&&!s.startsWith("dm:")&&s!=="_direct";function q4(s){const e=_.useRef(new Nr),[t,r]=_.useState(s??[]),[i,n]=_.useState(!1),[a,o]=_.useState([]),l=_.useRef(null),[,h]=_.useState(0),d=_.useCallback(()=>h(j=>j+1),[]),u=_.useCallback(j=>e.current.getStreamSessions(j),[]),f=_.useCallback((j,M)=>{const L=e.current.addStreamSession(j,M);_c(j)&&sr.markAgentStreaming(j,!0),L&&d()},[d]),p=_.useCallback((j,M)=>{const L=e.current.removeStreamSession(j,M);_c(j)&&sr.markAgentStreaming(j,!1),L&&d()},[d]),b=_.useCallback((j,M)=>e.current.setActiveSession(j,M),[]),v=_.useCallback(j=>e.current.clearActiveSession(j),[]);_.useEffect(()=>()=>{l.current!==null&&cancelAnimationFrame(l.current)},[]);const g=_.useCallback((j,M,L)=>{const E=e.current.updateMessages(j,M,L);E.displayChanged&&E.newMessages&&r(E.newMessages)},[]),O=_.useCallback((j,M,L)=>{e.current.updateMessages(j,M,L).displayChanged&&l.current===null&&(l.current=requestAnimationFrame(()=>{l.current=null;const B=e.current.getMessages(j);B&&e.current.currentConvKey===j&&r([...B])}))},[]),m=_.useCallback((j,M,L)=>{const E=e.current.appendActivity(j,M,L);E.displayChanged&&E.newActivities&&o(E.newActivities)},[]),x=_.useCallback(j=>e.current.getPhase(j),[]),y=_.useCallback(j=>e.current.beginLoad(j),[]),w=_.useCallback(j=>{e.current.beginStream(j),_c(j)&&sr.markAgentStreaming(j,!0)},[]),C=_.useCallback(j=>{e.current.endStream(j)},[]),P=_.useCallback((j,M)=>{const L=e.current.abortStream(j,M);L&&_c(j)&&sr.markAgentStreaming(j,!1),L&&d(),e.current.currentConvKey===j&&(n(!1),o([]))},[d]),S=_.useCallback((j,M)=>{e.current.resetConv(j,M),e.current.deleteBuffer(j)},[]),T=_.useCallback(async(j,M,L)=>{e.current.loadingSession=j,e.current.beginLoad(M);try{const E=await L(),B=e.current.applyLoadResult(M,j,E.messages);return B.displayChanged&&B.newMessages&&r(B.newMessages),{count:E.messages.length,hasMore:E.hasMore,oldestCursor:E.oldestCursor}}catch{return e.current.currentConvKey===M&&e.current.getPhase(M)!=="streaming"&&(r([]),e.current.completeLoad(M)),{count:0,hasMore:!1,oldestCursor:null}}},[]);return{manager:e.current,messages:t,setMessages:r,sending:i,setSending:n,activities:a,setActivities:o,get msgBuffers(){return e.current.msgBuffers},get sessionMsgCache(){return e.current.sessionMsgCache},get activeSessionBuffer(){return e.current.activeSession},get actBuffers(){return e.current.actBuffers},get sessionTabsBuffer(){return e.current.sessionTabs},get currentConvKeyRef(){return{get current(){return e.current.currentConvKey},set current(j){e.current.currentConvKey=j}}},get loadingSessionRef(){return{get current(){return e.current.loadingSession},set current(j){e.current.loadingSession=j}}},updateConvMsgs:g,updateConvMsgsRaf:O,appendConvActivity:m,getPhase:x,beginLoad:y,beginStream:w,endStream:C,resetConv:S,abortStream:P,loadAndDisplay:T,setActiveSession:b,clearActiveSession:v,incrementSending:j=>e.current.incrementSend(j),decrementSending:j=>e.current.decrementSend(j),resetSending:j=>e.current.resetSend(j),isSendingFor:j=>e.current.isSending(j),setStreamSession:f,clearStreamSession:p,getStreamSession:u,saveSessionToCache:(j,M)=>e.current.saveToCache(j,M),restoreSessionFromCache:(j,M)=>{const L=e.current.restoreFromCache(j,M);return r(L??[]),L},isSessionCacheFresherThanDb:(j,M)=>e.current.isCacheFresher(j,M)}}function Z4(s){const e=_.useRef(null),t=_.useRef(null),r=_.useRef(new Map),i=_.useRef(new Set),n=_.useRef(null),a=_.useRef(new Map),o=_.useRef(0),{stateRef:l}=s,{msgBuffers:h,actBuffers:d,sessionMsgCache:u,activeSessionBuffer:f,currentConvKeyRef:p,updateConvMsgs:b,updateConvMsgsRaf:v,appendConvActivity:g,beginStream:O,endStream:m,abortStream:x,clearStreamSession:y,setStreamSession:w,getStreamSession:C,setActiveSession:P,incrementSending:S,decrementSending:T,loadAndDisplay:j,thinkingTimeoutRef:M,sessionSwitchSeqRef:L,oldestMsgId:E,setSending:B,setActivities:U,setInput:Z,setChatContext:I,setPendingImages:ie,setMentionDropdown:Q,setChatReplyTo:W,setActiveSessionId:A,setStoredActiveSession:X,setOpenSessionTabs:Y,setSessions:se,setLoadingChat:ee,setHasMore:me,setThinkingAgents:V,makeConvKey:N,makeDmChannel:ne,addRecentMsgId:H,resumeChatScrollFollow:te,loadSessions:J}=s,{t:ge}=s,Qe=_.useCallback(async(Ae,ke)=>{const oe=L.current,dt=p.current===ke&&(h.get(ke)?.length??0)===0;dt&&ee(!0);try{const{count:Ge,hasMore:Ke,oldestCursor:Ot}=await j(Ae,ke,async()=>{const rt=await re.sessions.getMessages(Ae,50);return{messages:nk(rt.messages.map(ef).filter($e=>$e.sender!=="agent"||$e.text||$e.segments&&$e.segments.length>0||$e.isStreaming)),hasMore:rt.hasMore,oldestCursor:rt.messages[0]?new Date(rt.messages[0].createdAt).toISOString():null}});return me(Ke),E.current=Ot,Ge}finally{dt&&p.current===ke&&L.current===oe&&ee(!1)}},[j,h,L]),_e=()=>{const Ae=l.current.chatMode==="direct"?l.current.selectedAgent:null;if(Ae){const ke=l.current.activeSessionId,oe=ke&&ke!==pt?{sessionId:ke}:void 0;re.agents.cancelProcessing(Ae,oe).catch(()=>{})}e.current?.abort(),e.current=null,t.current?.abort(),t.current=null,Ae&&l.current.activeSessionId&&l.current.activeSessionId!==pt&&i.current.add(l.current.activeSessionId),x(p.current,l.current.activeSessionId)},pe=_.useCallback(async(Ae,ke,oe)=>{if(!Ae||!ke||ke===pt||i.current.has(ke))return;let dt=null;try{if(e.current&&!e.current.signal.aborted&&C(oe)?.has(ke)){p.current===oe&&B(!0);return}const Ge=()=>{const Me=C(oe);Me&&Me.size>0||(y(oe,ke),p.current===oe&&(B(!1),b(oe,Ne=>Xg(Ne),ke)))},Ke=`${Ae}:${ke}`,Ot=r.current.get(Ke)??0;if(Date.now()-Ot<1500){Ge();return}r.current.set(Ke,Date.now());const rt=await re.sessions.streamStatus(Ae,ke),qt=h.get(oe)??[],$e=ok(qt),ut=rt.status==="streaming",as=!!rt.active&&(rt.status==="done"||rt.status==="error")&&!!$e?.isStreaming;if(!ut&&!as){Ge();return}r.current.set(Ke,Date.now()),t.current?.abort(),dt=new AbortController,t.current=dt,O(oe),B(!0),w(oe,ke);let mt=$e?.id;if(!$e||$e.isError)mt=`reattach_${Date.now()}`,b(oe,Me=>[...Me,{id:mt,sender:"agent",text:"",time:new Date().toLocaleTimeString(),isStreaming:!0,segments:[]}],ke);else{const Me=($e.segments??[]).filter(Ne=>Ne.type==="tool").map(Ne=>Ne.status==="stopped"||Ne.status==="running"?{...Ne,status:"running"}:Ne);b(oe,Ne=>Ne.map(Ce=>Ce.id===$e.id?{...Ce,text:"",isStreaming:!0,isStopped:!1,segments:Me,committedSegments:void 0}:Ce),ke)}const wt=Me=>{p.current===oe&&(o.current=Date.now(),v(oe,Ne=>{const Ce=[...Ne],Ve=mt?Ce.findIndex(fe=>fe.id===mt):-1,G=Ve>=0?Ve:Ce.map((fe,Pe)=>({m:fe,j:Pe})).reverse().find(fe=>fe.m.sender==="agent"&&fe.m.isStreaming)?.j??-1;if(G<0)return Ne;const K=Ce[G];return Ce[G]={...K,text:(K.text??"")+Me,segments:zg(K.segments??[],Me),isStreaming:!0},Ce},ke))},De=Me=>{p.current===oe&&(o.current=Date.now(),v(oe,Ne=>{const Ce=[...Ne],Ve=mt?Ce.findIndex(fe=>fe.id===mt):-1,G=Ve>=0?Ve:Ce.map((fe,Pe)=>({m:fe,j:Pe})).reverse().find(fe=>fe.m.sender==="agent"&&fe.m.isStreaming)?.j??-1;if(G<0)return Ne;const K=Ce[G];return Ce[G]={...K,segments:qg(K.segments??[],Me),isStreaming:!0},Ce},ke))},Nt=Me=>{if(p.current===oe&&(o.current=Date.now(),Me.phase!=="heartbeat")){if((Me.phase==="start"||Me.phase==="end")&&g(oe,{...Me,phase:Me.phase,ts:Date.now()},ke),Me.phase==="start"){const Ne=`${Me.tool}_${Date.now()}`,Ce=new Date().toISOString(),Ve=G=>{const K=[...G];for(let fe=K.length-1;fe>=0;fe--){const Pe=K[fe];if(Pe.type==="tool"&&Pe.tool===Me.tool&&(Pe.status==="running"||Pe.status==="stopped"))return K[fe]={...Pe,status:"running",args:Me.arguments??Pe.args},K}return K.push({type:"tool",key:Ne,tool:Me.tool,status:"running",args:Me.arguments,createdAt:Ce}),K};b(oe,G=>{const K=[...G],fe=mt?K.findIndex(ae=>ae.id===mt):-1;if(fe<0)return G;const Pe=Ve(K[fe].segments??[]),ze=K[fe].committedSegments,xt=ze&&Ve(ze);return K[fe]={...K[fe],segments:Pe,committedSegments:xt,isStreaming:!0},K},ke)}else if(Me.phase==="end"){const Ne=new Date().toISOString(),Ce=Ve=>{const G=[...Ve];for(let K=G.length-1;K>=0;K--){const fe=G[K];if(fe.type==="tool"&&fe.tool===Me.tool&&(fe.status==="running"||fe.status==="stopped")){G[K]={...fe,status:Me.success===!1?"error":"done",args:Me.arguments??fe.args,result:Me.result,error:Me.error,durationMs:Me.durationMs,liveOutput:void 0,createdAt:Ne};break}}return G};b(oe,Ve=>{const G=[...Ve],K=mt?G.findIndex(xt=>xt.id===mt):-1;if(K<0)return Ve;const fe=Ce(G[K].segments??[]),Pe=G[K].committedSegments,ze=Pe&&Ce(Pe);return G[K]={...G[K],segments:fe,committedSegments:ze,isStreaming:!0},G},ke)}else if(Me.phase==="subagent_progress"&&Me.subagentEvent){const Ne=Ce=>{const Ve=[...Ce];for(let G=Ve.length-1;G>=0;G--){const K=Ve[G];if(K.type==="tool"&&(K.tool==="spawn_subagent"||K.tool==="spawn_subagents")&&(K.status==="running"||K.status==="stopped")){Ve[G]={...K,status:"running",subagentLogs:Zg(K.subagentLogs,Me.subagentEvent)};break}}return Ve};v(oe,Ce=>{const Ve=[...Ce],G=mt?Ve.findIndex(ze=>ze.id===mt):-1;if(G<0)return Ce;const K=Ne(Ve[G].segments??[]),fe=Ve[G].committedSegments,Pe=fe&&Ne(fe);return Ve[G]={...Ve[G],segments:K,committedSegments:Pe,isStreaming:!0},Ve},ke)}}},et=Me=>{p.current===oe&&(o.current=Date.now(),b(oe,Ne=>{const Ce=[...Ne],Ve=mt?Ce.findIndex(K=>K.id===mt):-1;if(Ve<0)return Ne;const G=[...Ce[Ve].committedSegments??[]];if(Me.type==="thinking_commit")G.push({type:"text",content:"",thinking:Me.content,createdAt:Me.createdAt});else if(Me.type==="text_commit")G.push({type:"text",content:Me.content,createdAt:Me.createdAt});else return Ne;return Ce[Ve]={...Ce[Ve],committedSegments:G,isStreaming:!0},Ce},ke))},ct=Me=>{if(p.current!==oe)return;o.current=Date.now();const Ne=(Me.segments??[]).map((Ce,Ve)=>Ce.type==="tool"?{type:"tool",key:`${Ce.tool}_${Ve}`,tool:Ce.tool??"tool",status:Ce.status==="error"?"error":Ce.status==="running"||Ce.status==="stopped"?"running":"done",args:Ce.arguments,result:Ce.result,error:Ce.error,durationMs:Ce.durationMs,createdAt:Ce.createdAt,...Ce.subagentLogs?.length?{subagentLogs:Ce.subagentLogs}:{}}:{type:"text",content:Ce.content??"",thinking:Ce.thinking,createdAt:Ce.createdAt});b(oe,Ce=>{const Ve=[...Ce],G=mt?Ve.findIndex(K=>K.id===mt):-1;return G<0?Ce:(Ve[G]={...Ve[G],text:Me.content||Ve[G].text,segments:Ne,committedSegments:Ne,isStreaming:!0,isStopped:!1},Ve)},ke);for(const Ce of Ne)Ce.type==="tool"&&g(oe,{tool:Ce.tool,phase:Ce.status==="running"||Ce.status==="stopped"?"start":"end",success:Ce.status!=="error",arguments:Ce.args,result:Ce.result,error:Ce.error,durationMs:Ce.durationMs,ts:Date.now()},ke)},kt=await re.sessions.reattachStream(Ae,ke,{onChunk:wt,onThinking:De,onActivity:Nt,onCommit:et,onSnapshot:ct},dt.signal,0);if(!kt.attached){m(oe),y(oe,ke),p.current===oe&&(b(oe,Me=>{const Ne=[...Me],Ce=mt?Ne.findIndex(K=>K.id===mt):-1,Ve=Ce>=0?Ce:Ne.map((K,fe)=>({m:K,j:fe})).reverse().find(K=>K.m.sender==="agent"&&K.m.isStreaming)?.j??-1;if(Ve<0)return Me;const G=Ne[Ve];return G.isStreaming?(Ne[Ve]={...G,isStreaming:!1,isStopped:G.isError?G.isStopped:!0},Ne):Me},ke),B(!1));return}p.current===oe&&(b(oe,Me=>{const Ne=[...Me],Ce=mt?Ne.findIndex(fe=>fe.id===mt):-1,Ve=Ce>=0?Ce:Ne.map((fe,Pe)=>({m:fe,j:Pe})).reverse().find(fe=>fe.m.sender==="agent"&&fe.m.isStreaming)?.j??-1;if(Ve<0)return Me;const G=Ne[Ve];if(!G.isStreaming)return Me;const K=kt.segments?.length?Vg(kt.segments,G.segments):void 0;return Ne[Ve]={...G,text:kt.content||G.text,isStreaming:!1,isStopped:!1,...K?{segments:K,committedSegments:K}:{}},Ne},ke),B(!1)),m(oe),y(oe,ke),t.current===dt&&(t.current=null)}catch(Ge){const Ke=t.current===dt;if(Ke&&(t.current=null),m(oe),y(oe,ke),p.current===oe&&(B(!1),Ke&&b(oe,Ot=>Xg(Ot),ke)),Ge instanceof Error&&Ge.name==="AbortError")return}},[g,O,m,C,h,w,b,v]),be=_.useCallback(async(Ae,ke)=>{const oe=l.current,dt=!Ae&&oe.chatContext.length>0?oe.chatContext.map(wt=>wt.content).join(`
75
+ `)+"\nPlease review each change and update your files if appropriate. You can use the `update_file` tool or ask me to apply the changes.";yr.navigate(Gt.TEAM,{agentId:s,prefillMessage:Q})},M=async Z=>{if(y?.file===Z){w(null);return}try{const I=await re.agents.roleDiff(s,Z);I.agentContent!=null&&I.templateContent!=null&&w({file:Z,agent:I.agentContent,template:I.templateContent})}catch{}};if(i)return c.jsx("div",{className:"text-xs text-fg-tertiary py-8 text-center",children:e("agent:profilePage.filesTab.loading")});const L={"ROLE.md":"roleMd","HEARTBEAT.md":"heartbeatMd","POLICIES.md":"policiesMd","CONTEXT.md":"contextMd"},E=Z=>{const I=L[Z];return I?e(`agent:profilePage.filesTab.fileLabels.${I}`):Z},B=m?.hasTemplate&&!m.isUpToDate,U=a?T.some(Z=>Z.file===a):!1;return c.jsxs("div",{className:"space-y-4",children:[B&&c.jsxs("div",{className:"bg-amber-500/8 border border-amber-500/25 rounded-xl p-4 flex items-start gap-3",children:[c.jsx("span",{className:"text-amber-600 text-sm mt-0.5",children:"↻"}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsx("div",{className:"text-xs text-amber-600 font-medium",children:e("agent:profilePage.filesTab.templateUpdateAvailable")}),c.jsxs("div",{className:"text-[11px] text-amber-600/70 mt-0.5",children:[e("agent:profilePage.filesTab.filesDiffer",{count:T.length,templateId:m.templateId})," ",T.map(Z=>Z.file).join(", ")]})]}),c.jsx("button",{onClick:()=>j(),className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 text-white rounded-lg transition-colors shrink-0",children:e("agent:profilePage.filesTab.sendToAgent")})]}),c.jsxs(fs,{title:e("agent:profilePage.filesTab.agentConfigFiles"),action:m?.hasTemplate?c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:`inline-block w-1.5 h-1.5 rounded-full ${m.isUpToDate?"bg-green-400":"bg-amber-400"}`}),c.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:[e("agent:profilePage.filesTab.templateLabel")," ",c.jsx("span",{className:"text-fg-secondary",children:m.templateId}),m.isUpToDate?e("agent:profilePage.filesTab.upToDate"):e("agent:profilePage.filesTab.updatesAvailable")]})]}):c.jsx("div",{className:"text-[10px] text-fg-tertiary",children:e("agent:profilePage.filesTab.customAgentNoTemplate")}),children:[c.jsx("div",{className:"flex gap-2 mb-4 flex-wrap",children:t.map(Z=>{const I=T.some(ie=>ie.file===Z.name);return c.jsxs("button",{onClick:()=>P(Z.name),className:`px-3 py-1.5 text-xs rounded-lg border transition-colors relative ${a===Z.name?"bg-brand-600/15 border-brand-500/40 text-brand-500":"border-border-default text-fg-tertiary hover:text-fg-secondary"}`,children:[Z.name,I&&c.jsx("span",{className:"absolute -top-1 -right-1 w-2 h-2 bg-amber-400 rounded-full"})]},Z.name)})}),a&&c.jsxs("div",{children:[c.jsxs("div",{className:"flex items-center justify-between mb-1",children:[c.jsx("div",{className:"text-xs text-fg-secondary",children:E(a)}),c.jsxs("div",{className:"flex gap-2 items-center",children:[U&&c.jsxs(c.Fragment,{children:[c.jsx("button",{onClick:()=>M(a),className:"px-2.5 py-1 text-[11px] text-amber-600 hover:text-amber-600 border border-amber-500/30 hover:border-amber-500/50 rounded-lg transition-colors",children:y?.file===a?e("agent:profilePage.filesTab.hideDiff"):e("agent:profilePage.filesTab.viewDiff")}),c.jsx("button",{onClick:()=>j(a),className:"px-2.5 py-1 text-[11px] bg-brand-600 hover:bg-brand-500 text-white rounded-lg transition-colors",title:e("agent:profilePage.filesTab.sendToAgentTitle"),children:e("agent:profilePage.filesTab.sendToAgent")})]}),b&&c.jsx("span",{className:"text-[10px] text-fg-tertiary",children:e("common:saving")})]})]}),d&&c.jsxs("div",{className:"flex items-center gap-2 mb-3 bg-surface-elevated/40 rounded-lg px-3 py-2",children:[c.jsxs("code",{className:"text-[10px] text-fg-tertiary font-mono flex-1 truncate select-all",title:`${d}/${a}`,children:[d,"/",a]}),c.jsx("button",{onClick:()=>{navigator.clipboard.writeText(`${d}/${a}`),p(!0),setTimeout(()=>p(!1),2e3)},className:"shrink-0 px-2 py-1 text-[10px] text-fg-tertiary hover:text-fg-secondary border border-border-default hover:border-border-hover rounded-md transition-colors",title:e("agent:profilePage.filesTab.copyPath"),children:e(f?"agent:profilePage.filesTab.pathCopied":"agent:profilePage.filesTab.copyPath")}),c.jsx("button",{onClick:()=>{re.system.openPath(d)},className:"shrink-0 px-2 py-1 text-[10px] text-fg-tertiary hover:text-fg-secondary border border-border-default hover:border-border-hover rounded-md transition-colors",title:e("agent:profilePage.filesTab.openInFinder"),children:e("agent:profilePage.filesTab.openInFinder")})]}),y?.file===a&&c.jsx(v4,{agent:y.agent,template:y.template,templateId:m?.templateId??""}),c.jsx(_4,{content:t.find(Z=>Z.name===a)?.content??"",editContent:l,setEditContent:Z=>{h(Z),O(!0)},dirty:g,onSave:S}),a==="ROLE.md"&&c.jsx("div",{className:"text-[10px] text-fg-tertiary mt-2",children:e("agent:profilePage.filesTab.roleMdHint")})]}),t.length===0&&c.jsx(wh,{text:e("agent:profilePage.filesTab.noConfigFiles")})]})]})}function _4({content:s,editContent:e,setEditContent:t,dirty:r,onSave:i}){const[n,a]=_.useState(!1),o=_.useRef(null);return _.useEffect(()=>{n&&o.current?.focus()},[n]),_.useEffect(()=>{a(!1)},[s]),n||r?c.jsx("textarea",{ref:o,value:e,onChange:l=>t(l.target.value),onBlur:()=>{e!==s&&i(),a(!1)},onKeyDown:l=>{l.key==="Escape"&&(l.preventDefault(),t(s),a(!1))},className:"w-full min-h-[60vh] bg-surface-elevated/60 border border-border-default rounded-lg p-4 text-xs font-mono text-fg-secondary leading-relaxed resize-y focus:border-brand-500 outline-none",spellCheck:!1}):c.jsxs("div",{className:"group relative cursor-pointer rounded-lg px-4 py-3 bg-surface-elevated hover:bg-surface-overlay transition-colors min-h-[200px]",onClick:()=>a(!0),role:"button",tabIndex:0,onKeyDown:l=>{l.key==="Enter"&&a(!0)},children:[c.jsx("div",{className:"absolute top-2 right-2 opacity-0 group-hover:opacity-100 transition-opacity text-[10px] text-fg-tertiary bg-surface-secondary/80 px-2 py-0.5 rounded",children:"Click to edit"}),e.trim()?c.jsx(_.Suspense,{fallback:c.jsx("div",{className:"text-xs text-fg-tertiary",children:"Loading…"}),children:c.jsx(g4,{content:e,className:"text-sm text-fg-secondary leading-relaxed"})}):c.jsx("div",{className:"text-sm text-fg-tertiary italic py-4 text-center",children:"Empty"})]})}function w4(s){return s.replace(/^\[MCP:[^\]]*\]\s*/i,"")}function k4({tools:s}){const{t:e}=Qt(["agent","common"]),t=f4(s,e);return c.jsxs("div",{className:"space-y-4",children:[c.jsx("div",{className:"text-xs text-fg-tertiary",children:e("agent:profilePage.toolsTab.registeredCount",{count:s.length})}),t.map(r=>c.jsx(fs,{title:`${r.category} (${r.tools.length})`,children:c.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-2",children:r.tools.map(i=>{const n=rk(i.name),a=e(`common:execution.tools.${n.key}`,{defaultValue:n.label}),o=i.name.includes("__"),l=o?i.name.split("__").pop():i.name,h=w4(i.description||"");return c.jsxs("div",{className:"flex items-start gap-2.5 px-3 py-2.5 rounded-lg bg-surface-elevated min-w-0",children:[c.jsx(ik,{name:n.iconName,size:15,className:"shrink-0 mt-0.5 text-fg-secondary"}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[c.jsx("span",{className:"text-xs font-medium text-fg-primary truncate",children:a}),o&&c.jsx("span",{className:"text-[9px] px-1 py-px rounded bg-surface-secondary text-fg-tertiary border border-border-default/40 shrink-0",children:"MCP"})]}),l!==a&&c.jsx("div",{className:"text-[10px] font-mono text-fg-tertiary/70 truncate",children:l}),h&&c.jsx("div",{className:"text-[10px] text-fg-tertiary truncate mt-0.5",title:h,children:h})]})]},i.name)})})},r.category)),s.length===0&&c.jsx("div",{className:"text-center py-12 text-fg-tertiary text-sm",children:e("agent:profilePage.toolsTab.noToolsRegistered")})]})}function C4({agent:s}){const{t:e}=Qt(["agent","common"]),t=s.proficiency??{},[r,i]=_.useState(null),[n,a]=_.useState(null),[o,l]=_.useState(!1),h=s.availableSkills??[],d=new Map;for(const g of h){const O=g.category||"custom";d.has(O)||d.set(O,[]),d.get(O).push(g)}const u=async g=>{if(r===g){i(null),a(null);return}i(g),l(!0);try{const O=await fetch(`/api/skills/${encodeURIComponent(g)}`);if(O.ok){const m=await O.json();a(m.skill)}else a(null)}catch{a(null)}l(!1)},f={development:"bg-blue-500/15 text-blue-600",devops:"bg-amber-500/15 text-amber-600",communication:"bg-green-500/15 text-green-600",data:"bg-brand-500/15 text-brand-500",productivity:"bg-amber-500/15 text-amber-600",browser:"bg-blue-500/15 text-blue-600",custom:"bg-gray-500/15 text-fg-secondary",platform:"bg-purple-500/15 text-purple-500"},p=g=>{const O=t[g.name],m=O&&O.uses>0?Math.round(O.successes/O.uses*100):null,x=O&&c.jsxs("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:[e("agent:profilePage.skillsTab.usesStats",{uses:O.uses,successes:O.successes}),O.lastUsed&&e("agent:profilePage.skillsTab.lastUsed",{date:new Date(O.lastUsed).toLocaleDateString()})]}),y=r===g.name;return c.jsxs("div",{children:[c.jsxs("div",{className:`flex items-center gap-3 px-4 py-2.5 rounded-lg border cursor-pointer transition-all ${y?"bg-brand-500/10 border-brand-500/40":"bg-surface-elevated/30 border-border-default/30 hover:border-gray-600/50"}`,onClick:()=>u(g.name),children:[c.jsx("span",{className:`text-sm transition-transform ${y?"rotate-90":""}`,children:"▶"}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-sm font-medium",children:g.name}),g.alwaysOn&&c.jsx("span",{className:"px-1.5 py-0.5 rounded text-[9px] font-medium bg-green-500/15 text-green-500",children:e("agent:profilePage.skillsTab.alwaysOn")}),g.builtIn&&!g.alwaysOn&&c.jsx("span",{className:"px-1.5 py-0.5 rounded text-[9px] font-medium bg-surface-overlay/40 text-fg-tertiary",children:e("agent:profilePage.skillsTab.builtIn")}),!g.builtIn&&c.jsx("span",{className:"px-1.5 py-0.5 rounded text-[9px] font-medium bg-brand-500/15 text-brand-400",children:e("agent:profilePage.skillsTab.installed")})]}),c.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5 truncate",children:g.description}),x]}),m!==null&&c.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[c.jsx("div",{className:"w-16 h-1.5 bg-surface-overlay rounded-full overflow-hidden",children:c.jsx("div",{className:`h-full rounded-full ${m>=80?"bg-green-400":m>=50?"bg-amber-400":"bg-red-400"}`,style:{width:`${m}%`}})}),c.jsxs("span",{className:"text-[10px] text-fg-tertiary w-8 text-right",children:[m,"%"]})]})]}),y&&c.jsx("div",{className:"ml-6 mt-1 mb-2 p-4 bg-surface-elevated/30 rounded-lg border border-border-default/20 space-y-3",children:o?c.jsx("div",{className:"text-[10px] text-fg-tertiary py-3 text-center",children:e("agent:profilePage.skillsTab.loadingDetails")}):n?c.jsxs(c.Fragment,{children:[c.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[c.jsx("span",{className:`px-2 py-0.5 rounded text-[10px] font-medium ${f[n.category]??f.custom}`,children:n.category}),c.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:["v",n.version]}),n.author&&c.jsx("span",{className:"text-[10px] text-fg-tertiary",children:e("agent:profilePage.skillsTab.byAuthor",{author:n.author})}),n.requiredPermissions?.map(w=>c.jsx("span",{className:"px-1.5 py-0.5 bg-amber-500/10 text-amber-600 text-[10px] rounded",children:w},w))]}),n.description&&c.jsx("p",{className:"text-xs text-fg-secondary leading-relaxed",children:n.description}),n.tags&&n.tags.length>0&&c.jsx("div",{className:"flex gap-1 flex-wrap",children:n.tags.map(w=>c.jsxs("span",{className:"px-1.5 py-0.5 bg-surface-overlay/40 text-fg-tertiary text-[10px] rounded",children:["#",w]},w))}),(n.toolDetails??n.tools??[]).length>0&&c.jsxs("div",{children:[c.jsx("div",{className:"text-[10px] text-fg-tertiary font-semibold uppercase tracking-wider mb-2",children:e("agent:profilePage.skillsTab.toolsHeading",{count:(n.toolDetails??n.tools??[]).length})}),c.jsx("div",{className:"space-y-1.5",children:(n.toolDetails??n.tools??[]).map(w=>c.jsxs("div",{className:"px-3 py-2 bg-surface-secondary/50 rounded border border-border-default/20",children:[c.jsx("div",{className:"text-xs font-medium text-brand-500",children:w.name}),w.description&&c.jsx("div",{className:"text-[10px] text-fg-tertiary mt-0.5",children:w.description})]},w.name))})]})]}):c.jsx("div",{className:"text-[10px] text-fg-tertiary py-3 text-center",children:e("agent:profilePage.skillsTab.detailsUnavailable")})})]},g.name)},b=["development","productivity","browser","communication","devops","data","platform","custom"],v=[...d.entries()].sort((g,O)=>{const m=b.indexOf(g[0]),x=b.indexOf(O[0]);return(m===-1?999:m)-(x===-1?999:x)});return c.jsxs("div",{className:"space-y-4",children:[c.jsx("div",{className:"flex items-center justify-between",children:c.jsx("div",{className:"text-xs text-fg-tertiary",children:e("agent:profilePage.skillsTab.installedCount",{count:h.length})})}),v.map(([g,O])=>c.jsx(fs,{title:c.jsxs("span",{className:"capitalize",children:[g," ",c.jsxs("span",{className:"text-fg-tertiary font-normal",children:["(",O.length,")"]})]}),children:c.jsx("div",{className:"space-y-2",children:O.map(m=>p(m))})},g)),h.length===0&&c.jsx(wh,{text:e("agent:profilePage.skillsTab.noSkills")})]})}function P4({tools:s,agent:e}){const{t}=Qt(["agent","common"]),[r,i]=_.useState("tools");return c.jsxs("div",{className:"space-y-4",children:[c.jsx("div",{className:"flex items-center gap-2 mb-2",children:["tools","skills"].map(n=>c.jsx("button",{onClick:()=>i(n),className:`px-3 py-1.5 text-xs rounded-lg border transition-colors ${r===n?"bg-brand-600/15 border-brand-500/40 text-brand-500":"border-border-default text-fg-tertiary hover:text-fg-secondary"}`,children:n==="tools"?`${t("agent:profilePage.toolsTab.title",{defaultValue:"Tools"})} (${s.length})`:`${t("agent:tabs.skills")} (${e.availableSkills?.length??0})`},n))}),r==="tools"?c.jsx(k4,{tools:s}):c.jsx(C4,{agent:e})]})}function T4({agentId:s}){const{t:e}=Qt(["agent","common"]),[t,r]=_.useState(null),[i,n]=_.useState(!0),[a,o]=_.useState("longterm"),[l,h]=_.useState(""),[d,u]=_.useState(""),[f,p]=_.useState(!1),[b,v]=_.useState(null),[g,O]=_.useState(null),[m,x]=_.useState([]),[y,w]=_.useState(!1),C=_.useCallback(()=>{n(!0),re.agents.getMemory(s).then(L=>{r(L),h(L.recentDailyLogs??""),u(L.longTermMemory??"")}).catch(()=>{}).finally(()=>n(!1))},[s]);_.useEffect(()=>{C()},[C]);const P=async()=>{p(!0),await re.agents.updateDailyMemory(s,l).catch(()=>{}),p(!1),C()},S=async()=>{p(!0),await re.agents.updateLongTermMemory(s,e("agent:profilePage.memoryTab.userEditedSource"),d).catch(()=>{}),p(!1),C()},T=l!==(t?.recentDailyLogs??""),j=d!==(t?.longTermMemory??"");if(i)return c.jsx("div",{className:"text-xs text-fg-tertiary py-8 text-center",children:e("agent:profilePage.memoryTab.loading")});if(!t)return c.jsx("div",{className:"text-xs text-fg-tertiary py-8 text-center",children:e("agent:profilePage.memoryTab.loadFailed")});const M=[{key:"longterm",label:"MEMORY.md"},{key:"entries",label:`Observations (${t.entries.length})`},{key:"sessions",label:e("agent:profilePage.memoryTab.sessions",{count:t.sessions.length})},{key:"daily",label:e("agent:profilePage.memoryTab.dailyLogs")}];return c.jsxs("div",{className:"space-y-4",children:[c.jsx("div",{className:"flex gap-2",children:M.map(L=>c.jsx("button",{onClick:()=>o(L.key),className:`px-3 py-1.5 text-xs rounded-lg border transition-colors ${a===L.key?"bg-brand-600/15 border-brand-500/40 text-brand-500":"border-border-default text-fg-tertiary hover:text-fg-secondary"}`,children:L.label},L.key))}),a==="entries"&&c.jsx(fs,{title:e("agent:profilePage.memoryTab.recentEntries"),children:t.entries.length===0?c.jsx(wh,{text:e("agent:profilePage.memoryTab.noEntries")}):c.jsx("div",{className:"space-y-1.5 max-h-[600px] overflow-y-auto",children:t.entries.map((L,E)=>{const B=b===E;return c.jsxs("div",{children:[c.jsxs("button",{onClick:()=>v(B?null:E),className:"w-full flex gap-2 px-3 py-2 rounded-lg bg-surface-elevated/20 text-xs text-left hover:bg-surface-elevated/40 transition-colors cursor-pointer",children:[c.jsx("span",{className:`px-1.5 py-0.5 rounded text-[10px] font-medium shrink-0 ${L.type==="fact"?"bg-blue-500/15 text-blue-600":L.type==="task"?"bg-green-500/15 text-green-600":L.type==="note"?"bg-brand-500/15 text-brand-500":"bg-surface-overlay text-fg-secondary"}`,children:L.type}),c.jsx("span",{className:`text-fg-secondary flex-1 min-w-0 ${B?"":"line-clamp-2"}`,children:L.content}),c.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[L.importance!=null&&c.jsxs("span",{className:`px-1 py-0.5 rounded text-[9px] font-medium ${L.importance>=7?"bg-red-500/15 text-red-500":L.importance>=4?"bg-amber-500/15 text-amber-600":"bg-surface-overlay text-fg-tertiary"}`,children:["P",L.importance]}),c.jsx("span",{className:"text-fg-tertiary text-[10px]",children:new Date(L.timestamp).toLocaleTimeString()}),c.jsx("span",{className:"text-fg-tertiary text-[10px]",children:B?"▲":"▼"})]})]}),B&&c.jsxs("div",{className:"mx-3 mt-1 mb-2 p-3 bg-surface-elevated/30 rounded-lg border border-border-default/20",children:[c.jsx("pre",{className:"text-xs text-fg-secondary whitespace-pre-wrap font-mono leading-relaxed break-words",children:L.content}),c.jsxs("div",{className:"flex gap-3 mt-2 pt-2 border-t border-border-default/30 text-[10px] text-fg-tertiary",children:[c.jsxs("span",{children:[e("agent:profilePage.overview.labels.type"),": ",L.type]}),L.importance!=null&&c.jsxs("span",{children:[e("agent:profilePage.overview.labels.importance"),": ",L.importance]}),c.jsx("span",{children:new Date(L.timestamp).toLocaleString()})]})]})]},E)})})}),a==="sessions"&&c.jsx(fs,{title:e("agent:profilePage.memoryTab.chatSessions"),children:t.sessions.length===0?c.jsx(wh,{text:e("agent:profilePage.memoryTab.noSessions")}):c.jsx("div",{className:"space-y-1.5 max-h-[600px] overflow-y-auto",children:t.sessions.map(L=>{const E=g===L.id,B=async()=>{if(E){O(null),x([]);return}O(L.id),w(!0);try{const U=await re.agents.getMemorySession(s,L.id);x(U.messages)}catch{x([])}w(!1)};return c.jsxs("div",{children:[c.jsxs("button",{onClick:B,className:"w-full flex items-center gap-3 px-3 py-2.5 rounded-lg bg-surface-elevated/20 hover:bg-surface-elevated/40 transition-colors cursor-pointer text-left",children:[c.jsx("div",{className:"text-xs text-fg-secondary font-mono flex-1 truncate",children:L.id}),c.jsxs("span",{className:"text-[10px] text-fg-tertiary",children:[L.messageCount," ",e("agent:profilePage.memoryTab.msgs")]}),c.jsx("span",{className:"text-[10px] text-fg-tertiary",children:new Date(L.updatedAt).toLocaleDateString()}),c.jsx("span",{className:"text-fg-tertiary text-[10px]",children:E?"▲":"▼"})]}),E&&c.jsx("div",{className:"mx-3 mt-1 mb-2 bg-surface-elevated/30 rounded-lg border border-border-default/20 max-h-96 overflow-y-auto",children:y?c.jsx("div",{className:"text-[10px] text-fg-tertiary py-3 text-center",children:e("agent:profilePage.memoryTab.loadingMessages")}):m.length===0?c.jsx("div",{className:"text-[10px] text-fg-tertiary py-3 text-center",children:e("agent:profilePage.memoryTab.noMessagesInSession")}):(()=>{const U=new Map;for(const Z of m)Z.role==="tool"&&Z.toolCallId&&U.set(Z.toolCallId,Z.content);return c.jsx("div",{className:"divide-y divide-gray-700/30",children:m.filter(Z=>Z.role!=="tool").map((Z,I)=>c.jsxs("div",{className:"px-3 py-2",children:[(Z.role==="user"||Z.role==="system")&&c.jsxs("div",{children:[c.jsx("span",{className:`inline-block px-1.5 py-0.5 rounded text-[10px] font-medium mb-1 ${Z.role==="user"?"bg-blue-500/15 text-blue-600":"bg-surface-overlay text-fg-secondary"}`,children:e(`agent:profilePage.memoryTab.roles.${Z.role}`,{defaultValue:Z.role})}),c.jsx("div",{className:"text-xs text-fg-secondary",children:c.jsx(ja,{content:Z.content,className:"text-xs text-fg-secondary"})})]}),Z.role==="assistant"&&c.jsxs("div",{className:"space-y-1",children:[Z.content&&c.jsxs("div",{children:[c.jsx("span",{className:"inline-block px-1.5 py-0.5 rounded text-[10px] font-medium mb-1 bg-green-500/15 text-green-600",children:e("agent:profilePage.memoryTab.roles.assistant")}),c.jsx("div",{className:"text-xs text-fg-secondary",children:c.jsx(ja,{content:Z.content,className:"text-xs text-fg-secondary"})})]}),Z.toolCalls&&Z.toolCalls.length>0&&c.jsx("div",{className:"space-y-0.5",children:Z.toolCalls.map(ie=>{let Q;try{Q=JSON.parse(ie.arguments)}catch{}const W={tool:ie.name,status:"done",args:Q,result:U.get(ie.id)};return c.jsx(ek,{entry:{type:"tool",info:W}},ie.id)})})]})]},I))})})()})]},L.id)})})}),a==="daily"&&c.jsx(fs,{title:e("agent:profilePage.memoryTab.dailyLogs"),action:T?c.jsxs("div",{className:"flex gap-2",children:[c.jsx("button",{onClick:()=>h(t?.recentDailyLogs??""),className:"text-xs text-fg-tertiary hover:text-fg-secondary",children:e("common:cancel")}),c.jsx("button",{onClick:P,disabled:f,className:"text-xs text-brand-500",children:e(f?"common:saving":"common:save")})]}):null,children:c.jsx("textarea",{value:l,onChange:L=>h(L.target.value),placeholder:e("agent:profilePage.memoryTab.noDailyLogs"),className:"w-full min-h-[50vh] bg-surface-elevated/30 border border-border-default/50 hover:border-border-default focus:border-brand-500 rounded-lg p-4 text-xs font-mono text-fg-secondary leading-relaxed resize-y outline-none transition-colors"})}),a==="longterm"&&c.jsx(fs,{title:e("agent:profilePage.memoryTab.longTermTitle"),action:j?c.jsxs("div",{className:"flex gap-2",children:[c.jsx("button",{onClick:()=>u(t?.longTermMemory??""),className:"text-xs text-fg-tertiary hover:text-fg-secondary",children:e("common:cancel")}),c.jsx("button",{onClick:S,disabled:f,className:"text-xs text-brand-500",children:e(f?"common:saving":"common:save")})]}):null,children:c.jsx("textarea",{value:d,onChange:L=>u(L.target.value),placeholder:e("agent:profilePage.memoryTab.noLongTerm"),className:"w-full min-h-[50vh] bg-surface-elevated/30 border border-border-default/50 hover:border-border-default focus:border-brand-500 rounded-lg p-4 text-xs font-mono text-fg-secondary leading-relaxed resize-y outline-none transition-colors"})})]})}function Q4({agentId:s,initialData:e}){const{t}=Qt(["agent","common"]),[r,i]=_.useState(e??null),[n,a]=_.useState(!e),[o,l]=_.useState([]),[h,d]=_.useState(null),[u,f]=_.useState(!1),[p,b]=_.useState(null),[v,g]=_.useState(null),O=_.useRef(null);_.useEffect(()=>()=>{O.current!==null&&window.clearTimeout(O.current)},[]);const m=_.useCallback(()=>Promise.all([re.agents.getHeartbeat(s).then(i).catch(()=>{}),re.agents.getRecentActivities(s).then(P=>{l(P.activities.filter(S=>S.type==="heartbeat"))}).catch(()=>{})]),[s]);_.useEffect(()=>{a(!0),m().finally(()=>a(!1))},[m]),_.useEffect(()=>bt.on("agent:update",S=>{S.payload?.agentId===s&&m()}),[s,m]);const x=async()=>{f(!0),b(null);try{const P=await re.agents.triggerHeartbeat(s);b(P.message),setTimeout(()=>b(null),4e3),setTimeout(m,2e3)}catch(P){b(String(P).replace("Error: ",""))}f(!1)},y=async P=>{O.current!==null&&window.clearTimeout(O.current),g(null);try{await re.agents.cancelWakeup(s,P),g({kind:"ok",text:t("agent:profilePage.heartbeatTab.cancelWakeupOk")}),O.current=window.setTimeout(()=>g(null),4e3)}catch(S){const T=S instanceof Error?S.message:String(S),j=!T||/no scheduled wakeup|404/i.test(T);g({kind:"error",text:j?t("agent:profilePage.heartbeatTab.cancelWakeupGone"):`${t("agent:profilePage.heartbeatTab.cancelWakeupFailed")}: ${T}`})}m()};if(n)return c.jsx("div",{className:"text-xs text-fg-tertiary py-8 text-center",children:t("agent:profilePage.heartbeatTab.loading")});if(!r)return c.jsx("div",{className:"text-xs text-fg-tertiary py-8 text-center",children:t("agent:profilePage.heartbeatTab.noData")});const w=P=>P?P<1e3?`${P}ms`:P<6e4?`${(P/1e3).toFixed(1)}s`:`${(P/6e4).toFixed(1)}m`:null,C=P=>{if(!P)return null;const S=Date.now()-new Date(P).getTime();if(S<0){const T=Math.abs(S);return T<6e4?t("agent:profilePage.relative.inSeconds",{count:Math.ceil(T/1e3)}):T<36e5?t("agent:profilePage.relative.inMinutes",{count:Math.ceil(T/6e4)}):t("agent:profilePage.relative.inHours",{hours:(T/36e5).toFixed(1)})}return S<6e4?t("agent:profilePage.relative.secondsAgo",{count:Math.floor(S/1e3)}):S<36e5?t("agent:profilePage.relative.minutesAgo",{count:Math.floor(S/6e4)}):t("agent:profilePage.relative.hoursAgo",{hours:(S/36e5).toFixed(1)})};return c.jsxs("div",{className:"space-y-4",children:[c.jsxs(fs,{title:t("agent:profilePage.heartbeatTab.scheduler"),action:c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("button",{onClick:m,className:"text-[10px] text-fg-tertiary hover:text-fg-secondary transition-colors",children:t("common:refresh")}),c.jsx("button",{onClick:x,disabled:u||!r.running,className:"text-[10px] px-2.5 py-1 rounded-md bg-blue-600/20 text-blue-600 hover:bg-blue-600/30 border border-blue-500/30 transition-colors disabled:opacity-40",children:t(u?"agent:profilePage.heartbeatTab.triggering":"agent:profilePage.heartbeatTab.triggerNow")})]}),children:[c.jsxs("div",{className:"grid grid-cols-4 gap-4",children:[c.jsx(Xs,{label:t("agent:profilePage.overview.labels.status"),value:r.running?t("agent:profilePage.heartbeatTab.running"):t("agent:profilePage.heartbeatTab.stopped"),color:r.running?"green":"gray"}),c.jsx(j4,{agentId:s,intervalMs:r.intervalMs,onChanged:m}),c.jsx(Xs,{label:t("agent:profilePage.heartbeatTab.lastRun"),value:r.lastHeartbeat?C(r.lastHeartbeat)??t("agent:profilePage.emDash"):t("agent:profilePage.never")}),c.jsx(Xs,{label:t("agent:profilePage.heartbeatTab.nextWake"),value:r.nextWakeAt?C(r.nextWakeAt)??t("agent:profilePage.emDash"):r.running?t("agent:profilePage.heartbeatTab.pending"):t("agent:profilePage.emDash")})]}),c.jsx("p",{className:"mt-2 text-[10px] text-fg-tertiary leading-relaxed",children:t("agent:profilePage.heartbeatTab.rhythmHint")}),p&&c.jsx("div",{className:"mt-3 text-[11px] text-blue-600 bg-blue-500/10 border border-blue-500/20 rounded-lg px-3 py-2",children:p})]}),v&&c.jsx("div",{className:`text-[11px] rounded-lg px-3 py-2 border ${v.kind==="ok"?"text-green-600 bg-green-500/10 border-green-500/20":"text-red-500 bg-red-500/10 border-red-500/20"}`,children:v.text}),r.wakeups&&r.wakeups.length>0&&c.jsx(fs,{title:t("agent:profilePage.heartbeatTab.wakeupsTitle"),action:c.jsx("span",{className:"text-[10px] text-fg-tertiary",children:t("agent:profilePage.heartbeatTab.wakeupsCount",{count:r.wakeups.length})}),children:c.jsx("div",{className:"divide-y divide-gray-800/50 -mx-5",children:r.wakeups.map(P=>c.jsxs("div",{className:"flex items-center gap-2.5 px-5 py-2.5",children:[c.jsx("span",{className:"text-sm shrink-0 opacity-60",children:"⏰"}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsx("div",{className:"text-xs text-fg-secondary truncate",children:P.note||t("agent:profilePage.heartbeatTab.wakeupNoNote")}),c.jsxs("div",{className:"text-[10px] text-fg-tertiary",children:[C(P.wakeAt)??new Date(P.wakeAt).toLocaleString(),P.recurringMs?` · ${t("agent:profilePage.heartbeatTab.recurring")}`:"",` · ${P.deliveryMode==="in_session"?t("agent:profilePage.heartbeatTab.deliveryInSession"):t("agent:profilePage.heartbeatTab.deliveryMailbox")}`]})]}),c.jsx("button",{onClick:()=>y(P.id),className:"text-[10px] px-2 py-0.5 rounded text-fg-tertiary hover:text-red-500 hover:bg-red-500/10 transition-colors shrink-0",children:t("agent:profilePage.heartbeatTab.cancelWakeup")})]},P.id))})}),r.pendingCallbacks&&r.pendingCallbacks.length>0&&c.jsx(fs,{title:t("agent:profilePage.heartbeatTab.pendingOpsTitle"),action:c.jsx("span",{className:"text-[10px] text-fg-tertiary",children:t("agent:profilePage.heartbeatTab.pendingOpsCount",{count:r.pendingCallbacks.length})}),children:c.jsx("div",{className:"divide-y divide-gray-800/50 -mx-5",children:r.pendingCallbacks.map(P=>c.jsxs("div",{className:"flex items-center gap-2.5 px-5 py-2.5",children:[c.jsx("span",{className:"text-sm shrink-0 opacity-60",children:P.type==="background_exec"?"⚙":"↔"}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsx("div",{className:"text-xs text-fg-secondary truncate font-mono",children:P.label}),c.jsxs("div",{className:"text-[10px] text-fg-tertiary",children:[t(`agent:profilePage.heartbeatTab.callbackType.${P.type}`),` · ${t("agent:profilePage.heartbeatTab.timesOut")} ${C(P.timeoutAt)??new Date(P.timeoutAt).toLocaleString()}`]})]})]},P.id))})}),r.lastSummary&&c.jsx(fs,{title:t("agent:profilePage.heartbeatTab.lastSummary"),action:r.lastSummaryAt?c.jsx("span",{className:"text-[10px] text-fg-tertiary",children:new Date(r.lastSummaryAt).toLocaleString()}):void 0,children:c.jsx("div",{className:"bg-surface-primary/50 rounded-lg px-4 py-3",children:c.jsx(ja,{content:r.lastSummary,className:"text-xs text-fg-secondary leading-relaxed"})})}),o.length>0?c.jsx(fs,{title:t("agent:profilePage.heartbeatTab.recentRuns"),action:c.jsx("span",{className:"text-[10px] text-fg-tertiary",children:t("agent:profilePage.heartbeatTab.runsThisSession",{count:o.length})}),children:c.jsx("div",{className:"divide-y divide-gray-800/50 -mx-5",children:[...o].reverse().map(P=>{const S=h===P.id;return c.jsxs("div",{children:[c.jsxs("button",{onClick:()=>d(S?null:P.id),className:"w-full flex items-center gap-2.5 px-5 py-2.5 text-left transition-colors hover:bg-surface-elevated/40 cursor-pointer",children:[c.jsx("span",{className:"w-2 h-2 rounded-full shrink-0 bg-blue-400"}),c.jsx("span",{className:"text-xs text-fg-secondary flex-1 truncate",children:P.label}),c.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:t("agent:profilePage.heartbeatTab.actionsCount",{count:P.logCount})}),c.jsx("span",{className:"text-[10px] text-fg-tertiary shrink-0",children:new Date(P.startedAt).toLocaleString()}),c.jsx("svg",{className:`w-3 h-3 text-fg-tertiary shrink-0 transition-transform ${S?"rotate-180":""}`,viewBox:"0 0 12 12",fill:"currentColor",children:c.jsx("path",{d:"M3 4.5l3 3 3-3",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})]}),S&&c.jsx("div",{className:"border-t border-border-default/60 bg-surface-primary/40",children:c.jsx(_h,{agentId:s,activityId:P.id})})]},P.id)})})}):r.lastHeartbeat?null:c.jsx(fs,{title:t("agent:profilePage.heartbeatTab.recentRuns"),children:c.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center",children:[c.jsx("div",{className:"text-xl mb-2 opacity-40",children:"♡"}),c.jsx("p",{className:"text-xs text-fg-tertiary",children:t("agent:profilePage.heartbeatTab.noRunsYet")}),c.jsx("p",{className:"text-[10px] text-fg-tertiary mt-1",children:r.running?t("agent:profilePage.heartbeatTab.firstHeartbeatSoon",{when:w(r.intervalMs-r.uptimeMs%r.intervalMs)??t("agent:profilePage.heartbeatTab.soon")}):t("agent:profilePage.heartbeatTab.schedulerStopped")}),r.running&&c.jsx("button",{onClick:x,disabled:u,className:"mt-3 text-[10px] px-3 py-1.5 rounded-md bg-blue-600/15 text-blue-600 hover:bg-blue-600/25 border border-blue-500/25 transition-colors disabled:opacity-40",children:t(u?"agent:profilePage.heartbeatTab.triggering":"agent:profilePage.heartbeatTab.runFirstNow")})]})})]})}function $4({taskId:s,isLive:e}){const{t}=Qt("agent"),[r,i]=_.useState([]),[n,a]=_.useState(""),[o,l]=_.useState(!0),[h,d]=_.useState("compact");if(_.useEffect(()=>{l(!0),a(""),re.tasks.getLogs(s).then(p=>{i(p.logs),l(!1)}).catch(()=>l(!1))},[s]),_.useEffect(()=>{if(!e)return;const p=bt.on("task:log",v=>{const g=v.payload;if(g.taskId!==s)return;const O={id:g.id,taskId:g.taskId,agentId:g.agentId,seq:g.seq,type:g.logType,content:g.content,metadata:g.metadata,createdAt:g.createdAt};i(m=>O.id&&m.some(x=>x.id===O.id)?m:[...m,O]),O.type==="text"&&a("")}),b=bt.on("task:log:delta",v=>{const g=v.payload;g.taskId===s&&a(O=>O+g.text)});return()=>{p(),b()}},[s,e]),o)return c.jsx("div",{className:"px-4 py-3 text-xs text-fg-tertiary",children:t("profilePage.taskLog.loading")});if(r.length===0&&!n)return c.jsx("div",{className:"px-4 py-3 text-xs text-fg-tertiary",children:t("profilePage.taskLog.noLogs")});const u=r.map(p=>sk(p)),f=new Set(u.filter(p=>p.executionRound!=null).map(p=>p.executionRound)).size>1;return c.jsx("div",{className:"px-3 py-2",children:h==="compact"?c.jsx(Vb,{entries:u,streamingText:n,isActive:e,onExpand:()=>d("full"),showRounds:f}):c.jsx(Fb,{entries:u,streamingText:n,isActive:e,onCollapse:()=>d("compact"),showRounds:f})})}function _h({agentId:s,activityId:e,isLive:t=!1}){const{t:r}=Qt("agent"),[i,n]=_.useState([]),[a,o]=_.useState(!0),[l,h]=_.useState("compact");if(_.useEffect(()=>{o(!0),re.agents.getActivityLogs(s,e).then(u=>{n(u.logs),o(!1)}).catch(()=>o(!1))},[s,e]),_.useEffect(()=>t?bt.on("agent:activity_log",f=>{const p=f.payload;if(p.agentId!==s||p.activityId!==e)return;const b={seq:p.seq,type:p.type,content:p.content,metadata:p.metadata,createdAt:p.createdAt};n(v=>v.some(g=>g.seq===b.seq)?v:[...v,b])}):void 0,[s,e,t]),a)return c.jsx("div",{className:"px-4 py-3 text-xs text-fg-tertiary",children:r("profilePage.activityLog.loading")});if(i.length===0)return c.jsx("div",{className:"px-4 py-3 text-xs text-fg-tertiary",children:r("profilePage.activityLog.noLogs")});const d=i.map(u=>tk(u,e,s)).filter(u=>u!==null);return c.jsx("div",{className:"px-3 py-2",children:l==="compact"?c.jsx(Vb,{entries:d,isActive:t,onExpand:()=>h("full")}):c.jsx(Fb,{entries:d,isActive:t,onCollapse:()=>h("compact")})})}function fs({title:s,action:e,children:t}){return c.jsxs("div",{className:"bg-surface-elevated rounded-xl p-5",children:[c.jsxs("div",{className:"flex items-center justify-between mb-3",children:[c.jsx("h3",{className:"text-[10px] font-semibold text-fg-tertiary uppercase tracking-wider",children:s}),e]}),t]})}function Ms({label:s,mono:e,children:t}){return c.jsxs("div",{className:"flex flex-col gap-0.5",children:[c.jsx("span",{className:"text-[10px] text-fg-tertiary",children:s}),c.jsx("span",{className:`text-xs text-fg-secondary ${e?"font-mono text-[10px]":""}`,children:t})]})}function Xs({label:s,value:e,color:t}){const r=t==="green"?"text-green-500":t==="blue"?"text-blue-400":t==="indigo"?"text-brand-500":t==="red"?"text-red-400":"text-fg-secondary";return c.jsxs("div",{className:"flex items-baseline gap-1.5",children:[c.jsx("span",{className:`text-sm font-semibold ${r}`,children:e}),c.jsx("span",{className:"text-[10px] text-fg-tertiary",children:s})]})}const Tb=[1800*1e3,3600*1e3,10800*1e3,360*60*1e3,720*60*1e3,1440*60*1e3],Qb=5,$b=1440;function j4({agentId:s,intervalMs:e,onChanged:t}){const{t:r}=Qt(["agent","common"]),[i,n]=_.useState(!1),[a,o]=_.useState(null),[l,h]=_.useState(!1),[d,u]=_.useState(String(Math.round(e/6e4))),f=m=>m%(3600*1e3)===0?r("agent:profilePage.heartbeatTab.intervalHours",{count:m/(3600*1e3)}):r("agent:profilePage.heartbeatTab.intervalMinutes",{count:Math.round(m/6e4)}),p=async m=>{n(!0),o(null);try{await re.agents.updateConfig(s,{heartbeatIntervalMs:m}),t()}catch(x){o(String(x).replace("Error: ",""))}n(!1)},b=m=>{if(m.target.value==="custom"){h(!0);return}h(!1),p(Number(m.target.value))},v=()=>{const m=Math.round(Number(d));if(!Number.isFinite(m)||m<Qb||m>$b){o(r("agent:profilePage.heartbeatTab.intervalRangeHint"));return}p(m*60*1e3)},g=Tb.includes(e),O=l||!g?"custom":String(e);return c.jsxs("div",{className:"flex flex-col gap-1",children:[c.jsx("span",{className:"text-[10px] text-fg-tertiary",children:r("agent:profilePage.heartbeatTab.safetyNetInterval")}),c.jsxs("select",{value:O,onChange:b,disabled:i,className:"text-xs bg-bg-secondary border border-gray-700/50 rounded-md px-1.5 py-1 text-fg-secondary focus:outline-none focus:border-blue-500/50 disabled:opacity-40",children:[!g&&c.jsx("option",{value:String(e),children:f(e)}),Tb.map(m=>c.jsx("option",{value:String(m),children:f(m)},m)),c.jsx("option",{value:"custom",children:r("agent:profilePage.heartbeatTab.intervalCustom")})]}),(l||!g)&&c.jsxs("div",{className:"flex items-center gap-1.5 mt-1",children:[c.jsx("input",{type:"number",min:Qb,max:$b,value:d,onChange:m=>u(m.target.value),disabled:i,className:"w-16 text-xs bg-bg-secondary border border-gray-700/50 rounded-md px-1.5 py-1 text-fg-secondary focus:outline-none focus:border-blue-500/50 disabled:opacity-40"}),c.jsx("span",{className:"text-[10px] text-fg-tertiary",children:r("agent:profilePage.heartbeatTab.intervalCustomUnit")}),c.jsx("button",{onClick:v,disabled:i,className:"text-[10px] px-2 py-1 rounded-md bg-blue-600/20 text-blue-600 hover:bg-blue-600/30 border border-blue-500/30 transition-colors disabled:opacity-40",children:r(i?"agent:profilePage.heartbeatTab.intervalSaving":"agent:profilePage.heartbeatTab.intervalSave")})]}),a&&c.jsx("span",{className:"text-[10px] text-red-400",children:a})]})}function wh({text:s}){return c.jsx("div",{className:"text-xs text-fg-tertiary py-6 text-center",children:s})}function jb(s){if(s===0)return"0 B";const e=["B","KB","MB","GB"],t=Math.min(Math.floor(Math.log(s)/Math.log(1024)),e.length-1),r=s/Math.pow(1024,t);return`${r<10?r.toFixed(1):Math.round(r)} ${e[t]}`}const Eb={0:"0",1:"1",2:"2",3:"3",4:"4"},Rb={0:"text-red-500",1:"text-amber-500",2:"text-fg-secondary",3:"text-fg-tertiary",4:"text-fg-tertiary/60"},E4={pick:"bg-brand-500/20 text-brand-500",continue:"bg-gray-500/20 text-gray-500",preempt:"bg-amber-500/20 text-amber-500",merge:"bg-blue-500/20 text-blue-500",defer:"bg-purple-500/20 text-purple-500",delegate:"bg-green-500/20 text-green-500",drop:"bg-red-500/20 text-red-500"},R4={idle:"bg-green-500/20 text-green-500",focused:"bg-brand-500/20 text-brand-500",deciding:"bg-amber-500/20 text-amber-500"},yc={system_event:"⚙",human_chat:"💬",task_comment:"💬",mention:"@",session_reply:"↩",task_status_update:"📋",a2a_message:"🔗",review_request:"👀",requirement_update:"📝",requirement_comment:"💬",daily_report:"📊",heartbeat:"♡",memory_consolidation:"🧠"},A4=["all","interaction","task","notification","system"],M4={interaction:["human_chat","a2a_message","mention"],task:["task_status_update","task_comment","requirement_comment","review_request","session_reply"],notification:["requirement_update"],system:["system_event","heartbeat","daily_report","memory_consolidation"]},L4={completed:"bg-green-500",processing:"bg-blue-400 animate-pulse",deferred:"bg-purple-400",merged:"bg-brand-400",queued:"bg-amber-400",dropped:"bg-red-500"},N4={pending:"text-gray-400",assigned:"text-blue-400",in_progress:"text-brand-400",completed:"text-green-400",failed:"text-red-400",cancelled:"text-gray-500",review:"text-amber-400",approved:"text-green-500",rejected:"text-red-500",draft:"text-gray-400"};function Ju(s){const e=s.match(/Comment from .+?:\s*(.+?)(?:\n\n\*\*MANDATORY|\n\n---|\n\n\[|$)/s);if(e?.[1]){const t=e[1].trim().replace(/\n/g," ");return t.length>80?t.slice(0,80)+"…":t}}function Ab(s,e){const t=s.payload,r=t?.summary??"",i=t?.content??"",n=s.metadata?.senderName;switch(s.sourceType){case"task_status_update":{const a=r.match(/^Task "(.+?)" status:/),o=r.match(/status:\s*(\S+)\s*→\s*(\S+)/),l=a?.[1]??r;if(o){const d=o[1],u=o[2],f=fm(d,e),p=fm(u,e),b=N4[u]??"text-fg-secondary";return{title:l,subtitle:e("agent:profilePage.mind.mailbox.statusArrow",{from:f,to:p}),badge:{label:p,color:b}}}const h=r.match(/^Task:\s*(.+)/);return h?{title:h[1]}:{title:l}}case"task_comment":{const a=r.match(/^Comment on task "(.+?)" from (.+?)(\s*\(\+\d+\))?$/),o=Ju(i);if(a){const l=o?e("agent:profilePage.mind.mailbox.commentFromAuthor",{author:a[2],text:o}):e("agent:profilePage.mind.mailbox.commentFrom",{name:a[2]});return{title:a[1],subtitle:l}}return{title:r}}case"requirement_update":{const a=r.match(/^Requirement "(.+?)"\s+(.*)/);return a?{title:a[1],subtitle:a[2]}:{title:r}}case"requirement_comment":{const a=r.match(/^Comment on requirement "(.+?)" from (.+?)(\s*\(\+\d+\))?$/),o=Ju(i);if(a){const l=o?e("agent:profilePage.mind.mailbox.commentFromAuthor",{author:a[2],text:o}):e("agent:profilePage.mind.mailbox.commentFrom",{name:a[2]});return{title:a[1],subtitle:l}}return{title:r}}case"human_chat":{const a=i.slice(0,120).replace(/\n/g," ");return{title:n?e("agent:profilePage.mind.mailbox.chatFrom",{sender:n}):e("agent:profilePage.mind.mailbox.humanChat"),subtitle:a+(i.length>120?"…":"")}}case"a2a_message":{const a=i.slice(0,120).replace(/\n/g," ");return{title:n?e("agent:profilePage.mind.mailbox.messageFrom",{sender:n}):e("agent:profilePage.mind.mailbox.agentMessage"),subtitle:a+(i.length>120?"…":"")}}case"mention":{const a=r.match(/from (.+)$/),o=Ju(i);return{title:a?e("agent:profilePage.mind.mailbox.mentionedBy",{name:a[1]}):e("agent:profilePage.mind.mailbox.mention"),subtitle:o||void 0}}case"review_request":{const a=i.slice(0,120).replace(/\n/g," ");return{title:n?e("agent:profilePage.mind.mailbox.reviewRequestFrom",{sender:n}):e("agent:profilePage.mind.mailbox.reviewRequest"),subtitle:a+(i.length>120?"…":"")}}case"session_reply":{const a=i.slice(0,120).replace(/\n/g," ");return{title:n?e("agent:profilePage.mind.mailbox.replyInSession",{sender:n}):e("agent:profilePage.mind.mailbox.sessionReply"),subtitle:a+(i.length>120?"…":"")}}case"heartbeat":return{title:e("agent:profilePage.mind.mailbox.scheduledHeartbeat")};case"daily_report":return{title:e("agent:profilePage.mind.mailbox.dailyReport")};case"memory_consolidation":return{title:e("agent:profilePage.mind.mailbox.memoryConsolidation")};case"system_event":{const a=r.match(/^\[Announcement]\s*(.+)/);return a?{title:a[1],subtitle:e("agent:profilePage.mind.mailbox.systemAnnouncement")}:{title:r||e("agent:profilePage.mind.mailbox.systemEvent")}}default:return{title:r||s.sourceType}}}function D4({agentId:s,highlightId:e,agentStatus:t,canManageAgents:r}){const{t:i}=Qt(["agent","common","team"]),[n,a]=_.useState(null),[o,l]=_.useState(null),[h,d]=_.useState(!0),[u,f]=_.useState("all"),[p,b]=_.useState("all"),[v,g]=_.useState(e??null),[O,m]=_.useState(e??null),[x,y]=_.useState(!1),[w,C]=_.useState(!1),[P,S]=_.useState(!0),[T,j]=_.useState(null),M=50,L=3,E=_.useCallback(async(A=!0)=>{A&&d(!0);try{const X=u==="all"?void 0:u,Y=p==="all"?void 0:p,[se,ee]=await Promise.all([re.agents.getMindState(s),re.agents.getMailbox(s,{limit:M,category:X,status:Y})]);a(se),l(ee),S((ee.history?.length??0)>=M)}catch{}d(!1)},[s,u,p]),B=_.useCallback(async()=>{if(!o)return;const A=u==="all"?void 0:u,X=p==="all"?void 0:p;try{const Y=await re.agents.getMailbox(s,{limit:M,offset:o.history.length,category:A,status:X});l(se=>se?{...se,history:[...se.history,...Y.history]}:Y),S((Y.history?.length??0)>=M)}catch{}},[s,o,u,p]);_.useEffect(()=>{g(e??null),m(e??null),E()},[E,e]);const U=_.useRef(!1);if(_.useEffect(()=>{if(!O||h)return;if(o?.history?.some(X=>X.id===O)){U.current=!1;const X=document.getElementById(`mbx-${O}`);if(X){setTimeout(()=>X.scrollIntoView({behavior:"smooth",block:"center"}),100);const Y=setTimeout(()=>m(null),3e3);return()=>clearTimeout(Y)}}else P&&!U.current&&(U.current=!0,(async()=>{let X=o?.history??[],Y=P;for(;Y;)try{const se=await re.agents.getMailbox(s,{limit:M,offset:X.length}),ee=[...X,...se.history];X=ee,Y=(se.history?.length??0)>=M;const me=se.history.some(V=>V.id===O);if(l(V=>V?{...V,history:ee}:se),S(Y),me||!Y)break}catch{break}U.current=!1})())},[O,h,o,P,s]),_.useEffect(()=>{let A=null;const X=se=>{se.payload?.agentId===s&&(A&&clearTimeout(A),A=setTimeout(()=>{A=null,E(!1)},500))},Y=[bt.on("agent:mailbox",X),bt.on("agent:decision",X),bt.on("agent:attention",X),bt.on("agent:focus",X),bt.on("agent:update",X),bt.on("agent:triage",X)];return()=>{A&&clearTimeout(A),Y.forEach(se=>se())}},[s,E]),h&&!n)return c.jsx("div",{className:"text-fg-tertiary text-sm animate-pulse",children:i("agent:profilePage.mind.loading")});const Z=n?.mailboxDepth??n?.queuedItems?.length??0,I=Ch(t).running,ie=(()=>{const A=n?.attentionState??"idle";return A==="deciding"||A==="idle"&&Z>0?"deciding":A!=="idle"&&!n?.currentFocus?"idle":A})(),Q=ie==="idle"&&o?.history?.some(A=>A.status==="processing"),W=(n?.attentionState??"idle")==="idle"&&Z>0;return c.jsxs("div",{className:"space-y-4",children:[c.jsxs("section",{children:[c.jsxs("div",{className:"flex items-center gap-3 mb-3",children:[I?c.jsx("span",{className:`px-2.5 py-1 text-xs font-medium rounded-full ${R4[ie]??"bg-gray-500/20 text-gray-500"}`,children:i(`agent:profilePage.mind.attention.${ie}`)}):c.jsx("span",{className:"px-2.5 py-1 text-xs font-medium rounded-full bg-gray-500/20 text-fg-tertiary",children:i("agent:profilePage.mind.agentStopped")}),I?n?.currentFocus?(()=>{const A=Ab({id:n.currentFocus.mailboxItemId,sourceType:n.currentFocus.type,payload:{summary:n.currentFocus.label,taskId:n.currentFocus.taskId},metadata:{},queuedAt:n.currentFocus.startedAt},i);return c.jsxs("span",{className:"text-sm text-fg-secondary inline-flex items-center gap-2",children:[c.jsxs("span",{children:[yc[n.currentFocus.type]??"●"," ",c.jsx("span",{className:"text-fg-primary font-medium",children:A.title}),A.subtitle&&c.jsx("span",{className:"text-fg-tertiary ml-1.5 text-xs",children:A.subtitle}),c.jsx("span",{className:"text-fg-tertiary ml-2 text-xs",children:i("agent:profilePage.mind.since",{time:new Date(n.currentFocus.startedAt).toLocaleTimeString()})})]}),r&&c.jsxs("button",{onClick:()=>j(n.currentFocus.mailboxItemId),className:"px-2 py-0.5 text-[10px] font-medium rounded-md bg-red-500/15 text-red-500 hover:bg-red-500/25 transition-colors shrink-0",children:["✕ ",i("agent:profilePage.mind.cancelCurrentBtn")]})]})})():W?c.jsx("span",{className:"text-sm text-amber-500",children:i("agent:profilePage.mind.queuedButIdle",{count:Z,defaultValue:"Queue has {{count}} item(s) — attention loop should pick them up…"})}):ie==="deciding"?c.jsx("span",{className:"text-sm text-amber-500",children:i("agent:profilePage.mind.decidingWaiting",{count:Z})}):c.jsx("span",{className:"text-sm text-fg-tertiary",children:i("agent:profilePage.mind.idleWaiting")}):c.jsx("span",{className:"text-sm text-fg-tertiary",children:i("agent:profilePage.mind.stoppedHint")}),c.jsx("div",{className:"ml-auto flex items-center gap-2",children:c.jsx("button",{onClick:()=>{E()},className:"text-xs text-fg-tertiary hover:text-fg-secondary active:text-fg-primary transition-colors",children:i("agent:profilePage.mind.refresh")})})]}),I&&Q&&c.jsxs("div",{className:"mb-3 px-3 py-2 rounded-lg bg-amber-500/10 border border-amber-500/30 flex items-center gap-2",children:[c.jsx("span",{className:"text-amber-500 text-sm",children:"⚠"}),c.jsx("span",{className:"text-[11px] text-amber-600",children:i("agent:profilePage.mind.staleProcessingWarning")})]}),(n?.queuedItems?.length??0)>0&&(()=>{const A=n.queuedItems,X=A.length>L,Y=X&&!x?A.slice(0,L):A,se=A.reduce((ee,me)=>(ee[me.sourceType]=(ee[me.sourceType]??0)+1,ee),{});return c.jsxs("div",{className:"mb-3",children:[c.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[c.jsx("h4",{className:"text-xs font-medium text-amber-500 uppercase tracking-wider",children:i("agent:profilePage.mind.queue",{count:A.length})}),c.jsx("div",{className:"flex gap-1.5 flex-wrap",children:Object.entries(se).map(([ee,me])=>c.jsxs("span",{className:"text-[10px] text-fg-tertiary bg-amber-500/10 px-1.5 py-0.5 rounded",children:[yc[ee]??"●"," ",me]},ee))})]}),c.jsxs("div",{className:"space-y-1",children:[Y.map((ee,me)=>c.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 rounded bg-amber-500/5 border border-amber-500/20 text-sm",children:[c.jsx("span",{className:"text-fg-tertiary w-4 text-right text-xs",children:me+1}),c.jsx("span",{className:"text-sm",children:yc[ee.sourceType]??"●"}),c.jsx("span",{className:`text-[10px] ${Rb[ee.priority]??"text-fg-tertiary"}`,children:i(`agent:profilePage.mind.priority.${Eb[ee.priority]??ee.priority}`,{defaultValue:`P${ee.priority}`})}),c.jsx("span",{className:"text-fg-secondary truncate flex-1 text-xs",children:ee.summary}),c.jsx("span",{className:"text-[10px] text-fg-tertiary",children:new Date(ee.queuedAt).toLocaleTimeString()})]},ee.id)),X&&c.jsx("button",{onClick:()=>y(!x),className:"w-full text-center text-[11px] text-amber-500 hover:text-amber-400 py-1 transition-colors",children:x?i("agent:profilePage.mind.collapseQueue"):i("agent:profilePage.mind.expandQueue",{count:A.length-L})})]})]})})()]}),(n?.notebook?.length??0)>0&&(()=>{const A=m4(n.notebook,w);return c.jsx("section",{className:"bg-surface-2 rounded-lg border border-border-subtle p-3",children:c.jsxs("details",{children:[c.jsxs("summary",{className:"flex items-center gap-2 cursor-pointer list-none",children:[c.jsx("span",{className:"text-sm",children:"📓"}),c.jsx("h4",{className:"text-xs font-medium text-fg-secondary uppercase tracking-wider",children:i("agent:profilePage.mind.notebook")}),c.jsx("span",{className:"text-[10px] text-fg-quaternary ml-auto",children:i("agent:profilePage.mind.notebookEntries",{count:n.notebook.length})})]}),c.jsx("p",{className:"mt-2 text-[10px] text-fg-quaternary leading-relaxed",children:i("agent:profilePage.mind.notebookHint",{count:R_})}),c.jsxs("div",{className:"mt-2 space-y-2",children:[A.visible.map(X=>{const Y=p4(X.updatedAt),se=i(`agent:profilePage.relative.${Y.unit==="seconds"?"secondsAgo":Y.unit==="minutes"?"minutesAgo":"hoursAgo"}`,{count:Y.count,hours:Y.count}),ee=X.managed==="system"?"text-blue-400":X.managed==="cpp"?"text-purple-400":"text-emerald-400";return c.jsxs("div",{className:"px-3 py-2 rounded bg-surface-3 border border-border-subtle",children:[c.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[c.jsx("span",{className:"text-xs font-medium text-fg-primary",children:X.key}),c.jsxs("span",{className:`text-[10px] ${ee}`,children:["[",X.managed,"]"]}),c.jsx("span",{className:"text-[10px] text-fg-quaternary ml-auto",children:se})]}),c.jsx("pre",{className:"text-[11px] text-fg-secondary whitespace-pre-wrap break-words leading-relaxed max-h-32 overflow-y-auto",children:X.text.length>500?X.text.slice(0,500)+"…":X.text})]},X.key)}),A.collapsible&&c.jsx("button",{onClick:()=>C(!w),className:"w-full text-center text-[11px] text-accent-primary hover:opacity-80 py-1 transition-colors",children:w?i("agent:profilePage.mind.collapseQueue"):i("agent:profilePage.mind.expandNotebook",{count:A.hiddenCount})})]})]})})})(),n?.deliberationActivity&&c.jsxs("section",{className:"bg-surface-2 rounded-lg border border-amber-500/20 p-3",children:[c.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[c.jsx("span",{className:"text-sm",children:"🧠"}),c.jsx("h4",{className:"text-xs font-medium text-amber-500 uppercase tracking-wider",children:i("agent:profilePage.mind.deliberationInProgress")}),c.jsx("span",{className:"text-[10px] text-fg-quaternary ml-auto",children:i("agent:profilePage.mind.since",{time:new Date(n.deliberationActivity.startedAt).toLocaleTimeString()})})]}),c.jsx(_h,{agentId:s,activityId:n.deliberationActivity.activityId,isLive:!0})]}),n?.lastTriage&&(()=>{const X=Date.now()-new Date(n.lastTriage.timestamp).getTime()>6e4;return c.jsx("section",{className:`bg-surface-2 rounded-lg border p-3 transition-opacity ${X?"border-border-subtle opacity-60":"border-indigo-500/20"}`,children:c.jsxs("details",{open:!X,children:[c.jsxs("summary",{className:"flex items-center gap-2 cursor-pointer list-none",children:[c.jsx("span",{className:"text-sm",children:"🧠"}),c.jsx("h4",{className:"text-xs font-medium text-indigo-400 uppercase tracking-wider",children:i("agent:profilePage.mind.triageDecision")}),c.jsx("span",{className:"text-[10px] text-fg-quaternary ml-auto",children:new Date(n.lastTriage.timestamp).toLocaleTimeString()})]}),c.jsx("p",{className:"text-xs text-fg-secondary leading-relaxed mt-2",children:n.lastTriage.reasoning}),c.jsxs("div",{className:"flex flex-wrap gap-2 mt-2 text-[10px]",children:[c.jsx("span",{className:"px-1.5 py-0.5 rounded bg-green-500/10 text-green-400",children:i("agent:profilePage.mind.processingItem",{id:n.lastTriage.processedItemId.slice(0,12)})}),n.lastTriage.deferredItemIds.length>0&&c.jsx("span",{className:"px-1.5 py-0.5 rounded bg-amber-500/10 text-amber-400",children:i("agent:profilePage.mind.deferred",{count:n.lastTriage.deferredItemIds.length})}),n.lastTriage.droppedItemIds.length>0&&c.jsx("span",{className:"px-1.5 py-0.5 rounded bg-red-500/10 text-red-400",children:i("agent:profilePage.mind.dropped",{count:n.lastTriage.droppedItemIds.length})}),(n.lastTriage.inlineCompletedIds?.length??0)>0&&c.jsx("span",{className:"px-1.5 py-0.5 rounded bg-blue-500/10 text-blue-400",children:i("agent:profilePage.mind.inlineCompleted",{count:n.lastTriage.inlineCompletedIds.length})})]})]})})})(),c.jsxs("section",{children:[c.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[c.jsx("h3",{className:"text-xs font-medium text-fg-tertiary uppercase tracking-wider",children:i("agent:profilePage.mind.mailboxHistory")}),c.jsx("div",{className:"flex gap-1 ml-auto flex-wrap",children:A4.map(A=>{const X=o?.sourceTypeCounts,Y=A==="all"?X?Object.values(X).reduce((se,ee)=>se+ee,0):void 0:X?(M4[A]??[]).reduce((se,ee)=>se+(X[ee]??0),0):void 0;return c.jsxs("button",{onClick:()=>f(A),className:`px-2 py-0.5 text-[10px] rounded-md border transition-colors ${u===A?"bg-brand-500/20 border-brand-500/40 text-brand-300":"bg-surface-2 border-border-subtle text-fg-secondary hover:bg-surface-3"}`,children:[i(`agent:profilePage.mind.categoryFilters.${A}`),Y!=null&&Y>0&&c.jsx("span",{className:"ml-1 opacity-60",children:Y})]},A)})})]}),c.jsx("div",{className:"flex gap-1 mb-2 flex-wrap",children:[{key:"all",dot:""},{key:"queued",dot:"bg-amber-400"},{key:"processing",dot:"bg-blue-400"},{key:"completed",dot:"bg-green-500"},{key:"merged",dot:"bg-brand-400"},{key:"deferred",dot:"bg-purple-400"},{key:"dropped",dot:"bg-red-500"}].map(A=>{const X=o?.statusCounts,Y=A.key==="all"?X?Object.values(X).reduce((se,ee)=>se+ee,0):void 0:X?.[A.key];return c.jsxs("button",{onClick:()=>b(A.key),className:`px-2 py-0.5 text-[10px] rounded-md border transition-colors flex items-center gap-1 ${p===A.key?"bg-brand-500/20 border-brand-500/40 text-brand-300":"bg-surface-2 border-border-subtle text-fg-secondary hover:bg-surface-3"}`,children:[A.dot&&c.jsx("span",{className:`w-1.5 h-1.5 rounded-full ${A.dot}`}),i(`agent:profilePage.mind.statusFilters.${A.key}`),Y!=null&&Y>0&&c.jsx("span",{className:"ml-1 opacity-60",children:Y})]},A.key)})}),(!o?.history||o.history.length===0)&&!h&&c.jsx("div",{className:"text-center text-fg-tertiary text-sm py-8",children:i("agent:profilePage.mind.noHistory")}),c.jsx("div",{className:"space-y-1",children:o?.history?.map(A=>{const X=v===A.id,Y=yc[A.sourceType]??"●",se=Ab(A,i),ee=A.metadata?.senderName,me=A.metadata?.senderRole,V=O===A.id;return c.jsxs("div",{id:`mbx-${A.id}`,className:`bg-surface-2 rounded-lg border transition-colors duration-1000 ${V?"border-brand-500 ring-1 ring-brand-500/40":"border-border-subtle"}`,children:[c.jsxs("button",{className:"w-full px-3 py-2.5 flex items-start gap-2 text-left hover:bg-surface-3/50 transition-colors rounded-lg",onClick:()=>g(X?null:A.id),children:[c.jsx("span",{className:"text-xs mt-0.5 text-fg-tertiary",children:X?"▾":"▸"}),c.jsx("span",{className:`w-2 h-2 mt-1.5 rounded-full shrink-0 ${L4[A.status]??"bg-gray-400"}`}),c.jsx("span",{className:"text-sm",children:Y}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:`text-xs font-medium text-fg-primary ${X?"":"truncate"}`,children:se.title}),se.badge&&c.jsx("span",{className:`text-[10px] font-medium shrink-0 ${se.badge.color}`,children:se.badge.label}),c.jsx("span",{className:`text-[10px] shrink-0 ${Rb[A.priority]??"text-fg-tertiary"}`,children:i(`agent:profilePage.mind.priority.${Eb[A.priority]??A.priority}`,{defaultValue:""})})]}),se.subtitle&&c.jsx("div",{className:`text-[11px] text-fg-secondary mt-0.5 ${X?"":"truncate"}`,children:se.subtitle}),c.jsxs("div",{className:"text-[10px] text-fg-tertiary mt-0.5 flex gap-2 flex-wrap",children:[c.jsx("span",{children:new Date(A.queuedAt).toLocaleString()}),A.completedAt&&c.jsxs("span",{children:["→ ",new Date(A.completedAt).toLocaleTimeString()]}),A.activity&&c.jsxs(c.Fragment,{children:[A.activity.totalTokens>0&&c.jsx("span",{children:i("agent:profilePage.mind.tokensCount",{count:mm(A.activity.totalTokens)})}),A.activity.totalTools>0&&c.jsx("span",{children:i("agent:profilePage.mind.toolsCount",{count:A.activity.totalTools})})]})]})]}),c.jsx("span",{className:"text-[10px] text-fg-tertiary bg-surface-3 px-1.5 py-0.5 rounded shrink-0",children:A.sourceType}),r&&A.status==="processing"&&c.jsxs("button",{onClick:N=>{N.stopPropagation(),j(A.id)},className:"px-2 py-0.5 text-[10px] font-medium rounded-md bg-red-500/15 text-red-500 hover:bg-red-500/25 transition-colors shrink-0",children:["✕ ",i("agent:profilePage.mind.cancelCurrentBtn")]})]}),X&&c.jsxs("div",{className:"border-t border-border-subtle px-3 py-3 space-y-3",children:[ee&&c.jsxs("div",{className:"text-[10px] text-fg-tertiary",children:[i("agent:profilePage.mind.from")," ",c.jsx("span",{className:"text-fg-secondary",children:ee}),me&&c.jsxs("span",{className:"text-fg-tertiary",children:[" (",me,")"]})]}),A.payload?.content&&["human_chat","a2a_message","task_comment","requirement_comment","review_request","session_reply","mention"].includes(A.sourceType)&&c.jsx("div",{className:"text-xs text-fg-secondary bg-surface-primary/50 rounded-md p-2.5 whitespace-pre-wrap break-words max-h-60 overflow-y-auto",children:A.payload.content}),A.decisions&&A.decisions.length>0&&c.jsxs("div",{children:[c.jsx("h5",{className:"text-[10px] font-medium text-fg-tertiary uppercase tracking-wider mb-1",children:i("agent:profilePage.mind.decisions")}),c.jsx("div",{className:"space-y-1",children:A.decisions.map(N=>c.jsxs("div",{className:"flex items-start gap-2 text-xs",children:[c.jsx("span",{className:`px-1.5 py-0.5 rounded shrink-0 ${E4[N.decisionType]??"bg-gray-500/20 text-gray-500"}`,children:N.decisionType}),c.jsx("span",{className:"text-fg-secondary flex-1",children:N.reasoning}),c.jsx("span",{className:"text-fg-tertiary shrink-0",children:new Date(N.createdAt).toLocaleTimeString()})]},N.id))})]}),A.activity?c.jsxs("div",{children:[c.jsxs("h5",{className:"text-[10px] font-medium text-fg-tertiary uppercase tracking-wider mb-1",children:[i("agent:profilePage.mind.activityHeading",{label:A.activity.label}),c.jsx("span",{className:`ml-2 inline-block px-1 py-0 rounded text-[9px] ${A.activity.success?"bg-green-500/15 text-green-500":"bg-red-500/15 text-red-500"}`,children:A.activity.success?i("agent:profilePage.mind.success"):i("agent:profilePage.mind.failed")})]}),A.activity.type==="task"&&A.payload?.taskId?c.jsx($4,{taskId:A.payload.taskId,isLive:!A.activity.endedAt}):c.jsx(_h,{agentId:s,activityId:A.activity.id,isLive:!A.activity.endedAt})]}):A.status==="processing"?c.jsx("div",{className:"text-xs text-fg-tertiary text-center py-2 animate-pulse",children:i("agent:profilePage.mind.processing")}):A.status==="completed"?c.jsx("div",{className:"text-xs text-fg-tertiary text-center py-2",children:i("agent:profilePage.mind.noActivityLog")}):null]})]},A.id)})}),P&&(o?.history?.length??0)>0&&c.jsx("div",{className:"text-center mt-3",children:c.jsx("button",{onClick:B,className:"text-xs text-brand-400 hover:text-brand-300 transition-colors",children:i("agent:profilePage.mind.loadEarlier")})})]}),T&&c.jsx(Po,{title:i("agent:profilePage.mind.cancelConfirmTitle"),message:i("agent:profilePage.mind.cancelConfirmMessage"),confirmLabel:i("agent:profilePage.mind.cancelCurrentBtn"),onConfirm:()=>{const A=T;j(null),re.agents.cancelProcessing(s,{itemId:A}).then(()=>{let X=0;const Y=()=>{X+=1,E(),X<8&&window.setTimeout(Y,750)};Y()}).catch(()=>{E()})},onCancel:()=>j(null)})]})}function Mb({agentId:s}){const{t:e}=Qt(["agent","common"]),t=kh(),[r,i]=_.useState([]),[n,a]=_.useState(!0),o=_.useCallback(h=>{if(jC(t?.hostAvailable)==="right-panel"){t?.openRightPanel({kind:"deliverable",deliverable:h});return}yr.navigate(Gt.DELIVERABLES,{openDeliverable:h.id})},[t]),l=_.useCallback(async()=>{a(!0);try{const{results:h}=await re.deliverables.search({agentId:s,limit:200});i(h)}catch{i([])}a(!1)},[s]);return _.useEffect(()=>{l()},[l]),_.useEffect(()=>{const h=bt.on("deliverable:created",()=>l()),d=bt.on("deliverable:updated",()=>l()),u=bt.on("deliverable:removed",()=>l());return()=>{h(),d(),u()}},[l]),n?c.jsx("div",{className:"space-y-3 py-4",children:[1,2,3].map(h=>c.jsxs("div",{className:"animate-pulse space-y-2",children:[c.jsx("div",{className:"h-4 bg-surface-elevated rounded w-3/4"}),c.jsx("div",{className:"h-3 bg-surface-elevated rounded w-1/2"})]},h))}):r.length===0?c.jsxs("div",{className:"flex flex-col items-center justify-center py-16 text-center",children:[c.jsx("span",{className:"text-3xl mb-3",children:"📦"}),c.jsx("p",{className:"text-sm text-fg-secondary",children:e("agent:deliverables.empty")}),c.jsx("p",{className:"text-xs text-fg-tertiary mt-1",children:e("agent:deliverables.emptyHint")})]}):c.jsx(c.Fragment,{children:c.jsxs("div",{className:"space-y-2",children:[c.jsx("div",{className:"text-xs text-fg-tertiary mb-3",children:e("agent:deliverables.count",{count:r.length})}),r.map(h=>{const d=Jw[h.type]??{icon:"📎",color:"bg-surface-elevated text-fg-secondary"},u=Wg[h.status]??Wg.active;return c.jsxs("button",{onClick:()=>o(h),className:"w-full text-left rounded-xl border border-border-default bg-surface-elevated/30 overflow-hidden transition-colors hover:border-brand-500/40 hover:bg-surface-elevated/50 px-4 py-3 flex items-start gap-3",children:[c.jsx("span",{className:`inline-flex items-center justify-center w-8 h-8 rounded-lg text-sm shrink-0 ${d.color}`,children:d.icon}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[c.jsx("span",{className:"text-sm font-medium text-fg-primary truncate",children:h.title}),c.jsx("span",{className:`px-1.5 py-0.5 text-[10px] rounded font-medium ${u.color}`,children:h.status})]}),h.summary&&c.jsx("p",{className:"text-xs text-fg-tertiary mt-0.5 line-clamp-1",children:h.summary}),c.jsxs("div",{className:"flex items-center gap-3 mt-1 text-[10px] text-fg-tertiary",children:[c.jsx("span",{children:new Date(h.createdAt).toLocaleDateString()}),h.tags.length>0&&c.jsx("span",{children:h.tags.slice(0,3).join(", ")})]})]}),c.jsx("svg",{className:"w-4 h-4 text-fg-tertiary shrink-0 mt-1",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:c.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M9 5l7 7-7 7"})})]},h.id)})]})})}const I4=_.lazy(()=>Ub(()=>import("./index-B6fl84HP.js").then(s=>s.b1),__vite__mapDeps([0,1])).then(s=>({default:s.MarkdownMessage}))),Lp=[{key:"overview",labelKey:"teamProfile.overview",icon:"▦"},{key:"announcements",labelKey:"teamProfile.announcements",icon:"◈"},{key:"norms",labelKey:"teamProfile.norms",icon:"☰"},{key:"settings",labelKey:"teamProfile.settings",icon:"⚙"}],Lb={idle:"bg-green-400",working:"bg-blue-400 animate-pulse",offline:"bg-gray-500",error:"bg-red-400"};function Nb({teamId:s,onBack:e,inline:t,headless:r,activeTab:i,onSelectAgent:n}){const{t:a}=Qt("team"),[o,l]=_.useState(null),[h,d]=_.useState(null),[u,f]=_.useState("overview"),p=r&&i?i:u,[b,v]=_.useState(""),[g,O]=_.useState(""),[m,x]=_.useState(!1),[y,w]=_.useState(!1),[C,P]=_.useState(""),[S,T]=_.useState(""),j=_.useRef(null),M=_.useRef(null),L=_.useRef(null),E=_.useRef(null),[B,U]=_.useState(!1),[Z,I]=_.useState(!1),[ie,Q]=_.useState(""),[W,A]=_.useState(""),[X,Y]=_.useState(!1),[se,ee]=_.useState([]),me=_.useRef(null),V=_.useCallback(async()=>{try{const be=(await re.teams.list()).teams.find(ke=>ke.id===s);be&&l(be);const Ae=await re.teams.status(s);ee(Ae.agents)}catch{}},[s]),N=_.useCallback(async()=>{try{const pe=await re.teams.getFile(s,"ANNOUNCEMENT.md");v(pe.content)}catch{v("")}try{const pe=await re.teams.getFile(s,"NORMS.md");O(pe.content)}catch{O("")}},[s]);_.useEffect(()=>{f("overview"),V(),N()},[s,V,N]),_.useEffect(()=>{m&&M.current&&M.current.focus()},[m]),_.useEffect(()=>{y&&E.current&&E.current.focus()},[y]);const ne=async(pe,be)=>{U(!0);try{await re.teams.updateFile(s,pe,be),pe==="ANNOUNCEMENT.md"?(v(be),x(!1)):(O(be),w(!1))}catch{}U(!1)},H=async()=>{ie.trim()&&(await re.teams.update(s,{name:ie.trim()}),I(!1),V())},te=async()=>{await re.teams.update(s,{description:W}),Y(!1),V()};if(!o)return c.jsx("div",{className:"flex-1 flex items-center justify-center text-fg-tertiary text-sm",children:"Loading team..."});const J=o.members.find(pe=>pe.agentRole==="manager"),ge=se.filter(pe=>pe.status!=="offline").length,Qe=p==="announcements"&&m||p==="norms"&&y;if(r)return c.jsx("div",{className:`flex-1 bg-surface-primary ${Qe?"flex flex-col overflow-hidden":"overflow-y-auto"}`,children:c.jsxs("div",{className:`${Qe?"flex-1 flex flex-col min-h-0 p-5":"p-5"}`,children:[p==="overview"&&c.jsxs("div",{className:"space-y-5",children:[c.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[c.jsxs("div",{className:"p-4 bg-surface-secondary rounded-xl border border-border-default",children:[c.jsx("div",{className:"text-xs text-fg-tertiary mb-1",children:"Manager"}),c.jsx("div",{className:"text-sm font-medium",children:J?.name??o.managerName??"None"})]}),c.jsxs("div",{className:"p-4 bg-surface-secondary rounded-xl border border-border-default",children:[c.jsx("div",{className:"text-xs text-fg-tertiary mb-1",children:"Team ID"}),c.jsx("div",{className:"text-sm font-mono text-fg-secondary truncate",children:o.id})]})]}),c.jsxs("div",{className:"space-y-3",children:[c.jsx("div",{className:"text-xs text-fg-tertiary font-medium px-1",children:"Members"}),o.members.map(pe=>{const be=se.find(oe=>oe.id===pe.id),Ae=Lb[be?.status??"offline"]??"bg-gray-500",ke=pe.type==="agent";return c.jsxs("div",{onClick:()=>ke&&n?.(pe.id),className:`p-3 bg-surface-secondary rounded-xl border border-border-default flex items-center gap-3${ke&&n?" cursor-pointer hover:border-brand-500/40 transition-colors":""}`,children:[c.jsx(Qs,{name:pe.name,avatarUrl:pe.avatarUrl,size:32,className:"rounded-lg"}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-sm font-medium",children:pe.name}),c.jsx("span",{className:`w-2 h-2 rounded-full ${Ae}`}),c.jsx("span",{className:"text-xs text-fg-tertiary",children:be?.status??"offline"}),pe.agentRole==="manager"&&c.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-amber-500/15 text-amber-600 rounded font-medium",children:"Manager"})]}),c.jsxs("div",{className:"text-xs text-fg-tertiary",children:[pe.role," · ",pe.type]})]}),ke&&n&&c.jsx("svg",{className:"w-4 h-4 text-fg-tertiary shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"9 18 15 12 9 6"})})]},pe.id)}),o.members.length===0&&c.jsx("div",{className:"text-sm text-fg-tertiary text-center py-8",children:"No members"})]})]}),p==="announcements"&&c.jsx(Sc,{content:b,draft:C,setDraft:P,editing:m,setEditing:x,textareaRef:M,contentRef:j,saving:B,onSave:()=>ne("ANNOUNCEMENT.md",C),placeholder:a("teamProfile.annPlaceholder"),emptyText:a("teamProfile.noAnnouncements")}),p==="norms"&&c.jsx(Sc,{content:g,draft:S,setDraft:T,editing:y,setEditing:w,textareaRef:E,contentRef:L,saving:B,onSave:()=>ne("NORMS.md",S),placeholder:a("teamProfile.normsPlaceholder"),emptyText:a("teamProfile.noNorms")}),p==="settings"&&c.jsxs("div",{className:"space-y-5",children:[c.jsxs("div",{className:"p-4 bg-surface-secondary rounded-xl border border-border-default space-y-4",children:[c.jsxs("div",{children:[c.jsx("div",{className:"text-xs text-fg-tertiary mb-1",children:"Team Name"}),Z?c.jsxs("div",{className:"flex gap-2 items-center",children:[c.jsx("input",{ref:me,value:ie,onChange:pe=>Q(pe.target.value),onKeyDown:pe=>pe.key==="Enter"&&H(),className:"flex-1 bg-surface-elevated border border-border-default rounded-lg px-3 py-1.5 text-sm text-fg-primary focus:outline-none focus:border-brand-500",autoFocus:!0}),c.jsx("button",{onClick:H,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-white",children:"Save"}),c.jsx("button",{onClick:()=>I(!1),className:"px-3 py-1.5 text-xs bg-surface-elevated hover:bg-surface-overlay rounded-lg text-fg-secondary",children:"Cancel"})]}):c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-sm",children:o.name}),c.jsx("button",{onClick:()=>{Q(o.name),I(!0)},className:"text-xs text-fg-tertiary hover:text-fg-secondary",children:"Edit"})]})]}),c.jsxs("div",{children:[c.jsx("div",{className:"text-xs text-fg-tertiary mb-1",children:"Description"}),X?c.jsxs("div",{className:"space-y-2",children:[c.jsx("textarea",{value:W,onChange:pe=>A(pe.target.value),className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-1.5 text-sm text-fg-primary resize-y focus:outline-none focus:border-brand-500",rows:3,autoFocus:!0}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx("button",{onClick:te,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-white",children:"Save"}),c.jsx("button",{onClick:()=>Y(!1),className:"px-3 py-1.5 text-xs bg-surface-elevated hover:bg-surface-overlay rounded-lg text-fg-secondary",children:"Cancel"})]})]}):c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-sm text-fg-secondary",children:o.description||"No description"}),c.jsx("button",{onClick:()=>{A(o.description??""),Y(!0)},className:"text-xs text-fg-tertiary hover:text-fg-secondary",children:"Edit"})]})]})]}),c.jsx(Db,{teamId:s,teamName:o.name,onDeleted:e})]})]})});const _e=u==="announcements"&&m||u==="norms"&&y;return c.jsxs("div",{className:`flex-1 bg-surface-primary ${_e?"flex flex-col overflow-hidden":"overflow-y-auto"}`,children:[c.jsxs("div",{className:"px-5 py-3.5 bg-surface-secondary sticky top-0 z-10 shrink-0",children:[c.jsxs("div",{className:"flex items-center gap-3",children:[c.jsx("div",{className:"w-10 h-10 rounded-xl bg-brand-600 text-white flex items-center justify-center text-lg font-bold shrink-0",children:c.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[c.jsx("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),c.jsx("circle",{cx:"9",cy:"7",r:"4"}),c.jsx("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),c.jsx("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]})}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[c.jsx("h2",{className:"text-base font-semibold",children:o.name}),c.jsxs("span",{className:"px-1.5 py-0.5 text-[10px] bg-brand-500/15 text-brand-500 rounded font-medium",children:[o.members.length," members"]}),c.jsxs("span",{className:"px-1.5 py-0.5 text-[10px] bg-green-500/15 text-green-600 rounded font-medium",children:[ge," online"]})]}),c.jsx("div",{className:"text-xs text-fg-tertiary truncate",children:o.description||"No description"})]}),c.jsxs("button",{onClick:async()=>{if(o)try{const{files:pe}=await re.teams.getFilesMap(o.id),be=o.members.filter(ke=>ke.type==="agent"),Ae={type:"team",name:Zb(o.name,o.name),displayName:o.name,version:"1.0.0",description:o.description??"",author:"",category:"general",tags:[],team:{members:be.map(ke=>({name:ke.name,roleName:ke.role,role:ke.agentRole??"worker",count:1,skills:[]}))}};await vm.publishViaProxy({itemType:"team",name:o.name,description:o.description??"",category:"general",config:Ae,files:pe}),d({title:"Hub",message:`Published "${o.name}" to Markus Hub`,variant:"primary"})}catch(pe){d({title:"Hub",message:`Failed to publish: ${pe}`,variant:"danger"})}},className:"px-3 py-1.5 text-xs bg-green-600 hover:bg-green-500 text-white rounded-lg transition-colors flex items-center gap-1",title:"Publish to Markus Hub",children:[c.jsx("span",{children:"↑"})," Hub"]}),t&&c.jsx("button",{onClick:e,className:"p-1.5 text-fg-tertiary hover:text-fg-secondary text-lg leading-none",children:"×"})]}),c.jsx("div",{className:"flex gap-1 mt-3 -mb-[1px] overflow-x-auto",children:Lp.map(pe=>c.jsxs("button",{onClick:()=>f(pe.key),className:`px-3 py-1.5 text-xs rounded-t-lg whitespace-nowrap transition-colors ${u===pe.key?"bg-surface-primary text-fg-primary border border-border-default border-b-gray-950":"text-fg-tertiary hover:text-fg-secondary"}`,children:[pe.icon," ",a(pe.labelKey)]},pe.key))})]}),c.jsxs("div",{className:`${_e?"flex-1 flex flex-col min-h-0 p-5":"p-5"}`,children:[u==="overview"&&c.jsxs("div",{className:"space-y-5",children:[c.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[c.jsxs("div",{className:"p-4 bg-surface-secondary rounded-xl border border-border-default",children:[c.jsx("div",{className:"text-xs text-fg-tertiary mb-1",children:"Manager"}),c.jsx("div",{className:"text-sm font-medium",children:J?.name??o.managerName??"None"})]}),c.jsxs("div",{className:"p-4 bg-surface-secondary rounded-xl border border-border-default",children:[c.jsx("div",{className:"text-xs text-fg-tertiary mb-1",children:"Team ID"}),c.jsx("div",{className:"text-sm font-mono text-fg-secondary truncate",children:o.id})]})]}),c.jsxs("div",{className:"space-y-3",children:[c.jsx("div",{className:"text-xs text-fg-tertiary font-medium px-1",children:"Members"}),o.members.map(pe=>{const be=se.find(oe=>oe.id===pe.id),Ae=Lb[be?.status??"offline"]??"bg-gray-500",ke=pe.type==="agent";return c.jsxs("div",{onClick:()=>ke&&n?.(pe.id),className:`p-3 bg-surface-secondary rounded-xl border border-border-default flex items-center gap-3${ke&&n?" cursor-pointer hover:border-brand-500/40 transition-colors":""}`,children:[c.jsx(Qs,{name:pe.name,avatarUrl:pe.avatarUrl,size:32,className:"rounded-lg"}),c.jsxs("div",{className:"flex-1 min-w-0",children:[c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-sm font-medium",children:pe.name}),c.jsx("span",{className:`w-2 h-2 rounded-full ${Ae}`}),c.jsx("span",{className:"text-xs text-fg-tertiary",children:be?.status??"offline"}),pe.agentRole==="manager"&&c.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-amber-500/15 text-amber-600 rounded font-medium",children:"Manager"})]}),c.jsxs("div",{className:"text-xs text-fg-tertiary",children:[pe.role," · ",pe.type]})]}),ke&&n&&c.jsx("svg",{className:"w-4 h-4 text-fg-tertiary shrink-0",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:c.jsx("polyline",{points:"9 18 15 12 9 6"})})]},pe.id)}),o.members.length===0&&c.jsx("div",{className:"text-sm text-fg-tertiary text-center py-8",children:"No members"})]})]}),u==="announcements"&&c.jsx(Sc,{content:b,draft:C,setDraft:P,editing:m,setEditing:x,textareaRef:M,contentRef:j,saving:B,onSave:()=>ne("ANNOUNCEMENT.md",C),placeholder:a("teamProfile.annPlaceholder"),emptyText:a("teamProfile.noAnnouncements")}),u==="norms"&&c.jsx(Sc,{content:g,draft:S,setDraft:T,editing:y,setEditing:w,textareaRef:E,contentRef:L,saving:B,onSave:()=>ne("NORMS.md",S),placeholder:a("teamProfile.normsPlaceholder"),emptyText:a("teamProfile.noNorms")}),u==="settings"&&c.jsxs("div",{className:"space-y-5",children:[c.jsxs("div",{className:"p-4 bg-surface-secondary rounded-xl border border-border-default space-y-4",children:[c.jsxs("div",{children:[c.jsx("div",{className:"text-xs text-fg-tertiary mb-1",children:"Team Name"}),Z?c.jsxs("div",{className:"flex gap-2 items-center",children:[c.jsx("input",{ref:me,value:ie,onChange:pe=>Q(pe.target.value),onKeyDown:pe=>pe.key==="Enter"&&H(),className:"flex-1 bg-surface-elevated border border-border-default rounded-lg px-3 py-1.5 text-sm text-fg-primary focus:outline-none focus:border-brand-500",autoFocus:!0}),c.jsx("button",{onClick:H,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-white",children:"Save"}),c.jsx("button",{onClick:()=>I(!1),className:"px-3 py-1.5 text-xs bg-surface-elevated hover:bg-surface-overlay rounded-lg text-fg-secondary",children:"Cancel"})]}):c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-sm",children:o.name}),c.jsx("button",{onClick:()=>{Q(o.name),I(!0)},className:"text-xs text-fg-tertiary hover:text-fg-secondary",children:"Edit"})]})]}),c.jsxs("div",{children:[c.jsx("div",{className:"text-xs text-fg-tertiary mb-1",children:"Description"}),X?c.jsxs("div",{className:"space-y-2",children:[c.jsx("textarea",{value:W,onChange:pe=>A(pe.target.value),className:"w-full bg-surface-elevated border border-border-default rounded-lg px-3 py-1.5 text-sm text-fg-primary resize-y focus:outline-none focus:border-brand-500",rows:3,autoFocus:!0}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx("button",{onClick:te,className:"px-3 py-1.5 text-xs bg-brand-600 hover:bg-brand-500 rounded-lg text-white",children:"Save"}),c.jsx("button",{onClick:()=>Y(!1),className:"px-3 py-1.5 text-xs bg-surface-elevated hover:bg-surface-overlay rounded-lg text-fg-secondary",children:"Cancel"})]})]}):c.jsxs("div",{className:"flex items-center gap-2",children:[c.jsx("span",{className:"text-sm text-fg-secondary",children:o.description||"No description"}),c.jsx("button",{onClick:()=>{A(o.description??""),Y(!0)},className:"text-xs text-fg-tertiary hover:text-fg-secondary",children:"Edit"})]})]})]}),c.jsx(Db,{teamId:s,teamName:o.name,onDeleted:e})]})]}),h&&c.jsx(Po,{alertOnly:!0,variant:h.variant??"primary",title:h.title,message:h.message,onConfirm:()=>d(null),onCancel:()=>d(null)})]})}function Sc({content:s,draft:e,setDraft:t,editing:r,setEditing:i,textareaRef:n,contentRef:a,saving:o,onSave:l,placeholder:h,emptyText:d}){return r?c.jsxs("div",{className:"flex flex-col h-full min-h-0",children:[c.jsx("textarea",{ref:n,value:e,onChange:u=>t(u.target.value),onBlur:()=>{e!==s?l():i(!1)},onKeyDown:u=>{u.key==="Escape"&&(u.preventDefault(),t(s),i(!1))},className:"flex-1 w-full bg-transparent border border-brand-500/30 rounded-lg text-sm text-fg-primary focus:border-brand-500 outline-none resize-none px-3 py-2 font-mono",placeholder:h}),o&&c.jsx("div",{className:"text-xs text-fg-tertiary mt-1 shrink-0",children:"Saving..."})]}):c.jsx("div",{ref:a,className:"group relative cursor-pointer rounded-lg px-1 py-1 hover:bg-surface-elevated/50 transition-colors min-h-[80px]",onClick:()=>{t(s),i(!0)},role:"button",tabIndex:0,onKeyDown:u=>{u.key==="Enter"&&(t(s),i(!0))},children:s.trim()?c.jsx(_.Suspense,{fallback:c.jsx("div",{className:"text-xs text-fg-tertiary",children:"Loading…"}),children:c.jsx(I4,{content:s,className:"text-sm text-fg-secondary leading-relaxed"})}):c.jsx("div",{className:"text-sm text-fg-tertiary italic",children:d})})}function Db({teamId:s,teamName:e,onDeleted:t}){const[r,i]=_.useState(!1),[n,a]=_.useState(!1),[o,l]=_.useState(!1),[h,d]=_.useState(!1);return c.jsxs("div",{className:"p-4 bg-surface-secondary rounded-xl border border-red-900/30 space-y-3",children:[c.jsx("div",{className:"text-sm font-medium text-red-500",children:"Danger Zone"}),r?c.jsxs("div",{className:"space-y-3",children:[c.jsxs("div",{className:"text-xs text-fg-secondary",children:['Delete team "',e,'"? This removes the team record from the database.']}),c.jsxs("label",{className:"flex items-center gap-2 text-xs text-fg-secondary cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:o,onChange:u=>l(u.target.checked),className:"rounded"}),"Also delete all members in this team"]}),c.jsxs("label",{className:"flex items-center gap-2 text-xs text-fg-secondary cursor-pointer",children:[c.jsx("input",{type:"checkbox",checked:n,onChange:u=>a(u.target.checked),className:"rounded"}),"Also delete disk files (workspace, memory, logs)"]}),c.jsxs("div",{className:"flex gap-2",children:[c.jsx("button",{disabled:h,onClick:async()=>{d(!0);try{await re.teams.delete(s,o,{purgeFiles:n}),window.dispatchEvent(new CustomEvent("markus:data-changed")),t()}catch{d(!1)}},className:"px-4 py-1.5 text-xs bg-red-600 hover:bg-red-700 text-white rounded-lg transition-colors disabled:opacity-50",children:h?"Deleting...":"Confirm Delete"}),c.jsx("button",{onClick:()=>i(!1),className:"px-4 py-1.5 text-xs bg-surface-elevated hover:bg-surface-overlay text-fg-secondary rounded-lg transition-colors border border-border-default",children:"Cancel"})]})]}):c.jsx("button",{onClick:()=>i(!0),className:"px-4 py-1.5 text-xs bg-red-600/20 hover:bg-red-600/30 text-red-500 rounded-lg transition-colors border border-red-500/30",children:"Delete Team"})]})}const B4=["chat","overview","deliverables"],W4=["chat","overview","announcements","norms","settings"];function X4(s,e){if(s==="chat")return e("page.chatTitle");if(Mp.find(i=>i.key===s))return e(`agent:tabs.${s}`);const r=Lp.find(i=>i.key===s);return r?e(r.labelKey):s}function z4(s){if(s==="chat")return"💬";const e=Mp.find(r=>r.key===s);if(e)return e.icon;const t=Lp.find(r=>r.key===s);return t?t.icon:""}function ri(s){return s!=="chat"}function Oa(s,e,t,r){return s==="channel"?`ch:${t}`:s==="dm"?`dm:${r??""}`:e||"_direct"}class Nr{currentConvKey="";loadingSession=null;msgBuffers=new Map;sessionMsgCache=new Map;activeSession=new Map;actBuffers=new Map;sessionTabs=new Map;phase=new Map;sendCount=new Map;streamingSessions=new Map;sessionCacheOrder=[];static MAX_MESSAGES=500;static MAX_CONVERSATIONS=20;static MAX_SESSION_CACHE=30;static NEW_CHAT_ID="__new_chat__";getPhase(e){return this.phase.get(e)??"idle"}beginLoad(e){this.getPhase(e)!=="streaming"&&this.phase.set(e,"loading")}completeLoad(e){this.getPhase(e)==="loading"&&this.phase.set(e,"ready")}beginStream(e){this.phase.set(e,"streaming")}endStream(e){this.getPhase(e)==="streaming"&&this.phase.set(e,"ready")}resetConv(e,t){this.phase.set(e,"idle"),this.activeSession.delete(e),t&&this.activeSession.set(e,t)}updateMessages(e,t,r){const i=this.activeSession.get(e),n=this.isDisplayRoute(e,i,r),a=n?this.msgBuffers.get(e)??[]:this.sessionMsgCache.get(r)??[];let o=t(a);o.length>Nr.MAX_MESSAGES&&(o=o.slice(-500));let l=!1;return n&&(this.msgBuffers.set(e,o),this.evictIfNeeded(e),l=this.currentConvKey===e),r&&r!==Nr.NEW_CHAT_ID&&(this.sessionMsgCache.set(r,o),this.touchSessionCache(r)),{displayChanged:l,newMessages:l?o:void 0}}isDisplayRoute(e,t,r){if(!r)return!0;if(t!==void 0&&t!==Nr.NEW_CHAT_ID)return t===r;const i=this.msgBuffers.get(e)??[];for(let n=i.length-1;n>=Math.max(0,i.length-3);n--){const a=i[n];if(a?.sender==="agent"&&a.isStreaming&&!a.isStopped)return!0}return!1}applyLoadResult(e,t,r){const i=this.sessionMsgCache.get(t),n=this.isCacheFresher(t,r);n||(this.sessionMsgCache.set(t,r),this.touchSessionCache(t));const o=this.getPhase(e)==="streaming",l=this.streamingSessions.get(e),h=o&&(l?.size??0)>0&&!l.has(t),d=this.activeSession.get(e);if(this.currentConvKey===e&&(this.loadingSession===t||d===t)&&(!o||h)){const f=this.mergeDbWithCache(r,n?i:void 0);return this.msgBuffers.set(e,f),this.loadingSession=t,this.completeLoad(e),{displayChanged:!0,newMessages:f}}return{displayChanged:!1}}mergeDbWithCache(e,t){if(!t||t.length===0)return[...e];const r=new Set,i=[];for(const o of e)r.add(o.id),i.push(o);const n=[],a=[];for(const o of t)r.has(o.id)||(o.sender==="agent"&&o.isStreaming?(n.push(o),r.add(o.id)):a.push(o));for(const o of a){if(r.has(o.id))continue;const l=o.rawCreatedAt?Date.parse(o.rawCreatedAt):NaN;let h=i.length;for(;h>0&&i[h-1].rawCreatedAt&&Number.isFinite(l);){const d=Date.parse(i[h-1].rawCreatedAt);if(!Number.isFinite(d)||d<=l)break;h--}i.splice(h,0,o),r.add(o.id)}for(const o of n)i.push(o);return i}appendActivity(e,t,r){const i=r??e,n=[...this.actBuffers.get(i)??[],t];if(this.actBuffers.set(i,n),this.currentConvKey!==e)return{displayChanged:!1};const a=this.activeSession.get(e);return!r||!a||a===r?{displayChanged:!0,newActivities:n}:{displayChanged:!1}}getActiveSession(e){return this.activeSession.get(e)}setActiveSession(e,t){this.activeSession.set(e,t)}clearActiveSession(e){this.activeSession.delete(e)}saveToCache(e,t){if(!t||t===Nr.NEW_CHAT_ID)return;const r=this.msgBuffers.get(e);r&&r.length>0&&(this.sessionMsgCache.set(t,r),this.touchSessionCache(t))}restoreFromCache(e,t){const r=this.sessionMsgCache.get(t);if(r&&r.length>0)return this.msgBuffers.set(e,r),r;this.msgBuffers.delete(e)}isCacheFresher(e,t){const r=this.sessionMsgCache.get(e);if(!r||r.length===0)return!1;if(r.length>t.length)return!0;const i=r.reduce((l,h)=>l+h.text.length,0),n=t.reduce((l,h)=>l+h.text.length,0);if(i>n)return!0;const a=r.reduce((l,h)=>l+(h.segments?.length??0),0),o=t.reduce((l,h)=>l+(h.segments?.length??0),0);return a>o}incrementSend(e){this.sendCount.set(e,(this.sendCount.get(e)??0)+1)}decrementSend(e){const t=Math.max(0,(this.sendCount.get(e)??1)-1);return this.sendCount.set(e,t),t}resetSend(e){this.sendCount.set(e,0)}isSending(e){return(this.sendCount.get(e)??0)>0}addStreamSession(e,t){const r=this.streamingSessions.get(e)??new Set;return r.has(t)?(this.streamingSessions.set(e,r),!1):(r.add(t),this.streamingSessions.set(e,r),!0)}removeStreamSession(e,t){if(t){const r=this.streamingSessions.get(e);return!r||!r.has(t)?!1:(r.delete(t),r.size===0&&this.streamingSessions.delete(e),!0)}return this.streamingSessions.delete(e)}getStreamSessions(e){return this.streamingSessions.get(e)}abortStream(e,t){let r=!1;(this.sendCount.get(e)??0)>0&&(this.sendCount.set(e,0),r=!0);const i=t??e;if(this.actBuffers.delete(i)&&(r=!0),this.getPhase(e)==="streaming"&&(this.phase.set(e,"ready"),r=!0),t){const n=this.streamingSessions.get(e)?.has(t)??!1;this.removeStreamSession(e,t),n&&(r=!0)}else this.streamingSessions.delete(e)&&(r=!0);return r}getMessages(e){return this.msgBuffers.get(e)}getActivities(e){return this.actBuffers.get(e)??[]}deleteBuffer(e){this.msgBuffers.delete(e)}evictIfNeeded(e){if(this.msgBuffers.size<=Nr.MAX_CONVERSATIONS)return;const t=[...this.msgBuffers.keys()],r=t.filter(i=>i!==e&&i!==this.currentConvKey).slice(0,t.length-Nr.MAX_CONVERSATIONS);for(const i of r)this.msgBuffers.delete(i),this.actBuffers.delete(i),this.sessionTabs.delete(i),this.activeSession.delete(i)}touchSessionCache(e){const t=this.sessionCacheOrder.indexOf(e);for(t!==-1&&this.sessionCacheOrder.splice(t,1),this.sessionCacheOrder.push(e);this.sessionCacheOrder.length>Nr.MAX_SESSION_CACHE;){const r=this.sessionCacheOrder.shift();if(new Set(this.activeSession.values()).has(r)){this.sessionCacheOrder.push(r);break}this.sessionMsgCache.delete(r)}}}const pt=Nr.NEW_CHAT_ID,_c=s=>!!s&&!s.startsWith("ch:")&&!s.startsWith("dm:")&&s!=="_direct";function q4(s){const e=_.useRef(new Nr),[t,r]=_.useState(s??[]),[i,n]=_.useState(!1),[a,o]=_.useState([]),l=_.useRef(null),[,h]=_.useState(0),d=_.useCallback(()=>h(j=>j+1),[]),u=_.useCallback(j=>e.current.getStreamSessions(j),[]),f=_.useCallback((j,M)=>{const L=e.current.addStreamSession(j,M);_c(j)&&sr.markAgentStreaming(j,!0),L&&d()},[d]),p=_.useCallback((j,M)=>{const L=e.current.removeStreamSession(j,M);_c(j)&&sr.markAgentStreaming(j,!1),L&&d()},[d]),b=_.useCallback((j,M)=>e.current.setActiveSession(j,M),[]),v=_.useCallback(j=>e.current.clearActiveSession(j),[]);_.useEffect(()=>()=>{l.current!==null&&cancelAnimationFrame(l.current)},[]);const g=_.useCallback((j,M,L)=>{const E=e.current.updateMessages(j,M,L);E.displayChanged&&E.newMessages&&r(E.newMessages)},[]),O=_.useCallback((j,M,L)=>{e.current.updateMessages(j,M,L).displayChanged&&l.current===null&&(l.current=requestAnimationFrame(()=>{l.current=null;const B=e.current.getMessages(j);B&&e.current.currentConvKey===j&&r([...B])}))},[]),m=_.useCallback((j,M,L)=>{const E=e.current.appendActivity(j,M,L);E.displayChanged&&E.newActivities&&o(E.newActivities)},[]),x=_.useCallback(j=>e.current.getPhase(j),[]),y=_.useCallback(j=>e.current.beginLoad(j),[]),w=_.useCallback(j=>{e.current.beginStream(j),_c(j)&&sr.markAgentStreaming(j,!0)},[]),C=_.useCallback(j=>{e.current.endStream(j)},[]),P=_.useCallback((j,M)=>{const L=e.current.abortStream(j,M);L&&_c(j)&&sr.markAgentStreaming(j,!1),L&&d(),e.current.currentConvKey===j&&(n(!1),o([]))},[d]),S=_.useCallback((j,M)=>{e.current.resetConv(j,M),e.current.deleteBuffer(j)},[]),T=_.useCallback(async(j,M,L)=>{e.current.loadingSession=j,e.current.beginLoad(M);try{const E=await L(),B=e.current.applyLoadResult(M,j,E.messages);return B.displayChanged&&B.newMessages&&r(B.newMessages),{count:E.messages.length,hasMore:E.hasMore,oldestCursor:E.oldestCursor}}catch{return e.current.currentConvKey===M&&e.current.getPhase(M)!=="streaming"&&(r([]),e.current.completeLoad(M)),{count:0,hasMore:!1,oldestCursor:null}}},[]);return{manager:e.current,messages:t,setMessages:r,sending:i,setSending:n,activities:a,setActivities:o,get msgBuffers(){return e.current.msgBuffers},get sessionMsgCache(){return e.current.sessionMsgCache},get activeSessionBuffer(){return e.current.activeSession},get actBuffers(){return e.current.actBuffers},get sessionTabsBuffer(){return e.current.sessionTabs},get currentConvKeyRef(){return{get current(){return e.current.currentConvKey},set current(j){e.current.currentConvKey=j}}},get loadingSessionRef(){return{get current(){return e.current.loadingSession},set current(j){e.current.loadingSession=j}}},updateConvMsgs:g,updateConvMsgsRaf:O,appendConvActivity:m,getPhase:x,beginLoad:y,beginStream:w,endStream:C,resetConv:S,abortStream:P,loadAndDisplay:T,setActiveSession:b,clearActiveSession:v,incrementSending:j=>e.current.incrementSend(j),decrementSending:j=>e.current.decrementSend(j),resetSending:j=>e.current.resetSend(j),isSendingFor:j=>e.current.isSending(j),setStreamSession:f,clearStreamSession:p,getStreamSession:u,saveSessionToCache:(j,M)=>e.current.saveToCache(j,M),restoreSessionFromCache:(j,M)=>{const L=e.current.restoreFromCache(j,M);return r(L??[]),L},isSessionCacheFresherThanDb:(j,M)=>e.current.isCacheFresher(j,M)}}function Z4(s){const e=_.useRef(null),t=_.useRef(null),r=_.useRef(new Map),i=_.useRef(new Set),n=_.useRef(null),a=_.useRef(new Map),o=_.useRef(0),{stateRef:l}=s,{msgBuffers:h,actBuffers:d,sessionMsgCache:u,activeSessionBuffer:f,currentConvKeyRef:p,updateConvMsgs:b,updateConvMsgsRaf:v,appendConvActivity:g,beginStream:O,endStream:m,abortStream:x,clearStreamSession:y,setStreamSession:w,getStreamSession:C,setActiveSession:P,incrementSending:S,decrementSending:T,loadAndDisplay:j,thinkingTimeoutRef:M,sessionSwitchSeqRef:L,oldestMsgId:E,setSending:B,setActivities:U,setInput:Z,setChatContext:I,setPendingImages:ie,setMentionDropdown:Q,setChatReplyTo:W,setActiveSessionId:A,setStoredActiveSession:X,setOpenSessionTabs:Y,setSessions:se,setLoadingChat:ee,setHasMore:me,setThinkingAgents:V,makeConvKey:N,makeDmChannel:ne,addRecentMsgId:H,resumeChatScrollFollow:te,loadSessions:J}=s,{t:ge}=s,Qe=_.useCallback(async(Ae,ke)=>{const oe=L.current,dt=p.current===ke&&(h.get(ke)?.length??0)===0;dt&&ee(!0);try{const{count:Ge,hasMore:Ke,oldestCursor:Ot}=await j(Ae,ke,async()=>{const rt=await re.sessions.getMessages(Ae,50);return{messages:nk(rt.messages.map(ef).filter($e=>$e.sender!=="agent"||$e.text||$e.segments&&$e.segments.length>0||$e.isStreaming)),hasMore:rt.hasMore,oldestCursor:rt.messages[0]?new Date(rt.messages[0].createdAt).toISOString():null}});return me(Ke),E.current=Ot,Ge}finally{dt&&p.current===ke&&L.current===oe&&ee(!1)}},[j,h,L]),_e=()=>{const Ae=l.current.chatMode==="direct"?l.current.selectedAgent:null;if(Ae){const ke=l.current.activeSessionId,oe=ke&&ke!==pt?{sessionId:ke}:void 0;re.agents.cancelProcessing(Ae,oe).catch(()=>{})}e.current?.abort(),e.current=null,t.current?.abort(),t.current=null,Ae&&l.current.activeSessionId&&l.current.activeSessionId!==pt&&i.current.add(l.current.activeSessionId),x(p.current,l.current.activeSessionId)},pe=_.useCallback(async(Ae,ke,oe)=>{if(!Ae||!ke||ke===pt||i.current.has(ke))return;let dt=null;try{if(e.current&&!e.current.signal.aborted&&C(oe)?.has(ke)){p.current===oe&&B(!0);return}const Ge=()=>{const Me=C(oe);Me&&Me.size>0||(y(oe,ke),p.current===oe&&(B(!1),b(oe,Ne=>Xg(Ne),ke)))},Ke=`${Ae}:${ke}`,Ot=r.current.get(Ke)??0;if(Date.now()-Ot<1500){Ge();return}r.current.set(Ke,Date.now());const rt=await re.sessions.streamStatus(Ae,ke),qt=h.get(oe)??[],$e=ok(qt),ut=rt.status==="streaming",as=!!rt.active&&(rt.status==="done"||rt.status==="error")&&!!$e?.isStreaming;if(!ut&&!as){Ge();return}r.current.set(Ke,Date.now()),t.current?.abort(),dt=new AbortController,t.current=dt,O(oe),B(!0),w(oe,ke);let mt=$e?.id;if(!$e||$e.isError)mt=`reattach_${Date.now()}`,b(oe,Me=>[...Me,{id:mt,sender:"agent",text:"",time:new Date().toLocaleTimeString(),isStreaming:!0,segments:[]}],ke);else{const Me=($e.segments??[]).filter(Ne=>Ne.type==="tool").map(Ne=>Ne.status==="stopped"||Ne.status==="running"?{...Ne,status:"running"}:Ne);b(oe,Ne=>Ne.map(Ce=>Ce.id===$e.id?{...Ce,text:"",isStreaming:!0,isStopped:!1,segments:Me,committedSegments:void 0}:Ce),ke)}const wt=Me=>{p.current===oe&&(o.current=Date.now(),v(oe,Ne=>{const Ce=[...Ne],Ve=mt?Ce.findIndex(fe=>fe.id===mt):-1,G=Ve>=0?Ve:Ce.map((fe,Pe)=>({m:fe,j:Pe})).reverse().find(fe=>fe.m.sender==="agent"&&fe.m.isStreaming)?.j??-1;if(G<0)return Ne;const K=Ce[G];return Ce[G]={...K,text:(K.text??"")+Me,segments:zg(K.segments??[],Me),isStreaming:!0},Ce},ke))},De=Me=>{p.current===oe&&(o.current=Date.now(),v(oe,Ne=>{const Ce=[...Ne],Ve=mt?Ce.findIndex(fe=>fe.id===mt):-1,G=Ve>=0?Ve:Ce.map((fe,Pe)=>({m:fe,j:Pe})).reverse().find(fe=>fe.m.sender==="agent"&&fe.m.isStreaming)?.j??-1;if(G<0)return Ne;const K=Ce[G];return Ce[G]={...K,segments:qg(K.segments??[],Me),isStreaming:!0},Ce},ke))},Nt=Me=>{if(p.current===oe&&(o.current=Date.now(),Me.phase!=="heartbeat")){if((Me.phase==="start"||Me.phase==="end")&&g(oe,{...Me,phase:Me.phase,ts:Date.now()},ke),Me.phase==="start"){const Ne=`${Me.tool}_${Date.now()}`,Ce=new Date().toISOString(),Ve=G=>{const K=[...G];for(let fe=K.length-1;fe>=0;fe--){const Pe=K[fe];if(Pe.type==="tool"&&Pe.tool===Me.tool&&(Pe.status==="running"||Pe.status==="stopped"))return K[fe]={...Pe,status:"running",args:Me.arguments??Pe.args},K}return K.push({type:"tool",key:Ne,tool:Me.tool,status:"running",args:Me.arguments,createdAt:Ce}),K};b(oe,G=>{const K=[...G],fe=mt?K.findIndex(ae=>ae.id===mt):-1;if(fe<0)return G;const Pe=Ve(K[fe].segments??[]),ze=K[fe].committedSegments,xt=ze&&Ve(ze);return K[fe]={...K[fe],segments:Pe,committedSegments:xt,isStreaming:!0},K},ke)}else if(Me.phase==="end"){const Ne=new Date().toISOString(),Ce=Ve=>{const G=[...Ve];for(let K=G.length-1;K>=0;K--){const fe=G[K];if(fe.type==="tool"&&fe.tool===Me.tool&&(fe.status==="running"||fe.status==="stopped")){G[K]={...fe,status:Me.success===!1?"error":"done",args:Me.arguments??fe.args,result:Me.result,error:Me.error,durationMs:Me.durationMs,liveOutput:void 0,createdAt:Ne};break}}return G};b(oe,Ve=>{const G=[...Ve],K=mt?G.findIndex(xt=>xt.id===mt):-1;if(K<0)return Ve;const fe=Ce(G[K].segments??[]),Pe=G[K].committedSegments,ze=Pe&&Ce(Pe);return G[K]={...G[K],segments:fe,committedSegments:ze,isStreaming:!0},G},ke)}else if(Me.phase==="subagent_progress"&&Me.subagentEvent){const Ne=Ce=>{const Ve=[...Ce];for(let G=Ve.length-1;G>=0;G--){const K=Ve[G];if(K.type==="tool"&&(K.tool==="spawn_subagent"||K.tool==="spawn_subagents")&&(K.status==="running"||K.status==="stopped")){Ve[G]={...K,status:"running",subagentLogs:Zg(K.subagentLogs,Me.subagentEvent)};break}}return Ve};v(oe,Ce=>{const Ve=[...Ce],G=mt?Ve.findIndex(ze=>ze.id===mt):-1;if(G<0)return Ce;const K=Ne(Ve[G].segments??[]),fe=Ve[G].committedSegments,Pe=fe&&Ne(fe);return Ve[G]={...Ve[G],segments:K,committedSegments:Pe,isStreaming:!0},Ve},ke)}}},et=Me=>{p.current===oe&&(o.current=Date.now(),b(oe,Ne=>{const Ce=[...Ne],Ve=mt?Ce.findIndex(K=>K.id===mt):-1;if(Ve<0)return Ne;const G=[...Ce[Ve].committedSegments??[]];if(Me.type==="thinking_commit")G.push({type:"text",content:"",thinking:Me.content,createdAt:Me.createdAt});else if(Me.type==="text_commit")G.push({type:"text",content:Me.content,createdAt:Me.createdAt});else return Ne;return Ce[Ve]={...Ce[Ve],committedSegments:G,isStreaming:!0},Ce},ke))},ct=Me=>{if(p.current!==oe)return;o.current=Date.now();const Ne=(Me.segments??[]).map((Ce,Ve)=>Ce.type==="tool"?{type:"tool",key:`${Ce.tool}_${Ve}`,tool:Ce.tool??"tool",status:Ce.status==="error"?"error":Ce.status==="running"||Ce.status==="stopped"?"running":"done",args:Ce.arguments,result:Ce.result,error:Ce.error,durationMs:Ce.durationMs,createdAt:Ce.createdAt,...Ce.subagentLogs?.length?{subagentLogs:Ce.subagentLogs}:{}}:{type:"text",content:Ce.content??"",thinking:Ce.thinking,createdAt:Ce.createdAt});b(oe,Ce=>{const Ve=[...Ce],G=mt?Ve.findIndex(K=>K.id===mt):-1;return G<0?Ce:(Ve[G]={...Ve[G],text:Me.content||Ve[G].text,segments:Ne,committedSegments:Ne,isStreaming:!0,isStopped:!1},Ve)},ke);for(const Ce of Ne)Ce.type==="tool"&&g(oe,{tool:Ce.tool,phase:Ce.status==="running"||Ce.status==="stopped"?"start":"end",success:Ce.status!=="error",arguments:Ce.args,result:Ce.result,error:Ce.error,durationMs:Ce.durationMs,ts:Date.now()},ke)},kt=await re.sessions.reattachStream(Ae,ke,{onChunk:wt,onThinking:De,onActivity:Nt,onCommit:et,onSnapshot:ct},dt.signal,0);if(!kt.attached){m(oe),y(oe,ke),p.current===oe&&(b(oe,Me=>{const Ne=[...Me],Ce=mt?Ne.findIndex(K=>K.id===mt):-1,Ve=Ce>=0?Ce:Ne.map((K,fe)=>({m:K,j:fe})).reverse().find(K=>K.m.sender==="agent"&&K.m.isStreaming)?.j??-1;if(Ve<0)return Me;const G=Ne[Ve];return G.isStreaming?(Ne[Ve]={...G,isStreaming:!1,isStopped:G.isError?G.isStopped:!0},Ne):Me},ke),B(!1));return}p.current===oe&&(b(oe,Me=>{const Ne=[...Me],Ce=mt?Ne.findIndex(fe=>fe.id===mt):-1,Ve=Ce>=0?Ce:Ne.map((fe,Pe)=>({m:fe,j:Pe})).reverse().find(fe=>fe.m.sender==="agent"&&fe.m.isStreaming)?.j??-1;if(Ve<0)return Me;const G=Ne[Ve];if(!G.isStreaming)return Me;const K=kt.segments?.length?Vg(kt.segments,G.segments):void 0;return Ne[Ve]={...G,text:kt.content||G.text,isStreaming:!1,isStopped:!1,...K?{segments:K,committedSegments:K}:{}},Ne},ke),B(!1)),m(oe),y(oe,ke),t.current===dt&&(t.current=null)}catch(Ge){const Ke=t.current===dt;if(Ke&&(t.current=null),m(oe),y(oe,ke),p.current===oe&&(B(!1),Ke&&b(oe,Ot=>Xg(Ot),ke)),Ge instanceof Error&&Ge.name==="AbortError")return}},[g,O,m,C,h,w,b,v]),be=_.useCallback(async(Ae,ke)=>{const oe=l.current,dt=!Ae&&oe.chatContext.length>0?oe.chatContext.map(wt=>wt.content).join(`
76
76
 
77
77
  `)+`
78
78