@agent-relay/dashboard-server 2.0.81 → 2.0.82
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.
- package/dist/mocks/fixtures.d.ts.map +1 -1
- package/dist/mocks/fixtures.js +23 -0
- package/dist/mocks/fixtures.js.map +1 -1
- package/dist/mocks/routes.d.ts.map +1 -1
- package/dist/mocks/routes.js +124 -0
- package/dist/mocks/routes.js.map +1 -1
- package/dist/mocks/types.d.ts +7 -0
- package/dist/mocks/types.d.ts.map +1 -1
- package/out/404.html +1 -1
- package/out/_next/static/chunks/{118-4c8241b0218335de.js → 118-ae2b650136a5a5fc.js} +1 -1
- package/out/_next/static/chunks/407-0c82986cf79c8ecb.js +1 -0
- package/out/_next/static/chunks/app/app/[[...slug]]/{page-1e81c047cff17212.js → page-f7eca1b66fb4249b.js} +1 -1
- package/out/_next/static/chunks/app/{page-6892fe2dd07fb48b.js → page-0ee604f7070d14c0.js} +1 -1
- package/out/_next/static/css/8968d98ed4c4d33f.css +1 -0
- package/out/about.html +2 -2
- package/out/about.txt +1 -1
- package/out/app/onboarding.html +1 -1
- package/out/app/onboarding.txt +1 -1
- package/out/app.html +1 -1
- package/out/app.txt +2 -2
- package/out/blog/go-to-bed-wake-up-to-a-finished-product.html +2 -2
- package/out/blog/go-to-bed-wake-up-to-a-finished-product.txt +1 -1
- package/out/blog/let-them-cook-multi-agent-orchestration.html +2 -2
- package/out/blog/let-them-cook-multi-agent-orchestration.txt +2 -2
- package/out/blog.html +2 -2
- package/out/blog.txt +1 -1
- package/out/careers.html +2 -2
- package/out/careers.txt +1 -1
- package/out/changelog.html +2 -2
- package/out/changelog.txt +1 -1
- package/out/cloud/link.html +1 -1
- package/out/cloud/link.txt +2 -2
- package/out/complete-profile.html +2 -2
- package/out/complete-profile.txt +1 -1
- package/out/connect-repos.html +1 -1
- package/out/connect-repos.txt +1 -1
- package/out/contact.html +2 -2
- package/out/contact.txt +1 -1
- package/out/docs.html +2 -2
- package/out/docs.txt +1 -1
- package/out/history.html +1 -1
- package/out/history.txt +2 -2
- package/out/index.html +1 -1
- package/out/index.txt +2 -2
- package/out/login.html +2 -2
- package/out/login.txt +1 -1
- package/out/metrics.html +1 -1
- package/out/metrics.txt +2 -2
- package/out/pricing.html +2 -2
- package/out/pricing.txt +1 -1
- package/out/privacy.html +2 -2
- package/out/privacy.txt +1 -1
- package/out/providers/setup/claude.html +1 -1
- package/out/providers/setup/claude.txt +1 -1
- package/out/providers/setup/codex.html +1 -1
- package/out/providers/setup/codex.txt +1 -1
- package/out/providers/setup/cursor.html +1 -1
- package/out/providers/setup/cursor.txt +1 -1
- package/out/providers.html +1 -1
- package/out/providers.txt +1 -1
- package/out/security.html +2 -2
- package/out/security.txt +1 -1
- package/out/signup.html +2 -2
- package/out/signup.txt +1 -1
- package/out/terms.html +2 -2
- package/out/terms.txt +1 -1
- package/package.json +1 -1
- package/out/_next/static/chunks/285-dc644487a8d6500d.js +0 -1
- package/out/_next/static/css/4c58d9cf493aa626.css +0 -1
- /package/out/_next/static/{dYlczDQI12PIQ3tqq3N4Y → IxfA6RZu4trcsEMYlkQra}/_buildManifest.js +0 -0
- /package/out/_next/static/{dYlczDQI12PIQ3tqq3N4Y → IxfA6RZu4trcsEMYlkQra}/_ssgManifest.js +0 -0
- /package/out/_next/static/chunks/{528-d375bc8b46912d2c.js → 528-f5f676996d613c25.js} +0 -0
- /package/out/_next/static/chunks/app/blog/let-them-cook-multi-agent-orchestration/{page-a58308f43557b908.js → page-b194f207fbd91862.js} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[407],{7407:function(e,t,r){r.d(t,{fM:function(){return sz},gV:function(){return sG}});var n=r(7573),s=r(7653);function a(e){let{event:t,onClick:r}=e,s=function(e){switch(e){case"agent_spawned":return"\uD83D\uDE80";case"agent_released":return"\uD83D\uDED1";case"agent_online":return"\uD83D\uDFE2";case"agent_offline":return"⚫";case"user_joined":case"user_left":return"\uD83D\uDC4B";case"broadcast":return"\uD83D\uDCE2";case"error":return"⚠️";default:return"\uD83D\uDCCC"}}(t.type),a=function(e){switch(e){case"agent_spawned":case"agent_online":return"text-green-400";case"agent_released":return"text-red-400";case"agent_offline":case"user_left":return"text-gray-400";case"user_joined":return"text-cyan-400";case"broadcast":return"text-yellow-400";case"error":return"text-red-500";default:return"text-text-muted"}}(t.type);return(0,n.jsxs)("div",{className:"flex items-start gap-3 p-3 rounded-lg hover:bg-bg-hover transition-colors ".concat(r?"cursor-pointer":""),onClick:r,children:[(0,n.jsx)("div",{className:"flex-shrink-0 w-8 h-8 flex items-center justify-center",children:t.actorAvatarUrl?(0,n.jsx)("img",{src:t.actorAvatarUrl,alt:t.actor,className:"w-8 h-8 rounded-full"}):(0,n.jsx)("span",{className:"text-lg",children:s})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"font-medium ".concat(a),children:t.actor}),(0,n.jsx)("span",{className:"text-text-muted text-sm",children:t.title})]}),t.description&&(0,n.jsx)("p",{className:"text-text-muted text-sm mt-1 line-clamp-2",children:t.description}),t.metadata&&Object.keys(t.metadata).length>0&&(()=>{let e=t.metadata.cli,r=t.metadata.task;return(0,n.jsxs)("div",{className:"flex flex-wrap gap-1 mt-2",children:[null!=e&&(0,n.jsx)("span",{className:"px-2 py-0.5 bg-bg-secondary rounded text-xs text-text-muted",children:String(e)}),null!=r&&(0,n.jsx)("span",{className:"px-2 py-0.5 bg-bg-secondary rounded text-xs text-text-muted truncate max-w-[200px]",children:String(r)})]})})()]}),(0,n.jsx)("div",{className:"flex-shrink-0 text-xs text-text-muted",children:function(e){let t=new Date,r=new Date(e),n=Math.floor((t.getTime()-r.getTime())/1e3),s=Math.floor(n/60),a=Math.floor(s/60),l=Math.floor(a/24);return n<60?"just now":s<60?"".concat(s,"m ago"):a<24?"".concat(a,"h ago"):l<7?"".concat(l,"d ago"):r.toLocaleDateString()}(t.timestamp)})]})}function l(){return(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-full text-center p-8",children:[(0,n.jsx)("div",{className:"text-4xl mb-4",children:"\uD83D\uDCCB"}),(0,n.jsx)("h3",{className:"text-lg font-medium text-text-primary mb-2",children:"No activity yet"}),(0,n.jsx)("p",{className:"text-text-muted text-sm max-w-xs",children:"Activity will appear here as agents spawn, users join, and broadcasts are sent."})]})}function o(e){let{events:t,maxEvents:r=100,onEventClick:o}=e,i=(0,s.useMemo)(()=>[...t].sort((e,t)=>new Date(t.timestamp).getTime()-new Date(e.timestamp).getTime()).slice(0,r),[t,r]);return 0===i.length?(0,n.jsx)(l,{}):(0,n.jsxs)("div",{className:"flex flex-col h-full",children:[(0,n.jsxs)("div",{className:"flex-shrink-0 px-4 py-3 border-b border-border-subtle",children:[(0,n.jsx)("h2",{className:"text-lg font-semibold text-text-primary",children:"Activity"}),(0,n.jsxs)("p",{className:"text-sm text-text-muted",children:[i.length," event",1!==i.length?"s":""]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto px-2 py-2",children:(0,n.jsx)("div",{className:"space-y-1",children:i.map(e=>(0,n.jsx)(a,{event:e,onClick:o?()=>o(e):void 0},e.id))})})]})}let i="agent-relay-pinned-agents";var c=r(1841);let d={autoRefresh:!0,refreshInterval:3e4,autoWakeup:!1,onStatusChange:()=>{}};function u(){var e,t,r,n,a;let l=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},o=null!==(e=l.autoRefresh)&&void 0!==e?e:d.autoRefresh,i=null!==(t=l.refreshInterval)&&void 0!==t?t:d.refreshInterval,u=null!==(r=l.autoWakeup)&&void 0!==r?r:d.autoWakeup,x=(0,s.useRef)(null!==(n=l.onStatusChange)&&void 0!==n?n:d.onStatusChange);x.current=null!==(a=l.onStatusChange)&&void 0!==a?a:d.onStatusChange;let[m,h]=(0,s.useState)(null),[p,g]=(0,s.useState)(!1),[f,b]=(0,s.useState)(!0),[v,y]=(0,s.useState)(!1),[j,w]=(0,s.useState)(""),[N,k]=(0,s.useState)(null),[C,S]=(0,s.useState)(null),L=(0,s.useRef)(null),M=(0,s.useRef)(!0),D=(0,s.useRef)(null),A=(0,s.useCallback)(async()=>{try{b(!0),S(null);let e=await c.xv.getPrimaryWorkspace();if(!M.current)return;if(e.success){if(g(e.data.exists),w(e.data.statusMessage),k(e.data.actionNeeded||null),e.data.workspace){let t=e.data.workspace;h(t),D.current&&D.current!==t.status&&x.current(t.status,!1),D.current=t.status}else h(null)}else S(e.error)}catch(e){M.current&&S("Failed to fetch workspace status")}finally{M.current&&b(!1)}},[]),E=(0,s.useRef)(i);E.current=i;let T=(0,s.useRef)(o);T.current=o;let W=(0,s.useCallback)(async()=>{if(!(null==m?void 0:m.id))return{success:!1,message:"No workspace to wake up"};try{y(!0),S(null);let e=await c.xv.wakeupWorkspace(m.id);if(!M.current)return{success:!1,message:"Component unmounted"};if(e.success)return e.data.wasRestarted&&(w(e.data.message),k(null),x.current("starting",!0),L.current&&clearInterval(L.current),L.current=setInterval(A,5e3),setTimeout(()=>{M.current&&L.current&&(clearInterval(L.current),T.current&&(L.current=setInterval(A,E.current)))},12e4)),{success:!0,message:e.data.message};return S(e.error),{success:!1,message:e.error}}catch(t){let e=t instanceof Error?t.message:"Failed to wake up workspace";return M.current&&S(e),{success:!1,message:e}}finally{M.current&&y(!1)}},[null==m?void 0:m.id,A]);return(0,s.useEffect)(()=>(M.current=!0,A(),()=>{M.current=!1}),[A]),(0,s.useEffect)(()=>{if(o)return L.current=setInterval(A,i),()=>{L.current&&(clearInterval(L.current),L.current=null)}},[o,i,A]),(0,s.useEffect)(()=>{u&&(null==m?void 0:m.isStopped)&&!v&&W()},[u,null==m?void 0:m.isStopped,v,W]),{workspace:m,exists:p,isLoading:f,isWakingUp:v,statusMessage:j,actionNeeded:N,error:C,refresh:A,wakeup:W}}var x=r(5493);function m(e){let t=new Map;for(let r of e){let e=r.team||(0,x.oU)(r.name),n=(0,x.GW)(r.name),s=t.get(e);s||(s={prefix:e,displayName:f(e),color:n,agents:[],isExpanded:!0},t.set(e,s)),s.agents.push(r)}let r=Array.from(t.values()).sort((e,t)=>e.prefix.localeCompare(t.prefix));for(let e of r)e.agents.sort((e,t)=>e.name.localeCompare(t.name));return r}function h(e){let t=e.split("-").filter(Boolean);return 0===t.length?e:f(t[t.length-1])}function p(e){return e.split("-").filter(Boolean).map(f).join(" > ")}function g(e,t){return t?e.filter(e=>(function(e,t){if(!t)return!0;let r=t.toLowerCase(),n=e.toLowerCase();return!!n.includes(r)||n.split("-").some(e=>e.includes(r))})(e.name,t)):e}function f(e){return e?e.charAt(0).toUpperCase()+e.slice(1):e}function b(e){let t=0,r=0,n=0;for(let s of e)"online"===s.status?t++:"offline"===s.status&&r++,s.needsAttention&&n++;return{total:e.length,online:t,offline:r,needsAttention:n}}function v(e){let{isProcessing:t,processingStartedAt:r,size:a="medium",showElapsed:l=!1,showLabel:o=!1}=e,[i,c]=(0,s.useState)(0);if((0,s.useEffect)(()=>{if(!t||!r){c(0);return}let e=()=>{c(Date.now()-r)};e();let n=setInterval(e,1e3);return()=>clearInterval(n)},[t,r]),!t)return null;let d={small:"w-1 h-1",medium:"w-1.5 h-1.5",large:"w-2 h-2"};return(0,n.jsxs)("span",{className:"inline-flex items-center gap-1.5 text-accent-purple",title:"Processing...",children:[(0,n.jsxs)("span",{className:"inline-flex items-center ".concat({small:"gap-0.5",medium:"gap-1",large:"gap-1.5"}[a]),children:[(0,n.jsx)("span",{className:"".concat(d[a]," rounded-full bg-accent-purple animate-bounce"),style:{animationDelay:"0ms",animationDuration:"800ms"}}),(0,n.jsx)("span",{className:"".concat(d[a]," rounded-full bg-accent-purple animate-bounce"),style:{animationDelay:"150ms",animationDuration:"800ms"}}),(0,n.jsx)("span",{className:"".concat(d[a]," rounded-full bg-accent-purple animate-bounce"),style:{animationDelay:"300ms",animationDuration:"800ms"}})]}),o&&(0,n.jsx)("span",{className:"text-xs font-medium text-accent-purple",children:"thinking"}),l&&i>0&&(0,n.jsx)("span",{className:"text-xs text-accent-purple/70",children:(e=>{let t=Math.floor(e/1e3);return t<60?"".concat(t,"s"):"".concat(Math.floor(t/60),"m ").concat(t%60,"s")})(i)})]})}function y(e){let{isProcessing:t}=e;return t?(0,n.jsx)("span",{className:"thinking-dot-inline",title:"Processing...",children:(0,n.jsx)("span",{className:"thinking-dot-pulse"})}):null}function j(e){if(e<6e4)return"<1m";let t=Math.floor(e/6e4);if(t<60)return"".concat(t,"m");let r=Math.floor(t/60),n=t%60;return 0===n?"".concat(r,"h"):"".concat(r,"h ").concat(n,"m")}function w(e){var t,r,s,a,l,o;let{agent:i,isSelected:c=!1,showBreadcrumb:d=!1,compact:u=!1,displayNameOverride:m,isPinned:g=!1,isMaxPinned:f=!1,onClick:b,onMessageClick:w,onReleaseClick:D,onLogsClick:A,onProfileClick:E,onPinToggle:T}=e,W=(0,x.GW)(i.name),P=(0,x.hP)(i.name),R=m||h(i.name),I=!i.lastMessageReceivedAt||i.lastOutputAt&&i.lastOutputAt>=i.lastMessageReceivedAt?0:Date.now()-i.lastMessageReceivedAt,B=i.isStuck||I>0,F=B?x.yh.stuck:x.yh[i.status]||x.yh.offline,U="online"===i.status,_=function(e,t,r,n){if(r&&n)return"Stuck - Agent received message ".concat(j(n)," ago but hasn't responded");if(t)return"Processing - Agent is actively working";switch(e){case"online":return"Connected - Agent is online and ready";case"offline":return"Disconnected - Agent is not connected";case"busy":return"Busy - Agent is occupied with a task";case"processing":return"Processing - Agent is actively working";case"error":return"Error - Agent encountered an error";case"attention":return"Attention - Agent requires user input";case"stuck":return"Stuck - Agent may be blocked or unresponsive";default:return"Status: ".concat(e)}}(i.status,i.isProcessing,B,I),O=()=>{null==b||b(i)},H=e=>{e.stopPropagation(),null==D||D(i)},z=e=>{e.stopPropagation(),null==A||A(i)},G=e=>{e.stopPropagation(),null==E||E(i)},V=e=>{e.stopPropagation(),null==T||T(i)};return u?(0,n.jsxs)("div",{className:"\n group relative flex items-start gap-3 py-2.5 px-3 rounded-lg cursor-pointer\n transition-all duration-300 ease-out\n hover:bg-bg-hover\n ".concat(c?"bg-bg-active":"","\n "),onClick:O,style:{borderLeft:c?"2px solid ".concat(W.primary):"2px solid transparent",boxShadow:c?"inset 4px 0 12px -4px ".concat(W.primary,"40"):"none"},children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsxs)("div",{className:"\n w-8 h-8 rounded-lg flex items-center justify-center font-bold text-[11px] tracking-wide\n transition-all duration-300 relative overflow-hidden\n ".concat(U?"shadow-lg":"opacity-60","\n "),style:{background:"linear-gradient(135deg, ".concat(W.primary,", ").concat(W.primary,"99)"),boxShadow:U?"0 2px 12px ".concat(W.primary,"50"):"none"},children:[(0,n.jsx)("div",{className:"absolute inset-0 opacity-30",style:{background:"linear-gradient(135deg, rgba(255,255,255,0.3) 0%, transparent 50%)"}}),(0,n.jsx)("span",{className:"relative z-10",style:{color:W.text},children:P})]}),U&&(0,n.jsx)("div",{className:"absolute -bottom-0.5 -right-0.5 w-3 h-3 rounded-full border-2 border-bg-primary",style:{backgroundColor:F,boxShadow:"0 0 8px ".concat(F)},title:_})]}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-start gap-1.5 flex-wrap",children:[(0,n.jsx)("span",{className:"\n text-[13px] font-semibold tracking-tight transition-colors duration-200\n whitespace-normal break-words leading-snug\n ".concat(U?"text-text-primary":"text-text-secondary","\n "),children:R}),i.isLocal&&(0,n.jsx)("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-[9px] font-medium uppercase tracking-wider bg-warning-light text-warning border border-warning/30",title:"Local agent from ".concat(i.daemonName||"linked daemon"),children:"Local"}),g&&(0,n.jsx)("span",{className:"inline-flex items-center text-amber-400",title:"Pinned to top",children:(0,n.jsx)(M,{size:12,filled:!0})})]}),i.cli&&(0,n.jsx)("span",{className:"text-[10px] text-text-muted truncate font-mono opacity-70 mt-0.5",children:i.cli}),(i.model||(null===(a=i.profile)||void 0===a?void 0:a.model))&&(0,n.jsx)("span",{className:"text-[9px] text-accent-muted font-mono opacity-80 mt-0.5",title:"Model: ".concat(i.model||(null===(l=i.profile)||void 0===l?void 0:l.model)),children:i.model||(null===(o=i.profile)||void 0===o?void 0:o.model)}),(0,n.jsxs)("div",{className:"mt-2 flex items-center flex-wrap gap-2",children:[T&&(0,n.jsx)("button",{className:"\n relative bg-transparent border border-transparent p-1.5 cursor-pointer\n flex items-center justify-center rounded-md transition-all duration-200\n ".concat(g?"text-amber-400 hover:bg-amber-400/10 hover:border-amber-400/30":"text-text-dim hover:bg-amber-400/10 hover:border-amber-400/30 hover:text-amber-400","\n ").concat(!g&&f?"opacity-40 cursor-not-allowed":"","\n "),onClick:V,title:g?"Unpin from top":f?"Maximum pins reached (5)":"Pin to top",disabled:!g&&f,children:(0,n.jsx)(M,{size:16,filled:g})}),E&&(0,n.jsx)("button",{className:"relative bg-transparent border border-transparent text-text-dim p-1.5 cursor-pointer flex items-center justify-center rounded-md transition-all duration-200 opacity-100 hover:bg-accent-purple/10 hover:border-accent-purple/30 hover:text-accent-purple",onClick:G,title:"View profile",children:(0,n.jsx)(L,{})}),A&&(0,n.jsx)("button",{className:"relative bg-transparent border border-transparent text-text-dim p-1.5 cursor-pointer flex items-center justify-center rounded-md transition-all duration-200 opacity-100 hover:bg-accent-cyan/10 hover:border-accent-cyan/30 hover:text-accent-cyan",onClick:z,title:"View logs",children:(0,n.jsx)(C,{})}),i.isSpawned&&D&&(0,n.jsx)("button",{className:"relative bg-transparent border border-transparent text-text-dim p-1.5 cursor-pointer flex items-center justify-center rounded-md transition-all duration-200 opacity-100 hover:bg-error/10 hover:border-error/30 hover:text-error",onClick:H,title:"Kill agent",children:(0,n.jsx)(k,{})}),i.isProcessing?(0,n.jsx)("div",{title:_,children:(0,n.jsx)(y,{isProcessing:!0})}):(0,n.jsx)("div",{className:"\n w-2 h-2 rounded-full transition-all duration-300\n ".concat(U?"animate-pulse":"","\n "),style:{backgroundColor:F,boxShadow:U?"0 0 6px ".concat(F):"none"},title:_}),B&&(0,n.jsxs)("div",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded bg-warning-light text-warning text-[10px] font-medium animate-pulse",title:_,children:[(0,n.jsx)(S,{}),(0,n.jsx)("span",{children:j(I)})]})]})]})]}):(0,n.jsxs)("div",{className:"\n rounded-lg p-3 cursor-pointer transition-all duration-200\n hover:shadow-md hover:-translate-y-px\n ".concat(c?"border-2 shadow-[0_0_0_2px_rgba(74,158,255,0.15)]":"border","\n "),onClick:O,style:{backgroundColor:W.light,borderColor:W.primary},children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsxs)("div",{className:"w-10 h-10 rounded-lg flex items-center justify-center font-semibold text-sm relative",style:{backgroundColor:W.primary},children:[(0,n.jsx)("span",{style:{color:W.text},children:P}),(0,n.jsx)("div",{className:"absolute -bottom-0.5 -right-0.5 w-3 h-3 rounded-full border-2 border-bg-secondary",style:{backgroundColor:F},title:_})]}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"font-semibold text-sm text-text-primary",children:R}),i.isLocal&&(0,n.jsx)("span",{className:"inline-flex items-center px-1.5 py-0.5 rounded text-[9px] font-medium uppercase tracking-wider bg-warning-light text-warning border border-warning/30",title:"Local agent from ".concat(i.daemonName||"linked daemon"),children:"Local"}),g&&(0,n.jsx)("span",{className:"inline-flex items-center text-amber-400",title:"Pinned to top",children:(0,n.jsx)(M,{size:14,filled:!0})}),i.needsAttention&&(0,n.jsx)("span",{className:"bg-error text-white text-[10px] font-bold w-4 h-4 rounded-full flex items-center justify-center",title:"Needs Attention - Agent requires user input or has pending decisions",children:"!"}),B&&(0,n.jsxs)("span",{className:"bg-warning text-white text-[10px] font-bold px-1.5 py-0.5 rounded flex items-center gap-1",title:_,children:[(0,n.jsx)(S,{})," ",j(I)]})]}),d?(0,n.jsx)("span",{className:"text-xs text-text-muted truncate block",children:i.isLocal?i.daemonName||i.machineId:p(i.name)}):(0,n.jsx)("span",{className:"text-xs text-text-muted truncate block",children:i.isLocal?i.daemonName||i.machineId:i.name}),i.agentId&&(0,n.jsxs)("span",{className:"text-[10px] text-text-muted font-mono opacity-70",title:"Agent ID (use to resume)",children:["ID: ",i.agentId]})]})]}),i.isProcessing&&(0,n.jsxs)("div",{className:"mt-2 p-2 bg-accent-light rounded flex items-center gap-2 border border-accent/20",children:[(0,n.jsx)(v,{isProcessing:!0,processingStartedAt:i.processingStartedAt,size:"medium",showElapsed:!0}),(0,n.jsx)("span",{className:"text-xs text-accent font-medium",children:"Thinking..."})]}),i.currentTask&&!i.isProcessing&&(0,n.jsxs)("div",{className:"mt-2 p-2 bg-bg-hover rounded text-xs",children:[(0,n.jsx)("span",{className:"text-text-muted mr-1",children:"Working on:"}),(0,n.jsx)("span",{className:"text-text-primary line-clamp-2",title:i.currentTask,children:i.currentTask})]}),(0,n.jsxs)("div",{className:"mt-3 flex justify-between items-center",children:[(0,n.jsxs)("div",{className:"flex gap-2 text-xs text-text-muted flex-wrap",children:[i.cli&&(0,n.jsx)("span",{className:"bg-bg-hover py-0.5 px-1.5 rounded",children:i.cli}),(i.model||(null===(t=i.profile)||void 0===t?void 0:t.model))&&(0,n.jsx)("span",{className:"bg-accent-cyan/10 text-accent-cyan py-0.5 px-1.5 rounded font-mono text-[10px]",title:"Model: ".concat(i.model||(null===(r=i.profile)||void 0===r?void 0:r.model)),children:i.model||(null===(s=i.profile)||void 0===s?void 0:s.model)}),void 0!==i.messageCount&&i.messageCount>0&&(0,n.jsxs)("span",{style:{color:W.primary},children:[i.messageCount," msgs"]}),i.isSpawned&&(0,n.jsx)("span",{className:"bg-accent-light text-accent text-[10px] py-0.5 px-1.5 rounded uppercase font-medium",children:"spawned"})]}),(0,n.jsxs)("div",{className:"flex gap-1.5",children:[T&&(0,n.jsx)("button",{className:"\n rounded-md py-1.5 px-2.5 cursor-pointer flex items-center justify-center gap-1 transition-all duration-200\n border\n ".concat(g?"bg-amber-500/10 text-amber-400 border-amber-500/30 hover:bg-amber-500/20":"bg-bg-tertiary text-text-muted border-border hover:bg-amber-500/10 hover:text-amber-400 hover:border-amber-500/30","\n ").concat(!g&&f?"opacity-40 cursor-not-allowed":"hover:scale-105","\n active:scale-[0.98]\n "),onClick:V,title:g?"Unpin from top":f?"Maximum pins reached (5)":"Pin to top",disabled:!g&&f,children:(0,n.jsx)(M,{size:16,filled:g})}),E&&(0,n.jsx)("button",{className:"bg-accent-purple/10 text-accent-purple border border-accent-purple/30 rounded-md py-1.5 px-2.5 cursor-pointer flex items-center justify-center gap-1 transition-all duration-200 hover:bg-accent-purple/20 hover:scale-105 active:scale-[0.98]",onClick:G,title:"View profile",children:(0,n.jsx)(L,{})}),A&&(0,n.jsx)("button",{className:"bg-accent-cyan/10 text-accent-cyan border border-accent-cyan/30 rounded-md py-1.5 px-2.5 cursor-pointer flex items-center justify-center gap-1 transition-all duration-200 hover:bg-accent-cyan/20 hover:scale-105 active:scale-[0.98]",onClick:z,title:"View logs",children:(0,n.jsx)(C,{})}),i.isSpawned&&D&&(0,n.jsx)("button",{className:"bg-error/10 text-error border border-error/30 rounded-md py-1.5 px-2.5 cursor-pointer flex items-center justify-center gap-1 transition-all duration-200 hover:bg-error/20 hover:scale-105 active:scale-[0.98]",onClick:H,title:"Release agent",children:(0,n.jsx)(k,{})}),w&&(0,n.jsx)("button",{className:"text-white border-none rounded py-1 px-2 cursor-pointer flex items-center justify-center transition-opacity duration-200 hover:opacity-90",style:{backgroundColor:W.primary},onClick:e=>{e.stopPropagation(),null==w||w(i)},title:"Send message",children:(0,n.jsx)(N,{})})]})]})]})}function N(){return(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.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"})})}function k(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",className:"release-icon",children:[(0,n.jsx)("path",{d:"M12 22c5.523 0 10-4.477 10-10a9.96 9.96 0 0 0-3-7.141",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),(0,n.jsx)("path",{d:"M12 22C6.477 22 2 17.523 2 12a9.96 9.96 0 0 1 3-7.141",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"}),(0,n.jsx)("line",{x1:"12",y1:"2",x2:"12",y2:"12",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round"})]})}function C(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,n.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]})}function S(){return(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,n.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}function L(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"}),(0,n.jsx)("circle",{cx:"12",cy:"7",r:"4"})]})}function M(e){let{size:t=16,filled:r=!1}=e;return(0,n.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:r?"currentColor":"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V17h14v-1.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V6a2 2 0 0 0-2-2h-2a2 2 0 0 0-2 2v4.76Z"})]})}function D(e){let{agents:t,selectedAgent:r,searchQuery:a="",pinnedAgents:l=[],isMaxPinned:o=!1,onAgentSelect:i,onAgentMessage:c,onReleaseClick:d,onLogsClick:u,onProfileClick:x,onPinToggle:h,compact:p=!1,showGroupStats:f=!0}=e,[b,v]=(0,s.useState)(new Set),[y,j]=(0,s.useState)(!0),[N,k]=(0,s.useState)(!1),C=(0,s.useMemo)(()=>g(t.filter(e=>!e.name.startsWith("__setup__")&&"Dashboard"!==e.name),a),[t,a]),{pinnedAgentsList:S,unpinnedAgents:L}=(0,s.useMemo)(()=>{let e=[],t=[];for(let r of C)l.includes(r.name)?e.push(r):t.push(r);return e.sort((e,t)=>l.indexOf(e.name)-l.indexOf(t.name)),{pinnedAgentsList:e,unpinnedAgents:t}},[C,l]),M=(0,s.useMemo)(()=>m(L),[L]),D=(0,s.useRef)(!1);(0,s.useEffect)(()=>{!D.current&&M.length>0&&(v(new Set(M.map(e=>e.prefix))),D.current=!0)},[M]);let E=e=>{v(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})};return 0===t.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-10 px-5 text-text-muted text-center",children:[(0,n.jsx)(T,{}),(0,n.jsx)("p",{children:"No agents connected"})]}):0===C.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-10 px-5 text-text-muted text-center",children:[(0,n.jsx)(W,{}),(0,n.jsxs)("p",{children:['No agents match "',a,'"']})]}):(0,n.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,n.jsxs)("div",{className:"flex justify-between items-center py-2 px-3 text-xs text-text-muted",children:[(0,n.jsxs)("span",{children:[C.length," ",1===C.length?"agent":"agents"]}),(0,n.jsx)("button",{className:"bg-transparent border-none text-accent cursor-pointer text-xs hover:underline",onClick:()=>{N?(k(!1),v(new Set(M.map(e=>e.prefix))),j(!0)):k(!0)},children:N?"Expand all":"Collapse all"})]}),!N&&(0,n.jsxs)(n.Fragment,{children:[S.length>0&&(0,n.jsxs)("div",{className:"mb-2",children:[(0,n.jsxs)("button",{className:"flex items-center gap-2 w-full py-2 px-3 bg-transparent border-none cursor-pointer text-sm text-left rounded transition-colors duration-200 relative hover:bg-amber-400/5",onClick:()=>j(!y),children:[(0,n.jsx)("div",{className:"absolute left-0 top-1 bottom-1 w-[3px] rounded-sm bg-amber-400"}),(0,n.jsx)(P,{expanded:y}),(0,n.jsx)(R,{}),(0,n.jsx)("span",{className:"font-semibold text-amber-400",children:"Pinned"}),(0,n.jsxs)("span",{className:"text-text-muted font-normal",children:["(",S.length,")"]})]}),y&&(0,n.jsx)("div",{className:"py-1 pl-4 flex flex-col gap-1",children:S.map(e=>(0,n.jsx)(w,{agent:e,isSelected:e.name===r,compact:p,isPinned:!0,isMaxPinned:o,onClick:i,onMessageClick:c,onReleaseClick:d,onLogsClick:u,onProfileClick:x,onPinToggle:h},e.name))})]}),M.map(e=>(0,n.jsx)(A,{group:e,isExpanded:b.has(e.prefix),selectedAgent:r,compact:p,showStats:f,pinnedAgents:l,isMaxPinned:o,onToggle:()=>E(e.prefix),onAgentSelect:i,onAgentMessage:c,onReleaseClick:d,onLogsClick:u,onProfileClick:x,onPinToggle:h},e.prefix))]})]})}function A(e){let{group:t,isExpanded:r,selectedAgent:s,compact:a,showStats:l,pinnedAgents:o=[],isMaxPinned:i=!1,onToggle:c,onAgentSelect:d,onAgentMessage:u,onReleaseClick:m,onLogsClick:p,onProfileClick:g,onPinToggle:f}=e,v=l?b(t.agents):null;if(1===t.agents.length&&t.agents[0].name.toLowerCase()===t.prefix.toLowerCase()){let e=t.agents[0];return(0,n.jsx)("div",{className:"mb-1 py-1 px-2",children:(0,n.jsx)(w,{agent:e,isSelected:e.name===s,compact:a,isPinned:o.includes(e.name),isMaxPinned:i,onClick:d,onMessageClick:u,onReleaseClick:m,onLogsClick:p,onProfileClick:g,onPinToggle:f},e.name)})}return(0,n.jsxs)("div",{className:"mb-1",children:[(0,n.jsxs)("button",{className:"flex items-center gap-2 w-full py-2 px-3 bg-transparent border-none cursor-pointer text-sm text-left rounded transition-colors duration-200 relative hover:bg-[var(--group-light)]",onClick:c,style:{"--group-color":t.color.primary,"--group-light":t.color.light},children:[(0,n.jsx)("div",{className:"absolute left-0 top-1 bottom-1 w-[3px] rounded-sm",style:{backgroundColor:t.color.primary}}),(0,n.jsx)(E,{expanded:r}),(0,n.jsx)("span",{className:"font-semibold text-text-primary",children:t.displayName}),(0,n.jsxs)("span",{className:"text-text-muted font-normal",children:["(",t.agents.length,")"]}),l&&v&&(0,n.jsxs)("div",{className:"ml-auto flex gap-2",children:[v.online>0&&(0,n.jsxs)("span",{className:"flex items-center gap-1 text-xs text-text-muted",title:"".concat(v.online," agent").concat(v.online>1?"s":""," online"),children:[(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:x.yh.online}}),v.online]}),v.needsAttention>0&&(0,n.jsxs)("span",{className:"flex items-center gap-1 text-xs text-text-muted",title:"".concat(v.needsAttention," agent").concat(v.needsAttention>1?"s":""," need").concat(1===v.needsAttention?"s":""," attention"),children:[(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:x.yh.attention}}),v.needsAttention]})]})]}),r&&(0,n.jsx)("div",{className:"py-1 pl-4 flex flex-col gap-1",children:t.agents.map(e=>(0,n.jsx)(w,{agent:e,isSelected:e.name===s,compact:a,displayNameOverride:h(e.name),isPinned:o.includes(e.name),isMaxPinned:i,onClick:d,onMessageClick:u,onReleaseClick:m,onLogsClick:p,onProfileClick:g,onPinToggle:f},e.name))})]})}function E(e){let{expanded:t}=e;return(0,n.jsx)("svg",{className:"text-text-muted transition-transform duration-200 ".concat(t?"rotate-90":""),width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.jsx)("polyline",{points:"9 18 15 12 9 6"})})}function T(){return(0,n.jsxs)("svg",{className:"mb-3 opacity-50",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1",children:[(0,n.jsx)("circle",{cx:"12",cy:"8",r:"5"}),(0,n.jsx)("path",{d:"M20 21a8 8 0 1 0-16 0"})]})}function W(){return(0,n.jsxs)("svg",{className:"mb-3 opacity-50",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1",children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function P(e){let{expanded:t}=e;return(0,n.jsx)("svg",{className:"text-amber-400 transition-transform duration-200 ".concat(t?"rotate-90":""),width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.jsx)("polyline",{points:"9 18 15 12 9 6"})})}function R(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-amber-400",children:[(0,n.jsx)("path",{d:"M12 17v5"}),(0,n.jsx)("path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V17h14v-1.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V6a2 2 0 0 0-2-2h-2a2 2 0 0 0-2 2v4.76Z"})]})}function I(e){return e.split(/[-_]/).map(e=>e.charAt(0).toUpperCase()+e.slice(1).toLowerCase()).join(" ")}function B(e){let{projects:t,localAgents:r=[],bridgeAgents:a=[],currentProject:l,selectedAgent:o,searchQuery:i="",pinnedAgents:c=[],isMaxPinned:d=!1,onProjectSelect:u,onAgentSelect:x,onReleaseClick:m,onLogsClick:h,onProfileClick:p,onPinToggle:g,compact:f=!1}=e,[b,v]=(0,s.useState)(()=>new Set(t.map(e=>e.id))),[y,j]=(0,s.useState)(!1),w=e=>e.filter(e=>!e.name.startsWith("__setup__")&&"Dashboard"!==e.name&&!e.isHuman&&"dashboard"!==e.cli),N=(0,s.useMemo)(()=>{let e=i.toLowerCase().trim(),n=w(r),s=w(a),l=t.map(e=>({...e,agents:w(e.agents)}));if(!e)return{projects:l,localAgents:n,bridgeAgents:s};let o=n.filter(t=>{var r;return t.name.toLowerCase().includes(e)||(null===(r=t.currentTask)||void 0===r?void 0:r.toLowerCase().includes(e))}),c=s.filter(t=>{var r;return t.name.toLowerCase().includes(e)||(null===(r=t.currentTask)||void 0===r?void 0:r.toLowerCase().includes(e))});return{projects:l.map(t=>{var r;let n=(null===(r=t.name)||void 0===r?void 0:r.toLowerCase().includes(e))||t.path.toLowerCase().includes(e),s=t.agents.filter(t=>{var r;return t.name.toLowerCase().includes(e)||(null===(r=t.currentTask)||void 0===r?void 0:r.toLowerCase().includes(e))});return n||s.length>0?{...t,agents:n?t.agents:s}:null}).filter(Boolean),localAgents:o,bridgeAgents:c}},[t,r,a,i]),k=e=>{v(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},C=N.localAgents.length+N.bridgeAgents.length+N.projects.reduce((e,t)=>e+t.agents.length,0);if(0===C&&0===t.length&&0===r.length)return(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-10 px-5 text-text-muted text-center",children:[(0,n.jsx)(G,{}),(0,n.jsx)("p",{children:"No projects or agents"})]});if(0===C&&i)return(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-10 px-5 text-text-muted text-center",children:[(0,n.jsx)(V,{}),(0,n.jsxs)("p",{children:['No results for "',i,'"']})]});let S=N.projects.length>1;return(0,n.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,n.jsxs)("div",{className:"flex justify-between items-center py-2 px-3 text-xs text-text-muted",children:[(0,n.jsxs)("span",{children:[C," ",1===C?"agent":"agents"]}),(0,n.jsx)("button",{className:"bg-transparent border-none text-accent cursor-pointer text-xs hover:underline",onClick:()=>{if(y){j(!1);let e=new Set(N.projects.map(e=>e.id));N.localAgents.length>0&&e.add("__local__"),v(e)}else j(!0)},children:y?"Expand all":"Collapse all"})]}),!y&&(0,n.jsxs)(n.Fragment,{children:[S&&N.bridgeAgents.length>0&&(0,n.jsx)(U,{agents:N.bridgeAgents,selectedAgent:o,compact:f,pinnedAgents:c,isMaxPinned:d,onAgentSelect:e=>null==x?void 0:x(e),onReleaseClick:m,onLogsClick:h,onProfileClick:p,onPinToggle:g}),!S&&N.localAgents.length>0&&(0,n.jsx)(F,{project:{id:"__local__",path:"",name:"Local",agents:N.localAgents},isExpanded:b.has("__local__"),isCurrentProject:!0,selectedAgent:o,compact:f,pinnedAgents:c,isMaxPinned:d,onToggle:()=>k("__local__"),onAgentSelect:e=>null==x?void 0:x(e),onReleaseClick:m,onLogsClick:h,onProfileClick:p,onPinToggle:g}),N.projects.map(e=>(0,n.jsx)(F,{project:e,isExpanded:b.has(e.id),isCurrentProject:e.id===l,selectedAgent:o,compact:f,isBridgeMode:S,pinnedAgents:c,isMaxPinned:d,onToggle:()=>k(e.id),onProjectSelect:()=>null==u?void 0:u(e),onAgentSelect:t=>null==x?void 0:x(t,e),onReleaseClick:m,onLogsClick:h,onProfileClick:p,onPinToggle:g},e.id))]})]})}function F(e){var t;let{project:r,isExpanded:a,isCurrentProject:l,selectedAgent:o,compact:i,isBridgeMode:c=!1,pinnedAgents:d=[],isMaxPinned:u=!1,onToggle:m,onProjectSelect:h,onAgentSelect:p,onReleaseClick:g,onLogsClick:f,onProfileClick:b,onPinToggle:v}=e,[y,j]=(0,s.useState)(new Set),N=(0,s.useMemo)(()=>{let e=0,t=0;for(let n of r.agents)"online"===n.status&&e++,n.needsAttention&&t++;return{online:e,needsAttention:t,total:r.agents.length}},[r.agents]),{teams:k,ungroupedAgents:C}=(0,s.useMemo)(()=>{let e=new Map,t=[];for(let n of r.agents)if(n.team){let t=e.get(n.team)||[];t.push(n),e.set(n.team,t)}else t.push(n);return{teams:Array.from(e.entries()).map(e=>{let[t,r]=e;return{name:t,agents:r}}).sort((e,t)=>e.name.localeCompare(t.name)),ungroupedAgents:t}},[r.agents]),S=e=>{j(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})};(0,s.useEffect)(()=>{a&&0===y.size&&k.length>0&&j(new Set(k.map(e=>e.name)))},[a,k,y]);let L=(0,x.GW)(r.name||r.id),M=r.name||r.path.split("/").pop()||r.id;return(0,n.jsxs)("div",{className:"mb-1",children:[(0,n.jsxs)("button",{className:"group flex items-center gap-2 w-full py-2.5 px-3 bg-none border-none cursor-pointer text-[13px] text-left rounded-md transition-colors duration-200 relative text-text-primary hover:bg-bg-hover ".concat(l?"bg-success-light":""),onClick:m,onDoubleClick:h,style:{"--project-color":L.primary,"--project-light":L.light},children:[(0,n.jsx)("div",{className:"absolute left-0 top-1 bottom-1 w-[3px] rounded-sm",style:{background:L.primary}}),(0,n.jsx)(O,{expanded:a}),(0,n.jsx)(H,{color:L.primary}),(0,n.jsx)("span",{className:"font-semibold text-text-primary whitespace-nowrap overflow-hidden text-ellipsis",children:M}),(0,n.jsxs)("span",{className:"text-text-muted font-normal flex-shrink-0",children:["(",N.total,")"]}),(0,n.jsxs)("div",{className:"ml-auto flex gap-2 flex-shrink-0",children:[N.online>0&&(0,n.jsxs)("span",{className:"flex items-center gap-1 text-[11px] text-text-dim",children:[(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:x.yh.online}}),N.online]}),N.needsAttention>0&&(0,n.jsxs)("span",{className:"flex items-center gap-1 text-[11px] text-text-dim",children:[(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full",style:{backgroundColor:x.yh.attention}}),N.needsAttention]})]}),(null===(t=r.lead)||void 0===t?void 0:t.connected)&&(0,n.jsx)("span",{className:"text-[#ffd700] text-xs ml-1",title:"Lead: ".concat(r.lead.name),children:"★"}),c&&!l&&h&&(0,n.jsx)("span",{role:"button",tabIndex:0,className:"ml-2 py-1 px-2 text-[10px] font-medium bg-accent-cyan/20 text-accent-cyan rounded cursor-pointer opacity-0 group-hover:opacity-100 transition-opacity hover:bg-accent-cyan/30",onClick:e=>{e.stopPropagation(),h()},onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),e.stopPropagation(),h())},title:"Switch to this project",children:"Switch"})]}),a&&(0,n.jsxs)("div",{className:"py-1 pl-5 flex flex-col gap-1",children:[k.map(e=>(0,n.jsxs)("div",{className:"mb-0.5",children:[(0,n.jsxs)("button",{className:"flex items-center gap-1.5 w-full py-1.5 px-2 bg-none border-none cursor-pointer text-xs text-left rounded transition-colors duration-200 text-text-secondary hover:bg-bg-hover",onClick:()=>S(e.name),children:[(0,n.jsx)(O,{expanded:y.has(e.name)}),(0,n.jsx)(z,{}),(0,n.jsx)("span",{className:"font-medium text-text-secondary",children:e.name}),(0,n.jsxs)("span",{className:"text-text-muted font-normal",children:["(",e.agents.length,")"]})]}),y.has(e.name)&&(0,n.jsx)("div",{className:"py-0.5 pl-4 flex flex-col gap-1",children:e.agents.map(t=>(0,n.jsx)(w,{agent:t,isSelected:t.name===o,compact:i,displayNameOverride:function(e,t){let r=e.toLowerCase(),n=t.toLowerCase().replace(/-?team$/i,"");if(n&&r.startsWith(n+"-")||n&&r.startsWith(n+"_"))return I(e.substring(n.length+1));let s=e.split("-");return s.length>1?I(s[s.length-1]):I(e)}(t.name,e.name),isPinned:d.includes(t.name),isMaxPinned:u,onClick:p,onReleaseClick:g,onLogsClick:f,onProfileClick:b,onPinToggle:v},t.name))})]},e.name)),C.map(e=>(0,n.jsx)(w,{agent:e,isSelected:e.name===o,compact:i,isPinned:d.includes(e.name),isMaxPinned:u,onClick:p,onReleaseClick:g,onLogsClick:f,onProfileClick:b,onPinToggle:v},e.name))]})]})}function U(e){let{agents:t,selectedAgent:r,compact:a,pinnedAgents:l=[],isMaxPinned:o=!1,onAgentSelect:i,onReleaseClick:c,onLogsClick:d,onProfileClick:u,onPinToggle:x}=e,[m,h]=(0,s.useState)(!0);return(0,n.jsxs)("div",{className:"mb-2",children:[(0,n.jsxs)("button",{className:"flex items-center gap-2 w-full py-2.5 px-3 bg-none border-none cursor-pointer text-[13px] text-left rounded-md transition-colors duration-200 relative text-text-primary hover:bg-accent-purple/10",onClick:()=>h(!m),children:[(0,n.jsx)("div",{className:"absolute left-0 top-1 bottom-1 w-[3px] rounded-sm bg-accent-purple"}),(0,n.jsx)(O,{expanded:m}),(0,n.jsx)(_,{}),(0,n.jsx)("span",{className:"font-semibold text-text-primary",children:"Bridge"}),(0,n.jsxs)("span",{className:"text-text-muted font-normal flex-shrink-0",children:["(",t.length,")"]})]}),m&&(0,n.jsx)("div",{className:"py-1 pl-5 flex flex-col gap-1",children:t.map(e=>(0,n.jsx)(w,{agent:e,isSelected:e.name===r,compact:a,isPinned:l.includes(e.name),isMaxPinned:o,onClick:i,onReleaseClick:c,onLogsClick:d,onProfileClick:u,onPinToggle:x},e.name))})]})}function _(){return(0,n.jsxs)("svg",{className:"flex-shrink-0 text-accent-purple",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,n.jsx)("circle",{cx:"5",cy:"5",r:"2"}),(0,n.jsx)("circle",{cx:"19",cy:"5",r:"2"}),(0,n.jsx)("circle",{cx:"5",cy:"19",r:"2"}),(0,n.jsx)("circle",{cx:"19",cy:"19",r:"2"}),(0,n.jsx)("line",{x1:"9.5",y1:"9.5",x2:"6.5",y2:"6.5"}),(0,n.jsx)("line",{x1:"14.5",y1:"9.5",x2:"17.5",y2:"6.5"}),(0,n.jsx)("line",{x1:"9.5",y1:"14.5",x2:"6.5",y2:"17.5"}),(0,n.jsx)("line",{x1:"14.5",y1:"14.5",x2:"17.5",y2:"17.5"})]})}function O(e){let{expanded:t}=e;return(0,n.jsx)("svg",{className:"transition-transform duration-200 text-text-muted flex-shrink-0 ".concat(t?"rotate-90":""),width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.jsx)("polyline",{points:"9 18 15 12 9 6"})})}function H(e){let{color:t}=e;return(0,n.jsx)("svg",{className:"flex-shrink-0",style:{color:t},width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.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"})})}function z(){return(0,n.jsxs)("svg",{className:"text-text-muted flex-shrink-0",width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),(0,n.jsx)("circle",{cx:"9",cy:"7",r:"4"}),(0,n.jsx)("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),(0,n.jsx)("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]})}function G(){return(0,n.jsx)("svg",{className:"mb-3 opacity-50",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1",children:(0,n.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"})})}function V(){return(0,n.jsxs)("svg",{className:"mb-3 opacity-50",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1",children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function K(e){let{threads:t,currentThread:r,onThreadSelect:s,totalUnreadCount:a=0,isCollapsed:l=!1,onToggleCollapse:o}=e;return 0===t.length?null:(0,n.jsxs)("div",{className:"px-2 py-2",children:[(0,n.jsxs)("button",{className:"w-full flex items-center justify-between px-2 py-2 mb-1.5 bg-transparent border-none cursor-pointer rounded-lg transition-all duration-200 hover:bg-gradient-to-r hover:from-[rgba(255,255,255,0.03)] hover:to-transparent",onClick:o,"aria-expanded":!l,"aria-label":l?"Expand threads":"Collapse threads",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(J,{isCollapsed:l}),(0,n.jsx)("span",{className:"text-xs font-semibold uppercase tracking-wider text-text-muted",children:"Threads"}),(0,n.jsxs)("span",{className:"text-xs text-text-dim font-mono",children:["(",t.length,")"]})]}),a>0&&(0,n.jsx)("span",{className:"min-w-[18px] h-[18px] flex items-center justify-center text-[10px] font-bold bg-accent-cyan text-bg-deep rounded-full px-1.5",style:{boxShadow:"0 0 8px rgba(0, 217, 255, 0.5)"},children:a>99?"99+":a})]}),!l&&(0,n.jsx)("div",{className:"space-y-1",children:t.map(e=>(0,n.jsx)(Z,{thread:e,isSelected:r===e.id,onClick:()=>s(e.id)},e.id))})]})}function Z(e){let{thread:t,isSelected:r,onClick:s}=e,a=t.unreadCount>0,l=function(e){let t=new Date(e),r=new Date().getTime()-t.getTime(),n=Math.floor(r/6e4),s=Math.floor(r/36e5),a=Math.floor(r/864e5);return n<1?"now":n<60?"".concat(n,"m"):s<24?"".concat(s,"h"):a<7?"".concat(a,"d"):t.toLocaleDateString([],{month:"short",day:"numeric"})}(t.lastMessage.timestamp);return(0,n.jsxs)("button",{className:"\n group w-full flex items-center gap-3 px-2.5 py-2.5 rounded-lg text-left transition-all duration-200 cursor-pointer border-none\n hover:bg-gradient-to-r hover:from-[rgba(255,255,255,0.03)] hover:to-transparent\n ".concat(r?"bg-gradient-to-r from-[rgba(255,255,255,0.06)] to-transparent":"bg-transparent","\n "),onClick:s,style:{borderLeft:r?"2px solid #00d9ff":"2px solid transparent",boxShadow:r?"inset 4px 0 12px -4px rgba(0, 217, 255, 0.25)":"none"},children:[(0,n.jsxs)("div",{className:"\n relative shrink-0 w-8 h-8 rounded-lg flex items-center justify-center overflow-hidden transition-all duration-200\n ".concat(a?"text-accent-cyan":"text-text-muted","\n "),style:{background:a?"linear-gradient(135deg, rgba(0, 217, 255, 0.2), rgba(0, 217, 255, 0.1))":"rgba(255, 255, 255, 0.03)",boxShadow:a?"0 0 8px rgba(0, 217, 255, 0.2)":"none"},children:[(0,n.jsx)("div",{className:"absolute inset-0 opacity-20",style:{background:"linear-gradient(135deg, rgba(255,255,255,0.2) 0%, transparent 50%)"}}),(0,n.jsx)(q,{})]}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"\n text-[13px] truncate transition-colors duration-200\n ".concat(a?"font-semibold text-text-primary":"text-text-secondary group-hover:text-text-primary","\n "),children:t.name}),a&&(0,n.jsx)("span",{className:"shrink-0 min-w-[16px] h-[16px] flex items-center justify-center text-[9px] font-bold bg-accent-cyan text-bg-deep rounded-full px-1",style:{boxShadow:"0 0 6px rgba(0, 217, 255, 0.4)"},children:t.unreadCount>99?"99+":t.unreadCount})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5 text-[11px] text-text-muted font-mono",children:[(0,n.jsx)("span",{className:"truncate",children:t.participants.slice(0,2).join(", ")}),t.participants.length>2&&(0,n.jsxs)("span",{className:"text-text-dim",children:["+",t.participants.length-2]}),(0,n.jsx)("span",{className:"text-text-dim opacity-50",children:"\xb7"}),(0,n.jsx)("span",{className:"text-text-dim",children:l})]})]})]})}function q(){return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.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"})})}function J(e){let{isCollapsed:t}=e;return(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-text-muted transition-transform duration-200 ".concat(t?"":"rotate-90"),children:(0,n.jsx)("polyline",{points:"9 18 15 12 9 6"})})}var $=r(5634);let Y="agent-relay-threads-collapsed",X="agent-relay-sidebar-tab",Q="agent-relay-channels-collapsed";function ee(e){var t;let{agents:r,bridgeAgents:a=[],projects:l=[],currentUserName:o,humanUnreadCounts:c={},currentProject:d,selectedAgent:x,viewMode:m,isFleetAvailable:h,isConnected:p,isOpen:g=!1,activeThreads:f=[],currentThread:b,totalUnreadThreadCount:v=0,isActivitySelected:y=!1,activityUnreadCount:j=0,onActivitySelect:w,channels:N=[],archivedChannels:k=[],selectedChannelId:C,onChannelSelect:S,onArchiveChannel:L,onUnarchiveChannel:M,onCreateChannel:A,onInviteToChannel:E,onAgentSelect:T,onHumanSelect:W,onProjectSelect:P,onViewModeChange:R,onSpawnClick:I,onReleaseClick:F,onLogsClick:U,onProfileClick:_,onThreadSelect:O,onClose:H,onSettingsClick:z,onTrajectoryClick:G,hasActiveTrajectory:V,onFleetClick:Z,isFleetViewActive:q}=e,[J,ee]=(0,s.useState)(""),[ey,ej]=(0,s.useState)(()=>{try{let e=localStorage.getItem(X);return"team"===e?"team":"agents"}catch(e){return"agents"}}),[ew,eN]=(0,s.useState)(()=>{try{let e=localStorage.getItem(Y);return"true"===e}catch(e){return!1}}),[ek,eC]=(0,s.useState)(()=>{try{let e=localStorage.getItem(Q);return null===e||"true"===e}catch(e){return!0}});(0,s.useEffect)(()=>{try{localStorage.setItem(X,ey)}catch(e){}},[ey]),(0,s.useEffect)(()=>{try{localStorage.setItem(Y,String(ew))}catch(e){}},[ew]),(0,s.useEffect)(()=>{try{localStorage.setItem(Q,String(ek))}catch(e){}},[ek]);let eS=N.reduce((e,t)=>e+t.unreadCount,0),eL=N.length>0,eM=!!eL&&ek,eD=k.length>0,[eA,eE]=(0,s.useState)(!0),[eT,eW]=(0,s.useState)(null);(0,s.useEffect)(()=>{eW(null)},[C]);let eP=r.filter(e=>!e.isHuman&&"Dashboard"!==e.name),eR=r.filter(e=>e.isHuman&&"Dashboard"!==e.name&&(!o||e.name.toLowerCase()!==o.toLowerCase())),eI=eR.filter(e=>!J||e.name.toLowerCase().includes(J.toLowerCase())),{pinnedAgents:eB,togglePin:eF,isMaxPinned:eU}=function(){let[e,t]=(0,s.useState)(()=>(function(){try{if("undefined"==typeof localStorage)return[];let e=localStorage.getItem(i);if(e){let t=JSON.parse(e);if(Array.isArray(t))return t.slice(0,5)}}catch(e){}return[]})());(0,s.useEffect)(()=>{!function(e){try{if("undefined"==typeof localStorage)return;localStorage.setItem(i,JSON.stringify(e))}catch(e){}}(e)},[e]);let r=(0,s.useCallback)(t=>e.includes(t),[e]),n=(0,s.useCallback)(r=>{let{newPinned:n,success:s}=e.includes(r)?{newPinned:e,success:!0}:e.length>=5?{newPinned:e,success:!1}:{newPinned:[...e,r],success:!0};return n!==e&&t(n),s},[e]),a=(0,s.useCallback)(e=>{t(t=>t.filter(t=>t!==e))},[]),l=(0,s.useCallback)(e=>{r(e)?a(e):n(e)},[r,n,a]),o=(0,s.useMemo)(()=>e.length>=5,[e]);return{pinnedAgents:e,isPinned:r,togglePin:l,pin:n,unpin:a,isMaxPinned:o,maxPinned:5}}(),{workspace:e_}=u(),eO=null!==(t=null==e_?void 0:e_.isStopped)&&void 0!==t&&t,eH=l.length>0;return(0,n.jsxs)("aside",{className:"flex-1 flex flex-col overflow-hidden",children:[(0,n.jsx)("div",{className:"p-3 sm:p-4 border-b border-border-subtle",children:(0,n.jsxs)("div",{className:"flex items-center gap-2 sm:gap-3",children:[(0,n.jsx)($.K7,{size:24,withGlow:!0}),(0,n.jsx)("h1",{className:"text-base sm:text-lg font-display font-semibold m-0 text-text-primary",children:"Agent Relay"}),(0,n.jsx)(et,{isConnected:p}),(0,n.jsx)("button",{className:"md:hidden ml-auto p-2 -mr-1 sm:-mr-2 bg-transparent border-none text-text-muted cursor-pointer rounded-lg transition-colors hover:bg-bg-hover hover:text-text-primary active:bg-bg-hover",onClick:H,"aria-label":"Close sidebar",children:(0,n.jsx)(ex,{})})]})}),eR.length>0&&(0,n.jsxs)("div",{className:"flex bg-bg-tertiary rounded-lg p-1 mx-3 mt-3",children:[(0,n.jsxs)("button",{className:"\n flex-1 py-2 px-4 bg-transparent border-none text-xs font-medium cursor-pointer rounded-md transition-all duration-150 flex items-center justify-center gap-1.5\n ".concat("agents"===ey?"bg-bg-elevated text-accent-cyan shadow-sm":"text-text-muted hover:text-text-secondary","\n "),onClick:()=>ej("agents"),children:[(0,n.jsx)(eh,{}),"Agents",eP.length>0&&(0,n.jsxs)("span",{className:"text-[10px] opacity-70",children:["(",eP.length,")"]})]}),(0,n.jsxs)("button",{className:"\n flex-1 py-2 px-4 bg-transparent border-none text-xs font-medium cursor-pointer rounded-md transition-all duration-150 flex items-center justify-center gap-1.5\n ".concat("team"===ey?"bg-bg-elevated text-accent-cyan shadow-sm":"text-text-muted hover:text-text-secondary","\n "),onClick:()=>ej("team"),children:[(0,n.jsx)(ep,{}),"Team",eR.length>0&&(0,n.jsxs)("span",{className:"text-[10px] opacity-70",children:["(",eR.length,")"]})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2 py-2 sm:py-2.5 px-2 sm:px-3 bg-bg-tertiary m-2 sm:m-3 rounded-lg border border-border-subtle focus-within:border-accent-cyan/50 transition-colors",children:[(0,n.jsx)(er,{}),(0,n.jsx)("input",{type:"text",placeholder:"agents"===ey?"Search agents...":"Search team...",value:J,onChange:e=>ee(e.target.value),className:"flex-1 bg-transparent border-none text-text-primary text-sm outline-none placeholder:text-text-muted"}),J&&(0,n.jsx)("button",{className:"bg-transparent border-none text-text-muted cursor-pointer p-1 flex items-center justify-center hover:text-text-secondary rounded transition-colors active:text-text-secondary",onClick:()=>ee(""),children:(0,n.jsx)(en,{})})]}),f.length>0&&(0,n.jsx)("div",{className:"border-b border-border-subtle",children:(0,n.jsx)(K,{threads:f,currentThread:b,onThreadSelect:e=>null==O?void 0:O(e),totalUnreadCount:v,isCollapsed:ew,onToggleCollapse:()=>eN(!ew)})}),(0,n.jsx)("div",{className:"border-b border-border-subtle px-2 py-2",children:(0,n.jsxs)("button",{onClick:w,className:"\n w-full flex items-center gap-2 px-2 py-2 rounded-lg text-left text-sm transition-colors\n ".concat(y?"bg-accent-cyan/10 text-text-primary border border-accent-cyan/30":"hover:bg-bg-hover text-text-secondary hover:text-text-primary border border-transparent","\n "),children:[(0,n.jsx)(ev,{}),(0,n.jsx)("span",{className:"flex-1 ".concat(j>0?"font-semibold text-text-primary":""),children:"Activity"}),j>0&&(0,n.jsx)("span",{className:"text-[11px] font-semibold px-1.5 py-0.5 rounded-full bg-accent-cyan/20 text-accent-cyan",children:j})]})}),!eO&&(0,n.jsxs)("div",{className:"border-b border-border-subtle",children:[(0,n.jsxs)("button",{className:"w-full flex items-center justify-between px-3 py-2 text-xs font-semibold text-text-muted uppercase tracking-wide hover:bg-bg-hover transition-colors",onClick:()=>eC(!ek),children:[(0,n.jsxs)("span",{className:"flex items-center gap-2",children:[(0,n.jsx)(ec,{}),"Channels",eS>0&&(0,n.jsx)("span",{className:"text-[10px] font-semibold px-1.5 py-0.5 rounded-full bg-accent-cyan/20 text-accent-cyan",children:eS})]}),(0,n.jsx)(ed,{className:"transition-transform ".concat(eM?"":"rotate-180")})]}),!eM&&(0,n.jsxs)("div",{className:"px-2 pb-2 space-y-0.5 max-h-40 md:max-h-none overflow-y-auto",children:[N.map(e=>(0,n.jsxs)("div",{className:"group relative",children:[(0,n.jsxs)("button",{onClick:()=>null==S?void 0:S(e),className:"\n w-full flex items-center gap-2 px-2 py-1.5 rounded-md text-left text-sm transition-colors\n ".concat(C===e.id?"bg-accent-cyan/10 text-text-primary":"hover:bg-bg-hover text-text-secondary hover:text-text-primary","\n "),children:[(0,n.jsx)("span",{className:"text-text-muted",children:"#"}),(0,n.jsx)("span",{className:"flex-1 truncate ".concat(e.unreadCount>0?"font-semibold text-text-primary":""),children:e.name}),e.unreadCount>0&&(0,n.jsx)("span",{className:"\n text-[11px] font-semibold px-1.5 py-0.5 rounded-full min-w-[18px] text-center\n ".concat(e.hasMentions?"bg-red-500/20 text-red-400":"bg-accent-cyan/20 text-accent-cyan","\n "),children:e.unreadCount})]}),(E||L)&&(0,n.jsx)("button",{onClick:t=>{t.stopPropagation(),eW(eT===e.id?null:e.id)},title:"Channel actions",className:"absolute right-1 top-1/2 -translate-y-1/2 p-1 rounded opacity-0 group-hover:opacity-100 hover:bg-bg-tertiary text-text-muted hover:text-text-primary transition-all",children:(0,n.jsx)(eu,{})}),eT===e.id&&(0,n.jsxs)("div",{className:"absolute right-0 top-full mt-1 z-30 bg-bg-elevated border border-border-subtle rounded-lg shadow-lg py-1 min-w-[160px]",children:[E&&(0,n.jsxs)(es,{onClick:()=>{E(e),eW(null)},children:[(0,n.jsx)(el,{}),(0,n.jsx)("span",{children:"Invite members"})]}),L&&(0,n.jsxs)(es,{onClick:()=>{L(e),eW(null)},children:[(0,n.jsx)(eo,{}),(0,n.jsx)("span",{children:"Archive"})]})]})]},e.id)),A&&(0,n.jsxs)("button",{onClick:A,className:"w-full flex items-center gap-2 px-2 py-1.5 rounded-md text-left text-sm text-text-muted hover:bg-bg-hover hover:text-text-secondary transition-colors",children:[(0,n.jsx)(ea,{}),(0,n.jsx)("span",{children:eL?"Add channel":"Create your first channel"})]})]}),eD&&(0,n.jsxs)("div",{className:"mt-1 border-t border-border-subtle",children:[(0,n.jsxs)("button",{className:"w-full flex items-center justify-between px-3 py-2 text-xs font-semibold text-text-muted uppercase tracking-wide hover:bg-bg-hover transition-colors",onClick:()=>eE(!eA),children:[(0,n.jsxs)("span",{className:"flex items-center gap-2",children:[(0,n.jsx)(eo,{}),"Archived",(0,n.jsxs)("span",{className:"text-[10px] opacity-80",children:["(",k.length,")"]})]}),(0,n.jsx)(ed,{className:"transition-transform ".concat(eA?"":"rotate-180")})]}),!eA&&(0,n.jsx)("div",{className:"px-2 pb-2 space-y-0.5 max-h-32 md:max-h-none overflow-y-auto",children:k.map(e=>(0,n.jsxs)("div",{className:"group relative",children:[(0,n.jsxs)("button",{onClick:()=>null==S?void 0:S(e),className:"\n w-full flex items-center gap-2 px-2 py-1.5 rounded-md text-left text-sm transition-colors\n ".concat(C===e.id?"bg-bg-tertiary text-text-primary":"hover:bg-bg-hover text-text-secondary hover:text-text-primary","\n "),children:[(0,n.jsx)("span",{className:"text-text-muted",children:"#"}),(0,n.jsx)("span",{className:"flex-1 truncate",children:e.name}),(0,n.jsx)("span",{className:"text-[10px] font-medium px-1.5 py-0.5 rounded-full bg-border-subtle text-text-muted",children:"Archived"})]}),M&&(0,n.jsxs)("button",{onClick:t=>{t.stopPropagation(),M(e)},title:"Unarchive channel",className:"absolute right-1 top-1/2 -translate-y-1/2 px-2 py-1 rounded-md bg-bg-tertiary text-text-secondary hover:text-text-primary hover:bg-bg-hover transition-colors text-xs flex items-center gap-1",children:[(0,n.jsx)(ei,{}),(0,n.jsx)("span",{children:"Unarchive"})]})]},e.id))})]})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto px-2",children:["team"===ey&&eR.length>0?(0,n.jsxs)("div",{className:"flex flex-col gap-1 py-2",children:[eI.map(e=>(0,n.jsxs)("button",{onClick:()=>W?W(e):null==T?void 0:T(e),className:"\n flex items-center gap-3 p-3 rounded-lg border transition-all duration-150 text-left w-full\n ".concat(x===e.name?"bg-accent-cyan/10 border-accent-cyan/30":"bg-bg-tertiary border-border-subtle hover:border-accent-cyan/30 hover:bg-bg-hover","\n "),children:[e.avatarUrl?(0,n.jsx)("img",{src:e.avatarUrl,alt:e.name,className:"w-9 h-9 rounded-full object-cover"}):(0,n.jsx)("div",{className:"w-9 h-9 rounded-full bg-gradient-to-br from-purple-500 to-pink-500 flex items-center justify-center text-white font-medium text-sm",children:e.name.charAt(0).toUpperCase()}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("p",{className:"text-sm font-medium text-text-primary truncate",children:e.name}),(0,n.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.role||"Team Member"})]}),c[e.name]>0&&(0,n.jsx)("span",{className:"text-[11px] font-semibold px-2 py-0.5 rounded-full bg-accent-cyan/20 text-accent-cyan",children:c[e.name]}),(0,n.jsx)("div",{className:"w-2 h-2 rounded-full ".concat("online"===e.status?"bg-success":"bg-text-dim")})]},e.name)),0===eI.length&&(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-10 px-5 text-text-muted text-center",children:[(0,n.jsx)(er,{}),(0,n.jsxs)("p",{className:"mt-3",children:['No team members match "',J,'"']})]})]}):eH?(0,n.jsx)(B,{projects:l,localAgents:eP,bridgeAgents:a,currentProject:d,selectedAgent:x,searchQuery:J,pinnedAgents:eB,isMaxPinned:eU,onProjectSelect:P,onAgentSelect:T,onReleaseClick:F,onLogsClick:U,onProfileClick:_,onPinToggle:e=>eF(e.name),compact:!0}):(0,n.jsx)(D,{agents:eP,selectedAgent:x,searchQuery:J,pinnedAgents:eB,isMaxPinned:eU,onAgentSelect:e=>null==T?void 0:T(e),onReleaseClick:F,onLogsClick:U,onProfileClick:_,onPinToggle:e=>eF(e.name),compact:!0,showGroupStats:!0}),"agents"===ey&&eR.length>0&&(0,n.jsxs)("div",{className:"mt-4 mb-2 pt-3 border-t border-border-subtle",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-1 pb-2",children:[(0,n.jsx)("p",{className:"text-xs uppercase tracking-wide text-text-muted font-semibold m-0",children:"Direct messages"}),(0,n.jsxs)("span",{className:"text-[11px] text-text-muted",children:[eI.length," member",1===eI.length?"":"s"]})]}),(0,n.jsx)("div",{className:"flex flex-col gap-1",children:eI.length>0?eI.map(e=>(0,n.jsxs)("button",{onClick:()=>W?W(e):null==T?void 0:T(e),className:"\n flex items-center gap-3 p-2.5 rounded-lg border transition-all duration-150 text-left w-full\n ".concat(x===e.name?"bg-accent-cyan/10 border-accent-cyan/30":"bg-bg-tertiary border-border-subtle hover:border-accent-cyan/30 hover:bg-bg-hover","\n "),children:[e.avatarUrl?(0,n.jsx)("img",{src:e.avatarUrl,alt:e.name,className:"w-8 h-8 rounded-full object-cover"}):(0,n.jsx)("div",{className:"w-8 h-8 rounded-full bg-gradient-to-br from-purple-500 to-pink-500 flex items-center justify-center text-white font-medium text-xs",children:e.name.charAt(0).toUpperCase()}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("p",{className:"text-sm font-medium text-text-primary truncate",children:e.name}),(0,n.jsx)("p",{className:"text-[11px] text-text-muted truncate",children:e.role||"Team Member"})]}),c[e.name]>0&&(0,n.jsx)("span",{className:"text-[11px] font-semibold px-2 py-0.5 rounded-full bg-accent-cyan/20 text-accent-cyan",children:c[e.name]}),(0,n.jsx)("div",{className:"w-2 h-2 rounded-full ".concat("online"===e.status?"bg-success":"bg-text-dim")})]},e.name)):(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center py-6 px-3 text-text-muted text-center",children:[(0,n.jsx)(er,{}),(0,n.jsxs)("p",{className:"mt-2 text-xs",children:['No team members match "',J,'"']})]})})]})]}),(0,n.jsxs)("div",{className:"md:hidden border-t border-border-subtle p-3",children:[(0,n.jsx)("p",{className:"text-xs text-text-muted font-medium mb-2 px-1",children:"Quick Actions"}),(0,n.jsxs)("div",{className:"grid grid-cols-2 gap-2",children:[Z&&(0,n.jsxs)("button",{className:"flex items-center gap-2 p-2.5 rounded-lg border text-sm transition-all duration-150 ".concat(q?"bg-accent-cyan/20 border-accent-cyan text-accent-cyan":"bg-bg-tertiary border-border-subtle text-text-secondary hover:bg-bg-hover hover:text-text-primary"),onClick:()=>{Z(),null==H||H()},children:[(0,n.jsx)(eg,{}),(0,n.jsx)("span",{children:"Fleet"})]}),G&&(0,n.jsxs)("button",{className:"flex items-center gap-2 p-2.5 rounded-lg border text-sm transition-all duration-150 relative ".concat(V?"bg-accent-cyan/20 border-accent-cyan text-accent-cyan":"bg-bg-tertiary border-border-subtle text-text-secondary hover:bg-bg-hover hover:text-text-primary"),onClick:()=>{G(),null==H||H()},children:[(0,n.jsx)(ef,{}),(0,n.jsx)("span",{children:"Trajectory"}),V&&(0,n.jsx)("span",{className:"absolute top-1 right-1 w-2 h-2 bg-accent-cyan rounded-full animate-pulse"})]}),(0,n.jsxs)("a",{href:"/metrics",className:"flex items-center gap-2 p-2.5 bg-bg-tertiary border border-border-subtle rounded-lg text-text-secondary text-sm transition-all duration-150 hover:bg-bg-hover hover:text-accent-orange no-underline",onClick:()=>null==H?void 0:H(),children:[(0,n.jsx)(eb,{}),(0,n.jsx)("span",{children:"Metrics"})]})]})]}),(0,n.jsxs)("div",{className:"p-3 sm:p-4 border-t border-border-subtle space-y-2",children:[(0,n.jsxs)("button",{className:"w-full py-2.5 sm:py-3 px-3 sm:px-4 bg-gradient-to-r from-accent-cyan to-[#00b8d9] text-bg-deep font-semibold text-sm cursor-pointer flex items-center justify-center gap-2 rounded-lg transition-all duration-150 hover:shadow-glow-cyan hover:-translate-y-0.5 active:scale-[0.98]",onClick:I,children:[(0,n.jsx)(ea,{}),"Spawn Agent"]}),(0,n.jsxs)("button",{className:"w-full py-2 sm:py-2.5 px-3 sm:px-4 bg-bg-tertiary text-text-secondary text-sm cursor-pointer flex items-center justify-center gap-2 rounded-lg border border-border-subtle transition-all duration-150 hover:bg-bg-hover hover:text-text-primary hover:border-border-subtle active:bg-bg-hover",onClick:z,children:[(0,n.jsx)(em,{}),"Settings"]})]})]})}function et(e){let{isConnected:t}=e;return(0,n.jsxs)("div",{className:"flex items-center gap-1.5 ml-auto",children:[(0,n.jsx)("div",{className:"w-2 h-2 rounded-full ".concat(t?"bg-success animate-pulse-glow":"bg-text-dim")}),(0,n.jsx)("span",{className:"text-xs text-text-muted",children:t?"Live":"Offline"})]})}function er(){return(0,n.jsxs)("svg",{className:"text-text-muted",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function en(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function es(e){let{onClick:t,children:r}=e;return(0,n.jsx)("button",{onClick:t,className:"w-full flex items-center gap-2 px-3 py-2 text-sm text-text-secondary hover:bg-bg-hover hover:text-text-primary transition-colors",children:r})}function ea(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[(0,n.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,n.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function el(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M16 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),(0,n.jsx)("circle",{cx:"8.5",cy:"7",r:"4"}),(0,n.jsx)("line",{x1:"20",y1:"8",x2:"20",y2:"14"}),(0,n.jsx)("line",{x1:"23",y1:"11",x2:"17",y2:"11"})]})}function eo(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 7h18"}),(0,n.jsx)("path",{d:"M5 7v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7"}),(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"4",rx:"1"}),(0,n.jsx)("line",{x1:"10",y1:"12",x2:"14",y2:"12"})]})}function ei(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 7h18"}),(0,n.jsx)("path",{d:"M5 7v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7"}),(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"4",rx:"1"}),(0,n.jsx)("path",{d:"M12 11v6"}),(0,n.jsx)("path",{d:"M9 14l3-3 3 3"})]})}function ec(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"4",y1:"9",x2:"20",y2:"9"}),(0,n.jsx)("line",{x1:"4",y1:"15",x2:"20",y2:"15"}),(0,n.jsx)("line",{x1:"10",y1:"3",x2:"8",y2:"21"}),(0,n.jsx)("line",{x1:"16",y1:"3",x2:"14",y2:"21"})]})}function ed(e){let{className:t}=e;return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:(0,n.jsx)("polyline",{points:"6 9 12 15 18 9"})})}function eu(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"5",cy:"12",r:"1"}),(0,n.jsx)("circle",{cx:"12",cy:"12",r:"1"}),(0,n.jsx)("circle",{cx:"19",cy:"12",r:"1"})]})}function ex(){return(0,n.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function em(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,n.jsx)("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"})]})}function eh(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"11",width:"18",height:"10",rx:"2"}),(0,n.jsx)("circle",{cx:"12",cy:"5",r:"2"}),(0,n.jsx)("path",{d:"M12 7v4"}),(0,n.jsx)("line",{x1:"8",y1:"16",x2:"8",y2:"16"}),(0,n.jsx)("line",{x1:"16",y1:"16",x2:"16",y2:"16"})]})}function ep(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),(0,n.jsx)("circle",{cx:"9",cy:"7",r:"4"}),(0,n.jsx)("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),(0,n.jsx)("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]})}function eg(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"}),(0,n.jsx)("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),(0,n.jsx)("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}function ef(){return(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M3 12h4l3 9 4-18 3 9h4"})})}function eb(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 3v18h18"}),(0,n.jsx)("path",{d:"M18 17V9"}),(0,n.jsx)("path",{d:"M13 17V5"}),(0,n.jsx)("path",{d:"M8 17v-3"})]})}function ev(){return(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M22 12h-4l-3 9L9 3l-3 9H2"})})}function ey(e){let{projects:t,recentProjects:r=[],currentProject:a,onProjectChange:l}=e,[o,i]=(0,s.useState)(!1),[c,d]=(0,s.useState)(-1),u=(0,s.useRef)(null),x=(0,s.useRef)([]),m=t.length>1,h=new Set(r.map(e=>e.id)),p=t.filter(e=>!h.has(e.id)),g=[...r,...p],f=e=>{if(!e)return"No project";if(e.name)return e.name;let t=e.path.split("/").filter(Boolean);return t.length>=2?"".concat(t[t.length-2],"/").concat(t[t.length-1]):t[t.length-1]||e.id};return((0,s.useEffect)(()=>{let e=e=>{u.current&&!u.current.contains(e.target)&&i(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,s.useEffect)(()=>{let e=e=>{if(o)switch(e.key){case"Escape":i(!1),d(-1);break;case"ArrowDown":e.preventDefault(),d(e=>{var t;let r=e<g.length-1?e+1:0;return null===(t=x.current[r])||void 0===t||t.focus(),r});break;case"ArrowUp":e.preventDefault(),d(e=>{var t;let r=e>0?e-1:g.length-1;return null===(t=x.current[r])||void 0===t||t.focus(),r});break;case"Enter":c>=0&&c<g.length&&(l(g[c]),i(!1),d(-1))}};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[o,c,g,l]),(0,s.useEffect)(()=>{if(o){let e=g.findIndex(e=>e.id===(null==a?void 0:a.id));d(e>=0?e:0)}else d(-1)},[o,g,a]),0===t.length)?null:(0,n.jsxs)("div",{className:"relative",ref:u,children:[(0,n.jsxs)("button",{className:"flex items-center gap-2 px-3 py-1.5 rounded-lg text-sm font-medium transition-all duration-150 border ".concat(m?"bg-bg-tertiary/80 border-border-subtle hover:bg-bg-elevated hover:border-border-medium cursor-pointer":"bg-transparent border-transparent cursor-default"),onClick:()=>m&&i(!o),disabled:!m,"aria-expanded":o,"aria-haspopup":"listbox",children:[(0,n.jsx)(eN,{}),(0,n.jsx)("span",{className:"text-text-primary truncate max-w-[200px]",children:f(a)}),m&&(0,n.jsx)(ek,{isOpen:o})]}),o&&m&&(0,n.jsxs)("div",{className:"absolute top-[calc(100%+4px)] left-0 min-w-[280px] bg-bg-primary border border-border-subtle rounded-xl shadow-[0_10px_40px_rgba(0,0,0,0.4)] z-[1000] overflow-hidden",children:[(0,n.jsx)("div",{className:"px-3 py-2 border-b border-border-subtle",children:(0,n.jsx)("span",{className:"text-xs font-medium text-text-muted uppercase tracking-wider",children:"Switch Project"})}),(0,n.jsxs)("div",{className:"max-h-[300px] overflow-y-auto",role:"listbox",children:[r.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"px-3 py-1.5 bg-bg-tertiary/50",children:(0,n.jsxs)("span",{className:"text-[10px] font-medium text-text-muted uppercase tracking-wider flex items-center gap-1.5",children:[(0,n.jsx)(ew,{}),"Recent"]})}),(0,n.jsx)("div",{className:"py-1",children:r.map((e,t)=>(0,n.jsx)(ej,{project:e,index:t,isActive:(null==a?void 0:a.id)===e.id,isFocused:c===t,formatProjectName:f,buttonRefs:x,onSelect:()=>{l(e),i(!1)}},e.id))})]}),p.length>0&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"px-3 py-1.5 bg-bg-tertiary/50",children:(0,n.jsx)("span",{className:"text-[10px] font-medium text-text-muted uppercase tracking-wider",children:r.length>0?"All Projects":"Projects"})}),(0,n.jsx)("div",{className:"py-1",children:p.map((e,t)=>{let s=r.length+t;return(0,n.jsx)(ej,{project:e,index:s,isActive:(null==a?void 0:a.id)===e.id,isFocused:c===s,formatProjectName:f,buttonRefs:x,onSelect:()=>{l(e),i(!1)}},e.id)})})]})]})]})]})}function ej(e){var t,r;let{project:s,index:a,isActive:l,isFocused:o,formatProjectName:i,buttonRefs:c,onSelect:d}=e,u=i(s),x=(null===(t=s.agents)||void 0===t?void 0:t.length)||0;return(0,n.jsxs)("button",{ref:e=>{c.current[a]=e},className:"w-full flex items-center gap-3 px-3 py-2.5 text-left transition-colors border-none cursor-pointer ".concat(l?"bg-accent-cyan/10 text-accent-cyan":o?"bg-bg-hover text-text-primary":"bg-transparent text-text-primary hover:bg-bg-hover"),onClick:d,role:"option","aria-selected":l,tabIndex:o?0:-1,children:[(0,n.jsx)(eN,{className:l?"text-accent-cyan":"text-text-muted"}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"font-medium text-sm truncate",children:u}),(0,n.jsx)("div",{className:"text-xs text-text-muted truncate",children:s.path})]}),(0,n.jsxs)("span",{className:"text-xs px-2 py-0.5 rounded-full ".concat(l?"bg-accent-cyan/20 text-accent-cyan":"bg-bg-tertiary text-text-muted"),children:[x," ",1===x?"agent":"agents"]}),(null===(r=s.lead)||void 0===r?void 0:r.connected)&&(0,n.jsx)("span",{className:"w-2 h-2 rounded-full bg-success animate-pulse",title:"Lead: ".concat(s.lead.name)}),l&&(0,n.jsx)(eC,{})]})}function ew(){return(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("polyline",{points:"12 6 12 12 16 14"})]})}function eN(e){let{className:t="text-text-muted"}=e;return(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:(0,n.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"})})}function ek(e){let{isOpen:t}=e;return(0,n.jsx)("svg",{className:"text-text-muted transition-transform duration-150 ".concat(t?"rotate-180":""),width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:(0,n.jsx)("polyline",{points:"6 9 12 15 18 9"})})}function eC(){return(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-accent-cyan",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})})}function eS(e){let{expanded:t=!1,autoWakeup:r=!1,onWakeup:a,onStatusChange:l,className:o=""}=e,[i,d]=(0,s.useState)(!1),[x,m]=(0,s.useState)(""),{workspace:h,exists:p,isLoading:g,isWakingUp:f,statusMessage:b,actionNeeded:v,wakeup:y}=u({autoWakeup:r,onStatusChange:(e,t)=>{null==l||l(e),t?(m("Workspace is starting up..."),d(!0),setTimeout(()=>d(!1),5e3)):"running"===e&&(m("Workspace is ready!"),d(!0),setTimeout(()=>d(!1),3e3))}}),[j,w]=(0,s.useState)(!1),N=(0,s.useCallback)(async()=>{let e=await y();e.success&&(null==a||a(),m(e.message),d(!0),setTimeout(()=>d(!1),5e3))},[y,a]),k=(0,s.useCallback)(async()=>{if(!h)return;w(!0);let e=await c.xv.restartWorkspace(h.id);e.success?m(e.data.message):m(e.error),d(!0),setTimeout(()=>d(!1),5e3),w(!1)},[h]),C=p?g&&!h?{color:"text-text-muted",bgColor:"bg-bg-tertiary",borderColor:"border-border-subtle",icon:(0,n.jsx)(eT,{}),label:"Loading...",pulseColor:null}:(null==h?void 0:h.isRunning)?{color:"text-success",bgColor:"bg-success/10",borderColor:"border-success/30",icon:(0,n.jsx)(eL,{}),label:"Running",pulseColor:"bg-success"}:(null==h?void 0:h.isStopped)?{color:"text-amber-400",bgColor:"bg-amber-400/10",borderColor:"border-amber-400/30",icon:(0,n.jsx)(eM,{}),label:"Stopped",pulseColor:null}:(null==h?void 0:h.isProvisioning)||f?{color:"text-accent-cyan",bgColor:"bg-accent-cyan/10",borderColor:"border-accent-cyan/30",icon:(0,n.jsx)(eD,{}),label:f?"Starting...":"Provisioning",pulseColor:"bg-accent-cyan"}:(null==h?void 0:h.hasError)?{color:"text-error",bgColor:"bg-error/10",borderColor:"border-error/30",icon:(0,n.jsx)(eA,{}),label:"Error",pulseColor:null}:{color:"text-text-muted",bgColor:"bg-bg-tertiary",borderColor:"border-border-subtle",icon:(0,n.jsx)(eE,{}),label:"Unknown",pulseColor:null}:{color:"text-text-muted",bgColor:"bg-bg-tertiary",borderColor:"border-border-subtle",icon:(0,n.jsx)(eE,{}),label:"No workspace",pulseColor:null};return t?(0,n.jsxs)("div",{className:"rounded-lg border ".concat(C.borderColor," ").concat(C.bgColor," p-4 ").concat(o),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:C.color,children:C.icon}),(0,n.jsx)("span",{className:"text-sm font-semibold ".concat(C.color),children:"Workspace Status"})]}),C.pulseColor&&(0,n.jsx)("span",{className:"w-2.5 h-2.5 rounded-full ".concat(C.pulseColor," animate-pulse")})]}),(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-xs text-text-muted",children:"Name"}),(0,n.jsx)("span",{className:"text-sm text-text-primary font-medium truncate max-w-[150px]",children:(null==h?void 0:h.name)||"None"})]}),(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsx)("span",{className:"text-xs text-text-muted",children:"Status"}),(0,n.jsx)("span",{className:"text-sm font-medium ".concat(C.color),children:C.label})]}),b&&(0,n.jsx)("p",{className:"text-xs text-text-muted mt-2",children:b}),"wakeup"===v&&!f&&(0,n.jsx)("button",{onClick:N,className:"w-full mt-3 px-3 py-2 text-sm font-medium text-amber-400 bg-amber-400/10 border border-amber-400/30 rounded-lg hover:bg-amber-400/20 transition-colors",children:"Wake up workspace"}),"check_error"===v&&(0,n.jsxs)("div",{className:"flex gap-2 mt-3",children:[(0,n.jsx)("button",{onClick:k,disabled:j,className:"flex-1 px-3 py-2 text-sm font-medium text-accent-cyan bg-accent-cyan/10 border border-accent-cyan/30 rounded-lg hover:bg-accent-cyan/20 transition-colors disabled:opacity-50",children:j?"Restarting...":"Restart"}),(0,n.jsx)("a",{href:"/app/settings/workspace",className:"px-3 py-2 text-sm font-medium text-center text-text-muted bg-bg-tertiary border border-border-subtle rounded-lg hover:bg-bg-hover transition-colors no-underline",children:"Settings"})]})]}),i&&(0,n.jsx)("div",{className:"mt-3 px-3 py-2 bg-bg-card border border-border-medium rounded-lg text-sm text-text-primary animate-in fade-in",children:x})]}):(0,n.jsxs)("div",{className:"relative ".concat(o),children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-2.5 py-1.5 rounded-lg border ".concat(C.bgColor," ").concat(C.borderColor," cursor-default"),title:b||C.label,children:[(0,n.jsx)("span",{className:C.color,children:C.icon}),(0,n.jsx)("span",{className:"text-xs font-medium ".concat(C.color," truncate max-w-[100px]"),title:b||C.label,children:C.label}),C.pulseColor&&(0,n.jsx)("span",{className:"w-2 h-2 rounded-full ".concat(C.pulseColor," animate-pulse")})]}),"wakeup"===v&&!f&&(0,n.jsx)("button",{onClick:N,className:"ml-2 px-2 py-1 text-xs font-medium text-amber-400 bg-amber-400/10 border border-amber-400/30 rounded hover:bg-amber-400/20 transition-colors",children:"Wake up"}),i&&(0,n.jsx)("div",{className:"absolute top-full mt-2 left-0 z-50 px-3 py-2 bg-bg-card border border-border-medium rounded-lg shadow-lg text-sm text-text-primary whitespace-nowrap animate-in fade-in slide-in-from-top-2",children:x})]})}function eL(){return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polygon",{points:"5 3 19 12 5 21 5 3"})})}function eM(){return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("rect",{x:"6",y:"6",width:"12",height:"12"})})}function eD(){return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"animate-spin",children:(0,n.jsx)("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})})}function eA(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),(0,n.jsx)("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]})}function eE(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),(0,n.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"16"}),(0,n.jsx)("line",{x1:"8",y1:"12",x2:"16",y2:"12"})]})}function eT(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"animate-spin",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",strokeOpacity:"0.25"}),(0,n.jsx)("path",{d:"M12 2a10 10 0 0 1 10 10"})]})}function eW(e){let{currentChannel:t,selectedAgent:r,projects:s=[],currentProject:a,recentProjects:l=[],viewMode:o,selectedChannelName:i,onProjectChange:c,onCommandPaletteOpen:d,onSettingsClick:u,onHistoryClick:m,onNewConversationClick:h,onFleetClick:g,isFleetViewActive:f,onTrajectoryClick:b,hasActiveTrajectory:v,onMenuClick:y,hasUnreadNotifications:j}=e,w=r?(0,x.GW)(r.name):null;return(0,n.jsxs)("header",{className:"h-[52px] bg-bg-secondary border-b border-border-subtle flex items-center justify-between px-2 sm:px-4",children:[(0,n.jsxs)("button",{className:"flex md:hidden items-center justify-center w-10 h-10 sm:w-11 sm:h-11 bg-transparent border-none text-text-primary cursor-pointer rounded-lg transition-colors hover:bg-bg-hover active:bg-bg-hover relative flex-shrink-0",onClick:y,"aria-label":"Open menu",children:[(0,n.jsx)(eO,{}),j&&(0,n.jsx)("span",{className:"absolute top-1 right-1 sm:top-1.5 sm:right-1.5 w-2.5 h-2.5 bg-error rounded-full animate-pulse shadow-[0_0_8px_rgba(239,68,68,0.6)]"})]}),s.length>0&&c&&(0,n.jsx)("div",{className:"max-md:hidden mr-3",children:(0,n.jsx)(ey,{projects:s,recentProjects:l,currentProject:null!=a?a:null,onProjectChange:c})}),s.length>0&&c&&(0,n.jsx)("div",{className:"w-px h-6 bg-border-subtle mr-3 max-md:hidden"}),(0,n.jsx)(eS,{className:"max-md:hidden mr-3"}),(0,n.jsx)("div",{className:"w-px h-6 bg-border-subtle mr-3 max-md:hidden"}),(0,n.jsx)("div",{className:"flex items-center gap-2 sm:gap-3 flex-1 min-w-0",children:r&&!r.isHuman&&"dashboard"!==r.cli?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"w-7 h-7 sm:w-8 sm:h-8 rounded-lg flex items-center justify-center font-semibold text-[10px] sm:text-xs border-2 flex-shrink-0",style:{backgroundColor:null==w?void 0:w.primary,borderColor:null==w?void 0:w.primary,boxShadow:"0 0 12px ".concat(null==w?void 0:w.primary,"40")},children:(0,n.jsx)("span",{style:{color:null==w?void 0:w.text},children:(0,x.hP)(r.name)})}),(0,n.jsxs)("div",{className:"flex flex-col min-w-0",children:[(0,n.jsx)("span",{className:"font-display font-semibold text-sm sm:text-base text-text-primary truncate",children:r.name}),(0,n.jsx)("span",{className:"text-text-muted text-xs font-mono hidden md:block truncate",children:p(r.name)})]}),r.status&&(0,n.jsx)("span",{className:"hidden sm:inline text-xs py-1 px-2.5 rounded-full font-medium ml-2 flex-shrink-0 truncate max-w-[80px] ".concat("online"===r.status?"bg-success/20 text-success":"bg-bg-tertiary text-text-muted"),title:r.status,children:r.status})]}):r&&(r.isHuman||"dashboard"===r.cli)?null:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-accent-cyan text-base sm:text-lg font-mono",children:"@"}),(0,n.jsx)("span",{className:"font-display font-semibold text-sm sm:text-base text-text-primary truncate",children:t})]})}),(0,n.jsxs)("div",{className:"flex items-center gap-1 sm:gap-2",children:[(0,n.jsxs)("button",{className:"flex items-center gap-1 sm:gap-2 py-1.5 sm:py-2 px-2 sm:px-4 bg-gradient-to-r from-accent-cyan to-[#00b8d9] text-bg-deep font-semibold border-none rounded-lg text-xs sm:text-sm cursor-pointer transition-all duration-150 hover:shadow-glow-cyan hover:-translate-y-0.5",onClick:h,title:"Start new conversation (⌘N)",children:[(0,n.jsx)(eP,{}),(0,n.jsx)("span",{className:"hidden sm:inline",children:"New"}),(0,n.jsx)("span",{className:"hidden md:inline",children:"Message"})]}),(0,n.jsxs)("button",{className:"flex items-center gap-1 sm:gap-2 py-1.5 sm:py-2 px-2 sm:px-3 bg-bg-tertiary border border-border-subtle rounded-lg text-text-secondary text-xs sm:text-sm cursor-pointer transition-all duration-150 hover:bg-bg-elevated hover:border-border-medium hover:text-text-primary",onClick:d,title:"Command Palette (⌘K)",children:[(0,n.jsx)(eR,{}),(0,n.jsx)("span",{className:"hidden md:inline",children:"Search"}),(0,n.jsx)("kbd",{className:"hidden md:inline bg-bg-card border border-border-subtle rounded px-1.5 py-0.5 text-xs text-text-muted font-mono",children:"⌘K"})]}),(0,n.jsx)("button",{className:"hidden sm:flex items-center justify-center p-1.5 sm:p-2 bg-bg-tertiary border border-border-subtle rounded-lg text-text-secondary cursor-pointer transition-all duration-150 hover:bg-bg-elevated hover:border-border-medium hover:text-accent-cyan",onClick:m,title:"Message History",children:(0,n.jsx)(eI,{})}),g&&(0,n.jsx)("button",{className:"hidden sm:flex items-center justify-center p-1.5 sm:p-2 border rounded-lg cursor-pointer transition-all duration-150 ".concat(f?"bg-accent-cyan/20 border-accent-cyan text-accent-cyan":"bg-bg-tertiary border-border-subtle text-text-secondary hover:bg-bg-elevated hover:border-border-medium hover:text-accent-cyan"),onClick:g,title:f?"Back to Chat":"Fleet Overview",children:(0,n.jsx)(eF,{})}),b&&(0,n.jsxs)("button",{className:"hidden md:flex items-center justify-center p-2 border rounded-lg cursor-pointer transition-all duration-150 relative ".concat(v?"bg-accent-cyan/20 border-accent-cyan text-accent-cyan":"bg-bg-tertiary border-border-subtle text-text-secondary hover:bg-bg-elevated hover:border-border-medium hover:text-accent-cyan"),onClick:b,title:"Trajectory Viewer",children:[(0,n.jsx)(eU,{}),v&&(0,n.jsx)("span",{className:"absolute -top-1 -right-1 w-2 h-2 bg-accent-cyan rounded-full animate-pulse"})]}),(0,n.jsx)("a",{href:"/metrics",className:"hidden sm:flex items-center justify-center p-1.5 sm:p-2 bg-bg-tertiary border border-border-subtle rounded-lg text-text-secondary cursor-pointer transition-all duration-150 hover:bg-bg-elevated hover:border-border-medium hover:text-accent-orange no-underline",title:"Fleet Metrics",children:(0,n.jsx)(eB,{})}),(0,n.jsx)("button",{className:"flex items-center justify-center p-1.5 sm:p-2 bg-bg-tertiary border border-border-subtle rounded-lg text-text-secondary cursor-pointer transition-all duration-150 hover:bg-bg-elevated hover:border-border-medium hover:text-accent-purple",onClick:u,title:"Settings",children:(0,n.jsx)(e_,{})})]})]})}function eP(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[(0,n.jsx)("path",{d:"M12 20h9"}),(0,n.jsx)("path",{d:"M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"})]})}function eR(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function eI(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("polyline",{points:"12 6 12 12 16 14"})]})}function eB(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M3 3v18h18"}),(0,n.jsx)("path",{d:"M18 17V9"}),(0,n.jsx)("path",{d:"M13 17V5"}),(0,n.jsx)("path",{d:"M8 17v-3"})]})}function eF(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"}),(0,n.jsx)("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),(0,n.jsx)("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}function eU(){return(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("path",{d:"M3 12h4l3 9 4-18 3 9h4"})})}function e_(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,n.jsx)("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"})]})}function eO(){return(0,n.jsxs)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"3",y1:"12",x2:"21",y2:"12"}),(0,n.jsx)("line",{x1:"3",y1:"6",x2:"21",y2:"6"}),(0,n.jsx)("line",{x1:"3",y1:"18",x2:"21",y2:"18"})]})}function eH(e){let{status:t,size:r="small"}=e;if(!t)return null;let s={small:"w-3.5 h-3.5",medium:"w-4 h-4"}[r];return"sending"===t||"unread"===t?(0,n.jsx)("span",{className:"inline-flex items-center justify-center ".concat(s," text-text-muted"),title:"Sending...",children:(0,n.jsx)(ez,{className:s})}):"acked"===t||"read"===t?(0,n.jsx)("span",{className:"inline-flex items-center justify-center ".concat(s," text-success"),title:"Delivered",children:(0,n.jsx)(eG,{className:s})}):"failed"===t?(0,n.jsx)("span",{className:"inline-flex items-center justify-center ".concat(s," text-error"),title:"Delivery failed",children:(0,n.jsx)(eV,{className:s})}):null}function ez(e){let{className:t}=e;return(0,n.jsxs)("svg",{className:"animate-pulse ".concat(t),viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[(0,n.jsx)("circle",{cx:"8",cy:"8",r:"6"}),(0,n.jsx)("path",{d:"M8 5v3l2 1",strokeLinecap:"round",strokeLinejoin:"round"})]})}function eG(e){let{className:t}=e;return(0,n.jsx)("svg",{className:t,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.jsx)("path",{d:"M3 8l3 3 7-7",strokeLinecap:"round",strokeLinejoin:"round"})})}function eV(e){let{className:t}=e;return(0,n.jsxs)("svg",{className:t,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("circle",{cx:"8",cy:"8",r:"6"}),(0,n.jsx)("line",{x1:"8",y1:"5",x2:"8",y2:"8",strokeLinecap:"round"}),(0,n.jsx)("circle",{cx:"8",cy:"11",r:"0.5",fill:"currentColor",stroke:"none"})]})}function eK(e){let{displayName:t,color:r,isCurrentUser:a=!1,agent:l,userPresence:o,onAgentClick:i,onUserClick:c,className:d=""}=e,u=(0,s.useCallback)(()=>{l&&i?i(l):o&&c&&c(o)},[l,o,i,c]);return l&&i||o&&c?(0,n.jsx)("button",{type:"button",onClick:u,className:"\n font-display font-semibold text-sm\n bg-transparent border-none p-0 m-0\n cursor-pointer\n transition-all duration-150\n hover:underline hover:decoration-current hover:decoration-1 hover:underline-offset-2\n focus:outline-none focus:ring-2 focus:ring-offset-1 focus:ring-accent-cyan/50 focus:rounded-sm\n ".concat(d,"\n "),style:{color:r},title:"View ".concat(l?"agent":"user"," profile: ").concat(t),children:t}):(0,n.jsx)("span",{className:"font-display font-semibold text-sm ".concat(d),style:{color:r},children:t})}var eZ=r(1832),eq=r(2446);let eJ=(0,s.createContext)({wsBaseUrl:null,isCloudMode:!1});function e$(e){let{children:t,wsUrl:r}=e,a=(0,s.useMemo)(()=>{if(!r)return{wsBaseUrl:null,isCloudMode:!1};let e=function(e){try{let t=new URL(e);return"".concat(t.protocol,"//").concat(t.host)}catch(t){return e}}(r),t=!1;try{t=new URL(r).host!==window.location.host}catch(e){}return{wsBaseUrl:e,isCloudMode:t}},[r]);return(0,n.jsx)(eJ.Provider,{value:a,children:t})}function eY(e){let{wsBaseUrl:t}=(0,s.useContext)(eJ);return(0,s.useMemo)(()=>t?"".concat(t).concat(e):(0,eq.HE)(e),[t,e])}let eX=0;function eQ(){return"log-".concat(Date.now(),"-").concat(++eX)}function e0(e){let{agentName:t,maxLines:r=5e3,autoConnect:n=!0,reconnect:a=!0,maxReconnectAttempts:l=1/0}=e,o=eY("/ws/logs/".concat(encodeURIComponent(t))),[i,c]=(0,s.useState)([]),[d,u]=(0,s.useState)(!1),[x,m]=(0,s.useState)(!1),[h,p]=(0,s.useState)("disconnected"),[g,f]=(0,s.useState)(null),b=(0,s.useRef)(null),v=(0,s.useRef)(0),y=(0,s.useRef)(null),j=(0,s.useRef)(t),w=(0,s.useRef)(!0),N=(0,s.useRef)(!1),k=(0,s.useRef)(new WeakMap),C=(0,s.useRef)(new WeakMap),S=(0,s.useRef)(null),L=(0,s.useRef)(!1),M=(0,s.useRef)(new Set);j.current=t;let D=(0,s.useCallback)((e,t)=>"".concat(t,":").concat(e.slice(0,100)),[]),A=(0,s.useCallback)(()=>{var e,t;if(w.current=!0,(null===(e=b.current)||void 0===e?void 0:e.readyState)!==WebSocket.OPEN&&(null===(t=b.current)||void 0===t?void 0:t.readyState)!==WebSocket.CONNECTING&&!N.current){L.current&&p("reconnecting"),N.current=!0,m(!0),f(null);try{let e=new WebSocket(o);b.current=e,k.current.set(e,!1),C.current.set(e,!1),e.onopen=()=>{N.current=!1,u(!0),m(!1),p("connected"),f(null),v.current=0,L.current&&null!==S.current&&(console.log("[WS:Logs] Requesting replay from timestamp ".concat(S.current)),e.send(JSON.stringify({type:"replay",agent:j.current,lastTimestamp:S.current}))),L.current=!0,c(e=>[...e,{id:eQ(),timestamp:Date.now(),content:"Connected to ".concat(j.current," log stream"),type:"system",agentName:j.current}])},e.onclose=t=>{var r,n;let s=null!==(r=k.current.get(e))&&void 0!==r&&r,o=null!==(n=C.current.get(e))&&void 0!==n&&n;if(N.current=!1,u(!1),m(!1),b.current=null,y.current&&(clearTimeout(y.current),y.current=null),s||4404===t.code){p("disconnected");return}if(!t.wasClean&&o){let e=w.current&&a&&v.current<l;c(r=>[...r,{id:eQ(),timestamp:Date.now(),content:e?"Lost connection to log stream (code: ".concat(t.code,"). Reconnecting..."):"Disconnected from log stream (code: ".concat(t.code,")"),type:"system",agentName:j.current}])}if(w.current&&a&&v.current<l){p("reconnecting");let e=Math.min(500*Math.pow(2,v.current),15e3);v.current++,console.log("[WS:Logs] Reconnecting (attempt ".concat(v.current,")...")),y.current=setTimeout(()=>{A()},Math.round(e*(.5+.5*Math.random())))}else p("disconnected")},e.onerror=()=>{N.current=!1,f(Error("WebSocket connection error")),m(!1)},e.onmessage=t=>{try{let n=JSON.parse(t.data);if("error"===n.type){f(Error(n.error||"Failed to stream logs for ".concat(n.agent||j.current))),c(e=>[...e,{id:eQ(),timestamp:Date.now(),content:"Error: ".concat(n.error||"Unknown error"),type:"system",agentName:n.agent||j.current}]);return}if("subscribed"===n.type){console.log("[useAgentLogs] Subscribed to ".concat(n.agent));return}if("replay"===n.type&&Array.isArray(n.entries)){C.current.set(e,!0),c(e=>{let t=[];for(let e of n.entries){var s;let r=e.content||"",n=e.timestamp||Date.now(),a=D(r,n);!M.current.has(a)&&(M.current.add(a),t.push({id:eQ(),timestamp:n,content:r,type:"stdout",agentName:j.current}),n>(null!==(s=S.current)&&void 0!==s?s:0)&&(S.current=n))}return 0===t.length?e:[...e,...t].slice(-r)});return}if("history"===n.type&&Array.isArray(n.lines)){n.lines.length>0&&C.current.set(e,!0),c(e=>{let t=n.lines.map(e=>{let t=Date.now(),r=D(e,t);return M.current.add(r),S.current=t,{id:eQ(),timestamp:t,content:e,type:"stdout",agentName:n.agent||j.current}});return[...e,...t].slice(-r)});return}if("string"==typeof n){C.current.set(e,!0);let t=Date.now();S.current=t;let s=D(n,t);M.current.add(s),c(e=>[...e,{id:eQ(),timestamp:t,content:n,type:"stdout",agentName:j.current}].slice(-r))}else if("log"===n.type||"output"===n.type){C.current.set(e,!0);let t=n.timestamp||Date.now(),s=n.content||n.data||n.message||"";S.current=t;let a=D(s,t);M.current.add(a),c(e=>{let a="stderr"===n.stream?"stderr":"stdout";return[...e,{id:eQ(),timestamp:t,content:s,type:a,agentName:n.agentName||j.current}].slice(-r)})}else n.lines&&Array.isArray(n.lines)&&(C.current.set(e,!0),c(e=>{let t=n.lines.map(e=>{let t="object"==typeof e&&"stderr"===e.type?"stderr":"stdout",r="string"==typeof e?e:e.content,n=Date.now();S.current=n;let s=D(r,n);return M.current.add(s),{id:eQ(),timestamp:n,content:r,type:t,agentName:j.current}});return[...e,...t].slice(-r)}));if(M.current.size>2e3){let e=Array.from(M.current);M.current=new Set(e.slice(-1e3))}}catch(n){if("string"==typeof t.data){C.current.set(e,!0);let n=Date.now();S.current=n,c(e=>[...e,{id:eQ(),timestamp:n,content:t.data,type:"stdout",agentName:j.current}].slice(-r))}}}}catch(e){N.current=!1,f(e instanceof Error?e:Error("Failed to create WebSocket")),m(!1)}}},[o,r,a,l,D]),E=(0,s.useCallback)(()=>{w.current=!1,y.current&&(clearTimeout(y.current),y.current=null),b.current&&(k.current.set(b.current,!0),b.current.close(),b.current=null),N.current=!1,u(!1),m(!1),p("disconnected")},[]),T=(0,s.useCallback)(()=>{c([]),M.current.clear()},[]);return(0,s.useEffect)(()=>(n&&t&&A(),()=>{E()}),[t,n,A,E]),(0,s.useEffect)(()=>{let e=()=>{"visible"!==document.visibilityState||b.current&&b.current.readyState!==WebSocket.CLOSED||(console.log("[WS:Logs] Tab visible, reconnecting..."),v.current=0,A())};return document.addEventListener("visibilitychange",e),()=>{document.removeEventListener("visibilitychange",e)}},[A]),{logs:i,isConnected:d,isConnecting:x,connectionState:h,error:g,connect:A,disconnect:E,clear:T}}function e1(e){let{agentName:t,lines:r=2,compact:a=!1,onExpand:l,className:o=""}=e,{logs:i,isConnected:c,isConnecting:d,error:u}=e0({agentName:t,autoConnect:!0,maxLines:50}),m=(0,x.GW)(t),h=(0,s.useMemo)(()=>{let e=/^[⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏⣾⣽⣻⢿⡿⣟⣯⣷◐◓◑◒●○◉◎|\\\/\-*.\u2800-\u28FF]+$/,t=[];for(let r of i)if("system"!==r.type)for(let n of(function(e){if(!e)return"";let t=e;return(t=(t=(t=(t=(t=(t=(t=(t=(t=t.replace(RegExp("\\x1b\\].*?(?:\\x07|\\x1b\\\\)","gs"),"")).replace(RegExp("\\x1bP.*?\\x1b\\\\","gs"),"")).replace(/\x1b\[[0-9;?]*[ -/]*[@-~]/g,"")).replace(/\x1b[@-Z\\-_]/g,"")).replace(/^\[\??\d+[hlKJHfABCDGPXsu]/gm,"")).replace(/\[\d+(?:;\d+)*m/g,"")).replace(/\r/g,"")).replace(/.\x08/g,"")).replace(/\x08+/g,"")).replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g,"")})(r.content).split("\n")){let r=n.trim();0!==r.length&&(r.length<=2&&e.test(r)||t.push(n.replace(/\s+$/g,"")))}return t.slice(-Math.max(1,r))},[i,r]),p=d?{label:"connecting",cls:"bg-[#d29922]/15 text-[#d29922]"}:c?{label:"live",cls:"bg-[#238636]/15 text-[#3fb950]"}:u?{label:"error",cls:"bg-[#f85149]/15 text-[#f85149]"}:{label:"offline",cls:"bg-[#484f58]/15 text-[#8b949e]"};return(0,n.jsxs)("div",{className:"mt-2 rounded-lg border ".concat(o),style:{borderColor:"".concat(m.primary,"35"),background:"linear-gradient(180deg, rgba(13,15,20,0.9) 0%, rgba(18,21,28,0.9) 100%)",boxShadow:"inset 0 1px 0 rgba(255,255,255,0.02)"},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between ".concat(a?"px-2 py-1":"px-2.5 py-1.5"," border-b border-[#2a2d35]/70"),children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0",children:[(0,n.jsx)(e2,{}),(0,n.jsx)("span",{className:"text-[11px] font-medium truncate",style:{color:m.primary},children:"Logs"}),(0,n.jsx)("span",{className:"px-1.5 py-0.5 rounded-full text-[10px] uppercase tracking-wider font-medium ".concat(p.cls),children:p.label})]}),l&&(0,n.jsx)("button",{type:"button",className:"p-1.5 rounded-lg hover:bg-[#21262d] text-[#8b949e] hover:text-accent-cyan transition-all duration-200",onClick:l,title:"Expand logs",children:(0,n.jsx)(e5,{})})]}),(0,n.jsx)("div",{className:"".concat(a?"px-2 py-1.5":"px-2.5 py-2"," font-mono text-[11px] leading-4"),children:h.length>0?h.map((e,t)=>(0,n.jsx)("div",{className:"text-[#c9d1d9] truncate",children:e},t)):(0,n.jsx)("div",{className:"text-[#8b949e] italic",children:(null==u?void 0:u.message)||"Waiting for output..."})})]})}function e2(e){let{size:t=14}=e;return(0,n.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-[#8b949e]",children:[(0,n.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,n.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]})}function e5(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("polyline",{points:"15 3 21 3 21 9"}),(0,n.jsx)("polyline",{points:"9 21 3 21 3 15"}),(0,n.jsx)("line",{x1:"21",y1:"3",x2:"14",y2:"10"}),(0,n.jsx)("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]})}var e4=r(3458);let e3=["\uD83D\uDC4D","\uD83D\uDC4E","❤️","\uD83D\uDD25","\uD83D\uDC40","\uD83C\uDF89","\uD83D\uDE02","\uD83E\uDD14","✅","❌","\uD83D\uDE80","\uD83D\uDCAF","⚡","\uD83D\uDE4F","\uD83D\uDC4F","\uD83E\uDD16"];function e6(e){var t,r;let{onSelect:a,onClose:l,anchorRef:o}=e,i=(0,s.useRef)(null);(0,s.useEffect)(()=>{function e(e){var t;!i.current||i.current.contains(e.target)||(null==o?void 0:null===(t=o.current)||void 0===t?void 0:t.contains(e.target))||l()}function t(e){"Escape"===e.key&&l()}return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)}},[l]);let[c,d]=s.useState(null),u=s.useCallback(()=>{if(!(null==o?void 0:o.current))return;let e=o.current.getBoundingClientRect();d({top:e.top>88?e.top-80-4:e.bottom+4,left:e.left})},[o]);return(0,s.useEffect)(()=>(u(),window.addEventListener("scroll",u,!0),window.addEventListener("resize",u),()=>{window.removeEventListener("scroll",u,!0),window.removeEventListener("resize",u)}),[u]),(0,e4.createPortal)((0,n.jsx)("div",{ref:i,style:{position:"fixed",top:null!==(t=null==c?void 0:c.top)&&void 0!==t?t:0,left:null!==(r=null==c?void 0:c.left)&&void 0!==r?r:0,zIndex:9999,visibility:c?"visible":"hidden",background:"var(--color-bg-elevated, #202030)",border:"1px solid var(--color-border-subtle, rgba(255,255,255,0.06))",borderRadius:8,padding:8,boxShadow:"0 10px 25px rgba(0,0,0,0.5)"},children:(0,n.jsx)("div",{style:{display:"grid",gridTemplateColumns:"repeat(8, 1fr)",gap:2},children:e3.map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>{a(e),l()},style:{width:32,height:32,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:6,fontSize:18,cursor:"pointer",border:"none",background:"transparent",transition:"background 150ms"},onMouseEnter:e=>{e.currentTarget.style.background="var(--color-bg-hover, rgba(255,255,255,0.08))"},onMouseLeave:e=>{e.currentTarget.style.background="transparent"},children:e},e))})}),document.body)}function e8(e){let{reactions:t,messageId:r,currentUser:a,onToggleReaction:l}=e,[o,i]=(0,s.useState)(!1),c=(0,s.useRef)(null),d=t&&t.length>0;return(0,n.jsxs)("div",{className:"flex flex-wrap items-center gap-1 mt-1.5",children:[d&&t.map(e=>{let t=!!a&&(e.agents||[]).includes(a);return(0,n.jsxs)("button",{type:"button",onClick:()=>l(r,e.emoji,t),className:"\n inline-flex items-center gap-1 px-2 py-0.5 rounded-full text-xs border cursor-pointer transition-colors\n ".concat(t?"bg-accent-cyan/15 border-accent-cyan/40 text-accent-cyan":"bg-bg-tertiary border-border-subtle text-text-muted hover:bg-bg-hover","\n "),children:[(0,n.jsx)("span",{children:e.emoji}),(0,n.jsx)("span",{className:"font-medium",children:e.count})]},e.emoji)}),(0,n.jsx)("button",{ref:c,type:"button",onClick:()=>i(!o),className:"inline-flex items-center justify-center w-6 h-6 rounded-full text-xs text-text-muted bg-transparent border border-border-subtle hover:bg-bg-hover cursor-pointer transition-colors",title:"Add reaction",children:"+"}),o&&(0,n.jsx)(e6,{anchorRef:c,onSelect:e=>{let n=t.find(t=>t.emoji===e);l(r,e,!!(a&&(null==n?void 0:n.agents.includes(a))))},onClose:()=>i(!1)})]})}let e9={claude:{icon:"◈",color:"#00d9ff"},codex:{icon:"⬡",color:"#ff6b35"},gemini:{icon:"◇",color:"#a855f7"},openai:{icon:"◆",color:"#10a37f"},default:{icon:"●",color:"#00d9ff"}};function e7(e){let t=e.toLowerCase();if(t.includes("claude")||t.includes("anthropic"))return e9.claude;if(t.includes("codex")||t.includes("openai")||t.includes("gpt"))return e9.codex;if(t.includes("gemini")||t.includes("google")||t.includes("bard"))return e9.gemini;let r=e.split("").reduce((e,t)=>e+t.charCodeAt(0),0),n=Object.keys(e9).filter(e=>"default"!==e);return e9[n[r%n.length]]}function te(e){let{messages:t,currentChannel:r,onThreadClick:a,highlightedMessageId:l,currentThread:o,agents:i=[],currentUser:c,skipChannelFilter:d=!1,autoScrollDefault:u=!0,showTimestamps:x=!0,compactMode:m=!1,onAgentClick:h,onUserClick:p,onLogsClick:g,onlineUsers:f=[],onReaction:b}=e,v=new Map;for(let e of i)e.isProcessing&&v.set(e.name,{isProcessing:!0,processingStartedAt:e.processingStartedAt});let y=new Map,j=(0,s.useRef)(null),w=(0,s.useRef)(null),[N,k]=(0,s.useState)(u),C=(0,s.useRef)(0),S=(0,s.useRef)(r),L=(0,s.useRef)(!1),M=(0,s.useRef)(!1),D=(0,s.useRef)(null);(0,s.useEffect)(()=>{k(u)},[u]);let A=t.filter(e=>o?e.id===o||e.thread===o:!!d||r!==sz&&("#general"===r?"general"===e.channel||"#general"===e.channel||"#general"===e.to:e.from===r||e.to===r));for(let e of A)("Dashboard"===e.from||c&&e.from===c.displayName)&&"*"!==e.to&&y.set(e.to,e.id);let E=A.length;if(E>C.current){let e=A[A.length-1],t=(null==e?void 0:e.from)==="Dashboard"||c&&(null==e?void 0:e.from)===c.displayName;u&&(t||N)&&(L.current=!0,t&&!N&&k(!0))}C.current=E;let T=(0,s.useCallback)(()=>{if(!j.current||M.current||!u)return;let e=j.current,t=e.scrollHeight-e.scrollTop-e.clientHeight;t<50&&!N?k(!0):t>150&&N&&k(!1)},[N]);return((0,s.useEffect)(()=>{if(!u||!N||"undefined"==typeof ResizeObserver)return;let e=w.current;if(!e)return;let t=new ResizeObserver(()=>{N&&j.current&&null===D.current&&(D.current=requestAnimationFrame(()=>{if(D.current=null,!N||!j.current)return;M.current=!0;let e=j.current;e.scrollTop=e.scrollHeight,requestAnimationFrame(()=>{setTimeout(()=>{M.current=!1},50)})}))});return t.observe(e),()=>{t.disconnect(),null!==D.current&&(cancelAnimationFrame(D.current),D.current=null)}},[N,u]),(0,s.useLayoutEffect)(()=>{if(L.current&&j.current){L.current=!1,M.current=!0;let e=j.current;e.scrollTop=e.scrollHeight,requestAnimationFrame(()=>{setTimeout(()=>{M.current=!1},50)})}},[A.length]),(0,s.useLayoutEffect)(()=>{if(r!==S.current&&(S.current=r,C.current=A.length,k(!0),j.current)){M.current=!0;let e=j.current;e.scrollTop=e.scrollHeight,requestAnimationFrame(()=>{setTimeout(()=>{M.current=!1},50)})}},[r,A.length]),0===A.length)?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-full text-text-muted text-center",children:[(0,n.jsx)(tn,{}),(0,n.jsx)("h3",{className:"m-0 mb-2 text-base font-display text-text-secondary",children:"No messages yet"}),(0,n.jsx)("p",{className:"m-0 text-sm",children:"Messages in ".concat(r," will appear here")})]}):(0,n.jsx)("div",{className:"bg-bg-secondary h-full overflow-y-auto",ref:j,onScroll:T,children:(0,n.jsx)("div",{ref:w,className:"flex flex-col ".concat(m?"gap-0 p-1 sm:p-1.5":"gap-2 p-3 sm:p-4"),children:A.map(e=>{let t=("Dashboard"===e.from||c&&e.from===c.displayName)&&"*"!==e.to&&y.get(e.to)===e.id?v.get(e.to):void 0;return(0,n.jsx)(tt,{message:e,isHighlighted:e.id===l,onThreadClick:a,recipientProcessing:t,currentUser:c,showTimestamps:x,compactMode:m,agents:i,onlineUsers:f,onAgentClick:h,onUserClick:p,onLogsClick:g,onReaction:b},e.id)})})})}function tt(e){var t,r,s;let{message:a,isHighlighted:l,onThreadClick:o,recipientProcessing:i,currentUser:c,showTimestamps:d=!0,compactMode:u=!1,agents:x=[],onlineUsers:m=[],onAgentClick:h,onUserClick:p,onLogsClick:g,onReaction:f}=e,b=function(e){let t=new Date(e),r=new Date;if(t.toDateString()===r.toDateString())return t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"});let n=new Date(r);return(n.setDate(n.getDate()-1),t.toDateString()===n.toDateString())?"Yesterday ".concat(t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})):t.toLocaleDateString([],{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}(a.timestamp),y="Dashboard"===a.from||c&&a.from===c.displayName,j=y&&c?{icon:"",color:"#a855f7"}:e7(a.from),w=y&&c?c.displayName:a.from,N=null!==(s=null!==(r=null===(t=a.threadSummary)||void 0===t?void 0:t.replyCount)&&void 0!==r?r:a.replyCount)&&void 0!==s?s:0,k=N>0,C=x.find(e=>e.name.toLowerCase()===a.from.toLowerCase()&&!e.isHuman),S=m.find(e=>e.username.toLowerCase()===a.from.toLowerCase()),L="*"!==a.to?x.find(e=>e.name.toLowerCase()===a.to.toLowerCase()&&!e.isHuman):void 0,M="*"!==a.to?m.find(e=>e.username.toLowerCase()===a.to.toLowerCase()):void 0,D=L?e7(a.to):void 0,A=y&&("acked"===a.status||"read"===a.status)&&(null==i?void 0:i.isProcessing);return(0,n.jsxs)("div",{className:"\n group flex rounded-xl transition-all duration-150\n ".concat(u?"gap-1.5 py-1 px-1.5":"gap-3 sm:gap-4 py-2.5 sm:py-3 px-3 sm:px-4","\n hover:bg-bg-card/50\n ").concat(l?"bg-warning-light/20 border-l-2 border-l-warning pl-2 sm:pl-3":"","\n "),children:[y&&(null==c?void 0:c.avatarUrl)?(0,n.jsx)("img",{src:c.avatarUrl,alt:w,className:"shrink-0 rounded-lg sm:rounded-xl border-2 object-cover ".concat(u?"w-6 h-6 sm:w-7 sm:h-7":"w-9 h-9 sm:w-10 sm:h-10"),style:{borderColor:j.color,boxShadow:"0 0 16px ".concat(j.color,"30")}}):(null==S?void 0:S.avatarUrl)?(0,n.jsx)("img",{src:S.avatarUrl,alt:w,className:"shrink-0 rounded-lg sm:rounded-xl border-2 object-cover ".concat(u?"w-6 h-6 sm:w-7 sm:h-7":"w-9 h-9 sm:w-10 sm:h-10"),style:{borderColor:j.color,boxShadow:"0 0 16px ".concat(j.color,"30")}}):(0,n.jsx)("div",{className:"shrink-0 rounded-lg sm:rounded-xl flex items-center justify-center font-medium border-2 ".concat(u?"w-6 h-6 sm:w-7 sm:h-7 text-xs sm:text-sm":"w-9 h-9 sm:w-10 sm:h-10 text-base sm:text-lg"),style:{backgroundColor:"".concat(j.color,"15"),borderColor:j.color,color:j.color,boxShadow:"0 0 16px ".concat(j.color,"30")},children:j.icon}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 flex-wrap ".concat(u?"mb-0.5":"mb-1.5"),children:[(0,n.jsx)(eK,{displayName:w,color:j.color,isCurrentUser:y,agent:C,userPresence:S,onAgentClick:h,onUserClick:p}),"*"!==a.to&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-text-dim text-xs",children:"→"}),(0,n.jsx)(eK,{displayName:a.to,color:(null==D?void 0:D.color)||"#00d9ff",agent:L,userPresence:M,onAgentClick:h,onUserClick:p})]}),a.thread&&(0,n.jsx)("span",{className:"text-xs py-0.5 px-2 rounded-full font-mono font-medium bg-accent-purple/20 text-accent-purple",children:a.thread}),"*"===a.to&&(0,n.jsx)("span",{className:"text-xs py-0.5 px-2 rounded-full uppercase font-medium bg-warning/20 text-warning",children:"broadcast"}),d&&(0,n.jsx)("span",{className:"text-text-dim text-xs ml-auto font-mono",children:b}),y&&(0,n.jsx)(eH,{status:a.status,size:"small"}),A&&(0,n.jsx)(v,{isProcessing:!0,processingStartedAt:null==i?void 0:i.processingStartedAt,size:"small",showLabel:!0}),(0,n.jsxs)("button",{className:"\n inline-flex items-center gap-1.5 p-1.5 rounded-lg transition-all duration-150 cursor-pointer border-none\n ".concat(k||a.thread?"text-accent-cyan bg-accent-cyan/10 hover:bg-accent-cyan/20":"text-text-muted bg-transparent opacity-0 group-hover:opacity-100 hover:text-accent-cyan hover:bg-accent-cyan/10","\n "),onClick:()=>null==o?void 0:o(a.thread||a.id),title:a.thread?"View thread: ".concat(a.thread):k?"".concat(N," ").concat(1===N?"reply":"replies"):"Reply in thread",children:[(0,n.jsx)(ts,{}),k&&(0,n.jsx)("span",{className:"text-xs font-medium",children:N})]})]}),(0,n.jsx)("div",{className:"text-sm leading-relaxed text-text-primary whitespace-pre-wrap break-words",children:(0,eZ.y)(a.content)}),a.attachments&&a.attachments.length>0&&(0,n.jsx)(tr,{attachments:a.attachments}),f&&(0,n.jsx)(e8,{reactions:a.reactions||[],messageId:a.id,currentUser:(null==c?void 0:c.displayName)||"user",onToggleReaction:f}),A&&L&&(0,n.jsx)(e1,{agentName:L.name,lines:5,compact:u,onExpand:g?()=>g(L):void 0})]})]})}function tr(e){let{attachments:t}=e,[r,a]=(0,s.useState)(null),l=t.filter(e=>e.mimeType.startsWith("image/"));return 0===l.length?null:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex flex-wrap gap-2 mt-2",children:l.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>a(e),className:"relative group cursor-pointer bg-transparent border-0 p-0",title:"View ".concat(e.filename),children:[(0,n.jsx)("img",{src:e.data||e.url,alt:e.filename,className:"max-h-48 max-w-xs rounded-lg border border-border-subtle object-cover transition-all duration-150 group-hover:border-accent-cyan/50 group-hover:shadow-[0_0_8px_rgba(0,217,255,0.2)]",loading:"lazy"}),(0,n.jsx)("div",{className:"absolute inset-0 bg-black/0 group-hover:bg-black/10 rounded-lg transition-colors flex items-center justify-center opacity-0 group-hover:opacity-100",children:(0,n.jsxs)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2",className:"drop-shadow-lg",children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"}),(0,n.jsx)("line",{x1:"11",y1:"8",x2:"11",y2:"14"}),(0,n.jsx)("line",{x1:"8",y1:"11",x2:"14",y2:"11"})]})})]},e.id))}),r&&(0,n.jsx)("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/80 backdrop-blur-sm",onClick:()=>a(null),children:(0,n.jsxs)("div",{className:"relative max-w-[90vw] max-h-[90vh]",children:[(0,n.jsx)("img",{src:r.data||r.url,alt:r.filename,className:"max-w-full max-h-[90vh] rounded-lg shadow-2xl",onClick:e=>e.stopPropagation()}),(0,n.jsx)("button",{type:"button",onClick:()=>a(null),className:"absolute -top-3 -right-3 w-8 h-8 bg-bg-tertiary border border-border-subtle rounded-full flex items-center justify-center text-text-muted hover:text-text-primary hover:bg-bg-card transition-colors shadow-lg",title:"Close",children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}),(0,n.jsx)("div",{className:"absolute bottom-0 left-0 right-0 p-3 bg-gradient-to-t from-black/60 to-transparent rounded-b-lg",children:(0,n.jsx)("p",{className:"text-white text-sm truncate",children:r.filename})})]})})]})}function tn(){return(0,n.jsx)("svg",{className:"mb-4 opacity-50 text-text-muted",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:(0,n.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"})})}function ts(){return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.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"})})}function ta(e){let{originalMessage:t,replies:r,onClose:a,onReply:l,isSending:o=!1,currentUser:i,showTimestamps:c=!0,isLoading:d=!1,hasMore:u=!1,onLoadMore:x}=e,[m,h]=(0,s.useState)(""),p=(0,s.useRef)(null),g=(0,s.useRef)(null);(0,s.useEffect)(()=>{requestAnimationFrame(()=>{var e;null===(e=p.current)||void 0===e||e.scrollIntoView({behavior:"smooth"})})},[null==r?void 0:r.length]),(0,s.useEffect)(()=>{var e;null===(e=g.current)||void 0===e||e.focus()},[null==t?void 0:t.id]);let f=async e=>{e.preventDefault(),m.trim()&&!o&&await l(m.trim())&&h("")};return t?(0,n.jsxs)("div",{className:"flex flex-col h-full bg-bg-primary border-l border-border",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border bg-bg-secondary",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(ti,{}),(0,n.jsx)("span",{className:"font-semibold text-sm text-text-primary",children:"Thread"}),(0,n.jsxs)("span",{className:"text-text-muted text-xs",children:[(null==r?void 0:r.length)||0," ",(null==r?void 0:r.length)===1?"reply":"replies"]})]}),(0,n.jsx)("button",{onClick:a,className:"p-1.5 rounded hover:bg-bg-hover transition-colors text-text-muted hover:text-text-primary",title:"Close thread",children:(0,n.jsx)(tc,{})})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto",children:[(0,n.jsx)("div",{className:"p-4 border-b border-border",children:(0,n.jsx)(tl,{message:t,isOriginal:!0,currentUser:i,showTimestamps:c})}),(0,n.jsxs)("div",{className:"p-4 space-y-3",children:[u&&(0,n.jsx)("div",{className:"text-center pb-2",children:(0,n.jsx)("button",{type:"button",onClick:x,disabled:d,className:"text-xs text-accent-cyan hover:text-accent-cyan/80 transition-colors cursor-pointer bg-transparent border-none disabled:opacity-50",children:d?"Loading...":"Load earlier replies"})}),d&&0===r.length?(0,n.jsx)("div",{className:"text-center text-text-muted text-sm py-8",children:"Loading thread..."}):0===r.length?(0,n.jsx)("div",{className:"text-center text-text-muted text-sm py-8",children:"No replies yet. Be the first to reply!"}):r.map(e=>(0,n.jsx)(tl,{message:e,currentUser:i,showTimestamps:c},e.id)),(0,n.jsx)("div",{ref:p})]})]}),(0,n.jsx)("div",{className:"p-4 border-t border-border bg-bg-secondary",children:(0,n.jsxs)("form",{onSubmit:f,className:"flex gap-2",children:[(0,n.jsx)("textarea",{ref:g,value:m,onChange:e=>h(e.target.value),onKeyDown:e=>{if("Enter"===e.key&&e.altKey){e.preventDefault();let t=e.currentTarget,r=t.selectionStart,n=t.selectionEnd;h(m.slice(0,r)+"\n"+m.slice(n)),setTimeout(()=>{t.selectionStart=t.selectionEnd=r+1},0);return}"Enter"!==e.key||e.shiftKey||e.altKey||(e.preventDefault(),f(e))},placeholder:"Reply to thread...",disabled:o,rows:1,className:"flex-1 py-2 px-3 bg-bg-primary border border-border rounded-md text-sm text-text-primary resize-none min-h-[40px] max-h-[100px] overflow-y-auto focus:outline-none focus:border-accent transition-colors placeholder:text-text-muted"}),(0,n.jsx)("button",{type:"submit",disabled:!m.trim()||o,className:"px-4 py-2 bg-accent text-white rounded-md text-sm font-medium transition-colors hover:bg-accent-hover disabled:opacity-50 disabled:cursor-not-allowed",children:o?"Sending...":"Reply"})]})})]}):(0,n.jsxs)("div",{className:"flex flex-col h-full bg-bg-primary border-l border-border",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-border bg-bg-secondary",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(ti,{}),(0,n.jsx)("span",{className:"font-semibold text-sm text-text-primary",children:"Thread"})]}),(0,n.jsx)("button",{onClick:a,className:"p-1.5 rounded hover:bg-bg-hover transition-colors text-text-muted hover:text-text-primary",title:"Close thread",children:(0,n.jsx)(tc,{})})]}),(0,n.jsx)("div",{className:"flex-1 flex items-center justify-center text-text-muted text-sm",children:d?"Loading thread...":"Thread not found"})]})}function tl(e){let{message:t,isOriginal:r,currentUser:s,showTimestamps:a=!0}=e,l=(0,x.GW)(t.from),o=function(e){let t=new Date(e),r=new Date;return t.toDateString()===r.toDateString()?t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):t.toLocaleDateString([],{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}(t.timestamp),i="Dashboard"===t.from||s&&t.from===s.displayName,c=i&&s?s.displayName:t.from;return(0,n.jsxs)("div",{className:"flex gap-3 ".concat(r?"":"pl-2"),children:[i&&(null==s?void 0:s.avatarUrl)?(0,n.jsx)("img",{src:s.avatarUrl,alt:c,className:"shrink-0 w-8 h-8 rounded-lg object-cover"}):(0,n.jsx)("div",{className:"shrink-0 w-8 h-8 rounded-lg flex items-center justify-center font-semibold text-xs",style:{backgroundColor:l.primary,color:l.text},children:(0,x.hP)(t.from)}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-1",children:[(0,n.jsx)("span",{className:"font-semibold text-sm text-text-primary",children:c}),"*"!==t.to&&!r&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-text-muted text-xs",children:"→"}),(0,n.jsx)("span",{className:"text-sm text-accent",children:t.to})]}),a&&(0,n.jsx)("span",{className:"text-text-muted text-xs",children:o}),r&&(0,n.jsx)("span",{className:"text-[10px] py-0.5 px-1.5 rounded bg-accent-light text-accent font-medium",children:"Original"})]}),(0,n.jsx)("div",{className:"text-sm leading-relaxed text-text-primary whitespace-pre-wrap break-words",children:(0,eZ.y)(t.content)}),t.attachments&&t.attachments.length>0&&(0,n.jsx)(to,{attachments:t.attachments})]})]})}function to(e){let{attachments:t}=e,[r,a]=(0,s.useState)(null),l=t.filter(e=>e.mimeType.startsWith("image/"));return 0===l.length?null:(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex flex-wrap gap-2 mt-2",children:l.map(e=>(0,n.jsxs)("button",{type:"button",onClick:()=>a(e),className:"relative group cursor-pointer bg-transparent border-0 p-0",title:"View ".concat(e.filename),children:[(0,n.jsx)("img",{src:e.data||e.url,alt:e.filename,className:"max-h-32 max-w-[200px] rounded-lg border border-border object-cover transition-all duration-150 group-hover:border-accent/50 group-hover:shadow-md",loading:"lazy"}),(0,n.jsx)("div",{className:"absolute inset-0 bg-black/0 group-hover:bg-black/10 rounded-lg transition-colors flex items-center justify-center opacity-0 group-hover:opacity-100",children:(0,n.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"white",strokeWidth:"2",className:"drop-shadow-lg",children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"}),(0,n.jsx)("line",{x1:"11",y1:"8",x2:"11",y2:"14"}),(0,n.jsx)("line",{x1:"8",y1:"11",x2:"14",y2:"11"})]})})]},e.id))}),r&&(0,n.jsx)("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/80 backdrop-blur-sm",onClick:()=>a(null),children:(0,n.jsxs)("div",{className:"relative max-w-[90vw] max-h-[90vh]",children:[(0,n.jsx)("img",{src:r.data||r.url,alt:r.filename,className:"max-w-full max-h-[90vh] rounded-lg shadow-2xl",onClick:e=>e.stopPropagation()}),(0,n.jsx)("button",{type:"button",onClick:()=>a(null),className:"absolute -top-3 -right-3 w-8 h-8 bg-bg-primary border border-border rounded-full flex items-center justify-center text-text-muted hover:text-text-primary hover:bg-bg-secondary transition-colors shadow-lg",title:"Close",children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}),(0,n.jsx)("div",{className:"absolute bottom-0 left-0 right-0 p-3 bg-gradient-to-t from-black/60 to-transparent rounded-b-lg",children:(0,n.jsx)("p",{className:"text-white text-sm truncate",children:r.filename})})]})})]})}function ti(){return(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-text-primary",children:(0,n.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"})})}function tc(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}let td=["projects","agents","actions","channels","navigation","settings"],tu={critical:{label:"Critical",beadsPriority:0,color:"#ef4444"},high:{label:"High",beadsPriority:1,color:"#f97316"},medium:{label:"Medium",beadsPriority:2,color:"#f59e0b"},low:{label:"Low",beadsPriority:3,color:"#6366f1"}};function tx(e){return e.isOpen?(0,n.jsx)(tm,{...e}):null}function tm(e){let{onClose:t,agents:r,projects:a=[],currentProject:l,onAgentSelect:o,onProjectSelect:i,onSpawnClick:c,onTaskCreate:d,onSettingsClick:u,onGeneralClick:m,customCommands:h=[]}=e,[p,g]=(0,s.useState)(""),[f,b]=(0,s.useState)(0),[v,y]=(0,s.useState)(null),j=(0,s.useRef)(f),w=(0,s.useRef)(null),N=(0,s.useRef)(null),k=(0,s.useRef)([]),[C,S]=(0,s.useState)("search"),[L,M]=(0,s.useState)(null),[D,A]=(0,s.useState)(""),[E,T]=(0,s.useState)("medium"),[W,P]=(0,s.useState)(!1),R=(0,s.useMemo)(()=>r.filter(e=>"offline"!==e.status&&"error"!==e.status),[r]),I=(0,s.useMemo)(()=>{if(!p.trim())return R;let e=p.toLowerCase();return R.filter(t=>t.name.toLowerCase().includes(e))},[R,p]),B=(0,s.useCallback)(()=>{S("task-select-agent"),g(""),b(0),M(null),A(""),T("medium")},[]),F=(0,s.useCallback)(async()=>{if(L&&D.trim()&&d){P(!0);try{await d({agentName:L.name,title:D.trim(),priority:E}),t()}catch(e){console.error("Failed to create task:",e)}finally{P(!1)}}},[L,D,E,d,t]);(0,s.useEffect)(()=>{j.current=f},[f]);let U=(0,s.useMemo)(()=>[...[...a].sort((e,t)=>{let r=e.id===l,n=t.id===l;if(r&&!n)return -1;if(!r&&n)return 1;let s=e.name||e.path.split("/").pop()||e.id,a=t.name||t.path.split("/").pop()||t.id;return s.localeCompare(a)}).map(e=>{let r=e.name||e.path.split("/").pop()||e.id,s=e.id===l;return{id:"project-".concat(e.id),label:r,description:s?"Current project • ".concat(e.agents.length," agents"):"".concat(e.agents.length," agents"),category:"projects",icon:s?(0,n.jsx)(tj,{}):(0,n.jsx)(ty,{}),action:()=>{null==i||i(e),t()}}}),...r.map(e=>({id:"agent-".concat(e.name),label:e.name,description:e.currentTask||e.status,category:"agents",icon:(0,n.jsx)(th,{name:e.name}),action:()=>{o(e),t()}})),{id:"spawn-agent",label:"Spawn Agent",description:"Launch a new agent instance",category:"actions",icon:(0,n.jsx)(tg,{}),shortcut:"⌘⇧S",action:()=>{c(),t()}},{id:"broadcast",label:"Broadcast Message",description:"Send message to all agents",category:"actions",icon:(0,n.jsx)(tf,{}),action:()=>{t()}},...d?[{id:"assign-task",label:"Assign Task",description:"Create a task for an agent (creates bead)",category:"actions",icon:(0,n.jsx)(tw,{}),shortcut:"⌘⇧T",action:()=>{B()}}]:[],{id:"nav-general",label:"Go to #general",description:"General discussion channel",category:"navigation",icon:(0,n.jsx)(tb,{}),action:()=>{null==m||m(),t()}},...u?[{id:"settings",label:"Settings",description:"Configure dashboard preferences",category:"settings",icon:(0,n.jsx)(tv,{}),shortcut:"⌘,",action:()=>{u(),t()}}]:[],...h],[r,a,l,o,i,c,u,m,t,h]),_=(0,s.useMemo)(()=>{let e=U;if(v&&(e=e.filter(e=>e.category===v)),p.trim()){let t=p.toLowerCase();e=e.filter(e=>{var r;return e.label.toLowerCase().includes(t)||(null===(r=e.description)||void 0===r?void 0:r.toLowerCase().includes(t))||e.category.toLowerCase().includes(t)})}return e},[U,p,v]),O=(0,s.useMemo)(()=>{let e={};for(let t of _)e[t.category]||(e[t.category]=[]),e[t.category].push(t);return e},[_]),H=(0,s.useMemo)(()=>td.flatMap(e=>O[e]||[]),[O]);(0,s.useEffect)(()=>{b(0)},[p]),(0,s.useEffect)(()=>{g(""),b(0),y(null),S("search"),M(null),A(""),T("medium")},[]),(0,s.useEffect)(()=>{let e=k.current[f];e&&e.scrollIntoView({block:"nearest",behavior:"smooth"})},[f]),(0,s.useEffect)(()=>{let e=e=>{if("task-details"===C){"Escape"===e.key?(e.preventDefault(),S("task-select-agent"),g("")):"Enter"===e.key&&(e.metaKey||e.ctrlKey)&&(e.preventDefault(),F());return}if("task-select-agent"===C){switch(e.key){case"ArrowDown":e.preventDefault(),b(e=>Math.min(e+1,I.length-1));break;case"ArrowUp":e.preventDefault(),b(e=>Math.max(e-1,0));break;case"Enter":e.preventDefault(),I[j.current]&&(M(I[j.current]),S("task-details"),g(""));break;case"Escape":e.preventDefault(),S("search"),g("")}return}switch(e.key){case"ArrowDown":e.preventDefault(),b(e=>Math.min(e+1,H.length-1));break;case"ArrowUp":e.preventDefault(),b(e=>Math.max(e-1,0));break;case"Enter":e.preventDefault(),H[j.current]&&H[j.current].action();break;case"Tab":e.preventDefault(),y(t=>{if(null===t)return td[0];let r=td.indexOf(t);return e.shiftKey?0===r?null:td[r-1]:r===td.length-1?null:td[r+1]}),b(0);break;case"Escape":e.preventDefault(),v?(y(null),b(0)):t()}};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[H,I,C,f,v,t,F]);let z={projects:"Projects",agents:"Agents",actions:"Actions",navigation:"Navigation",settings:"Settings"},G=0;if("task-select-agent"===C)return(0,n.jsx)("div",{className:"fixed inset-0 bg-black/60 flex items-start justify-center pt-[15vh] z-[1000] animate-fade-in",onClick:()=>{S("search"),g("")},children:(0,n.jsxs)("div",{className:"bg-sidebar-bg border border-sidebar-border rounded-xl w-[560px] max-w-[90vw] max-h-[60vh] flex flex-col shadow-modal animate-slide-down",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 p-4 border-b border-sidebar-border",children:[(0,n.jsx)("button",{className:"p-1 rounded hover:bg-sidebar-border text-text-muted",onClick:()=>{S("search"),g("")},children:(0,n.jsx)(tN,{})}),(0,n.jsx)(tw,{}),(0,n.jsx)("input",{ref:w,autoFocus:!0,type:"text",className:"flex-1 border-none text-base font-sans outline-none bg-transparent text-text-primary placeholder:text-text-muted",placeholder:"Select agent to assign task...",value:p,onChange:e=>{g(e.target.value),b(0)}}),(0,n.jsx)("kbd",{className:"bg-sidebar-border border border-sidebar-hover rounded px-1.5 py-0.5 text-xs text-text-muted font-sans",children:"ESC"})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-2",ref:N,children:0===I.length?(0,n.jsx)("div",{className:"py-8 text-center text-text-muted text-sm",children:p?'No agents matching "'.concat(p,'"'):"No available agents"}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"text-xs font-semibold text-text-muted uppercase tracking-wider py-2 px-3",children:"Select Agent"}),I.map((e,t)=>{let r=(0,x.GW)(e.name);return(0,n.jsxs)("button",{ref:e=>{k.current[t]=e},className:"\n flex items-center gap-3 w-full py-2.5 px-3 border-none rounded-lg cursor-pointer text-left font-sans transition-colors duration-100\n ".concat(t===f?"bg-accent-light border border-accent/30":"bg-transparent hover:bg-sidebar-border","\n "),onClick:()=>{M(e),S("task-details"),g("")},onMouseEnter:()=>b(t),children:[(0,n.jsx)("div",{className:"w-7 h-7 rounded-md flex items-center justify-center text-xs font-semibold",style:{backgroundColor:r.primary,color:r.text},children:(0,x.hP)(e.name)}),(0,n.jsxs)("span",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-text-primary",children:e.name}),(0,n.jsx)("span",{className:"text-xs text-text-muted truncate",children:e.currentTask||e.status})]})]},e.name)})]})})]})});if("task-details"===C&&L){let e=(0,x.GW)(L.name);return(0,n.jsx)("div",{className:"fixed inset-0 bg-black/60 flex items-start justify-center pt-[15vh] z-[1000] animate-fade-in",onClick:()=>{S("task-select-agent"),g("")},children:(0,n.jsxs)("div",{className:"bg-sidebar-bg border border-sidebar-border rounded-xl w-[560px] max-w-[90vw] flex flex-col shadow-modal animate-slide-down",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 p-4 border-b border-sidebar-border",children:[(0,n.jsx)("button",{className:"p-1 rounded hover:bg-sidebar-border text-text-muted",onClick:()=>{S("task-select-agent"),g("")},children:(0,n.jsx)(tN,{})}),(0,n.jsx)("div",{className:"w-7 h-7 rounded-md flex items-center justify-center text-xs font-semibold",style:{backgroundColor:e.primary,color:e.text},children:(0,x.hP)(L.name)}),(0,n.jsxs)("span",{className:"text-base font-medium text-text-primary",children:["Assign task to ",L.name]})]}),(0,n.jsxs)("div",{className:"p-4 flex flex-col gap-4",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-xs font-medium text-text-muted mb-1.5",children:"Task Title"}),(0,n.jsx)("input",{autoFocus:!0,type:"text",value:D,onChange:e=>A(e.target.value),placeholder:"What needs to be done?",className:"w-full px-3 py-2 text-sm bg-bg-tertiary border border-sidebar-border rounded-md text-text-primary placeholder:text-text-dim focus:outline-none focus:border-accent-cyan"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-xs font-medium text-text-muted mb-1.5",children:"Priority"}),(0,n.jsx)("div",{className:"flex gap-2",children:Object.keys(tu).map(e=>{let t=tu[e],r=E===e;return(0,n.jsx)("button",{type:"button",className:"px-3 py-1.5 text-xs font-medium rounded-md border transition-all ".concat(r?"border-transparent text-white":"border-sidebar-border text-text-muted hover:border-sidebar-hover"),style:{backgroundColor:r?t.color:"transparent"},onClick:()=>T(e),children:t.label},e)})}),(0,n.jsxs)("p",{className:"text-xs text-text-dim mt-1.5",children:["Maps to beads priority P",tu[E].beadsPriority]})]}),(0,n.jsxs)("div",{className:"flex justify-end gap-2 pt-2 border-t border-sidebar-border",children:[(0,n.jsx)("button",{type:"button",className:"px-4 py-2 text-sm text-text-muted hover:text-text-primary transition-colors",onClick:()=>{S("task-select-agent"),g("")},children:"Back"}),(0,n.jsx)("button",{type:"button",disabled:!D.trim()||W,onClick:F,className:"px-4 py-2 text-sm font-medium bg-accent-cyan text-bg-deep rounded-md hover:bg-accent-cyan/90 transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2",children:W?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(tk,{}),"Creating..."]}):(0,n.jsxs)(n.Fragment,{children:["Create Task",(0,n.jsx)("kbd",{className:"bg-black/20 rounded px-1 py-0.5 text-[10px]",children:"⌘↵"})]})})]})]})]})})}return(0,n.jsx)("div",{className:"fixed inset-0 bg-black/60 flex items-start justify-center pt-[15vh] z-[1000] animate-fade-in",onClick:t,children:(0,n.jsxs)("div",{className:"bg-sidebar-bg border border-sidebar-border rounded-xl w-[560px] max-w-[90vw] max-h-[60vh] flex flex-col shadow-modal animate-slide-down",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 p-4 border-b border-sidebar-border",children:[(0,n.jsx)(tp,{}),v&&(0,n.jsxs)("button",{onClick:()=>{y(null),b(0)},className:"flex items-center gap-1 px-2 py-0.5 text-xs font-medium bg-accent-cyan/20 text-accent-cyan rounded-md hover:bg-accent-cyan/30 transition-colors",children:[z[v],(0,n.jsx)("span",{className:"text-accent-cyan/60",children:"\xd7"})]}),(0,n.jsx)("input",{ref:w,autoFocus:!0,type:"text",className:"flex-1 border-none text-base font-sans outline-none bg-transparent text-text-primary placeholder:text-text-muted",placeholder:v?"Search ".concat(z[v].toLowerCase(),"..."):"Search commands, agents...",value:p,onChange:e=>g(e.target.value)}),(0,n.jsx)("kbd",{className:"bg-sidebar-border border border-sidebar-hover rounded px-1.5 py-0.5 text-xs text-text-muted font-sans",title:"Cycle categories",children:"Tab"}),(0,n.jsx)("kbd",{className:"bg-sidebar-border border border-sidebar-hover rounded px-1.5 py-0.5 text-xs text-text-muted font-sans",children:"ESC"})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-2",ref:N,children:0===H.length?(0,n.jsxs)("div",{className:"py-8 text-center text-text-muted text-sm",children:['No results for "',p,'"']}):td.map(e=>{let t=O[e];return(null==t?void 0:t.length)?(0,n.jsxs)("div",{className:"mb-2",children:[(0,n.jsx)("div",{className:"text-xs font-semibold text-text-muted uppercase tracking-wider py-2 px-3",children:z[e]||e}),t.map(e=>{let t=G++;return(0,n.jsxs)("button",{ref:e=>{k.current[t]=e},className:"\n flex items-center gap-3 w-full py-2.5 px-3 border-none rounded-lg cursor-pointer text-left font-sans transition-colors duration-100\n ".concat(t===f?"bg-accent-light border border-accent/30":"bg-transparent hover:bg-sidebar-border","\n "),onClick:e.action,onMouseEnter:()=>b(t),children:[(0,n.jsx)("span",{className:"flex items-center justify-center w-7 h-7 text-text-muted",children:e.icon}),(0,n.jsxs)("span",{className:"flex-1 min-w-0 flex flex-col gap-0.5",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-text-primary",children:e.label}),e.description&&(0,n.jsx)("span",{className:"text-xs text-text-muted truncate",children:e.description})]}),e.shortcut&&(0,n.jsx)("kbd",{className:"bg-sidebar-border border border-sidebar-hover rounded px-1.5 py-0.5 text-xs text-text-muted font-sans",children:e.shortcut})]},e.id)})]},e):null})})]})})}function th(e){let{name:t}=e,r=(0,x.GW)(t);return(0,n.jsx)("div",{className:"w-7 h-7 rounded-md flex items-center justify-center text-xs font-semibold",style:{backgroundColor:r.primary,color:r.text},children:(0,x.hP)(t)})}function tp(){return(0,n.jsxs)("svg",{className:"text-text-muted shrink-0",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function tg(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,n.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function tf(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"2"}),(0,n.jsx)("path",{d:"M16.24 7.76a6 6 0 0 1 0 8.49m-8.48-.01a6 6 0 0 1 0-8.49m11.31-2.82a10 10 0 0 1 0 14.14m-14.14 0a10 10 0 0 1 0-14.14"})]})}function tb(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("line",{x1:"4",y1:"9",x2:"20",y2:"9"}),(0,n.jsx)("line",{x1:"4",y1:"15",x2:"20",y2:"15"}),(0,n.jsx)("line",{x1:"10",y1:"3",x2:"8",y2:"21"}),(0,n.jsx)("line",{x1:"16",y1:"3",x2:"14",y2:"21"})]})}function tv(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,n.jsx)("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"})]})}function ty(){return(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.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"})})}function tj(){return(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-accent-cyan",children:(0,n.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"})}),(0,n.jsx)("svg",{className:"absolute -bottom-0.5 -right-0.5 text-accent-cyan bg-sidebar-bg rounded-full",width:"10",height:"10",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M9 16.17L4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z"})})]})}function tw(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-text-muted",children:[(0,n.jsx)("path",{d:"M9 11l3 3L22 4"}),(0,n.jsx)("path",{d:"M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"})]})}function tN(){return(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.jsx)("polyline",{points:"15 18 9 12 15 6"})})}function tk(){return(0,n.jsx)("svg",{className:"animate-spin",width:"14",height:"14",viewBox:"0 0 24 24",children:(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}let tC=[{value:"sonnet",label:"Sonnet"},{value:"opus",label:"Opus"},{value:"haiku",label:"Haiku"}],tS=[{value:"opus-4.5-thinking",label:"Claude 4.5 Opus (Thinking)"},{value:"opus-4.5",label:"Claude 4.5 Opus"},{value:"sonnet-4.5",label:"Claude 4.5 Sonnet"},{value:"sonnet-4.5-thinking",label:"Claude 4.5 Sonnet (Thinking)"},{value:"gpt-5.2-codex",label:"GPT-5.2 Codex"},{value:"gpt-5.2-codex-high",label:"GPT-5.2 Codex High"},{value:"gpt-5.2-codex-low",label:"GPT-5.2 Codex Low"},{value:"gpt-5.2-codex-xhigh",label:"GPT-5.2 Codex Extra High"},{value:"gpt-5.2-codex-fast",label:"GPT-5.2 Codex Fast"},{value:"gpt-5.2-codex-high-fast",label:"GPT-5.2 Codex High Fast"},{value:"gpt-5.2-codex-low-fast",label:"GPT-5.2 Codex Low Fast"},{value:"gpt-5.2-codex-xhigh-fast",label:"GPT-5.2 Codex Extra High Fast"},{value:"gpt-5.1-codex-max",label:"GPT-5.1 Codex Max"},{value:"gpt-5.1-codex-max-high",label:"GPT-5.1 Codex Max High"},{value:"gpt-5.2",label:"GPT-5.2"},{value:"gpt-5.2-high",label:"GPT-5.2 High"},{value:"gpt-5.1-high",label:"GPT-5.1 High"},{value:"gemini-3-pro",label:"Gemini 3 Pro"},{value:"gemini-3-flash",label:"Gemini 3 Flash"},{value:"composer-1",label:"Composer 1"},{value:"grok",label:"Grok"}],tL=[{value:"gpt-5.2-codex",label:"GPT-5.2 Codex — Frontier agentic coding model"},{value:"gpt-5.3-codex",label:"GPT-5.3 Codex — Latest frontier agentic coding model"},{value:"gpt-5.1-codex-max",label:"GPT-5.1 Codex Max — Deep and fast reasoning"},{value:"gpt-5.2",label:"GPT-5.2 — Frontier model, knowledge & reasoning"},{value:"gpt-5.1-codex-mini",label:"GPT-5.1 Codex Mini — Cheaper, faster"}],tM=[{value:"gemini-3-pro-preview",label:"Gemini 3 Pro Preview"},{value:"gemini-2.5-pro",label:"Gemini 2.5 Pro"},{value:"gemini-2.5-flash",label:"Gemini 2.5 Flash"},{value:"gemini-2.5-flash-lite",label:"Gemini 2.5 Flash Lite"}],tD=[{id:"claude",name:"Claude",command:"claude",description:"Claude Code CLI agent",icon:"\uD83E\uDD16",providerId:"anthropic",supportsModelSelection:!0},{id:"codex",name:"Codex",command:"codex",description:"OpenAI Codex agent",icon:"⚡",providerId:"codex",supportsModelSelection:!0},{id:"gemini",name:"Gemini",command:"gemini",description:"Google Gemini CLI agent",icon:"\uD83D\uDC8E",providerId:"google",supportsModelSelection:!0},{id:"opencode",name:"OpenCode",command:"opencode",description:"OpenCode AI agent",icon:"\uD83D\uDD37",providerId:"opencode",comingSoon:!0},{id:"droid",name:"Droid",command:"droid",description:"Factory Droid agent",icon:"\uD83E\uDD16",providerId:"droid",comingSoon:!0},{id:"cursor",name:"Cursor",command:"cursor",description:"Cursor AI agent",icon:"\uD83D\uDCDD",providerId:"cursor",supportsModelSelection:!0},{id:"custom",name:"Custom",command:"",description:"Custom command",icon:"\uD83D\uDD27",providerId:null}];function tA(e){let{isOpen:t,onClose:r,onSpawn:a,existingAgents:l,isSpawning:o=!1,error:i,isCloudMode:d=!1,workspaceId:u,agentDefaults:m,repos:h,activeRepoId:p}=e,[g,f]=(0,s.useState)(tD[0]),[b,v]=(0,s.useState)(""),[y,j]=(0,s.useState)(""),[w,N]=(0,s.useState)("sonnet"),[k,C]=(0,s.useState)("opus-4.5-thinking"),[S,L]=(0,s.useState)("gpt-5.2-codex"),[M,D]=(0,s.useState)("gemini-2.5-pro"),[A,E]=(0,s.useState)(""),[T,W]=(0,s.useState)(p),[P,R]=(0,s.useState)(""),[I,B]=(0,s.useState)(!1),[F,U]=(0,s.useState)(""),[_,O]=(0,s.useState)(""),[H,z]=(0,s.useState)(["EXPLICIT_ASK"]),[G,V]=(0,s.useState)(null),K=(0,s.useRef)(null),Z=(0,s.useMemo)(()=>"custom"===g.id?y:"claude"===g.id?"".concat(g.command," --model ").concat(w):"cursor"===g.id?"".concat(g.command," --model ").concat(k):"codex"===g.id?"".concat(g.command," --model ").concat(S):"gemini"===g.id?"".concat(g.command," --model ").concat(M):g.command,[g,y,w,k,S,M]),q=(0,s.useMemo)(()=>(function(e){let t=e.trim().split(" ")[0].toLowerCase();return t.startsWith("claude")||"codex"===t||"opencode"===t||"gemini"===t||"droid"===t||"cursor"===t?"subagent":"process"})(Z),[Z]),[J,$]=(0,s.useState)(new Set),[Y,X]=(0,s.useState)(!1),Q=(0,s.useMemo)(()=>!d||!g.providerId||("codex"===g.providerId?J.has("codex")||J.has("openai"):J.has(g.providerId)),[d,g.providerId,J]),ee=(0,s.useMemo)(()=>{if(!g.providerId)return null;let e=g.command;if(!["claude","codex"].includes(e))return u?"/providers?workspace=".concat(u):"/providers";{let t="/providers/setup/".concat(e);return u?"".concat(t,"?workspace=").concat(u):t}},[g,u]);(0,s.useEffect)(()=>{t&&d&&u&&(async()=>{X(!0);try{let e=await c.xv.getProviders(u);if(e.success&&e.data.providers){let t=new Set(e.data.providers.filter(e=>e.isConnected).map(e=>e.id));$(t)}}catch(e){console.error("Failed to fetch provider credentials:",e)}finally{X(!1)}})()},[t,d,u]);let et=(0,s.useCallback)(()=>{let e="claude"===g.id?"claude":g.id,t=1;for(;l.includes("".concat(e,"-").concat(t));)t++;return"".concat(e,"-").concat(t)},[g,l]);(0,s.useEffect)(()=>{if(t){var e,r,n,s,a,l,o,i,c;let t=null==m?void 0:m.defaultCliType;f(t&&null!==(a=tD.find(e=>e.id===t&&!e.comingSoon))&&void 0!==a?a:tD[0]),v(""),j(""),N(null!==(l=null==m?void 0:null===(e=m.defaultModels)||void 0===e?void 0:e.claude)&&void 0!==l?l:"sonnet"),C(null!==(o=null==m?void 0:null===(r=m.defaultModels)||void 0===r?void 0:r.cursor)&&void 0!==o?o:"opus-4.5-thinking"),L(null!==(i=null==m?void 0:null===(n=m.defaultModels)||void 0===n?void 0:n.codex)&&void 0!==i?i:"gpt-5.2-codex"),D(null!==(c=null==m?void 0:null===(s=m.defaultModels)||void 0===s?void 0:s.gemini)&&void 0!==c?c:"gemini-2.5-pro"),E(""),W(p),R(""),B(!1),U(""),O(""),z(["EXPLICIT_ASK"]),V(null),setTimeout(()=>{var e;return null===(e=K.current)||void 0===e?void 0:e.focus()},100)}},[t,m,p,h]);let er=(0,s.useCallback)(e=>e.trim()?/^[a-zA-Z][a-zA-Z0-9-]*$/.test(e)?l.includes(e)?"An agent with this name already exists":null:"Name must start with a letter and contain only letters, numbers, and hyphens":"Name is required",[l]),en=async e=>{let t;e.preventDefault();let n=b.trim()||et(),s=er(n);if(s){V(s);return}if(!Z.trim()){V("Command is required");return}if(I&&!F){V("Please select an agent to shadow");return}if(V(null),d&&h&&h.length>0&&T){if("__all__"===T)t=void 0;else{let e=h.find(e=>e.id===T);e&&(t=e.githubFullName.split("/").pop())}}else t=A.trim()||void 0;await a({name:n,command:Z.trim(),cwd:t,team:P.trim()||void 0,shadowMode:q,shadowOf:I?F:void 0,shadowAgent:_.trim()||void 0,shadowTriggers:I?H:void 0,shadowSpeakOn:I?H:void 0})&&r()};if(!t)return null;let es=b?(0,x.GW)(b):(0,x.GW)(et()),ea=i||G;return(0,n.jsx)("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-[1000] animate-fade-in",onClick:r,children:(0,n.jsxs)("div",{className:"relative bg-bg-primary border border-border rounded-xl w-[480px] max-w-[90vw] max-h-[90vh] overflow-y-auto shadow-modal animate-slide-up",onClick:e=>e.stopPropagation(),onKeyDown:e=>{"Escape"===e.key&&(e.preventDefault(),r())},children:[o&&(0,n.jsx)(tI,{agentName:b.trim()||et(),colors:es}),(0,n.jsxs)("div",{className:"flex items-center justify-between p-5 border-b border-border",children:[(0,n.jsx)("h2",{className:"m-0 text-lg font-semibold text-text-primary",children:"Spawn New Agent"}),(0,n.jsx)("button",{className:"flex items-center justify-center w-8 h-8 bg-transparent border-none rounded-md text-text-muted cursor-pointer transition-all duration-150 hover:bg-bg-hover hover:text-text-primary",onClick:r,"aria-label":"Close",children:(0,n.jsx)(tE,{})})]}),(0,n.jsxs)("form",{onSubmit:en,className:"p-6",children:[(0,n.jsxs)("div",{className:"mb-5",children:[(0,n.jsx)("label",{className:"block text-sm font-semibold text-text-primary mb-2",children:"Agent Type"}),(0,n.jsx)("div",{className:"grid grid-cols-3 gap-2",children:tD.map(e=>{let t=e.comingSoon&&d;return(0,n.jsxs)("button",{type:"button",disabled:t,className:"\n flex flex-col items-center gap-1 py-3 px-2 border-2 rounded-lg font-sans transition-all duration-150 relative\n ".concat(t?"opacity-50 cursor-not-allowed bg-bg-hover border-transparent":g.id===e.id?"bg-accent/10 border-accent cursor-pointer":"bg-bg-hover border-transparent hover:bg-bg-active cursor-pointer","\n "),onClick:()=>!t&&f(e),children:[t&&(0,n.jsx)("span",{className:"absolute top-1 right-1 px-1.5 py-0.5 bg-amber-400/20 text-amber-400 text-[10px] font-medium rounded",children:"Soon"}),(0,n.jsx)("span",{className:"text-2xl ".concat(t?"grayscale":""),children:e.icon}),(0,n.jsx)("span",{className:"text-sm font-semibold text-text-primary",children:e.name}),(0,n.jsx)("span",{className:"text-xs text-text-muted text-center",children:e.description})]},e.id)})})]}),"claude"===g.id&&(0,n.jsxs)("div",{className:"mb-5",children:[(0,n.jsx)("label",{className:"block text-sm font-semibold text-text-primary mb-2",htmlFor:"claude-model",children:"Model"}),(0,n.jsx)("select",{id:"claude-model",className:"w-full py-2.5 px-3.5 border border-border rounded-md text-sm font-sans outline-none bg-bg-primary text-text-primary transition-colors duration-150 focus:border-accent disabled:bg-bg-hover disabled:text-text-muted",value:w,onChange:e=>N(e.target.value),disabled:o,children:tC.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))})]}),"cursor"===g.id&&(0,n.jsxs)("div",{className:"mb-5",children:[(0,n.jsx)("label",{className:"block text-sm font-semibold text-text-primary mb-2",htmlFor:"cursor-model",children:"Model"}),(0,n.jsx)("select",{id:"cursor-model",className:"w-full py-2.5 px-3.5 border border-border rounded-md text-sm font-sans outline-none bg-bg-primary text-text-primary transition-colors duration-150 focus:border-accent disabled:bg-bg-hover disabled:text-text-muted",value:k,onChange:e=>C(e.target.value),disabled:o,children:tS.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))})]}),"codex"===g.id&&(0,n.jsxs)("div",{className:"mb-5",children:[(0,n.jsx)("label",{className:"block text-sm font-semibold text-text-primary mb-2",htmlFor:"codex-model",children:"Model"}),(0,n.jsx)("select",{id:"codex-model",className:"w-full py-2.5 px-3.5 border border-border rounded-md text-sm font-sans outline-none bg-bg-primary text-text-primary transition-colors duration-150 focus:border-accent disabled:bg-bg-hover disabled:text-text-muted",value:S,onChange:e=>L(e.target.value),disabled:o,children:tL.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))})]}),"gemini"===g.id&&(0,n.jsxs)("div",{className:"mb-5",children:[(0,n.jsx)("label",{className:"block text-sm font-semibold text-text-primary mb-2",htmlFor:"gemini-model",children:"Model"}),(0,n.jsx)("select",{id:"gemini-model",className:"w-full py-2.5 px-3.5 border border-border rounded-md text-sm font-sans outline-none bg-bg-primary text-text-primary transition-colors duration-150 focus:border-accent disabled:bg-bg-hover disabled:text-text-muted",value:M,onChange:e=>D(e.target.value),disabled:o,children:tM.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))})]}),(0,n.jsxs)("div",{className:"mb-5",children:[(0,n.jsx)("label",{className:"block text-sm font-semibold text-text-primary mb-2",htmlFor:"agent-name",children:"Agent Name"}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("div",{className:"shrink-0 w-10 h-10 rounded-lg flex items-center justify-center text-sm font-semibold",style:{backgroundColor:es.primary,color:es.text},children:(0,x.hP)(b||et())}),(0,n.jsx)("input",{ref:K,id:"agent-name",type:"text",className:"flex-1 py-2.5 px-3.5 border border-border rounded-md text-sm font-sans outline-none bg-transparent text-text-primary transition-colors duration-150 focus:border-accent disabled:bg-bg-hover disabled:text-text-muted placeholder:text-text-muted",placeholder:et(),value:b,onChange:e=>{v(e.target.value),V(null)},disabled:o})]})]}),(0,n.jsxs)("div",{className:"mb-5",children:[(0,n.jsxs)("label",{className:"block text-sm font-semibold text-text-primary mb-2",htmlFor:"agent-team",children:["Team ",(0,n.jsx)("span",{className:"font-normal text-text-muted",children:"(optional)"})]}),(0,n.jsx)("input",{id:"agent-team",type:"text",className:"w-full py-2.5 px-3.5 border border-border rounded-md text-sm font-sans outline-none bg-transparent text-text-primary transition-colors duration-150 focus:border-accent disabled:bg-bg-hover disabled:text-text-muted placeholder:text-text-muted",placeholder:"e.g., frontend, backend, infra",value:P,onChange:e=>R(e.target.value),disabled:o})]}),"custom"===g.id&&(0,n.jsxs)("div",{className:"mb-5",children:[(0,n.jsx)("label",{className:"block text-sm font-semibold text-text-primary mb-2",htmlFor:"agent-command",children:"Command"}),(0,n.jsx)("input",{id:"agent-command",type:"text",className:"w-full py-2.5 px-3.5 border border-border rounded-md text-sm font-sans outline-none bg-transparent text-text-primary transition-colors duration-150 focus:border-accent disabled:bg-bg-hover disabled:text-text-muted placeholder:text-text-muted",placeholder:"e.g., python agent.py",value:y,onChange:e=>j(e.target.value),disabled:o})]}),d&&h&&h.length>0?(0,n.jsxs)("div",{className:"mb-5",children:[(0,n.jsx)("label",{className:"block text-sm font-semibold text-text-primary mb-2",htmlFor:"agent-repo",children:"Repository"}),(0,n.jsxs)("select",{id:"agent-repo",className:"w-full py-2.5 px-3.5 border border-border rounded-md text-sm font-sans outline-none bg-transparent text-text-primary transition-colors duration-150 focus:border-accent disabled:bg-bg-hover disabled:text-text-muted",value:T||"",onChange:e=>W(e.target.value),disabled:o,children:[h.length>1&&(0,n.jsx)("option",{value:"__all__",children:"All Repositories (Coordinator)"}),h.map(e=>(0,n.jsx)("option",{value:e.id,children:e.githubFullName},e.id))]}),"__all__"===T&&(0,n.jsx)("p",{className:"mt-1.5 text-xs text-accent-purple",children:"Agent will have access to all repositories in this workspace"})]}):(0,n.jsxs)("div",{className:"mb-5",children:[(0,n.jsxs)("label",{className:"block text-sm font-semibold text-text-primary mb-2",htmlFor:"agent-cwd",children:["Working Directory ",(0,n.jsx)("span",{className:"font-normal text-text-muted",children:"(optional)"})]}),(0,n.jsx)("input",{id:"agent-cwd",type:"text",className:"w-full py-2.5 px-3.5 border border-border rounded-md text-sm font-sans outline-none bg-transparent text-text-primary transition-colors duration-150 focus:border-accent disabled:bg-bg-hover disabled:text-text-muted placeholder:text-text-muted",placeholder:"Current directory",value:A,onChange:e=>E(e.target.value),disabled:o})]}),(0,n.jsxs)("div",{className:"mb-5 p-4 border border-border rounded-lg bg-bg-hover/50",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-semibold text-text-primary",children:"Shadow Mode"}),(0,n.jsxs)("span",{className:"text-xs text-text-muted",children:["Shadow execution: ","subagent"===q?"Subagent (in-process)":"Process (separate)"]})]}),(0,n.jsx)("button",{type:"button",className:"\n relative w-11 h-6 rounded-full transition-colors duration-200\n ".concat(I?"bg-accent":"bg-bg-active","\n "),onClick:()=>B(!I),disabled:o,"aria-pressed":I,children:(0,n.jsx)("span",{className:"\n absolute top-0.5 left-0.5 w-5 h-5 bg-white rounded-full transition-transform duration-200 shadow-sm\n ".concat(I?"translate-x-5":"translate-x-0","\n ")})})]}),I&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"mb-4",children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-text-secondary mb-2",htmlFor:"shadow-of",children:"Shadow Agent"}),(0,n.jsxs)("select",{id:"shadow-of",className:"w-full py-2.5 px-3.5 border border-border rounded-md text-sm font-sans outline-none bg-bg-primary text-text-primary transition-colors duration-150 focus:border-accent disabled:bg-bg-hover disabled:text-text-muted",value:F,onChange:e=>U(e.target.value),disabled:o,children:[(0,n.jsx)("option",{value:"",children:"Select an agent to shadow..."}),l.map(e=>(0,n.jsx)("option",{value:e,children:e},e))]})]}),(0,n.jsxs)("div",{className:"mb-4",children:[(0,n.jsxs)("label",{className:"block text-sm font-medium text-text-secondary mb-2",htmlFor:"shadow-agent",children:["Shadow Agent Profile ",(0,n.jsx)("span",{className:"font-normal text-text-muted",children:"(optional)"})]}),(0,n.jsx)("input",{id:"shadow-agent",type:"text",className:"w-full py-2.5 px-3.5 border border-border rounded-md text-sm font-sans outline-none bg-bg-primary text-text-primary transition-colors duration-150 focus:border-accent disabled:bg-bg-hover disabled:text-text-muted placeholder:text-text-muted",placeholder:"e.g., shadow-reviewer",value:_,onChange:e=>O(e.target.value),disabled:o})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-sm font-medium text-text-secondary mb-2",children:"Speak When"}),(0,n.jsx)("div",{className:"flex flex-wrap gap-2",children:[{value:"EXPLICIT_ASK",label:"Explicit Ask",description:"When directly asked"},{value:"SESSION_END",label:"Session End",description:"When session ends"},{value:"CODE_WRITTEN",label:"Code Written",description:"When code is written"},{value:"REVIEW_REQUEST",label:"Review Request",description:"When review requested"},{value:"ALL_MESSAGES",label:"All Messages",description:"On every message"}].map(e=>(0,n.jsx)("button",{type:"button",className:"\n py-1.5 px-3 rounded-md text-xs font-medium transition-all duration-150 border\n ".concat(H.includes(e.value)?"bg-accent/20 border-accent text-accent":"bg-bg-primary border-border text-text-secondary hover:bg-bg-active hover:text-text-primary","\n "),onClick:()=>{H.includes(e.value)?z(H.filter(t=>t!==e.value)):z([...H,e.value])},disabled:o,title:e.description,children:e.label},e.value))})]})]})]}),d&&!Q&&!Y&&g.providerId&&(0,n.jsx)("div",{className:"p-4 bg-amber-400/10 border border-amber-400/30 rounded-lg mb-5",children:(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"shrink-0 w-8 h-8 rounded-lg bg-amber-400/20 flex items-center justify-center",children:(0,n.jsx)(tB,{})}),(0,n.jsxs)("div",{className:"flex-1",children:[(0,n.jsxs)("h4",{className:"text-sm font-semibold text-amber-400 mb-1",children:[g.name," credentials required"]}),(0,n.jsxs)("p",{className:"text-xs text-text-secondary mb-3",children:["Connect your ",g.name," account to spawn ",g.name," agents. This enables secure access to the AI provider's API."]}),(0,n.jsxs)("a",{href:ee||"#",className:"inline-flex items-center gap-2 py-2 px-4 bg-amber-400 text-bg-deep font-semibold rounded-md text-sm hover:bg-amber-500 transition-colors",children:[(0,n.jsx)(tB,{}),"Connect ",g.name]})]})]})}),d&&Y&&(0,n.jsxs)("div",{className:"flex items-center gap-2 p-3 bg-bg-hover rounded-md text-text-muted text-sm mb-5",children:[(0,n.jsx)(tP,{}),(0,n.jsx)("span",{children:"Checking provider credentials..."})]}),ea&&(0,n.jsxs)("div",{className:"flex items-center gap-2 p-3 bg-error/10 border border-error/30 rounded-md text-error text-sm mb-5",children:[(0,n.jsx)(tT,{}),(0,n.jsx)("span",{children:ea})]}),(0,n.jsxs)("div",{className:"flex justify-end gap-2 pt-2 border-t border-border",children:[(0,n.jsx)("button",{type:"button",className:"flex items-center gap-1.5 py-2.5 px-4 border-none rounded-md text-sm font-medium cursor-pointer font-sans transition-all duration-150 bg-bg-hover text-text-secondary hover:bg-bg-active hover:text-text-primary disabled:opacity-50 disabled:cursor-not-allowed",onClick:r,disabled:o,children:"Cancel"}),(0,n.jsxs)("button",{type:"submit",className:"flex items-center gap-1.5 py-2.5 px-4 border-none rounded-md text-sm font-medium cursor-pointer font-sans transition-all duration-150 bg-accent text-white hover:bg-accent-hover disabled:opacity-50 disabled:cursor-not-allowed",disabled:o||d&&!Q,title:!Q&&d?"Connect ".concat(g.name," credentials first"):void 0,children:[(0,n.jsx)(tW,{}),"Spawn Agent"]})]})]})]})})}function tE(){return(0,n.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function tT(){return(0,n.jsxs)("svg",{className:"shrink-0",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,n.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}function tW(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("path",{d:"M4.5 16.5c-1.5 1.26-2 5-2 5s3.74-.5 5-2c.71-.84.7-2.13-.09-2.91a2.18 2.18 0 0 0-2.91-.09z"}),(0,n.jsx)("path",{d:"m12 15-3-3a22 22 0 0 1 2-3.95A12.88 12.88 0 0 1 22 2c0 2.72-.78 7.5-6 11a22.35 22.35 0 0 1-4 2z"}),(0,n.jsx)("path",{d:"M9 12H4s.55-3.03 2-4c1.62-1.08 5 0 5 0"}),(0,n.jsx)("path",{d:"M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5"})]})}function tP(){return(0,n.jsx)("svg",{className:"animate-spin",width:"16",height:"16",viewBox:"0 0 24 24",children:(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}let tR=["Initializing agent environment...","Loading model configuration...","Establishing communication channel...","Preparing workspace...","Almost ready..."];function tI(e){let{agentName:t,colors:r}=e,[a,l]=(0,s.useState)(0),[o,i]=(0,s.useState)("");(0,s.useEffect)(()=>{let e=setInterval(()=>{l(e=>(e+1)%tR.length)},2400);return()=>clearInterval(e)},[]),(0,s.useEffect)(()=>{let e=setInterval(()=>{i(e=>e.length>=3?"":e+".")},500);return()=>clearInterval(e)},[]);let c=(0,x.hP)(t);return(0,n.jsxs)("div",{className:"absolute inset-0 bg-bg-primary/95 backdrop-blur-sm flex flex-col items-center justify-center z-10 rounded-xl",children:[(0,n.jsxs)("div",{className:"relative mb-6",children:[(0,n.jsx)("div",{className:"absolute inset-0 rounded-full animate-ping opacity-20",style:{backgroundColor:r.primary}}),(0,n.jsx)("div",{className:"relative w-16 h-16 rounded-full flex items-center justify-center text-xl font-bold animate-pulse",style:{backgroundColor:r.primary,color:r.text},children:c})]}),(0,n.jsxs)("div",{className:"text-lg font-semibold text-text-primary mb-2",children:["Spawning ",t,o]}),(0,n.jsx)("div",{className:"text-sm text-text-muted transition-opacity duration-300 mb-6",style:{animation:"fadeInUp 0.3s ease-out"},children:tR[a]},a),(0,n.jsx)("div",{className:"w-48 h-1 bg-bg-hover rounded-full overflow-hidden",children:(0,n.jsx)("div",{className:"h-full rounded-full",style:{backgroundColor:r.primary,animation:"spawningProgress 2.4s ease-in-out infinite"}})}),(0,n.jsx)("style",{children:"\n @keyframes fadeInUp {\n from { opacity: 0; transform: translateY(4px); }\n to { opacity: 1; transform: translateY(0); }\n }\n @keyframes spawningProgress {\n 0% { width: 0%; margin-left: 0%; }\n 50% { width: 60%; margin-left: 20%; }\n 100% { width: 0%; margin-left: 100%; }\n }\n "})]})}function tB(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),(0,n.jsx)("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function tF(e){let{isOpen:t,onClose:r,onSend:a,agents:l,isSending:o=!1,error:i,preselectedAgent:c}=e,[d,u]=(0,s.useState)(""),[m,h]=(0,s.useState)(""),[p,g]=(0,s.useState)(""),[f,b]=(0,s.useState)(null),v=(0,s.useRef)(null),y=(0,s.useRef)(null),j=(0,s.useMemo)(()=>{if(!p.trim())return l;let e=p.toLowerCase();return l.filter(t=>{var r,n;return t.name.toLowerCase().includes(e)||(null===(r=t.role)||void 0===r?void 0:r.toLowerCase().includes(e))||(null===(n=t.team)||void 0===n?void 0:n.toLowerCase().includes(e))})},[l,p]);(0,s.useEffect)(()=>{t&&(u(c||""),h(""),g(""),b(null),setTimeout(()=>{var e,t;c?null===(e=v.current)||void 0===e||e.focus():null===(t=y.current)||void 0===t||t.focus()},100))},[t,c]);let w=async e=>{if(e.preventDefault(),!d){b("Please select an agent");return}if(!m.trim()){b("Please enter a message");return}b(null),await a(d,m.trim())&&r()},N=(0,s.useCallback)(e=>{u(e),b(null),setTimeout(()=>{var e;return null===(e=v.current)||void 0===e?void 0:e.focus()},50)},[]);if(!t)return null;let k=i||f,C=l.find(e=>e.name===d),S=C?(0,x.GW)(C.name):null;return(0,n.jsx)("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-[1000] animate-fade-in",onClick:r,children:(0,n.jsxs)("div",{className:"bg-bg-primary border border-border rounded-xl w-[520px] max-w-[90vw] max-h-[85vh] overflow-hidden shadow-modal animate-slide-up flex flex-col",onClick:e=>e.stopPropagation(),onKeyDown:e=>{"Escape"===e.key&&(e.preventDefault(),r())},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between p-5 border-b border-border shrink-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("div",{className:"w-9 h-9 rounded-lg bg-accent/10 flex items-center justify-center",children:(0,n.jsx)(tU,{})}),(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"m-0 text-lg font-semibold text-text-primary",children:"New Conversation"}),(0,n.jsx)("p",{className:"m-0 text-xs text-text-muted",children:"Start a direct message with an agent"})]})]}),(0,n.jsx)("button",{className:"flex items-center justify-center w-8 h-8 bg-transparent border-none rounded-md text-text-muted cursor-pointer transition-all duration-150 hover:bg-bg-hover hover:text-text-primary",onClick:r,"aria-label":"Close",children:(0,n.jsx)(t_,{})})]}),(0,n.jsxs)("form",{onSubmit:w,className:"flex flex-col flex-1 overflow-hidden",children:[(0,n.jsxs)("div",{className:"p-5 border-b border-border",children:[(0,n.jsx)("label",{className:"block text-sm font-semibold text-text-primary mb-2",children:"To"}),d?(0,n.jsxs)("div",{className:"flex items-center gap-3 p-3 bg-bg-hover rounded-lg",children:[(0,n.jsx)("div",{className:"shrink-0 w-10 h-10 rounded-lg flex items-center justify-center text-sm font-semibold",style:{backgroundColor:null==S?void 0:S.primary,color:null==S?void 0:S.text},children:(0,x.hP)(d)}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"font-semibold text-text-primary",children:d}),(null==C?void 0:C.role)&&(0,n.jsx)("div",{className:"text-xs text-text-muted truncate",children:C.role})]}),(0,n.jsx)("button",{type:"button",className:"flex items-center justify-center w-8 h-8 bg-bg-active border-none rounded-md text-text-muted cursor-pointer transition-all duration-150 hover:bg-bg-tertiary hover:text-text-primary",onClick:()=>{u(""),setTimeout(()=>{var e;return null===(e=y.current)||void 0===e?void 0:e.focus()},50)},"aria-label":"Change agent",children:(0,n.jsx)(tH,{})})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{className:"relative mb-3",children:[(0,n.jsx)("div",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-text-muted",children:(0,n.jsx)(tO,{})}),(0,n.jsx)("input",{ref:y,type:"text",className:"w-full py-2.5 pl-10 pr-3.5 border border-border rounded-md text-sm font-sans outline-none bg-transparent text-text-primary transition-colors duration-150 focus:border-accent placeholder:text-text-muted",placeholder:"Search agents...",value:p,onChange:e=>g(e.target.value)})]}),(0,n.jsx)("div",{className:"max-h-[200px] overflow-y-auto border border-border rounded-lg",children:0===j.length?(0,n.jsx)("div",{className:"p-4 text-center text-text-muted text-sm",children:p?"No agents found":"No agents available"}):(0,n.jsxs)("div",{className:"divide-y divide-border",children:[(0,n.jsxs)("button",{type:"button",className:"w-full flex items-center gap-3 p-3 bg-transparent border-none cursor-pointer transition-colors duration-150 hover:bg-bg-hover text-left",onClick:()=>N("*"),children:[(0,n.jsx)("div",{className:"shrink-0 w-9 h-9 rounded-lg bg-warning/20 flex items-center justify-center",children:(0,n.jsx)(tz,{})}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"font-semibold text-text-primary",children:"Everyone"}),(0,n.jsx)("div",{className:"text-xs text-text-muted",children:"Broadcast to all agents"})]})]}),j.map(e=>{let t=(0,x.GW)(e.name);return(0,n.jsxs)("button",{type:"button",className:"w-full flex items-center gap-3 p-3 bg-transparent border-none cursor-pointer transition-colors duration-150 hover:bg-bg-hover text-left",onClick:()=>N(e.name),children:[(0,n.jsx)("div",{className:"shrink-0 w-9 h-9 rounded-lg flex items-center justify-center text-xs font-semibold",style:{backgroundColor:t.primary,color:t.text},children:(0,x.hP)(e.name)}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"font-semibold text-text-primary",children:e.name}),(0,n.jsx)("span",{className:"w-2 h-2 rounded-full ".concat("online"===e.status?"bg-success":"bg-text-muted")})]}),(e.role||e.team)&&(0,n.jsxs)("div",{className:"text-xs text-text-muted truncate",children:[e.role,e.role&&e.team&&" - ",e.team]})]})]},e.name)})]})})]})]}),(0,n.jsxs)("div",{className:"p-5 flex-1 overflow-hidden flex flex-col",children:[(0,n.jsx)("label",{className:"block text-sm font-semibold text-text-primary mb-2",htmlFor:"message",children:"Message"}),(0,n.jsx)("textarea",{ref:v,id:"message",className:"flex-1 min-h-[120px] w-full py-3 px-3.5 border border-border rounded-md text-sm font-sans outline-none bg-transparent text-text-primary transition-colors duration-150 focus:border-accent resize-none placeholder:text-text-muted",placeholder:"*"===d?"Write a message to all agents...":d?"Write a message to ".concat(d,"..."):"Select an agent first...",value:m,onChange:e=>{h(e.target.value),b(null)},disabled:o||!d})]}),k&&(0,n.jsxs)("div",{className:"flex items-center gap-2 mx-5 mb-4 p-3 bg-error/10 border border-error/30 rounded-md text-error text-sm",children:[(0,n.jsx)(tV,{}),(0,n.jsx)("span",{children:k})]}),(0,n.jsxs)("div",{className:"flex justify-end gap-2 p-5 pt-0 border-t border-border",children:[(0,n.jsx)("button",{type:"button",className:"flex items-center gap-1.5 py-2.5 px-4 border-none rounded-md text-sm font-medium cursor-pointer font-sans transition-all duration-150 bg-bg-hover text-text-secondary hover:bg-bg-active hover:text-text-primary disabled:opacity-50 disabled:cursor-not-allowed",onClick:r,disabled:o,children:"Cancel"}),(0,n.jsx)("button",{type:"submit",className:"flex items-center gap-1.5 py-2.5 px-4 border-none rounded-md text-sm font-medium cursor-pointer font-sans transition-all duration-150 bg-accent text-white hover:bg-accent-hover disabled:opacity-50 disabled:cursor-not-allowed",disabled:o||!d||!m.trim(),children:o?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(tK,{}),"Sending..."]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(tG,{}),"Send Message"]})})]})]})]})})}function tU(){return(0,n.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-accent",children:[(0,n.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"}),(0,n.jsx)("line",{x1:"9",y1:"10",x2:"15",y2:"10"})]})}function t_(){return(0,n.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function tO(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function tH(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("polyline",{points:"1 4 1 10 7 10"}),(0,n.jsx)("path",{d:"M3.51 15a9 9 0 1 0 2.13-9.36L1 10"})]})}function tz(){return(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-warning",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"2"}),(0,n.jsx)("path",{d:"M16.24 7.76a6 6 0 0 1 0 8.49m-8.48-.01a6 6 0 0 1 0-8.49m11.31-2.82a10 10 0 0 1 0 14.14m-14.14 0a10 10 0 0 1 0-14.14"})]})}function tG(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),(0,n.jsx)("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})}function tV(){return(0,n.jsxs)("svg",{className:"shrink-0",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,n.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}function tK(){return(0,n.jsx)("svg",{className:"animate-spin",width:"16",height:"16",viewBox:"0 0 24 24",children:(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}var tZ=r(4722),tq=r(1994),tJ=r(5888);let t$=e=>{let{className:t="w-5 h-5"}=e;return(0,n.jsx)("svg",{className:t,viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0024 12c0-6.63-5.37-12-12-12z"})})},tY=e=>{let{className:t="w-5 h-5"}=e;return(0,n.jsx)("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"})})},tX=e=>{let{className:t="w-4 h-4"}=e;return(0,n.jsx)("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 15v2m-6 4h12a2 2 0 002-2v-6a2 2 0 00-2-2H6a2 2 0 00-2 2v6a2 2 0 002 2zm10-10V7a4 4 0 00-8 0v4h8z"})})},tQ=e=>{let{className:t="w-4 h-4"}=e;return(0,n.jsx)("svg",{className:t,fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M5 13l4 4L19 7"})})};function t0(e){let{workspaceId:t,workspaceRepos:r=[],onRepoAdded:a,onRepoRemoved:l,csrfToken:o,className:i=""}=e,[c,d]=(0,s.useState)([]),[u,x]=(0,s.useState)("idle"),[m,h]=(0,s.useState)(null),[p,g]=(0,s.useState)(!1),[f,b]=(0,s.useState)(""),[v,y]=(0,s.useState)(1),[j,w]=(0,s.useState)(!1),[N,k]=(0,s.useState)(!1),[C,S]=(0,s.useState)(!1),[L,M]=(0,s.useState)([]),D=(0,s.useRef)(null),[A,E]=(0,s.useState)(null),[T,W]=(0,s.useState)(null),[P,R]=(0,s.useState)(new Set),I=(0,s.useRef)(null),[B,F]=(0,s.useState)(!1),[U,_]=(0,s.useState)(!1),[O,H]=(0,s.useState)(null),[z,G]=(0,s.useState)(!1),[V,K]=(0,s.useState)(null),[Z,q]=(0,s.useState)(!1),[J,$]=(0,s.useState)(new Set),[Y,X]=(0,s.useState)(!1),Q=s.useMemo(()=>new Set(r.map(e=>e.fullName.toLowerCase())),[r]),ee=(0,s.useCallback)(async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:1,t=arguments.length>1&&void 0!==arguments[1]&&arguments[1];t||x("loading"),h(null);try{var r;let n=await fetch("/api/repos/accessible?perPage=".concat(25,"&page=").concat(e),{credentials:"include"}),s=await n.json();if(!n.ok)throw"NANGO_NOT_CONNECTED"===s.code&&g(!0),Error(s.error||"Failed to fetch repositories");let a=(s.repositories||[]).map(e=>({...e,gitHubAppAccess:"unknown",isInWorkspace:!1}));t?d(e=>[...e,...a]):d(a),y(e),w((null===(r=s.pagination)||void 0===r?void 0:r.hasMore)||!1),x("loaded"),g(!1)}catch(e){console.error("Error fetching repos:",e),h(e instanceof Error?e.message:"Failed to fetch repositories"),x("error")}},[]),et=(0,s.useCallback)(async()=>{try{let e=await fetch("/api/repos/github-app-accessible",{credentials:"include"}),t=await e.json();if(e.ok&&t.repositories){let e=t.repositories.map(e=>e.fullName.toLowerCase());$(new Set(e)),X(t.hasConnection||!1)}}catch(e){console.error("Error fetching GitHub App repos:",e)}},[]);(0,s.useEffect)(()=>{ee(),et()},[ee,et]),(0,s.useEffect)(()=>{if(!p)return;let e=!0;return(async()=>{try{let t=await fetch("/api/auth/nango/login-session",{credentials:"include"}),r=await t.json();if(!e)return;t.ok&&r.sessionToken&&(I.current=new tJ.ZP({connectSessionToken:r.sessionToken}),F(!0))}catch(e){console.error("Failed to initialize Nango:",e)}})(),()=>{e=!1}},[p]);let er=(0,s.useCallback)(async e=>{let[t,r]=e.split("/");if(!t||!r)return{hasAccess:!1,needsReconnect:!1,message:"Invalid repository name"};try{let e=await fetch("/api/repos/check-github-app-access/".concat(t,"/").concat(r),{credentials:"include"}),n=await e.json();if(!e.ok)return{hasAccess:!1,needsReconnect:!0,message:n.error||"Failed to check access"};return n}catch(e){return console.error("Error checking GitHub App access:",e),{hasAccess:!1,needsReconnect:!0,message:"Failed to check access"}}},[]),en=(0,s.useCallback)((e,t)=>{d(r=>r.map(r=>r.fullName===e?{...r,gitHubAppAccess:t}:r))},[]),es=(0,s.useCallback)(async e=>{G(!0),K(e),q(!1),h(null);try{let t=await fetch("/api/auth/nango/repo-reconnect-session",{credentials:"include"}),r=await t.json();if(t.ok&&"NO_EXISTING_CONNECTION"!==r.code||(t=await fetch("/api/auth/nango/repo-session",{credentials:"include"}),r=await t.json()),!t.ok||!r.sessionToken){h("Failed to initialize GitHub connection. Please refresh the page."),G(!1),K(null);return}new tJ.ZP({connectSessionToken:r.sessionToken}).auth("github-app-oauth").catch(e=>{var t;"user_cancelled"===e.type||(null===(t=e.message)||void 0===t?void 0:t.includes("closed"))||console.error("GitHub App auth background error:",e)});let[n,s]=e.split("/"),a=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;if(e>60)throw Error("Connection timed out. Please try again.");try{let e=await fetch("/api/repos/check-github-app-access/".concat(n,"/").concat(s),{credentials:"include"});if((await e.json()).hasAccess)return!0}catch(e){}return await new Promise(e=>setTimeout(e,2e3)),a(e+1)};await a()&&(q(!0),G(!1))}catch(e){console.error("GitHub App reconnect error:",e),h(e.message||"Failed to reconnect GitHub"),K(null),G(!1)}},[]);(0,s.useEffect)(()=>{Z&&V&&!z&&(q(!1),K(null),en(V,"has_access"),ea(V))},[Z,V,z]);let ea=(0,s.useCallback)(async e=>{E(e),h(null);try{let r={"Content-Type":"application/json"};o&&(r["X-CSRF-Token"]=o);let n=await fetch("/api/workspaces/".concat(t,"/repos"),{method:"POST",credentials:"include",headers:r,body:JSON.stringify({repositoryFullName:e})}),s=await n.json();if(!n.ok)throw Error(s.error||"Failed to add repository");null==a||a(e)}catch(e){console.error("Error adding repo to workspace:",e),h(e instanceof Error?e.message:"Failed to add repository")}finally{E(null)}},[t,o,a]),el=(0,s.useCallback)(async e=>{let n=r.find(t=>t.fullName.toLowerCase()===e.fullName.toLowerCase());if(n){W(e.fullName),h(null);try{let r={};o&&(r["X-CSRF-Token"]=o);let s=await fetch("/api/workspaces/".concat(t,"/repos/").concat(n.id),{method:"DELETE",credentials:"include",headers:r}),a=await s.json();if(!s.ok)throw Error(a.error||"Failed to remove repository");null==l||l(e.fullName)}catch(e){console.error("Error removing repo from workspace:",e),h(e instanceof Error?e.message:"Failed to remove repository")}finally{W(null)}}},[t,r,o,l]),eo=(0,s.useCallback)(async e=>{if(e.isInWorkspace)return;if("has_access"===e.gitHubAppAccess){await ea(e.fullName);return}R(t=>new Set(t).add(e.fullName)),en(e.fullName,"checking");let t=await er(e.fullName);R(t=>{let r=new Set(t);return r.delete(e.fullName),r}),t.hasAccess?(en(e.fullName,"has_access"),await ea(e.fullName)):(en(e.fullName,"no_access"),await es(e.fullName))},[er,ea,es,en]),ei=async()=>{if(!I.current){H("GitHub connection not available. Please refresh the page.");return}_(!0),H(null);try{await I.current.auth("github"),window.location.reload()}catch(e){"user_cancelled"!==e.type&&H(e.message||"Failed to connect GitHub")}finally{_(!1)}},ec=async()=>{if(!N&&j){k(!0);try{await ee(v+1,!0)}finally{k(!1)}}},ed=(0,s.useCallback)(async e=>{if(!e.trim()){M([]),S(!1);return}S(!0);try{let t=await fetch("/api/repos/search?q=".concat(encodeURIComponent(e)),{credentials:"include"}),r=await t.json();if(t.ok){let e=(r.repositories||[]).map(e=>({id:e.githubId,fullName:e.fullName,isPrivate:e.isPrivate,defaultBranch:e.defaultBranch,description:e.description,permissions:{admin:!1,push:!0,pull:!0}}));M(e)}}catch(e){console.error("Search error:",e)}finally{S(!1)}},[]),eu=(0,s.useCallback)(e=>{b(e),D.current&&clearTimeout(D.current),e.trim()?D.current=setTimeout(()=>{ed(e)},300):M([])},[ed]),ex=s.useMemo(()=>{let e=e=>J.has(e.toLowerCase())?"has_access":Y?"no_access":"unknown";return f.trim()&&L.length>0?L.map(t=>({...t,gitHubAppAccess:e(t.fullName),isInWorkspace:Q.has(t.fullName.toLowerCase())})):c.map(t=>({...t,gitHubAppAccess:e(t.fullName),isInWorkspace:Q.has(t.fullName.toLowerCase())}))},[c,L,f,Q,J,Y]),em=ex.filter(e=>e.isInWorkspace),eh=ex.filter(e=>!e.isInWorkspace).sort((e,t)=>"has_access"===e.gitHubAppAccess&&"has_access"!==t.gitHubAppAccess?-1:"has_access"!==e.gitHubAppAccess&&"has_access"===t.gitHubAppAccess?1:0),ep=!f.trim()&&j;if("loading"===u)return(0,n.jsx)("div",{className:"flex items-center justify-center py-12 ".concat(i),children:(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsxs)("svg",{className:"w-8 h-8 text-accent-cyan animate-spin mx-auto",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),(0,n.jsx)("p",{className:"mt-4 text-text-muted",children:"Loading repositories..."})]})});if("error"===u&&p)return(0,n.jsx)("div",{className:"p-6 ".concat(i),children:(0,n.jsxs)("div",{className:"bg-bg-tertiary border border-border-subtle rounded-xl p-8 text-center",children:[(0,n.jsx)("div",{className:"w-16 h-16 mx-auto mb-4 bg-bg-hover rounded-full flex items-center justify-center",children:(0,n.jsx)(t$,{className:"w-8 h-8 text-text-muted"})}),(0,n.jsx)("h3",{className:"text-lg font-semibold text-text-primary mb-2",children:"Connect GitHub"}),(0,n.jsx)("p",{className:"text-text-muted mb-6 max-w-md mx-auto",children:"Connect your GitHub account to see your repositories and enable agent access to your code."}),O&&(0,n.jsx)("p",{className:"text-error text-sm mb-4",children:O}),(0,n.jsx)("button",{onClick:ei,disabled:!B||U,className:"px-6 py-3 bg-gradient-to-r from-accent-cyan to-[#00b8d9] text-bg-deep font-medium rounded-lg hover:shadow-glow-cyan transition-all disabled:opacity-50 disabled:cursor-not-allowed",children:U?"Connecting...":B?(0,n.jsxs)("span",{className:"flex items-center gap-2",children:[(0,n.jsx)(t$,{className:"w-5 h-5"}),"Connect GitHub Account"]}):"Loading..."})]})});if("error"===u)return(0,n.jsx)("div",{className:"p-6 ".concat(i),children:(0,n.jsxs)("div",{className:"bg-error/10 border border-error/20 rounded-xl p-4 text-center",children:[(0,n.jsx)("p",{className:"text-error mb-4",children:m}),(0,n.jsx)("button",{onClick:()=>ee(),className:"px-4 py-2 bg-bg-tertiary border border-border-subtle rounded-lg text-text-primary hover:bg-bg-hover transition-colors",children:"Try Again"})]})});let eg=e=>{var t;let r=(t=e.permissions).admin?{level:"admin",label:"Admin",color:"text-accent-purple bg-accent-purple/10 border-accent-purple/30"}:t.push?{level:"write",label:"Write",color:"text-accent-cyan bg-accent-cyan/10 border-accent-cyan/30"}:{level:"read",label:"Read",color:"text-text-muted bg-bg-tertiary border-border-subtle"},s=A===e.fullName,a=P.has(e.fullName)||"checking"===e.gitHubAppAccess,l=z&&V===e.fullName;return(0,n.jsxs)("div",{className:"flex items-center justify-between p-4 hover:bg-bg-hover transition-colors",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 min-w-0 flex-1",children:[(0,n.jsx)(t$,{className:"w-5 h-5 text-text-muted flex-shrink-0"}),(0,n.jsxs)("div",{className:"min-w-0",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"font-medium text-text-primary truncate",children:e.fullName}),e.isPrivate&&(0,n.jsx)(tX,{className:"w-3.5 h-3.5 text-text-muted flex-shrink-0"})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2 mt-0.5",children:[(0,n.jsx)("span",{className:"text-xs px-1.5 py-0.5 rounded border ".concat(r.color),children:r.label}),(0,n.jsx)("span",{className:"text-xs text-text-muted",children:e.defaultBranch})]})]})]}),(0,n.jsx)("div",{className:"flex-shrink-0 ml-4",children:e.isInWorkspace?(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("span",{className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-success bg-success/10 border border-success/30 rounded-lg",children:[(0,n.jsx)(tQ,{className:"w-4 h-4"}),"In Workspace"]}),(0,n.jsx)("button",{onClick:()=>el(e),disabled:T===e.fullName,className:"p-1.5 text-text-muted hover:text-error hover:bg-error/10 rounded-md transition-colors disabled:opacity-50",title:"Remove from workspace",children:T===e.fullName?(0,n.jsxs)("svg",{className:"w-4 h-4 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}):(0,n.jsx)("svg",{className:"w-4 h-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:"2",children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M6 18L18 6M6 6l12 12"})})})]}):(0,n.jsx)("button",{onClick:()=>eo(e),disabled:s||a||l,className:"px-4 py-2 text-sm bg-gradient-to-r from-accent-cyan to-[#00b8d9] text-bg-deep font-medium rounded-lg hover:shadow-glow-cyan transition-all disabled:opacity-50 disabled:cursor-not-allowed",children:a?(0,n.jsxs)("span",{className:"flex items-center gap-2",children:[(0,n.jsxs)("svg",{className:"w-4 h-4 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),"Checking..."]}):l?(0,n.jsxs)("span",{className:"flex items-center gap-2",children:[(0,n.jsxs)("svg",{className:"w-4 h-4 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),"Connecting..."]}):s?(0,n.jsxs)("span",{className:"flex items-center gap-2",children:[(0,n.jsxs)("svg",{className:"w-4 h-4 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),"Adding..."]}):"has_access"===e.gitHubAppAccess?"Add to Workspace":"no_access"===e.gitHubAppAccess?"Enable Access":"Add"})})]},e.id)};return(0,n.jsxs)("div",{className:i,children:[m&&(0,n.jsx)("div",{className:"mx-4 mt-4 p-3 bg-error/10 border border-error/20 rounded-lg",children:(0,n.jsx)("p",{className:"text-error text-sm",children:m})}),(0,n.jsxs)("div",{className:"p-4 border-b border-border-subtle",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)(tY,{className:"w-5 h-5 absolute left-3 top-1/2 -translate-y-1/2 text-text-muted"}),(0,n.jsx)("input",{type:"text",placeholder:"Search your GitHub repositories...",value:f,onChange:e=>eu(e.target.value),className:"w-full pl-10 pr-4 py-2 bg-bg-tertiary border border-border-subtle rounded-lg text-text-primary placeholder:text-text-muted focus:outline-none focus:border-accent-cyan/50 transition-colors"}),C&&(0,n.jsx)("div",{className:"absolute right-3 top-1/2 -translate-y-1/2",children:(0,n.jsxs)("svg",{className:"w-4 h-4 text-text-muted animate-spin",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})})]}),f.trim()&&(0,n.jsx)("p",{className:"mt-2 text-xs text-text-muted",children:C?"Searching...":L.length>0?"Found ".concat(L.length," results"):"No results found. Try a different search term."})]}),em.length>0&&(0,n.jsxs)("div",{className:"border-b border-border-subtle",children:[(0,n.jsxs)("div",{className:"px-4 py-3 bg-bg-tertiary/50",children:[(0,n.jsxs)("h3",{className:"text-sm font-semibold text-text-primary",children:["In This Workspace (",em.length,")"]}),(0,n.jsx)("p",{className:"text-xs text-text-muted mt-0.5",children:"Repositories already added to this workspace"})]}),(0,n.jsx)("div",{className:"divide-y divide-border-subtle",children:em.map(eg)})]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("div",{className:"px-4 py-3 bg-bg-tertiary/50 border-b border-border-subtle",children:[(0,n.jsxs)("h3",{className:"text-sm font-semibold text-text-primary",children:[f.trim()?"Search Results":"Available Repositories"," (",eh.length,")"]}),(0,n.jsx)("p",{className:"text-xs text-text-muted mt-0.5",children:f.trim()?"Matching repositories from GitHub":"Repositories you have access to on GitHub"})]}),eh.length>0?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"divide-y divide-border-subtle",children:eh.map(eg)}),ep&&(0,n.jsx)("div",{className:"p-4 border-t border-border-subtle",children:(0,n.jsx)("button",{onClick:ec,disabled:N,className:"w-full py-2 text-sm text-accent-cyan hover:text-accent-cyan/80 transition-colors disabled:opacity-50",children:N?(0,n.jsxs)("span",{className:"flex items-center justify-center gap-2",children:[(0,n.jsxs)("svg",{className:"w-4 h-4 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[(0,n.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,n.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]}),"Loading more..."]}):"Load More Repositories"})})]}):(0,n.jsx)("div",{className:"p-8 text-center",children:(0,n.jsx)("p",{className:"text-text-muted",children:f.trim()?"No repositories match your search":"No additional repositories available"})})]})]})}let t1=[{id:"anthropic",name:"anthropic",displayName:"Claude",description:"Claude Code - recommended for code tasks",color:"#D97757",cliCommand:"claude",apiKeyUrl:"https://console.anthropic.com/settings/keys",apiKeyName:"API key",supportsOAuth:!0},{id:"codex",name:"codex",displayName:"Codex",description:"Codex - OpenAI coding assistant",color:"#10A37F",cliCommand:"codex login",apiKeyUrl:"https://platform.openai.com/api-keys",apiKeyName:"API key",supportsOAuth:!0},{id:"google",name:"google",displayName:"Gemini",description:"Gemini - Google AI coding assistant",color:"#4285F4",cliCommand:"gemini",supportsOAuth:!0},{id:"opencode",name:"opencode",displayName:"OpenCode",description:"OpenCode - AI coding assistant",color:"#00D4AA",cliCommand:"opencode",supportsOAuth:!0,comingSoon:!0},{id:"droid",name:"factory",displayName:"Droid",description:"Droid - Factory AI coding agent",color:"#6366F1",cliCommand:"droid",supportsOAuth:!0,comingSoon:!0},{id:"cursor",name:"cursor",displayName:"Cursor",description:"Cursor - AI-first code editor agent",color:"#7C3AED",cliCommand:"agent",supportsOAuth:!0}];function t2(e){let{workspaceId:t,csrfToken:r,onClose:a,onReposChanged:l}=e,[o,i]=(0,s.useState)(null),[d,u]=(0,s.useState)([]),[x,m]=(0,s.useState)(!0),[h,p]=(0,s.useState)(null),[g,f]=(0,s.useState)("general"),[b,v]=(0,s.useState)({}),[y,j]=(0,s.useState)(null),[w,N]=(0,s.useState)(""),[k,C]=(0,s.useState)(null),[S,L]=(0,s.useState)({}),[M,D]=(0,s.useState)({anthropic:!1,cursor:!1,google:!0}),[A,E]=(0,s.useState)(null),[T,W]=(0,s.useState)(null),[P,R]=(0,s.useState)(""),[I,B]=(0,s.useState)(!1),[F,U]=(0,s.useState)(null),[_,O]=(0,s.useState)(null);(0,s.useEffect)(()=>{if(!t||"default"===t||!/^[0-9a-f-]{36}$/i.test(t)){m(!1);return}!async function(){m(!0),p(null);let[e,r,n]=await Promise.all([c.xv.getWorkspaceDetails(t),c.xv.getRepos(),c.xv.getProviders(t)]);if(e.success?(i(e.data),e.data.customDomain&&R(e.data.customDomain)):p(e.error),r.success&&u(r.data.repositories),n.success){let e={};n.data.providers.forEach(t=>{t.isConnected&&(e[t.id]=!0,"openai"===t.id&&(e.codex=!0))}),v(e)}m(!1)}()},[t]);let H=e=>{C(null),j(e.id)},z=(0,s.useCallback)(async e=>{if(window.confirm("Are you sure you want to disconnect ".concat(e.displayName,"? This will remove the authentication and delete credential files from the workspace."))){E(e.id),C(null);try{let r=await c.xv.disconnectProvider(e.id,t);r.success?v(t=>{let r={...t};return delete r[e.id],r}):C(r.error)}catch(e){C(e instanceof Error?e.message:"Failed to disconnect provider")}finally{E(null)}}},[t]),G=async e=>{if(!w.trim()){C("Please enter an API key");return}C(null),j(e.id);try{let n={"Content-Type":"application/json"};r&&(n["X-CSRF-Token"]=r);let s=await fetch("/api/onboarding/token/".concat(e.id),{method:"POST",credentials:"include",headers:n,body:JSON.stringify({token:w.trim(),workspaceId:t})});if(!s.ok){let e=await s.json();throw Error(e.error||"Failed to connect")}v(t=>({...t,[e.id]:!0})),N(""),j(null),L(t=>({...t,[e.id]:!1}))}catch(e){C(e instanceof Error?e.message:"Failed to connect"),j(null)}},[V,K]=(0,s.useState)(!1),[Z,q]=(0,s.useState)(!1),J=(0,s.useCallback)(async()=>{if(!o||!window.confirm("Are you sure you want to restart this workspace?"))return;K(!0),p(null);let e=await c.xv.restartWorkspace(o.id);if(e.success){"reprovisioning"===e.data.action&&i(e=>e?{...e,status:"provisioning",errorMessage:void 0}:null);let r=await c.xv.getWorkspaceDetails(t);r.success&&i(r.data)}else p(e.error);K(!1)},[o,t]),$=(0,s.useCallback)(async()=>{if(!o||!window.confirm("This will completely rebuild your workspace from scratch. All running processes will be stopped. Continue?"))return;q(!0),p(null);let e=await c.xv.rebuildWorkspace(o.id);if(e.success){i(e=>e?{...e,status:"provisioning",errorMessage:void 0}:null);let e=await c.xv.getWorkspaceDetails(t);e.success&&i(e.data)}else p(e.error);q(!1)},[o,t]),Y=(0,s.useCallback)(async()=>{if(!o||!window.confirm("Are you sure you want to stop this workspace?"))return;let e=await c.xv.stopWorkspace(o.id);if(e.success){let e=await c.xv.getWorkspaceDetails(t);e.success&&i(e.data)}else p(e.error)},[o,t]);(0,s.useCallback)(async e=>{if(!o)return;let r=await c.xv.addReposToWorkspace(o.id,[e]);if(r.success){let e=await c.xv.getWorkspaceDetails(t);e.success&&i(e.data)}else p(r.error)},[o,t]),(0,s.useCallback)(async e=>{if(!o)return;W(e),p(null);let r=await c.xv.syncRepo(e);if(r.success){let e=await c.xv.getWorkspaceDetails(t);e.success&&i(e.data)}else p(r.error);W(null)},[o,t]);let X=(0,s.useCallback)(async()=>{if(!o||!P.trim())return;B(!0),U(null),O(null);let e=await c.xv.setCustomDomain(o.id,P.trim());if(e.success){O(e.data.instructions);let r=await c.xv.getWorkspaceDetails(t);r.success&&i(r.data)}else U(e.error);B(!1)},[o,P,t]),Q=(0,s.useCallback)(async()=>{if(!o)return;B(!0),U(null);let e=await c.xv.verifyCustomDomain(o.id);if(e.success){let r=await c.xv.getWorkspaceDetails(t);r.success&&i(r.data),"active"===e.data.status&&O(null)}else U(e.error);B(!1)},[o,t]),ee=(0,s.useCallback)(async()=>{if(!o||!window.confirm("Are you sure you want to remove the custom domain?"))return;B(!0);let e=await c.xv.removeCustomDomain(o.id);if(e.success){R(""),O(null);let e=await c.xv.getWorkspaceDetails(t);e.success&&i(e.data)}else U(e.error);B(!1)},[o,t]),et=(0,s.useCallback)(async()=>{if(!o||!window.confirm('Are you sure you want to delete "'.concat(o.name,'"? This action cannot be undone.'))||!window.confirm("This will permanently delete all workspace data. Are you absolutely sure?"))return;let e=await c.xv.deleteWorkspace(o.id);e.success?window.location.href="/app/onboarding?reason=deleted":p(e.error)},[o]);if(x)return(0,n.jsxs)("div",{className:"flex items-center justify-center h-64",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("div",{className:"w-12 h-12 rounded-full border-2 border-accent-cyan/20 border-t-accent-cyan animate-spin"}),(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,n.jsx)("div",{className:"w-4 h-4 rounded-full bg-accent-cyan/40 animate-pulse"})})]}),(0,n.jsx)("span",{className:"ml-4 text-text-muted font-mono text-sm tracking-wide",children:"LOADING WORKSPACE CONFIG..."})]});if(h&&!o)return(0,n.jsx)("div",{className:"p-6",children:(0,n.jsxs)("div",{className:"p-4 bg-error/10 border border-error/30 rounded-lg text-error flex items-center gap-3",children:[(0,n.jsx)(rr,{}),(0,n.jsx)("span",{children:h})]})});if(!o)return null;d.filter(e=>!o.repositories.some(t=>t.id===e.id));let er=[{id:"general",label:"General",icon:(0,n.jsx)(t9,{})},{id:"providers",label:"AI Providers",icon:(0,n.jsx)(t7,{})},{id:"repos",label:"Repositories",icon:(0,n.jsx)(re,{})},{id:"domain",label:"Domain",icon:(0,n.jsx)(rt,{})},{id:"danger",label:"Danger",icon:(0,n.jsx)(rr,{})}];return(0,n.jsxs)("div",{className:"flex flex-col h-full bg-bg-primary",children:[(0,n.jsx)("div",{className:"flex gap-1 p-2 sm:p-3 border-b border-border-subtle bg-gradient-to-b from-bg-tertiary to-bg-primary overflow-x-auto scrollbar-hide scroll-smooth snap-x snap-mandatory touch-pan-x",style:{WebkitOverflowScrolling:"touch"},children:er.map(e=>(0,n.jsxs)("button",{onClick:()=>f(e.id),className:"flex items-center gap-1.5 sm:gap-2 px-3 sm:px-4 py-2 sm:py-2.5 rounded-lg text-xs sm:text-sm font-medium transition-all duration-200 whitespace-nowrap shrink-0 snap-start ".concat(g===e.id?"bg-accent-cyan/15 text-accent-cyan border border-accent-cyan/30 shadow-[0_0_12px_rgba(0,217,255,0.15)]":"text-text-secondary hover:bg-bg-hover hover:text-text-primary border border-transparent"),children:[(0,n.jsx)("span",{className:g===e.id?"text-accent-cyan":"text-text-muted",children:e.icon}),e.label]},e.id))}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto p-4 sm:p-6",children:[h&&(0,n.jsxs)("div",{className:"mb-6 p-4 bg-error/10 border border-error/30 rounded-lg text-error text-sm flex items-center gap-3",children:[(0,n.jsx)(rr,{}),(0,n.jsx)("span",{className:"flex-1",children:h}),(0,n.jsx)("button",{onClick:()=>p(null),className:"text-error/60 hover:text-error",children:(0,n.jsx)(ri,{})})]}),"general"===g&&(0,n.jsxs)("div",{className:"space-y-8",children:[(0,n.jsx)(t5,{title:"Workspace Overview",subtitle:"Core configuration and status"}),"error"===o.status&&(0,n.jsxs)("div",{className:"p-5 bg-error/10 border border-error/30 rounded-xl space-y-4",children:[(0,n.jsxs)("div",{className:"flex items-start gap-3",children:[(0,n.jsx)("div",{className:"w-10 h-10 rounded-lg bg-error/20 flex items-center justify-center shrink-0 mt-0.5",children:(0,n.jsx)(rr,{className:"text-error"})}),(0,n.jsxs)("div",{className:"flex-1",children:[(0,n.jsx)("h4",{className:"text-sm font-semibold text-error",children:"Workspace Error"}),(0,n.jsx)("p",{className:"text-xs text-text-secondary mt-1",children:o.errorMessage||"The workspace encountered an error and is not running."})]})]}),(0,n.jsxs)("div",{className:"flex gap-3",children:[(0,n.jsx)(t3,{onClick:J,disabled:V||Z,variant:"primary",icon:V?(0,n.jsx)(rd,{}):(0,n.jsx)(ra,{}),children:V?"Restarting...":"Restart Workspace"}),(0,n.jsx)(t3,{onClick:$,disabled:V||Z,variant:"warning",icon:Z?(0,n.jsx)(rd,{}):(0,n.jsx)(ru,{}),children:Z?"Rebuilding...":"Rebuild from Scratch"})]})]}),(0,n.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,n.jsx)(t4,{label:"Name",value:o.name}),(0,n.jsx)(t4,{label:"Status",value:V||Z?"Provisioning":o.status.charAt(0).toUpperCase()+o.status.slice(1),valueColor:V||Z?"text-accent-cyan":"running"===o.status?"text-success":"stopped"===o.status?"text-amber-400":"error"===o.status?"text-error":"text-text-muted",indicator:"running"===o.status&&!V&&!Z}),(0,n.jsx)(t4,{label:"Public URL",value:o.publicUrl||"Not available",mono:!0}),(0,n.jsx)(t4,{label:"Compute Provider",value:o.computeProvider.charAt(0).toUpperCase()+o.computeProvider.slice(1)})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)(t5,{title:"Actions",subtitle:"Manage workspace state"}),(0,n.jsxs)("div",{className:"flex flex-wrap gap-3 mt-4",children:["running"===o.status&&(0,n.jsx)(t3,{onClick:Y,variant:"warning",icon:(0,n.jsx)(rs,{}),children:"Stop Workspace"}),(0,n.jsx)(t3,{onClick:J,disabled:V||Z,variant:"primary",icon:V?(0,n.jsx)(rd,{}):(0,n.jsx)(ra,{}),children:V?"Restarting...":"Restart Workspace"}),(0,n.jsx)(t3,{onClick:$,disabled:V||Z,variant:"danger",icon:Z?(0,n.jsx)(rd,{}):(0,n.jsx)(ru,{}),children:Z?"Rebuilding...":"Rebuild Workspace"})]})]})]}),"providers"===g&&(0,n.jsxs)("div",{className:"space-y-8",children:[(0,n.jsx)(t5,{title:"AI Providers",subtitle:"Connect AI providers to spawn agents in this workspace"}),k&&(0,n.jsxs)("div",{className:"p-4 bg-error/10 border border-error/30 rounded-lg text-error text-sm flex items-center gap-3",children:[(0,n.jsx)(rr,{}),(0,n.jsx)("span",{children:k})]}),(0,n.jsx)("div",{className:"space-y-4",children:t1.map(e=>(0,n.jsxs)("div",{className:"p-5 bg-bg-tertiary rounded-xl border border-border-subtle transition-all duration-200 ".concat(e.comingSoon?"opacity-60":"hover:border-border-medium"),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-4",children:[(0,n.jsx)("div",{className:"w-12 h-12 rounded-xl flex items-center justify-center text-white font-bold text-lg shadow-lg ".concat(e.comingSoon?"grayscale":""),style:{backgroundColor:e.color,boxShadow:e.comingSoon?"none":"0 4px 20px ".concat(e.color,"40")},children:e.displayName[0]}),(0,n.jsxs)("div",{children:[(0,n.jsxs)("h4",{className:"text-base font-semibold text-text-primary flex items-center gap-2",children:[e.displayName,e.comingSoon&&(0,n.jsx)("span",{className:"px-2 py-0.5 bg-amber-400/20 text-amber-400 text-xs font-medium rounded-full",children:"Coming Soon"})]}),(0,n.jsx)("p",{className:"text-sm text-text-muted",children:e.description})]})]}),e.comingSoon?(0,n.jsx)("div",{className:"px-4 py-2 bg-bg-card rounded-full border border-border-subtle",children:(0,n.jsx)("span",{className:"text-sm text-text-muted",children:"Not available yet"})}):b[e.id]?(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2 bg-success/15 rounded-full border border-success/30",children:[(0,n.jsx)("div",{className:"w-2 h-2 rounded-full bg-success animate-pulse"}),(0,n.jsx)("span",{className:"text-sm font-medium text-success",children:"Connected"})]}),(0,n.jsx)("button",{onClick:()=>z(e),disabled:A===e.id,className:"px-3 py-2 text-xs font-medium text-error/80 hover:text-error hover:bg-error/10 rounded-lg border border-transparent hover:border-error/30 transition-all disabled:opacity-50 disabled:cursor-not-allowed",title:"Disconnect ".concat(e.displayName),children:A===e.id?"Disconnecting...":"Disconnect"})]}):null]}),!b[e.id]&&!e.comingSoon&&(0,n.jsx)("div",{className:"mt-5 pt-5 border-t border-border-subtle",children:y!==e.id||S[e.id]?S[e.id]?(0,n.jsxs)("div",{className:"space-y-4",children:[(0,n.jsxs)("div",{className:"flex gap-3",children:[(0,n.jsx)("input",{type:"password",placeholder:"Enter ".concat(e.displayName," ").concat(e.apiKeyName||"API key"),value:y===e.id?w:"",onChange:t=>{j(e.id),N(t.target.value)},onFocus:()=>j(e.id),className:"flex-1 px-4 py-3 bg-bg-card border border-border-subtle rounded-lg text-sm text-text-primary placeholder:text-text-muted focus:outline-none focus:border-accent-cyan focus:ring-1 focus:ring-accent-cyan/30 transition-all"}),(0,n.jsx)("button",{onClick:()=>G(e),disabled:y!==e.id||!w.trim(),className:"px-5 py-3 bg-accent-cyan text-bg-deep font-semibold rounded-lg text-sm hover:bg-accent-cyan/90 disabled:opacity-50 disabled:cursor-not-allowed transition-all",children:"Connect"})]}),e.apiKeyUrl&&(0,n.jsxs)("p",{className:"text-xs text-text-muted",children:["Get your API key from"," ",(0,n.jsx)("a",{href:e.apiKeyUrl,target:"_blank",rel:"noopener noreferrer",className:"text-accent-cyan hover:underline",children:new URL(e.apiKeyUrl).hostname})]}),e.supportsOAuth&&(0,n.jsx)("button",{onClick:()=>L(t=>({...t,[e.id]:!1})),className:"text-xs text-text-muted hover:text-text-secondary transition-colors",children:"← Back to OAuth login"})]}):e.supportsOAuth?(0,n.jsxs)("div",{className:"space-y-3",children:[["codex","anthropic","cursor"].includes(e.id)&&(0,n.jsxs)("div",{className:"p-3 bg-accent-cyan/10 border border-accent-cyan/30 rounded-lg",children:[(0,n.jsx)("p",{className:"text-sm text-accent-cyan font-medium mb-1",children:"CLI-assisted authentication"}),(0,n.jsxs)("p",{className:"text-xs text-accent-cyan/80",children:["Click the button below to get a CLI command with a unique session token. Run it on your local machine to authenticate with ",e.displayName," via a secure SSH tunnel."]})]}),(0,n.jsxs)("button",{onClick:()=>H(e),disabled:null!==y,className:"w-full py-3 px-4 bg-gradient-to-r from-accent-cyan to-[#00b8d9] text-bg-deep font-semibold rounded-lg text-sm hover:shadow-glow-cyan hover:-translate-y-0.5 disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:translate-y-0 disabled:hover:shadow-none transition-all duration-200 flex items-center justify-center gap-2",children:[(0,n.jsx)(rn,{}),"Connect with ",e.displayName]}),e.apiKeyUrl&&(0,n.jsx)("button",{onClick:()=>L(t=>({...t,[e.id]:!0})),className:"w-full text-xs text-text-muted hover:text-text-secondary transition-colors",children:"Or enter API key manually"})]}):(0,n.jsxs)("div",{className:"space-y-4",children:[(0,n.jsxs)("div",{className:"flex gap-3",children:[(0,n.jsx)("input",{type:"password",placeholder:"Enter ".concat(e.displayName," ").concat(e.apiKeyName||"API key"),value:y===e.id?w:"",onChange:t=>{j(e.id),N(t.target.value)},onFocus:()=>j(e.id),className:"flex-1 px-4 py-3 bg-bg-card border border-border-subtle rounded-lg text-sm text-text-primary placeholder:text-text-muted focus:outline-none focus:border-accent-cyan focus:ring-1 focus:ring-accent-cyan/30 transition-all"}),(0,n.jsx)("button",{onClick:()=>G(e),disabled:y!==e.id||!w.trim(),className:"px-5 py-3 bg-accent-cyan text-bg-deep font-semibold rounded-lg text-sm hover:bg-accent-cyan/90 disabled:opacity-50 disabled:cursor-not-allowed transition-all",children:"Connect"})]}),e.apiKeyUrl&&(0,n.jsxs)("p",{className:"text-xs text-text-muted",children:["Get your API key from"," ",(0,n.jsx)("a",{href:e.apiKeyUrl,target:"_blank",rel:"noopener noreferrer",className:"text-accent-cyan hover:underline",children:new URL(e.apiKeyUrl).hostname})]}),(0,n.jsxs)("p",{className:"text-xs text-amber-400/80",children:["OAuth not available for ",e.displayName," in container environments"]})]}):M[e.id]?(0,n.jsx)(tq.$,{provider:{id:e.id,name:e.name,displayName:e.displayName,color:e.color},workspaceId:t,csrfToken:r,maxHeight:"350px",onSuccess:()=>{v(t=>({...t,[e.id]:!0})),j(null)},onCancel:()=>{j(null)},onError:e=>{C(e),j(null)},onConnectAnother:()=>{v(t=>({...t,[e.id]:!0})),j(null)}}):(0,n.jsx)(tZ.j,{provider:{id:e.id,name:e.name,displayName:e.displayName,color:e.color,requiresUrlCopy:["codex","anthropic","cursor"].includes(e.id)},workspaceId:t,csrfToken:r,onSuccess:()=>{v(t=>({...t,[e.id]:!0})),j(null)},onCancel:()=>{j(null)},onError:e=>{C(e),j(null)}})})]},e.id))})]}),"repos"===g&&(0,n.jsxs)("div",{className:"space-y-6",children:[(0,n.jsx)(t5,{title:"Repositories",subtitle:"Manage repositories for this workspace"}),(0,n.jsx)(t0,{workspaceId:t,workspaceRepos:o.repositories,onRepoAdded:()=>{c.xv.getWorkspaceDetails(t).then(e=>{e.success&&i(e.data)}),null==l||l()},onRepoRemoved:()=>{c.xv.getWorkspaceDetails(t).then(e=>{e.success&&i(e.data)}),null==l||l()},csrfToken:r,className:"bg-bg-tertiary rounded-xl border border-border-subtle overflow-hidden"})]}),"domain"===g&&(0,n.jsxs)("div",{className:"space-y-8",children:[(0,n.jsx)(t5,{title:"Custom Domain",subtitle:"Connect your own domain to this workspace"}),(0,n.jsx)("div",{className:"p-5 bg-gradient-to-r from-accent-purple/10 to-accent-cyan/10 border border-accent-purple/20 rounded-xl",children:(0,n.jsxs)("div",{className:"flex items-center gap-3 mb-3",children:[(0,n.jsx)("div",{className:"w-10 h-10 rounded-lg bg-accent-purple/20 flex items-center justify-center",children:(0,n.jsx)(rt,{className:"text-accent-purple"})}),(0,n.jsxs)("div",{children:[(0,n.jsx)("h4",{className:"text-sm font-semibold text-text-primary",children:"Premium Feature"}),(0,n.jsx)("p",{className:"text-xs text-text-secondary",children:"Requires Team or Enterprise plan"})]})]})}),o.customDomain?(0,n.jsxs)("div",{className:"space-y-4",children:[(0,n.jsxs)("div",{className:"p-5 bg-bg-tertiary rounded-xl border border-border-subtle",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,n.jsx)("span",{className:"text-xs text-text-muted uppercase tracking-wide font-semibold",children:"Current Domain"}),(0,n.jsx)(t6,{status:o.customDomainStatus||"pending"})]}),(0,n.jsx)("p",{className:"text-lg font-mono text-text-primary",children:o.customDomain})]}),"pending"===o.customDomainStatus&&(0,n.jsx)(t3,{onClick:Q,disabled:I,variant:"primary",icon:(0,n.jsx)(rl,{}),fullWidth:!0,children:I?"Verifying...":"Verify DNS Configuration"}),(0,n.jsx)(t3,{onClick:ee,disabled:I,variant:"danger",icon:(0,n.jsx)(ro,{}),fullWidth:!0,children:"Remove Custom Domain"})]}):(0,n.jsxs)("div",{className:"space-y-4",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs font-semibold text-text-muted uppercase tracking-wide mb-2 block",children:"Domain Name"}),(0,n.jsx)("input",{type:"text",value:P,onChange:e=>R(e.target.value),placeholder:"workspace.yourdomain.com",className:"w-full px-4 py-3 bg-bg-tertiary border border-border-subtle rounded-lg text-sm text-text-primary font-mono placeholder:text-text-muted focus:outline-none focus:border-accent-cyan focus:ring-1 focus:ring-accent-cyan/30 transition-all"})]}),(0,n.jsx)(t3,{onClick:X,disabled:I||!P.trim(),variant:"primary",icon:(0,n.jsx)(rt,{}),fullWidth:!0,children:I?"Setting up...":"Set Custom Domain"})]}),F&&(0,n.jsx)("div",{className:"p-4 bg-error/10 border border-error/30 rounded-lg text-error text-sm",children:F}),_&&(0,n.jsxs)("div",{className:"p-5 bg-bg-tertiary rounded-xl border border-border-subtle space-y-4",children:[(0,n.jsxs)("h4",{className:"text-sm font-semibold text-text-primary flex items-center gap-2",children:[(0,n.jsx)(rc,{}),"DNS Configuration Required"]}),(0,n.jsx)("p",{className:"text-xs text-text-secondary",children:"Add the following DNS record to your domain provider:"}),(0,n.jsxs)("div",{className:"grid grid-cols-3 gap-3",children:[(0,n.jsx)(t8,{label:"Type",value:_.type}),(0,n.jsx)(t8,{label:"Name",value:_.name}),(0,n.jsx)(t8,{label:"Value",value:_.value})]})]})]}),"danger"===g&&(0,n.jsx)("div",{className:"space-y-8",children:(0,n.jsxs)("div",{className:"p-6 bg-error/5 border-2 border-error/20 rounded-xl",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 mb-4",children:[(0,n.jsx)("div",{className:"w-10 h-10 rounded-lg bg-error/20 flex items-center justify-center",children:(0,n.jsx)(rr,{className:"text-error"})}),(0,n.jsxs)("div",{children:[(0,n.jsx)("h3",{className:"text-base font-semibold text-error",children:"Danger Zone"}),(0,n.jsx)("p",{className:"text-xs text-text-secondary",children:"These actions are destructive and cannot be undone"})]})]}),(0,n.jsx)("div",{className:"p-5 border border-error/30 rounded-lg bg-bg-primary",children:(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h4",{className:"text-sm font-semibold text-text-primary",children:"Delete Workspace"}),(0,n.jsx)("p",{className:"text-xs text-text-muted mt-1",children:"Permanently delete this workspace and all its data"})]}),(0,n.jsx)("button",{onClick:et,className:"px-5 py-2.5 bg-error text-white rounded-lg text-sm font-semibold hover:bg-error/90 transition-colors",children:"Delete Workspace"})]})})]})})]})]})}function t5(e){let{title:t,subtitle:r}=e;return(0,n.jsxs)("div",{className:"mb-4",children:[(0,n.jsx)("h3",{className:"text-sm font-semibold text-text-muted uppercase tracking-wide",children:t}),(0,n.jsx)("p",{className:"text-xs text-text-muted mt-1",children:r})]})}function t4(e){let{label:t,value:r,valueColor:s="text-text-primary",mono:a=!1,indicator:l=!1}=e;return(0,n.jsxs)("div",{className:"p-4 bg-bg-tertiary rounded-lg border border-border-subtle",children:[(0,n.jsx)("label",{className:"text-xs text-text-muted uppercase tracking-wide font-medium",children:t}),(0,n.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[l&&(0,n.jsx)("div",{className:"w-2 h-2 rounded-full bg-success animate-pulse"}),(0,n.jsx)("p",{className:"text-sm font-medium ".concat(s," ").concat(a?"font-mono":""," break-all"),children:r})]})]})}function t3(e){let{children:t,onClick:r,disabled:s,variant:a,icon:l,fullWidth:o}=e;return(0,n.jsxs)("button",{onClick:r,disabled:s,className:"".concat(o?"w-full":""," px-5 py-2.5 border rounded-lg text-sm font-semibold transition-all duration-200 disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2 ").concat({primary:"bg-accent-cyan/10 border-accent-cyan/30 text-accent-cyan hover:bg-accent-cyan/20",warning:"bg-amber-400/10 border-amber-400/30 text-amber-400 hover:bg-amber-400/20",danger:"bg-error/10 border-error/30 text-error hover:bg-error/20"}[a]),children:[l,t]})}function t6(e){let{status:t}=e;return(0,n.jsx)("span",{className:"text-xs px-3 py-1 rounded-full border ".concat({synced:"bg-success/15 text-success border-success/30",active:"bg-success/15 text-success border-success/30",syncing:"bg-accent-cyan/15 text-accent-cyan border-accent-cyan/30",verifying:"bg-accent-cyan/15 text-accent-cyan border-accent-cyan/30",pending:"bg-amber-400/15 text-amber-400 border-amber-400/30",error:"bg-error/15 text-error border-error/30"}[t]||"bg-bg-hover text-text-muted border-border-subtle"),children:t})}function t8(e){let{label:t,value:r}=e;return(0,n.jsxs)("div",{className:"p-3 bg-bg-card rounded-lg",children:[(0,n.jsx)("label",{className:"text-xs text-text-muted block mb-1",children:t}),(0,n.jsx)("p",{className:"font-mono text-sm text-text-primary break-all",children:r})]})}function t9(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,n.jsx)("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"})]})}function t7(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M12 2L2 7l10 5 10-5-10-5z"}),(0,n.jsx)("path",{d:"M2 17l10 5 10-5"}),(0,n.jsx)("path",{d:"M2 12l10 5 10-5"})]})}function re(e){let{className:t=""}=e;return(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-text-muted ".concat(t),children:(0,n.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"})})}function rt(e){let{className:t=""}=e;return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"2",y1:"12",x2:"22",y2:"12"}),(0,n.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"})]})}function rr(e){let{className:t=""}=e;return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[(0,n.jsx)("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),(0,n.jsx)("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),(0,n.jsx)("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]})}function rn(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),(0,n.jsx)("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function rs(){return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("rect",{x:"6",y:"6",width:"12",height:"12"})})}function ra(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M23 4v6h-6"}),(0,n.jsx)("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}function rl(){return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})})}function ro(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.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"})]})}function ri(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function rc(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,n.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}function rd(){return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"animate-spin",children:(0,n.jsx)("path",{d:"M21 12a9 9 0 1 1-6.219-8.56"})})}function ru(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M2 12a10 10 0 0 1 10-10"}),(0,n.jsx)("path",{d:"M22 12a10 10 0 0 1-10 10"}),(0,n.jsx)("path",{d:"M12 2v4"}),(0,n.jsx)("path",{d:"M12 18v4"}),(0,n.jsx)("path",{d:"M4.93 4.93l2.83 2.83"}),(0,n.jsx)("path",{d:"M16.24 16.24l2.83 2.83"})]})}let rx={owner:"bg-accent-purple/20 text-accent-purple",admin:"bg-accent-cyan/20 text-accent-cyan",member:"bg-success/20 text-success",viewer:"bg-bg-hover text-text-muted"},rm={owner:"Full access, can delete workspace and transfer ownership",admin:"Can manage members, settings, and all workspace features",member:"Can use workspace, spawn agents, and send messages",viewer:"Read-only access to workspace activity"};function rh(e){var t;let{workspaceId:r,currentUserId:a}=e,[l,o]=(0,s.useState)([]),[i,d]=(0,s.useState)([]),[u,x]=(0,s.useState)([]),[m,h]=(0,s.useState)(!0),[p,g]=(0,s.useState)(!0),[f,b]=(0,s.useState)(null),[v,y]=(0,s.useState)(null),[j,w]=(0,s.useState)(!1),[N,k]=(0,s.useState)(""),[C,S]=(0,s.useState)("member"),[L,M]=(0,s.useState)(!1),[D,A]=(0,s.useState)(null),[E,T]=(0,s.useState)(null);(0,s.useEffect)(()=>{(async function(){h(!0),b(null);let[e,t]=await Promise.all([c.xv.getWorkspaceMembers(r),c.xv.getPendingInvites()]);e.success?o(e.data.members):b(e.error),t.success&&d(t.data.invites.filter(e=>e.workspaceId===r)),h(!1)})()},[r]),(0,s.useEffect)(()=>{(async function(){g(!0);let e=await c.xv.getRepoCollaborators(r);e.success&&x(e.data.collaborators||[]),g(!1)})()},[r]);let W=(0,s.useCallback)(async()=>{if(!N.trim()){A("Please enter a GitHub username");return}M(!0),A(null);let e=await c.xv.inviteMember(r,N.trim(),C);if(e.success){let e=await c.xv.getWorkspaceMembers(r);e.success&&o(e.data.members),k(""),w(!1),y("Invitation sent to ".concat(N)),setTimeout(()=>y(null),3e3)}else A(e.error);M(!1)},[r,N,C]),P=(0,s.useCallback)(async(e,t)=>{T(e);let n=await c.xv.updateMemberRole(r,e,t);n.success?(o(r=>r.map(r=>r.id===e?{...r,role:t}:r)),y("Role updated successfully"),setTimeout(()=>y(null),3e3)):b(n.error),T(null)},[r]),R=(0,s.useCallback)(async e=>{var t;if(!window.confirm("Are you sure you want to remove ".concat((null===(t=e.user)||void 0===t?void 0:t.githubUsername)||"this member"," from the workspace?")))return;let n=await c.xv.removeMember(r,e.id);n.success?(o(t=>t.filter(t=>t.id!==e.id)),y("Member removed successfully"),setTimeout(()=>y(null),3e3)):b(n.error)},[r]),I=null===(t=l.find(e=>e.userId===a))||void 0===t?void 0:t.role,B="owner"===I||"admin"===I;return m?(0,n.jsxs)("div",{className:"flex items-center justify-center h-64",children:[(0,n.jsx)(rp,{}),(0,n.jsx)("span",{className:"ml-3 text-text-muted",children:"Loading team members..."})]}):(0,n.jsxs)("div",{className:"space-y-6",children:[(0,n.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h3",{className:"text-sm font-semibold text-text-muted uppercase tracking-wide",children:"Team Members"}),(0,n.jsxs)("p",{className:"text-xs text-text-muted mt-1",children:[l.length," member",1!==l.length?"s":""]})]}),B&&(0,n.jsxs)("button",{onClick:()=>w(!j),className:"px-3 md:px-4 py-2 bg-accent-cyan text-bg-deep rounded-lg text-xs md:text-sm font-medium hover:bg-accent-cyan/90 transition-colors flex items-center justify-center gap-2 w-full sm:w-auto",children:[(0,n.jsx)(rg,{}),"Invite Member"]})]}),f&&(0,n.jsxs)("div",{className:"p-3 bg-error/10 border border-error/30 rounded-lg text-error text-sm",children:[f,(0,n.jsx)("button",{onClick:()=>b(null),className:"ml-2 text-error/70 hover:text-error",children:"\xd7"})]}),v&&(0,n.jsx)("div",{className:"p-3 bg-success/10 border border-success/30 rounded-lg text-success text-sm",children:v}),j&&(0,n.jsxs)("div",{className:"p-4 bg-bg-tertiary rounded-lg border border-border-subtle space-y-4",children:[(0,n.jsx)("h4",{className:"text-sm font-medium text-text-primary",children:"Invite New Member"}),D&&(0,n.jsx)("div",{className:"p-2 bg-error/10 border border-error/30 rounded text-error text-xs",children:D}),(0,n.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-text-muted mb-1 block",children:"GitHub Username"}),(0,n.jsx)("input",{type:"text",value:N,onChange:e=>k(e.target.value),placeholder:"username",className:"w-full px-3 py-2 bg-bg-card border border-border-subtle rounded-lg text-sm text-text-primary placeholder:text-text-muted focus:outline-none focus:border-accent-cyan"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-text-muted mb-1 block",children:"Role"}),(0,n.jsxs)("select",{value:C,onChange:e=>S(e.target.value),className:"w-full px-3 py-2 bg-bg-card border border-border-subtle rounded-lg text-sm text-text-primary focus:outline-none focus:border-accent-cyan",children:[(0,n.jsx)("option",{value:"admin",children:"Admin"}),(0,n.jsx)("option",{value:"member",children:"Member"}),(0,n.jsx)("option",{value:"viewer",children:"Viewer"})]})]})]}),(0,n.jsx)("p",{className:"text-xs text-text-muted",children:rm[C]}),(0,n.jsxs)("div",{className:"flex flex-col sm:flex-row gap-2",children:[(0,n.jsx)("button",{onClick:W,disabled:L||!N.trim(),className:"px-4 py-2 bg-accent-cyan text-bg-deep rounded-lg text-sm font-medium hover:bg-accent-cyan/90 disabled:opacity-50 transition-colors",children:L?"Sending...":"Send Invitation"}),(0,n.jsx)("button",{onClick:()=>{w(!1),k(""),A(null)},className:"px-4 py-2 bg-bg-hover text-text-secondary rounded-lg text-sm font-medium hover:text-text-primary transition-colors",children:"Cancel"})]})]}),(0,n.jsx)("div",{className:"space-y-2",children:l.map(e=>{var t,r,s,l,o,i;return(0,n.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3 p-3 md:p-4 bg-bg-tertiary rounded-lg",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(null===(t=e.user)||void 0===t?void 0:t.avatarUrl)?(0,n.jsx)("img",{src:e.user.avatarUrl,alt:e.user.githubUsername,className:"w-9 h-9 md:w-10 md:h-10 rounded-full"}):(0,n.jsx)("div",{className:"w-9 h-9 md:w-10 md:h-10 rounded-full bg-accent-cyan/20 flex items-center justify-center text-accent-cyan font-bold text-xs md:text-sm",children:(null===(l=e.user)||void 0===l?void 0:null===(s=l.githubUsername)||void 0===s?void 0:null===(r=s[0])||void 0===r?void 0:r.toUpperCase())||"?"}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,n.jsx)("p",{className:"text-sm font-medium text-text-primary truncate",children:(null===(o=e.user)||void 0===o?void 0:o.githubUsername)||"Unknown User"}),e.isPending&&(0,n.jsx)("span",{className:"text-[10px] px-2 py-0.5 bg-amber-400/20 text-amber-400 rounded-full",children:"Pending"}),e.userId===a&&(0,n.jsx)("span",{className:"text-xs text-text-muted",children:"(you)"})]}),(null===(i=e.user)||void 0===i?void 0:i.email)&&(0,n.jsx)("p",{className:"text-xs text-text-muted truncate",children:e.user.email})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2 sm:gap-3 ml-12 sm:ml-0",children:[B&&"owner"!==e.role&&e.userId!==a?(0,n.jsxs)("select",{value:e.role,onChange:t=>P(e.id,t.target.value),disabled:E===e.id,className:"px-2 md:px-3 py-1 md:py-1.5 rounded-full text-[10px] md:text-xs font-medium border-none cursor-pointer ".concat(rx[e.role]," focus:outline-none"),children:[(0,n.jsx)("option",{value:"admin",children:"Admin"}),(0,n.jsx)("option",{value:"member",children:"Member"}),(0,n.jsx)("option",{value:"viewer",children:"Viewer"})]}):(0,n.jsx)("span",{className:"px-2 md:px-3 py-1 md:py-1.5 rounded-full text-[10px] md:text-xs font-medium ".concat(rx[e.role]),children:e.role.charAt(0).toUpperCase()+e.role.slice(1)}),B&&"owner"!==e.role&&e.userId!==a&&(0,n.jsx)("button",{onClick:()=>R(e),className:"p-1.5 text-text-muted hover:text-error rounded transition-colors",title:"Remove member",children:(0,n.jsx)(rf,{})})]})]},e.id)})}),(u.length>0||p)&&(0,n.jsxs)("div",{className:"mt-8",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 mb-4",children:[(0,n.jsx)("h3",{className:"text-sm font-semibold text-text-muted uppercase tracking-wide",children:"Repo Collaborators"}),(0,n.jsx)("span",{className:"px-2 py-0.5 bg-accent-purple/10 text-accent-purple text-[10px] rounded-full",children:"GitHub Access"})]}),(0,n.jsx)("p",{className:"text-xs text-text-muted mb-4",children:"These users have access via GitHub repo permissions. They can access this workspace without an explicit invite."}),p?(0,n.jsxs)("div",{className:"flex items-center gap-2 py-4",children:[(0,n.jsx)(rp,{}),(0,n.jsx)("span",{className:"text-sm text-text-muted",children:"Loading collaborators..."})]}):(0,n.jsx)("div",{className:"space-y-2",children:u.map(e=>{var t;return(0,n.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3 p-3 md:p-4 bg-bg-tertiary rounded-lg border border-accent-purple/20",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[e.avatarUrl?(0,n.jsx)("img",{src:e.avatarUrl,alt:e.login,className:"w-9 h-9 md:w-10 md:h-10 rounded-full"}):(0,n.jsx)("div",{className:"w-9 h-9 md:w-10 md:h-10 rounded-full bg-accent-purple/20 flex items-center justify-center text-accent-purple font-bold text-xs md:text-sm",children:(null===(t=e.login[0])||void 0===t?void 0:t.toUpperCase())||"?"}),(0,n.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,n.jsxs)("div",{className:"flex flex-wrap items-center gap-2",children:[(0,n.jsx)("p",{className:"text-sm font-medium text-text-primary truncate",children:e.login}),(0,n.jsx)("span",{className:"text-[10px] px-2 py-0.5 bg-accent-purple/10 text-accent-purple rounded-full",children:"via GitHub"})]}),(0,n.jsx)("p",{className:"text-xs text-text-muted truncate",children:1===e.repos.length?"Access via ".concat(e.repos[0]):"Access via ".concat(e.repos.length," repos")})]})]}),(0,n.jsx)("div",{className:"flex items-center gap-2 sm:gap-3 ml-12 sm:ml-0",children:(0,n.jsx)("span",{className:"px-2 md:px-3 py-1 md:py-1.5 rounded-full text-[10px] md:text-xs font-medium ".concat("admin"===e.permission?"bg-accent-cyan/20 text-accent-cyan":"write"===e.permission?"bg-success/20 text-success":"bg-bg-hover text-text-muted"),children:"admin"===e.permission?"Admin":"write"===e.permission?"Write":"Read"})})]},e.id)})})]}),i.length>0&&(0,n.jsxs)("div",{className:"mt-8",children:[(0,n.jsx)("h3",{className:"text-sm font-semibold text-text-muted uppercase tracking-wide mb-4",children:"Your Pending Invitations"}),(0,n.jsx)("div",{className:"space-y-2",children:i.map(e=>(0,n.jsxs)("div",{className:"flex items-center justify-between p-4 bg-bg-tertiary rounded-lg border border-accent-cyan/30",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("p",{className:"text-sm font-medium text-text-primary",children:e.workspaceName}),(0,n.jsxs)("p",{className:"text-xs text-text-muted",children:["Invited by ",e.invitedBy," as ",e.role]})]}),(0,n.jsxs)("div",{className:"flex gap-2",children:[(0,n.jsx)("button",{onClick:async()=>{(await c.xv.acceptInvite(e.id)).success&&(d(t=>t.filter(t=>t.id!==e.id)),y("Invitation accepted!"),setTimeout(()=>y(null),3e3))},className:"px-3 py-1.5 bg-success/20 text-success rounded text-xs font-medium hover:bg-success/30 transition-colors",children:"Accept"}),(0,n.jsx)("button",{onClick:async()=>{(await c.xv.declineInvite(e.id)).success&&d(t=>t.filter(t=>t.id!==e.id))},className:"px-3 py-1.5 bg-bg-hover text-text-muted rounded text-xs font-medium hover:text-text-primary transition-colors",children:"Decline"})]})]},e.id))})]}),(0,n.jsxs)("div",{className:"mt-8 p-4 bg-bg-tertiary/50 rounded-lg",children:[(0,n.jsx)("h4",{className:"text-xs font-semibold text-text-muted uppercase tracking-wide mb-3",children:"Role Permissions"}),(0,n.jsx)("div",{className:"space-y-2",children:Object.entries(rm).map(e=>{let[t,r]=e;return(0,n.jsxs)("div",{className:"flex items-start gap-2",children:[(0,n.jsx)("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium ".concat(rx[t]," shrink-0"),children:t.charAt(0).toUpperCase()+t.slice(1)}),(0,n.jsx)("p",{className:"text-xs text-text-muted",children:r})]},t)})})]})]})}function rp(){return(0,n.jsx)("svg",{className:"animate-spin h-5 w-5 text-accent-cyan",viewBox:"0 0 24 24",children:(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function rg(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,n.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function rf(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.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"})]})}let rb={free:"bg-bg-tertiary border-border-subtle text-text-muted",pro:"bg-accent-cyan/10 border-accent-cyan/30 text-accent-cyan",team:"bg-blue-900/30 border-blue-500/40 text-blue-400",enterprise:"bg-amber-400/10 border-amber-400/30 text-amber-400"},rv={free:"Free tier - upgrade to unlock more features",pro:"Professional plan with enhanced features",team:"Team plan with collaboration features",enterprise:"Enterprise plan with dedicated support"},ry={free:0,pro:1,team:2,enterprise:3};function rj(e){let{onUpgrade:t}=e,[r,a]=(0,s.useState)([]),[l,o]=(0,s.useState)("free"),[i,d]=(0,s.useState)(null),[u,x]=(0,s.useState)([]),[m,h]=(0,s.useState)(!0),[p,g]=(0,s.useState)(null),[f,b]=(0,s.useState)(null),[v,y]=(0,s.useState)("month"),[j,w]=(0,s.useState)(null),[N,k]=(0,s.useState)(!1),[C,S]=(0,s.useState)(!1),[L,M]=(0,s.useState)(!1);(0,s.useEffect)(()=>{!async function(){h(!0),g(null);let[e,t,r]=await Promise.all([c.xv.getBillingPlans(),c.xv.getSubscription(),c.xv.getInvoices()]);if(e.success&&a(e.data.plans),t.success){var n;o(t.data.tier),d(t.data.subscription),(null===(n=t.data.subscription)||void 0===n?void 0:n.interval)&&y(t.data.subscription.interval)}r.success&&x(r.data.invoices),e.success||g(e.error),h(!1)}()},[]);let D=(0,s.useCallback)(async e=>{w(e);let t=await c.xv.createCheckoutSession(e,v);t.success&&t.data.checkoutUrl?window.location.href=t.data.checkoutUrl:t.success||(g(t.error),w(null))},[v]),A=(0,s.useCallback)(async()=>{k(!0);let e=await c.xv.createBillingPortal();e.success&&e.data.portalUrl?window.location.href=e.data.portalUrl:e.success||g(e.error),k(!1)},[]),E=(0,s.useCallback)(async()=>{if(!window.confirm("Are you sure you want to cancel your subscription? You will retain access until the end of your billing period."))return;S(!0);let e=await c.xv.cancelSubscription();e.success?(d(e=>e?{...e,cancelAtPeriodEnd:!0}:null),b(e.data.message),setTimeout(()=>b(null),5e3)):g(e.error),S(!1)},[]),T=(0,s.useCallback)(async()=>{M(!0);let e=await c.xv.resumeSubscription();e.success?(d(e=>e?{...e,cancelAtPeriodEnd:!1}:null),b(e.data.message),setTimeout(()=>b(null),3e3)):g(e.error),M(!1)},[]);return m?(0,n.jsxs)("div",{className:"flex items-center justify-center h-64",children:[(0,n.jsx)(rw,{}),(0,n.jsx)("span",{className:"ml-3 text-text-muted",children:"Loading billing information..."})]}):(0,n.jsxs)("div",{className:"space-y-8",children:[p&&(0,n.jsxs)("div",{className:"p-3 bg-error/10 border border-error/30 rounded-lg text-error text-sm",children:[p,(0,n.jsx)("button",{onClick:()=>g(null),className:"ml-2 text-error/70 hover:text-error",children:"\xd7"})]}),f&&(0,n.jsx)("div",{className:"p-3 bg-success/10 border border-success/30 rounded-lg text-success text-sm",children:f}),(0,n.jsxs)("div",{children:[(0,n.jsx)("h3",{className:"text-sm font-semibold text-text-muted uppercase tracking-wide mb-4",children:"Current Plan"}),(0,n.jsx)("div",{className:"p-4 md:p-6 rounded-lg border-2 ".concat(rb[l]),children:(0,n.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[(0,n.jsxs)("div",{children:[(0,n.jsxs)("h4",{className:"text-lg md:text-xl font-bold text-text-primary capitalize",children:[l," Plan"]}),i?(0,n.jsx)("p",{className:"text-xs md:text-sm text-text-secondary mt-1",children:i.cancelAtPeriodEnd?(0,n.jsxs)("span",{className:"text-amber-400",children:["Cancels on ",new Date(i.currentPeriodEnd).toLocaleDateString()]}):(0,n.jsxs)(n.Fragment,{children:["Renews on ",new Date(i.currentPeriodEnd).toLocaleDateString(),(0,n.jsxs)("span",{className:"text-text-muted ml-2",children:["(","year"===i.interval?"Yearly":"Monthly",")"]})]})}):(0,n.jsx)("p",{className:"text-xs md:text-sm text-text-muted mt-1",children:rv[l]||rv.free})]}),(0,n.jsxs)("div",{className:"flex flex-wrap gap-2",children:[i&&!i.cancelAtPeriodEnd&&(0,n.jsx)("button",{onClick:E,disabled:C,className:"px-3 md:px-4 py-2 bg-bg-hover text-text-secondary rounded-lg text-xs md:text-sm font-medium hover:text-text-primary disabled:opacity-50 transition-colors",children:C?"Canceling...":"Cancel Plan"}),(null==i?void 0:i.cancelAtPeriodEnd)&&(0,n.jsx)("button",{onClick:T,disabled:L,className:"px-3 md:px-4 py-2 bg-success/20 text-success rounded-lg text-xs md:text-sm font-medium hover:bg-success/30 disabled:opacity-50 transition-colors",children:L?"Resuming...":"Resume Plan"}),i&&(0,n.jsx)("button",{onClick:A,disabled:N,className:"px-3 md:px-4 py-2 bg-accent-cyan text-bg-deep rounded-lg text-xs md:text-sm font-medium hover:bg-accent-cyan/90 disabled:opacity-50 transition-colors",children:N?"Opening...":"Manage Billing"})]})]})})]}),(0,n.jsxs)("div",{className:"flex items-center justify-center gap-4",children:[(0,n.jsx)("span",{className:"text-sm font-medium ".concat("month"===v?"text-text-primary":"text-text-muted"),children:"Monthly"}),(0,n.jsx)("button",{onClick:()=>y(e=>"month"===e?"year":"month"),className:"relative w-14 h-7 bg-bg-tertiary rounded-full transition-colors",children:(0,n.jsx)("span",{className:"absolute top-1 w-5 h-5 bg-accent-cyan rounded-full transition-transform ".concat("year"===v?"translate-x-8":"translate-x-1")})}),(0,n.jsxs)("span",{className:"text-sm font-medium ".concat("year"===v?"text-text-primary":"text-text-muted"),children:["Yearly",(0,n.jsx)("span",{className:"ml-1 text-xs text-success",children:"(Save 20%)"})]})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("h3",{className:"text-sm font-semibold text-text-muted uppercase tracking-wide mb-4",children:"Available Plans"}),(0,n.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4",children:r.filter(e=>"free"!==e.tier).map(e=>{let t=(ry[e.tier]||0)>(ry[l]||0),r=e.recommended&&t,s=(ry[e.tier]||0)<(ry[l]||0);return(0,n.jsxs)("div",{className:"relative p-6 rounded-lg border ".concat(r?"border-accent-cyan shadow-glow-cyan":"border-border-subtle"," bg-bg-tertiary"),children:[r&&(0,n.jsx)("div",{className:"absolute -top-3 left-1/2 -translate-x-1/2 px-3 py-1 bg-accent-cyan text-bg-deep text-xs font-bold rounded-full",children:"Most Popular"}),(0,n.jsx)("h4",{className:"text-lg font-bold text-text-primary",children:e.name}),(0,n.jsx)("p",{className:"text-xs text-text-muted mt-1 mb-4",children:e.description}),(0,n.jsxs)("div",{className:"mb-4",children:[(0,n.jsxs)("span",{className:"text-3xl font-bold text-text-primary",children:["$","year"===v?e.price.yearly:e.price.monthly]}),(0,n.jsxs)("span",{className:"text-text-muted",children:["/","year"===v?"year":"month"]})]}),(0,n.jsx)("ul",{className:"space-y-2 mb-6",children:e.features.slice(0,5).map((e,t)=>(0,n.jsxs)("li",{className:"flex items-start gap-2 text-sm text-text-secondary",children:[(0,n.jsx)(rN,{className:"text-success shrink-0 mt-0.5"}),e]},t))}),l===e.tier?(0,n.jsx)("button",{disabled:!0,className:"w-full py-2.5 bg-bg-hover text-text-muted rounded-lg text-sm font-medium cursor-default",children:"Current Plan"}):(0,n.jsx)("button",{onClick:()=>D(e.tier),disabled:null!==j,className:"w-full py-2.5 rounded-lg text-sm font-medium transition-colors disabled:opacity-50 ".concat(r?"bg-accent-cyan text-bg-deep hover:bg-accent-cyan/90":"bg-bg-hover text-text-primary hover:bg-bg-active"),children:j===e.tier?"Loading...":s?"Downgrade":"Upgrade"})]},e.tier)})})]}),(0,n.jsx)("div",{className:"p-4 md:p-6 bg-gradient-to-r from-amber-400/10 to-accent-purple/10 border border-amber-400/20 rounded-lg",children:(0,n.jsxs)("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("h4",{className:"text-base md:text-lg font-bold text-text-primary",children:"Enterprise"}),(0,n.jsx)("p",{className:"text-xs md:text-sm text-text-secondary mt-1",children:"Custom solutions for large teams with dedicated support, SLA, and custom integrations."})]}),(0,n.jsx)("a",{href:"mailto:enterprise@agent-relay.com",className:"px-4 md:px-6 py-2 md:py-2.5 bg-amber-400 text-bg-deep rounded-lg text-xs md:text-sm font-bold hover:bg-amber-300 transition-colors text-center shrink-0",children:"Contact Sales"})]})}),u.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("h3",{className:"text-sm font-semibold text-text-muted uppercase tracking-wide mb-4",children:"Billing History"}),(0,n.jsx)("div",{className:"hidden md:block bg-bg-tertiary rounded-lg overflow-hidden",children:(0,n.jsxs)("table",{className:"w-full",children:[(0,n.jsx)("thead",{children:(0,n.jsxs)("tr",{className:"border-b border-border-subtle",children:[(0,n.jsx)("th",{className:"text-left px-4 py-3 text-xs font-semibold text-text-muted uppercase",children:"Invoice"}),(0,n.jsx)("th",{className:"text-left px-4 py-3 text-xs font-semibold text-text-muted uppercase",children:"Date"}),(0,n.jsx)("th",{className:"text-left px-4 py-3 text-xs font-semibold text-text-muted uppercase",children:"Amount"}),(0,n.jsx)("th",{className:"text-left px-4 py-3 text-xs font-semibold text-text-muted uppercase",children:"Status"}),(0,n.jsx)("th",{className:"text-right px-4 py-3 text-xs font-semibold text-text-muted uppercase"})]})}),(0,n.jsx)("tbody",{children:u.map(e=>(0,n.jsxs)("tr",{className:"border-b border-border-subtle last:border-0",children:[(0,n.jsx)("td",{className:"px-4 py-3 text-sm text-text-primary font-medium",children:e.number}),(0,n.jsx)("td",{className:"px-4 py-3 text-sm text-text-secondary",children:new Date(e.date).toLocaleDateString()}),(0,n.jsxs)("td",{className:"px-4 py-3 text-sm text-text-primary",children:["$",(e.amount/100).toFixed(2)]}),(0,n.jsx)("td",{className:"px-4 py-3",children:(0,n.jsx)("span",{className:"text-xs px-2 py-1 rounded-full ".concat("paid"===e.status?"bg-success/20 text-success":"open"===e.status?"bg-amber-400/20 text-amber-400":"bg-error/20 text-error"),children:e.status})}),(0,n.jsx)("td",{className:"px-4 py-3 text-right",children:e.pdfUrl&&(0,n.jsx)("a",{href:e.pdfUrl,target:"_blank",rel:"noopener noreferrer",className:"text-xs text-accent-cyan hover:underline",children:"Download"})})]},e.id))})]})}),(0,n.jsx)("div",{className:"md:hidden space-y-3",children:u.map(e=>(0,n.jsxs)("div",{className:"bg-bg-tertiary rounded-lg p-4",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-text-primary",children:e.number}),(0,n.jsx)("span",{className:"text-xs px-2 py-1 rounded-full ".concat("paid"===e.status?"bg-success/20 text-success":"open"===e.status?"bg-amber-400/20 text-amber-400":"bg-error/20 text-error"),children:e.status})]}),(0,n.jsxs)("div",{className:"flex items-center justify-between text-xs",children:[(0,n.jsx)("span",{className:"text-text-muted",children:new Date(e.date).toLocaleDateString()}),(0,n.jsxs)("span",{className:"text-text-primary font-medium",children:["$",(e.amount/100).toFixed(2)]})]}),e.pdfUrl&&(0,n.jsx)("a",{href:e.pdfUrl,target:"_blank",rel:"noopener noreferrer",className:"mt-3 block text-center text-xs text-accent-cyan py-2 border border-accent-cyan/30 rounded-lg hover:bg-accent-cyan/10 transition-colors",children:"Download PDF"})]},e.id))})]})]})}function rw(){return(0,n.jsx)("svg",{className:"animate-spin h-5 w-5 text-accent-cyan",viewBox:"0 0 24 24",children:(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function rN(e){let{className:t=""}=e;return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})})}function rk(e){var t,r,a,l,o,i,d,u,x,m,h,p,g,f,b,v;let{currentUserId:y,initialTab:j="dashboard",onClose:w,settings:N,onUpdateSettings:k,activeWorkspaceId:C,onReposChanged:S}=e,[L,M]=(0,s.useState)(j),[D,A]=(0,s.useState)([]),[E,T]=(0,s.useState)(null!=C?C:null),[W,P]=(0,s.useState)(!0);(0,s.useEffect)(()=>{C&&T(C)},[C]),(0,s.useEffect)(()=>{(async function(){P(!0);let e=await c.xv.getWorkspaceSummary();e.success&&e.data.workspaces.length>0&&(A(e.data.workspaces),E||T(e.data.workspaces[0].id)),P(!1)})()},[E]);let R=(0,s.useCallback)(e=>{k(e)},[k]),I=(0,s.useCallback)(e=>{R(t=>{let r={...t.notifications,...e};return{...t,notifications:{...r,enabled:r.sound||r.desktop||r.mentionsOnly}}})},[R]),B=[{id:"dashboard",label:"Dashboard",icon:(0,n.jsx)(rE,{})},{id:"workspace",label:"Workspace",icon:(0,n.jsx)(rT,{})},{id:"team",label:"Team",icon:(0,n.jsx)(rW,{})},{id:"billing",label:"Billing",icon:(0,n.jsx)(rP,{})}];return(0,n.jsxs)("div",{className:"fixed inset-0 z-[1100] bg-bg-deep",children:[(0,n.jsxs)("div",{className:"absolute inset-0 opacity-30",children:[(0,n.jsx)("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_top_right,_rgba(0,217,255,0.08)_0%,_transparent_50%)]"}),(0,n.jsx)("div",{className:"absolute inset-0 bg-[radial-gradient(ellipse_at_bottom_left,_rgba(168,85,247,0.06)_0%,_transparent_50%)]"})]}),(0,n.jsxs)("div",{className:"relative h-full flex flex-col",children:[(0,n.jsxs)("header",{className:"h-14 md:h-16 px-4 md:px-6 flex items-center justify-between border-b border-border-subtle bg-bg-secondary/80 backdrop-blur-sm",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3 md:gap-4",children:[(0,n.jsx)("div",{className:"w-8 h-8 md:w-10 md:h-10 rounded-xl bg-gradient-to-br from-accent-cyan to-accent-purple flex items-center justify-center shadow-lg shadow-accent-cyan/20",children:(0,n.jsx)(rA,{className:"text-white w-4 h-4 md:w-[18px] md:h-[18px]"})}),(0,n.jsxs)("div",{children:[(0,n.jsx)("h1",{className:"text-base md:text-lg font-bold text-text-primary tracking-tight",children:"Settings"}),(0,n.jsx)("p",{className:"text-[10px] md:text-xs text-text-muted hidden sm:block",children:"Manage your workspace and preferences"})]})]}),(0,n.jsx)("button",{onClick:w,className:"w-9 h-9 md:w-10 md:h-10 rounded-lg bg-bg-tertiary border border-border-subtle flex items-center justify-center text-text-muted hover:text-text-primary hover:bg-bg-hover transition-colors",children:(0,n.jsx)(rR,{})})]}),(0,n.jsx)("div",{className:"border-b border-border-subtle bg-bg-secondary/50",children:(0,n.jsx)("div",{className:"flex sm:justify-center overflow-x-auto scrollbar-hide scroll-smooth snap-x snap-mandatory touch-pan-x",style:{WebkitOverflowScrolling:"touch"},children:B.map(e=>(0,n.jsxs)("button",{onClick:()=>M(e.id),className:"flex items-center gap-2 px-4 sm:px-6 py-3 text-sm font-medium transition-all whitespace-nowrap shrink-0 snap-start ".concat(L===e.id?"text-accent-cyan border-b-2 border-accent-cyan bg-accent-cyan/5":"text-text-muted border-b-2 border-transparent hover:text-text-secondary"),children:[(0,n.jsx)("span",{className:L===e.id?"text-accent-cyan":"text-text-muted",children:e.icon}),e.label]},e.id))})}),("workspace"===L||"team"===L)&&D.length>0&&(0,n.jsx)("div",{className:"px-4 py-2 border-b border-border-subtle bg-bg-tertiary/50",children:(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("div",{className:"w-2 h-2 rounded-full shrink-0 ".concat((null===(t=D.find(e=>e.id===E))||void 0===t?void 0:t.status)==="running"?"bg-success":(null===(r=D.find(e=>e.id===E))||void 0===r?void 0:r.status)==="stopped"?"bg-amber-400":"bg-text-muted")}),1===D.length?(0,n.jsx)("span",{className:"text-sm text-text-primary",children:D[0].name}):(0,n.jsx)("select",{value:E||"",onChange:e=>T(e.target.value),className:"flex-1 px-3 py-2 bg-bg-card border border-border-subtle rounded-lg text-sm text-text-primary focus:outline-none focus:border-accent-cyan",children:D.map(e=>(0,n.jsx)("option",{value:e.id,children:e.name},e.id))})]})}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden",children:(0,n.jsx)("main",{className:"h-full w-full overflow-y-auto",children:(0,n.jsxs)("div",{className:"w-full max-w-4xl mx-auto p-4 md:p-8",children:["dashboard"===L&&(0,n.jsxs)("div",{className:"space-y-8",children:[(0,n.jsx)(rC,{title:"Dashboard Settings",subtitle:"Customize your dashboard experience"}),(0,n.jsxs)(rS,{title:"Appearance",icon:(0,n.jsx)(rI,{}),children:[(0,n.jsx)(rL,{label:"Theme",description:"Choose your preferred color scheme",children:(0,n.jsxs)("select",{value:N.theme,onChange:e=>R(t=>({...t,theme:e.target.value})),className:"px-4 py-2 bg-bg-tertiary border border-border-subtle rounded-lg text-sm text-text-primary focus:outline-none focus:border-accent-cyan",children:[(0,n.jsx)("option",{value:"dark",children:"Dark"}),(0,n.jsx)("option",{value:"light",children:"Light"}),(0,n.jsx)("option",{value:"system",children:"System"})]})}),(0,n.jsx)(rL,{label:"Compact Mode",description:"Reduce spacing and show more content",children:(0,n.jsx)(rM,{checked:N.display.compactMode,onChange:e=>R(t=>({...t,display:{...t.display,compactMode:e}}))})}),(0,n.jsx)(rL,{label:"Show Timestamps",description:"Display timestamps on messages",children:(0,n.jsx)(rM,{checked:N.display.showTimestamps,onChange:e=>R(t=>({...t,display:{...t.display,showTimestamps:e}}))})})]}),(0,n.jsxs)(rS,{title:"Notifications",icon:(0,n.jsx)(rB,{}),children:[(0,n.jsx)(rL,{label:"Sound Effects",description:"Play sounds for new messages",children:(0,n.jsx)(rM,{checked:N.notifications.sound,onChange:e=>I({sound:e})})}),(0,n.jsx)(rL,{label:"Browser Notifications",description:"Show desktop notifications",children:(0,n.jsx)(rM,{checked:N.notifications.desktop,onChange:e=>I({desktop:e})})})]}),(0,n.jsx)(rS,{title:"Behavior",icon:(0,n.jsx)(rA,{}),children:(0,n.jsx)(rL,{label:"Auto-scroll Messages",description:"Automatically scroll to new messages",children:(0,n.jsx)(rM,{checked:N.messages.autoScroll,onChange:e=>R(t=>({...t,messages:{...t.messages,autoScroll:e}}))})})}),(0,n.jsxs)(rS,{title:"Agent Defaults",icon:(0,n.jsx)(rF,{}),children:[(0,n.jsx)(rL,{label:"Default Agent Type",description:"Pre-select an agent type when spawning",children:(0,n.jsxs)("select",{value:null!==(p=null===(a=N.agentDefaults)||void 0===a?void 0:a.defaultCliType)&&void 0!==p?p:"",onChange:e=>R(t=>({...t,agentDefaults:{...t.agentDefaults,defaultCliType:""===e.target.value?null:e.target.value}})),className:"px-4 py-2 bg-bg-tertiary border border-border-subtle rounded-lg text-sm text-text-primary focus:outline-none focus:border-accent-cyan",children:[(0,n.jsx)("option",{value:"",children:"None (show all templates)"}),(0,n.jsx)("option",{value:"claude",children:"Claude"}),(0,n.jsx)("option",{value:"codex",children:"Codex"}),(0,n.jsx)("option",{value:"gemini",children:"Gemini"}),(0,n.jsx)("option",{value:"cursor",children:"Cursor"}),(0,n.jsx)("option",{value:"custom",children:"Custom"})]})}),(0,n.jsx)(rL,{label:"Default Claude Model",description:"Default model when spawning Claude agents",children:(0,n.jsx)("select",{value:null!==(g=null===(o=N.agentDefaults)||void 0===o?void 0:null===(l=o.defaultModels)||void 0===l?void 0:l.claude)&&void 0!==g?g:"sonnet",onChange:e=>R(t=>{var r;return{...t,agentDefaults:{...t.agentDefaults,defaultModels:{...null===(r=t.agentDefaults)||void 0===r?void 0:r.defaultModels,claude:e.target.value}}}}),className:"px-4 py-2 bg-bg-tertiary border border-border-subtle rounded-lg text-sm text-text-primary focus:outline-none focus:border-accent-cyan",children:tC.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))})}),(0,n.jsx)(rL,{label:"Default Cursor Model",description:"Default model when spawning Cursor agents",children:(0,n.jsx)("select",{value:null!==(f=null===(d=N.agentDefaults)||void 0===d?void 0:null===(i=d.defaultModels)||void 0===i?void 0:i.cursor)&&void 0!==f?f:"opus-4.5-thinking",onChange:e=>R(t=>{var r;return{...t,agentDefaults:{...t.agentDefaults,defaultModels:{...null===(r=t.agentDefaults)||void 0===r?void 0:r.defaultModels,cursor:e.target.value}}}}),className:"px-4 py-2 bg-bg-tertiary border border-border-subtle rounded-lg text-sm text-text-primary focus:outline-none focus:border-accent-cyan",children:tS.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))})}),(0,n.jsx)(rL,{label:"Default Codex Model",description:"Default model when spawning Codex agents",children:(0,n.jsx)("select",{value:null!==(b=null===(x=N.agentDefaults)||void 0===x?void 0:null===(u=x.defaultModels)||void 0===u?void 0:u.codex)&&void 0!==b?b:"gpt-5.2-codex",onChange:e=>R(t=>{var r;return{...t,agentDefaults:{...t.agentDefaults,defaultModels:{...null===(r=t.agentDefaults)||void 0===r?void 0:r.defaultModels,codex:e.target.value}}}}),className:"px-4 py-2 bg-bg-tertiary border border-border-subtle rounded-lg text-sm text-text-primary focus:outline-none focus:border-accent-cyan",children:tL.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))})}),(0,n.jsx)(rL,{label:"Default Gemini Model",description:"Default model when spawning Gemini agents",children:(0,n.jsx)("select",{value:null!==(v=null===(h=N.agentDefaults)||void 0===h?void 0:null===(m=h.defaultModels)||void 0===m?void 0:m.gemini)&&void 0!==v?v:"gemini-2.5-pro",onChange:e=>R(t=>{var r;return{...t,agentDefaults:{...t.agentDefaults,defaultModels:{...null===(r=t.agentDefaults)||void 0===r?void 0:r.defaultModels,gemini:e.target.value}}}}),className:"px-4 py-2 bg-bg-tertiary border border-border-subtle rounded-lg text-sm text-text-primary focus:outline-none focus:border-accent-cyan",children:tM.map(e=>(0,n.jsx)("option",{value:e.value,children:e.label},e.value))})})]})]}),"workspace"===L&&(0,n.jsx)(n.Fragment,{children:W?(0,n.jsxs)("div",{className:"flex items-center justify-center h-64",children:[(0,n.jsx)("div",{className:"relative",children:(0,n.jsx)("div",{className:"w-12 h-12 rounded-full border-2 border-accent-cyan/20 border-t-accent-cyan animate-spin"})}),(0,n.jsx)("span",{className:"ml-4 text-text-muted",children:"Loading workspaces..."})]}):E?(0,n.jsx)(t2,{workspaceId:E,csrfToken:(0,c._V)()||void 0,onClose:w,onReposChanged:S}):(0,n.jsx)(rD,{icon:(0,n.jsx)(rT,{}),title:"No Workspace",description:"Create a workspace to get started with Agent Relay.",action:(0,n.jsx)("button",{className:"px-6 py-3 bg-accent-cyan text-bg-deep font-semibold rounded-lg hover:bg-accent-cyan/90 transition-colors",children:"Create Workspace"})})}),"team"===L&&(0,n.jsx)(n.Fragment,{children:E?(0,n.jsxs)("div",{className:"space-y-8",children:[(0,n.jsx)(rC,{title:"Team Settings",subtitle:"Manage workspace members and permissions"}),(0,n.jsx)(rh,{workspaceId:E,currentUserId:y})]}):(0,n.jsx)(rD,{icon:(0,n.jsx)(rW,{}),title:"No Workspace Selected",description:"Select a workspace to manage team members."})}),"billing"===L&&(0,n.jsxs)("div",{className:"space-y-8",children:[(0,n.jsx)(rC,{title:"Billing & Subscription",subtitle:"Manage your plan and payment methods"}),(0,n.jsx)(rj,{})]})]})})})]})]})}function rC(e){let{title:t,subtitle:r}=e;return(0,n.jsxs)("div",{className:"mb-6 sm:mb-8",children:[(0,n.jsx)("h2",{className:"text-xl sm:text-2xl font-bold text-text-primary",children:t}),(0,n.jsx)("p",{className:"text-sm text-text-muted mt-1",children:r})]})}function rS(e){let{title:t,icon:r,children:s}=e;return(0,n.jsxs)("div",{className:"bg-bg-tertiary rounded-xl border border-border-subtle overflow-hidden",children:[(0,n.jsxs)("div",{className:"px-4 sm:px-6 py-3 sm:py-4 border-b border-border-subtle bg-bg-secondary/50 flex items-center gap-3",children:[(0,n.jsx)("span",{className:"text-accent-cyan",children:r}),(0,n.jsx)("h3",{className:"text-sm font-semibold text-text-primary uppercase tracking-wide",children:t})]}),(0,n.jsx)("div",{className:"divide-y divide-border-subtle",children:s})]})}function rL(e){let{label:t,description:r,children:s}=e;return(0,n.jsxs)("div",{className:"px-4 sm:px-6 py-3 sm:py-4 flex items-center justify-between",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("p",{className:"text-sm font-medium text-text-primary",children:t}),(0,n.jsx)("p",{className:"text-xs text-text-muted mt-0.5",children:r})]}),s]})}function rM(e){let{checked:t,onChange:r}=e;return(0,n.jsx)("button",{onClick:()=>r(!t),className:"relative w-12 h-6 rounded-full transition-colors ".concat(t?"bg-accent-cyan":"bg-bg-hover"),children:(0,n.jsx)("span",{className:"absolute top-1 w-4 h-4 bg-white rounded-full shadow transition-transform ".concat(t?"translate-x-7":"translate-x-1")})})}function rD(e){let{icon:t,title:r,description:s,action:a}=e;return(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-64 text-center",children:[(0,n.jsx)("div",{className:"w-16 h-16 rounded-2xl bg-bg-tertiary flex items-center justify-center text-text-muted mb-4",children:t}),(0,n.jsx)("h3",{className:"text-lg font-semibold text-text-primary mb-2",children:r}),(0,n.jsx)("p",{className:"text-sm text-text-muted max-w-sm mb-6",children:s}),a]})}function rA(e){let{className:t=""}=e;return(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,n.jsx)("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"})]})}function rE(){return(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"7",height:"9"}),(0,n.jsx)("rect",{x:"14",y:"3",width:"7",height:"5"}),(0,n.jsx)("rect",{x:"14",y:"12",width:"7",height:"9"}),(0,n.jsx)("rect",{x:"3",y:"16",width:"7",height:"5"})]})}function rT(){return(0,n.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,n.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"})})}function rW(){return(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),(0,n.jsx)("circle",{cx:"9",cy:"7",r:"4"}),(0,n.jsx)("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),(0,n.jsx)("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]})}function rP(){return(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"1",y:"4",width:"22",height:"16",rx:"2",ry:"2"}),(0,n.jsx)("line",{x1:"1",y1:"10",x2:"23",y2:"10"})]})}function rR(){return(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function rI(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("circle",{cx:"13.5",cy:"6.5",r:"2.5"}),(0,n.jsx)("circle",{cx:"19",cy:"13.5",r:"2.5"}),(0,n.jsx)("circle",{cx:"6",cy:"12",r:"2.5"}),(0,n.jsx)("circle",{cx:"11",cy:"19",r:"2.5"}),(0,n.jsx)("path",{d:"M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10c.926 0 1.648-.746 1.648-1.688 0-.437-.18-.835-.437-1.125-.29-.289-.438-.652-.438-1.125a1.64 1.64 0 0 1 1.668-1.668h1.996c3.051 0 5.555-2.503 5.555-5.555C21.965 6.012 17.461 2 12 2z"})]})}function rB(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9"}),(0,n.jsx)("path",{d:"M13.73 21a2 2 0 0 1-3.46 0"})]})}function rF(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("path",{d:"M4.5 16.5c-1.5 1.26-2 5-2 5s3.74-.5 5-2c.71-.84.7-2.13-.09-2.91a2.18 2.18 0 0 0-2.91-.09z"}),(0,n.jsx)("path",{d:"m12 15-3-3a22 22 0 0 1 2-3.95A12.88 12.88 0 0 1 22 2c0 2.72-.78 7.5-6 11a22.35 22.35 0 0 1-4 2z"}),(0,n.jsx)("path",{d:"M9 12H4s.55-3.03 2-4c1.62-1.08 5 0 5 0"}),(0,n.jsx)("path",{d:"M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5"})]})}let rU={theme:"system",notifications:{enabled:!0,sound:!0,desktop:!1,mentionsOnly:!1},display:{compactMode:!1,showTimestamps:!0,showAvatars:!0,animationsEnabled:!0},messages:{autoScroll:!0},connection:{autoReconnect:!0,reconnectDelay:3e3,keepAliveInterval:3e4},agentDefaults:{defaultCliType:null,defaultModels:{claude:"sonnet",cursor:"opus-4.5-thinking",codex:"gpt-5.2-codex",gemini:"gemini-2.5-pro"}}};var r_=r(5118);function rO(e){let{isOpen:t,onClose:r}=e,[a,l]=(0,s.useState)("conversations"),[o,i]=(0,s.useState)([]),[c,d]=(0,s.useState)([]),[u,x]=(0,s.useState)([]),[m,h]=(0,s.useState)(null),[p,g]=(0,s.useState)(!1),[f,b]=(0,s.useState)(null),[v,y]=(0,s.useState)(""),[j,w]=(0,s.useState)(""),[N,k]=(0,s.useState)(null);(0,s.useEffect)(()=>{t&&(async()=>{let e=await r_.hi.getHistoryStats();e.success&&e.data&&h(e.data)})()},[t]),(0,s.useEffect)(()=>{t&&(async()=>{g(!0),b(null);try{if("conversations"===a){let e=await r_.hi.getHistoryConversations();e.success&&e.data?i(e.data.conversations):b(e.error||"Failed to fetch conversations")}else if("sessions"===a){let e=await r_.hi.getHistorySessions({agent:j||void 0,limit:50});e.success&&e.data?d(e.data.sessions):b(e.error||"Failed to fetch sessions")}else if("messages"===a){let r={limit:100,order:"desc"};if(v&&(r.search=v),N){let[n,s]=N.participants,a=await r_.hi.getHistoryMessages({...r,from:n,to:s}),l=await r_.hi.getHistoryMessages({...r,from:s,to:n});if(a.success&&l.success){var e,t;let r=[...(null===(e=a.data)||void 0===e?void 0:e.messages)||[],...(null===(t=l.data)||void 0===t?void 0:t.messages)||[]].sort((e,t)=>new Date(t.timestamp).getTime()-new Date(e.timestamp).getTime());x(r)}}else{let e=await r_.hi.getHistoryMessages(r);e.success&&e.data?x(e.data.messages):b(e.error||"Failed to fetch messages")}}}catch(e){b("Failed to load data")}finally{g(!1)}})()},[t,a,j,v,N]);let C=(0,s.useCallback)(e=>{k(e),l("messages")},[]),S=(0,s.useCallback)(()=>{k(null),l("conversations")},[]);return t?(0,n.jsx)("div",{className:"fixed inset-0 z-[1000] flex items-center justify-center bg-black/50",children:(0,n.jsxs)("div",{className:"bg-bg-primary rounded-lg shadow-xl w-[90vw] max-w-4xl h-[80vh] flex flex-col",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between p-4 border-b border-border",children:[(0,n.jsxs)("div",{className:"flex items-center gap-4",children:[(0,n.jsx)("h2",{className:"text-lg font-semibold text-text-primary",children:"Conversation History"}),m&&"number"==typeof m.messageCount&&(0,n.jsxs)("div",{className:"flex gap-4 text-sm text-text-muted",children:[(0,n.jsxs)("span",{children:[m.messageCount," messages"]}),(0,n.jsxs)("span",{children:[m.sessionCount," sessions"]}),(0,n.jsxs)("span",{children:[m.uniqueAgents," agents"]})]})]}),(0,n.jsx)("button",{onClick:r,className:"p-2 text-text-muted hover:text-text-primary rounded transition-colors","aria-label":"Close",children:(0,n.jsx)(rq,{})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-4 p-4 border-b border-border",children:[(0,n.jsxs)("div",{className:"flex gap-1 bg-bg-secondary rounded-md p-1",children:[(0,n.jsx)(rH,{active:"conversations"===a,onClick:()=>{k(null),l("conversations")},children:"Conversations"}),(0,n.jsx)(rH,{active:"sessions"===a,onClick:()=>l("sessions"),children:"Sessions"}),(0,n.jsx)(rH,{active:"messages"===a,onClick:()=>l("messages"),children:"Messages"})]}),"messages"===a&&(0,n.jsx)("div",{className:"flex-1 max-w-xs",children:(0,n.jsx)("input",{type:"text",placeholder:"Search messages...",value:v,onChange:e=>y(e.target.value),className:"w-full px-3 py-2 bg-bg-secondary border border-border rounded-md text-sm text-text-primary placeholder:text-text-muted focus:outline-none focus:border-accent"})}),"sessions"===a&&(0,n.jsx)("div",{className:"flex-1 max-w-xs",children:(0,n.jsx)("input",{type:"text",placeholder:"Filter by agent...",value:j,onChange:e=>w(e.target.value),className:"w-full px-3 py-2 bg-bg-secondary border border-border rounded-md text-sm text-text-primary placeholder:text-text-muted focus:outline-none focus:border-accent"})}),N&&(0,n.jsxs)("button",{onClick:S,className:"flex items-center gap-1 px-3 py-2 text-sm text-text-muted hover:text-text-primary",children:[(0,n.jsx)(rJ,{})," Back to conversations"]})]}),(0,n.jsx)("div",{className:"flex-1 overflow-y-auto p-4",children:p?(0,n.jsx)("div",{className:"flex items-center justify-center h-full",children:(0,n.jsx)(r$,{})}):f?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-error",children:f}):"conversations"===a?(0,n.jsx)(rz,{conversations:o,onConversationClick:C}):"sessions"===a?(0,n.jsx)(rG,{sessions:c}):(0,n.jsx)(rK,{messages:u,conversationTitle:N?"".concat(N.participants[0]," & ").concat(N.participants[1]):void 0})})]})}):null}function rH(e){let{active:t,onClick:r,children:s}=e;return(0,n.jsx)("button",{onClick:r,className:"px-3 py-1.5 text-sm rounded transition-colors ".concat(t?"bg-accent text-white":"text-text-muted hover:text-text-primary hover:bg-bg-primary"),children:s})}function rz(e){let{conversations:t,onConversationClick:r}=e;return 0===t.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-text-muted",children:"No conversations found"}):(0,n.jsx)("div",{className:"space-y-2",children:t.map((e,t)=>(0,n.jsxs)("div",{onClick:()=>r(e),className:"p-4 bg-bg-secondary rounded-lg cursor-pointer hover:bg-bg-tertiary transition-colors",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"font-medium text-text-primary",children:e.participants.join(" & ")}),(0,n.jsxs)("span",{className:"text-xs px-2 py-0.5 bg-accent/10 text-accent rounded-full",children:[e.messageCount," messages"]})]}),(0,n.jsx)("span",{className:"text-xs text-text-muted",children:rZ(e.lastTimestamp)})]}),(0,n.jsx)("p",{className:"text-sm text-text-muted truncate",children:e.lastMessage})]},t))})}function rG(e){let{sessions:t}=e;return 0===t.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-text-muted",children:"No sessions found"}):(0,n.jsx)("div",{className:"space-y-2",children:t.map(e=>(0,n.jsxs)("div",{className:"p-4 bg-bg-secondary rounded-lg",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"font-medium text-text-primary",children:e.agentName}),e.cli&&(0,n.jsx)("span",{className:"text-xs px-2 py-0.5 bg-bg-tertiary text-text-muted rounded",children:e.cli}),(0,n.jsx)(rV,{isActive:e.isActive,closedBy:e.closedBy})]}),(0,n.jsx)("span",{className:"text-xs text-text-muted",children:e.duration})]}),(0,n.jsxs)("div",{className:"flex items-center gap-4 text-sm text-text-muted",children:[(0,n.jsx)("span",{children:new Date(e.startedAt).toLocaleString()}),(0,n.jsxs)("span",{children:[e.messageCount," messages"]})]}),e.summary&&(0,n.jsx)("p",{className:"mt-2 text-sm text-text-muted truncate",children:e.summary})]},e.id))})}function rV(e){let{isActive:t,closedBy:r}=e;if(t)return(0,n.jsx)("span",{className:"text-xs px-2 py-0.5 bg-success/10 text-success rounded-full",children:"Active"});let s={agent:"bg-text-muted/10 text-text-muted",disconnect:"bg-warning/10 text-warning",error:"bg-error/10 text-error"},a=r?s[r]:s.agent;return(0,n.jsx)("span",{className:"text-xs px-2 py-0.5 rounded-full ".concat(a),children:r?({agent:"Closed",disconnect:"Disconnected",error:"Error"})[r]:"Ended"})}function rK(e){let{messages:t,conversationTitle:r}=e;return 0===t.length?(0,n.jsx)("div",{className:"flex items-center justify-center h-full text-text-muted",children:"No messages found"}):(0,n.jsxs)("div",{className:"space-y-4",children:[r&&(0,n.jsx)("h3",{className:"text-lg font-medium text-text-primary mb-4",children:r}),t.map(e=>(0,n.jsxs)("div",{className:"p-4 bg-bg-secondary rounded-lg",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-2",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"font-medium text-accent",children:e.from}),(0,n.jsx)("span",{className:"text-text-muted",children:"to"}),(0,n.jsx)("span",{className:"font-medium text-text-primary",children:"*"===e.to?"Everyone":e.to}),e.isBroadcast&&(0,n.jsx)("span",{className:"text-xs px-2 py-0.5 bg-accent/10 text-accent rounded-full",children:"Broadcast"}),e.isUrgent&&(0,n.jsx)("span",{className:"text-xs px-2 py-0.5 bg-error/10 text-error rounded-full",children:"Urgent"})]}),(0,n.jsx)("span",{className:"text-xs text-text-muted",children:rZ(e.timestamp)})]}),(0,n.jsx)("p",{className:"text-sm text-text-primary whitespace-pre-wrap",children:e.content}),e.thread&&(0,n.jsxs)("div",{className:"mt-2 text-xs text-text-muted",children:["Thread: ",e.thread.slice(0,8),"..."]})]},e.id))]})}function rZ(e){let t=new Date(e),r=new Date().getTime()-t.getTime(),n=Math.floor(r/6e4),s=Math.floor(r/36e5),a=Math.floor(r/864e5);return n<1?"just now":n<60?"".concat(n,"m ago"):s<24?"".concat(s,"h ago"):a<7?"".concat(a,"d ago"):t.toLocaleDateString()}function rq(){return(0,n.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function rJ(){return(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.jsx)("polyline",{points:"15 18 9 12 15 6"})})}function r$(){return(0,n.jsx)("svg",{className:"animate-spin text-accent",width:"24",height:"24",viewBox:"0 0 24 24",children:(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function rY(e){let{toasts:t,onDismiss:r,position:s="top-right",maxVisible:a=5}=e,l=t.slice(0,a);return(0,n.jsx)("div",{className:"toast-container toast-".concat(s),children:l.map(e=>(0,n.jsx)(rX,{toast:e,onDismiss:r},e.id))})}function rX(e){let{toast:t,onDismiss:r}=e,[a,l]=(0,s.useState)(!1),o=(0,s.useCallback)(()=>{l(!0),setTimeout(()=>r(t.id),200)},[t.id,r]);(0,s.useEffect)(()=>{if(0===t.duration)return;let e=setTimeout(o,t.duration||5e3);return()=>clearTimeout(e)},[t.duration,o]);let i=t.agentName?(0,x.GW)(t.agentName):null,c=function(e){switch(e){case"success":return r0;case"warning":return r1;case"error":return r2;case"message":return r5;default:return rQ}}(t.type);return(0,n.jsxs)("div",{className:"toast toast-".concat(t.type," ").concat(a?"toast-exit":""),role:"alert",children:[(0,n.jsx)("div",{className:"toast-icon-wrapper",children:t.agentName?(0,n.jsx)("div",{className:"toast-agent-avatar",style:{backgroundColor:null==i?void 0:i.primary,color:null==i?void 0:i.text},children:(0,x.hP)(t.agentName)}):(0,n.jsx)("div",{className:"toast-icon toast-icon-".concat(t.type),children:(0,n.jsx)(c,{})})}),(0,n.jsxs)("div",{className:"toast-content",children:[(0,n.jsxs)("div",{className:"toast-header",children:[(0,n.jsx)("span",{className:"toast-title",children:t.title}),t.agentName&&(0,n.jsxs)("span",{className:"toast-agent",children:["@",t.agentName]})]}),t.message&&(0,n.jsx)("p",{className:"toast-message",children:t.message}),t.action&&(0,n.jsx)("button",{className:"toast-action",onClick:()=>{var e;null===(e=t.action)||void 0===e||e.onClick(),o()},children:t.action.label})]}),(0,n.jsx)("button",{className:"toast-close",onClick:o,"aria-label":"Dismiss",children:(0,n.jsx)(r4,{})}),0!==t.duration&&(0,n.jsx)("div",{className:"toast-progress",style:{animationDuration:"".concat(t.duration||5e3,"ms")}})]})}function rQ(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,n.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}function r0(){return(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})})}function r1(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),(0,n.jsx)("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),(0,n.jsx)("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]})}function r2(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),(0,n.jsx)("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]})}function r5(){return(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.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"})})}function r4(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function r3(e){let{workspaces:t,activeWorkspaceId:r,onSelect:a,onAddWorkspace:l,onWorkspaceSettings:o,isLoading:i=!1}=e,[c,d]=(0,s.useState)(!1),u=(0,s.useRef)(null),x=t.find(e=>e.id===r);return(0,s.useEffect)(()=>{let e=e=>{u.current&&!u.current.contains(e.target)&&d(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&d(!1)};return document.addEventListener("keydown",e),()=>document.removeEventListener("keydown",e)},[]),(0,n.jsxs)("div",{className:"relative w-full",ref:u,children:[(0,n.jsxs)("button",{className:"w-full flex items-center gap-2 px-3 py-2.5 bg-bg-secondary border border-border rounded-lg text-text-primary text-sm cursor-pointer transition-all hover:bg-bg-tertiary hover:border-border-medium disabled:opacity-60 disabled:cursor-not-allowed",onClick:()=>d(!c),disabled:i,children:[i?(0,n.jsx)("span",{className:"flex-1 text-left text-text-muted",children:"Loading..."}):x?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(r6,{provider:x.provider}),(0,n.jsx)("span",{className:"flex-1 text-left font-medium",children:x.name}),x.gitBranch&&(0,n.jsxs)("span",{className:"flex items-center gap-1 text-xs text-text-muted bg-bg-hover px-1.5 py-0.5 rounded",children:[(0,n.jsx)(r7,{}),x.gitBranch]})]}):(0,n.jsx)("span",{className:"flex-1 text-left text-text-muted",children:"Select workspace..."}),(0,n.jsx)(r9,{isOpen:c})]}),c&&(0,n.jsxs)("div",{className:"absolute top-[calc(100%+4px)] left-0 right-0 bg-bg-card border border-border rounded-lg shadow-modal z-[1000] overflow-hidden",children:[(0,n.jsx)("div",{className:"max-h-[300px] overflow-y-auto",children:0===t.length?(0,n.jsxs)("div",{className:"py-6 px-4 text-center text-text-muted text-[13px] leading-relaxed",children:["No workspaces added yet.",(0,n.jsx)("br",{}),"Add a repository to get started."]}):t.map(e=>(0,n.jsxs)("button",{className:"w-full flex items-center gap-2.5 px-3 py-2.5 bg-transparent border-none text-text-primary text-sm cursor-pointer transition-colors text-left hover:bg-bg-hover ".concat(e.id===r?"bg-success-light":""),onClick:()=>{a(e),d(!1)},children:[(0,n.jsx)(r6,{provider:e.provider}),(0,n.jsxs)("div",{className:"flex-1 flex flex-col gap-0.5 min-w-0",children:[(0,n.jsx)("span",{className:"font-medium",children:e.name}),(0,n.jsx)("span",{className:"text-[11px] text-text-muted overflow-hidden text-ellipsis whitespace-nowrap",children:e.path})]}),(0,n.jsx)(r8,{status:e.status})]},e.id))}),(0,n.jsxs)("div",{className:"p-2 border-t border-border space-y-1.5",children:[o&&x&&(0,n.jsxs)("button",{className:"w-full flex items-center justify-center gap-1.5 px-3 py-2 bg-transparent border border-border rounded-md text-text-muted text-[13px] cursor-pointer transition-all hover:bg-bg-hover hover:border-border-medium hover:text-text-primary",onClick:()=>{o(),d(!1)},children:[(0,n.jsx)(nt,{}),"Workspace Settings"]}),(0,n.jsxs)("button",{className:"w-full flex items-center justify-center gap-1.5 px-3 py-2 bg-transparent border border-dashed border-border rounded-md text-text-muted text-[13px] cursor-pointer transition-all hover:bg-bg-hover hover:border-border-medium hover:text-text-primary",onClick:l,children:[(0,n.jsx)(ne,{}),"Add Workspace"]})]})]})]})}function r6(e){let{provider:t}=e,r={claude:"\uD83E\uDD16",codex:"\uD83E\uDDE0",gemini:"✨",generic:"\uD83D\uDCC1"};return(0,n.jsx)("span",{className:"text-base",title:t,children:r[t]||r.generic})}function r8(e){let{status:t}=e,r={active:"bg-green-500",inactive:"bg-gray-500",error:"bg-red-500"};return(0,n.jsx)("span",{className:"w-2 h-2 rounded-full flex-shrink-0 ".concat(r[t]||r.inactive),title:t})}function r9(e){let{isOpen:t}=e;return(0,n.jsx)("svg",{className:"text-text-muted transition-transform ".concat(t?"rotate-180":""),width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.jsx)("polyline",{points:"6 9 12 15 18 9"})})}function r7(){return(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("line",{x1:"6",y1:"3",x2:"6",y2:"15"}),(0,n.jsx)("circle",{cx:"18",cy:"6",r:"3"}),(0,n.jsx)("circle",{cx:"6",cy:"18",r:"3"}),(0,n.jsx)("path",{d:"M18 9a9 9 0 0 1-9 9"})]})}function ne(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,n.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function nt(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,n.jsx)("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"})]})}function nr(e){let{isOpen:t,onClose:r,onAdd:a,isAdding:l=!1,error:o}=e,[i,c]=(0,s.useState)(""),[d,u]=(0,s.useState)(""),[x,m]=(0,s.useState)(null),h=(0,s.useRef)(null);(0,s.useEffect)(()=>{t&&h.current&&h.current.focus()},[t]),(0,s.useEffect)(()=>{t||(c(""),u(""),m(null))},[t]);let p=async e=>{if(e.preventDefault(),!i.trim()){m("Path is required");return}try{await a(i.trim(),d.trim()||void 0),r()}catch(e){m(e instanceof Error?e.message:"Failed to add workspace")}};if(!t)return null;let g=o||x;return(0,n.jsx)("div",{className:"fixed inset-0 bg-black/60 flex items-center justify-center z-[9999] backdrop-blur-sm",onClick:r,onKeyDown:e=>{"Escape"===e.key&&r()},children:(0,n.jsxs)("div",{className:"bg-[#1a1a2e] border border-[#3a3a4e] rounded-xl p-6 min-w-[450px] max-w-[90vw] shadow-[0_20px_60px_rgba(0,0,0,0.5)]",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-6",children:[(0,n.jsx)("h2",{className:"m-0 text-lg font-semibold text-[#e8e8e8]",children:"Add Workspace"}),(0,n.jsx)("button",{className:"bg-transparent border-none text-[#666] cursor-pointer p-1 flex items-center justify-center rounded transition-all hover:bg-white/10 hover:text-[#e8e8e8]",onClick:r,children:(0,n.jsx)(nn,{})})]}),(0,n.jsxs)("form",{onSubmit:p,children:[(0,n.jsxs)("div",{className:"mb-5",children:[(0,n.jsx)("label",{htmlFor:"workspace-path",className:"block mb-2 text-[13px] font-medium text-[#e8e8e8]",children:"Repository Path"}),(0,n.jsx)("input",{ref:h,id:"workspace-path",type:"text",value:i,onChange:e=>{c(e.target.value),m(null)},placeholder:"/path/to/repository",disabled:l,autoComplete:"off",className:"w-full px-3 py-2.5 bg-[#2a2a3e] border border-[#3a3a4e] rounded-md text-[#e8e8e8] text-sm outline-none transition-colors box-border focus:border-[#00c896] placeholder:text-[#666] disabled:opacity-60 disabled:cursor-not-allowed"}),(0,n.jsx)("p",{className:"mt-1.5 text-xs text-[#666] leading-relaxed",children:"Enter the full path to your repository. Use ~ for home directory."})]}),(0,n.jsxs)("div",{className:"mb-5",children:[(0,n.jsx)("label",{htmlFor:"workspace-name",className:"block mb-2 text-[13px] font-medium text-[#e8e8e8]",children:"Display Name (optional)"}),(0,n.jsx)("input",{id:"workspace-name",type:"text",value:d,onChange:e=>u(e.target.value),placeholder:"My Project",disabled:l,autoComplete:"off",className:"w-full px-3 py-2.5 bg-[#2a2a3e] border border-[#3a3a4e] rounded-md text-[#e8e8e8] text-sm outline-none transition-colors box-border focus:border-[#00c896] placeholder:text-[#666] disabled:opacity-60 disabled:cursor-not-allowed"}),(0,n.jsx)("p",{className:"mt-1.5 text-xs text-[#666] leading-relaxed",children:"A friendly name for this workspace. Defaults to the folder name."})]}),g&&(0,n.jsx)("div",{className:"px-3 py-2.5 bg-red-500/10 border border-red-500/30 rounded-md text-red-500 text-[13px] mb-5",children:g}),(0,n.jsxs)("div",{className:"flex gap-3 justify-end mt-6",children:[(0,n.jsx)("button",{type:"button",className:"px-5 py-2.5 rounded-md text-sm font-medium cursor-pointer transition-all bg-transparent border border-[#3a3a4e] text-[#e8e8e8] hover:bg-white/5 disabled:opacity-50 disabled:cursor-not-allowed",onClick:r,disabled:l,children:"Cancel"}),(0,n.jsx)("button",{type:"submit",className:"px-5 py-2.5 rounded-md text-sm font-medium cursor-pointer transition-all bg-[#00c896] border-none text-[#1a1a2e] hover:bg-[#00a87d] disabled:opacity-50 disabled:cursor-not-allowed",disabled:l||!i.trim(),children:l?"Adding...":"Add Workspace"})]})]})]})})}function nn(){return(0,n.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}var ns=r(2547),na=r(8514),nl=r(8345);let no={background:"#0d0f14",foreground:"#c9d1d9",cursor:"#58a6ff",cursorAccent:"#0d0f14",selectionBackground:"#264f78",selectionForeground:"#ffffff",black:"#484f58",red:"#f85149",green:"#3fb950",yellow:"#d29922",blue:"#58a6ff",magenta:"#bc8cff",cyan:"#39c5cf",white:"#b1bac4",brightBlack:"#6e7681",brightRed:"#ff7b72",brightGreen:"#56d364",brightYellow:"#e3b341",brightBlue:"#79c0ff",brightMagenta:"#d2a8ff",brightCyan:"#56d4dd",brightWhite:"#ffffff"};function ni(e){let{agentName:t,maxHeight:r="500px",showHeader:a=!0,onClose:l,className:o=""}=e,i=(0,s.useRef)(null),c=(0,s.useRef)(null),d=(0,s.useRef)(null),u=(0,s.useRef)(null),m=(0,s.useRef)(null),h=(0,s.useRef)(null),p=(0,s.useRef)(0),[g,f]=(0,s.useState)(!1),[b,v]=(0,s.useState)(!1),[y,j]=(0,s.useState)(null),[w,N]=(0,s.useState)(!1),[k,C]=(0,s.useState)(""),[S,L]=(0,s.useState)(0),[M,D]=(0,s.useState)(!1),A=(0,s.useRef)(null),E=(0,x.GW)(t),T=eY("/ws/logs/".concat(encodeURIComponent(t)));(0,s.useEffect)(()=>{if(!i.current)return;let e=new ns.o({theme:no,fontFamily:'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace',fontSize:12,lineHeight:1.4,convertEol:!0,scrollback:1e4,cursorBlink:!1,cursorStyle:"bar",disableStdin:!0,allowProposedApi:!0}),t=new na.X,r=new nl.Z;e.loadAddon(t),e.loadAddon(r),e.open(i.current),t.fit(),c.current=e,d.current=t,u.current=r,D(!0);let n=new ResizeObserver(()=>{t.fit()});return n.observe(i.current),()=>{n.disconnect(),e.dispose(),c.current=null,d.current=null,u.current=null,D(!1)}},[]),(0,s.useEffect)(()=>{if(!i.current||!M||!c.current||!window.matchMedia("(pointer: coarse)").matches)return;let e=i.current,t=c.current,r=12*1.4,n=0,s=0,a=0,l=!1,o=e=>{1===e.touches.length&&(s=n=e.touches[0].clientY,a=0,l=!1)},d=e=>{if(1!==e.touches.length)return;let o=e.touches[0].clientY,i=s-o;if(s=o,!l&&Math.abs(o-n)>10&&(l=!0),!l)return;let c=Math.trunc((a+=i)/r);0!==c&&(t.scrollLines(c),a-=c*r),e.preventDefault()},u=()=>{l=!1,a=0};return e.addEventListener("touchstart",o,{passive:!0}),e.addEventListener("touchmove",d,{passive:!1}),e.addEventListener("touchend",u,{passive:!0}),e.addEventListener("touchcancel",u,{passive:!0}),()=>{e.removeEventListener("touchstart",o),e.removeEventListener("touchmove",d),e.removeEventListener("touchend",u),e.removeEventListener("touchcancel",u)}},[M]);let W=(0,s.useCallback)(()=>{var e,r;if((null===(e=m.current)||void 0===e?void 0:e.readyState)===WebSocket.OPEN||(null===(r=m.current)||void 0===r?void 0:r.readyState)===WebSocket.CONNECTING)return;v(!0),j(null);let n=new WebSocket(T);m.current=n,n.onopen=()=>{var e;f(!0),v(!1),j(null),p.current=0,null===(e=c.current)||void 0===e||e.writeln("\x1b[90m[Connected to ".concat(t," log stream]\x1b[0m"))},n.onclose=e=>{var t,r;if(f(!1),v(!1),m.current=null,h.current&&(clearTimeout(h.current),h.current=null),4404===e.code){null===(r=c.current)||void 0===r||r.writeln("\x1b[31m[Agent not found]\x1b[0m");return}let n=Math.min(1e3*Math.pow(2,p.current),3e4);p.current++,null===(t=c.current)||void 0===t||t.writeln("\x1b[90m[Disconnected. Reconnecting in ".concat(n/1e3,"s...]\x1b[0m")),h.current=setTimeout(()=>{W()},n)},n.onerror=()=>{j(Error("WebSocket connection error")),v(!1)},n.onmessage=e=>{var t,r,n;try{let n=JSON.parse(e.data);if("error"===n.type){null===(t=c.current)||void 0===t||t.writeln("\x1b[31mError: ".concat(n.error,"\x1b[0m"));return}if("subscribed"===n.type)return;if("history"===n.type&&Array.isArray(n.lines)){n.lines.forEach(e=>{var t;null===(t=c.current)||void 0===t||t.writeln(e),L(e=>e+1)});return}if("log"===n.type||"output"===n.type){let e=n.content||n.data||n.message||"";if(e){null===(r=c.current)||void 0===r||r.write(e);let t=(e.match(/\n/g)||[]).length;t>0&&L(e=>e+t)}return}n.lines&&Array.isArray(n.lines)&&n.lines.forEach(e=>{var t;let r="string"==typeof e?e:e.content;null===(t=c.current)||void 0===t||t.writeln(r),L(e=>e+1)})}catch(t){if("string"==typeof e.data){null===(n=c.current)||void 0===n||n.write(e.data);let t=(e.data.match(/\n/g)||[]).length;t>0&&L(e=>e+t)}}}},[T,t]),P=(0,s.useCallback)(()=>{h.current&&(clearTimeout(h.current),h.current=null),m.current&&(m.current.close(),m.current=null),f(!1),v(!1)},[]),R=(0,s.useCallback)(()=>{var e;null===(e=c.current)||void 0===e||e.clear(),L(0)},[]),I=(0,s.useCallback)(e=>{C(e),e&&u.current&&u.current.findNext(e,{caseSensitive:!1})},[]),B=(0,s.useCallback)(()=>{k&&u.current&&u.current.findNext(k,{caseSensitive:!1})},[k]),F=(0,s.useCallback)(()=>{k&&u.current&&u.current.findPrevious(k,{caseSensitive:!1})},[k]);return(0,s.useEffect)(()=>(W(),()=>{P()}),[W,P]),(0,s.useEffect)(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"f"===e.key&&(e.preventDefault(),N(!0),setTimeout(()=>{var e;return null===(e=A.current)||void 0===e?void 0:e.focus()},0)),"Escape"===e.key&&w&&(N(!1),C("")),"Enter"===e.key&&w&&(e.preventDefault(),e.shiftKey?F():B())};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[w,B,F]),(0,n.jsxs)("div",{className:"xterm-log-viewer flex flex-col min-h-0 rounded-xl overflow-hidden border border-[#2a2d35] shadow-2xl ".concat(o),style:{background:"linear-gradient(180deg, #0d0f14 0%, #0a0c10 100%)",boxShadow:"0 0 60px -15px ".concat(E.primary,"25, 0 25px 50px -12px rgba(0, 0, 0, 0.8), inset 0 1px 0 rgba(255,255,255,0.02)")},children:[(0,n.jsx)("style",{children:"\n .xterm-log-viewer .xterm {\n height: 100%;\n }\n .xterm-log-viewer .xterm-viewport {\n height: 100%;\n max-height: 100%;\n overscroll-behavior: contain;\n }\n /* On touch devices, disable browser touch handling so our JS handler works */\n @media (pointer: coarse) {\n .xterm-log-viewer .xterm,\n .xterm-log-viewer .xterm-viewport,\n .xterm-log-viewer .xterm-screen,\n .xterm-log-viewer .xterm-screen canvas {\n touch-action: none;\n }\n }\n "}),a&&(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-3 border-b border-[#21262d]",style:{background:"linear-gradient(180deg, #161b22 0%, #0d1117 100%)"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("div",{className:"flex items-center gap-2",children:(0,n.jsxs)("div",{className:"flex gap-1.5",children:[(0,n.jsx)("div",{className:"w-3 h-3 rounded-full bg-[#ff5f56] border border-[#e0443e] transition-shadow hover:shadow-[0_0_8px_rgba(255,95,86,0.5)]"}),(0,n.jsx)("div",{className:"w-3 h-3 rounded-full bg-[#ffbd2e] border border-[#dea123] transition-shadow hover:shadow-[0_0_8px_rgba(255,189,46,0.5)]"}),(0,n.jsx)("div",{className:"w-3 h-3 rounded-full bg-[#27c93f] border border-[#1aab29] transition-shadow hover:shadow-[0_0_8px_rgba(39,201,63,0.5)]"})]})}),(0,n.jsx)("div",{className:"w-px h-4 bg-[#30363d]"}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(nc,{}),(0,n.jsx)("span",{className:"text-sm font-semibold",style:{color:E.primary},children:t}),(0,n.jsx)(ng,{isConnected:g,isConnecting:b})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,n.jsx)("button",{className:"p-1.5 rounded-lg transition-all duration-200 ".concat(w?"bg-accent-cyan/20 text-accent-cyan shadow-[0_0_12px_rgba(0,217,255,0.25)]":"hover:bg-[#21262d] text-[#8b949e] hover:text-[#c9d1d9]"),onClick:()=>{N(!w),w||setTimeout(()=>{var e;return null===(e=A.current)||void 0===e?void 0:e.focus()},0)},title:"Search (Cmd+F)",children:(0,n.jsx)(nd,{})}),(0,n.jsx)("button",{className:"p-1.5 rounded-lg hover:bg-[#21262d] text-[#8b949e] hover:text-[#c9d1d9] transition-all duration-200",onClick:R,title:"Clear logs",children:(0,n.jsx)(nu,{})}),(0,n.jsx)("button",{className:"p-1.5 rounded-lg transition-all duration-200 ".concat(g?"hover:bg-[#f85149]/10 text-[#8b949e] hover:text-[#f85149]":"bg-[#3fb950]/20 text-[#3fb950] shadow-[0_0_12px_rgba(63,185,80,0.25)]"),onClick:g?P:W,title:g?"Disconnect":"Connect",children:g?(0,n.jsx)(nh,{}):(0,n.jsx)(nm,{})}),l&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"w-px h-4 bg-[#30363d] mx-1"}),(0,n.jsx)("button",{className:"p-1.5 rounded-lg hover:bg-[#f85149]/10 text-[#8b949e] hover:text-[#f85149] transition-all duration-200",onClick:l,title:"Close",children:(0,n.jsx)(nx,{})})]})]})]}),w&&(0,n.jsxs)("div",{className:"flex items-center gap-3 px-4 py-2 border-b border-[#21262d] bg-[#161b22]",children:[(0,n.jsx)(nd,{}),(0,n.jsx)("input",{ref:A,type:"text",className:"flex-1 bg-transparent border-none text-sm text-[#c9d1d9] placeholder:text-[#484f58] outline-none font-mono",placeholder:"Search logs... (Enter: next, Shift+Enter: prev)",value:k,onChange:e=>I(e.target.value)}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{className:"px-2 py-0.5 text-xs rounded bg-[#21262d] text-[#8b949e] hover:text-[#c9d1d9] transition-colors",onClick:F,title:"Previous (Shift+Enter)",children:"↑"}),(0,n.jsx)("button",{className:"px-2 py-0.5 text-xs rounded bg-[#21262d] text-[#8b949e] hover:text-[#c9d1d9] transition-colors",onClick:B,title:"Next (Enter)",children:"↓"})]})]}),y&&(0,n.jsxs)("div",{className:"px-4 py-2 bg-[#3d1d20] border-b border-[#f85149]/30 text-sm text-[#f85149] flex items-center gap-2",children:[(0,n.jsx)(np,{}),(0,n.jsx)("span",{children:y.message}),(0,n.jsx)("button",{className:"ml-auto text-xs px-2 py-0.5 rounded bg-[#f85149]/20 hover:bg-[#f85149]/30 transition-colors",onClick:W,children:"Retry"})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",style:{height:r,maxHeight:r,minHeight:"200px"},children:(0,n.jsx)("div",{ref:i,className:"h-full w-full"})}),(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-2.5 border-t border-[#21262d] text-xs",style:{background:"linear-gradient(180deg, #0d1117 0%, #0a0c10 100%)"},children:[(0,n.jsx)("div",{className:"flex items-center gap-3",children:(0,n.jsxs)("span",{className:"tabular-nums font-mono text-[#6e7681]",children:[S," lines"]})}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"text-[#6e7681] font-mono uppercase tracking-wider text-[10px]",children:"PTY stream"}),(0,n.jsx)("div",{className:"w-2 h-2 rounded-full transition-all duration-300 ".concat(g?"bg-[#3fb950]":b?"bg-[#d29922] animate-pulse":"bg-[#484f58]"),style:{boxShadow:g?"0 0 8px rgba(63,185,80,0.6)":"none"}})]})]})]})}function nc(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-[#8b949e]",children:[(0,n.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,n.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]})}function nd(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-[#8b949e]",children:[(0,n.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,n.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function nu(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.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"})]})}function nx(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function nm(){return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("polygon",{points:"5 3 19 12 5 21 5 3"})})}function nh(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor",children:[(0,n.jsx)("rect",{x:"6",y:"4",width:"4",height:"16"}),(0,n.jsx)("rect",{x:"14",y:"4",width:"4",height:"16"})]})}function np(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,n.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}function ng(e){let{isConnected:t,isConnecting:r}=e;return r?(0,n.jsxs)("span",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded-full bg-[#d29922]/20 text-[10px] text-[#d29922] uppercase tracking-wider",children:[(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-[#d29922] animate-pulse"}),"connecting"]}):t?(0,n.jsxs)("span",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded-full bg-[#238636]/20 text-[10px] text-[#3fb950] uppercase tracking-wider",children:[(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-[#3fb950] shadow-[0_0_4px_rgba(63,185,80,0.5)]"}),"live"]}):(0,n.jsxs)("span",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded-full bg-[#484f58]/20 text-[10px] text-[#484f58] uppercase tracking-wider",children:[(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-[#484f58]"}),"offline"]})}function nf(e){let{agentName:t,mode:r="panel",maxHeight:a="500px",showHeader:l=!0,autoScrollDefault:o=!0,onClose:i,onExpand:c,className:d=""}=e,[u,m]=(0,s.useState)(o),h=(0,s.useRef)(null),{logs:p,isConnected:g,isConnecting:f}=e0({agentName:t,autoConnect:!0}),b=(0,x.GW)(t),v=(0,s.useMemo)(()=>p.filter(e=>{let t=ny(e.content).trim();return 0!==t.length&&!(t.length<=2&&/^[⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏⣾⣽⣻⢿⡿⣟⣯⣷◐◓◑◒●○◉◎|\\\/\-*.\u2800-\u28FF]+$/.test(t))}),[p]);(0,s.useEffect)(()=>{if(u&&h.current){let e=h.current;e.scrollTop=e.scrollHeight}},[p,u]);let y=(0,s.useCallback)(()=>{if(!h.current)return;let e=h.current,t=e.scrollHeight-e.scrollTop-e.clientHeight<50;t&&!u?m(!0):!t&&u&&m(!1)},[u]);return"inline"===r?(0,n.jsxs)("div",{className:"log-viewer-inline rounded-lg overflow-hidden border border-[#2a2d35] ".concat(d),style:{background:"linear-gradient(180deg, #0d0f14 0%, #12151c 100%)",boxShadow:"inset 0 1px 0 rgba(255,255,255,0.02), 0 4px 12px rgba(0,0,0,0.3)"},children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-3 py-2 border-b border-[#2a2d35]",style:{background:"linear-gradient(180deg, #161b22 0%, #0d1117 100%)"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(nj,{}),(0,n.jsx)("span",{className:"text-xs font-medium",style:{color:b.primary},children:"Live logs"}),(0,n.jsx)(nv,{isConnected:g,isConnecting:f})]}),(0,n.jsx)("div",{className:"flex items-center gap-1",children:(0,n.jsx)("button",{className:"p-1.5 rounded-lg hover:bg-[#21262d] text-[#8b949e] hover:text-accent-cyan transition-all duration-200 hover:shadow-[0_0_8px_rgba(0,217,255,0.15)]",onClick:c,title:"Expand",children:(0,n.jsx)(nw,{})})})]}),(0,n.jsxs)("div",{className:"font-mono text-xs leading-relaxed p-3 overflow-y-auto touch-pan-y",style:{maxHeight:"150px",WebkitOverflowScrolling:"touch",overscrollBehavior:"contain",touchAction:"pan-y"},ref:h,onScroll:y,children:[v.slice(-20).map(e=>(0,n.jsx)(nb,{log:e,compact:!0},e.id)),0===v.length&&(0,n.jsxs)("div",{className:"text-[#484f58] italic flex items-center gap-2",children:[(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-[#484f58] animate-pulse"}),"Waiting for output..."]})]})]}):(0,n.jsx)(ni,{agentName:t,maxHeight:a,showHeader:l,onClose:i,className:d})}function nb(e){let{log:t,compact:r=!1}=e,s=ny(t.content);return(0,n.jsx)("div",{className:"".concat((()=>{switch(t.type){case"stderr":return"text-[#f85149]";case"system":return"text-[#58a6ff] italic";case"input":return"text-[#d29922]";default:return"text-[#c9d1d9]"}})()," leading-5 whitespace-pre-wrap break-all min-w-0 overflow-hidden"),children:s})}function nv(e){let{isConnected:t,isConnecting:r}=e;return r?(0,n.jsxs)("span",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded-full bg-[#d29922]/20 text-[10px] text-[#d29922] uppercase tracking-wider",children:[(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-[#d29922] animate-pulse"}),"connecting"]}):t?(0,n.jsxs)("span",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded-full bg-[#238636]/20 text-[10px] text-[#3fb950] uppercase tracking-wider",children:[(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-[#3fb950] shadow-[0_0_4px_rgba(63,185,80,0.5)]"}),"live"]}):(0,n.jsxs)("span",{className:"flex items-center gap-1 px-1.5 py-0.5 rounded-full bg-[#484f58]/20 text-[10px] text-[#484f58] uppercase tracking-wider",children:[(0,n.jsx)("span",{className:"w-1.5 h-1.5 rounded-full bg-[#484f58]"}),"offline"]})}function ny(e){if(!e)return"";let t=e;return(t=(t=(t=(t=(t=(t=(t=(t=(t=t.replace(RegExp("\\x1b\\].*?(?:\\x07|\\x1b\\\\)","gs"),"")).replace(RegExp("\\x1bP.*?\\x1b\\\\","gs"),"")).replace(/\x1b\[[0-9;?]*[ -/]*[@-~]/g,"")).replace(/\x1b[@-Z\\-_]/g,"")).replace(/^\[\??\d+[hlKJHfABCDGPXsu]/gm,"")).replace(/\[\d+(?:;\d+)*m/g,"")).replace(/\r/g,"")).replace(/.\x08/g,"")).replace(/\x08+/g,"")).replace(/[\x00-\x08\x0B\x0C\x0E-\x1F]/g,"")}function nj(e){let{size:t=16}=e;return(0,n.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-[#8b949e]",children:[(0,n.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,n.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]})}function nw(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("polyline",{points:"15 3 21 3 21 9"}),(0,n.jsx)("polyline",{points:"9 21 3 21 3 15"}),(0,n.jsx)("line",{x1:"21",y1:"3",x2:"14",y2:"10"}),(0,n.jsx)("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]})}function nN(e){let{agent:t,position:r="right",isOpen:a,onClose:l,onAgentChange:o,availableAgents:i=[]}=e,c=(0,x.GW)(t.name),[d,u]=(0,s.useState)(!1),m=(0,s.useCallback)(async()=>{if(!d){u(!0);try{let e=await r_.hi.interruptAgent(t.name);e.success||console.error("Failed to interrupt agent:",e.error)}catch(e){console.error("Error interrupting agent:",e)}finally{setTimeout(()=>u(!1),500)}}},[t.name,d]);return((0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&a&&l()};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[a,l]),(0,s.useEffect)(()=>{if(!a)return;let e=document.body.style.overflow,t=document.body.style.overscrollBehavior;return document.body.style.overflow="hidden",document.body.style.overscrollBehavior="none",()=>{document.body.style.overflow=e,document.body.style.overscrollBehavior=t}},[a]),a)?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"fixed inset-0 bg-black/60 z-[1099] animate-fade-in",onClick:l}),(0,n.jsxs)("div",{className:"flex flex-col ".concat((()=>{switch(r){case"right":return"animate-slide-in-right";case"bottom":return"animate-slide-in-bottom";case"fullscreen":return"animate-fade-in"}})()),style:(()=>{let e={position:"fixed",zIndex:1100,background:"linear-gradient(180deg, #0d0f14 0%, #0a0c10 100%)"};switch(r){case"right":return{...e,top:0,right:0,bottom:0,width:"600px",maxWidth:"100vw",borderLeft:"1px solid #21262d",boxShadow:"-20px 0 60px rgba(0, 0, 0, 0.5)"};case"bottom":return{...e,left:0,right:0,bottom:0,height:"400px",maxHeight:"60vh",borderTop:"1px solid #21262d",boxShadow:"0 -20px 60px rgba(0, 0, 0, 0.5)"};case"fullscreen":return{...e,inset:0}}})(),children:[(0,n.jsxs)("div",{className:"flex flex-col gap-3 border-b border-[#21262d] px-4 py-3 sm:px-5 sm:py-4",style:{background:"linear-gradient(180deg, #161b22 0%, #0d1117 100%)"},children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsxs)("div",{className:"relative shrink-0 rounded-xl flex items-center justify-center font-bold overflow-hidden w-9 h-9 text-sm sm:w-11 sm:h-11",style:{backgroundColor:c.primary,color:c.text,boxShadow:"0 0 20px ".concat(c.primary,"50, inset 0 1px 0 rgba(255,255,255,0.2)")},children:[(0,n.jsx)("div",{className:"absolute inset-0 opacity-30",style:{background:"linear-gradient(135deg, rgba(255,255,255,0.35) 0%, transparent 50%)"}}),(0,n.jsx)("span",{className:"relative z-10",children:(0,x.hP)(t.name)})]}),(0,n.jsxs)("div",{className:"flex flex-col min-w-0 flex-1",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2.5 flex-wrap",children:[(0,n.jsx)("h2",{className:"text-base sm:text-lg font-semibold m-0",style:{color:c.primary},title:t.name,children:t.name}),(0,n.jsx)("span",{className:"px-2 py-0.5 rounded-md text-[10px] uppercase tracking-wider font-medium shrink-0 ".concat("online"===t.status?"bg-[#3fb950]/15 text-[#3fb950]":"busy"===t.status?"bg-[#d29922]/15 text-[#d29922]":"bg-[#484f58]/15 text-[#484f58]"),style:{boxShadow:"online"===t.status?"0 0 8px rgba(63,185,80,0.2)":"none"},children:t.status})]}),t.currentTask&&(0,n.jsx)("span",{className:"text-xs sm:text-sm text-[#8b949e] truncate mt-0.5",title:t.currentTask,children:t.currentTask})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2 flex-wrap",children:[i.length>1&&o&&(0,n.jsx)(nk,{agents:i,currentAgent:t,onSelect:o}),(0,n.jsxs)("div",{className:"flex items-center gap-1 bg-[#21262d]/80 rounded-lg p-1 border border-[#30363d]/50",children:[(0,n.jsx)("button",{className:"p-1.5 rounded-md transition-all duration-200 ".concat("right"===r?"bg-accent-cyan/15 text-accent-cyan shadow-[0_0_8px_rgba(0,217,255,0.15)]":"text-[#8b949e] hover:text-[#c9d1d9] hover:bg-[#30363d]"),title:"Sidebar view",children:(0,n.jsx)(nL,{})}),(0,n.jsx)("button",{className:"p-1.5 rounded-md transition-all duration-200 ".concat("bottom"===r?"bg-accent-cyan/15 text-accent-cyan shadow-[0_0_8px_rgba(0,217,255,0.15)]":"text-[#8b949e] hover:text-[#c9d1d9] hover:bg-[#30363d]"),title:"Bottom panel",children:(0,n.jsx)(nM,{})}),(0,n.jsx)("button",{className:"p-1.5 rounded-md transition-all duration-200 ".concat("fullscreen"===r?"bg-accent-cyan/15 text-accent-cyan shadow-[0_0_8px_rgba(0,217,255,0.15)]":"text-[#8b949e] hover:text-[#c9d1d9] hover:bg-[#30363d]"),title:"Fullscreen",children:(0,n.jsx)(nD,{})})]}),(0,n.jsx)("div",{className:"flex-1"}),(0,n.jsx)("button",{className:"p-2 rounded-lg transition-all duration-200 ".concat(d?"bg-[#d29922]/20 text-[#d29922] animate-pulse":"text-[#8b949e] hover:text-[#d29922] hover:bg-[#d29922]/10 hover:shadow-[0_0_8px_rgba(210,153,34,0.2)]"),onClick:m,disabled:d,title:"Send ESC to agent - interrupt current operation",children:(0,n.jsx)(nC,{})}),(0,n.jsx)("button",{className:"p-2 rounded-lg text-[#8b949e] hover:text-[#f85149] hover:bg-[#f85149]/10 transition-all duration-200 hover:shadow-[0_0_8px_rgba(248,81,73,0.2)]",onClick:l,children:(0,n.jsx)(nS,{})})]})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-hidden",children:(0,n.jsx)(nf,{agentName:t.name,mode:"panel",showHeader:!1,maxHeight:"100%",className:"h-full rounded-none border-none"})})]}),(0,n.jsx)("style",{children:"\n @keyframes slideInRight {\n from {\n transform: translateX(100%);\n opacity: 0;\n }\n to {\n transform: translateX(0);\n opacity: 1;\n }\n }\n\n @keyframes slideInBottom {\n from {\n transform: translateY(100%);\n opacity: 0;\n }\n to {\n transform: translateY(0);\n opacity: 1;\n }\n }\n\n .animate-slide-in-right {\n animation: slideInRight 0.3s cubic-bezier(0.32, 0.72, 0, 1);\n }\n\n .animate-slide-in-bottom {\n animation: slideInBottom 0.3s cubic-bezier(0.32, 0.72, 0, 1);\n }\n "})]}):null}function nk(e){let{agents:t,currentAgent:r,onSelect:a}=e,[l,o]=s.useState(!1),i=s.useRef(null);return(0,s.useEffect)(()=>{let e=e=>{i.current&&!i.current.contains(e.target)&&o(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,n.jsxs)("div",{className:"relative",ref:i,children:[(0,n.jsxs)("button",{className:"flex items-center gap-2 px-3 py-1.5 bg-[#21262d] hover:bg-[#30363d] rounded-lg text-sm text-[#c9d1d9] transition-colors",onClick:()=>o(!l),children:[(0,n.jsx)("span",{children:"Switch agent"}),(0,n.jsx)(nA,{})]}),l&&(0,n.jsx)("div",{className:"absolute right-0 top-full mt-2 w-64 bg-[#161b22] border border-[#30363d] rounded-lg shadow-xl overflow-hidden z-10",children:(0,n.jsx)("div",{className:"max-h-64 overflow-y-auto",children:t.map(e=>{let t=(0,x.GW)(e.name),s=e.name===r.name;return(0,n.jsxs)("button",{className:"w-full flex items-center gap-3 px-3 py-2 text-left transition-colors ".concat(s?"bg-[#238636]/20":"hover:bg-[#21262d]"),onClick:()=>{a(e),o(!1)},children:[(0,n.jsx)("div",{className:"w-8 h-8 rounded flex items-center justify-center text-xs font-semibold shrink-0",style:{backgroundColor:t.primary,color:t.text},children:(0,x.hP)(e.name)}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-sm text-[#c9d1d9] truncate",children:e.name}),(0,n.jsx)("div",{className:"text-xs text-[#8b949e]",children:e.status})]}),s&&(0,n.jsx)(nE,{})]},e.name)})})})]})}function nC(){return(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("rect",{x:"3",y:"5",width:"18",height:"14",rx:"2"}),(0,n.jsx)("text",{x:"12",y:"15",textAnchor:"middle",fill:"currentColor",stroke:"none",fontSize:"8",fontWeight:"600",fontFamily:"system-ui",children:"ESC"})]})}function nS(){return(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function nL(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,n.jsx)("line",{x1:"15",y1:"3",x2:"15",y2:"21"})]})}function nM(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),(0,n.jsx)("line",{x1:"3",y1:"15",x2:"21",y2:"15"})]})}function nD(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("polyline",{points:"15 3 21 3 21 9"}),(0,n.jsx)("polyline",{points:"9 21 3 21 3 15"}),(0,n.jsx)("line",{x1:"21",y1:"3",x2:"14",y2:"10"}),(0,n.jsx)("line",{x1:"3",y1:"21",x2:"10",y2:"14"})]})}function nA(){return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.jsx)("polyline",{points:"6 9 12 15 18 9"})})}function nE(){return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#3fb950",strokeWidth:"2",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})})}function nT(e){let{agentName:t,steps:r,history:a=[],selectedTrajectoryId:l,onSelectTrajectory:o,isLoading:i=!1,onStepClick:c,compact:d=!1}=e,[u,x]=(0,s.useState)(new Set),[m,h]=(0,s.useState)("all"),[p,g]=(0,s.useState)(""),f=null===l&&a.length>0;(0,s.useEffect)(()=>{h("all")},[l]);let b=(0,s.useMemo)(()=>"all"===m?r:r.filter(e=>e.type===m),[r,m]),v=(0,s.useMemo)(()=>{let e=p.trim().toLowerCase();return e?a.filter(t=>{var r,n,s,a,l;let o=null===(r=t.title)||void 0===r?void 0:r.toLowerCase().includes(e),i=null===(n=t.summary)||void 0===n?void 0:n.toLowerCase().includes(e),c=null===(s=t.agents)||void 0===s?void 0:s.some(t=>t.toLowerCase().includes(e)),d=null===(a=t.status)||void 0===a?void 0:a.toLowerCase().includes(e),u=null===(l=t.id)||void 0===l?void 0:l.toLowerCase().includes(e);return o||i||c||d||u}):a},[a,p]),y=e=>{x(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},j=[{value:"all",label:"All",icon:(0,n.jsx)(nI,{})},{value:"tool_call",label:"Tools",icon:(0,n.jsx)(nB,{})},{value:"decision",label:"Decisions",icon:(0,n.jsx)(nF,{})},{value:"message",label:"Messages",icon:(0,n.jsx)(nU,{})},{value:"state_change",label:"State",icon:(0,n.jsx)(n_,{})},{value:"phase_transition",label:"Phases",icon:(0,n.jsx)(nO,{})},{value:"error",label:"Errors",icon:(0,n.jsx)(nH,{})}],w=(0,s.useMemo)(()=>{let e=r.filter(e=>e.phase).reduce((e,t)=>(t.phase&&(e[t.phase]=(e[t.phase]||0)+1),e),{}),t=Object.values(e).reduce((e,t)=>e+t,0);return{phases:e,total:t}},[r]);return(0,n.jsxs)("div",{className:"h-full flex flex-col bg-gradient-to-b from-bg-card to-bg-tertiary rounded-xl border border-border/50 overflow-hidden shadow-lg backdrop-blur-sm",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("div",{className:"absolute top-0 left-0 right-0 h-[2px] bg-gradient-to-r from-blue-500 via-accent-cyan to-blue-500 opacity-60"}),(0,n.jsxs)("div",{className:"flex items-center justify-between px-5 py-4 border-b border-border/30",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[l&&o&&(0,n.jsxs)("button",{onClick:()=>o(null),className:"flex items-center gap-1.5 px-2 py-1.5 text-[11px] font-medium text-text-muted hover:text-accent-cyan bg-bg-elevated/50 hover:bg-bg-elevated rounded-lg border border-border/30 hover:border-accent-cyan/30 transition-all duration-200",title:"Back to trajectory list",children:[(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:(0,n.jsx)("path",{d:"M19 12H5M12 19l-7-7 7-7",strokeLinecap:"round",strokeLinejoin:"round"})}),(0,n.jsx)("span",{children:"List"})]}),(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("div",{className:"w-9 h-9 rounded-lg bg-gradient-to-br from-blue-500/20 to-accent-cyan/20 flex items-center justify-center border border-blue-500/30",children:(0,n.jsx)(nR,{})}),r.some(e=>"running"===e.status)&&(0,n.jsx)("span",{className:"absolute -top-1 -right-1 w-3 h-3 bg-accent-cyan rounded-full animate-pulse shadow-[0_0_8px_rgba(0,217,255,0.6)]"})]}),(0,n.jsxs)("div",{className:"flex flex-col",children:[(0,n.jsx)("span",{className:"font-semibold text-sm text-text-primary tracking-wide",children:"Trajectory"}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsxs)("span",{className:"text-[11px] text-text-muted font-mono",children:[r.length," ",1===r.length?"step":"steps"]}),t&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("span",{className:"text-text-dim",children:"|"}),(0,n.jsx)("span",{className:"text-[11px] text-accent-cyan/80 font-medium truncate max-w-[120px]",children:t})]})]})]})]}),w.total>0&&!d&&(0,n.jsx)("div",{className:"flex items-center gap-1.5",children:["plan","design","execute","review","observe"].map(e=>{let t=w.phases[e]||0,r=nP(e);return t>0?(0,n.jsx)("div",{className:"h-1.5 rounded-full transition-all duration-300",style:{width:"".concat(Math.max(8,t/w.total*48),"px"),backgroundColor:r||"var(--color-border)"},title:"".concat(e,": ").concat(t)},e):null})})]}),!d&&!f&&(0,n.jsx)("div",{className:"flex items-center gap-1 px-4 py-2 bg-bg-elevated/50 border-b border-border/20 overflow-x-auto scrollbar-thin",children:j.map(e=>(0,n.jsxs)("button",{className:"flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium rounded-lg transition-all duration-200 whitespace-nowrap ".concat(m===e.value?"bg-blue-500/20 text-blue-500 border border-blue-500/30 shadow-[0_0_12px_rgba(59,130,246,0.15)]":"text-text-muted hover:text-text-secondary hover:bg-bg-hover/50"),onClick:()=>h(e.value),children:[(0,n.jsx)("span",{className:"opacity-70",children:e.icon}),e.label]},e.value))})]}),(0,n.jsx)("div",{className:"flex-1 min-h-0 overflow-y-auto px-4 py-3 scrollbar-thin scrollbar-thumb-border scrollbar-track-transparent",children:i?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center gap-4 py-12 text-text-muted",children:[(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)(nV,{}),(0,n.jsx)("div",{className:"absolute inset-0 bg-accent-cyan/10 rounded-full blur-xl"})]}),(0,n.jsx)("span",{className:"text-sm font-medium",children:"Loading trajectory..."})]}):f?(0,n.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between gap-3 px-2",children:[(0,n.jsx)("span",{className:"text-xs font-medium text-text-secondary uppercase tracking-wider",children:"All Trajectories"}),(0,n.jsx)("input",{type:"search",value:p,onChange:e=>g(e.target.value),placeholder:"Search trajectories...",className:"text-[11px] text-text-secondary bg-bg-elevated/60 border border-border/30 rounded-md px-2 py-1 w-40 focus:outline-none focus:border-accent-cyan/40"})]}),(0,n.jsxs)("div",{className:"flex flex-col gap-1",children:[v.map(e=>(0,n.jsxs)("button",{onClick:()=>null==o?void 0:o(e.id),className:"w-full text-left px-3 py-2.5 rounded-lg transition-all duration-200 border ".concat("active"===e.status?"bg-blue-500/10 border-blue-500/30 hover:bg-blue-500/20":"bg-bg-tertiary/50 border-transparent hover:bg-bg-elevated/60 hover:border-border/40"),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between gap-2",children:[(0,n.jsx)("span",{className:"text-[13px] font-medium text-text-primary truncate flex-1",children:e.title}),(0,n.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded font-medium flex-shrink-0 ".concat("completed"===e.status?"bg-green-500/15 text-green-500":"active"===e.status?"bg-blue-500/15 text-blue-500":"bg-amber-500/15 text-amber-500"),children:e.status})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2 mt-1",children:[(0,n.jsx)("span",{className:"text-[10px] text-text-dim",children:function(e){let t=new Date(e),r=new Date().getTime()-t.getTime(),n=Math.floor(r/6e4),s=Math.floor(r/36e5),a=Math.floor(r/864e5);return n<1?"just now":n<60?"".concat(n,"m ago"):s<24?"".concat(s,"h ago"):a<7?"".concat(a,"d ago"):t.toLocaleDateString()}(e.startedAt)}),e.confidence&&(0,n.jsxs)("span",{className:"text-[10px] text-text-dim",children:["• ",Math.round(100*e.confidence),"% confidence"]})]}),e.summary&&(0,n.jsx)("p",{className:"text-[11px] text-text-muted mt-1 line-clamp-2",children:e.summary})]},e.id)),0===v.length&&(0,n.jsx)("div",{className:"px-3 py-4 text-[11px] text-text-muted",children:"No matching trajectories. Try a different search."})]})]}):0===b.length?(0,n.jsx)("div",{className:"flex flex-col gap-4 py-4 text-text-muted",children:0===r.length?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center gap-4 py-8",children:[(0,n.jsx)("div",{className:"w-16 h-16 rounded-2xl bg-bg-elevated/50 flex items-center justify-center border border-border/30",children:(0,n.jsx)(nG,{})}),(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("p",{className:"text-sm font-medium text-text-secondary",children:"No steps recorded"}),(0,n.jsx)("p",{className:"text-xs text-text-dim mt-1",children:"Steps will appear here as the agent works"})]})]}):(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center gap-4 py-8",children:[(0,n.jsx)("div",{className:"w-16 h-16 rounded-2xl bg-bg-elevated/50 flex items-center justify-center border border-border/30",children:(0,n.jsx)(nG,{})}),(0,n.jsxs)("div",{className:"text-center",children:[(0,n.jsx)("p",{className:"text-sm font-medium text-text-secondary",children:"No matching steps"}),(0,n.jsx)("p",{className:"text-xs text-text-dim mt-1",children:'Try a different filter or select "All"'})]})]})}):(0,n.jsx)("div",{className:"flex flex-col gap-0.5",children:b.map((e,t)=>(0,n.jsx)(nW,{step:e,isExpanded:u.has(e.id),isLast:t===b.length-1,isFirst:0===t,compact:d,onToggle:()=>y(e.id),onClick:c?()=>c(e):void 0},e.id))})})]})}function nW(e){var t;let{step:r,isExpanded:s,isLast:a,isFirst:l=!1,compact:o=!1,onToggle:i,onClick:c}=e,d=new Date(r.timestamp).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit",second:"2-digit"}),u=function(e){switch(e){case"tool_call":return(0,n.jsx)(nB,{});case"decision":return(0,n.jsx)(nF,{});case"message":return(0,n.jsx)(nU,{});case"state_change":return(0,n.jsx)(n_,{});case"phase_transition":return(0,n.jsx)(nO,{});case"error":return(0,n.jsx)(nH,{});default:return null}}(r.type),x=function(e){switch(e){case"running":return"#ff6b35";case"success":return"#00ffc8";case"error":return"#ff4757";default:return null}}(r.status),m=nP(r.phase),h=function(e){switch(e){case"tool_call":return"#00d9ff";case"decision":case"message":return"#3b82f6";case"state_change":return"#10b981";case"phase_transition":return"#f59e0b";case"error":return"#ef4444";default:return"#6b7280"}}(r.type),p=r.metadata&&Object.keys(r.metadata).length>0,g=!!r.description||p||!!c;return(0,n.jsxs)("div",{className:"flex gap-3 group",children:[(0,n.jsxs)("div",{className:"flex flex-col items-center w-7 relative",children:[!l&&(0,n.jsx)("div",{className:"absolute top-0 w-px h-2 transition-colors",style:{backgroundColor:m?"".concat(m,"40"):"var(--color-border)"}}),(0,n.jsx)("div",{className:"w-7 h-7 rounded-lg flex items-center justify-center flex-shrink-0 z-10 mt-2 transition-all duration-200 ".concat("running"===r.status?"animate-pulse shadow-[0_0_12px_rgba(0,217,255,0.4)]":"group-hover:scale-110"),style:{background:x?"linear-gradient(135deg, ".concat(x,"40, ").concat(x,"20)"):m?"linear-gradient(135deg, ".concat(m,"30, ").concat(m,"10)"):"linear-gradient(135deg, ".concat(h,"30, ").concat(h,"10)"),borderWidth:"1px",borderStyle:"solid",borderColor:x||m||h||"var(--color-border)",color:x||m||h||"var(--color-text-secondary)"},children:u}),!a&&(0,n.jsx)("div",{className:"w-px flex-1 mt-1 transition-colors",style:{background:"linear-gradient(to bottom, ".concat(m||h||"var(--color-border)","40, transparent)")}})]}),(0,n.jsxs)("div",{className:"flex-1 min-w-0 pt-1 ".concat(a?"pb-1":"pb-3"),children:[(0,n.jsxs)("button",{className:"w-full flex items-center justify-between gap-3 px-3 py-2.5 rounded-lg transition-all duration-200 text-left border ".concat(s?"bg-bg-elevated/80 border-border/60 shadow-sm":"bg-bg-tertiary/50 border-transparent hover:bg-bg-elevated/60 hover:border-border/40"),onClick:i,children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"text-[13px] font-medium text-text-primary truncate",children:r.title}),(0,n.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded font-medium flex-shrink-0",style:{backgroundColor:"".concat(h,"15"),color:h},children:{tool_call:"Tool",decision:"Decision",message:"Message",state_change:"State",phase_transition:"Phase",error:"Error"}[r.type]}),r.phase&&m&&(0,n.jsx)("span",{className:"text-[10px] px-1.5 py-0.5 rounded font-medium flex-shrink-0",style:{backgroundColor:"".concat(m,"15"),color:m},children:r.phase})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2 flex-shrink-0",children:[void 0!==r.duration&&(0,n.jsx)("span",{className:"text-[10px] font-mono text-text-muted px-1.5 py-0.5 bg-bg-elevated/50 rounded",children:(t=r.duration)<1e3?"".concat(t,"ms"):t<6e4?"".concat((t/1e3).toFixed(1),"s"):"".concat((t/6e4).toFixed(1),"m")}),(0,n.jsx)("span",{className:"text-[10px] text-text-dim",children:d}),!o&&(0,n.jsx)(nz,{isExpanded:s})]})]}),s&&!o&&g&&(0,n.jsxs)("div",{className:"mt-2 ml-1 pl-3 border-l-2 border-border/30",children:[r.description&&(0,n.jsx)("p",{className:"text-[13px] text-text-secondary mb-3 leading-relaxed",children:r.description}),p&&(0,n.jsx)("div",{className:"bg-bg-elevated/50 rounded-lg p-3 mb-3 overflow-x-auto border border-border/20",children:(0,n.jsx)("pre",{className:"text-[11px] font-mono text-text-muted whitespace-pre-wrap break-words leading-relaxed",children:JSON.stringify(r.metadata,null,2)})}),c&&(0,n.jsxs)("button",{className:"inline-flex items-center gap-1.5 px-3 py-1.5 text-[11px] font-medium text-accent-cyan bg-accent-cyan/10 border border-accent-cyan/20 rounded-md hover:bg-accent-cyan/20 hover:border-accent-cyan/30 transition-colors",onClick:e=>{e.stopPropagation(),c()},children:[(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[(0,n.jsx)("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),(0,n.jsx)("polyline",{points:"15 3 21 3 21 9"}),(0,n.jsx)("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]}),"View Details"]})]})]})]})}function nP(e){switch(e){case"plan":return"#3b82f6";case"design":return"#00d9ff";case"execute":return"#ff6b35";case"review":return"#00ffc8";case"observe":return"#fbbf24";default:return null}}function nR(){return(0,n.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"text-blue-500",children:(0,n.jsx)("path",{d:"M3 12h4l3 9 4-18 3 9h4",strokeLinecap:"round",strokeLinejoin:"round"})})}function nI(){return(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,n.jsx)("path",{d:"M12 2v4m0 12v4m-7.07-14.93l2.83 2.83m8.48 8.48l2.83 2.83M2 12h4m12 0h4M4.93 19.07l2.83-2.83m8.48-8.48l2.83-2.83"})]})}function nB(){return(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.jsx)("path",{d:"M14.7 6.3a1 1 0 0 0 0 1.4l1.6 1.6a1 1 0 0 0 1.4 0l3.77-3.77a6 6 0 0 1-7.94 7.94l-6.91 6.91a2.12 2.12 0 0 1-3-3l6.91-6.91a6 6 0 0 1 7.94-7.94l-3.76 3.76z"})})}function nF(){return(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.jsx)("path",{d:"M12 2l2.4 7.4H22l-6 4.6 2.3 7-6.3-4.6L5.7 21l2.3-7-6-4.6h7.6z"})})}function nU(){return(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.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"})})}function n_(){return(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),(0,n.jsx)("path",{d:"M9 12h6m-3-3v6"})]})}function nO(){return(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("path",{d:"M12 6v6l4 2"})]})}function nH(){return(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,n.jsx)("circle",{cx:"12",cy:"16",r:"0.5",fill:"currentColor"})]})}function nz(e){let{isExpanded:t}=e;return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-text-muted transition-transform duration-200 ".concat(t?"rotate-180":""),children:(0,n.jsx)("polyline",{points:"6 9 12 15 18 9"})})}function nG(){return(0,n.jsxs)("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"text-text-dim",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"8",y1:"12",x2:"16",y2:"12"})]})}function nV(){return(0,n.jsx)("svg",{className:"animate-spin",width:"20",height:"20",viewBox:"0 0 24 24",children:(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round",className:"text-accent"})})}function nK(e){let{decisions:t,onApprove:r,onReject:a,onDismiss:l,isProcessing:o={}}=e,[i,c]=(0,s.useState)(null),[d,u]=(0,s.useState)({}),x=(0,s.useMemo)(()=>{let e={critical:0,high:1,medium:2,low:3};return[...t].sort((t,r)=>{let n=e[t.priority]-e[r.priority];return 0!==n?n:new Date(t.timestamp).getTime()-new Date(r.timestamp).getTime()})},[t]),m=(0,s.useMemo)(()=>t.reduce((e,t)=>(e[t.priority]=(e[t.priority]||0)+1,e),{}),[t]),h=async(e,t)=>{await (null==r?void 0:r(e.id,t))},p=async e=>{await (null==a?void 0:a(e.id,d[e.id])),u(t=>{let r={...t};return delete r[e.id],r})};return 0===t.length?(0,n.jsxs)("div",{className:"decision-queue decision-queue-empty",children:[(0,n.jsx)(n$,{}),(0,n.jsx)("span",{children:"No pending decisions"})]}):(0,n.jsxs)("div",{className:"decision-queue",children:[(0,n.jsxs)("div",{className:"decision-queue-header",children:[(0,n.jsxs)("div",{className:"decision-queue-title",children:[(0,n.jsx)(nJ,{}),(0,n.jsx)("span",{children:"Pending Decisions"}),(0,n.jsx)("span",{className:"decision-queue-count",children:t.length})]}),(0,n.jsxs)("div",{className:"decision-queue-summary",children:[m.critical&&(0,n.jsxs)("span",{className:"decision-priority-badge critical",children:[m.critical," critical"]}),m.high&&(0,n.jsxs)("span",{className:"decision-priority-badge high",children:[m.high," high"]})]})]}),(0,n.jsx)("div",{className:"decision-queue-list",children:x.map(e=>(0,n.jsx)(nZ,{decision:e,isExpanded:i===e.id,isProcessing:o[e.id]||!1,rejectReason:d[e.id]||"",onToggle:()=>c(t=>t===e.id?null:e.id),onApprove:t=>h(e,t),onReject:()=>p(e),onRejectReasonChange:t=>u(r=>({...r,[e.id]:t})),onDismiss:()=>null==l?void 0:l(e.id)},e.id))})]})}function nZ(e){let{decision:t,isExpanded:r,isProcessing:s,rejectReason:a,onToggle:l,onApprove:o,onReject:i,onRejectReasonChange:c,onDismiss:d}=e,u=(0,x.GW)(t.agentName),m=function(e){let t=new Date(e),r=Math.floor((new Date().getTime()-t.getTime())/6e4);return r<1?"just now":r<60?"".concat(r,"m ago"):r<1440?"".concat(Math.floor(r/60),"h ago"):t.toLocaleDateString()}(t.timestamp),h=t.expiresAt?function(e){let t=new Date(e),r=new Date,n=t.getTime()-r.getTime();if(n<=0)return{text:"Expired",urgent:!0};let s=Math.floor(n/6e4);return s<5?{text:"".concat(s,"m left"),urgent:!0}:s<60?{text:"".concat(s,"m left"),urgent:!1}:{text:"".concat(Math.floor(s/60),"h left"),urgent:!1}}(t.expiresAt):null;return(0,n.jsxs)("div",{className:"decision-card ".concat(t.priority),children:[(0,n.jsxs)("div",{className:"decision-card-header",onClick:l,children:[(0,n.jsx)("div",{className:"decision-card-avatar",style:{backgroundColor:u.primary,color:u.text},children:(0,x.hP)(t.agentName)}),(0,n.jsxs)("div",{className:"decision-card-info",children:[(0,n.jsxs)("div",{className:"decision-card-title",children:[(0,n.jsx)("span",{className:"decision-card-agent",children:t.agentName}),(0,n.jsx)("span",{className:"decision-card-type",children:{approval:"Approval",choice:"Choice",confirmation:"Confirm",input:"Input"}[t.type]}),(0,n.jsx)(nq,{priority:t.priority})]}),(0,n.jsx)("div",{className:"decision-card-subtitle",children:t.title})]}),(0,n.jsxs)("div",{className:"decision-card-meta",children:[h&&(0,n.jsx)("span",{className:"decision-card-expires ".concat(h.urgent?"urgent":""),children:h.text}),(0,n.jsx)("span",{className:"decision-card-time",children:m}),(0,n.jsx)(nX,{isExpanded:r})]})]}),r&&(0,n.jsxs)("div",{className:"decision-card-body",children:[(0,n.jsx)("p",{className:"decision-card-desc",children:t.description}),t.context&&Object.keys(t.context).length>0&&(0,n.jsxs)("div",{className:"decision-card-context",children:[(0,n.jsx)("span",{className:"decision-card-context-label",children:"Context"}),(0,n.jsx)("pre",{children:JSON.stringify(t.context,null,2)})]}),"choice"===t.type&&t.options&&(0,n.jsx)("div",{className:"decision-card-options",children:t.options.map(e=>(0,n.jsxs)("button",{className:"decision-card-option",onClick:()=>o(e.id),disabled:s,children:[(0,n.jsx)("span",{className:"decision-option-label",children:e.label}),e.description&&(0,n.jsx)("span",{className:"decision-option-desc",children:e.description})]},e.id))}),"choice"!==t.type&&(0,n.jsxs)("div",{className:"decision-card-actions",children:[(0,n.jsxs)("button",{className:"decision-btn decision-btn-approve",onClick:()=>o(),disabled:s,children:[s?(0,n.jsx)(nQ,{}):(0,n.jsx)(n$,{}),"confirmation"===t.type?"Confirm":"Approve"]}),(0,n.jsxs)("div",{className:"decision-reject-group",children:[(0,n.jsx)("input",{type:"text",className:"decision-reject-input",placeholder:"Reason (optional)",value:a,onChange:e=>c(e.target.value),disabled:s}),(0,n.jsxs)("button",{className:"decision-btn decision-btn-reject",onClick:i,disabled:s,children:[(0,n.jsx)(nY,{}),"Reject"]})]})]}),(0,n.jsx)("button",{className:"decision-card-dismiss",onClick:d,disabled:s,children:"Dismiss without action"})]})]})}function nq(e){let{priority:t}=e;return(0,n.jsx)("span",{className:"decision-priority-badge ".concat(t),children:t})}function nJ(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,n.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}function n$(){return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})})}function nY(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function nX(e){let{isExpanded:t}=e;return(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",style:{transform:t?"rotate(180deg)":"rotate(0deg)",transition:"transform 0.2s"},children:(0,n.jsx)("polyline",{points:"6 9 12 15 18 9"})})}function nQ(){return(0,n.jsx)("svg",{className:"decision-spinner",width:"14",height:"14",viewBox:"0 0 24 24",children:(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function n0(e){var t;let{server:r,isSelected:s=!1,onClick:a,onReconnect:l,compact:o=!1}=e,i=function(e){switch(e){case"online":return"#10b981";case"offline":return"#ef4444";case"degraded":return"#f59e0b";case"connecting":return"#6366f1";default:return"#888888"}}(r.status),c=function(e){switch(e){case"online":return"Online";case"offline":return"Offline";case"degraded":return"Degraded";case"connecting":return"Connecting...";default:return"Unknown"}}(r.status);return o?(0,n.jsxs)("button",{className:"\n flex items-center gap-2 py-2 px-3 bg-bg-tertiary border border-border-subtle rounded-md cursor-pointer font-inherit transition-all duration-150\n hover:bg-bg-hover\n ".concat(s?"bg-bg-elevated border-accent-cyan":"","\n ").concat("offline"===r.status?"opacity-70":"","\n "),onClick:a,children:[(0,n.jsx)("div",{className:"w-2 h-2 rounded-full flex-shrink-0",style:{backgroundColor:i}}),(0,n.jsx)("span",{className:"flex-1 text-sm font-medium text-text-primary text-left",children:r.name}),(0,n.jsx)("span",{className:"text-xs text-text-muted bg-bg-tertiary px-1.5 py-0.5 rounded-full",children:r.agentCount})]}):(0,n.jsxs)("div",{className:"\n bg-bg-card border border-border-subtle rounded-lg p-4 cursor-pointer transition-all duration-150\n hover:border-border-hover hover:shadow-md\n ".concat(s?"border-accent-cyan bg-bg-elevated":"","\n ").concat("offline"===r.status?"opacity-70":"","\n ").concat("degraded"===r.status?"border-l-[3px] border-l-warning":"","\n "),onClick:a,role:a?"button":void 0,tabIndex:a?0:void 0,children:[(0,n.jsxs)("div",{className:"flex items-start justify-between mb-4",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)(n1,{}),(0,n.jsxs)("div",{className:"flex flex-col",children:[(0,n.jsx)("span",{className:"font-semibold text-sm text-text-primary",children:r.name}),r.region&&(0,n.jsx)("span",{className:"text-xs text-text-muted",children:r.region})]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5 text-xs font-medium",style:{color:i},children:[(0,n.jsx)("span",{className:"w-2 h-2 rounded-full flex-shrink-0 ".concat("connecting"===r.status?"animate-pulse":""),style:{backgroundColor:i}}),(0,n.jsx)("span",{children:c})]})]}),(0,n.jsxs)("div",{className:"grid grid-cols-[repeat(auto-fit,minmax(60px,1fr))] gap-3 mb-4",children:[(0,n.jsxs)("div",{className:"flex flex-col items-center text-center",children:[(0,n.jsx)("span",{className:"text-lg font-semibold text-text-primary",children:r.agentCount}),(0,n.jsx)("span",{className:"text-[11px] text-text-muted uppercase tracking-wide",children:"Agents"})]}),void 0!==r.messageRate&&(0,n.jsxs)("div",{className:"flex flex-col items-center text-center",children:[(0,n.jsxs)("span",{className:"text-lg font-semibold text-text-primary",children:[r.messageRate,"/s"]}),(0,n.jsx)("span",{className:"text-[11px] text-text-muted uppercase tracking-wide",children:"Messages"})]}),void 0!==r.latency&&(0,n.jsxs)("div",{className:"flex flex-col items-center text-center",children:[(0,n.jsxs)("span",{className:"text-lg font-semibold text-text-primary",children:[r.latency,"ms"]}),(0,n.jsx)("span",{className:"text-[11px] text-text-muted uppercase tracking-wide",children:"Latency"})]}),void 0!==r.uptime&&(0,n.jsxs)("div",{className:"flex flex-col items-center text-center",children:[(0,n.jsx)("span",{className:"text-lg font-semibold text-text-primary",children:(t=r.uptime)<60?"".concat(t,"s"):t<3600?"".concat(Math.floor(t/60),"m"):t<86400?"".concat(Math.floor(t/3600),"h"):"".concat(Math.floor(t/86400),"d")}),(0,n.jsx)("span",{className:"text-[11px] text-text-muted uppercase tracking-wide",children:"Uptime"})]})]}),(0,n.jsxs)("div",{className:"flex items-center justify-between pt-3 border-t border-border-subtle",children:[(0,n.jsx)("span",{className:"text-[11px] text-text-muted font-mono",children:r.url}),r.version&&(0,n.jsxs)("span",{className:"text-[11px] text-text-muted bg-bg-tertiary px-1.5 py-0.5 rounded",children:["v",r.version]})]}),"offline"===r.status&&l&&(0,n.jsxs)("button",{className:"flex items-center justify-center gap-1.5 w-full mt-3 py-2 px-3 bg-error/10 border border-error/30 rounded-md text-error text-xs font-medium cursor-pointer font-inherit transition-all duration-150 hover:bg-error/20 hover:border-error/50",onClick:e=>{e.stopPropagation(),l()},children:[(0,n.jsx)(n2,{}),"Reconnect"]})]})}function n1(){return(0,n.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("rect",{x:"2",y:"2",width:"20",height:"8",rx:"2",ry:"2"}),(0,n.jsx)("rect",{x:"2",y:"14",width:"20",height:"8",rx:"2",ry:"2"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"6.01",y2:"6"}),(0,n.jsx)("line",{x1:"6",y1:"18",x2:"6.01",y2:"18"})]})}function n2(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("polyline",{points:"23 4 23 10 17 10"}),(0,n.jsx)("polyline",{points:"1 20 1 14 7 14"}),(0,n.jsx)("path",{d:"M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"})]})}function n5(e){let{servers:t,agents:r,selectedServerId:a,onServerSelect:l,onServerReconnect:o,isLoading:i=!1}=e,[c,d]=(0,s.useState)("grid"),u=(0,s.useMemo)(()=>{let e=t.filter(e=>"online"===e.status).length,r=t.reduce((e,t)=>e+t.agentCount,0),n=t.filter(e=>void 0!==e.latency).length>0?Math.round(t.reduce((e,t)=>e+(t.latency||0),0)/t.filter(e=>void 0!==e.latency).length):null,s=t.reduce((e,t)=>e+(t.messageRate||0),0);return{online:e,total:t.length,totalAgents:r,avgLatency:n,totalMessages:s}},[t]),m=(0,s.useMemo)(()=>{let e={};return t.forEach(t=>{e[t.id]=[]}),r.forEach((r,n)=>{let s=n%t.length;t[s]&&e[t[s].id].push(r)}),e},[t,r]);return i?(0,n.jsxs)("div",{className:"bg-bg-card rounded-lg border border-border-subtle overflow-hidden flex flex-col items-center justify-center p-12 text-text-muted text-center",children:[(0,n.jsx)(n9,{}),(0,n.jsx)("span",{className:"mt-3 text-sm",children:"Loading fleet data..."})]}):0===t.length?(0,n.jsxs)("div",{className:"bg-bg-card rounded-lg border border-border-subtle overflow-hidden flex flex-col items-center justify-center p-12 text-text-muted text-center",children:[(0,n.jsx)(n8,{}),(0,n.jsx)("h3",{className:"mt-4 mb-2 text-base font-semibold text-text-primary",children:"No Fleet Servers"}),(0,n.jsx)("p",{className:"text-sm",children:"Connect to peer servers to enable fleet view"})]}):(0,n.jsxs)("div",{className:"bg-bg-card rounded-lg border border-border-subtle overflow-hidden",children:[(0,n.jsxs)("div",{className:"flex items-center gap-6 p-4 border-b border-border-subtle bg-bg-secondary",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2 font-semibold text-sm text-text-primary",children:[(0,n.jsx)(n4,{}),(0,n.jsx)("span",{children:"Fleet Overview"})]}),(0,n.jsxs)("div",{className:"flex gap-6 flex-1",children:[(0,n.jsxs)("div",{className:"flex flex-col items-center",children:[(0,n.jsxs)("span",{className:"text-base font-semibold text-text-primary",children:[u.online,"/",u.total]}),(0,n.jsx)("span",{className:"text-xs text-text-muted uppercase tracking-wide",children:"Servers"})]}),(0,n.jsxs)("div",{className:"flex flex-col items-center",children:[(0,n.jsx)("span",{className:"text-base font-semibold text-text-primary",children:u.totalAgents}),(0,n.jsx)("span",{className:"text-xs text-text-muted uppercase tracking-wide",children:"Agents"})]}),null!==u.avgLatency&&(0,n.jsxs)("div",{className:"flex flex-col items-center",children:[(0,n.jsxs)("span",{className:"text-base font-semibold text-text-primary",children:[u.avgLatency,"ms"]}),(0,n.jsx)("span",{className:"text-xs text-text-muted uppercase tracking-wide",children:"Avg Latency"})]}),(0,n.jsxs)("div",{className:"flex flex-col items-center",children:[(0,n.jsxs)("span",{className:"text-base font-semibold text-text-primary",children:[u.totalMessages,"/s"]}),(0,n.jsx)("span",{className:"text-xs text-text-muted uppercase tracking-wide",children:"Messages"})]})]}),(0,n.jsxs)("div",{className:"flex gap-1 bg-bg-tertiary rounded-md p-0.5",children:[(0,n.jsx)("button",{className:"flex items-center justify-center w-7 h-7 bg-transparent border-none rounded cursor-pointer transition-all duration-150 ".concat("grid"===c?"bg-bg-card text-text-primary shadow-sm":"text-text-muted hover:text-text-secondary"),onClick:()=>d("grid"),title:"Grid view",children:(0,n.jsx)(n3,{})}),(0,n.jsx)("button",{className:"flex items-center justify-center w-7 h-7 bg-transparent border-none rounded cursor-pointer transition-all duration-150 ".concat("list"===c?"bg-bg-card text-text-primary shadow-sm":"text-text-muted hover:text-text-secondary"),onClick:()=>d("list"),title:"List view",children:(0,n.jsx)(n6,{})})]})]}),(0,n.jsx)("div",{className:"flex h-1 bg-bg-tertiary",children:t.map(e=>(0,n.jsx)("div",{className:"transition-all duration-300 ".concat({online:"bg-success",offline:"bg-error",degraded:"bg-warning",connecting:"bg-accent-purple"}[e.status]||"bg-text-dim"),style:{flex:e.agentCount||1},title:"".concat(e.name,": ").concat(e.agentCount," agents")},e.id))}),(0,n.jsx)("div",{className:"p-4 ".concat("grid"===c?"grid grid-cols-[repeat(auto-fill,minmax(280px,1fr))] gap-4":"flex flex-col gap-2"),children:t.map(e=>{var t;return(0,n.jsxs)("div",{className:"flex flex-col gap-2",children:[(0,n.jsx)(n0,{server:e,isSelected:e.id===a,onClick:()=>null==l?void 0:l(e.id),onReconnect:()=>null==o?void 0:o(e.id),compact:"list"===c}),"grid"===c&&(null===(t=m[e.id])||void 0===t?void 0:t.length)>0&&(0,n.jsxs)("div",{className:"flex gap-1 px-2",children:[m[e.id].slice(0,5).map((e,t)=>{let r=(0,x.GW)(e.name);return(0,n.jsx)("div",{className:"w-6 h-6 rounded-md flex items-center justify-center text-[9px] font-semibold border-2 border-bg-card",style:{backgroundColor:r.primary,color:r.text,marginLeft:t>0?"-4px":0},title:e.name,children:(0,x.hP)(e.name)},e.name)}),m[e.id].length>5&&(0,n.jsxs)("div",{className:"w-6 h-6 rounded-md flex items-center justify-center text-[9px] font-semibold bg-bg-tertiary text-text-muted border-2 border-bg-card",style:{marginLeft:"-4px"},children:["+",m[e.id].length-5]})]})]},e.id)})})]})}function n4(){return(0,n.jsxs)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"}),(0,n.jsx)("line",{x1:"8",y1:"21",x2:"16",y2:"21"}),(0,n.jsx)("line",{x1:"12",y1:"17",x2:"12",y2:"21"})]})}function n3(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"7",height:"7"}),(0,n.jsx)("rect",{x:"14",y:"3",width:"7",height:"7"}),(0,n.jsx)("rect",{x:"3",y:"14",width:"7",height:"7"}),(0,n.jsx)("rect",{x:"14",y:"14",width:"7",height:"7"})]})}function n6(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("line",{x1:"8",y1:"6",x2:"21",y2:"6"}),(0,n.jsx)("line",{x1:"8",y1:"12",x2:"21",y2:"12"}),(0,n.jsx)("line",{x1:"8",y1:"18",x2:"21",y2:"18"}),(0,n.jsx)("line",{x1:"3",y1:"6",x2:"3.01",y2:"6"}),(0,n.jsx)("line",{x1:"3",y1:"12",x2:"3.01",y2:"12"}),(0,n.jsx)("line",{x1:"3",y1:"18",x2:"3.01",y2:"18"})]})}function n8(){return(0,n.jsxs)("svg",{width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[(0,n.jsx)("rect",{x:"2",y:"2",width:"20",height:"8",rx:"2",ry:"2"}),(0,n.jsx)("rect",{x:"2",y:"14",width:"20",height:"8",rx:"2",ry:"2"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"6.01",y2:"6"}),(0,n.jsx)("line",{x1:"6",y1:"18",x2:"6.01",y2:"18"})]})}function n9(){return(0,n.jsx)("svg",{className:"animate-spin",width:"24",height:"24",viewBox:"0 0 24 24",children:(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function n7(e){let{typingUsers:t}=e;return 0===t.length?null:(0,n.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2 text-sm text-[#8d8d8e]",children:[(0,n.jsx)("div",{className:"flex -space-x-1.5",children:t.slice(0,3).map(e=>(0,n.jsx)("div",{className:"relative",title:e.username,children:e.avatarUrl?(0,n.jsx)("img",{src:e.avatarUrl,alt:e.username,className:"w-5 h-5 rounded-full border border-[#1a1d21]"}):(0,n.jsx)("div",{className:"w-5 h-5 rounded-full bg-[#a855f7] border border-[#1a1d21] flex items-center justify-center text-[9px] text-white font-medium",children:e.username.charAt(0).toUpperCase()})},e.username))}),(0,n.jsxs)("span",{className:"flex items-center gap-1",children:[1===t.length?"".concat(t[0].username," is typing"):2===t.length?"".concat(t[0].username," and ").concat(t[1].username," are typing"):"".concat(t[0].username," and ").concat(t.length-1," others are typing"),(0,n.jsxs)("span",{className:"flex gap-0.5",children:[(0,n.jsx)("span",{className:"w-1 h-1 bg-[#8d8d8e] rounded-full animate-bounce",style:{animationDelay:"0ms"}}),(0,n.jsx)("span",{className:"w-1 h-1 bg-[#8d8d8e] rounded-full animate-bounce",style:{animationDelay:"150ms"}}),(0,n.jsx)("span",{className:"w-1 h-1 bg-[#8d8d8e] rounded-full animate-bounce",style:{animationDelay:"300ms"}})]})]})]})}function se(e,t){let r=e.substring(0,t).match(/(?:^|[\s(])@(\S*)$/);return r?r[1]:null}function st(e,t,r){let n=e.substring(0,r),s=e.substring(r),a=n.match(/(?:^|[\s(])@(\S*)$/);if(a){let r=a.index||0,n=a[0].charAt(0),l=e.substring(0,"@"===n?r:r+1),o="@".concat(t," "),i=l.length+o.length;return{value:l+o+s,cursorPosition:i}}return{value:e,cursorPosition:r}}function sr(e){let{agents:t,humanUsers:r=[],inputValue:a,cursorPosition:l,onSelect:o,onClose:i,isVisible:c}=e,[d,u]=(0,s.useState)(0),m=(0,s.useRef)(null),h=(0,s.useMemo)(()=>se(a,l),[a,l]),p=(0,s.useMemo)(()=>{let e=new Map;return t.forEach(t=>{if(t.team){let r=e.get(t.team)||[];r.push(t),e.set(t.team,r)}}),e},[t]),g=(0,s.useMemo)(()=>{if(null===h)return[];let e=h.toLowerCase(),n=[];("*".includes(e)||"everyone".includes(e)||"all".includes(e)||"broadcast".includes(e)||""===e)&&n.push({name:"*",displayName:"@everyone",description:"Broadcast to all agents",isBroadcast:!0});let s=e.startsWith("team:")||e.startsWith("team"),a=e.startsWith("team:")?e.substring(5):e.replace(/^team/,"");(s||""===e)&&p.forEach((t,r)=>{let s=r.toLowerCase();(""===a||s.includes(a)||"team:".concat(s).includes(e))&&n.push({name:"team:".concat(r),displayName:"@team:".concat(r),description:"".concat(t.length," agent").concat(1!==t.length?"s":"",": ").concat(t.map(e=>e.name).join(", ")),isTeam:!0,memberCount:t.length})});let l=new Set(t.map(e=>e.name.toLowerCase()));return r.filter(t=>{let r=t.username.toLowerCase();return r.includes(e)&&!l.has(r)}).forEach(e=>{n.push({name:e.username,displayName:"@".concat(e.username),description:"Human user",isHuman:!0,avatarUrl:e.avatarUrl})}),t.filter(t=>t.name.toLowerCase().includes(e)).forEach(e=>{n.push({name:e.name,displayName:"@".concat(e.name),description:e.team?"".concat(e.status||"Agent"," \xb7 ").concat(e.team):e.status||"Agent"})}),n},[h,t,r,p]);(0,s.useEffect)(()=>{u(0)},[g.length]),(0,s.useEffect)(()=>{if(!m.current)return;let e=m.current.querySelector('[data-selected="true"]');e&&e.scrollIntoView({block:"nearest"})},[d]);let f=(0,s.useCallback)(e=>{if(c&&0!==g.length)switch(e.key){case"ArrowDown":e.preventDefault(),u(e=>(e+1)%g.length);break;case"ArrowUp":e.preventDefault(),u(e=>(e-1+g.length)%g.length);break;case"Enter":case"Tab":e.preventDefault();let t=g[d];if(t){let e=st(a,t.name,l);o(t.name,e.value)}break;case"Escape":e.preventDefault(),i()}},[c,g,d,a,l,o,i]);(0,s.useEffect)(()=>{if(c)return window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)},[c,f]);let b=(0,s.useCallback)(e=>{let t=st(a,e.name,l);o(e.name,t.value)},[a,l,o]);return c&&0!==g.length?(0,n.jsx)("div",{className:"absolute bottom-full left-0 right-0 max-h-[200px] overflow-y-auto bg-bg-card border border-border rounded-lg shadow-modal z-[100] mb-1",ref:m,children:g.map((e,t)=>(0,n.jsxs)("div",{"data-selected":t===d,className:"flex items-center gap-2.5 py-2 px-3 cursor-pointer transition-colors duration-150 ".concat(t===d?"bg-bg-hover":"hover:bg-bg-hover"),onClick:()=>b(e),onMouseEnter:()=>u(t),children:[e.isHuman&&e.avatarUrl?(0,n.jsx)("img",{src:e.avatarUrl,alt:e.name,className:"w-7 h-7 rounded-md object-cover"}):(0,n.jsx)("div",{className:"w-7 h-7 rounded-md flex items-center justify-center text-white text-[11px] font-semibold",style:{background:e.isBroadcast?"var(--color-warning, #f59e0b)":e.isTeam?"var(--color-accent-purple, #a855f7)":e.isHuman?"#a855f7":(0,x.GW)(e.name).primary},children:e.isBroadcast?"*":e.isTeam?(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),(0,n.jsx)("circle",{cx:"9",cy:"7",r:"4"}),(0,n.jsx)("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),(0,n.jsx)("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]}):e.isHuman?(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("path",{d:"M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"}),(0,n.jsx)("circle",{cx:"12",cy:"7",r:"4"})]}):(0,x.hP)(e.name)}),(0,n.jsxs)("div",{className:"flex flex-col gap-0.5 min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-text-primary",children:e.displayName}),(0,n.jsx)("span",{className:"text-xs text-text-muted truncate",children:e.description})]})]},e.name))}):null}function sn(e,t){let r=e.substring(0,t).match(/(?:^|[\s(])@(\S*)$/);if(r){let e=r[1];if(e.includes("/")||/\.[a-zA-Z0-9]{1,10}$/.test(e))return e}return null}function ss(e,t,r){let n=e.substring(0,r),s=e.substring(r),a=n.match(/(?:^|[\s(])@(\S*)$/);if(a){let r=a.index||0,n=a[0].charAt(0);return e.substring(0,"@"===n?r:r+1)+"@".concat(t," ")+s}return e}let sa=new Map;function sl(e){let{inputValue:t,cursorPosition:r,onSelect:a,onClose:l,isVisible:o,apiBase:i=""}=e,[c,d]=(0,s.useState)(0),[u,x]=(0,s.useState)([]),[m,h]=(0,s.useState)(!1),[p,g]=(0,s.useState)(null),f=(0,s.useRef)(null),b=(0,s.useRef)(null),v=(0,s.useMemo)(()=>sn(t,r),[t,r]);(0,s.useEffect)(()=>{if(!o||null===v){x([]);return}let e=v||"__root__",t=sa.get(e);if(t&&Date.now()-t.timestamp<3e4){x(t.files),g(null);return}b.current&&b.current.abort();let r=new AbortController;b.current=r;let n=setTimeout(async()=>{h(!0),g(null);try{let t=v||"",n=i?"".concat(i,"/api/files?q=").concat(encodeURIComponent(t),"&limit=15"):(0,r_.kG)("/api/files?q=".concat(encodeURIComponent(t),"&limit=15")),s=await fetch(n,{signal:r.signal});if(!s.ok)throw Error("Failed to fetch files");let a=((await s.json()).files||[]).map(e=>({path:e.path,name:e.name,isDirectory:e.isDirectory||!1}));sa.set(e,{files:a,timestamp:Date.now()}),x(a)}catch(e){if(e instanceof Error&&"AbortError"===e.name)return;g("Failed to load files"),x([])}finally{h(!1)}},150);return()=>{clearTimeout(n),r.abort()}},[o,v,i]),(0,s.useEffect)(()=>{d(0)},[u.length]),(0,s.useEffect)(()=>{if(!f.current)return;let e=f.current.querySelector('[data-selected="true"]');e&&e.scrollIntoView({block:"nearest"})},[c]);let y=(0,s.useCallback)(e=>{if(o&&0!==u.length)switch(e.key){case"ArrowDown":e.preventDefault(),d(e=>(e+1)%u.length);break;case"ArrowUp":e.preventDefault(),d(e=>(e-1+u.length)%u.length);break;case"Enter":case"Tab":e.preventDefault();let n=u[c];if(n){let e=ss(t,n.path,r);a(n.path,e)}break;case"Escape":e.preventDefault(),l()}},[o,u,c,t,r,a,l]);(0,s.useEffect)(()=>{if(o)return window.addEventListener("keydown",y),()=>window.removeEventListener("keydown",y)},[o,y]);let j=(0,s.useCallback)(e=>{let n=ss(t,e.path,r);a(e.path,n)},[t,r,a]);return o&&(0!==u.length||m||p)?(0,n.jsxs)("div",{className:"absolute bottom-full left-0 right-0 max-h-[240px] overflow-y-auto bg-bg-card border border-border rounded-lg shadow-modal z-[100] mb-1",ref:f,children:[(0,n.jsxs)("div",{className:"px-3 py-1.5 text-[10px] uppercase tracking-wider text-text-muted border-b border-border-subtle flex items-center gap-2",children:[(0,n.jsxs)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("path",{d:"M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"}),(0,n.jsx)("polyline",{points:"13 2 13 9 20 9"})]}),"Files ",v&&(0,n.jsxs)("span",{className:"text-text-dim",children:['matching "',v,'"']})]}),m&&0===u.length&&(0,n.jsxs)("div",{className:"px-3 py-4 text-sm text-text-muted text-center",children:[(0,n.jsx)("svg",{className:"animate-spin mx-auto mb-2",width:"16",height:"16",viewBox:"0 0 24 24",children:(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})}),"Searching files..."]}),p&&(0,n.jsx)("div",{className:"px-3 py-4 text-sm text-red-400 text-center",children:p}),u.map((e,t)=>(0,n.jsxs)("div",{"data-selected":t===c,className:"flex items-center gap-2.5 py-2 px-3 cursor-pointer transition-colors duration-150 ".concat(t===c?"bg-bg-hover":"hover:bg-bg-hover"),onClick:()=>j(e),onMouseEnter:()=>d(t),children:[(0,n.jsx)("div",{className:"w-7 h-7 rounded-md flex items-center justify-center text-text-muted",style:{background:e.isDirectory?"rgba(251, 191, 36, 0.15)":"rgba(96, 165, 250, 0.15)"},children:e.isDirectory?(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#fbbf24",strokeWidth:"2",children:(0,n.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"})}):(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"#60a5fa",strokeWidth:"2",children:[(0,n.jsx)("path",{d:"M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"}),(0,n.jsx)("polyline",{points:"13 2 13 9 20 9"})]})}),(0,n.jsxs)("div",{className:"flex flex-col gap-0.5 min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"text-sm font-medium text-text-primary truncate",children:e.name}),(0,n.jsx)("span",{className:"text-xs text-text-dim truncate",children:e.path})]})]},e.path)),!m&&!p&&0===u.length&&v&&(0,n.jsxs)("div",{className:"px-3 py-4 text-sm text-text-muted text-center",children:['No files found matching "',v,'"']})]}):null}function so(e){let{onSend:t,onTyping:r,isSending:a=!1,disabled:l=!1,placeholder:o="Type a message...",error:i,agents:c=[],humanUsers:d=[],enableFileAutocomplete:u=!1,insertMention:x,onMentionInserted:m,className:h=""}=e,[p,g]=(0,s.useState)(""),[f,b]=(0,s.useState)(0),[v,y]=(0,s.useState)(!1),[j,w]=(0,s.useState)(!1),[N,k]=(0,s.useState)([]),C=(0,s.useRef)(null),S=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(x&&m){let e="@".concat(x," "),t=C.current;if(t){let r=t.selectionStart||p.length;g(p.slice(0,r)+e+p.slice(r)),setTimeout(()=>{t.focus();let n=r+e.length;t.setSelectionRange(n,n)},0)}else g(t=>t+e);m()}},[x,m,p]);let L=(0,s.useCallback)(async e=>{for(let t of e){let e=crypto.randomUUID(),r=URL.createObjectURL(t);k(n=>[...n,{id:e,file:t,preview:r,isUploading:!0}]);try{let r=await r_.hi.uploadAttachment(t);r.success&&r.data?k(t=>t.map(t=>t.id===e?{...t,isUploading:!1,uploadedId:r.data.attachment.id}:t)):k(t=>t.map(t=>t.id===e?{...t,isUploading:!1,error:r.error||"Upload failed"}:t))}catch(t){k(t=>t.map(t=>t.id===e?{...t,isUploading:!1,error:"Upload failed"}:t))}}},[]),M=(0,s.useCallback)(e=>{if(!e||0===e.length)return;let t=Array.from(e).filter(e=>e.type.startsWith("image/"));t.length>0&&L(t)},[L]),D=(0,s.useCallback)(e=>{let t=e.clipboardData;if(!t)return;let r=[];if(t.files&&t.files.length>0&&(r=Array.from(t.files).filter(e=>e.type.startsWith("image/"))),0===r.length&&t.items){for(let e of Array.from(t.items))if("file"===e.kind&&e.type.startsWith("image/")){let t=e.getAsFile();t&&r.push(t)}}r.length>0&&(e.preventDefault(),L(r))},[L]),A=(0,s.useCallback)(e=>{k(t=>{let r=t.find(t=>t.id===e);return r&&URL.revokeObjectURL(r.preview),t.filter(t=>t.id!==e)})},[]),E=async e=>{e.preventDefault();let r=p.trim().length>0,n=N.length>0;if(!r&&!n||a||l||N.some(e=>e.isUploading))return;let s=N.filter(e=>e.uploadedId).map(e=>e.uploadedId),o=p.trim();!o&&s.length>0&&(o="[Screenshot attached]"),await t(o,s.length>0?s:void 0)&&(N.forEach(e=>URL.revokeObjectURL(e.preview)),g(""),k([]),y(!1),w(!1))},T=(p.trim()||N.length>0)&&!a&&!l&&!N.some(e=>e.isUploading);return(0,n.jsxs)("form",{className:"flex flex-col gap-1.5 sm:gap-2 ".concat(h),onSubmit:E,children:[N.length>0&&(0,n.jsx)("div",{className:"flex flex-wrap gap-1.5 sm:gap-2 p-1.5 sm:p-2 bg-bg-card rounded-lg border border-border-subtle",children:N.map(e=>(0,n.jsxs)("div",{className:"relative group",children:[(0,n.jsx)("img",{src:e.preview,alt:e.file.name,className:"h-16 w-auto rounded-lg object-cover ".concat(e.isUploading?"opacity-50":""," ").concat(e.error?"border-2 border-error":"")}),e.isUploading&&(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,n.jsx)("svg",{className:"animate-spin h-5 w-5 text-accent-cyan",viewBox:"0 0 24 24",children:(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}),e.error&&(0,n.jsx)("div",{className:"absolute bottom-0 left-0 right-0 bg-error/90 text-white text-[10px] px-1 py-0.5 truncate",children:e.error}),(0,n.jsx)("button",{type:"button",onClick:()=>A(e.id),className:"absolute -top-1.5 -right-1.5 w-5 h-5 bg-bg-tertiary border border-border-subtle rounded-full flex items-center justify-center text-text-muted hover:text-error hover:border-error transition-colors opacity-0 group-hover:opacity-100",title:"Remove",children:(0,n.jsxs)("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:[(0,n.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]},e.id))}),(0,n.jsxs)("div",{className:"flex items-center gap-1.5 sm:gap-3",children:[(0,n.jsx)("input",{ref:S,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:e=>M(e.target.files)}),(0,n.jsx)("button",{type:"button",onClick:()=>{var e;return null===(e=S.current)||void 0===e?void 0:e.click()},disabled:l,className:"p-2 sm:p-2.5 bg-bg-card border border-border-subtle rounded-lg sm:rounded-xl text-text-muted hover:text-accent-cyan hover:border-accent-cyan/50 transition-colors flex-shrink-0 disabled:opacity-50 disabled:cursor-not-allowed",title:"Attach screenshot (or paste from clipboard)",children:(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"sm:w-[18px] sm:h-[18px]",children:[(0,n.jsx)("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",ry:"2"}),(0,n.jsx)("circle",{cx:"8.5",cy:"8.5",r:"1.5"}),(0,n.jsx)("polyline",{points:"21 15 16 10 5 21"})]})}),(0,n.jsxs)("div",{className:"flex-1 relative min-w-0",children:[(c.length>0||d.length>0)&&(0,n.jsx)(sr,{agents:c,humanUsers:d,inputValue:p,cursorPosition:f,onSelect:(e,t)=>{g(t),y(!1),w(!1),setTimeout(()=>{if(C.current){C.current.focus();let e=t.indexOf(" ")+1;C.current.setSelectionRange(e,e)}},0)},onClose:()=>y(!1),isVisible:v}),u&&(0,n.jsx)(sl,{inputValue:p,cursorPosition:f,onSelect:(e,t)=>{g(t),w(!1),y(!1),setTimeout(()=>{if(C.current){C.current.focus();let e=t.indexOf(" ",1)+1;C.current.setSelectionRange(e,e)}},0)},onClose:()=>w(!1),isVisible:j}),(0,n.jsx)("textarea",{ref:C,className:"w-full py-2 sm:py-3 px-3 sm:px-4 bg-bg-card border border-border-subtle rounded-lg sm:rounded-xl text-sm font-sans text-text-primary outline-none transition-all duration-200 resize-none min-h-[40px] sm:min-h-[44px] max-h-[100px] sm:max-h-[120px] overflow-y-auto focus:border-accent-cyan/50 focus:shadow-[0_0_0_3px_rgba(0,217,255,0.1)] placeholder:text-text-muted disabled:opacity-50 disabled:cursor-not-allowed",placeholder:o,value:p,onChange:e=>{let t=e.target.value,n=e.target.selectionStart||0;if(g(t),b(n),null==r||r(t.trim().length>0),u&&null!==sn(t,n)){w(!0),y(!1);return}if((c.length>0||d.length>0)&&null!==se(t,n)){y(!0),w(!1);return}y(!1),w(!1)},onKeyDown:e=>{if(!v&&!j||"ArrowDown"!==e.key&&"ArrowUp"!==e.key&&"Tab"!==e.key){if("Enter"===e.key&&e.altKey&&!v&&!j){e.preventDefault();let t=e.currentTarget,r=t.selectionStart,n=t.selectionEnd;g(p.slice(0,r)+"\n"+p.slice(n)),setTimeout(()=>{t.selectionStart=t.selectionEnd=r+1},0);return}"Enter"!==e.key||e.shiftKey||e.altKey||v||j||(e.preventDefault(),(p.trim()||N.length>0)&&!a&&!l&&E(e))}},onPaste:D,onSelect:e=>b(e.target.selectionStart||0),disabled:l||a,rows:1})]}),(0,n.jsx)("button",{type:"submit",className:"py-2 sm:py-3 px-3 sm:px-5 bg-gradient-to-r from-accent-cyan to-[#00b8d9] text-bg-deep font-semibold border-none rounded-lg sm:rounded-xl text-xs sm:text-sm cursor-pointer transition-all duration-150 hover:shadow-glow-cyan hover:-translate-y-0.5 disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:translate-y-0 disabled:hover:shadow-none flex-shrink-0",disabled:!T,title:a?"Sending...":N.some(e=>e.isUploading)?"Uploading...":"Send message",children:a?(0,n.jsx)("span",{className:"hidden sm:inline",children:"Sending..."}):N.some(e=>e.isUploading)?(0,n.jsx)("span",{className:"hidden sm:inline",children:"Uploading..."}):(0,n.jsxs)("span",{className:"flex items-center gap-1 sm:gap-2",children:[(0,n.jsx)("span",{className:"hidden sm:inline",children:"Send"}),(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),(0,n.jsx)("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})]})}),i&&(0,n.jsx)("span",{className:"text-error text-xs ml-2",children:i})]}),(0,n.jsxs)("p",{className:"text-xs text-text-muted px-1",children:[(0,n.jsx)("kbd",{className:"px-1 py-0.5 bg-bg-tertiary rounded text-[10px]",children:"Enter"})," to send,"," ",(0,n.jsx)("kbd",{className:"px-1 py-0.5 bg-bg-tertiary rounded text-[10px]",children:"Shift/Option+Enter"})," for new line",(c.length>0||d.length>0)&&(0,n.jsxs)(n.Fragment,{children:[", ",(0,n.jsx)("kbd",{className:"px-1 py-0.5 bg-bg-tertiary rounded text-[10px]",children:"@"})," to mention"]})]})]})}function si(e){let{onlineUsers:t,onUserClick:r,maxAvatars:a=4}=e,[l,o]=(0,s.useState)(!1),i=(0,s.useRef)(null);if((0,s.useEffect)(()=>{let e=e=>{i.current&&!i.current.contains(e.target)&&o(!1)};return l&&document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[l]),0===t.length)return null;let c=t.slice(0,a),d=Math.max(0,t.length-a);return(0,n.jsxs)("div",{className:"relative",ref:i,children:[(0,n.jsxs)("button",{onClick:()=>o(!l),className:"flex items-center gap-1.5 px-2 py-1 rounded-md hover:bg-white/[0.05] transition-colors",title:"".concat(t.length," user").concat(1!==t.length?"s":""," online"),children:[(0,n.jsx)("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),(0,n.jsxs)("div",{className:"flex -space-x-1.5",children:[c.map(e=>(0,n.jsx)("div",{className:"relative ring-2 ring-[#1a1d21] rounded-full",title:e.username,children:e.avatarUrl?(0,n.jsx)("img",{src:e.avatarUrl,alt:e.username,className:"w-6 h-6 rounded-full object-cover"}):(0,n.jsx)("div",{className:"w-6 h-6 rounded-full bg-[#a855f7] flex items-center justify-center text-[10px] text-white font-medium",children:e.username.charAt(0).toUpperCase()})},e.username)),d>0&&(0,n.jsxs)("div",{className:"w-6 h-6 rounded-full bg-[#3d4043] ring-2 ring-[#1a1d21] flex items-center justify-center text-[10px] text-[#d1d2d3] font-medium",children:["+",d]})]}),(0,n.jsxs)("span",{className:"text-xs text-[#8d8d8e]",children:[t.length," online"]})]}),l&&(0,n.jsxs)("div",{className:"absolute right-0 top-full mt-1 w-64 bg-[#1a1d21] border border-white/10 rounded-lg shadow-xl z-50 max-h-[300px] overflow-y-auto",children:[(0,n.jsx)("div",{className:"p-2 border-b border-white/10",children:(0,n.jsx)("h3",{className:"text-sm font-medium text-[#d1d2d3]",children:"Online Users"})}),(0,n.jsx)("div",{className:"py-1",children:t.map(e=>(0,n.jsxs)("button",{onClick:()=>{null==r||r(e),o(!1)},className:"w-full flex items-center gap-3 px-3 py-2 hover:bg-white/[0.05] transition-colors text-left",children:[(0,n.jsxs)("div",{className:"relative",children:[e.avatarUrl?(0,n.jsx)("img",{src:e.avatarUrl,alt:e.username,className:"w-8 h-8 rounded-full object-cover"}):(0,n.jsx)("div",{className:"w-8 h-8 rounded-full bg-[#a855f7] flex items-center justify-center text-xs text-white font-medium",children:e.username.charAt(0).toUpperCase()}),(0,n.jsx)("div",{className:"absolute -bottom-0.5 -right-0.5 w-3 h-3 bg-green-500 rounded-full border-2 border-[#1a1d21]"})]}),(0,n.jsxs)("div",{className:"flex-1 min-w-0",children:[(0,n.jsx)("div",{className:"text-sm font-medium text-[#d1d2d3] truncate",children:e.username}),(0,n.jsxs)("div",{className:"text-xs text-[#8d8d8e]",children:["Online since ",function(e){let t=new Date(e),r=new Date;return t.toDateString()===r.toDateString()?t.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):t.toLocaleDateString([],{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}(e.connectedAt)]})]})]},e.username))})]})]})}function sc(e){let{user:t,onClose:r,onMention:a,onSendMessage:l}=e,o=(0,s.useRef)(null);(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&r()};return t&&window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[t,r]);let i=(0,s.useRef)(!1);if((0,s.useEffect)(()=>{t&&(i.current=!0)},[t]),(0,s.useEffect)(()=>{let e=e=>{if(i.current){i.current=!1;return}o.current&&!o.current.contains(e.target)&&r()};if(t)return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[t,r]),!t)return null;let c="https://github.com/".concat(t.username);return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"fixed inset-0 bg-black/50 z-40"}),(0,n.jsxs)("div",{ref:o,className:"fixed right-0 top-0 h-full w-80 bg-[#1a1d21] border-l border-white/10 shadow-2xl z-50 flex flex-col animate-slide-in-right",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between p-4 border-b border-white/10",children:[(0,n.jsx)("h2",{className:"text-lg font-semibold text-[#d1d2d3]",children:"Profile"}),(0,n.jsx)("button",{onClick:r,className:"p-1 hover:bg-white/10 rounded-md transition-colors",title:"Close",children:(0,n.jsx)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.jsx)("path",{d:"M18 6L6 18M6 6l12 12"})})})]}),(0,n.jsxs)("div",{className:"flex flex-col items-center p-6 border-b border-white/10",children:[(0,n.jsxs)("div",{className:"relative mb-4",children:[t.avatarUrl?(0,n.jsx)("img",{src:t.avatarUrl,alt:t.username,className:"w-24 h-24 rounded-full object-cover border-4 border-[#a855f7]/30"}):(0,n.jsx)("div",{className:"w-24 h-24 rounded-full bg-[#a855f7] flex items-center justify-center text-3xl text-white font-bold border-4 border-[#a855f7]/30",children:t.username.charAt(0).toUpperCase()}),(0,n.jsx)("div",{className:"absolute bottom-1 right-1 w-5 h-5 bg-green-500 rounded-full border-4 border-[#1a1d21]"})]}),(0,n.jsx)("h3",{className:"text-xl font-semibold text-[#d1d2d3] mb-1",children:t.username}),(0,n.jsxs)("span",{className:"text-sm text-green-400 flex items-center gap-1.5",children:[(0,n.jsx)("div",{className:"w-2 h-2 bg-green-500 rounded-full"}),"Online"]})]}),(0,n.jsx)("div",{className:"flex-1 p-4 overflow-y-auto",children:(0,n.jsxs)("div",{className:"space-y-4",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-[#8d8d8e] uppercase tracking-wide",children:"Online Since"}),(0,n.jsx)("p",{className:"text-sm text-[#d1d2d3] mt-1",children:sd(t.connectedAt)})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-[#8d8d8e] uppercase tracking-wide",children:"Last Active"}),(0,n.jsx)("p",{className:"text-sm text-[#d1d2d3] mt-1",children:sd(t.lastSeen)})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-[#8d8d8e] uppercase tracking-wide",children:"GitHub"}),(0,n.jsxs)("a",{href:c,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 mt-1 text-sm text-[#a855f7] hover:text-[#c084fc] transition-colors",children:[(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0024 12c0-6.63-5.37-12-12-12z"})}),"@",t.username,(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.jsx)("path",{d:"M18 13v6a2 2 0 01-2 2H5a2 2 0 01-2-2V8a2 2 0 012-2h6M15 3h6v6M10 14L21 3"})})]})]})]})}),(0,n.jsxs)("div",{className:"p-4 border-t border-white/10 space-y-2",children:[(0,n.jsxs)("button",{onClick:()=>{null==l||l(t),r()},className:"w-full flex items-center justify-center gap-2 py-2.5 bg-[#00d4aa] hover:bg-[#00bfa0] text-[#0a0e14] font-medium rounded-lg transition-colors",children:[(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.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"})}),"Send Message"]}),(0,n.jsxs)("button",{onClick:()=>{null==a||a(t.username),r()},className:"w-full flex items-center justify-center gap-2 py-2.5 bg-[#a855f7] hover:bg-[#9333ea] text-white font-medium rounded-lg transition-colors",children:[(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"4"}),(0,n.jsx)("path",{d:"M16 8v5a3 3 0 006 0v-1a10 10 0 10-3.92 7.94"})]}),"Mention @",t.username]}),(0,n.jsxs)("a",{href:c,target:"_blank",rel:"noopener noreferrer",className:"w-full flex items-center justify-center gap-2 py-2.5 border border-white/20 text-[#d1d2d3] hover:bg-white/5 font-medium rounded-lg transition-colors",children:[(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"currentColor",children:(0,n.jsx)("path",{d:"M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0024 12c0-6.63-5.37-12-12-12z"})}),"View on GitHub"]})]})]})]})}function sd(e){return new Date(e).toLocaleString([],{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})}let su={claude:{label:"Claude",color:"#00d9ff",icon:"\uD83E\uDD16"},codex:{label:"Codex",color:"#10a37f",icon:"\uD83E\uDDE0"},gemini:{label:"Gemini",color:"#4285f4",icon:"✨"},droid:{label:"Droid",color:"#ff6b35",icon:"\uD83E\uDD16"},opencode:{label:"OpenCode",color:"#a855f7",icon:"\uD83D\uDCBB"},cursor:{label:"Cursor",color:"#00b4d8",icon:"\uD83D\uDDB1️"},other:{label:"AI Agent",color:"#8d8d8e",icon:"\uD83E\uDD16"}},sx={agent:"cursor"};function sm(e){var t;let{agent:r,onClose:a,onMessage:l,onLogs:o,onRelease:i,summary:c}=e,d=(0,s.useRef)(null),[u,m]=(0,s.useState)(!1),[g,f]=(0,s.useState)(!1);(0,s.useEffect)(()=>{let e=e=>{"Escape"===e.key&&a()};return r&&window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[r,a]);let b=(0,s.useRef)(!1);if((0,s.useEffect)(()=>{r&&(b.current=!0,m(!1),f(!1))},[r]),(0,s.useEffect)(()=>{let e=e=>{if(b.current){b.current=!1;return}d.current&&!d.current.contains(e.target)&&a()};if(r)return document.addEventListener("mousedown",e),()=>{document.removeEventListener("mousedown",e)}},[r,a]),!r)return null;let v=(0,x.GW)(r.name),y=(0,x.hP)(r.name),j=h(r.name),w=p(r.name),N=x.yh[r.status]||x.yh.offline,k="online"===r.status,C=r.profile;return(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"fixed inset-0 bg-black/50 z-40"}),(0,n.jsxs)("div",{ref:d,className:"fixed right-0 top-0 h-full w-96 bg-[#1a1d21] border-l border-white/10 shadow-2xl z-50 flex flex-col animate-slide-in-right",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between p-4 border-b border-white/10",children:[(0,n.jsx)("h2",{className:"text-lg font-semibold text-[#d1d2d3]",children:"Agent Profile"}),(0,n.jsx)("button",{onClick:a,className:"p-1 hover:bg-white/10 rounded-md transition-colors text-[#d1d2d3]",title:"Close",children:(0,n.jsx)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.jsx)("path",{d:"M18 6L6 18M6 6l12 12"})})})]}),(0,n.jsxs)("div",{className:"flex flex-col items-center p-6 border-b border-white/10",children:[(0,n.jsxs)("div",{className:"relative mb-4",children:[(0,n.jsx)("div",{className:"w-24 h-24 rounded-2xl flex items-center justify-center text-3xl font-bold shadow-lg",style:{background:"linear-gradient(135deg, ".concat(v.primary,", ").concat(v.primary,"99)"),boxShadow:k?"0 4px 20px ".concat(v.primary,"50"):"none"},children:(0,n.jsx)("span",{style:{color:v.text},children:y})}),(0,n.jsx)("div",{className:"absolute bottom-1 right-1 w-5 h-5 rounded-full border-4 border-[#1a1d21] ".concat(k?"animate-pulse":""),style:{backgroundColor:N,boxShadow:k?"0 0 8px ".concat(N):"none"}})]}),(0,n.jsx)("h3",{className:"text-xl font-semibold text-[#d1d2d3] mb-1",children:j}),w&&(0,n.jsx)("span",{className:"text-sm text-[#8d8d8e] font-mono mb-2",children:w}),(null==C?void 0:C.title)&&(0,n.jsx)("span",{className:"text-sm text-[#a855f7] font-medium mb-2",children:C.title}),(0,n.jsxs)("span",{className:"text-sm flex items-center gap-1.5",style:{color:N},children:[(0,n.jsx)("div",{className:"w-2 h-2 rounded-full ".concat(k?"animate-pulse":""),style:{backgroundColor:N}}),r.status.charAt(0).toUpperCase()+r.status.slice(1),r.isProcessing&&" - Thinking..."]}),r.cli&&(()=>{let e=r.cli.toLowerCase(),t=su[sx[e]||e]||su.other;return(0,n.jsxs)("div",{className:"flex items-center gap-3 mt-3 px-3 py-2.5 rounded-lg border",style:{borderColor:"".concat(t.color,"40"),backgroundColor:"".concat(t.color,"10")},children:[(0,n.jsx)("span",{className:"text-lg",children:t.icon}),(0,n.jsxs)("div",{className:"flex flex-col gap-0.5",children:[(0,n.jsx)("span",{className:"text-sm font-medium",style:{color:t.color},children:t.label}),(r.model||(null==C?void 0:C.model))&&(0,n.jsx)("span",{className:"text-[11px] font-mono px-1.5 py-0.5 rounded w-fit",style:{color:t.color,backgroundColor:"".concat(t.color,"15")},children:r.model||(null==C?void 0:C.model)})]})]})})(),(0,n.jsxs)("div",{className:"flex flex-wrap gap-2 mt-3",children:[r.isSpawned&&(0,n.jsx)("span",{className:"text-xs bg-[#a855f7]/20 text-[#a855f7] px-2 py-1 rounded uppercase font-medium",children:"Spawned"}),r.team&&(0,n.jsx)("span",{className:"text-xs bg-[#00d9ff]/20 text-[#00d9ff] px-2 py-1 rounded",children:r.team}),(null==C?void 0:C.personaName)&&(0,n.jsx)("span",{className:"text-xs bg-[#10b981]/20 text-[#10b981] px-2 py-1 rounded",children:C.personaName})]})]}),(0,n.jsx)("div",{className:"flex-1 p-4 overflow-y-auto",children:(0,n.jsxs)("div",{className:"space-y-4",children:[c&&((null===(t=c.completedTasks)||void 0===t?void 0:t.length)||c.currentTask||c.context)&&(0,n.jsxs)("div",{className:"bg-[#1e2024] border border-[#00d9ff]/20 rounded-lg p-3",children:[(0,n.jsxs)("label",{className:"text-xs text-[#00d9ff] uppercase tracking-wide font-medium flex items-center gap-1.5 mb-2",children:[(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.jsx)("path",{d:"M3 12h4l3 9 4-18 3 9h4"})}),"Recent Work"]}),c.currentTask&&(0,n.jsxs)("div",{className:"mb-2",children:[(0,n.jsx)("span",{className:"text-xs text-[#8d8d8e]",children:"Working on:"}),(0,n.jsx)("p",{className:"text-sm text-[#d1d2d3] mt-0.5 bg-[#2a2d31] p-2 rounded",children:c.currentTask})]}),c.completedTasks&&c.completedTasks.length>0&&(0,n.jsxs)("div",{className:"mb-2",children:[(0,n.jsx)("span",{className:"text-xs text-[#8d8d8e]",children:"Completed:"}),(0,n.jsxs)("ul",{className:"mt-1 space-y-1",children:[c.completedTasks.slice(0,5).map((e,t)=>(0,n.jsxs)("li",{className:"text-xs text-[#d1d2d3] flex items-start gap-1.5",children:[(0,n.jsx)("span",{className:"text-[#10b981] mt-0.5",children:"✓"}),(0,n.jsx)("span",{children:e})]},t)),c.completedTasks.length>5&&(0,n.jsxs)("li",{className:"text-xs text-[#8d8d8e]",children:["+",c.completedTasks.length-5," more..."]})]})]}),c.context&&(0,n.jsxs)("div",{className:"mb-2",children:[(0,n.jsx)("span",{className:"text-xs text-[#8d8d8e]",children:"Context:"}),(0,n.jsx)("p",{className:"text-xs text-[#a0a0b0] mt-0.5 italic",children:c.context})]}),c.files&&c.files.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("span",{className:"text-xs text-[#8d8d8e]",children:"Files:"}),(0,n.jsxs)("div",{className:"flex flex-wrap gap-1 mt-1",children:[c.files.slice(0,6).map((e,t)=>(0,n.jsx)("span",{className:"text-[10px] font-mono bg-[#2a2d31] text-[#a855f7] px-1.5 py-0.5 rounded",title:e,children:e.split("/").pop()},t)),c.files.length>6&&(0,n.jsxs)("span",{className:"text-[10px] text-[#8d8d8e]",children:["+",c.files.length-6]})]})]}),c.lastUpdated&&(0,n.jsx)("div",{className:"mt-2 pt-2 border-t border-[#2a2d31]",children:(0,n.jsxs)("span",{className:"text-[10px] text-[#606070]",children:["Updated ",function(e){let t=new Date(e),r=Math.floor((new Date().getTime()-t.getTime())/1e3),n=Math.floor(r/60),s=Math.floor(n/60),a=Math.floor(s/24);return r<60?"just now":n<60?"".concat(n," min ago"):s<24?"".concat(s," hr ago"):a<7?"".concat(a," day").concat(a>1?"s":""," ago"):sh(e)}(c.lastUpdated)]})})]}),(null==C?void 0:C.description)&&(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-[#8d8d8e] uppercase tracking-wide",children:"Description"}),(0,n.jsx)("p",{className:"text-sm text-[#d1d2d3] mt-1",children:C.description})]}),r.currentTask&&(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-[#8d8d8e] uppercase tracking-wide",children:"Current Task"}),(0,n.jsx)("p",{className:"text-sm text-[#d1d2d3] mt-1 bg-[#2a2d31] p-2 rounded",children:r.currentTask})]}),(null==C?void 0:C.spawnPrompt)&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("label",{className:"text-xs text-[#8d8d8e] uppercase tracking-wide flex items-center justify-between",children:[(0,n.jsx)("span",{children:"Spawn Prompt"}),C.spawnPrompt.length>200&&(0,n.jsx)("button",{onClick:()=>m(!u),className:"text-[#a855f7] hover:text-[#c084fc] text-xs font-normal",children:u?"Show less":"Show more"})]}),(0,n.jsx)("pre",{className:"text-sm text-[#d1d2d3] mt-1 bg-[#2a2d31] p-3 rounded font-mono whitespace-pre-wrap ".concat(!u&&C.spawnPrompt.length>200?"line-clamp-4":""),children:C.spawnPrompt})]}),(null==C?void 0:C.personaPrompt)&&(0,n.jsxs)("div",{children:[(0,n.jsxs)("label",{className:"text-xs text-[#8d8d8e] uppercase tracking-wide flex items-center justify-between",children:[(0,n.jsx)("span",{children:"Agent Persona"}),C.personaPrompt.length>200&&(0,n.jsx)("button",{onClick:()=>f(!g),className:"text-[#a855f7] hover:text-[#c084fc] text-xs font-normal",children:g?"Show less":"Show more"})]}),(0,n.jsx)("pre",{className:"text-sm text-[#d1d2d3] mt-1 bg-[#2a2d31] p-3 rounded font-mono whitespace-pre-wrap ".concat(!g&&C.personaPrompt.length>200?"line-clamp-4":""),children:C.personaPrompt})]}),(r.model||(null==C?void 0:C.model))&&(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-[#8d8d8e] uppercase tracking-wide",children:"Model"}),(0,n.jsx)("p",{className:"text-sm text-[#d1d2d3] mt-1 font-mono",children:r.model||(null==C?void 0:C.model)})]}),(null==C?void 0:C.workingDirectory)&&(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-[#8d8d8e] uppercase tracking-wide",children:"Working Directory"}),(0,n.jsx)("p",{className:"text-sm text-[#d1d2d3] mt-1 font-mono bg-[#2a2d31] p-2 rounded truncate",title:C.workingDirectory,children:C.workingDirectory})]}),r.agentId&&(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-[#8d8d8e] uppercase tracking-wide",children:"Agent ID"}),(0,n.jsx)("p",{className:"text-sm text-[#d1d2d3] mt-1 font-mono bg-[#2a2d31] p-2 rounded",children:r.agentId})]}),(null==C?void 0:C.capabilities)&&C.capabilities.length>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-[#8d8d8e] uppercase tracking-wide",children:"Capabilities"}),(0,n.jsx)("div",{className:"flex flex-wrap gap-1.5 mt-1",children:C.capabilities.map((e,t)=>(0,n.jsx)("span",{className:"text-xs bg-[#2a2d31] text-[#d1d2d3] px-2 py-1 rounded",children:e},t))})]}),r.lastSeen&&(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-[#8d8d8e] uppercase tracking-wide",children:"Last Seen"}),(0,n.jsx)("p",{className:"text-sm text-[#d1d2d3] mt-1",children:sh(r.lastSeen)})]}),(null==C?void 0:C.firstSeen)&&(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-[#8d8d8e] uppercase tracking-wide",children:"First Seen"}),(0,n.jsx)("p",{className:"text-sm text-[#d1d2d3] mt-1",children:sh(C.firstSeen)})]}),void 0!==r.messageCount&&r.messageCount>0&&(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"text-xs text-[#8d8d8e] uppercase tracking-wide",children:"Messages"}),(0,n.jsxs)("p",{className:"text-sm text-[#d1d2d3] mt-1",children:[r.messageCount," messages sent"]})]})]})}),(0,n.jsxs)("div",{className:"p-4 border-t border-white/10 space-y-2",children:[l&&(0,n.jsxs)("button",{onClick:()=>{l(r),a()},className:"w-full flex items-center justify-center gap-2 py-2.5 bg-[#a855f7] hover:bg-[#9333ea] text-white font-medium rounded-lg transition-colors",children:[(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.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"})}),"Send Message"]}),r.isSpawned&&o&&(0,n.jsxs)("button",{onClick:()=>{o(r),a()},className:"w-full flex items-center justify-center gap-2 py-2.5 border border-[#00d9ff]/30 text-[#00d9ff] hover:bg-[#00d9ff]/10 font-medium rounded-lg transition-colors",children:[(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("polyline",{points:"4 17 10 11 4 5"}),(0,n.jsx)("line",{x1:"12",y1:"19",x2:"20",y2:"19"})]}),"View Logs"]}),r.isSpawned&&i&&(0,n.jsxs)("button",{onClick:()=>{confirm("Are you sure you want to release ".concat(j,"?"))&&(i(r),a())},className:"w-full flex items-center justify-center gap-2 py-2.5 border border-[#ff6b6b]/30 text-[#ff6b6b] hover:bg-[#ff6b6b]/10 font-medium rounded-lg transition-colors",children:[(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"15",y1:"9",x2:"9",y2:"15"}),(0,n.jsx)("line",{x1:"9",y1:"9",x2:"15",y2:"15"})]}),"Release Agent"]})]})]})]})}function sh(e){return new Date(e).toLocaleString([],{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"})}function sp(e){let{isOpen:t,onClose:r,projects:a,isCloudMode:l=!1,hasArchitect:o=!1,onArchitectSpawned:i}=e,[d,u]=(0,s.useState)([]),[x,m]=(0,s.useState)([]),[h,p]=(0,s.useState)(!1),[g,f]=(0,s.useState)(null),[b,v]=(0,s.useState)(!1),[y,j]=(0,s.useState)(""),[w,N]=(0,s.useState)(""),[k,C]=(0,s.useState)(new Set),[S,L]=(0,s.useState)(!1),[M,D]=(0,s.useState)("claude"),[A,E]=(0,s.useState)(null),[T,W]=(0,s.useState)(null),[P,R]=(0,s.useState)(new Set),I=()=>{let e=(0,c._V)();return e?{"X-CSRF-Token":e}:{}};(0,s.useEffect)(()=>{t&&l&&B()},[t,l]);let B=async()=>{p(!0),f(null);try{let e=await fetch("/api/project-groups");if(e.ok){let t=await e.json();u(t.groups||[]),m(t.ungroupedRepositories||[])}else{let t=await e.json().catch(()=>({}));f(t.error||"Failed to load project groups")}}catch(e){f("Failed to load project groups")}finally{p(!1)}},F=async()=>{if(y.trim()&&0!==k.size){p(!0),f(null);try{let e=await fetch("/api/project-groups",{method:"POST",headers:{"Content-Type":"application/json",...I()},body:JSON.stringify({name:y.trim(),description:w.trim()||void 0,repositoryIds:Array.from(k)})});if(e.ok){let t=await e.json();t.group&&(u(e=>[...e,t.group]),m(e=>e.filter(e=>!k.has(e.id))),v(!1),j(""),N(""),C(new Set))}else{let t=await e.json().catch(()=>({}));f(t.error||"Failed to create project group")}}catch(e){f("Failed to create project group")}finally{p(!1)}}},U=async(e,t)=>{f(null);try{let r=await fetch("/api/project-groups/".concat(e),{method:"PATCH",headers:{"Content-Type":"application/json",...I()},body:JSON.stringify(t)});if(r.ok){let t=await r.json();t.group&&(u(r=>r.map(r=>r.id===e?{...r,...t.group}:r)),E(null))}else{let e=await r.json().catch(()=>({}));f(e.error||"Failed to update project group")}}catch(e){f("Failed to update project group")}},_=async(e,t)=>{f(null);try{let r="/api/project-groups/".concat(e,"/coordinator/").concat(t?"enable":"disable"),n=await fetch(r,{method:"POST",headers:I()});if(n.ok){let r=await n.json();u(n=>n.map(n=>{var s,a;return n.id===e?{...n,coordinatorAgent:{...n.coordinatorAgent,enabled:t,name:(null===(s=r.coordinator)||void 0===s?void 0:s.name)||(null===(a=n.coordinatorAgent)||void 0===a?void 0:a.name)}}:n}))}else{let e=await n.json().catch(()=>({}));402===n.status&&e.upgrade?f("".concat(e.error,". Go to Settings > Billing to upgrade.")):f(e.error||"Failed to ".concat(t?"enable":"disable"," coordinator"))}}catch(e){f("Failed to ".concat(t?"enable":"disable"," coordinator"))}},O=async e=>{if(window.confirm("Delete this project group? The coordinator will be stopped and repositories will be ungrouped."))try{let t=d.find(t=>t.id===e),r=await fetch("/api/project-groups/".concat(e),{method:"DELETE",headers:I()});if(r.ok)u(t=>t.filter(t=>t.id!==e)),(null==t?void 0:t.repositories)&&m(e=>[...e,...t.repositories]);else{let e=await r.json().catch(()=>({}));f(e.error||"Failed to delete project group")}}catch(e){f("Failed to delete project group")}},H=async(e,t)=>{try{let r=await fetch("/api/project-groups/".concat(e,"/repositories/").concat(t),{method:"DELETE",headers:I()});if(r.ok){let r=d.find(t=>t.id===e),n=null==r?void 0:r.repositories.find(e=>e.id===t);u(r=>r.map(r=>r.id===e?{...r,repositories:r.repositories.filter(e=>e.id!==t),repositoryCount:r.repositoryCount-1}:r)),n&&m(e=>[...e,n])}else{let e=await r.json().catch(()=>({}));f(e.error||"Failed to remove repository from group")}}catch(e){f("Failed to remove repository from group")}},z=async(e,t)=>{if(0!==t.length)try{let r=await fetch("/api/project-groups/".concat(e,"/repositories"),{method:"POST",headers:{"Content-Type":"application/json",...I()},body:JSON.stringify({repositoryIds:t})});if(r.ok)await B(),W(null),R(new Set);else{let e=await r.json().catch(()=>({}));f(e.error||"Failed to add repositories to group")}}catch(e){f("Failed to add repositories to group")}},G=e=>{R(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})},V=e=>{C(t=>{let r=new Set(t);return r.has(e)?r.delete(e):r.add(e),r})};if(!t)return null;let K=async()=>{L(!0),f(null);try{let e=await fetch("/api/spawn/architect",{method:"POST",headers:{"Content-Type":"application/json",...I()},body:JSON.stringify({cli:M})}),t=await e.json();e.ok&&t.success?(null==i||i(),r()):f(t.error||"Failed to spawn Architect")}catch(e){f("Failed to spawn Architect")}finally{L(!1)}};if(!l){let e=a.length>1;return(0,n.jsx)("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[1000] animate-fade-in",onClick:r,children:(0,n.jsxs)("div",{className:"bg-bg-secondary rounded-xl w-[500px] max-w-[90vw] max-h-[80vh] flex flex-col shadow-modal animate-slide-up",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between py-5 px-6 border-b border-border-subtle",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)(sb,{}),(0,n.jsx)("h2",{className:"m-0 text-lg font-semibold text-text-primary",children:"Coordinator Agent"})]}),(0,n.jsx)("button",{className:"flex items-center justify-center w-8 h-8 bg-transparent border-none rounded-md text-text-secondary cursor-pointer transition-all duration-150 hover:bg-bg-hover hover:text-text-primary",onClick:r,children:(0,n.jsx)(sv,{})})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto p-6",children:[g&&(0,n.jsx)("div",{className:"bg-error/10 border border-error/30 rounded-lg p-3 mb-4 text-error text-sm",children:g}),e&&(0,n.jsxs)("div",{className:"bg-gradient-to-r from-accent-purple/10 to-accent-cyan/10 border border-accent-purple/30 rounded-lg p-4 mb-4",children:[(0,n.jsxs)("h3",{className:"text-sm font-semibold text-text-primary mb-3 flex items-center gap-2",children:[(0,n.jsx)(sb,{}),"Spawn Architect"]}),o?(0,n.jsxs)("div",{className:"flex items-center gap-2 text-sm text-success",children:[(0,n.jsx)(sk,{}),"Architect is running"]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("p",{className:"text-sm text-text-secondary mb-4",children:["Spawn an Architect agent to coordinate across your ",a.length," connected projects."]}),(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsxs)("select",{className:"flex-1 py-2 px-3 bg-bg-card border border-border-subtle rounded-md text-sm text-text-primary outline-none focus:border-accent-purple/50",value:M,onChange:e=>D(e.target.value),children:[(0,n.jsx)("option",{value:"claude",children:"Claude (default)"}),(0,n.jsx)("option",{value:"claude:opus",children:"Claude Opus"}),(0,n.jsx)("option",{value:"claude:sonnet",children:"Claude Sonnet"}),(0,n.jsx)("option",{value:"codex",children:"Codex"})]}),(0,n.jsx)("button",{className:"py-2 px-4 bg-gradient-to-r from-accent-purple to-accent-cyan text-bg-deep rounded-md text-sm font-semibold hover:shadow-lg transition-all disabled:opacity-50",onClick:K,disabled:S,children:S?"Spawning...":"Spawn"})]})]})]}),!e&&(0,n.jsxs)("div",{className:"bg-bg-tertiary rounded-lg p-4 mb-4 border border-border-subtle",children:[(0,n.jsx)("h3",{className:"text-sm font-semibold text-text-primary mb-2",children:"Not in Bridge Mode"}),(0,n.jsx)("p",{className:"text-sm text-text-secondary",children:"The Architect coordinates multiple projects. Start bridge mode to enable:"}),(0,n.jsxs)("div",{className:"bg-bg-card rounded-lg p-3 font-mono text-sm mt-3",children:[(0,n.jsx)("span",{className:"text-text-muted",children:"$"})," ",(0,n.jsx)("span",{className:"text-accent-cyan",children:"relay bridge"})," ",(0,n.jsx)("span",{className:"text-accent-orange",children:"~/project1 ~/project2"})]})]}),(0,n.jsxs)("div",{className:"bg-bg-tertiary rounded-lg p-4 mb-4",children:[(0,n.jsx)("h3",{className:"text-sm font-semibold text-text-primary mb-2",children:"CLI Alternative"}),(0,n.jsxs)("p",{className:"text-sm text-text-secondary mb-3",children:["You can also spawn the Architect via CLI with the ",(0,n.jsx)("code",{className:"bg-bg-card px-1.5 py-0.5 rounded text-accent-cyan",children:"--architect"})," flag:"]}),(0,n.jsxs)("div",{className:"bg-bg-card rounded-lg p-3 font-mono text-sm",children:[(0,n.jsx)("span",{className:"text-text-muted",children:"$"})," ",(0,n.jsx)("span",{className:"text-accent-cyan",children:"relay bridge"})," ",(0,n.jsx)("span",{className:"text-accent-orange",children:"~/project1 ~/project2"})," ",(0,n.jsx)("span",{className:"text-accent-purple",children:"--architect"})]})]})]}),(0,n.jsx)("div",{className:"flex justify-end py-4 px-6 border-t border-border-subtle",children:(0,n.jsx)("button",{className:"py-2 px-5 bg-bg-tertiary border border-border-subtle rounded-md text-sm text-text-secondary cursor-pointer transition-colors duration-150 hover:bg-bg-hover",onClick:r,children:"Close"})})]})})}return(0,n.jsx)("div",{className:"fixed inset-0 bg-black/70 flex items-center justify-center z-[1000] animate-fade-in",onClick:r,children:(0,n.jsxs)("div",{className:"bg-bg-secondary rounded-xl w-[600px] max-w-[90vw] max-h-[80vh] flex flex-col shadow-modal animate-slide-up",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between py-5 px-6 border-b border-border-subtle",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)(sb,{}),(0,n.jsx)("h2",{className:"m-0 text-lg font-semibold text-text-primary",children:"Coordinator Agents"})]}),(0,n.jsx)("button",{className:"flex items-center justify-center w-8 h-8 bg-transparent border-none rounded-md text-text-secondary cursor-pointer transition-all duration-150 hover:bg-bg-hover hover:text-text-primary",onClick:r,children:(0,n.jsx)(sv,{})})]}),(0,n.jsxs)("div",{className:"flex-1 overflow-y-auto p-6",children:[g&&(0,n.jsx)("div",{className:"bg-error/10 border border-error/30 rounded-lg p-3 mb-4 text-error text-sm",children:g}),h&&0===d.length?(0,n.jsx)("div",{className:"flex items-center justify-center py-12 text-text-muted",children:(0,n.jsx)(sf,{})}):(0,n.jsxs)(n.Fragment,{children:[d.length>0&&(0,n.jsxs)("div",{className:"space-y-3 mb-6",children:[(0,n.jsx)("h4",{className:"text-xs font-semibold text-text-muted uppercase tracking-wider",children:"Project Groups"}),d.map(e=>{var t,r,s,a;return(0,n.jsxs)("div",{className:"bg-bg-tertiary rounded-lg p-4 border border-border-subtle",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)("span",{className:"font-semibold text-text-primary",children:e.name}),(0,n.jsxs)("span",{className:"text-xs text-text-muted",children:[e.repositoryCount," ",1===e.repositoryCount?"repo":"repos"]})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1",children:[(0,n.jsx)("button",{className:"text-text-muted hover:text-accent-cyan transition-colors p-1",onClick:()=>E(e),title:"Edit group",children:(0,n.jsx)(sy,{})}),(0,n.jsx)("button",{className:"text-text-muted hover:text-error transition-colors p-1",onClick:()=>O(e.id),title:"Delete group",children:(0,n.jsx)(sw,{})})]})]}),e.repositories.length>0&&(0,n.jsx)("div",{className:"mb-3 space-y-1",children:e.repositories.map(t=>(0,n.jsxs)("div",{className:"flex items-center justify-between py-1 px-2 bg-bg-card/50 rounded text-xs",children:[(0,n.jsx)("span",{className:"text-text-secondary font-mono",children:t.githubFullName}),(0,n.jsx)("button",{className:"text-text-muted hover:text-error transition-colors p-0.5",onClick:()=>H(e.id,t.id),title:"Remove from group",children:(0,n.jsx)(sv,{size:12})})]},t.id))}),e.description&&(0,n.jsx)("p",{className:"text-xs text-text-muted mb-3",children:e.description}),T===e.id?(0,n.jsxs)("div",{className:"mb-3 p-3 bg-bg-card rounded-lg border border-border-subtle",children:[(0,n.jsx)("div",{className:"text-xs font-medium text-text-muted mb-2",children:"Select repositories to add:"}),(0,n.jsx)("div",{className:"space-y-1 max-h-[150px] overflow-y-auto mb-3",children:x.length>0?x.map(e=>(0,n.jsxs)("label",{className:"flex items-center gap-2 p-1.5 rounded cursor-pointer hover:bg-bg-hover",children:[(0,n.jsx)("input",{type:"checkbox",className:"accent-accent-cyan",checked:P.has(e.id),onChange:()=>G(e.id)}),(0,n.jsx)("span",{className:"text-xs text-text-primary font-mono",children:e.githubFullName})]},e.id)):(0,n.jsx)("p",{className:"text-xs text-text-muted py-2 text-center",children:"No ungrouped repositories available"})}),(0,n.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,n.jsx)("button",{className:"py-1 px-3 text-xs bg-transparent border border-border-subtle rounded text-text-secondary hover:bg-bg-hover",onClick:()=>{W(null),R(new Set)},children:"Cancel"}),(0,n.jsx)("button",{className:"py-1 px-3 text-xs bg-accent-cyan text-bg-deep rounded font-medium hover:bg-accent-cyan/90 disabled:opacity-50",onClick:()=>z(e.id,Array.from(P)),disabled:0===P.size,children:"Add Selected"})]})]}):x.length>0?(0,n.jsxs)("button",{className:"mb-3 w-full py-1.5 text-xs border border-dashed border-border-subtle rounded text-text-muted hover:border-accent-cyan/50 hover:text-accent-cyan transition-colors flex items-center justify-center gap-1",onClick:()=>{W(e.id),R(new Set)},children:[(0,n.jsx)(sj,{}),"Add repositories"]}):null,(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(0,n.jsx)(sg,{status:(null===(t=e.coordinatorAgent)||void 0===t?void 0:t.enabled)?"running":"stopped"}),(null===(r=e.coordinatorAgent)||void 0===r?void 0:r.name)&&(0,n.jsx)("span",{className:"text-sm text-text-secondary",children:e.coordinatorAgent.name})]}),(0,n.jsxs)("button",{className:"py-1.5 px-3 rounded-md text-xs font-medium transition-colors ".concat((null===(s=e.coordinatorAgent)||void 0===s?void 0:s.enabled)?"bg-error/20 text-error hover:bg-error/30":"bg-accent-cyan/20 text-accent-cyan hover:bg-accent-cyan/30"," ").concat(0===e.repositoryCount?"opacity-50 cursor-not-allowed":""),onClick:()=>{var t;return e.repositoryCount>0&&_(e.id,!(null===(t=e.coordinatorAgent)||void 0===t?void 0:t.enabled))},disabled:0===e.repositoryCount,title:0===e.repositoryCount?"Add repositories first":void 0,children:[(null===(a=e.coordinatorAgent)||void 0===a?void 0:a.enabled)?"Stop":"Start"," Coordinator"]})]})]},e.id)})]}),A&&(0,n.jsxs)("div",{className:"bg-bg-tertiary rounded-lg p-4 border border-accent-cyan/30 mb-4",children:[(0,n.jsx)("h4",{className:"text-sm font-semibold text-text-primary mb-4",children:"Edit Project Group"}),(0,n.jsx)(sC,{group:A,onSave:e=>U(A.id,e),onCancel:()=>E(null)})]}),b?(0,n.jsxs)("div",{className:"bg-bg-tertiary rounded-lg p-4 border border-accent-cyan/30",children:[(0,n.jsx)("h4",{className:"text-sm font-semibold text-text-primary mb-4",children:"Create Project Group"}),(0,n.jsxs)("div",{className:"space-y-4",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-xs font-medium text-text-muted mb-1.5",children:"Group Name"}),(0,n.jsx)("input",{type:"text",className:"w-full py-2 px-3 bg-bg-card border border-border-subtle rounded-md text-sm text-text-primary outline-none focus:border-accent-cyan/50",placeholder:"e.g., Frontend Team",value:y,onChange:e=>j(e.target.value)})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-xs font-medium text-text-muted mb-1.5",children:"Description (optional)"}),(0,n.jsx)("input",{type:"text",className:"w-full py-2 px-3 bg-bg-card border border-border-subtle rounded-md text-sm text-text-primary outline-none focus:border-accent-cyan/50",placeholder:"e.g., All frontend repositories",value:w,onChange:e=>N(e.target.value)})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-xs font-medium text-text-muted mb-1.5",children:"Select Repositories"}),(0,n.jsxs)("div",{className:"space-y-2 max-h-[200px] overflow-y-auto",children:[x.map(e=>(0,n.jsxs)("label",{className:"flex items-center gap-2 p-2 bg-bg-card rounded-md cursor-pointer hover:bg-bg-hover",children:[(0,n.jsx)("input",{type:"checkbox",className:"accent-accent-cyan",checked:k.has(e.id),onChange:()=>V(e.id)}),(0,n.jsx)("span",{className:"text-sm text-text-primary font-mono",children:e.githubFullName}),e.isPrivate&&(0,n.jsx)("span",{className:"text-xs text-text-muted",children:"\uD83D\uDD12"})]},e.id)),0===x.length&&(0,n.jsx)("p",{className:"text-sm text-text-muted py-4 text-center",children:"No ungrouped repositories. Add repositories in Settings or ungroup existing ones."})]})]}),(0,n.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,n.jsx)("button",{className:"py-2 px-4 bg-transparent border border-border-subtle rounded-md text-sm text-text-secondary hover:bg-bg-hover",onClick:()=>{v(!1),j(""),N(""),C(new Set)},children:"Cancel"}),(0,n.jsx)("button",{className:"py-2 px-4 bg-accent-cyan text-bg-deep rounded-md text-sm font-medium hover:bg-accent-cyan/90 disabled:opacity-50",onClick:F,disabled:!y.trim()||0===k.size||h,children:h?"Creating...":"Create Group"})]})]})]}):(0,n.jsxs)("button",{className:"w-full py-3 px-4 border-2 border-dashed border-border-subtle rounded-lg text-text-muted hover:border-accent-cyan/50 hover:text-accent-cyan transition-colors flex items-center justify-center gap-2",onClick:()=>v(!0),disabled:!!A,children:[(0,n.jsx)(sj,{}),"Create Project Group"]}),(0,n.jsxs)("div",{className:"mt-6 p-4 bg-bg-tertiary/50 rounded-lg border border-border-subtle",children:[(0,n.jsxs)("h4",{className:"text-sm font-semibold text-text-primary mb-2 flex items-center gap-2",children:[(0,n.jsx)(sN,{}),"What is a Coordinator?"]}),(0,n.jsx)("p",{className:"text-sm text-text-secondary",children:"A coordinator is a high-level AI agent that oversees multiple projects. It can delegate tasks to project leads, ensure consistency across codebases, and manage cross-project dependencies."})]})]})]})]})})}function sg(e){let{status:t}=e,r={stopped:"bg-text-muted/20 text-text-muted",starting:"bg-accent-orange/20 text-accent-orange",running:"bg-success/20 text-success",error:"bg-error/20 text-error"};return(0,n.jsx)("span",{className:"px-2 py-0.5 rounded-full text-xs font-medium ".concat(r[t]||r.stopped),children:t})}function sf(){return(0,n.jsx)("svg",{className:"animate-spin h-6 w-6 text-accent-cyan",viewBox:"0 0 24 24",children:(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function sb(){return(0,n.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-accent-cyan",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,n.jsx)("circle",{cx:"5",cy:"5",r:"2"}),(0,n.jsx)("circle",{cx:"19",cy:"5",r:"2"}),(0,n.jsx)("circle",{cx:"5",cy:"19",r:"2"}),(0,n.jsx)("circle",{cx:"19",cy:"19",r:"2"}),(0,n.jsx)("line",{x1:"9.5",y1:"9.5",x2:"6.5",y2:"6.5"}),(0,n.jsx)("line",{x1:"14.5",y1:"9.5",x2:"17.5",y2:"6.5"}),(0,n.jsx)("line",{x1:"9.5",y1:"14.5",x2:"6.5",y2:"17.5"}),(0,n.jsx)("line",{x1:"14.5",y1:"14.5",x2:"17.5",y2:"17.5"})]})}function sv(e){let{size:t=20}=e;return(0,n.jsxs)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function sy(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),(0,n.jsx)("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})}function sj(){return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),(0,n.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}function sw(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,n.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"})]})}function sN(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-accent-cyan",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,n.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}function sk(){return(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"text-success",children:(0,n.jsx)("polyline",{points:"20 6 9 17 4 12"})})}function sC(e){let{group:t,onSave:r,onCancel:a}=e,[l,o]=(0,s.useState)(t.name),[i,c]=(0,s.useState)(t.description||"");return(0,n.jsxs)("div",{className:"space-y-4",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-xs font-medium text-text-muted mb-1.5",children:"Group Name"}),(0,n.jsx)("input",{type:"text",className:"w-full py-2 px-3 bg-bg-card border border-border-subtle rounded-md text-sm text-text-primary outline-none focus:border-accent-cyan/50",value:l,onChange:e=>o(e.target.value)})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)("label",{className:"block text-xs font-medium text-text-muted mb-1.5",children:"Description"}),(0,n.jsx)("input",{type:"text",className:"w-full py-2 px-3 bg-bg-card border border-border-subtle rounded-md text-sm text-text-primary outline-none focus:border-accent-cyan/50",placeholder:"Optional description",value:i,onChange:e=>c(e.target.value)})]}),(0,n.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,n.jsx)("button",{className:"py-2 px-4 bg-transparent border border-border-subtle rounded-md text-sm text-text-secondary hover:bg-bg-hover",onClick:a,children:"Cancel"}),(0,n.jsx)("button",{className:"py-2 px-4 bg-accent-cyan text-bg-deep rounded-md text-sm font-medium hover:bg-accent-cyan/90 disabled:opacity-50",onClick:()=>{let e={};l.trim()!==t.name&&(e.name=l.trim()),i.trim()!==(t.description||"")&&(e.description=i.trim()),Object.keys(e).length>0?r(e):a()},disabled:!l.trim(),children:"Save Changes"})]})]})}function sS(){let e=(0,s.useMemo)(()=>Array.from({length:50},(e,t)=>({id:t,x:100*Math.random(),delay:.5*Math.random(),duration:2+2*Math.random(),size:4+8*Math.random(),color:["#00d9ff","#00b8d9","#4ade80","#facc15","#f472b6","#a78bfa"][Math.floor(6*Math.random())],rotation:360*Math.random()})),[]);return(0,n.jsxs)("div",{className:"fixed inset-0 pointer-events-none overflow-hidden z-50",children:[e.map(e=>(0,n.jsx)("div",{className:"absolute animate-confetti-fall",style:{left:"".concat(e.x,"%"),top:"-20px",width:e.size,height:.6*e.size,backgroundColor:e.color,transform:"rotate(".concat(e.rotation,"deg)"),animationDelay:"".concat(e.delay,"s"),animationDuration:"".concat(e.duration,"s"),borderRadius:"2px"}},e.id)),(0,n.jsx)("style",{children:"\n @keyframes confetti-fall {\n 0% {\n transform: translateY(0) rotate(0deg) scale(1);\n opacity: 1;\n }\n 100% {\n transform: translateY(100vh) rotate(720deg) scale(0.5);\n opacity: 0;\n }\n }\n .animate-confetti-fall {\n animation: confetti-fall linear forwards;\n }\n "})]})}function sL(){return(0,n.jsxs)("div",{className:"relative w-20 h-20",children:[(0,n.jsx)("div",{className:"absolute inset-0 rounded-full bg-gradient-to-r from-emerald-400 to-cyan-400 opacity-20 animate-pulse-slow"}),(0,n.jsx)("div",{className:"absolute inset-1 rounded-full bg-gradient-to-br from-emerald-400 via-emerald-500 to-cyan-500 p-0.5 animate-scale-in",children:(0,n.jsx)("div",{className:"w-full h-full rounded-full bg-bg-primary flex items-center justify-center",children:(0,n.jsxs)("svg",{className:"w-10 h-10",viewBox:"0 0 24 24",fill:"none",children:[(0,n.jsx)("path",{d:"M5 12l5 5L19 7",stroke:"url(#check-gradient)",strokeWidth:"3",strokeLinecap:"round",strokeLinejoin:"round",className:"animate-draw-check",style:{strokeDasharray:30,strokeDashoffset:30}}),(0,n.jsx)("defs",{children:(0,n.jsxs)("linearGradient",{id:"check-gradient",x1:"5",y1:"12",x2:"19",y2:"7",children:[(0,n.jsx)("stop",{stopColor:"#34d399"}),(0,n.jsx)("stop",{offset:"1",stopColor:"#22d3ee"})]})})]})})}),(0,n.jsx)("div",{className:"absolute -top-1 -right-1 w-3 h-3 bg-yellow-400 rounded-full animate-sparkle",style:{animationDelay:"0.5s"}}),(0,n.jsx)("div",{className:"absolute top-0 -left-2 w-2 h-2 bg-cyan-400 rounded-full animate-sparkle",style:{animationDelay:"0.7s"}}),(0,n.jsx)("div",{className:"absolute -bottom-1 right-2 w-2 h-2 bg-emerald-400 rounded-full animate-sparkle",style:{animationDelay:"0.9s"}}),(0,n.jsx)("style",{children:"\n @keyframes scale-in {\n 0% { transform: scale(0); opacity: 0; }\n 50% { transform: scale(1.1); }\n 100% { transform: scale(1); opacity: 1; }\n }\n @keyframes draw-check {\n to { stroke-dashoffset: 0; }\n }\n @keyframes sparkle {\n 0%, 100% { transform: scale(0); opacity: 0; }\n 50% { transform: scale(1); opacity: 1; }\n }\n @keyframes pulse-slow {\n 0%, 100% { transform: scale(1); opacity: 0.2; }\n 50% { transform: scale(1.2); opacity: 0.4; }\n }\n .animate-scale-in {\n animation: scale-in 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;\n }\n .animate-draw-check {\n animation: draw-check 0.4s ease-out 0.4s forwards;\n }\n .animate-sparkle {\n animation: sparkle 1s ease-in-out infinite;\n }\n .animate-pulse-slow {\n animation: pulse-slow 2s ease-in-out infinite;\n }\n "})]})}function sM(){return(0,n.jsxs)("div",{className:"relative w-20 h-20",children:[(0,n.jsx)("div",{className:"absolute inset-0 rounded-full border-2 border-transparent border-t-accent-cyan border-r-accent-cyan/50 animate-spin"}),(0,n.jsx)("div",{className:"absolute inset-3 rounded-full bg-gradient-to-br from-accent-cyan/20 to-transparent animate-pulse"}),(0,n.jsx)("div",{className:"absolute inset-0 flex items-center justify-center",children:(0,n.jsx)("div",{className:"w-3 h-3 rounded-full bg-accent-cyan animate-ping"})}),(0,n.jsx)("div",{className:"absolute inset-0 animate-spin",style:{animationDuration:"3s"},children:(0,n.jsx)("div",{className:"absolute top-0 left-1/2 -translate-x-1/2 w-2 h-2 rounded-full bg-accent-cyan/80"})}),(0,n.jsx)("div",{className:"absolute inset-0 animate-spin",style:{animationDuration:"4s",animationDirection:"reverse"},children:(0,n.jsx)("div",{className:"absolute bottom-1 left-1/2 -translate-x-1/2 w-1.5 h-1.5 rounded-full bg-cyan-300/60"})})]})}function sD(e){let{children:t,delay:r}=e;return(0,n.jsxs)("li",{className:"flex items-center gap-3 opacity-0 animate-slide-in-left",style:{animationDelay:"".concat(r,"s"),animationFillMode:"forwards"},children:[(0,n.jsx)("div",{className:"w-5 h-5 rounded-full bg-gradient-to-br from-emerald-400 to-cyan-400 flex items-center justify-center flex-shrink-0",children:(0,n.jsx)("svg",{className:"w-3 h-3 text-white",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",children:(0,n.jsx)("path",{d:"M20 6L9 17l-5-5",strokeLinecap:"round",strokeLinejoin:"round"})})}),(0,n.jsx)("span",{className:"text-text-secondary",children:t}),(0,n.jsx)("style",{children:"\n @keyframes slide-in-left {\n from {\n opacity: 0;\n transform: translateX(-20px);\n }\n to {\n opacity: 1;\n transform: translateX(0);\n }\n }\n .animate-slide-in-left {\n animation: slide-in-left 0.4s ease-out forwards;\n }\n "})]})}function sA(e){let{type:t,sessionId:r,onClose:a}=e,[l,o]=(0,s.useState)(null),[i,d]=(0,s.useState)("success"===t),[u,x]=(0,s.useState)(null),[m,h]=(0,s.useState)(!1);(0,s.useEffect)(()=>{"success"===t&&(async()=>{try{await new Promise(e=>setTimeout(e,1500));let r=await c.xv.getSubscription();if(r.success&&r.data){var e,t;o({plan:(null===(e=r.data.subscription)||void 0===e?void 0:e.tier)||"pro",status:(null===(t=r.data.subscription)||void 0===t?void 0:t.status)||"active"}),setTimeout(()=>h(!0),200)}}catch(e){x("Could not verify subscription. Please check your billing settings.")}finally{d(!1)}})()},[t,r]);let p=(null==l?void 0:l.plan)==="pro"?"Pro":(null==l?void 0:l.plan)==="team"?"Team":(null==l?void 0:l.plan)==="enterprise"?"Enterprise":"Premium";return"success"===t?(0,n.jsxs)("div",{className:"min-h-screen bg-bg-deep flex items-center justify-center p-4 overflow-hidden",children:[(0,n.jsxs)("div",{className:"fixed inset-0 overflow-hidden pointer-events-none",children:[(0,n.jsx)("div",{className:"absolute top-1/4 -left-32 w-96 h-96 bg-accent-cyan/10 rounded-full blur-3xl animate-float"}),(0,n.jsx)("div",{className:"absolute bottom-1/4 -right-32 w-96 h-96 bg-emerald-500/10 rounded-full blur-3xl animate-float",style:{animationDelay:"1s"}})]}),m&&(0,n.jsx)(sS,{}),(0,n.jsxs)("div",{className:"relative max-w-md w-full bg-bg-primary/95 backdrop-blur-xl rounded-3xl border border-border-subtle p-10 text-center shadow-2xl opacity-0 animate-fade-scale-in",style:{animationFillMode:"forwards"},children:[(0,n.jsx)("div",{className:"absolute top-0 left-8 right-8 h-1 rounded-full bg-gradient-to-r from-transparent via-accent-cyan to-transparent"}),i?(0,n.jsxs)("div",{className:"py-8",children:[(0,n.jsx)("div",{className:"flex justify-center mb-8",children:(0,n.jsx)(sM,{})}),(0,n.jsx)("h1",{className:"text-2xl font-bold text-text-primary mb-3 tracking-tight",children:"Processing your upgrade"}),(0,n.jsx)("p",{className:"text-text-muted",children:"Confirming your subscription..."})]}):u?(0,n.jsxs)("div",{className:"py-4",children:[(0,n.jsx)("div",{className:"w-16 h-16 mx-auto mb-6 rounded-full bg-amber-500/20 flex items-center justify-center",children:(0,n.jsxs)("svg",{className:"w-8 h-8 text-amber-400",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,n.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}),(0,n.jsx)("h1",{className:"text-2xl font-bold text-text-primary mb-3",children:"Almost there!"}),(0,n.jsx)("p",{className:"text-text-muted mb-8",children:u}),(0,n.jsx)("button",{onClick:a,className:"group w-full py-4 px-6 bg-gradient-to-r from-accent-cyan to-cyan-400 text-bg-deep font-bold rounded-2xl transition-all duration-300 hover:shadow-[0_0_30px_rgba(0,217,255,0.4)] hover:scale-[1.02] active:scale-[0.98]",children:"Go to Billing Settings"})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"flex justify-center mb-6",children:(0,n.jsx)(sL,{})}),(0,n.jsxs)("h1",{className:"text-3xl font-extrabold text-transparent bg-clip-text bg-gradient-to-r from-text-primary via-accent-cyan to-emerald-400 mb-3 tracking-tight opacity-0 animate-fade-in",style:{animationDelay:"0.3s",animationFillMode:"forwards"},children:["Welcome to ",p,"!"]}),(0,n.jsx)("p",{className:"text-text-muted mb-8 opacity-0 animate-fade-in",style:{animationDelay:"0.5s",animationFillMode:"forwards"},children:"Your subscription is active. Time to supercharge your workflow."}),(0,n.jsxs)("div",{className:"bg-gradient-to-br from-bg-secondary to-bg-deep rounded-2xl p-5 mb-8 text-left border border-border-subtle/50 opacity-0 animate-fade-in",style:{animationDelay:"0.6s",animationFillMode:"forwards"},children:[(0,n.jsx)("h3",{className:"text-xs font-bold text-accent-cyan uppercase tracking-wider mb-4",children:"Your new powers"}),(0,n.jsxs)("ul",{className:"space-y-3 text-sm",children:[(0,n.jsx)(sD,{delay:.8,children:"Expanded workspace & repository limits"}),(0,n.jsx)(sD,{delay:.9,children:"More compute hours for your agents"}),(0,n.jsx)(sD,{delay:1,children:"Increased concurrent agent capacity"}),(0,n.jsx)(sD,{delay:1.1,children:"Priority support & faster responses"})]})]}),(0,n.jsx)("button",{onClick:a,className:"group w-full py-4 px-6 bg-gradient-to-r from-accent-cyan via-cyan-400 to-emerald-400 text-bg-deep font-bold rounded-2xl transition-all duration-300 hover:shadow-[0_0_40px_rgba(0,217,255,0.5)] hover:scale-[1.02] active:scale-[0.98] opacity-0 animate-fade-in",style:{animationDelay:"1.2s",animationFillMode:"forwards"},children:(0,n.jsxs)("span",{className:"flex items-center justify-center gap-2",children:["Launch Dashboard",(0,n.jsx)("svg",{className:"w-5 h-5 transition-transform group-hover:translate-x-1",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:(0,n.jsx)("path",{d:"M5 12h14M12 5l7 7-7 7",strokeLinecap:"round",strokeLinejoin:"round"})})]})})]})]}),(0,n.jsx)("style",{children:"\n @keyframes fade-scale-in {\n from {\n opacity: 0;\n transform: scale(0.95) translateY(10px);\n }\n to {\n opacity: 1;\n transform: scale(1) translateY(0);\n }\n }\n @keyframes fade-in {\n from { opacity: 0; }\n to { opacity: 1; }\n }\n @keyframes float {\n 0%, 100% { transform: translateY(0) scale(1); }\n 50% { transform: translateY(-20px) scale(1.05); }\n }\n .animate-fade-scale-in {\n animation: fade-scale-in 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;\n }\n .animate-fade-in {\n animation: fade-in 0.5s ease-out forwards;\n }\n .animate-float {\n animation: float 6s ease-in-out infinite;\n }\n "})]}):(0,n.jsxs)("div",{className:"min-h-screen bg-bg-deep flex items-center justify-center p-4",children:[(0,n.jsx)("div",{className:"fixed inset-0 overflow-hidden pointer-events-none",children:(0,n.jsx)("div",{className:"absolute top-1/3 left-1/4 w-64 h-64 bg-text-muted/5 rounded-full blur-3xl"})}),(0,n.jsxs)("div",{className:"relative max-w-md w-full bg-bg-primary/95 backdrop-blur-xl rounded-3xl border border-border-subtle p-10 text-center shadow-xl opacity-0 animate-fade-scale-in",style:{animationFillMode:"forwards"},children:[(0,n.jsx)("div",{className:"w-16 h-16 mx-auto mb-6 rounded-full bg-bg-secondary border border-border-subtle flex items-center justify-center",children:(0,n.jsx)("svg",{className:"w-7 h-7 text-text-muted",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.jsx)("path",{d:"M18 6L6 18M6 6l12 12",strokeLinecap:"round",strokeLinejoin:"round"})})}),(0,n.jsx)("h1",{className:"text-2xl font-bold text-text-primary mb-3",children:"No problem!"}),(0,n.jsx)("p",{className:"text-text-muted mb-8 leading-relaxed",children:"Checkout was canceled and you haven't been charged. You can upgrade anytime when you're ready."}),(0,n.jsxs)("div",{className:"space-y-3",children:[(0,n.jsx)("button",{onClick:a,className:"group w-full py-4 px-6 bg-gradient-to-r from-accent-cyan to-cyan-400 text-bg-deep font-bold rounded-2xl transition-all duration-300 hover:shadow-[0_0_30px_rgba(0,217,255,0.4)] hover:scale-[1.02] active:scale-[0.98]",children:(0,n.jsxs)("span",{className:"flex items-center justify-center gap-2",children:["Return to Dashboard",(0,n.jsx)("svg",{className:"w-5 h-5 transition-transform group-hover:translate-x-1",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:(0,n.jsx)("path",{d:"M5 12h14M12 5l7 7-7 7",strokeLinecap:"round",strokeLinejoin:"round"})})]})}),(0,n.jsx)("button",{onClick:()=>{window.location.href="/?settings=billing"},className:"w-full py-4 px-6 bg-bg-secondary text-text-primary font-semibold rounded-2xl border border-border-subtle transition-all duration-300 hover:border-accent-cyan/50 hover:bg-bg-secondary/80",children:"View Plans"})]})]}),(0,n.jsx)("style",{children:"\n @keyframes fade-scale-in {\n from {\n opacity: 0;\n transform: scale(0.95) translateY(10px);\n }\n to {\n opacity: 1;\n transform: scale(1) translateY(0);\n }\n }\n .animate-fade-scale-in {\n animation: fade-scale-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;\n }\n "})]})}function sE(e){let{apiBaseUrl:t="",onUpgradeClick:r}=e,[a,l]=(0,s.useState)(null),[o,i]=(0,s.useState)(!0),[c,d]=(0,s.useState)(null),[u,x]=(0,s.useState)(!1);if((0,s.useEffect)(()=>{async function e(){try{let e=await fetch("".concat(t,"/api/usage"),{credentials:"include"});if(!e.ok){if(401===e.status){i(!1);return}throw Error("Failed to fetch usage")}let r=await e.json();l(r)}catch(e){d(e instanceof Error?e.message:"Unknown error")}finally{i(!1)}}e();let r=setInterval(e,3e5);return()=>clearInterval(r)},[t]),o||c||!a||"free"!==a.plan||u)return null;let{computeHoursThisMonth:m}=a.usage,{computeHoursPerMonth:h}=a.limits,p=a.percentUsed.computeHours,g=Math.max(0,h-m),f=g<=0,b=p>=80&&!f,v=a.introBonus,y=(null==v?void 0:v.isActive)&&v.daysRemaining>0,j=new Date().toLocaleDateString("en-US",{month:"long"}),w="bg-bg-tertiary border-border-subtle",N="text-text-secondary",k="text-accent-cyan";return f?(w="bg-error/10 border-error/30",N="text-error",k="text-error"):b?(w="bg-warning/10 border-warning/30",N="text-warning",k="text-warning"):y&&(w="bg-accent-cyan/10 border-accent-cyan/30",N="text-accent-cyan",k="text-accent-cyan"),(0,n.jsxs)("div",{className:"flex items-center justify-between px-4 py-2 border-b ".concat(w),children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[y?(0,n.jsx)(sP,{className:k}):(0,n.jsx)(sT,{className:k}),(0,n.jsx)("span",{className:"text-sm ".concat(N),children:f?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("strong",{children:"Compute limit reached"})," — Your free tier compute hours for ",j," have been used. Workspaces are paused until next month."]}):b?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("strong",{children:[g.toFixed(1),"h remaining"]})," — You've used ",p,"% of your free tier compute hours for ",j,"."]}):y?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("strong",{children:"Intro Bonus Active"})," — ",v.resources.cpus," CPU / ",v.resources.memoryGb,"GB RAM."," ",(0,n.jsxs)("span",{className:"text-text-secondary",children:[v.daysRemaining," day",1!==v.daysRemaining?"s":""," remaining before auto-resize to 1 CPU / 2GB."]})]}):(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("strong",{children:[g.toFixed(1)," of ",h,"h"]})," compute hours remaining this month"]})})]}),(0,n.jsxs)("div",{className:"flex items-center gap-2",children:[(f||b||y)&&(0,n.jsx)("button",{onClick:r||(()=>window.location.href="/pricing"),className:"px-3 py-1.5 bg-gradient-to-r from-accent-cyan to-[#00b8d9] text-bg-deep font-semibold border-none rounded-md text-xs cursor-pointer transition-all duration-150 hover:shadow-glow-cyan hover:-translate-y-0.5",children:y?"Keep Pro Resources":"Upgrade Plan"}),!f&&(0,n.jsx)("button",{onClick:()=>x(!0),className:"p-1 text-text-muted hover:text-text-primary transition-colors","aria-label":"Dismiss",children:(0,n.jsx)(sW,{})})]})]})}function sT(e){let{className:t}=e;return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("polyline",{points:"12 6 12 12 16 14"})]})}function sW(){return(0,n.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,n.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function sP(e){let{className:t}=e;return(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:t,children:[(0,n.jsx)("path",{d:"M4.5 16.5c-1.5 1.26-2 5-2 5s3.74-.5 5-2c.71-.84.7-2.13-.09-2.91a2.18 2.18 0 0 0-2.91-.09z"}),(0,n.jsx)("path",{d:"m12 15-3-3a22 22 0 0 1 2-3.95A12.88 12.88 0 0 1 22 2c0 2.72-.78 7.5-6 11a22.35 22.35 0 0 1-4 2z"}),(0,n.jsx)("path",{d:"M9 12H4s.55-3.03 2-4c1.62-1.08 5 0 5 0"}),(0,n.jsx)("path",{d:"M12 15v5s3.03-.55 4-2c1.08-1.62 0-5 0-5"})]})}let sR={url:"",autoConnect:!0,reconnect:!0,maxReconnectAttempts:10,reconnectDelay:500,onEvent:void 0},sI="relay:recentRepos";function sB(e){try{localStorage.setItem(sI,JSON.stringify(e))}catch(e){}}var sF=r(608),sU=r(7118);function s_(e){let t=e.replace(/^\//,"").split("/").filter(Boolean);if(0===t.length||"app"===t[0])return"app"===t[0]&&t.length>1?s_("/"+t.slice(1).join("/")):{type:"activity"};switch(t[0]){case"channel":return{type:"channel",id:t[1]||void 0};case"dm":return{type:"dm",id:t[1]||void 0};case"agent":return{type:"agent",id:t[1]||void 0};case"settings":return{type:"settings",tab:t[1]&&["dashboard","workspace","team","billing"].includes(t[1])?t[1]:"dashboard"};default:return{type:"activity"}}}function sO(e){let t="/app";switch(e.type){case"channel":return e.id?"".concat(t,"/channel/").concat(encodeURIComponent(e.id)):t;case"dm":return e.id?"".concat(t,"/dm/").concat(encodeURIComponent(e.id)):t;case"agent":return e.id?"".concat(t,"/agent/").concat(encodeURIComponent(e.id)):t;case"settings":return e.tab&&"dashboard"!==e.tab?"".concat(t,"/settings/").concat(e.tab):"".concat(t,"/settings");default:return t}}let sH="dashboard-settings",sz="__activity__";function sG(e){var t,a,l,i,d,u,h,p,f,v;let{wsUrl:y,orchestratorUrl:j,enableReactions:w=!1}=e,N=(0,s.useRef)(void 0),{data:k,isConnected:C,error:S}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t={...sR,...e},[r,n]=(0,s.useState)(null),[a,l]=(0,s.useState)(!1),[o,i]=(0,s.useState)("disconnected"),[c,d]=(0,s.useState)(null),u=(0,s.useRef)(null),x=(0,s.useRef)(0),m=(0,s.useRef)(null),h=(0,s.useRef)(t.onEvent);h.current=t.onEvent;let p=(0,s.useRef)(null),g=(0,s.useRef)(!1),f=(0,s.useRef)(new Set),b=(0,s.useRef)(!1),v=(0,s.useCallback)(e=>{let t="number"==typeof e.seq?e.seq:null;if(null!==t&&f.current.has(t))return!1;if(null!==t&&(f.current.add(t),p.current=t,f.current.size>1e3)){let e=Array.from(f.current).sort((e,t)=>e-t);for(let t of e.slice(0,e.length-500))f.current.delete(t)}let{seq:r,...s}=e;if(s&&"object"==typeof s&&"type"in s&&"string"==typeof s.type){var a;null===(a=h.current)||void 0===a||a.call(h,s)}else n(s);return!0},[]),y=(0,s.useCallback)(()=>{var e;if((null===(e=u.current)||void 0===e?void 0:e.readyState)===WebSocket.OPEN)return;let r=t.url||(0,eq.HE)("/ws");b.current&&i("reconnecting");try{let e=new WebSocket(r);e.onopen=()=>{l(!0),i("connected"),d(null),x.current=0,b.current&&null!==p.current&&g.current&&(console.log("[WS] Requesting replay from seq ".concat(p.current)),e.send(JSON.stringify({type:"replay",lastSequenceId:p.current}))),b.current=!0},e.onclose=()=>{if(l(!1),u.current=null,t.reconnect&&x.current<t.maxReconnectAttempts){i("reconnecting");let e=Math.min(t.reconnectDelay*Math.pow(2,x.current),15e3);x.current++,console.log("[WS] Reconnecting (attempt ".concat(x.current,")...")),m.current=setTimeout(()=>{y()},Math.round(e*(.5+.5*Math.random())))}else i("disconnected")},e.onerror=e=>{d(Error("WebSocket connection error")),console.error("[useWebSocket] Error:",e)},e.onmessage=e=>{try{let t=JSON.parse(e.data);if(t&&"sync"===t.type&&"number"==typeof t.sequenceId){g.current=!0,null===p.current&&(p.current=t.sequenceId);return}if(t&&"replay"===t.type&&Array.isArray(t.messages)){for(let e of t.messages)v(e);return}v(t)}catch(e){console.error("[useWebSocket] Failed to parse message:",e)}},u.current=e}catch(e){d(e instanceof Error?e:Error("Failed to create WebSocket"))}},[t.url,t.reconnect,t.maxReconnectAttempts,t.reconnectDelay,v]),j=(0,s.useCallback)(()=>{m.current&&(clearTimeout(m.current),m.current=null),u.current&&(u.current.close(),u.current=null),l(!1),i("disconnected")},[]);return(0,s.useEffect)(()=>(t.autoConnect&&y(),()=>{j()}),[t.autoConnect,y,j]),(0,s.useEffect)(()=>{let e=()=>{"visible"!==document.visibilityState||u.current&&u.current.readyState!==WebSocket.CLOSED||(console.log("[WS] Tab visible, reconnecting..."),x.current=0,y())};return document.addEventListener("visibilitychange",e),()=>{document.removeEventListener("visibilitychange",e)}},[y]),{data:r,isConnected:a,connectionState:o,error:c,connect:y,disconnect:j}}({url:y,onEvent:e=>{var t;return null===(t=N.current)||void 0===t?void 0:t.call(N,e)}}),[L,M]=(0,s.useState)(null),[D,A]=(0,s.useState)(!1);(0,s.useEffect)(()=>{if(S&&!k&&!L){let e=!1;return A(!1),r_.hi.getData().then(t=>{e||(t.success&&t.data?M(t.data):A(!0))}).catch(()=>{e||A(!0)}),()=>{e=!0}}},[S,k,L]);let[E,T]=(0,s.useState)(new Map),W=k||L,P=(0,s.useRef)(W);P.current=W,(0,s.useEffect)(()=>{if(W&&E.size>0){let e=Date.now();T(t=>{let r=new Map;for(let[n,s]of t)e-s.timestamp<5e3&&r.set(n,s);return r.size===t.size?t:r})}},[W]);let R=(0,s.useMemo)(()=>W&&0!==E.size?{...W,messages:W.messages.map(e=>{let t=E.get(e.id);return t?{...e,reactions:t.reactions}:e})}:W,[W,E]),{workspaces:I,activeWorkspaceId:B,agents:F,isConnected:U,isLoading:_,error:O,switchWorkspace:H,addWorkspace:z,removeWorkspace:G,spawnAgent:V,stopAgent:K}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{apiUrl:t="http://localhost:3456",enabled:r=!1}=e,[n,a]=(0,s.useState)([]),[l,o]=(0,s.useState)(),[i,c]=(0,s.useState)([]),[d,u]=(0,s.useState)(!1),[x,m]=(0,s.useState)(r),[h,p]=(0,s.useState)(null),g=(0,s.useRef)(null),f=(0,s.useRef)(),b=t.replace(/^http/,"ws"),v=(0,s.useCallback)(async()=>{if(r)try{m(!0),p(null);let e=await fetch("".concat(t,"/workspaces"));if(!e.ok)throw Error("Failed to fetch workspaces: ".concat(e.statusText));let r=await e.json();if(a(r.workspaces.map(e=>({...e,lastActiveAt:new Date(e.lastActiveAt)}))),o(r.activeWorkspaceId),r.activeWorkspaceId){let e=await fetch("".concat(t,"/workspaces/").concat(r.activeWorkspaceId,"/agents"));if(e.ok){let t=await e.json(),n=t.workspaceId||r.activeWorkspaceId;c(t.agents.map(e=>({...e,workspaceId:e.workspaceId||n,spawnedAt:new Date(e.spawnedAt)})))}}}catch(e){p(e instanceof Error?e:Error(String(e)))}finally{m(!1)}},[t,r]),y=(0,s.useRef)(0);(0,s.useEffect)(()=>{if(!r)return;let e=()=>{try{let t=new WebSocket(b);t.onopen=()=>{u(!0),p(null),y.current=0},t.onmessage=e=>{try{let r=JSON.parse(e.data);if("init"===r.type){var t;a(r.data.workspaces.map(e=>({...e,lastActiveAt:new Date(e.lastActiveAt)}))),o(r.data.activeWorkspaceId);let e=r.data.activeWorkspaceId;c((null===(t=r.data.agents)||void 0===t?void 0:t.map(t=>({...t,workspaceId:t.workspaceId||e,spawnedAt:new Date(t.spawnedAt)})))||[]),m(!1)}else"event"===r.type&&j(r.data)}catch(e){console.error("Failed to parse WebSocket message:",e)}},t.onclose=()=>{u(!1),g.current=null;let t=Math.min(500*Math.pow(2,y.current),15e3);y.current++,console.log("[WS:Orchestrator] Reconnecting (attempt ".concat(y.current,")...")),f.current=setTimeout(e,Math.round(t*(.5+.5*Math.random())))},t.onerror=e=>{console.error("WebSocket error:",e),t.close()},g.current=t}catch(r){p(r instanceof Error?r:Error(String(r)));let t=Math.min(500*Math.pow(2,y.current),15e3);y.current++,f.current=setTimeout(e,Math.round(t*(.5+.5*Math.random())))}};v().then(e);let t=()=>{"visible"!==document.visibilityState||g.current&&g.current.readyState!==WebSocket.CLOSED||(console.log("[WS:Orchestrator] Tab visible, reconnecting..."),y.current=0,e())};return document.addEventListener("visibilitychange",t),()=>{document.removeEventListener("visibilitychange",t),f.current&&clearTimeout(f.current),g.current&&g.current.close()}},[b,v,r]);let j=(0,s.useCallback)(e=>{switch(e.type){case"workspace:added":a(t=>[...t,e.data]);break;case"workspace:removed":a(t=>t.filter(t=>t.id!==e.workspaceId));break;case"workspace:updated":a(t=>t.map(t=>t.id===e.workspaceId?{...t,...e.data}:t));break;case"workspace:switched":o(e.data.currentId);break;case"agent:spawned":{let t=e.data;c(r=>[...r,{...t,workspaceId:t.workspaceId||e.workspaceId||l||""}]);break}case"agent:stopped":case"agent:crashed":c(t=>t.filter(t=>t.name!==e.data.name));break;case"agent:restarted":c(t=>t.map(t=>t.name===e.data.name?{...t,status:"running",restartCount:t.restartCount+1}:t))}},[l]),w=(0,s.useCallback)(async e=>{let r=await fetch("".concat(t,"/workspaces/").concat(e,"/switch"),{method:"POST"});if(!r.ok)throw Error("Failed to switch workspace: ".concat(r.statusText));let n=await fetch("".concat(t,"/workspaces/").concat(e,"/agents"));n.ok&&c((await n.json()).agents.map(e=>({...e,spawnedAt:new Date(e.spawnedAt)})))},[t]),N=(0,s.useCallback)(async(e,r)=>{let n=await fetch("".concat(t,"/workspaces"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({path:e,name:r})});if(!n.ok)throw Error((await n.json()).error||"Failed to add workspace");return n.json()},[t]),k=(0,s.useCallback)(async e=>{let r=await fetch("".concat(t,"/workspaces/").concat(e),{method:"DELETE"});if(!r.ok)throw Error("Failed to remove workspace: ".concat(r.statusText))},[t]),C=(0,s.useCallback)(async(e,r,n,s)=>{if(!l)throw Error("No active workspace");let a=await fetch("".concat(t,"/workspaces/").concat(l,"/agents"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:e,task:r,provider:n,cwd:s})});if(!a.ok)throw Error((await a.json()).error||"Failed to spawn agent");let o=await a.json(),i=await fetch("".concat(t,"/workspaces/").concat(l,"/agents"));if(i.ok){let e=await i.json(),t=e.workspaceId||l;c(e.agents.map(e=>({...e,workspaceId:e.workspaceId||t,spawnedAt:new Date(e.spawnedAt)})))}return o},[t,l]),S=(0,s.useCallback)(async e=>{if(!l)throw Error("No active workspace");let r=await fetch("".concat(t,"/workspaces/").concat(l,"/agents/").concat(e),{method:"DELETE"});if(!r.ok)throw Error("Failed to stop agent: ".concat(r.statusText))},[t,l]);return{workspaces:n,activeWorkspaceId:l,agents:i,isConnected:d,isLoading:x,error:h,switchWorkspace:w,addWorkspace:N,removeWorkspace:k,spawnAgent:C,stopAgent:S,refresh:v}}({apiUrl:j}),Z=(0,sU.uo)(),q=(null==Z?void 0:Z.user)?{displayName:Z.user.githubUsername||Z.user.displayName||"",avatarUrl:Z.user.avatarUrl}:void 0,[J,$]=(0,s.useState)([]),[Y,X]=(0,s.useState)(()=>(0,r_.J$)()),[Q,et]=(0,s.useState)(!1),[er,en]=(0,s.useState)([]);(0,s.useEffect)(()=>{if(!(null==Z?void 0:Z.user))return;let e=async e=>{e&&et(!0);try{let e=await c.xv.getAccessibleWorkspaces();if(e.success&&e.data.workspaces){$(e.data.workspaces);let t=new Set(e.data.workspaces.map(e=>e.id));if(Y&&!t.has(Y)){if(e.data.workspaces.length>0){let t=e.data.workspaces[0].id;X(t),(0,r_.hc)(t)}else X(null),(0,r_.hc)(null)}else if(!Y&&e.data.workspaces.length>0){let t=e.data.workspaces[0].id;X(t),(0,r_.hc)(t)}}}catch(e){console.error("Failed to fetch cloud workspaces:",e)}finally{e&&et(!1)}};e(!0);let t=setInterval(()=>e(!1),3e4);return()=>clearInterval(t)},[null==Z?void 0:Z.user,Y]),(0,s.useEffect)(()=>{if(!(null==Z?void 0:Z.user)||!Y){en([]);return}let e=async()=>{try{let e=await r_.hi.get("/api/daemons/workspace/".concat(Y,"/agents"));if(e.agents){let t=e.agents.map(e=>({name:e.name,status:"online"===e.daemonStatus?"online":"offline",isLocal:!e.isHuman,isHuman:e.isHuman,avatarUrl:e.avatarUrl,daemonName:e.isHuman?void 0:e.daemonName,machineId:e.isHuman?void 0:e.machineId,lastSeen:e.lastSeenAt||void 0}));en(t)}}catch(e){console.error("Failed to fetch local agents:",e),en([])}};e();let t=setInterval(e,15e3);return()=>clearInterval(t)},[null==Z?void 0:Z.user,Y]);let es=null!==(h=null==Z?void 0:Z.isCloudMode)&&void 0!==h&&h,ea=(0,s.useMemo)(()=>es&&J.length>0?J.map(e=>({id:e.id,name:e.name,path:e.publicUrl||"/workspace/".concat(e.name),status:"running"===e.status?"active":"inactive",provider:"claude",lastActiveAt:new Date})):I,[es,J,I]),el=es?Y:null!=B?B:"default",eo=es?Q:_;(0,s.useEffect)(()=>{es&&Y?(0,r_.hc)(Y):es&&!Y?(0,r_.hc)(null):es||(0,r_.hc)(null)},[es,Y]);let ei=(0,s.useCallback)(async e=>{es?(X(e.id),(0,r_.hc)(e.id)):await H(e.id)},[es,H]),ec=(0,s.useMemo)(()=>q?{username:q.displayName,avatarUrl:q.avatarUrl}:void 0,[null==q?void 0:q.displayName,null==q?void 0:q.avatarUrl]),[ed,eu]=(0,s.useState)(es?sz:"#general"),[ex,em]=(0,s.useState)([]),eh=(0,s.useCallback)(e=>{let t={...e,id:"activity-".concat(Date.now(),"-").concat(Math.random().toString(36).slice(2,9)),timestamp:new Date().toISOString()};em(e=>[t,...e].slice(0,200))},[]),[ep,eg]=(0,s.useState)(!1),[ef,eb]=(0,s.useState)([]),ev=(0,s.useCallback)((e,t)=>e.some(e=>e.id===t.id||e.from===t.from&&e.content===t.content&&e.threadId===t.threadId&&2e3>Math.abs(new Date(e.timestamp).getTime()-new Date(t.timestamp).getTime())),[]),ey=(0,s.useCallback)((e,t,r)=>{var n;let s=null===(n=null==r?void 0:r.incrementUnread)||void 0===n||n;eV(r=>{var n;let s=null!==(n=r[e])&&void 0!==n?n:[];if(ev(s,t))return r;let a=[...s,t].sort((e,t)=>new Date(e.timestamp).getTime()-new Date(t.timestamp).getTime());return{...r,[e]:a}}),ed===e?(ez(e=>ev(e,t)?e:[...e,t].sort((e,t)=>new Date(e.timestamp).getTime()-new Date(t.timestamp).getTime())),e0(void 0)):s&&eU(t=>t.find(t=>t.id===e)?t.map(t=>{var r;return t.id===e?{...t,unreadCount:(null!==(r=t.unreadCount)&&void 0!==r?r:0)+1}:t}):[...t,{id:e,name:e.startsWith("#")?e.slice(1):e,visibility:"public",status:"active",createdAt:new Date().toISOString(),createdBy:(null==q?void 0:q.displayName)||"Dashboard",memberCount:1,unreadCount:1,hasMentions:!1,isDm:e.startsWith("dm:")}])},[null==q?void 0:q.displayName,ed]),ej=(0,s.useCallback)(e=>{var t,r,n,s;if((null==e?void 0:e.type)==="presence_join"&&e.user){let t=e.user;t.username!==(null==q?void 0:q.displayName)&&eh({type:"user_joined",actor:t.username,actorAvatarUrl:t.avatarUrl,actorType:"user",title:"came online"})}else if((null==e?void 0:e.type)==="presence_leave"&&e.username)e.username!==(null==q?void 0:q.displayName)&&eh({type:"user_left",actor:e.username,actorType:"user",title:"went offline"});else if((null==e?void 0:e.type)==="agent_spawned"&&e.agent)eh({type:"agent_spawned",actor:e.agent.name||e.agent,actorType:"agent",title:"was spawned",description:e.task,metadata:{cli:e.cli,task:e.task,spawnedBy:e.spawnedBy}});else if((null==e?void 0:e.type)==="agent_released"&&e.agent)eh({type:"agent_released",actor:e.agent.name||e.agent,actorType:"agent",title:"was released",metadata:{releasedBy:e.releasedBy}});else if((null==e?void 0:e.type)==="channel_created"){let t=e.channel;if(!t||!t.id)return;eU(e=>{if(e.some(e=>e.id===t.id))return e;let r={id:t.id,name:t.name||t.id,description:t.description,visibility:t.visibility||"public",status:t.status||"active",createdAt:t.createdAt||new Date().toISOString(),createdBy:t.createdBy||"unknown",memberCount:t.memberCount||1,unreadCount:t.unreadCount||0,hasMentions:t.hasMentions||!1,isDm:t.isDm||!1};return console.log("[App] Channel created via WebSocket:",r.id),[...e,r]})}else if((null==e?void 0:e.type)==="channel_message"){let n=e.channel;if(!n)return;let s=e.from||"unknown",a=e.fromEntityType||((null==q?void 0:q.displayName)&&s===q.displayName?"user":"agent"),l={id:null!==(t=e.id)&&void 0!==t?t:"ws-".concat(Date.now()),channelId:n,from:s,fromEntityType:a,fromAvatarUrl:e.fromAvatarUrl,content:null!==(r=e.body)&&void 0!==r?r:"",timestamp:e.timestamp||new Date().toISOString(),threadId:e.thread,isRead:ed===n};ey(n,l,{incrementUnread:ed!==n})}else if((null==e?void 0:e.type)==="direct_message"){let t=e.from||"unknown",r=[t,(null==q?void 0:q.displayName)||e.targetUser||"Dashboard"].sort(),a="dm:".concat(r.join(":")),l=e.fromEntityType||"agent",o={id:null!==(n=e.id)&&void 0!==n?n:"dm-".concat(Date.now()),channelId:a,from:t,fromEntityType:l,fromAvatarUrl:e.fromAvatarUrl,content:null!==(s=e.body)&&void 0!==s?s:"",timestamp:e.timestamp||new Date().toISOString(),threadId:e.thread,isRead:ed===a};ey(a,o,{incrementUnread:ed!==a})}},[eh,ey,null==q?void 0:q.displayName,ed]);N.current=ej;let{onlineUsers:ew,typingUsers:eN,sendTyping:ek,isConnected:eC}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{currentUser:t,wsUrl:r,autoConnect:n=!0,onEvent:a,workspaceId:l}=e,[o,i]=(0,s.useState)([]),[c,d]=(0,s.useState)([]),[u,x]=(0,s.useState)(!1),[m,h]=(0,s.useState)("disconnected"),p=(0,s.useRef)(null),g=(0,s.useRef)(null),f=(0,s.useRef)(0),b=(0,s.useRef)(null),v=(0,s.useRef)(!1),y=(0,s.useRef)(!1),j=(0,s.useRef)(t);j.current=t;let w=(0,s.useRef)(l);w.current=l;let N=(0,s.useRef)(a);N.current=a,(0,s.useEffect)(()=>{let e=setInterval(()=>{let e=Date.now();d(t=>t.filter(t=>e-t.startedAt<3e3))},1e3);return()=>clearInterval(e)},[]);let k=(0,s.useCallback)(()=>{var e;if(!j.current||(null===(e=p.current)||void 0===e?void 0:e.readyState)===WebSocket.OPEN||v.current)return;y.current&&h("reconnecting"),v.current=!0;let t=r||(0,eq.HE)("/ws/presence");try{let e=new WebSocket(t);e.onopen=()=>{v.current=!1,x(!0),h("connected"),f.current=0,y.current=!0;let t=j.current;if(t){e.send(JSON.stringify({type:"presence",action:"join",user:{username:t.username,avatarUrl:t.avatarUrl}}));let r=w.current;r&&e.send(JSON.stringify({type:"subscribe_channels",workspaceId:r}))}},e.onclose=()=>{if(v.current=!1,x(!1),p.current=null,j.current){h("reconnecting");let e=Math.min(500*Math.pow(2,f.current),15e3);f.current++,console.log("[WS:Presence] Reconnecting (attempt ".concat(f.current,")...")),g.current=setTimeout(()=>{k()},Math.round(e*(.5+.5*Math.random())))}else h("disconnected")},e.onerror=e=>{console.error("[usePresence] Error:",e)},e.onmessage=e=>{try{var t,r,n,s;let a=JSON.parse(e.data);switch(a.type){case"presence_list":i(a.users||[]);break;case"presence_join":i(e=>[...e.filter(e=>e.username!==a.user.username),a.user]),null===(t=N.current)||void 0===t||t.call(N,a);break;case"presence_leave":i(e=>e.filter(e=>e.username!==a.username)),d(e=>e.filter(e=>e.username!==a.username)),null===(r=N.current)||void 0===r||r.call(N,a);break;case"typing":if(a.username===(null===(n=j.current)||void 0===n?void 0:n.username))break;a.isTyping?d(e=>[...e.filter(e=>e.username!==a.username),{username:a.username,avatarUrl:a.avatarUrl,startedAt:Date.now()}]):d(e=>e.filter(e=>e.username!==a.username));break;default:null===(s=N.current)||void 0===s||s.call(N,a)}}catch(e){console.error("[usePresence] Failed to parse message:",e)}},p.current=e}catch(e){console.error("[usePresence] Failed to create WebSocket:",e)}},[r]),C=(0,s.useCallback)(()=>{if(g.current&&(clearTimeout(g.current),g.current=null),v.current=!1,p.current){let e=p.current;e.onclose=null,e.onerror=null;let t=j.current;e.readyState===WebSocket.OPEN&&t&&e.send(JSON.stringify({type:"presence",action:"leave",username:t.username})),e.close(),p.current=null}x(!1),h("disconnected")},[]),S=(0,s.useCallback)(e=>{if(!p.current||p.current.readyState!==WebSocket.OPEN)return;let t=j.current;t&&(b.current&&(clearTimeout(b.current),b.current=null),p.current.send(JSON.stringify({type:"typing",isTyping:e,username:t.username,avatarUrl:t.avatarUrl})),e&&(b.current=setTimeout(()=>{b.current=null,S(!1)},3e3)))},[]);return(0,s.useEffect)(()=>{if(n&&j.current&&(!p.current||p.current.readyState===WebSocket.CLOSED))return k(),()=>{C()}},[n,null==t?void 0:t.username,k,C]),(0,s.useEffect)(()=>{let e=()=>{var e;let t=j.current;(null===(e=p.current)||void 0===e?void 0:e.readyState)===WebSocket.OPEN&&t&&p.current.send(JSON.stringify({type:"presence",action:"leave",username:t.username}))};return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[]),(0,s.useEffect)(()=>{let e=()=>{"visible"===document.visibilityState&&j.current&&(!p.current||p.current.readyState===WebSocket.CLOSED)&&(console.log("[WS:Presence] Tab visible, reconnecting..."),f.current=0,k())};return document.addEventListener("visibilitychange",e),()=>{document.removeEventListener("visibilitychange",e)}},[k]),{onlineUsers:o,typingUsers:c,sendTyping:S,isConnected:u,connectionState:m}}({currentUser:ec,onEvent:ej,workspaceId:null!=el?el:void 0});(0,s.useEffect)(()=>{(null==q?void 0:q.displayName)?localStorage.setItem("relay_username",q.displayName):es||localStorage.removeItem("relay_username")},[null==q?void 0:q.displayName,es]);let{memberUsernames:eS}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{workspaceId:t,enabled:r=!0}=e,[n,a]=(0,s.useState)([]),[l,o]=(0,s.useState)(!1),[i,d]=(0,s.useState)(null),u=(0,s.useCallback)(async()=>{if(!t||!r){a([]);return}o(!0),d(null);try{let e=await c.xv.getWorkspaceMembers(t);e.success?a(e.data.members):(d(e.error),a([]))}catch(e){d(e instanceof Error?e.message:"Failed to fetch members"),a([])}finally{o(!1)}},[t,r]);return(0,s.useEffect)(()=>{u()},[u]),{memberUsernames:(0,s.useMemo)(()=>{let e=new Set;for(let a of n){var t,r,s;(null===(t=a.user)||void 0===t?void 0:t.githubUsername)&&e.add(a.user.githubUsername.toLowerCase()),(null===(r=a.user)||void 0===r?void 0:r.displayName)&&e.add(a.user.displayName.toLowerCase()),(null===(s=a.user)||void 0===s?void 0:s.email)&&e.add(a.user.email.split("@")[0].toLowerCase())}return e},[n]),isLoading:l,error:i,refetch:u}}({workspaceId:null!=el?el:void 0,enabled:es&&!!el}),eL=(0,s.useMemo)(()=>0===eS.size?ew:ew.filter(e=>eS.has(e.username.toLowerCase())),[ew,eS]),[eM,eD]=(0,s.useState)(null),[eA,eE]=(0,s.useState)(),[eT,eP]=(0,s.useState)(null),eR=(0,s.useMemo)(()=>{var e;let t=new Map;for(let r of null!==(e=null==R?void 0:R.summaries)&&void 0!==e?e:[])t.set(r.agentName.toLowerCase(),r);return t},[null==R?void 0:R.summaries]),[eI,eB]=(0,s.useState)(es?"local":"channels"),[eF,eU]=(0,s.useState)([]),[e_,eO]=(0,s.useState)([]),[eH,ez]=(0,s.useState)([]),[eG,eV]=(0,s.useState)({}),eK=(0,s.useRef)(new Set),[eZ,eJ]=(0,s.useState)(!1),[eY,eX]=(0,s.useState)(!1),[eQ,e0]=(0,s.useState)(),e1=["#general","#engineering"],e2=(0,s.useCallback)(e=>{let t=[...e.archivedChannels||[],...e.channels.filter(e=>"archived"===e.status)],r=e.channels.filter(e=>"archived"!==e.status),n=new Set(r.map(e=>e.id));eU([...e1.filter(e=>!n.has(e)).map(e=>({id:e,name:e.replace("#",""),description:"#general"===e?"General discussion for all agents":"Engineering discussion",visibility:"public",memberCount:0,unreadCount:0,hasMentions:!1,createdAt:new Date().toISOString(),status:"active",createdBy:"system",isDm:!1})),...r]),eO(t)},[]),e5=(0,s.useMemo)(()=>{if(ed)return eF.find(e=>e.id===ed)||e_.find(e=>e.id===ed)},[ed,eF,e_]),[e4,e3]=(0,s.useState)([]),[e6,e8]=(0,s.useState)(),[e9,e7]=(0,s.useState)(!1),[tt,tr]=(0,s.useState)(!1),[tn,ts]=(0,s.useState)(null),[tl,to]=(0,s.useState)(!1),[ti,tc]=(0,s.useState)(!1),[td,tm]=(0,s.useState)(null),[th,tp]=(0,s.useState)(!1),[tg,tf]=(0,s.useState)(!1),[tb,tv]=(0,s.useState)(!1),[ty,tj]=(0,s.useState)(null),[tw,tN]=(0,s.useState)(!1),[tk,tC]=(0,s.useState)(!1),[tS,tL]=(0,s.useState)(()=>(function(){try{let r=localStorage.getItem(sH);if(!r)return rU;let n=JSON.parse(r);if(!n||"object"!=typeof n)return rU;if("notifications"in n&&"display"in n){var e,t;let r={...rU,...n,notifications:{...rU.notifications,...n.notifications},display:{...rU.display,...n.display},messages:{...rU.messages,...n.messages},connection:{...rU.connection,...n.connection},agentDefaults:{...rU.agentDefaults,...n.agentDefaults,defaultModels:{...null===(e=rU.agentDefaults)||void 0===e?void 0:e.defaultModels,...null===(t=n.agentDefaults)||void 0===t?void 0:t.defaultModels}}};return r.notifications.enabled=r.notifications.sound||r.notifications.desktop||r.notifications.mentionsOnly,r}if("notificationsEnabled"in n||"soundEnabled"in n||"autoScrollMessages"in n)return function(e){var t,r,n,s,a;let l=e.theme&&["dark","light","system"].includes(e.theme)?e.theme:rU.theme,o=null!==(t=e.soundEnabled)&&void 0!==t?t:rU.notifications.sound,i=null!==(r=e.notificationsEnabled)&&void 0!==r?r:rU.notifications.desktop;return{...rU,theme:l,display:{...rU.display,compactMode:null!==(n=e.compactMode)&&void 0!==n?n:rU.display.compactMode,showTimestamps:null!==(s=e.showTimestamps)&&void 0!==s?s:rU.display.showTimestamps},notifications:{...rU.notifications,sound:o,desktop:i,enabled:o||i||rU.notifications.mentionsOnly},messages:{...rU.messages,autoScroll:null!==(a=e.autoScrollMessages)&&void 0!==a?a:rU.messages.autoScroll}}}(n)}catch(e){}return rU})()),tM=(0,s.useCallback)(e=>{tL(t=>e(t))},[]),[tD,tE]=(0,s.useState)(!1),[tT,tW]=(0,s.useState)("dashboard"),[tP,tR]=(0,s.useState)(!1),[tI,tB]=(0,s.useState)(!1),[tU,t_]=(0,s.useState)({}),[tO,tH]=(0,s.useState)({}),[tz,tG]=(0,s.useState)(null),[tV,tK]=(0,s.useState)(!1),{steps:tZ,status:tq,history:tJ,isLoading:t$,selectTrajectory:tY,selectedTrajectoryId:tX}=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{pollInterval:t=2e3,autoPoll:r=!0,trajectoryId:n,apiBaseUrl:a=""}=e,[l,o]=(0,s.useState)([]),[i,c]=(0,s.useState)(null),[d,u]=(0,s.useState)([]),[x,m]=(0,s.useState)(!0),[h,p]=(0,s.useState)(null),[g,f]=(0,s.useState)(n||null),b=(0,s.useRef)(null),v=(0,s.useRef)(!1),y=(0,s.useRef)(!1),j=(0,s.useRef)(g),w=(0,s.useRef)(0),N=(0,s.useCallback)(async()=>{try{let e=a?"".concat(a,"/api/trajectory"):(0,r_.kG)("/api/trajectory"),t=await fetch(e,{credentials:"include"}),r=await t.json();!1!==r.success&&c({active:r.active,trajectoryId:r.trajectoryId,phase:r.phase,task:r.task})}catch(e){console.error("[useTrajectory] Status fetch error:",e)}},[a]),k=(0,s.useCallback)(async()=>{try{let e=a?"".concat(a,"/api/trajectory/history"):(0,r_.kG)("/api/trajectory/history"),t=await fetch(e,{credentials:"include"}),r=await t.json();r.success&&u(r.trajectories||[])}catch(e){console.error("[useTrajectory] History fetch error:",e)}},[a]),C=(0,s.useCallback)(async()=>{let e=++w.current;try{let t=g?"/api/trajectory/steps?trajectoryId=".concat(encodeURIComponent(g)):"/api/trajectory/steps",r=a?"".concat(a).concat(t):(0,r_.kG)(t),n=await fetch(r,{credentials:"include"}),s=await n.json();if(e!==w.current){console.log("[useTrajectory] Ignoring superseded fetch (request",e,"current",w.current,")");return}if(g!==j.current){console.log("[useTrajectory] Ignoring stale fetch for",g,"current is",j.current);return}s.success?(o(s.steps||[]),p(null)):p(s.error||"Failed to fetch trajectory steps")}catch(t){e===w.current&&g===j.current&&(console.error("[useTrajectory] Steps fetch error:",t),p(t.message))}},[a,g]),S=(0,s.useCallback)(e=>{let t=""===e?null:e;t!==g&&(w.current++,j.current=t,o([]),null!==t&&m(!0),f(t))},[g]),L=(0,s.useCallback)(async()=>{m(!0),await Promise.all([N(),C(),k()]),m(!1)},[N,C,k]);return(0,s.useEffect)(()=>{j.current=g},[g]),(0,s.useEffect)(()=>{y.current||(y.current=!0,L())},[L]),(0,s.useEffect)(()=>{if(!v.current){v.current=!0;return}let e=!1;return m(!0),C().finally(()=>{e||m(!1)}),()=>{e=!0}},[g,C]),(0,s.useEffect)(()=>{if(!r)return;b.current=setInterval(()=>{C(),N()},t);let e=setInterval(k,1e4);return()=>{b.current&&clearInterval(b.current),clearInterval(e)}},[r,t,C,N,k]),{steps:l,status:i,history:d,isLoading:x,error:h,refresh:L,selectTrajectory:S,selectedTrajectoryId:g}}({autoPoll:tV}),tQ=(0,s.useMemo)(()=>{var e,t;return tX&&null!==(t=null===(e=tJ.find(e=>e.id===tX))||void 0===e?void 0:e.title)&&void 0!==t?t:null},[tX,tJ]),{recentRepos:t0,addRecentRepo:t1,getRecentProjects:t2}=function(){var e;let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=null!==(e=t.maxRecent)&&void 0!==e?e:5,[n,a]=(0,s.useState)([]);(0,s.useEffect)(()=>{a(function(){try{let e=localStorage.getItem(sI);if(!e)return[];let t=JSON.parse(e);if(!Array.isArray(t))return[];return t}catch(e){return[]}}())},[]);let l=(0,s.useCallback)(e=>{a(t=>{let n=t.filter(t=>t.id!==e.id),s=[{id:e.id,path:e.path,name:e.name,lastAccessed:Date.now()},...n].slice(0,r);return sB(s),s})},[r]),o=(0,s.useCallback)(e=>{a(t=>{let r=t.filter(t=>t.id!==e);return sB(r),r})},[]),i=(0,s.useCallback)(()=>{a([]),sB([])},[]),c=(0,s.useCallback)(e=>{let t=new Map(e.map(e=>[e.id,e]));return n.map(e=>t.get(e.id)).filter(e=>void 0!==e)},[n]);return{recentRepos:n,addRecentRepo:l,removeRecentRepo:o,clearRecentRepos:i,getRecentProjects:c}}(),{repos:t5,refetch:t4}=function(e){let{workspaceId:t,apiBaseUrl:r="/api",enabled:n=!0}=e,[a,l]=(0,s.useState)([]),[o,i]=(0,s.useState)(!1),[c,d]=(0,s.useState)(null),u=(0,s.useCallback)(async()=>{if(t&&n){i(!0),d(null);try{let e=await fetch("".concat(r,"/workspaces/").concat(t,"/repos"),{credentials:"include"});if(!e.ok)throw Error("Failed to fetch workspace repos");let n=await e.json();l(n.repositories||[])}catch(e){d(e instanceof Error?e.message:"Failed to fetch repos"),console.error("Error fetching workspace repos:",e)}finally{i(!1)}}},[t,r,n]);return(0,s.useEffect)(()=>{u()},[u]),{repos:a,isLoading:o,error:c,refetch:u}}({workspaceId:null!=el?el:void 0,apiBaseUrl:"/api",enabled:es&&!!el});(0,s.useEffect)(()=>{eV({}),ez([]),eu(void 0),eK.current.clear()},[el]);let[t3,t6]=(0,s.useState)(!1),[t8,t9]=(0,s.useState)(!1),[t7,re]=(0,s.useState)([]),[rt,rr]=(0,s.useState)({}),[rn,rs]=(0,s.useState)(!1),[ra,rl]=(0,s.useState)([]),{toasts:ro,addToast:ri,dismissToast:rc}=function(){let[e,t]=(0,s.useState)([]),r=(0,s.useCallback)(e=>{let r=Math.random().toString(36).substring(2,9);return t(t=>[...t,{...e,id:r}]),r},[]),n=(0,s.useCallback)(e=>{t(t=>t.filter(t=>t.id!==e))},[]),a=(0,s.useCallback)(()=>{t([])},[]),l=(0,s.useCallback)((e,t)=>r({type:"info",title:e,message:t}),[r]),o=(0,s.useCallback)((e,t)=>r({type:"success",title:e,message:t}),[r]),i=(0,s.useCallback)((e,t)=>r({type:"warning",title:e,message:t}),[r]),c=(0,s.useCallback)((e,t)=>r({type:"error",title:e,message:t}),[r]),d=(0,s.useCallback)((e,t,n)=>r({type:"message",title:"New Message",message:t,agentName:e,action:n}),[r]);return{toasts:e,addToast:r,dismissToast:n,clearToasts:a,info:l,success:o,warning:i,error:c,message:d}}(),[rd,ru]=(0,s.useState)(new Set),[rx,rm]=(0,s.useState)(),[rh,rp]=(0,s.useState)(!1),[rg,rf]=(0,s.useState)(!1),[rb,rv]=(0,s.useState)(!1),ry=(0,s.useRef)(0),rj=(0,s.useRef)(!0),[rw,rN]=(0,s.useState)(new Map),rC=(0,s.useRef)(null),rS=(0,s.useCallback)(()=>{window.innerWidth<=768&&rf(!1)},[]),rL=(0,s.useMemo)(()=>(function(e){let{agents:t=[],users:r=[],localAgents:n=[]}=e,s=[...t,...r,...n].filter(e=>"dashboard"!==e.name.toLowerCase()),a=new Map;for(let e of s){let t=e.name.toLowerCase(),r=a.get(t);if(r){let n=!r.isLocal&&e.isLocal;a.set(t,{...r,...e,isLocal:!n&&!!e.isLocal})}else a.set(t,e)}return Array.from(a.values())})({agents:null==R?void 0:R.agents,users:null==R?void 0:R.users,localAgents:er}),[null==R?void 0:R.agents,null==R?void 0:R.users,er]),rM=(0,s.useRef)(new Map);(0,s.useEffect)(()=>{if(!rL||0===rL.length)return;let e=new Map(rL.map(e=>[e.name,e])),t=rM.current;if(t.size>0){for(let[r,n]of e)t.has(r)?t.get(r).status!==n.status&&("online"===n.status||"busy"===n.status?eh({type:"agent_online",actor:r,actorType:"agent",title:"came online",metadata:{cli:n.cli}}):"offline"===n.status&&eh({type:"agent_offline",actor:r,actorType:"agent",title:"went offline"})):eh({type:"agent_spawned",actor:r,actorType:"agent",title:"came online",description:n.currentTask,metadata:{cli:n.cli,task:n.currentTask}});for(let[r]of t)e.has(r)||eh({type:"agent_released",actor:r,actorType:"agent",title:"went offline"})}rM.current=e},[rL,eh]);let rD=(0,s.useCallback)(e=>{rN(t=>{let r=new Map(t);return r.set(e.toLowerCase(),Date.now()),r})},[]),{agents:rA,groups:rE,selectedAgent:rT,selectAgent:rW,searchQuery:rP,setSearchQuery:rR,totalCount:rI,onlineCount:rB,needsAttentionCount:rF}=function(e){let{agents:t,initialSelected:r,initialSearchQuery:n=""}=e,[a,l]=(0,s.useState)(null!=r?r:null),[o,i]=(0,s.useState)(n),c=(0,s.useMemo)(()=>g(t,o),[t,o]),d=(0,s.useMemo)(()=>m(c),[c]),u=(0,s.useMemo)(()=>[...c].sort((e,t)=>e.name.localeCompare(t.name)),[c]),h=(0,s.useMemo)(()=>{var e;return null!==(e=t.find(e=>e.name===a))&&void 0!==e?e:null},[t,a]),p=(0,s.useMemo)(()=>{let e=b(t);return{totalCount:e.total,onlineCount:e.online,needsAttentionCount:e.needsAttention}},[t]),f=(0,s.useCallback)(e=>{l(e)},[]),v=(0,s.useCallback)(e=>t.find(t=>t.name===e),[t]),y=(0,s.useCallback)(e=>({...e,color:(0,x.GW)(e.name)}),[]);return{agents:c,groups:d,sortedAgents:u,selectedAgent:h,selectAgent:f,searchQuery:o,setSearchQuery:i,...p,getAgentByName:v,getAgentWithColor:y}}({agents:rL}),{messages:rH,threadMessages:rz,currentChannel:rG,setCurrentChannel:rV,currentThread:rK,setCurrentThread:rZ,activeThreads:rq,totalUnreadThreadCount:rJ,sendMessage:r$,isSending:rX,sendError:rQ}=function(e){let{messages:t,currentChannel:r="general",senderName:n}=e,[a,l]=(0,s.useState)(r),[o,i]=(0,s.useState)(null),[c,d]=(0,s.useState)(!1),[u,x]=(0,s.useState)(null),[m,h]=(0,s.useState)(new Map),p=n||"Dashboard",[g,f]=(0,s.useState)([]);(0,s.useEffect)(()=>{if(0===g.length)return;let e=new Set(t.slice(-50).map(e=>"".concat(e.to,":").concat(e.content.slice(0,100))));f(t=>t.filter(t=>{let r="".concat(t.to,":").concat(t.content.slice(0,100));return!e.has(r)}))},[t,g.length]);let b=(0,s.useMemo)(()=>0===g.length?t:[...t,...g].sort((e,t)=>new Date(e.timestamp).getTime()-new Date(t.timestamp).getTime()),[t,g]),v=(0,s.useMemo)(()=>{let e=new Set(b.map(e=>e.id)),t=b.filter(t=>!t.thread||!e.has(t.thread));return"general"===a?t:t.filter(e=>e.from===a||e.to===a)},[b,a]),y=(0,s.useCallback)(e=>b.filter(t=>t.thread===e),[b]),j=(0,s.useMemo)(()=>{let e=new Map,t=new Set(b.map(e=>e.id));for(let t of b)if(t.thread){let r=e.get(t.thread)||[];r.push(t),e.set(t.thread,r)}let r=[];for(let[n,s]of e.entries()){let e=[...s].sort((e,t)=>new Date(t.timestamp).getTime()-new Date(e.timestamp).getTime()),a=[...new Set(s.flatMap(e=>[e.from,e.to]))].filter(e=>"*"!==e),l=m.get(n),o=s.filter(e=>e.from!==p&&!e.isRead&&(!l||new Date(e.timestamp).getTime()>l)).length,i=n;if(t.has(n)){let e=b.find(e=>e.id===n);if(e){let t=e.content.split("\n")[0];i=t.length>30?t.substring(0,30)+"...":t}}r.push({id:n,name:i,lastMessage:e[0],messageCount:s.length,unreadCount:o,participants:a})}return r.sort((e,t)=>new Date(t.lastMessage.timestamp).getTime()-new Date(e.lastMessage.timestamp).getTime())},[b,m]),w=(0,s.useCallback)(e=>{i(e),e&&h(t=>{let r=new Map(t);return r.set(e,Date.now()),r})},[]),N=(0,s.useMemo)(()=>j.filter(e=>e.unreadCount>0).length,[j]),k=(0,s.useMemo)(()=>{let e=b.filter(e=>!e.isRead).length;return{totalCount:b.length,unreadCount:e}},[b]);return{messages:v,threadMessages:y,currentChannel:a,setCurrentChannel:l,currentThread:o,setCurrentThread:w,activeThreads:j,totalUnreadThreadCount:N,sendMessage:(0,s.useCallback)(async(e,t,r,s)=>{d(!0),x(null);let a="optimistic-".concat(Date.now(),"-").concat(Math.random().toString(36).slice(2,9)),l={id:a,from:p,to:e,content:t,timestamp:new Date().toISOString(),status:"sending",thread:r,isRead:!0};f(e=>[...e,l]);try{let l={to:e,message:t,thread:r,attachments:s};n&&(l.from=n);let o=await r_.hi.sendMessage(l);if(o.success)return!0;return f(e=>e.filter(e=>e.id!==a)),x(o.error||"Failed to send message"),!1}catch(e){return f(e=>e.filter(e=>e.id!==a)),x("Network error"),!1}finally{d(!1)}},[p,n]),isSending:c,sendError:u,...k}}({messages:null!==(p=null==R?void 0:R.messages)&&void 0!==p?p:[],senderName:null==q?void 0:q.displayName}),r0=function(e){var t,r,n;let{threadId:a,fallbackMessages:l}=e,[o,i]=(0,s.useState)(null),[c,d]=(0,s.useState)([]),[u,x]=(0,s.useState)(!1),[m,h]=(0,s.useState)(!1),[p,g]=(0,s.useState)(),[f,b]=(0,s.useState)(!1),v=(0,s.useRef)(null);(0,s.useEffect)(()=>{if(v.current=a,!a){i(null),d([]),h(!1),g(void 0),b(!1),x(!1);return}i(null),d([]),h(!1),g(void 0),b(!1);let e=!1;return x(!0),r_.hi.getThread(a,{limit:50}).then(t=>{if(!e){if(x(!1),t.success&&t.data){b(!1);let{parent:e,replies:r,nextCursor:n}=t.data;i(e),d(r),h(!!n),g(n)}else b(!0)}}),()=>{e=!0}},[a]);let y=f?null!==(r=null!==(t=null==l?void 0:l.find(e=>e.id===a))&&void 0!==t?t:null==l?void 0:l.filter(e=>e.thread===a).sort((e,t)=>new Date(e.timestamp).getTime()-new Date(t.timestamp).getTime())[0])&&void 0!==r?r:null:o,j=f?null!==(n=null==l?void 0:l.filter(e=>e.thread===a&&e.id!==(null==y?void 0:y.id)))&&void 0!==n?n:[]:c,w=(0,s.useCallback)(async()=>{if(!a||!m||!p||f)return;x(!0);let e=await r_.hi.getThread(a,{cursor:p,limit:50});v.current===a&&(x(!1),e.success&&e.data&&(d(t=>[...e.data.replies,...t]),h(!!e.data.nextCursor),g(e.data.nextCursor)))},[a,m,p,f]);return{parentMessage:y,replies:j,isLoading:u,hasMore:!f&&m,loadMore:w,sendReply:(0,s.useCallback)(async e=>{if(!a)return!1;let t=await r_.hi.postReply(a,e);return!!t.success&&!!t.data&&(d(e=>[...e,t.data]),!0)},[a]),addReply:(0,s.useCallback)(e=>{d(t=>t.some(t=>t.id===e.id)?t:[...t,e])},[])}}({threadId:"channels"===eI?null:rK,fallbackMessages:rH}),r1=(0,s.useMemo)(()=>rG&&rL.find(e=>e.isHuman&&e.name.toLowerCase()===rG.toLowerCase())||null,[rL,rG]),r2=(0,s.useMemo)(()=>{var e;return r1&&null!==(e=tU[r1.name])&&void 0!==e?e:[]},[r1,tU]),r5=(0,s.useMemo)(()=>{var e;return r1&&null!==(e=tO[r1.name])&&void 0!==e?e:[]},[r1,tO]),{visibleMessages:r4,participantAgents:r6}=function(e){let{currentHuman:t,currentUserName:r,messages:n,agents:a,selectedDmAgents:l,removedDmAgents:o}=e,i=(0,s.useMemo)(()=>new Set(a.map(e=>e.name)),[a]),c=(0,s.useMemo)(()=>{if(!t)return[];let e=t.name,r=new Set;for(let t of n){let{from:n,to:s}=t;n&&s&&(n===e&&i.has(s)&&r.add(s),s===e&&i.has(n)&&r.add(n),l.includes(n)&&i.has(s)&&r.add(s),l.includes(s)&&i.has(n)&&r.add(n))}let s=new Set([...l,...r]);return o.forEach(e=>s.delete(e)),Array.from(s)},[i,t,n,o,l]),d=(0,s.useMemo)(()=>{if(!t)return n;let e=new Set([t.name,...c]),s=r||"Dashboard";e.add(s),console.log("[DM Filter] currentHuman:",t.name,"currentUser:",r,"agents:",c,"participants:",Array.from(e));let a=n.filter(t=>{var r,n;if(!t.from||!t.to)return!1;let s=e.has(t.from),a=e.has(t.to),l=s&&a;return((null===(r=t.from)||void 0===r?void 0:r.includes("Agent"))||(null===(n=t.to)||void 0===n?void 0:n.includes("Agent")))&&console.log("[DM Filter] msg:",t.from,"->",t.to,"hasFrom:",s,"hasTo:",a,"passes:",l),l});return console.log("[DM Filter] filtered count:",a.length),a},[t,r,c,n]);return{visibleMessages:(0,s.useMemo)(()=>{var e,r,n,s,a,l;if(!t)return d;let o=e=>(null!=e?e:"").trim().replace(/\s+/g," "),i=e=>"sending"===e.status?1:0,c=(e,t)=>{let r=i(e),n=i(t),s=new Date(e.timestamp).getTime(),a=new Date(t.timestamp).getTime();return n<r?t:n>r?e:a>=s?t:e},u=[...d].sort((e,t)=>new Date(e.timestamp).getTime()-new Date(t.timestamp).getTime()),x=new Map,m=new Map;for(let t of u){if(t.id){let e=x.get(t.id);x.set(t.id,e?c(e,t):t);continue}let n=null!==(r=null===(e=t.from)||void 0===e?void 0:e.toLowerCase())&&void 0!==r?r:"",s=Math.floor(new Date(t.timestamp).getTime()/5e3),a="".concat(n,"|").concat(s,"|").concat(o(t.content)),l=m.get(a);m.set(a,l?c(l,t):t)}let h=[...x.values(),...m.values()],p=new Map;for(let e of h){let t=null!==(a=null===(n=e.from)||void 0===n?void 0:n.toLowerCase())&&void 0!==a?a:"",r=null!==(l=null===(s=e.to)||void 0===s?void 0:s.toLowerCase())&&void 0!==l?l:"",i="".concat(t,"|").concat(r,"|").concat(o(e.content)),d=p.get(i);p.set(i,d?c(d,e):e)}return Array.from(p.values()).sort((e,t)=>new Date(e.timestamp).getTime()-new Date(t.timestamp).getTime())},[t,d]),participantAgents:c}}({currentHuman:r1,currentUserName:null!==(f=null==q?void 0:q.displayName)&&void 0!==f?f:null,messages:rH,agents:rA,selectedDmAgents:r2,removedDmAgents:r5}),r8=(0,s.useMemo)(()=>el||!ed?[]:rH.filter(e=>ed!==sz&&(e.to===ed||e.channel===ed||e.thread===ed)).map(e=>{var t;return{id:e.id,channelId:ed,from:e.from,fromEntityType:"Dashboard"===e.from||e.from===(null==q?void 0:q.displayName)?"user":"agent",content:e.content,timestamp:e.timestamp,isRead:null===(t=e.isRead)||void 0===t||t,threadId:e.thread!==ed?e.thread:void 0}}),[rH,ed,el,null==q?void 0:q.displayName]),r9=eH.length>0?eH:r8,r7=(0,s.useMemo)(()=>{var e;let t=new Set(rA.map(e=>e.name.toLowerCase())),r=new Map;for(let n of(q&&r.set(q.displayName.toLowerCase(),{username:q.displayName,avatarUrl:q.avatarUrl}),null!==(e=null==R?void 0:R.messages)&&void 0!==e?e:[])){let e=n.from;!e||"Dashboard"===e||"*"===e||t.has(e.toLowerCase())||r.has(e.toLowerCase())||r.set(e.toLowerCase(),{username:e})}return Array.from(r.values())},[null==R?void 0:R.messages,rA,q]),ne=(0,s.useMemo)(()=>{var e,t;if(!q)return{};let r={},n=new Set(rL.filter(e=>e.isHuman).map(e=>e.name.toLowerCase()));for(let s of null!==(e=null==R?void 0:R.messages)&&void 0!==e?e:[]){let e=s.from,a=s.to;if(!e||!a)continue;let l=a===q.displayName,o=n.has(e.toLowerCase());if(!l||!o)continue;let i=null!==(t=rw.get(e.toLowerCase()))&&void 0!==t?t:0;new Date(s.timestamp).getTime()>i&&(r[e]=(r[e]||0)+1)}return r},[rL,q,null==R?void 0:R.messages,rw]),{navigateToChannel:nt,navigateToDm:nn,navigateToAgent:ns,navigateToSettings:na,navigateToActivity:nl,closeSettings:no}=function(e){let{onRouteChange:t}=e,r=(0,s.useRef)(!1),n=(0,s.useRef)(""),a=(0,s.useCallback)(function(e){let t=arguments.length>1&&void 0!==arguments[1]&&arguments[1],s=sO(e);s!==window.location.pathname&&(r.current=!0,n.current=s,t?window.history.replaceState({route:e},"",s):window.history.pushState({route:e},"",s),setTimeout(()=>{r.current=!1},0))},[]),l=(0,s.useCallback)(e=>{a({type:"channel",id:e})},[a]),o=(0,s.useCallback)(e=>{a({type:"dm",id:e})},[a]),i=(0,s.useCallback)(e=>{a({type:"agent",id:e})},[a]),c=(0,s.useCallback)(e=>{a({type:"settings",tab:e})},[a]),d=(0,s.useCallback)(()=>{a({type:"activity"})},[a]),u=(0,s.useCallback)(()=>{window.history.length>1?window.history.back():a({type:"activity"})},[a]);return(0,s.useEffect)(()=>{let e=e=>{let r=s_(window.location.pathname);n.current=window.location.pathname,t(r)};return window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)},[t]),(0,s.useEffect)(()=>{let e=window.location.pathname;if(e!==n.current){n.current=e;let r=s_(e);("activity"!==r.type||e.includes("/app"))&&t(r)}},[t]),{navigate:a,navigateToChannel:l,navigateToDm:o,navigateToAgent:i,navigateToSettings:c,navigateToActivity:d,closeSettings:u,parseRoute:s_,buildPath:sO}}({onRouteChange:(0,s.useCallback)(e=>{switch(e.type){case"channel":e.id&&(eB("channels"),eu("activity"===e.id?sz:e.id));break;case"dm":case"agent":e.id&&(eB("local"),eu(void 0),rV(e.id));break;case"settings":tW(e.tab||"dashboard"),tE(!0);break;case"activity":eB("channels"),eu(sz)}},[rV])});(0,s.useEffect)(()=>{q&&rG&&new Set(rL.filter(e=>e.isHuman).map(e=>e.name.toLowerCase())).has(rG.toLowerCase())&&rD(rG)},[rL,rG,q,rD]),(0,s.useEffect)(()=>{if(!(window.innerWidth<=768)){rv(!1);return}let e=rH.length;!rg&&e>ry.current&&rv(!0),rj.current=!rg},[rH.length,rg]),(0,s.useEffect)(()=>{rg&&(rv(!1),ry.current=rH.length)},[rg,rH.length]),(0,s.useEffect)(()=>{ry.current=rH.length},[]),(0,s.useEffect)(()=>{if(null==R?void 0:R.messages)for(let s of R.messages){var e,t,r,n;if((null===(e=s.content)||void 0===e?void 0:e.includes("auth_revoked"))||(null===(t=s.content)||void 0===t?void 0:t.includes("authentication_error")))try{let e=JSON.parse(s.content);if("auth_revoked"===e.type&&e.agent){let t=e.agent;rd.has(t)||(ru(e=>new Set([...e,t])),ri({type:"error",title:"Authentication Expired",message:"".concat(t,"'s API credentials have expired. Please reconnect."),agentName:t,duration:0,action:{label:"Reconnect",onClick:()=>{window.location.href="/providers"}}}))}}catch(e){if((null===(r=s.content)||void 0===r?void 0:r.includes("OAuth token"))&&(null===(n=s.content)||void 0===n?void 0:n.includes("expired"))){let e=s.from;e&&!rd.has(e)&&(ru(t=>new Set([...t,e])),ri({type:"error",title:"Authentication Expired",message:"".concat(e,"'s API credentials have expired. Please reconnect."),agentName:e,duration:0,action:{label:"Reconnect",onClick:()=>{window.location.href="/providers"}}}))}}}},[null==R?void 0:R.messages,rd,ri]);let ni=!!(null==R?void 0:null===(a=R.fleet)||void 0===a?void 0:null===(t=a.servers)||void 0===t?void 0:t.length)||I.length>0,nc=ea.length>0;(0,s.useEffect)(()=>{if(nc){if(t5.length>1&&el){let t=t5.map(e=>{let t=e.githubFullName.split("/").pop()||e.githubFullName;return{id:e.id,path:e.githubFullName,name:t,agents:[],lead:void 0}});if(e3(t),!e6||!t.find(e=>e.id===e6)){var e;e8(null===(e=t[0])||void 0===e?void 0:e.id)}}else if(I.length>0)e3(I.map(e=>({id:e.id,path:e.path,name:e.name,agents:F.filter(t=>t.workspaceId===e.id).map(e=>({name:e.name,status:"running"===e.status?"online":"offline",isSpawned:!0,cli:e.provider,cwd:e.cwd})),lead:void 0}))),e8(B);else if(es&&el){let e=ea.find(e=>e.id===el);e&&(e3([{id:e.id,path:e.path,name:e.name,agents:[],lead:void 0}]),e8(e.id))}}},[nc,I,F,B,t5,el,e6,es,ea]),(0,s.useEffect)(()=>{if(nc)return;let e=async()=>{let e=await r_.hi.getBridgeData();if(e.success&&e.data){let t=e.data;if(t.projects&&t.projects.length>0){let e=t.projects.map(e=>({id:e.id,path:e.path,name:e.name||e.path.split("/").pop(),agents:(e.agents||[]).filter(e=>"dashboard"!==e.cli).map(e=>({name:e.name,status:"online"===e.status||"active"===e.status?"online":"offline",currentTask:e.task,cli:e.cli})),lead:e.lead}));e3(e),!e6&&e.length>0&&e8(e[0].id)}}};e();let t=setInterval(e,5e3);return()=>clearInterval(t)},[nc,e6]);let nd=["architect"],{bridgeAgents:nu,projectAgents:nx}=(0,s.useMemo)(()=>{let e=[],t=[];for(let r of rA)r.isHuman||"dashboard"===r.cli||(nd.includes(r.name.toLowerCase())?e.push(r):t.push(r));return{bridgeAgents:e,projectAgents:t}},[rA]),nm=(0,s.useMemo)(()=>{if(0===e4.length)return e4;if(t5.length>1){let e=[...nx],t=new Set(nx.map(e=>e.name.toLowerCase()));for(let r of F)t.has(r.name.toLowerCase())||(t.add(r.name.toLowerCase()),e.push({name:r.name,status:"running"===r.status?"online":"offline",isSpawned:!0,cli:r.provider,cwd:r.cwd}));if(0===e.length)return e4;let r=new Set(e4.map(e=>e.name)),n=e4.map(t=>{let r=t.name,n=e.filter(e=>e.cwd===r);return{...t,agents:[...t.agents,...n]}}),s=new Set(n.flatMap(e=>e.agents.map(e=>e.name.toLowerCase()))),a=e.filter(e=>!s.has(e.name.toLowerCase())&&(!e.cwd||!r.has(e.cwd)));return a.length>0?[{id:"__workspace__",path:"/workspace",name:"Workspace",agents:a},...n]:n}return 0===nx.length?e4:e4.map((e,t)=>{if(0===t||e.id===e6){let t=new Set(e.agents.map(e=>e.name.toLowerCase())),r=nx.filter(e=>!t.has(e.name.toLowerCase()));return{...e,agents:[...e.agents,...r]}}return e})},[e4,nx,F,e6,t5.length]),nh=(0,s.useMemo)(()=>{let e=e=>es&&0!==eS.size?e.filter(e=>!e.isHuman||eS.has(e.name.toLowerCase())):e,t=e(rA).filter(e=>e.isHuman);return nm.length>0?t:[...e(nx),...t]},[nm,nx,rA,es,eS]);(0,s.useCallback)(async e=>{try{await H(e.id)}catch(e){console.error("Failed to switch workspace:",e)}},[H]);let np=(0,s.useCallback)(async(e,t)=>{tc(!0),tm(null);try{await z(e,t),to(!1)}catch(e){throw tm(e instanceof Error?e.message:"Failed to add workspace"),e}finally{tc(!1)}},[z]),ng=(0,s.useCallback)(e=>{e8(e.id),eB("local"),eu(void 0),t1(e),I.length>0&&H(e.id).catch(e=>{console.error("Failed to switch workspace:",e)}),e.agents.length>0&&(rW(e.agents[0].name),rV(e.agents[0].name)),rS()},[rW,rV,rS,I.length,H,t1]),nf=(0,s.useCallback)(e=>{eB("local"),eu(void 0),rW(e.name),rV(e.name),ns(e.name),rS()},[rW,rV,rS,ns]),nb=(0,s.useCallback)(()=>{ts(null),e7(!0)},[]),nv=(0,s.useCallback)(()=>{tW("dashboard"),tE(!0),na("dashboard")},[na]),ny=(0,s.useCallback)(()=>{tW("workspace"),tE(!0),na("workspace")},[na]),nj=(0,s.useCallback)(()=>{tW("billing"),tE(!0),na("billing")},[na]),nw=(0,s.useCallback)(()=>{tR(!0)},[]),nk=(0,s.useCallback)(()=>{tB(!0)},[]);(0,s.useCallback)(()=>{t6(!0)},[]);let nC=(0,s.useCallback)(e=>{eB("local"),eu(void 0),rV(e.name),rD(e.name),nn(e.name),rS()},[rS,rD,rV,nn]),nS=(0,s.useCallback)((e,t)=>{e!==(null==q?void 0:q.displayName)&&(eB("local"),eu(void 0),"agent"===t&&rW(e),rV(e),rS())},[null==q?void 0:q.displayName,rW,rV,rS]),nL=(0,s.useMemo)(()=>[{id:"#general",name:"general",description:"General discussion for all agents",visibility:"public",memberCount:0,unreadCount:0,hasMentions:!1,createdAt:"2024-01-01T00:00:00.000Z",status:"active",createdBy:"system",isDm:!1},{id:"#engineering",name:"engineering",description:"Engineering discussion",visibility:"public",memberCount:0,unreadCount:0,hasMentions:!1,createdAt:"2024-01-01T00:00:00.000Z",status:"active",createdBy:"system",isDm:!1}],[]);(0,s.useEffect)(()=>{if(!es||!el){eU(nL),eO([]);return}eU(nL),eO([]),eJ(!0),(async()=>{try{let e=await (0,sF.Gn)(el);e2(e)}catch(e){console.error("Failed to fetch channels:",e)}finally{eJ(!1)}})()},[el,es,nL,e2]),(0,s.useEffect)(()=>{var e;if(!ed||"channels"!==eI||ed===sz||es&&!el)return;let t=null!==(e=eG[ed])&&void 0!==e?e:[];t.length>0?(ez(t),eX(!1)):eK.current.has(ed)?(ez([]),eX(!1)):(eK.current.add(ed),(async()=>{try{let e=await (0,sF._U)(el||"local",ed,{limit:200});eV(t=>({...t,[ed]:e.messages})),ez(e.messages),eX(e.hasMore)}catch(e){console.error("Failed to fetch channel messages:",e),eK.current.delete(ed),ez([]),eX(!1)}})()),e0(void 0),eU(e=>e.map(e=>e.id===ed?{...e,unreadCount:0,hasMentions:!1}:e))},[ed,eI,el]);let nM=(0,s.useCallback)(async e=>{eu(e.id),nt(e.id),rS();try{let{joinChannel:t}=await Promise.resolve().then(r.bind(r,608));await t(el||"local",e.id)}catch(e){console.error("Failed to join channel:",e)}},[rS,el,nt]),nD=(0,s.useCallback)(()=>{tp(!0)},[]),nA=(0,s.useCallback)(async e=>{if(el){tf(!0);try{var t;let r=await (0,sF.mi)(el,e),n=await (0,sF.Gn)(el);e2(n),(null===(t=r.channel)||void 0===t?void 0:t.id)&&eu(r.channel.id),tp(!1)}catch(e){console.error("Failed to create channel:",e)}finally{tf(!1)}}},[el]),nE=(0,s.useCallback)(e=>{tj(e),tv(!0)},[]),nW=(0,s.useCallback)(async e=>{if(ty){tN(!0);try{let t=(0,r_._V)(),r={"Content-Type":"application/json"};t&&(r["X-CSRF-Token"]=t);let n=e.map(e=>({id:e,type:"agent"}));if(!(await fetch("/api/channels/invite",{method:"POST",headers:r,credentials:"include",body:JSON.stringify({channel:ty.name,invites:n,workspaceId:el})})).ok)throw Error("Failed to invite members");tv(!1),tj(null)}catch(e){console.error("Failed to invite to channel:",e)}finally{tN(!1)}}},[ty,el]);(0,s.useCallback)(async e=>{if(el)try{let{joinChannel:t}=await Promise.resolve().then(r.bind(r,608));await t(el,e);let n=await (0,sF.Gn)(el);e2(n)}catch(e){console.error("Failed to join channel:",e)}},[el,e2]),(0,s.useCallback)(async e=>{if(el)try{let{leaveChannel:t}=await Promise.resolve().then(r.bind(r,608));await t(el,e.id),ed===e.id&&eu(void 0);let n=await (0,sF.Gn)(el);e2(n)}catch(e){console.error("Failed to leave channel:",e)}},[el,ed,e2]);let nP=(0,s.useCallback)(async()=>{if(e5&&el)try{let e=await (0,sF.Fk)(el,e5.id);eb(e),eg(!0)}catch(e){console.error("Failed to load channel members:",e)}},[e5,el]),nR=(0,s.useCallback)(async(e,t)=>{if(e5&&el)try{await (0,sF.Ah)(el,e5.id,e,t);let r=await (0,sF.Fk)(el,e5.id);eb(r)}catch(e){console.error("Failed to remove member:",e)}},[e5,el]),nI=(0,s.useCallback)(async(e,t,r)=>{if(e5&&el)try{let r=(0,r_._V)(),n={"Content-Type":"application/json"};if(r&&(n["X-CSRF-Token"]=r),!(await fetch("/api/channels/invite",{method:"POST",headers:n,credentials:"include",body:JSON.stringify({channel:e5.name,invites:[{id:e,type:t}],workspaceId:el})})).ok)throw Error("Failed to add member");let s=await (0,sF.Fk)(el,e5.id);eb(s)}catch(e){console.error("Failed to add member:",e)}},[e5,el]),nB=(0,s.useCallback)(async e=>{if(el)try{let{archiveChannel:t}=await Promise.resolve().then(r.bind(r,608));await t(el,e.id),ed===e.id&&eu(void 0);let n=await (0,sF.Gn)(el);e2(n)}catch(e){console.error("Failed to archive channel:",e)}},[el,ed,e2]),nF=(0,s.useCallback)(async e=>{if(el)try{let{unarchiveChannel:t}=await Promise.resolve().then(r.bind(r,608));await t(el,e.id);let n=await (0,sF.Gn)(el);e2(n)}catch(e){console.error("Failed to unarchive channel:",e)}},[el,e2]),nU=(0,s.useCallback)(async(e,t)=>{if(!ed)return;let r=(null==q?void 0:q.displayName)||"Dashboard",n={id:"local-".concat(Date.now()),channelId:ed,from:r,fromEntityType:"user",content:e,timestamp:new Date().toISOString(),threadId:t,isRead:!0};ey(ed,n,{incrementUnread:!1});try{await (0,sF.bG)(el||"local",ed,{content:e,threadId:t})}catch(e){console.error("Failed to send channel message:",e)}},[el,ed,null==q?void 0:q.displayName,ey]),n_=(0,s.useCallback)(async(e,t,r)=>{let n=(null==q?void 0:q.displayName)||"user";T(s=>{var a;let l;let o=new Map(s),i=null===(a=P.current)||void 0===a?void 0:a.messages.find(t=>t.id===e),c=s.get(e),d=(null==c?void 0:c.reactions)||(null==i?void 0:i.reactions)||[];return l=r?d.map(e=>e.emoji===t?{...e,count:e.count-1,agents:e.agents.filter(e=>e!==n)}:e).filter(e=>e.count>0):d.find(e=>e.emoji===t)?d.map(e=>e.emoji===t?{...e,count:e.count+1,agents:[...e.agents,n]}:e):[...d,{emoji:t,count:1,agents:[n]}],o.set(e,{reactions:l,timestamp:Date.now()}),o}),r?r_.hi.removeReaction(e,t).catch(()=>void 0):r_.hi.addReaction(e,t).catch(()=>void 0)},[null==q?void 0:q.displayName]),nO=(0,s.useCallback)(async()=>{},[]),nH=(0,s.useRef)(null),nz=(0,s.useCallback)(e=>{el&&(nH.current&&clearTimeout(nH.current),nH.current=setTimeout(async()=>{try{await (0,sF.Qh)(el,e),e0(void 0),eU(t=>t.map(t=>t.id===e?{...t,unreadCount:0,hasMentions:!1}:t))}catch(e){console.error("Failed to mark channel as read:",e)}},500))},[el]);(0,s.useEffect)(()=>{ed&&eQ&&0!==eQ.count&&"channels"===eI&&nz(ed)},[ed,eQ,eI,nz]),(0,s.useEffect)(()=>()=>{nH.current&&clearTimeout(nH.current)},[]);let nG=(0,s.useCallback)(e=>{var t;if(!r1)return;let r=r1.name,n=(null!==(t=tU[r])&&void 0!==t?t:[]).includes(e);t_(t=>{var s;let a=null!==(s=t[r])&&void 0!==s?s:[],l=n?a.filter(t=>t!==e):[...a,e];return{...t,[r]:l}}),tH(t=>{var s;let a=null!==(s=t[r])&&void 0!==s?s:[];return n?a.includes(e)?t:{...t,[r]:[...a,e]}:{...t,[r]:a.filter(t=>t!==e)}})},[r1,tU]),nV=(0,s.useCallback)(async(e,t)=>{if(!r1)return!1;let r=r1.name;if(await r$(r,e,void 0,t),r2.length>0)for(let r of r2)await r$(r,e,void 0,t);return!0},[r1,r2,r$]),nZ=(0,s.useCallback)(async(e,t)=>r1?nV(e,t):r$(rG,e,void 0,t),[rG,r1,nV,r$]),nq=(0,s.useMemo)(()=>r1?rA.filter(e=>!e.isHuman).map(e=>{var t;let r=(null!==(t=tU[r1.name])&&void 0!==t?t:[]).includes(e.name);return{id:"dm-toggle-".concat(r1.name,"-").concat(e.name),label:"".concat(r?"Remove":"Invite"," ").concat(e.name," in DM"),description:"DM with ".concat(r1.name),category:"actions",action:()=>nG(e.name)}}):[],[rA,r1,tU,nG]),nJ=(0,s.useMemo)(()=>{let e=[];return e.push({id:"channels-view",label:"Go to Channels",description:"Switch to channel messaging view",category:"channels",shortcut:"⌘⇧C",action:()=>{eB("channels")}}),e.push({id:"channels-create",label:"Create Channel",description:"Create a new messaging channel",category:"channels",action:()=>{eB("channels"),nD()}}),eF.forEach(t=>{let r=t.unreadCount>0?" (".concat(t.unreadCount," unread)"):"";e.push({id:"channel-switch-".concat(t.id),label:t.isDm?"@".concat(t.name):"#".concat(t.name),description:t.description||"Switch to ".concat(t.isDm?"DM":"channel").concat(r),category:"channels",action:()=>{eB("channels"),eu(t.id)}})}),e},[eF,nD]),n$=(0,s.useCallback)(async(e,t)=>{let r=await r$(e,t);if(r){let t=rA.find(t=>t.name===e);t?(rW(t.name),rV(t.name)):rV(e)}return r},[r$,rW,rV,rA]),nY=(0,s.useCallback)(async e=>{if(es)try{let t=await c.xv.restartWorkspace(e);t.success?(rl(t=>t.map(t=>t.id===e?{...t,status:"connecting"}:t)),setTimeout(async()=>{try{let e=await c.xv.getWorkspaceSummary();e.success&&e.data.workspaces&&$(e.data.workspaces)}catch(e){console.error("Failed to refresh workspaces after reconnect:",e)}},2e3)):console.error("Failed to restart workspace:",t.error)}catch(e){console.error("Failed to reconnect to server:",e)}else console.warn("Server reconnect not fully supported in orchestrator mode")},[es]),nX=(0,s.useCallback)(async e=>{tr(!0),ts(null);try{if(I.length>0&&B)return await V(e.name,void 0,e.command,e.cwd),!0;let t=await r_.hi.spawnAgent({name:e.name,cli:e.command,cwd:e.cwd,team:e.team,shadowMode:e.shadowMode,shadowOf:e.shadowOf,shadowAgent:e.shadowAgent,shadowTriggers:e.shadowTriggers,shadowSpeakOn:e.shadowSpeakOn});if(!t.success)return ts(t.error||"Failed to spawn agent"),!1;return!0}catch(e){return ts(e instanceof Error?e.message:"Failed to spawn agent"),!1}finally{tr(!1)}},[I.length,B,V]),nQ=(0,s.useCallback)(async e=>{if(e.isSpawned&&window.confirm('Are you sure you want to release agent "'.concat(e.name,'"?')))try{if(I.length>0&&B){await K(e.name);return}let t=await r_.hi.releaseAgent(e.name);t.success||console.error("Failed to release agent:",t.error)}catch(e){console.error("Failed to release agent:",e)}},[I.length,B,K]),n0=(0,s.useCallback)(e=>{tG(e)},[]);(0,s.useEffect)(()=>{if(!rn)return;let e=async()=>{let e=await r_.hi.getFleetServers();e.success&&e.data&&rl(e.data.servers.map(e=>({id:e.id,name:e.name,url:"local"===e.id?window.location.origin:"http://".concat(e.id),status:"healthy"===e.status?"online":"degraded"===e.status?"degraded":"offline",agentCount:e.agents.length,uptime:e.uptime,lastSeen:e.lastHeartbeat})))};e();let t=setInterval(e,5e3);return()=>clearInterval(t)},[rn]),(0,s.useEffect)(()=>{if(!t8)return;let e=async()=>{let e=await r_.hi.getDecisions();e.success&&e.data&&re(e.data.decisions.map(r_.XP))};e();let t=setInterval(e,5e3);return()=>clearInterval(t)},[t8]);let n1=(0,s.useCallback)(async(e,t)=>{rr(t=>({...t,[e]:!0}));try{let r=await r_.hi.approveDecision(e,t);r.success?re(t=>t.filter(t=>t.id!==e)):console.error("Failed to approve decision:",r.error)}catch(e){console.error("Failed to approve decision:",e)}finally{rr(t=>({...t,[e]:!1}))}},[]),n2=(0,s.useCallback)(async(e,t)=>{rr(t=>({...t,[e]:!0}));try{let r=await r_.hi.rejectDecision(e,t);r.success?re(t=>t.filter(t=>t.id!==e)):console.error("Failed to reject decision:",r.error)}catch(e){console.error("Failed to reject decision:",e)}finally{rr(t=>({...t,[e]:!1}))}},[]),n4=(0,s.useCallback)(async e=>{(await r_.hi.dismissDecision(e)).success&&re(t=>t.filter(t=>t.id!==e))},[]),n3=(0,s.useCallback)(async e=>{rp(!0);try{var t;let r=tu[e.priority].beadsPriority,n=await r_.hi.createBead({title:e.title,assignee:e.agentName,priority:r,type:"task"});if(n.success&&(null===(t=n.data)||void 0===t?void 0:t.bead))await r_.hi.sendRelayMessage({to:e.agentName,content:'\uD83D\uDCCB New task assigned: "'.concat(e.title,'" (P').concat(r,")\nCheck `bd ready` for details.")}),console.log("Task created:",n.data.bead.id);else throw console.error("Failed to create task bead:",n.error),Error(n.error||"Failed to create task")}catch(e){throw console.error("Failed to create task:",e),e}finally{rp(!1)}},[]),n6=(0,s.useCallback)(()=>{tC(!0)},[]),n8=(0,s.useCallback)(()=>{tC(!1)},[]);(0,s.useEffect)(()=>{!function(e){try{localStorage.setItem(sH,JSON.stringify(e))}catch(e){}}(tS)},[tS]),s.useEffect(()=>{let e=e=>{let t;t="system"===e?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":e;let r=document.documentElement;r.classList.remove("theme-light","theme-dark"),r.classList.add("theme-".concat(t)),r.style.colorScheme=t};if(e(tS.theme),"system"===tS.theme){let t=window.matchMedia("(prefers-color-scheme: dark)"),r=()=>e("system");return t.addEventListener("change",r),()=>t.removeEventListener("change",r)}},[tS.theme]),(0,s.useEffect)(()=>{if(tS.notifications.desktop&&"Notification"in window&&"granted"!==Notification.permission){if("denied"===Notification.permission){tM(e=>({...e,notifications:{...e.notifications,desktop:!1,enabled:e.notifications.sound||e.notifications.mentionsOnly}}));return}Notification.requestPermission().then(e=>{"granted"!==e&&tM(e=>({...e,notifications:{...e.notifications,desktop:!1,enabled:e.notifications.sound||e.notifications.mentionsOnly}}))}).catch(()=>void 0)}},[tS.notifications.desktop,tS.notifications.sound,tS.notifications.mentionsOnly,tM]),(0,s.useEffect)(()=>{let e=null==R?void 0:R.messages;if(!e||0===e.length){rC.current=null;return}let t=e[e.length-1];if(!tS.notifications.enabled){var r;rC.current=null!==(r=null==t?void 0:t.id)&&void 0!==r?r:null;return}if(!rC.current){rC.current=t.id;return}let n=e.findIndex(e=>e.id===rC.current);if(-1===n){rC.current=t.id;return}let s=e.slice(n+1);if(0===s.length)return;rC.current=t.id;let a=e=>"Dashboard"===e.from||q&&e.from===q.displayName,l=e=>e.from===rG||e.to===rG,o=e=>!(a(e)||tS.notifications.mentionsOnly&&(null==q?void 0:q.displayName)&&!e.content.includes("@".concat(q.displayName))||"undefined"!=typeof document&&!document.hidden&&l(e)),i=!1;for(let e of s)if(o(e)){if(tS.notifications.desktop&&"Notification"in window&&"granted"===Notification.permission){let t=e.to,r=e.content.split("\n")[0].slice(0,160),n=new Notification("".concat(e.from," → ").concat(t),{body:r});n.onclick=()=>{window.focus(),rV(e.from),n.close()}}tS.notifications.sound&&(i=!0)}i&&function(){let e=window.AudioContext||window.webkitAudioContext;if(e)try{let t=new e,r=t.createOscillator(),n=t.createGain();r.type="sine",r.frequency.value=880,n.gain.value=.03,r.connect(n),n.connect(t.destination),r.start(),r.stop(t.currentTime+.12),r.onended=()=>{t.close().catch(()=>void 0)}}catch(e){}}()},[null==R?void 0:R.messages,tS.notifications,rG,q,rV]),s.useEffect(()=>{let e=e=>{(e.metaKey||e.ctrlKey)&&"k"===e.key&&(e.preventDefault(),tC(!0)),(e.metaKey||e.ctrlKey)&&e.shiftKey&&"s"===e.key&&(e.preventDefault(),nb()),(e.metaKey||e.ctrlKey)&&e.shiftKey&&"c"===e.key&&(e.preventDefault(),eB("channels")),(e.metaKey||e.ctrlKey)&&"n"===e.key&&(e.preventDefault(),nk()),"Escape"===e.key&&(tC(!1),e7(!1),tB(!1),tK(!1),tD&&(tE(!1),no()))};return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e)},[nb,nk]);let n9=window.location.pathname,se=new URLSearchParams(window.location.search);return"/billing/success"===n9?(0,n.jsx)(sA,{type:"success",sessionId:se.get("session_id")||void 0,onClose:()=>{window.location.href="/"}}):"/billing/canceled"===n9?(0,n.jsx)(sA,{type:"canceled",onClose:()=>{window.location.href="/"}}):(0,n.jsx)(e$,{wsUrl:y,children:(0,n.jsxs)("div",{className:"flex h-screen bg-bg-deep font-sans text-text-primary",children:[(0,n.jsx)("div",{className:"\n fixed inset-0 bg-black/60 backdrop-blur-sm z-[999] transition-opacity duration-200\n md:hidden\n ".concat(rg?"opacity-100 pointer-events-auto":"opacity-0 pointer-events-none","\n "),onClick:()=>rf(!1)}),(0,n.jsxs)("div",{className:"\n flex flex-col w-[280px] max-md:w-[85vw] max-md:max-w-[280px] h-screen bg-bg-primary border-r border-border-subtle\n fixed left-0 top-0 z-[1000] transition-transform duration-200\n md:relative md:translate-x-0 md:flex-shrink-0\n ".concat(rg?"translate-x-0":"-translate-x-full","\n "),children:[(0,n.jsx)("div",{className:"p-3 border-b border-sidebar-border",children:(0,n.jsx)(r3,{workspaces:ea,activeWorkspaceId:null!=el?el:void 0,onSelect:ei,onAddWorkspace:()=>{es?(localStorage.removeItem("agentrelay_workspace_id"),window.location.href="/app?select=true"):to(!0)},onWorkspaceSettings:ny,isLoading:eo})}),(0,n.jsx)(ee,{agents:nh,bridgeAgents:nu,projects:nm,currentUserName:null==q?void 0:q.displayName,humanUnreadCounts:ne,currentProject:e6,selectedAgent:null==rT?void 0:rT.name,viewMode:eI,isFleetAvailable:ni,isConnected:C||U,isOpen:rg,activeThreads:rq,currentThread:rK,totalUnreadThreadCount:rJ,channels:eF.filter(e=>!e.isDm&&!e.id.startsWith("dm:")).map(e=>({id:e.id,name:e.name,unreadCount:e.unreadCount,hasMentions:e.hasMentions})),archivedChannels:e_.filter(e=>!e.isDm&&!e.id.startsWith("dm:")).map(e=>{var t;return{id:e.id,name:e.name,unreadCount:null!==(t=e.unreadCount)&&void 0!==t?t:0,hasMentions:e.hasMentions}}),selectedChannelId:ed,isActivitySelected:ed===sz,activityUnreadCount:0,onActivitySelect:()=>{eu(sz),rW(null),eB("channels"),nl()},onChannelSelect:e=>{let t=eF.find(t=>t.id===e.id)||e_.find(t=>t.id===e.id);t&&(nM(t),eB("channels"))},onCreateChannel:nD,onInviteToChannel:e=>{let t=eF.find(t=>t.id===e.id);t&&nE(t)},onArchiveChannel:e=>{let t=eF.find(t=>t.id===e.id);t&&nB(t)},onUnarchiveChannel:e=>{let t=e_.find(t=>t.id===e.id)||eF.find(t=>t.id===e.id);t&&nF(t)},onAgentSelect:nf,onHumanSelect:nC,onProjectSelect:ng,onViewModeChange:eB,onSpawnClick:nb,onReleaseClick:nQ,onLogsClick:n0,onProfileClick:eP,onThreadSelect:rZ,onClose:()=>rf(!1),onSettingsClick:nv,onTrajectoryClick:()=>tK(!0),hasActiveTrajectory:null==tq?void 0:tq.active,onFleetClick:()=>rs(!rn),isFleetViewActive:rn})]}),(0,n.jsxs)("main",{className:"flex-1 flex flex-col min-w-0 bg-bg-secondary/50 overflow-hidden",children:[(0,n.jsxs)("div",{className:"fixed top-0 left-0 right-0 z-50 md:sticky md:top-0 md:left-auto md:right-auto bg-bg-secondary",children:[(0,n.jsx)(eW,{currentChannel:rG,selectedAgent:rT,projects:nm,currentProject:nm.find(e=>e.id===e6)||null,recentProjects:t2(nm),viewMode:eI,selectedChannelName:null==e5?void 0:e5.name,onProjectChange:ng,onCommandPaletteOpen:n6,onSettingsClick:nv,onHistoryClick:nw,onNewConversationClick:nk,onFleetClick:()=>rs(!rn),isFleetViewActive:rn,onTrajectoryClick:()=>tK(!0),hasActiveTrajectory:null==tq?void 0:tq.active,onMenuClick:()=>rf(!0),hasUnreadNotifications:rb}),(0,n.jsx)(sE,{onUpgradeClick:nj})]}),(0,n.jsx)("div",{className:"h-[52px] flex-shrink-0 md:hidden"}),q&&eL.length>0&&(0,n.jsx)("div",{className:"flex items-center justify-end px-4 py-1 bg-bg-tertiary/80 border-b border-border-subtle flex-shrink-0",children:(0,n.jsx)(si,{onlineUsers:eL,onUserClick:eD})}),(0,n.jsxs)("div",{className:"flex-1 flex overflow-hidden min-h-0",children:[(0,n.jsxs)("div",{className:"flex-1 min-h-0 overflow-y-auto ".concat(rK?"hidden md:block md:flex-[2]":""),children:[r1&&(0,n.jsxs)("div",{className:"px-4 py-2 border-b border-border-subtle bg-bg-secondary flex flex-col gap-2 sticky top-0 z-10",children:[(0,n.jsxs)("div",{className:"text-xs text-text-muted",children:["DM with ",(0,n.jsx)("span",{className:"font-semibold text-text-primary",children:r1.name}),". Invite agents:"]}),(0,n.jsxs)("div",{className:"flex flex-wrap gap-2",children:[rA.filter(e=>!e.isHuman).map(e=>{var t;let r=(null!==(t=tU[r1.name])&&void 0!==t?t:[]).includes(e.name);return(0,n.jsxs)("button",{onClick:()=>nG(e.name),className:"px-3 py-1.5 text-xs font-medium rounded-lg transition-colors ".concat(r?"bg-accent-cyan text-bg-deep":"bg-bg-tertiary text-text-secondary hover:bg-bg-tertiary/80"),title:e.name,children:[r?"✓ ":"",e.name]},e.name)}),0===rA.filter(e=>!e.isHuman).length&&(0,n.jsx)("span",{className:"text-xs text-text-muted",children:"No agents available"})]})]}),S&&!R&&D?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-full text-text-muted text-center px-4",children:[(0,n.jsx)(sK,{}),(0,n.jsx)("h2",{className:"m-0 mb-2 font-display text-text-primary",children:"Connection Error"}),(0,n.jsx)("p",{className:"text-text-secondary",children:S.message}),(0,n.jsx)("button",{className:"mt-6 py-3 px-6 bg-gradient-to-r from-accent-cyan to-[#00b8d9] text-bg-deep font-semibold border-none rounded-xl cursor-pointer transition-all duration-150 hover:shadow-glow-cyan hover:-translate-y-0.5",onClick:()=>window.location.reload(),children:"Retry Connection"})]}):R?rn?(0,n.jsx)("div",{className:"p-4 h-full overflow-y-auto",children:(0,n.jsx)(n5,{servers:ra,agents:rA,selectedServerId:rx,onServerSelect:rm,onServerReconnect:nY,isLoading:!R})}):ed===sz?(0,n.jsx)(o,{events:ex,maxEvents:100}):"channels"===eI&&e5?(0,n.jsx)(sF.F,{channel:e5,messages:r9,currentUser:(null==q?void 0:q.displayName)||"Anonymous",isLoadingMore:!1,hasMoreMessages:eY&&!!el,mentionSuggestions:rA.map(e=>e.name),unreadState:eQ,onSendMessage:nU,onLoadMore:nO,onThreadClick:e=>rZ(e),onShowMembers:nP,onMemberClick:nS}):"channels"===eI?(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-full text-text-muted text-center px-4",children:[(0,n.jsx)(sZ,{}),(0,n.jsx)("h2",{className:"m-0 mb-2 font-display text-text-primary",children:"Select a channel"}),(0,n.jsx)("p",{className:"text-text-secondary",children:"Choose a channel from the sidebar to start messaging"})]}):(0,n.jsx)(te,{messages:r4,currentChannel:rG,currentThread:rK,onThreadClick:e=>rZ(e),highlightedMessageId:null!=rK?rK:void 0,agents:rL,currentUser:q,skipChannelFilter:null!==r1,showTimestamps:tS.display.showTimestamps,autoScrollDefault:tS.messages.autoScroll,compactMode:tS.display.compactMode,onAgentClick:eP,onUserClick:eD,onLogsClick:n0,onlineUsers:eL,onReaction:w?n_:void 0}):(0,n.jsxs)("div",{className:"flex flex-col items-center justify-center h-full text-text-muted text-center",children:[(0,n.jsx)(sV,{}),(0,n.jsx)("p",{className:"font-display text-text-secondary",children:"Connecting to dashboard..."})]})]}),rK&&(()=>{let e;let t="channels"===eI,r=e=>{var t;return{id:e.id,from:e.from,to:e.channelId,content:e.content,timestamp:e.timestamp,thread:e.threadId,isRead:e.isRead,replyCount:null===(t=e.threadSummary)||void 0===t?void 0:t.replyCount,threadSummary:e.threadSummary}},s=null,a=[],l=!1,o=!1,i=!1;if(t){let e=r9.find(e=>e.id===rK);if(e)s=r(e);else{l=!0;let e=r9.filter(e=>e.threadId===rK).sort((e,t)=>new Date(e.timestamp).getTime()-new Date(t.timestamp).getTime());e[0]&&(s=r(e[0]))}a=r9.filter(e=>e.threadId===rK).map(r)}else s=r0.parentMessage,a=r0.replies,l=!s,o=r0.isLoading,i=r0.hasMore,e=r0.loadMore;return(0,n.jsx)("div",{className:"w-full md:w-[400px] md:min-w-[320px] md:max-w-[500px] flex-shrink-0 h-full overflow-hidden",children:(0,n.jsx)(ta,{originalMessage:s,replies:a,onClose:()=>rZ(null),showTimestamps:tS.display.showTimestamps,isLoading:o,hasMore:i,onLoadMore:e,onReply:async e=>{if(t&&e5)return await nU(e,rK),!0;let r="*";return!l&&s&&(r="Dashboard"===s.from||q&&s.from===q.displayName?s.to:s.from),r$(r,e,rK)},isSending:rX,currentUser:q})})})()]}),eN.length>0&&(0,n.jsx)("div",{className:"px-4 bg-bg-tertiary border-t border-border-subtle",children:(0,n.jsx)(n7,{typingUsers:eN})}),"channels"!==eI&&(0,n.jsx)("div",{className:"p-2 sm:p-4 bg-bg-tertiary border-t border-border-subtle",children:(0,n.jsx)(so,{agents:rA,humanUsers:r7,onSend:nZ,onTyping:ek,isSending:rX,error:rQ,insertMention:eA,onMentionInserted:()=>eE(void 0),enableFileAutocomplete:!0,placeholder:"Message @".concat(rG,"...")})})]}),(0,n.jsx)(tx,{isOpen:tk,onClose:n8,agents:rA,projects:e4,currentProject:e6,onAgentSelect:nf,onProjectSelect:ng,onSpawnClick:nb,onTaskCreate:n3,onGeneralClick:()=>{rW(null),eu("#general"),eB("channels")},customCommands:[...nq,...nJ]}),(0,n.jsx)(tA,{isOpen:e9,onClose:()=>e7(!1),onSpawn:nX,existingAgents:rA.map(e=>e.name),isSpawning:tt,error:tn,isCloudMode:es,workspaceId:null!=el?el:void 0,agentDefaults:tS.agentDefaults,repos:t5,activeRepoId:null!==(v=null===(l=t5.find(e=>e.id===e6))||void 0===l?void 0:l.id)&&void 0!==v?v:null===(i=t5[0])||void 0===i?void 0:i.id}),(0,n.jsx)(nr,{isOpen:tl,onClose:()=>{to(!1),tm(null)},onAdd:np,isAdding:ti,error:td}),(0,n.jsx)(sF.hG,{isOpen:th,onClose:()=>tp(!1),onCreate:nA,isLoading:tg,existingChannels:eF.map(e=>e.name),availableMembers:rA.map(e=>e.name),workspaceId:null!=el?el:void 0}),(0,n.jsx)(sF.PC,{isOpen:tb,channelName:(null==ty?void 0:ty.name)||"",onClose:()=>{tv(!1),tj(null)},onInvite:nW,isLoading:tw,availableMembers:rA.map(e=>e.name)}),e5&&(0,n.jsx)(sF.pw,{channel:e5,members:ef,isOpen:ep,onClose:()=>eg(!1),onAddMember:nI,onRemoveMember:nR,onUpdateRole:()=>{},currentUserId:null==q?void 0:q.displayName,availableAgents:rA.map(e=>({name:e.name})),workspaceId:null!=el?el:void 0}),(0,n.jsx)(rO,{isOpen:tP,onClose:()=>tR(!1)}),(0,n.jsx)(tF,{isOpen:tI,onClose:()=>tB(!1),onSend:n$,agents:rA,isSending:rX,error:rQ}),tz&&(0,n.jsx)(nN,{agent:tz,isOpen:!0,onClose:()=>tG(null),availableAgents:rA,onAgentChange:tG}),tV&&(0,n.jsx)("div",{className:"fixed inset-0 z-50 flex bg-black/50 backdrop-blur-sm",onClick:()=>tK(!1),children:(0,n.jsxs)("div",{className:"ml-auto w-full max-w-3xl h-full bg-bg-primary shadow-2xl animate-in slide-in-from-right duration-300 flex flex-col",onClick:e=>e.stopPropagation(),children:[(0,n.jsxs)("div",{className:"flex items-center justify-between px-6 py-4 border-b border-border-subtle bg-bg-secondary",children:[(0,n.jsxs)("div",{className:"flex items-center gap-3",children:[(0,n.jsx)("div",{className:"w-10 h-10 rounded-xl bg-gradient-to-br from-blue-500/20 to-accent-cyan/20 flex items-center justify-center border border-blue-500/30",children:(0,n.jsx)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"text-blue-500",children:(0,n.jsx)("path",{d:"M3 12h4l3 9 4-18 3 9h4",strokeLinecap:"round",strokeLinejoin:"round"})})}),(0,n.jsxs)("div",{children:[(0,n.jsx)("h2",{className:"text-lg font-semibold text-text-primary m-0",children:"Trajectory Viewer"}),(0,n.jsx)("p",{className:"text-xs text-text-muted m-0",children:(null==tq?void 0:tq.active)?"Active: ".concat(tq.task||"Working..."):"Browse past trajectories"})]})]}),(0,n.jsx)("button",{onClick:()=>tK(!1),className:"w-10 h-10 rounded-lg bg-bg-tertiary border border-border-subtle flex items-center justify-center text-text-muted hover:text-text-primary hover:bg-bg-hover hover:border-blue-500/50 transition-all",title:"Close (Esc)",children:(0,n.jsx)("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.jsx)("path",{d:"M18 6L6 18M6 6l12 12"})})})]}),(0,n.jsx)("div",{className:"flex-1 overflow-hidden p-6",children:(0,n.jsx)(nT,{agentName:(null==tQ?void 0:tQ.slice(0,30))||(null==tq?void 0:null===(d=tq.task)||void 0===d?void 0:d.slice(0,30))||"Trajectories",steps:tZ,history:tJ,selectedTrajectoryId:tX,onSelectTrajectory:tY,isLoading:t$})})]})}),t8&&(0,n.jsx)("div",{className:"fixed left-4 bottom-4 w-[400px] max-h-[500px] z-50 shadow-modal",children:(0,n.jsxs)("div",{className:"relative",children:[(0,n.jsx)("button",{onClick:()=>t9(!1),className:"absolute -top-2 -right-2 w-6 h-6 bg-bg-elevated border border-border rounded-full flex items-center justify-center text-text-muted hover:text-text-primary hover:bg-bg-hover z-10",title:"Close decisions",children:(0,n.jsx)("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:(0,n.jsx)("path",{d:"M18 6L6 18M6 6l12 12"})})}),(0,n.jsx)(nK,{decisions:t7,onApprove:n1,onReject:n2,onDismiss:n4,isProcessing:rt})]})}),!t8&&t7.length>0&&(0,n.jsxs)("button",{onClick:()=>t9(!0),className:"fixed left-4 bottom-4 w-12 h-12 bg-warning text-bg-deep rounded-full shadow-[0_0_20px_rgba(255,107,53,0.4)] flex items-center justify-center hover:scale-105 transition-transform z-50",title:"".concat(t7.length," pending decision").concat(t7.length>1?"s":""),children:[(0,n.jsxs)("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,n.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]}),t7.length>0&&(0,n.jsx)("span",{className:"absolute -top-1 -right-1 w-5 h-5 bg-error text-white text-[10px] font-bold rounded-full flex items-center justify-center",children:t7.length})]}),(0,n.jsx)(sc,{user:eM,onClose:()=>eD(null),onMention:e=>{eE(e),eD(null)},onSendMessage:e=>{rV(e.username),rD(e.username),eD(null)}}),(0,n.jsx)(sm,{agent:eT,onClose:()=>eP(null),onMessage:e=>{rW(e.name),rV(e.name),eP(null)},onLogs:n0,onRelease:nQ,summary:eT?eR.get(eT.name.toLowerCase()):null}),(0,n.jsx)(sp,{isOpen:t3,onClose:()=>t6(!1),projects:nm,isCloudMode:!!q,hasArchitect:nu.some(e=>"architect"===e.name.toLowerCase()),onArchitectSpawned:()=>{t6(!1)}}),tD&&(0,n.jsx)(rk,{currentUserId:null==Z?void 0:null===(u=Z.user)||void 0===u?void 0:u.id,initialTab:tT,onClose:()=>{tE(!1),no()},settings:tS,onUpdateSettings:tM,activeWorkspaceId:el,onReposChanged:t4}),(0,n.jsx)(rY,{toasts:ro,onDismiss:rc,position:"top-right"})]})})}function sV(){return(0,n.jsx)("svg",{className:"animate-spin mb-4 text-accent-cyan",width:"28",height:"28",viewBox:"0 0 24 24",children:(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"2",fill:"none",strokeDasharray:"32",strokeLinecap:"round"})})}function sK(){return(0,n.jsxs)("svg",{className:"text-error mb-4",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[(0,n.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,n.jsx)("line",{x1:"12",y1:"8",x2:"12",y2:"12"}),(0,n.jsx)("line",{x1:"12",y1:"16",x2:"12.01",y2:"16"})]})}function sZ(){return(0,n.jsxs)("svg",{className:"text-text-muted mb-4",width:"48",height:"48",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,n.jsx)("line",{x1:"4",y1:"9",x2:"20",y2:"9"}),(0,n.jsx)("line",{x1:"4",y1:"15",x2:"20",y2:"15"}),(0,n.jsx)("line",{x1:"10",y1:"3",x2:"8",y2:"21"}),(0,n.jsx)("line",{x1:"16",y1:"3",x2:"14",y2:"21"})]})}},7118:function(e,t,r){r.d(t,{TI:function(){return c},uo:function(){return d}});var n=r(7573),s=r(7653),a=r(1841);let l={checkOnMount:!0,checkInterval:6e4,onExpired:()=>{}};function o(e){let{isOpen:t,error:r,onLogin:s,onDismiss:a}=e;return t?(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)("div",{className:"fixed inset-0 bg-black/60 backdrop-blur-sm z-[9998]",onClick:a,"aria-hidden":"true"}),(0,n.jsx)("div",{className:"fixed inset-0 flex items-center justify-center z-[9999] p-4",role:"dialog","aria-modal":"true","aria-labelledby":"session-expired-title",children:(0,n.jsxs)("div",{className:"bg-bg-primary rounded-lg shadow-xl max-w-md w-full p-6 animate-in fade-in zoom-in-95 duration-200",children:[(0,n.jsx)("div",{className:"flex justify-center mb-4",children:(0,n.jsx)("div",{className:"w-16 h-16 rounded-full bg-warning/10 flex items-center justify-center",children:(0,n.jsx)("svg",{className:"w-8 h-8 text-warning",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:(0,n.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})})})}),(0,n.jsx)("h2",{id:"session-expired-title",className:"text-xl font-semibold text-text-primary text-center mb-2",children:"Session Expired"}),(0,n.jsx)("p",{className:"text-text-muted text-center mb-6",children:(()=>{if(!r)return"Your session has expired. Please log in again to continue.";switch(r.code){case"SESSION_EXPIRED":return"Your session has expired. Please log in again to continue.";case"USER_NOT_FOUND":return"Your account was not found. Please log in again.";case"SESSION_ERROR":return"There was a problem with your session. Please log in again.";default:return r.message||"Your session has expired. Please log in again."}})()}),(0,n.jsxs)("div",{className:"flex flex-col gap-3",children:[(0,n.jsx)("button",{onClick:s,className:"w-full py-3 px-4 bg-accent text-white font-medium rounded-lg hover:bg-accent-hover transition-colors duration-200 focus:outline-none focus:ring-2 focus:ring-accent focus:ring-offset-2 focus:ring-offset-bg-primary",children:"Log In Again"}),a&&(0,n.jsx)("button",{onClick:a,className:"w-full py-3 px-4 text-text-muted hover:text-text-primary font-medium rounded-lg transition-colors duration-200 hover:bg-bg-secondary",children:"Dismiss"})]}),(0,n.jsx)("p",{className:"text-xs text-text-muted text-center mt-4",children:"You'll be redirected to the login page where you can sign in with GitHub."})]})})]}):null}let i=(0,s.createContext)(void 0);function c(e){let{children:t,cloudMode:r,checkInterval:c=6e4,onSessionExpired:d}=e,u=null!=r?r:function(){let e=window.location.hostname;if(e.includes("agent-relay.com")||e.includes("agentrelay.cloud"))return!0;let t=document.querySelector('meta[name="agent-relay-cloud"]');return(null==t?void 0:t.getAttribute("content"))==="true"||"true"===localStorage.getItem("agent-relay-cloud-mode")}(),x=function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},t={...l,...e},[r,n]=(0,s.useState)(null),[o,i]=(0,s.useState)(!0),[c,d]=(0,s.useState)(!1),[u,x]=(0,s.useState)(null),m=(0,s.useRef)(null),h=(0,s.useRef)(!0),p=(0,s.useCallback)(async()=>{try{let e=await a.xv.checkSession();if(!h.current)return e;if(!e.authenticated&&(n(null),e.code)){let r={error:"Session expired",code:e.code,message:e.message||"Your session has expired. Please log in again."};x(r),d(!0),t.onExpired(r)}return e}catch(e){return{authenticated:!1,code:"SESSION_ERROR",message:"Failed to check session"}}},[t]),g=(0,s.useCallback)(async()=>{i(!0);try{let e=await a.xv.getMe();if(!h.current)return;e.success?(n(e.data),d(!1),x(null)):e.sessionExpired?(n(null),d(!0)):x({error:e.error,code:"SESSION_ERROR",message:e.error})}finally{h.current&&i(!1)}},[]);(0,s.useEffect)(()=>(0,a.Zk)(e=>{h.current&&(n(null),d(!0),x(e),t.onExpired(e))}),[t]),(0,s.useEffect)(()=>(h.current=!0,t.checkOnMount&&g(),()=>{h.current=!1}),[t.checkOnMount,g]),(0,s.useEffect)(()=>{if(!(t.checkInterval<=0))return m.current=setInterval(()=>{r&&p()},t.checkInterval),()=>{m.current&&(clearInterval(m.current),m.current=null)}},[t.checkInterval,r,p]);let f=(0,s.useCallback)(()=>{d(!1),x(null)},[]),b=(0,s.useCallback)(()=>{let e=encodeURIComponent(window.location.pathname+window.location.search);window.location.href="/login?returnTo=".concat(e)},[]),v=(0,s.useCallback)(async()=>{await a.xv.logout(),n(null),d(!1),x(null),window.location.href="/login"},[]);return{user:r,isLoading:o,isAuthenticated:null!==r,isExpired:c,error:u,csrfToken:(0,a._V)(),checkSession:p,clearExpired:f,redirectToLogin:b,logout:v}}({checkOnMount:u,checkInterval:u?c:0,onExpired:d}),m=(0,s.useCallback)(()=>{x.redirectToLogin()},[x]),h=(0,s.useCallback)(()=>{x.clearExpired()},[x]),p={...x,isCloudMode:u};return(0,n.jsxs)(i.Provider,{value:p,children:[t,u&&(0,n.jsx)(o,{isOpen:x.isExpired,error:x.error,onLogin:m,onDismiss:h})]})}function d(){return(0,s.useContext)(i)}},608:function(e,t,r){r.d(t,{F:function(){return V},hG:function(){return K},PC:function(){return Z},pw:function(){return et},archiveChannel:function(){return x},mi:function(){return i},Fk:function(){return f},_U:function(){return o},joinChannel:function(){return d},leaveChannel:function(){return u},Gn:function(){return l},Qh:function(){return h},Ah:function(){return g},bG:function(){return c},unarchiveChannel:function(){return m}}),new Date().toISOString(),new Date(Date.now()-3e5).toISOString(),new Date(Date.now()-36e5).toISOString(),new Date(Date.now()-18e5).toISOString(),new Date(Date.now()-72e5).toISOString(),new Date(Date.now()-6e6).toISOString(),Date.now(),new Date(Date.now()-36e5).toISOString(),new Date(Date.now()-18e5).toISOString(),new Date(Date.now()-3e5).toISOString();var n=r(5118);function s(){return localStorage.getItem("relay_username")||"Dashboard"}class a extends Error{constructor(e,t,r){super(e),this.status=t,this.body=r,this.name="ApiError"}}async function l(e){(0,n.$3)();let t=new URLSearchParams;e&&t.set("workspaceId",e);let r=(0,n.kG)("/api/channels?".concat(t.toString()));try{var s,l;let e=await fetch(r,{method:"GET",headers:{"Content-Type":"application/json"},credentials:"include"});if(!e.ok)throw new a("Failed to fetch channels",e.status);let t=await e.json();return{channels:null!==(s=t.channels)&&void 0!==s?s:[],archivedChannels:null!==(l=t.archivedChannels)&&void 0!==l?l:[]}}catch(e){if(e instanceof a)throw e;throw new a("Network error fetching channels",0)}}async function o(e,t,r){var s;if("__activity__"===t)return{messages:[],hasMore:!1,unread:{count:0}};(0,n.$3)();let l=new URLSearchParams;if((null==r?void 0:r.limit)&&l.set("limit",String(r.limit)),null==r?void 0:r.before){let e=Date.parse(r.before);Number.isNaN(e)||l.set("before",String(e))}e&&l.set("workspaceId",e);let o="/api/channels/".concat(encodeURIComponent(t),"/messages").concat(l.toString()?"?".concat(l.toString()):""),i=await fetch((0,n.kG)(o),{method:"GET",headers:{"Content-Type":"application/json"}});if(!i.ok)throw new a("Failed to fetch channel messages",i.status);let c=await i.json();return{messages:null!==(s=c.messages)&&void 0!==s?s:[],hasMore:!!c.hasMore,unread:{count:0}}}async function i(e,t){(0,n.$3)();try{let r=(0,n._V)(),s={"Content-Type":"application/json"};r&&(s["X-CSRF-Token"]=r);let l=await fetch((0,n.kG)("/api/channels"),{method:"POST",headers:s,credentials:"include",body:JSON.stringify({name:t.name,description:t.description,isPrivate:"private"===t.visibility,invites:t.members,workspaceId:e})});if(!l.ok){let e=await l.json().catch(()=>({error:"Unknown error"}));throw new a(e.error||"Failed to create channel",l.status)}let o=await l.json();return{channel:{id:o.channel.id,name:o.channel.name,description:o.channel.description,visibility:o.channel.visibility,status:o.channel.status,createdAt:o.channel.createdAt,createdBy:o.channel.createdBy,memberCount:1,unreadCount:0,hasMentions:!1,isDm:!1}}}catch(e){if(e instanceof a)throw e;throw new a("Network error creating channel",0)}}async function c(e,t,r){(0,n.$3)();let l=s();try{let s=await fetch((0,n.kG)("/api/channels/message"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:l,channel:t,body:r.content,thread:r.threadId,workspaceId:e})});if(!s.ok){let e=await s.json().catch(()=>({error:"Unknown error"}));throw new a(e.error||"Failed to send message",s.status)}return{message:{id:"pending-".concat(Date.now()),channelId:t,from:l,fromEntityType:"user",content:r.content,timestamp:new Date().toISOString(),threadId:r.threadId,isRead:!0}}}catch(e){if(e instanceof a)throw e;throw new a("Network error sending message",0)}}async function d(e,t){(0,n.$3)();let r=s();try{let s=await fetch((0,n.kG)("/api/channels/join"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:r,channel:t,workspaceId:e})});if(!s.ok){let e=await s.json().catch(()=>({error:"Unknown error"}));throw new a(e.error||"Failed to join channel",s.status)}return{id:t,name:t.startsWith("#")?t.slice(1):t,visibility:"public",status:"active",createdAt:new Date().toISOString(),createdBy:r,memberCount:1,unreadCount:0,hasMentions:!1,isDm:t.startsWith("dm:")}}catch(e){if(e instanceof a)throw e;throw new a("Network error joining channel",0)}}async function u(e,t){(0,n.$3)();let r=s();try{let s=await fetch((0,n.kG)("/api/channels/leave"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:r,channel:t,workspaceId:e})});if(!s.ok){let e=await s.json().catch(()=>({error:"Unknown error"}));throw new a(e.error||"Failed to leave channel",s.status)}}catch(e){if(e instanceof a)throw e;throw new a("Network error leaving channel",0)}}async function x(e,t){(0,n.$3)();let r=await fetch((0,n.kG)("/api/channels/archive"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({channel:t,workspaceId:e})});if(!r.ok)throw new a("Failed to archive channel",r.status);return{id:t,name:t.startsWith("#")?t.slice(1):t,visibility:"public",status:"archived",createdAt:new Date().toISOString(),createdBy:s(),memberCount:0,unreadCount:0,hasMentions:!1,isDm:t.startsWith("dm:")}}async function m(e,t){(0,n.$3)();let r=await fetch((0,n.kG)("/api/channels/unarchive"),{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({channel:t,workspaceId:e})});if(!r.ok)throw new a("Failed to unarchive channel",r.status);return{id:t,name:t.startsWith("#")?t.slice(1):t,visibility:"public",status:"active",createdAt:new Date().toISOString(),createdBy:s(),memberCount:0,unreadCount:0,hasMentions:!1,isDm:t.startsWith("dm:")}}async function h(e,t,r){}async function p(e){(0,n.$3)();let t=new URLSearchParams;e&&t.set("workspaceId",e);try{var r,s;let e=(0,n.kG)("/api/channels/available-members?".concat(t.toString())),a=await fetch(e,{method:"GET",headers:{"Content-Type":"application/json"},credentials:"include"});if(!a.ok)return console.error("[ChannelsAPI] Failed to fetch available members:",a.status),{members:[],agents:[]};let l=await a.json();return{members:null!==(r=l.members)&&void 0!==r?r:[],agents:null!==(s=l.agents)&&void 0!==s?s:[]}}catch(e){return console.error("[ChannelsAPI] Error fetching available members:",e),{members:[],agents:[]}}}async function g(e,t,r,s){let l=(0,n.kG)("/api/channels/admin-remove"),o=await fetch(l,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({channel:t.startsWith("#")?t:"#".concat(t),member:r})});if(!o.ok)throw new a((await o.json().catch(()=>({}))).error||"Failed to remove member",o.status)}async function f(e,t){try{let e=(0,n.kG)("/api/channels/".concat(encodeURIComponent(t),"/members")),r=await fetch(e,{method:"GET",headers:{"Content-Type":"application/json"}});if(!r.ok)return console.warn("[ChannelsAPI] Failed to get channel members:",r.statusText),[{id:s(),displayName:s(),entityType:"user",role:"owner",status:"online",joinedAt:new Date().toISOString()}];return(await r.json()).members||[]}catch(e){return console.error("[ChannelsAPI] Error getting channel members:",e),[{id:s(),displayName:s(),entityType:"user",role:"owner",status:"online",joinedAt:new Date().toISOString()}]}}var b=r(7573),v=r(7653);function y(e){let{channel:t,members:r=[],canEdit:n=!1,onEditChannel:s,onShowMembers:a,onShowPinned:l,onSearch:o}=e,[i,c]=(0,v.useState)(!1),d=t.isDm,u=d?t.name:"".concat(t.name),x=r.filter(e=>"online"===e.status).length;return(0,b.jsxs)("div",{className:"flex-shrink-0 border-b border-border-subtle bg-bg-primary",children:[(0,b.jsxs)("div",{className:"flex items-center justify-between px-4 py-3",children:[(0,b.jsxs)("div",{className:"flex items-center gap-3 min-w-0",children:[(0,b.jsx)("div",{className:"\n flex-shrink-0 w-8 h-8 rounded-lg flex items-center justify-center\n ".concat(d?"bg-purple-500/10":"bg-accent-cyan/10","\n "),children:d?(0,b.jsx)(N,{className:"w-4 h-4 text-purple-400"}):(0,b.jsx)(w,{className:"w-4 h-4 text-accent-cyan"})}),(0,b.jsxs)("div",{className:"min-w-0",children:[(0,b.jsxs)("div",{className:"flex items-center gap-2",children:[(0,b.jsx)("h1",{className:"text-base font-semibold text-text-primary truncate",children:u}),"archived"===t.status&&(0,b.jsx)("span",{className:"px-1.5 py-0.5 text-[10px] font-medium bg-warning/20 text-warning rounded",children:"Archived"}),"private"===t.visibility&&!d&&(0,b.jsx)(k,{className:"w-3.5 h-3.5 text-text-muted flex-shrink-0"})]}),t.topic&&(0,b.jsx)("p",{className:"text-xs text-text-muted truncate mt-0.5",children:t.topic})]})]}),(0,b.jsxs)("div",{className:"flex items-center gap-1",children:[(0,b.jsxs)("button",{onClick:a,className:"flex items-center gap-1.5 px-2 py-1.5 rounded-md text-text-muted hover:text-text-primary hover:bg-bg-hover transition-colors",title:"View members",children:[(0,b.jsx)(C,{className:"w-4 h-4"}),(0,b.jsxs)("span",{className:"text-xs",children:[t.memberCount,x>0&&(0,b.jsxs)("span",{className:"text-success ml-1",children:["(",x," online)"]})]})]}),(0,b.jsx)("div",{className:"w-px h-5 bg-border-subtle mx-1"}),o&&(0,b.jsx)("button",{onClick:o,className:"p-2 rounded-md text-text-muted hover:text-text-primary hover:bg-bg-hover transition-colors",title:"Search in channel",children:(0,b.jsx)(S,{className:"w-4 h-4"})}),l&&(0,b.jsx)("button",{onClick:l,className:"p-2 rounded-md text-text-muted hover:text-text-primary hover:bg-bg-hover transition-colors",title:"Pinned messages",children:(0,b.jsx)(L,{className:"w-4 h-4"})}),(0,b.jsx)("button",{onClick:()=>c(!i),className:"p-2 rounded-md transition-colors ".concat(i?"text-accent-cyan bg-accent-cyan/10":"text-text-muted hover:text-text-primary hover:bg-bg-hover"),title:"Channel details",children:(0,b.jsx)(M,{className:"w-4 h-4"})}),n&&s&&(0,b.jsx)("button",{onClick:s,className:"p-2 rounded-md text-text-muted hover:text-text-primary hover:bg-bg-hover transition-colors",title:"Channel settings",children:(0,b.jsx)(D,{className:"w-4 h-4"})})]})]}),i&&(0,b.jsx)("div",{className:"px-4 pb-3 border-t border-border-subtle pt-3 bg-bg-secondary/50",children:(0,b.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-4",children:[t.description&&(0,b.jsxs)("div",{children:[(0,b.jsx)("h3",{className:"text-xs font-semibold text-text-muted uppercase tracking-wide mb-1",children:"Description"}),(0,b.jsx)("p",{className:"text-sm text-text-secondary",children:t.description})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("h3",{className:"text-xs font-semibold text-text-muted uppercase tracking-wide mb-1",children:"Created"}),(0,b.jsxs)("p",{className:"text-sm text-text-secondary",children:[new Date(t.createdAt).toLocaleDateString(void 0,{year:"numeric",month:"short",day:"numeric"})," by ",t.createdBy]})]}),r.length>0&&(0,b.jsxs)("div",{className:"sm:col-span-2",children:[(0,b.jsxs)("h3",{className:"text-xs font-semibold text-text-muted uppercase tracking-wide mb-2",children:["Members (",t.memberCount,")"]}),(0,b.jsxs)("div",{className:"flex flex-wrap gap-2",children:[r.slice(0,10).map(e=>(0,b.jsx)(j,{member:e},e.id)),t.memberCount>10&&(0,b.jsxs)("button",{onClick:a,className:"text-xs text-accent-cyan hover:underline",children:["+",t.memberCount-10," more"]})]})]})]})})]})}function j(e){let{member:t}=e;return(0,b.jsxs)("div",{className:"flex items-center gap-1.5 px-2 py-1 bg-bg-tertiary rounded-full text-sm",children:[t.avatarUrl?(0,b.jsx)("img",{src:t.avatarUrl,alt:t.displayName||t.id,className:"w-4 h-4 rounded-full object-cover"}):(0,b.jsx)("div",{className:"\n w-4 h-4 rounded-full flex items-center justify-center text-[9px] font-medium\n ".concat("user"===t.entityType?"bg-purple-500/30 text-purple-300":"bg-accent-cyan/30 text-accent-cyan","\n "),children:(t.displayName||t.id).charAt(0).toUpperCase()}),(0,b.jsx)("span",{className:"text-text-secondary truncate max-w-[100px]",children:t.displayName||t.id}),(0,b.jsx)("span",{className:"w-1.5 h-1.5 rounded-full ".concat("online"===t.status?"bg-success":"away"===t.status?"bg-warning":"bg-text-dim")})]})}function w(e){let{className:t}=e;return(0,b.jsxs)("svg",{className:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,b.jsx)("line",{x1:"4",y1:"9",x2:"20",y2:"9"}),(0,b.jsx)("line",{x1:"4",y1:"15",x2:"20",y2:"15"}),(0,b.jsx)("line",{x1:"10",y1:"3",x2:"8",y2:"21"}),(0,b.jsx)("line",{x1:"16",y1:"3",x2:"14",y2:"21"})]})}function N(e){let{className:t}=e;return(0,b.jsxs)("svg",{className:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,b.jsx)("circle",{cx:"12",cy:"12",r:"4"}),(0,b.jsx)("path",{d:"M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-3.92 7.94"})]})}function k(e){let{className:t}=e;return(0,b.jsxs)("svg",{className:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,b.jsx)("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),(0,b.jsx)("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function C(e){let{className:t}=e;return(0,b.jsxs)("svg",{className:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,b.jsx)("path",{d:"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),(0,b.jsx)("circle",{cx:"9",cy:"7",r:"4"}),(0,b.jsx)("path",{d:"M23 21v-2a4 4 0 0 0-3-3.87"}),(0,b.jsx)("path",{d:"M16 3.13a4 4 0 0 1 0 7.75"})]})}function S(e){let{className:t}=e;return(0,b.jsxs)("svg",{className:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,b.jsx)("circle",{cx:"11",cy:"11",r:"8"}),(0,b.jsx)("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]})}function L(e){let{className:t}=e;return(0,b.jsxs)("svg",{className:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,b.jsx)("line",{x1:"12",y1:"17",x2:"12",y2:"22"}),(0,b.jsx)("path",{d:"M5 17h14v-1.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V6h1a2 2 0 0 0 0-4H8a2 2 0 0 0 0 4h1v4.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24Z"})]})}function M(e){let{className:t}=e;return(0,b.jsxs)("svg",{className:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,b.jsx)("circle",{cx:"12",cy:"12",r:"10"}),(0,b.jsx)("line",{x1:"12",y1:"16",x2:"12",y2:"12"}),(0,b.jsx)("line",{x1:"12",y1:"8",x2:"12.01",y2:"8"})]})}function D(e){let{className:t}=e;return(0,b.jsxs)("svg",{className:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,b.jsx)("circle",{cx:"12",cy:"12",r:"3"}),(0,b.jsx)("path",{d:"M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"})]})}var A=r(1832);function E(e){let{messages:t,unreadState:r,currentUser:n,isLoadingMore:s=!1,hasMore:a=!1,onLoadMore:l,onThreadClick:o,onMemberClick:i}=e,c=(0,v.useRef)(null),d=(0,v.useRef)(null),[u,x]=(0,v.useState)(!0),[m,h]=(0,v.useState)(!1),p=(0,v.useMemo)(()=>{let e=[],r="";return t.forEach(t=>{let n=new Date(t.timestamp).toDateString();n!==r?(r=n,e.push({date:n,messages:[t]})):e[e.length-1].messages.push(t)}),e},[t]),g=(0,v.useCallback)(()=>{let e=c.current;if(!e)return;let{scrollTop:t,scrollHeight:r,clientHeight:n}=e,o=r-t-n,i=o<100;x(i),h(!i&&o>500),t<100&&a&&!s&&l&&l()},[a,s,l]);(0,v.useEffect)(()=>{u&&d.current&&d.current.scrollIntoView({behavior:"smooth"})},[t.length,u]),(0,v.useEffect)(()=>{d.current&&d.current.scrollIntoView()},[]);let f=(0,v.useCallback)(()=>{var e;null===(e=d.current)||void 0===e||e.scrollIntoView({behavior:"smooth"})},[]);return(0,b.jsxs)("div",{className:"relative flex-1 overflow-hidden",children:[(0,b.jsxs)("div",{ref:c,onScroll:g,className:"h-full overflow-y-auto px-4 py-2",children:[s&&(0,b.jsx)("div",{className:"flex justify-center py-4",children:(0,b.jsx)(B,{})}),a&&!s&&(0,b.jsx)("div",{className:"flex justify-center py-4",children:(0,b.jsx)("button",{onClick:l,className:"text-sm text-accent-cyan hover:underline",children:"Load earlier messages"})}),0===t.length&&!s&&(0,b.jsxs)("div",{className:"flex flex-col items-center justify-center h-full text-center py-12",children:[(0,b.jsx)("div",{className:"text-4xl mb-3",children:(0,b.jsx)(F,{className:"w-12 h-12 text-text-muted"})}),(0,b.jsx)("h3",{className:"text-lg font-medium text-text-primary mb-1",children:"No messages yet"}),(0,b.jsx)("p",{className:"text-sm text-text-muted",children:"Be the first to send a message in this channel"})]}),p.map(e=>{let{date:t,messages:s}=e;return(0,b.jsxs)("div",{children:[(0,b.jsx)(R,{date:t}),s.map((e,t)=>{let a=(null==r?void 0:r.firstUnreadMessageId)===e.id&&r&&r.count>0;return(0,b.jsxs)(v.Fragment,{children:[a&&(0,b.jsx)(I,{count:r.count}),(0,b.jsx)(T,{message:e,isOwn:e.from===n,onThreadClick:o,onMemberClick:i,showAvatar:function(e,t){if(0===t)return!0;let r=e[t],n=e[t-1];return r.from!==n.from||new Date(r.timestamp).getTime()-new Date(n.timestamp).getTime()>3e5}(s,t)})]},e.id)})]},t)}),(0,b.jsx)("div",{ref:d})]}),m&&(0,b.jsx)("button",{onClick:f,className:"absolute bottom-4 right-4 p-3 bg-bg-elevated border border-border-subtle rounded-full shadow-lg hover:bg-bg-hover transition-colors",title:"Scroll to bottom",children:(0,b.jsx)(_,{className:"w-5 h-5 text-text-primary"})})]})}function T(e){let{message:t,isOwn:r,onThreadClick:n,onMemberClick:s,showAvatar:a}=e,l=t.threadSummary&&t.threadSummary.replyCount>0;return(0,b.jsx)("div",{className:"group relative py-1 ".concat(a?"mt-3":""),children:(0,b.jsxs)("div",{className:"flex gap-3",children:[(0,b.jsx)("div",{className:"w-9 flex-shrink-0",children:a&&(0,b.jsx)(W,{name:t.from,avatarUrl:t.fromAvatarUrl,entityType:t.fromEntityType})}),(0,b.jsxs)("div",{className:"flex-1 min-w-0",children:[a&&(0,b.jsxs)("div",{className:"flex items-center gap-2 mb-0.5",children:[(0,b.jsx)("button",{type:"button",onClick:()=>{!r&&s&&s(t.from,t.fromEntityType||"agent")},disabled:r||!s,className:"text-sm font-semibold ".concat(r?"text-accent-cyan cursor-default":"text-text-primary hover:underline cursor-pointer"," disabled:cursor-default disabled:hover:no-underline"),children:t.from}),(0,b.jsx)("span",{className:"text-xs text-text-muted",children:new Date(t.timestamp).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"})}),t.editedAt&&(0,b.jsx)("span",{className:"text-xs text-text-muted",children:"(edited)"}),(0,b.jsxs)("button",{className:"\n inline-flex items-center gap-1.5 p-1.5 rounded-lg transition-all duration-150 cursor-pointer border-none\n ".concat(l||t.threadId?"text-accent-cyan bg-accent-cyan/10 hover:bg-accent-cyan/20":"text-text-muted bg-transparent opacity-0 group-hover:opacity-100 hover:text-accent-cyan hover:bg-accent-cyan/10","\n "),onClick:()=>null==n?void 0:n(t.threadId||t.id),title:t.threadId?"View thread":l?"".concat(t.threadSummary.replyCount," ").concat(1===t.threadSummary.replyCount?"reply":"replies"):"Reply in thread",children:[(0,b.jsx)(U,{className:"w-3.5 h-3.5"}),l&&(0,b.jsx)("span",{className:"text-xs font-medium",children:t.threadSummary.replyCount})]})]}),(0,b.jsx)("div",{className:"text-sm text-text-primary whitespace-pre-wrap break-words",children:(0,A.y)(t.content,{mentions:t.mentions})}),t.attachments&&t.attachments.length>0&&(0,b.jsx)("div",{className:"mt-2 flex flex-wrap gap-2",children:t.attachments.map(e=>(0,b.jsx)(P,{attachment:e},e.id))})]})]})})}function W(e){let{name:t,avatarUrl:r,entityType:n}=e;return r?(0,b.jsx)("img",{src:r,alt:t,className:"w-9 h-9 rounded-full object-cover"}):(0,b.jsx)("div",{className:"\n w-9 h-9 rounded-full flex items-center justify-center text-sm font-medium\n ".concat("user"===n?"bg-purple-500/30 text-purple-300":"bg-accent-cyan/30 text-accent-cyan","\n "),children:t.charAt(0).toUpperCase()})}function P(e){var t;let{attachment:r}=e;return r.mimeType.startsWith("image/")?(0,b.jsx)("a",{href:r.url,target:"_blank",rel:"noopener noreferrer",className:"block max-w-xs rounded-lg overflow-hidden border border-border-subtle hover:border-accent-cyan/30 transition-colors",children:(0,b.jsx)("img",{src:r.thumbnailUrl||r.url,alt:r.filename,className:"max-w-full max-h-48 object-cover"})}):(0,b.jsxs)("a",{href:r.url,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-2 px-3 py-2 bg-bg-tertiary rounded-lg border border-border-subtle hover:border-accent-cyan/30 transition-colors",children:[(0,b.jsx)(O,{className:"w-5 h-5 text-text-muted"}),(0,b.jsxs)("div",{className:"min-w-0",children:[(0,b.jsx)("p",{className:"text-sm text-text-primary truncate",children:r.filename}),(0,b.jsx)("p",{className:"text-xs text-text-muted",children:(t=r.size)<1024?"".concat(t," B"):t<1048576?"".concat((t/1024).toFixed(1)," KB"):"".concat((t/1048576).toFixed(1)," MB")})]})]})}function R(e){let{date:t}=e;return(0,b.jsxs)("div",{className:"flex items-center gap-3 py-3",children:[(0,b.jsx)("div",{className:"flex-1 h-px bg-border-subtle"}),(0,b.jsx)("span",{className:"text-xs font-medium text-text-muted px-2",children:function(e){let t=new Date(e),r=new Date,n=new Date(r);return(n.setDate(n.getDate()-1),t.toDateString()===r.toDateString())?"Today":t.toDateString()===n.toDateString()?"Yesterday":t.toLocaleDateString(void 0,{weekday:"long",month:"long",day:"numeric"})}(t)}),(0,b.jsx)("div",{className:"flex-1 h-px bg-border-subtle"})]})}function I(e){let{count:t}=e;return(0,b.jsxs)("div",{className:"flex items-center gap-3 py-2 my-2",children:[(0,b.jsx)("div",{className:"flex-1 h-px bg-red-500/50"}),(0,b.jsxs)("span",{className:"text-xs font-semibold text-red-400 px-2 flex items-center gap-1",children:[(0,b.jsx)("span",{className:"w-2 h-2 bg-red-500 rounded-full"}),t," new ",1===t?"message":"messages"]}),(0,b.jsx)("div",{className:"flex-1 h-px bg-red-500/50"})]})}function B(){return(0,b.jsx)("div",{className:"w-5 h-5 border-2 border-accent-cyan/30 border-t-accent-cyan rounded-full animate-spin"})}function F(e){let{className:t}=e;return(0,b.jsx)("svg",{className:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,b.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"})})}function U(e){let{className:t}=e;return(0,b.jsx)("svg",{className:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,b.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"})})}function _(e){let{className:t}=e;return(0,b.jsx)("svg",{className:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,b.jsx)("polyline",{points:"6 9 12 15 18 9"})})}function O(e){let{className:t}=e;return(0,b.jsxs)("svg",{className:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,b.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,b.jsx)("polyline",{points:"14 2 14 8 20 8"})]})}function H(e){let{channelId:t,placeholder:r="Send a message...",disabled:n=!1,onSend:s,onTyping:a,mentionSuggestions:l=[]}=e,[o,i]=(0,v.useState)(""),[c,d]=(0,v.useState)(!1),[u,x]=(0,v.useState)(""),[m,h]=(0,v.useState)(0),[p,g]=(0,v.useState)(0),f=(0,v.useRef)(null),y=(0,v.useRef)(null),j=(0,v.useRef)(!1),w=(0,v.useMemo)(()=>{if(!u)return l.slice(0,5);let e=u.toLowerCase();return l.filter(t=>t.toLowerCase().includes(e)).slice(0,5)},[l,u]),N=(0,v.useCallback)(e=>{a&&(e&&!j.current&&(j.current=!0,a(!0)),y.current&&clearTimeout(y.current),e?y.current=setTimeout(()=>{j.current=!1,a(!1)},1e3):(j.current=!1,a(!1)))},[a]);(0,v.useEffect)(()=>()=>{y.current&&clearTimeout(y.current),j.current&&a&&a(!1)},[a]);let k=(0,v.useCallback)(e=>{let t=e.target.value,r=e.target.selectionStart;i(t),g(r),N(t.length>0);let n=t.slice(0,r).match(/@(\w*)$/);n?(x(n[1]),d(!0),h(0)):(d(!1),x(""));let s=f.current;s&&(s.style.height="auto",s.style.height="".concat(Math.min(s.scrollHeight,200),"px"))},[N]),C=(0,v.useCallback)(e=>{let t=o.slice(0,p),r=o.slice(p),n=t.match(/@(\w*)$/);if(!n)return;let s=t.slice(0,-n[0].length);i("".concat(s,"@").concat(e," ").concat(r)),d(!1),x(""),setTimeout(()=>{if(f.current){f.current.focus();let t=s.length+e.length+2;f.current.setSelectionRange(t,t),g(t)}},0)},[o,p]),S=(0,v.useCallback)(e=>{if(c&&w.length>0)switch(e.key){case"ArrowDown":e.preventDefault(),h(e=>e<w.length-1?e+1:0);return;case"ArrowUp":e.preventDefault(),h(e=>e>0?e-1:w.length-1);return;case"Tab":case"Enter":e.preventDefault(),C(w[m]);return;case"Escape":e.preventDefault(),d(!1);return}if("Enter"===e.key&&e.altKey){e.preventDefault();let t=e.target,r=t.selectionStart,n=t.selectionEnd;i(o.slice(0,r)+"\n"+o.slice(n)),setTimeout(()=>{t.selectionStart=t.selectionEnd=r+1},0);return}"Enter"!==e.key||e.shiftKey||e.altKey||(e.preventDefault(),L())},[c,w,m,C,o]),L=(0,v.useCallback)(()=>{let e=o.trim();e&&!n&&(s(e),i(""),N(!1),f.current&&(f.current.style.height="auto"))},[o,n,s,N]);return(0,b.jsxs)("div",{className:"relative flex-shrink-0 border-t border-border-subtle bg-bg-primary",children:[c&&w.length>0&&(0,b.jsx)("div",{className:"absolute bottom-full left-4 mb-1 bg-bg-elevated border border-border-subtle rounded-lg shadow-lg py-1 min-w-[200px] max-h-[200px] overflow-y-auto",children:w.map((e,t)=>(0,b.jsxs)("button",{onClick:()=>C(e),className:"\n w-full flex items-center gap-2 px-3 py-1.5 text-sm text-left transition-colors\n ".concat(t===m?"bg-accent-cyan/10 text-text-primary":"text-text-secondary hover:bg-bg-hover","\n "),children:[(0,b.jsx)("div",{className:"w-6 h-6 rounded-full bg-accent-cyan/20 flex items-center justify-center text-xs font-medium text-accent-cyan",children:e.charAt(0).toUpperCase()}),(0,b.jsx)("span",{children:e})]},e))}),(0,b.jsxs)("div",{className:"p-4",children:[(0,b.jsxs)("div",{className:"flex items-end gap-3",children:[(0,b.jsx)("button",{type:"button",disabled:n,className:"p-2 rounded-lg text-text-muted hover:text-text-primary hover:bg-bg-hover transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex-shrink-0",title:"Attach file",children:(0,b.jsx)(z,{className:"w-5 h-5"})}),(0,b.jsx)("div",{className:"flex-1 relative",children:(0,b.jsx)("textarea",{ref:f,value:o,onChange:k,onKeyDown:S,placeholder:r,disabled:n,rows:1,className:"w-full px-4 py-2.5 bg-bg-tertiary border border-border-subtle rounded-lg text-text-primary text-sm resize-none focus:outline-none focus:border-accent-cyan/50 disabled:opacity-50 disabled:cursor-not-allowed placeholder:text-text-muted",style:{maxHeight:"200px"}})}),(0,b.jsx)("button",{type:"button",onClick:L,disabled:!o.trim()||n,className:"\n p-2.5 rounded-lg transition-colors flex-shrink-0\n ".concat(o.trim()&&!n?"bg-accent-cyan text-bg-deep hover:bg-accent-cyan/90":"bg-bg-tertiary text-text-muted cursor-not-allowed","\n "),title:"Send message",children:(0,b.jsx)(G,{className:"w-5 h-5"})})]}),(0,b.jsxs)("p",{className:"mt-2 text-xs text-text-muted",children:[(0,b.jsx)("kbd",{className:"px-1 py-0.5 bg-bg-tertiary rounded text-[10px]",children:"Enter"})," to send,"," ",(0,b.jsx)("kbd",{className:"px-1 py-0.5 bg-bg-tertiary rounded text-[10px]",children:"Shift/Option+Enter"})," for new line,"," ",(0,b.jsx)("kbd",{className:"px-1 py-0.5 bg-bg-tertiary rounded text-[10px]",children:"@"})," to mention"]})]})]})}function z(e){let{className:t}=e;return(0,b.jsx)("svg",{className:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:(0,b.jsx)("path",{d:"M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"})})}function G(e){let{className:t}=e;return(0,b.jsxs)("svg",{className:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,b.jsx)("line",{x1:"22",y1:"2",x2:"11",y2:"13"}),(0,b.jsx)("polygon",{points:"22 2 15 22 11 13 2 9 22 2"})]})}function V(e){let{channel:t,members:r=[],messages:n,unreadState:s,currentUser:a,canEditChannel:l=!1,isLoadingMore:o=!1,hasMoreMessages:i=!1,mentionSuggestions:c=[],onLoadMore:d,onSendMessage:u,onEditChannel:x,onShowMembers:m,onShowPinned:h,onSearch:p,onThreadClick:g,onTyping:f,onMarkRead:j,onMemberClick:w}=e,N=(0,v.useCallback)(e=>{u(e)},[u]),k=(0,v.useMemo)(()=>t.isDm?"Message ".concat(t.name):"Message #".concat(t.name),[t]),C="archived"===t.status;return(0,b.jsxs)("div",{className:"flex flex-col h-full bg-bg-primary",children:[(0,b.jsx)(y,{channel:t,members:r,canEdit:l,onEditChannel:x,onShowMembers:m,onShowPinned:h,onSearch:p}),(0,b.jsx)(E,{messages:n,unreadState:s,currentUser:a,isLoadingMore:o,hasMore:i,onLoadMore:d,onThreadClick:g,onMemberClick:w}),C?(0,b.jsx)("div",{className:"px-4 py-3 bg-bg-secondary border-t border-border-subtle text-center",children:(0,b.jsx)("p",{className:"text-sm text-text-muted",children:"This channel is archived. Unarchive it to send messages."})}):(0,b.jsx)(H,{channelId:t.id,placeholder:k,onSend:N,onTyping:f,mentionSuggestions:c})]})}function K(e){let{isOpen:t,onClose:r,onCreate:n,isLoading:s=!1,existingChannels:a=[],availableMembers:l=[],workspaceId:o}=e,[i,c]=(0,v.useState)(""),[d,u]=(0,v.useState)(""),[x,m]=(0,v.useState)("public"),[h,g]=(0,v.useState)(""),[f,y]=(0,v.useState)([]),[j,w]=(0,v.useState)([]),[N,k]=(0,v.useState)([]),[C,S]=(0,v.useState)(!1);(0,v.useEffect)(()=>{t&&(S(!0),p(o).then(e=>{let{members:t,agents:r}=e;w(t),k(r)}).catch(e=>{console.error("[CreateChannelModal] Failed to fetch available members:",e)}).finally(()=>{S(!1)}))},[t,o]);let L=[...j,...N,...l.filter(e=>!N.some(t=>t.id===e)&&!j.some(t=>t.id===e)).map(e=>({id:e,displayName:e,type:"agent"}))],M=(0,v.useCallback)(()=>{c(""),u(""),m("public"),g(""),y([]),r()},[r]),D=(0,v.useCallback)(e=>{f.some(t=>t.id===e.id)||(y(t=>[...t,{id:e.id,type:e.type}]),g(""))},[f]),A=(0,v.useCallback)(e=>{y(t=>t.filter(t=>t.id!==e))},[]),E=(0,v.useCallback)(e=>{e.preventDefault(),i.trim()&&n({name:i.trim().toLowerCase().replace(/\s+/g,"-"),description:d.trim()||void 0,visibility:x,members:f.length>0?f:void 0})},[i,d,x,f,n]),T=L.filter(e=>{var t;return((null===(t=e.displayName)||void 0===t?void 0:t.toLowerCase().includes(h.toLowerCase()))||e.id.toLowerCase().includes(h.toLowerCase()))&&!f.some(t=>t.id===e.id)}).slice(0,8);if(!t)return null;let W=i.trim().toLowerCase().replace(/\s+/g,"-"),P=a.includes("#".concat(W)),R=W.length>=2&&W.length<=80&&/^[a-z0-9-]+$/.test(W),I=i.trim()&&R&&!P;return(0,b.jsx)(q,{onClose:M,children:(0,b.jsxs)("form",{onSubmit:E,className:"p-6 w-[400px] max-w-full",children:[(0,b.jsx)("h2",{className:"text-lg font-semibold text-text-primary mb-6",children:"Create a channel"}),(0,b.jsxs)("div",{className:"mb-4",children:[(0,b.jsx)("label",{className:"block text-sm font-medium text-text-primary mb-1.5",children:"Channel name"}),(0,b.jsxs)("div",{className:"relative",children:[(0,b.jsx)("span",{className:"absolute left-3 top-1/2 -translate-y-1/2 text-text-muted",children:"#"}),(0,b.jsx)("input",{type:"text",value:i,onChange:e=>c(e.target.value),placeholder:"e.g., engineering",className:"w-full pl-7 pr-3 py-2 bg-bg-tertiary border border-border-subtle rounded-lg text-text-primary text-sm focus:outline-none focus:border-accent-cyan/50",autoFocus:!0})]}),i&&!R&&(0,b.jsx)("p",{className:"mt-1 text-xs text-red-400",children:"Channel names must be 2-80 characters, lowercase letters, numbers, and hyphens only"}),P&&(0,b.jsx)("p",{className:"mt-1 text-xs text-red-400",children:"A channel with this name already exists"})]}),(0,b.jsxs)("div",{className:"mb-4",children:[(0,b.jsxs)("label",{className:"block text-sm font-medium text-text-primary mb-1.5",children:["Description ",(0,b.jsx)("span",{className:"text-text-muted font-normal",children:"(optional)"})]}),(0,b.jsx)("textarea",{value:d,onChange:e=>u(e.target.value),placeholder:"What's this channel about?",rows:2,className:"w-full px-3 py-2 bg-bg-tertiary border border-border-subtle rounded-lg text-text-primary text-sm focus:outline-none focus:border-accent-cyan/50 resize-none"})]}),(0,b.jsxs)("div",{className:"mb-4",children:[(0,b.jsxs)("label",{className:"block text-sm font-medium text-text-primary mb-1.5",children:["Invite members ",(0,b.jsx)("span",{className:"text-text-muted font-normal",children:"(optional)"}),C&&(0,b.jsx)("span",{className:"ml-2 text-text-muted text-xs",children:"Loading..."})]}),(0,b.jsxs)("div",{className:"relative",children:[(0,b.jsx)("input",{type:"text",value:h,onChange:e=>g(e.target.value),placeholder:L.length>0?"Type agent or user name...":"No members available",className:"w-full px-3 py-2 bg-bg-tertiary border border-border-subtle rounded-lg text-text-primary text-sm focus:outline-none focus:border-accent-cyan/50"}),h&&T.length>0&&(0,b.jsx)("div",{className:"absolute z-10 w-full mt-1 bg-bg-secondary border border-border-subtle rounded-lg shadow-lg max-h-48 overflow-y-auto",children:T.map(e=>(0,b.jsxs)("button",{type:"button",onClick:()=>D(e),className:"w-full px-3 py-2 text-left text-sm text-text-primary hover:bg-bg-hover transition-colors flex items-center justify-between",children:[(0,b.jsx)("span",{children:e.displayName||e.id}),(0,b.jsx)("span",{className:"text-xs px-1.5 py-0.5 rounded ".concat("agent"===e.type?"bg-purple-500/20 text-purple-400":"bg-accent-cyan/20 text-accent-cyan"),children:"agent"===e.type?"Agent":"User"})]},e.id))}),!h&&L.length>0&&(0,b.jsxs)("div",{className:"mt-2 text-xs text-text-muted",children:[j.length>0&&(0,b.jsxs)("span",{children:[j.length," user",1!==j.length?"s":""]}),j.length>0&&N.length>0&&(0,b.jsx)("span",{children:", "}),N.length>0&&(0,b.jsxs)("span",{children:[N.length," agent",1!==N.length?"s":""]}),(0,b.jsx)("span",{children:" available"})]})]}),f.length>0&&(0,b.jsx)("div",{className:"flex flex-wrap gap-1.5 mt-2",children:f.map(e=>(0,b.jsxs)("span",{className:"inline-flex items-center gap-1 px-2 py-1 text-xs rounded-full ".concat("agent"===e.type?"bg-purple-500/10 text-purple-400":"bg-accent-cyan/10 text-accent-cyan"),children:[e.id,(0,b.jsxs)("span",{className:"text-[10px] opacity-70",children:["(","agent"===e.type?"Agent":"User",")"]}),(0,b.jsx)("button",{type:"button",onClick:()=>A(e.id),className:"hover:text-red-400 transition-colors",children:(0,b.jsx)(ee,{className:"w-3 h-3"})})]},e.id))})]}),(0,b.jsxs)("div",{className:"mb-6",children:[(0,b.jsx)("label",{className:"block text-sm font-medium text-text-primary mb-2",children:"Visibility"}),(0,b.jsxs)("div",{className:"space-y-2",children:[(0,b.jsxs)("label",{className:"\n flex items-start gap-3 p-3 rounded-lg border cursor-pointer transition-colors\n ".concat("public"===x?"border-accent-cyan/30 bg-accent-cyan/5":"border-border-subtle hover:bg-bg-hover","\n "),children:[(0,b.jsx)("input",{type:"radio",name:"visibility",value:"public",checked:"public"===x,onChange:()=>m("public"),className:"mt-1"}),(0,b.jsxs)("div",{children:[(0,b.jsxs)("div",{className:"flex items-center gap-2",children:[(0,b.jsx)($,{className:"w-4 h-4 text-text-primary"}),(0,b.jsx)("span",{className:"text-sm font-medium text-text-primary",children:"Public"})]}),(0,b.jsx)("p",{className:"text-xs text-text-muted mt-0.5",children:"Anyone can join and view messages"})]})]}),(0,b.jsxs)("label",{className:"\n flex items-start gap-3 p-3 rounded-lg border cursor-pointer transition-colors\n ".concat("private"===x?"border-accent-cyan/30 bg-accent-cyan/5":"border-border-subtle hover:bg-bg-hover","\n "),children:[(0,b.jsx)("input",{type:"radio",name:"visibility",value:"private",checked:"private"===x,onChange:()=>m("private"),className:"mt-1"}),(0,b.jsxs)("div",{children:[(0,b.jsxs)("div",{className:"flex items-center gap-2",children:[(0,b.jsx)(Y,{className:"w-4 h-4 text-text-primary"}),(0,b.jsx)("span",{className:"text-sm font-medium text-text-primary",children:"Private"})]}),(0,b.jsx)("p",{className:"text-xs text-text-muted mt-0.5",children:"Only invited members can join"})]})]})]})]}),(0,b.jsxs)("div",{className:"flex justify-end gap-3",children:[(0,b.jsx)("button",{type:"button",onClick:M,disabled:s,className:"px-4 py-2 text-sm font-medium text-text-secondary bg-bg-tertiary hover:bg-bg-hover rounded-lg transition-colors disabled:opacity-50",children:"Cancel"}),(0,b.jsxs)("button",{type:"submit",disabled:!I||s,className:"px-4 py-2 text-sm font-medium bg-accent-cyan text-bg-deep hover:bg-accent-cyan/90 rounded-lg transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2",children:[s&&(0,b.jsx)(J,{className:"w-4 h-4"}),"Create Channel"]})]})]})})}function Z(e){let{isOpen:t,channelName:r,onClose:n,onInvite:s,isLoading:a=!1,availableMembers:l=[]}=e,[o,i]=(0,v.useState)(""),[c,d]=(0,v.useState)([]),u=(0,v.useCallback)(()=>{i(""),d([]),n()},[n]),x=(0,v.useCallback)(e=>{let t=e.trim();t&&!c.includes(t)&&(d(e=>[...e,t]),i(""))},[c]),m=(0,v.useCallback)(e=>{d(t=>t.filter(t=>t!==e))},[]),h=(0,v.useCallback)(e=>{e.preventDefault(),0!==c.length&&s(c)},[c,s]),p=l.filter(e=>e.toLowerCase().includes(o.toLowerCase())&&!c.includes(e)).slice(0,5);return t?(0,b.jsx)(q,{onClose:u,children:(0,b.jsxs)("form",{onSubmit:h,className:"p-6 w-[400px] max-w-full",children:[(0,b.jsxs)("h2",{className:"text-lg font-semibold text-text-primary mb-2",children:["Invite to #",r]}),(0,b.jsx)("p",{className:"text-sm text-text-muted mb-6",children:"Add agents or users to this channel"}),(0,b.jsxs)("div",{className:"mb-4",children:[(0,b.jsx)("label",{className:"block text-sm font-medium text-text-primary mb-1.5",children:"Members to invite"}),(0,b.jsxs)("div",{className:"relative",children:[(0,b.jsx)("input",{type:"text",value:o,onChange:e=>i(e.target.value),onKeyDown:e=>{"Enter"===e.key&&o.trim()&&(e.preventDefault(),x(o))},placeholder:"Type agent or user name...",className:"w-full px-3 py-2 bg-bg-tertiary border border-border-subtle rounded-lg text-text-primary text-sm focus:outline-none focus:border-accent-cyan/50",autoFocus:!0}),o&&p.length>0&&(0,b.jsx)("div",{className:"absolute z-10 w-full mt-1 bg-bg-secondary border border-border-subtle rounded-lg shadow-lg max-h-40 overflow-y-auto",children:p.map(e=>(0,b.jsx)("button",{type:"button",onClick:()=>x(e),className:"w-full px-3 py-2 text-left text-sm text-text-primary hover:bg-bg-hover transition-colors",children:e},e))})]}),c.length>0&&(0,b.jsx)("div",{className:"flex flex-wrap gap-1.5 mt-2",children:c.map(e=>(0,b.jsxs)("span",{className:"inline-flex items-center gap-1 px-2 py-1 bg-accent-cyan/10 text-accent-cyan text-xs rounded-full",children:[e,(0,b.jsx)("button",{type:"button",onClick:()=>m(e),className:"hover:text-red-400 transition-colors",children:(0,b.jsx)(ee,{className:"w-3 h-3"})})]},e))})]}),(0,b.jsxs)("div",{className:"flex justify-end gap-3",children:[(0,b.jsx)("button",{type:"button",onClick:u,disabled:a,className:"px-4 py-2 text-sm font-medium text-text-secondary bg-bg-tertiary hover:bg-bg-hover rounded-lg transition-colors disabled:opacity-50",children:"Cancel"}),(0,b.jsxs)("button",{type:"submit",disabled:0===c.length||a,className:"px-4 py-2 text-sm font-medium bg-accent-cyan text-bg-deep hover:bg-accent-cyan/90 rounded-lg transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2",children:[a&&(0,b.jsx)(J,{className:"w-4 h-4"}),"Invite ",c.length>0?"(".concat(c.length,")"):""]})]})]})}):null}function q(e){let{children:t,onClose:r}=e;return(0,b.jsxs)("div",{className:"fixed inset-0 z-50 flex items-center justify-center",onClick:r,children:[(0,b.jsx)("div",{className:"absolute inset-0 bg-black/60 backdrop-blur-sm"}),(0,b.jsx)("div",{className:"relative bg-bg-elevated border border-border-subtle rounded-xl shadow-2xl animate-in fade-in zoom-in-95 duration-150",onClick:e=>e.stopPropagation(),children:t})]})}function J(e){let{className:t}=e;return(0,b.jsxs)("svg",{className:"animate-spin ".concat(t),viewBox:"0 0 24 24",fill:"none",children:[(0,b.jsx)("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),(0,b.jsx)("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}function $(e){let{className:t}=e;return(0,b.jsxs)("svg",{className:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,b.jsx)("line",{x1:"4",y1:"9",x2:"20",y2:"9"}),(0,b.jsx)("line",{x1:"4",y1:"15",x2:"20",y2:"15"}),(0,b.jsx)("line",{x1:"10",y1:"3",x2:"8",y2:"21"}),(0,b.jsx)("line",{x1:"16",y1:"3",x2:"14",y2:"21"})]})}function Y(e){let{className:t}=e;return(0,b.jsxs)("svg",{className:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,b.jsx)("rect",{x:"3",y:"11",width:"18",height:"11",rx:"2",ry:"2"}),(0,b.jsx)("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})}function X(e){let{className:t}=e;return(0,b.jsxs)("svg",{className:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,b.jsx)("path",{d:"M16 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),(0,b.jsx)("circle",{cx:"8.5",cy:"7",r:"4"}),(0,b.jsx)("line",{x1:"20",y1:"8",x2:"20",y2:"14"}),(0,b.jsx)("line",{x1:"23",y1:"11",x2:"17",y2:"11"})]})}function Q(e){let{className:t}=e;return(0,b.jsxs)("svg",{className:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,b.jsx)("path",{d:"M16 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"}),(0,b.jsx)("circle",{cx:"8.5",cy:"7",r:"4"}),(0,b.jsx)("line",{x1:"23",y1:"11",x2:"17",y2:"11"})]})}function ee(e){let{className:t}=e;return(0,b.jsxs)("svg",{className:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,b.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,b.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function et(e){let{channel:t,members:r,isOpen:n,onClose:s,onAddMember:a,onRemoveMember:l,onUpdateRole:o,currentUserId:i,isLoading:c=!1,availableUsers:d=[],availableAgents:u=[],workspaceId:x}=e,[m,h]=(0,v.useState)(!1),[g,f]=(0,v.useState)("user"),[y,j]=(0,v.useState)(""),[w,N]=(0,v.useState)("member"),[k,C]=(0,v.useState)([]),[S,L]=(0,v.useState)([]),[M,D]=(0,v.useState)(!1);(0,v.useEffect)(()=>{n&&(D(!0),p(x).then(e=>{let{members:t,agents:r}=e;C(t),L(r)}).catch(e=>{console.error("[MemberManagementPanel] Failed to fetch available members:",e)}).finally(()=>{D(!1)}))},[n,x]);let A=k.length>0?k.map(e=>({id:e.id,name:e.displayName||e.id})):d,E=S.length>0?S.map(e=>({name:e.displayName||e.id})):u;if(!n)return null;let T=r.filter(e=>"user"===e.entityType),W=r.filter(e=>"agent"===e.entityType),P=r.find(e=>e.id===i),R=(null==P?void 0:P.role)==="owner"||(null==P?void 0:P.role)==="admin",I=r.filter(e=>"owner"===e.role||"admin"===e.role).length,B=new Set(r.map(e=>e.id)),F=A.filter(e=>!B.has(e.id)),U=E.filter(e=>!r.some(t=>t.displayName===e.name&&"agent"===t.entityType)),_=e=>"owner"!==e.role&&("admin"!==e.role||!(I<=1))&&e.id!==i&&R,O=e=>"owner"!==e.role&&("admin"!==e.role||!(I<=1))&&R;return(0,b.jsx)(q,{onClose:s,children:(0,b.jsxs)("div",{className:"p-6 w-[500px] max-w-full max-h-[80vh] overflow-hidden flex flex-col",children:[(0,b.jsxs)("div",{className:"flex items-center justify-between mb-4",children:[(0,b.jsxs)("div",{className:"flex items-center gap-3",children:[(0,b.jsx)("div",{className:"w-10 h-10 rounded-full bg-accent-cyan/10 flex items-center justify-center",children:(0,b.jsx)(X,{className:"w-5 h-5 text-accent-cyan"})}),(0,b.jsxs)("div",{children:[(0,b.jsx)("h2",{className:"text-lg font-semibold text-text-primary",children:"Members"}),(0,b.jsxs)("p",{className:"text-sm text-text-muted",children:["#",t.name," \xb7 ",r.length," ",1===r.length?"member":"members"]})]})]}),R&&(0,b.jsx)("button",{onClick:()=>h(!m),className:"px-3 py-1.5 text-sm font-medium bg-accent-cyan/20 text-accent-cyan hover:bg-accent-cyan/30 rounded-lg transition-colors",children:m?"Cancel":"Add Member"})]}),m&&R&&(0,b.jsxs)("div",{className:"mb-4 p-4 bg-bg-tertiary rounded-lg border border-border-subtle",children:[(0,b.jsxs)("div",{className:"flex gap-2 mb-3",children:[(0,b.jsx)("button",{onClick:()=>f("user"),className:"px-3 py-1.5 text-sm rounded-lg transition-colors ".concat("user"===g?"bg-accent-cyan text-bg-deep":"bg-bg-hover text-text-secondary hover:text-text-primary"),children:"User"}),(0,b.jsx)("button",{onClick:()=>f("agent"),className:"px-3 py-1.5 text-sm rounded-lg transition-colors ".concat("agent"===g?"bg-accent-cyan text-bg-deep":"bg-bg-hover text-text-secondary hover:text-text-primary"),children:"Agent"})]}),(0,b.jsxs)("div",{className:"flex gap-2 mb-3",children:[(0,b.jsxs)("select",{value:y,onChange:e=>j(e.target.value),className:"flex-1 px-3 py-2 bg-bg-deep border border-border-subtle rounded-lg text-text-primary text-sm focus:outline-none focus:border-accent-cyan/50",disabled:M,children:[(0,b.jsx)("option",{value:"",children:M?"Loading...":"Select ".concat(g,"...")}),"user"===g?F.map(e=>(0,b.jsx)("option",{value:e.id,children:e.name},e.id)):U.map(e=>(0,b.jsx)("option",{value:e.name,children:e.name},e.name))]}),(0,b.jsxs)("select",{value:w,onChange:e=>N(e.target.value),className:"px-3 py-2 bg-bg-deep border border-border-subtle rounded-lg text-text-primary text-sm focus:outline-none focus:border-accent-cyan/50",children:[(0,b.jsx)("option",{value:"member",children:"Member"}),(0,b.jsx)("option",{value:"admin",children:"Admin"}),(0,b.jsx)("option",{value:"read_only",children:"Read Only"})]})]}),(0,b.jsxs)("button",{onClick:()=>{y&&(a(y,g,w),j(""),h(!1))},disabled:!y||c,className:"w-full px-3 py-2 text-sm font-medium bg-accent-cyan text-bg-deep hover:bg-accent-cyan/90 rounded-lg transition-colors disabled:opacity-50 disabled:cursor-not-allowed",children:["Add ","user"===g?"User":"Agent"]})]}),(0,b.jsxs)("div",{className:"flex-1 overflow-y-auto space-y-4",children:[T.length>0&&(0,b.jsxs)("div",{children:[(0,b.jsxs)("h3",{className:"text-xs font-medium text-text-muted uppercase mb-2",children:["Users (",T.length,")"]}),(0,b.jsx)("div",{className:"space-y-1",children:T.map(e=>(0,b.jsx)(er,{member:e,canChangeRole:O(e),canRemove:_(e),onChangeRole:t=>o(e.id,"user",t),onRemove:()=>l(e.id,"user"),isCurrentUser:e.id===i},e.id))})]}),W.length>0&&(0,b.jsxs)("div",{children:[(0,b.jsxs)("h3",{className:"text-xs font-medium text-text-muted uppercase mb-2",children:["Agents (",W.length,")"]}),(0,b.jsx)("div",{className:"space-y-1",children:W.map(e=>(0,b.jsx)(er,{member:e,canChangeRole:O(e),canRemove:_(e),onChangeRole:t=>o(e.id,"agent",t),onRemove:()=>l(e.id,"agent"),isAgent:!0},e.id))})]})]}),(0,b.jsx)("div",{className:"mt-4 pt-4 border-t border-border-subtle",children:(0,b.jsx)("button",{onClick:s,className:"w-full px-4 py-2 text-sm font-medium text-text-secondary bg-bg-tertiary hover:bg-bg-hover rounded-lg transition-colors",children:"Done"})})]})})}function er(e){let{member:t,canChangeRole:r,canRemove:n,onChangeRole:s,onRemove:a,isCurrentUser:l,isAgent:o}=e;return(0,b.jsxs)("div",{className:"flex items-center justify-between p-2 rounded-lg hover:bg-bg-tertiary group",children:[(0,b.jsxs)("div",{className:"flex items-center gap-3",children:[(0,b.jsx)("div",{className:"w-8 h-8 rounded-full flex items-center justify-center text-xs font-medium ".concat(o?"bg-purple-500/20 text-purple-400":"bg-accent-cyan/20 text-accent-cyan"),children:(t.displayName||t.id)[0].toUpperCase()}),(0,b.jsxs)("div",{children:[(0,b.jsxs)("div",{className:"flex items-center gap-2",children:[(0,b.jsx)("span",{className:"text-sm font-medium text-text-primary",children:t.displayName||t.id}),l&&(0,b.jsx)("span",{className:"text-xs text-text-muted",children:"(you)"}),o&&(0,b.jsx)("span",{className:"text-xs px-1.5 py-0.5 bg-purple-500/20 text-purple-400 rounded",children:"Agent"})]}),(0,b.jsx)("span",{className:"text-xs capitalize ".concat("owner"===t.role?"text-yellow-400":"admin"===t.role?"text-accent-cyan":"text-text-muted"),children:t.role})]})]}),(0,b.jsxs)("div",{className:"flex items-center gap-2 opacity-0 group-hover:opacity-100 transition-opacity",children:[r&&(0,b.jsxs)("select",{value:"owner"===t.role?"admin":t.role,onChange:e=>s(e.target.value),className:"px-2 py-1 text-xs bg-bg-tertiary border border-border-subtle rounded text-text-primary focus:outline-none focus:border-accent-cyan/50",children:[(0,b.jsx)("option",{value:"admin",children:"Admin"}),(0,b.jsx)("option",{value:"member",children:"Member"}),(0,b.jsx)("option",{value:"read_only",children:"Read Only"})]}),n&&(0,b.jsx)("button",{onClick:a,className:"p-1.5 text-red-400 hover:bg-red-500/20 rounded transition-colors",title:"Remove member",children:(0,b.jsx)(Q,{className:"w-4 h-4"})})]})]})}},1832:function(e,t,r){r.d(t,{y:function(){return k}});var n=r(7573),s=r(7653),a=r(47),l=r(5756),o=r(9363),i=r(9355),c=r(9425),d=r(3534),u=r(9714),x=r(890),m=r(2810),h=r(4583),p=r(6732),g=r(6047),f=r(4585),b=r(8864),v=r(9242),y=r(126);a.Z.registerLanguage("javascript",o.Z),a.Z.registerLanguage("typescript",i.Z),a.Z.registerLanguage("python",c.Z),a.Z.registerLanguage("bash",d.Z),a.Z.registerLanguage("shell",d.Z),a.Z.registerLanguage("json",u.Z),a.Z.registerLanguage("markdown",x.Z),a.Z.registerLanguage("yaml",m.Z),a.Z.registerLanguage("css",h.Z),a.Z.registerLanguage("go",p.Z),a.Z.registerLanguage("rust",g.Z),a.Z.registerLanguage("sql",f.Z),a.Z.registerLanguage("ruby",b.Z),a.Z.registerLanguage("java",v.Z),a.Z.registerLanguage("docker",y.Z),a.Z.registerLanguage("dockerfile",y.Z);let j={...l.Z,'pre[class*="language-"]':{...l.Z['pre[class*="language-"]'],background:"rgba(15, 23, 42, 0.8)",margin:"0.5rem 0",padding:"1rem",borderRadius:"0.5rem",border:"1px solid rgba(148, 163, 184, 0.1)",fontSize:"0.75rem",lineHeight:"1.5"},'code[class*="language-"]':{...l.Z['code[class*="language-"]'],background:"transparent",fontSize:"0.75rem"}};function w(e){let{code:t,language:r}=e,[l,o]=(0,s.useState)(!1),i=(0,s.useCallback)(async()=>{try{await navigator.clipboard.writeText(t),o(!0),setTimeout(()=>o(!1),2e3)}catch(e){console.error("Failed to copy:",e)}},[t]),c=r.toLowerCase().replace(/^(js|jsx)$/,"javascript").replace(/^(ts|tsx)$/,"typescript").replace(/^(py)$/,"python").replace(/^(rb)$/,"ruby").replace(/^(sh|shell|zsh)$/,"bash");return(0,n.jsxs)("div",{className:"relative group my-2",children:[(0,n.jsxs)("div",{className:"absolute top-2 right-2 flex items-center gap-2 z-10",children:[r&&"text"!==r&&(0,n.jsx)("span",{className:"text-xs px-2 py-0.5 rounded bg-accent-cyan/20 text-accent-cyan font-mono",children:r}),(0,n.jsx)("button",{onClick:i,className:"opacity-0 group-hover:opacity-100 transition-opacity text-xs px-2 py-1 rounded bg-bg-tertiary hover:bg-bg-card text-text-muted hover:text-text-primary border border-border-subtle",title:"Copy code",children:l?"✓ Copied":"Copy"})]}),(0,n.jsx)(a.Z,{language:c,style:j,customStyle:{margin:0,background:"rgba(15, 23, 42, 0.8)"},showLineNumbers:t.split("\n").length>3,lineNumberStyle:{minWidth:"2.5em",paddingRight:"1em",color:"rgba(148, 163, 184, 0.4)",userSelect:"none"},children:t.trim()})]})}function N(e){let t=e.split("\n"),r=[],n=null;for(let e of t){let t;let s=e;e.trimStart().startsWith(">")?(t="quote",s=function(e){let t=e.trimStart();return t.startsWith("> ")?t.slice(2):t.startsWith(">")?t.slice(1):e}(e)):t=(e.match(/\|/g)||[]).length>=2||e.trim().startsWith("|")&&e.trim().endsWith("|")||/^[\s|:-]+$/.test(e)&&e.includes("-")&&e.includes("|")?"table":"text",n&&n.type===t?n.content+="\n"+s:(n&&r.push(n),n={type:t,content:s})}return n&&r.push(n),r}function k(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=e.replace(/\\n/g,"\n").replace(/\r\n/g,"\n").replace(/\r/g,"\n"),a=function(e){let t;let r=[],n=/```(\w*)\n([\s\S]*?)```/g,s=0;for(;null!==(t=n.exec(e));){if(t.index>s){let n=N(e.slice(s,t.index));r.push(...n)}r.push({type:"code",language:t[1]||"text",content:t[2]}),s=t.index+t[0].length}if(s<e.length){let t=N(e.slice(s));r.push(...t)}return 0===r.length?N(e):r}(r);return 1===a.length&&"text"===a[0].type?r.split("\n").map((e,r)=>(0,n.jsxs)(s.Fragment,{children:[r>0&&(0,n.jsx)("br",{}),S(e,t.mentions)]},r)):a.map((e,r)=>{if("code"===e.type)return(0,n.jsx)(w,{code:e.content,language:e.language||"text"},r);if("table"===e.type)return(0,n.jsx)("pre",{className:"font-mono text-xs leading-relaxed whitespace-pre overflow-x-auto my-2 p-3 bg-bg-tertiary/50 rounded-lg border border-border-subtle",children:e.content},r);if("quote"===e.type){let a=e.content.split("\n");return(0,n.jsx)("blockquote",{className:"my-2 pl-3 py-1 border-l-2 border-accent-cyan/50 bg-bg-tertiary/30 rounded-r text-text-secondary italic",children:a.map((e,r)=>(0,n.jsxs)(s.Fragment,{children:[r>0&&(0,n.jsx)("br",{}),S(e,t.mentions)]},r))},r)}let a=e.content.split("\n");return(0,n.jsx)("span",{children:a.map((e,r)=>(0,n.jsxs)(s.Fragment,{children:[r>0&&(0,n.jsx)("br",{}),S(e,t.mentions)]},r))},r)})}function C(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"",s=[],a=e,l=0,o=[{regex:/`([^`]+)`/,render:(e,t)=>(0,n.jsx)("code",{className:"px-1.5 py-0.5 mx-0.5 rounded bg-bg-elevated/80 text-accent-cyan font-mono text-[0.85em] border border-border-subtle/50",children:e[1]},t)},{regex:/\[([^\]]+)\]\(([^)]+)\)/,render:(e,t)=>(0,n.jsx)("a",{href:e[2],target:"_blank",rel:"noopener noreferrer",className:"text-accent-cyan no-underline hover:underline",children:e[1]},t)},{regex:/\*\*([^*]+)\*\*/,render:(e,r)=>(0,n.jsx)("strong",{className:"font-semibold text-text-primary",children:C(e[1],t,"".concat(r,"-inner"))},r)},{regex:/__([^_]+)__/,render:(e,r)=>(0,n.jsx)("strong",{className:"font-semibold text-text-primary",children:C(e[1],t,"".concat(r,"-inner"))},r)},{regex:/_([^_]+)_/,render:(e,r)=>(0,n.jsx)("em",{className:"italic",children:C(e[1],t,"".concat(r,"-inner"))},r)},{regex:/\*([^*]+)\*/,render:(e,r)=>(0,n.jsx)("em",{className:"italic",children:C(e[1],t,"".concat(r,"-inner"))},r)},{regex:/~~([^~]+)~~/,render:(e,t)=>(0,n.jsx)("del",{className:"line-through text-text-muted",children:e[1]},t)},{regex:/https?:\/\/[^\s]+/,render:(e,t)=>(0,n.jsx)("a",{href:e[0],target:"_blank",rel:"noopener noreferrer",className:"text-accent-cyan no-underline hover:underline",children:e[0]},t)}];for(;a.length>0;){let e=null;for(let t of o){let r=a.match(t.regex);r&&void 0!==r.index&&(!e||r.index<e.index)&&(e={pattern:t,match:r,index:r.index})}if(!e){s.push(M(a,t,"".concat(r,"-text-").concat(l)));break}if(e.index>0){let n=a.slice(0,e.index);s.push(M(n,t,"".concat(r,"-pre-").concat(l))),l++}s.push(e.pattern.render(e.match,"".concat(r,"-el-").concat(l))),l++,a=a.slice(e.index+e.match[0].length)}return 1===s.length?s[0]:s}function S(e,t){let r=function(e){let t=e.match(/^(#{1,6})\s+/);return t?t[1].length:0}(e);if(r>0){let s=e.replace(/^#{1,6}\s+/,""),a={1:{className:"font-bold text-text-primary mt-4 mb-2 pb-1 border-b border-border-subtle",style:{fontSize:"1.5rem",lineHeight:"2rem"}},2:{className:"font-bold text-text-primary mt-3 mb-2",style:{fontSize:"1.25rem",lineHeight:"1.75rem"}},3:{className:"font-semibold text-text-primary mt-2.5 mb-1.5",style:{fontSize:"1.125rem",lineHeight:"1.5rem"}},4:{className:"font-semibold text-text-primary mt-2 mb-1",style:{fontSize:"1rem",lineHeight:"1.5rem"}},5:{className:"font-medium text-text-secondary mt-1.5 mb-1",style:{fontSize:"0.875rem",lineHeight:"1.25rem"}},6:{className:"font-medium text-text-muted mt-1 mb-0.5 uppercase tracking-wide",style:{fontSize:"0.75rem",lineHeight:"1rem"}}},{className:l,style:o}=a[r]||a[3];return(0,n.jsx)("div",{className:l,style:o,children:C(s,t,"heading")})}let s=function(e){let t=e.match(/^(\s*)([-*])\s+(.*)$/);if(t)return{type:"bullet",content:t[3],indent:t[1].length};let r=e.match(/^(\s*)(\d+\.)\s+(.*)$/);return r?{type:"numbered",content:r[3],indent:r[1].length}:{type:null,content:e,indent:0}}(e);if(s.type){var a;let r={marginLeft:"".concat(.5*s.indent+.5,"rem")};return(0,n.jsxs)("div",{className:"flex items-start gap-2 my-0.5",style:r,children:[(0,n.jsx)("span",{className:"text-accent-cyan flex-shrink-0 w-4 text-center",children:"bullet"===s.type?"•":null===(a=e.match(/^\s*(\d+\.)/))||void 0===a?void 0:a[1]}),(0,n.jsx)("span",{children:C(s.content,t,"list")})]})}return C(e,t,"line")}function L(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function M(e,t,r){let s;if(!t||0===t.length)return e;let a=t.map(L).filter(Boolean);if(0===a.length)return e;let l=RegExp("@(".concat(a.join("|"),")\\b"),"g"),o=[],i=0;for(;null!==(s=l.exec(e));)s.index>i&&o.push(e.slice(i,s.index)),o.push((0,n.jsxs)("span",{className:"px-1 py-0.5 bg-accent-cyan/20 text-accent-cyan rounded",children:["@",s[1]]},"".concat(r,"-mention-").concat(s.index))),i=s.index+s[0].length;return i<e.length&&o.push(e.slice(i)),o.length>0?o:e}},1841:function(e,t,r){r.d(t,{Zk:function(){return i},_V:function(){return l},xv:function(){return d}});var n=r(5118);let s=new Set,a=null;function l(){return a}function o(e){let t=e.headers.get("X-CSRF-Token");t&&(a=t,(0,n.aM)(t))}function i(e){return s.add(e),()=>s.delete(e)}async function c(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};try{let r={"Content-Type":"application/json",...t.headers};t.method&&"GET"!==t.method&&a&&(r["X-CSRF-Token"]=a);let n=await fetch(e,{...t,credentials:"include",headers:r});o(n);let l=await n.json();if(401===n.status||"object"==typeof l&&null!==l&&("SESSION_EXPIRED"===l.code||"USER_NOT_FOUND"===l.code)){let e={error:l.error||"Session expired",code:l.code||"SESSION_EXPIRED",message:l.message||"Your session has expired. Please log in again."};return!function(e){for(let t of s)try{t(e)}catch(e){console.error("[cloudApi] Session expired listener error:",e)}}(e),{success:!1,error:e.message,sessionExpired:!0}}if(!n.ok)return{success:!1,error:l.error||"Request failed with status ".concat(n.status)};return{success:!0,data:l}}catch(e){return{success:!1,error:e instanceof Error?e.message:"Network error"}}}let d={async getNangoLoginSession(){try{let e=await fetch("/api/auth/nango/login-session",{credentials:"include"});o(e);let t=await e.json();if(!e.ok)return{success:!1,error:t.error||"Failed to create login session"};return{success:!0,data:t}}catch(e){return{success:!1,error:e instanceof Error?e.message:"Network error"}}},async checkNangoLoginStatus(e){try{let t=await fetch("/api/auth/nango/login-status/".concat(encodeURIComponent(e)),{credentials:"include"});o(t);let r=await t.json();if(!t.ok)return{success:!1,error:r.error||"Failed to check login status"};return{success:!0,data:r}}catch(e){return{success:!1,error:e instanceof Error?e.message:"Network error"}}},getNangoRepoSession:async()=>c("/api/auth/nango/repo-session"),checkNangoRepoStatus:async e=>c("/api/auth/nango/repo-status/".concat(encodeURIComponent(e))),async checkSession(){try{let e=await fetch("/api/auth/session",{credentials:"include"});return o(e),await e.json()}catch(e){return{authenticated:!1,code:"SESSION_ERROR",message:"Failed to check session status"}}},getMe:async()=>c("/api/auth/me"),async logout(){try{let e={};a&&(e["X-CSRF-Token"]=a);let t=await fetch("/api/auth/logout",{method:"POST",credentials:"include",headers:e});return await t.json()}catch(e){return{success:!1,error:"Network error"}}},getWorkspaces:async()=>c("/api/workspaces"),getWorkspace:async e=>c("/api/workspaces/".concat(encodeURIComponent(e))),createWorkspace:async e=>c("/api/workspaces",{method:"POST",body:JSON.stringify(e)}),getPrimaryWorkspace:async()=>c("/api/workspaces/primary"),getWorkspaceSummary:async()=>c("/api/workspaces/summary"),getAccessibleWorkspaces:async()=>c("/api/workspaces/accessible"),getWorkspaceStatus:async e=>c("/api/workspaces/".concat(encodeURIComponent(e),"/status")),wakeupWorkspace:async e=>c("/api/workspaces/".concat(encodeURIComponent(e),"/wakeup"),{method:"POST"}),restartWorkspace:async e=>c("/api/workspaces/".concat(encodeURIComponent(e),"/restart"),{method:"POST"}),rebuildWorkspace:async e=>c("/api/workspaces/".concat(encodeURIComponent(e),"/rebuild"),{method:"POST"}),getProviders:async e=>e&&"default"!==e&&/^[0-9a-f-]{36}$/i.test(e)?c("/api/providers?workspaceId=".concat(encodeURIComponent(e))):{success:!1,error:"Invalid workspace ID"},disconnectProvider:async(e,t)=>c("/api/providers/".concat(encodeURIComponent(e),"?workspaceId=").concat(encodeURIComponent(t)),{method:"DELETE"}),getWorkspaceMembers:async e=>c("/api/workspaces/".concat(encodeURIComponent(e),"/members")),getRepoCollaborators:async e=>c("/api/workspaces/".concat(encodeURIComponent(e),"/repo-collaborators")),async inviteMember(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"member";return c("/api/workspaces/".concat(encodeURIComponent(e),"/members"),{method:"POST",body:JSON.stringify({githubUsername:t,role:r})})},getPendingInvites:async()=>c("/api/invites"),acceptInvite:async e=>c("/api/invites/".concat(encodeURIComponent(e),"/accept"),{method:"POST"}),declineInvite:async e=>c("/api/invites/".concat(encodeURIComponent(e),"/decline"),{method:"POST"}),updateMemberRole:async(e,t,r)=>c("/api/workspaces/".concat(encodeURIComponent(e),"/members/").concat(encodeURIComponent(t)),{method:"PATCH",body:JSON.stringify({role:r})}),removeMember:async(e,t)=>c("/api/workspaces/".concat(encodeURIComponent(e),"/members/").concat(encodeURIComponent(t)),{method:"DELETE"}),getBillingPlans:async()=>c("/api/billing/plans"),getSubscription:async()=>c("/api/billing/subscription"),async createCheckoutSession(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"month";return c("/api/billing/checkout",{method:"POST",body:JSON.stringify({tier:e,interval:t})})},createBillingPortal:async()=>c("/api/billing/portal",{method:"POST"}),async changeSubscription(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"month";return c("/api/billing/change",{method:"POST",body:JSON.stringify({tier:e,interval:t})})},cancelSubscription:async()=>c("/api/billing/cancel",{method:"POST"}),resumeSubscription:async()=>c("/api/billing/resume",{method:"POST"}),getInvoices:async()=>c("/api/billing/invoices"),stopWorkspace:async e=>c("/api/workspaces/".concat(encodeURIComponent(e),"/stop"),{method:"POST"}),deleteWorkspace:async e=>c("/api/workspaces/".concat(encodeURIComponent(e)),{method:"DELETE"}),addReposToWorkspace:async(e,t)=>c("/api/workspaces/".concat(encodeURIComponent(e),"/repos"),{method:"POST",body:JSON.stringify({repositoryIds:t})}),setCustomDomain:async(e,t)=>c("/api/workspaces/".concat(encodeURIComponent(e),"/domain"),{method:"POST",body:JSON.stringify({domain:t})}),verifyCustomDomain:async e=>c("/api/workspaces/".concat(encodeURIComponent(e),"/domain/verify"),{method:"POST"}),removeCustomDomain:async e=>c("/api/workspaces/".concat(encodeURIComponent(e),"/domain"),{method:"DELETE"}),getWorkspaceDetails:async e=>c("/api/workspaces/".concat(encodeURIComponent(e))),getRepos:async()=>c("/api/github-app/repos"),syncRepo:async e=>c("/api/repos/".concat(encodeURIComponent(e),"/sync"),{method:"POST"})}},5493:function(e,t,r){r.d(t,{GW:function(){return i},hP:function(){return c},oU:function(){return o},yh:function(){return a}});let n={backend:{primary:"#1264a3",light:"#e8f4fd",dark:"#0d4f82",text:"#ffffff"},frontend:{primary:"#7c3aed",light:"#f3e8ff",dark:"#5b21b6",text:"#ffffff"},infra:{primary:"#ea580c",light:"#fff7ed",dark:"#c2410c",text:"#ffffff"},lead:{primary:"#2bac76",light:"#ecfdf5",dark:"#059669",text:"#ffffff"},test:{primary:"#0d9488",light:"#f0fdfa",dark:"#0f766e",text:"#ffffff"},data:{primary:"#dc2626",light:"#fef2f2",dark:"#b91c1c",text:"#ffffff"},api:{primary:"#2563eb",light:"#eff6ff",dark:"#1d4ed8",text:"#ffffff"},worker:{primary:"#9333ea",light:"#faf5ff",dark:"#7e22ce",text:"#ffffff"},monitor:{primary:"#0891b2",light:"#ecfeff",dark:"#0e7490",text:"#ffffff"},security:{primary:"#be123c",light:"#fff1f2",dark:"#9f1239",text:"#ffffff"}},s=[{primary:"#6366f1",light:"#eef2ff",dark:"#4f46e5",text:"#ffffff"},{primary:"#ec4899",light:"#fdf2f8",dark:"#db2777",text:"#ffffff"},{primary:"#14b8a6",light:"#f0fdfa",dark:"#0d9488",text:"#ffffff"},{primary:"#f59e0b",light:"#fffbeb",dark:"#d97706",text:"#000000"},{primary:"#8b5cf6",light:"#f5f3ff",dark:"#7c3aed",text:"#ffffff"},{primary:"#06b6d4",light:"#ecfeff",dark:"#0891b2",text:"#ffffff"},{primary:"#f43f5e",light:"#fff1f2",dark:"#e11d48",text:"#ffffff"},{primary:"#84cc16",light:"#f7fee7",dark:"#65a30d",text:"#000000"}],a={online:"#22c55e",offline:"#6b7280",busy:"#eab308",processing:"#6366f1",error:"#ef4444",attention:"#ef4444",stuck:"#f97316"};function l(e){return e.toLowerCase().split("-").filter(Boolean)}function o(e){return l(e)[0]||e.toLowerCase()}function i(e){let t=o(e);return t in n?n[t]:s[function(e){let t=0;for(let r=0;r<e.length;r++)t=(t<<5)-t+e.charCodeAt(r),t&=t;return Math.abs(t)}(t)%s.length]}function c(e){let t=l(e);return 0===t.length?e.substring(0,2).toUpperCase():t.length>=2?(t[0][0]+t[1][0]).toUpperCase():t[0].substring(0,2).toUpperCase()}}}]);
|